Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Move open coded processing of tgid_map into helper function

In preparation of moving the saved_cmdlines logic out of trace.c and into
trace_sched_switch.c, replace the open coded manipulation of tgid_map in
set_tracer_flag() into a helper function trace_alloc_tgid_map() so that it
can be easily moved into trace_sched_switch.c without changing existing
functions in trace.c.

No functional changes.

Link: https://lore.kernel.org/linux-trace-kernel/20240220140703.338116216@goodmis.org

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Vincent Donnefort <vdonnefort@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Mete Durlu <meted@linux.ibm.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+23 -15
+23 -15
kernel/trace/trace.c
··· 5453 5453 return 0; 5454 5454 } 5455 5455 5456 - int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) 5456 + static int trace_alloc_tgid_map(void) 5457 5457 { 5458 5458 int *map; 5459 5459 5460 + if (tgid_map) 5461 + return 0; 5462 + 5463 + tgid_map_max = pid_max; 5464 + map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map), 5465 + GFP_KERNEL); 5466 + if (!map) 5467 + return -ENOMEM; 5468 + 5469 + /* 5470 + * Pairs with smp_load_acquire() in 5471 + * trace_find_tgid_ptr() to ensure that if it observes 5472 + * the tgid_map we just allocated then it also observes 5473 + * the corresponding tgid_map_max value. 5474 + */ 5475 + smp_store_release(&tgid_map, map); 5476 + return 0; 5477 + } 5478 + 5479 + int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) 5480 + { 5460 5481 if ((mask == TRACE_ITER_RECORD_TGID) || 5461 5482 (mask == TRACE_ITER_RECORD_CMD)) 5462 5483 lockdep_assert_held(&event_mutex); ··· 5500 5479 trace_event_enable_cmd_record(enabled); 5501 5480 5502 5481 if (mask == TRACE_ITER_RECORD_TGID) { 5503 - if (!tgid_map) { 5504 - tgid_map_max = pid_max; 5505 - map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map), 5506 - GFP_KERNEL); 5507 - 5508 - /* 5509 - * Pairs with smp_load_acquire() in 5510 - * trace_find_tgid_ptr() to ensure that if it observes 5511 - * the tgid_map we just allocated then it also observes 5512 - * the corresponding tgid_map_max value. 5513 - */ 5514 - smp_store_release(&tgid_map, map); 5515 - } 5516 - if (!tgid_map) { 5482 + if (trace_alloc_tgid_map() < 0) { 5517 5483 tr->trace_flags &= ~TRACE_ITER_RECORD_TGID; 5518 5484 return -ENOMEM; 5519 5485 }