From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Rusty Russell <rusty@rustcorp.com.au>, Pekka Paalanen <pq@iki.fi>,
David Miller <davem@davemloft.net>,
linuxppc-dev@ozlabs.org, Steven Rostedt <srostedt@redhat.com>,
Paul Mundt <lethal@linux-sh.org>,
Paul Mackerras <paulus@samba.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 2/7] ftrace, ppc: convert to new dynamic ftrace arch API
Date: Sun, 16 Nov 2008 16:24:30 -0500 [thread overview]
Message-ID: <20081116212515.331278109@goodmis.org> (raw)
In-Reply-To: 20081116212428.938752312@goodmis.org
Impact: change PPC to use new ftrace arch API
This patch converts PPC to use the new dynamic ftrace arch API.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
arch/powerpc/include/asm/ftrace.h | 14 ++++++++-
arch/powerpc/kernel/ftrace.c | 60 +++++++++++++++++++++++++++++++++---
2 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h
index b298f7a..17efecc 100644
--- a/arch/powerpc/include/asm/ftrace.h
+++ b/arch/powerpc/include/asm/ftrace.h
@@ -7,7 +7,19 @@
#ifndef __ASSEMBLY__
extern void _mcount(void);
-#endif
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+static inline unsigned long ftrace_call_adjust(unsigned long addr)
+{
+ /* reloction of mcount call site is the same as the address */
+ return addr;
+}
+
+struct dyn_arch_ftrace {
+ /* nothing yet */
+};
+#endif /* CONFIG_DYNAMIC_FTRACE */
+#endif /* __ASSEMBLY__ */
#endif
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index f4b006e..aa5d0b2 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -33,12 +33,12 @@ static unsigned int ftrace_calc_offset(long ip, long addr)
return (int)(addr - ip);
}
-unsigned char *ftrace_nop_replace(void)
+static unsigned char *ftrace_nop_replace(void)
{
return (char *)&ftrace_nop;
}
-unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
+static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
{
static unsigned int op;
@@ -68,7 +68,7 @@ unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
# define _ASM_PTR " .long "
#endif
-int
+static int
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
unsigned char *new_code)
{
@@ -113,6 +113,55 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
return faulted;
}
+static int test_24bit_addr(unsigned long ip, unsigned long addr)
+{
+ unsigned long diff;
+
+ /* can we get to addr from ip in 24 bits? */
+ diff = ip > addr ? ip - addr : addr - ip;
+
+ return !(diff & ((unsigned long)-1 << 24));
+}
+
+int ftrace_make_nop(struct module *mod,
+ struct dyn_ftrace *rec, unsigned long addr)
+{
+ unsigned char *old, *new;
+
+ /*
+ * If the calling address is more that 24 bits away,
+ * then we had to use a trampoline to make the call.
+ * Otherwise just update the call site.
+ */
+ if (test_24bit_addr(rec->ip, addr)) {
+ /* within range */
+ old = ftrace_call_replace(rec->ip, addr);
+ new = ftrace_nop_replace();
+ return ftrace_modify_code(rec->ip, old, new);
+ }
+
+ return 0;
+}
+
+int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
+{
+ unsigned char *old, *new;
+
+ /*
+ * If the calling address is more that 24 bits away,
+ * then we had to use a trampoline to make the call.
+ * Otherwise just update the call site.
+ */
+ if (test_24bit_addr(rec->ip, addr)) {
+ /* within range */
+ old = ftrace_nop_replace();
+ new = ftrace_call_replace(rec->ip, addr);
+ return ftrace_modify_code(rec->ip, old, new);
+ }
+
+ return 0;
+}
+
int ftrace_update_ftrace_func(ftrace_func_t func)
{
unsigned long ip = (unsigned long)(&ftrace_call);
@@ -128,9 +177,10 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
int __init ftrace_dyn_arch_init(void *data)
{
- /* This is running in kstop_machine */
+ /* caller expects data to be zero */
+ unsigned long *p = data;
- ftrace_mcount_set(data);
+ *p = 0;
return 0;
}
--
1.5.6.5
--
next prev parent reply other threads:[~2008-11-16 21:25 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-16 21:24 [PATCH 0/7] Porting dynmaic ftrace to PowerPC Steven Rostedt
2008-11-16 21:24 ` [PATCH 1/7] ftrace, PPC: do not latency trace idle Steven Rostedt
2008-11-17 3:43 ` Paul Mackerras
2008-11-17 15:43 ` Steven Rostedt
2008-11-16 21:24 ` Steven Rostedt [this message]
2008-11-17 3:57 ` [PATCH 2/7] ftrace, ppc: convert to new dynamic ftrace arch API Paul Mackerras
2008-11-17 15:47 ` Steven Rostedt
2008-11-16 21:24 ` [PATCH 3/7] ftrace: powerpc mcount record port Steven Rostedt
2008-11-16 21:24 ` [PATCH 4/7] ftrace, PPC: use probe_kernel API to modify code Steven Rostedt
2008-11-17 4:44 ` Paul Mackerras
2008-11-17 15:51 ` Steven Rostedt
2008-11-16 21:24 ` [PATCH 5/7] ftrace, PPC64: handle module trampolines for dyn ftrace Steven Rostedt
2008-11-17 5:00 ` Paul Mackerras
2008-11-17 16:02 ` Steven Rostedt
2008-11-17 16:18 ` Steven Rostedt
2008-11-16 21:24 ` [PATCH 6/7] ftrace,ppc32: enabled dynamic ftrace Steven Rostedt
2008-11-16 21:24 ` [PATCH 7/7] ftrace,ppc32: dynamic ftrace to handle modules Steven Rostedt
2008-11-16 22:55 ` [PATCH 0/7] Porting dynmaic ftrace to PowerPC Paul Mackerras
2008-11-17 15:42 ` Steven Rostedt
2008-11-17 20:03 ` Steven Rostedt
2008-11-18 13:56 ` Steven Rostedt
2008-11-19 2:38 ` Paul Mackerras
2008-11-19 3:04 ` Steven Rostedt
2008-11-19 9:27 ` Ingo Molnar
2008-11-19 10:38 ` Paul Mackerras
2008-11-19 10:57 ` Ingo Molnar
2008-11-19 11:35 ` Paul Mackerras
2008-11-19 12:10 ` Steven Rostedt
2008-11-19 12:15 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081116212515.331278109@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=fweisbec@gmail.com \
--cc=lethal@linux-sh.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=pq@iki.fi \
--cc=rusty@rustcorp.com.au \
--cc=srostedt@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).