Skip to contentSkip to conversation

rcu tests: fix compilation on 32-bit ppc

PATCH Superseded Paolo Bonzini 2 participants 2 messages Mar 21, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rcu tests: fix compilation on 32-bit ppc

32-bit PPC cannot do atomic operations on long long. Inside the loops, we are already using local counters that are summed at the end of the run---with some exceptions (rcu_stress_count for rcutorture, n_nodes for test-rcu-list): fix them to use the same technique. For test-rcu-list, remove the mostly unused member "val" from the list. Then, use a mutex to protect the global counts.

Performance does not matter there because every thread will only enter the critical section once.

Remaining uses of atomic instructions are for ints or pointers.

---
 tests/rcutorture.c    | 20 ++++++++++++++++----
 tests/test-rcu-list.c | 42 ++++++++++++++++++++++--------------------
 2 files changed, 38 insertions(+), 24 deletions(-)
tests/rcutorture.c +16 -4
index 60a2ccf..d6b304d 100644
@@ -82,6 +82,7 @@ static volatile int goflag = GOFLAG_INIT;
 #define RCU_READ_RUN 1000
 
 #define NR_THREADS 100
+static QemuMutex counts_mutex;
 static QemuThread threads[NR_THREADS];
 static struct rcu_reader_data *data[NR_THREADS];
 static int n_threads;
@@ -130,7 +131,9 @@ static void *rcu_read_perf_test(void *arg)
         }
         n_reads_local += RCU_READ_RUN;
     }
-    atomic_add(&n_reads, n_reads_local);
+    qemu_mutex_lock(&counts_mutex);
+    n_reads += n_reads_local;
+    qemu_mutex_unlock(&counts_mutex);
 
     rcu_unregister_thread();
     return NULL;
@@ -151,7 +154,9 @@ static void *rcu_update_perf_test(void *arg)
         synchronize_rcu();
         n_updates_local++;
     }
-    atomic_add(&n_updates, n_updates_local);
+    qemu_mutex_lock(&counts_mutex);
+    n_updates += n_updates_local;
+    qemu_mutex_unlock(&counts_mutex);
 
     rcu_unregister_thread();
     return NULL;
@@ -241,6 +246,7 @@ static void *rcu_read_stress_test(void *arg)
     struct rcu_stress *p;
     int pc;
     long long n_reads_local = 0;
+    long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] = { 0 };
     volatile int garbage = 0;
 
     rcu_register_thread();
@@ -265,13 +271,18 @@ static void *rcu_read_stress_test(void *arg)
         if ((pc > RCU_STRESS_PIPE_LEN) || (pc < 0)) {
             pc = RCU_STRESS_PIPE_LEN;
         }
-        atomic_inc(&rcu_stress_count[pc]);
+        rcu_stress_local[pc]++;
         n_reads_local++;
         if ((++itercnt % 0x1000) == 0) {
             synchronize_rcu();
         }
     }
-    atomic_add(&n_reads, n_reads_local);
+    qemu_mutex_lock(&counts_mutex);
+    n_reads += n_reads_local;
+    for (i = 0; i <= RCU_STRESS_PIPE_LEN; i++) {
+        rcu_stress_count[i] += rcu_stress_local[i];
+    }
+    qemu_mutex_unlock(&counts_mutex);
 
     rcu_unregister_thread();
     return NULL;
@@ -419,6 +430,7 @@ int main(int argc, char *argv[])
     int nreaders = 1;
     int duration = 1;
 
+    qemu_mutex_init(&counts_mutex);
     if (argc >= 2 && argv[1][0] == '-') {
         g_test_init(&argc, &argv, NULL);
         if (g_test_quick()) {
tests/test-rcu-list.c +22 -20

109 lines not on this page · raw message

Signature · 1 line
2.3.3
#1 lore raw

Am 21.03.2015 um 19:13 schrieb Paolo Bonzini:

Quoted 10 lines

32-bit PPC cannot do atomic operations on long long. Inside the loops, we are already using local counters that are summed at the end of the run---with some exceptions (rcu_stress_count for rcutorture, n_nodes for test-rcu-list): fix them to use the same technique. For test-rcu-list, remove the mostly unused member "val" from the list. Then, use a mutex to protect the global counts.

Performance does not matter there because every thread will only enter the critical section once.

Quoted 8 lines

Remaining uses of atomic instructions are for ints or pointers.

---
 tests/rcutorture.c    | 20 ++++++++++++++++----
 tests/test-rcu-list.c | 42 ++++++++++++++++++++++--------------------
 2 files changed, 38 insertions(+), 24 deletions(-)

Still two errors in test-rcu-list:

[ 1365s] tests/test-rcu-list.o: In function `rcu_qtest_init':
[ 1365s] /home/abuild/rpmbuild/BUILD/qemu-2.3.0-rc0/tests/test-rcu-list.c:201:
undefined reference to `__sync_fetch_and_add_8'
[ 1365s] tests/test-rcu-list.o: In function `rcu_qtest':
[ 1365s] /home/abuild/rpmbuild/BUILD/qemu-2.3.0-rc0/tests/test-rcu-list.c:237:
undefined reference to `__sync_fetch_and_add_8'
[ 1365s] collect2: error: ld returned 1 exit status
[ 1365s] make: *** [tests/test-rcu-list] Error 1

https://build.opensuse.org/package/live_build_log/home:a_faerber:branches:Virtualization/qemu/openSUSE_13.1/ppc

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)