* [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h
@ 2023-09-30 3:11 Richard Henderson
2023-09-30 3:11 ` [PATCH v2 1/2] tcg: Remove argument to tcg_prologue_init Richard Henderson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Richard Henderson @ 2023-09-30 3:11 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Supercedes: <20230923130843.3708899-1-peter.maydell@linaro.org>
("[PATCH] tcg.h: Split out runtime-only functions into tcg/runtime.h")
I thought "startup.h" was perhaps a better name than "runtime.h",
at least for the functions moved, since it's about starting up
either tcg or tcg within a new thread.
By removing the argument to tcg_prologue_init(), we can simplify
the users even further, since they no longer require TCGContext.
Adding tcg_init() seems to match the other two as a startup-y
function and allows tcg-all.c to avoid "tcg.h" as well.
r~
Richard Henderson (2):
tcg: Remove argument to tcg_prologue_init
tcg: Split out tcg init functions to tcg/startup.h
include/tcg/startup.h | 58 +++++++++++++++++++++++++++++++++
include/tcg/tcg.h | 3 --
accel/tcg/tcg-accel-ops-mttcg.c | 2 +-
accel/tcg/tcg-accel-ops-rr.c | 2 +-
accel/tcg/tcg-all.c | 4 +--
bsd-user/main.c | 4 +--
linux-user/main.c | 4 +--
linux-user/syscall.c | 2 +-
tcg/tcg.c | 4 ++-
9 files changed, 70 insertions(+), 13 deletions(-)
create mode 100644 include/tcg/startup.h
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] tcg: Remove argument to tcg_prologue_init
2023-09-30 3:11 [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h Richard Henderson
@ 2023-09-30 3:11 ` Richard Henderson
2023-09-30 3:11 ` [PATCH v2 2/2] tcg: Split out tcg init functions to tcg/startup.h Richard Henderson
2023-10-02 12:51 ` [PATCH v2 0/2] " Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-09-30 3:11 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
We can load tcg_ctx just as easily within the callee.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg.h | 2 +-
accel/tcg/tcg-all.c | 2 +-
bsd-user/main.c | 2 +-
linux-user/main.c | 2 +-
tcg/tcg.c | 3 ++-
5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index c9c6d770d0..44aced2ddd 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -785,7 +785,7 @@ static inline void *tcg_malloc(int size)
void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus);
void tcg_register_thread(void);
-void tcg_prologue_init(TCGContext *s);
+void tcg_prologue_init(void);
void tcg_func_start(TCGContext *s);
int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start);
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 03dfd67e9e..d9d8dde202 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -121,7 +121,7 @@ static int tcg_init_machine(MachineState *ms)
* There's no guest base to take into account, so go ahead and
* initialize the prologue now.
*/
- tcg_prologue_init(tcg_ctx);
+ tcg_prologue_init();
#endif
return 0;
diff --git a/bsd-user/main.c b/bsd-user/main.c
index f913cb55a7..dcdaf059bc 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -586,7 +586,7 @@ int main(int argc, char **argv)
* generating the prologue until now so that the prologue can take
* the real value of GUEST_BASE into account.
*/
- tcg_prologue_init(tcg_ctx);
+ tcg_prologue_init();
target_cpu_init(env, regs);
diff --git a/linux-user/main.c b/linux-user/main.c
index 96be354897..66962e1d4a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -994,7 +994,7 @@ int main(int argc, char **argv, char **envp)
/* Now that we've loaded the binary, GUEST_BASE is fixed. Delay
generating the prologue until now so that the prologue can take
the real value of GUEST_BASE into account. */
- tcg_prologue_init(tcg_ctx);
+ tcg_prologue_init();
target_cpu_copy_regs(env, regs);
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 604fa9bf3e..4ec4f34b93 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1387,8 +1387,9 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s)
return tb;
}
-void tcg_prologue_init(TCGContext *s)
+void tcg_prologue_init(void)
{
+ TCGContext *s = tcg_ctx;
size_t prologue_size;
s->code_ptr = s->code_gen_ptr;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] tcg: Split out tcg init functions to tcg/startup.h
2023-09-30 3:11 [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h Richard Henderson
2023-09-30 3:11 ` [PATCH v2 1/2] tcg: Remove argument to tcg_prologue_init Richard Henderson
@ 2023-09-30 3:11 ` Richard Henderson
2023-10-02 12:51 ` [PATCH v2 0/2] " Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-09-30 3:11 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
The tcg/tcg.h header is a big bucket, containing stuff related to
the translators and the JIT backend. The places that initialize
tcg or create new threads do not need all of that, so split out
these three functions to a new header.
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/startup.h | 58 +++++++++++++++++++++++++++++++++
include/tcg/tcg.h | 3 --
accel/tcg/tcg-accel-ops-mttcg.c | 2 +-
accel/tcg/tcg-accel-ops-rr.c | 2 +-
accel/tcg/tcg-all.c | 2 +-
bsd-user/main.c | 2 +-
linux-user/main.c | 2 +-
linux-user/syscall.c | 2 +-
tcg/tcg.c | 1 +
9 files changed, 65 insertions(+), 9 deletions(-)
create mode 100644 include/tcg/startup.h
diff --git a/include/tcg/startup.h b/include/tcg/startup.h
new file mode 100644
index 0000000000..f71305765c
--- /dev/null
+++ b/include/tcg/startup.h
@@ -0,0 +1,58 @@
+/*
+ * Tiny Code Generator for QEMU: definitions used by runtime startup
+ *
+ * Copyright (c) 2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef TCG_STARTUP_H
+#define TCG_STARTUP_H
+
+/**
+ * tcg_init: Initialize the TCG runtime
+ * @tb_size: translation buffer size
+ * @splitwx: use separate rw and rx mappings
+ * @max_cpus: number of vcpus in system mode
+ *
+ * Allocate and initialize TCG resources, especially the JIT buffer.
+ * In user-only mode, @max_cpus is unused.
+ */
+void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus);
+
+/**
+ * tcg_register_thread: Register this thread with the TCG runtime
+ *
+ * All TCG threads except the parent (i.e. the one that called the TCG
+ * accelerator's init_machine() method) must register with this
+ * function before initiating translation.
+ */
+void tcg_register_thread(void);
+
+/**
+ * tcg_prologue_init(): Generate the code for the TCG prologue
+ *
+ * In softmmu this is done automatically as part of the TCG
+ * accelerator's init_machine() method, but for user-mode, the
+ * user-mode code must call this function after it has loaded
+ * the guest binary and the value of guest_base is known.
+ */
+void tcg_prologue_init(void);
+
+#endif
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 44aced2ddd..3e45ee26fe 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -783,9 +783,6 @@ static inline void *tcg_malloc(int size)
}
}
-void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus);
-void tcg_register_thread(void);
-void tcg_prologue_init(void);
void tcg_func_start(TCGContext *s);
int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start);
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index 4b0dfb4be7..aed919d10b 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -32,7 +32,7 @@
#include "qemu/guest-random.h"
#include "exec/exec-all.h"
#include "hw/boards.h"
-#include "tcg/tcg.h"
+#include "tcg/startup.h"
#include "tcg-accel-ops.h"
#include "tcg-accel-ops-mttcg.h"
diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 2d523289a8..7c530d3cda 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -32,7 +32,7 @@
#include "qemu/notify.h"
#include "qemu/guest-random.h"
#include "exec/exec-all.h"
-#include "tcg/tcg.h"
+#include "tcg/startup.h"
#include "tcg-accel-ops.h"
#include "tcg-accel-ops-rr.h"
#include "tcg-accel-ops-icount.h"
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index d9d8dde202..a95c0bfe6d 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -27,7 +27,7 @@
#include "sysemu/tcg.h"
#include "exec/replay-core.h"
#include "sysemu/cpu-timers.h"
-#include "tcg/tcg.h"
+#include "tcg/startup.h"
#include "tcg/oversized-guest.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
diff --git a/bsd-user/main.c b/bsd-user/main.c
index dcdaf059bc..e72beaaa29 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -36,7 +36,7 @@
#include "qemu/help_option.h"
#include "qemu/module.h"
#include "exec/exec-all.h"
-#include "tcg/tcg.h"
+#include "tcg/startup.h"
#include "qemu/timer.h"
#include "qemu/envlist.h"
#include "qemu/cutils.h"
diff --git a/linux-user/main.c b/linux-user/main.c
index 66962e1d4a..b0501996c7 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -41,7 +41,7 @@
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/user.h"
-#include "tcg/tcg.h"
+#include "tcg/startup.h"
#include "qemu/timer.h"
#include "qemu/envlist.h"
#include "qemu/guest-random.h"
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3521a2d70b..c6ffadd082 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -23,6 +23,7 @@
#include "qemu/memfd.h"
#include "qemu/queue.h"
#include "qemu/plugin.h"
+#include "tcg/startup.h"
#include "target_mman.h"
#include <elf.h>
#include <endian.h>
@@ -141,7 +142,6 @@
#include "special-errno.h"
#include "qapi/error.h"
#include "fd-trans.h"
-#include "tcg/tcg.h"
#include "cpu_loop-common.h"
#ifndef CLONE_IO
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 4ec4f34b93..87006496a9 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -36,6 +36,7 @@
#include "qemu/timer.h"
#include "exec/translation-block.h"
#include "exec/tlb-common.h"
+#include "tcg/startup.h"
#include "tcg/tcg-op-common.h"
#if UINTPTR_MAX == UINT32_MAX
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h
2023-09-30 3:11 [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h Richard Henderson
2023-09-30 3:11 ` [PATCH v2 1/2] tcg: Remove argument to tcg_prologue_init Richard Henderson
2023-09-30 3:11 ` [PATCH v2 2/2] tcg: Split out tcg init functions to tcg/startup.h Richard Henderson
@ 2023-10-02 12:51 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-02 12:51 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: peter.maydell
On 30/9/23 05:11, Richard Henderson wrote:
> Supercedes: <20230923130843.3708899-1-peter.maydell@linaro.org>
> ("[PATCH] tcg.h: Split out runtime-only functions into tcg/runtime.h")
>
> I thought "startup.h" was perhaps a better name than "runtime.h",
> at least for the functions moved, since it's about starting up
> either tcg or tcg within a new thread.
>
> By removing the argument to tcg_prologue_init(), we can simplify
> the users even further, since they no longer require TCGContext.
>
> Adding tcg_init() seems to match the other two as a startup-y
> function and allows tcg-all.c to avoid "tcg.h" as well.
>
>
> r~
>
>
> Richard Henderson (2):
> tcg: Remove argument to tcg_prologue_init
> tcg: Split out tcg init functions to tcg/startup.h
Series:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-02 12:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-30 3:11 [PATCH v2 0/2] Split out tcg init functions to tcg/startup.h Richard Henderson
2023-09-30 3:11 ` [PATCH v2 1/2] tcg: Remove argument to tcg_prologue_init Richard Henderson
2023-09-30 3:11 ` [PATCH v2 2/2] tcg: Split out tcg init functions to tcg/startup.h Richard Henderson
2023-10-02 12:51 ` [PATCH v2 0/2] " Philippe Mathieu-Daudé
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).