From nobody Thu Nov 6 01:09:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538296262954169.9090224393516; Sun, 30 Sep 2018 01:31:02 -0700 (PDT) Received: from localhost ([::1]:54300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6X81-0001CH-N1 for importer@patchew.org; Sun, 30 Sep 2018 04:31:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WrA-000281-Bf for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6Wr7-0008VV-0J for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:36 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:45645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6Wr5-0008Nh-1C for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:31 -0400 Received: by mail-wr1-x430.google.com with SMTP id q5-v6so3999799wrw.12 for ; Sun, 30 Sep 2018 01:13:29 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=34rE4OlENNXoK8jxGS/GuyvAAu491DOuy8TDuDC3ThA=; b=ROCZodR5teNyqGGuNUdlrR29wpJvPriZP1EO10htoxumYh9joO4K3/TC3WnZOlZWZ2 9CHwIggN/Tcs5QVcb3wu8Q2RjUhp2hx4t9ZeIsvSsS4PcqKRGreAL80AlLlGwrYRUN/2 uZAbynBkUGENYKfPZLd1c2KQQamobdgrAvU4TLaecz0GUBOC9yWtQ9DdjsYBoNmZVOxA Z9NX7fKtYHB0FEICYc423MZ64ZIRveLmwtCn64wvI5IKfDEuhA2V9E5ykprkyB2fPTDP mPuhPtVGrjLg5Fw48Q3cJjy/39uxnkq3m67s2Z2kefbcFXNLKWgWprjEwpQmd+75Yu3s mG6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=34rE4OlENNXoK8jxGS/GuyvAAu491DOuy8TDuDC3ThA=; b=I90YFGBtJwHOgJs6HDbSGLbPPYBtD4/+20m9Zq5oaEwokTq7PAAU/56MbqvF7XT2AC VG6Q1Ng4UEa7wswZVtsLQg2iysxabz1ufGc0nJ8Hba6wkIRxHbLY5UOOdFSRaIT+JIU8 X55Em72NvxJqfcK5NLhqCrBSdqsFCDrsbcH0RqCdJORK3sqcpL70fWsW/c1ZTCT70jh2 oi78v92Ogkk7cJFfmNBCV9Hi6FSwd2WXoP5k+a2QAwQ79ib2fa50cNUf0rihcq9M1n5E JJ2NGlrCOCg+iqvk1wIOHhg93lh520S41RdswOHHLHWUwb1T/x90Z/FoJ1rq5t38kEHg xs2Q== X-Gm-Message-State: ABuFfojxdznFuodyNyL3R5FQvkuc2W5JqiwxTTIT6sBV06tp4bRmp7Eo OAJskaxww4wr93TJ+kAWaeXr9cfY X-Google-Smtp-Source: ACcGV62JNZZzwvAiXiokO7ZrpGDQJPIuD+iLWy7TaHf7s5D/wnx+U02mYu2rlSQnVLIodYcXYDJuLA== X-Received: by 2002:adf:db8e:: with SMTP id u14-v6mr3883214wri.217.1538295207905; Sun, 30 Sep 2018 01:13:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:07 +0200 Message-Id: <1538295197-23704-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 Subject: [Qemu-devel] [PULL 09/79] tests: add atomic64-bench X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" - With CONFIG_ATOMIC64: $ tests/atomic64-bench -n 1 Throughput: 310.40 Mops/s - Without: $ tests/atomic64-bench -n 1 Throughput: 149.08 Mops/s Signed-off-by: Emilio G. Cota Message-Id: <20180910232752.31565-4-cota@braap.org> Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/atomic64-bench.c | 171 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/atomic64-bench.c diff --git a/tests/Makefile.include b/tests/Makefile.include index d0c0a92..175d013 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -613,7 +613,7 @@ test-obj-y =3D tests/check-qnum.o tests/check-qstring.o= tests/check-qdict.o \ tests/test-rcu-tailq.o \ tests/test-qdist.o tests/test-shift128.o \ tests/test-qht.o tests/qht-bench.o tests/test-qht-par.o \ - tests/atomic_add-bench.o + tests/atomic_add-bench.o tests/atomic64-bench.o =20 $(test-obj-y): QEMU_INCLUDES +=3D -Itests QEMU_CFLAGS +=3D -I$(SRC_PATH)/tests @@ -668,6 +668,7 @@ tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests= /qht-bench$(EXESUF) $(tes tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y) tests/test-bufferiszero$(EXESUF): tests/test-bufferiszero.o $(test-util-ob= j-y) tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o $(test-util-obj-= y) +tests/atomic64-bench$(EXESUF): tests/atomic64-bench.o $(test-util-obj-y) =20 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\ diff --git a/tests/atomic64-bench.c b/tests/atomic64-bench.c new file mode 100644 index 0000000..7169256 --- /dev/null +++ b/tests/atomic64-bench.c @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2018, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu/thread.h" +#include "qemu/host-utils.h" +#include "qemu/processor.h" + +struct thread_info { + uint64_t r; + uint64_t accesses; +} QEMU_ALIGNED(64); + +struct count { + int64_t i64; +} QEMU_ALIGNED(64); + +static QemuThread *threads; +static struct thread_info *th_info; +static unsigned int n_threads =3D 1; +static unsigned int n_ready_threads; +static struct count *counts; +static unsigned int duration =3D 1; +static unsigned int range =3D 1024; +static bool test_start; +static bool test_stop; + +static const char commands_string[] =3D + " -d =3D duration in seconds\n" + " -n =3D number of threads\n" + " -r =3D range (will be rounded up to pow2)"; + +static void usage_complete(char *argv[]) +{ + fprintf(stderr, "Usage: %s [options]\n", argv[0]); + fprintf(stderr, "options:\n%s\n", commands_string); +} + +/* + * From: https://en.wikipedia.org/wiki/Xorshift + * This is faster than rand_r(), and gives us a wider range (RAND_MAX is o= nly + * guaranteed to be >=3D INT_MAX). + */ +static uint64_t xorshift64star(uint64_t x) +{ + x ^=3D x >> 12; /* a */ + x ^=3D x << 25; /* b */ + x ^=3D x >> 27; /* c */ + return x * UINT64_C(2685821657736338717); +} + +static void *thread_func(void *arg) +{ + struct thread_info *info =3D arg; + + atomic_inc(&n_ready_threads); + while (!atomic_read(&test_start)) { + cpu_relax(); + } + + while (!atomic_read(&test_stop)) { + unsigned int index; + + info->r =3D xorshift64star(info->r); + index =3D info->r & (range - 1); + atomic_read_i64(&counts[index].i64); + info->accesses++; + } + return NULL; +} + +static void run_test(void) +{ + unsigned int remaining; + unsigned int i; + + while (atomic_read(&n_ready_threads) !=3D n_threads) { + cpu_relax(); + } + atomic_set(&test_start, true); + do { + remaining =3D sleep(duration); + } while (remaining); + atomic_set(&test_stop, true); + + for (i =3D 0; i < n_threads; i++) { + qemu_thread_join(&threads[i]); + } +} + +static void create_threads(void) +{ + unsigned int i; + + threads =3D g_new(QemuThread, n_threads); + th_info =3D g_new(struct thread_info, n_threads); + counts =3D g_malloc0_n(range, sizeof(*counts)); + + for (i =3D 0; i < n_threads; i++) { + struct thread_info *info =3D &th_info[i]; + + info->r =3D (i + 1) ^ time(NULL); + info->accesses =3D 0; + qemu_thread_create(&threads[i], NULL, thread_func, info, + QEMU_THREAD_JOINABLE); + } +} + +static void pr_params(void) +{ + printf("Parameters:\n"); + printf(" # of threads: %u\n", n_threads); + printf(" duration: %u\n", duration); + printf(" ops' range: %u\n", range); +} + +static void pr_stats(void) +{ + unsigned long long val =3D 0; + double tx; + int i; + + for (i =3D 0; i < n_threads; i++) { + val +=3D th_info[i].accesses; + } + tx =3D val / duration / 1e6; + + printf("Results:\n"); + printf("Duration: %u s\n", duration); + printf(" Throughput: %.2f Mops/s\n", tx); + printf(" Throughput/thread: %.2f Mops/s/thread\n", tx / n_threads); +} + +static void parse_args(int argc, char *argv[]) +{ + int c; + + for (;;) { + c =3D getopt(argc, argv, "hd:n:r:"); + if (c < 0) { + break; + } + switch (c) { + case 'h': + usage_complete(argv); + exit(0); + case 'd': + duration =3D atoi(optarg); + break; + case 'n': + n_threads =3D atoi(optarg); + break; + case 'r': + range =3D pow2ceil(atoi(optarg)); + break; + } + } +} + +int main(int argc, char *argv[]) +{ + parse_args(argc, argv); + pr_params(); + create_threads(); + run_test(); + pr_stats(); + return 0; +} --=20 1.8.3.1