# 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'
-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
--- /dev/null
+/*
+ * 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 */
--- /dev/null
+/*
+ * 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); })
--- /dev/null
+#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 <jblunck@suse.de>
+ *
+ * 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 */
--- /dev/null
+#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 */
--- /dev/null
+/*
+ * 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 <limits.h>
+#include <bits/wordsize.h>
+#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 <stdint.h>
+#include <stddef.h>
+
+/* Taken from userspace-rcu */
+#include <urcu/arch.h>
+
+/* Kernel libs */
+#include <ust/kcompat/simple.h>
+#include <ust/kcompat/compiler.h>
+#include <ust/kcompat/types.h>
+#include <ust/kcompat/hlist.h>
+
+#include <ust/kcompat/jhash.h>
+
+#include <ust/kcompat/disable.h>
+
+#include <ust/kcompat/kref.h>
+
+#endif /* KCOMPAT_H */
--- /dev/null
+#ifndef _KCOMPAT_KREF_H
+#define _KCOMPAT_KREF_H
+
+/*
+ * Kernel sourcecode compatible reference counting implementation
+ *
+ * Copyright (C) 2009 Novell Inc.
+ *
+ * Author: Jan Blunck <jblunck@suse.de>
+ *
+ * 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 <assert.h>
+#include <urcu/uatomic_arch.h>
+
+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 */
--- /dev/null
+/*
+ * 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 */
--- /dev/null
+#ifndef _KCOMPAT_TYPES
+#define _KCOMPAT_TYPES
+
+/*
+ * Kernel sourcecode compatibility layer
+ *
+ * Copyright (C) 2009 Novell Inc.
+ *
+ * Author: Jan Blunck <jblunck@suse.de>
+ *
+ * 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 <asm/types.h>
+
+#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 */
#ifndef KERNELCOMPAT_H
#define KERNELCOMPAT_H
-#include <kcompat.h>
+#include <ust/kcompat/kcompat.h>
#include <urcu/list.h>
/* FIXME: libkcompat must not define arch-specific local ops, as ust *must*
#include <sys/shm.h>
#include <fcntl.h>
#include <ust/kernelcompat.h>
-#include <kcompat/kref.h>
#include <stdlib.h>
#include "buffers.h"
#include "channels.h"
#ifndef _UST_BUFFERS_H
#define _UST_BUFFERS_H
-#include <kcompat/kref.h>
#include <assert.h>
+#include <ust/kernelcompat.h>
+#include "usterr.h"
#include "channels.h"
#include "tracerconst.h"
#include "tracercore.h"
#include "header-inline.h"
-#include <usterr.h>
/***** FIXME: SHOULD BE REMOVED ***** */
#include <errno.h>
#include <ust/kernelcompat.h>
-#include <kcompat/kref.h>
#define EVENTS_PER_CHANNEL 65536
#define MAX_CPUS 32
#include <errno.h>
#define _LGPL_SOURCE
#include <urcu-bp.h>
+#include <urcu/rculist.h>
#include <ust/kernelcompat.h>
#include <ust/marker.h>
#include <sys/un.h>
#include <urcu/list.h>
-#include "kcompat.h"
+#include <ust/kcompat/kcompat.h>
#include "multipoll.h"
#define SOCK_DIR "/tmp/ust-app-socks"