From patchwork Fri Sep 23 07:31:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 673965 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 3sgRSM4Wp1z9t0p for ; Fri, 23 Sep 2016 18:32:35 +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=dr9Nl2Mm; dkim-atps=neutral Received: from localhost ([::1]:42122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnLuL-0005fa-0H for incoming@patchwork.ozlabs.org; Fri, 23 Sep 2016 04:32:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnKyk-0005a5-Gb for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnKyi-0005hL-FV for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:01 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnKyi-0005h5-7A for qemu-devel@nongnu.org; Fri, 23 Sep 2016 03:33:00 -0400 Received: by mail-wm0-f68.google.com with SMTP id b184so1276280wma.3 for ; Fri, 23 Sep 2016 00:33:00 -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 :mime-version:content-transfer-encoding; bh=ZbqoFX7rGHktP+jfXEJbVVgJ15l3W9jKFHwCWu8WEPY=; b=dr9Nl2Mm1QSemX4PoBBZJOJa+X6tA0gX5gBAusuTgHLnfFiX+W1PQ5nFgG07jEhWVv rCgjN4Pi4FyBxsDj4TuAUjaDdJUYsEml53vZPJsR5AvgrN8WNV5LFCYtJAwiCW/dr7Wr OBL9sHGRbOtSAxVMdrcUeL2y3ytrgU2dNRkB/UTj3PY6D6KwV9oMHD6NFBp1IT4bDhMp GXL+AXfvOJJwAkYcnSmRZMMjsWK6jGjx606dYN9cH9rKqMPN7C6lWqm4wxPzgVlpgfmD wQ2CJJDa0FYL9040QSLZDOXd3CghoJvuYYKib5eGFasZIKkJKLqnFLbfQexl8hRYS+Nn ulnQ== 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:mime-version:content-transfer-encoding; bh=ZbqoFX7rGHktP+jfXEJbVVgJ15l3W9jKFHwCWu8WEPY=; b=IB9kbW9hmZ51HH7mZ5J3fP02zjUiQXBrASwpJIDyESoxRWvspavDR+UujUpFLUK7gV nWz/9dYKpkwo8gn+QSFgF6TyWSwLv0Odd0hG1wTaDBU3mw5G6jiHaV0p21JSojaBLkCq pQWRuAPm3dcyRt5R4ELGRSdBm4LyZlmqA3/ARTqKGKdO8AvTcllJkW2KL0qHx25fWBBT hn9BXAI9EQyNUkPuMP+PwidXPPZH9FJfON+Vo9VQaYGLZT0rLHJ9Wzk/yidv0U/l6XU2 jddw3N+W37Nt+kCGqo93I7U3MVuuckHX7w8JQ2fFxJAy8uKN2ewPSZeRJsfmtpWI8ADS ntEw== X-Gm-Message-State: AE9vXwOOMrJmji+cL0Nibu3vIpu2FnVZFZocjSq9pcw34D6DVndAaf/Dg8K5fCd5Xi+rrw== X-Received: by 10.194.9.36 with SMTP id w4mr5459068wja.133.1474615919458; Fri, 23 Sep 2016 00:31:59 -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.31.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Sep 2016 00:31:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Sep 2016 09:31:37 +0200 Message-Id: <1474615909-17069-5-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.68 Subject: [Qemu-devel] [PATCH 04/16] 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: 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" 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 Signed-off-by: Alex Bennée Message-Id: <1470158864-17651-7-git-send-email-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- linux-user/main.c | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 3ad70f8..462b4bf 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -111,17 +111,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_lock; +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_lock); + 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(); } @@ -138,14 +146,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_lock); + 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); } } @@ -155,7 +163,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); } } @@ -165,7 +173,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; @@ -176,8 +184,8 @@ static inline void start_exclusive(void) cpu_exit(other_cpu); } } - if (pending_cpus > 1) { - pthread_cond_wait(&exclusive_cond, &exclusive_lock); + while (pending_cpus > 1) { + qemu_cond_wait(&exclusive_cond, &exclusive_lock); } } @@ -185,42 +193,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_lock); } void cpu_list_unlock(void) { - pthread_mutex_unlock(&cpu_list_mutex); + qemu_mutex_unlock(&cpu_list_lock); } @@ -4211,6 +4219,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) {