Merge remote branch 'origin/urcu/ht' into urcu/ht
[urcu.git] / tests / test_urcu_gc.c
index 60f7816b36fe50fa7d2ecf5a6d12a0ea38b8a8d8..4eaa61b777d0dd6460b4f0ae196bb5ca0d833c28 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Userspace RCU library - test program (with baatch reclamation)
  *
- * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
  */
 
 #define _GNU_SOURCE
+#include "../config.h"
 #include <stdio.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <assert.h>
-#include <sys/syscall.h>
 #include <sched.h>
+#include <errno.h>
 
 #include <urcu/arch.h>
 
-/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */
-#define CACHE_LINE_SIZE 4096
+#ifdef __linux__
+#include <syscall.h>
+#endif
 
 /* hardcoded number of CPUs */
 #define NR_CPUS 16384
@@ -87,10 +89,13 @@ static unsigned long duration;
 /* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+/* write-side C.S. duration, in loops */
+static unsigned long wduration;
+
 static inline void loop_sleep(unsigned long l)
 {
        while(l-- != 0)
-               cpu_relax();
+               caa_cpu_relax();
 }
 
 static int verbose_mode;
@@ -107,6 +112,12 @@ static int use_affinity = 0;
 
 pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+#ifndef HAVE_CPU_SET_T
+typedef unsigned long cpu_set_t;
+# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0)
+# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0)
+#endif
+
 static void set_affinity(void)
 {
        cpu_set_t mask;
@@ -116,6 +127,7 @@ static void set_affinity(void)
        if (!use_affinity)
                return;
 
+#if HAVE_SCHED_SETAFFINITY
        ret = pthread_mutex_lock(&affinity_mutex);
        if (ret) {
                perror("Error in pthread mutex lock");
@@ -127,9 +139,15 @@ static void set_affinity(void)
                perror("Error in pthread mutex unlock");
                exit(-1);
        }
+
        CPU_ZERO(&mask);
        CPU_SET(cpu, &mask);
+#if SCHED_SETAFFINITY_ARGS == 2
+       sched_setaffinity(0, &mask);
+#else
        sched_setaffinity(0, sizeof(mask), &mask);
+#endif
+#endif /* HAVE_SCHED_SETAFFINITY */
 }
 
 /*
@@ -149,7 +167,7 @@ static unsigned long long __thread nr_writes;
 static unsigned long long __thread nr_reads;
 
 static
-unsigned long long __attribute__((aligned(CACHE_LINE_SIZE))) *tot_nr_writes;
+unsigned long long __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *tot_nr_writes;
 
 static unsigned int nr_readers;
 static unsigned int nr_writers;
@@ -192,7 +210,7 @@ void *thr_reader(void *_count)
        while (!test_go)
        {
        }
-       smp_mb();
+       cmm_smp_mb();
 
        for (;;) {
                rcu_read_lock();
@@ -265,7 +283,7 @@ void *thr_writer(void *data)
        while (!test_go)
        {
        }
-       smp_mb();
+       cmm_smp_mb();
 
        for (;;) {
 #ifndef TEST_LOCAL_GC
@@ -273,6 +291,8 @@ void *thr_writer(void *data)
                new->a = 8;
                old = rcu_xchg_pointer(&test_rcu_pointer, new);
 #endif
+               if (unlikely(wduration))
+                       loop_sleep(wduration);
                rcu_gc_reclaim(wtidx, old);
                nr_writes++;
                if (unlikely(!test_duration_write()))
@@ -295,6 +315,7 @@ void show_usage(int argc, char **argv)
 #endif
        printf(" [-d delay] (writer period (us))");
        printf(" [-c duration] (reader C.S. duration (in loops))");
+       printf(" [-e duration] (writer C.S. duration (in loops))");
        printf(" [-v] (verbose output)");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
@@ -375,6 +396,13 @@ int main(int argc, char **argv)
                        }
                        wdelay = atol(argv[++i]);
                        break;
+               case 'e':
+                       if (argc < i + 2) {
+                               show_usage(argc, argv);
+                               return -1;
+                       }
+                       wduration = atol(argv[++i]);
+                       break;
                case 'v':
                        verbose_mode = 1;
                        break;
@@ -394,9 +422,9 @@ int main(int argc, char **argv)
        tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers);
        pending_reclaims = malloc(sizeof(*pending_reclaims) * nr_writers);
        if (reclaim_batch * sizeof(*pending_reclaims[i].queue)
-                       < CACHE_LINE_SIZE)
+                       < CAA_CACHE_LINE_SIZE)
                for (i = 0; i < nr_writers; i++)
-                       pending_reclaims[i].queue = calloc(1, CACHE_LINE_SIZE);
+                       pending_reclaims[i].queue = calloc(1, CAA_CACHE_LINE_SIZE);
        else
                for (i = 0; i < nr_writers; i++)
                        pending_reclaims[i].queue = calloc(reclaim_batch,
@@ -419,7 +447,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       smp_mb();
+       cmm_smp_mb();
 
        test_go = 1;
 
@@ -443,11 +471,11 @@ int main(int argc, char **argv)
        
        printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,
               tot_writes);
-       printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu "
+       printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu "
                "nr_writers %3u "
                "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu "
                "batch %u\n",
-               argv[0], duration, nr_readers, rduration,
+               argv[0], duration, nr_readers, rduration, wduration,
                nr_writers, wdelay, tot_reads, tot_writes,
                tot_reads + tot_writes, reclaim_batch);
        free(tid_reader);
This page took 0.025128 seconds and 4 git commands to generate.