From nobody Mon Feb 9 02:23:14 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; 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 1534872442271748.147451094816; Tue, 21 Aug 2018 10:27:22 -0700 (PDT) Received: from localhost ([::1]:55066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsAR1-0000Xn-3y for importer@patchew.org; Tue, 21 Aug 2018 13:27:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsA4Q-0001kf-2x for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:03:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsA4H-0006Q6-0j for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:03:46 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:33121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsA48-0005zD-AQ for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:03:38 -0400 Received: by mail-wm0-x22c.google.com with SMTP id i134-v6so10056936wmf.0 for ; Tue, 21 Aug 2018 10:03:28 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id v6-v6sm2608955wmc.43.2018.08.21.10.03.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 10:03:26 -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=w41FUUYLEwT5OqPffinerT0RywsBFEH9Tebqv+ixdpo=; b=GRGrUn4fS7Q3cXav0uL5pTjlecoQVkhiF5BHwM+u7fw+iIoPwZkDUGKoUUdhCX02uM pB2mV6BenF8QTvfI/R3DI/LgbiHQmHehv/KQTjPXZ5mlLHKYgIw0v3draNQR23ZtOGY8 SL8851Ha4CEly0vv8xdYTt6upHZ8BTq4D5j/1A8E1JPWx6epvvyygKn6nw62YJ3xonWq 8liGWEOSQ261GhEqECfYhp17gx5Xkt55/b51AvQk3lJZnOqRd20ejCUfyRtTkKTBH/iW cMBWIJHZb7waGPnqX2nSqdv6c/QVNAODF/qdtq24ChmY1V1JympS3ylCskfklIZ34h6Q CAeA== 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=w41FUUYLEwT5OqPffinerT0RywsBFEH9Tebqv+ixdpo=; b=Y9YEqloIb7cQKv3qch2QfRc32u1Hy+YnXnrH68NiBq15depPv+fVl2SLh4u8REJQRc yVlimUjpXM4VJ6treMP0/magF3PdeIclnNUB9ay4ykuBW8AJur7yIlbwZMDspMsHu5Zx KU6iM8WR4IectEInZM6EsONjMs5t6k6y+z8lnSgX9XYT4tODLXpGxOFOzLNVeKwaYI3i P7DfUVoXQX2vRVJWs1kC3+Ggoq2fy0oQmAnJXCzBk6FDbAEXo0fwJfjgJsxWylDDLHvE MWBG7oOp6rVprdovQIH03fjDG57kq64H2i6Kecc7RorbBwxUMMDJ6Zyy6XEp5VZDE7w0 TTOg== X-Gm-Message-State: APzg51A/gjo/bPpwxO1t1cEuOeJ69AMAvc0f8q5mmXFBmWIPDLq3Gl/o YTf4LAVhG1AXnuUAVAltwyZc/0uY X-Google-Smtp-Source: ANB0VdbMu9Nnb6m07iv7BJZy2KLLMcZ7cJDyRIEhXJuOu+6VccjmWLrFgXssQtSDEhzM6au0Nuk30A== X-Received: by 2002:a1c:ea53:: with SMTP id i80-v6mr134036wmh.113.1534871006923; Tue, 21 Aug 2018 10:03:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2018 19:01:54 +0200 Message-Id: <1534870966-9287-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> References: <1534870966-9287-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 22/74] 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: "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" 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 Signed-off-by: Paolo Bonzini --- cpus.c | 10 ++++++++-- include/qemu/main-loop.h | 4 +++- include/qemu/thread.h | 1 + stubs/iothread-lock.c | 2 +- util/qsp.c | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cpus.c b/cpus.c index b5844b7..a5ea3ee 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/include/qemu/main-loop.h b/include/qemu/main-loop.h index 721aa24..e59f9ae 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 c90ea47..dacebcf 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/stubs/iothread-lock.c b/stubs/iothread-lock.c index 9b6db2e..eb745d7 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 4dc851e..b0c2575 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, }; @@ -123,10 +124,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; @@ -419,6 +422,7 @@ static inline void qsp_entry_record(QSPEntry *e, int64_= t delta) 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 @@ -453,6 +457,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); @@ -462,6 +467,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 1.8.3.1