Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] tracing: Ensure optimized hashing works
@ 2025-09-23 16:59 Michal Koutný
  2025-09-24  8:11 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Koutný @ 2025-09-23 16:59 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel
  Cc: Michal Koutný, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers

If ever PID_MAX_DEFAULT changes, it must be compatible with tracing
hashmaps assumptions.

Link: https://lore.kernel.org/r/20240409110126.651e94cb@gandalf.local.home/
Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/trace/trace_sched_switch.c | 2 ++
 1 file changed, 2 insertions(+)

Drive-by flushing an old idea. Take it or leave it.

diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
index cb49f7279dc80..aabae7daaac91 100644
--- a/kernel/trace/trace_sched_switch.c
+++ b/kernel/trace/trace_sched_switch.c
@@ -243,6 +243,8 @@ int trace_create_savedcmd(void)
 int trace_save_cmdline(struct task_struct *tsk)
 {
 	unsigned tpid, idx;
+	/* so that map_pid_to_cmdline indexing is efficient */
+	BUILD_BUG_ON(!is_power_of_2(PID_MAX_DEFAULT));
 
 	/* treat recording of idle task as a success */
 	if (!tsk->pid)
-- 
2.51.0


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

* Re: [PATCH] tracing: Ensure optimized hashing works
  2025-09-23 16:59 [PATCH] tracing: Ensure optimized hashing works Michal Koutný
@ 2025-09-24  8:11 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2025-09-24  8:11 UTC (permalink / raw)
  To: Michal Koutný
  Cc: linux-kernel, linux-trace-kernel, Masami Hiramatsu,
	Mathieu Desnoyers

On Tue, 23 Sep 2025 18:59:07 +0200
Michal Koutný <mkoutny@suse.com> wrote:

> If ever PID_MAX_DEFAULT changes, it must be compatible with tracing
> hashmaps assumptions.
> 
> Link: https://lore.kernel.org/r/20240409110126.651e94cb@gandalf.local.home/
> Signed-off-by: Michal Koutný <mkoutny@suse.com>
> ---
>  kernel/trace/trace_sched_switch.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> Drive-by flushing an old idea. Take it or leave it.
> 
> diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
> index cb49f7279dc80..aabae7daaac91 100644
> --- a/kernel/trace/trace_sched_switch.c
> +++ b/kernel/trace/trace_sched_switch.c
> @@ -243,6 +243,8 @@ int trace_create_savedcmd(void)
>  int trace_save_cmdline(struct task_struct *tsk)
>  {
>  	unsigned tpid, idx;
> +	/* so that map_pid_to_cmdline indexing is efficient */
> +	BUILD_BUG_ON(!is_power_of_2(PID_MAX_DEFAULT));

Please move this to just above the test. And it doesn't need a comment,
as it's obvious for why it needs to be a power of two when it's above
the test.

>  
>  	/* treat recording of idle task as a success */
>  	if (!tsk->pid)

Like this:

	/* treat recording of idle task as a success */
	if (!tsk->pid)
		return 1;

+	BUILD_BUG_ON(!is_power_of_2(PID_MAX_DEFAULT));
+
	tpid = tsk->pid & (PID_MAX_DEFAULT - 1);

-- Steve

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

end of thread, other threads:[~2025-09-24  8:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 16:59 [PATCH] tracing: Ensure optimized hashing works Michal Koutný
2025-09-24  8:11 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox