Received: by 10.223.164.202 with SMTP id h10csp4846852wrb; Wed, 29 Nov 2017 12:54:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMYD6P5jMhOUbHRxavkAe4H223njuWVAFbAQWw+lXZMgn9shhCPVQZx/T7BuqCewak5mB9Zk X-Received: by 10.99.129.73 with SMTP id t70mr157610pgd.227.1511988898580; Wed, 29 Nov 2017 12:54:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511988898; cv=none; d=google.com; s=arc-20160816; b=M5Z6k0TVe5HTdLRnL5hIJpYPJxlw8jYhxUAAWF34YrG0ixXt76/RNWqZeB65Zx4aIm /Jfkoi5wgPws8jKM92PdYBwNX6ShSuw01gnTwT2YXFtvZ/Pz3e/QdROBrTyQjYZ795i0 dfGsvgAp7J2pcA6LRjBKtrmFeaHTIOlboDhNgOmvC92IMWWhUfuqxZJQY9TRrt88shde bfyxTg/pFZR+Wf/0SOyCRpPXKtqsrYHy5j8wlirPZz5t6n5wW9t910ZKrkvh7PQyEBm+ wVa5RYYfwgMFk/lDtj6HrbF20jh00/baxiXH58ix0SQiCG7I+T9AAEM9R2SyNPv5XQO6 gRWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=HE/nYy7VubRe1Hw81PUoN3YeMwoB7q2NE9slvzPMPb4=; b=ZDOHRaVEvVdEmqB4VpUPgjD7Xwkwkkk+2uAB2zNiBek84/rNGdNN+qBBqLsdaVJFMl aOZF5SaSm2kXfMOgg8FMzgYfY0h+zws/zOydQz/fW6SsOAomAN6EEA/swVyHlueeyL1f Tp6rZ7p49bGSN86pko/Rn20UgQAlEDoaU7SbsQ8d9JuPuccX3ASkK0LB/ocuOrc6ssOm WkIEYNG/PWNFYLR/2pwVGTumIJXiTChp/sJl4vS/9C5lsrKQaggHQpoJWaOHzCqXhaWo WZ5+23VLPAE8rJj2MI7k/QdByooCs0/TI4mfbC8E/hDEhHa7LNKWEu7++sAsi8J7ZR0i k/zg== 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 t64si1923981pfi.306.2017.11.29.12.54.44; Wed, 29 Nov 2017 12:54:58 -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 S1752981AbdK2UxL (ORCPT + 99 others); Wed, 29 Nov 2017 15:53:11 -0500 Received: from mga03.intel.com ([134.134.136.65]:17089 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752449AbdK2UxK (ORCPT ); Wed, 29 Nov 2017 15:53:10 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2017 12:53:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,339,1508828400"; d="scan'208";a="11151260" Received: from tzanussi-mobl.amr.corp.intel.com (HELO [10.255.78.174]) ([10.255.78.174]) by orsmga001.jf.intel.com with ESMTP; 29 Nov 2017 12:53:07 -0800 Message-ID: <1511988786.31570.13.camel@tzanussi-mobl.amr.corp.intel.com> Subject: Re: [PATCH v6 27/37] tracing: Add 'onmax' hist trigger action support From: Tom Zanussi To: Namhyung Kim Cc: rostedt@goodmis.org, tglx@linutronix.de, mhiramat@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, kernel-team@lge.com Date: Wed, 29 Nov 2017 14:53:06 -0600 In-Reply-To: <20171123050903.GA25472@sejong> References: <2d9cfba35cc17e8c9ee44256b9244546e9f3106c.1510948725.git.tom.zanussi@linux.intel.com> <20171123050903.GA25472@sejong> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Namhyung, Sorry for the delayed response - was out on vacation.. On Thu, 2017-11-23 at 14:09 +0900, Namhyung Kim wrote: > On Fri, Nov 17, 2017 at 02:33:06PM -0600, Tom Zanussi wrote: > > Add an 'onmax(var).save(field,...)' hist trigger action which is > > invoked whenever an event exceeds the current maximum. > > > > The end result is that the trace event fields or variables specified > > as the onmax.save() params will be saved if 'var' exceeds the current > > maximum for that hist trigger entry. This allows context from the > > event that exhibited the new maximum to be saved for later reference. > > When the histogram is displayed, additional fields displaying the > > saved values will be printed. > > > > As an example the below defines a couple of hist triggers, one for > > sched_wakeup and another for sched_switch, keyed on pid. Whenever a > > sched_wakeup occurs, the timestamp is saved in the entry corresponding > > to the current pid, and when the scheduler switches back to that pid, > > the timestamp difference is calculated. If the resulting latency > > exceeds the current maximum latency, the specified save() values are > > saved: > > > > # echo 'hist:keys=pid:ts0=$common_timestamp.usecs \ > > if comm=="cyclictest"' >> \ > > /sys/kernel/debug/tracing/events/sched/sched_wakeup/trigger > > > > # echo 'hist:keys=next_pid:\ > > wakeup_lat=$common_timestamp.usecs-$ts0:\ > > onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) \ > > if next_comm=="cyclictest"' >> \ > > /sys/kernel/debug/tracing/events/sched/sched_switch/trigger > > > > When the histogram is displayed, the max value and the saved values > > corresponding to the max are displayed following the rest of the > > fields: > > > > # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist > > > > { next_pid: 3728 } hitcount: 199 \ > > max: 123 next_comm: cyclictest prev_pid: 0 \ > > prev_prio: 120 prev_comm: swapper/3 > > { next_pid: 3730 } hitcount: 1321 \ > > max: 15 next_comm: cyclictest prev_pid: 0 \ > > prev_prio: 120 prev_comm: swapper/1 > > { next_pid: 3729 } hitcount: 1973\ > > max: 25 next_comm: cyclictest prev_pid: 0 \ > > prev_prio: 120 prev_comm: swapper/0 > > > > Totals: > > Hits: 3493 > > Entries: 3 > > Dropped: 0 > > > > Signed-off-by: Tom Zanussi > > --- > > [SNIP] > > +static int onmax_create(struct hist_trigger_data *hist_data, > > + struct action_data *data) > > +{ > > + struct trace_event_call *call = hist_data->event_file->event_call; > > + struct trace_event_file *file = hist_data->event_file; > > + struct hist_field *var_field, *ref_field, *max_var; > > + unsigned int var_ref_idx = hist_data->n_var_refs; > > + struct field_var *field_var; > > + char *onmax_var_str, *param; > > + const char *event_name; > > + unsigned long flags; > > + unsigned int i; > > + int ret = 0; > > + > > + onmax_var_str = data->onmax.var_str; > > + if (onmax_var_str[0] != '$') > > + return -EINVAL; > > + onmax_var_str++; > > + > > + event_name = trace_event_name(call); > > It seems not used. > > > > + var_field = find_target_event_var(hist_data, NULL, NULL, onmax_var_str); > > + if (!var_field) > > + return -EINVAL; > > + > > + flags = HIST_FIELD_FL_VAR_REF; > > + ref_field = create_hist_field(hist_data, NULL, flags, NULL); > > + if (!ref_field) > > + return -ENOMEM; > > + > > + if (init_var_ref(ref_field, var_field, NULL, NULL)) { > > + destroy_hist_field(ref_field, 0); > > + ret = -ENOMEM; > > + goto out; > > + } > > + hist_data->var_refs[hist_data->n_var_refs] = ref_field; > > + ref_field->var_ref_idx = hist_data->n_var_refs++; > > + data->onmax.var = ref_field; > > I was confused that this could create a reference to self-variable > which would prevent a hist from being freed. IIUC it tries to avoid > such a self reference by using local field variable and disallowing > variable of expression, right? > > But it seems that's not the case since the reference is saved in other > place than hist_data->fields which is used in find_var_ref(). > The onmax processing only allows a variable defined on the target to be used in the onmax(), so yes it can only be a 'self' variable defined on the same trigger. But that variable can reference variables in an expression e.g. where ts0 is a variable on another trigger: wakeup_lat=$common_timestamp.usecs-$ts0:onmax($wakeup_lat).save(...) The reference to $ts0 prevents that other trigger from going away, just as a further event referencing $wakeup_lat would prevent the onmax() trigger from going away - both of these cases are covered by the find_var_ref() code. But if the only trigger that accesses the $wakeup_lat is the onmax() trigger itself, then it's ok to free that trigger. Hope that answers your question about this.. Thanks, Tom > > > + > > + data->fn = onmax_save; > > + data->onmax.max_var_ref_idx = var_ref_idx; > > + max_var = create_var(hist_data, file, "max", sizeof(u64), "u64"); > > + if (IS_ERR(max_var)) { > > + ret = PTR_ERR(max_var); > > + goto out; > > + } > > + data->onmax.max_var = max_var; > > + > > + for (i = 0; i < data->n_params; i++) { > > + param = kstrdup(data->params[i], GFP_KERNEL); > > + if (!param) { > > + ret = -ENOMEM; > > + goto out; > > + } > > + > > + field_var = create_target_field_var(hist_data, NULL, NULL, param); > > + if (IS_ERR(field_var)) { > > + ret = PTR_ERR(field_var); > > + kfree(param); > > + goto out; > > + } > > + > > + hist_data->max_vars[hist_data->n_max_vars++] = field_var; > > + if (field_var->val->flags & HIST_FIELD_FL_STRING) > > + hist_data->n_max_var_str++; > > + > > + kfree(param); > > + } > > + out: > > + return ret; > > +} > > + > > [SNIP] > > +static struct action_data *onmax_parse(char *str) > > +{ > > + char *onmax_fn_name, *onmax_var_str; > > + struct action_data *data; > > + int ret = -EINVAL; > > + > > + data = kzalloc(sizeof(*data), GFP_KERNEL); > > + if (!data) > > + return ERR_PTR(-ENOMEM); > > + > > + onmax_var_str = strsep(&str, ")"); > > + if (!onmax_var_str || !str) > > + return ERR_PTR(-EINVAL); > > 'data' leaked. > > Thanks, > Namhyung > > > > + data->onmax.var_str = kstrdup(onmax_var_str, GFP_KERNEL); > > + if (!data->onmax.var_str) { > > + ret = -ENOMEM; > > + goto free; > > + } > > + > > + strsep(&str, "."); > > + if (!str) > > + goto free; > > + > > + onmax_fn_name = strsep(&str, "("); > > + if (!onmax_fn_name || !str) > > + goto free; > > + > > + if (strncmp(onmax_fn_name, "save", strlen("save")) == 0) { > > + char *params = strsep(&str, ")"); > > + > > + if (!params) { > > + ret = -EINVAL; > > + goto free; > > + } > > + > > + ret = parse_action_params(params, data); > > + if (ret) > > + goto free; > > + } else > > + goto free; > > + > > + data->onmax.fn_name = kstrdup(onmax_fn_name, GFP_KERNEL); > > + if (!data->onmax.fn_name) { > > + ret = -ENOMEM; > > + goto free; > > + } > > + out: > > + return data; > > + free: > > + onmax_destroy(data); > > + data = ERR_PTR(ret); > > + goto out; > > +} From 1584832232935074274@xxx Thu Nov 23 05:09:56 +0000 2017 X-GM-THRID: 1584401103895282352 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread