From: Mathieu Desnoyers Date: Thu, 17 Nov 2011 19:37:56 +0000 (-0500) Subject: Installed headers relicensing and cleanup X-Git-Tag: v1.9.1~87 X-Git-Url: http://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=b728d87e617189fe9898a9492a559ecf949d2348 Installed headers relicensing and cleanup - Move all locally-used code outside of include/lttng. - All headers included in applications for tracing are relicensed to MIT license, except for lttng/core.h and lttng/usterr-signal-safe.h, which both purposefully only contain trivial declarations are static inline functions/macros of 10 lines or less. They are therefore OK to include into non-GPL applications without being considered as derivative work under the terms of the LGPLv2.1 license. - Update version number support. Signed-off-by: Mathieu Desnoyers --- diff --git a/configure.ac b/configure.ac index 65eafee7..134ed145 100644 --- a/configure.ac +++ b/configure.ac @@ -11,13 +11,16 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_CONFIG_SRCDIR([include/lttng/tracepoint.h]) AC_CONFIG_HEADERS([config.h include/lttng/config.h]) AH_TEMPLATE([HAVE_EFFICIENT_UNALIGNED_ACCESS], [Use efficient unaligned access.]) -# Compute minor/major version numbers -major_version=`echo AC_PACKAGE_VERSION | sed 's/\..*//'` -minor_version=`echo AC_PACKAGE_VERSION | sed 's/.*\.//' | sed 's/^0//'` +# Compute minor/major/patchlevel version numbers +major_version=$(echo AC_PACKAGE_VERSION | sed 's/\([^.]\)*\.\([^.]*\)\.\([^.]*\)/\1/)' +minor_version=$(echo AC_PACKAGE_VERSION | sed 's/\([^.]\)*\.\([^.]*\)\.\([^.]*\)/\2/)' +patchlevel_version=$(echo AC_PACKAGE_VERSION | sed 's/\([^.]\)*\.\([^.]*\)\.\([^.]*\)/\3/)' AC_SUBST([MAJOR_VERSION], [$major_version]) AC_SUBST([MINOR_VERSION], [$minor_version]) +AC_SUBST([PATCHLEVEL_VERSION], [$patchlevel_version]) AC_DEFINE_UNQUOTED([VERSION_MAJOR], $major_version, [UST major version number]) AC_DEFINE_UNQUOTED([VERSION_MINOR], $minor_version, [UST minor version number]) +AC_DEFINE_UNQUOTED([VERSION_PATCHLEVEL], $patchlevel_version, [UST patchlevel version number]) # Checks for programs. @@ -213,7 +216,7 @@ AM_CONDITIONAL(BUILD_JNI_INTERFACE, test "$with_jni_interface" = "yes") AC_CONFIG_FILES([ Makefile include/Makefile - include/lttng/version.h + include/lttng/ust-version.h doc/Makefile doc/man/Makefile doc/info/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 350d927e..4a0a4ba6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,7 +6,7 @@ nobase_include_HEADERS = \ lttng/ust-tracepoint-event-reset.h \ lttng/ust-events.h \ lttng/ust-ctl.h \ - lttng/version.h \ + lttng/ust-version.h \ lttng/ust-abi.h \ lttng/ringbuffer-abi.h \ lttng/ust-tracer.h \ @@ -15,25 +15,14 @@ nobase_include_HEADERS = \ lttng/share.h \ lttng/ust.h \ lttng/core.h \ - lttng/processor.h \ - lttng/kcompat/kcompat.h \ - lttng/kcompat/jhash.h \ - lttng/kcompat/compiler.h \ - lttng/kcompat/types.h \ lttng/ringbuffer-config.h \ lttng/align.h \ - lttng/bug.h \ - lttng/vatomic.h + lttng/bug.h # note: usterr-signal-safe.h, core.h and share.h need namespace cleanup. noinst_HEADERS = \ usterr.h \ ust_snprintf.h \ - lttng/ust-comm.h \ - lttng/compat.h \ - lttng/clock.h \ - lttng/probe-internal.h \ - lttng/stringify.h \ - lttng/wait.h \ + ust-comm.h \ lttng/bitfield.h diff --git a/include/lttng/clock.h b/include/lttng/clock.h deleted file mode 100644 index 3de1fa81..00000000 --- a/include/lttng/clock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2010 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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; 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 - */ - -#ifndef _UST_CLOCK_H -#define _UST_CLOCK_H - -#include -#include -#include -#include -#include - -/* TRACE CLOCK */ - -/* - * Currently using the kernel MONOTONIC clock, waiting for kernel-side - * LTTng to implement mmap'd trace clock. - */ - -/* Choosing correct trace clock */ - -static __inline__ uint64_t trace_clock_read64(void) -{ - struct timespec ts; - - clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * 1000000000) + ts.tv_nsec; -} - -#if __i386__ || __x86_64__ -static __inline__ uint64_t trace_clock_frequency(void) -{ - return 1000000000LL; -} -#endif /* #else #if __i386__ || __x86_64__ */ - -static __inline__ uint32_t trace_clock_freq_scale(void) -{ - return 1; -} - -#endif /* _UST_CLOCK_H */ diff --git a/include/lttng/compat.h b/include/lttng/compat.h deleted file mode 100644 index c896e728..00000000 --- a/include/lttng/compat.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _UST_COMPAT_H -#define _UST_COMPAT_H - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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; either - * 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 - -#ifdef __UCLIBC__ -#define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache) -static inline -int sched_getcpu(void) -{ - int c, s; - - s = __getcpu(&c, NULL, NULL); - return (s == -1) ? s : c; -} -#endif /* __UCLIBC__ */ -#endif /* _UST_COMPAT_H */ diff --git a/include/lttng/core.h b/include/lttng/core.h index 5bd19829..086d50d3 100644 --- a/include/lttng/core.h +++ b/include/lttng/core.h @@ -105,7 +105,6 @@ void *zmalloc_align(size_t len) /* MATH */ -#include static inline unsigned int hweight32(unsigned int w) { unsigned int res = w - ((w >> 1) & 0x55555555); @@ -115,20 +114,6 @@ static inline unsigned int hweight32(unsigned int w) return (res + (res >> 16)) & 0x000000FF; } -static __inline__ int get_count_order(unsigned int count) -{ - int order; - - order = fls(count) - 1; - if (count & (count - 1)) - order++; - return order; -} - -#define _ust_container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - #ifndef inline_memcpy #define inline_memcpy memcpy #endif @@ -139,30 +124,29 @@ static __inline__ int get_count_order(unsigned int count) #ifndef UST_VALGRIND +/* + * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback. + */ static __inline__ int ust_get_cpu(void) { - int cpu; + int cpu = sched_getcpu(); - cpu = sched_getcpu(); if (caa_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 */ +/* + * 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. + */ 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; } diff --git a/include/lttng/kcompat/compiler.h b/include/lttng/kcompat/compiler.h deleted file mode 100644 index f2fbd3e3..00000000 --- a/include/lttng/kcompat/compiler.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * compiler.h - * - * Copyright (C) 2009 - Pierre-Marc Fournier (pierre-marc dot fournier at polymtl dot ca) - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - */ - -#ifndef KCOMPAT_COMPILER_H -#define KCOMPAT_COMPILER_H - -# define inline inline __attribute__((always_inline)) -# define __inline__ __inline__ __attribute__((always_inline)) -# define __inline __inline __attribute__((always_inline)) - -#ifndef __always_inline -#define __always_inline inline -#endif - -#define __pure __attribute__((pure)) -#define __aligned(x) __attribute__((aligned(x))) -#define __printf(a,b) __attribute__((format(printf,a,b))) -#define noinline __attribute__((noinline)) -#define __attribute_const__ __attribute__((__const__)) -#define __used __attribute__((used)) -#define __maybe_unused __attribute__((unused)) - -#define notrace __attribute__((no_instrument_function)) - -#endif /* KCOMPAT_COMPILER_H */ diff --git a/include/lttng/kcompat/jhash.h b/include/lttng/kcompat/jhash.h deleted file mode 100644 index 2635167b..00000000 --- a/include/lttng/kcompat/jhash.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef KCOMPAT_JHASH_H -#define KCOMPAT_JHASH_H - -/* jhash.h: Jenkins hash support. - * - * Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net) - * - * http://burtleburtle.net/bob/hash/ - * - * These are the credits from Bob's sources: - * - * lookup2.c, by Bob Jenkins, December 1996, Public Domain. - * hash(), hash2(), hash3, and mix() are externally useful functions. - * Routines to test the hash are included if SELF_TEST is defined. - * You can use this free for any purpose. It has no warranty. - * - * Copyright (C) 2003 David S. Miller (davem@redhat.com) - * - * I've modified Bob's hash to be useful in the Linux kernel, and - * any bugs present are surely my fault. -DaveM - */ - -/* NOTE: Arguments are modified. */ -#define __jhash_mix(a, b, c) \ -{ \ - a -= b; a -= c; a ^= (c>>13); \ - b -= c; b -= a; b ^= (a<<8); \ - c -= a; c -= b; c ^= (b>>13); \ - a -= b; a -= c; a ^= (c>>12); \ - b -= c; b -= a; b ^= (a<<16); \ - c -= a; c -= b; c ^= (b>>5); \ - a -= b; a -= c; a ^= (c>>3); \ - b -= c; b -= a; b ^= (a<<10); \ - c -= a; c -= b; c ^= (b>>15); \ -} - -/* The golden ration: an arbitrary value */ -#define JHASH_GOLDEN_RATIO 0x9e3779b9 - -/* The most generic version, hashes an arbitrary sequence - * of bytes. No alignment or length assumptions are made about - * the input key. - */ -static inline u32 jhash(const void *key, u32 length, u32 initval) -{ - u32 a, b, c, len; - const u8 *k = (const u8 *) key; - - len = length; - a = b = JHASH_GOLDEN_RATIO; - c = initval; - - while (len >= 12) { - a += (k[0] +((u32)k[1]<<8) +((u32)k[2]<<16) +((u32)k[3]<<24)); - b += (k[4] +((u32)k[5]<<8) +((u32)k[6]<<16) +((u32)k[7]<<24)); - c += (k[8] +((u32)k[9]<<8) +((u32)k[10]<<16)+((u32)k[11]<<24)); - - __jhash_mix(a,b,c); - - k += 12; - len -= 12; - } - - c += length; - switch (len) { - case 11: c += ((u32)k[10]<<24); - case 10: c += ((u32)k[9]<<16); - case 9 : c += ((u32)k[8]<<8); - case 8 : b += ((u32)k[7]<<24); - case 7 : b += ((u32)k[6]<<16); - case 6 : b += ((u32)k[5]<<8); - case 5 : b += k[4]; - case 4 : a += ((u32)k[3]<<24); - case 3 : a += ((u32)k[2]<<16); - case 2 : a += ((u32)k[1]<<8); - case 1 : a += k[0]; - }; - - __jhash_mix(a,b,c); - - return c; -} - -#endif /* KCOMPAT_JHASH_H */ diff --git a/include/lttng/kcompat/kcompat.h b/include/lttng/kcompat/kcompat.h deleted file mode 100644 index 3fdea648..00000000 --- a/include/lttng/kcompat/kcompat.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * kcompat.h - * - * Copyright (C) 2009 - Pierre-Marc Fournier (pierre-marc dot fournier at polymtl dot ca) - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - */ - -#ifndef KCOMPAT_H -#define KCOMPAT_H - -#define __KERNEL__ -#define _LOOSE_KERNEL_NAMES - -#ifndef CONFIG_SMP -#define CONFIG_SMP 1 /* Needed for urcu, verify it's ok to remove it. */ -#endif - -#include -#include -#if __WORDSIZE == 32 -#define LIBKCOMPAT_X86_32 -#elif __WORDSIZE == 64 -#define LIBKCOMPAT_X86_64 -#else -#error "Unsupported" -#endif - -#ifdef LIBKCOMPAT_X86_32 -#define CONFIG_X86_32 -#define CONFIG_32BIT -#endif - -#ifdef LIBKCOMPAT_X86_64 -#define CONFIG_X86_64 -#define CONFIG_64BIT -#endif - -/* Standard libs */ -#include -#include - -/* Taken from userspace-rcu */ -#include - -/* Kernel libs */ -#include -#include -#include - -#endif /* KCOMPAT_H */ diff --git a/include/lttng/kcompat/types.h b/include/lttng/kcompat/types.h deleted file mode 100644 index 63f9ede0..00000000 --- a/include/lttng/kcompat/types.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _KCOMPAT_TYPES -#define _KCOMPAT_TYPES - -/* - * Kernel sourcecode compatibility layer - * - * Copyright (C) 2009 Novell Inc. - * - * Author: Jan Blunck - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2.1 as - * published by the Free Software Foundation. - */ - -#include - -#ifdef __KERNEL__ -typedef __s8 s8; -typedef __u8 u8; - -typedef __s16 s16; -typedef __u16 u16; - -typedef __s32 s32; -typedef __u32 u32; - -typedef __s64 s64; -typedef __u64 u64; -#endif - -#endif /* _KCOMPAT_TYPES */ diff --git a/include/lttng/probe-internal.h b/include/lttng/probe-internal.h deleted file mode 100644 index a4f3a0e5..00000000 --- a/include/lttng/probe-internal.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _UST_PROBE_H -#define _UST_PROBE_H - -/* - * Copyright (C) 2009 Pierre-Marc Fournier - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - * - */ - -/* Maximum number of callbacks per marker */ -#define LTT_NR_CALLBACKS 10 - -struct ltt_serialize_closure; -struct ust_buffer; - -typedef size_t (*ltt_serialize_cb)(struct ust_buffer *buf, size_t buf_offset, - struct ltt_serialize_closure *closure, - void *serialize_private, - unsigned int stack_pos_ctx, - int *largest_align, - const char *fmt, va_list *args); - -struct ltt_available_probe { - const char *name; /* probe name */ - const char *format; - ust_marker_probe_func *probe_func; - ltt_serialize_cb callbacks[LTT_NR_CALLBACKS]; - struct cds_list_head node; /* registered probes list */ -}; - -extern int ltt_probe_register(struct ltt_available_probe *pdata); -extern int ltt_probe_unregister(struct ltt_available_probe *pdata); -extern int ltt_ust_marker_connect(const char *channel, const char *mname, - const char *pname); -extern int ltt_ust_marker_disconnect(const char *channel, const char *mname, - const char *pname); - -#endif /* _UST_PROBE_H */ diff --git a/include/lttng/processor.h b/include/lttng/processor.h deleted file mode 100644 index e3407bab..00000000 --- a/include/lttng/processor.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2009 Pierre-Marc Fournier - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - */ - -#ifndef UST_PROCESSOR_H -#define UST_PROCESSOR_H - -#define ____cacheline_aligned __attribute__((aligned(CAA_CACHE_LINE_SIZE))) - -#ifdef __i386 - -static inline int fls(int x) -{ - int r; - asm("bsrl %1,%0\n\t" - "cmovzl %2,%0" - : "=&r" (r) : "rm" (x), "rm" (-1)); - return r + 1; -} - -#elif defined(__x86_64) - -static inline int fls(int x) -{ - int r; - asm("bsrl %1,%0\n\t" - "cmovzl %2,%0" - : "=&r" (r) : "rm" (x), "rm" (-1)); - return r + 1; -} - -#elif defined(__PPC__) - -static __inline__ int fls(unsigned int x) -{ - int lz; - - asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x)); - return 32 - lz; -} - -#else /* arch-agnostic */ - -static __inline__ int fls(unsigned int x) -{ - int r = 32; - - if (!x) - return 0; - if (!(x & 0xFFFF0000U)) { - x <<= 16; - r -= 16; - } - if (!(x & 0xFF000000U)) { - x <<= 8; - r -= 8; - } - if (!(x & 0xF0000000U)) { - x <<= 4; - r -= 4; - } - if (!(x & 0xC0000000U)) { - x <<= 2; - r -= 2; - } - if (!(x & 0x80000000U)) { - x <<= 1; - r -= 1; - } - return r; -} - -#endif - -#endif /* UST_PROCESSOR_H */ diff --git a/include/lttng/ringbuffer-config.h b/include/lttng/ringbuffer-config.h index 60124c60..151fda13 100644 --- a/include/lttng/ringbuffer-config.h +++ b/include/lttng/ringbuffer-config.h @@ -22,7 +22,9 @@ #include #include "lttng/ust-tracer.h" #include "lttng/usterr-signal-safe.h" -#include "lttng/kcompat/kcompat.h" +#include +#include +#include #include "lttng/align.h" struct lttng_ust_lib_ring_buffer; diff --git a/include/lttng/share.h b/include/lttng/share.h index cecfaa17..776fc85f 100644 --- a/include/lttng/share.h +++ b/include/lttng/share.h @@ -1,83 +1,20 @@ +#ifndef _LTTNG_SHARE_H +#define _LTTNG_SHARE_H + /* - * Copyright (C) 2009 Pierre-Marc Fournier - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. + * Copyright (c) 2011 - Mathieu Desnoyers * - * 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. + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. * - * 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 - */ - -#ifndef UST_SHARE_H -#define UST_SHARE_H - -/* write() */ -#include - -/* send() */ -#include -#include - -#include - -/* - * This write is patient because it restarts if it was incomplete. + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. */ -static __inline__ ssize_t patient_write(int fd, const void *buf, size_t count) -{ - const char *bufc = (const char *) buf; - int result; - - for(;;) { - result = write(fd, bufc, count); - if (result == -1 && errno == EINTR) { - continue; - } - if (result <= 0) { - return result; - } - count -= result; - bufc += result; - - if (count == 0) { - break; - } - } - - return bufc-(const char *)buf; -} - -static __inline__ ssize_t patient_send(int fd, const void *buf, size_t count, int flags) -{ - const char *bufc = (const char *) buf; - int result; - - for(;;) { - result = send(fd, bufc, count, flags); - if (result == -1 && errno == EINTR) { - continue; - } - if (result <= 0) { - return result; - } - count -= result; - bufc += result; - - if (count == 0) { - break; - } - } - - return bufc - (const char *) buf; -} +ssize_t patient_write(int fd, const void *buf, size_t count); +ssize_t patient_send(int fd, const void *buf, size_t count, int flags); -#endif /* UST_SHARE_H */ +#endif /* _LTTNG_SHARE_H */ diff --git a/include/lttng/stringify.h b/include/lttng/stringify.h deleted file mode 100644 index b8dfd90c..00000000 --- a/include/lttng/stringify.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __LINUX_STRINGIFY_H -#define __LINUX_STRINGIFY_H -/* - * Copyright (C) 2009 Zhaolei - * - * 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; - * 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 - */ - -/* Indirect stringification. Doing two levels allows the parameter to be a - * macro itself. For example, compile with -DFOO=bar, __stringify(FOO) - * converts to "bar". - */ - -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - -#endif /* !__LINUX_STRINGIFY_H */ diff --git a/include/lttng/tracepoint-types.h b/include/lttng/tracepoint-types.h new file mode 100644 index 00000000..fad23bc4 --- /dev/null +++ b/include/lttng/tracepoint-types.h @@ -0,0 +1,34 @@ +#ifndef _LTTNG_TRACEPOINT_TYPES_H +#define _LTTNG_TRACEPOINT_TYPES_H + +/* + * Copyright (c) 2011 - Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +struct tracepoint_probe { + void *callback; + void *priv; +}; + +struct tracepoint { + const char *name; + int state; + struct tracepoint_probe *probes; +}; + +struct tracepoint_lib { + struct cds_list_head list; + struct tracepoint tracepoints_start; + int tracepoints_count; +}; + +#endif /* _LTTNG_TRACEPOINT_TYPES_H */ diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h new file mode 100644 index 00000000..ffae20a2 --- /dev/null +++ b/include/lttng/tracepoint.h @@ -0,0 +1,339 @@ +#ifndef _LTTNG_TRACEPOINT_H +#define _LTTNG_TRACEPOINT_H + +/* + * Copyright (c) 2011 - Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define tracepoint(provider, name, ...) \ + do { \ + if (caa_unlikely(__tracepoint_##provider##_##name.state)) \ + __tracepoint_##provider##_##name(__VA_ARGS__); \ + } while (0) + +#define TP_ARGS(...) __VA_ARGS__ + +/* + * TP_ARGS takes tuples of type, argument separated by a comma. + * It can take up to 10 tuples (which means that less than 10 tuples is + * fine too). + * Each tuple is also separated by a comma. + */ +#define _TP_COMBINE_TOKENS1(_tokena, _tokenb) _tokena##_tokenb +#define _TP_COMBINE_TOKENS(_tokena, _tokenb) _TP_COMBINE_TOKENS1(_tokena, _tokenb) + +/* _TP_EXVAR* extract the vars names. */ +#define _TP_EXVAR0() +#define _TP_EXVAR2(a,b) b +#define _TP_EXVAR4(a,b,c,d) b,d +#define _TP_EXVAR6(a,b,c,d,e,f) b,d,f +#define _TP_EXVAR8(a,b,c,d,e,f,g,h) b,d,f,h +#define _TP_EXVAR10(a,b,c,d,e,f,g,h,i,j) b,d,f,h,j +#define _TP_EXVAR12(a,b,c,d,e,f,g,h,i,j,k,l) b,d,f,h,j,l +#define _TP_EXVAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) b,d,f,h,j,l,n +#define _TP_EXVAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) b,d,f,h,j,l,n,p +#define _TP_EXVAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) b,d,f,h,j,l,n,p,r +#define _TP_EXVAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) b,d,f,h,j,l,n,p,r,t + +#define _TP_EXDATA_VAR0() __tp_data +#define _TP_EXDATA_VAR2(a,b) __tp_data,b +#define _TP_EXDATA_VAR4(a,b,c,d) __tp_data,b,d +#define _TP_EXDATA_VAR6(a,b,c,d,e,f) __tp_data,b,d,f +#define _TP_EXDATA_VAR8(a,b,c,d,e,f,g,h) __tp_data,b,d,f,h +#define _TP_EXDATA_VAR10(a,b,c,d,e,f,g,h,i,j) __tp_data,b,d,f,h,j +#define _TP_EXDATA_VAR12(a,b,c,d,e,f,g,h,i,j,k,l) __tp_data,b,d,f,h,j,l +#define _TP_EXDATA_VAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) __tp_data,b,d,f,h,j,l,n +#define _TP_EXDATA_VAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) __tp_data,b,d,f,h,j,l,n,p +#define _TP_EXDATA_VAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) __tp_data,b,d,f,h,j,l,n,p,r +#define _TP_EXDATA_VAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) __tp_data,b,d,f,h,j,l,n,p,r,t + +/* _TP_EXPROTO* extract tuples of type, var */ +#define _TP_EXPROTO0() +#define _TP_EXPROTO2(a,b) a b +#define _TP_EXPROTO4(a,b,c,d) a b,c d +#define _TP_EXPROTO6(a,b,c,d,e,f) a b,c d,e f +#define _TP_EXPROTO8(a,b,c,d,e,f,g,h) a b,c d,e f,g h +#define _TP_EXPROTO10(a,b,c,d,e,f,g,h,i,j) a b,c d,e f,g h,i j +#define _TP_EXPROTO12(a,b,c,d,e,f,g,h,i,j,k,l) a b,c d,e f,g h,i j,k l +#define _TP_EXPROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) a b,c d,e f,g h,i j,k l,m n +#define _TP_EXPROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) a b,c d,e f,g h,i j,k l,m n,o p +#define _TP_EXPROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) a b,c d,e f,g h,i j,k l,m n,o p,q r +#define _TP_EXPROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) a b,c d,e f,g h,i j,k l,m n,o p,q r,s t + +#define _TP_EXDATA_PROTO0() void *__tp_data +#define _TP_EXDATA_PROTO2(a,b) void *__tp_data,a b +#define _TP_EXDATA_PROTO4(a,b,c,d) void *__tp_data,a b,c d +#define _TP_EXDATA_PROTO6(a,b,c,d,e,f) void *__tp_data,a b,c d,e f +#define _TP_EXDATA_PROTO8(a,b,c,d,e,f,g,h) void *__tp_data,a b,c d,e f,g h +#define _TP_EXDATA_PROTO10(a,b,c,d,e,f,g,h,i,j) void *__tp_data,a b,c d,e f,g h,i j +#define _TP_EXDATA_PROTO12(a,b,c,d,e,f,g,h,i,j,k,l) void *__tp_data,a b,c d,e f,g h,i j,k l +#define _TP_EXDATA_PROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) void *__tp_data,a b,c d,e f,g h,i j,k l,m n +#define _TP_EXDATA_PROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p +#define _TP_EXDATA_PROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r +#define _TP_EXDATA_PROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r,s t + +/* Preprocessor trick to count arguments. Inspired from sdt.h. */ +#define _TP_NARGS(...) __TP_NARGS(__VA_ARGS__, 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) +#define __TP_NARGS(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, N, ...) N +#define _TP_PROTO_N(N, ...) _TP_PARAMS(TP_COMBINE_TOKENS(_TP_SPLIT, N)(__VA_ARGS__)) +#define _TP_VARS_N(N, ...) _TP_PARAMS(TP_COMBINE_TOKENS(_TP_EVEN, N)(__VA_ARGS__)) +#define _TP_DATA_PROTO_N(N, ...) _TP_PARAMS(TP_COMBINE_TOKENS(_TP_SPLIT_DATA, N)(__VA_ARGS__)) +#define _TP_DATA_VARS_N(N, ...) _TP_PARAMS(TP_COMBINE_TOKENS(_TP_EVEN_DATA, N)(__VA_ARGS__)) +#define _TP_ARGS_PROTO(...) _TP_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) +#define _TP_ARGS_VARS(...) _TP_VARS_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) +#define _TP_ARGS_DATA_PROTO(...) _TP_DATA_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) +#define _TP_ARGS_DATA_VARS(...) _TP_DATA_VARS_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) +#define _TP_PARAMS(...) __VA_ARGS__ + +#define _DECLARE_TRACEPOINT(provider, name, ...) \ +static inline void __tracepoint_##provider##_##name(_TP_ARGS_DATA_PROTO(__VA_ARGS__)) \ +{ \ + struct tracepoint_probe *__tp_probe; \ + \ + rcu_read_lock_bp(); \ + p = rcu_dereference(__tracepoint_##provider##_##name.probes); \ + if (caa_unlikely(!p)) \ + goto end; \ + do { \ + void *__tp_data = p->priv; \ + \ + (*p->callback)(_TP_ARGS_DATA_VARS(__VA_ARGS__)); \ + __tp_probe++; \ + } while (*__tp_probe); \ +end: \ + rcu_read_unlock_bp(); \ +} \ +static inline void __tracepoint_register_##provider##_##name(char *name, \ + void *callback, void *priv) \ +{ \ + __tracepoint_probe_register(name, callback, data); \ +} \ +static inline void __tracepoint_unregister_##provider##_##name(char *name, \ + void *callback, void *priv) \ +{ \ + __tracepoint_probe_unregister(name, callback, data); \ +} + +/* + * Note: to allow PIC code, we need to allow the linker to update the pointers + * in the __tracepoints_ptrs section. + * Therefore, this section is _not_ const (read-only). + */ +#define _DEFINE_TRACEPOINT(provider, name) \ + static const char __tp_strtab_##provider##___##name[] \ + __attribute__((section("__tracepoints_strings"))) = \ + #provider ":" #name; \ + struct tracepoint __tracepoint_##provider##___##name \ + __attribute__((section("__tracepoints"))) = \ + { __tp_strtab_##provider##___##name, 0, NULL }; \ + static struct tracepoint * __tracepoint_ptr_##provider##___##name \ + __attribute__((used, section("__tracepoints_ptrs"))) = \ + &__tracepoint_##provider##___##name; + +extern int __tracepoint_probe_register(const char *name, void *callback, void *priv); +extern int __tracepoint_probe_unregister(const char *name, void *callback, void *priv); +extern int tracepoint_register_lib(struct tracepoint * const *tracepoints_start, + int tracepoints_count); +extern int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); + +/* + * These weak symbols, the constructor, and destructor take care of + * registering only _one_ instance of the tracepoints per shared-ojbect + * (or for the whole main program). + */ +extern struct tracepoint * const __start___tracepoints_ptrs[] + __attribute__((weak, visibility("hidden"))); +extern struct tracepoint * const __stop___tracepoints_ptrs[] + __attribute__((weak, visibility("hidden"))); +int __tracepoint_registered + __attribute__((weak, visibility("hidden"))); + +static void __attribute__((constructor)) __tracepoints__init(void) +{ + if (__tracepoint_registered++) + return; + tracepoint_register_lib(__start___tracepoints_ptrs, + __stop___tracepoints_ptrs - + __start___tracepoints_ptrs); +} + +static void __attribute__((destructor)) __tracepoints__destroy(void) +{ + if (--__tracepoint_registered) + return; + tracepoint_unregister_lib(__start___tracepoints_ptrs); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _LTTNG_TRACEPOINT_H */ + +/* The following declarations must be outside re-inclusion protection. */ + +#ifndef TRACEPOINT_EVENT + +/* + * How to use the TRACEPOINT_EVENT macro: + * + * An example: + * + * TRACEPOINT_EVENT(someproject_component, event_name, + * + * * TP_ARGS takes from 0 to 10 "type, field_name" pairs * + * + * TP_ARGS(int, arg0, void *, arg1, char *, string, size_t, strlen, + * long *, arg4, size_t, arg4_len), + * + * * TP_FIELDS describes the event payload layout in the trace * + * + * TP_FIELDS( + * * Integer, printed in base 10 * + * ctf_integer(int, field_a, arg0) + * + * * Integer, printed with 0x base 16 * + * ctf_integer_hex(unsigned long, field_d, arg1) + * + * * Array Sequence, printed as UTF8-encoded array of bytes * + * ctf_array_text(char, field_b, string, FIXED_LEN) + * ctf_sequence_text(char, field_c, string, size_t, strlen) + * + * * String, printed as UTF8-encoded string * + * ctf_string(field_e, string) + * + * * Array sequence of signed integer values * + * ctf_array(long, field_f, arg4, FIXED_LEN4) + * ctf_sequence(long, field_g, arg4, size_t, arg4_len) + * ) + * ) + * + * More detailed explanation: + * + * The name of the tracepoint is expressed as a tuple with the provider + * and name arguments. + * + * The provider and name should be a proper C99 identifier. + * The "provider" and "name" MUST follow these rules to ensure no + * namespace clash occurs: + * + * For projects (applications and libraries) for which an entity + * specific to the project controls the source code and thus its + * tracepoints (typically with a scope larger than a single company): + * + * either: + * project_component, event + * or: + * project, event + * + * Where "project" is the name of the project, + * "component" is the name of the project component (which may + * include several levels of sub-components, e.g. + * ...component_subcomponent_...) where the tracepoint is located + * (optional), + * "event" is the name of the tracepoint event. + * + * For projects issued from a single company wishing to advertise that + * the company controls the source code and thus the tracepoints, the + * "com_" prefix should be used: + * + * either: + * com_company_project_component, event + * or: + * com_company_project, event + * + * Where "company" is the name of the company, + * "project" is the name of the project, + * "component" is the name of the project component (which may + * include several levels of sub-components, e.g. + * ...component_subcomponent_...) where the tracepoint is located + * (optional), + * "event" is the name of the tracepoint event. + * + * the provider:event identifier is limited to 127 characters. + */ + + +#define TRACEPOINT_EVENT(provider, name, args, fields) \ + _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) + +#define TRACEPOINT_EVENT_CLASS(provider, name, args, fields) + +#define TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \ + _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) + +#endif /* #ifndef TRACEPOINT_EVENT */ + +#ifndef TRACEPOINT_LOGLEVEL + +/* + * Tracepoint Loglevel Declaration Facility + * + * This is a place-holder the tracepoint loglevel declaration, + * overridden by the tracer implementation. + * + * Typical use of these loglevels: + * + * 1) Declare the mapping between loglevel names and an integer values + * within TRACEPOINT_LOGLEVEL_ENUM, using TP_LOGLEVEL for each tuple. + * Do _NOT_ add comma (,) nor semicolon (;) between the + * TRACEPOINT_LOGLEVEL_ENUM entries. Do _NOT_ add comma (,) nor + * semicolon (;) after the TRACEPOINT_LOGLEVEL_ENUM declaration. The + * name should be a proper C99 identifier. + * + * TRACEPOINT_LOGLEVEL_ENUM( + * TP_LOGLEVEL( < loglevel_name >, < value > ) + * TP_LOGLEVEL( < loglevel_name >, < value > ) + * ... + * ) + * + * e.g.: + * + * TRACEPOINT_LOGLEVEL_ENUM( + * TP_LOGLEVEL(LOG_EMERG, 0) + * TP_LOGLEVEL(LOG_ALERT, 1) + * TP_LOGLEVEL(LOG_CRIT, 2) + * TP_LOGLEVEL(LOG_ERR, 3) + * TP_LOGLEVEL(LOG_WARNING, 4) + * TP_LOGLEVEL(LOG_NOTICE, 5) + * TP_LOGLEVEL(LOG_INFO, 6) + * TP_LOGLEVEL(LOG_DEBUG, 7) + * ) + * + * 2) Then, declare tracepoint loglevels for tracepoints. A + * TRACEPOINT_EVENT should be declared prior to the the + * TRACEPOINT_LOGLEVEL for a given tracepoint name. The first field + * is the name of the tracepoint, the second field is the loglevel + * name. + * + * TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >, < event >, + * < loglevel_name >) + * + * The TRACEPOINT_PROVIDER must be defined when declaring a + * TRACEPOINT_LOGLEVEL_ENUM and TRACEPOINT_LOGLEVEL. The tracepoint + * loglevel enumeration apply to the entire TRACEPOINT_PROVIDER. Only one + * tracepoint loglevel enumeration should be declared per tracepoint + * provider. + */ + +#define TRACEPOINT_LOGLEVEL_ENUM() +#define TRACEPOINT_LOGLEVEL(name, loglevel) + +#endif /* #ifndef TRACEPOINT_LOGLEVEL */ diff --git a/include/lttng/ust-abi.h b/include/lttng/ust-abi.h index 31140b4e..5e4bf49e 100644 --- a/include/lttng/ust-abi.h +++ b/include/lttng/ust-abi.h @@ -36,9 +36,9 @@ enum lttng_ust_output { }; struct lttng_ust_tracer_version { - uint32_t version; + uint32_t major; + uint32_t minor; uint32_t patchlevel; - uint32_t sublevel; }; struct lttng_ust_channel { diff --git a/include/lttng/ust-comm.h b/include/lttng/ust-comm.h deleted file mode 100644 index deb0438b..00000000 --- a/include/lttng/ust-comm.h +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef _LTTNG_UST_COMM_H -#define _LTTNG_UST_COMM_H - -/* - * Copyright (C) 2011 - David Goulet - * Julien Desfossez - * Mathieu Desnoyers - * - * 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 - */ - -/* - * This header is meant for liblttng and libust internal use ONLY. - * These declarations should NOT be considered stable API. - */ - -#include -#include -#include - -/* - * Default timeout the application waits for the sessiond to send its - * "register done" command. Can be overridden with the environment - * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not - * found, the application proceeds directly without any delay. - */ -#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000 - -#define LTTNG_RUNDIR "/var/run/lttng" - -/* Default unix socket path */ -#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-lttng-sessiond" -#define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-lttng-sessiond" -#define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-lttng-sessiond" -#define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-lttng-sessiond" - -#define DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait" -#define DEFAULT_HOME_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait-%u" - -/* Queue size of listen(2) */ -#define LTTNG_UST_COMM_MAX_LISTEN 10 - -/* Get the error code index from 0. USTCOMM_ERR starts at 1000. - */ -#define USTCOMM_ERR_INDEX(code) (code - USTCOMM_ERR) - -/* - * ustcomm error code. - */ -enum ustcomm_return_code { - USTCOMM_OK = 0, /* Ok */ - /* Range 1 to 999 used for standard error numbers (errno.h) */ - USTCOMM_ERR = 1000, /* Unknown Error */ - USTCOMM_UND, /* Undefine command */ - USTCOMM_NOT_IMPLEMENTED, /* Command not implemented */ - USTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */ - USTCOMM_ALLOC_FAIL, /* Trace allocation fail */ - USTCOMM_NO_SESSION, /* No session found */ - USTCOMM_CREATE_FAIL, /* Create trace fail */ - USTCOMM_SESSION_FAIL, /* Create session fail */ - USTCOMM_START_FAIL, /* Start tracing fail */ - USTCOMM_STOP_FAIL, /* Stop tracing fail */ - USTCOMM_LIST_FAIL, /* Listing apps fail */ - USTCOMM_NO_APPS, /* No traceable application */ - USTCOMM_SESS_NOT_FOUND, /* Session name not found */ - USTCOMM_NO_TRACE, /* No trace exist */ - USTCOMM_FATAL, /* Session daemon had a fatal error */ - USTCOMM_NO_TRACEABLE, /* Error for non traceable app */ - USTCOMM_SELECT_SESS, /* Must select a session */ - USTCOMM_EXIST_SESS, /* Session name already exist */ - USTCOMM_NO_EVENT, /* No event found */ - USTCOMM_KERN_NA, /* Kernel tracer unavalable */ - USTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */ - USTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ - USTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ - USTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ - USTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ - USTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ - USTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ - USTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ - USTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ - USTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ - USTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ - USTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ - USTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ - USTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ - USTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ - USTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ - USTCOMM_KERN_NO_SESSION, /* No kernel session found */ - USTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ - USTCONSUMER_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ - USTCONSUMER_SUCCESS_RECV_FD, /* success on receiving fds */ - USTCONSUMER_ERROR_RECV_FD, /* error on receiving fds */ - USTCONSUMER_POLL_ERROR, /* Error in polling thread in kconsumerd */ - USTCONSUMER_POLL_NVAL, /* Poll on closed fd */ - USTCONSUMER_POLL_HUP, /* All fds have hungup */ - USTCONSUMER_EXIT_SUCCESS, /* kconsumerd exiting normally */ - USTCONSUMER_EXIT_FAILURE, /* kconsumerd exiting on error */ - USTCONSUMER_OUTFD_ERROR, /* error opening the tracefile */ - USTCONSUMER_SPLICE_EBADF, /* EBADF from splice(2) */ - USTCONSUMER_SPLICE_EINVAL, /* EINVAL from splice(2) */ - USTCONSUMER_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ - USTCONSUMER_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ - /* MUST be last element */ - USTCOMM_NR, /* Last element */ -}; - -/* - * Data structure for the commands sent from sessiond to UST. - */ -struct ustcomm_ust_msg { - uint32_t handle; - uint32_t cmd; - union { - struct lttng_ust_channel channel; - struct lttng_ust_stream stream; - struct lttng_ust_event event; - struct lttng_ust_context context; - struct lttng_ust_tracer_version version; - char tracepoint_list_entry[LTTNG_UST_SYM_NAME_LEN]; - } u; -}; - -/* - * Data structure for the response from UST to the session daemon. - * cmd_type is sent back in the reply for validation. - */ -struct ustcomm_ust_reply { - uint32_t handle; - uint32_t cmd; - uint32_t ret_code; /* enum enum ustcomm_return_code */ - uint32_t ret_val; /* return value */ - union { - struct { - uint64_t memory_map_size; - } channel; - struct { - uint64_t memory_map_size; - } stream; - struct lttng_ust_tracer_version version; - char tracepoint_list_entry[LTTNG_UST_SYM_NAME_LEN]; - } u; -}; - -extern int ustcomm_create_unix_sock(const char *pathname); -extern int ustcomm_connect_unix_sock(const char *pathname); -extern int ustcomm_accept_unix_sock(int sock); -extern int ustcomm_listen_unix_sock(int sock); -extern int ustcomm_close_unix_sock(int sock); -/* Send fd(s) over a unix socket. */ -extern ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, - size_t nb_fd, size_t len); -extern ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len); -extern ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len); -extern const char *ustcomm_get_readable_code(int code); -extern int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum); -extern int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, - uint32_t expected_handle, uint32_t expected_cmd); -extern int ustcomm_send_app_cmd(int sock, - struct ustcomm_ust_msg *lum, - struct ustcomm_ust_reply *lur); -int ustcomm_recv_fd(int sock); - -#endif /* _LTTNG_UST_COMM_H */ diff --git a/include/lttng/ust-tracer.h b/include/lttng/ust-tracer.h index 234e75c0..dafb6934 100644 --- a/include/lttng/ust-tracer.h +++ b/include/lttng/ust-tracer.h @@ -6,32 +6,24 @@ * * This contains the core definitions for the Linux Trace Toolkit. * - * 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; version 2.1 of - * the License. + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. * - * 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 + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. */ #include +#include #ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS /* Align data on its natural alignment */ #define RING_BUFFER_ALIGN #endif -#define LTTNG_UST_VERSION 0 -#define LTTNG_UST_PATCHLEVEL 9 -#define LTTNG_UST_SUBLEVEL 1 - #ifndef CHAR_BIT #define CHAR_BIT 8 #endif diff --git a/include/lttng/ust-version.h.in b/include/lttng/ust-version.h.in new file mode 100644 index 00000000..ea042524 --- /dev/null +++ b/include/lttng/ust-version.h.in @@ -0,0 +1,24 @@ +#ifndef _LTTNG_UST_VERSION_H +#define _LTTNG_UST_VERSION_H + +/* + * lttng/ust-version.h.in. Contains the LTTng-UST versions + * + * Copyright (c) 2011 - Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#define LTTNG_UST_MAJOR_VERSION @MAJOR_VERSION@ +#define LTTNG_UST_MINOR_VERSION @MINOR_VERSION@ +#define LTTNG_UST_PATCHLEVEL_VERSION @PATCHLEVEL_VERSION@ +#define LTTNG_UST_VERSION @PACKAGE_VERSION@ + +#endif /* _LTTNG_UST_VERSION_H */ diff --git a/include/lttng/ust.h b/include/lttng/ust.h index 593598b4..05f262be 100644 --- a/include/lttng/ust.h +++ b/include/lttng/ust.h @@ -1,39 +1,29 @@ +#ifndef _LTTNG_UST_H +#define _LTTNG_UST_H + /* - * Copyright (C) 2009 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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; version 2.1 of - * the License. + * Copyright (c) 2011 - Mathieu Desnoyers * - * 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. + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. * - * 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 + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. */ -#ifndef _UST_H -#define _UST_H - #ifdef __cplusplus extern "C" { #endif -typedef struct ust_fork_info { - sigset_t orig_sigs; -} ust_fork_info_t; - -extern void ust_before_fork(ust_fork_info_t *fork_info); -extern void ust_after_fork_parent(ust_fork_info_t *fork_info); -extern void ust_after_fork_child(ust_fork_info_t *fork_info); +extern void ust_before_fork(sigset_t *save_sigset); +extern void ust_after_fork_parent(sigset_t *restore_sigset); +extern void ust_after_fork_child(sigset_t *restore_sigset); #ifdef __cplusplus } #endif -#endif /* _UST_H */ +#endif /* _LTTNG_UST_H */ diff --git a/include/lttng/vatomic.h b/include/lttng/vatomic.h deleted file mode 100644 index 29bb67d7..00000000 --- a/include/lttng/vatomic.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _LINUX_RING_BUFFER_VATOMIC_H -#define _LINUX_RING_BUFFER_VATOMIC_H - -/* - * linux/ringbuffer/vatomic.h - * - * Copyright (C) 2010 - Mathieu Desnoyers - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED - * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program - * for any purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - */ - -#include -#include - -/* - * Same data type (long) accessed differently depending on configuration. - * v field is for non-atomic access (protected by mutual exclusion). - * In the fast-path, the ring_buffer_config structure is constant, so the - * compiler can statically select the appropriate branch. - * local_t is used for per-cpu and per-thread buffers. - * atomic_long_t is used for globally shared buffers. - */ -union v_atomic { - long a; /* accessed through uatomic */ - long v; -}; - -static inline -long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) -{ - assert(config->sync != RING_BUFFER_SYNC_PER_CPU); - return uatomic_read(&v_a->a); -} - -static inline -void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, - long v) -{ - assert(config->sync != RING_BUFFER_SYNC_PER_CPU); - uatomic_set(&v_a->a, v); -} - -static inline -void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a) -{ - assert(config->sync != RING_BUFFER_SYNC_PER_CPU); - uatomic_add(&v_a->a, v); -} - -static inline -void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) -{ - assert(config->sync != RING_BUFFER_SYNC_PER_CPU); - uatomic_inc(&v_a->a); -} - -/* - * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer. - */ -static inline -void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) -{ - --v_a->v; -} - -static inline -long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, - long old, long _new) -{ - assert(config->sync != RING_BUFFER_SYNC_PER_CPU); - return uatomic_cmpxchg(&v_a->a, old, _new); -} - -#endif /* _LINUX_RING_BUFFER_VATOMIC_H */ diff --git a/include/lttng/version.h.in b/include/lttng/version.h.in deleted file mode 100644 index d65b9209..00000000 --- a/include/lttng/version.h.in +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _UST_VERSION_H -#define _UST_VERSION_H - -/* - * ust/version.h.in. Contains the UST versions - * - * (C) Copyright 2011 Yannick Brosseau - * - * 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; - * 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 - */ - -#define UST_MAJOR_VERSION @MAJOR_VERSION@ -#define UST_MINOR_VERSION @MINOR_VERSION@ -#define UST_VERSION @PACKAGE_VERSION@ - -#endif /* _UST_VERSION_H */ diff --git a/include/lttng/wait.h b/include/lttng/wait.h deleted file mode 100644 index 6cc0e373..00000000 --- a/include/lttng/wait.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _UST_WAIT_H -#define _UST_WAIT_H - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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; 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 - -/* - * Wait until "cond" gets true or timeout (in ms). - */ -#define wait_cond_interruptible_timeout(_cond, _timeout) \ - ({ \ - int __ret = 0, __pollret; \ - int __timeout = _timeout; \ - \ - for (;;) { \ - if (_cond) \ - break; \ - if (__timeout <= 0) { \ - __ret = -ETIMEDOUT; \ - break; \ - } \ - __pollret = poll(NULL, 0, 10); /* wait 10ms */ \ - if (__pollret < 0) { \ - __ret = -errno; \ - break; \ - } \ - __timeout -= 10; \ - } \ - __ret; \ - }) - - -#endif /* _UST_WAIT_H */ diff --git a/include/ust-comm.h b/include/ust-comm.h new file mode 100644 index 00000000..deb0438b --- /dev/null +++ b/include/ust-comm.h @@ -0,0 +1,176 @@ +#ifndef _LTTNG_UST_COMM_H +#define _LTTNG_UST_COMM_H + +/* + * Copyright (C) 2011 - David Goulet + * Julien Desfossez + * Mathieu Desnoyers + * + * 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 + */ + +/* + * This header is meant for liblttng and libust internal use ONLY. + * These declarations should NOT be considered stable API. + */ + +#include +#include +#include + +/* + * Default timeout the application waits for the sessiond to send its + * "register done" command. Can be overridden with the environment + * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not + * found, the application proceeds directly without any delay. + */ +#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000 + +#define LTTNG_RUNDIR "/var/run/lttng" + +/* Default unix socket path */ +#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-lttng-sessiond" +#define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-lttng-sessiond" +#define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-lttng-sessiond" +#define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-lttng-sessiond" + +#define DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait" +#define DEFAULT_HOME_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait-%u" + +/* Queue size of listen(2) */ +#define LTTNG_UST_COMM_MAX_LISTEN 10 + +/* Get the error code index from 0. USTCOMM_ERR starts at 1000. + */ +#define USTCOMM_ERR_INDEX(code) (code - USTCOMM_ERR) + +/* + * ustcomm error code. + */ +enum ustcomm_return_code { + USTCOMM_OK = 0, /* Ok */ + /* Range 1 to 999 used for standard error numbers (errno.h) */ + USTCOMM_ERR = 1000, /* Unknown Error */ + USTCOMM_UND, /* Undefine command */ + USTCOMM_NOT_IMPLEMENTED, /* Command not implemented */ + USTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */ + USTCOMM_ALLOC_FAIL, /* Trace allocation fail */ + USTCOMM_NO_SESSION, /* No session found */ + USTCOMM_CREATE_FAIL, /* Create trace fail */ + USTCOMM_SESSION_FAIL, /* Create session fail */ + USTCOMM_START_FAIL, /* Start tracing fail */ + USTCOMM_STOP_FAIL, /* Stop tracing fail */ + USTCOMM_LIST_FAIL, /* Listing apps fail */ + USTCOMM_NO_APPS, /* No traceable application */ + USTCOMM_SESS_NOT_FOUND, /* Session name not found */ + USTCOMM_NO_TRACE, /* No trace exist */ + USTCOMM_FATAL, /* Session daemon had a fatal error */ + USTCOMM_NO_TRACEABLE, /* Error for non traceable app */ + USTCOMM_SELECT_SESS, /* Must select a session */ + USTCOMM_EXIST_SESS, /* Session name already exist */ + USTCOMM_NO_EVENT, /* No event found */ + USTCOMM_KERN_NA, /* Kernel tracer unavalable */ + USTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */ + USTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ + USTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ + USTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ + USTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ + USTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ + USTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ + USTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ + USTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ + USTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ + USTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ + USTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ + USTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ + USTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ + USTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ + USTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ + USTCOMM_KERN_NO_SESSION, /* No kernel session found */ + USTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ + USTCONSUMER_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ + USTCONSUMER_SUCCESS_RECV_FD, /* success on receiving fds */ + USTCONSUMER_ERROR_RECV_FD, /* error on receiving fds */ + USTCONSUMER_POLL_ERROR, /* Error in polling thread in kconsumerd */ + USTCONSUMER_POLL_NVAL, /* Poll on closed fd */ + USTCONSUMER_POLL_HUP, /* All fds have hungup */ + USTCONSUMER_EXIT_SUCCESS, /* kconsumerd exiting normally */ + USTCONSUMER_EXIT_FAILURE, /* kconsumerd exiting on error */ + USTCONSUMER_OUTFD_ERROR, /* error opening the tracefile */ + USTCONSUMER_SPLICE_EBADF, /* EBADF from splice(2) */ + USTCONSUMER_SPLICE_EINVAL, /* EINVAL from splice(2) */ + USTCONSUMER_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ + USTCONSUMER_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ + /* MUST be last element */ + USTCOMM_NR, /* Last element */ +}; + +/* + * Data structure for the commands sent from sessiond to UST. + */ +struct ustcomm_ust_msg { + uint32_t handle; + uint32_t cmd; + union { + struct lttng_ust_channel channel; + struct lttng_ust_stream stream; + struct lttng_ust_event event; + struct lttng_ust_context context; + struct lttng_ust_tracer_version version; + char tracepoint_list_entry[LTTNG_UST_SYM_NAME_LEN]; + } u; +}; + +/* + * Data structure for the response from UST to the session daemon. + * cmd_type is sent back in the reply for validation. + */ +struct ustcomm_ust_reply { + uint32_t handle; + uint32_t cmd; + uint32_t ret_code; /* enum enum ustcomm_return_code */ + uint32_t ret_val; /* return value */ + union { + struct { + uint64_t memory_map_size; + } channel; + struct { + uint64_t memory_map_size; + } stream; + struct lttng_ust_tracer_version version; + char tracepoint_list_entry[LTTNG_UST_SYM_NAME_LEN]; + } u; +}; + +extern int ustcomm_create_unix_sock(const char *pathname); +extern int ustcomm_connect_unix_sock(const char *pathname); +extern int ustcomm_accept_unix_sock(int sock); +extern int ustcomm_listen_unix_sock(int sock); +extern int ustcomm_close_unix_sock(int sock); +/* Send fd(s) over a unix socket. */ +extern ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, + size_t nb_fd, size_t len); +extern ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len); +extern ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len); +extern const char *ustcomm_get_readable_code(int code); +extern int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum); +extern int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, + uint32_t expected_handle, uint32_t expected_cmd); +extern int ustcomm_send_app_cmd(int sock, + struct ustcomm_ust_msg *lum, + struct ustcomm_ust_reply *lur); +int ustcomm_recv_fd(int sock); + +#endif /* _LTTNG_UST_COMM_H */ diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index e7d43e98..aa3e761e 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -30,7 +30,7 @@ #include #include -#include +#include /* * Human readable error message. diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index ed814b29..83c60034 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -21,9 +21,9 @@ #include #include #include -#include #include #include +#include #include "../libringbuffer/backend.h" #include "../libringbuffer/frontend.h" diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index 9acd241b..fe474f72 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -18,7 +18,9 @@ liblttng_ust_runtime_la_SOURCES = \ ltt-context.c \ ltt-events.c \ tracepoint.c \ - tracepoint-internal.h + tracepoint-internal.h \ + clock.h \ + wait.h liblttng_ust_support_la_SOURCES = \ ltt-tracer.h \ diff --git a/liblttng-ust/clock.h b/liblttng-ust/clock.h new file mode 100644 index 00000000..3de1fa81 --- /dev/null +++ b/liblttng-ust/clock.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers + * + * 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; 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 + */ + +#ifndef _UST_CLOCK_H +#define _UST_CLOCK_H + +#include +#include +#include +#include +#include + +/* TRACE CLOCK */ + +/* + * Currently using the kernel MONOTONIC clock, waiting for kernel-side + * LTTng to implement mmap'd trace clock. + */ + +/* Choosing correct trace clock */ + +static __inline__ uint64_t trace_clock_read64(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * 1000000000) + ts.tv_nsec; +} + +#if __i386__ || __x86_64__ +static __inline__ uint64_t trace_clock_frequency(void) +{ + return 1000000000LL; +} +#endif /* #else #if __i386__ || __x86_64__ */ + +static __inline__ uint32_t trace_clock_freq_scale(void) +{ + return 1; +} + +#endif /* _UST_CLOCK_H */ diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h new file mode 100644 index 00000000..8ee4470a --- /dev/null +++ b/liblttng-ust/compat.h @@ -0,0 +1,30 @@ +#ifndef _UST_COMPAT_H +#define _UST_COMPAT_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include + +#ifdef __UCLIBC__ +#define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache) +static inline +int sched_getcpu(void) +{ + int c, s; + + s = __getcpu(&c, NULL, NULL); + return (s == -1) ? s : c; +} +#endif /* __UCLIBC__ */ +#endif /* _UST_COMPAT_H */ diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 18b257b3..d9da1006 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -27,11 +27,11 @@ #include "lttng/core.h" #include "ltt-tracer.h" #include "ltt-tracer-core.h" -#include "lttng/wait.h" +#include "wait.h" #include "../libringbuffer/shm.h" - -typedef u32 uint32_t; -#include +#include +#include +#include /* * The sessions mutex is the centralized mutex across UST tracing diff --git a/liblttng-ust/ltt-ring-buffer-client.h b/liblttng-ust/ltt-ring-buffer-client.h index 8844ae28..b2ef3273 100644 --- a/liblttng-ust/ltt-ring-buffer-client.h +++ b/liblttng-ust/ltt-ring-buffer-client.h @@ -11,7 +11,7 @@ #include #include #include "lttng/bitfield.h" -#include "lttng/clock.h" +#include "clock.h" #include "ltt-tracer.h" #include "../libringbuffer/frontend_types.h" diff --git a/liblttng-ust/ltt-tracer-core.h b/liblttng-ust/ltt-tracer-core.h index 20ed0c0e..0a0bad99 100644 --- a/liblttng-ust/ltt-tracer-core.h +++ b/liblttng-ust/ltt-tracer-core.h @@ -21,7 +21,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include +#include +#include #include #include #include diff --git a/liblttng-ust/ltt-tracer.h b/liblttng-ust/ltt-tracer.h index 6ab80e7c..d51479ce 100644 --- a/liblttng-ust/ltt-tracer.h +++ b/liblttng-ust/ltt-tracer.h @@ -26,9 +26,9 @@ #include #include #include -#include #include #include "ltt-tracer-core.h" +#include "compat.h" /* Number of bytes to log with a read/write event */ #define LTT_LOG_RW_SIZE 32L diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index e03024f4..76f78702 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -249,9 +249,9 @@ static long lttng_abi_tracer_version(int objd, struct lttng_ust_tracer_version *v) { - v->version = LTTNG_UST_VERSION; + v->major = LTTNG_UST_MAJOR; + v->minor = LTTNG_UST_MINOR; v->patchlevel = LTTNG_UST_PATCHLEVEL; - v->sublevel = LTTNG_UST_SUBLEVEL; return 0; } diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 71bf716a..d0239cda 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include @@ -876,7 +876,7 @@ void __attribute__((destructor)) lttng_ust_exit(void) * in the middle of an tracepoint or ust tracing state modification. * Holding this mutex protects these structures across fork and clone. */ -void ust_before_fork(ust_fork_info_t *fork_info) +void ust_before_fork(sigset_t *save_sigset) { /* * Disable signals. This is to avoid that the child intervenes @@ -889,7 +889,7 @@ void ust_before_fork(ust_fork_info_t *fork_info) /* Disable signals */ sigfillset(&all_sigs); - ret = sigprocmask(SIG_BLOCK, &all_sigs, &fork_info->orig_sigs); + ret = sigprocmask(SIG_BLOCK, &all_sigs, save_sigset); if (ret == -1) { PERROR("sigprocmask"); } @@ -897,25 +897,25 @@ void ust_before_fork(ust_fork_info_t *fork_info) rcu_bp_before_fork(); } -static void ust_after_fork_common(ust_fork_info_t *fork_info) +static void ust_after_fork_common(sigset_t *restore_sigset) { int ret; DBG("process %d", getpid()); ust_unlock(); /* Restore signals */ - ret = sigprocmask(SIG_SETMASK, &fork_info->orig_sigs, NULL); + ret = sigprocmask(SIG_SETMASK, &restore_sigset, NULL); if (ret == -1) { PERROR("sigprocmask"); } } -void ust_after_fork_parent(ust_fork_info_t *fork_info) +void ust_after_fork_parent(sigset_t *restore_sigset) { DBG("process %d", getpid()); rcu_bp_after_fork_parent(); /* Release mutexes and reenable signals */ - ust_after_fork_common(fork_info); + ust_after_fork_common(restore_sigset); } /* @@ -927,7 +927,7 @@ void ust_after_fork_parent(ust_fork_info_t *fork_info) * This is meant for forks() that have tracing in the child between the * fork and following exec call (if there is any). */ -void ust_after_fork_child(ust_fork_info_t *fork_info) +void ust_after_fork_child(sigset_t *restore_sigset) { DBG("process %d", getpid()); /* Release urcu mutexes */ @@ -935,6 +935,6 @@ void ust_after_fork_child(ust_fork_info_t *fork_info) lttng_ust_cleanup(0); lttng_context_vtid_reset(); /* Release mutexes and reenable signals */ - ust_after_fork_common(fork_info); + ust_after_fork_common(restore_sigset); lttng_ust_init(); } diff --git a/liblttng-ust/tracepoint.c b/liblttng-ust/tracepoint.c index 8bf87528..217ef4c2 100644 --- a/liblttng-ust/tracepoint.c +++ b/liblttng-ust/tracepoint.c @@ -24,10 +24,13 @@ #include #include #include -#include +#include +#include +#include #include #include #include +#include #include #include "ltt-tracer-core.h" @@ -89,7 +92,7 @@ static inline void *allocate_probes(int count) static inline void release_probes(void *old) { if (old) { - struct tp_probes *tp_probes = _ust_container_of(old, + struct tp_probes *tp_probes = caa_container_of(old, struct tp_probes, probes[0]); synchronize_rcu(); free(tp_probes); @@ -411,7 +414,7 @@ static void tracepoint_add_old_probes(void *old) { need_update = 1; if (old) { - struct tp_probes *tp_probes = _ust_container_of(old, + struct tp_probes *tp_probes = caa_container_of(old, struct tp_probes, probes[0]); cds_list_add(&tp_probes->u.list, &old_probes); } diff --git a/liblttng-ust/wait.h b/liblttng-ust/wait.h new file mode 100644 index 00000000..6cc0e373 --- /dev/null +++ b/liblttng-ust/wait.h @@ -0,0 +1,50 @@ +#ifndef _UST_WAIT_H +#define _UST_WAIT_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * 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; 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 + +/* + * Wait until "cond" gets true or timeout (in ms). + */ +#define wait_cond_interruptible_timeout(_cond, _timeout) \ + ({ \ + int __ret = 0, __pollret; \ + int __timeout = _timeout; \ + \ + for (;;) { \ + if (_cond) \ + break; \ + if (__timeout <= 0) { \ + __ret = -ETIMEDOUT; \ + break; \ + } \ + __pollret = poll(NULL, 0, 10); /* wait 10ms */ \ + if (__pollret < 0) { \ + __ret = -errno; \ + break; \ + } \ + __timeout -= 10; \ + } \ + __ret; \ + }) + + +#endif /* _UST_WAIT_H */ diff --git a/libringbuffer/Makefile.am b/libringbuffer/Makefile.am index f1e8a971..74a9b0dc 100644 --- a/libringbuffer/Makefile.am +++ b/libringbuffer/Makefile.am @@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \ api.h \ backend.h backend_internal.h backend_types.h \ frontend_api.h frontend.h frontend_internal.h frontend_types.h \ - nohz.h + nohz.h vatomic.h libringbuffer_la_LDFLAGS = -no-undefined -version-info 0:0:0 diff --git a/libringbuffer/backend_internal.h b/libringbuffer/backend_internal.h index f61d1d61..dbe34fc1 100644 --- a/libringbuffer/backend_internal.h +++ b/libringbuffer/backend_internal.h @@ -430,4 +430,45 @@ do { \ inline_memcpy(dest, src, __len); \ } while (0) +/* arch-agnostic implementation */ + +static inline int fls(unsigned int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xFFFF0000U)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xFF000000U)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xF0000000U)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xC0000000U)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000U)) { + x <<= 1; + r -= 1; + } + return r; +} + +static inline int get_count_order(unsigned int count) +{ + int order; + + order = fls(count) - 1; + if (count & (count - 1)) + order++; + return order; +} + #endif /* _LINUX_RING_BUFFER_BACKEND_INTERNAL_H */ diff --git a/libringbuffer/frontend_types.h b/libringbuffer/frontend_types.h index 93131616..0a048845 100644 --- a/libringbuffer/frontend_types.h +++ b/libringbuffer/frontend_types.h @@ -54,18 +54,18 @@ struct channel { * be last member. */ struct channel_backend backend; /* Associated backend */ -} ____cacheline_aligned; +} __attribute__((aligned(CAA_CACHE_LINE_SIZE))); /* Per-subbuffer commit counters used on the hot path */ struct commit_counters_hot { union v_atomic cc; /* Commit counter */ union v_atomic seq; /* Consecutive commits */ -} ____cacheline_aligned; +} __attribute__((aligned(CAA_CACHE_LINE_SIZE))); /* Per-subbuffer commit counters used only on cold paths */ struct commit_counters_cold { union v_atomic cc_sb; /* Incremented _once_ at sb switch */ -} ____cacheline_aligned; +} __attribute__((aligned(CAA_CACHE_LINE_SIZE))); /* ring buffer state */ struct lttng_ust_lib_ring_buffer { @@ -110,7 +110,7 @@ struct lttng_ust_lib_ring_buffer { int read_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */ /* shmp pointer to self */ DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self); -} ____cacheline_aligned; +} __attribute__((aligned(CAA_CACHE_LINE_SIZE))); static inline void *channel_get_private(struct channel *chan) diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 23802e82..3f47ebd1 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -10,6 +10,7 @@ #include "lttng/core.h" +#include "uatomic.h" #include #include "backend.h" #include "frontend.h" diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 53d269d2..18c47ddf 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -45,6 +45,7 @@ #include #include +#include "vatomic.h" #include "smp.h" #include #include "backend.h" diff --git a/libringbuffer/vatomic.h b/libringbuffer/vatomic.h new file mode 100644 index 00000000..29bb67d7 --- /dev/null +++ b/libringbuffer/vatomic.h @@ -0,0 +1,81 @@ +#ifndef _LINUX_RING_BUFFER_VATOMIC_H +#define _LINUX_RING_BUFFER_VATOMIC_H + +/* + * linux/ringbuffer/vatomic.h + * + * Copyright (C) 2010 - Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include +#include + +/* + * Same data type (long) accessed differently depending on configuration. + * v field is for non-atomic access (protected by mutual exclusion). + * In the fast-path, the ring_buffer_config structure is constant, so the + * compiler can statically select the appropriate branch. + * local_t is used for per-cpu and per-thread buffers. + * atomic_long_t is used for globally shared buffers. + */ +union v_atomic { + long a; /* accessed through uatomic */ + long v; +}; + +static inline +long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) +{ + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + return uatomic_read(&v_a->a); +} + +static inline +void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, + long v) +{ + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_set(&v_a->a, v); +} + +static inline +void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a) +{ + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_add(&v_a->a, v); +} + +static inline +void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) +{ + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_inc(&v_a->a); +} + +/* + * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer. + */ +static inline +void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) +{ + --v_a->v; +} + +static inline +long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, + long old, long _new) +{ + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + return uatomic_cmpxchg(&v_a->a, old, _new); +} + +#endif /* _LINUX_RING_BUFFER_VATOMIC_H */