From: Mathieu Desnoyers Date: Sat, 16 Jul 2011 18:44:09 +0000 (-0400) Subject: implement ring buffer clients X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9f3fdbc68877e1f12b6cedb15ef76d9af9b48bac;p=ust.git implement ring buffer clients Signed-off-by: Mathieu Desnoyers --- diff --git a/include/Makefile.am b/include/Makefile.am index 3b1503f..76c8cf6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,7 +3,9 @@ nobase_include_HEADERS = \ ust/tracepoint.h \ ust/tracepoint_event.h \ ust/probe.h \ - ust/version.h + ust/version.h \ + ust/lttng-ust-abi.h \ + ust/ringbuffer-abi.h noinst_HEADERS = \ share.h \ diff --git a/include/ust/bitfield.h b/include/ust/bitfield.h index 861e6dc..df8ab0b 100644 --- a/include/ust/bitfield.h +++ b/include/ust/bitfield.h @@ -19,11 +19,10 @@ * all copies or substantial portions of the Software. */ -#include "../ltt-endian.h" - -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif +#include /* C99 5.2.4.2 Numerical limits */ +#include /* C99 5.2.4.2 Numerical limits */ +#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ +#include /* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */ #define _bt_piecewise_rshift(_v, _shift) \ @@ -201,7 +200,7 @@ do { \ * bt_bitfield_write_be - write integer to a bitfield in big endian */ -#if (__BYTE_ORDER == __LITTLE_ENDIAN) +#if (BYTE_ORDER == LITTLE_ENDIAN) #define bt_bitfield_write(ptr, type, _start, _length, _v) \ _bt_bitfield_write_le(ptr, type, _start, _length, _v) @@ -212,7 +211,7 @@ do { \ #define bt_bitfield_write_be(ptr, type, _start, _length, _v) \ _bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v) -#elif (__BYTE_ORDER == __BIG_ENDIAN) +#elif (BYTE_ORDER == BIG_ENDIAN) #define bt_bitfield_write(ptr, type, _start, _length, _v) \ _bt_bitfield_write_be(ptr, type, _start, _length, _v) @@ -369,7 +368,7 @@ do { \ * bt_bitfield_read_be - read integer from a bitfield in big endian */ -#if (__BYTE_ORDER == __LITTLE_ENDIAN) +#if (BYTE_ORDER == LITTLE_ENDIAN) #define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) @@ -380,7 +379,7 @@ do { \ #define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ _bt_bitfield_read_be(_ptr, unsigned char, _start, _length, _vptr) -#elif (__BYTE_ORDER == __BIG_ENDIAN) +#elif (BYTE_ORDER == BIG_ENDIAN) #define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) @@ -391,7 +390,7 @@ do { \ #define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) -#else /* (__BYTE_ORDER == __PDP_ENDIAN) */ +#else /* (BYTE_ORDER == PDP_ENDIAN) */ #error "Byte order not supported" diff --git a/include/ust/core.h b/include/ust/core.h index d1fdb2d..b9f5b97 100644 --- a/include/ust/core.h +++ b/include/ust/core.h @@ -138,4 +138,35 @@ static __inline__ int get_count_order(unsigned int count) #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) #endif +#ifndef UST_VALGRIND + +static __inline__ int ust_get_cpu(void) +{ + int cpu; + + cpu = sched_getcpu(); + if (likely(cpu >= 0)) + return cpu; + /* + * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback. + */ + return 0; +} + +#else /* #else #ifndef UST_VALGRIND */ + +static __inline__ int ust_get_cpu(void) +{ + /* + * Valgrind does not support the sched_getcpu() vsyscall. + * It causes it to detect a segfault in the program and stop it. + * So if we want to check libust with valgrind, we have to refrain + * from using this call. TODO: it would probably be better to return + * other values too, to better test it. + */ + return 0; +} + +#endif /* #else #ifndef UST_VALGRIND */ + #endif /* UST_CORE_H */ diff --git a/include/ust/lttng-ust-abi.h b/include/ust/lttng-ust-abi.h new file mode 100644 index 0000000..ff76a71 --- /dev/null +++ b/include/ust/lttng-ust-abi.h @@ -0,0 +1,96 @@ +#ifndef _LTTNG_UST_ABI_H +#define _LTTNG_UST_ABI_H + +/* + * lttng-ust-abi.h + * + * Copyright 2010-2011 (c) - Mathieu Desnoyers + * + * LTTng-UST ABI header + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#define LTTNG_UST_SYM_NAME_LEN 128 + +enum lttng_ust_instrumentation { + LTTNG_UST_TRACEPOINT = 0, +}; + +/* + * LTTng consumer mode + */ +enum lttng_ust_output { + LTTNG_UST_MMAP = 0, +}; + +/* + * LTTng DebugFS ABI structures. + */ + +struct lttng_ust_channel { + int overwrite; /* 1: overwrite, 0: discard */ + uint64_t subbuf_size; /* in bytes */ + uint64_t num_subbuf; + unsigned int switch_timer_interval; /* usecs */ + unsigned int read_timer_interval; /* usecs */ + enum lttng_ust_output output; /* mmap */ +}; + +struct lttng_ust_event { + char name[LTTNG_UST_SYM_NAME_LEN]; /* event name */ + enum lttng_ust_instrumentation instrumentation; + /* Per instrumentation type configuration */ + union { + } u; +}; + +struct lttng_ust_tracer_version { + uint32_t version; + uint32_t patchlevel; + uint32_t sublevel; +}; + +enum lttng_ust_context_type { + LTTNG_UST_CONTEXT_VTID = 0, +}; + +struct lttng_ust_context { + enum lttng_ust_context_type ctx; + union { + } u; +}; + +#define _UST_CMD(minor) (minor) +#define _UST_CMDR(minor, type) (minor) +#define _UST_CMDW(minor, type) (minor) + +/* LTTng-UST commands */ +#define LTTNG_UST_SESSION _UST_CMD(0x40) +#define LTTNG_UST_TRACER_VERSION \ + _UST_CMDR(0x41, struct lttng_ust_tracer_version) +#define LTTNG_UST_TRACEPOINT_LIST _UST_CMD(0x42) +#define LTTNG_UST_WAIT_QUIESCENT _UST_CMD(0x43) + +/* Session FD ioctl */ +#define LTTNG_UST_METADATA \ + _UST_CMDW(0x50, struct lttng_ust_channel) +#define LTTNG_UST_CHANNEL \ + _UST_CMDW(0x51, struct lttng_ust_channel) +#define LTTNG_UST_SESSION_START _UST_CMD(0x52) +#define LTTNG_UST_SESSION_STOP _UST_CMD(0x53) + +/* Channel FD ioctl */ +#define LTTNG_UST_STREAM _UST_CMD(0x60) +#define LTTNG_UST_EVENT \ + _UST_CMDW(0x61, struct lttng_ust_event) + +/* Event and Channel FD ioctl */ +#define LTTNG_UST_CONTEXT \ + _UST_CMDW(0x70, struct lttng_ust_context) + +/* Event, Channel and Session ioctl */ +#define LTTNG_UST_ENABLE _UST_CMD(0x80) +#define LTTNG_UST_DISABLE _UST_CMD(0x81) + +#endif /* _LTTNG_UST_ABI_H */ diff --git a/include/ust/ringbuffer-abi.h b/include/ust/ringbuffer-abi.h new file mode 100644 index 0000000..25bc194 --- /dev/null +++ b/include/ust/ringbuffer-abi.h @@ -0,0 +1,67 @@ +#ifndef _UST_RING_BUFFER_ABI_H +#define _UST_RING_BUFFER_ABI_H + +/* + * ust/ringbuffer-abi.h + * + * (C) Copyright 2005-2010 - Mathieu Desnoyers + * + * Wait-free ring buffer ABI. + * + * Author: + * Mathieu Desnoyers + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#define _UST_CMD(minor) (minor) +#define _UST_CMDR(minor, type) (minor) +#define _UST_CMDW(minor, type) (minor) + +/* + * Use RING_BUFFER_GET_NEXT_SUBBUF / RING_BUFFER_PUT_NEXT_SUBBUF to read and + * consume sub-buffers sequentially. + * + * Reading sub-buffers without consuming them can be performed with: + * + * RING_BUFFER_SNAPSHOT + * RING_BUFFER_SNAPSHOT_GET_CONSUMED + * RING_BUFFER_SNAPSHOT_GET_PRODUCED + * + * to get the offset range to consume, and then by passing each sub-buffer + * offset to RING_BUFFER_GET_SUBBUF, read the sub-buffer, and then release it + * with RING_BUFFER_PUT_SUBBUF. + * + * Note that the "snapshot" API can be used to read the sub-buffer in reverse + * order, which is useful for flight recorder snapshots. + */ + +/* Get a snapshot of the current ring buffer producer and consumer positions */ +#define RING_BUFFER_SNAPSHOT _UST_CMD(0x00) +/* Get the consumer position (iteration start) */ +#define RING_BUFFER_SNAPSHOT_GET_CONSUMED _UST_CMDR(0x01, unsigned long) +/* Get the producer position (iteration end) */ +#define RING_BUFFER_SNAPSHOT_GET_PRODUCED _UST_CMDR(0x02, unsigned long) +/* Get exclusive read access to the specified sub-buffer position */ +#define RING_BUFFER_GET_SUBBUF _UST_CMDW(0x03, unsigned long) +/* Release exclusive sub-buffer access */ +#define RING_BUFFER_PUT_SUBBUF _UST_CMD(0x04) + +/* Get exclusive read access to the next sub-buffer that can be read. */ +#define RING_BUFFER_GET_NEXT_SUBBUF _UST_CMD(0x05) +/* Release exclusive sub-buffer access, move consumer forward. */ +#define RING_BUFFER_PUT_NEXT_SUBBUF _UST_CMD(0x06) +/* returns the size of the current sub-buffer, without padding (for mmap). */ +#define RING_BUFFER_GET_SUBBUF_SIZE _UST_CMDR(0x07, unsigned long) +/* returns the size of the current sub-buffer, with padding (for splice). */ +#define RING_BUFFER_GET_PADDED_SUBBUF_SIZE _UST_CMDR(0x08, unsigned long) +/* returns the maximum size for sub-buffers. */ +#define RING_BUFFER_GET_MAX_SUBBUF_SIZE _UST_CMDR(0x09, unsigned long) +/* returns the length to mmap. */ +#define RING_BUFFER_GET_MMAP_LEN _UST_CMDR(0x0A, unsigned long) +/* returns the offset of the subbuffer belonging to the mmap reader. */ +#define RING_BUFFER_GET_MMAP_READ_OFFSET _UST_CMDR(0x0B, unsigned long) +/* flush the current sub-buffer */ +#define RING_BUFFER_FLUSH _UST_CMD(0x0C) + +#endif /* _UST_RING_BUFFER_ABI_H */ diff --git a/libringbuffer/api.h b/libringbuffer/api.h index aa23e40..2f15326 100644 --- a/libringbuffer/api.h +++ b/libringbuffer/api.h @@ -13,7 +13,7 @@ #include "backend.h" #include "frontend.h" -#include "vfs.h" +#include /* * ring_buffer_frontend_api.h contains static inline functions that depend on diff --git a/libringbuffer/frontend_api.h b/libringbuffer/frontend_api.h index ebe5db4..75146e6 100644 --- a/libringbuffer/frontend_api.h +++ b/libringbuffer/frontend_api.h @@ -18,14 +18,17 @@ */ #include "frontend.h" +#include "ust/core.h" +#include +#include /** * lib_ring_buffer_get_cpu - Precedes ring buffer reserve/commit. * - * Disables preemption (acts as a RCU read-side critical section) and keeps a - * ring buffer nesting count as supplementary safety net to ensure tracer client - * code will never trigger an endless recursion. Returns the processor ID on - * success, -EPERM on failure (nesting count too high). + * Grabs RCU read-side lock and keeps a ring buffer nesting count as + * supplementary safety net to ensure tracer client code will never + * trigger an endless recursion. Returns the processor ID on success, + * -EPERM on failure (nesting count too high). * * asm volatile and "memory" clobber prevent the compiler from moving * instructions out of the ring buffer nesting count. This is required to ensure @@ -38,15 +41,15 @@ int lib_ring_buffer_get_cpu(const struct lib_ring_buffer_config *config) { int cpu, nesting; - rcu_read_lock_sched_notrace(); - cpu = smp_processor_id(); + rcu_read_lock(); + cpu = ust_get_cpu(); nesting = ++lib_ring_buffer_nesting; /* TLS */ - barrier(); + cmm_barrier(); if (unlikely(nesting > 4)) { WARN_ON_ONCE(1); lib_ring_buffer_nesting--; /* TLS */ - rcu_read_unlock_sched_notrace(); + rcu_read_unlock(); return -EPERM; } else return cpu; @@ -58,9 +61,9 @@ int lib_ring_buffer_get_cpu(const struct lib_ring_buffer_config *config) static inline void lib_ring_buffer_put_cpu(const struct lib_ring_buffer_config *config) { - barrier(); + cmm_barrier(); lib_ring_buffer_nesting--; /* TLS */ - rcu_read_unlock_sched_notrace(); + rcu_read_unlock(); } /* @@ -89,7 +92,7 @@ int lib_ring_buffer_try_reserve(const struct lib_ring_buffer_config *config, * commit counter to increment it and commit seq value to compare it to * the commit counter. */ - prefetch(&buf->commit_hot[subbuf_index(*o_begin, chan)]); + //prefetch(&buf->commit_hot[subbuf_index(*o_begin, chan)]); if (last_tsc_overflow(config, buf, ctx->tsc)) ctx->rflags |= RING_BUFFER_RFLAG_FULL_TSC; @@ -147,14 +150,14 @@ int lib_ring_buffer_reserve(const struct lib_ring_buffer_config *config, unsigned long o_begin, o_end, o_old; size_t before_hdr_pad = 0; - if (atomic_read(&chan->record_disabled)) + if (uatomic_read(&chan->record_disabled)) return -EAGAIN; if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) - buf = per_cpu_ptr(chan->backend.buf, ctx->cpu); + buf = &shmp(chan->backend.buf)[ctx->cpu]; else - buf = chan->backend.buf; - if (atomic_read(&buf->record_disabled)) + buf = shmp(chan->backend.buf); + if (uatomic_read(&buf->record_disabled)) return -EAGAIN; ctx->buf = buf; @@ -245,17 +248,9 @@ void lib_ring_buffer_commit(const struct lib_ring_buffer_config *config, * Order all writes to buffer before the commit count update that will * determine that the subbuffer is full. */ - if (config->ipi == RING_BUFFER_IPI_BARRIER) { - /* - * Must write slot data before incrementing commit count. This - * compiler barrier is upgraded into a smp_mb() by the IPI sent - * by get_subbuf(). - */ - barrier(); - } else - smp_wmb(); + cmm_smp_wmb(); - v_add(config, ctx->slot_size, &buf->commit_hot[endidx].cc); + v_add(config, ctx->slot_size, &shmp(buf->commit_hot)[endidx].cc); /* * commit count read can race with concurrent OOO commit count updates. @@ -275,7 +270,7 @@ void lib_ring_buffer_commit(const struct lib_ring_buffer_config *config, * count reaches back the reserve offset for a specific sub-buffer, * which is completely independent of the order. */ - commit_count = v_read(config, &buf->commit_hot[endidx].cc); + commit_count = v_read(config, &shmp(buf->commit_hot)[endidx].cc); lib_ring_buffer_check_deliver(config, buf, chan, offset_end - 1, commit_count, endidx); @@ -330,28 +325,28 @@ static inline void channel_record_disable(const struct lib_ring_buffer_config *config, struct channel *chan) { - atomic_inc(&chan->record_disabled); + uatomic_inc(&chan->record_disabled); } static inline void channel_record_enable(const struct lib_ring_buffer_config *config, struct channel *chan) { - atomic_dec(&chan->record_disabled); + uatomic_dec(&chan->record_disabled); } static inline void lib_ring_buffer_record_disable(const struct lib_ring_buffer_config *config, struct lib_ring_buffer *buf) { - atomic_inc(&buf->record_disabled); + uatomic_inc(&buf->record_disabled); } static inline void lib_ring_buffer_record_enable(const struct lib_ring_buffer_config *config, struct lib_ring_buffer *buf) { - atomic_dec(&buf->record_disabled); + uatomic_dec(&buf->record_disabled); } #endif /* _LINUX_RING_BUFFER_FRONTEND_API_H */ diff --git a/libringbuffer/ring_buffer_abi.c b/libringbuffer/ring_buffer_abi.c index 5642327..fbf6df5 100644 --- a/libringbuffer/ring_buffer_abi.c +++ b/libringbuffer/ring_buffer_abi.c @@ -1,5 +1,5 @@ /* - * ring_buffer_vfs.c + * ring_buffer_abi.c * * Copyright (C) 2009-2010 - Mathieu Desnoyers * @@ -10,7 +10,7 @@ #include "backend.h" #include "frontend.h" -#include "vfs.h" +#include static int put_ulong(unsigned long val, unsigned long arg) { diff --git a/libringbuffer/vfs.h b/libringbuffer/vfs.h deleted file mode 100644 index 00404a3..0000000 --- a/libringbuffer/vfs.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _LINUX_RING_BUFFER_VFS_H -#define _LINUX_RING_BUFFER_VFS_H - -/* - * linux/ringbuffer/vfs.h - * - * (C) Copyright 2005-2010 - Mathieu Desnoyers - * - * Wait-free ring buffer VFS file operations. - * - * Author: - * Mathieu Desnoyers - * - * Dual LGPL v2.1/GPL v2 license. - */ - -/* VFS API */ - -extern const struct file_operations lib_ring_buffer_file_operations; - -/* - * Internal file operations. - */ - -int lib_ring_buffer_open(struct inode *inode, struct file *file); -int lib_ring_buffer_release(struct inode *inode, struct file *file); -unsigned int lib_ring_buffer_poll(struct file *filp, poll_table *wait); -ssize_t lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags); -int lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma); - -/* Ring Buffer ioctl() and ioctl numbers */ -long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); -#ifdef CONFIG_COMPAT -long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, - unsigned long arg); -#endif - -/* - * Use RING_BUFFER_GET_NEXT_SUBBUF / RING_BUFFER_PUT_NEXT_SUBBUF to read and - * consume sub-buffers sequentially. - * - * Reading sub-buffers without consuming them can be performed with: - * - * RING_BUFFER_SNAPSHOT - * RING_BUFFER_SNAPSHOT_GET_CONSUMED - * RING_BUFFER_SNAPSHOT_GET_PRODUCED - * - * to get the offset range to consume, and then by passing each sub-buffer - * offset to RING_BUFFER_GET_SUBBUF, read the sub-buffer, and then release it - * with RING_BUFFER_PUT_SUBBUF. - * - * Note that the "snapshot" API can be used to read the sub-buffer in reverse - * order, which is useful for flight recorder snapshots. - */ - -/* Get a snapshot of the current ring buffer producer and consumer positions */ -#define RING_BUFFER_SNAPSHOT _IO(0xF6, 0x00) -/* Get the consumer position (iteration start) */ -#define RING_BUFFER_SNAPSHOT_GET_CONSUMED _IOR(0xF6, 0x01, unsigned long) -/* Get the producer position (iteration end) */ -#define RING_BUFFER_SNAPSHOT_GET_PRODUCED _IOR(0xF6, 0x02, unsigned long) -/* Get exclusive read access to the specified sub-buffer position */ -#define RING_BUFFER_GET_SUBBUF _IOW(0xF6, 0x03, unsigned long) -/* Release exclusive sub-buffer access */ -#define RING_BUFFER_PUT_SUBBUF _IO(0xF6, 0x04) - -/* Get exclusive read access to the next sub-buffer that can be read. */ -#define RING_BUFFER_GET_NEXT_SUBBUF _IO(0xF6, 0x05) -/* Release exclusive sub-buffer access, move consumer forward. */ -#define RING_BUFFER_PUT_NEXT_SUBBUF _IO(0xF6, 0x06) -/* returns the size of the current sub-buffer, without padding (for mmap). */ -#define RING_BUFFER_GET_SUBBUF_SIZE _IOR(0xF6, 0x07, unsigned long) -/* returns the size of the current sub-buffer, with padding (for splice). */ -#define RING_BUFFER_GET_PADDED_SUBBUF_SIZE _IOR(0xF6, 0x08, unsigned long) -/* returns the maximum size for sub-buffers. */ -#define RING_BUFFER_GET_MAX_SUBBUF_SIZE _IOR(0xF6, 0x09, unsigned long) -/* returns the length to mmap. */ -#define RING_BUFFER_GET_MMAP_LEN _IOR(0xF6, 0x0A, unsigned long) -/* returns the offset of the subbuffer belonging to the mmap reader. */ -#define RING_BUFFER_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, unsigned long) -/* flush the current sub-buffer */ -#define RING_BUFFER_FLUSH _IO(0xF6, 0x0C) - -#endif /* _LINUX_RING_BUFFER_VFS_H */ diff --git a/libust/Makefile.am b/libust/Makefile.am index 3d7e354..bfddd3a 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -7,7 +7,12 @@ libust_la_SOURCES = \ tracepoint.c \ trace_event.c \ ltt-tracer.h \ - ltt-tracer-core.h + ltt-tracer-core.h \ + ltt-ring-buffer-client.h \ + ltt-ring-buffer-client-discard.c \ + ltt-ring-buffer-client-overwrite.c \ + ltt-ring-buffer-metadata-client.h \ + ltt-ring-buffer-metadata-client.c #removed: buffers.c buffers.h diff --git a/libust/ltt-events.h b/libust/ltt-events.h index 9b972ab..8587cfe 100644 --- a/libust/ltt-events.h +++ b/libust/ltt-events.h @@ -11,10 +11,10 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include -#include -#include -#include "ltt-debugfs-abi.h" +#include +#include +#include +#include #undef is_signed_type #define is_signed_type(type) (((type)(-1)) < 0) @@ -22,8 +22,6 @@ struct ltt_channel; struct ltt_session; struct lib_ring_buffer_ctx; -struct perf_event; -struct perf_event_attr; /* Type description */ @@ -126,12 +124,6 @@ struct lttng_ctx_field { struct lib_ring_buffer_ctx *ctx, struct ltt_channel *chan); union { - struct { - struct perf_event **e; /* per-cpu array */ - struct notifier_block nb; - int hp_enable; - struct perf_event_attr *attr; - } perf_counter; } u; void (*destroy)(struct lttng_ctx_field *field); }; @@ -148,13 +140,12 @@ struct lttng_event_desc { const struct lttng_event_ctx *ctx; /* context */ const struct lttng_event_field *fields; /* event payload */ unsigned int nr_fields; - struct module *owner; }; struct lttng_probe_desc { const struct lttng_event_desc *event_desc; unsigned int nr_events; - struct list_head head; /* chain registered probes */ + struct cds_list_head head; /* chain registered probes */ }; /* @@ -168,17 +159,10 @@ struct ltt_event { const struct lttng_event_desc *desc; void *filter; struct lttng_ctx *ctx; - enum lttng_kernel_instrumentation instrumentation; + enum lttng_ust_instrumentation instrumentation; union { - struct { - struct kprobe kp; - char *symbol_name; - } kprobe; - struct { - char *symbol_name; - } ftrace; } u; - struct list_head list; /* Event list */ + struct cds_list_head list; /* Event list */ int metadata_dumped:1; }; @@ -188,7 +172,8 @@ struct ltt_channel_ops { void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval); + unsigned int read_timer_interval, + int *shmid); void (*channel_destroy)(struct channel *chan); struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); void (*buffer_read_close)(struct lib_ring_buffer *buf); @@ -203,8 +188,8 @@ struct ltt_channel_ops { * may change due to concurrent writes. */ size_t (*packet_avail_size)(struct channel *chan); - wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); - wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); + //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); + //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); int (*is_finalized)(struct channel *chan); int (*is_disabled)(struct channel *chan); }; @@ -218,7 +203,7 @@ struct ltt_channel { struct ltt_session *session; struct file *file; /* File associated to channel */ unsigned int free_event_id; /* Next event ID to allocate */ - struct list_head list; /* Channel list */ + struct cds_list_head list; /* Channel list */ struct ltt_channel_ops *ops; int header_type; /* 0: unset, 1: compact, 2: large */ int metadata_dumped:1; @@ -229,18 +214,17 @@ struct ltt_session { int been_active; /* Has trace session been active ? */ struct file *file; /* File associated to session */ struct ltt_channel *metadata; /* Metadata channel */ - struct list_head chan; /* Channel list head */ - struct list_head events; /* Event list head */ - struct list_head list; /* Session list */ + struct cds_list_head chan; /* Channel list head */ + struct cds_list_head events; /* Event list head */ + struct cds_list_head list; /* Session list */ unsigned int free_chan_id; /* Next chan ID to allocate */ - uuid_le uuid; /* Trace session unique ID */ + uuid_t uuid; /* Trace session unique ID */ int metadata_dumped:1; }; struct ltt_transport { char *name; - struct module *owner; - struct list_head node; + struct cds_list_head node; struct ltt_channel_ops ops; }; @@ -262,7 +246,7 @@ struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, unsigned int read_timer_interval); struct ltt_event *ltt_event_create(struct ltt_channel *chan, - struct lttng_kernel_event *event_param, + struct lttng_ust_event *event_param, void *filter); int ltt_channel_enable(struct ltt_channel *channel); @@ -274,8 +258,8 @@ void ltt_transport_register(struct ltt_transport *transport); void ltt_transport_unregister(struct ltt_transport *transport); void synchronize_trace(void); -int ltt_debugfs_abi_init(void); -void ltt_debugfs_abi_exit(void); +//int ltt_debugfs_abi_init(void); +//void ltt_debugfs_abi_exit(void); int ltt_probe_register(struct lttng_probe_desc *desc); void ltt_probe_unregister(struct lttng_probe_desc *desc); @@ -287,71 +271,8 @@ struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); void lttng_remove_context_field(struct lttng_ctx **ctx, struct lttng_ctx_field *field); void lttng_destroy_context(struct lttng_ctx *ctx); -int lttng_add_pid_to_ctx(struct lttng_ctx **ctx); -int lttng_add_comm_to_ctx(struct lttng_ctx **ctx); -int lttng_add_prio_to_ctx(struct lttng_ctx **ctx); -int lttng_add_nice_to_ctx(struct lttng_ctx **ctx); -int lttng_add_perf_counter_to_ctx(uint32_t type, - uint64_t config, - const char *name, - struct lttng_ctx **ctx); - -#ifdef CONFIG_KPROBES -int lttng_kprobes_register(const char *name, - const char *symbol_name, - uint64_t offset, - uint64_t addr, - struct ltt_event *event); -void lttng_kprobes_unregister(struct ltt_event *event); -void lttng_kprobes_destroy_private(struct ltt_event *event); -#else -static inline -int lttng_kprobes_register(const char *name, - const char *symbol_name, - uint64_t offset, - uint64_t addr, - struct ltt_event *event) -{ - return -ENOSYS; -} - -static inline -void lttng_kprobes_unregister(struct ltt_event *event) -{ -} - -static inline -void lttng_kprobes_destroy_private(struct ltt_event *event) -{ -} -#endif - -#ifdef CONFIG_DYNAMIC_FTRACE -int lttng_ftrace_register(const char *name, - const char *symbol_name, - struct ltt_event *event); -void lttng_ftrace_unregister(struct ltt_event *event); -void lttng_ftrace_destroy_private(struct ltt_event *event); -#else -static inline -int lttng_ftrace_register(const char *name, - const char *symbol_name, - struct ltt_event *event) -{ - return -ENOSYS; -} - -static inline -void lttng_ftrace_unregister(struct ltt_event *event) -{ -} - -static inline -void lttng_ftrace_destroy_private(struct ltt_event *event) -{ -} -#endif - -extern const struct file_operations lttng_tracepoint_list_fops; +int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); + +//extern const struct file_operations lttng_tracepoint_list_fops; #endif /* _LTT_EVENTS_H */ diff --git a/libust/ltt-ring-buffer-client-discard.c b/libust/ltt-ring-buffer-client-discard.c index ca7dfa8..1df3fd7 100644 --- a/libust/ltt-ring-buffer-client-discard.c +++ b/libust/ltt-ring-buffer-client-discard.c @@ -8,13 +8,8 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include #include "ltt-tracer.h" #define RING_BUFFER_MODE_TEMPLATE RING_BUFFER_DISCARD #define RING_BUFFER_MODE_TEMPLATE_STRING "discard" #include "ltt-ring-buffer-client.h" - -MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("LTTng Ring Buffer Client Discard Mode"); diff --git a/libust/ltt-ring-buffer-client-overwrite.c b/libust/ltt-ring-buffer-client-overwrite.c index ec3b1cf..602c3ce 100644 --- a/libust/ltt-ring-buffer-client-overwrite.c +++ b/libust/ltt-ring-buffer-client-overwrite.c @@ -8,13 +8,8 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include #include "ltt-tracer.h" #define RING_BUFFER_MODE_TEMPLATE RING_BUFFER_OVERWRITE #define RING_BUFFER_MODE_TEMPLATE_STRING "overwrite" #include "ltt-ring-buffer-client.h" - -MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("LTTng Ring Buffer Client Overwrite Mode"); diff --git a/libust/ltt-ring-buffer-client.h b/libust/ltt-ring-buffer-client.h index 0d8051e..c7496bf 100644 --- a/libust/ltt-ring-buffer-client.h +++ b/libust/ltt-ring-buffer-client.h @@ -8,14 +8,12 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include -#include -#include "lib/bitfield.h" -#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ -#include "wrapper/trace-clock.h" +#include +#include "ust/bitfield.h" +#include "ust/clock.h" #include "ltt-events.h" #include "ltt-tracer.h" -#include "wrapper/ringbuffer/frontend_types.h" +#include "../libringbuffer/frontend_types.h" /* * Keep the natural field alignment for _each field_ within this structure if @@ -137,6 +135,7 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, } break; default: + padding = 0; WARN_ON_ONCE(1); } offset += ctx_get_size(offset, event->ctx); @@ -146,9 +145,9 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, return offset - orig_offset; } -#include "wrapper/ringbuffer/api.h" +#include "../libringbuffer/api.h" -extern +static void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx, uint32_t event_id); @@ -206,6 +205,7 @@ slow_path: ltt_write_event_header_slow(config, ctx, event_id); } +static void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx, uint32_t event_id) @@ -295,7 +295,7 @@ static size_t client_packet_header_size(void) static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, unsigned int subbuf_idx) { - struct channel *chan = buf->backend.chan; + struct channel *chan = shmp(buf->backend.chan); struct packet_header *header = (struct packet_header *) lib_ring_buffer_offset_address(&buf->backend, @@ -304,7 +304,7 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, struct ltt_session *session = ltt_chan->session; header->magic = CTF_MAGIC_NUMBER; - memcpy(header->uuid, session->uuid.b, sizeof(session->uuid)); + memcpy(header->uuid, session->uuid, sizeof(session->uuid)); header->stream_id = ltt_chan->id; header->ctx.timestamp_begin = tsc; header->ctx.timestamp_end = 0; @@ -321,7 +321,7 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc, unsigned int subbuf_idx, unsigned long data_size) { - struct channel *chan = buf->backend.chan; + struct channel *chan = shmp(buf->backend.chan); struct packet_header *header = (struct packet_header *) lib_ring_buffer_offset_address(&buf->backend, @@ -372,11 +372,12 @@ struct channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shmid) { return channel_create(&client_config, name, ltt_chan, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, - read_timer_interval); + read_timer_interval, shmid); } static @@ -454,6 +455,7 @@ void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src, lib_ring_buffer_write(&client_config, ctx, src, len); } +#if 0 static wait_queue_head_t *ltt_get_reader_wait_queue(struct channel *chan) { @@ -465,6 +467,7 @@ wait_queue_head_t *ltt_get_hp_wait_queue(struct channel *chan) { return &chan->hp_wait; } +#endif //0 static int ltt_is_finalized(struct channel *chan) @@ -480,7 +483,6 @@ int ltt_is_disabled(struct channel *chan) static struct ltt_transport ltt_relay_transport = { .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING, - .owner = THIS_MODULE, .ops = { .channel_create = _channel_create, .channel_destroy = ltt_channel_destroy, @@ -490,36 +492,23 @@ static struct ltt_transport ltt_relay_transport = { .event_commit = ltt_event_commit, .event_write = ltt_event_write, .packet_avail_size = NULL, /* Would be racy anyway */ - .get_reader_wait_queue = ltt_get_reader_wait_queue, - .get_hp_wait_queue = ltt_get_hp_wait_queue, + //.get_reader_wait_queue = ltt_get_reader_wait_queue, + //.get_hp_wait_queue = ltt_get_hp_wait_queue, .is_finalized = ltt_is_finalized, .is_disabled = ltt_is_disabled, }, }; -static int __init ltt_ring_buffer_client_init(void) +static +void __attribute__((constructor)) ltt_ring_buffer_client_init(void) { - /* - * This vmalloc sync all also takes care of the lib ring buffer - * vmalloc'd module pages when it is built as a module into LTTng. - */ - wrapper_vmalloc_sync_all(); - printk(KERN_INFO "LTT : ltt ring buffer client init\n"); + printf("LTT : ltt ring buffer client init\n"); ltt_transport_register(<t_relay_transport); - return 0; } -module_init(ltt_ring_buffer_client_init); - -static void __exit ltt_ring_buffer_client_exit(void) +static +void __attribute__((destructor)) ltt_ring_buffer_client_exit(void) { - printk(KERN_INFO "LTT : ltt ring buffer client exit\n"); + printf("LTT : ltt ring buffer client exit\n"); ltt_transport_unregister(<t_relay_transport); } - -module_exit(ltt_ring_buffer_client_exit); - -MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING - " client"); diff --git a/libust/ltt-ring-buffer-metadata-client.c b/libust/ltt-ring-buffer-metadata-client.c index 64f4408..2794a26 100644 --- a/libust/ltt-ring-buffer-metadata-client.c +++ b/libust/ltt-ring-buffer-metadata-client.c @@ -8,13 +8,8 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include #include "ltt-tracer.h" #define RING_BUFFER_MODE_TEMPLATE RING_BUFFER_DISCARD #define RING_BUFFER_MODE_TEMPLATE_STRING "metadata" #include "ltt-ring-buffer-metadata-client.h" - -MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("LTTng Ring Buffer Metadata Client"); diff --git a/libust/ltt-ring-buffer-metadata-client.h b/libust/ltt-ring-buffer-metadata-client.h index 8b1079d..1ea4117 100644 --- a/libust/ltt-ring-buffer-metadata-client.h +++ b/libust/ltt-ring-buffer-metadata-client.h @@ -8,11 +8,11 @@ * Dual LGPL v2.1/GPL v2 license. */ -#include -#include -#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ +#include +#include "ust/bitfield.h" #include "ltt-events.h" #include "ltt-tracer.h" +#include "../libringbuffer/frontend_types.h" struct metadata_packet_header { uint32_t magic; /* 0x75D11D57 */ @@ -47,7 +47,7 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, return 0; } -#include "wrapper/ringbuffer/api.h" +#include "../libringbuffer/api.h" static u64 client_ring_buffer_clock_read(struct channel *chan) { @@ -78,7 +78,7 @@ static size_t client_packet_header_size(void) static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, unsigned int subbuf_idx) { - struct channel *chan = buf->backend.chan; + struct channel *chan = shmp(buf->backend.chan); struct metadata_packet_header *header = (struct metadata_packet_header *) lib_ring_buffer_offset_address(&buf->backend, @@ -87,7 +87,7 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, struct ltt_session *session = ltt_chan->session; header->magic = TSDL_MAGIC_NUMBER; - memcpy(header->uuid, session->uuid.b, sizeof(session->uuid)); + memcpy(header->uuid, session->uuid, sizeof(session->uuid)); header->checksum = 0; /* 0 if unused */ header->content_size = 0xFFFFFFFF; /* in bits, for debugging */ header->packet_size = 0xFFFFFFFF; /* in bits, for debugging */ @@ -103,7 +103,7 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc, unsigned int subbuf_idx, unsigned long data_size) { - struct channel *chan = buf->backend.chan; + struct channel *chan = shmp(buf->backend.chan); struct metadata_packet_header *header = (struct metadata_packet_header *) lib_ring_buffer_offset_address(&buf->backend, @@ -153,11 +153,12 @@ struct channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shmid) { return channel_create(&client_config, name, ltt_chan, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, - read_timer_interval); + read_timer_interval, shmid); } static @@ -209,7 +210,7 @@ size_t ltt_packet_avail_size(struct channel *chan) unsigned long o_begin; struct lib_ring_buffer *buf; - buf = chan->backend.buf; /* Only for global buffer ! */ + buf = shmp(chan->backend.buf); /* Only for global buffer ! */ o_begin = v_read(&client_config, &buf->offset); if (subbuf_offset(o_begin, chan) != 0) { return chan->backend.subbuf_size - subbuf_offset(o_begin, chan); @@ -219,6 +220,7 @@ size_t ltt_packet_avail_size(struct channel *chan) } } +#if 0 static wait_queue_head_t *ltt_get_reader_wait_queue(struct channel *chan) { @@ -230,6 +232,7 @@ wait_queue_head_t *ltt_get_hp_wait_queue(struct channel *chan) { return &chan->hp_wait; } +#endif //0 static int ltt_is_finalized(struct channel *chan) @@ -245,7 +248,6 @@ int ltt_is_disabled(struct channel *chan) static struct ltt_transport ltt_relay_transport = { .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING, - .owner = THIS_MODULE, .ops = { .channel_create = _channel_create, .channel_destroy = ltt_channel_destroy, @@ -255,36 +257,23 @@ static struct ltt_transport ltt_relay_transport = { .event_commit = ltt_event_commit, .event_write = ltt_event_write, .packet_avail_size = ltt_packet_avail_size, - .get_reader_wait_queue = ltt_get_reader_wait_queue, - .get_hp_wait_queue = ltt_get_hp_wait_queue, + //.get_reader_wait_queue = ltt_get_reader_wait_queue, + //.get_hp_wait_queue = ltt_get_hp_wait_queue, .is_finalized = ltt_is_finalized, .is_disabled = ltt_is_disabled, }, }; -static int __init ltt_ring_buffer_client_init(void) +static +void __attribute__((constructor)) ltt_ring_buffer_client_init(void) { - /* - * This vmalloc sync all also takes care of the lib ring buffer - * vmalloc'd module pages when it is built as a module into LTTng. - */ - wrapper_vmalloc_sync_all(); - printk(KERN_INFO "LTT : ltt ring buffer metadata client init\n"); + printf("LTT : ltt ring buffer client init\n"); ltt_transport_register(<t_relay_transport); - return 0; } -module_init(ltt_ring_buffer_client_init); - -static void __exit ltt_ring_buffer_client_exit(void) +static +void __attribute__((destructor)) ltt_ring_buffer_client_exit(void) { - printk(KERN_INFO "LTT : ltt ring buffer metadata client exit\n"); + printf("LTT : ltt ring buffer client exit\n"); ltt_transport_unregister(<t_relay_transport); } - -module_exit(ltt_ring_buffer_client_exit); - -MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING - " client"); diff --git a/libust/ltt-tracer-core.h b/libust/ltt-tracer-core.h index d6839e4..36d46b9 100644 --- a/libust/ltt-tracer-core.h +++ b/libust/ltt-tracer-core.h @@ -30,10 +30,12 @@ #define RING_BUFFER_ALIGN #endif +#include "usterr_signal_safe.h" +#include "ust/bug.h" #include "../libringbuffer/config.h" struct ltt_session; struct ltt_channel; struct ltt_event; -#define /* _LTT_TRACER_CORE_H */ +#endif /* _LTT_TRACER_CORE_H */