Skip to contentSkip to conversation

Renaming 'trace' to 'relay' and enhancements to 'relay'

PATCH In review K.Prasad 3 participants 9 messages Aug 4, 2008 – Aug 13, 2008

Subsystems (3)
lore
Share & tools
lore

K.Prasad

author
#0 lore raw

cover Renaming 'trace' to 'relay' and enhancements to 'relay'

Hi Andrew,
Please find the patches that enhance the 'trace' infrastructure
(available in the -mm tree) and which introduce two new APIs relay_dump() and relay_printk().

These patches were submitted earlier as enhancements to trace, but were renamed and merged with 'relay' based on your suggestion
(http://lkml.org/lkml/2008/5/28/207).

The patches apply on 2.6.27-rc1-mm1 and have been tested on an x86 machine. Kindly accept them.

Thanks,
K.Prasad

author
#1 lore raw

PATCH 1/2 Merging Documentation/trace.txt with Documentation/filesystems/relay.txt

This patch merges the "trace" documentation with that of "relay" as a part of renaming/merging "trace" with "relay. It also renames the functions wherever required.

---
 Documentation/filesystems/relay.txt |  215 ++++++++++++++++++++++++++++++++++++
 Documentation/trace.txt             |  210 -----------------------------------
 2 files changed, 215 insertions(+), 210 deletions(-)
Documentation/filesystems/relay.txt +215 -0
Index: linux-relay_NEW-2.6.25-mm1/Documentation/filesystems/relay.txt
===================================================================
@@ -470,6 +470,213 @@ unmapped.  The client can use this notif
 within the kernel application, such as enabling/disabling logging to
 the channel.
 
+Enhanced Relay interface using debugfs -- Relay debugfs
+========================================================
+Relay debugfs Setup and Control
+================================
+In the kernel, the 'relay debugfs' interface provides a simple mechanism for
+starting and managing data channels (relays) to user space.  The
+'relay debugfs' interface builds on the relay interface.  For a complete
+description of the relay interface, please see:
+Documentation/filesystems/relay.txt.
+
+The 'relay debugfs' interface provides a single layer in a complete tracing
+application.  'relay debugfs' provides a kernel API that can be used for the
+setup and control of tracing channels.  User of 'relay debugfs' must provide a
+data layer responsible for formatting and writing data into the 'relay debugfs'
+channels.
+
+A layered approach to tracing
+=============================
+A complete kernel tracing application consists of a data provider and
+a data consumer.  Both provider and consumer contain three layers; each
+layer works in tandem with the corresponding layer in the opposite side.
+The layers are represented in the following diagram.
+
+Provider Data layer
+	Formats raw data and provides data-related service.
+	For example, adding timestamps used by consumer to sort data.
+
+Provider Control layer
+	Provided by the 'relay debugfs' interface, this layer creates 'relay
+	debugfs' channels and informs the data layer and consumer of the current
+	state of the 'relay debugfs' channels.
+
+Provider Buffering layer
+	Provided by relay. This layer buffers data in the
+	kernel for consumption by the consumer's buffer
+	layer.
+
+Provider (in-kernel facility)
+-----------------------------------------------------------------------------
+Consumer (user application)
+
+
+Consumer Buffer layer
+	Reads/consumes data from the provider's data buffers.
+
+Consumer Control layer
+	Communicates to the provider's control layer to control the state
+	of the 'relay debugfs' channels.
+
+Consumer Data layer
+	Sorts and formats data as provided by the provider's data layer.
+
+The provider is coded as a kernel facility.  The consumer is coded as
+a user application.
+
+
+'relay debugfs' - Features
+===========================
+'relay debugfs' exploits services and features provided by relay.  These
+features are:
+- The creation and destruction of relay channels.
+- Buffer management.  Overwrite or non-overwrite modes can be selected
+  as well as global or per-CPU buffering.
+
+Overwrite mode can be called "flight recorder mode".  Flight recorder
+mode is selected by setting the TRACE_FLIGHT_CHANNEL flag when
+creating 'relay debugfs' channels.  In flight mode when a tracing buffer is
+full, the oldest records in the buffer will be discarded to make room
+as new records arrive. In the default non-overwrite mode, new records
+may be written only if the buffer has room.  In either case, to
+prevent data loss, a user space reader must keep the buffers
+drained. 'relay debugfs' provides a means to detect the number of records that
+have been dropped due to a buffer-full condition (non-overwrite mode
+only).
+
+When per-CPU buffers are used, relay creates one debugfs file for each
+running CPU.  The user-space consumer of the data is responsible for
+reading the per-CPU buffers and collating the records presumably using
+a time stamp or sequence number included in the 'relay debugfs' records.  The
+use of global buffers eliminates this extra work of sequencing
+records; however the provider's data layer must hold a lock when
+writing records.  The lock prevents writers running on different CPUs
+from overwriting each other's data.  However, buffering may be slower
+because writes to the buffer are serialized. Global buffering is
+selected by setting the TRACE_GLOBAL_CHANNEL flag when creating 'relay debugfs'
+channels.
+
+'relay debugfs' User Interface
+==============================
+When a 'relay debugfs' channel is created and started, the following
+directories and files are created in the root of the mounted debugfs.
+
+/debug (root of the debugfs)
+	/<relay_debugfs-root-dir>
+		/<relay_debugfs-name>
+			relay[0...N-1]     Per-CPU 'relay debugfs' data, one
+					   file per CPU.
+
+			state		   Start or stop tracing by
+					   by writing the strings
+					   "start" or "stop" to this
+					   file. Read the file to get the
+					   current state.
+
+			dropped		   The number of records dropped
+					   due to a full-buffer condition,
+					   for non-TRACE_FLIGHT_CHANNELs
+					   only.
+
+			rewind		   Trigger a rewind by writing
+					   to this file.  i.e. start
+					   next read at the beginning
+					   again. Only available for
+					   TRACE_FLIGHT_CHANNELS.
+
+
+			nr_sub		   Number of sub-buffers
+					   in the channel.
+
+			sub_size	   Size of sub-buffers in
+					   the channel.
+
+'relay debugfs' data is gathered from the 'relay debugfs'[0...N-1] files using
+one of the available interfaces provided by relay.
+
+When using the read(2) interface, as data is read it is marked as
+consumed by the relay subsystem.  Therefore, subsequent reads will
+only return unconsumed data.
+
+'relay debugfs' Kernel API
+==========================
+An overview of the 'relay debugfs' Kernel API is now given. More details of the
+API can be found in linux/trace.h.
+
+The steps a kernel data provider takes to utilize the 'relay debugfs' interface
+are:
+1) Set up a 'relay debugfs' channel - relay_setup()
+2) Start the 'relay debugfs' channel - relay_start()
+3) Write one or more 'relay debugfs' records into the channel (using the relay
+   API).
+
+   Important: When writing a 'relay debugfs' record the provider must insure
+   that preemption is disabled and that 'relay debugfs' state is  set to
+   "running". A typical function used to write records into a 'relay debugfs'
+   channel should follow the following semantics:
+
+	rcu_read_lock();	    // disables preemption
+	if (relay_running(relay)){
+		relay_write(....); // use any available relay data
+				   // function
+	}
+	rcu_read_unlock();	   // enables preemption
+
+4) Stop and start tracing as desired - relay_start()/relay_stop()
+5) Destroy the 'relay debugfs' channel and underlying relay channel -
+   relay_cleanup().
+
+Kernel Configuration
+--------------------
+To use 'relay debugfs', configure your kernel with CONFIG_TRACE=y.
+'relay debugfs' depends on both CONFIG_RELAY and CONFIG_DEBUG_FS, these will be
+automatically configured when CONFIG_TRACE is selected (if not already
+configured).
+
+Using the User Interface
+------------------------
+Reading 'relay debugfs' data and controlling the 'relay debugfs' can be done
+using commands such as cat, echo and sort.  However, If you are logging binary
+'relay debugfs' data a custom application may be required to read and process
+the 'relay debugfs' data. This section shows several examples of reading
+'relay debugfs' data and controling the 'relay debugfs'.  All examples assume
+that the relay_debugfs directory is your current working directory.
+
+Viewing the current 'relay debugfs' state:
+$cat state
+
+Turning the 'relay debugfs' on and off:
+$echo start > state
+$echo stop > state
+
+Reading data when using global buffers (USE_GLOBAL_BUFFERS):
+$echo stop > state
+$cat  relay0
+$echo start > state
+
+Reading data when using per-cpu buffers:
+When using per-cpu buffers the user should add a time stamp or sequence
+number to each 'relay debugfs' records.  This is used by the consumer to sort
+the 'relay debugfs' records into chronological order.  In the following example
+the user has placed a time stamp at the front of each the record.  The format of
+a record is now shown.
+
+:<time stamp>:<field 1>:<field 2>:..........
+
+Collect the data from the per-cpu 'relay debugfs' buffers, sorting
+chronologically:
+$sort --field-separator=: --key=2.1 relay*
+
+Verify that no data was lost by examining the dropped file:
+$ cat  dropped
+
+To collect a larger amount of data the 'relay debugfs' buffers can be read
+continuously using something like:
+
+while [ 1 ] ; do
+	sort --field-separator=: --key=2.1   relay*
+done
 
 Resources
 =========
@@ -493,3 +700,11 @@ Tom Zanussi		<[email protected]>
 
 Also thanks to Hubertus Franke for a lot of useful suggestions and bug
 reports.
+
+'relay debugfs' is adapted from blktrace authored by Jens Axboe
+([email protected]).
+
+Major contributions were made by:
+Tom Zanussi <[email protected]>
+Martin Hunt <[email protected]>
+David Wilder <[email protected]>
Documentation/trace.txt deleted +0 -210

210 lines not on this page · raw message

author
#2 lore raw

PATCH 2/2 Renaming lib/trace.[ch] files to kernel/relay_debugfs.[ch] and enhancements

In reply to K.Prasad

This patch renames the lib/trace.[ch] files to kernel/relay_debugfs.[ch]. Also present are the changes to rename the "trace_*" functions to "relay_*".

Two new functions which provide an easy-to-use interface for relay called relay_printk() and relay_dump() are also introduced (earlier called as trace_printk() and trace_dump()).

---
 Documentation/filesystems/relay.txt |   22 +
 include/linux/relay_debugfs.h       |  155 +++++++
 include/linux/trace.h               |   99 ----
 init/Kconfig                        |    9 
 kernel/Makefile                     |    1 
 kernel/relay_debugfs.c              |  760 ++++++++++++++++++++++++++++++++++++
 lib/Kconfig                         |    9 
 lib/Makefile                        |    2 
 lib/trace.c                         |  563 --------------------------
 samples/Kconfig                     |    8 
 samples/Makefile                    |    2 
 samples/relay/Makefile              |    4 
 samples/relay/fork_trace.c          |  132 ++++++
 samples/trace/Makefile              |    4 
 samples/trace/fork_new_trace.c      |   99 ++++
 samples/trace/fork_trace.c          |  132 ------
 16 files changed, 1187 insertions(+), 814 deletions(-)
