From patchwork Fri Oct 19 01:05:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 986405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=braap.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="UZaBy1sh"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="bQzldrJ2"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bnns48hwz9sCQ for ; Fri, 19 Oct 2018 12:07:29 +1100 (AEDT) Received: from localhost ([::1]:45886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDJGB-0004Vj-3W for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 21:07:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDJFP-0004U9-27 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 21:06:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDJFM-0002mM-Or for qemu-devel@nongnu.org; Thu, 18 Oct 2018 21:06:38 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:36779) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gDJFM-0002jY-5T for qemu-devel@nongnu.org; Thu, 18 Oct 2018 21:06:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1B1A42293D; Thu, 18 Oct 2018 21:06:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 18 Oct 2018 21:06:28 -0400 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=O3H+tgwcrYkSp5mPtm6WJY53j5YJJetU5qNKy51Vvnc=; b=UZaBy 1shQ4vNvoLin/Wl7pAxkbEhdIRjaLael+tJnWlvHk008DRbdheH+VKX/KQyRS/T0 /N61IR1dXXkBMKTBlWlufDQdzOVEOUqLqH9FeLuioKAy6KcLVKcUIfND0J2kJVJl 9frFVUKoQDLBl/d6SsVG7Te34x54SD0G9IOzzE= 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=O3H+tgwcrYkSp5mPtm6WJY53j5YJJ etU5qNKy51Vvnc=; b=bQzldrJ2a+KAlHlRDj8r8IWJywv7ivOdCSt0BSBpn8EZF 7TIzPxPQOErLb3/PyzulTh5QKRMQgLKWbvx+/Y/hLw4tem1UBBV88wFHYvc3B9/T SCZzXgMukk8GmK0GWLGjc64/VsdQZcQuGRNq74RZtPcFChe+/LgGmfA+ONqw2u5v Pyzk7Su4wRyfJpe2+UA3J9g8+2ayUvO54knykAh/BHRmz1MT8KHtsGpEPzoNNZyx VtuW97rYML+u6kzQ0RaBVBv2FpHVm9Zwsm05L3QUMT7q+1jZsdWpdyddZ3k5jPnt TaBRMhwWlfKqzcdWL2aIqXHjn6+Dh2MeYBgr8iNPg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id B6D84102E4; Thu, 18 Oct 2018 21:06:27 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 21:05:35 -0400 Message-Id: <20181019010625.25294-7-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181019010625.25294-1-cota@braap.org> References: <20181019010625.25294-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.29 Subject: [Qemu-devel] [RFC v3 06/56] cpu: introduce process_queued_cpu_work_locked 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: Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It will gain a user once we protect more of CPUState under cpu->lock. This completes the conversion to cpu_mutex_lock/unlock in the file. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson --- include/qom/cpu.h | 9 +++++++++ cpus-common.c | 17 +++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 90fd685899..30d1c260dc 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -986,6 +986,15 @@ void cpu_remove_sync(CPUState *cpu); */ void process_queued_cpu_work(CPUState *cpu); +/** + * process_queued_cpu_work_locked - process all items on CPU work queue + * @cpu: The CPU which work queue to process. + * + * Call with @cpu->lock held. + * See also: process_queued_cpu_work() + */ +void process_queued_cpu_work_locked(CPUState *cpu); + /** * cpu_exec_start: * @cpu: The CPU for the current thread. diff --git a/cpus-common.c b/cpus-common.c index 20096ec3c6..d559f94ef1 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -315,20 +315,19 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, queue_work_on_cpu(cpu, wi); } -void process_queued_cpu_work(CPUState *cpu) +/* Called with the CPU's lock held */ +void process_queued_cpu_work_locked(CPUState *cpu) { struct qemu_work_item *wi; bool has_bql = qemu_mutex_iothread_locked(); - qemu_mutex_lock(&cpu->lock); if (QSIMPLEQ_EMPTY(&cpu->work_list)) { - qemu_mutex_unlock(&cpu->lock); return; } while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { wi = QSIMPLEQ_FIRST(&cpu->work_list); QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); - qemu_mutex_unlock(&cpu->lock); + cpu_mutex_unlock(cpu); if (wi->exclusive) { /* Running work items outside the BQL avoids the following deadlock: * 1) start_exclusive() is called with the BQL taken while another @@ -354,13 +353,19 @@ void process_queued_cpu_work(CPUState *cpu) qemu_mutex_unlock_iothread(); } } - qemu_mutex_lock(&cpu->lock); + cpu_mutex_lock(cpu); if (wi->free) { g_free(wi); } else { atomic_mb_set(&wi->done, true); } } - qemu_mutex_unlock(&cpu->lock); qemu_cond_broadcast(&cpu->cond); } + +void process_queued_cpu_work(CPUState *cpu) +{ + cpu_mutex_lock(cpu); + process_queued_cpu_work_locked(cpu); + cpu_mutex_unlock(cpu); +}