[lttng-dev] [PATCH] Create kernel events by writing to proc file

Francis Giraldeau francis.giraldeau at gmail.com
Thu May 10 09:36:34 EDT 2012


Le mercredi 09 mai 2012 à 14:04 -0400, Mathieu Desnoyers a écrit :
> * Francis Giraldeau (francis.giraldeau at gmail.com) wrote:
> > This feature allow to write events in the kernel trace stream by writing to the
> > file /proc/lttng_user_event. The content is written unmodified to the trace as
> > string type. The maximum string length saved per event is 256 bytes. The event
> > type and the proc file are accessibles when the module lttng-user-event is
> > loaded.
> > 
> > This is a prototype implementation. The final implementation should avoid the
> > temp copy of the string on the kernel stack.
> > ---
> >  Makefile                                    |    1 +
> >  instrumentation/events/lttng-module/lttng.h |   19 +++
> >  probes/Makefile                             |    1 +
> >  probes/lttng-user-event.c                   |  159 +++++++++++++++++++++++++++
> >  4 files changed, 180 insertions(+), 0 deletions(-)
> >  create mode 100644 probes/lttng-user-event.c
> > 
> > diff --git a/Makefile b/Makefile
> > index dfa0792..6bd203d 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -24,6 +24,7 @@ lttng-tracer-objs :=  lttng-events.o lttng-abi.o \
> >  
> >  obj-m += lttng-statedump.o
> >  lttng-statedump-objs := lttng-statedump-impl.o wrapper/irqdesc.o
> > +lttng-user-event-objs := lttng-user-event.o
> >  
> >  ifneq ($(CONFIG_HAVE_SYSCALL_TRACEPOINTS),)
> >  lttng-tracer-objs += lttng-syscalls.o
> > diff --git a/instrumentation/events/lttng-module/lttng.h b/instrumentation/events/lttng-module/lttng.h
> > index 6f3d6d1..9da3c7e 100644
> > --- a/instrumentation/events/lttng-module/lttng.h
> > +++ b/instrumentation/events/lttng-module/lttng.h
> > @@ -6,6 +6,8 @@
> >  
> >  #include <linux/tracepoint.h>
> >  
> > +#define LTTNG_UEVENT_SIZE 256
> > +
> >  TRACE_EVENT(lttng_metadata,
> >  
> >  	TP_PROTO(const char *str),
> > @@ -28,6 +30,23 @@ TRACE_EVENT(lttng_metadata,
> >  	TP_printk("")
> >  )
> >  
> > +TRACE_EVENT(lttng_uevent,
> > +
> > +	TP_PROTO(char *str),
> > +
> > +	TP_ARGS(str),
> > +
> > +	TP_STRUCT__entry(
> > +		__array_text(	char,	text,	LTTNG_UEVENT_SIZE	)
> > +	),
> > +
> > +	TP_fast_assign(
> > +		tp_memcpy(text, str, LTTNG_UEVENT_SIZE)
> 
> FYI, we have __string_from_user and tp_copy_string_from_user for that
> (you won't have to do the copy).

Ok, did an experiment to compare TP, see next message.

> > + * This library is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; only
> > + * version 2.1 of the License.
> 
> This file should be GPLv2, as below one function states that it is
> inspired from tracing_mark_write in the Linux kernel, which is licensed
> GPLv2. Or simply reimplement write_event: it will become _trivial_ with
> the proper zero-copy approach hinted at above.

Ok, will take that into account for the final version.

> > +struct proc_dir_entry *lttng_root;
> 
> static.

Removed anyway...

> > +	/* lttng is already a file with the current abi, not a directory */
> > +	/*
> > +	lttng_root = proc_mkdir("lttng", NULL);
> 
> why do you mkdir lttng ? It conflicts with /proc/lttng.

Yeah, that's why it was disabled. I removed it. It would have been great
if /proc/lttng was a directory, because then all related files could
have been added into it.
(ex: /proc/lttng/control, /proc/lttng/user_event, etc.) I guess that,
since old clients uses /proc/lttng, it's cast in stone, isn't?

Francis




More information about the lttng-dev mailing list