Received: by 10.223.164.202 with SMTP id h10csp1606140wrb; Sat, 18 Nov 2017 02:29:12 -0800 (PST) X-Google-Smtp-Source: AGs4zMbwceUwZ5EHeBrferh3sQBiIq6ziOG21/YIp/IvGtbzoa7AdRWSrrruki+DxOai1LwvHtQ8 X-Received: by 10.99.175.7 with SMTP id w7mr7950820pge.11.1511000952179; Sat, 18 Nov 2017 02:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511000952; cv=none; d=google.com; s=arc-20160816; b=00apRHIf44mCJoxcWXDYLlxvicZD0/UHOWxV/RnrUwQpLE4rciin/cOh3R90wkGd/T B67PYwRgzetB2oKE2G4Vrz1WXy1hDdUg3KQaSZ9lV/YpxPw3pLi/V55+Y3555YviTrgb pcVic5XiSR21Tt5kT9XwsPPN6X12sFD8AYpmumKWVG4F+fp36aUVb/DZUSMHdqsb3d+v FYJUTfHQK7wLk1k9YtdLMZE0Xi1vY9dprfHYYvS1+KyN3xWFs8AJVhOnb94JKO+ObD2t 7giGOslhxU3O0cfB39pqyId3rtq+4FpOqUOwGt1NHIizKzQ8inZZqaxMw9ngZJKbj5PH vOHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kM/kAbiPN6cdH5cSWUxkLrPP1PKOusaD9VmpI2XE+3c=; b=So0J4N947M+fAkPy7CtGq6ShBNAE83UwGg9zh8BaFjcXgt/VXRSVegDpKtCk8DkHYJ 1scQzNBDy3mBgrW7g+5nX1ey7QPKE3qRCS/XXUyVzcebDaspl8h7YWPGh/fvH1FBt8js YM0rfIJs8Rkjwu+mau10qEBdQLjhUWmXNwUa471B5XUOscJaCxqh9RYF7U+qxiWh1zZb 36sZBCTXB6ewznBBemafjKOKIJtAzcaqQeO3vAE06fHFcKZFONpx/mzTX/XlKQY5vyZy fBRvCrRsXkt/g+AA6Hbbfzt3aKz3+InTMwoaGS29/7NsWB3d6MpUBChTBENLNovGLmrR TgDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si2656010plt.5.2017.11.18.02.28.59; Sat, 18 Nov 2017 02:29:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422732AbdKQUfz (ORCPT + 93 others); Fri, 17 Nov 2017 15:35:55 -0500 Received: from mga01.intel.com ([192.55.52.88]:58582 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936057AbdKQUfm (ORCPT ); Fri, 17 Nov 2017 15:35:42 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Nov 2017 12:35:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,411,1505804400"; d="scan'208";a="1245396663" Received: from mjglynn-mobl.ger.corp.intel.com (HELO localhost) ([10.254.124.112]) by fmsmga002.fm.intel.com with ESMTP; 17 Nov 2017 12:35:39 -0800 From: Tom Zanussi To: rostedt@goodmis.org Cc: tglx@linutronix.de, mhiramat@kernel.org, namhyung@kernel.org, vedang.patel@intel.com, bigeasy@linutronix.de, joel.opensrc@gmail.com, joelaf@google.com, mathieu.desnoyers@efficios.com, baohong.liu@intel.com, rajvi.jingar@intel.com, julia@ni.com, fengguang.wu@intel.com, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Tom Zanussi Subject: [PATCH v6 30/37] tracing: Add hist trigger support for variable reference aliases Date: Fri, 17 Nov 2017 14:33:09 -0600 Message-Id: <8ce0f1a90c683dec3ab71ec608ca8fa44ede4fc1.1510948725.git.tom.zanussi@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for alias=$somevar where alias can be used as onmatch.xxx($alias). Aliases are a way of creating a new name for an existing variable, for flexibly in making naming more clear in certain cases. For example in the below the user perhaps feels that using $new_lat in the synthetic event invocation is opaque or doesn't fit well stylistically with previous triggers, so creates an alias of $new_lat named $latency and uses that in the call instead: # echo 'hist:keys=next_pid:new_lat=$common_timestamp.usecs' > /sys/kernel/debug/tracing/events/sched/sched_switch/trigger # echo 'hist:keys=pid:latency=$new_lat: onmatch(sched.sched_switch).wake2($latency,pid)' > /sys/kernel/debug/tracing/events/synthetic/wake1/trigger Signed-off-by: Tom Zanussi --- kernel/trace/trace_events_hist.c | 58 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index afbfa9c..0336f03 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -228,6 +228,7 @@ enum hist_field_flags { HIST_FIELD_FL_EXPR = 1 << 13, HIST_FIELD_FL_VAR_REF = 1 << 14, HIST_FIELD_FL_CPU = 1 << 15, + HIST_FIELD_FL_ALIAS = 1 << 16, }; struct var_defs { @@ -1629,7 +1630,8 @@ static const char *hist_field_name(struct hist_field *field, if (field->field) field_name = field->field->name; - else if (field->flags & HIST_FIELD_FL_LOG2) + else if (field->flags & HIST_FIELD_FL_LOG2 || + field->flags & HIST_FIELD_FL_ALIAS) field_name = hist_field_name(field->operands[0], ++level); else if (field->flags & HIST_FIELD_FL_TIMESTAMP) field_name = "$common_timestamp"; @@ -2096,7 +2098,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data, hist_field->hist_data = hist_data; - if (flags & HIST_FIELD_FL_EXPR) + if (flags & HIST_FIELD_FL_EXPR || flags & HIST_FIELD_FL_ALIAS) goto out; /* caller will populate */ if (flags & HIST_FIELD_FL_VAR_REF) { @@ -2380,6 +2382,28 @@ static struct hist_field *parse_var_ref(struct hist_trigger_data *hist_data, return field; } +static struct hist_field *create_alias(struct hist_trigger_data *hist_data, + struct hist_field *var_ref, + char *var_name) +{ + struct hist_field *alias = NULL; + unsigned long flags = HIST_FIELD_FL_ALIAS | HIST_FIELD_FL_VAR; + + alias = create_hist_field(hist_data, NULL, flags, var_name); + if (!alias) + return NULL; + + alias->fn = var_ref->fn; + alias->operands[0] = var_ref; + + if (init_var_ref(alias, var_ref, var_ref->system, var_ref->event_name)) { + destroy_hist_field(alias, 0); + return NULL; + } + + return alias; +} + struct hist_field *parse_atom(struct hist_trigger_data *hist_data, struct trace_event_file *file, char *str, unsigned long *flags, char *var_name) @@ -2413,6 +2437,13 @@ struct hist_field *parse_atom(struct hist_trigger_data *hist_data, if (hist_field) { hist_data->var_refs[hist_data->n_var_refs] = hist_field; hist_field->var_ref_idx = hist_data->n_var_refs++; + if (var_name) { + hist_field = create_alias(hist_data, hist_field, var_name); + if (!hist_field) { + ret = -ENOMEM; + goto out; + } + } return hist_field; } } else @@ -2517,6 +2548,26 @@ static int check_expr_operands(struct hist_field *operand1, unsigned long operand1_flags = operand1->flags; unsigned long operand2_flags = operand2->flags; + if ((operand1_flags & HIST_FIELD_FL_VAR_REF) || + (operand1_flags & HIST_FIELD_FL_ALIAS)) { + struct hist_field *var; + + var = find_var_field(operand1->var.hist_data, operand1->name); + if (!var) + return -EINVAL; + operand1_flags = var->flags; + } + + if ((operand2_flags & HIST_FIELD_FL_VAR_REF) || + (operand2_flags & HIST_FIELD_FL_ALIAS)) { + struct hist_field *var; + + var = find_var_field(operand2->var.hist_data, operand2->name); + if (!var) + return -EINVAL; + operand2_flags = var->flags; + } + if ((operand1_flags & HIST_FIELD_FL_TIMESTAMP_USECS) != (operand2_flags & HIST_FIELD_FL_TIMESTAMP_USECS)) return -EINVAL; @@ -4639,7 +4690,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) else if (hist_field->flags & HIST_FIELD_FL_CPU) seq_puts(m, "cpu"); else if (field_name) { - if (hist_field->flags & HIST_FIELD_FL_VAR_REF) + if (hist_field->flags & HIST_FIELD_FL_VAR_REF || + hist_field->flags & HIST_FIELD_FL_ALIAS) seq_putc(m, '$'); seq_printf(m, "%s", field_name); } -- 1.9.3 From 1584466888653811504@xxx Sun Nov 19 04:22:56 +0000 2017 X-GM-THRID: 1584466888653811504 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread