From nobody Fri Nov 7 01:04:26 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 1544680065445223.9638764832522; Wed, 12 Dec 2018 21:47:45 -0800 (PST) Received: from localhost ([::1]:50651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXJqa-00025U-2q for importer@patchew.org; Thu, 13 Dec 2018 00:47:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXJD2-000859-Gy for qemu-devel@nongnu.org; Thu, 13 Dec 2018 00:06:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXJCz-0002DQ-Ld for qemu-devel@nongnu.org; Thu, 13 Dec 2018 00:06:52 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39995) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gXJCz-0001td-9d for qemu-devel@nongnu.org; Thu, 13 Dec 2018 00:06:49 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 685712228D; Thu, 13 Dec 2018 00:05:53 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 13 Dec 2018 00:05:53 -0500 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id F0C3A1033F; Thu, 13 Dec 2018 00:05:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=G7YiPYLyF3yBXRdKRh3trsxZEFJg+TUhHZurjtigpzc=; b=Ua9E1 JVrtkALHo6mAnPLe6y5K4cGx7beNZQSbngf9si8DgHZz7iTl4Mv+AuCVwEU6lf9W FsYb4jvAvnWgS8UMlsccOvri1WsmDj4zWl0yF60hOLRZzpKCQg/fYLbgsPXexpZm Pm5rc/bJzqTY0UB6ICu7J9UFL1Ndlv/IMB4iFI= 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-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=G7YiPYLyF3yBXRdKRh3trsxZEFJg+ TUhHZurjtigpzc=; b=rY1FEhAIt89m7HfYF1wxZWvsrTuW+QgMlJVkivV5fIfxV 5/epUzLgAc7FniVA+6RvSxPOAsPtSXyFmoMV6CuekhjV7DEw8dAWolNw6ikA2mBp fWUK8Z+9N0/jBiAQYCwHofm635GFgsI2itKmr785H51DQqVBSwtzamyZ9RvHjRDJ gJUVUEcloZEXTIOPrvMF2zbTZ4mL0qtGF1LRp8o8pUD7QNN40+fwcAFjchj32AGZ pRqfDbLV7DtAVfPcHzDKIZ42gUX7fnp74kjWjC2nZD+pt7JmPENwxRki1mNLH8tm ws13/hgCa6qWQqsNUegR9yWpfYZgDrbHGs3tKhc1w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudehuddgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkof gjfhestddtredtredttdenucfhrhhomhepfdfgmhhilhhiohcuifdrucevohhtrgdfuceo tghothgrsegsrhgrrghprdhorhhgqeenucfkphepuddvkedrheelrddvtddrvdduieenuc frrghrrghmpehmrghilhhfrhhomheptghothgrsegsrhgrrghprdhorhhgnecuvehluhhs thgvrhfuihiivgepudel X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 00:04:52 -0500 Message-Id: <20181213050453.9677-73-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181213050453.9677-1-cota@braap.org> References: <20181213050453.9677-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v5 72/73] cpu: add async_run_on_cpu_no_bql 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Some async jobs do not need the BQL. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota --- include/qom/cpu.h | 14 ++++++++++++++ cpus-common.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index bcb46c3946..7ef0120213 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -876,9 +876,23 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, r= un_on_cpu_data data); * @data: Data to pass to the function. * * Schedules the function @func for execution on the vCPU @cpu asynchronou= sly. + * See also: async_run_on_cpu_no_bql() */ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data= data); =20 +/** + * async_run_on_cpu_no_bql: + * @cpu: The vCPU to run on. + * @func: The function to be executed. + * @data: Data to pass to the function. + * + * Schedules the function @func for execution on the vCPU @cpu asynchronou= sly. + * This function is run outside the BQL. + * See also: async_run_on_cpu() + */ +void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func, + run_on_cpu_data data); + /** * async_safe_run_on_cpu: * @cpu: The vCPU to run on. diff --git a/cpus-common.c b/cpus-common.c index 08031e37f4..a8f913b918 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -109,6 +109,7 @@ struct qemu_work_item { run_on_cpu_func func; run_on_cpu_data data; bool free, exclusive, done; + bool bql; }; =20 /* Called with the CPU's lock held */ @@ -155,6 +156,7 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, ru= n_on_cpu_data data) wi.done =3D false; wi.free =3D false; wi.exclusive =3D false; + wi.bql =3D true; =20 cpu_mutex_lock(cpu); queue_work_on_cpu_locked(cpu, &wi); @@ -179,6 +181,21 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func f= unc, run_on_cpu_data data) wi->func =3D func; wi->data =3D data; wi->free =3D true; + wi->bql =3D true; + + queue_work_on_cpu(cpu, wi); +} + +void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func, + run_on_cpu_data data) +{ + struct qemu_work_item *wi; + + wi =3D g_malloc0(sizeof(struct qemu_work_item)); + wi->func =3D func; + wi->data =3D data; + wi->free =3D true; + /* wi->bql initialized to false */ =20 queue_work_on_cpu(cpu, wi); } @@ -323,6 +340,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_fu= nc func, wi->data =3D data; wi->free =3D true; wi->exclusive =3D true; + /* wi->bql initialized to false */ =20 queue_work_on_cpu(cpu, wi); } @@ -347,6 +365,7 @@ static void process_queued_cpu_work_locked(CPUState *cp= u) * BQL, so it goes to sleep; start_exclusive() is sleeping too= , so * neither CPU can proceed. */ + g_assert(!wi->bql); if (has_bql) { qemu_mutex_unlock_iothread(); } @@ -357,12 +376,22 @@ static void process_queued_cpu_work_locked(CPUState *= cpu) qemu_mutex_lock_iothread(); } } else { - if (has_bql) { - wi->func(cpu, wi->data); + if (wi->bql) { + if (has_bql) { + wi->func(cpu, wi->data); + } else { + qemu_mutex_lock_iothread(); + wi->func(cpu, wi->data); + qemu_mutex_unlock_iothread(); + } } else { - qemu_mutex_lock_iothread(); - wi->func(cpu, wi->data); - qemu_mutex_unlock_iothread(); + if (has_bql) { + qemu_mutex_unlock_iothread(); + wi->func(cpu, wi->data); + qemu_mutex_lock_iothread(); + } else { + wi->func(cpu, wi->data); + } } } cpu_mutex_lock(cpu); --=20 2.17.1