From: Claudio Fontana <cfontana@suse.de>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Wenchao Wang" <wenchao.wang@intel.com>,
"Roman Bolshakov" <r.bolshakov@yadro.com>,
"Sunil Muthuswamy" <sunilmut@microsoft.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Eduardo Habkost <ehabkost@redhat.com>,
Paul Durrant <paul@xen.org>, Jason Wang <jasowang@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>,
Dario Faggioli <dfaggioli@suse.com>,
Cameron Esfahani <dirty@apple.com>,
haxm-team@intel.com, Claudio Fontana <cfontana@suse.de>,
Anthony Perard <anthony.perard@citrix.com>,
Bruce Rogers <brogers@suse.com>, Olaf Hering <ohering@suse.de>,
"Emilio G . Cota" <cota@braap.org>, Colin Xu <colin.xu@intel.com>
Subject: [PATCH v11 02/25] accel/tcg: split tcg_start_vcpu_thread
Date: Fri, 11 Dec 2020 09:31:20 +0100 [thread overview]
Message-ID: <20201211083143.14350-3-cfontana@suse.de> (raw)
In-Reply-To: <20201211083143.14350-1-cfontana@suse.de>
after the initial split into 3 tcg variants, we proceed to also
split tcg_start_vcpu_thread.
We actually split it in 2 this time, since the icount variant
just uses the round robin function.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tcg-cpus-mttcg.h | 21 --------------
accel/tcg/tcg-cpus-rr.h | 3 +-
accel/tcg/tcg-cpus.h | 1 -
accel/tcg/tcg-all.c | 5 ++++
accel/tcg/tcg-cpus-icount.c | 2 +-
accel/tcg/tcg-cpus-mttcg.c | 29 +++++++++++++++++--
accel/tcg/tcg-cpus-rr.c | 39 +++++++++++++++++++++++--
accel/tcg/tcg-cpus.c | 58 -------------------------------------
8 files changed, 71 insertions(+), 87 deletions(-)
delete mode 100644 accel/tcg/tcg-cpus-mttcg.h
diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h
deleted file mode 100644
index d1bd771f49..0000000000
--- a/accel/tcg/tcg-cpus-mttcg.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * QEMU TCG Multi Threaded vCPUs implementation
- *
- * Copyright 2020 SUSE LLC
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef TCG_CPUS_MTTCG_H
-#define TCG_CPUS_MTTCG_H
-
-/*
- * In the multi-threaded case each vCPU has its own thread. The TLS
- * variable current_cpu can be used deep in the code to find the
- * current CPUState for a given thread.
- */
-
-void *tcg_cpu_thread_fn(void *arg);
-
-#endif /* TCG_CPUS_MTTCG_H */
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
index 1936fd16ab..2e5943eda9 100644
--- a/accel/tcg/tcg-cpus-rr.h
+++ b/accel/tcg/tcg-cpus-rr.h
@@ -15,6 +15,7 @@
/* Kick all RR vCPUs. */
void qemu_cpu_kick_rr_cpus(CPUState *unused);
-void *tcg_rr_cpu_thread_fn(void *arg);
+/* start the round robin vcpu thread */
+void rr_start_vcpu_thread(CPUState *cpu);
#endif /* TCG_CPUS_RR_H */
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
index 279ba72e1f..b7ca954e13 100644
--- a/accel/tcg/tcg-cpus.h
+++ b/accel/tcg/tcg-cpus.h
@@ -18,7 +18,6 @@ extern const CpusAccel tcg_cpus_mttcg;
extern const CpusAccel tcg_cpus_icount;
extern const CpusAccel tcg_cpus_rr;
-void tcg_start_vcpu_thread(CPUState *cpu);
void qemu_tcg_destroy_vcpu(CPUState *cpu);
int tcg_cpu_exec(CPUState *cpu);
void tcg_handle_interrupt(CPUState *cpu, int mask);
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index e42a028043..1ac0b76515 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -105,6 +105,11 @@ static int tcg_init(MachineState *ms)
tcg_exec_init(s->tb_size * 1024 * 1024);
mttcg_enabled = s->mttcg_enabled;
+ /*
+ * Initialize TCG regions
+ */
+ tcg_region_init();
+
if (mttcg_enabled) {
cpus_register_accel(&tcg_cpus_mttcg);
} else if (icount_enabled()) {
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
index d3af3afb6d..82dbe2cacf 100644
--- a/accel/tcg/tcg-cpus-icount.c
+++ b/accel/tcg/tcg-cpus-icount.c
@@ -138,7 +138,7 @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
}
const CpusAccel tcg_cpus_icount = {
- .create_vcpu_thread = tcg_start_vcpu_thread,
+ .create_vcpu_thread = rr_start_vcpu_thread,
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
.handle_interrupt = icount_handle_interrupt,
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
index dac724fc85..f2b892a380 100644
--- a/accel/tcg/tcg-cpus-mttcg.c
+++ b/accel/tcg/tcg-cpus-mttcg.c
@@ -33,7 +33,6 @@
#include "hw/boards.h"
#include "tcg-cpus.h"
-#include "tcg-cpus-mttcg.h"
/*
* In the multi-threaded case each vCPU has its own thread. The TLS
@@ -41,7 +40,7 @@
* current CPUState for a given thread.
*/
-void *tcg_cpu_thread_fn(void *arg)
+static void *tcg_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
@@ -109,8 +108,32 @@ static void mttcg_kick_vcpu_thread(CPUState *cpu)
cpu_exit(cpu);
}
+static void mttcg_start_vcpu_thread(CPUState *cpu)
+{
+ char thread_name[VCPU_THREAD_NAME_SIZE];
+
+ g_assert(tcg_enabled());
+
+ parallel_cpus = (current_machine->smp.max_cpus > 1);
+
+ cpu->thread = g_malloc0(sizeof(QemuThread));
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+ qemu_cond_init(cpu->halt_cond);
+
+ /* create a thread per vCPU with TCG (MTTCG) */
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
+ cpu->cpu_index);
+
+ qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
+ cpu, QEMU_THREAD_JOINABLE);
+
+#ifdef _WIN32
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
+#endif
+}
+
const CpusAccel tcg_cpus_mttcg = {
- .create_vcpu_thread = tcg_start_vcpu_thread,
+ .create_vcpu_thread = mttcg_start_vcpu_thread,
.kick_vcpu_thread = mttcg_kick_vcpu_thread,
.handle_interrupt = tcg_handle_interrupt,
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
index ad50a3765f..f3b262bec7 100644
--- a/accel/tcg/tcg-cpus-rr.c
+++ b/accel/tcg/tcg-cpus-rr.c
@@ -144,7 +144,7 @@ static void deal_with_unplugged_cpus(void)
* elsewhere.
*/
-void *tcg_rr_cpu_thread_fn(void *arg)
+static void *tcg_rr_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
@@ -262,8 +262,43 @@ void *tcg_rr_cpu_thread_fn(void *arg)
return NULL;
}
+void rr_start_vcpu_thread(CPUState *cpu)
+{
+ char thread_name[VCPU_THREAD_NAME_SIZE];
+ static QemuCond *single_tcg_halt_cond;
+ static QemuThread *single_tcg_cpu_thread;
+
+ g_assert(tcg_enabled());
+ parallel_cpus = false;
+
+ if (!single_tcg_cpu_thread) {
+ cpu->thread = g_malloc0(sizeof(QemuThread));
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+ qemu_cond_init(cpu->halt_cond);
+
+ /* share a single thread for all cpus with TCG */
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
+ qemu_thread_create(cpu->thread, thread_name,
+ tcg_rr_cpu_thread_fn,
+ cpu, QEMU_THREAD_JOINABLE);
+
+ single_tcg_halt_cond = cpu->halt_cond;
+ single_tcg_cpu_thread = cpu->thread;
+#ifdef _WIN32
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
+#endif
+ } else {
+ /* we share the thread */
+ cpu->thread = single_tcg_cpu_thread;
+ cpu->halt_cond = single_tcg_halt_cond;
+ cpu->thread_id = first_cpu->thread_id;
+ cpu->can_do_io = 1;
+ cpu->created = true;
+ }
+}
+
const CpusAccel tcg_cpus_rr = {
- .create_vcpu_thread = tcg_start_vcpu_thread,
+ .create_vcpu_thread = rr_start_vcpu_thread,
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
.handle_interrupt = tcg_handle_interrupt,
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
index f2b9bbf99e..86fd09545a 100644
--- a/accel/tcg/tcg-cpus.c
+++ b/accel/tcg/tcg-cpus.c
@@ -35,67 +35,9 @@
#include "hw/boards.h"
#include "tcg-cpus.h"
-#include "tcg-cpus-mttcg.h"
-#include "tcg-cpus-rr.h"
/* common functionality among all TCG variants */
-void tcg_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
- static QemuCond *single_tcg_halt_cond;
- static QemuThread *single_tcg_cpu_thread;
- static int tcg_region_inited;
-
- assert(tcg_enabled());
- /*
- * Initialize TCG regions--once. Now is a good time, because:
- * (1) TCG's init context, prologue and target globals have been set up.
- * (2) qemu_tcg_mttcg_enabled() works now (TCG init code runs before the
- * -accel flag is processed, so the check doesn't work then).
- */
- if (!tcg_region_inited) {
- tcg_region_inited = 1;
- tcg_region_init();
- parallel_cpus = qemu_tcg_mttcg_enabled() && current_machine->smp.max_cpus > 1;
- }
-
- if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) {
- cpu->thread = g_malloc0(sizeof(QemuThread));
- cpu->halt_cond = g_malloc0(sizeof(QemuCond));
- qemu_cond_init(cpu->halt_cond);
-
- if (qemu_tcg_mttcg_enabled()) {
- /* create a thread per vCPU with TCG (MTTCG) */
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
- cpu->cpu_index);
-
- qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-
- } else {
- /* share a single thread for all cpus with TCG */
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
- qemu_thread_create(cpu->thread, thread_name,
- tcg_rr_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-
- single_tcg_halt_cond = cpu->halt_cond;
- single_tcg_cpu_thread = cpu->thread;
- }
-#ifdef _WIN32
- cpu->hThread = qemu_thread_get_handle(cpu->thread);
-#endif
- } else {
- /* For non-MTTCG cases we share the thread */
- cpu->thread = single_tcg_cpu_thread;
- cpu->halt_cond = single_tcg_halt_cond;
- cpu->thread_id = first_cpu->thread_id;
- cpu->can_do_io = 1;
- cpu->created = true;
- }
-}
-
void qemu_tcg_destroy_vcpu(CPUState *cpu)
{
cpu_thread_signal_destroyed(cpu);
--
2.26.2
next prev parent reply other threads:[~2020-12-11 8:36 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 8:31 [PATCH v11 00/25] i386 cleanup PART 1 Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 01/25] accel/tcg: split CpusAccel into three TCG variants Claudio Fontana
2020-12-11 8:31 ` Claudio Fontana [this message]
2020-12-11 8:31 ` [PATCH v11 03/25] accel/tcg: rename tcg-cpus functions to match module name Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 04/25] i386: move kvm accel files into kvm/ Claudio Fontana
2020-12-11 16:08 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 05/25] i386: move whpx accel files into whpx/ Claudio Fontana
2020-12-11 16:09 ` Richard Henderson
2020-12-11 20:41 ` Eduardo Habkost
2020-12-12 9:24 ` Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 06/25] i386: move hax accel files into hax/ Claudio Fontana
2020-12-11 16:10 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 07/25] i386: hvf: remove stale MAINTAINERS entry for old hvf stubs Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 08/25] i386: move TCG accel files into tcg/ Claudio Fontana
2020-12-11 16:10 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 09/25] i386: move cpu dump out of helper.c into cpu-dump.c Claudio Fontana
2020-12-11 16:13 ` Richard Henderson
2020-12-11 17:21 ` Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 10/25] i386: move TCG cpu class initialization out of helper.c Claudio Fontana
2020-12-11 16:44 ` Richard Henderson
2020-12-11 17:31 ` Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 11/25] tcg: cpu_exec_{enter,exit} helpers Claudio Fontana
2020-12-11 16:45 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 12/25] tcg: make CPUClass.cpu_exec_* optional Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 13/25] tcg: Make CPUClass.debug_excp_handler optional Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 14/25] cpu: Remove unnecessary noop methods Claudio Fontana
2020-12-11 11:05 ` Philippe Mathieu-Daudé
2020-12-11 8:31 ` [PATCH v11 15/25] cpu: Introduce TCGCpuOperations struct Claudio Fontana
2020-12-11 16:55 ` Richard Henderson
2020-12-11 16:57 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 16/25] target/riscv: remove CONFIG_TCG, as it is always TCG Claudio Fontana
2020-12-11 16:56 ` Richard Henderson
2020-12-11 17:19 ` Claudio Fontana
2020-12-11 8:31 ` [PATCH v11 17/25] accel/tcg: split TCG-only code from cpu_exec_realizefn Claudio Fontana
2020-12-11 16:58 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 18/25] cpu: Move synchronize_from_tb() to tcg_ops Claudio Fontana
2020-12-11 17:05 ` Richard Henderson
2020-12-11 17:10 ` Claudio Fontana
2020-12-11 17:11 ` Claudio Fontana
2020-12-11 17:28 ` Richard Henderson
2020-12-11 17:47 ` Claudio Fontana
2020-12-11 18:04 ` Richard Henderson
2020-12-11 18:15 ` Claudio Fontana
2020-12-11 18:22 ` Richard Henderson
2020-12-11 18:26 ` Philippe Mathieu-Daudé
2020-12-11 18:51 ` Claudio Fontana
2020-12-11 18:54 ` Philippe Mathieu-Daudé
2020-12-11 20:02 ` Eduardo Habkost
2020-12-12 10:00 ` Claudio Fontana
2020-12-12 11:41 ` Claudio Fontana
2020-12-14 21:04 ` Eduardo Habkost
2020-12-11 8:31 ` [PATCH v11 19/25] cpu: Move cpu_exec_* " Claudio Fontana
2020-12-11 17:30 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 20/25] cpu: Move tlb_fill " Claudio Fontana
2020-12-11 17:42 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 21/25] cpu: Move debug_excp_handler " Claudio Fontana
2020-12-11 17:44 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 22/25] target/arm: do not use cc->do_interrupt for KVM directly Claudio Fontana
2020-12-11 17:44 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 23/25] cpu: move cc->do_interrupt to tcg_ops Claudio Fontana
2020-12-11 17:46 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 24/25] cpu: move cc->transaction_failed " Claudio Fontana
2020-12-11 11:00 ` Philippe Mathieu-Daudé
2020-12-11 17:50 ` Richard Henderson
2020-12-11 8:31 ` [PATCH v11 25/25] cpu: move do_unaligned_access " Claudio Fontana
2020-12-11 11:01 ` Philippe Mathieu-Daudé
2020-12-11 17:58 ` Richard Henderson
2020-12-11 8:57 ` [PATCH v11 00/25] i386 cleanup PART 1 no-reply
2020-12-11 11:07 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201211083143.14350-3-cfontana@suse.de \
--to=cfontana@suse.de \
--cc=anthony.perard@citrix.com \
--cc=brogers@suse.com \
--cc=colin.xu@intel.com \
--cc=cota@braap.org \
--cc=dfaggioli@suse.com \
--cc=dirty@apple.com \
--cc=ehabkost@redhat.com \
--cc=haxm-team@intel.com \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=mtosatti@redhat.com \
--cc=ohering@suse.de \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=r.bolshakov@yadro.com \
--cc=richard.henderson@linaro.org \
--cc=sstabellini@kernel.org \
--cc=sunilmut@microsoft.com \
--cc=thuth@redhat.com \
--cc=wenchao.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).