All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH lttng-modules] LTTng logger ABI
@ 2014-02-15 22:08 Mathieu Desnoyers
  0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2014-02-15 22:08 UTC (permalink / raw)
  To: Karim Yaghmour; +Cc: lttng-dev

Add a user-space ABI (new file /proc/lttng-logger) to lttng-modules
which can be written into by any user on the system. The content is
saved into the kernel trace stream into the "lttng_logger" kernel event.

The content of a single write is written into an lttng_logger event,
provided the packet size is large enough to store the content. If it is
not large enough, it won't be logged. However we cannot return any error
to the caller, since there may be more than one trace session listening
to this event.

Example use:

Enable the "lttng_logger" event.

echo -n "this is a test" > /proc/lttng-logger

Result in babeltrace output:

[17:00:04.251970425] (+179.750663203) thinkos lttng_logger: { cpu_id = 3 }, { _msg_length = 14, msg = "this is a test" }

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Karim Yaghmour <karim.yaghmour@opersys.com>
---
 Makefile                                    |    3 +-
 instrumentation/events/lttng-module/lttng.h |   24 +++++++
 lttng-events.c                              |    7 ++
 lttng-events.h                              |    3 +
 probes/lttng.c                              |   98 +++++++++++++++++++++++++++
 5 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 instrumentation/events/lttng-module/lttng.h
 create mode 100644 probes/lttng.c

diff --git a/Makefile b/Makefile
index a9d1cb1..a4c602f 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,8 @@ lttng-tracer-objs :=  lttng-events.o lttng-abi.o \
 			lttng-context-vpid.o lttng-context-tid.o \
 			lttng-context-vtid.o lttng-context-ppid.o \
 			lttng-context-vppid.o lttng-calibrate.o \
-			lttng-context-hostname.o wrapper/random.o
+			lttng-context-hostname.o wrapper/random.o \
+			probes/lttng.o
 
 obj-m += lttng-statedump.o
 lttng-statedump-objs := lttng-statedump-impl.o wrapper/irqdesc.o \
diff --git a/instrumentation/events/lttng-module/lttng.h b/instrumentation/events/lttng-module/lttng.h
new file mode 100644
index 0000000..c2ddf8d
--- /dev/null
+++ b/instrumentation/events/lttng-module/lttng.h
@@ -0,0 +1,24 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM lttng
+
+#if !defined(_TRACE_LTTNG_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_LTTNG_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(lttng_logger,
+	TP_PROTO(const char __user *text, size_t len),
+	TP_ARGS(text, len),
+	TP_STRUCT__entry(
+		__dynamic_array_text(char, msg, len)
+	),
+	TP_fast_assign(
+		tp_memcpy_dyn_from_user(msg, text)
+	),
+	TP_printk("")
+)
+
+#endif /* _TRACE_LTTNG_H */
+
+/* This part must be outside protection */
+#include "../../../probes/define_trace.h"
diff --git a/lttng-events.c b/lttng-events.c
index 0512a3f..ff28c9a 100644
--- a/lttng-events.c
+++ b/lttng-events.c
@@ -1261,7 +1261,13 @@ static int __init lttng_events_init(void)
 	ret = lttng_abi_init();
 	if (ret)
 		goto error_abi;
+	ret = lttng_logger_init();
+	if (ret)
+		goto error_logger;
 	return 0;
+
+error_logger:
+	lttng_abi_exit();
 error_abi:
 	kmem_cache_destroy(event_cache);
 	return ret;
@@ -1273,6 +1279,7 @@ static void __exit lttng_events_exit(void)
 {
 	struct lttng_session *session, *tmpsession;
 
+	lttng_logger_exit();
 	lttng_abi_exit();
 	list_for_each_entry_safe(session, tmpsession, &sessions, list)
 		lttng_session_destroy(session);
diff --git a/lttng-events.h b/lttng-events.h
index 6b39304..aeb2a6b 100644
--- a/lttng-events.h
+++ b/lttng-events.h
@@ -429,6 +429,9 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
 }
 #endif
 
+int lttng_logger_init(void);
+void lttng_logger_exit(void);
+
 extern int lttng_statedump_start(struct lttng_session *session);
 
 #ifdef CONFIG_KPROBES
