Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [lttng-dev] Expose kernel tracer to user-space
@ 2012-06-05  9:20 Francis Giraldeau
  2012-06-05  9:20 ` [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro Francis Giraldeau
  2012-06-05  9:20 ` [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space Francis Giraldeau
  0 siblings, 2 replies; 5+ messages in thread
From: Francis Giraldeau @ 2012-06-05  9:20 UTC (permalink / raw)


This series of patch follows the discussion about exposing kernel tracer to
user-space. Here are few highlights:

  * Creates one lttng_uevent kernel event by writing to /proc/lttng
  * The event is a variable size byte sequence, parsed by default as UTF-8 text
  * Uses already existing /proc/lttng file instead of creating another
  * Refactor the tp_memcpy macros to support sequence and copy_from_user




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro
  2012-06-05  9:20 [lttng-dev] Expose kernel tracer to user-space Francis Giraldeau
@ 2012-06-05  9:20 ` Francis Giraldeau
  2012-06-05 15:14   ` Mathieu Desnoyers
  2012-06-05  9:20 ` [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space Francis Giraldeau
  1 sibling, 1 reply; 5+ messages in thread
From: Francis Giraldeau @ 2012-06-05  9:20 UTC (permalink / raw)


Memcpy source can be either user-space or kernel-space. To avoid code
duplication, this patch makes the operation a parameter to the macros.
Available macros are thus:

* tp_memcpy:               kernel-space array copy
* tp_memcpy_from_user:     user-space array copy
* tp_memcpy_dyn:           kernel-space sequence copy
* tp_memcpy_dyn_from_user: user-space sequence copy

Those are TP_fast_assign macros that can be used with __dynamic_array
macros in TP_STRUCT__entry in a TRACE_EVENT.

Signed-off-by: Francis Giraldeau <francis.giraldeau at gmail.com>
---
 probes/lttng-events.h |   37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/probes/lttng-events.h b/probes/lttng-events.h
index 05e17b9..492423a 100644
--- a/probes/lttng-events.h
+++ b/probes/lttng-events.h
@@ -523,17 +523,27 @@ __assign_##dest:							\
 	}								\
 	goto __end_field_##dest;
 
-#undef tp_memcpy
-#define tp_memcpy(dest, src, len)					\
+/* fixed length array memcpy */
+#undef tp_memcpy_gen
+#define tp_memcpy_gen(write_ops, dest, src, len)			\
 __assign_##dest:							\
 	if (0)								\
 		(void) __typemap.dest;					\
 	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
-	__chan->ops->event_write(&__ctx, src, len);			\
+	__chan->ops->write_ops(&__ctx, src, len);			\
 	goto __end_field_##dest;
 
-#undef tp_memcpy_dyn
-#define tp_memcpy_dyn(dest, src)					\
+#undef tp_memcpy
+#define tp_memcpy(dest, src, len)					\
+	tp_memcpy_gen(event_write, dest, src, len)
+
+#undef tp_memcpy_from_user
+#define tp_memcpy_from_user(dest, src, len)				\
+	tp_memcpy_gen(event_write_from_user, dest, src, len)
+
+/* variable length sequence memcpy */
+#undef tp_memcpy_dyn_gen
+#define tp_memcpy_dyn_gen(write_ops, dest, src)				\
 __assign_##dest##_1:							\
 	{								\
 		u32 __tmpl = __dynamic_len[__dynamic_len_idx];		\
@@ -543,18 +553,17 @@ __assign_##dest##_1:							\
 	goto __end_field_##dest##_1;					\
 __assign_##dest##_2:							\
 	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
-	__chan->ops->event_write(&__ctx, src,				\
+	__chan->ops->write_ops(&__ctx, src,				\
 		sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
 	goto __end_field_##dest##_2;
 
-#undef tp_memcpy_from_user
-#define tp_memcpy_from_user(dest, src, len)				\
-	__assign_##dest:						\
-	if (0)								\
-		(void) __typemap.dest;					\
-	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
-	__chan->ops->event_write_from_user(&__ctx, src, len);		\
-	goto __end_field_##dest;
+#undef tp_memcpy_dyn
+#define tp_memcpy_dyn(dest, src)					\
+	tp_memcpy_dyn_gen(event_write, dest, src)
+
+#undef tp_memcpy_dyn_from_user
+#define tp_memcpy_dyn_from_user(dest, src)				\
+	tp_memcpy_dyn_gen(event_write_from_user, dest, src)
 
 /*
  * The string length including the final \0.
-- 
1.7.9.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space
  2012-06-05  9:20 [lttng-dev] Expose kernel tracer to user-space Francis Giraldeau
  2012-06-05  9:20 ` [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro Francis Giraldeau
@ 2012-06-05  9:20 ` Francis Giraldeau
  2012-06-05 15:16   ` Mathieu Desnoyers
  1 sibling, 1 reply; 5+ messages in thread
From: Francis Giraldeau @ 2012-06-05  9:20 UTC (permalink / raw)


By writing to the file /proc/lttng, a user-space application creates a
kernel event. The event's payload is by default UTF-8 text, but any data
can be written, up to 1024 bytes. Null-character is optional and is not
enforced. The event uses sequence for space efficiency and to store any
data as payload.

Signed-off-by: Francis Giraldeau <francis.giraldeau at gmail.com>
---
 instrumentation/events/lttng-module/lttng.h |   21 +++++++++++++++++++++
 lttng-abi.c                                 |   20 ++++++++++++++++++++
 lttng-abi.h                                 |    1 +
 3 files changed, 42 insertions(+)

diff --git a/instrumentation/events/lttng-module/lttng.h b/instrumentation/events/lttng-module/lttng.h
index 6f3d6d1..cc36a8b 100644
--- a/instrumentation/events/lttng-module/lttng.h
+++ b/instrumentation/events/lttng-module/lttng.h
@@ -28,6 +28,27 @@ TRACE_EVENT(lttng_metadata,
 	TP_printk("")
 )
 
+TRACE_EVENT(lttng_uevent,
+
+	TP_PROTO(const char *str, size_t len),
+
+	TP_ARGS(str, len),
+
+	/*
+	 * Uses sequence to hold variable size data, by default considered
+	 * as text. Null-terminal character is optional and is not enforced.
+	 */
+	TP_STRUCT__entry(
+		__dynamic_array_text(char, text, len)
+	),
+
+	TP_fast_assign(
+		tp_memcpy_dyn_from_user(text, str)
+	),
+
+	TP_printk("")
+)
+
 #endif /*  _TRACE_LTTNG_H */
 
 /* This part must be outside protection */
diff --git a/lttng-abi.c b/lttng-abi.c
index 26a02ed..fa29e53 100644
--- a/lttng-abi.c
+++ b/lttng-abi.c
@@ -50,6 +50,10 @@
 #include "lttng-events.h"
 #include "lttng-tracer.h"
 
+/* include our own uevent tracepoint */
+#include "instrumentation/events/lttng-module/lttng.h"
+DEFINE_TRACE(lttng_uevent);
+
 /*
  * This is LTTng's own personal way to create a system call as an external
  * module. We use ioctl() on /proc/lttng.
@@ -252,9 +256,25 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	}
 }
 
+/*
+ * lttng_write_uevent - expose kernel tracer to user-space
+ */
+
+static
+ssize_t lttng_write_uevent(struct file *file, const char __user *user_buf,
+		    size_t count, loff_t *fpos)
+{
+	if (count > LTTNG_UEVENT_SIZE)
+		count = LTTNG_UEVENT_SIZE;
+
+	trace_lttng_uevent(user_buf, count);
+	return count;
+}
+
 static const struct file_operations lttng_fops = {
 	.owner = THIS_MODULE,
 	.unlocked_ioctl = lttng_ioctl,
+	.write = lttng_write_uevent,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = lttng_ioctl,
 #endif
diff --git a/lttng-abi.h b/lttng-abi.h
index dc230d8..f99b037 100644
--- a/lttng-abi.h
+++ b/lttng-abi.h
@@ -26,6 +26,7 @@
 #include <linux/fs.h>
 
 #define LTTNG_KERNEL_SYM_NAME_LEN	256
+#define LTTNG_UEVENT_SIZE		1024
 
 enum lttng_kernel_instrumentation {
 	LTTNG_KERNEL_TRACEPOINT	= 0,
-- 
1.7.9.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro
  2012-06-05  9:20 ` [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro Francis Giraldeau
@ 2012-06-05 15:14   ` Mathieu Desnoyers
  0 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2012-06-05 15:14 UTC (permalink / raw)


* Francis Giraldeau (francis.giraldeau at gmail.com) wrote:
> Memcpy source can be either user-space or kernel-space. To avoid code
> duplication, this patch makes the operation a parameter to the macros.
> Available macros are thus:
> 
> * tp_memcpy:               kernel-space array copy
> * tp_memcpy_from_user:     user-space array copy
> * tp_memcpy_dyn:           kernel-space sequence copy
> * tp_memcpy_dyn_from_user: user-space sequence copy
> 
> Those are TP_fast_assign macros that can be used with __dynamic_array
> macros in TP_STRUCT__entry in a TRACE_EVENT.

Merged, thanks !

Mathieu

> 
> Signed-off-by: Francis Giraldeau <francis.giraldeau at gmail.com>
> ---
>  probes/lttng-events.h |   37 +++++++++++++++++++++++--------------
>  1 file changed, 23 insertions(+), 14 deletions(-)
> 
> diff --git a/probes/lttng-events.h b/probes/lttng-events.h
> index 05e17b9..492423a 100644
> --- a/probes/lttng-events.h
> +++ b/probes/lttng-events.h
> @@ -523,17 +523,27 @@ __assign_##dest:							\
>  	}								\
>  	goto __end_field_##dest;
>  
> -#undef tp_memcpy
> -#define tp_memcpy(dest, src, len)					\
> +/* fixed length array memcpy */
> +#undef tp_memcpy_gen
> +#define tp_memcpy_gen(write_ops, dest, src, len)			\
>  __assign_##dest:							\
>  	if (0)								\
>  		(void) __typemap.dest;					\
>  	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
> -	__chan->ops->event_write(&__ctx, src, len);			\
> +	__chan->ops->write_ops(&__ctx, src, len);			\
>  	goto __end_field_##dest;
>  
> -#undef tp_memcpy_dyn
> -#define tp_memcpy_dyn(dest, src)					\
> +#undef tp_memcpy
> +#define tp_memcpy(dest, src, len)					\
> +	tp_memcpy_gen(event_write, dest, src, len)
> +
> +#undef tp_memcpy_from_user
> +#define tp_memcpy_from_user(dest, src, len)				\
> +	tp_memcpy_gen(event_write_from_user, dest, src, len)
> +
> +/* variable length sequence memcpy */
> +#undef tp_memcpy_dyn_gen
> +#define tp_memcpy_dyn_gen(write_ops, dest, src)				\
>  __assign_##dest##_1:							\
>  	{								\
>  		u32 __tmpl = __dynamic_len[__dynamic_len_idx];		\
> @@ -543,18 +553,17 @@ __assign_##dest##_1:							\
>  	goto __end_field_##dest##_1;					\
>  __assign_##dest##_2:							\
>  	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
> -	__chan->ops->event_write(&__ctx, src,				\
> +	__chan->ops->write_ops(&__ctx, src,				\
>  		sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
>  	goto __end_field_##dest##_2;
>  
> -#undef tp_memcpy_from_user
> -#define tp_memcpy_from_user(dest, src, len)				\
> -	__assign_##dest:						\
> -	if (0)								\
> -		(void) __typemap.dest;					\
> -	lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));	\
> -	__chan->ops->event_write_from_user(&__ctx, src, len);		\
> -	goto __end_field_##dest;
> +#undef tp_memcpy_dyn
> +#define tp_memcpy_dyn(dest, src)					\
> +	tp_memcpy_dyn_gen(event_write, dest, src)
> +
> +#undef tp_memcpy_dyn_from_user
> +#define tp_memcpy_dyn_from_user(dest, src)				\
> +	tp_memcpy_dyn_gen(event_write_from_user, dest, src)
>  
>  /*
>   * The string length including the final \0.
> -- 
> 1.7.9.5
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space
  2012-06-05  9:20 ` [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space Francis Giraldeau
@ 2012-06-05 15:16   ` Mathieu Desnoyers
  0 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2012-06-05 15:16 UTC (permalink / raw)


* Francis Giraldeau (francis.giraldeau at gmail.com) wrote:
> By writing to the file /proc/lttng, a user-space application creates a
> kernel event. The event's payload is by default UTF-8 text, but any data
> can be written, up to 1024 bytes. Null-character is optional and is not
> enforced. The event uses sequence for space efficiency and to store any
> data as payload.

As discussed on IRC, please move the function to a separate module in
/probes/, and add a register function into lttng-abi.c that allows that
module to register its callback.

Thanks,

Mathieu

> 
> Signed-off-by: Francis Giraldeau <francis.giraldeau at gmail.com>
> ---
>  instrumentation/events/lttng-module/lttng.h |   21 +++++++++++++++++++++
>  lttng-abi.c                                 |   20 ++++++++++++++++++++
>  lttng-abi.h                                 |    1 +
>  3 files changed, 42 insertions(+)
> 
> diff --git a/instrumentation/events/lttng-module/lttng.h b/instrumentation/events/lttng-module/lttng.h
> index 6f3d6d1..cc36a8b 100644
> --- a/instrumentation/events/lttng-module/lttng.h
> +++ b/instrumentation/events/lttng-module/lttng.h
> @@ -28,6 +28,27 @@ TRACE_EVENT(lttng_metadata,
>  	TP_printk("")
>  )
>  
> +TRACE_EVENT(lttng_uevent,
> +
> +	TP_PROTO(const char *str, size_t len),
> +
> +	TP_ARGS(str, len),
> +
> +	/*
> +	 * Uses sequence to hold variable size data, by default considered
> +	 * as text. Null-terminal character is optional and is not enforced.
> +	 */
> +	TP_STRUCT__entry(
> +		__dynamic_array_text(char, text, len)
> +	),
> +
> +	TP_fast_assign(
> +		tp_memcpy_dyn_from_user(text, str)
> +	),
> +
> +	TP_printk("")
> +)
> +
>  #endif /*  _TRACE_LTTNG_H */
>  
>  /* This part must be outside protection */
> diff --git a/lttng-abi.c b/lttng-abi.c
> index 26a02ed..fa29e53 100644
> --- a/lttng-abi.c
> +++ b/lttng-abi.c
> @@ -50,6 +50,10 @@
>  #include "lttng-events.h"
>  #include "lttng-tracer.h"
>  
> +/* include our own uevent tracepoint */
> +#include "instrumentation/events/lttng-module/lttng.h"
> +DEFINE_TRACE(lttng_uevent);
> +
>  /*
>   * This is LTTng's own personal way to create a system call as an external
>   * module. We use ioctl() on /proc/lttng.
> @@ -252,9 +256,25 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  	}
>  }
>  
> +/*
> + * lttng_write_uevent - expose kernel tracer to user-space
> + */
> +
> +static
> +ssize_t lttng_write_uevent(struct file *file, const char __user *user_buf,
> +		    size_t count, loff_t *fpos)
> +{
> +	if (count > LTTNG_UEVENT_SIZE)
> +		count = LTTNG_UEVENT_SIZE;
> +
> +	trace_lttng_uevent(user_buf, count);
> +	return count;
> +}
> +
>  static const struct file_operations lttng_fops = {
>  	.owner = THIS_MODULE,
>  	.unlocked_ioctl = lttng_ioctl,
> +	.write = lttng_write_uevent,
>  #ifdef CONFIG_COMPAT
>  	.compat_ioctl = lttng_ioctl,
>  #endif
> diff --git a/lttng-abi.h b/lttng-abi.h
> index dc230d8..f99b037 100644
> --- a/lttng-abi.h
> +++ b/lttng-abi.h
> @@ -26,6 +26,7 @@
>  #include <linux/fs.h>
>  
>  #define LTTNG_KERNEL_SYM_NAME_LEN	256
> +#define LTTNG_UEVENT_SIZE		1024
>  
>  enum lttng_kernel_instrumentation {
>  	LTTNG_KERNEL_TRACEPOINT	= 0,
> -- 
> 1.7.9.5
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-05 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-05  9:20 [lttng-dev] Expose kernel tracer to user-space Francis Giraldeau
2012-06-05  9:20 ` [lttng-dev] [PATCH 1/2] Makes write operation a parameter for tp_memcpy macro Francis Giraldeau
2012-06-05 15:14   ` Mathieu Desnoyers
2012-06-05  9:20 ` [lttng-dev] [PATCH 2/2] Expose kernel tracer to user-space Francis Giraldeau
2012-06-05 15:16   ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox