mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tracing: save cmdline only when task does not exist in savecmd for optimization
@ 2021-10-11 11:50 Yang Jihong
  2021-10-14  3:02 ` Steven Rostedt
  2021-10-14 14:32 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Jihong @ 2021-10-11 11:50 UTC (permalink / raw)
  To: rostedt, mingo, linux-kernel; +Cc: yangjihong1

commit 85f726a35e504418 use strncpy instead of memcpy when copying comm,
on ARM64 machine, this commit causes performance degradation.

For the task that already exists in savecmd, it is unnecessary to call
set_cmdline to execute strncpy once, run set_cmdline only if the task does
not exist in savecmd.

I have written an example (which is an extreme case) in which trace sched switch
is invoked for 1000 times, as shown in the following:

  for (int i = 0; i < 1000; i++) {
          trace_sched_switch(true, current, current);
 }

On ARM64 machine, compare the data before and after the optimization:
+---------------------+------------------------------+------------------------+
|                     | Total number of instructions | Total number of cycles |
+---------------------+------------------------------+------------------------+
| Before optimization |           1107367            |          658491        |
+---------------------+------------------------------+------------------------+
| After optimization  |            869367            |          520171        |
+---------------------+------------------------------+------------------------+
As shown above, there is nearly 26% performance

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 kernel/trace/trace.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 7896d30d90f7..a795610a3b37 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2427,8 +2427,11 @@ static int trace_save_cmdline(struct task_struct *tsk)
 		savedcmd->cmdline_idx = idx;
 	}
 
-	savedcmd->map_cmdline_to_pid[idx] = tsk->pid;
-	set_cmdline(idx, tsk->comm);
+	/* save cmdline only when task does not exist in savecmd */
+	if (savedcmd->map_cmdline_to_pid[idx] != tsk->pid) {
+		savedcmd->map_cmdline_to_pid[idx] = tsk->pid;
+		set_cmdline(idx, tsk->comm);
+	}
 
 	arch_spin_unlock(&trace_cmdline_lock);
 
-- 
2.30.GIT


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-15  1:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 11:50 [PATCH] tracing: save cmdline only when task does not exist in savecmd for optimization Yang Jihong
2021-10-14  3:02 ` Steven Rostedt
2021-10-14  8:09   ` Yang Jihong
2021-10-14 14:32 ` Steven Rostedt
2021-10-15  1:27   ` Yang Jihong

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®