From 9edd34bd25f52dd39b354a84f02697254121aefd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 19 May 2011 17:03:11 -0400 Subject: [PATCH] Privatize headers Remove most installed headers, which should be internal. The header kcompat (kernel-style compatibility header) only makes sense within the UST package: this should never be exported, nor be included into instrumented applications. Move the type-serializer header back into libust/. It is so internal it does not even belong to include/ust/. Standardize all the installed headers on non-kcompat style: use uint64_t instead of u64 for types, open-code likely/unlikely. Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 27 +++--- include/ust/clock.h | 16 ++-- include/ust/core.h | 36 -------- include/ust/define_trace.h | 3 +- include/ust/marker.h | 13 +-- include/ust/{kcompat => }/stringify.h | 1 - include/ust/tracepoint.h | 1 - include/ust/ust.h | 27 ------ include/ust/ustconsumer.h | 4 +- libust/Makefile.am | 2 +- libust/buffers.h | 92 ++++++++++++++++++- libust/header-inline.h | 81 ---------------- libust/type-serializer.c | 2 +- {include/ust => libust}/type-serializer.h | 1 + libustconsumer/libustconsumer.c | 2 +- libustfork/ustfork.c | 1 - tests/exit-fast/exit-fast.c | 4 +- tests/test-nevents/prog.c | 2 +- .../benchmark/tracepoint_benchmark.c | 4 +- ust-consumerd/ust-consumerd.c | 9 +- 20 files changed, 142 insertions(+), 186 deletions(-) rename include/ust/{kcompat => }/stringify.h (99%) delete mode 100644 include/ust/ust.h delete mode 100644 libust/header-inline.h rename {include/ust => libust}/type-serializer.h (99%) diff --git a/include/Makefile.am b/include/Makefile.am index 9014627..9fd7dee 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,22 +3,25 @@ nobase_include_HEADERS = \ ust/tracepoint.h \ ust/define_trace.h \ ust/ust_trace.h \ - ust/processor.h \ - ust/probe.h \ - ust/ust.h \ ust/tracectl.h \ ust/config.h \ + ust/stringify.h \ + ust/ustctl.h \ + ust/ustconsumer.h + +noinst_HEADERS = \ + share.h \ + usterr.h \ + ust_snprintf.h \ + usterr_signal_safe.h \ ust/core.h \ + ust/marker-internal.h \ + ust/tracepoint-internal.h \ ust/clock.h \ + ust/probe.h \ + ust/processor.h \ ust/kcompat/kcompat.h \ - ust/kcompat/compiler.h \ ust/kcompat/jhash.h \ + ust/kcompat/compiler.h \ ust/kcompat/simple.h \ - ust/kcompat/types.h \ - ust/kcompat/stringify.h \ - ust/ustctl.h \ - ust/ustconsumer.h - -noinst_HEADERS = share.h usterr.h ust_snprintf.h usterr_signal_safe.h \ - ust/marker-internal.h ust/tracepoint-internal.h \ - ust/type-serializer.h + ust/kcompat/types.h diff --git a/include/ust/clock.h b/include/ust/clock.h index 22d2efc..5e8f755 100644 --- a/include/ust/clock.h +++ b/include/ust/clock.h @@ -20,7 +20,9 @@ #include #include -#include +#include +#include +#include /* TRACE CLOCK */ @@ -44,17 +46,17 @@ #define CLOCK_TRACE 15 union lttng_timespec { struct timespec ts; - u64 lttng_ts; + uint64_t lttng_ts; }; extern int ust_clock_source; /* Choosing correct trace clock */ -static __inline__ u64 trace_clock_read64(void) +static __inline__ uint64_t trace_clock_read64(void) { struct timespec ts; - u64 retval; + uint64_t retval; union lttng_timespec *lts = (union lttng_timespec *) &ts; clock_gettime(ust_clock_source, &ts); @@ -75,7 +77,7 @@ static __inline__ u64 trace_clock_read64(void) } #if __i386__ || __x86_64__ -static __inline__ u64 trace_clock_frequency(void) +static __inline__ uint64_t trace_clock_frequency(void) { struct timespec ts; union lttng_timespec *lts = (union lttng_timespec *) &ts; @@ -87,13 +89,13 @@ static __inline__ u64 trace_clock_frequency(void) return 1000000000LL; } #else /* #if __i386__ || __x86_64__ */ -static __inline__ u64 trace_clock_frequency(void) +static __inline__ uint64_t trace_clock_frequency(void) { return 1000000000LL; } #endif /* #else #if __i386__ || __x86_64__ */ -static __inline__ u32 trace_clock_freq_scale(void) +static __inline__ uint32_t trace_clock_freq_scale(void) { return 1; } diff --git a/include/ust/core.h b/include/ust/core.h index d0e2750..eee405d 100644 --- a/include/ust/core.h +++ b/include/ust/core.h @@ -24,42 +24,6 @@ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) -#ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS - -/* - * Calculate the offset needed to align the type. - * size_of_type must be non-zero. - */ -static inline unsigned int ltt_align(size_t align_drift, size_t size_of_type) -{ - size_t alignment = min(sizeof(void *), size_of_type); - return (alignment - align_drift) & (alignment - 1); -} -/* Default arch alignment */ -#define LTT_ALIGN - -static inline int ltt_get_alignment(void) -{ - return sizeof(void *); -} - -#else /* HAVE_EFFICIENT_UNALIGNED_ACCESS */ - -static inline unsigned int ltt_align(size_t align_drift, - size_t size_of_type) -{ - return 0; -} - -#define LTT_ALIGN __attribute__((packed)) - -static inline int ltt_get_alignment(void) -{ - return 0; -} -#endif /* HAVE_EFFICIENT_UNALIGNED_ACCESS */ - - /* ARRAYS */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/include/ust/define_trace.h b/include/ust/define_trace.h index f377ddb..14543f9 100644 --- a/include/ust/define_trace.h +++ b/include/ust/define_trace.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Steven Rostedt + * 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 @@ -37,7 +38,7 @@ /* Prevent recursion */ #undef TRACEPOINT_CREATE_PROBES -#include +#include #undef TRACEPOINT_EVENT #define TRACEPOINT_EVENT(name, proto, args, fields) \ diff --git a/include/ust/marker.h b/include/ust/marker.h index 41ae10a..af15ad4 100644 --- a/include/ust/marker.h +++ b/include/ust/marker.h @@ -26,10 +26,10 @@ */ #include +#include +#include #include #include -#include -#include struct ust_marker; @@ -64,8 +64,8 @@ struct ust_marker { char state; /* State. */ char ptype; /* probe type : 0 : single, 1 : multi */ /* Probe wrapper */ - u16 channel_id; /* Numeric channel identifier, dynamic */ - u16 event_id; /* Numeric event identifier, dynamic */ + uint16_t channel_id; /* Numeric channel identifier, dynamic */ + uint16_t event_id; /* Numeric event identifier, dynamic */ void (*call)(const struct ust_marker *mdata, void *call_private, ...); struct ust_marker_probe_closure single; struct ust_marker_probe_closure *multi; @@ -109,7 +109,7 @@ struct ust_marker { do { \ _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \ __ust_marker_check_format(format, ## args); \ - if (unlikely(__ust_marker_def_##name.state)) \ + if (__builtin_expect(!!(__ust_marker_def_##name.state), 0)) \ (__ust_marker_def_##name.call) \ (&__ust_marker_def_##name, call_private,\ ## args); \ @@ -138,7 +138,8 @@ void __trace_mark_is_deprecated() /* To be used for string format validity checking with gcc */ static inline -void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...) +void __attribute__((format(printf, 1, 2))) + ___ust_marker_check_format(const char *fmt, ...) { } diff --git a/include/ust/kcompat/stringify.h b/include/ust/stringify.h similarity index 99% rename from include/ust/kcompat/stringify.h rename to include/ust/stringify.h index 4ae13d0..b8dfd90 100644 --- a/include/ust/kcompat/stringify.h +++ b/include/ust/stringify.h @@ -16,7 +16,6 @@ * 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 diff --git a/include/ust/tracepoint.h b/include/ust/tracepoint.h index 4d84ead..3d61f72 100644 --- a/include/ust/tracepoint.h +++ b/include/ust/tracepoint.h @@ -26,7 +26,6 @@ */ #include -#include #include struct tracepoint_probe { diff --git a/include/ust/ust.h b/include/ust/ust.h deleted file mode 100644 index a7da4b3..0000000 --- a/include/ust/ust.h +++ /dev/null @@ -1,27 +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_H -#define UST_H - -#include -#include -#include -#include -#include - -#endif /* UST_H */ diff --git a/include/ust/ustconsumer.h b/include/ust/ustconsumer.h index cde8440..8c53488 100644 --- a/include/ust/ustconsumer.h +++ b/include/ust/ustconsumer.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #define USTCONSUMER_DEFAULT_TRACE_PATH "/tmp/usttrace" @@ -67,7 +67,7 @@ struct buffer_info { long consumed_old; - s64 pidunique; + int64_t pidunique; void *user_data; }; diff --git a/libust/Makefile.am b/libust/Makefile.am index 697b469..44addf0 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -20,7 +20,7 @@ libust_la_SOURCES = \ serialize.c \ tracectl.c \ tracerconst.h \ - header-inline.h \ + type-serializer.h \ type-serializer.c libust_la_LDFLAGS = -no-undefined -version-info 0:0:0 diff --git a/libust/buffers.h b/libust/buffers.h index 4017964..afeaef3 100644 --- a/libust/buffers.h +++ b/libust/buffers.h @@ -32,7 +32,6 @@ #include "channels.h" #include "tracerconst.h" #include "tracercore.h" -#include "header-inline.h" /***** FIXME: SHOULD BE REMOVED ***** */ @@ -122,6 +121,40 @@ extern int ltt_reserve_slot_lockless_slow(struct ust_channel *chan, extern void ltt_force_switch_lockless_slow(struct ust_buffer *buf, enum force_switch_mode mode); +#ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS + +/* + * Calculate the offset needed to align the type. + * size_of_type must be non-zero. + */ +static inline unsigned int ltt_align(size_t align_drift, size_t size_of_type) +{ + size_t alignment = min(sizeof(void *), size_of_type); + return (alignment - align_drift) & (alignment - 1); +} +/* Default arch alignment */ +#define LTT_ALIGN + +static inline int ltt_get_alignment(void) +{ + return sizeof(void *); +} + +#else /* HAVE_EFFICIENT_UNALIGNED_ACCESS */ + +static inline unsigned int ltt_align(size_t align_drift, + size_t size_of_type) +{ + return 0; +} + +#define LTT_ALIGN __attribute__((packed)) + +static inline int ltt_get_alignment(void) +{ + return 0; +} +#endif /* HAVE_EFFICIENT_UNALIGNED_ACCESS */ static __inline__ void ust_buffers_do_copy(void *dest, const void *src, size_t len) { @@ -194,6 +227,63 @@ static __inline__ int last_tsc_overflow(struct ust_buffer *ltt_buf, } #endif +/* + * ust_get_header_size + * + * Calculate alignment offset to 32-bits. This is the alignment offset of the + * event header. + * + * Important note : + * The event header must be 32-bits. The total offset calculated here : + * + * Alignment of header struct on 32 bits (min arch size, header size) + * + sizeof(header struct) (32-bits) + * + (opt) u16 (ext. event id) + * + (opt) u16 (event_size) (if event_size == 0xFFFFUL, has ext. event size) + * + (opt) u32 (ext. event size) + * + (opt) u64 full TSC (aligned on min(64-bits, arch size)) + * + * The payload must itself determine its own alignment from the biggest type it + * contains. + * */ +static __inline__ unsigned char ust_get_header_size( + struct ust_channel *channel, + size_t offset, + size_t data_size, + size_t *before_hdr_pad, + unsigned int rflags) +{ + size_t orig_offset = offset; + size_t padding; + + padding = ltt_align(offset, sizeof(struct ltt_event_header)); + offset += padding; + offset += sizeof(struct ltt_event_header); + + if(unlikely(rflags)) { + switch (rflags) { + case LTT_RFLAG_ID_SIZE_TSC: + offset += sizeof(u16) + sizeof(u16); + if (data_size >= 0xFFFFU) + offset += sizeof(u32); + offset += ltt_align(offset, sizeof(u64)); + offset += sizeof(u64); + break; + case LTT_RFLAG_ID_SIZE: + offset += sizeof(u16) + sizeof(u16); + if (data_size >= 0xFFFFU) + offset += sizeof(u32); + break; + case LTT_RFLAG_ID: + offset += sizeof(u16); + break; + } + } + + *before_hdr_pad = padding; + return offset - orig_offset; +} + static __inline__ void ltt_reserve_push_reader( struct ust_channel *rchan, struct ust_buffer *buf, diff --git a/libust/header-inline.h b/libust/header-inline.h deleted file mode 100644 index 04abaa9..0000000 --- a/libust/header-inline.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2008 - Mathieu Desnoyers (mathieu.desnoyers@polymtl.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 UST_HEADER_INLINE_H -#define UST_HEADER_INLINE_H - -#include - -/* - * ust_get_header_size - * - * Calculate alignment offset to 32-bits. This is the alignment offset of the - * event header. - * - * Important note : - * The event header must be 32-bits. The total offset calculated here : - * - * Alignment of header struct on 32 bits (min arch size, header size) - * + sizeof(header struct) (32-bits) - * + (opt) u16 (ext. event id) - * + (opt) u16 (event_size) (if event_size == 0xFFFFUL, has ext. event size) - * + (opt) u32 (ext. event size) - * + (opt) u64 full TSC (aligned on min(64-bits, arch size)) - * - * The payload must itself determine its own alignment from the biggest type it - * contains. - * */ -static __inline__ unsigned char ust_get_header_size( - struct ust_channel *channel, - size_t offset, - size_t data_size, - size_t *before_hdr_pad, - unsigned int rflags) -{ - size_t orig_offset = offset; - size_t padding; - - padding = ltt_align(offset, sizeof(struct ltt_event_header)); - offset += padding; - offset += sizeof(struct ltt_event_header); - - if(unlikely(rflags)) { - switch (rflags) { - case LTT_RFLAG_ID_SIZE_TSC: - offset += sizeof(u16) + sizeof(u16); - if (data_size >= 0xFFFFU) - offset += sizeof(u32); - offset += ltt_align(offset, sizeof(u64)); - offset += sizeof(u64); - break; - case LTT_RFLAG_ID_SIZE: - offset += sizeof(u16) + sizeof(u16); - if (data_size >= 0xFFFFU) - offset += sizeof(u32); - break; - case LTT_RFLAG_ID: - offset += sizeof(u16); - break; - } - } - - *before_hdr_pad = padding; - return offset - orig_offset; -} - -#endif /* UST_HEADER_INLINE_H */ diff --git a/libust/type-serializer.c b/libust/type-serializer.c index 611f91f..070542c 100644 --- a/libust/type-serializer.c +++ b/libust/type-serializer.c @@ -13,11 +13,11 @@ #define _GNU_SOURCE #define _LGPL_SOURCE #include -#include #include #include #include #include "tracer.h" +#include "type-serializer.h" notrace void _ltt_specialized_trace(const struct ust_marker *mdata, void *probe_data, diff --git a/include/ust/type-serializer.h b/libust/type-serializer.h similarity index 99% rename from include/ust/type-serializer.h rename to libust/type-serializer.h index d4e2a1e..3b1a23a 100644 --- a/include/ust/type-serializer.h +++ b/libust/type-serializer.h @@ -4,6 +4,7 @@ #include #include #include +#include "buffers.h" /* * largest_align must be non-zero, equal to the minimum between the largest type diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c index b47f04a..c6dd20c 100644 --- a/libustconsumer/libustconsumer.c +++ b/libustconsumer/libustconsumer.c @@ -146,7 +146,7 @@ void decrement_active_buffers(void *arg) pthread_mutex_unlock(&instance->mutex); } -static int get_pidunique(int sock, s64 *pidunique) +static int get_pidunique(int sock, int64_t *pidunique) { struct ustcomm_header _send_hdr, *send_hdr; struct ustcomm_header _recv_hdr, *recv_hdr; diff --git a/libustfork/ustfork.c b/libustfork/ustfork.c index ecc39e3..c88805f 100644 --- a/libustfork/ustfork.c +++ b/libustfork/ustfork.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/exit-fast/exit-fast.c b/tests/exit-fast/exit-fast.c index 84bb0c5..ee987f2 100644 --- a/tests/exit-fast/exit-fast.c +++ b/tests/exit-fast/exit-fast.c @@ -20,7 +20,9 @@ #include #include -#include +#include +#include +#include int main(int argc, char *argv[]) { diff --git a/tests/test-nevents/prog.c b/tests/test-nevents/prog.c index 21e01f0..6d6ba96 100644 --- a/tests/test-nevents/prog.c +++ b/tests/test-nevents/prog.c @@ -21,7 +21,7 @@ #include #include -#include +#include #define N_ITER 100000 diff --git a/tests/tracepoint/benchmark/tracepoint_benchmark.c b/tests/tracepoint/benchmark/tracepoint_benchmark.c index 45f7d3c..c1208b0 100644 --- a/tests/tracepoint/benchmark/tracepoint_benchmark.c +++ b/tests/tracepoint/benchmark/tracepoint_benchmark.c @@ -28,7 +28,9 @@ #define TRACEPOINT_CREATE_PROBES #include "tracepoint_benchmark.h" -#include + +/* Yes, this is now internal. */ +#include "../../../libust/type-serializer.h" #define NR_EVENTS 10000000 diff --git a/ust-consumerd/ust-consumerd.c b/ust-consumerd/ust-consumerd.c index c961394..0761253 100644 --- a/ust-consumerd/ust-consumerd.c +++ b/ust-consumerd/ust-consumerd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -192,8 +193,8 @@ int on_open_buffer(struct ustconsumer_callbacks *data, struct buffer_info *buf) trace_path = USTCONSUMER_DEFAULT_TRACE_PATH; } - if (asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique) < 0) { - ERR("on_open_buffer : asprintf failed (%s/%u_%lld)", + if (asprintf(&tmp, "%s/%u_%" PRId64 "", trace_path, buf->pid, buf->pidunique) < 0) { + ERR("on_open_buffer : asprintf failed (%s/%u_%" PRId64 ")", trace_path, buf->pid, buf->pidunique); return 1; } @@ -205,8 +206,8 @@ int on_open_buffer(struct ustconsumer_callbacks *data, struct buffer_info *buf) } free(tmp); - if (asprintf(&tmp, "%s/%u_%lld/%s", trace_path, buf->pid, buf->pidunique, buf->name) < 0) { - ERR("on_open_buffer : asprintf failed (%s/%u_%lld/%s)", + if (asprintf(&tmp, "%s/%u_%" PRId64 "/%s", trace_path, buf->pid, buf->pidunique, buf->name) < 0) { + ERR("on_open_buffer : asprintf failed (%s/%u_%" PRId64 "/%s)", trace_path, buf->pid, buf->pidunique, buf->name); return 1; } -- 2.34.1