From patchwork Wed Aug 29 12:17:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" X-Patchwork-Id: 10580187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65C70174A for ; Wed, 29 Aug 2018 12:40:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54F8F2AFF8 for ; Wed, 29 Aug 2018 12:40:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C3C2B002; Wed, 29 Aug 2018 12:40:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D92C2AFF8 for ; Wed, 29 Aug 2018 12:40:06 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2D914D06; Wed, 29 Aug 2018 12:36:44 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 23E13D18 for ; Wed, 29 Aug 2018 12:36:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx04.melco.co.jp (mx04.melco.co.jp [192.218.140.144]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E819F786 for ; Wed, 29 Aug 2018 12:36:37 +0000 (UTC) Received: from mr04.melco.co.jp (mr04 [133.141.98.166]) by mx04.melco.co.jp (Postfix) with ESMTP id 231E83A32B3 for ; Wed, 29 Aug 2018 21:18:04 +0900 (JST) Received: from mr04.melco.co.jp (unknown [127.0.0.1]) by mr04.imss (Postfix) with ESMTP id 420l580wPmzRk8j for ; Wed, 29 Aug 2018 21:18:04 +0900 (JST) Received: from mf04_second.melco.co.jp (unknown [192.168.20.184]) by mr04.melco.co.jp (Postfix) with ESMTP id 420l580cYMzRjwX for ; Wed, 29 Aug 2018 21:18:04 +0900 (JST) Received: from mf04.melco.co.jp (unknown [133.141.98.184]) by mf04_second.melco.co.jp (Postfix) with ESMTP id 420l580bQ4zRkCw for ; Wed, 29 Aug 2018 21:18:04 +0900 (JST) Received: from JPN01-TY1-obe.outbound.protection.outlook.com (unknown [23.103.139.176]) by mf04.melco.co.jp (Postfix) with ESMTP id 420l580Qc9zRkCn for ; Wed, 29 Aug 2018 21:18:04 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mitsubishielectricgroup.onmicrosoft.com; s=selector1-mitsubishielectricgroup-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WaRE2cdQaet/ljkYCxVCC6TWeM5PxlULnA+L0tDyGZU=; b=BX1dRnfsJk1fL2CQvFcDeI3vswbH9Wdd7ItGtRh/c0jidX8lrqfkaHxGrlZYHQYoUAoYkjyaTETkq6iTTDzcJM8DxFNNkCkldVMYqVTzXMmRnRwpAM/9kn4nzZfir308W2oEWeAFO5SGHgJEHVKeOjbFQw64WBBsY33fhKg0Z+Q= Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com (52.133.160.145) by TY1PR01MB0762.jpnprd01.prod.outlook.com (10.167.158.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.15; Wed, 29 Aug 2018 12:18:03 +0000 Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa]) by TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa%2]) with mapi id 15.20.1080.015; Wed, 29 Aug 2018 12:18:03 +0000 From: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" To: "ltsi-dev@lists.linuxfoundation.org" Thread-Topic: [LTSI-dev] [PATCH 36/54] tracing: Add hist trigger support for variable reference aliases Thread-Index: AdQ/jJ3hvP7O5EHLQB2nffRKmPoUkg== Date: Wed, 29 Aug 2018 12:17:10 +0000 Deferred-Delivery: Wed, 29 Aug 2018 12:15:00 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-melpop: 1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=Motai.Hirotaka@aj.MitsubishiElectric.co.jp; x-originating-ip: [153.231.200.201] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; TY1PR01MB0762; 6:ABHsqwN4GiaBLGAqsh95RloLiIF6tTyt0OGuSkaD03jckzpk6q73hYWlRFZmY+PPqzMpR463l/PIUrIBvvwCYJy673j9QylUHQbEE5lEmhX6yqk6bZVLpUi8deVCWMFt1gMyqrTlSSz1Kb5fNNwVX8QEL385N6vAxOWhVzotgHfLCIS6FNdrAi5til0tWmnXv/XaOK+vbyaRNqR4MD3tS9HTLMDxQb3FBcEJciuhsQINFTlNBCetw2Xz6MFqTEa089vBef+WZxCbdZy7ZWVI+3SfMlH9rT3VGCaF3YhgnQ6UCKP4xuSBoI/SfCAc0d408pfNZIZDk6MBtten1bCRioRvhdQWFCX0ezAnPJz+a/rD4IaBPDLvtV3FN0SLZO6lvEneAGHycN42hJlZJl8Edyzmj77SIjLI4XW+mhnpZA1eAqATvWz/59YwZ+qZo7m/6jTKAnO70agYB8jfpOdTlQ==; 5:0dQwQ6nA2OJ7FAUXFdqXLgTRewiLZSva4RnsYmB3N3gE6JaCW0JMJw+HQT1ys6AGC+jg8ctdQjU/fwfFTIUDNVlyYoOkw5AzToDudprtvKlbrfu8gsbsAF3BfVrCIv2DIn9W2Z2SeSKdwX5LxFNXjFSfKMnl/GXAtO14aJ5NWj0=; 7:gOQCaRM8to8fYxgJToLdQyXvLogX5T4REpVQ+yuJe/HEnFQdSQAP2n+XWfXhzc4wWHwUPh0amLx1jfTrp6mhr1H0aQ6QyVhMOJ7D2ogUSHTzULQ47QnrTLvJ/JctslatfWcfHc3P5pReNXz65a/drhd3orwHgsOSovo+sWrCfP7nZaLIYIBfu6+apRSEIMcXHPqE4sVbN1GiX6LBTHRaqx/k/yhQW7qrELwRQjtxhhued+7mGaGE9IWtWIO4edWq x-ms-office365-filtering-correlation-id: 1862957e-7f69-469c-91cf-08d60da97805 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:TY1PR01MB0762; x-ms-traffictypediagnostic: TY1PR01MB0762: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(42068640409301)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201708071742011)(7699016); SRVR:TY1PR01MB0762; BCL:0; PCL:0; RULEID:; SRVR:TY1PR01MB0762; x-forefront-prvs: 077929D941 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(396003)(346002)(376002)(136003)(366004)(199004)(189003)(7696005)(186003)(72206003)(6116002)(478600001)(3846002)(1857600001)(256004)(74482002)(5250100002)(5660300001)(966005)(2501003)(99286004)(2900100001)(8936002)(53936002)(68736007)(33656002)(9686003)(2906002)(97736004)(6306002)(26005)(476003)(7736002)(305945005)(74316002)(6666003)(316002)(14454004)(486006)(55016002)(81166006)(5640700003)(66066001)(8676002)(86362001)(6436002)(2351001)(6506007)(106356001)(25786009)(6916009)(105586002)(102836004)(81156014)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:TY1PR01MB0762; H:TY1PR01MB1692.jpnprd01.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: aj.MitsubishiElectric.co.jp does not designate permitted sender hosts) x-microsoft-antispam-message-info: wTAFbjkkf75PjXscixve/bm7YlqcOgJhdwdgGLuehaTi0YQbCbyhWDjjU+rV4B5h44cJbd9JwFuLBeJ6eGfEJqoCkJ1QwpsUHMcMkXfcOCXw/0lih38FZ/rH7qCxKYz4RAUzuTqHEKqL4ml16CVzbv2wDvJYX3eYXe09IT4M+7b4+t03cTwQIeh3rpip0MZTjmWEKwQ+YpaQJ/3YIDX4u7oMBSWHCm/s76pbnIYaiMBEg521zZLhxjS60d7n0c9sowZLS0eV5Pfxq3zqptEtjlScDrZguZBOyGkHL6TpnfE6f3TFpHlaJc6vIBZhXZApgxEarKCYxjiBaQnQlnqGh/Tl+fziQg3it3NoaQOI018= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aj.MitsubishiElectric.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 1862957e-7f69-469c-91cf-08d60da97805 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2018 12:17:22.6427 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c5a75b62-4bff-4c96-a720-6621ce9978e5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR01MB0762 Subject: [LTSI-dev] [PATCH 36/54] tracing: Add hist trigger support for variable reference aliases X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Link: http://lkml.kernel.org/r/ef20a65d921af3a873a6f1e8c71407c926d5586f.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi Signed-off-by: Steven Rostedt (VMware) (cherry picked from commit 7e8b88a30b085d4205b6afcc5e577604978b1268) Signed-off-by: Hirotaka MOTAI --- kernel/trace/trace_events_hist.c | 74 +++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 98be6ad8..32af5235 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -223,16 +223,17 @@ enum hist_field_flags { HIST_FIELD_FL_STACKTRACE = 1 << 8, HIST_FIELD_FL_LOG2 = 1 << 9, HIST_FIELD_FL_TIMESTAMP = 1 << 10, HIST_FIELD_FL_TIMESTAMP_USECS = 1 << 11, HIST_FIELD_FL_VAR = 1 << 12, 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 { unsigned int n_vars; char *name[TRACING_MAP_VARS_MAX]; char *expr[TRACING_MAP_VARS_MAX]; }; @@ -1604,17 +1605,18 @@ static const char *hist_field_name(struct hist_field *field, { const char *field_name = ""; if (level > 1) return field_name; 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"; else if (field->flags & HIST_FIELD_FL_CPU) field_name = "cpu"; else if (field->flags & HIST_FIELD_FL_EXPR || field->flags & HIST_FIELD_FL_VAR_REF) { if (field->system) { @@ -2075,17 +2077,17 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data, return NULL; hist_field = kzalloc(sizeof(struct hist_field), GFP_KERNEL); if (!hist_field) return NULL; 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) { hist_field->fn = hist_field_var_ref; goto out; } if (flags & HIST_FIELD_FL_HITCOUNT) { @@ -2212,20 +2214,28 @@ static int init_var_ref(struct hist_field *ref_field, if (event_name) { ref_field->event_name = kstrdup(event_name, GFP_KERNEL); if (!ref_field->event_name) { err = -ENOMEM; goto free; } } - ref_field->name = kstrdup(var_field->var.name, GFP_KERNEL); - if (!ref_field->name) { - err = -ENOMEM; - goto free; + if (var_field->var.name) { + ref_field->name = kstrdup(var_field->var.name, GFP_KERNEL); + if (!ref_field->name) { + err = -ENOMEM; + goto free; + } + } else if (var_field->name) { + ref_field->name = kstrdup(var_field->name, GFP_KERNEL); + if (!ref_field->name) { + err = -ENOMEM; + goto free; + } } ref_field->type = kstrdup(var_field->type, GFP_KERNEL); if (!ref_field->type) { err = -ENOMEM; goto free; } out: @@ -2377,16 +2387,38 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file, } } out: kfree(str); 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; +} + static struct hist_field *parse_atom(struct hist_trigger_data *hist_data, struct trace_event_file *file, char *str, unsigned long *flags, char *var_name) { char *s, *ref_system = NULL, *ref_event = NULL, *ref_var = str; struct ftrace_event_field *field = NULL; struct hist_field *hist_field = NULL; int ret = 0; @@ -2410,16 +2442,23 @@ static struct hist_field *parse_atom(struct hist_trigger_data *hist_data, } s = local_field_var_ref(hist_data, ref_system, ref_event, ref_var); if (!s) { hist_field = parse_var_ref(hist_data, ref_system, ref_event, ref_var); 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 str = s; field = parse_field(hist_data, file, str, flags); if (IS_ERR(field)) { ret = PTR_ERR(field); @@ -2510,16 +2549,36 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data, } static int check_expr_operands(struct hist_field *operand1, struct hist_field *operand2) { 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; return 0; } static struct hist_field *parse_expr(struct hist_trigger_data *hist_data, @@ -4641,17 +4700,18 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) if (hist_field->var.name) seq_printf(m, "%s=", hist_field->var.name); if (hist_field->flags & HIST_FIELD_FL_TIMESTAMP) seq_puts(m, "common_timestamp"); 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); } if (hist_field->flags) { const char *flags_str = get_hist_field_flags(hist_field); if (flags_str)