Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3106511ybi; Mon, 17 Jun 2019 16:45:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6JwChMlQOYIvkP/xOyzNrbdbux1d/KY0A6LhNmtk3mUMjyq73M7zS/ni8ix1Dj/N9jwHN X-Received: by 2002:a62:d44d:: with SMTP id u13mr16358403pfl.251.1560815144474; Mon, 17 Jun 2019 16:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560815144; cv=none; d=google.com; s=arc-20160816; b=gIfYYB7A/9StL/VqqELO7sexiLk62dbos8LeCyeN3tbaRW0QeTusShoRtIh9YBVuOU HRPcGSBKINLvyH5qBQLZcuGRau4xbIjURKO12bCCG9Gxaop1sDqNI3WabPuFWDdKL7Pr jcmhdXk80rgbeJmFxBMBpSjvHq27jZrRvkNONoI2Mu21NljM+5+W47lFhCYVgMY55EZ1 bwyCA/EcG8CQ5ViN/5itJ0pPdFGeO0uc/4XE1lGt11u0Xsvo0kyVOE6rsEt7BA8Vh7Ua 6V3NGL1zUnqEqMDTwH58V3/vo6/rTTXirdA8K5dBm71d2N2223TZ+eA2Lh8cjZbXCmZs bwDg== 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:message-id:subject:cc:to:from:date; bh=3qAEaftHVOOwys2hTMCQRkAvZqA6vU66L8LTR5Z+WwA=; b=ePXJMteyefgRtXWmOJKdtwiaFKieTaRre7zWZSlHV5WSOQI2pfi7+fbGAxNEq4b8Bw d6e6EvQEPqyubQBEgWkPEWKl18RmpID+mC3soL5NBNtHpCNvvLrNXJ+CYaqELm5XCKXG FXG7ZuFwt0l6dvOgb4/krDAyn9Y5yuvUa7PrwXMnFWddMkNx7Xc69oa99fowCw79VeFX pYi6yM69iziEaNXPc7UvWP+Co2YLCLbalLgYt1SuxCvynPcNmVt0qgiJU2J1i3jdf5E4 KYeMzZxvfLnBoveJfQBwQ2EmkFNbP0wnGEH6rkordLDTNHjntx7WujeIWQMMz+MElJRE teuw== 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 h38si11220832plb.149.2019.06.17.16.45.28; Mon, 17 Jun 2019 16:45:44 -0700 (PDT) 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 S1727980AbfFQXpR (ORCPT + 99 others); Mon, 17 Jun 2019 19:45:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:44036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbfFQXpR (ORCPT ); Mon, 17 Jun 2019 19:45:17 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D91AD20861; Mon, 17 Jun 2019 23:45:15 +0000 (UTC) Date: Mon, 17 Jun 2019 19:45:14 -0400 From: Steven Rostedt To: Divya Indi Cc: linux-kernel@vger.kernel.org, Srinivas Eeda , Aruna Ramakrishna Subject: Re: [PATCH 3/3] tracing: Add 2 new funcs. for kernel access to Ftrace instances. Message-ID: <20190617194514.2f760437@gandalf.local.home> In-Reply-To: <1560357259-3497-4-git-send-email-divya.indi@oracle.com> References: <1560357259-3497-1-git-send-email-divya.indi@oracle.com> <1560357259-3497-2-git-send-email-divya.indi@oracle.com> <1560357259-3497-3-git-send-email-divya.indi@oracle.com> <1560357259-3497-4-git-send-email-divya.indi@oracle.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 12 Jun 2019 09:34:19 -0700 Divya Indi wrote: > Adding 2 new functions - > 1) trace_array_lookup : Look up and return a trace array, given its > name. > 2) trace_array_set_clr_event : Enable/disable event recording to the > given trace array. > > Newly added functions trace_array_lookup and trace_array_create also > need to increment the reference counter associated with the trace array > they return. This is to ensure the trace array does not get freed > while in use by the newly introduced APIs. > The reference ctr is decremented in the trace_array_destroy. > > Signed-off-by: Divya Indi > --- > include/linux/trace_events.h | 3 +++ > kernel/trace/trace.c | 30 +++++++++++++++++++++++++++++- > kernel/trace/trace_events.c | 22 ++++++++++++++++++++++ > 3 files changed, 54 insertions(+), 1 deletion(-) > > diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h > index d7b7d85..0cc99a8 100644 > --- a/include/linux/trace_events.h > +++ b/include/linux/trace_events.h > @@ -545,7 +545,10 @@ int trace_array_printk(struct trace_array *tr, unsigned long ip, > struct trace_array *trace_array_create(const char *name); > int trace_array_destroy(struct trace_array *tr); > int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set); > +struct trace_array *trace_array_lookup(const char *name); > int trace_set_clr_event(const char *system, const char *event, int set); > +int trace_array_set_clr_event(struct trace_array *tr, const char *system, > + const char *event, int set); > > /* > * The double __builtin_constant_p is because gcc will give us an error > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index a60dc13..fb70ccc 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -8364,6 +8364,8 @@ struct trace_array *trace_array_create(const char *name) > > list_add(&tr->list, &ftrace_trace_arrays); > > + tr->ref++; > + Needs a comment for why the ref is incremented. > mutex_unlock(&trace_types_lock); > mutex_unlock(&event_mutex); > > @@ -8385,7 +8387,14 @@ struct trace_array *trace_array_create(const char *name) > > static int instance_mkdir(const char *name) > { > - return PTR_ERR_OR_ZERO(trace_array_create(name)); > + struct trace_array *tr; > + > + tr = trace_array_create(name); > + if (IS_ERR(tr)) > + return PTR_ERR(tr); > + trace_array_put(tr); Need a comment to why we need to do a put here. > + > + return 0; > } > > static int __remove_instance(struct trace_array *tr) > @@ -8434,6 +8443,7 @@ int trace_array_destroy(struct trace_array *tr) > mutex_lock(&event_mutex); > mutex_lock(&trace_types_lock); > > + tr->ref--; > ret = __remove_instance(tr); > > mutex_unlock(&trace_types_lock); > @@ -8465,6 +8475,24 @@ static int instance_rmdir(const char *name) > return ret; > } > Need a kerneldoc heading here, that also states that if a trace_array is returned, it requires a call to trace_array_put(). > +struct trace_array *trace_array_lookup(const char *name) > +{ > + struct trace_array *tr; > + > + mutex_lock(&trace_types_lock); > + > + list_for_each_entry(tr, &ftrace_trace_arrays, list) { > + if (tr->name && strcmp(tr->name, name) == 0) { > + tr->ref++; > + mutex_unlock(&trace_types_lock); > + return tr; > + } > + } > + mutex_unlock(&trace_types_lock); > + return NULL; > +} > +EXPORT_SYMBOL_GPL(trace_array_lookup); > + > static __init void create_trace_instances(struct dentry *d_tracer) > { > trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer, > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c > index 445b059..c126d2c 100644 > --- a/kernel/trace/trace_events.c > +++ b/kernel/trace/trace_events.c > @@ -859,6 +859,28 @@ int trace_set_clr_event(const char *system, const char *event, int set) > } > EXPORT_SYMBOL_GPL(trace_set_clr_event); > > +/** > + * trace_array_set_clr_event - enable or disable an event for a trace array > + * @system: system name to match (NULL for any system) > + * @event: event name to match (NULL for all events, within system) > + * @set: 1 to enable, 0 to disable > + * > + * This is a way for other parts of the kernel to enable or disable > + * event recording to instances. > + * > + * Returns 0 on success, -EINVAL if the parameters do not match any > + * registered events. > + */ > +int trace_array_set_clr_event(struct trace_array *tr, const char *system, > + const char *event, int set) > +{ > + if (!tr) > + return -ENODEV; If we have this, should we get rid of the external use of ftrace_set_clr_event()? -- Steve > + > + return __ftrace_set_clr_event(tr, NULL, system, event, set); > +} > +EXPORT_SYMBOL_GPL(trace_array_set_clr_event); > + > /* 128 should be much more than enough */ > #define EVENT_BUF_SIZE 127 >