From nobody Wed Nov 5 09:27:46 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 1534483361923646.9923228514923; Thu, 16 Aug 2018 22:22:41 -0700 (PDT) Received: from localhost ([::1]:60002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqXDc-0004pU-OF for importer@patchew.org; Fri, 17 Aug 2018 01:22:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqXA8-0000dB-On for qemu-devel@nongnu.org; Fri, 17 Aug 2018 01:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqXA5-0005Z1-FM for qemu-devel@nongnu.org; Fri, 17 Aug 2018 01:19:04 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:59001) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fqXA3-0005Vo-Dt for qemu-devel@nongnu.org; Fri, 17 Aug 2018 01:18:59 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 72C7021E50; Fri, 17 Aug 2018 01:18:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 17 Aug 2018 01:18:57 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 292811029A; Fri, 17 Aug 2018 01:18:57 -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=nubas8S5NqCwjV a0jdcbbyEEBN9414KFvbYG/dDcJgI=; b=o1Q65WqPi61hfdng/uU/fXSeGYyrX/ vrcUaXWKpxSPz9MNXpGtDFtZ5llYrh3j4veb9FIl/R/U3y4jcve5bD1zEJkh7mXP 3w/V3IZkjHh6l75H41o/TGNRbPqNa8z9IhycWVvrZbhU41MkIVNYwmPChzoCONDJ dkU/HhpQ72BMk= 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=nubas8S5NqCwjVa0jdcbbyEEBN9414KFvbYG/dDcJgI=; b=mlKvtwhs 6IcaSZmGmdsLyQs6o///Jbgv/UfUy9aUCTCKqzxGtqlmsCS5dHduuvRe7xdvgEZf T1HwwpnS/EVPMGddnVp7dNcqmdK9adadBxJ0RsORPmRx9OfQOzep2VPLnTr2gmhz w+43CN93oZkjiH4Wz932EX+OBXZrnxtrda9Bb+iOhNbQYFOKljNFwyQ9c0mbLpPq KyAyI/x8L9ZXNLg9ecCghUIYgDq/RrkOjtFPL0/iz49hQmyje1TYrH7XwaKAbmGv RgACvt2dvoumrqAyOgxrjiwAq0kBfbcM0hd46FKJshGjWBq7mGlMNCePQsapXf3y OS1irBh3Fv5bNg== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Fri, 17 Aug 2018 01:18:49 -0400 Message-Id: <20180817051853.23792-6-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180817051853.23792-1-cota@braap.org> References: <20180817051853.23792-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 5/9] qsp: track BQL callers explicitly 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: Fam Zheng , Peter Crosthwaite , Stefan Weil , "Dr. David Alan Gilbert" , Peter Xu , Markus Armbruster , Paolo Bonzini , 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" The BQL is acquired via qemu_mutex_lock_iothread(), which makes the profiler assign the associated wait time (i.e. most of BQL wait time) entirely to that function. This loses the original call site information, which does not help diagnose BQL contention. Fix it by tracking the callers explicitly. Signed-off-by: Emilio G. Cota --- include/qemu/main-loop.h | 4 +++- include/qemu/thread.h | 1 + cpus.c | 10 ++++++++-- stubs/iothread-lock.c | 2 +- util/qsp.c | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 721aa2416a..e59f9ae1e9 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -276,7 +276,9 @@ bool qemu_mutex_iothread_locked(void); * NOTE: tools currently are single-threaded and qemu_mutex_lock_iothread * is a no-op there. */ -void qemu_mutex_lock_iothread(void); +#define qemu_mutex_lock_iothread() \ + qemu_mutex_lock_iothread_impl(__FILE__, __LINE__) +void qemu_mutex_lock_iothread_impl(const char *file, int line); =20 /** * qemu_mutex_unlock_iothread: Unlock the main loop mutex. diff --git a/include/qemu/thread.h b/include/qemu/thread.h index ab508df3cd..b41c0ae16a 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -35,6 +35,7 @@ typedef int (*QemuRecMutexTrylockFunc)(QemuRecMutex *m, c= onst char *f, int l); typedef void (*QemuCondWaitFunc)(QemuCond *c, QemuMutex *m, const char *f, int l); =20 +extern QemuMutexLockFunc qemu_bql_mutex_lock_func; extern QemuMutexLockFunc qemu_mutex_lock_func; extern QemuMutexTrylockFunc qemu_mutex_trylock_func; extern QemuRecMutexLockFunc qemu_rec_mutex_lock_func; diff --git a/cpus.c b/cpus.c index b5844b7103..a5ea3eef80 100644 --- a/cpus.c +++ b/cpus.c @@ -1762,10 +1762,16 @@ bool qemu_mutex_iothread_locked(void) return iothread_locked; } =20 -void qemu_mutex_lock_iothread(void) +/* + * The BQL is taken from so many places that it is worth profiling the + * callers directly, instead of funneling them all through a single functi= on. + */ +void qemu_mutex_lock_iothread_impl(const char *file, int line) { + QemuMutexLockFunc bql_lock =3D atomic_read(&qemu_bql_mutex_lock_func); + g_assert(!qemu_mutex_iothread_locked()); - qemu_mutex_lock(&qemu_global_mutex); + bql_lock(&qemu_global_mutex, file, line); iothread_locked =3D true; } =20 diff --git a/stubs/iothread-lock.c b/stubs/iothread-lock.c index 9b6db2e740..eb745d7d6a 100644 --- a/stubs/iothread-lock.c +++ b/stubs/iothread-lock.c @@ -7,7 +7,7 @@ bool qemu_mutex_iothread_locked(void) return true; } =20 -void qemu_mutex_lock_iothread(void) +void qemu_mutex_lock_iothread_impl(const char *file, int line) { } =20 diff --git a/util/qsp.c b/util/qsp.c index ea128d3748..65d9d8f0d6 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -65,6 +65,7 @@ =20 enum QSPType { QSP_MUTEX, + QSP_BQL_MUTEX, QSP_REC_MUTEX, QSP_CONDVAR, }; @@ -116,10 +117,12 @@ static bool qsp_initialized, qsp_initializing; =20 static const char * const qsp_typenames[] =3D { [QSP_MUTEX] =3D "mutex", + [QSP_BQL_MUTEX] =3D "BQL mutex", [QSP_REC_MUTEX] =3D "rec_mutex", [QSP_CONDVAR] =3D "condvar", }; =20 +QemuMutexLockFunc qemu_bql_mutex_lock_func =3D qemu_mutex_lock_impl; QemuMutexLockFunc qemu_mutex_lock_func =3D qemu_mutex_lock_impl; QemuMutexTrylockFunc qemu_mutex_trylock_func =3D qemu_mutex_trylock_impl; QemuRecMutexLockFunc qemu_rec_mutex_lock_func =3D qemu_rec_mutex_lock_impl; @@ -368,6 +371,7 @@ static QSPEntry *qsp_entry_get(const void *obj, const c= har *file, int line, return err; \ } =20 +QSP_GEN_VOID(QemuMutex, QSP_BQL_MUTEX, qsp_bql_mutex_lock, qemu_mutex_lock= _impl) QSP_GEN_VOID(QemuMutex, QSP_MUTEX, qsp_mutex_lock, qemu_mutex_lock_impl) QSP_GEN_RET1(QemuMutex, QSP_MUTEX, qsp_mutex_trylock, qemu_mutex_trylock_i= mpl) =20 @@ -403,6 +407,7 @@ void qsp_enable(void) { atomic_set(&qemu_mutex_lock_func, qsp_mutex_lock); atomic_set(&qemu_mutex_trylock_func, qsp_mutex_trylock); + atomic_set(&qemu_bql_mutex_lock_func, qsp_bql_mutex_lock); atomic_set(&qemu_rec_mutex_lock_func, qsp_rec_mutex_lock); atomic_set(&qemu_rec_mutex_trylock_func, qsp_rec_mutex_trylock); atomic_set(&qemu_cond_wait_func, qsp_cond_wait); @@ -412,6 +417,7 @@ void qsp_disable(void) { atomic_set(&qemu_mutex_lock_func, qemu_mutex_lock_impl); atomic_set(&qemu_mutex_trylock_func, qemu_mutex_trylock_impl); + atomic_set(&qemu_bql_mutex_lock_func, qemu_mutex_lock_impl); atomic_set(&qemu_rec_mutex_lock_func, qemu_rec_mutex_lock_impl); atomic_set(&qemu_rec_mutex_trylock_func, qemu_rec_mutex_trylock_impl); atomic_set(&qemu_cond_wait_func, qemu_cond_wait_impl); --=20 2.17.1