Received: by 10.223.164.202 with SMTP id h10csp681394wrb; Thu, 9 Nov 2017 12:36:46 -0800 (PST) X-Google-Smtp-Source: ABhQp+SmYwqrlHxiVc9wEKlZjVNc5hoUAkpSuFl6VLVftISQDzgThsHbhfJllPJzjMK4ZOlU2hfW X-Received: by 10.84.143.68 with SMTP id 62mr1588081ply.315.1510259806835; Thu, 09 Nov 2017 12:36:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510259806; cv=none; d=google.com; s=arc-20160816; b=wivu4EjQOJToyuOJY37YOcbin7xBy8qiI+mIeNs2rHNleWH1OSPSd7X7n4La9DY1lE om4IufJLKZrftWleSOejSUGo7MS8k0PxFTJXLsL5b0Ww4O2qnsIm8+5+jnjmoI9i9fQJ mk5AU9KldVne8QpPSezEygkFgOZYpXJzmZn+/z5SXUtAfm8lELFNhpzHbGSVaKLnomji ziwpKmMchor+R5V1XgcycNdd0/iWDloBas7rZbDADon7lOaLw0CbZ7bUCJo0MUwR+2ae b6oeLuQgdtMx1MTNS+XvTJ8wQ5/0pKZaUdeQeedt2hZc3joBkiE7uK6jqXPqtnU1rQkX EJVQ== 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=v/WJ7H5LEv9ARpvOPxVM71aUBsdidoCMGahQqDlLTQk=; b=lItqOcr4Q2UBXPOBsRSMoofeY6WRrhfUqUaKBLsOsud91xGSsMWaFYISdBRIBn3OVK s66Y7Q7Q7wGXM4gOHPtfW2aYT5NKcQT8/rlPH+HDNp2ue2DhAA3CVyEHNhkpsgY4MoFt GVbWKsKN5o7WHJfJjcfHScp1OSSqPX8EfXyca5/DfXbCvWnxkWhkSmgVEXoahQbzekQ8 mZ0/FS3YdCPiV73Agh4X/L1bEMQr5GXtxlY9jf75OKvFPylbqWxtbq0lBaG3ltZ1jPx4 sBm/V7KCNSCtunr07ZBuDEg/KaAUsSq7IulcKkese7YFCJW/3wd16T3J7CBnJjdfY6To as6g== 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 f15si7785741pfh.149.2017.11.09.12.36.35; Thu, 09 Nov 2017 12:36:46 -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 S1755082AbdKIUf3 (ORCPT + 83 others); Thu, 9 Nov 2017 15:35:29 -0500 Received: from mga05.intel.com ([192.55.52.43]:34057 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755003AbdKIUf0 (ORCPT ); Thu, 9 Nov 2017 15:35:26 -0500 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 09 Nov 2017 12:35:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,370,1505804400"; d="scan'208";a="148048014" Received: from dkusalov-mobl4.amr.corp.intel.com (HELO localhost) ([10.254.117.34]) by orsmga004.jf.intel.com with ESMTP; 09 Nov 2017 12:35:23 -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, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Tom Zanussi Subject: [PATCH v5 23/37] tracing: Add hist trigger action hook Date: Thu, 9 Nov 2017 14:33:54 -0600 Message-Id: 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 a hook for executing extra actions whenever a histogram entry is added or updated. The default 'action' when a hist entry is added to a histogram is to update the set of values associated with it. Some applications may want to perform additional actions at that point, such as generate another event, or compare and save a maximum. Add a simple framework for doing that; specific actions will be implemented on top of it in later patches. Signed-off-by: Tom Zanussi --- kernel/trace/trace_events_hist.c | 108 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 75494a8..3504aa8 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -33,6 +33,7 @@ typedef u64 (*hist_field_fn_t) (struct hist_field *field, #define HIST_FIELD_OPERANDS_MAX 2 #define HIST_FIELDS_MAX (TRACING_MAP_FIELDS_MAX + TRACING_MAP_VARS_MAX) +#define HIST_ACTIONS_MAX 8 enum field_op_id { FIELD_OP_NONE, @@ -242,6 +243,9 @@ struct hist_trigger_attrs { char *assignment_str[TRACING_MAP_VARS_MAX]; unsigned int n_assignments; + char *action_str[HIST_ACTIONS_MAX]; + unsigned int n_actions; + struct var_defs var_defs; }; @@ -261,6 +265,21 @@ struct hist_trigger_data { bool remove; struct hist_field *var_refs[TRACING_MAP_VARS_MAX]; unsigned int n_var_refs; + + struct action_data *actions[HIST_ACTIONS_MAX]; + unsigned int n_actions; +}; + +struct action_data; + +typedef void (*action_fn_t) (struct hist_trigger_data *hist_data, + struct tracing_map_elt *elt, void *rec, + struct ring_buffer_event *rbe, + struct action_data *data, u64 *var_ref_vals); + +struct action_data { + action_fn_t fn; + unsigned int var_ref_idx; }; static u64 hist_field_timestamp(struct hist_field *hist_field, @@ -772,6 +791,9 @@ static void destroy_hist_trigger_attrs(struct hist_trigger_attrs *attrs) for (i = 0; i < attrs->n_assignments; i++) kfree(attrs->assignment_str[i]); + for (i = 0; i < attrs->n_actions; i++) + kfree(attrs->action_str[i]); + kfree(attrs->name); kfree(attrs->sort_key_str); kfree(attrs->keys_str); @@ -779,6 +801,16 @@ static void destroy_hist_trigger_attrs(struct hist_trigger_attrs *attrs) kfree(attrs); } +static int parse_action(char *str, struct hist_trigger_attrs *attrs) +{ + int ret = 0; + + if (attrs->n_actions >= HIST_ACTIONS_MAX) + return ret; + + return ret; +} + static int parse_assignment(char *str, struct hist_trigger_attrs *attrs) { int ret = 0; @@ -862,8 +894,9 @@ static struct hist_trigger_attrs *parse_hist_trigger_attrs(char *trigger_str) else if (strcmp(str, "clear") == 0) attrs->clear = true; else { - ret = -EINVAL; - goto free; + ret = parse_action(str, attrs); + if (ret) + goto free; } } @@ -2033,11 +2066,55 @@ static int create_sort_keys(struct hist_trigger_data *hist_data) return ret; } +static void destroy_actions(struct hist_trigger_data *hist_data) +{ + unsigned int i; + + for (i = 0; i < hist_data->n_actions; i++) { + struct action_data *data = hist_data->actions[i]; + + kfree(data); + } +} + +static int parse_actions(struct hist_trigger_data *hist_data) +{ + unsigned int i; + int ret = 0; + char *str; + + for (i = 0; i < hist_data->attrs->n_actions; i++) { + str = hist_data->attrs->action_str[i]; + } + + return ret; +} + +static int create_actions(struct hist_trigger_data *hist_data, + struct trace_event_file *file) +{ + struct action_data *data; + unsigned int i; + int ret = 0; + + for (i = 0; i < hist_data->attrs->n_actions; i++) { + data = hist_data->actions[i]; + } + + return ret; +} + static void destroy_hist_data(struct hist_trigger_data *hist_data) { + if (!hist_data) + return; + destroy_hist_trigger_attrs(hist_data->attrs); destroy_hist_fields(hist_data); tracing_map_destroy(hist_data->map); + + destroy_actions(hist_data); + kfree(hist_data); } @@ -2104,6 +2181,10 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data) hist_data->remove = remove; hist_data->event_file = file; + ret = parse_actions(hist_data); + if (ret) + goto free; + ret = create_hist_fields(hist_data, file); if (ret) goto free; @@ -2195,6 +2276,20 @@ static inline void add_to_key(char *compound_key, void *key, memcpy(compound_key + key_field->offset, key, size); } +static void +hist_trigger_actions(struct hist_trigger_data *hist_data, + struct tracing_map_elt *elt, void *rec, + struct ring_buffer_event *rbe, u64 *var_ref_vals) +{ + struct action_data *data; + unsigned int i; + + for (i = 0; i < hist_data->n_actions; i++) { + data = hist_data->actions[i]; + data->fn(hist_data, elt, rec, rbe, data, var_ref_vals); + } +} + static void event_hist_trigger(struct event_trigger_data *data, void *rec, struct ring_buffer_event *rbe) { @@ -2250,6 +2345,9 @@ static void event_hist_trigger(struct event_trigger_data *data, void *rec, return; hist_trigger_elt_update(hist_data, elt, rec, rbe, var_ref_vals); + + if (resolve_var_refs(hist_data, key, var_ref_vals, true)) + hist_trigger_actions(hist_data, elt, rec, rbe, var_ref_vals); } static void hist_trigger_stacktrace_print(struct seq_file *m, @@ -3034,6 +3132,10 @@ static int event_hist_trigger_func(struct event_command *cmd_ops, if (has_hist_vars(hist_data)) save_hist_vars(hist_data); + ret = create_actions(hist_data, file); + if (ret) + goto out_unreg; + ret = tracing_map_init(hist_data->map); if (ret) goto out_unreg; @@ -3055,8 +3157,8 @@ static int event_hist_trigger_func(struct event_command *cmd_ops, remove_hist_vars(hist_data); kfree(trigger_data); - destroy_hist_data(hist_data); + goto out; } -- 1.9.3 From 1583688961700038185@xxx Fri Nov 10 14:18:07 +0000 2017 X-GM-THRID: 1583516180493773162 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread