From nobody Tue Nov 4 15:26:23 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 1530217172085221.35186434593038; Thu, 28 Jun 2018 13:19:32 -0700 (PDT) Received: from localhost ([::1]:38349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdO5-0001n4-Ao for importer@patchew.org; Thu, 28 Jun 2018 16:19:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAW-00079f-Cx for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAU-0000HF-Sn for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:28 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:55461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAU-0000Fy-KB for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:26 -0400 Received: by mail-wm0-x22c.google.com with SMTP id v16-v6so11054850wmv.5 for ; Thu, 28 Jun 2018 13:05:26 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.05.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05:24 -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=/EzWCZymR/XFULCXrJs5I7W2DDvAnvZnLfMZIlUNdtk=; b=TDiCx7tSv7A4Rpk3NQ/YotCJf66VHNPmIRSilynVIj3pO8Gh5teSvmfXojNQSTKZ6s B6ac0V6sA3K/XJdJ3Qb8JHY2xzga7D9MbS+xBc8Dl11kdTOQfcvuUkN43Ci62XrpgBRS SdYkXQJlnG6oGz0kW0DTMyeJ2uqxrMXdOmvIVWaPctL2tkerECyP640nxHUQNgFA2XZ9 ZglRyMBcm9GtmaCJntgFfBscCj+yQsbSXSFTL3FkIC1qNwponkg54etB7OArGVysDkmh mpwarPWTPKpFEYC7wewuKGnxe3j/9n/NGxtYt3msJ+aqXCDu6zlp6OAKz6b8AZNDLl3z us4w== 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=/EzWCZymR/XFULCXrJs5I7W2DDvAnvZnLfMZIlUNdtk=; b=T7qajv+vZ/zIO9EyGWqcydo+ynyP+rvp0YW/Fg2nj2tFR109JtFjJgA2oBeAk7Tgul oA8ECq1XqMfxTDn6fBdwMPXkdb0VVOuaAZ7IBGBPjQyRaxaLs290q8+Ugalr09fPzz64 xH4i3y93tOtiDKg43T7qSJm3x4eP++HSwxx2zfdFcj4WPUXrqAfoBFanPF80DHR7RpKa fF/mPHDbS/m1K6+5pfGtkfZJRudN0eN7V2qrdCI+d9VkB+Mx1pefPud6nw097ZmNBSca kS903/o8IVY0Uay3qnz58zzz/t8TzypTeqWqpK9eXkvQEsEebWiBCRffE9X39z40FCox 1Naw== X-Gm-Message-State: APt69E1fkRU1VcOyWEWdsa+Q2VKjoxA4vW9Zd/CC8rUpibLvfYVGBz+w gN+QhE9TIQeWxDdqGRFlMb5sYbPH X-Google-Smtp-Source: AAOMgpeePwHU3Ax188c7Zx1FkxByBNote2NKcfbk9IZBEgUjjMwys1iMQ/82dL9en6ULrYBt2M8+dA== X-Received: by 2002:a1c:84d0:: with SMTP id g199-v6mr9959265wmd.90.1530216325258; Thu, 28 Jun 2018 13:05:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:21 +0200 Message-Id: <1530216310-52873-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-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:400c:c09::22c Subject: [Qemu-devel] [PULL 11/60] 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: "Emilio G. Cota" , Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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" 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 Message-Id: <20180425025459.5258-2-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- 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 caa1e8e..f96d448 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 1.8.3.1