From nobody Tue Nov 4 15:26:22 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 1530216865062440.9421602667195; Thu, 28 Jun 2018 13:14:25 -0700 (PDT) Received: from localhost ([::1]:38321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdJ7-00063h-4B for importer@patchew.org; Thu, 28 Jun 2018 16:14:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAY-0007Be-8O for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAW-0000KZ-Qd for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:30 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:51455) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAW-0000Id-IR for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:28 -0400 Received: by mail-wm0-x241.google.com with SMTP id w137-v6so11045995wmw.1 for ; Thu, 28 Jun 2018 13:05:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05: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=3EWaxMKGlE5P48LNnpAUTWc7xkRhr/qftI18YCJyCCc=; b=a1vyjC5THAPLEXaR6H/cjoo03+ewyryL/PIQ56YdDiUg8els9G3EHKrXd1wSk83wGl 8N46veEfdwqScu0060V1fUmXzXAan8ENyf7Dz5VCcYqcp+V/D3jVRJeN9OfssZPJS9UP eZrDGAdE7VPs+LPfN9jGHM1MkFpx02Nk4CbaVCfVrGzgMBnWiX68iRGH1RNRCNf9hl/y OtSLdDwnQxELxRbpsljwD1uXQvmcuSQMEEgK2XMJ28mYY6aG27v2gAuPcY9uAd7KLt2j xlDVzGaOtnYvU1lmcYiPYR49DpT82BBeGQgCEzXuRKChoxewMbKOaDSoUPXxOumCnA5l mpww== 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=3EWaxMKGlE5P48LNnpAUTWc7xkRhr/qftI18YCJyCCc=; b=KtyngGPR+O3+4ke2Tjf/RmBSsid0JYWYiioM7K5IjGI18bV0arCz+kD8W2fk5l7JXO 6qHfT4By+hV1dd4U0nMfhBxc33IDQ3psRo8AWbVhSNVZxXtf+OjL1tzRKe6R7R5lqDvP xQpulSclYWfacs2kGlB5otxRFbdJ46S4yEceSWu6tNTcm73+0gfLY2sPJoXHQI3tUxt7 gdmCrlLPPm/8aANtD20li/rvS8ilObc3ykXDWi89Sox2MxiDc3YxDOZLQho/pVwyWhHv Z3qzkSquE5RiWhvPp+HZH1W3g/RAAOMj5WAArMClsJRfSoflB+VjBlGry0ROVtONwaXU V08w== X-Gm-Message-State: APt69E1ip2FpDEmIlwssO3aVcOoNHBlNOSQAUupCsfO1hA2tRz+P3jHL VXzjzUayY8ELOPRhBWxotRzJOJ9P X-Google-Smtp-Source: AAOMgpeWe1qgjhGgIdWAXOt5aKBYtRlPs0EVXSO378cU6P9GtE4cvOPgc1iNEH08pQAG2H4k1nVc9w== X-Received: by 2002:a1c:a341:: with SMTP id m62-v6mr5902514wme.3.1530216327186; Thu, 28 Jun 2018 13:05:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:23 +0200 Message-Id: <1530216310-52873-14-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::241 Subject: [Qemu-devel] [PULL 13/60] QemuMutex: support --enable-debug-mutex 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: 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" We have had some tracing tools for mutex but it's not easy to use them for e.g. dead locks. Let's provide "--enable-debug-mutex" parameter when configure to allow QemuMutex to store the last owner that took specific lock. It will be easy to use this tool to debug deadlocks since we can directly know who took the lock then as long as we can have a debugger attached to the process. Reviewed-by: Emilio G. Cota Signed-off-by: Peter Xu Message-Id: <20180425025459.5258-4-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- configure | 10 ++++++++++ include/qemu/thread-posix.h | 4 ++++ include/qemu/thread-win32.h | 4 ++++ util/qemu-thread-common.h | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/configure b/configure index 4d12cfb..3f53aa7 100755 --- a/configure +++ b/configure @@ -456,6 +456,7 @@ replication=3D"yes" vxhs=3D"" libxml2=3D"" docker=3D"no" +debug_mutex=3D"no" =20 # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64=3D"aarch64-linux-gnu-gcc" @@ -1411,6 +1412,10 @@ for opt do ;; --disable-git-update) git_update=3Dno ;; + --enable-debug-mutex) debug_mutex=3Dyes + ;; + --disable-debug-mutex) debug_mutex=3Dno + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1685,6 +1690,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: crypto-afalg Linux AF_ALG crypto backend driver vhost-user vhost-user support capstone capstone disassembler support + debug-mutex mutex debugging support =20 NOTE: The object files are built at the place where configure is launched EOF @@ -5951,6 +5957,7 @@ echo "seccomp support $seccomp" echo "coroutine backend $coroutine" echo "coroutine pool $coroutine_pool" echo "debug stack usage $debug_stack_usage" +echo "mutex debugging $debug_mutex" echo "crypto afalg $crypto_afalg" echo "GlusterFS support $glusterfs" echo "gcov $gcov_tool" @@ -6704,6 +6711,9 @@ fi if test "$capstone" !=3D "no" ; then echo "CONFIG_CAPSTONE=3Dy" >> $config_host_mak fi +if test "$debug_mutex" =3D "yes" ; then + echo "CONFIG_DEBUG_MUTEX=3Dy" >> $config_host_mak +fi =20 # Hold two types of flag: # CONFIG_THREAD_SETNAME_BYTHREAD - we've got a way of setting the name = on diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index f3f47e4..fd27b34 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -12,6 +12,10 @@ typedef QemuMutex QemuRecMutex; =20 struct QemuMutex { pthread_mutex_t lock; +#ifdef CONFIG_DEBUG_MUTEX + const char *file; + int line; +#endif bool initialized; }; =20 diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index 3a05e3b..d668d78 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -5,6 +5,10 @@ =20 struct QemuMutex { SRWLOCK lock; +#ifdef CONFIG_DEBUG_MUTEX + const char *file; + int line; +#endif bool initialized; }; =20 diff --git a/util/qemu-thread-common.h b/util/qemu-thread-common.h index d329208..a0ea7c0 100644 --- a/util/qemu-thread-common.h +++ b/util/qemu-thread-common.h @@ -19,6 +19,10 @@ =20 static inline void qemu_mutex_post_init(QemuMutex *mutex) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file =3D NULL; + mutex->line =3D 0; +#endif mutex->initialized =3D true; } =20 @@ -31,12 +35,20 @@ static inline void qemu_mutex_pre_lock(QemuMutex *mutex, static inline void qemu_mutex_post_lock(QemuMutex *mutex, const char *file, int line) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file =3D file; + mutex->line =3D line; +#endif trace_qemu_mutex_locked(mutex, file, line); } =20 static inline void qemu_mutex_pre_unlock(QemuMutex *mutex, const char *file, int line) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file =3D NULL; + mutex->line =3D 0; +#endif trace_qemu_mutex_unlock(mutex, file, line); } =20 --=20 1.8.3.1