include/linux/relay_debugfs.h new file +155 -0
Index: linux-trace-relay-2.6.27-rc1-mm1/include/linux/relay_debugfs.h
===================================================================
@@ -0,0 +1,155 @@
+/*
+ * RELAY DEBUGFS defines and function prototypes
+ *
+ * Copyright (C) 2007 IBM Inc.
+ *
+ *	Tom Zanussi <[email protected]>
+ *	Martin Hunt <[email protected]>
+ *	David Wilder <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+#ifndef _LINUX_RELAY_DEBUGFS_H
+#define _LINUX_RELAY_DEBUGFS_H
+
+#include <linux/relay.h>
+
+/*
+ * RELAY DEBUGFS channel flags
+ */
+#define RELAY_GLOBAL_CHANNEL	0x01
+#define RELAY_FLIGHT_CHANNEL	0x02
+#define RELAY_DISABLE_STATE	0x04
+
+enum relay_state {
+	RELAY_SETUP,
+	RELAY_RUNNING,
+	RELAY_STOPPED,
+};
+
+enum relay_dir_state {
+	RELAY_PARENT_DIR_ABSENT,
+	RELAY_PARENT_DIR_EXISTS,
+	RELAY_DIR_EXISTS
+};
+
+#define RELAY_ROOT_NAME_SIZE	64	/* Max root dir identifier */
+#define RELAY_NAME_SIZE		64	/* Max relay identifier */
+
+/*
+ * Buffers for use by relay_printk
+ */
+#define DEFAULT_RELAY_BUF_SIZE 4096
+#define DEFAULT_RELAY_SUB_BUF_NR 40
+/*
+ * Global root user information
+ */
+struct relay_root {
+	struct list_head list;
+	char name[RELAY_ROOT_NAME_SIZE];
+	struct dentry *root;
+	unsigned int users;
+};
+
+/*
+ * Client information
+ */
+struct relay_info {
+	struct mutex state_mutex; /* Used to protect state changes */
+	enum relay_state state;
+	struct dentry *state_file;
+	struct rchan *rchan;
+	struct dentry *dir;
+	struct dentry *dropped_file;
+	struct dentry *reset_consumed_file;
+	struct dentry *nr_sub_file;
+	struct dentry *sub_size_file;
+	atomic_t dropped;
+	struct relay_root *root;
+	void *private_data;
+	unsigned int flags;
+	unsigned int buf_size;
+	unsigned int buf_nr;
+	spinlock_t relay_lock;
+};
+
+struct relay_printk_data {
+	char *parent_dir;
+	char *dir;
+	int exists;
+	int buf_size;
+	int sub_buf_size;
+	unsigned long flags;
+	struct relay_info *ti;
+};
+
+/*
+ * Information about every 'relay debugfs' directory
+ */
+struct relay_dir {
+	struct list_head relay_dir_list;
+	char relay_dir_name[RELAY_NAME_SIZE];
+	struct dentry *relay_root;
+	struct dentry *relay_dir;
+	struct relay_info *ti;
+};
+
+#ifdef CONFIG_RELAY_DEBUGFS
+static inline int relay_running(struct relay_info *relay)
+{
+	return relay->state == RELAY_RUNNING;
+}
+struct relay_info *relay_setup(const char *root, const char *name,
+			       u32 buf_size, u32 buf_nr, u32 flags);
+int relay_start(struct relay_info *relay);
+int relay_stop(struct relay_info *relay);
+void relay_cleanup(struct relay_info *relay);
+int relay_exists(const char *parent_dir, const char *dir,
+					struct relay_info **ti);
+void relay_cleanup_all(const char *parent_dir);
+int relay_printk(struct relay_printk_data *dpk, char *format, ...);
+int relay_dump(struct relay_printk_data *dpk, const void *output,
+							const int output_len);
+#else
+static inline struct relay_info *relay_setup(const char *root,
+					     const char *name, u32 buf_size,
+					     u32 buf_nr, u32 flags)
+{
+	return NULL;
+}
+static inline int relay_start(struct relay_info *relay) { return -EINVAL; }
+static inline int relay_stop(struct relay_info *relay) { return -EINVAL; }
+static inline int relay_running(struct relay_info *relay) { return 0; }
+static inline void relay_cleanup(struct relay_info *relay) {}
+static inline int relay_exists(const char *parent_dir, const char *dir,
+				struct relay_info **ti)
+{
+	return -EINVAL;
+}
+static inline void relay_cleanup_all(const char *parent_dir) {}
+static inline int relay_printk(struct relay_printk_data *dpk, char *format,
+				...)
+{
+	return -EINVAL;
+}
+int relay_dump(struct relay_printk_data *dpk, const void *output,
+							const int output_len)
+{
+	return -EINVAL;
+}
+
+#endif
+
+#endif /* ifdef CONFIG_RELAY_DEBUGFS */
include/linux/trace.h deleted +0 -99

