* [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
@ 2024-04-19 14:38 Bang Li
2024-04-20 1:40 ` Steven Rostedt
0 siblings, 1 reply; 4+ messages in thread
From: Bang Li @ 2024-04-19 14:38 UTC (permalink / raw)
To: rostedt, mhiramat
Cc: mark.rutland, mathieu.desnoyers, linux-trace-kernel,
libang.linux, Bang Li
Use the existing function ftrace_is_dead to replace the variable to make
the code clearer.
Signed-off-by: Bang Li <libang.li@antgroup.com>
---
kernel/trace/ftrace.c | 46 +++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 50ca4d4f8840..4a08c79db677 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2693,7 +2693,7 @@ void __weak ftrace_replace_code(int mod_flags)
int schedulable = mod_flags & FTRACE_MODIFY_MAY_SLEEP_FL;
int failed;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return;
do_for_each_ftrace_rec(pg, rec) {
@@ -2789,7 +2789,7 @@ ftrace_nop_initialize(struct module *mod, struct dyn_ftrace *rec)
{
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return 0;
ret = ftrace_init_nop(mod, rec);
@@ -3014,7 +3014,7 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
{
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
ret = __register_ftrace_function(ops);
@@ -3054,7 +3054,7 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
* to prevent the NULL pointer, instead of totally rolling it back and
* free trampoline, because those actions could cause further damage.
*/
- if (unlikely(ftrace_disabled)) {
+ if (unlikely(ftrace_is_dead())) {
__unregister_ftrace_function(ops);
return -ENODEV;
}
@@ -3068,7 +3068,7 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command)
{
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
ret = __unregister_ftrace_function(ops);
@@ -3211,7 +3211,7 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
for (i = 0; i < pg->index; i++) {
/* If something went wrong, bail without enabling anything */
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -1;
p = &pg->records[i];
@@ -3604,7 +3604,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
loff_t l = *pos; /* t_probe_start() must use original pos */
void *ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return NULL;
if (iter->flags & FTRACE_ITER_PROBE)
@@ -3642,7 +3642,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)
mutex_lock(&ftrace_lock);
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return NULL;
/*
@@ -3908,7 +3908,7 @@ ftrace_avail_open(struct inode *inode, struct file *file)
if (ret)
return ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
@@ -3981,7 +3981,7 @@ ftrace_avail_addrs_open(struct inode *inode, struct file *file)
if (ret)
return ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
@@ -4025,7 +4025,7 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
ftrace_ops_init(ops);
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
if (tracing_check_open_get_tr(tr))
@@ -4310,7 +4310,7 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
mutex_lock(&ftrace_lock);
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
goto out_unlock;
if (func_g.type == MATCH_INDEX) {
@@ -5181,7 +5181,7 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
} else
iter = file->private_data;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
/* iter->hash is a local copy, so we don't need regex_lock */
@@ -5267,7 +5267,7 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
struct ftrace_hash *hash;
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
mutex_lock(&ops->func_hash->regex_lock);
@@ -6159,7 +6159,7 @@ ftrace_graph_open(struct inode *inode, struct file *file)
struct ftrace_graph_data *fgd;
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
fgd = kmalloc(sizeof(*fgd), GFP_KERNEL);
@@ -6187,7 +6187,7 @@ ftrace_graph_notrace_open(struct inode *inode, struct file *file)
struct ftrace_graph_data *fgd;
int ret;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return -ENODEV;
fgd = kmalloc(sizeof(*fgd), GFP_KERNEL);
@@ -6297,7 +6297,7 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
mutex_lock(&ftrace_lock);
- if (unlikely(ftrace_disabled)) {
+ if (unlikely(ftrace_is_dead())) {
mutex_unlock(&ftrace_lock);
return -ENODEV;
}
@@ -6767,7 +6767,7 @@ void ftrace_release_mod(struct module *mod)
mutex_lock(&ftrace_lock);
- if (ftrace_disabled)
+ if (unlikely(ftrace_is_dead()))
goto out_unlock;
list_for_each_entry_safe(mod_map, n, &ftrace_mod_maps, list) {
@@ -6830,7 +6830,7 @@ void ftrace_module_enable(struct module *mod)
mutex_lock(&ftrace_lock);
- if (ftrace_disabled)
+ if (unlikely(ftrace_is_dead()))
goto out_unlock;
/*
@@ -6905,7 +6905,7 @@ void ftrace_module_init(struct module *mod)
{
int ret;
- if (ftrace_disabled || !mod->num_ftrace_callsites)
+ if (unlikely(ftrace_is_dead()) || !mod->num_ftrace_callsites)
return;
ret = ftrace_process_locs(mod, mod->ftrace_callsites,
@@ -8171,7 +8171,7 @@ static void ftrace_startup_sysctl(void)
{
int command;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return;
/* Force update next time */
@@ -8189,7 +8189,7 @@ static void ftrace_shutdown_sysctl(void)
{
int command;
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
return;
/* ftrace_start_up is true if ftrace is running */
@@ -8225,7 +8225,7 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
mutex_lock(&ftrace_lock);
- if (unlikely(ftrace_disabled))
+ if (unlikely(ftrace_is_dead()))
goto out;
ret = proc_dointvec(table, write, buffer, lenp, ppos);
--
2.19.1.6.gb485710b
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
2024-04-19 14:38 [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function Bang Li
@ 2024-04-20 1:40 ` Steven Rostedt
2024-04-20 3:50 ` Bang Li
0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2024-04-20 1:40 UTC (permalink / raw)
To: Bang Li
Cc: mhiramat, mark.rutland, mathieu.desnoyers, linux-trace-kernel,
libang.linux
On Fri, 19 Apr 2024 22:38:44 +0800
"Bang Li" <libang.li@antgroup.com> wrote:
> Use the existing function ftrace_is_dead to replace the variable to make
> the code clearer.
>
> Signed-off-by: Bang Li <libang.li@antgroup.com>
> ---
> kernel/trace/ftrace.c | 46 +++++++++++++++++++++----------------------
> 1 file changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 50ca4d4f8840..4a08c79db677 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2693,7 +2693,7 @@ void __weak ftrace_replace_code(int mod_flags)
> int schedulable = mod_flags & FTRACE_MODIFY_MAY_SLEEP_FL;
> int failed;
>
> - if (unlikely(ftrace_disabled))
> + if (unlikely(ftrace_is_dead()))
> return;
>
NACK!
ftrace_is_dead() is only there to make the static variable
"ftrace_disabled" available for code outside of ftrace.c. In ftrace.c,
it is perfectly fine to use ftrace_disabled.
-- Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
2024-04-20 1:40 ` Steven Rostedt
@ 2024-04-20 3:50 ` Bang Li
2024-04-28 4:17 ` Steven Rostedt
0 siblings, 1 reply; 4+ messages in thread
From: Bang Li @ 2024-04-20 3:50 UTC (permalink / raw)
To: Steven Rostedt
Cc: mhiramat, mark.rutland, mathieu.desnoyers, linux-trace-kernel,
libang.linux
On 2024/4/20 9:40, Steven Rostedt wrote:
> On Fri, 19 Apr 2024 22:38:44 +0800
> "Bang Li" <libang.li@antgroup.com> wrote:
>
>> Use the existing function ftrace_is_dead to replace the variable to make
>> the code clearer.
>>
>> Signed-off-by: Bang Li <libang.li@antgroup.com>
>> ---
>> kernel/trace/ftrace.c | 46 +++++++++++++++++++++----------------------
>> 1 file changed, 23 insertions(+), 23 deletions(-)
>>
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> index 50ca4d4f8840..4a08c79db677 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -2693,7 +2693,7 @@ void __weak ftrace_replace_code(int mod_flags)
>> int schedulable = mod_flags & FTRACE_MODIFY_MAY_SLEEP_FL;
>> int failed;
>>
>> - if (unlikely(ftrace_disabled))
>> + if (unlikely(ftrace_is_dead()))
>> return;
>>
>
> NACK!
>
> ftrace_is_dead() is only there to make the static variable
> "ftrace_disabled" available for code outside of ftrace.c. In ftrace.c,
> it is perfectly fine to use ftrace_disabled.
>
> -- Steve
Thank you for your explanation, let me understand this. How about
replacing ftrace_disabled with unlike(ftrace_disabled)?
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 50ca4d4f8840..76e0814723cb 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6767,7 +6767,7 @@ void ftrace_release_mod(struct module *mod)
mutex_lock(&ftrace_lock);
- if (ftrace_disabled)
+ if (unlikely(ftrace_disabled))
goto out_unlock;
list_for_each_entry_safe(mod_map, n, &ftrace_mod_maps, list) {
@@ -6830,7 +6830,7 @@ void ftrace_module_enable(struct module *mod)
mutex_lock(&ftrace_lock);
- if (ftrace_disabled)
+ if (unlikely(ftrace_disabled))
goto out_unlock;
/*
Thanks again for the review!
Bang
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
2024-04-20 3:50 ` Bang Li
@ 2024-04-28 4:17 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2024-04-28 4:17 UTC (permalink / raw)
To: Bang Li
Cc: mhiramat, mark.rutland, mathieu.desnoyers, linux-trace-kernel,
libang.linux
On Sat, 20 Apr 2024 11:50:29 +0800
"Bang Li" <libang.li@antgroup.com> wrote:
> Thank you for your explanation, let me understand this. How about
> replacing ftrace_disabled with unlike(ftrace_disabled)?
Why? They are slow paths. No need to optimize them.
-- Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-28 4:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 14:38 [PATCH] ftrace: Replace ftrace_disabled variable with ftrace_is_dead function Bang Li
2024-04-20 1:40 ` Steven Rostedt
2024-04-20 3:50 ` Bang Li
2024-04-28 4:17 ` Steven Rostedt
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.