[kernel patch] Experimental systemtap integration of LTTng

Tom Zanussi <[email protected]>
Newsgroups gmane.linux.systemtap,gmane.linux.kernel.tracing
Message-ID <[email protected]>
This adds the systemtap facility to the kernel (2.6.17.4) with (I used
LTTng kernel patch patch-2.6.17-lttng-0.5.112.tar.bz2).  I'm sure this
would be better as a module or better, have it be included in the
systemtap generated code, but for now, I just added it as a systemtap
facility config option.

Tom

diff -urpN -X dontdiff linux-2.6.17.4-ltt/include/linux/ltt/ltt-facility-id-systemtap.h linux-2.6.17.4-ltt-systemtap/include/linux/ltt/ltt-facility-id-systemtap.h
--- linux-2.6.17.4-ltt/include/linux/ltt/ltt-facility-id-systemtap.h	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.17.4-ltt-systemtap/include/linux/ltt/ltt-facility-id-systemtap.h	2006-10-05 00:46:58.000000000 -0500
@@ -0,0 +1,21 @@
+#ifndef _LTT_FACILITY_ID_SYSTEMTAP_H_
+#define _LTT_FACILITY_ID_SYSTEMTAP_H_
+
+#ifdef CONFIG_LTT
+#include <linux/ltt-facilities.h>
+
+/****  facility handle  ****/
+
+extern ltt_facility_t ltt_facility_systemtap_3D461C68;
+extern ltt_facility_t ltt_facility_systemtap;
+
+
+/****  event index  ****/
+
+enum systemtap_event {
+	event_systemtap_probelog,
+	facility_systemtap_num_events
+};
+
+#endif //CONFIG_LTT
+#endif //_LTT_FACILITY_ID_SYSTEMTAP_H_
diff -urpN -X dontdiff linux-2.6.17.4-ltt/include/linux/ltt/ltt-facility-systemtap.h linux-2.6.17.4-ltt-systemtap/include/linux/ltt/ltt-facility-systemtap.h
--- linux-2.6.17.4-ltt/include/linux/ltt/ltt-facility-systemtap.h	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.17.4-ltt-systemtap/include/linux/ltt/ltt-facility-systemtap.h	2006-10-05 00:46:37.000000000 -0500
@@ -0,0 +1,179 @@
+#ifndef _LTT_FACILITY_SYSTEMTAP_H_
+#define _LTT_FACILITY_SYSTEMTAP_H_
+
+#include <linux/types.h>
+#include <linux/ltt/ltt-facility-id-systemtap.h>
+#include <linux/ltt-core.h>
+
+/* Named types */
+
+/* Event probelog structures */
+typedef struct lttng_sequence_systemtap_probelog_probedata lttng_sequence_systemtap_probelog_probedata;
+struct lttng_sequence_systemtap_probelog_probedata {
+	unsigned int len;
+	const unsigned char *array;
+};
+
+static inline size_t lttng_get_alignment_sequence_systemtap_probelog_probedata(
+		lttng_sequence_systemtap_probelog_probedata *obj)
+{
+	size_t align=0, localign;
+	localign = sizeof(unsigned int);
+	align = max(align, localign);
+
+	localign = sizeof(unsigned char);
+	align = max(align, localign);
+
+	return align;
+}
+
+static inline void lttng_write_sequence_systemtap_probelog_probedata(
+		char *buffer,
+		size_t *to_base,
+		size_t *to,
+		const char **from,
+		size_t *len,
+		lttng_sequence_systemtap_probelog_probedata *obj)
+{
+	size_t align;
+
+	/* Flush pending memcpy */
+	if(*len != 0) {
+		if(buffer != NULL)
+			memcpy(buffer+*to_base+*to, *from, *len);
+	}
+	*to += *len;
+	*len = 0;
+
+	align = lttng_get_alignment_sequence_systemtap_probelog_probedata(obj);
+
+	if(*len == 0) {
+		*to += ltt_align(*to, align); /* align output */
+	} else {
+		*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+	}
+
+	/* Contains variable sized fields : must explode the structure */
+
+	/* Copy members */
+	align = sizeof(unsigned int);
+
+	if(*len == 0) {
+		*to += ltt_align(*to, align); /* align output */
+	} else {
+		*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+	}
+
+	*len += sizeof(unsigned int);
+
+	if(buffer != NULL)
+		memcpy(buffer+*to_base+*to, &obj->len, *len);
+	*to += *len;
+	*len = 0;
+
+	align = sizeof(unsigned char);
+
+	if(*len == 0) {
+		*to += ltt_align(*to, align); /* align output */
+	} else {
+		*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+	}
+
+	*len += sizeof(unsigned char);
+
+	*len = obj->len * (*len);
+	if(buffer != NULL)
+		memcpy(buffer+*to_base+*to, obj->array, *len);
+	*to += *len;
+	*len = 0;
+
+
+	/* Realign the *to_base on arch size, set *to to 0 */
+	*to += ltt_align(*to, sizeof(void *));
+	*to_base = *to_base+*to;
+	*to = 0;
+
+	/* Put source *from just after the C sequence */
+	*from = (const char*)(obj+1);
+}
+
+
+/* Event probelog logging function */
+static inline void trace_systemtap_probelog(
+		lttng_sequence_systemtap_probelog_probedata * lttng_param_probedata)
+#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_SYSTEMTAP))
+{
+}
+#else
+{
+	unsigned int index;
+	struct ltt_channel_struct *channel;
+	struct ltt_trace_struct *trace;
+	void *transport_data;
+	char *buffer = NULL;
+	size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+	size_t *to_base = &real_to_base;
+	size_t real_to = 0;
+	size_t *to = &real_to;
+	size_t real_len = 0;
+	size_t *len = &real_len;
+	size_t reserve_size;
+	size_t slot_size;
+	const char *real_from;
+	const char **from = &real_from;
+	u64 tsc;
+	size_t before_hdr_pad, after_hdr_pad, header_size;
+
+	if(ltt_traces.num_active_traces == 0) return;
+
+	/* For each field, calculate the field size. */
+	/* size = *to_base + *to + *len */
+	/* Assume that the padding for alignment starts at a
+	 * sizeof(void *) address. */
+
+	*from = (const char*)lttng_param_probedata;
+	lttng_write_sequence_systemtap_probelog_probedata(buffer, to_base, to, from, len, lttng_param_probedata);
+	reserve_size = *to_base + *to + *len;
+	preempt_disable();
+	ltt_nesting[smp_processor_id()]++;
+	index = ltt_get_index_from_facility(ltt_facility_systemtap_3D461C68,
+						event_systemtap_probelog);
+
+	list_for_each_entry_rcu(trace, &ltt_traces.head, list) {
+		if(!trace->active) continue;
+
+		channel = ltt_get_channel_from_index(trace, index);
+
+		slot_size = 0;
+		buffer = ltt_reserve_slot(trace, channel, &transport_data,
+			reserve_size, &slot_size, &tsc,
+			&before_hdr_pad, &after_hdr_pad, &header_size);
+		if(!buffer) continue; /* buffer full */
+
+		*to_base = *to = *len = 0;
+
+		ltt_write_event_header(trace, channel, buffer,
+			ltt_facility_systemtap_3D461C68, event_systemtap_probelog,
+			reserve_size, before_hdr_pad, tsc);
+		*to_base += before_hdr_pad + after_hdr_pad + header_size;
+
+		*from = (const char*)lttng_param_probedata;
+		lttng_write_sequence_systemtap_probelog_probedata(buffer, to_base, to, from, len, lttng_param_probedata);
+		/* Flush pending memcpy */
+		if(*len != 0) {
+			memcpy(buffer+*to_base+*to, *from, *len);
+			*to += *len;
+			*len = 0;
+		}
+
+		ltt_commit_slot(channel, &transport_data, buffer, slot_size);
+
+	}
+
+	ltt_nesting[smp_processor_id()]--;
+	preempt_enable_no_resched();
+}
+#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_SYSTEMTAP))
+
+
+#endif //_LTT_FACILITY_SYSTEMTAP_H_
diff -urpN -X dontdiff linux-2.6.17.4-ltt/ltt/Kconfig linux-2.6.17.4-ltt-systemtap/ltt/Kconfig
--- linux-2.6.17.4-ltt/ltt/Kconfig	2006-09-23 11:41:07.000000000 -0500
+++ linux-2.6.17.4-ltt-systemtap/ltt/Kconfig	2006-10-05 00:47:32.000000000 -0500
@@ -236,6 +236,13 @@ config LTT_FACILITY_STATEDUMP
 	  LTT Kernel State Dump facility. Contains events for dumping kernel
 	  state at the beginning of a trace.
 
