From nobody Wed Dec 17 10:44:48 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10AFB292099 for ; Fri, 9 May 2025 13:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; cv=none; b=bY+xbXT4PmaMdf36Dyia1Db6pEdYTcu9DuHB4ObePNYw48kgMZuHwyHJLtn1289PVkfnHkhadjGzk69weZ9/jOADUI6jrvYZ8PceogTbHEL/jluDBbK0UviTtuEc551d+4nNCT1s2yqvE6OlTUm+WFCUmVKr9ocOvfnsT8cmDto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=aB5ChLg+sd/ahTtsLC+FEEEjtrIaTPRnuGFbw2aQwIw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Jn0BpHZgDR3SWX3QHqPps8IoRXPy1XqKjp/7Nb3uVuuWHnJ4MSVeocTvtW+8dtprvLbFpZXFq1EQYisuHpUvqyEsgYigTzDXK2fir1/tSsFwB/I7FVH3yjZfcLLeskZz/dsYB6m7PvMiM5aSlEur4uw3vX40vNQOpvVCe55xqpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63C21C4AF0B; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002brl-3t2b; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.779021770@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi Subject: [for-next][PATCH 08/31] tracing: Add common_comm to histograms References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt If one wants to trace the name of the task that wakes up a process and pass that to the synthetic events, there's nothing currently that lets the synthetic events do that. Add a "common_comm" to the histogram logic that allows histograms save the current->comm as a variable that can be passed through and added to a synthetic event: # cd /sys/kernel/tracing # echo 's:wake_lat char[] waker; char[] wakee; u64 delta;' >> dynamic_even= ts # echo 'hist:keys=3Dpid:comm=3Dcommon_comm:ts=3Dcommon_timestamp.usecs if = !(common_flags & 0x18)' > events/sched/sched_waking/trigger # echo 'hist:keys=3Dnext_pid:wake_comm=3D$comm:delta=3Dcommon_timestamp.us= ecs-$ts:onmatch(sched.sched_waking).trace(wake_lat,$wake_comm,next_comm,$de= lta)' > events/sched/sched_switch/trigger The above will create a synthetic trace event that will save both the name of the waker and the wakee but only if the wakeup did not happen in a hard or soft interrupt context. The "common_comm" is used to save the task->comm at the time of the initial event and is passed via the "comm" variable to the second event, and that is saved as the "waker" field in the "wake_lat" synthetic event. Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250407154912.3c6c6246@gandalf.local.home Acked-by: Masami Hiramatsu (Google) Reviewed-by: Tom Zanussi Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 51 ++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index e85bc59c0421..58c9535f61df 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -114,6 +114,7 @@ enum hist_field_fn { HIST_FIELD_FN_BUCKET, HIST_FIELD_FN_TIMESTAMP, HIST_FIELD_FN_CPU, + HIST_FIELD_FN_COMM, HIST_FIELD_FN_STRING, HIST_FIELD_FN_DYNSTRING, HIST_FIELD_FN_RELDYNSTRING, @@ -506,6 +507,7 @@ enum hist_field_flags { HIST_FIELD_FL_CONST =3D 1 << 18, HIST_FIELD_FL_PERCENT =3D 1 << 19, HIST_FIELD_FL_GRAPH =3D 1 << 20, + HIST_FIELD_FL_COMM =3D 1 << 21, }; =20 struct var_defs { @@ -885,6 +887,15 @@ static u64 hist_field_cpu(struct hist_field *hist_fiel= d, return cpu; } =20 +static u64 hist_field_comm(struct hist_field *hist_field, + struct tracing_map_elt *elt, + struct trace_buffer *buffer, + struct ring_buffer_event *rbe, + void *event) +{ + return (u64)(unsigned long)current->comm; +} + /** * check_field_for_var_ref - Check if a VAR_REF field references a variable * @hist_field: The VAR_REF field to check @@ -1338,6 +1349,8 @@ static const char *hist_field_name(struct hist_field = *field, field_name =3D hist_field_name(field->operands[0], ++level); else if (field->flags & HIST_FIELD_FL_CPU) field_name =3D "common_cpu"; + else if (field->flags & HIST_FIELD_FL_COMM) + field_name =3D "common_comm"; else if (field->flags & HIST_FIELD_FL_EXPR || field->flags & HIST_FIELD_FL_VAR_REF) { if (field->system) { @@ -2015,6 +2028,13 @@ static struct hist_field *create_hist_field(struct h= ist_trigger_data *hist_data, goto out; } =20 + if (flags & HIST_FIELD_FL_COMM) { + hist_field->fn_num =3D HIST_FIELD_FN_COMM; + hist_field->size =3D MAX_FILTER_STR_VAL; + hist_field->type =3D "char[]"; + goto out; + } + if (WARN_ON_ONCE(!field)) goto out; =20 @@ -2359,9 +2379,11 @@ parse_field(struct hist_trigger_data *hist_data, str= uct trace_event_file *file, hist_data->attrs->ts_in_usecs =3D true; } else if (strcmp(field_name, "common_stacktrace") =3D=3D 0) { *flags |=3D HIST_FIELD_FL_STACKTRACE; - } else if (strcmp(field_name, "common_cpu") =3D=3D 0) + } else if (strcmp(field_name, "common_cpu") =3D=3D 0) { *flags |=3D HIST_FIELD_FL_CPU; - else if (strcmp(field_name, "hitcount") =3D=3D 0) + } else if (strcmp(field_name, "common_comm") =3D=3D 0) { + *flags |=3D HIST_FIELD_FL_COMM | HIST_FIELD_FL_STRING; + } else if (strcmp(field_name, "hitcount") =3D=3D 0) *flags |=3D HIST_FIELD_FL_HITCOUNT; else { field =3D trace_find_event_field(file->event_call, field_name); @@ -2377,6 +2399,8 @@ parse_field(struct hist_trigger_data *hist_data, stru= ct trace_event_file *file, *flags |=3D HIST_FIELD_FL_CPU; } else if (field && field->filter_type =3D=3D FILTER_STACKTRACE) { *flags |=3D HIST_FIELD_FL_STACKTRACE; + } else if (field && field->filter_type =3D=3D FILTER_COMM) { + *flags |=3D HIST_FIELD_FL_COMM | HIST_FIELD_FL_STRING; } else { hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, errpos(field_name)); @@ -4327,6 +4351,8 @@ static u64 hist_fn_call(struct hist_field *hist_field, return hist_field_timestamp(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_CPU: return hist_field_cpu(hist_field, elt, buffer, rbe, event); + case HIST_FIELD_FN_COMM: + return hist_field_comm(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_STRING: return hist_field_string(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_DYNSTRING: @@ -5212,14 +5238,19 @@ static inline void add_to_key(char *compound_key, v= oid *key, size_t size =3D key_field->size; =20 if (key_field->flags & HIST_FIELD_FL_STRING) { - struct ftrace_event_field *field; =20 - field =3D key_field->field; - if (field->filter_type =3D=3D FILTER_DYN_STRING || - field->filter_type =3D=3D FILTER_RDYN_STRING) - size =3D *(u32 *)(rec + field->offset) >> 16; - else if (field->filter_type =3D=3D FILTER_STATIC_STRING) - size =3D field->size; + if (key_field->flags & HIST_FIELD_FL_COMM) { + size =3D strlen((char *)key); + } else { + struct ftrace_event_field *field; + + field =3D key_field->field; + if (field->filter_type =3D=3D FILTER_DYN_STRING || + field->filter_type =3D=3D FILTER_RDYN_STRING) + size =3D *(u32 *)(rec + field->offset) >> 16; + else if (field->filter_type =3D=3D FILTER_STATIC_STRING) + size =3D field->size; + } =20 /* ensure NULL-termination */ if (size > key_field->size - 1) @@ -6097,6 +6128,8 @@ static void hist_field_print(struct seq_file *m, stru= ct hist_field *hist_field) =20 if (hist_field->flags & HIST_FIELD_FL_CPU) seq_puts(m, "common_cpu"); + if (hist_field->flags & HIST_FIELD_FL_COMM) + seq_puts(m, "common_comm"); else if (hist_field->flags & HIST_FIELD_FL_CONST) seq_printf(m, "%llu", hist_field->constant); else if (field_name) { --=20 2.47.2