From: Jan Blunck Date: Sun, 25 Oct 2009 13:57:47 +0000 (+0100) Subject: Move kernelcompat.h to include/ust/ and share.h, usterr.h to include/ X-Git-Tag: v1.9.1~847^2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fbca6b624335eef18c8d86194aeb101a720168f4;p=lttng-ust.git Move kernelcompat.h to include/ust/ and share.h, usterr.h to include/ kernelcompat.h is included by marker.h and tracepoint.h therefore it should be in include/ust/ as well. Move shared headers to include/ as well. Signed-off-by: Jan Blunck --- diff --git a/Makefile.am b/Makefile.am index 1ab59487..1bdedea2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = libust tests libmallocwrap ustd ustctl libinterfork include -EXTRA_DIST = doc share/kernelcompat.h share/share.h share/usterr.h +EXTRA_DIST = doc dist_bin_SCRIPTS = usttrace - -include_HEADERS = share/kernelcompat.h share/usterr.h diff --git a/include/Makefile.am b/include/Makefile.am index 0a4f87da..48a898b6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1,4 @@ -nobase_include_HEADERS = ust/immediate.h ust/marker.h ust/tracepoint.h +nobase_include_HEADERS = ust/immediate.h ust/kernelcompat.h ust/marker.h \ + ust/tracepoint.h + +noinst_HEADERS = share.h usterr.h diff --git a/include/share.h b/include/share.h new file mode 100644 index 00000000..f674f31f --- /dev/null +++ b/include/share.h @@ -0,0 +1,34 @@ +#ifndef UST_SHARE_H +#define UST_SHARE_H + +#include +#include + +/* This write is patient because it restarts if it was incomplete. + */ + +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; +} + +#endif /* UST_SHARE_H */ diff --git a/include/ust/kernelcompat.h b/include/ust/kernelcompat.h new file mode 100644 index 00000000..5cc5eaa2 --- /dev/null +++ b/include/ust/kernelcompat.h @@ -0,0 +1,206 @@ +#ifndef KERNELCOMPAT_H +#define KERNELCOMPAT_H + +#include + +#include +#include + +/* FIXME: libkcompat must not define arch-specific local ops, as ust *must* + * fallback to the normal atomic ops. Fix things so we don't add them and + * break things accidentally. + */ + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define KERN_DEBUG "" +#define KERN_NOTICE "" +#define KERN_INFO "" +#define KERN_ERR "" +#define KERN_ALERT "" +#define KERN_WARNING "" + +/* ERROR OPS */ + +#define MAX_ERRNO 4095 + +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) + +static inline void *ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long PTR_ERR(const void *ptr) +{ + return (long) ptr; +} + +static inline long IS_ERR(const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + + +/* Min / Max */ + +#define min_t(type, x, y) ({ \ + type __min1 = (x); \ + type __min2 = (y); \ + __min1 < __min2 ? __min1: __min2; }) + +#define max_t(type, x, y) ({ \ + type __max1 = (x); \ + type __max2 = (y); \ + __max1 > __max2 ? __max1: __max2; }) + + +/* MUTEXES */ + +#include + +#define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER; +#define DECLARE_MUTEX(m) extern pthread_mutex_t (m); + +#define mutex_lock(m) pthread_mutex_lock(m) + +#define mutex_unlock(m) pthread_mutex_unlock(m) + + +/* MALLOCATION */ + +#include + +#define kmalloc(s, t) malloc(s) +#define kzalloc(s, t) zmalloc(s) +#define kfree(p) free((void *)p) +#define kstrdup(s, t) strdup(s) + +#define zmalloc(s) calloc(1, s) + +#define GFP_KERNEL + +/* PRINTK */ + +#include +#define printk(fmt, args...) printf(fmt, ## args) + + +/* ATTRIBUTES */ + +#define ____cacheline_aligned + +/* MATH */ + +static inline unsigned int hweight32(unsigned int w) +{ + unsigned int res = w - ((w >> 1) & 0x55555555); + res = (res & 0x33333333) + ((res >> 2) & 0x33333333); + res = (res + (res >> 4)) & 0x0F0F0F0F; + res = res + (res >> 8); + return (res + (res >> 16)) & 0x000000FF; +} + +static inline int fls(int x) +{ + int r; +//ust// #ifdef CONFIG_X86_CMOV + asm("bsrl %1,%0\n\t" + "cmovzl %2,%0" + : "=&r" (r) : "rm" (x), "rm" (-1)); +//ust// #else +//ust// asm("bsrl %1,%0\n\t" +//ust// "jnz 1f\n\t" +//ust// "movl $-1,%0\n" +//ust// "1:" : "=r" (r) : "rm" (x)); +//ust// #endif + return r + 1; +} + +static __inline__ int get_count_order(unsigned int count) +{ + int order; + + order = fls(count) - 1; + if (count & (count - 1)) + order++; + return order; +} + + + + +#include + +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) +#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) +#define PAGE_MASK (~(PAGE_SIZE-1)) + + + + +/* ARRAYS */ + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +/* TRACE CLOCK */ + +/* There are two types of clocks that can be used. + - TSC based clock + - gettimeofday() clock + + Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are inlined): + Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call + Calls (100000000) to gettimeofday(): 9723158352 cycles or 97 cycles/call + + For merging traces with the kernel, a time source compatible with that of + the kernel is necessary. + +*/ + +#if 0 +/* WARNING: Make sure to set frequency and scaling functions that will not + * result in lttv timestamps (sec.nsec) with seconds greater than 2**32-1. + */ +static inline u64 trace_clock_read64(void) +{ + uint32_t low; + uint32_t high; + uint64_t retval; + __asm__ volatile ("rdtsc\n" : "=a" (low), "=d" (high)); + + retval = high; + retval <<= 32; + return retval | low; +} +#endif + +static inline u64 trace_clock_read64(void) +{ + struct timeval tv; + u64 retval; + + gettimeofday(&tv, NULL); + retval = tv.tv_sec; + retval *= 1000000; + retval += tv.tv_usec; + + return retval; +} + +static inline u64 trace_clock_frequency(void) +{ + return 1000000LL; +} + +static inline u32 trace_clock_freq_scale(void) +{ + return 1; +} + + +#endif /* KERNELCOMPAT_H */ diff --git a/include/ust/marker.h b/include/ust/marker.h index cb2c46d9..2b5a0c38 100644 --- a/include/ust/marker.h +++ b/include/ust/marker.h @@ -28,9 +28,8 @@ //ust// #include #include //ust// #include -#include "kernelcompat.h" +#include #include -#include "usterr.h" //ust// struct module; //ust// struct task_struct; @@ -303,7 +302,6 @@ extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ static void __attribute__((constructor)) __markers__init(void) \ { \ - DBG("next registration in "__FILE__"\n");\ marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ } diff --git a/include/ust/tracepoint.h b/include/ust/tracepoint.h index 7cfdbb01..56c62b0c 100644 --- a/include/ust/tracepoint.h +++ b/include/ust/tracepoint.h @@ -32,7 +32,7 @@ #include #include -#include "kernelcompat.h" +#include struct module; struct tracepoint; diff --git a/include/usterr.h b/include/usterr.h new file mode 100644 index 00000000..1819f973 --- /dev/null +++ b/include/usterr.h @@ -0,0 +1,80 @@ +#ifndef USTERR_H +#define USTERR_H + +#include +#include +#include +#include +#include + +#include "share.h" + +#ifndef UST_COMPONENT +//#error UST_COMPONENT is undefined +#define UST_COMPONENT libust +#endif + +/* To stringify the expansion of a define */ +#define XSTR(d) STR(d) +#define STR(s) #s + +/* We sometimes print in the tracing path, and tracing can occur in + * signal handlers, so we must use a print method which is signal safe. + */ + +#define sigsafe_print_err(fmt, args...) \ +{ \ + /* Can't use dynamic allocation. Limit ourselves to 250 chars. */ \ + char ____buf[250]; \ + int ____saved_errno; \ +\ + /* Save the errno. */ \ + ____saved_errno = errno; \ +\ + snprintf(____buf, sizeof(____buf), fmt, ## args); \ +\ + /* Add end of string in case of buffer overflow. */ \ + ____buf[sizeof(____buf)-1] = 0; \ +\ + patient_write(STDERR_FILENO, ____buf, strlen(____buf)); \ + /* Can't print errors because we are in the error printing code path. */ \ +\ + /* Restore errno, in order to be async-signal safe. */ \ + errno = ____saved_errno; \ +} + +#define UST_STR_COMPONENT XSTR(UST_COMPONENT) + +#define ERRMSG(fmt, args...) do { sigsafe_print_err(UST_STR_COMPONENT "[%ld/%ld]: " fmt " (" __FILE__ ":" XSTR(__LINE__) ")\n", (long) getpid(), (long) syscall(SYS_gettid), ## args); fflush(stderr); } while(0) + +#define DEBUG +#ifdef DEBUG +# define DBG(fmt, args...) ERRMSG(fmt, ## args) +#else +# define DBG(fmt, args...) do {} while(0) +#endif +#define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args) +#define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args) +#define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args) + +#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE) +#define PERROR(call, args...)\ + do { \ + char buf[200] = "Error in strerror_r()"; \ + strerror_r(errno, buf, sizeof(buf)); \ + ERRMSG("Error: " call ": %s", ## args, buf); \ + } while(0); +#else +#define PERROR(call, args...)\ + do { \ + char *buf; \ + char tmp[200]; \ + buf = strerror_r(errno, tmp, sizeof(tmp)); \ + ERRMSG("Error: " call ": %s", ## args, buf); \ + } while(0); +#endif + +#define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0) +#define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected on line %s:%d", __FILE__, __LINE__); } while(0) + +#endif /* USTERR_H */ diff --git a/java/Makefile.am b/java/Makefile.am index f9deb7ac..fa536287 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/libust +AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/libust lib_LTLIBRARIES = libustjava.la libustjava_la_SOURCES = UST.c UST.h diff --git a/libinterfork/Makefile.am b/libinterfork/Makefile.am index 2bcebb11..6540103b 100644 --- a/libinterfork/Makefile.am +++ b/libinterfork/Makefile.am @@ -1,3 +1,5 @@ +AM_CPPFLAGS = -I$(top_builddir)/include + lib_LTLIBRARIES = libinterfork.la libinterfork_la_SOURCES = interfork.c libinterfork_la_LIBADD = -ldl diff --git a/libinterfork/interfork.c b/libinterfork/interfork.c index 26a8bd6a..e9dce9bf 100644 --- a/libinterfork/interfork.c +++ b/libinterfork/interfork.c @@ -20,7 +20,7 @@ #include #include #include -#include "share/usterr.h" +#include "usterr.h" extern void ust_fork(void); extern void ust_potential_exec(void); diff --git a/libmallocwrap/Makefile.am b/libmallocwrap/Makefile.am index fa093071..23b7004e 100644 --- a/libmallocwrap/Makefile.am +++ b/libmallocwrap/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include lib_LTLIBRARIES = libmallocwrap.la libmallocwrap_la_SOURCES = mallocwrap.c diff --git a/libust/Makefile.am b/libust/Makefile.am index a8986f2f..9ee3c9a2 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -1,7 +1,7 @@ -AM_CPPFLAGS = -I$(top_builddir)/share -I$(top_builddir)/libustcomm -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/libustcomm lib_LTLIBRARIES = libust.la -libust_la_SOURCES = buffer.h marker.c tracepoint.c channels.c channels.h marker-control.c marker-control.h relay.c relay.h tracer.c tracer.h tracercore.c tracercore.h serialize.c tracectl.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/share/usterr.h +libust_la_SOURCES = buffer.h marker.c tracepoint.c channels.c channels.h marker-control.c marker-control.h relay.c relay.h tracer.c tracer.h tracercore.c tracercore.h serialize.c tracectl.c $(top_builddir)/libustcomm/ustcomm.c libust_la_LDFLAGS = -no-undefined -version-info 0:0:0 libust_la_LIBADD = -lpthread libust_la_CFLAGS = -DUST_COMPONENT="libust" diff --git a/libust/channels.c b/libust/channels.c index a4f4af10..27ceefc6 100644 --- a/libust/channels.c +++ b/libust/channels.c @@ -28,7 +28,7 @@ //ust// #include //ust// #include -#include "kernelcompat.h" +#include #include "channels.h" #include "usterr.h" #include diff --git a/libust/channels.h b/libust/channels.h index c91874b5..e460e12b 100644 --- a/libust/channels.h +++ b/libust/channels.h @@ -26,7 +26,7 @@ //ust// #include #include -#include "kernelcompat.h" +#include #include #define EVENTS_PER_CHANNEL 65536 diff --git a/libust/marker-control.c b/libust/marker-control.c index c874c946..a0786bad 100644 --- a/libust/marker-control.c +++ b/libust/marker-control.c @@ -33,7 +33,7 @@ //ust// #include #include -#include "kernelcompat.h" +#include //#include "list.h" #include "tracer.h" #include "usterr.h" diff --git a/libust/marker.c b/libust/marker.c index cebf07dd..8690d2b1 100644 --- a/libust/marker.c +++ b/libust/marker.c @@ -33,7 +33,7 @@ #define _LGPL_SOURCE #include -#include "kernelcompat.h" +#include #include #include "usterr.h" diff --git a/libust/relay.c b/libust/relay.c index 0326adc1..408ce906 100644 --- a/libust/relay.c +++ b/libust/relay.c @@ -22,7 +22,7 @@ //ust// #include //ust// #include //ust// #include -#include "kernelcompat.h" +#include #include #include #include diff --git a/libust/serialize.c b/libust/serialize.c index 0055d994..99d4dce4 100644 --- a/libust/serialize.c +++ b/libust/serialize.c @@ -32,7 +32,7 @@ #include #include -#include "kernelcompat.h" +#include #define _LGPL_SOURCE #include #include diff --git a/libust/tracepoint.c b/libust/tracepoint.c index 9de21c88..cc2adf15 100644 --- a/libust/tracepoint.c +++ b/libust/tracepoint.c @@ -32,7 +32,7 @@ #include -#include "kernelcompat.h" +#include #include #include "usterr.h" //#include "list.h" diff --git a/libust/tracer.c b/libust/tracer.c index 4150551a..a3ace72c 100644 --- a/libust/tracer.c +++ b/libust/tracer.c @@ -54,7 +54,7 @@ //ust// #include #include -#include "kernelcompat.h" +#include #include "tracercore.h" #include "tracer.h" #include "usterr.h" diff --git a/libust/tracer.h b/libust/tracer.h index 9275fd0d..cb84dad7 100644 --- a/libust/tracer.h +++ b/libust/tracer.h @@ -27,7 +27,7 @@ #include #include //#include "list.h" -#include "kernelcompat.h" +#include #include "buffer.h" #include "relay.h" #include "channels.h" diff --git a/libust/tracercore.c b/libust/tracercore.c index 90adee45..652de1b1 100644 --- a/libust/tracercore.c +++ b/libust/tracercore.c @@ -22,7 +22,7 @@ //ust// #include //ust// #include //ust// #include -#include "kernelcompat.h" +#include #include "tracercore.h" /* Traces structures */ diff --git a/libust/tracercore.h b/libust/tracercore.h index 8dfffa13..5a088db6 100644 --- a/libust/tracercore.h +++ b/libust/tracercore.h @@ -21,7 +21,7 @@ #ifndef LTT_CORE_H #define LTT_CORE_H -#include "kernelcompat.h" +#include //ust// #include /* ltt's root dir in debugfs */ diff --git a/share/kernelcompat.h b/share/kernelcompat.h deleted file mode 100644 index 5cc5eaa2..00000000 --- a/share/kernelcompat.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef KERNELCOMPAT_H -#define KERNELCOMPAT_H - -#include - -#include -#include - -/* FIXME: libkcompat must not define arch-specific local ops, as ust *must* - * fallback to the normal atomic ops. Fix things so we don't add them and - * break things accidentally. - */ - -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - -#define KERN_DEBUG "" -#define KERN_NOTICE "" -#define KERN_INFO "" -#define KERN_ERR "" -#define KERN_ALERT "" -#define KERN_WARNING "" - -/* ERROR OPS */ - -#define MAX_ERRNO 4095 - -#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) - -static inline void *ERR_PTR(long error) -{ - return (void *) error; -} - -static inline long PTR_ERR(const void *ptr) -{ - return (long) ptr; -} - -static inline long IS_ERR(const void *ptr) -{ - return IS_ERR_VALUE((unsigned long)ptr); -} - - -/* Min / Max */ - -#define min_t(type, x, y) ({ \ - type __min1 = (x); \ - type __min2 = (y); \ - __min1 < __min2 ? __min1: __min2; }) - -#define max_t(type, x, y) ({ \ - type __max1 = (x); \ - type __max2 = (y); \ - __max1 > __max2 ? __max1: __max2; }) - - -/* MUTEXES */ - -#include - -#define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER; -#define DECLARE_MUTEX(m) extern pthread_mutex_t (m); - -#define mutex_lock(m) pthread_mutex_lock(m) - -#define mutex_unlock(m) pthread_mutex_unlock(m) - - -/* MALLOCATION */ - -#include - -#define kmalloc(s, t) malloc(s) -#define kzalloc(s, t) zmalloc(s) -#define kfree(p) free((void *)p) -#define kstrdup(s, t) strdup(s) - -#define zmalloc(s) calloc(1, s) - -#define GFP_KERNEL - -/* PRINTK */ - -#include -#define printk(fmt, args...) printf(fmt, ## args) - - -/* ATTRIBUTES */ - -#define ____cacheline_aligned - -/* MATH */ - -static inline unsigned int hweight32(unsigned int w) -{ - unsigned int res = w - ((w >> 1) & 0x55555555); - res = (res & 0x33333333) + ((res >> 2) & 0x33333333); - res = (res + (res >> 4)) & 0x0F0F0F0F; - res = res + (res >> 8); - return (res + (res >> 16)) & 0x000000FF; -} - -static inline int fls(int x) -{ - int r; -//ust// #ifdef CONFIG_X86_CMOV - asm("bsrl %1,%0\n\t" - "cmovzl %2,%0" - : "=&r" (r) : "rm" (x), "rm" (-1)); -//ust// #else -//ust// asm("bsrl %1,%0\n\t" -//ust// "jnz 1f\n\t" -//ust// "movl $-1,%0\n" -//ust// "1:" : "=r" (r) : "rm" (x)); -//ust// #endif - return r + 1; -} - -static __inline__ int get_count_order(unsigned int count) -{ - int order; - - order = fls(count) - 1; - if (count & (count - 1)) - order++; - return order; -} - - - - -#include - -#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) -#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) -#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) -#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#define PAGE_MASK (~(PAGE_SIZE-1)) - - - - -/* ARRAYS */ - -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - -/* TRACE CLOCK */ - -/* There are two types of clocks that can be used. - - TSC based clock - - gettimeofday() clock - - Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are inlined): - Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call - Calls (100000000) to gettimeofday(): 9723158352 cycles or 97 cycles/call - - For merging traces with the kernel, a time source compatible with that of - the kernel is necessary. - -*/ - -#if 0 -/* WARNING: Make sure to set frequency and scaling functions that will not - * result in lttv timestamps (sec.nsec) with seconds greater than 2**32-1. - */ -static inline u64 trace_clock_read64(void) -{ - uint32_t low; - uint32_t high; - uint64_t retval; - __asm__ volatile ("rdtsc\n" : "=a" (low), "=d" (high)); - - retval = high; - retval <<= 32; - return retval | low; -} -#endif - -static inline u64 trace_clock_read64(void) -{ - struct timeval tv; - u64 retval; - - gettimeofday(&tv, NULL); - retval = tv.tv_sec; - retval *= 1000000; - retval += tv.tv_usec; - - return retval; -} - -static inline u64 trace_clock_frequency(void) -{ - return 1000000LL; -} - -static inline u32 trace_clock_freq_scale(void) -{ - return 1; -} - - -#endif /* KERNELCOMPAT_H */ diff --git a/share/share.h b/share/share.h deleted file mode 100644 index f674f31f..00000000 --- a/share/share.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef UST_SHARE_H -#define UST_SHARE_H - -#include -#include - -/* This write is patient because it restarts if it was incomplete. - */ - -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; -} - -#endif /* UST_SHARE_H */ diff --git a/share/usterr.h b/share/usterr.h deleted file mode 100644 index 1819f973..00000000 --- a/share/usterr.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef USTERR_H -#define USTERR_H - -#include -#include -#include -#include -#include - -#include "share.h" - -#ifndef UST_COMPONENT -//#error UST_COMPONENT is undefined -#define UST_COMPONENT libust -#endif - -/* To stringify the expansion of a define */ -#define XSTR(d) STR(d) -#define STR(s) #s - -/* We sometimes print in the tracing path, and tracing can occur in - * signal handlers, so we must use a print method which is signal safe. - */ - -#define sigsafe_print_err(fmt, args...) \ -{ \ - /* Can't use dynamic allocation. Limit ourselves to 250 chars. */ \ - char ____buf[250]; \ - int ____saved_errno; \ -\ - /* Save the errno. */ \ - ____saved_errno = errno; \ -\ - snprintf(____buf, sizeof(____buf), fmt, ## args); \ -\ - /* Add end of string in case of buffer overflow. */ \ - ____buf[sizeof(____buf)-1] = 0; \ -\ - patient_write(STDERR_FILENO, ____buf, strlen(____buf)); \ - /* Can't print errors because we are in the error printing code path. */ \ -\ - /* Restore errno, in order to be async-signal safe. */ \ - errno = ____saved_errno; \ -} - -#define UST_STR_COMPONENT XSTR(UST_COMPONENT) - -#define ERRMSG(fmt, args...) do { sigsafe_print_err(UST_STR_COMPONENT "[%ld/%ld]: " fmt " (" __FILE__ ":" XSTR(__LINE__) ")\n", (long) getpid(), (long) syscall(SYS_gettid), ## args); fflush(stderr); } while(0) - -#define DEBUG -#ifdef DEBUG -# define DBG(fmt, args...) ERRMSG(fmt, ## args) -#else -# define DBG(fmt, args...) do {} while(0) -#endif -#define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args) -#define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args) -#define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args) - -#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE) -#define PERROR(call, args...)\ - do { \ - char buf[200] = "Error in strerror_r()"; \ - strerror_r(errno, buf, sizeof(buf)); \ - ERRMSG("Error: " call ": %s", ## args, buf); \ - } while(0); -#else -#define PERROR(call, args...)\ - do { \ - char *buf; \ - char tmp[200]; \ - buf = strerror_r(errno, tmp, sizeof(tmp)); \ - ERRMSG("Error: " call ": %s", ## args, buf); \ - } while(0); -#endif - -#define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0) -#define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected on line %s:%d", __FILE__, __LINE__); } while(0) - -#endif /* USTERR_H */ diff --git a/tests/basic/Makefile.am b/tests/basic/Makefile.am index bfb77fcd..4945cdf1 100644 --- a/tests/basic/Makefile.am +++ b/tests/basic/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include noinst_PROGRAMS = basic basic_SOURCES = basic.c diff --git a/tests/basic_long/Makefile.am b/tests/basic_long/Makefile.am index 867ac837..00b5ec61 100644 --- a/tests/basic_long/Makefile.am +++ b/tests/basic_long/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include noinst_PROGRAMS = basic_long basic_long_SOURCES = basic_long.c diff --git a/tests/fork/Makefile.am b/tests/fork/Makefile.am index 4e2baf89..7bbef71d 100644 --- a/tests/fork/Makefile.am +++ b/tests/fork/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include noinst_PROGRAMS = fork fork2 fork_SOURCES = fork.c diff --git a/tests/hello/Makefile.am b/tests/hello/Makefile.am index e6b33857..ce0ad2fe 100644 --- a/tests/hello/Makefile.am +++ b/tests/hello/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include noinst_PROGRAMS = hello hello_SOURCES = hello.c tp.c tp.h diff --git a/tests/hello/hello.c b/tests/hello/hello.c index dc220c46..c48b6df5 100644 --- a/tests/hello/hello.c +++ b/tests/hello/hello.c @@ -8,6 +8,7 @@ #include #include +#include "usterr.h" #include "tp.h" diff --git a/tests/hello2/Makefile.am b/tests/hello2/Makefile.am index 85cfd2b8..e06d5059 100644 --- a/tests/hello2/Makefile.am +++ b/tests/hello2/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/share -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/include noinst_PROGRAMS = hello2 hello2_SOURCES = hello2.c diff --git a/ustctl/Makefile.am b/ustctl/Makefile.am index a27880a0..93c5629c 100644 --- a/ustctl/Makefile.am +++ b/ustctl/Makefile.am @@ -1,8 +1,7 @@ +AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/libustcomm \ + -I$(top_builddir)/libustcmd $(KCOMPAT_CFLAGS) + bin_PROGRAMS = ustctl -ustctl_SOURCES = ustctl.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/libustcmd/ustcmd.c $(top_builddir)/libustcmd/ustcmd.h $(top_builddir)/share/usterr.h +ustctl_SOURCES = ustctl.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/libustcmd/ustcmd.c $(top_builddir)/libustcmd/ustcmd.h ustctl_CFLAGS = -DUST_COMPONENT=ustctl -INCLUDES = $(KCOMPAT_CFLAGS) -INCLUDES += -I$(top_builddir)/libustcomm -INCLUDES += -I$(top_builddir)/libustcmd -INCLUDES += -I$(top_builddir)/share diff --git a/ustd/Makefile.am b/ustd/Makefile.am index e8fa272b..8c8fe647 100644 --- a/ustd/Makefile.am +++ b/ustd/Makefile.am @@ -1,7 +1,7 @@ -AM_CPPFLAGS = -I$(top_builddir)/share -I$(top_builddir)/libust \ - -I$(top_builddir)/libustcomm -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_builddir)/libust -I$(top_builddir)/libustcomm \ + -I$(top_builddir)/include bin_PROGRAMS = ustd -ustd_SOURCES = lowlevel.c ustd.c ustd.h $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/share/usterr.h +ustd_SOURCES = lowlevel.c ustd.c ustd.h $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h ustd_LDFLAGS = -lpthread ustd_CFLAGS = -DUST_COMPONENT=ustd diff --git a/ustd/ustd.c b/ustd/ustd.c index fef0eae1..0026c3b1 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -35,7 +35,6 @@ #include "ustd.h" #include "usterr.h" #include "ustcomm.h" -#include "share.h" /* return value: 0 = subbuffer is finished, it won't produce data anymore * 1 = got subbuffer successfully