diff --git a/probes/lttng.c b/probes/lttng.c
new file mode 100644
index 0000000..2761f19
--- /dev/null
+++ b/probes/lttng.c
@@ -0,0 +1,98 @@
+/*
+ * lttng.c
+ *
+ * LTTng logger ABI
+ *
+ * Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/tracepoint.h>
+#include <linux/uaccess.h>
+#include <linux/gfp.h>
+#include <linux/fs.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include "../wrapper/vmalloc.h"
+#include "../lttng-events.h"
+
+#define TP_MODULE_NOAUTOLOAD
+#define LTTNG_PACKAGE_BUILD
+#define CREATE_TRACE_POINTS
+#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
+#define TRACE_INCLUDE_FILE lttng
+
+#include "../instrumentation/events/lttng-module/lttng.h"
+
+#define LTTNG_LOGGER_FILE	"lttng-logger"
+
+static struct proc_dir_entry *lttng_logger_dentry;
+
+/**
+ * lttng_logger_write - write a userspace string into the trace system
+ * @file: file pointer
+ * @user_buf: user string
+ * @count: length to copy
+ * @ppos: unused
+ *
+ * Copy a userspace string into a trace event named "lttng:logger".
+ * Copies @count bytes into the event "msg" dynamic array.
+ * Returns the number of bytes copied from the source. It cannot return
+ * more than @count.
+ */
+static
+ssize_t lttng_logger_write(struct file *file, const char __user *user_buf,
+		    size_t count, loff_t *ppos)
+{
+	trace_lttng_logger(user_buf, count);
+	return count;
+}
+
+static const struct file_operations lttng_logger_operations = {
+	.write = lttng_logger_write,
+};
+
+int __init lttng_logger_init(void)
+{
+	int ret = 0;
+
+	wrapper_vmalloc_sync_all();
+	lttng_logger_dentry = proc_create_data(LTTNG_LOGGER_FILE,
+				S_IRUGO | S_IWUGO, NULL,
+				&lttng_logger_operations, NULL);
+	if (!lttng_logger_dentry) {
+		printk(KERN_ERR "Error creating LTTng logger file\n");
+		ret = -ENOMEM;
+		goto error;
+	}
+	ret = __lttng_events_init__lttng();
+	if (ret)
+		goto error_events;
+	return ret;
+
+error_events:
+	remove_proc_entry("lttng-logger", NULL);
+error:
+	return ret;
+}
+
+void __exit lttng_logger_exit(void)
+{
+	__lttng_events_exit__lttng();
+	if (lttng_logger_dentry)
+		remove_proc_entry("lttng-logger", NULL);
+}
-- 
1.7.10.4

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found]           ` <1299774859.26113.1392655235092.JavaMail.zimbra@efficios.com>
@ 2014-02-17 16:41             ` Karim Yaghmour
  0 siblings, 0 replies; 8+ messages in thread
From: Karim Yaghmour @ 2014-02-17 16:41 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev


On 14-02-17 11:40 AM, Mathieu Desnoyers wrote:
> trace.h:#define TRACE_BUF_SIZE		1024
> 
> so actually, ftrace truncates at 1024 bytes. We could very well do the same
> within the lttng-logger write() op.
> 
> Thoughts ?

Sold.

-- 
Karim Yaghmour
CEO - Opersys inc. / www.opersys.com
http://twitter.com/karimyaghmour

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found]         ` <53023832.6010005@opersys.com>
@ 2014-02-17 16:40           ` Mathieu Desnoyers
       [not found]           ` <1299774859.26113.1392655235092.JavaMail.zimbra@efficios.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2014-02-17 16:40 UTC (permalink / raw)
  To: Karim Yaghmour; +Cc: lttng-dev



----- Original Message -----
> From: "Karim Yaghmour" <karim.yaghmour@opersys.com>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: lttng-dev@lists.lttng.org
> Sent: Monday, February 17, 2014 11:26:26 AM
> Subject: Re: [RFC PATCH lttng-modules] LTTng logger ABI
> 
> 
> On 14-02-17 11:21 AM, Mathieu Desnoyers wrote:
> > I'm seeing here that the event in trace_marker is limited to 1 page (it can
> > cross a page boundary, so ftrace deals with 2 pages at most). It makes
> > sense,
> > since Ftrace's buffers are split into pages.
> > 
> > Its truncation happens here:
> > 
> >         if (cnt > TRACE_BUF_SIZE)
> >                 cnt = TRACE_BUF_SIZE;
> 
> Good to know. So at least we know ftrace truncates by default.
> 
> > The minimum size of sub-buffers (trace packets) LTTng can allocate is a
> > page.
> > However, the available space for event records is slightly less, since we
> > have
> > a packet header at the beginning of the packet. Since the packet header can
> > be extended between LTTng versions, it's hard to say. The space can be
> > slightly less if event contexts are enabled (this can be done dynamically
> > at runtime, per-buffer).
> > 
> > Thoughts ?
> 
> I'd be tempted to say that anything that big should be good enough. But
> from the sounds of it, even doing strlen's in user-space wouldn't be
> good enough to ensure that the data fits in lttng buffer. I can't say
> that I have a good solution here. Ideally there should be some form of
> automatic truncation somewhere without having to go through the expense
> of strlens or the likes.

trace.h:#define TRACE_BUF_SIZE		1024

so actually, ftrace truncates at 1024 bytes. We could very well do the same
within the lttng-logger write() op.

Thoughts ?

Thanks,

Mathieu

> 
> --
> Karim Yaghmour
> CEO - Opersys inc. / www.opersys.com
> http://twitter.com/karimyaghmour
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found]       ` <1098265448.26099.1392654107038.JavaMail.zimbra@efficios.com>
@ 2014-02-17 16:26         ` Karim Yaghmour
       [not found]         ` <53023832.6010005@opersys.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Karim Yaghmour @ 2014-02-17 16:26 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev


On 14-02-17 11:21 AM, Mathieu Desnoyers wrote:
> I'm seeing here that the event in trace_marker is limited to 1 page (it can
> cross a page boundary, so ftrace deals with 2 pages at most). It makes sense,
> since Ftrace's buffers are split into pages.
> 
> Its truncation happens here:
> 
>         if (cnt > TRACE_BUF_SIZE)
>                 cnt = TRACE_BUF_SIZE;

Good to know. So at least we know ftrace truncates by default.

> The minimum size of sub-buffers (trace packets) LTTng can allocate is a page.
> However, the available space for event records is slightly less, since we have
> a packet header at the beginning of the packet. Since the packet header can
> be extended between LTTng versions, it's hard to say. The space can be
> slightly less if event contexts are enabled (this can be done dynamically
> at runtime, per-buffer).
> 
> Thoughts ?

I'd be tempted to say that anything that big should be good enough. But
from the sounds of it, even doing strlen's in user-space wouldn't be
good enough to ensure that the data fits in lttng buffer. I can't say
that I have a good solution here. Ideally there should be some form of
automatic truncation somewhere without having to go through the expense
of strlens or the likes.

-- 
Karim Yaghmour
CEO - Opersys inc. / www.opersys.com
http://twitter.com/karimyaghmour

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found]     ` <53023536.9050007@opersys.com>
@ 2014-02-17 16:21       ` Mathieu Desnoyers
       [not found]       ` <1098265448.26099.1392654107038.JavaMail.zimbra@efficios.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2014-02-17 16:21 UTC (permalink / raw)
  To: Karim Yaghmour; +Cc: lttng-dev

----- Original Message -----
> From: "Karim Yaghmour" <karim.yaghmour@opersys.com>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: lttng-dev@lists.lttng.org
> Sent: Monday, February 17, 2014 11:13:42 AM
> Subject: Re: [RFC PATCH lttng-modules] LTTng logger ABI
> 
> 
> On 14-02-17 11:08 AM, Mathieu Desnoyers wrote:
> > I'd be tempted to ask: is that the behavior of ftrace when receiving an
> > event larger than a page through trace_marker ?
> 
> I've never bothered looking it up to be quite honest.

I'm seeing here that the event in trace_marker is limited to 1 page (it can
cross a page boundary, so ftrace deals with 2 pages at most). It makes sense,
since Ftrace's buffers are split into pages.

Its truncation happens here:

        if (cnt > TRACE_BUF_SIZE)
                cnt = TRACE_BUF_SIZE;

> 
> > We could indeed truncate the event, but it would increase complexity
> > compared to the current patch. So I'm tempted to wait a bit before doing
> > so.
> 
> What's the maximum length of events lttng-logger will take? We just
> truncate in the Android user-space library that writes the atrace events.

The minimum size of sub-buffers (trace packets) LTTng can allocate is a page.
However, the available space for event records is slightly less, since we have
a packet header at the beginning of the packet. Since the packet header can
be extended between LTTng versions, it's hard to say. The space can be
slightly less if event contexts are enabled (this can be done dynamically
at runtime, per-buffer).

Thoughts ?

Thanks,

Mathieu

> 
> --
> Karim Yaghmour
> CEO - Opersys inc. / www.opersys.com
> http://twitter.com/karimyaghmour
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found]   ` <1718413437.26031.1392653324422.JavaMail.zimbra@efficios.com>
@ 2014-02-17 16:13     ` Karim Yaghmour
       [not found]     ` <53023536.9050007@opersys.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Karim Yaghmour @ 2014-02-17 16:13 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev


On 14-02-17 11:08 AM, Mathieu Desnoyers wrote:
> I'd be tempted to ask: is that the behavior of ftrace when receiving an
> event larger than a page through trace_marker ?