+config LTT_FACILITY_SYSTEMTAP
+	bool "Linux Trace Toolkit Systemtap Trace Facility"
+	depends on LTT
+	default y
+	help
+	  LTT Systemtap Trace facility.  Allows Systemtap to use LTT for tracing.
+
 config LTT_FACILITY_TIMER
 	bool "Linux Trace Toolkit Timer Facility"
 	depends on LTT
diff -urpN -X dontdiff linux-2.6.17.4-ltt/ltt/Makefile linux-2.6.17.4-ltt-systemtap/ltt/Makefile
--- linux-2.6.17.4-ltt/ltt/Makefile	2006-09-23 11:41:07.000000000 -0500
+++ linux-2.6.17.4-ltt-systemtap/ltt/Makefile	2006-10-05 00:47:41.000000000 -0500
@@ -19,6 +19,7 @@ obj-$(CONFIG_LTT_FACILITY_STACK)	+= \
 			ltt-facility-loader-stack.o
 obj-$(CONFIG_LTT_FACILITY_STATEDUMP)	+= \
 			ltt-facility-loader-network_ip_interface.o
+obj-$(CONFIG_LTT_FACILITY_SYSTEMTAP)	+= ltt-facility-loader-systemtap.o
 
 obj-$(CONFIG_LTT_TRACER)		+= ltt-core.o
 obj-$(CONFIG_LTT_RELAY)			+= ltt-relay.o
