mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Xie <xiehuan09@gmail.com>
To: rostedt@goodmis.org
Cc: mingo@redhat.com, mhiramat@kernel.org, zanussi@kernel.org,
	linux-kernel@vger.kernel.org, Jeff Xie <xiehuan09@gmail.com>
Subject: [PATCH 3/3] tracing: make tp_printk work on syscall tracepoints
Date: Wed, 30 Mar 2022 00:39:31 +0800	[thread overview]
Message-ID: <20220329163931.710555-4-xiehuan09@gmail.com> (raw)
In-Reply-To: <20220329163931.710555-1-xiehuan09@gmail.com>

Adding printk for syscall tracepoints for the tp_printk work.

Signed-off-by: Jeff Xie <xiehuan09@gmail.com>
---
 kernel/trace/trace_syscalls.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index f755bde42fd0..9798122166d3 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -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);
 }
-- 
2.25.1


  parent reply	other threads:[~2022-03-29 16:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 16:39 [PATCH 0/3] " Jeff Xie
2022-03-29 16:39 ` [PATCH 1/3] tracing: make tracepoint_iter_lock public Jeff Xie
2022-03-29 16:39 ` [PATCH 2/3] tracing: make tracepoint_printk_key public Jeff Xie
2022-03-29 16:39 ` Jeff Xie [this message]
2022-04-08 21:18   ` [PATCH 3/3] tracing: make tp_printk work on syscall tracepoints Steven Rostedt
2022-04-09  2:17     ` Jeff Xie
2022-04-08 14:21 ` [PATCH 0/3] " Jeff Xie
2022-04-08 21:03   ` 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=20220329163931.710555-4-xiehuan09@gmail.com \
    --to=xiehuan09@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=zanussi@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®