I've never bothered looking it up to be quite honest.

> We could indeed truncate the event, but it would increase complexity
> compared to the current patch. So I'm tempted to wait a bit before doing so.

What's the maximum length of events lttng-logger will take? We just
truncate in the Android user-space library that writes the atrace events.

-- 
Karim Yaghmour
CEO - Opersys inc. / www.opersys.com
http://twitter.com/karimyaghmour

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found] ` <53022631.90209@opersys.com>
@ 2014-02-17 16:08   ` Mathieu Desnoyers
       [not found]   ` <1718413437.26031.1392653324422.JavaMail.zimbra@efficios.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2014-02-17 16:08 UTC (permalink / raw)
  To: Karim Yaghmour; +Cc: lttng-dev

----- Original Message -----
> From: "Karim Yaghmour" <karim.yaghmour@opersys.com>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: lttng-dev@lists.lttng.org
> Sent: Monday, February 17, 2014 10:09:37 AM
> Subject: Re: [RFC PATCH lttng-modules] LTTng logger ABI
> 
> 
> That was quick :)
> 
> On 14-02-15 05:08 PM, Mathieu Desnoyers wrote:
> > Add a user-space ABI (new file /proc/lttng-logger) to lttng-modules
> > which can be written into by any user on the system. The content is
> > saved into the kernel trace stream into the "lttng_logger" kernel event.
> 
> Nice. I think this would do for the use-case we discussed (i.e. feedback
> Android's "ATRACE" events into lttng instead of ftrace's "trace_marker"
> file.)

Great!

> 
> > The content of a single write is written into an lttng_logger event,
> > provided the packet size is large enough to store the content. If it is
> > not large enough, it won't be logged. However we cannot return any error
> > to the caller, since there may be more than one trace session listening
> > to this event.
> 
> Can we just truncate instead of dropping if the event is too large?

I'd be tempted to ask: is that the behavior of ftrace when receiving an
event larger than a page through trace_marker ?

We could indeed truncate the event, but it would increase complexity
compared to the current patch. So I'm tempted to wait a bit before doing so.

Thanks,

Mathieu

> 
> --
> Karim Yaghmour
> CEO - Opersys inc. / www.opersys.com
> http://twitter.com/karimyaghmour
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

* Re: [RFC PATCH lttng-modules] LTTng logger ABI
       [not found] <1392502096-1900-1-git-send-email-mathieu.desnoyers@efficios.com>
@ 2014-02-17 15:09 ` Karim Yaghmour
       [not found] ` <53022631.90209@opersys.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Karim Yaghmour @ 2014-02-17 15:09 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev


That was quick :)

On 14-02-15 05:08 PM, Mathieu Desnoyers wrote:
> Add a user-space ABI (new file /proc/lttng-logger) to lttng-modules
> which can be written into by any user on the system. The content is
> saved into the kernel trace stream into the "lttng_logger" kernel event.

Nice. I think this would do for the use-case we discussed (i.e. feedback
Android's "ATRACE" events into lttng instead of ftrace's "trace_marker"
file.)

> The content of a single write is written into an lttng_logger event,
> provided the packet size is large enough to store the content. If it is
> not large enough, it won't be logged. However we cannot return any error
> to the caller, since there may be more than one trace session listening
> to this event.

Can we just truncate instead of dropping if the event is too large?

-- 
Karim Yaghmour
CEO - Opersys inc. / www.opersys.com
http://twitter.com/karimyaghmour

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

end of thread, other threads:[~2014-02-17 16:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-15 22:08 [RFC PATCH lttng-modules] LTTng logger ABI Mathieu Desnoyers
     [not found] <1392502096-1900-1-git-send-email-mathieu.desnoyers@efficios.com>
2014-02-17 15:09 ` Karim Yaghmour
     [not found] ` <53022631.90209@opersys.com>
2014-02-17 16:08   ` Mathieu Desnoyers
     [not found]   ` <1718413437.26031.1392653324422.JavaMail.zimbra@efficios.com>
2014-02-17 16:13     ` Karim Yaghmour
     [not found]     ` <53023536.9050007@opersys.com>
2014-02-17 16:21       ` Mathieu Desnoyers
     [not found]       ` <1098265448.26099.1392654107038.JavaMail.zimbra@efficios.com>
2014-02-17 16:26         ` Karim Yaghmour
     [not found]         ` <53023832.6010005@opersys.com>
2014-02-17 16:40           ` Mathieu Desnoyers
     [not found]           ` <1299774859.26113.1392655235092.JavaMail.zimbra@efficios.com>
2014-02-17 16:41             ` Karim Yaghmour

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.