99 lines not on this page · raw message

kernel/relay_debugfs.c new file +760 -0

760 lines not on this page · raw message

lib/trace.c deleted +0 -563

563 lines not on this page · raw message

init/Kconfig +9 -0
Index: linux-trace-relay-2.6.27-rc1-mm1/init/Kconfig
===================================================================
@@ -460,6 +460,15 @@ config RELAY
 
 	  If unsure, say N.
 
+config RELAY_DEBUGFS
+	bool "Relay debugfs setup and control"
+	depends on RELAY && DEBUG_FS
+	help
+	  This option provides support for the setup, teardown and control
+	  of relay channels from kernel code which are mounted on debugfs.
+	  It also provides information and control to userspace via a set of
+	  debugfs control files.  If unsure, say N.
+
 config NAMESPACES
 	bool "Namespaces support" if EMBEDDED
 	default !EMBEDDED
kernel/Makefile +1 -0
Index: linux-trace-relay-2.6.27-rc1-mm1/kernel/Makefile
===================================================================
@@ -77,6 +77,7 @@ ifeq ($(CONFIG_PREEMPT_RCU),y)
 obj-$(CONFIG_RCU_TRACE) += rcupreempt_trace.o
 endif
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_RELAY_DEBUGFS) += relay_debugfs.o
 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
lib/Kconfig +0 -9
Index: linux-trace-relay-2.6.27-rc1-mm1/lib/Kconfig
===================================================================
@@ -157,13 +157,4 @@ config CHECK_SIGNATURE
 config HAVE_LMB
 	boolean
 
-config TRACE
-	bool "Trace setup and control"
-	depends on RELAY && DEBUG_FS
-	help
-	  This option provides support for the setup, teardown and control
-	  of tracing channels from kernel code.  It also provides trace
-	  information and control to userspace via a set of debugfs control
-	  files.  If unsure, say N.
-
 endmenu
lib/Makefile +0 -2
Index: linux-trace-relay-2.6.27-rc1-mm1/lib/Makefile
===================================================================
@@ -82,8 +82,6 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o
 
 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
 
-obj-$(CONFIG_TRACE) += trace.o
-
 obj-$(CONFIG_PROFILE_LIKELY) += likely_prof.o
 
 hostprogs-y	:= gen_crc32table
samples/relay/Makefile new file +4 -0
Index: linux-trace-relay-2.6.27-rc1-mm1/samples/relay/Makefile
===================================================================
@@ -0,0 +1,4 @@
+# builds the trace example kernel modules;
+# then to use (as root):  insmod <fork_trace.ko>
+
+obj-$(CONFIG_SAMPLE_RELAY) := fork_trace.o fork_new_trace.o
samples/relay/fork_trace.c new file +132 -0

132 lines not on this page · raw message

samples/trace/Makefile deleted +0 -4
Index: linux-trace-relay-2.6.27-rc1-mm1/samples/trace/Makefile
===================================================================
@@ -1,4 +0,0 @@
-# builds the trace example kernel modules;
-# then to use (as root):  insmod <fork_trace.ko>
-
-obj-$(CONFIG_SAMPLE_TRACE) := fork_trace.o
samples/trace/fork_trace.c deleted +0 -132

132 lines not on this page · raw message

samples/Kconfig +4 -4
Index: linux-trace-relay-2.6.27-rc1-mm1/samples/Kconfig
===================================================================
@@ -33,11 +33,11 @@ config SAMPLE_KRETPROBES
 	default m
 	depends on SAMPLE_KPROBES && KRETPROBES
 
-config SAMPLE_TRACE
-	tristate "Build trace example -- loadable modules only"
-	depends on TRACE && KPROBES && m
+config SAMPLE_RELAY
+	tristate "Build relay debugfs example -- loadable modules only"
+	depends on RELAY && KPROBES && m
 	help
-	  This builds a trace example module.
+	  This builds a relay debugfs example module.
 
 endif # SAMPLES
 
samples/Makefile +1 -1
Index: linux-trace-relay-2.6.27-rc1-mm1/samples/Makefile
===================================================================
@@ -1,3 +1,3 @@
 # Makefile for Linux samples code
 
-obj-$(CONFIG_SAMPLES)	+= markers/ kobject/ kprobes/ trace/
+obj-$(CONFIG_SAMPLES)	+= markers/ kobject/ kprobes/ relay/
Documentation/filesystems/relay.txt +22 -0
Index: linux-trace-relay-2.6.27-rc1-mm1/Documentation/filesystems/relay.txt
===================================================================
@@ -637,6 +637,28 @@ are:
 5) Destroy the 'relay debugfs' channel and underlying relay channel -
    relay_cleanup().
 
+Alternatively the user may choose to make use of two new interfaces --
+relay_printk() and relay_dump() -- to setup trace interface and
+relay_cleanup_all() to tear-down the same.
+
+Steps to use:
+1) Create and populate an instance of relay_printk_data structure. The fields
+   parent_dir and dir are mandatory. The fields buf_size, sub_buf_size and flags
+   are optional and will take default values if not populated. The field
+   'exists' and ti are for the trace infrastructure to use. The pointer to the
+   'struct relay_info' i.e. ti may be used to perform fine granular operations
+   such as determine the state of the 'trace', stop individual traces, etc.
+2) Default values for buf_size and sub_buf_size are 4096, 40 respectively.
+3) Use relay_dump() to output binary data which may be acted upon by a
+   high-level program (say dumping a structure). relay_printk() can be used
+   for string output. Pass a pointer to the instance of relay_printk_data
+   structure to these functions along with other parameters. The output from
+   these functions can be found at
+   <debugfs_mount>/<parent_dir>/<dir>/trace<0..n>.
+4) relay_cleanup_all() for a given parent directory will cleanup and remove all
+   trace directories created under the specified directory.
+5) Sample code for the same can be found in samples/trace/fork_new_trace.c
+
 Kernel Configuration
 --------------------
 To use 'relay debugfs', configure your kernel with CONFIG_TRACE=y.
