From nobody Thu Apr 25 02:23:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515675372073973.5816418444324; Thu, 11 Jan 2018 04:56:12 -0800 (PST) Received: from localhost ([::1]:41155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZcOu-0000ue-5j for importer@patchew.org; Thu, 11 Jan 2018 07:56:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZcNg-0000MX-KA for qemu-devel@nongnu.org; Thu, 11 Jan 2018 07:54:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZcNd-0007nq-Hf for qemu-devel@nongnu.org; Thu, 11 Jan 2018 07:54:52 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:41733) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZcNd-0007n8-8X for qemu-devel@nongnu.org; Thu, 11 Jan 2018 07:54:49 -0500 Received: by mail-wr0-x243.google.com with SMTP id o7so2050380wro.8 for ; Thu, 11 Jan 2018 04:54:49 -0800 (PST) Received: from donizetti.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id g60sm36857587wrd.92.2018.01.11.04.54.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jan 2018 04:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=+rXBamn1vd7kEzUAyvUr2DppJ/r88ZeB7/VG5GTk7fE=; b=Q5VZxedCEW3cP3PiixtjF+5nD6FkMGdnXoSdhRLfBzPDsTPNXI9FmyEBvI8LSFAssu tMg4BTOrrN0xls4das4hcjfA8yGfCUZEQZSBglqRXa58sR6KtMB1NTzxSFj6yIg4lsgJ pEC/AELfiRK3EJSm0J7qfRaCDBf8C46MIse17tWgWSNqXI4JDzLgyVn3KCXPh4NZ9+4J 3w0gT6/Wkrf8or78kwWFX4bt1Vpo2GUNPnbh7R/Ysu5OM1BFfa3Qkv5E2/awey69aXVY 3ljOSCq9A5j8+5WKXrUZUQyNbLMC5do0fjRjau2Q2hiqai6mQl9kuRAsCWZoHqRsvEat WmzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=+rXBamn1vd7kEzUAyvUr2DppJ/r88ZeB7/VG5GTk7fE=; b=jgNi7atJ/eZj+tOVaOecXDYwOuETPlmTa/Xe85+vf741CgmHtuYEFT9zqy0gjnMXpV q2F7mQTpBoNZiL/X7LepaXb8CxwqU52Ccz4b2xCYtguMEQl7OZb9i83fXn/VoZU1KohE ZYweT8kcQF4NYeCRqLpeBDFOWDz7dHNdW6oVk6wgkuQnOBa0onDionD6vmkl8G/yiCjh jHnLNMyFmnzpEjRVqFrDaR+tm+B0FVmKDJXpQlW2t7B62hQJ331l244/QiTVrykAZWHn Q1IN7ir2lgfQ2kqIRUhgIvTiJnSdLaKnKAzlm3+Tg2+3WH09hTDejjMO2AtAK/BIbYSj gXyg== X-Gm-Message-State: AKGB3mJBBSKAMRFqBxIXsrY7IFP0+8mXt+pjaLg96mXTVWzyx1jmqSUG OWObM30RqCyxGH0bWF6QsQw4jHGN X-Google-Smtp-Source: ACJfBov2jcT7lU6ZqKKKSeQKdB/IdR447Ah2M1AszhDpmkL4owP949yfoBPNJugHm7nK2B8Foc9kDw== X-Received: by 10.223.133.69 with SMTP id 63mr20895988wrh.79.1515675287713; Thu, 11 Jan 2018 04:54:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 11 Jan 2018 13:54:44 +0100 Message-Id: <20180111125444.6498-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH] cpus: unify qemu_*_wait_io_event 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: =?UTF-8?q?Alex=20Benn=C3=83=C2=A9e?= , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Except for round-robin TCG, every other accelerator is using more or less the same code around qemu_wait_io_event_common. The exception is HAX, which also has to eat the dummy APC that is queued by qemu_cpu_kick_thread. We can add the SleepEx call to qemu_wait_io_event under "if (!tcg_enabled())", since that is the condition that is used in qemu_cpu_kick_thread, and unify the function for KVM, HAX, HVF and multi-threaded TCG. Single-threaded TCG code can also be simplified since it is only used in the round-robin, sleep-if-all-CPUs-idle case. Signed-off-by: Paolo Bonzini Acked-by: Alex Benn=C3=A9e --- cpus.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/cpus.c b/cpus.c index 440b9291f5..3b6c9879ec 100644 --- a/cpus.c +++ b/cpus.c @@ -911,7 +911,8 @@ static void kick_tcg_thread(void *opaque) =20 static void start_tcg_kick_timer(void) { - if (!mttcg_enabled && !tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { + assert(!mttcg_enabled); + if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { tcg_kick_vcpu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, kick_tcg_thread, NULL); timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); @@ -920,6 +921,7 @@ static void start_tcg_kick_timer(void) =20 static void stop_tcg_kick_timer(void) { + assert(!mttcg_enabled); if (tcg_kick_vcpu_timer) { timer_del(tcg_kick_vcpu_timer); tcg_kick_vcpu_timer =3D NULL; @@ -1154,18 +1156,9 @@ static void qemu_wait_io_event_common(CPUState *cpu) process_queued_cpu_work(cpu); } =20 -static bool qemu_tcg_should_sleep(CPUState *cpu) +static void qemu_tcg_rr_wait_io_event(CPUState *cpu) { - if (mttcg_enabled) { - return cpu_thread_is_idle(cpu); - } else { - return all_cpu_threads_idle(); - } -} - -static void qemu_tcg_wait_io_event(CPUState *cpu) -{ - while (qemu_tcg_should_sleep(cpu)) { + while (all_cpu_threads_idle()) { stop_tcg_kick_timer(); qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); } @@ -1175,20 +1168,18 @@ static void qemu_tcg_wait_io_event(CPUState *cpu) qemu_wait_io_event_common(cpu); } =20 -static void qemu_kvm_wait_io_event(CPUState *cpu) +static void qemu_wait_io_event(CPUState *cpu) { while (cpu_thread_is_idle(cpu)) { qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); } =20 - qemu_wait_io_event_common(cpu); -} - -static void qemu_hvf_wait_io_event(CPUState *cpu) -{ - while (cpu_thread_is_idle(cpu)) { - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); +#ifdef _WIN32 + /* Eat dummy APC queued by qemu_cpu_kick_thread. */ + if (!tcg_enabled()) { + SleepEx(0, TRUE); } +#endif qemu_wait_io_event_common(cpu); } =20 @@ -1224,7 +1215,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) cpu_handle_guest_debug(cpu); } } - qemu_kvm_wait_io_event(cpu); + qemu_wait_io_event(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 qemu_kvm_destroy_vcpu(cpu); @@ -1270,7 +1261,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) exit(1); } qemu_mutex_lock_iothread(); - qemu_wait_io_event_common(cpu); + qemu_wait_io_event(cpu); } =20 return NULL; @@ -1487,7 +1478,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) atomic_mb_set(&cpu->exit_request, 0); } =20 - qemu_tcg_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus)); + qemu_tcg_rr_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus)); deal_with_unplugged_cpus(); } =20 @@ -1518,13 +1509,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) } } =20 - while (cpu_thread_is_idle(cpu)) { - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); - } -#ifdef _WIN32 - SleepEx(0, TRUE); -#endif - qemu_wait_io_event_common(cpu); + qemu_wait_io_event(cpu); } return NULL; } @@ -1561,7 +1546,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) cpu_handle_guest_debug(cpu); } } - qemu_hvf_wait_io_event(cpu); + qemu_wait_io_event(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 hvf_vcpu_destroy(cpu); @@ -1640,7 +1625,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } =20 atomic_mb_set(&cpu->exit_request, 0); - qemu_tcg_wait_io_event(cpu); + qemu_wait_io_event(cpu); } =20 return NULL; --=20 2.14.3