Add support for ppc hw tb clock, remove kernelcompat.h
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 23 Apr 2010 15:31:52 +0000 (11:31 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 23 Apr 2010 15:35:12 +0000 (11:35 -0400)
21 files changed:
include/Makefile.am
include/ust/clock.h [new file with mode: 0644]
include/ust/core.h
include/ust/kernelcompat.h [deleted file]
include/ust/marker.h
include/ust/tracepoint.h
include/ust/ust.h
include/usterr.h
libust/buffers.c
libust/buffers.h
libust/channels.c
libust/channels.h
libust/marker-control.c
libust/marker.c
libust/serialize.c
libust/tracepoint.c
libust/tracer.c
libust/tracer.h
libust/tracercore.c
libust/tracercore.h
libust/type-serializer.c

index 5a8b075f528bfb7bde1a1a14f8130c9d604450cc..eba0fe5b8153ff37e571d857a466fdc7e850a5a7 100644 (file)
@@ -1,6 +1,5 @@
 nobase_include_HEADERS = \
        ust/immediate.h \
-       ust/kernelcompat.h \
        ust/marker.h \
        ust/tracepoint.h \
        ust/processor.h \
diff --git a/include/ust/clock.h b/include/ust/clock.h
new file mode 100644 (file)
index 0000000..d4b6a9d
--- /dev/null
@@ -0,0 +1,115 @@
+/* Copyright (C) 2010  Pierre-Marc Fournier
+ *
+ * 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 UST_CLOCK_H
+#define UST_CLOCK_H
+
+#include <sys/time.h>
+#include <ust/kcompat/kcompat.h>
+
+/* 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.
+
+*/
+
+#define TRACE_CLOCK_GENERIC
+#ifdef TRACE_CLOCK_GENERIC
+
+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;
+}
+
+#else
+
+#if __i386 || __x86_64
+
+/* 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 /* __i386 || __x86_64 */
+
+#ifdef __PPC__
+
+static __inline__ u64 trace_clock_read64(void)
+{
+       unsigned long tb_l;
+       unsigned long tb_h;
+       unsigned long tb_h2;
+       u64 tb;
+
+       __asm__ (
+               "1:\n\t"
+               "mftbu %[rhigh]\n\t"
+               "mftb %[rlow]\n\t"
+               "mftbu %[rhigh2]\n\t"
+               "cmpw %[rhigh],%[rhigh2]\n\t"
+               "bne 1b\n\t"
+       : [rhigh] "=r" (tb_h), [rhigh2] "=r" (tb_h2), [rlow] "=r" (tb_l));
+       
+       tb = tb_h;
+       tb <<= 32;
+       tb |= tb_l;
+
+       return tb;
+}
+
+#endif /* __PPC__ */
+
+#endif /* ! UST_TRACE_CLOCK_GENERIC */
+
+static __inline__ u64 trace_clock_frequency(void)
+{
+       return 1000000LL;
+}
+
+static __inline__ u32 trace_clock_freq_scale(void)
+{
+       return 1;
+}
+
+#endif /* UST_CLOCK_H */
index 27c7e6d4802717215792fe68cd4c3234ebaa0ad0..c6057ea7b0a93e13de955d1c903a4f4cd2f8b3a4 100644 (file)
@@ -1,6 +1,28 @@
+/* Copyright (C) 2010  Pierre-Marc Fournier
+ *
+ * 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 UST_CORE_H
 #define UST_CORE_H
 
+#include <sys/types.h>
+
+#define likely(x)      __builtin_expect(!!(x), 1)
+#define unlikely(x)    __builtin_expect(!!(x), 0)
+
 #if defined(CONFIG_LTT) && defined(CONFIG_LTT_ALIGNMENT)
 
 /*
@@ -36,4 +58,101 @@ static inline int ltt_get_alignment(void)
 }
 #endif /* defined(CONFIG_LTT) && defined(CONFIG_LTT_ALIGNMENT) */
 
+
+/* ARRAYS */
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+
+/* ALIGNMENT SHORTCUTS */
+
+#include <unistd.h>
+
+#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))
+
+/* 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 <pthread.h>
+
+#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 */
+
+#define zmalloc(s) calloc(1, s)
+
+/* ATTRIBUTES */
+
+/* FIXME: define this */
+#define ____cacheline_aligned
+
+/* MATH */
+
+#include <ust/processor.h>
+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 get_count_order(unsigned int count)
+{
+       int order;
+       
+       order = fls(count) - 1;
+       if (count & (count - 1))
+               order++;
+       return order;
+}
+
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+        (type *)( (char *)__mptr - offsetof(type,member) );})
+
 #endif /* UST_CORE_H */
