test rcuja: add ratio parameter
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 27 May 2013 17:39:25 +0000 (13:39 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 27 May 2013 17:39:25 +0000 (13:39 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_ja.c

index d973220ce7fb15f8a6644e83958f6f7573690201..bc976030ce26635c4ef2b39baa13a0a275d298d9 100644 (file)
@@ -71,6 +71,8 @@ DEFINE_URCU_TLS(unsigned long long, nr_reads);
 unsigned int nr_readers;
 unsigned int nr_writers;
 
+static unsigned int add_ratio = 50;
+
 static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 void set_affinity(void)
@@ -163,7 +165,7 @@ void show_usage(int argc, char **argv)
        printf("        [-v] (verbose output)\n");
        printf("        [-a cpu#] [-a cpu#]... (affinity)\n");
 printf("        [not -u nor -s] Add entries (supports redundant keys).\n");
-       printf("        [-i] Add only (no removal).\n");
+       printf("        [-r] Add ratio (in %% of add+removal).\n");
        printf("        [-k nr_nodes] Number of nodes to insert initially.\n");
        printf("        [-R offset] Lookup pool offset.\n");
        printf("        [-S offset] Write pool offset.\n");
@@ -631,6 +633,12 @@ void *test_ja_rw_thr_reader(void *_count)
        return ((void*)1);
 }
 
+static
+int is_add(void)
+{
+       return ((unsigned int) rand_r(&URCU_TLS(rand_lookup)) % 100) < add_ratio;
+}
+
 static
 void *test_ja_rw_thr_writer(void *_count)
 {
@@ -652,8 +660,8 @@ void *test_ja_rw_thr_writer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               if ((addremove == AR_ADD || add_only)
-                               || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) {
+               if ((addremove == AR_ADD)
+                               || (addremove == AR_RANDOM && is_add())) {
                        struct ja_test_node *node = malloc(sizeof(*node));
 
                        /* note: only inserting ulong keys */
@@ -906,8 +914,8 @@ int main(int argc, char **argv)
                case 'v':
                        verbose_mode = 1;
                        break;
-               case 'i':
-                       add_only = 1;
+               case 'r':
+                       add_ratio = atoi(argv[++i]);
                        break;
                case 'k':
                        init_populate = atol(argv[++i]);
@@ -946,8 +954,7 @@ int main(int argc, char **argv)
                duration, nr_readers, nr_writers);
        printf_verbose("Writer delay : %lu loops.\n", wdelay);
        printf_verbose("Reader duration : %lu loops.\n", rduration);
-       printf_verbose("Mode:%s.\n",
-               add_only ? " add only" : " add/delete");
+       printf_verbose("Add ratio: %u%%.\n", add_ratio);
        printf_verbose("Init pool size offset %lu size %lu.\n",
                init_pool_offset, init_pool_size);
        printf_verbose("Lookup pool size offset %lu size %lu.\n",
This page took 0.027051 seconds and 4 git commands to generate.