samples/trace/fork_new_trace.c new file +99 -0

99 lines not on this page · raw message

maintainer
#3 lore raw

Re: [Patch 2/2] Renaming lib/trace.[ch] files to kernel/relay_debugfs.[ch] and enhancements

Quoted 7 lines · On Mon, 4 Aug 2008 09:38:09 +0530 "K.Prasad" <[email protected]> wrote:

This patch renames the lib/trace.[ch] files to kernel/relay_debugfs.[ch]. Also present are the changes to rename the "trace_*" functions to "relay_*".

Two new functions which provide an easy-to-use interface for relay called relay_printk() and relay_dump() are also introduced (earlier called as trace_printk() and trace_dump()).

akpm2:/usr/src/25> make M=samples

  LD      samples/kobject/built-in.o
  CC [M]  samples/kobject/kobject-example.o
  CC [M]  samples/kobject/kset-example.o
  LD      samples/kprobes/built-in.o
  CC [M]  samples/kprobes/kprobe_example.o
  CC [M]  samples/kprobes/jprobe_example.o
  CC [M]  samples/kprobes/kretprobe_example.o
  LD      samples/markers/built-in.o
  CC [M]  samples/markers/probe-example.o
  CC [M]  samples/markers/marker-example.o
  LD      samples/relay/built-in.o
  CC [M]  samples/relay/fork_trace.o

make[2]: *** No rule to make target samples/relay/fork_new_trace.c', needed by samples/relay/fork_new_trace.o'. Stop.

author
#4 lore raw

Re: [Patch 2/2] Renaming lib/trace.[ch] files to kernel/relay_debugfs.[ch] and enhancements

Quoted 23 lines · Andrew Morton
Quoted 7 lines · On Mon, 4 Aug 2008 09:38:09 +0530 "K.Prasad" <[email protected]> wrote:

This patch renames the lib/trace.[ch] files to kernel/relay_debugfs.[ch]. Also present are the changes to rename the "trace_*" functions to "relay_*".

Two new functions which provide an easy-to-use interface for relay called relay_printk() and relay_dump() are also introduced (earlier called as trace_printk() and trace_dump()).

akpm2:/usr/src/25> make M=samples

  LD      samples/kobject/built-in.o
  CC [M]  samples/kobject/kobject-example.o
  CC [M]  samples/kobject/kset-example.o
  LD      samples/kprobes/built-in.o
  CC [M]  samples/kprobes/kprobe_example.o
  CC [M]  samples/kprobes/jprobe_example.o
  CC [M]  samples/kprobes/kretprobe_example.o
  LD      samples/markers/built-in.o
  CC [M]  samples/markers/probe-example.o
  CC [M]  samples/markers/marker-example.o
  LD      samples/relay/built-in.o
  CC [M]  samples/relay/fork_trace.o
Quoted 1 line

make[2]: *** No rule to make target samples/relay/fork_new_trace.c', needed by samples/relay/fork_new_trace.o'. Stop.

Found that the build breakage is due to fork_new_trace.c still lying in samples/trace/ directory.

Kindly apply the patch below which moves samples/trace/fork_new_trace.c to samples/relay/. Also remove the empty directory samples/trace (unable to show the same in the diff).

I have verified that the build happens fine after applying this patch on an x86 machine with default configs.

Thanks,
K.Prasad

Moves fork_new_trace.c file into samples/relay directory.

---
 samples/relay/fork_new_trace.c |   99 +++++++++++++++++++++++++++++++++++++++++
 samples/trace/fork_new_trace.c |   99 -----------------------------------------
 2 files changed, 99 insertions(+), 99 deletions(-)
