From 4b18c4a6b6c014a11c6e316df0c6e2b8119810dd Mon Sep 17 00:00:00 2001 From: compudj Date: Tue, 15 Aug 2006 16:34:08 +0000 Subject: [PATCH] completely remove kernel headers git-svn-id: http://ltt.polymtl.ca/svn@2029 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt-usertrace/Makefile | 4 +- ltt-usertrace/ltt-usertrace-fast.c | 3 - ltt-usertrace/ltt/kernelutils-i386.h | 154 +++++++++++++++++++++++ ltt-usertrace/ltt/kernelutils-x86_64.h | 168 +++++++++++++++++++++++++ ltt-usertrace/ltt/ltt-usertrace.h | 11 +- ltt-usertrace/specs/ltt-usertrace.spec | 1 + 6 files changed, 329 insertions(+), 12 deletions(-) create mode 100644 ltt-usertrace/ltt/kernelutils-i386.h create mode 100644 ltt-usertrace/ltt/kernelutils-x86_64.h diff --git a/ltt-usertrace/Makefile b/ltt-usertrace/Makefile index de07916e..93748564 100644 --- a/ltt-usertrace/Makefile +++ b/ltt-usertrace/Makefile @@ -22,7 +22,7 @@ sample: sample.c $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^ sample-block: sample-block.c $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^ - + sample-thread-brand: sample-thread-brand.c $(CC) $(LTT_CFLAGS) $(CFLAGS) -lltt-loader-user_generic -o $@ $^ @@ -95,4 +95,4 @@ install_libs: install: install_headers libs install_libs clean: - rm -fr *.o *~ sample-thread sample sample-highspeed sample-printf sample-instrument-fct libltt-instrument-functions.so* libltt-instrument-functions.a libltt-usertrace-fast.a libltt-usertrace-fast.so* libltt-loader-user_generic.so* libltt-loader-user_generic.a sample-thread-slow sample-thread-fast sample-thread-brand sample-block java/*.class java/Sample.h java/TestBrand.h + find . -name \*~ | xargs rm -fr *.o sample-thread sample sample-highspeed sample-printf sample-instrument-fct libltt-instrument-functions.so* libltt-instrument-functions.a libltt-usertrace-fast.a libltt-usertrace-fast.so* libltt-loader-user_generic.so* libltt-loader-user_generic.a sample-thread-slow sample-thread-fast sample-thread-brand sample-block java/*.class java/Sample.h java/TestBrand.h diff --git a/ltt-usertrace/ltt-usertrace-fast.c b/ltt-usertrace/ltt-usertrace-fast.c index 17da6cd8..032b2241 100644 --- a/ltt-usertrace/ltt-usertrace-fast.c +++ b/ltt-usertrace/ltt-usertrace-fast.c @@ -68,9 +68,6 @@ #include #include -// included with hack for powerpc in ltt-usertrace.h #include -#include //for get_cycles() - #include #define gettid() syscall(__NR_gettid) diff --git a/ltt-usertrace/ltt/kernelutils-i386.h b/ltt-usertrace/ltt/kernelutils-i386.h new file mode 100644 index 00000000..df7e695d --- /dev/null +++ b/ltt-usertrace/ltt/kernelutils-i386.h @@ -0,0 +1,154 @@ +/***************************************************************************** + * kernelutils-x386.h + * + * This file holds the code needed by LTT usertrace that comes from the + * kernel headers. Since including kernel headers is not recommended in + * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED + * (i.e. copied/pasted) from the original kernel headers (2.6.17). + * + * Martin Bisson, July 2006 + * Mathieu Desnoyers, August 2006 + */ + +#ifndef _KERNELUTILS_I386_H +#define _KERNELUTILS_I386_H + +// We are careful, so we assume a possibly SMP machine +#define LOCK "lock ; " +#define LOCK_PREFIX "lock ; " + + + + +// From atomic.h + + +/* + * Make sure gcc doesn't try to be clever and move things around + * on us. We need to use _exactly_ the address the user gave us, + * not some alias that contains the same information. + */ +typedef struct { volatile int counter; } atomic_t; + + +/** + * atomic_read - read atomic variable + * @v: pointer of type atomic_t + * + * Atomically reads the value of @v. + */ +#define atomic_read(v) ((v)->counter) + +/** + * atomic_add - add integer to atomic variable + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v. + */ +static __inline__ void atomic_add(int i, atomic_t *v) +{ + __asm__ __volatile__( + LOCK "addl %1,%0" + :"=m" (v->counter) + :"ir" (i), "m" (v->counter)); +} + +/** + * atomic_inc - increment atomic variable + * @v: pointer of type atomic_t + * + * Atomically increments @v by 1. + */ +static __inline__ void atomic_inc(atomic_t *v) +{ + __asm__ __volatile__( + LOCK "incl %0" + :"=m" (v->counter) + :"m" (v->counter)); +} + +/** + * atomic_add_return - add and return + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v and returns @i + @v + */ +static __inline__ int atomic_add_return(int i, atomic_t *v) +{ + int __i = i; + __asm__ __volatile__( + LOCK "xaddl %0, %1;" + :"=r"(i) + :"m"(v->counter), "0"(i)); + return i + __i; +} + + + + +// From system.h + +struct __xchg_dummy { unsigned long a[100]; }; +#define __xg(x) ((struct __xchg_dummy *)(x)) + + +/* + * Atomic compare and exchange. Compare OLD with MEM, if identical, + * store NEW in MEM. Return the initial value in MEM. Success is + * indicated by comparing RETURN with OLD. + */ + +#define __HAVE_ARCH_CMPXCHG 1 +#define cmpxchg(ptr,o,n)\ + ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ + (unsigned long)(n),sizeof(*(ptr)))) + +static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, + unsigned long new, int size) +{ + unsigned long prev; + switch (size) { + case 1: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2" + : "=a"(prev) + : "q"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + case 2: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2" + : "=a"(prev) + : "r"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + case 4: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2" + : "=a"(prev) + : "r"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + } + return old; +} + + +// From msr.h + +#define rdtscll(val) \ + __asm__ __volatile__("rdtsc" : "=A" (val)) + +// From timex.h + +typedef unsigned long long cycles_t; + +static inline cycles_t get_cycles (void) +{ + unsigned long long ret; + + rdtscll(ret); + return ret; +} + + +#endif // _KERNELUTILS_I386_H diff --git a/ltt-usertrace/ltt/kernelutils-x86_64.h b/ltt-usertrace/ltt/kernelutils-x86_64.h new file mode 100644 index 00000000..4f2ec2f7 --- /dev/null +++ b/ltt-usertrace/ltt/kernelutils-x86_64.h @@ -0,0 +1,168 @@ +/***************************************************************************** + * kernelutils-x86_64.h + * + * This file holds the code needed by LTT usertrace that comes from the + * kernel headers. Since including kernel headers is not recommended in + * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED + * (i.e. copied/pasted) from the original kernel headers (2.6.17). + * + * Martin Bisson, July 2006 + */ + +#ifndef _KERNELUTILS_X86_64_H +#define _KERNELUTILS_X86_64_H + +// We are careful, so we assume a possibly SMP machine +#define LOCK "lock ; " +#define LOCK_PREFIX "lock ; " + + + + +// From atomic.h + + +/* + * Make sure gcc doesn't try to be clever and move things around + * on us. We need to use _exactly_ the address the user gave us, + * not some alias that contains the same information. + */ +typedef struct { volatile int counter; } atomic_t; + + +/** + * atomic_read - read atomic variable + * @v: pointer of type atomic_t + * + * Atomically reads the value of @v. + */ +#define atomic_read(v) ((v)->counter) + +/** + * atomic_add - add integer to atomic variable + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v. + */ +static __inline__ void atomic_add(int i, atomic_t *v) +{ + __asm__ __volatile__( + LOCK "addl %1,%0" + :"=m" (v->counter) + :"ir" (i), "m" (v->counter)); +} + +/** + * atomic_inc - increment atomic variable + * @v: pointer of type atomic_t + * + * Atomically increments @v by 1. + */ +static __inline__ void atomic_inc(atomic_t *v) +{ + __asm__ __volatile__( + LOCK "incl %0" + :"=m" (v->counter) + :"m" (v->counter)); +} + +/** + * atomic_add_return - add and return + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v and returns @i + @v + */ +static __inline__ int atomic_add_return(int i, atomic_t *v) +{ + int __i = i; + __asm__ __volatile__( + LOCK "xaddl %0, %1;" + :"=r"(i) + :"m"(v->counter), "0"(i)); + return i + __i; +} + + + + +// From system.h + +#define __xg(x) ((volatile long *)(x)) + + +/* + * Atomic compare and exchange. Compare OLD with MEM, if identical, + * store NEW in MEM. Return the initial value in MEM. Success is + * indicated by comparing RETURN with OLD. + */ + +#define __HAVE_ARCH_CMPXCHG 1 + +static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, + unsigned long new, int size) +{ + unsigned long prev; + switch (size) { + case 1: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2" + : "=a"(prev) + : "q"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + case 2: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2" + : "=a"(prev) + : "r"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + case 4: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2" + : "=a"(prev) + : "r"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + case 8: + __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2" + : "=a"(prev) + : "r"(new), "m"(*__xg(ptr)), "0"(old) + : "memory"); + return prev; + } + return old; +} + +#define cmpxchg(ptr,o,n)\ + ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ + (unsigned long)(n),sizeof(*(ptr)))) + + + + +// From msr.h + + +#define rdtscll(val) do { \ + unsigned int __a,__d; \ + asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \ + (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ +} while(0) + + + + +// From timex.h + +typedef unsigned long long cycles_t; + +static inline cycles_t get_cycles (void) +{ + unsigned long long ret; + + rdtscll(ret); + return ret; +} + + +#endif // _KERNELUTILS_X86_64_H diff --git a/ltt-usertrace/ltt/ltt-usertrace.h b/ltt-usertrace/ltt/ltt-usertrace.h index 4fed3b76..d4d88613 100644 --- a/ltt-usertrace/ltt/ltt-usertrace.h +++ b/ltt-usertrace/ltt/ltt-usertrace.h @@ -14,7 +14,6 @@ #include #include #include -#include #define inline inline __attribute__((always_inline)) @@ -30,13 +29,11 @@ #include #endif #elif defined(__x86_64__) -#include -#include -#include -#include +#include +#elif defined(__i386__) +#include #else -#include -#include +#error "Unsupported architecture" #endif #ifndef min diff --git a/ltt-usertrace/specs/ltt-usertrace.spec b/ltt-usertrace/specs/ltt-usertrace.spec index 0480933a..a7b4e3e6 100644 --- a/ltt-usertrace/specs/ltt-usertrace.spec +++ b/ltt-usertrace/specs/ltt-usertrace.spec @@ -47,6 +47,7 @@ ldconfig /usr/include/ltt /usr/include/ltt/atomic-ppc.h /usr/include/ltt/atomic-ppc64.h +/usr/include/ltt/kernelutils-x86_64.h /usr/include/ltt/ltt-facility-custom-user_generic.h /usr/include/ltt/ltt-facility-id-user_generic.h /usr/include/ltt/ltt-facility-user_generic.h -- 2.34.1