All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Theodore Tso <tytso@mit.edu>,
	Arjan van de Ven <arjan@infradead.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: [RFC][PATCH 2/5] [PATCH 2/5] tracing/events: Add code to (un)register stable events
Date: Tue, 16 Nov 2010 19:53:59 -0500	[thread overview]
Message-ID: <20101117005939.931158103@goodmis.org> (raw)
In-Reply-To: 20101117005357.024472450@goodmis.org

[-- Attachment #1: 0002-tracing-events-Add-code-to-un-register-stable-events.patch --]
[-- Type: text/plain, Size: 8089 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Add the framework to create and register stable events.
To create a stable event, add a file into:

  include/trace/stable/myfile.h

With the following format:

  STABLE_EVENT(myevent,

	EVENT_STRUCT(
		__field(type, item)
		__array(type, item, count)
	)
  )

This will create the function prototype:

 typedef void (*trace_proto_myevent)(type item, type *item);

And the functions:

 int register_stable_trace_myevent(trace_proto_myevent func, void *data);
 void unregister_stable_trace_myevent(trace_proto_myevent func, void *data);

This will allow developers to register a callback of a stable event.

The stable events must have a matching raw (in field debugging)
trace event. Although, only the names must match, the information
in the stable event is just a subset of the information that can
be extracted from the raw event.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/trace/stable.h      |   72 +++++++++++++++++++++++++++++++++++++++
 include/trace/stable_list.h |    2 +
 kernel/Makefile             |    1 +
 kernel/events/Makefile      |    1 +
 kernel/events/event_reg.h   |   79 +++++++++++++++++++++++++++++++++++++++++++
 kernel/events/events.c      |   16 +++++++++
 kernel/trace/Kconfig        |    1 +
 7 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 include/trace/stable.h
 create mode 100644 include/trace/stable_list.h
 create mode 100644 kernel/events/Makefile
 create mode 100644 kernel/events/event_reg.h
 create mode 100644 kernel/events/events.c

diff --git a/include/trace/stable.h b/include/trace/stable.h
new file mode 100644
index 0000000..ee10f41
--- /dev/null
+++ b/include/trace/stable.h
@@ -0,0 +1,72 @@
+#ifndef _TRACE_STABLE_H
+#define _TRACE_STABLE_H
+/*
+ * stable.h - create structure and format for stable events
+ *
+ * Copyright (C) 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc
+ *
+ * This file creates the registering function prototypes
+ * to hook to the stable events and the function prototypes of those
+ * hooks.
+ *
+ * The stable events themselves reside in the directory:
+ *   include/trace/stable/
+ *
+ * Each of these files must be added to the header:
+ *   include/trace/stable_list.
+ *
+ * Code that registers and unregisters stable events only needs
+ * to include this file:
+ *   #include <trace/stable.h>
+ *
+ * and all the stable structures and registering functions will
+ * also be included for all stable events.
+ *
+ * The current elements that can be used by stable events are:
+ *
+ *    __field(type, item)
+ *    __array(type, time, size)
+ *
+ *  Example:
+ *   STABLE_EVENT(myevent,
+ * 	EVENT_STRUCT(
+ *      __field(	pid_t,		pid			)
+ *      __array(	char,		comm,	TASK_COMM_LEN	)
+ *	)
+ *   )
+ *
+ * The above would create the following:
+ *
+ *  typedef void (*trace_proto_myevent)(pid_t pid, char comm[TASK_COMM_LEN]);
+ *  int register_stable_trace_myevent(trace_proto_myevent func, void *data);
+ *  void unregister_stable_trace_myevent(trace_proto_myevent func, void *data);
+ *
+ * These functions will be created in kernel/events/events.c
+ */
+
+#define STABLE_HEADER_MULTI_READ
+
+#undef __SEP__
+#define __SEP__ ,
+
+#undef __field
+#define __field(type, item)				type item
+
+#undef __array
+#define __array(type, item, size)			type *item
+
+#undef EVENT_STRUCT
+#define EVENT_STRUCT(s)	s
+
+#undef STABLE_EVENT
+#define STABLE_EVENT(name, estruct)					\
+	typedef void (*trace_proto_##name)(void *data, estruct);	\
+	int register_stable_trace_##name(trace_proto_##name func, void *data); \
+	void unregister_stable_trace_##name(trace_proto_##name func, void *data)
+
+/* New stable defines must be added here */
+#include <trace/stable_list.h>
+
+#undef STABLE_HEADER_MULTI_READ
+
+#endif /* _TRACE_STABLE_H */
diff --git a/include/trace/stable_list.h b/include/trace/stable_list.h
new file mode 100644
index 0000000..996932a
--- /dev/null
+++ b/include/trace/stable_list.h
@@ -0,0 +1,2 @@
+
+/* New stable defines must be added here */
diff --git a/kernel/Makefile b/kernel/Makefile
index 0b5ff08..8c1cbbd 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -106,6 +106,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
+obj-y += events/
 
 ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff --git a/kernel/events/Makefile b/kernel/events/Makefile
new file mode 100644
index 0000000..86fd7c1
--- /dev/null
+++ b/kernel/events/Makefile
@@ -0,0 +1 @@
+obj-y += events.o
diff --git a/kernel/events/event_reg.h b/kernel/events/event_reg.h
new file mode 100644
index 0000000..dfe16df
--- /dev/null
+++ b/kernel/events/event_reg.h
@@ -0,0 +1,79 @@
+/*
+ * event_reg.h - code to register stable events
+ *
+ * Copyright (C) 2010 Steven Rostedt <srostedt@redhat.com> Red Hat Inc
+ *
+ * Create the registration functions for the stable events:
+ *
+ * int register_stable_trace_##name(func, data);
+ * void unregister_stable_stable_trace_##name(func, data);
+ *
+ * The func is of the format based off of the STABLE_EVENT() structure.
+ * For example:
+ *
+ *   STABLE_EVENT(myevent,
+ * 	EVENT_STRUCT(
+ *      __field(	pid_t,		pid			)
+ *      __array(	char,		comm,	TASK_COMM_LEN	)
+ *	)
+ *   )
+ *
+ *  Will yield a function proto type of:
+ *
+ *  void func(pid_t pid, char *comm, void *data);
+ *
+ * When registering a call back to a stable event, what ever you
+ * pass into data, will be sent to your function in the data field.
+ *
+ * Once you register it, the function will start being called when
+ * the corresponding tracepoint is hit.
+ *
+ * To stop tracing, just unregister the function. Note, both
+ * registering and unregistering must be called from sleepable
+ * context, since those functions may sleep.
+ */
+
+#define STABLE_HEADER_MULTI_READ
+
+#undef __SEP__
+#define __SEP__
+
+#undef __field
+#define __field(type, item)
+
+#undef __array
+#define __array(type, item, size)
+
+#undef STABLE_EVENT
+#define STABLE_EVENT(name, estruct)					\
+static int name##_ref_count;						\
+int register_stable_trace_##name(trace_proto_##name func, void *__data)	\
+{									\
+	int ret;							\
+									\
+	mutex_lock(&stable_event_mutex);				\
+	ret = register_trace_stable_##name(func, __data);		\
+	if (!ret)							\
+		goto out;						\
+									\
+	if (name##_ref_count++ == 0)					\
+		ret = register_trace_##name(hook_##name, NULL);		\
+									\
+ out:									\
+	mutex_unlock(&stable_event_mutex);				\
+	return ret;							\
+}									\
+EXPORT_SYMBOL(register_stable_trace_##name);				\
+									\
+void unregister_stable_trace_##name(trace_proto_##name func, void *__data) \
+{									\
+	mutex_lock(&stable_event_mutex);				\
+	if (--name##_ref_count == 0)					\
+		unregister_trace_##name(hook_##name, NULL);		\
+									\
+	unregister_trace_stable_##name(func, __data);			\
+	mutex_unlock(&stable_event_mutex);				\
+}									\
+EXPORT_SYMBOL(unregister_stable_trace_##name)
+
+#include <trace/stable_list.h>
diff --git a/kernel/events/events.c b/kernel/events/events.c
new file mode 100644
index 0000000..6868bf1
--- /dev/null
+++ b/kernel/events/events.c
@@ -0,0 +1,16 @@
+/*
+ * events.c - code to register stable events
+ *
+ * Copyright (C) 2010 Steven Rostedt <srostedt@redhat.com> Red Hat Inc
+ *
+ * This file holds the hooks that are required to convert
+ * a raw tracepoing into a stable one. The conversion names
+ * must be named: hook_##tracepoint_name.
+ */
+#include <linux/tracepoint.h>
+#include <linux/module.h>
+#include <trace/stable.h>
+
+static struct mutex stable_event_mutex;
+
+#include "event_reg.h"
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index e04b8bc..0533182 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -94,6 +94,7 @@ config TRACING
 	select NOP_TRACER
 	select BINARY_PRINTF
 	select EVENT_TRACING
+	select EVENT_FS
 
 config GENERIC_TRACER
 	bool
-- 
1.7.1



  parent reply	other threads:[~2010-11-17  0:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17  0:53 [RFC][PATCH 0/5] tracing/events: stable tracepoints Steven Rostedt
2010-11-17  0:53 ` [RFC][PATCH 1/5] [PATCH 1/5] events: Add EVENT_FS the event filesystem Steven Rostedt
2010-11-17  3:32   ` Greg KH
2010-11-17 10:39     ` Ingo Molnar
2010-11-17 12:25       ` Steven Rostedt
2010-11-17 15:03         ` Ingo Molnar
2010-11-17 15:16           ` Peter Zijlstra
2010-11-17 15:16           ` Steven Rostedt
2010-11-17 15:35             ` Peter Zijlstra
2010-11-17 18:42           ` Ted Ts'o
2010-11-17 15:16         ` Peter Zijlstra
2010-11-23 21:29           ` Steven Rostedt
2010-11-17 17:46         ` Mathieu Desnoyers
2010-11-17 17:52           ` Steven Rostedt
2010-11-17 18:12             ` Mathieu Desnoyers
2010-11-18  9:42               ` Avi Kivity
2010-11-17 23:48             ` Ted Ts'o
2010-11-18 13:05               ` Mathieu Desnoyers
2010-11-17 12:16     ` Steven Rostedt
2010-11-17  0:53 ` Steven Rostedt [this message]
2010-11-17  0:54 ` [RFC][PATCH 3/5] [PATCH 3/5] tracing/events: Add infrastructure to show stable event formats Steven Rostedt
2010-11-17  0:54 ` [RFC][PATCH 4/5] [PATCH 4/5] tracing/events: Add stable event sched_switch Steven Rostedt
2010-11-17  0:54 ` [RFC][PATCH 5/5] [PATCH 5/5] tracing/events: Add sched_migrate_task stable event Steven Rostedt
2010-11-17 20:14 ` [RFC][PATCH 0/5] tracing/events: stable tracepoints Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101117005939.931158103@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.