Skip to content

Commit 155fd6c

Browse files
committed
tracing/sched: Use __string() instead of fixed lengths for task->comm
The sched_switch and sched_waking events hardcoded the length of the comm it recorded because these events were created before the dynamic strings were implemented. Unfortunately, several other events copied this method. As the size of the comm may change in the future, make the string dynamic. The dynamic string requires a 4 byte meta data to hold the size and offset of the string. The amount stored in the ring buffer will then be the strlen(comm) + 5 (for the \n), and aligned to 4 bytes if there's no other strings. This means that a task comm can have up to 10 characters before it requires another 4 bytes in the ring buffer. Most tasks are usually less than that, so this should not be a problem, and it also allows the name to be extended over the TASK_COMM_LEN [1] Note, sched_switch and the sched_waking trace events still hardcode the length, as there is tooling that still requires that. An effort to update the tooling will be made to allow this to change in the future. [1] https://lore.kernel.org/all/20250507110444.963779-1-bhupesh@igalia.com/ Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Bhupesh <bhupesh@igalia.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Juri Lelli <juri.lelli@redhat.com> Link: https://lore.kernel.org/20250507133458.51bafd95@gandalf.local.home Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ac01fa7 commit 155fd6c

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

include/trace/events/sched.h

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ TRACE_EVENT(sched_kthread_stop,
2020
TP_ARGS(t),
2121

2222
TP_STRUCT__entry(
23-
__array( char, comm, TASK_COMM_LEN )
24-
__field( pid_t, pid )
23+
__string( comm, t->comm )
24+
__field( pid_t, pid )
2525
),
2626

2727
TP_fast_assign(
28-
memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
28+
__assign_str(comm);
2929
__entry->pid = t->pid;
3030
),
3131

32-
TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
32+
TP_printk("comm=%s pid=%d", __get_str(comm), __entry->pid)
3333
);
3434

3535
/*
@@ -276,23 +276,23 @@ TRACE_EVENT(sched_migrate_task,
276276
TP_ARGS(p, dest_cpu),
277277

278278
TP_STRUCT__entry(
279-
__array( char, comm, TASK_COMM_LEN )
280-
__field( pid_t, pid )
281-
__field( int, prio )
282-
__field( int, orig_cpu )
283-
__field( int, dest_cpu )
279+
__string( comm, p->comm )
280+
__field( pid_t, pid )
281+
__field( int, prio )
282+
__field( int, orig_cpu )
283+
__field( int, dest_cpu )
284284
),
285285

286286
TP_fast_assign(
287-
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
287+
__assign_str(comm);
288288
__entry->pid = p->pid;
289289
__entry->prio = p->prio; /* XXX SCHED_DEADLINE */
290290
__entry->orig_cpu = task_cpu(p);
291291
__entry->dest_cpu = dest_cpu;
292292
),
293293

294294
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
295-
__entry->comm, __entry->pid, __entry->prio,
295+
__get_str(comm), __entry->pid, __entry->prio,
296296
__entry->orig_cpu, __entry->dest_cpu)
297297
);
298298

@@ -303,19 +303,19 @@ DECLARE_EVENT_CLASS(sched_process_template,
303303
TP_ARGS(p),
304304

305305
TP_STRUCT__entry(
306-
__array( char, comm, TASK_COMM_LEN )
307-
__field( pid_t, pid )
308-
__field( int, prio )
306+
__string( comm, p->comm )
307+
__field( pid_t, pid )
308+
__field( int, prio )
309309
),
310310

311311
TP_fast_assign(
312-
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
312+
__assign_str(comm);
313313
__entry->pid = p->pid;
314314
__entry->prio = p->prio; /* XXX SCHED_DEADLINE */
315315
),
316316

317317
TP_printk("comm=%s pid=%d prio=%d",
318-
__entry->comm, __entry->pid, __entry->prio)
318+
__get_str(comm), __entry->pid, __entry->prio)
319319
);
320320

321321
/*
@@ -349,19 +349,19 @@ TRACE_EVENT(sched_process_wait,
349349
TP_ARGS(pid),
350350

351351
TP_STRUCT__entry(
352-
__array( char, comm, TASK_COMM_LEN )
352+
__string( comm, current->comm )
353353
__field( pid_t, pid )
354354
__field( int, prio )
355355
),
356356

357357
TP_fast_assign(
358-
memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
358+
__assign_str(comm);
359359
__entry->pid = pid_nr(pid);
360360
__entry->prio = current->prio; /* XXX SCHED_DEADLINE */
361361
),
362362

363363
TP_printk("comm=%s pid=%d prio=%d",
364-
__entry->comm, __entry->pid, __entry->prio)
364+
__get_str(comm), __entry->pid, __entry->prio)
365365
);
366366

367367
/*
@@ -374,22 +374,22 @@ TRACE_EVENT(sched_process_fork,
374374
TP_ARGS(parent, child),
375375

376376
TP_STRUCT__entry(
377-
__array( char, parent_comm, TASK_COMM_LEN )
378-
__field( pid_t, parent_pid )
379-
__array( char, child_comm, TASK_COMM_LEN )
380-
__field( pid_t, child_pid )
377+
__string( parent_comm, parent->comm )
378+
__field( pid_t, parent_pid )
379+
__string( child_comm, child->comm )
380+
__field( pid_t, child_pid )
381381
),
382382

383383
TP_fast_assign(
384-
memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
384+
__assign_str(parent_comm);
385385
__entry->parent_pid = parent->pid;
386-
memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
386+
__assign_str(child_comm);
387387
__entry->child_pid = child->pid;
388388
),
389389

390390
TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
391-
__entry->parent_comm, __entry->parent_pid,
392-
__entry->child_comm, __entry->child_pid)
391+
__get_str(parent_comm), __entry->parent_pid,
392+
__get_str(child_comm), __entry->child_pid)
393393
);
394394

395395
/*
@@ -473,19 +473,19 @@ DECLARE_EVENT_CLASS_SCHEDSTAT(sched_stat_template,
473473
TP_ARGS(__perf_task(tsk), __perf_count(delay)),
474474

475475
TP_STRUCT__entry(
476-
__array( char, comm, TASK_COMM_LEN )
477-
__field( pid_t, pid )
478-
__field( u64, delay )
476+
__string( comm, tsk->comm )
477+
__field( pid_t, pid )
478+
__field( u64, delay )
479479
),
480480

481481
TP_fast_assign(
482-
memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
482+
__assign_str(comm);
483483
__entry->pid = tsk->pid;
484484
__entry->delay = delay;
485485
),
486486

487487
TP_printk("comm=%s pid=%d delay=%Lu [ns]",
488-
__entry->comm, __entry->pid,
488+
__get_str(comm), __entry->pid,
489489
(unsigned long long)__entry->delay)
490490
);
491491

@@ -531,19 +531,19 @@ DECLARE_EVENT_CLASS(sched_stat_runtime,
531531
TP_ARGS(tsk, __perf_count(runtime)),
532532

533533
TP_STRUCT__entry(
534-
__array( char, comm, TASK_COMM_LEN )
535-
__field( pid_t, pid )
536-
__field( u64, runtime )
534+
__string( comm, tsk->comm )
535+
__field( pid_t, pid )
536+
__field( u64, runtime )
537537
),
538538

539539
TP_fast_assign(
540-
memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
540+
__assign_str(comm);
541541
__entry->pid = tsk->pid;
542542
__entry->runtime = runtime;
543543
),
544544

545545
TP_printk("comm=%s pid=%d runtime=%Lu [ns]",
546-
__entry->comm, __entry->pid,
546+
__get_str(comm), __entry->pid,
547547
(unsigned long long)__entry->runtime)
548548
);
549549

@@ -562,14 +562,14 @@ TRACE_EVENT(sched_pi_setprio,
562562
TP_ARGS(tsk, pi_task),
563563

564564
TP_STRUCT__entry(
565-
__array( char, comm, TASK_COMM_LEN )
566-
__field( pid_t, pid )
567-
__field( int, oldprio )
568-
__field( int, newprio )
565+
__string( comm, tsk->comm )
566+
__field( pid_t, pid )
567+
__field( int, oldprio )
568+
__field( int, newprio )
569569
),
570570

571571
TP_fast_assign(
572-
memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
572+
__assign_str(comm);
573573
__entry->pid = tsk->pid;
574574
__entry->oldprio = tsk->prio;
575575
__entry->newprio = pi_task ?
@@ -579,7 +579,7 @@ TRACE_EVENT(sched_pi_setprio,
579579
),
580580

581581
TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
582-
__entry->comm, __entry->pid,
582+
__get_str(comm), __entry->pid,
583583
__entry->oldprio, __entry->newprio)
584584
);
585585

@@ -589,16 +589,16 @@ TRACE_EVENT(sched_process_hang,
589589
TP_ARGS(tsk),
590590

591591
TP_STRUCT__entry(
592-
__array( char, comm, TASK_COMM_LEN )
593-
__field( pid_t, pid )
592+
__string( comm, tsk->comm )
593+
__field( pid_t, pid )
594594
),
595595

596596
TP_fast_assign(
597-
memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
597+
__assign_str(comm);
598598
__entry->pid = tsk->pid;
599599
),
600600

601-
TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
601+
TP_printk("comm=%s pid=%d", __get_str(comm), __entry->pid)
602602
);
603603
#endif /* CONFIG_DETECT_HUNG_TASK */
604604

0 commit comments

Comments
 (0)