diff --git a/include/ust/kernelcompat.h b/include/ust/kernelcompat.h
deleted file mode 100644 (file)
index 1b9058d..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/* Copyright (C) 2009  Pierre-Marc Fournier
- *
- * 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 KERNELCOMPAT_H
-#define KERNELCOMPAT_H
-
-#include <ust/kcompat/kcompat.h>
-#include <urcu/list.h>
-
-/* 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) );})
-
-/* 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 <pthread.h>
-
-#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 */
-
-#define zmalloc(s) calloc(1, s)
-
-/* ATTRIBUTES */
-
-/* FIXME: define this */
-#define ____cacheline_aligned
-
-/* MATH */
-
-#include <ust/processor.h>
-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 get_count_order(unsigned int count)
-{
-       int order;
-       
-       order = fls(count) - 1;
-       if (count & (count - 1))
-               order++;
-       return order;
-}
-
-
-
-
-#include <unistd.h>
-
-#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
-
-#include <sys/time.h>
-
-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 */
index 0e0b466b994546337c61e3d95e7714837e8c49ad..72ced98c4e3fb16eedaa17d294566d2622394742 100644 (file)
 
 #include <stdarg.h>
 #include <ust/immediate.h>
-#include <ust/kernelcompat.h>
+#include <ust/core.h>
 #include <urcu/list.h>
 #include <ust/processor.h>
+#include <ust/kcompat/kcompat.h>
 
 #include <bits/wordsize.h>
 
index 7db6ed3065e8f9e4316d6b5bbcff4b11f379bd71..be35f92665e7d69eeaf6633f95c535c213262c9b 100644 (file)
  * Ported to userspace by Pierre-Marc Fournier.
  */
 
-//#include <linux/immediate.h>
-//#include <linux/types.h>
-//#include <linux/rcupdate.h>
-
 #define _LGPL_SOURCE
 #include <urcu-bp.h>
-
 #include <ust/immediate.h>
-#include <ust/kernelcompat.h>
+#include <ust/core.h>
 
 struct module;
 struct tracepoint;
index 47e5b6efa9826e48e7cc2f190f55c0ac34d35048..d99a706a842647bf0e0cbc6f935388df81f219a5 100644 (file)
@@ -19,7 +19,6 @@
 #define UST_H
 
 #include <ust/immediate.h>
-#include <ust/kernelcompat.h>
 #include <ust/marker.h>
 #include <ust/processor.h>
 #include <ust/tracepoint.h>
index 0f6d3608bdbdcc6b859c804c98508fcc0d35727c..f0cdeb02f7d0922b3041e6c76c9028f02a3935f8 100644 (file)
@@ -25,6 +25,8 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#include <ust/core.h>
+
 #include "share.h"
 
 #ifndef UST_COMPONENT
index ef62a305e9ca6e8feb0aff1a500e31bfabc1646d..ac34e5fa5f3102de5fc93dd7c1833d586c578b6a 100644 (file)
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <fcntl.h>
-#include <ust/kernelcompat.h>
 #include <stdlib.h>
+
+#include <ust/clock.h>
+
 #include "buffers.h"
 #include "channels.h"
 #include "tracer.h"
index ca78796fbc9aa7e2aa28f2c4a0fcb9db73cbc7c7..00655a49cb394838ae3e323f9ca69d6a1673476d 100644 (file)
@@ -24,7 +24,9 @@
 #define _UST_BUFFERS_H
 
 #include <assert.h>
-#include <ust/kernelcompat.h>
+
+#include <ust/core.h>
+
 #include "usterr.h"
 #include "channels.h"
 #include "tracerconst.h"
index 32942cf795f79a4d7c1f7b63755eef68a9c4fdf8..e06720f3bc75c3f4fd1ac1b4958d827391dba9f8 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include <stdlib.h>
-#include <ust/kernelcompat.h>
 #include <ust/marker.h>
 #include "channels.h"
 #include "usterr.h"
index 693bf82bedc9bac9208abd66d491fd878ed9efb4..2000430d9f42041c80d0820fa25e0f88b6963335 100644 (file)
@@ -23,8 +23,9 @@
 
 #include <linux/limits.h>
 #include <errno.h>
