From: Pierre-Marc Fournier Date: Tue, 16 Mar 2010 20:53:35 +0000 (-0400) Subject: move libkcompat inside ust X-Git-Tag: v1.9.1~640 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=17bb07b445acdef0034194bdcebe113988a8db60;p=lttng-ust.git move libkcompat inside ust --- diff --git a/configure.ac b/configure.ac index b1fb068b..e8cedce6 100644 --- a/configure.ac +++ b/configure.ac @@ -61,10 +61,6 @@ This error can also occur when the liburcu package's configure script has not be # urcu - check that URCU lib is available to compilation AC_CHECK_LIB([urcu-bp], [synchronize_rcu], [], [AC_MSG_ERROR([Cannot find liburcu-bp lib. Use [LDFLAGS]=-Ldir to specify its location.])]) -# kcompat - -AC_CHECK_HEADERS([kcompat.h], [], [AC_MSG_ERROR([Cannot find kcompat headers (kcompat.h). Use [CFLAGS]=-Idir to specify their location.])]) - # Check for various supplementary host information (beyond the # triplet) which might affect the library format choices. E.g., we # can be building with `i686-unknown-linux-gnu-gcc -m64' diff --git a/include/Makefile.am b/include/Makefile.am index ac8fffea..a98cee1a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,18 @@ -nobase_include_HEADERS = ust/immediate.h ust/kernelcompat.h ust/marker.h \ - ust/tracepoint.h ust/processor.h ust/probe.h ust/ust.h ust/tracectl.h +nobase_include_HEADERS = \ + ust/immediate.h \ + ust/kernelcompat.h \ + ust/marker.h \ + ust/tracepoint.h \ + ust/processor.h \ + ust/probe.h \ + ust/ust.h \ + ust/tracectl.h \ + ust/kcompat/compiler.h \ + ust/kcompat/disable.h \ + ust/kcompat/hlist.h \ + ust/kcompat/jhash.h \ + ust/kcompat/kref.h \ + ust/kcompat/simple.h \ + ust/kcompat/types.h noinst_HEADERS = share.h usterr.h ust_snprintf.h diff --git a/include/ust/kcompat/compiler.h b/include/ust/kcompat/compiler.h new file mode 100644 index 00000000..d3ef8a1e --- /dev/null +++ b/include/ust/kcompat/compiler.h @@ -0,0 +1,41 @@ +/* + * 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 __maybe_unused __attribute__((unused)) + +#define notrace __attribute__((no_instrument_function)) + +#endif /* KCOMPAT_COMPILER_H */ diff --git a/include/ust/kcompat/disable.h b/include/ust/kcompat/disable.h new file mode 100644 index 00000000..36d36f50 --- /dev/null +++ b/include/ust/kcompat/disable.h @@ -0,0 +1,21 @@ +/* + * disable.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 + */ + +#define prefetch(a) ({ do {} while(0); }) diff --git a/include/ust/kcompat/hlist.h b/include/ust/kcompat/hlist.h new file mode 100644 index 00000000..1bec11a5 --- /dev/null +++ b/include/ust/kcompat/hlist.h @@ -0,0 +1,73 @@ +#ifndef _KCOMPAT_HLIST_H +#define _KCOMPAT_HLIST_H + +/* + * Kernel sourcecode compatible lightweight single pointer list head useful + * for implementing hash tables + * + * 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. + */ + +struct hlist_head +{ + struct hlist_node *next; +}; + +struct hlist_node +{ + struct hlist_node *next; + struct hlist_node *prev; +}; + +/* Initialize a new list head. */ +static inline void INIT_HLIST_HEAD(struct hlist_head *ptr) +{ + ptr->next = NULL; +} + +/* Get typed element from list at a given position. */ +#define hlist_entry(ptr, type, member) \ + ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member))) + +/* Add new element at the head of the list. */ +static inline void hlist_add_head (struct hlist_node *newp, + struct hlist_head *head) +{ + if (head->next) + head->next->prev = newp; + + newp->next = head->next; + newp->prev = (struct hlist_node *)head; + head->next = newp; +} + +/* Remove element from list. */ +static inline void hlist_del (struct hlist_node *elem) +{ + if (elem->next) + elem->next->prev = elem->prev; + + elem->prev->next = elem->next; +} + +#define hlist_for_each_entry(entry, pos, head, member) \ + for (pos = (head)->next, \ + entry = hlist_entry(pos, typeof(*entry), member); \ + pos != NULL; \ + pos = pos->next, \ + entry = hlist_entry(pos, typeof(*entry), member)) + +#define hlist_for_each_entry_safe(entry, pos, p, head, member) \ + for (pos = (head)->next, \ + entry = hlist_entry(pos, typeof(*entry), member); \ + (pos != NULL) && ({ p = pos->next; 1;}); \ + pos = p, \ + entry = hlist_entry(pos, typeof(*entry), member)) + +#endif /* _KCOMPAT_HLIST_H */ diff --git a/include/ust/kcompat/jhash.h b/include/ust/kcompat/jhash.h new file mode 100644 index 00000000..dad0abbd --- /dev/null +++ b/include/ust/kcompat/jhash.h @@ -0,0 +1,84 @@ +#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 = 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/ust/kcompat/kcompat.h b/include/ust/kcompat/kcompat.h new file mode 100644 index 00000000..4aea4ccd --- /dev/null +++ b/include/ust/kcompat/kcompat.h @@ -0,0 +1,70 @@ +/* + * 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 +#include + +#include + +#include + +#include + +#endif /* KCOMPAT_H */ diff --git a/include/ust/kcompat/kref.h b/include/ust/kcompat/kref.h new file mode 100644 index 00000000..f0604ef3 --- /dev/null +++ b/include/ust/kcompat/kref.h @@ -0,0 +1,46 @@ +#ifndef _KCOMPAT_KREF_H +#define _KCOMPAT_KREF_H + +/* + * Kernel sourcecode compatible reference counting implementation + * + * 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 +#include + +struct kref { + long refcount; /* ATOMIC */ +}; + +static inline void kref_set(struct kref *ref, int val) +{ + uatomic_set(&ref->refcount, val); +} + +static inline void kref_init(struct kref *ref) +{ + kref_set(ref, 1); +} + +static inline void kref_get(struct kref *ref) +{ + long result = uatomic_add_return(&ref->refcount, 1); + assert(result != 0); +} + +static inline void kref_put(struct kref *ref, void (*release)(struct kref *)) +{ + long res = uatomic_sub_return(&ref->refcount, 1); + if (res == 0) + release(ref); +} + +#endif /* _KCOMPAT_KREF_H */ diff --git a/include/ust/kcompat/simple.h b/include/ust/kcompat/simple.h new file mode 100644 index 00000000..762d8029 --- /dev/null +++ b/include/ust/kcompat/simple.h @@ -0,0 +1,43 @@ +/* + * simple.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_SIMPLE_H +#define KCOMPAT_SIMPLE_H + +/** + * container_of - cast a member of a structure out to the containing structure + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + + +/* libkcompat: from rcupdate.h */ + +struct rcu_head { + struct rcu_head *next; + void (*func)(struct rcu_head *head); +}; + +#endif /* KCOMPAT_SIMPLE_H */ diff --git a/include/ust/kcompat/types.h b/include/ust/kcompat/types.h new file mode 100644 index 00000000..63f9ede0 --- /dev/null +++ b/include/ust/kcompat/types.h @@ -0,0 +1,32 @@ +#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/ust/kernelcompat.h b/include/ust/kernelcompat.h index b6e85c3f..e6885f7d 100644 --- a/include/ust/kernelcompat.h +++ b/include/ust/kernelcompat.h @@ -18,7 +18,7 @@ #ifndef KERNELCOMPAT_H #define KERNELCOMPAT_H -#include +#include #include /* FIXME: libkcompat must not define arch-specific local ops, as ust *must* diff --git a/libust/buffers.c b/libust/buffers.c index 88ec5d3b..8cadeabf 100644 --- a/libust/buffers.c +++ b/libust/buffers.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "buffers.h" #include "channels.h" diff --git a/libust/buffers.h b/libust/buffers.h index 44e8598d..d3267e10 100644 --- a/libust/buffers.h +++ b/libust/buffers.h @@ -23,13 +23,13 @@ #ifndef _UST_BUFFERS_H #define _UST_BUFFERS_H -#include #include +#include +#include "usterr.h" #include "channels.h" #include "tracerconst.h" #include "tracercore.h" #include "header-inline.h" -#include /***** FIXME: SHOULD BE REMOVED ***** */ diff --git a/libust/channels.h b/libust/channels.h index 0d2715d1..e92e6cce 100644 --- a/libust/channels.h +++ b/libust/channels.h @@ -25,7 +25,6 @@ #include #include -#include #define EVENTS_PER_CHANNEL 65536 #define MAX_CPUS 32 diff --git a/libust/marker.c b/libust/marker.c index ef6f029a..4a3e16b9 100644 --- a/libust/marker.c +++ b/libust/marker.c @@ -20,6 +20,7 @@ #include #define _LGPL_SOURCE #include +#include #include #include diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index e7e73621..a8fd6408 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -22,7 +22,7 @@ #include #include -#include "kcompat.h" +#include #include "multipoll.h" #define SOCK_DIR "/tmp/ust-app-socks"