tracing: Move open coded processing of tgid_map into helper function
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 20 Feb 2024 14:06:15 +0000 (09:06 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Sun, 17 Mar 2024 11:58:52 +0000 (07:58 -0400)
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>
kernel/trace/trace.c

index 70202e60a60a387dffca46655b7a3df24509e0e0..d3e630dd36f87608f840d039eca6a7823124a8a7 100644 (file)
@@ -5453,10 +5453,31 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
        return 0;
 }
 
-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
+static int trace_alloc_tgid_map(void)
 {
        int *map;
 
+       if (tgid_map)
+               return 0;
+
+       tgid_map_max = pid_max;
+       map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map),
+                      GFP_KERNEL);
+       if (!map)
+               return -ENOMEM;
+
+       /*
+        * Pairs with smp_load_acquire() in
+        * trace_find_tgid_ptr() to ensure that if it observes
+        * the tgid_map we just allocated then it also observes
+        * the corresponding tgid_map_max value.
+        */
+       smp_store_release(&tgid_map, map);
+       return 0;
+}
+
+int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
+{
        if ((mask == TRACE_ITER_RECORD_TGID) ||
            (mask == TRACE_ITER_RECORD_CMD))
                lockdep_assert_held(&event_mutex);
@@ -5479,20 +5500,7 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
                trace_event_enable_cmd_record(enabled);
 
        if (mask == TRACE_ITER_RECORD_TGID) {
-               if (!tgid_map) {
-                       tgid_map_max = pid_max;
-                       map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map),
-                                      GFP_KERNEL);
-
-                       /*
-                        * Pairs with smp_load_acquire() in
-                        * trace_find_tgid_ptr() to ensure that if it observes
-                        * the tgid_map we just allocated then it also observes
-                        * the corresponding tgid_map_max value.
-                        */
-                       smp_store_release(&tgid_map, map);
-               }
-               if (!tgid_map) {
+               if (trace_alloc_tgid_map() < 0) {
                        tr->trace_flags &= ~TRACE_ITER_RECORD_TGID;
                        return -ENOMEM;
                }