-
-#include <ust/kernelcompat.h>
+#include <ust/kcompat/kcompat.h>
+#include <urcu/list.h>
+#include <ust/core.h>
 
 #define EVENTS_PER_CHANNEL     65536
 #define MAX_CPUS               32
index a24a94c6876e747ef7a7e30b5e8cd62267e8a302..9ee5b7cd58e54771c05121b44b005b9c5bdb73e9 100644 (file)
@@ -21,7 +21,6 @@
 #include <ctype.h>
 #include <stdlib.h>
 
-#include <ust/kernelcompat.h>
 #include "tracer.h"
 #include "usterr.h"
 
index fd16860ecf85a9c070f6df1ee4d751bbae89c5d2..56ffe39960dd6d6e79281410cf5cf5002019906d 100644 (file)
@@ -22,7 +22,7 @@
 #include <urcu-bp.h>
 #include <urcu/rculist.h>
 
-#include <ust/kernelcompat.h>
+#include <ust/core.h>
 #include <ust/marker.h>
 
 #include "usterr.h"
index d3c8cdb3d54b4dbe5dc97e810243cb705d685680..32df0b96ddbae05c9b4c1765444684418e20980f 100644 (file)
 #include <urcu-bp.h>
 #include <urcu/rculist.h>
 
-#include <ust/kernelcompat.h>
 #include <ust/core.h>
+#include <ust/clock.h>
 #include "buffers.h"
 #include "tracer.h"
-//#include "list.h"
 #include "usterr.h"
 #include "ust_snprintf.h"
 
index dd2ad7fae24fcc37615db05bda2e6a917e2889e6..8eee320d4149bbc7bca9416ce7264a4c2821a900 100644 (file)
@@ -20,9 +20,9 @@
  */
 
 #include <errno.h>
-
-#include <ust/kernelcompat.h>
 #include <ust/tracepoint.h>
+#include <ust/core.h>
+#include <ust/kcompat/kcompat.h>
 #include "usterr.h"
 
 #define _LGPL_SOURCE
index 60fc8b7a182270110e9408ec7d96fd72e655d8e0..baab461f08317d934236113951efab9aeb926af4 100644 (file)
@@ -34,7 +34,8 @@
 #include <urcu-bp.h>
 #include <urcu/rculist.h>
 
-#include <ust/kernelcompat.h>
+#include <ust/clock.h>
+
 #include "tracercore.h"
 #include "tracer.h"
 #include "usterr.h"
index dc2d62fffe66b359c70c3d145355bc4af01b1c3d..0fa2e4dd929fcb54254fa0fff4f93fae965e5e69 100644 (file)
 
 #include <sys/types.h>
 #include <stdarg.h>
-#include <ust/kernelcompat.h>
+#include <ust/marker.h>
+#include <ust/probe.h>
+#include <ust/core.h>
 #include "channels.h"
 #include "tracercore.h"
 #include "tracerconst.h"
-#include <ust/marker.h>
-#include <ust/probe.h>
 #include "buffers.h"
 
 /* Number of bytes to log with a read/write event */
index 72c2887d8a1ece8b0ca479573d04b6172e4c5069..ff01f5e2a3933be64bed14260b79c182b77cb190 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <ust/kernelcompat.h>
 #include "tracercore.h"
 
 /* Traces structures */
index 52f75ec82352fca4ebddb7fde5245ecb39aef14d..5c396f464fec001b9aca07829c452dfb5bae01ee 100644 (file)
 #ifndef UST_TRACERCORE_H
 #define UST_TRACERCORE_H
 
-#include <ust/kernelcompat.h>
-//ust// #include <linux/percpu.h>
-
-/* ltt's root dir in debugfs */
-#define LTT_ROOT        "ltt"
+#include <ust/kcompat/kcompat.h>
+#include <ust/core.h>
+#include <urcu/list.h>
 
 /*
  * All modifications of ltt_traces must be done by ltt-tracer.c, while holding
index 3ee54ebab37eedcd41d101017bc8db3dfe53e0f0..5d20960e03a7c58a82a27a8fa6e352ffd568cd00 100644 (file)
@@ -10,6 +10,7 @@
 #include <urcu/rculist.h>
 #include <ust/type-serializer.h>
 #include <ust/core.h>
+#include <ust/clock.h>
 #include "tracer.h"
 
 notrace
This page took 0.03385 seconds and 4 git commands to generate.