samples/relay/fork_new_trace.c new file +99 -0
Index: linux-2.6.27-rc1-mm1/samples/relay/fork_new_trace.c
===================================================================
@@ -0,0 +1,99 @@
+/*
+ * An example of using trace in a kprobes module
+ *
+ * Copyright (C) 2008 IBM Inc.
+ *
+ * K.Prasad <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * -------
+ * This module creates a trace channel and places a kprobe
+ * on the function do_fork(). The value of current->pid is written to
+ * the trace channel each time the kprobe is hit..
+ *
+ * How to run the example:
+ * $ mount -t debugfs /debug
+ * $ insmod fork_new_trace.ko
+ *
+ * To view the data produced by the module:
+ * $ cat /debug/relay_example/do_fork/trace0
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/kprobes.h>
+#include <linux/relay_debugfs.h>
+
+#define SAMPLE_PARENT_DIR "relay_new_example"
+#define PROBE_POINT "do_fork"
+
+static struct kprobe kp;
+static struct relay_printk_data *tpk;
+
+static int handler_pre(struct kprobe *p, struct pt_regs *regs)
+{
+	relay_printk(tpk, "%d\n", current->pid);
+	return 0;
+}
+
+int init_module(void)
+{
+	int ret = 0;
+	int len_parent_dir, len_dir;
+
+	/* setup the kprobe */
+	kp.pre_handler = handler_pre;
+	kp.post_handler = NULL;
+	kp.fault_handler = NULL;
+	kp.symbol_name = PROBE_POINT;
+	ret = register_kprobe(&kp);
+	if (ret) {
+		printk(KERN_ERR "fork_trace: register_kprobe failed\n");
+		return ret;
+	}
+
+	len_parent_dir = strlen(SAMPLE_PARENT_DIR) + 1;
+	/* Initialising len_dir to the larger of the two dir names */
+	len_dir = strlen("kprobe_struct") + 1;
+
+	tpk = kzalloc(sizeof(*tpk), GFP_KERNEL);
+	if (!tpk)
+		ret = 1;
+
+	tpk->parent_dir = SAMPLE_PARENT_DIR;
+
+	/* Let's do a binary dump of struct kprobe using relay_dump */
+	tpk->dir = "kprobes_struct";
+	tpk->flags = RELAY_GLOBAL_CHANNEL;
+	relay_dump(tpk, &kp, sizeof(kp));
+
+	/* Now change the directory to collect fork pid data */
+	tpk->dir = PROBE_POINT;
+
+	if (ret)
+		printk(KERN_ERR "Unable to find required free memory. "
+				"Trace new sample module loading aborted");
+	return ret;
+}
+
+void cleanup_module(void)
+{
+	unregister_kprobe(&kp);
+
+	/* Just a single cleanup call passing the parent dir string */
+	relay_cleanup_all(SAMPLE_PARENT_DIR);
+}
+MODULE_LICENSE("GPL");
samples/trace/fork_new_trace.c deleted +0 -99

99 lines not on this page · raw message

maintainer
#5 lore raw
In reply to K.Prasad
Quoted 5 lines · On Mon, 4 Aug 2008 09:34:39 +0530 "K.Prasad" <[email protected]> wrote:

Hi Andrew,
Please find the patches that enhance the 'trace' infrastructure
(available in the -mm tree) and which introduce two new APIs relay_dump() and relay_printk().

Quoted 7 lines

