From patchwork Wed Jul 6 21:14:59 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: 9217073 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 F11606048B for ; Wed, 6 Jul 2016 21:30:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1B9228499 for ; Wed, 6 Jul 2016 21:30:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D27DE2849B; Wed, 6 Jul 2016 21:30:33 +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 630C628499 for ; Wed, 6 Jul 2016 21:30:33 +0000 (UTC) Received: from localhost ([::1]:35944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuOu-0004W6-47 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 17:30:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuAB-0003n5-Tc for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKuAA-0007Jh-Om for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:19 -0400 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]:35789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuAA-0007J0-Cz for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:18 -0400 Received: by mail-lf0-x232.google.com with SMTP id l188so162674004lfe.2 for ; Wed, 06 Jul 2016 14:15:18 -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; bh=fgcbGVkDRjGiLdU8SpE0colx1+/Pj9tG2Z9TPJZzoxg=; b=Fr6NL7lNz0rR4myRusS6mWdDbKsYN5sxncgBhAzVqkIclGVavr2sBGZdUfJMbjXofA knOCFCz8l+2Aewx6SgEOycKnvWP2atwzbVEG0YPFQjkG1zM2+e2oPS+lG1z8mbZYLfHM 0QbAIEBtcE89bfgMd0J1BPBA3JMS+qARRPqBg= 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; bh=fgcbGVkDRjGiLdU8SpE0colx1+/Pj9tG2Z9TPJZzoxg=; b=Fs1wnSF3Oy2w4UiROYrNe0XTrbeS4ld+gLIGEd+bTeKJA+Brn9K5IbgzUOB2tRo7Ix /3TcbZtab+ot9TpD6mzUeC6I6mVePA1coWBeht4AuwWb/1yBg3yxKOe9UHEv32yuQz2L M1Id+fmYcZC+a/t8kWPdYB9cH13AupW5xGnzkqdP9zFWTFT/PnG1igu5YwKZBs+F6r7V sNd+G+F7Yu2mOzCKEpN8OXZF3xLkHJvQz2gqyviJjLpxJd26IHXjYsAHOeubg/NYpYdq tKsAhJ+PvKQY49Zf8WKcxYWW82UrSOR6lrVyDafHQyXdy1SdNBauLrb5OUOoZiKT0Y0J YhNg== X-Gm-Message-State: ALyK8tKUVn8goU8H3O40HupHyOpdeJjo5a1MFuih9+mlkjeyE4rvc8pHcQt5jpB4PRzxy/Rv X-Received: by 10.25.88.146 with SMTP id m140mr5298642lfb.217.1467839717655; Wed, 06 Jul 2016 14:15:17 -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 l79sm4420028lfi.40.2016.07.06.14.15.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jul 2016 14:15:16 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 00:14:59 +0300 Message-Id: <1467839703-11733-8-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467839703-11733-1-git-send-email-sergey.fedorov@linaro.org> References: <1467839703-11733-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::232 Subject: [Qemu-devel] [RFC v2 07/11] 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 , Riku Voipio , Alvise Rigo , "Emilio G. Cota" , Sergey Fedorov , Paolo Bonzini , 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);