From patchwork Fri Jul 15 18:57:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 9232477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D448F60574 for ; Fri, 15 Jul 2016 19:15:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C531E26B4A for ; Fri, 15 Jul 2016 19:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9BFD275A2; Fri, 15 Jul 2016 19:15:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 59C8126B4A for ; Fri, 15 Jul 2016 19:15:36 +0000 (UTC) Received: from localhost ([::1]:34574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO8aF-00016Q-4v for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Jul 2016 15:15:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO8Qx-00073U-KO for qemu-devel@nongnu.org; Fri, 15 Jul 2016 15:06:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bO8Qs-0005K4-Fl for qemu-devel@nongnu.org; Fri, 15 Jul 2016 15:05:58 -0400 Received: from mail-lf0-x231.google.com ([2a00:1450:4010:c07::231]:35540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO8Qs-0005Js-3d for qemu-devel@nongnu.org; Fri, 15 Jul 2016 15:05:54 -0400 Received: by mail-lf0-x231.google.com with SMTP id f93so94532019lfi.2 for ; Fri, 15 Jul 2016 12:05:53 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=4ejqNVQmhjZqYIrU+w9fk1hqFI3cAiXjDwNDAzBEzG0=; b=C76Yr4WLT28OGtPK5fKXvpAxo4fhBqdJtyARhtgTu4BQ+G2UV8UK9XCSEdN0iWMWpG a+RNP81MehfR7HKrJclTJoiXi84e0JxW5CrEnSKcRwbgn3dCMFk0EOU/pqzwizymT71f qR7YxD5jCKlICnuFb4W/6UuyuJiHaTbOzd8VI= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4ejqNVQmhjZqYIrU+w9fk1hqFI3cAiXjDwNDAzBEzG0=; b=juzGU8znbRJ8Oh4hCD1+yG+690VWA/sLOHW+TBhdqrco0StpsrcoqlzQNcYtpiYdoR R/+ZVFPVL2+vL30SkHHe4m4V26yN1kS0sithM3czmVGmt0Hoj/Aqq0TX4VtWB+SvsI8M /u6GtwNEbA+gzi7kam5JJRExD++/TlvxdmKHf0arpHeM0rrvUMT+93ZHczrnEXWvcdkK UvGiDfI2P1gytnl/FmOoSMz1zViJtorUmNk3VHn9qogdWxSWDcEBGYAPhU9+JK1DcWmk vzWfcMPHaOEUAmYi0f4guANPE3sOj0mg/Gnq3hbAxaaIJoQ9mJ4JvqC4MTbc9UdIWluI KxgA== X-Gm-Message-State: ALyK8tIutLNAFJnA5I10pKuJJ0JMaDtNVxj630q7e673Iic4UwE9ceLMCBMxhseLhJ3rtR6M X-Received: by 10.25.19.105 with SMTP id j102mr9744618lfi.44.1468609063063; Fri, 15 Jul 2016 11:57:43 -0700 (PDT) Received: from sergey-laptop.Dlink (broadband-46-188-120-37.2com.net. [46.188.120.37]) by smtp.gmail.com with ESMTPSA id 35sm2126381ljb.10.2016.07.15.11.57.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jul 2016 11:57:41 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Fri, 15 Jul 2016 21:57:21 +0300 Message-Id: <20160715185726.10181-8-sergey.fedorov@linaro.org> X-Mailer: git-send-email 2.9.1 In-Reply-To: <20160715185726.10181-1-sergey.fedorov@linaro.org> References: <20160715185726.10181-1-sergey.fedorov@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::231 Subject: [Qemu-devel] [PATCH v4 07/12] linux-user: Rework exclusive operation mechanism 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: MTTCG Devel , Peter Maydell , Sergey Fedorov , patches@linaro.org, Riku Voipio , Alvise Rigo , "Emilio G. Cota" , Paolo Bonzini , Sergey Fedorov , Richard Henderson , =?UTF-8?Q?Alex_Benn=c3=a9e?= , =?UTF-8?B?S09OUkFEIEZyw6lkw6lyaWM=?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov A single variable 'pending_cpus' was used for both counting currently running CPUs and for signalling the pending exclusive operation request. To prepare for supporting operations which requires a quiescent state, like translation buffer flush, it is useful to keep a counter of currently running CPUs always up to date. Use a separate variable 'tcg_pending_threads' to count for currently running CPUs and a separate variable 'exclusive_pending' to indicate that there's an exclusive operation pending. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- Changes in v2: - Rename 'tcg_pending_cpus' to 'tcg_pending_threads' --- linux-user/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index bdbda693cc5f..5ff0b20bad89 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -112,7 +112,8 @@ static QemuMutex cpu_list_mutex; static QemuMutex exclusive_lock; static QemuCond exclusive_cond; static QemuCond exclusive_resume; -static int pending_cpus; +static bool exclusive_pending; +static int tcg_pending_threads; void qemu_init_cpu_loop(void) { @@ -142,7 +143,8 @@ void fork_end(int child) QTAILQ_REMOVE(&cpus, cpu, node); } } - pending_cpus = 0; + tcg_pending_threads = 0; + exclusive_pending = false; qemu_mutex_init(&exclusive_lock); qemu_mutex_init(&cpu_list_mutex); qemu_cond_init(&exclusive_cond); @@ -159,7 +161,7 @@ void fork_end(int child) must be held. */ static inline void exclusive_idle(void) { - while (pending_cpus) { + while (exclusive_pending) { qemu_cond_wait(&exclusive_resume, &exclusive_lock); } } @@ -173,15 +175,14 @@ static inline void start_exclusive(void) qemu_mutex_lock(&exclusive_lock); exclusive_idle(); - pending_cpus = 1; + exclusive_pending = true; /* Make all other cpus stop executing. */ CPU_FOREACH(other_cpu) { if (other_cpu->running) { - pending_cpus++; cpu_exit(other_cpu); } } - if (pending_cpus > 1) { + while (tcg_pending_threads) { qemu_cond_wait(&exclusive_cond, &exclusive_lock); } } @@ -189,7 +190,7 @@ static inline void start_exclusive(void) /* Finish an exclusive operation. */ static inline void __attribute__((unused)) end_exclusive(void) { - pending_cpus = 0; + exclusive_pending = false; qemu_cond_broadcast(&exclusive_resume); qemu_mutex_unlock(&exclusive_lock); } @@ -200,6 +201,7 @@ static inline void cpu_exec_start(CPUState *cpu) qemu_mutex_lock(&exclusive_lock); exclusive_idle(); cpu->running = true; + tcg_pending_threads++; qemu_mutex_unlock(&exclusive_lock); } @@ -208,11 +210,9 @@ static inline void cpu_exec_end(CPUState *cpu) { qemu_mutex_lock(&exclusive_lock); cpu->running = false; - if (pending_cpus > 1) { - pending_cpus--; - if (pending_cpus == 1) { - qemu_cond_signal(&exclusive_cond); - } + tcg_pending_threads--; + if (!tcg_pending_threads) { + qemu_cond_signal(&exclusive_cond); } exclusive_idle(); qemu_mutex_unlock(&exclusive_lock);