Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp582556pxv; Thu, 22 Jul 2021 07:29:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR3s+utKqEc/p9rgtiput1LUyGO4vWUUC/WQlEeptECaiQTBvKPvm6G2Cugk6cVSekiNg4 X-Received: by 2002:a92:d112:: with SMTP id a18mr95300ilb.67.1626964181389; Thu, 22 Jul 2021 07:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626964181; cv=none; d=google.com; s=arc-20160816; b=JZ/QNMIRRiNFGqiF/ZTsSC/bCBloR841pNQD1LigQqIOKQ6XcxJe5+V997jjhXJVo9 +XJUIDym1IPyEhvDJU8w8AYGpfaKy6m8L1jDt0jEm82RETUVPSqkYoSuXIdkfL+vNHCt cB0WzkQo8r8d7VcTWXz1AJf0bZpOjj6uF2WxmzJiPSOVup3BqP7R/jWeXs8u5LHmVz6B oToaU1OigumZPSLen3vLJLG4AuN9gxFHoKIA3zx079VnguDPIq2W5SGY4c89eT277+5K rVvly5gmljmsHqAuEtrTvtfYNWc+Nu4RjxxKEEdYQawCq2hkKh1zT0HFCBrBSuJVRYu0 TTRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=SOlmM3Hu6pyx6kGzOMMFTbSKs9KAf3Vczo4VmQd+CEc=; b=ftx5QTZ670b3apng1BbjAJ4GMBSJV5fryGv6AfOBQqTpWhtsjhj4EvyQGPCEijM8FB acFjJXj3kLnLqG+Ua1UzdUQBQULm26oB40oLGRyrouXwO4tDVTGJu/lw8lxCZ//vfr1o J6NEFz1i4Z0cl26UNUeJmWQ5KX/fqLUT4+p53EK8VSHQboBIAtNfnF7E7cYRvJvnVYH4 e77L8HXeceq2kZYxpWP0ZXR3i/W1J987CfD+eao92qEJrBuMwk97jk21e7prhIIeDxZ7 Ulb5JjvriYxiwgXi5QyfZduCmJd1ai6YQKoymFZ+11FDNHvYPRMIylu5DdWWYhvFbOA0 ng5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j1si20866797jak.102.2021.07.22.07.29.29; Thu, 22 Jul 2021 07:29:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbhGVNsG (ORCPT + 99 others); Thu, 22 Jul 2021 09:48:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:44566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbhGVNsD (ORCPT ); Thu, 22 Jul 2021 09:48:03 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A1D5D6101E; Thu, 22 Jul 2021 14:28:38 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1m6Zgj-001bCF-K4; Thu, 22 Jul 2021 10:28:37 -0400 Message-ID: <20210722142837.458596338@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 22 Jul 2021 10:27:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Andrew Morton , Tom Zanussi , Masami Hiramatsu , Namhyung Kim Subject: [PATCH v2 2/2] tracing: Allow execnames to be passed as args for synthetic events References: <20210722142705.992001628@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" Allow common_pid.execname to be saved in a variable in one histogram to be passed to another histogram that can pass it as a parameter to a synthetic event. ># echo 'hist:keys=pid:__arg__1=common_timestamp.usecs:arg2=common_pid.execname' \ > events/sched/sched_waking/trigger ># echo 'wakeup_lat s32 pid; u64 delta; char wake_comm[]' > synthetic_events ># echo 'hist:keys=next_pid:pid=next_pid,delta=common_timestamp.usecs-$__arg__1,exec=$arg2'\ ':onmatch(sched.sched_waking).trace(wakeup_lat,$pid,$delta,$exec)' \ > events/sched/sched_switch/trigger The above is a wake up latency synthetic event setup that passes the execname of the common_pid that woke the task to the scheduling of that task, which triggers a synthetic event that passes the original execname as a parameter to display it. ># echo 1 > events/synthetic/enable ># cat trace -0 [006] d..4 186.863801: wakeup_lat: pid=1306 delta=65 wake_comm=kworker/u16:3 -0 [000] d..4 186.863858: wakeup_lat: pid=163 delta=27 wake_comm= -0 [001] d..4 186.863903: wakeup_lat: pid=1307 delta=36 wake_comm=kworker/u16:4 -0 [000] d..4 186.863927: wakeup_lat: pid=163 delta=5 wake_comm= -0 [006] d..4 186.863957: wakeup_lat: pid=1306 delta=24 wake_comm=kworker/u16:3 sshd-1306 [006] d..4 186.864051: wakeup_lat: pid=61 delta=62 wake_comm= -0 [000] d..4 186.965030: wakeup_lat: pid=609 delta=18 wake_comm= -0 [006] d..4 186.987582: wakeup_lat: pid=1306 delta=65 wake_comm=kworker/u16:3 -0 [000] d..4 186.987639: wakeup_lat: pid=163 delta=27 wake_comm= Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/trace_events_hist.c | 46 +++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 5c9082201bc2..14b840de1326 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1395,17 +1395,17 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt) struct hist_trigger_data *hist_data = elt->map->private_data; unsigned int size = TASK_COMM_LEN; struct hist_elt_data *elt_data; - struct hist_field *key_field; + struct hist_field *hist_field; unsigned int i, n_str; elt_data = kzalloc(sizeof(*elt_data), GFP_KERNEL); if (!elt_data) return -ENOMEM; - for_each_hist_key_field(i, hist_data) { - key_field = hist_data->fields[i]; + for_each_hist_field(i, hist_data) { + hist_field = hist_data->fields[i]; - if (key_field->flags & HIST_FIELD_FL_EXECNAME) { + if (hist_field->flags & HIST_FIELD_FL_EXECNAME) { elt_data->comm = kzalloc(size, GFP_KERNEL); if (!elt_data->comm) { kfree(elt_data); @@ -3703,6 +3703,41 @@ static int create_val_field(struct hist_trigger_data *hist_data, return __create_val_field(hist_data, val_idx, file, NULL, field_str, 0); } +static const char *no_comm = "(no comm)"; + +static u64 hist_field_execname(struct hist_field *hist_field, + struct tracing_map_elt *elt, + struct trace_buffer *buffer, + struct ring_buffer_event *rbe, + void *event) +{ + struct hist_elt_data *elt_data; + + if (WARN_ON_ONCE(!elt)) + return (u64)(unsigned long)no_comm; + + elt_data = elt->private_data; + + if (WARN_ON_ONCE(!elt_data->comm)) + return (u64)(unsigned long)no_comm; + + return (u64)(unsigned long)(elt_data->comm); +} + +/* Convert a var that points to common_pid.execname to a string */ +static void update_var_execname(struct hist_field *hist_field) +{ + hist_field->flags = HIST_FIELD_FL_STRING | HIST_FIELD_FL_VAR | + HIST_FIELD_FL_EXECNAME; + hist_field->size = MAX_FILTER_STR_VAL; + hist_field->is_signed = 0; + + kfree_const(hist_field->type); + hist_field->type = "char[]"; + + hist_field->fn = hist_field_execname; +} + static int create_var_field(struct hist_trigger_data *hist_data, unsigned int val_idx, struct trace_event_file *file, @@ -3727,6 +3762,9 @@ static int create_var_field(struct hist_trigger_data *hist_data, ret = __create_val_field(hist_data, val_idx, file, var_name, expr_str, flags); + if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_EXECNAME) + update_var_execname(hist_data->fields[val_idx]); + if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_STRING) hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++; -- 2.30.2