From patchwork Fri Sep 23 07:31:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 674003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sgSMl2rsGz9t14 for ; Fri, 23 Sep 2016 19:13:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=aYSQbVMC; dkim-atps=neutral Received: from localhost ([::1]:42669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnMY4-0003fw-Uj for incoming@patchwork.ozlabs.org; Fri, 23 Sep 2016 05:13:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnKyy-0005oh-FN for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnKyv-0005pJ-3F for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:15 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnKyu-0005p9-Ti for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:13 -0400 Received: by mail-wm0-f65.google.com with SMTP id b184so1277236wma.3 for ; Fri, 23 Sep 2016 00:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4hByssUZSzrhiUXhmYreA59RT/d0LY8WZ3wyMwQWFro=; b=aYSQbVMCoOhTdGo2UUnVPoETQaJpoVLto5LmR6kLf4EMNCdy6W/hitN8MVJvDRWI1D DZ1geESkvlaqvF0pB95Byy8uP334+8qJrCu/x9gvYWZQ630yvv1mc41VAv81vzszY/pI Gj/z+LmCvbf41BHFcNUkLxaKqQDvrwBxsqUOPVN47sDIQDuw3ZAxMLquChzDMRc80/+0 CXtJrNI2TYdDFDFeIAKZ1WCScKHTjOymLOT+45kkzXe7UIt+0yry/5CEw9KtYn6Pvp25 D7SpEUTJ28wxUgqjV9fISNdehK55FGak08uFKH6ULT4J4rqbsjLeBaYaN8oFzfWQmPIZ zx7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4hByssUZSzrhiUXhmYreA59RT/d0LY8WZ3wyMwQWFro=; b=STWA9+uaEWazIvQubIoF4H6KOgaChYYmpsLkKGc8+MOcCe0ueaI8qW/wqzt3Tg6Hdk P+vbDgCsLjs1nkDOGVAnV9dTWsoIwCX0PIFOC1cOUCvO6TilYm7y+cFSn0KjsgjL8HOF vQ/uLaWDNjrqB2dbzf+5JSxqd633fWVbV32OOLQq+lj0NJLAE4pbz47X8EmfIjNl3o96 Sh4n6AzHF73CuC1bsmljaoQp87Kcg/GAVKuBG4pJ5TQV3DO6w8wPAPRH177aMZTDx6v4 C/zxnPh2LbsHYCgaZm54m8zY3YupFOqQiBfz0swhUi05EVChFUjPxu1oThexv4/5SAL0 x3mw== X-Gm-Message-State: AA6/9Rn7ERWiaJZ5J1l+EILDQhFzjk4Q2g+COH6Xk4bJVkmuVEFqT2131B3evw3lLPCQ8w== X-Received: by 10.28.134.8 with SMTP id i8mr1242283wmd.59.1474615932221; Fri, 23 Sep 2016 00:32:12 -0700 (PDT) Received: from donizetti.lan (94-39-176-182.adsl-ull.clienti.tiscali.it. [94.39.176.182]) by smtp.gmail.com with ESMTPSA id q10sm1691267wme.6.2016.09.23.00.32.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Sep 2016 00:32:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Sep 2016 09:31:46 +0200 Message-Id: <1474615909-17069-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474615909-17069-1-git-send-email-pbonzini@redhat.com> References: <1474615909-17069-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.65 Subject: [Qemu-devel] [PATCH 13/16] cpus-common: simplify locking for start_exclusive/end_exclusive 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: serge.fdrv@gmail.com, cota@braap.org, alex.bennee@linaro.org, sergey.fedorov@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It is not necessary to hold qemu_cpu_list_mutex throughout the exclusive section, because no other exclusive section can run while pending_cpus != 0. exclusive_idle() is called in cpu_exec_start(), and that prevents any CPUs created after start_exclusive() from entering cpu_exec() during an exclusive section. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée --- cpus-common.c | 11 ++++++++--- docs/tcg-exclusive.promela | 4 +++- include/qom/cpu.h | 4 ---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index 80aaf9b..429652c 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -171,8 +171,7 @@ static inline void exclusive_idle(void) } /* Start an exclusive operation. - Must only be called from outside cpu_exec, takes - qemu_cpu_list_lock. */ + Must only be called from outside cpu_exec. */ void start_exclusive(void) { CPUState *other_cpu; @@ -191,11 +190,17 @@ void start_exclusive(void) while (pending_cpus > 1) { qemu_cond_wait(&exclusive_cond, &qemu_cpu_list_lock); } + + /* Can release mutex, no one will enter another exclusive + * section until end_exclusive resets pending_cpus to 0. + */ + qemu_mutex_unlock(&qemu_cpu_list_lock); } -/* Finish an exclusive operation. Releases qemu_cpu_list_lock. */ +/* Finish an exclusive operation. */ void end_exclusive(void) { + qemu_mutex_lock(&qemu_cpu_list_lock); pending_cpus = 0; qemu_cond_broadcast(&exclusive_resume); qemu_mutex_unlock(&qemu_cpu_list_lock); diff --git a/docs/tcg-exclusive.promela b/docs/tcg-exclusive.promela index 9e7d9e3..a8896e5 100644 --- a/docs/tcg-exclusive.promela +++ b/docs/tcg-exclusive.promela @@ -97,9 +97,11 @@ byte has_waiter[N_CPUS]; do \ :: pending_cpus > 1 -> COND_WAIT(exclusive_cond, mutex); \ :: else -> break; \ - od + od; \ + MUTEX_UNLOCK(mutex); #define end_exclusive() \ + MUTEX_LOCK(mutex); \ pending_cpus = 0; \ COND_BROADCAST(exclusive_resume); \ MUTEX_UNLOCK(mutex); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index f872614..934c07a 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -846,9 +846,6 @@ void cpu_exec_end(CPUState *cpu); * cpu_exec are exited immediately. CPUs that call cpu_exec_start * during the exclusive section go to sleep until this CPU calls * end_exclusive. - * - * Returns with the CPU list lock taken (which nests outside all - * other locks except the BQL). */ void start_exclusive(void); @@ -856,7 +853,6 @@ void start_exclusive(void); * end_exclusive: * * Concludes an exclusive execution section started by start_exclusive. - * Releases the CPU list lock. */ void end_exclusive(void);