[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1564444954-28685-7-git-send-email-divya.indi@oracle.com>
Date: Mon, 29 Jul 2019 17:02:33 -0700
From: Divya Indi <divya.indi@...cle.com>
To: linux-kernel@...r.kernel.org, Steven Rostedt <rostedt@...dmis.org>
Cc: Divya Indi <divya.indi@...cle.com>, Joe Jin <joe.jin@...cle.com>,
Aruna Ramakrishna <aruna.ramakrishna@...cle.com>,
Srinivas Eeda <srinivas.eeda@...cle.com>
Subject: [PATCH 6/7] tracing: New functions for kernel access to Ftrace instances
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");
if (!tr)
tr = trace_array_create("foo-bar");
// Log to tr
// Enable/disable events to tr
trace_array_set_clr_event(tr, _THIS_IP,"system","event",1);
// Done using tr
trace_array_put(tr);
..
Signed-off-by: Divya Indi <divya.indi@...cle.com>
Reviewed-By: Aruna Ramakrishna <aruna.ramakrishna@...cle.com>
---
include/linux/trace.h | 2 ++
include/linux/trace_events.h | 2 ++
kernel/trace/trace.c | 28 ++++++++++++++++++++++++++++
kernel/trace/trace_events.c | 22 ++++++++++++++++++++++
4 files changed, 54 insertions(+)
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 0f874fb..6da3600 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -540,6 +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);
int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
/*
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 130579b..fcf42bb 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -8516,6 +8516,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 99eb5f8..9ee6b52 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 -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
--
1.8.3.1
Powered by blists - more mailing lists