From patchwork Sat Mar 21 15:34:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 452950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C239A1400DE for ; Sun, 22 Mar 2015 02:35:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=HU4Upjyn; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost ([::1]:48128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YZLQq-0000zL-8V for incoming@patchwork.ozlabs.org; Sat, 21 Mar 2015 11:35:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YZLQY-0000g0-Lv for qemu-devel@nongnu.org; Sat, 21 Mar 2015 11:35:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YZLQT-0006gc-NV for qemu-devel@nongnu.org; Sat, 21 Mar 2015 11:35:06 -0400 Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:36570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YZLQT-0006fo-IE for qemu-devel@nongnu.org; Sat, 21 Mar 2015 11:35:01 -0400 Received: by wgra20 with SMTP id a20so112250983wgr.3 for ; Sat, 21 Mar 2015 08:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=7I992qoqCa+T6pzJ0fQ1mWyGjA/MxK1sOx32hxboofw=; b=HU4Upjyn+clS1Qbd+uhZvBl3pdly0OvKDymfXnQNLormtDexYdcL6tLkr6taWEP7GS 6/etDY3dZ6kAZ1MCPBOSIdyHxmyhHExhCExRVpe40oBhCcWfjblfj1p7gmJiVk/S0C18 ZCNSi6+dQrMyeqHqh1CXEBXGHKrNrikmql/hL1iAyXELELaNl3Qu4DdVaP4ZqHihmv4W +wQ6K3D+/9OjtiXgjz4dwYMFyZvyMO/c5eFBWNseRhZAUqquNDbMLNfECvyQqFKVXAcO oboWHZUstGGPavJ4VTjvlHJU42snH+MJmqe9wjRmqNVWvpl73OvAao9PivUQJQ8oZ3Q5 n5SQ== X-Received: by 10.180.106.70 with SMTP id gs6mr5012115wib.48.1426952100982; Sat, 21 Mar 2015 08:35:00 -0700 (PDT) Received: from donizetti.station (net-93-66-123-41.cust.vodafonedsl.it. [93.66.123.41]) by mx.google.com with ESMTPSA id b4sm2875148wic.2.2015.03.21.08.34.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2015 08:34:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 21 Mar 2015 16:34:51 +0100 Message-Id: <1426952091-18019-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.3.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::236 Cc: afaerber@suse.de Subject: [Qemu-devel] [PATCH] rcutorture: fix compilation on 32-bit ppc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 one exception in rcu_read_stress_test: fix it to use the same technique. 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. Reported-by: Andreas Faerber Signed-off-by: Paolo Bonzini Tested-by: Andreas Färber --- tests/rcutorture.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/rcutorture.c b/tests/rcutorture.c index 60a2ccf..d6b304d 100644 --- a/tests/rcutorture.c +++ b/tests/rcutorture.c @@ -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()) {