From patchwork Wed Aug 29 12:17:05 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: 10580241 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 18951174A for ; Wed, 29 Aug 2018 12:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06D8A28A13 for ; Wed, 29 Aug 2018 12:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEE5528A44; Wed, 29 Aug 2018 12:43:19 +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 3D1C628A61 for ; Wed, 29 Aug 2018 12:43:19 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D7B99DAC; Wed, 29 Aug 2018 12:36:53 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 21061D75 for ; Wed, 29 Aug 2018 12:36:48 +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 smtp2.linuxfoundation.org (Postfix) with ESMTPS id B0C851DDC8 for ; Wed, 29 Aug 2018 12:36:41 +0000 (UTC) Received: from mr04.melco.co.jp (mr04 [133.141.98.166]) by mx04.melco.co.jp (Postfix) with ESMTP id 3ABA03A2875 for ; Wed, 29 Aug 2018 21:17:27 +0900 (JST) Received: from mr04.melco.co.jp (unknown [127.0.0.1]) by mr04.imss (Postfix) with ESMTP id 420l4R1bsczRkFM for ; Wed, 29 Aug 2018 21:17:27 +0900 (JST) Received: from mf04_second.melco.co.jp (unknown [192.168.20.184]) by mr04.melco.co.jp (Postfix) with ESMTP id 420l4R1JDHzRk8j for ; Wed, 29 Aug 2018 21:17:27 +0900 (JST) Received: from mf04.melco.co.jp (unknown [133.141.98.184]) by mf04_second.melco.co.jp (Postfix) with ESMTP id 420l4R1H7szRkCw for ; Wed, 29 Aug 2018 21:17:27 +0900 (JST) Received: from JPN01-OS2-obe.outbound.protection.outlook.com (unknown [23.103.139.151]) by mf04.melco.co.jp (Postfix) with ESMTP id 420l4R0lQyzRkCn for ; Wed, 29 Aug 2018 21:17:27 +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=uececfIvoFOZ6jT9/MXNex19Nz8TyyjzjCFL5BnHQc8=; b=eDxMD3xK3OPBMqTUOJnhK3ZqNa54dVSDgDikhfRg3PfZYIWNx10t/Yw/OuQnbmeTd9uKMx47ifCeyv6gnnqNeDK6bfWoZ+DgMtJkHuGuex/POAPWkw2tAR2MWngzI2WTNGaAtoEjBi/wGOr4aP+Zc3FzGrAkQaHb8TUwg5yTJPc= Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com (52.133.160.145) by TY1PR01MB1708.jpnprd01.prod.outlook.com (52.133.160.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:17:26 +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:17:26 +0000 From: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" To: "ltsi-dev@lists.linuxfoundation.org" Thread-Topic: [LTSI-dev] [PATCH 14/54] tracing: Add hist trigger timestamp support Thread-Index: AdQ/ijo3tmy/T2sZTJivQRJepa1cZw== Date: Wed, 29 Aug 2018 12:17:05 +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; TY1PR01MB1708; 6:zcvICG2talI1YE1tlCV0/fdkyn59kP0qgjCXZRJ4Ofe5643F4tbGz4TUmFX1ZqS73DYKoz2cB0PnKOaCO3XtCilNNLdyeUIY6t5RpJZKcXjUX/V15IBMguc178+9uvQlc+u1uoS/V0I521bvZ0jho75IQnxN6MZVeO/vHLt3pztvZw1S802iAzPufW3CzG96eULeKVcR3nHBhB/VuvdYN9zZ5bpdNqlLWZ3dbQ3cqXJ5OffHd2lkCKkFk+yrzojqpNRLzEp+IgmGqWN+Lv3/xVgpinqqPrgPcCKrd46c9MZTdX4NtH66VfaVFw4Y5vsON2358I/5AXVfRtfzNdSRrwnQxQ43/2JQ/DKo+D1YDLyIJOTJwIc4fnQ9zDZYlj2TfpmsnoKFaLB17IJkFCBbdPQeD/3UDjE/GoP5fhHKYIRZSVKGfy06C8pF7nbCfpOMnSidSi5QRgglMxA3A0JKrQ==; 5:GnKMCnD7SxfUpX+HHlqjms3Apod9fgG+D1/ExVv1roQLW/ZHGjr3BOQpIh32LUbJubwYpCnbkKQhqRmWUMiMHgG+WMhnGTb04XJJ1QPnYLjgIXKr7WLtGqrfXiZMuiyLZJCFEMtK24eUfSZgpsjz5z18z5FWgJKnr1NBJOMj4UU=; 7:SfOeSO/MybTb5CzqIoUWhu0bcxzFjYfJFhkC1dVEzAU5CSc2DtM6ZJGTAkuRAUaVe7UNR27AF6NkzSPRQRYw488izeowTRwI6sJIFvd4r7OiaK2aiVneAJ9udxmLXQvZNM8HZ1L0K/6D8THaCFDNQCpQypXRTwdkybMEbz4CE00iUe8VReAjs7r0mJnSfd/oFbjv5wTk6f2Nk/hPpqtzYzNo2qTz0QAUMIAKcXtuDIcLxiWp9iCPyq0kOmw/SZ7g x-ms-office365-filtering-correlation-id: f9717422-37c7-4b7d-910d-08d60da961ff x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:TY1PR01MB1708; x-ms-traffictypediagnostic: TY1PR01MB1708: 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)(3002001)(10201501046)(93006095)(93001095)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(201708071742011)(7699016); SRVR:TY1PR01MB1708; BCL:0; PCL:0; RULEID:; SRVR:TY1PR01MB1708; x-forefront-prvs: 077929D941 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(366004)(396003)(39860400002)(346002)(376002)(189003)(199004)(966005)(25786009)(74482002)(81156014)(8676002)(106356001)(5660300001)(105586002)(6506007)(14454004)(81166006)(33656002)(26005)(7736002)(74316002)(186003)(72206003)(305945005)(66066001)(68736007)(97736004)(478600001)(476003)(102836004)(2906002)(8936002)(6666003)(6916009)(486006)(6116002)(1857600001)(316002)(7696005)(2900100001)(5640700003)(3846002)(55016002)(99286004)(53936002)(14444005)(86362001)(256004)(6436002)(6306002)(2501003)(5250100002)(9686003)(575784001)(2351001); DIR:OUT; SFP:1102; SCL:1; SRVR:TY1PR01MB1708; H:TY1PR01MB1692.jpnprd01.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: aj.MitsubishiElectric.co.jp does not designate permitted sender hosts) x-microsoft-antispam-message-info: MfQrCEjwQfrluLUJ0Zjr59O4ohF+TWimoIfL/QA5s4qfjdlNmSXlszjWpzaN2JtRmcMsdyylcoU7Hu2+m1ImGRkvVfQywpvKMHM1+XVNgaDjo7ohd88Pkjr44HsHU12+MxyvCigYl7jP90MPyMiPltS1LzfUqCsx+1y+G6s4ePqyFv4COFEk5cjQO6uiFU5k7FpNBIdfUH+q73VIVlXZY+K0p0jxCxFk6CEjiNTqEOXlyiVh4rYBf7waTDEuuVobiJNzrLuX8WX/shFdYflo45xNKyASzMkhg2SgDoG59uG5RoUXwXKPB1PiuPW/k9342cMh33Gme+uuL3n+SVTpEvV6CnN4b/ltrpfUHtyOTmQ= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aj.MitsubishiElectric.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: f9717422-37c7-4b7d-910d-08d60da961ff X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2018 12:17:22.6307 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c5a75b62-4bff-4c96-a720-6621ce9978e5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR01MB1708 Subject: [LTSI-dev] [PATCH 14/54] tracing: Add hist trigger timestamp support 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 a timestamp event field. This is actually a 'pseudo-' event field in that it behaves like it's part of the event record, but is really part of the corresponding ring buffer event. To make use of the timestamp field, users can specify "common_timestamp" as a field name for any histogram. Note that this doesn't make much sense on its own either as either a key or value, but needs to be supported even so, since follow-on patches will add support for making use of this field in time deltas. The common_timestamp 'field' is not a bona fide event field - so you won't find it in the event description - but rather it's a synthetic field that can be used like a real field. Note that the use of this field requires the ring buffer be put into 'absolute timestamp' mode, which saves the complete timestamp for each event rather than an offset. This mode will be enabled if and only if a histogram makes use of the "common_timestamp" field. Link: http://lkml.kernel.org/r/97afbd646ed146e26271f3458b4b33e16d7817c2.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi Signed-off-by: Baohong Liu [kasan use-after-free fix] Signed-off-by: Vedang Patel Signed-off-by: Steven Rostedt (VMware) (cherry picked from commit ad42febe51ae0a2e875f507a37a6329277f75fdd) Signed-off-by: Hirotaka MOTAI --- kernel/trace/trace_events_hist.c | 94 ++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index e4368bb7..a793f8c0 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -84,16 +84,22 @@ static u64 hist_field_log2(struct hist_field *hist_field, void *event, { struct hist_field *operand = hist_field->operands[0]; u64 val = operand->fn(operand, event, rbe); return (u64) ilog2(roundup_pow_of_two(val)); } +static u64 hist_field_timestamp(struct hist_field *hist_field, void *event, + struct ring_buffer_event *rbe) +{ + return ring_buffer_event_time_stamp(rbe); +} + #define DEFINE_HIST_FIELD_FN(type) \ static u64 hist_field_##type(struct hist_field *hist_field, \ void *event, \ struct ring_buffer_event *rbe) \ { \ type *addr = (type *)(event + hist_field->field->offset); \ \ return (u64)(unsigned long)*addr; \ @@ -130,16 +136,17 @@ enum hist_field_flags { HIST_FIELD_FL_STRING = 1 << 2, HIST_FIELD_FL_HEX = 1 << 3, HIST_FIELD_FL_SYM = 1 << 4, HIST_FIELD_FL_SYM_OFFSET = 1 << 5, HIST_FIELD_FL_EXECNAME = 1 << 6, HIST_FIELD_FL_SYSCALL = 1 << 7, HIST_FIELD_FL_STACKTRACE = 1 << 8, HIST_FIELD_FL_LOG2 = 1 << 9, + HIST_FIELD_FL_TIMESTAMP = 1 << 10, }; struct hist_trigger_attrs { char *keys_str; char *vals_str; char *sort_key_str; char *name; bool pause; @@ -154,30 +161,33 @@ struct hist_trigger_data { unsigned int n_keys; unsigned int n_fields; unsigned int key_size; struct tracing_map_sort_key sort_keys[TRACING_MAP_SORT_KEYS_MAX]; unsigned int n_sort_keys; struct trace_event_file *event_file; struct hist_trigger_attrs *attrs; struct tracing_map *map; + bool enable_timestamps; }; static const char *hist_field_name(struct hist_field *field, unsigned int level) { 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) field_name = hist_field_name(field->operands[0], ++level); + else if (field->flags & HIST_FIELD_FL_TIMESTAMP) + field_name = "common_timestamp"; if (field_name == NULL) field_name = ""; return field_name; } static hist_field_fn_t select_value_fn(int field_size, int field_is_signed) @@ -435,16 +445,22 @@ static struct hist_field *create_hist_field(struct ftrace_event_field *field, if (flags & HIST_FIELD_FL_LOG2) { unsigned long fl = flags & ~HIST_FIELD_FL_LOG2; hist_field->fn = hist_field_log2; hist_field->operands[0] = create_hist_field(field, fl); hist_field->size = hist_field->operands[0]->size; goto out; } + if (flags & HIST_FIELD_FL_TIMESTAMP) { + hist_field->fn = hist_field_timestamp; + hist_field->size = sizeof(u64); + goto out; + } + if (WARN_ON_ONCE(!field)) goto out; if (is_string_field(field)) { flags |= HIST_FIELD_FL_STRING; if (field->filter_type == FILTER_STATIC_STRING) hist_field->fn = hist_field_string; @@ -512,20 +528,25 @@ static int create_val_field(struct hist_trigger_data *hist_data, if (strcmp(field_str, "hex") == 0) flags |= HIST_FIELD_FL_HEX; else { ret = -EINVAL; goto out; } } - field = trace_find_event_field(file->event_call, field_name); - if (!field || !field->size) { - ret = -EINVAL; - goto out; + if (strcmp(field_name, "common_timestamp") == 0) { + flags |= HIST_FIELD_FL_TIMESTAMP; + hist_data->enable_timestamps = true; + } else { + field = trace_find_event_field(file->event_call, field_name); + if (!field || !field->size) { + ret = -EINVAL; + goto out; + } } hist_data->fields[val_idx] = create_hist_field(field, flags); if (!hist_data->fields[val_idx]) { ret = -ENOMEM; goto out; } @@ -610,26 +631,32 @@ static int create_key_field(struct hist_trigger_data *hist_data, else if (strcmp(field_str, "log2") == 0) flags |= HIST_FIELD_FL_LOG2; else { ret = -EINVAL; goto out; } } - field = trace_find_event_field(file->event_call, field_name); - if (!field || !field->size) { - ret = -EINVAL; - goto out; - } + if (strcmp(field_name, "common_timestamp") == 0) { + flags |= HIST_FIELD_FL_TIMESTAMP; + hist_data->enable_timestamps = true; + key_size = sizeof(u64); + } else { + field = trace_find_event_field(file->event_call, field_name); + if (!field || !field->size) { + ret = -EINVAL; + goto out; + } - if (is_string_field(field)) - key_size = MAX_FILTER_STR_VAL; - else - key_size = field->size; + if (is_string_field(field)) + key_size = MAX_FILTER_STR_VAL; + else + key_size = field->size; + } } hist_data->fields[key_idx] = create_hist_field(field, flags); if (!hist_data->fields[key_idx]) { ret = -ENOMEM; goto out; } @@ -815,16 +842,19 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data) hist_field = hist_data->fields[i]; if (hist_field->flags & HIST_FIELD_FL_KEY) { tracing_map_cmp_fn_t cmp_fn; field = hist_field->field; if (hist_field->flags & HIST_FIELD_FL_STACKTRACE) cmp_fn = tracing_map_cmp_none; + else if (!field) + cmp_fn = tracing_map_cmp_num(hist_field->size, + hist_field->is_signed); else if (is_string_field(field)) cmp_fn = tracing_map_cmp_string; else cmp_fn = tracing_map_cmp_num(field->size, field->is_signed); idx = tracing_map_add_key_field(map, hist_field->offset, cmp_fn); @@ -1210,17 +1240,21 @@ static const char *get_hist_field_flags(struct hist_field *hist_field) return flags_str; } static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) { const char *field_name = hist_field_name(hist_field, 0); - seq_printf(m, "%s", field_name); + if (hist_field->flags & HIST_FIELD_FL_TIMESTAMP) + seq_puts(m, "common_timestamp"); + else if (field_name) + seq_printf(m, "%s", field_name); + if (hist_field->flags) { const char *flags_str = get_hist_field_flags(hist_field); if (flags_str) seq_printf(m, ".%s", flags_str); } } @@ -1261,37 +1295,35 @@ static int event_hist_trigger_print(struct seq_file *m, hist_field_print(m, hist_data->fields[i]); } } seq_puts(m, ":sort="); for (i = 0; i < hist_data->n_sort_keys; i++) { struct tracing_map_sort_key *sort_key; + unsigned int idx; sort_key = &hist_data->sort_keys[i]; + idx = sort_key->field_idx; + + if (WARN_ON(idx >= TRACING_MAP_FIELDS_MAX)) + return -EINVAL; if (i > 0) seq_puts(m, ","); - if (sort_key->field_idx == HITCOUNT_IDX) + if (idx == HITCOUNT_IDX) seq_puts(m, "hitcount"); - else { - unsigned int idx = sort_key->field_idx; - - if (WARN_ON(idx >= TRACING_MAP_FIELDS_MAX)) - return -EINVAL; - + else hist_field_print(m, hist_data->fields[idx]); - } if (sort_key->descending) seq_puts(m, ".descending"); } - seq_printf(m, ":size=%u", (1 << hist_data->map->map_bits)); if (data->filter_str) seq_printf(m, " if %s", data->filter_str); if (data->paused) seq_puts(m, " [paused]"); else @@ -1449,16 +1481,20 @@ static bool hist_trigger_match(struct event_trigger_data *data, key_field_test = hist_data_test->fields[i]; if (key_field->flags != key_field_test->flags) return false; if (!compatible_field(key_field->field, key_field_test->field)) return false; if (key_field->offset != key_field_test->offset) return false; + if (key_field->size != key_field_test->size) + return false; + if (key_field->is_signed != key_field_test->is_signed) + return false; } for (i = 0; i < hist_data->n_sort_keys; i++) { sort_key = &hist_data->sort_keys[i]; sort_key_test = &hist_data_test->sort_keys[i]; if (sort_key->field_idx != sort_key_test->field_idx || sort_key->descending != sort_key_test->descending) @@ -1531,16 +1567,19 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, goto out; } list_add_rcu(&data->list, &file->triggers); ret++; update_cond_flag(file); + if (hist_data->enable_timestamps) + tracing_set_time_stamp_abs(file->tr, true); + if (trace_event_trigger_enable_disable(file, 1) < 0) { list_del_rcu(&data->list); update_cond_flag(file); ret--; } out: return ret; } @@ -1565,27 +1604,36 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops, trace_event_trigger_enable_disable(file, 0); update_cond_flag(file); break; } } if (unregistered && test->ops->free) test->ops->free(test->ops, test); + + if (hist_data->enable_timestamps) { + if (unregistered) + tracing_set_time_stamp_abs(file->tr, false); + } } static void hist_unreg_all(struct trace_event_file *file) { struct event_trigger_data *test, *n; + struct hist_trigger_data *hist_data; list_for_each_entry_safe(test, n, &file->triggers, list) { if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) { + hist_data = test->private_data; list_del_rcu(&test->list); trace_event_trigger_enable_disable(file, 0); update_cond_flag(file); + if (hist_data->enable_timestamps) + tracing_set_time_stamp_abs(file->tr, false); if (test->ops->free) test->ops->free(test->ops, test); } } } static int event_hist_trigger_func(struct event_command *cmd_ops, struct trace_event_file *file,