aboutsummaryrefslogtreecommitdiff
path: root/tcg
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-03-09 22:52:45 -0600
committerRichard Henderson <richard.henderson@linaro.org>2021-06-11 09:27:08 -0700
commit43b972b7ebe9b8e84aa535031de7e605f6bf2cb2 (patch)
treecc1d8a122b43510682c1430134cafccbabe0edaf /tcg
parentefba8ae9f6f4df011b0441ae2b634be6152026a4 (diff)
accel/tcg: Pass down max_cpus to tcg_init
Start removing the include of hw/boards.h from tcg/. Pass down the max_cpus value from tcg_init_machine, where we have the MachineState already. Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tcg')
-rw-r--r--tcg/region.c32
-rw-r--r--tcg/tcg-internal.h2
-rw-r--r--tcg/tcg.c10
3 files changed, 16 insertions, 28 deletions
diff --git a/tcg/region.c b/tcg/region.c
index 162b4d6486..877baf16f5 100644
--- a/tcg/region.c
+++ b/tcg/region.c
@@ -27,9 +27,6 @@
#include "qapi/error.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
-#if !defined(CONFIG_USER_ONLY)
-#include "hw/boards.h"
-#endif
#include "tcg-internal.h"
@@ -366,27 +363,20 @@ void tcg_region_reset_all(void)
tcg_region_tree_reset_all();
}
-#ifdef CONFIG_USER_ONLY
-static size_t tcg_n_regions(void)
+static size_t tcg_n_regions(unsigned max_cpus)
{
+#ifdef CONFIG_USER_ONLY
return 1;
-}
#else
-/*
- * It is likely that some vCPUs will translate more code than others, so we
- * first try to set more regions than max_cpus, with those regions being of
- * reasonable size. If that's not possible we make do by evenly dividing
- * the code_gen_buffer among the vCPUs.
- */
-static size_t tcg_n_regions(void)
-{
+ /*
+ * It is likely that some vCPUs will translate more code than others,
+ * so we first try to set more regions than max_cpus, with those regions
+ * being of reasonable size. If that's not possible we make do by evenly
+ * dividing the code_gen_buffer among the vCPUs.
+ */
size_t i;
/* Use a single region if all we have is one vCPU thread */
-#if !defined(CONFIG_USER_ONLY)
- MachineState *ms = MACHINE(qdev_get_machine());
- unsigned int max_cpus = ms->smp.max_cpus;
-#endif
if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) {
return 1;
}
@@ -405,8 +395,8 @@ static size_t tcg_n_regions(void)
}
/* If we can't, then just allocate one region per vCPU thread */
return max_cpus;
-}
#endif
+}
/*
* Minimum size of the code gen buffer. This number is randomly chosen,
@@ -848,7 +838,7 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)
* in practice. Multi-threaded guests share most if not all of their translated
* code, which makes parallel code generation less appealing than in softmmu.
*/
-void tcg_region_init(size_t tb_size, int splitwx)
+void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus)
{
void *buf, *aligned;
size_t size;
@@ -865,7 +855,7 @@ void tcg_region_init(size_t tb_size, int splitwx)
buf = tcg_init_ctx.code_gen_buffer;
size = tcg_init_ctx.code_gen_buffer_size;
page_size = qemu_real_host_page_size;
- n_regions = tcg_n_regions();
+ n_regions = tcg_n_regions(max_cpus);
/* The first region will be 'aligned - buf' bytes larger than the others */
aligned = QEMU_ALIGN_PTR_UP(buf, page_size);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index f13c564d9b..fcfeca232f 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -30,7 +30,7 @@
extern TCGContext **tcg_ctxs;
extern unsigned int n_tcg_ctxs;
-void tcg_region_init(size_t tb_size, int splitwx);
+void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus);
bool tcg_region_alloc(TCGContext *s);
void tcg_region_initial_alloc(TCGContext *s);
void tcg_region_prologue_set(TCGContext *s);
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 2625d9e502..5cc384e205 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -576,7 +576,7 @@ static void process_op_defs(TCGContext *s);
static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type,
TCGReg reg, const char *name);
-static void tcg_context_init(void)
+static void tcg_context_init(unsigned max_cpus)
{
TCGContext *s = &tcg_init_ctx;
int op, total_args, n, i;
@@ -645,8 +645,6 @@ static void tcg_context_init(void)
tcg_ctxs = &tcg_ctx;
n_tcg_ctxs = 1;
#else
- MachineState *ms = MACHINE(qdev_get_machine());
- unsigned int max_cpus = ms->smp.max_cpus;
tcg_ctxs = g_new(TCGContext *, max_cpus);
#endif
@@ -655,10 +653,10 @@ static void tcg_context_init(void)
cpu_env = temp_tcgv_ptr(ts);
}
-void tcg_init(size_t tb_size, int splitwx)
+void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus)
{
- tcg_context_init();
- tcg_region_init(tb_size, splitwx);
+ tcg_context_init(max_cpus);
+ tcg_region_init(tb_size, splitwx, max_cpus);
}
/*