caa_get_cycles: caa_ prefix for type, use CLOCK_MONOTONIC
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 28 Sep 2015 16:58:59 +0000 (12:58 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 28 Sep 2015 16:58:59 +0000 (12:58 -0400)
clock_gettime() of CLOCK_MONOTONIC mimicks better the behavior of a
cycle counter, since it is not affected by NTP major time updates.

Also, now prefix "cycles_t" with a caa_ prefix, so it does not clash
with application namespaces. Anyway, caa_get_cycles() is mostly used in
testing.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/benchmark/test_cycles_per_loop.c
tests/benchmark/test_looplen.c
tests/benchmark/test_perthreadlock_timing.c
tests/benchmark/test_rwlock_timing.c
tests/benchmark/test_urcu_qsbr_timing.c
tests/benchmark/test_urcu_timing.c
urcu/arch/generic.h
urcu/arch/hppa.h
urcu/arch/ppc.h
urcu/arch/s390.h
urcu/arch/x86.h

index 6ff100bf38b34e518d937d6bc34760db74c6b63b..ca66ffaf7b44f7c4ef5cf6a3efdb7a4331596fcb 100644 (file)
@@ -33,7 +33,7 @@ static inline void loop_sleep(unsigned long loops)
 
 int main()
 {
 
 int main()
 {
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        time1 = caa_get_cycles();
        loop_sleep(NR_LOOPS);
 
        time1 = caa_get_cycles();
        loop_sleep(NR_LOOPS);
index 16674e76ac442343b77ea27d1994a5920cd6c9e7..c8b5a0256abebc7f14b546040ba2d7259eda6a4f 100644 (file)
@@ -54,8 +54,8 @@ static inline void loop_sleep(unsigned long loops)
 int main(int argc, char **argv)
 {
        unsigned long i;
 int main(int argc, char **argv)
 {
        unsigned long i;
-       cycles_t time1, time2;
-       cycles_t time_tot = 0;
+       caa_cycles_t time1, time2;
+       caa_cycles_t time_tot = 0;
        double cpl;
 
        for (i = 0; i < TESTS; i++) {
        double cpl;
 
        for (i = 0; i < TESTS; i++) {
index 97bdd044eae4d231621456efbd4b010b3d72c1aa..c9cc65f70736dc441fc7a13b19d9b064ac8ce227 100644 (file)
@@ -64,13 +64,13 @@ static int num_write;
 #define NR_READ num_read
 #define NR_WRITE num_write
 
 #define NR_READ num_read
 #define NR_WRITE num_write
 
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
 
 void *thr_reader(void *arg)
 {
        int i, j;
 
 void *thr_reader(void *arg)
 {
        int i, j;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
        long tidx = (long)arg;
 
        printf("thread_begin %s, tid %lu\n",
        long tidx = (long)arg;
 
        printf("thread_begin %s, tid %lu\n",
@@ -100,7 +100,7 @@ void *thr_writer(void *arg)
 {
        int i, j;
        long tidx;
 {
        int i, j;
        long tidx;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
@@ -133,8 +133,8 @@ int main(int argc, char **argv)
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
-       cycles_t tot_rtime = 0;
-       cycles_t tot_wtime = 0;
+       caa_cycles_t tot_rtime = 0;
+       caa_cycles_t tot_wtime = 0;
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
index d916071f61b459f9ea4f8ea24ec74445cd2b6e9c..fb9e41fdd16c5e804a5eaa584e919058e65ab793 100644 (file)
@@ -61,13 +61,13 @@ static int num_write;
 #define NR_READ num_read
 #define NR_WRITE num_write
 
 #define NR_READ num_read
 #define NR_WRITE num_write
 
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
 
 void *thr_reader(void *arg)
 {
        int i, j;
 
 void *thr_reader(void *arg)
 {
        int i, j;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
@@ -95,7 +95,7 @@ void *thr_reader(void *arg)
 void *thr_writer(void *arg)
 {
        int i, j;
 void *thr_writer(void *arg)
 {
        int i, j;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
@@ -124,8 +124,8 @@ int main(int argc, char **argv)
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
-       cycles_t tot_rtime = 0;
-       cycles_t tot_wtime = 0;
+       caa_cycles_t tot_rtime = 0;
+       caa_cycles_t tot_wtime = 0;
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
index 9b5195d9605e4ba914cf76cdeab14f2c63019c12..7619390e35f854df7020d8452e9dfd03420de540 100644 (file)
@@ -80,14 +80,14 @@ static int num_write;
 #define NR_READ num_read
 #define NR_WRITE num_write
 
 #define NR_READ num_read
 #define NR_WRITE num_write
 
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
 
 void *thr_reader(void *arg)
 {
        int i, j;
        struct test_array *local_ptr;
 
 void *thr_reader(void *arg)
 {
        int i, j;
        struct test_array *local_ptr;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
@@ -124,7 +124,7 @@ void *thr_writer(void *arg)
 {
        int i, j;
        struct test_array *new, *old;
 {
        int i, j;
        struct test_array *new, *old;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
@@ -165,8 +165,8 @@ int main(int argc, char **argv)
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
-       cycles_t tot_rtime = 0;
-       cycles_t tot_wtime = 0;
+       caa_cycles_t tot_rtime = 0;
+       caa_cycles_t tot_wtime = 0;
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
index e31b676ca506adf3dac9d20bdee7c6fba01a47fb..d586b1d25faea6d5b02ebe220e006e6e063ca4ce 100644 (file)
@@ -80,14 +80,14 @@ static int num_write;
 #define NR_READ num_read
 #define NR_WRITE num_write
 
 #define NR_READ num_read
 #define NR_WRITE num_write
 
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
 
 void *thr_reader(void *arg)
 {
        int i, j;
        struct test_array *local_ptr;
 
 void *thr_reader(void *arg)
 {
        int i, j;
        struct test_array *local_ptr;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "reader", urcu_get_thread_id());
@@ -123,7 +123,7 @@ void *thr_writer(void *arg)
 {
        int i, j;
        struct test_array *new, *old;
 {
        int i, j;
        struct test_array *new, *old;
-       cycles_t time1, time2;
+       caa_cycles_t time1, time2;
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
 
        printf("thread_begin %s, tid %lu\n",
                "writer", urcu_get_thread_id());
@@ -164,8 +164,8 @@ int main(int argc, char **argv)
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
-       cycles_t tot_rtime = 0;
-       cycles_t tot_wtime = 0;
+       caa_cycles_t tot_rtime = 0;
+       caa_cycles_t tot_wtime = 0;
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
 
        if (argc < 2) {
                printf("Usage : %s nr_readers nr_writers\n", argv[0]);
index e53ac564d5753216bd6400829deae651c03cf409..d42359557ef9147eafed2f2f077954e4246138ed 100644 (file)
@@ -152,17 +152,19 @@ extern "C" {
 
 #ifndef HAS_CAA_GET_CYCLES
 #define HAS_CAA_GET_CYCLES
 
 #ifndef HAS_CAA_GET_CYCLES
 #define HAS_CAA_GET_CYCLES
-typedef unsigned long long cycles_t;
 
 
-static inline cycles_t caa_get_cycles (void)
+#include <time.h>
+#include <stdint.h>
+
+typedef uint64_t caa_cycles_t;
+
+static inline caa_cycles_t caa_get_cycles (void)
 {
 {
-       cycles_t thetime;
-       struct timeval tv;
+       struct timespec ts;
 
 
-       if (gettimeofday(&tv, NULL) != 0)
-               return 0;
-       thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec);
-       return (cycles_t)thetime;
+       if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts)))
+               return -1ULL;
+       return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
 }
 #endif /* HAS_CAA_GET_CYCLES */
 
 }
 #endif /* HAS_CAA_GET_CYCLES */
 
index 82d2a426b330869054043681ee4d281b1e85d59e..f92b0ab594b43cf801aab944a1b47bf6df82c0b5 100644 (file)
@@ -33,11 +33,11 @@ extern "C" {
 #include <sys/time.h>
 
 #define HAS_CAA_GET_CYCLES
 #include <sys/time.h>
 
 #define HAS_CAA_GET_CYCLES
-typedef unsigned long cycles_t;
+typedef unsigned long caa_cycles_t;
 
 
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
 {
 {
-       cycles_t cycles;
+       caa_cycles_t cycles;
 
        asm volatile("mfctl 16, %0" : "=r" (cycles));
        return cycles;
 
        asm volatile("mfctl 16, %0" : "=r" (cycles));
        return cycles;
index dbdfec8a58dd3f29414fbc99aa48e83fa701cff3..7e2b6218f82ddc4808a775010c8bfd0c6e25ea5c 100644 (file)
@@ -25,6 +25,7 @@
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {
 
 #ifdef __cplusplus
 extern "C" {
@@ -84,15 +85,15 @@ extern "C" {
 
 #define HAS_CAA_GET_CYCLES
 
 
 #define HAS_CAA_GET_CYCLES
 
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
 
 #ifdef __powerpc64__
 
 #ifdef __powerpc64__
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
 {
 {
-       return (cycles_t) mftb();
+       return (caa_cycles_t) mftb();
 }
 #else
 }
 #else
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
 {
        unsigned long h, l;
 
 {
        unsigned long h, l;
 
@@ -102,7 +103,7 @@ static inline cycles_t caa_get_cycles(void)
                l = mftbl();
                cmm_barrier();
                if (mftbu() == h)
                l = mftbl();
                cmm_barrier();
                if (mftbu() == h)
-                       return (((cycles_t) h) << 32) + l;
+                       return (((caa_cycles_t) h) << 32) + l;
        }
 }
 #endif
        }
 }
 #endif
index e12c88c3398728025e745bd53e4c997e1d5e2fca..e71f99ec483d447e9bcdb7fa2ac1dd8ef82d5b69 100644 (file)
@@ -31,6 +31,7 @@
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,11 +43,11 @@ extern "C" {
 
 #define HAS_CAA_GET_CYCLES
 
 
 #define HAS_CAA_GET_CYCLES
 
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
 
 
-static inline cycles_t caa_get_cycles (void)
+static inline caa_cycles_t caa_get_cycles (void)
 {
 {
-       cycles_t cycles;
+       caa_cycles_t cycles;
 
        __asm__ __volatile__("stck %0" : "=m" (cycles) : : "cc", "memory" );
 
 
        __asm__ __volatile__("stck %0" : "=m" (cycles) : : "cc", "memory" );
 
index a5b3a23b385f26f7aea6b5daaf70cab762fc4262..b4d3694fdffb896fa3773f30ad8d0777ae9836a4 100644 (file)
@@ -25,6 +25,7 @@
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
 #include <urcu/compiler.h>
 #include <urcu/config.h>
 #include <urcu/syscall-compat.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {
 
 #ifdef __cplusplus
 extern "C" {
@@ -79,11 +80,11 @@ extern "C" {
                        | (((unsigned long long)__d) << 32);              \
        } while(0)
 
                        | (((unsigned long long)__d) << 32);              \
        } while(0)
 
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
 
 
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
 {
 {
-        cycles_t ret = 0;
+        caa_cycles_t ret = 0;
 
         rdtscll(ret);
         return ret;
 
         rdtscll(ret);
         return ret;
This page took 0.033011 seconds and 4 git commands to generate.