diff -urpN -X dontdiff linux-2.6.17.4-ltt/ltt/ltt-facility-loader-systemtap.c linux-2.6.17.4-ltt-systemtap/ltt/ltt-facility-loader-systemtap.c
--- linux-2.6.17.4-ltt/ltt/ltt-facility-loader-systemtap.c	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.17.4-ltt-systemtap/ltt/ltt-facility-loader-systemtap.c	2006-10-05 00:48:03.000000000 -0500
@@ -0,0 +1,66 @@
+/*
+ * ltt-facility-loader-systemtap.c
+ *
+ * (C) Copyright  2005 - 
+ *          Mathieu Desnoyers ([email protected])
+ *
+ * Contains the LTT facility loader.
+ *
+ */
+
+
+#include <linux/ltt-facilities.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/config.h>
+#include "ltt-facility-loader-systemtap.h"
+
+
+#ifdef CONFIG_LTT
+
+EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);
+EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);
+
+static const char ltt_facility_name[] = LTT_FACILITY_NAME;
+
+#define SYMBOL_STRING(sym) #sym
+
+static struct ltt_facility facility = {
+	.name = ltt_facility_name,
+	.num_events = LTT_FACILITY_NUM_EVENTS,
+	.checksum = LTT_FACILITY_CHECKSUM,
+	.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),
+};
+
+static int __init facility_init(void)
+{
+	printk(KERN_INFO "LTT : ltt-facility-systemtap init in kernel\n");
+
+	LTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);
+	LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
+	
+	return LTT_FACILITY_SYMBOL;
+}
+
+#ifndef MODULE
+__initcall(facility_init);
+#else
+module_init(facility_init);
+static void __exit facility_exit(void)
+{
+	int err;
+
+	err = ltt_facility_unregister(LTT_FACILITY_SYMBOL);
+	if(err != 0)
+		printk(KERN_ERR "LTT : Error in unregistering facility.\n");
+
+}
+module_exit(facility_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Facility");
+
+#endif //MODULE
+
+#endif //CONFIG_LTT
diff -urpN -X dontdiff linux-2.6.17.4-ltt/ltt/ltt-facility-loader-systemtap.h linux-2.6.17.4-ltt-systemtap/ltt/ltt-facility-loader-systemtap.h
--- linux-2.6.17.4-ltt/ltt/ltt-facility-loader-systemtap.h	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.17.4-ltt-systemtap/ltt/ltt-facility-loader-systemtap.h	2006-10-05 00:48:05.000000000 -0500
@@ -0,0 +1,20 @@
+#ifndef _LTT_FACILITY_LOADER_SYSTEMTAP_H_
+#define _LTT_FACILITY_LOADER_SYSTEMTAP_H_
+
+#ifdef CONFIG_LTT
+
+#include <linux/ltt-facilities.h>
+#include <linux/ltt/ltt-facility-id-systemtap.h>
+
+ltt_facility_t	ltt_facility_systemtap;
+ltt_facility_t	ltt_facility_systemtap_3D461C68;
+
+#define LTT_FACILITY_SYMBOL		ltt_facility_systemtap
+#define LTT_FACILITY_CHECKSUM_SYMBOL	ltt_facility_systemtap_3D461C68
+#define LTT_FACILITY_CHECKSUM		0x3D461C68
+#define LTT_FACILITY_NAME		"systemtap"
+#define LTT_FACILITY_NUM_EVENTS	facility_systemtap_num_events
+
+#endif //CONFIG_LTT
+
+#endif //_LTT_FACILITY_LOADER_SYSTEMTAP_H_
Files linux-2.6.17.4-ltt/ltt/ltt-statedump.ko and linux-2.6.17.4-ltt-systemtap/ltt/ltt-statedump.ko differ
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.