From nobody Sun Feb 8 20:59:51 2026 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; 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 1524545610791127.85318109594016; Mon, 23 Apr 2018 21:53:30 -0700 (PDT) Received: from localhost ([::1]:56508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fApxE-0002pE-2M for importer@patchew.org; Tue, 24 Apr 2018 00:53:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fApvT-00020x-OC for qemu-devel@nongnu.org; Tue, 24 Apr 2018 00:51:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fApvP-0006Um-PZ for qemu-devel@nongnu.org; Tue, 24 Apr 2018 00:51:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60898 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fApvP-0006UR-KY for qemu-devel@nongnu.org; Tue, 24 Apr 2018 00:51:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7410F40201A1; Tue, 24 Apr 2018 04:51:30 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFA6E1134CD3; Tue, 24 Apr 2018 04:51:27 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 24 Apr 2018 12:51:09 +0800 Message-Id: <20180424045112.12963-2-peterx@redhat.com> In-Reply-To: <20180424045112.12963-1-peterx@redhat.com> References: <20180424045112.12963-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 24 Apr 2018 04:51:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 24 Apr 2018 04:51:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v5 1/4] tests/atomic_add-bench: add -m option to use mutexes 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: Paolo Bonzini , "Emilio G . Cota" , Fam Zheng , peterx@redhat.com, Stefan Hajnoczi 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" From: "Emilio G. Cota" This allows us to use atomic-add-bench as a microbenchmark for evaluating qemu_mutex_lock's performance. Signed-off-by: Emilio G. Cota [cherry picked from https://github.com/cota/qemu/commit/f04f34df] Signed-off-by: Peter Xu --- tests/atomic_add-bench.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/atomic_add-bench.c b/tests/atomic_add-bench.c index caa1e8e689..f96d448f77 100644 --- a/tests/atomic_add-bench.c +++ b/tests/atomic_add-bench.c @@ -8,6 +8,7 @@ struct thread_info { } QEMU_ALIGNED(64); =20 struct count { + QemuMutex lock; unsigned long val; } QEMU_ALIGNED(64); =20 @@ -18,11 +19,13 @@ static unsigned int n_ready_threads; static struct count *counts; static unsigned int duration =3D 1; static unsigned int range =3D 1024; +static bool use_mutex; static bool test_start; static bool test_stop; =20 static const char commands_string[] =3D " -n =3D number of threads\n" + " -m =3D use mutexes instead of atomic increments\n" " -d =3D duration in seconds\n" " -r =3D range (will be rounded up to pow2)"; =20 @@ -59,7 +62,13 @@ static void *thread_func(void *arg) =20 info->r =3D xorshift64star(info->r); index =3D info->r & (range - 1); - atomic_inc(&counts[index].val); + if (use_mutex) { + qemu_mutex_lock(&counts[index].lock); + counts[index].val +=3D 1; + qemu_mutex_unlock(&counts[index].lock); + } else { + atomic_inc(&counts[index].val); + } } return NULL; } @@ -91,6 +100,9 @@ static void create_threads(void) th_info =3D g_new(struct thread_info, n_threads); counts =3D qemu_memalign(64, sizeof(*counts) * range); memset(counts, 0, sizeof(*counts) * range); + for (i =3D 0; i < range; i++) { + qemu_mutex_init(&counts[i].lock); + } =20 for (i =3D 0; i < n_threads; i++) { struct thread_info *info =3D &th_info[i]; @@ -131,7 +143,7 @@ static void parse_args(int argc, char *argv[]) int c; =20 for (;;) { - c =3D getopt(argc, argv, "hd:n:r:"); + c =3D getopt(argc, argv, "hd:n:mr:"); if (c < 0) { break; } @@ -145,6 +157,9 @@ static void parse_args(int argc, char *argv[]) case 'n': n_threads =3D atoi(optarg); break; + case 'm': + use_mutex =3D true; + break; case 'r': range =3D pow2ceil(atoi(optarg)); break; --=20 2.14.3