tracing: Various cleanups and small fixes
Subsystems (3)
Steven Rostedt
maintainercover tracing: Various cleanups and small fixes
This will be added to the queue for 3.10 and uploaded to my for-next branch in my git repo.
Chen Gang (1):
kernel: tracing: Use strlcpy instead of strncpy
Namhyung Kim (5):
tracing: Fix off-by-one on allocating stat->pages
tracing: Reset ftrace_graph_filter_enabled if count is zero
tracing: Get rid of unneeded key calculation in ftrace_hash_move()
tracing: Check return value of tracing_init_dentry()
ftrace: Get rid of ftrace_profile_bits
zhangwei(Jovi) (1):
tracing: Remove obsolete macro guard _TRACE_PROFILE_INIT
----
include/trace/ftrace.h | 2 -- kernel/trace/ftrace.c | 29 +++++++++-------------------- kernel/trace/trace.c | 6 ++++-- kernel/trace/trace_stack.c | 2 ++ kernel/trace/trace_stat.c | 2 ++ 5 files changed, 17 insertions(+), 24 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 kernel: tracing: Use strlcpy instead of strncpy
From: Chen Gang <[email protected]>
Use strlcpy() instead of strncpy() as it will always add a '\0' to the end of the string even if the buffer is smaller than what is being copied.
--- kernel/trace/ftrace.c | 4 ++-- kernel/trace/trace.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/trace/ftrace.c +2 -2
@@ -3496,14 +3496,14 @@ static char ftrace_filter_buf[FTRACE_FILTER_SIZE] __initdata;static int __init set_ftrace_notrace (char *str) { -strncpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +strlcpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { -strncpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +strlcpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
kernel/trace/trace.c +2 -2
@@ -125,7 +125,7 @@ static bool allocate_snapshot;static int __init set_cmdline_ftrace (char *str) { -strncpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); +strlcpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); default_bootup_tracer = bootup_tracer_buf;/* We are using ftrace early, expand it */ ring_buffer_expanded = true;
@@ -164,7 +164,7 @@ static char *trace_boot_options __initdata;static int __init set_trace_boot_options (char *str) { -strncpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); +strlcpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); trace_boot_options = trace_boot_options_buf;return 0 ; }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 2/7 tracing: Fix off-by-one on allocating stat->pages
In reply to Steven RostedtFrom: Namhyung Kim <[email protected]>
The first page was allocated separately, so no need to start from 0.
--- kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ftrace.c +1 -1
@@ -676,7 +676,7 @@ int ftrace_profile_pages_init(struct ftrace_profile_stat *stat) pages =DIV_ROUND_UP (functions,PROFILES_PER_PAGE ); -for (i =0 ; i < pages; i++) { +for (i =1 ; i < pages; i++) { pg->next = (void *)get_zeroed_page (GFP_KERNEL );if (!pg->next) goto out_free;
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 3/7 tracing: Reset ftrace_graph_filter_enabled if count is zero
In reply to Steven RostedtFrom: Namhyung Kim <[email protected]>
The ftrace_graph_count can be decreased with a "!" pattern, so that the enabled flag should be updated too.
--- kernel/trace/ftrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +2 -1
@@ -3792,7 +3792,8 @@ out:if (fail)return -EINVAL ; - ftrace_graph_filter_enabled =1 ; + ftrace_graph_filter_enabled = !!(*idx); +return 0 ; }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 4/7 tracing: Get rid of unneeded key calculation in ftrace_hash_move()
In reply to Steven RostedtFrom: Namhyung Kim <[email protected]>
It's not used anywhere in the function.
--- kernel/trace/ftrace.c | 5 ----- 1 file changed, 5 deletions(-)
kernel/trace/ftrace.c +0 -5
@@ -1320,7 +1320,6 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,struct hlist_head *hhd;struct ftrace_hash *old_hash;struct ftrace_hash *new_hash; -unsigned long key;int size = src->count;int bits =0 ;int ret;
@@ -1363,10 +1362,6 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,for (i =0 ; i < size; i++) { hhd = &src->buckets[i];hlist_for_each_entry_safe (entry, tp, tn, hhd, hlist) { -if (bits >0 ) - key =hash_long (entry->ip, bits); -else - key =0 ;remove_hash_entry (src, entry);__add_hash_entry (new_hash, entry); }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 5/7 tracing: Check return value of tracing_init_dentry()
In reply to Steven RostedtFrom: Namhyung Kim <[email protected]>
Check return value and bail out if it's NULL.
--- kernel/trace/trace.c | 2 ++ kernel/trace/trace_stack.c | 2 ++ kernel/trace/trace_stat.c | 2 ++ 3 files changed, 6 insertions(+)
kernel/trace/trace.c +2 -0
@@ -5953,6 +5953,8 @@ static __init int tracer_init_debugfs(void)trace_access_lock_init (); d_tracer =tracing_init_dentry (); +if (!d_tracer) +return 0 ;init_tracer_debugfs (&global_trace, d_tracer);
kernel/trace/trace_stack.c +2 -0
@@ -431,6 +431,8 @@ static __init int stack_trace_init(void)struct dentry *d_tracer; d_tracer =tracing_init_dentry (); +if (!d_tracer) +return 0 ;trace_create_file ("stack_max_size" ,0644 , d_tracer, &max_stack_size, &stack_max_size_fops);
kernel/trace/trace_stat.c +2 -0
@@ -307,6 +307,8 @@ static int tracing_stat_init(void)struct dentry *d_tracing; d_tracing =tracing_init_dentry (); +if (!d_tracing) +return 0 ; stat_dir =debugfs_create_dir ("trace_stat" , d_tracing);if (!stat_dir)
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 6/7 ftrace: Get rid of ftrace_profile_bits
In reply to Steven RostedtFrom: Namhyung Kim <[email protected]>
It seems that function profiler's hash size is fixed at 1024. Add and use FTRACE_PROFILE_HASH_BITS instead and update hash size macro.
--- kernel/trace/ftrace.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
kernel/trace/ftrace.c +4 -11
@@ -486,7 +486,6 @@ struct ftrace_profile_stat {#define PROFILES_PER_PAGE \ (PROFILE_RECORDS_SIZE / sizeof(struct ftrace_profile)) -static int ftrace_profile_bits__read_mostly ;static int ftrace_profile_enabled__read_mostly ;/* ftrace_profile_lock - synchronize the enable and disable of the profiler */
@@ -494,7 +493,8 @@ static DEFINE_MUTEX(ftrace_profile_lock); static DEFINE_PER_CPU(struct ftrace_profile_stat, ftrace_profile_stats); -#define FTRACE_PROFILE_HASH_SIZE 1024/* must be power of 2 */ +#define FTRACE_PROFILE_HASH_BITS 10 +#define FTRACE_PROFILE_HASH_SIZE (1 << FTRACE_PROFILE_HASH_BITS)static void *function_stat_next (void *v,int idx)
@@ -725,13 +725,6 @@ static int ftrace_profile_init_cpu(int cpu)if (!stat->hash)return -ENOMEM ; -if (!ftrace_profile_bits) { - size--; - -for (; size; size >>=1 ) - ftrace_profile_bits++; - } -/* Preallocate the function profiling pages */ if (ftrace_profile_pages_init (stat) <0 ) {kfree (stat->hash);
@@ -765,7 +758,7 @@ ftrace_find_profiled_func(struct ftrace_profile_stat *stat, unsigned long ip)struct hlist_node *n;unsigned long key; - key =hash_long (ip, ftrace_profile_bits); + key =hash_long (ip,FTRACE_PROFILE_HASH_BITS ); hhd = &stat->hash[key];if (hlist_empty (hhd))
@@ -784,7 +777,7 @@ static void ftrace_add_profile(struct ftrace_profile_stat *stat, {unsigned long key; - key =hash_long (rec->ip, ftrace_profile_bits); + key =hash_long (rec->ip,FTRACE_PROFILE_HASH_BITS );hlist_add_head_rcu (&rec->node, &stat->hash[key]); }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 7/7 tracing: Remove obsolete macro guard _TRACE_PROFILE_INIT
In reply to Steven RostedtFrom: "zhangwei(Jovi)" <[email protected]>
The macro _TRACE_PROFILE_INIT was removed a long time ago, but an "#undef" guard was left behind. Remove it.
--- include/trace/ftrace.h | 2 -- 1 file changed, 2 deletions(-)
include/trace/ftrace.h +0 -2
@@ -704,5 +704,3 @@ static inline void perf_test_probe_##call(void) \#include TRACE_INCLUDE (TRACE_INCLUDE_FILE )#endif /* CONFIG_PERF_EVENTS */ -#undef _TRACE_PROFILE_INIT -
Signature · 1 line
1.7.10.4