Delay reader in loops, not us
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Fri, 12 Jun 2009 17:51:20 +0000 (13:51 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Fri, 12 Jun 2009 17:51:20 +0000 (13:51 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
test_mutex.c
test_perthreadlock.c
test_qsbr.c
test_rwlock.c
test_urcu.c

index 29c840b284a3a8277edf4786d22d7c4ea4b584b7..6fd1746a1c03e35132cbdd34558befb97a5814a0 100644 (file)
@@ -71,9 +71,15 @@ static volatile struct test_array test_array = { 8 };
 
 static unsigned long duration;
 
-/* read-side C.S. duration, in us */
+/* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
 /*
  * returns 0 if test should end.
  */
@@ -134,7 +140,7 @@ void *thr_reader(void *data)
                pthread_mutex_lock(&lock);
                assert(test_array.a == 8);
                if (unlikely(rduration))
-                       usleep(rduration);
+                       loop_sleep(rduration);
                pthread_mutex_unlock(&lock);
                nr_reads++;
                if (unlikely(!test_duration_read()))
@@ -185,7 +191,7 @@ void show_usage(int argc, char **argv)
        printf(" [-r] [-w] (yield reader and/or writer)");
 #endif
        printf(" [-d delay] (writer period (us))");
-       printf(" [-c duration] (reader C.S. duration (us))");
+       printf(" [-c duration] (reader C.S. duration (in loops))");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
 }
index a2abb8df714c2e825aa31657032d46523135f6bf..0fc45d9e3b82e0ce1fb76046917ebce8174a2d8f 100644 (file)
@@ -75,9 +75,15 @@ static volatile struct test_array test_array = { 8 };
 
 static unsigned long duration;
 
-/* read-side C.S. duration, in us */
+/* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
 /*
  * returns 0 if test should end.
  */
@@ -138,7 +144,7 @@ void *thr_reader(void *data)
                pthread_mutex_lock(&per_thread_lock[tidx].lock);
                assert(test_array.a == 8);
                if (unlikely(rduration))
-                       usleep(rduration);
+                       loop_sleep(rduration);
                pthread_mutex_unlock(&per_thread_lock[tidx].lock);
                nr_reads++;
                if (unlikely(!test_duration_read()))
@@ -194,7 +200,7 @@ void show_usage(int argc, char **argv)
        printf(" [-r] [-w] (yield reader and/or writer)");
 #endif
        printf(" [-d delay] (writer period (us))");
-       printf(" [-c duration] (reader C.S. duration (us))");
+       printf(" [-c duration] (reader C.S. duration (in loops))");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
 }
index 7ff1aca9c7600994f5b2ad30d79d0ca7fd3a0e60..488c9041b1aae96d267aa6ea8e3ec4f027fc3032 100644 (file)
@@ -65,9 +65,15 @@ static struct test_array *test_rcu_pointer;
 
 static unsigned long duration;
 
-/* read-side C.S. duration, in us */
+/* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
 /*
  * returns 0 if test should end.
  */
@@ -168,7 +174,7 @@ void *thr_reader(void *_count)
                if (local_ptr)
                        assert(local_ptr->a == 8);
                if (unlikely(rduration))
-                       usleep(rduration);
+                       loop_sleep(rduration);
                _rcu_read_unlock();
                nr_reads++;
                /* QS each 1024 reads */
@@ -233,7 +239,7 @@ void show_usage(int argc, char **argv)
        printf(" [-r] [-w] (yield reader and/or writer)");
 #endif
        printf(" [-d delay] (writer period (us))");
-       printf(" [-c duration] (reader C.S. duration (us))");
+       printf(" [-c duration] (reader C.S. duration (in loops))");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
 }
index 4ec427b8be469e14f3f46b511b7d5744cc114d49..a6f31e31f1e7328de9a0dc2303c5591b2f2b41db 100644 (file)
@@ -71,9 +71,15 @@ static volatile struct test_array test_array = { 8 };
 
 static unsigned long duration;
 
-/* read-side C.S. duration, in us */
+/* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
 /*
  * returns 0 if test should end.
  */
@@ -131,7 +137,7 @@ void *thr_reader(void *_count)
                pthread_rwlock_rdlock(&lock);
                assert(test_array.a == 8);
                if (unlikely(rduration))
-                       usleep(rduration);
+                       loop_sleep(rduration);
                pthread_rwlock_unlock(&lock);
                nr_reads++;
                if (unlikely(!test_duration_read()))
@@ -182,7 +188,7 @@ void show_usage(int argc, char **argv)
        printf(" [-r] [-w] (yield reader and/or writer)");
 #endif
        printf(" [-d delay] (writer period (us))");
-       printf(" [-c duration] (reader C.S. duration (us))");
+       printf(" [-c duration] (reader C.S. duration (in loops))");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
 }
index 85f4a36ce8e1eb3a35a62854b916ff9b284ced50..fe469284ef1122f864ed9bb467ef49997cbb1afa 100644 (file)
@@ -69,9 +69,15 @@ static struct test_array *test_rcu_pointer;
 
 static unsigned long duration;
 
-/* read-side C.S. duration, in us */
+/* read-side C.S. duration, in loops */
 static unsigned long rduration;
 
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
 /*
  * returns 0 if test should end.
  */
@@ -172,7 +178,7 @@ void *thr_reader(void *_count)
                if (local_ptr)
                        assert(local_ptr->a == 8);
                if (unlikely(rduration))
-                       usleep(rduration);
+                       loop_sleep(rduration);
                rcu_read_unlock();
                nr_reads++;
                if (unlikely(!test_duration_read()))
@@ -234,7 +240,7 @@ void show_usage(int argc, char **argv)
        printf(" [-r] [-w] (yield reader and/or writer)");
 #endif
        printf(" [-d delay] (writer period (us))");
-       printf(" [-c duration] (reader C.S. duration (us))");
+       printf(" [-c duration] (reader C.S. duration (in loops))");
        printf(" [-a cpu#] [-a cpu#]... (affinity)");
        printf("\n");
 }
This page took 0.028659 seconds and 4 git commands to generate.