tracing: make tp_printk work on syscall tracepoints
cover tracing: make tp_printk work on syscall tracepoints
Currently the tp_printk option has no effect on syscall tracepoint. When adding the kernel option parameter tp_printk, then:
echo 1 > /sys/kernel/debug/tracing/events/syscalls/enable
When running any application, no trace information is printed on the terminal.
Now added printk for syscall tracepoints.
Jeff Xie (3):
tracing: make tracepoint_iter_lock public
tracing: make tracepoint_printk_key public
tracing: make tp_printk work on syscall tracepoints
kernel/trace/trace.c | 4 ++-- kernel/trace/trace.h | 2 ++ kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 tracing: make tracepoint_iter_lock public
The syscall tracepoints need tracepoint_iter_lock for the tp_printk work.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -2833,7 +2833,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb, }EXPORT_SYMBOL_GPL (trace_event_buffer_lock_reserve); -static DEFINE_SPINLOCK (tracepoint_iter_lock); +DEFINE_SPINLOCK (tracepoint_iter_lock);static DEFINE_MUTEX (tracepoint_printk_mutex);static void output_printk (struct trace_event_buffer *fbuffer)
kernel/trace/trace.h +1 -0
@@ -1523,6 +1523,7 @@ static inline void *event_file_data(struct file *filp)extern struct mutex event_mutex;extern struct list_head ftrace_events; +extern spinlock_t tracepoint_iter_lock;extern const struct file_operations event_trigger_fops;extern const struct file_operations event_hist_fops;
Signature · 1 line
2.25.1
PATCH 2/3 tracing: make tracepoint_printk_key public
In reply to Jeff XieThe syscall tracepoints need tracepoint_printk_key for the tp_printk work.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -88,7 +88,7 @@ void __init disable_tracing_selftest(const char *reason)struct trace_iterator *tracepoint_print_iter;int tracepoint_printk;static bool tracepoint_printk_stop_on_boot__initdata ; -static DEFINE_STATIC_KEY_FALSE (tracepoint_printk_key); +DEFINE_STATIC_KEY_FALSE (tracepoint_printk_key);/* For tracers that don't implement custom flags */ static struct tracer_opt dummy_tracer_opt[] = {
kernel/trace/trace.h +1 -0
@@ -1524,6 +1524,7 @@ static inline void *event_file_data(struct file *filp)extern struct mutex event_mutex;extern struct list_head ftrace_events;extern spinlock_t tracepoint_iter_lock; +DECLARE_STATIC_KEY_FALSE (tracepoint_printk_key);extern const struct file_operations event_trigger_fops;extern const struct file_operations event_hist_fops;
Signature · 1 line
2.25.1
PATCH 3/3 tracing: make tp_printk work on syscall tracepoints
In reply to Jeff XieAdding printk for syscall tracepoints for the tp_printk work.
--- kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
kernel/trace/trace_syscalls.c +25 -0
@@ -290,6 +290,25 @@ static int __init syscall_enter_define_fields(struct trace_event_call *call)return ret; } +static void syscall_output_printk (struct trace_entry *ent, +struct trace_event_file *trace_file,struct trace_array *tr) +{ +unsigned long flags; +struct trace_iterator *iter = tracepoint_print_iter; +struct trace_event *event = &trace_file->event_call->event; + +spin_lock_irqsave (&tracepoint_iter_lock, flags); + +trace_seq_init (&iter->seq); + iter->ent = ent; + iter->tr = tr; + event->funcs->trace (iter,0 , event); +trace_seq_putc (&iter->seq,0 ); +pr_info ("%s" , iter->seq.buffer); + +spin_unlock_irqrestore (&tracepoint_iter_lock, flags); +} +static void ftrace_syscall_enter (void *data,struct pt_regs *regs,long id) {struct trace_array *tr = data;
@@ -333,6 +352,9 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)syscall_get_arguments (current, regs, args);memcpy (entry->args, args,sizeof (unsigned long ) * sys_data->nb_args); +if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx); }
@@ -376,6 +398,9 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) entry->nr = syscall_nr; entry->ret =syscall_get_return_value (current, regs); +if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx); }
Signature · 1 line
2.25.1
Steven Rostedt
maintainerOn Wed, 30 Mar 2022 00:39:31 +0800
Jeff Xie <[email protected]> wrote:
First, patch 1 and 2 can be folded into this patch. Making something "available for future use" is not a reason to break up patches. It will not help in bisecting, and its not something to be backported.
Next, the tracing subsystem follows the "Capitalize first letter" for subjects:
"tracing: Make tp_printk work on syscall tracepoints"
Quoted 1 line
Adding printk for syscall tracepoints for the
tp_printkwork.
Need to add much more content to the above. Your cover letter would work.
Currently the tp_printk option has no effect on syscall tracepoint. When adding the kernel option parameter tp_printk, then:
echo 1 > /sys/kernel/debug/tracing/events/syscalls/enable
When running any application, no trace information is printed on the terminal.
Now added printk for syscall tracepoints.
As commit logs should be self explanatory per commit. The cover letter was, but this patch was lacking.
Quoted 49 lines
Signed-off-by Jeff Xie <[email protected]>--- kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)kernel/trace/trace_syscalls.c +22
-0@@ -290,6 +290,25 @@ static int __init syscall_enter_define_fields(struct trace_event_call *call)return ret; } +static void syscall_output_printk (struct trace_entry *ent, +struct trace_event_file *trace_file,struct trace_array *tr) +{ +unsigned long flags; +struct trace_iterator *iter = tracepoint_print_iter; +struct trace_event *event = &trace_file->event_call->event; + +spin_lock_irqsave (&tracepoint_iter_lock, flags); + +trace_seq_init (&iter->seq); + iter->ent = ent; + iter->tr = tr; + event->funcs->trace (iter,0 , event); +trace_seq_putc (&iter->seq,0 ); +pr_info ("%s" , iter->seq.buffer); + +spin_unlock_irqrestore (&tracepoint_iter_lock, flags); +} +static void ftrace_syscall_enter (void *data,struct pt_regs *regs,long id) {struct trace_array *tr = data;@@ -333,6 +352,9 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)syscall_get_arguments (current, regs, args);memcpy (entry->args, args,sizeof (unsigned long ) * sys_data->nb_args); +if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx);}
kernel/trace/trace_syscalls.c static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) · line 403
Quoted 6 lines
kernel/trace/trace_syscalls.c +3
-0@@ -376,6 +398,9 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) entry->nr = syscall_nr; entry->ret =syscall_get_return_value (current, regs); +if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +
Instead of reimplementing the logic, just convert the syscall code to use, trace_event_buffer_reserve() and trace_event_buffer_commit(), and then you not only get tp_printk() for syscalls, but also other features as well.
-- Steve
Quoted 3 lines
kernel/trace/trace_syscalls.c +0
-0event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx); }
Hi steve,
Quoted 22 lines · Steven Rostedt
On Wed, 30 Mar 2022 00:39:31 +0800
Jeff Xie <[email protected]> wrote:First, patch 1 and 2 can be folded into this patch. Making something "available for future use" is not a reason to break up patches. It will not help in bisecting, and its not something to be backported.
Next, the tracing subsystem follows the "Capitalize first letter" for subjects:
"tracing: Make
tp_printkwork on syscall tracepoints"Quoted 1 line
Adding printk for syscall tracepoints for the
tp_printkwork.Need to add much more content to the above. Your cover letter would work.
Currently the
tp_printkoption has no effect on syscall tracepoint. When adding the kernel option parametertp_printk, then:echo 1 >
/sys/kernel/debug/tracing/events/syscalls/enable
Quoted 7 lines
When running any application, no trace information is printed on the terminal.
Now added printk for syscall tracepoints.
As commit logs should be self explanatory per commit. The cover letter was, but this patch was lacking.
Thanks a lot for these detailed suggestions.
Quoted 53 lines
Quoted 53 lines
Signed-off-by Jeff Xie <[email protected]>--- kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)kernel/trace/trace_syscalls.c +22
-0@@ -290,6 +290,25 @@ static int __init syscall_enter_define_fields(struct trace_event_call *call)return ret; } +static void syscall_output_printk (struct trace_entry *ent, +struct trace_event_file *trace_file,struct trace_array *tr) +{ +unsigned long flags; +struct trace_iterator *iter = tracepoint_print_iter; +struct trace_event *event = &trace_file->event_call->event; + +spin_lock_irqsave (&tracepoint_iter_lock, flags); + +trace_seq_init (&iter->seq); + iter->ent = ent; + iter->tr = tr; + event->funcs->trace (iter,0 , event); +trace_seq_putc (&iter->seq,0 ); +pr_info ("%s" , iter->seq.buffer); + +spin_unlock_irqrestore (&tracepoint_iter_lock, flags); +} +static void ftrace_syscall_enter (void *data,struct pt_regs *regs,long id) {struct trace_array *tr = data;@@ -333,6 +352,9 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)syscall_get_arguments (current, regs, args);memcpy (entry->args, args,sizeof (unsigned long ) * sys_data->nb_args); +if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx);}
kernel/trace/trace_syscalls.c +0
-0@@ -376,6 +398,9 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) entry->nr = syscall_nr; entry->ret =syscall_get_return_value (current, regs);
Quoted 7 lines
kernel/trace/trace_syscalls.c static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · line 357
Quoted 3 lines
kernel/trace/trace_syscalls.c +3
-0+if (static_key_false (&tracepoint_printk_key.key)) +syscall_output_printk (&entry->ent, trace_file, tr); +Instead of reimplementing the logic, just convert the syscall code to use,
trace_event_buffer_reserve()andtrace_event_buffer_commit(), and then you not only gettp_printk()for syscalls, but also other features as well.
Thanks, I will prepare the V2.
Quoted 7 lines
-- Steve
Quoted 3 lines
kernel/trace/trace_syscalls.c +0
-0event_trigger_unlock_commit (trace_file, buffer, event, entry, trace_ctx); }
---
JeffXie
Hi,
Anyone have any suggestions for this patch series? ;-)
Quoted 16 lines · Jeff Xie
Currently the
tp_printkoption has no effect on syscall tracepoint. When adding the kernel option parametertp_printk, then:echo 1 >
/sys/kernel/debug/tracing/events/syscalls/enableWhen running any application, no trace information is printed on the terminal.
Now added printk for syscall tracepoints.
Jeff Xie (3):
tracing: maketracepoint_iter_lockpublic
tracing: maketracepoint_printk_keypublic
tracing: maketp_printkwork on syscall tracepoints
Quoted 8 lines
kernel/trace/trace.c | 4 ++-- kernel/trace/trace.h | 2 ++ kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-)--
2.25.1
---
JeffXie
Steven Rostedt
maintainerQuoted 1 line · On Fri, 8 Apr 2022 22:21:18 +0800 Jeff Xie <[email protected]> wrote:
Anyone have any suggestions for this patch series? ;-)
Thanks for the reminder. I'll look at them now.
-- Steve