From patchwork Wed Jul 6 21:14:58 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: 9217053 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 14A3D60752 for ; Wed, 6 Jul 2016 21:16:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 029FA28487 for ; Wed, 6 Jul 2016 21:16:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB8DD28489; Wed, 6 Jul 2016 21:16:04 +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 3E15A28487 for ; Wed, 6 Jul 2016 21:16:04 +0000 (UTC) Received: from localhost ([::1]:35861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuAt-00046A-9r for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 17:16:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuAA-0003jF-Va 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 1bKuA9-0007In-LV for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:18 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:34680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuA9-0007IC-8P for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:17 -0400 Received: by mail-lf0-x22b.google.com with SMTP id h129so162913898lfh.1 for ; Wed, 06 Jul 2016 14:15:17 -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=nOJLJS5wNAQilsN/XR6Cgj07N2nuKSOp2b8HLFEm1Ag=; b=QT+fk3U/FD2wEAtG9pZqYFTiSiAZcnUy9h4nX5x5z4YeilvaFC0CvtNiGeSYISnMYx zM8wUthgBdWkWGoXrTc5hNz3UfTwsSV0bRAdhXb+8JjB2pQOkvMJXR3swGtwJzJDqAF4 6PbxlRnzARsSc13BLFHdk8do9oHCC1CqMurwc= 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=nOJLJS5wNAQilsN/XR6Cgj07N2nuKSOp2b8HLFEm1Ag=; b=C73gpVFrfXZP9lgTsYXUP3vnpmdcNFRGUQXRxEnUY+Vr0cnEfQuw46lyNiB8fwmfI6 imkswY3lQqWhZT5mk1oDDljnbJkU2p+fv76G/yHn+lM4W7Q8GfVVLZFEHEWWN2LtfbtY dhrXVl4gO+otWtvXOZb+7ODhvlDsUbpeuUbeUos7JyqyIs3hOp8+ks/2+VAvExpCCbBC uKidtZKY0i2b49wKj6nhyoPLTbvNZpt01IwCa4Zg9UToMlrCceLu01v/fRGJaNL87zFD 8RTFwaSmgLphhRxh3Tt8OT8K6c84SjqAsY4cGqLJNafCNSfio80IHLOxm0iPLhfxTKyZ 5NCQ== X-Gm-Message-State: ALyK8tKhwdpGmLY36R3neEo+J5AbInEqQwe+7O30v6LNIkeFoDZlsT8G7MosLAI2jUU1EFdS X-Received: by 10.25.26.194 with SMTP id a185mr5496140lfa.156.1467839716535; Wed, 06 Jul 2016 14:15:16 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jul 2016 14:15:15 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 00:14:58 +0300 Message-Id: <1467839703-11733-7-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::22b Subject: [Qemu-devel] [RFC v2 06/11] linux-user: Use QemuMutex and QemuCond 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 Convert pthread_mutex_t and pthread_cond_t to QemuMutex and QemuCond. This will allow to make some locks and conditional variables common between user and system mode emulation. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- linux-user/main.c | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 617a179f14a4..bdbda693cc5f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -108,17 +108,25 @@ int cpu_get_pic_interrupt(CPUX86State *env) We don't require a full sync, only that no cpus are executing guest code. The alternative is to map target atomic ops onto host equivalents, which requires quite a lot of per host/target work. */ -static pthread_mutex_t cpu_list_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t exclusive_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t exclusive_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t exclusive_resume = PTHREAD_COND_INITIALIZER; +static QemuMutex cpu_list_mutex; +static QemuMutex exclusive_lock; +static QemuCond exclusive_cond; +static QemuCond exclusive_resume; static int pending_cpus; +void qemu_init_cpu_loop(void) +{ + qemu_mutex_init(&cpu_list_mutex); + qemu_mutex_init(&exclusive_lock); + qemu_cond_init(&exclusive_cond); + qemu_cond_init(&exclusive_resume); +} + /* Make sure everything is in a consistent state for calling fork(). */ void fork_start(void) { qemu_mutex_lock(&tcg_ctx.tb_ctx.tb_lock); - pthread_mutex_lock(&exclusive_lock); + qemu_mutex_lock(&exclusive_lock); mmap_fork_start(); } @@ -135,14 +143,14 @@ void fork_end(int child) } } pending_cpus = 0; - pthread_mutex_init(&exclusive_lock, NULL); - pthread_mutex_init(&cpu_list_mutex, NULL); - pthread_cond_init(&exclusive_cond, NULL); - pthread_cond_init(&exclusive_resume, NULL); + qemu_mutex_init(&exclusive_lock); + qemu_mutex_init(&cpu_list_mutex); + qemu_cond_init(&exclusive_cond); + qemu_cond_init(&exclusive_resume); qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); gdbserver_fork(thread_cpu); } else { - pthread_mutex_unlock(&exclusive_lock); + qemu_mutex_unlock(&exclusive_lock); qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); } } @@ -152,7 +160,7 @@ void fork_end(int child) static inline void exclusive_idle(void) { while (pending_cpus) { - pthread_cond_wait(&exclusive_resume, &exclusive_lock); + qemu_cond_wait(&exclusive_resume, &exclusive_lock); } } @@ -162,7 +170,7 @@ static inline void start_exclusive(void) { CPUState *other_cpu; - pthread_mutex_lock(&exclusive_lock); + qemu_mutex_lock(&exclusive_lock); exclusive_idle(); pending_cpus = 1; @@ -174,7 +182,7 @@ static inline void start_exclusive(void) } } if (pending_cpus > 1) { - pthread_cond_wait(&exclusive_cond, &exclusive_lock); + qemu_cond_wait(&exclusive_cond, &exclusive_lock); } } @@ -182,42 +190,42 @@ static inline void start_exclusive(void) static inline void __attribute__((unused)) end_exclusive(void) { pending_cpus = 0; - pthread_cond_broadcast(&exclusive_resume); - pthread_mutex_unlock(&exclusive_lock); + qemu_cond_broadcast(&exclusive_resume); + qemu_mutex_unlock(&exclusive_lock); } /* Wait for exclusive ops to finish, and begin cpu execution. */ static inline void cpu_exec_start(CPUState *cpu) { - pthread_mutex_lock(&exclusive_lock); + qemu_mutex_lock(&exclusive_lock); exclusive_idle(); cpu->running = true; - pthread_mutex_unlock(&exclusive_lock); + qemu_mutex_unlock(&exclusive_lock); } /* Mark cpu as not executing, and release pending exclusive ops. */ static inline void cpu_exec_end(CPUState *cpu) { - pthread_mutex_lock(&exclusive_lock); + qemu_mutex_lock(&exclusive_lock); cpu->running = false; if (pending_cpus > 1) { pending_cpus--; if (pending_cpus == 1) { - pthread_cond_signal(&exclusive_cond); + qemu_cond_signal(&exclusive_cond); } } exclusive_idle(); - pthread_mutex_unlock(&exclusive_lock); + qemu_mutex_unlock(&exclusive_lock); } void cpu_list_lock(void) { - pthread_mutex_lock(&cpu_list_mutex); + qemu_mutex_lock(&cpu_list_mutex); } void cpu_list_unlock(void) { - pthread_mutex_unlock(&cpu_list_mutex); + qemu_mutex_unlock(&cpu_list_mutex); } @@ -4210,6 +4218,7 @@ int main(int argc, char **argv, char **envp) int ret; int execfd; + qemu_init_cpu_loop(); module_call_init(MODULE_INIT_QOM); if ((envlist = envlist_create()) == NULL) {