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: v0.1~71^2 X-Git-Url: http://git.lttng.org/?p=ust.git;a=commitdiff_plain;h=fbca6b624335eef18c8d86194aeb101a720168f4 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 1ab5948..1bdedea 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 0a4f87d..48a898b 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 0000000..f674f31 --- /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 0000000..5cc5eaa --- /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 cb2c46d..2b5a0c3 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 7cfdbb0..56c62b0 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 0000000..1819f97 --- /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 f9deb7a..fa53628 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 2bcebb1..6540103 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 26a8bd6..e9dce9b 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 fa09307..23b7004 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 a8986f2..9ee3c9a 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 a4f4af1..27ceefc 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 c91874b..e460e12 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 c874c94..a0786ba 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 cebf07d..8690d2b 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 0326adc..408ce90 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 0055d99..99d4dce 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 9de21c8..cc2adf1 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 4150551..a3ace72 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 9275fd0..cb84dad 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 90adee4..652de1b 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 8dfffa1..5a088db 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 5cc5eaa..0000000 --- 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 f674f31..0000000 --- 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 1819f97..0000000 --- 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 bfb77fc..4945cdf 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 867ac83..00b5ec6 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 4e2baf8..7bbef71 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 e6b3385..ce0ad2f 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 dc220c4..c48b6df 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 85cfd2b..e06d505 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 a27880a..93c5629 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 e8fa272..8c8fe64 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 fef0eae..0026c3b 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