These patches were submitted earlier as enhancements to trace, but were renamed and merged with 'relay' based on your suggestion
(http://lkml.org/lkml/2008/5/28/207).

The patches apply on 2.6.27-rc1-mm1 and have been tested on an x86 machine. Kindly accept them.

I'm a bit perplexed by these trace patches
(http://userweb.kernel.org/~akpm/mmotm/broken-out/trace-code-and-documentation.patch).
Is it useful? Will it be useful? Has anyone expressed
interest/intent to use it, etc? I haven't heard much noise about it and I'm struggling to justify merging it.

Also, it's starting to look somewhat similar to ftrace, which also provides sort of high-bandwidth per-cpu channels into userspace for tracing purposes.

#6 lore raw
Quoted 10 lines · Andrew Morton

[...]

Quoted 4 lines

Please find the patches that enhance the 'trace' infrastructure
(available in the -mm tree) and which introduce two new APIs relay_dump() and relay_printk().
[...]

I'm a bit perplexed by these trace patches
(http://userweb.kernel.org/~akpm/mmotm/broken-out/trace-code [...] Is it useful? Will it be useful? [...] I haven't heard much noise about it and I'm struggling to justify merging it.

Right.

Quoted 3 lines

Also, it's starting to look somewhat similar to ftrace, which also provides sort of high-bandwidth per-cpu channels into userspace for tracing purposes.

Perhaps ftrace ought to use this facility for its debugfs-facing bulk data interface rather than an internal one that cannot be used by anyone else. Perhaps lttng could use it. Systemtap could. I believe a grand unification at this level was the idea.

- FChE

author
#7 lore raw
Quoted 15 lines · Frank Ch. Eigler
Quoted 10 lines · Andrew Morton

[...]

Quoted 4 lines

Please find the patches that enhance the 'trace' infrastructure
(available in the -mm tree) and which introduce two new APIs relay_dump() and relay_printk().
[...]

I'm a bit perplexed by these trace patches
(http://userweb.kernel.org/~akpm/mmotm/broken-out/trace-code [...] Is it useful? Will it be useful? [...] I haven't heard much noise about it and I'm struggling to justify merging it.

Right.

Quoted 9 lines
Quoted 3 lines

Also, it's starting to look somewhat similar to ftrace, which also provides sort of high-bandwidth per-cpu channels into userspace for tracing purposes.

Perhaps ftrace ought to use this facility for its debugfs-facing bulk data interface rather than an internal one that cannot be used by anyone else. Perhaps lttng could use it. Systemtap could. I believe a grand unification at this level was the idea.

Hi Andrew,
The 'relay_printk' and 'relay_dump' interfaces were meant to
provide clutter-free tracing interface for the user who does not want to care much beyond getting his trace output to user-space. It greatly helps reduce the amount of work that a tracer needs to perform to setup and tear-down. For e.g. when the Block I/O tracing code in block/blktrace.c was converted to use these interfaces they resulted in code-reduction of ~130 lines (http://lkml.org/lkml/2008/5/16/318).

The default values can work fine for most tunables and are also exposed to the user for overriding them.

These interfaces will be helpful in almost all non-blocking tracers (unlike usbmon which displays information in real-time) and uses the scalable infrastructure provided by 'relay'.

As pointed out by Frank earlier, most tracers (including ftrace) can be made to use the above-mentioned interfaces resulting in substantial savings in terms of LoC and increasing modularity/code re-usability.

Thanks,
K.Prasad

maintainer
#8 lore raw
Quoted 38 lines · On Fri, 8 Aug 2008 09:22:39 +0530 "K.Prasad" <[email protected]> wrote:
Quoted 15 lines · Frank Ch. Eigler
Quoted 10 lines · Andrew Morton

[...]

Quoted 4 lines

Please find the patches that enhance the 'trace' infrastructure
(available in the -mm tree) and which introduce two new APIs relay_dump() and relay_printk().
[...]

I'm a bit perplexed by these trace patches
(http://userweb.kernel.org/~akpm/mmotm/broken-out/trace-code [...] Is it useful? Will it be useful? [...] I haven't heard much noise about it and I'm struggling to justify merging it.

Right.

Quoted 9 lines
Quoted 3 lines

Also, it's starting to look somewhat similar to ftrace, which also provides sort of high-bandwidth per-cpu channels into userspace for tracing purposes.

Perhaps ftrace ought to use this facility for its debugfs-facing bulk data interface rather than an internal one that cannot be used by anyone else. Perhaps lttng could use it. Systemtap could. I believe a grand unification at this level was the idea.

Hi Andrew,
The 'relay_printk' and 'relay_dump' interfaces were meant to
provide clutter-free tracing interface for the user who does not want to care much beyond getting his trace output to user-space. It greatly helps reduce the amount of work that a tracer needs to perform to setup and tear-down. For e.g. when the Block I/O tracing code in block/blktrace.c was converted to use these interfaces they resulted in code-reduction of ~130 lines (http://lkml.org/lkml/2008/5/16/318).

The default values can work fine for most tunables and are also exposed to the user for overriding them.

Quoted 8 lines

These interfaces will be helpful in almost all non-blocking tracers (unlike usbmon which displays information in real-time) and uses the scalable infrastructure provided by 'relay'.

As pointed out by Frank earlier, most tracers (including ftrace) can be made to use the above-mentioned interfaces resulting in substantial savings in terms of LoC and increasing modularity/code re-usability.

Oh, OK, that's a good case.

Was the result of your blktrace conversion compatible with existing interfaces?

It would be higly persuasive if we were to see at least a prototype conversion of ftrace to use this new code (hint :))

On a naming note: I am officially utterly bewildered by the number of subsystems which call themselves "trace" or "footrace" or "tracebar". And we have at least one more (ltt) (a footracebar!) heading in our direction.

y:/usr/src/linux-2.6.27-rc2> find -type f -a -name '*trace*' | wc -l 144

(!)

Is there something we can do to bring order out of chaos here?