From patchwork Fri Oct 21 11:54:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 78648 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1257241qge; Fri, 21 Oct 2016 04:56:34 -0700 (PDT) X-Received: by 10.200.45.9 with SMTP id n9mr545207qta.52.1477050994895; Fri, 21 Oct 2016 04:56:34 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w126si1661558qka.48.2016.10.21.04.56.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 21 Oct 2016 04:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxYR8-0003Yn-Cs for patch@linaro.org; Fri, 21 Oct 2016 07:56:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxYPX-0002ur-Mb for qemu-devel@nongnu.org; Fri, 21 Oct 2016 07:54:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxYPT-0008Tp-Rr for qemu-devel@nongnu.org; Fri, 21 Oct 2016 07:54:55 -0400 Received: from mail-qt0-x232.google.com ([2607:f8b0:400d:c0d::232]:34276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bxYPT-0008TV-Nd for qemu-devel@nongnu.org; Fri, 21 Oct 2016 07:54:51 -0400 Received: by mail-qt0-x232.google.com with SMTP id q7so83026901qtq.1 for ; Fri, 21 Oct 2016 04:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UIgoI0nrTfSoy8tsZfoPsguy9rYvYhS5uqz36C6g8mA=; b=Fh1mrYorK7QQRQYxsYOAGS8bdMhEfUrZIJ3y7BFpvxDvZT5LRU4Wha6HUMQnaTIaMM 9QohfdBxKMDqUCSihqNMP8VXxb1f8qdXhEU0jAzWPPqaz+Z9JrQcy1XxHtHJyT0MpzDM 2y57j2r7wvy42d8RwG3LsSXOWuJLomkkZ7t0g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UIgoI0nrTfSoy8tsZfoPsguy9rYvYhS5uqz36C6g8mA=; b=dAvD376JZYl3YuPduqf1lEnOGaWhQswPZBlbyXHkSjSaijNEWAq8EZiA2xgKlSk54N yQ12EwfHZLFLTWMwQ8dFlb+Wb8jsI27fkHe2UcqiF7A+Tx/VyG11wYYCStdfRpRNbhrT th695m5uZjMhliQwWTaDnlNiG4cR46N0no+FcCpp4wRXF0iI//qvqrQX+cf2fXw/McVp cdnl+TzvHfzCrzS4SzXKnCXdN8JAW1KLaxVQTFH5X6BhC6mmpphFdRYD6NdOc7LH8KCO X0jdddPC/WyYdCWeF+BxkC8jc4TgW7Dt2vBateb72Pa85AmXEKwC2z1PSiL8W+0MgXqu yEMQ== X-Gm-Message-State: AA6/9RmMrfuX8neZqjtIH63MeYvQmDl2vn/xTF+8LkV12haavfOyc49mofyg8sMgfwgfJJZf X-Received: by 10.28.198.142 with SMTP id w136mr10125910wmf.13.1477050887721; Fri, 21 Oct 2016 04:54:47 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id af4sm2526989wjc.17.2016.10.21.04.54.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 04:54:47 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 76ABC3E0203; Fri, 21 Oct 2016 12:54:46 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: stefanha@redhat.com, pbonzini@redhat.com Date: Fri, 21 Oct 2016 12:54:42 +0100 Message-Id: <20161021115442.18420-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c0d::232 Subject: [Qemu-devel] [PATCH] cpus: make qemu_mutex_iothread_locked() understand co-routines 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: Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There is a slight wart when checking for the state of the BQL when using GThread base co-routines (which we keep for ThreadSanitizer runs). While the main-loop holds the BQL it is suspended until the co-routine completes however the co-routines run in a separate thread so checking the TLS variable could be wrong. We fix this by expanding the check to include qemu_in_coroutine() for GThread based builds. As it is not used for production builds I'm not overly worried about any performance impact which should be negligible anyway. Signed-off-by: Alex Bennée Cc: Stefan Hajnoczi --- configure | 3 +++ cpus.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) -- 2.9.3 diff --git a/configure b/configure index 91a14c1..97b89fb 100755 --- a/configure +++ b/configure @@ -5461,6 +5461,9 @@ if test "$rbd" = "yes" ; then fi echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak +if test "$coroutine" = "gthread" ; then + echo "CONFIG_COROUTINE_GTHREAD=1" >> $config_host_mak +fi if test "$coroutine_pool" = "yes" ; then echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak else diff --git a/cpus.c b/cpus.c index 0c18a9f..a3e189a 100644 --- a/cpus.c +++ b/cpus.c @@ -49,6 +49,10 @@ #include "hw/nmi.h" #include "sysemu/replay.h" +#ifdef CONFIG_COROUTINE_GTHREAD +#include "qemu/coroutine.h" +#endif + #ifndef _WIN32 #include "qemu/compatfd.h" #endif @@ -1422,9 +1426,18 @@ bool qemu_in_vcpu_thread(void) static __thread bool iothread_locked = false; +/* + * There is a slight wart when using gthread based co-routines. Here + * the BQL is held by the main-thread which is suspended until the + * co-routines complete. + */ bool qemu_mutex_iothread_locked(void) { +#ifdef CONFIG_COROUTINE_GTHREAD + return iothread_locked || qemu_in_coroutine(); +#else return iothread_locked; +#endif } void qemu_mutex_lock_iothread(void)