From nobody Wed Nov 5 20:17:20 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536623121440405.6639961872048; Mon, 10 Sep 2018 16:45:21 -0700 (PDT) Received: from localhost ([::1]:54640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVrs-0004Fb-7S for importer@patchew.org; Mon, 10 Sep 2018 19:45:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVjt-0003bp-7o for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:37:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzVbR-0005Io-W5 for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:25 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39037) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzVbR-0005HY-MO for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:21 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BBA7721E1C; Mon, 10 Sep 2018 19:28:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 10 Sep 2018 19:28:20 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 57C60E4937; Mon, 10 Sep 2018 19:28:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=eDLkbIBb07flMi YHltLd7aPJ9J9hNogQKc+TRQIvSGM=; b=JCG7rHID+qtG3Gvf0NaOX/ZbCfYCcU qLx2D9AVbpK7DX2r+/GXd0pR02xJW1Y65yeobUZoC4lI3hpmla5AHNHrKUVS+Hu9 U+l3c0QCqkXHggN0bylSIpDc1XbVrgjzqnO8oxVU823Z36csTrlH96j9b9fZOJpX XfInMA6zx7PjM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=eDLkbIBb07flMiYHltLd7aPJ9J9hNogQKc+TRQIvSGM=; b=bTj5o133 1DBik46HAoZuvHNg3Ysn1ojp9FVQ+J1aQMBJetlDnQ+PaIAe0kr+PP+wDG2wnDXp 76UDA8NJd+4ZhEt+9P1Z2mkJQfzYulgsKP1e/1IanZLdh/oUSkPkKJYUsPtxxuMR B3qss7iW3Aihe6ZMWm6XoMIC+jrv+D5IfmruSxFIrj9eIQwLy8MS5iZLLjZvKlI3 Oe6/73vcVbb3rWZeROBVIg5clRueZNxU54wJE1kUqPiakbS8F3Ucb21P/TXBs67o Q8w34KeTpZ9G6SIAaoBD/DLXu70UK2gDGAUwb/Qi33G09cDjnz0gTH2Zdzpzeu5M /zTQxBHuRk7sEQ== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2018 19:27:43 -0400 Message-Id: <20180910232752.31565-4-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180910232752.31565-1-cota@braap.org> References: <20180910232752.31565-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 03/12] 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: Eduardo Habkost , Peter Crosthwaite , Murilo Opsfelder Araujo , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" - 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 --- tests/atomic64-bench.c | 171 +++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 3 +- 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/atomic64-bench.c diff --git a/tests/atomic64-bench.c b/tests/atomic64-bench.c new file mode 100644 index 0000000000..71692560ed --- /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; +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 87c81d1dcc..b12b6a867a 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -601,7 +601,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 @@ -656,6 +656,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\ --=20 2.17.1