linux-mips
[Top] [All Lists]

[PATCH v3 2/2] MIPS: extract schedule_mfi info from __schedule

To: ralf@linux-mips.org, linux-mips@linux-mips.org
Subject: [PATCH v3 2/2] MIPS: extract schedule_mfi info from __schedule
From: Tony Wu <tung7970@gmail.com>
Date: Mon, 13 May 2013 00:05:34 +0800
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=r86Fb2tHfFEX/9bhXzt5A3PYLjcCIrdfX26+XhcNQPw=; b=WQFNRkqPB2eHNtoqUX8XM7fQrM7oFw1nlryXNtqDtHOAuZ6XeKbWqaZhcGQFYjICjo zn0BDvXt3DMQz2MzCxCs4dZ+qunxOJFhbxfLMgZNPNFOH+A9kdltOd5V1cnKcPQL/7bi fuQAH7fuKNvJyfg8bJwbf2jyxT/WmsQkRMqruCCbPQ7ThA12YdnfRn6dItOOMnh+s6N2 lXYSRyj1PJBNGQxbXacujoU+GnHGCt20sM8Vb77vV3I9Q5VPyw18MZhGYI8FZd8nlDGn zZSteXKNGLPp8Rv3pihrghUrhd3sVz/SiMCvKMh0fk8KUD+LCISKW32R7cwTgF+8qfRR Sc2g==
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
schedule_mfi is supposed to be extracted from schedule(), and
is used in thread_saved_pc and get_wchan.

But, after optimization, schedule() is reduced to a sibling
call to __schedule(), and no real frame info can be extracted.

One solution is to compile schedule() with -fno-omit-frame-pointer
and -fno-optimize-sibling-calls, but that will incur performance
degradation.

Another solution is to extract info from the real scheduler,
__schedule, and this is the approache adopted here.

This patch reads the __schedule address by either following
the 'j' call in schedule if KALLSYMS is disabled or by using
kallsyms_lookup_name to lookup __schedule if KALLSYMS is
available, then, extracts schedule_mfi from __schedule frame info.

This patch also fixes the "Can't analyze schedule() prologue"
warning at boot time.

Signed-off-by: Tony Wu <tung7970@gmail.com>
---
 arch/mips/kernel/process.c |   34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index d66b04d..b216157 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -223,6 +223,9 @@ struct mips_frame_info {
        int             pc_offset;
 };
 
+#define J_TARGET(pc,target)    \
+               (((unsigned long)(pc) & 0xf0000000) | ((target) << 2))
+
 static inline int is_ra_save_ins(union mips_instruction *ip)
 {
        /* sw / sd $ra, offset($sp) */
@@ -294,15 +297,42 @@ err:
 
 static struct mips_frame_info schedule_mfi __read_mostly;
 
+#ifdef CONFIG_KALLSYMS
+static unsigned long get___schedule_addr(void)
+{
+       return kallsyms_lookup_name("__schedule");
+}
+#else
+static unsigned long get___schedule_addr(void)
+{
+       union mips_instruction *ip = (void *)schedule;
+       int max_insns = 8;
+       int i;
+
+       for (i = 0; i < max_insns; i++, ip++) {
+               if (ip->j_format.opcode == j_op)
+                       return J_TARGET(ip, ip->j_format.target);
+       }
+       return 0;
+}
+#endif
+
 static int __init frame_info_init(void)
 {
        unsigned long size = 0;
 #ifdef CONFIG_KALLSYMS
        unsigned long ofs;
+#endif
+       unsigned long addr;
 
-       kallsyms_lookup_size_offset((unsigned long)schedule, &size, &ofs);
+       addr = get___schedule_addr();
+       if (!addr)
+               addr = (unsigned long)schedule;
+
+#ifdef CONFIG_KALLSYMS
+       kallsyms_lookup_size_offset(addr, &size, &ofs);
 #endif
-       schedule_mfi.func = schedule;
+       schedule_mfi.func = (void *)addr;
        schedule_mfi.func_size = size;
 
        get_frame_info(&schedule_mfi);
-- 
1.7.10.2 (Apple Git-33)


<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH v3 2/2] MIPS: extract schedule_mfi info from __schedule, Tony Wu <=