From patchwork Fri Jul 31 15:54:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 51788 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id D19EA22E88 for ; Fri, 31 Jul 2015 15:57:06 +0000 (UTC) Received: by wibdx1 with SMTP id dx1sf7738319wib.2 for ; Fri, 31 Jul 2015 08:57:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding:cc :subject:precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=lPsVcPs0aigB3uKz3zQeChnj+7aNMzE0l5hRIixViBI=; b=KOs/QYu761C9vaxfHQubHqbVZ4bn4Iy7It5jwfXQ/l93FbzlL9NAE/xe2zbBW3GtKm hDSbCmDbdMGGRMYvi26v50p6hcBXIPCTwoW+6jnFUlmnFcT4gxod0j+j8kIDlOhU92RO JKOlricGh8RJeoLd0RzbfG4dqZhpRdBfp7WxtAOeHJu5EHQ4oMxM1BuKpHztU3CdTmhB 53Z6JQXCc1MukT4KIgBpuV2xjQ6fVw92u0iUhrhuURFL2FNY9CoLFh673Xe7BFIMwWBO rzAWzqRGckMfCCfuKz6l6RkPuNHe4//5AfMUN0vcv2cyY9PH70tow2yquAkMF5mHKrd0 gIoQ== X-Gm-Message-State: ALoCoQktURVV5264UCPUNWauGGchTfzWVh6mrE17Smgxy8rjGWyNMlTx8pUO6RbZwrVAsyG4kLOh X-Received: by 10.112.51.177 with SMTP id l17mr1155355lbo.1.1438358226077; Fri, 31 Jul 2015 08:57:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.197 with SMTP id g5ls333850lam.99.gmail; Fri, 31 Jul 2015 08:57:05 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr3737373laj.88.1438358225803; Fri, 31 Jul 2015 08:57:05 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id oh11si4129077lbc.65.2015.07.31.08.57.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 08:57:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbqc9 with SMTP id c9so23572443lbq.1 for ; Fri, 31 Jul 2015 08:57:05 -0700 (PDT) X-Received: by 10.152.4.163 with SMTP id l3mr3839283lal.35.1438358225559; Fri, 31 Jul 2015 08:57:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp473803lba; Fri, 31 Jul 2015 08:57:04 -0700 (PDT) X-Received: by 10.140.194.133 with SMTP id p127mr5678282qha.38.1438358223743; Fri, 31 Jul 2015 08:57:03 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c33si6362589qkh.20.2015.07.31.08.57.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 31 Jul 2015 08:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:44882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCgA-00058M-Tj for patch@linaro.org; Fri, 31 Jul 2015 11:57:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCdq-0000zC-4E for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLCdj-0005v9-2k for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:38 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:36642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCdi-0005uw-Pl for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:31 -0400 Received: by wicgj17 with SMTP id gj17so23709625wic.1 for ; Fri, 31 Jul 2015 08:54:30 -0700 (PDT) X-Received: by 10.194.142.146 with SMTP id rw18mr6929596wjb.110.1438358070091; Fri, 31 Jul 2015 08:54:30 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id r19sm5121694wib.7.2015.07.31.08.54.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 08:54:29 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 81C803E13D6; Fri, 31 Jul 2015 16:54:23 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, mark.burton@greensocs.com, fred.konrad@greensocs.com Date: Fri, 31 Jul 2015 16:54:01 +0100 Message-Id: <1438358041-18021-12-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438358041-18021-1-git-send-email-alex.bennee@linaro.org> References: <1438358041-18021-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.173 Cc: peter.maydell@linaro.org, drjones@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvm@vger.kernel.org, a.spyridakis@virtualopensystems.com, claudio.fontana@huawei.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [Qemu-devel] [kvm-unit-tests PATCH v5 11/11] new: arm/barrier-test for memory barriers 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Alex Bennée This test has been written mainly to stress multi-threaded TCG behaviour but will demonstrate failure by default on real hardware. The test takes the following parameters: - "lock" use GCC's locking semantics - "excl" use load/store exclusive semantics - "acqrel" use acquire/release semantics Currently excl/acqrel lock up on MTTCG Signed-off-by: Alex Bennée --- arm/barrier-test.c | 206 +++++++++++++++++++++++++++++++++++++++++++ config/config-arm-common.mak | 2 + 2 files changed, 208 insertions(+) create mode 100644 arm/barrier-test.c diff --git a/arm/barrier-test.c b/arm/barrier-test.c new file mode 100644 index 0000000..53d690b --- /dev/null +++ b/arm/barrier-test.c @@ -0,0 +1,206 @@ +#include +#include +#include +#include +#include + +#include + +#define MAX_CPUS 4 + +/* How many increments to do */ +static int increment_count = 10000000; + + +/* shared value, we use the alignment to ensure the global_lock value + * doesn't share a page */ +static unsigned int shared_value; + +/* PAGE_SIZE * uint32_t means we span several pages */ +static uint32_t memory_array[PAGE_SIZE]; + +__attribute__((aligned(PAGE_SIZE))) static unsigned int per_cpu_value[MAX_CPUS]; +__attribute__((aligned(PAGE_SIZE))) static cpumask_t smp_test_complete; +__attribute__((aligned(PAGE_SIZE))) static int global_lock; + +struct isaac_ctx prng_context[MAX_CPUS]; + +void (*inc_fn)(void); + +static void lock(int *lock_var) +{ + while (__sync_lock_test_and_set(lock_var, 1)); +} +static void unlock(int *lock_var) +{ + __sync_lock_release(lock_var); +} + +static void increment_shared(void) +{ + shared_value++; +} + +static void increment_shared_with_lock(void) +{ + lock(&global_lock); + shared_value++; + unlock(&global_lock); +} + +static void increment_shared_with_excl(void) +{ +#if defined (__LP64__) || defined (_LP64) + asm volatile( + "1: ldxr w0, [%[sptr]]\n" + " add w0, w0, #0x1\n" + " stxr w1, w0, [%[sptr]]\n" + " cbnz w1, 1b\n" + : /* out */ + : [sptr] "r" (&shared_value) /* in */ + : "w0", "w1", "cc"); +#else + asm volatile( + "1: ldrex r0, [%[sptr]]\n" + " add r0, r0, #0x1\n" + " strexeq r1, r0, [%[sptr]]\n" + " cmpeq r1, #0\n" + " bne 1b\n" + : /* out */ + : [sptr] "r" (&shared_value) /* in */ + : "r0", "r1", "cc"); +#endif +} + +static void increment_shared_with_acqrel(void) +{ +#if defined (__LP64__) || defined (_LP64) + asm volatile( + " ldar w0, [%[sptr]]\n" + " add w0, w0, #0x1\n" + " str w0, [%[sptr]]\n" + : /* out */ + : [sptr] "r" (&shared_value) /* in */ + : "w0"); +#else + /* ARMv7 has no acquire/release semantics but we + * can ensure the results of the write are propagated + * with the use of barriers. + */ + asm volatile( + "1: ldrex r0, [%[sptr]]\n" + " add r0, r0, #0x1\n" + " strexeq r1, r0, [%[sptr]]\n" + " cmpeq r1, #0\n" + " bne 1b\n" + " dmb\n" + : /* out */ + : [sptr] "r" (&shared_value) /* in */ + : "r0", "r1", "cc"); +#endif + +} + +/* The idea of this is just to generate some random load/store + * activity which may or may not race with an un-barried incremented + * of the shared counter + */ +static void shuffle_memory(int cpu) +{ + int i; + uint32_t lspat = isaac_next_uint32(&prng_context[cpu]); + uint32_t seq = isaac_next_uint32(&prng_context[cpu]); + int count = seq & 0x1f; + uint32_t val=0; + + seq >>= 5; + + for (i=0; i>= PAGE_SHIFT; + seq ^= lspat; + lspat >>= 1; + } + +} + +static void do_increment(void) +{ + int i; + int cpu = smp_processor_id(); + + printf("CPU%d online\n", cpu); + + for (i=0; i < increment_count; i++) { + per_cpu_value[cpu]++; + inc_fn(); + + shuffle_memory(cpu); + } + + printf("CPU%d: Done, %d incs\n", cpu, per_cpu_value[cpu]); + + cpumask_set_cpu(cpu, &smp_test_complete); + if (cpu != 0) + halt(); +} + +int main(int argc, char **argv) +{ + int cpu; + unsigned int i, sum = 0; + static const unsigned char seed[] = "myseed"; + + inc_fn = &increment_shared; + + isaac_init(&prng_context[0], &seed[0], sizeof(seed)); + + for (i=0; i