From: Naveen N Rao <naveen@kernel.org>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [RFC PATCH] powerpc/ftrace: Refactoring and support for -fpatchable-function-entry
Date: Tue, 23 May 2023 15:01:39 +0530 [thread overview]
Message-ID: <1684833778.7ege0impv3.naveen@kernel.org> (raw)
In-Reply-To: <5463949f-289b-1eae-17c7-f77f63389f98@csgroup.eu>
Christophe Leroy wrote:
>
> That's better, but still more time than original implementation:
>
> +20% to activate function tracer (was +40% with your RFC)
> +21% to activate nop tracer (was +24% with your RFC)
>
> perf record (without strict kernel rwx) :
>
> 17.75% echo [kernel.kallsyms] [k] ftrace_check_record
> 9.76% echo [kernel.kallsyms] [k] ftrace_replace_code
> 6.53% echo [kernel.kallsyms] [k] patch_instruction
> 5.21% echo [kernel.kallsyms] [k] __ftrace_hash_rec_update
> 4.26% echo [kernel.kallsyms] [k] ftrace_get_addr_curr
> 4.18% echo [kernel.kallsyms] [k] ftrace_get_call_inst.isra.0
> 3.45% echo [kernel.kallsyms] [k] ftrace_get_addr_new
> 3.08% echo [kernel.kallsyms] [k] function_trace_call
> 2.20% echo [kernel.kallsyms] [k] __rb_reserve_next.constprop.0
> 2.05% echo [kernel.kallsyms] [k] copy_page
> 1.91% echo [kernel.kallsyms] [k]
> ftrace_create_branch_inst.constprop.0
> 1.83% echo [kernel.kallsyms] [k] ftrace_rec_iter_next
> 1.83% echo [kernel.kallsyms] [k] rb_commit
> 1.69% echo [kernel.kallsyms] [k] ring_buffer_lock_reserve
> 1.54% echo [kernel.kallsyms] [k] trace_function
> 1.39% echo [kernel.kallsyms] [k] __call_rcu_common.constprop.0
> 1.25% echo ld-2.23.so [.] do_lookup_x
> 1.17% echo [kernel.kallsyms] [k] ftrace_rec_iter_record
> 1.03% echo [kernel.kallsyms] [k] unmap_page_range
> 0.95% echo [kernel.kallsyms] [k] flush_dcache_icache_page
> 0.95% echo [kernel.kallsyms] [k] ftrace_lookup_ip
Ok, I simplified this further, and this is as close to the previous fast
path as we can get (applies atop the original RFC). The only difference
left is the ftrace_rec iterator.
- Naveen
---
arch/powerpc/kernel/trace/ftrace.c | 55 +++++++++++++-----------------
1 file changed, 23 insertions(+), 32 deletions(-)
diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index a9d57f338bd78e..4937651ecfafb0 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -96,13 +96,18 @@ static unsigned long find_ftrace_tramp(unsigned long ip)
static int ftrace_get_call_inst(struct dyn_ftrace *rec, unsigned long addr, ppc_inst_t *call_inst)
{
- struct module *mod = rec->arch.mod;
unsigned long ip = rec->ip;
unsigned long stub;
if (is_offset_in_branch_range(addr - ip)) {
/* Within range */
stub = addr;
+#ifdef CONFIG_MODULES
+ } else if (rec->arch.mod) {
+ /* Module code would be going to one of the module stubs */
+ stub = (addr == (unsigned long)ftrace_caller ? rec->arch.mod->arch.tramp :
+ rec->arch.mod->arch.tramp_regs);
+#endif
} else if (core_kernel_text(ip)) {
/* We would be branching to one of our ftrace stubs */
stub = find_ftrace_tramp(ip);
@@ -110,9 +115,6 @@ static int ftrace_get_call_inst(struct dyn_ftrace *rec, unsigned long addr, ppc_
pr_err("0x%lx: No ftrace stubs reachable\n", ip);
return -EINVAL;
}
- } else if (IS_ENABLED(CONFIG_MODULES)) {
- /* Module code would be going to one of the module stubs */
- stub = (addr == (unsigned long)ftrace_caller ? mod->arch.tramp : mod->arch.tramp_regs);
} else {
return -EINVAL;
}
@@ -159,7 +161,8 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long ad
void ftrace_replace_code(int enable)
{
- ppc_inst_t old, new, nop_inst, call_inst, new_call_inst;
+ ppc_inst_t old, new, call_inst, new_call_inst;
+ ppc_inst_t nop_inst = ppc_inst(PPC_RAW_NOP());
unsigned long ip, new_addr, addr;
struct ftrace_rec_iter *iter;
struct dyn_ftrace *rec;
@@ -167,53 +170,41 @@ void ftrace_replace_code(int enable)
for_ftrace_rec_iter(iter) {
rec = ftrace_rec_iter_record(iter);
- update = ftrace_test_record(rec, enable);
ip = rec->ip;
- new_addr = 0;
+
+ if (rec->flags & FTRACE_FL_DISABLED && !(rec->flags & FTRACE_FL_ENABLED))
+ continue;
+
+ addr = ftrace_get_addr_curr(rec);
+ new_addr = ftrace_get_addr_new(rec);
+ update = ftrace_update_record(rec, enable);
switch (update) {
case FTRACE_UPDATE_IGNORE:
default:
continue;
case FTRACE_UPDATE_MODIFY_CALL:
- addr = ftrace_get_addr_curr(rec);
- new_addr = ftrace_get_addr_new(rec);
- break;
- case FTRACE_UPDATE_MAKE_CALL:
- addr = ftrace_get_addr_new(rec);
- break;
- case FTRACE_UPDATE_MAKE_NOP:
- addr = ftrace_get_addr_curr(rec);
- break;
- }
- nop_inst = ppc_inst(PPC_RAW_NOP());
- ret = ftrace_get_call_inst(rec, addr, &call_inst);
- if (!ret && new_addr)
ret = ftrace_get_call_inst(rec, new_addr, &new_call_inst);
- if (ret)
- goto out;
-
- switch (update) {
- case FTRACE_UPDATE_MODIFY_CALL:
+ ret |= ftrace_get_call_inst(rec, addr, &call_inst);
old = call_inst;
new = new_call_inst;
break;
+ case FTRACE_UPDATE_MAKE_NOP:
+ ret = ftrace_get_call_inst(rec, addr, &call_inst);
+ old = call_inst;
+ new = nop_inst;
+ break;
case FTRACE_UPDATE_MAKE_CALL:
+ ret = ftrace_get_call_inst(rec, new_addr, &call_inst);
old = nop_inst;
new = call_inst;
break;
- case FTRACE_UPDATE_MAKE_NOP:
- new = nop_inst;
- old = call_inst;
- break;
}
- /* old == new when going to .ftrace.text stub for modify */
- if (!ppc_inst_equal(old, new))
+ if (!ret)
ret = ftrace_modify_code(ip, old, new);
if (ret)
goto out;
- ftrace_update_record(rec, enable);
}
out:
next prev parent reply other threads:[~2023-05-23 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-19 19:26 [RFC PATCH] powerpc/ftrace: Refactoring and support for -fpatchable-function-entry Naveen N Rao
2023-05-20 10:34 ` Christophe Leroy
2023-05-20 16:28 ` Christophe Leroy
2023-05-20 17:48 ` Christophe Leroy
2023-05-20 18:17 ` Naveen N Rao
2023-05-21 9:14 ` Christophe Leroy
2023-05-23 9:31 ` Naveen N Rao [this message]
2023-05-26 5:35 ` Christophe Leroy
2023-06-07 17:05 ` Naveen N Rao
2023-05-20 18:28 ` Naveen N Rao
2023-05-23 13:20 ` 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=1684833778.7ege0impv3.naveen@kernel.org \
--to=naveen@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.