ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
PATCH 1/1 ftrace: Replace ftrace_disabled variable with ftrace_is_dead function
Use the existing function ftrace_is_dead to replace the variable to make the code clearer.
--- kernel/trace/ftrace.c | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
kernel/trace/ftrace.c +23 -23
@@ -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);
Signature · 1 line
2.19.1.6.gb485710b
Quoted 13 lines · On Fri, 19 Apr 2024 22:38:44 +0800 "Bang Li" <[email protected]> wrote:
Use the existing function
ftrace_is_deadto replace the variable to make the code clearer.Signed-off-by Bang Li <[email protected]>--- kernel/trace/ftrace.c | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-)kernel/trace/ftrace.c +0
-0
kernel/trace/ftrace.c void __weak ftrace_replace_code(int mod_flags) · line 2698
Quoted 7 lines
kernel/trace/ftrace.c +1
-1@@ -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
Quoted 26 lines · Steven Rostedt
Quoted 13 lines · On Fri, 19 Apr 2024 22:38:44 +0800 "Bang Li" <[email protected]> wrote:
Use the existing function
ftrace_is_deadto replace the variable to make the code clearer.Signed-off-by Bang Li <[email protected]>--- kernel/trace/ftrace.c | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-)kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c void __weak ftrace_replace_code(int mod_flags) · line 2698
Quoted 7 lines
kernel/trace/ftrace.c +1
-1@@ -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!
Quoted 5 lines
ftrace_is_dead()is only there to make the static variable "ftrace_disabled" available for code outside offtrace.c. Inftrace.c, it is perfectly fine to useftrace_disabled.-- Steve
Thank you for your explanation, let me understand this. How about replacing ftrace_disabled with unlike(ftrace_disabled)?
kernel/trace/ftrace.c +2 -2
@@ -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
Steven Rostedt
maintainerQuoted 2 lines · On Sat, 20 Apr 2024 11:50:29 +0800 "Bang Li" <[email protected]> wrote:
Thank you for your explanation, let me understand this. How about replacing
ftrace_disabledwithunlike(ftrace_disabled)?
Why? They are slow paths. No need to optimize them.
-- Steve