Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6918228ybp; Wed, 16 Oct 2019 00:37:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHceogedmmWGpgCsbFqqSZO7XN5ds6Uq7dyg+39pQdJwSwRDOrXgYa9IKeeNC0KaOzmwKs X-Received: by 2002:aa7:d2cf:: with SMTP id k15mr35741330edr.208.1571211447232; Wed, 16 Oct 2019 00:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211447; cv=none; d=google.com; s=arc-20160816; b=trzLQtB5XXuJv6aDXjkmPzAYF5/nMu7LXrWF1AEkhAlITunE/J7MD+NPWe+1fuIhot T8JCMv2lh0vBQ95qkoKuagjU5M9eRxtECG28sVM5r2Gl2viwXpSEwFGDOKK5e64jPpEJ gipNW2bSnQtwYK18qEziuApyvUXHGdOuGvRFMlPy/GlbzdMBAX11bIL2oRj4x2I16nOD zbVZQuqzFIytirlIDkOI5zTd4GfKfTuBVzdFKjnDJ0USVPBYkymdcxuHsxkTBkt3j9il kiR7VXQqqp1/0ix5y7lI7BGTAI5W1nIfLg5i4Gd6ySQcxOmaqz46KxS0wafrIJeycLW5 tHsQ== 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=we/v+rnumtstKQoKCw7wPQPzEkY1Jq8Cwjhg+8eQmVI=; b=gGEHaPWmyLMy+YQsnnQAPXc8oYBwq1z1AmI56aogCgtgY27YfZmBmZe2gFPQw54daQ 41bTuqlhfzFbJMMsx4UN9hymWuFXlj42kq2un5iPp6aFLXHTv7Gfo5HnKiH1wPCZUp64 xL2uZ6bENYDjgumxCivUa3gyqxz0elM6tt/0aDhiT503p5IM9R9sqEz53GPxbB9SMa+/ tc8pZ9X+ZWnHect2FDAEWVt+yjYiSkz62DJBwKFZBBRbGvgv4Wc7MerLniaZgrKaNye4 j72uHaYkx6xYX4V2+VcYPCi/ePX93wba75qxXqkzSJr3X+nbFslcVGjpeByECWPVuQ3U kC9A== 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 f45si15910290edb.166.2019.10.16.00.37.03; Wed, 16 Oct 2019 00:37:27 -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 S1728044AbfJOXTY (ORCPT + 99 others); Tue, 15 Oct 2019 19:19:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbfJOXTX (ORCPT ); Tue, 15 Oct 2019 19:19:23 -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 C8D0B20663; Tue, 15 Oct 2019 23:19:20 +0000 (UTC) Date: Tue, 15 Oct 2019 19:19:17 -0400 From: Steven Rostedt To: Divya Indi Cc: linux-kernel@vger.kernel.org, Joe Jin , Srinivas Eeda , Aruna Ramakrishna Subject: Re: [PATCH 5/5] tracing: New functions for kernel access to Ftrace instances Message-ID: <20191015191917.6287ba10@gandalf.local.home> In-Reply-To: <1565805327-579-6-git-send-email-divya.indi@oracle.com> References: <1565805327-579-1-git-send-email-divya.indi@oracle.com> <1565805327-579-6-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, 14 Aug 2019 10:55:27 -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. > > NOTE: trace_array_lookup returns a trace array and also increments the > reference counter associated with the returned trace array. Make sure to > call trace_array_put() once the use is done so that the instance can be > removed at a later time. > > Example use: > > tr = trace_array_lookup("foo-bar"); Should probably be renamed to: trace_array_get_by_name("foo-bar") As the name should show that it adds a ref count. But if we make the change I suggested before, where we do not need to do the put before calling the destroy, we should have: > if (!tr) { > tr = trace_array_create("foo-bar"); trace_array_get(tr); } > // Log to tr > // Enable/disable events to tr > trace_array_set_clr_event(tr, _THIS_IP,"system","event",1); What's with the __THIS_IP? > > // Done using tr > trace_array_put(tr); > .. > > Also, use trace_array_set_clr_event to enable/disable events to a trace array. > So now we no longer need to have ftrace_set_clr_event as an exported > API. > > Signed-off-by: Divya Indi > --- > include/linux/trace.h | 2 ++ > include/linux/trace_events.h | 3 ++- > kernel/trace/trace.c | 28 ++++++++++++++++++++++++++++ > kernel/trace/trace_events.c | 23 ++++++++++++++++++++++- > 4 files changed, 54 insertions(+), 2 deletions(-) > > diff --git a/include/linux/trace.h b/include/linux/trace.h > index 2c782d5..05164bb 100644 > --- a/include/linux/trace.h > +++ b/include/linux/trace.h > @@ -32,6 +32,8 @@ 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); > void trace_array_put(struct trace_array *tr); > +struct trace_array *trace_array_lookup(const char *name); > + > #endif /* CONFIG_TRACING */ > > #endif /* _LINUX_TRACE_H */ > diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h > index 8a62731..05a7514 100644 > --- a/include/linux/trace_events.h > +++ b/include/linux/trace_events.h > @@ -540,7 +540,8 @@ extern int trace_define_field(struct trace_event_call *call, const char *type, > #define is_signed_type(type) (((type)(-1)) < (type)1) > > 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 > * if we try to allocate the static variable to fmt if it is not a > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 7b6a37a..e394d55 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -8514,6 +8514,34 @@ static int instance_rmdir(const char *name) > return ret; > } > > +/** > + * trace_array_lookup - Lookup the trace array, given its name. > + * @name: The name of the trace array to be looked up. > + * > + * Lookup and return the trace array associated with @name. > + * > + * NOTE: The reference counter associated with the returned trace array is > + * incremented to ensure it is not freed when in use. Make sure to call > + * "trace_array_put" for this trace array when its use is done. > + */ > +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 2621995..96dd997 100644 > --- a/kernel/trace/trace_events.c > +++ b/kernel/trace/trace_events.c > @@ -834,7 +834,6 @@ static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set) > > return ret; > } > -EXPORT_SYMBOL_GPL(ftrace_set_clr_event); > > /** > * trace_set_clr_event - enable or disable an event > @@ -859,6 +858,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 We probably should make this a boolean. -- Steve > + * > + * 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 -ENOENT; > + > + 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 >