1 | The following changes since commit 2ecfc0657afa5d29a373271b342f704a1a3c6737: | 1 | The following changes since commit 9c6c079bc6723da8061ccfb44361d67b1dd785dd: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-misc-2020-12-10' into staging (2020-12-10 17:01:05 +0000) | 3 | Merge tag 'pull-target-arm-20240430' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2024-04-30 09:58:54 -0700) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20201210 | 7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20240501 |
8 | 8 | ||
9 | for you to fetch changes up to 9e2658d62ebc23efe7df43fc0e306f129510d874: | 9 | for you to fetch changes up to 917d7f8d948d706e275c9f33169b9dd0149ded1e: |
10 | 10 | ||
11 | accel/tcg: rename tcg-cpus functions to match module name (2020-12-10 17:44:10 -0600) | 11 | plugins: Update the documentation block for plugin-gen.c (2024-04-30 16:12:05 -0700) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Split CpusAccel for tcg variants | 14 | plugins: Rewrite plugin tcg expansion |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Claudio Fontana (3): | 17 | Richard Henderson (20): |
18 | accel/tcg: split CpusAccel into three TCG variants | 18 | tcg: Make tcg/helper-info.h self-contained |
19 | accel/tcg: split tcg_start_vcpu_thread | 19 | tcg: Pass function pointer to tcg_gen_call* |
20 | accel/tcg: rename tcg-cpus functions to match module name | 20 | plugins: Zero new qemu_plugin_dyn_cb entries |
21 | plugins: Move function pointer in qemu_plugin_dyn_cb | ||
22 | plugins: Create TCGHelperInfo for all out-of-line callbacks | ||
23 | plugins: Use emit_before_op for PLUGIN_GEN_AFTER_INSN | ||
24 | plugins: Use emit_before_op for PLUGIN_GEN_FROM_TB | ||
25 | plugins: Add PLUGIN_GEN_AFTER_TB | ||
26 | plugins: Use emit_before_op for PLUGIN_GEN_FROM_INSN | ||
27 | plugins: Use emit_before_op for PLUGIN_GEN_FROM_MEM | ||
28 | plugins: Remove plugin helpers | ||
29 | tcg: Remove TCG_CALL_PLUGIN | ||
30 | tcg: Remove INDEX_op_plugin_cb_{start,end} | ||
31 | plugins: Simplify callback queues | ||
32 | plugins: Introduce PLUGIN_CB_MEM_REGULAR | ||
33 | plugins: Replace pr_ops with a proper debug dump flag | ||
34 | plugins: Split out common cb expanders | ||
35 | plugins: Merge qemu_plugin_tb_insn_get to plugin-gen.c | ||
36 | plugins: Inline plugin_gen_empty_callback | ||
37 | plugins: Update the documentation block for plugin-gen.c | ||
21 | 38 | ||
22 | accel/tcg/tcg-cpus-icount.h | 17 ++ | 39 | accel/tcg/plugin-helpers.h | 5 - |
23 | accel/tcg/tcg-cpus-rr.h | 21 ++ | 40 | include/exec/helper-gen-common.h | 4 - |
24 | accel/tcg/tcg-cpus.h | 12 +- | 41 | include/exec/helper-proto-common.h | 4 - |
25 | accel/tcg/tcg-all.c | 13 +- | 42 | include/exec/plugin-gen.h | 4 - |
26 | accel/tcg/tcg-cpus-icount.c | 147 +++++++++++++ | 43 | include/qemu/log.h | 1 + |
27 | accel/tcg/tcg-cpus-mttcg.c | 140 ++++++++++++ | 44 | include/qemu/plugin.h | 67 +-- |
28 | accel/tcg/tcg-cpus-rr.c | 305 ++++++++++++++++++++++++++ | 45 | include/tcg/helper-info.h | 3 + |
29 | accel/tcg/tcg-cpus.c | 506 +------------------------------------------- | 46 | include/tcg/tcg-op-common.h | 4 +- |
30 | softmmu/icount.c | 2 +- | 47 | include/tcg/tcg-opc.h | 4 +- |
31 | accel/tcg/meson.build | 9 +- | 48 | include/tcg/tcg.h | 26 +- |
32 | 10 files changed, 670 insertions(+), 502 deletions(-) | 49 | include/exec/helper-gen.h.inc | 24 +- |
33 | create mode 100644 accel/tcg/tcg-cpus-icount.h | 50 | accel/tcg/plugin-gen.c | 1007 +++++++++--------------------------- |
34 | create mode 100644 accel/tcg/tcg-cpus-rr.h | 51 | plugins/api.c | 26 +- |
35 | create mode 100644 accel/tcg/tcg-cpus-icount.c | 52 | plugins/core.c | 61 ++- |
36 | create mode 100644 accel/tcg/tcg-cpus-mttcg.c | 53 | tcg/tcg-op-ldst.c | 6 +- |
37 | create mode 100644 accel/tcg/tcg-cpus-rr.c | 54 | tcg/tcg-op.c | 8 +- |
38 | 55 | tcg/tcg.c | 78 ++- | |
56 | tcg/tci.c | 1 + | ||
57 | util/log.c | 4 + | ||
58 | 19 files changed, 399 insertions(+), 938 deletions(-) | ||
59 | delete mode 100644 accel/tcg/plugin-helpers.h | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Move MAX_CALL_IARGS from tcg.h and include for | ||
2 | the define of TCG_TARGET_REG_BITS. | ||
1 | 3 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | include/tcg/helper-info.h | 3 +++ | ||
9 | include/tcg/tcg.h | 2 -- | ||
10 | tcg/tci.c | 1 + | ||
11 | 3 files changed, 4 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/include/tcg/helper-info.h b/include/tcg/helper-info.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/include/tcg/helper-info.h | ||
16 | +++ b/include/tcg/helper-info.h | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | #ifdef CONFIG_TCG_INTERPRETER | ||
19 | #include <ffi.h> | ||
20 | #endif | ||
21 | +#include "tcg-target-reg-bits.h" | ||
22 | + | ||
23 | +#define MAX_CALL_IARGS 7 | ||
24 | |||
25 | /* | ||
26 | * Describe the calling convention of a given argument type. | ||
27 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/tcg/tcg.h | ||
30 | +++ b/include/tcg/tcg.h | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | /* XXX: make safe guess about sizes */ | ||
33 | #define MAX_OP_PER_INSTR 266 | ||
34 | |||
35 | -#define MAX_CALL_IARGS 7 | ||
36 | - | ||
37 | #define CPU_TEMP_BUF_NLONGS 128 | ||
38 | #define TCG_STATIC_FRAME_SIZE (CPU_TEMP_BUF_NLONGS * sizeof(long)) | ||
39 | |||
40 | diff --git a/tcg/tci.c b/tcg/tci.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/tcg/tci.c | ||
43 | +++ b/tcg/tci.c | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | |||
46 | #include "qemu/osdep.h" | ||
47 | #include "tcg/tcg.h" | ||
48 | +#include "tcg/helper-info.h" | ||
49 | #include "tcg/tcg-ldst.h" | ||
50 | #include <ffi.h> | ||
51 | |||
52 | -- | ||
53 | 2.34.1 | ||
54 | |||
55 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | For normal helpers, read the function pointer from the | |
2 | structure earlier. For plugins, this will allow the | ||
3 | function pointer to come from elsewhere. | ||
4 | |||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | --- | ||
9 | include/tcg/tcg.h | 21 +++++++++------- | ||
10 | include/exec/helper-gen.h.inc | 24 ++++++++++++------- | ||
11 | tcg/tcg.c | 45 +++++++++++++++++++---------------- | ||
12 | 3 files changed, 52 insertions(+), 38 deletions(-) | ||
13 | |||
14 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/tcg/tcg.h | ||
17 | +++ b/include/tcg/tcg.h | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct TCGTargetOpDef { | ||
19 | |||
20 | bool tcg_op_supported(TCGOpcode op); | ||
21 | |||
22 | -void tcg_gen_call0(TCGHelperInfo *, TCGTemp *ret); | ||
23 | -void tcg_gen_call1(TCGHelperInfo *, TCGTemp *ret, TCGTemp *); | ||
24 | -void tcg_gen_call2(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, TCGTemp *); | ||
25 | -void tcg_gen_call3(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, | ||
26 | +void tcg_gen_call0(void *func, TCGHelperInfo *, TCGTemp *ret); | ||
27 | +void tcg_gen_call1(void *func, TCGHelperInfo *, TCGTemp *ret, TCGTemp *); | ||
28 | +void tcg_gen_call2(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
29 | TCGTemp *, TCGTemp *); | ||
30 | -void tcg_gen_call4(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, TCGTemp *, | ||
31 | - TCGTemp *, TCGTemp *); | ||
32 | -void tcg_gen_call5(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, TCGTemp *, | ||
33 | +void tcg_gen_call3(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
34 | TCGTemp *, TCGTemp *, TCGTemp *); | ||
35 | -void tcg_gen_call6(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, TCGTemp *, | ||
36 | +void tcg_gen_call4(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
37 | TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *); | ||
38 | -void tcg_gen_call7(TCGHelperInfo *, TCGTemp *ret, TCGTemp *, TCGTemp *, | ||
39 | +void tcg_gen_call5(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
40 | TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *); | ||
41 | +void tcg_gen_call6(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
42 | + TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *, | ||
43 | + TCGTemp *, TCGTemp *); | ||
44 | +void tcg_gen_call7(void *func, TCGHelperInfo *, TCGTemp *ret, | ||
45 | + TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *, | ||
46 | + TCGTemp *, TCGTemp *, TCGTemp *); | ||
47 | |||
48 | TCGOp *tcg_emit_op(TCGOpcode opc, unsigned nargs); | ||
49 | void tcg_op_remove(TCGContext *s, TCGOp *op); | ||
50 | diff --git a/include/exec/helper-gen.h.inc b/include/exec/helper-gen.h.inc | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/include/exec/helper-gen.h.inc | ||
53 | +++ b/include/exec/helper-gen.h.inc | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | extern TCGHelperInfo glue(helper_info_, name); \ | ||
56 | static inline void glue(gen_helper_, name)(dh_retvar_decl0(ret)) \ | ||
57 | { \ | ||
58 | - tcg_gen_call0(&glue(helper_info_, name), dh_retvar(ret)); \ | ||
59 | + tcg_gen_call0(glue(helper_info_,name).func, \ | ||
60 | + &glue(helper_info_,name), dh_retvar(ret)); \ | ||
61 | } | ||
62 | |||
63 | #define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \ | ||
64 | @@ -XXX,XX +XXX,XX @@ extern TCGHelperInfo glue(helper_info_, name); \ | ||
65 | static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
66 | dh_arg_decl(t1, 1)) \ | ||
67 | { \ | ||
68 | - tcg_gen_call1(&glue(helper_info_, name), dh_retvar(ret), \ | ||
69 | + tcg_gen_call1(glue(helper_info_,name).func, \ | ||
70 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
71 | dh_arg(t1, 1)); \ | ||
72 | } | ||
73 | |||
74 | @@ -XXX,XX +XXX,XX @@ extern TCGHelperInfo glue(helper_info_, name); \ | ||
75 | static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
76 | dh_arg_decl(t1, 1), dh_arg_decl(t2, 2)) \ | ||
77 | { \ | ||
78 | - tcg_gen_call2(&glue(helper_info_, name), dh_retvar(ret), \ | ||
79 | + tcg_gen_call2(glue(helper_info_,name).func, \ | ||
80 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
81 | dh_arg(t1, 1), dh_arg(t2, 2)); \ | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ extern TCGHelperInfo glue(helper_info_, name); \ | ||
85 | static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
86 | dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3)) \ | ||
87 | { \ | ||
88 | - tcg_gen_call3(&glue(helper_info_, name), dh_retvar(ret), \ | ||
89 | + tcg_gen_call3(glue(helper_info_,name).func, \ | ||
90 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
91 | dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3)); \ | ||
92 | } | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
95 | dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), \ | ||
96 | dh_arg_decl(t3, 3), dh_arg_decl(t4, 4)) \ | ||
97 | { \ | ||
98 | - tcg_gen_call4(&glue(helper_info_, name), dh_retvar(ret), \ | ||
99 | + tcg_gen_call4(glue(helper_info_,name).func, \ | ||
100 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
101 | dh_arg(t1, 1), dh_arg(t2, 2), \ | ||
102 | dh_arg(t3, 3), dh_arg(t4, 4)); \ | ||
103 | } | ||
104 | @@ -XXX,XX +XXX,XX @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
105 | dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), \ | ||
106 | dh_arg_decl(t4, 4), dh_arg_decl(t5, 5)) \ | ||
107 | { \ | ||
108 | - tcg_gen_call5(&glue(helper_info_, name), dh_retvar(ret), \ | ||
109 | + tcg_gen_call5(glue(helper_info_,name).func, \ | ||
110 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
111 | dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \ | ||
112 | dh_arg(t4, 4), dh_arg(t5, 5)); \ | ||
113 | } | ||
114 | @@ -XXX,XX +XXX,XX @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
115 | dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), \ | ||
116 | dh_arg_decl(t4, 4), dh_arg_decl(t5, 5), dh_arg_decl(t6, 6)) \ | ||
117 | { \ | ||
118 | - tcg_gen_call6(&glue(helper_info_, name), dh_retvar(ret), \ | ||
119 | + tcg_gen_call6(glue(helper_info_,name).func, \ | ||
120 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
121 | dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \ | ||
122 | dh_arg(t4, 4), dh_arg(t5, 5), dh_arg(t6, 6)); \ | ||
123 | } | ||
124 | @@ -XXX,XX +XXX,XX @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
125 | dh_arg_decl(t4, 4), dh_arg_decl(t5, 5), dh_arg_decl(t6, 6), \ | ||
126 | dh_arg_decl(t7, 7)) \ | ||
127 | { \ | ||
128 | - tcg_gen_call7(&glue(helper_info_, name), dh_retvar(ret), \ | ||
129 | + tcg_gen_call7(glue(helper_info_,name).func, \ | ||
130 | + &glue(helper_info_,name), dh_retvar(ret), \ | ||
131 | dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \ | ||
132 | dh_arg(t4, 4), dh_arg(t5, 5), dh_arg(t6, 6), \ | ||
133 | dh_arg(t7, 7)); \ | ||
134 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/tcg/tcg.c | ||
137 | +++ b/tcg/tcg.c | ||
138 | @@ -XXX,XX +XXX,XX @@ bool tcg_op_supported(TCGOpcode op) | ||
139 | |||
140 | static TCGOp *tcg_op_alloc(TCGOpcode opc, unsigned nargs); | ||
141 | |||
142 | -static void tcg_gen_callN(TCGHelperInfo *info, TCGTemp *ret, TCGTemp **args) | ||
143 | +static void tcg_gen_callN(void *func, TCGHelperInfo *info, | ||
144 | + TCGTemp *ret, TCGTemp **args) | ||
145 | { | ||
146 | TCGv_i64 extend_free[MAX_CALL_IARGS]; | ||
147 | int n_extend = 0; | ||
148 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_callN(TCGHelperInfo *info, TCGTemp *ret, TCGTemp **args) | ||
149 | g_assert_not_reached(); | ||
150 | } | ||
151 | } | ||
152 | - op->args[pi++] = (uintptr_t)info->func; | ||
153 | + op->args[pi++] = (uintptr_t)func; | ||
154 | op->args[pi++] = (uintptr_t)info; | ||
155 | tcg_debug_assert(pi == total_args); | ||
156 | |||
157 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_callN(TCGHelperInfo *info, TCGTemp *ret, TCGTemp **args) | ||
158 | } | ||
159 | } | ||
160 | |||
161 | -void tcg_gen_call0(TCGHelperInfo *info, TCGTemp *ret) | ||
162 | +void tcg_gen_call0(void *func, TCGHelperInfo *info, TCGTemp *ret) | ||
163 | { | ||
164 | - tcg_gen_callN(info, ret, NULL); | ||
165 | + tcg_gen_callN(func, info, ret, NULL); | ||
166 | } | ||
167 | |||
168 | -void tcg_gen_call1(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1) | ||
169 | +void tcg_gen_call1(void *func, TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1) | ||
170 | { | ||
171 | - tcg_gen_callN(info, ret, &t1); | ||
172 | + tcg_gen_callN(func, info, ret, &t1); | ||
173 | } | ||
174 | |||
175 | -void tcg_gen_call2(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, TCGTemp *t2) | ||
176 | +void tcg_gen_call2(void *func, TCGHelperInfo *info, TCGTemp *ret, | ||
177 | + TCGTemp *t1, TCGTemp *t2) | ||
178 | { | ||
179 | TCGTemp *args[2] = { t1, t2 }; | ||
180 | - tcg_gen_callN(info, ret, args); | ||
181 | + tcg_gen_callN(func, info, ret, args); | ||
182 | } | ||
183 | |||
184 | -void tcg_gen_call3(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
185 | - TCGTemp *t2, TCGTemp *t3) | ||
186 | +void tcg_gen_call3(void *func, TCGHelperInfo *info, TCGTemp *ret, | ||
187 | + TCGTemp *t1, TCGTemp *t2, TCGTemp *t3) | ||
188 | { | ||
189 | TCGTemp *args[3] = { t1, t2, t3 }; | ||
190 | - tcg_gen_callN(info, ret, args); | ||
191 | + tcg_gen_callN(func, info, ret, args); | ||
192 | } | ||
193 | |||
194 | -void tcg_gen_call4(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
195 | - TCGTemp *t2, TCGTemp *t3, TCGTemp *t4) | ||
196 | +void tcg_gen_call4(void *func, TCGHelperInfo *info, TCGTemp *ret, | ||
197 | + TCGTemp *t1, TCGTemp *t2, TCGTemp *t3, TCGTemp *t4) | ||
198 | { | ||
199 | TCGTemp *args[4] = { t1, t2, t3, t4 }; | ||
200 | - tcg_gen_callN(info, ret, args); | ||
201 | + tcg_gen_callN(func, info, ret, args); | ||
202 | } | ||
203 | |||
204 | -void tcg_gen_call5(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
205 | +void tcg_gen_call5(void *func, TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
206 | TCGTemp *t2, TCGTemp *t3, TCGTemp *t4, TCGTemp *t5) | ||
207 | { | ||
208 | TCGTemp *args[5] = { t1, t2, t3, t4, t5 }; | ||
209 | - tcg_gen_callN(info, ret, args); | ||
210 | + tcg_gen_callN(func, info, ret, args); | ||
211 | } | ||
212 | |||
213 | -void tcg_gen_call6(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, TCGTemp *t2, | ||
214 | - TCGTemp *t3, TCGTemp *t4, TCGTemp *t5, TCGTemp *t6) | ||
215 | +void tcg_gen_call6(void *func, TCGHelperInfo *info, TCGTemp *ret, | ||
216 | + TCGTemp *t1, TCGTemp *t2, TCGTemp *t3, | ||
217 | + TCGTemp *t4, TCGTemp *t5, TCGTemp *t6) | ||
218 | { | ||
219 | TCGTemp *args[6] = { t1, t2, t3, t4, t5, t6 }; | ||
220 | - tcg_gen_callN(info, ret, args); | ||
221 | + tcg_gen_callN(func, info, ret, args); | ||
222 | } | ||
223 | |||
224 | -void tcg_gen_call7(TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
225 | +void tcg_gen_call7(void *func, TCGHelperInfo *info, TCGTemp *ret, TCGTemp *t1, | ||
226 | TCGTemp *t2, TCGTemp *t3, TCGTemp *t4, | ||
227 | TCGTemp *t5, TCGTemp *t6, TCGTemp *t7) | ||
228 | { | ||
229 | TCGTemp *args[7] = { t1, t2, t3, t4, t5, t6, t7 }; | ||
230 | - tcg_gen_callN(info, ret, args); | ||
231 | + tcg_gen_callN(func, info, ret, args); | ||
232 | } | ||
233 | |||
234 | static void tcg_reg_alloc_start(TCGContext *s) | ||
235 | -- | ||
236 | 2.34.1 | ||
237 | |||
238 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | --- | ||
4 | plugins/core.c | 2 +- | ||
5 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
1 | 6 | ||
7 | diff --git a/plugins/core.c b/plugins/core.c | ||
8 | index XXXXXXX..XXXXXXX 100644 | ||
9 | --- a/plugins/core.c | ||
10 | +++ b/plugins/core.c | ||
11 | @@ -XXX,XX +XXX,XX @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) | ||
12 | GArray *cbs = *arr; | ||
13 | |||
14 | if (!cbs) { | ||
15 | - cbs = g_array_sized_new(false, false, | ||
16 | + cbs = g_array_sized_new(false, true, | ||
17 | sizeof(struct qemu_plugin_dyn_cb), 1); | ||
18 | *arr = cbs; | ||
19 | } | ||
20 | -- | ||
21 | 2.34.1 | ||
22 | |||
23 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The out-of-line function pointer is mutually exclusive | ||
2 | with inline expansion, so move it into the union. | ||
3 | Wrap the pointer in a structure named 'regular' to match | ||
4 | PLUGIN_CB_REGULAR. | ||
1 | 5 | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | --- | ||
10 | include/qemu/plugin.h | 4 +++- | ||
11 | accel/tcg/plugin-gen.c | 4 ++-- | ||
12 | plugins/core.c | 8 ++++---- | ||
13 | 3 files changed, 9 insertions(+), 7 deletions(-) | ||
14 | |||
15 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/qemu/plugin.h | ||
18 | +++ b/include/qemu/plugin.h | ||
19 | @@ -XXX,XX +XXX,XX @@ enum plugin_dyn_cb_subtype { | ||
20 | * instance of a callback to be called upon the execution of a particular TB. | ||
21 | */ | ||
22 | struct qemu_plugin_dyn_cb { | ||
23 | - union qemu_plugin_cb_sig f; | ||
24 | void *userp; | ||
25 | enum plugin_dyn_cb_subtype type; | ||
26 | /* @rw applies to mem callbacks only (both regular and inline) */ | ||
27 | enum qemu_plugin_mem_rw rw; | ||
28 | /* fields specific to each dyn_cb type go here */ | ||
29 | union { | ||
30 | + struct { | ||
31 | + union qemu_plugin_cb_sig f; | ||
32 | + } regular; | ||
33 | struct { | ||
34 | qemu_plugin_u64 entry; | ||
35 | enum qemu_plugin_op op; | ||
36 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/accel/tcg/plugin-gen.c | ||
39 | +++ b/accel/tcg/plugin-gen.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static TCGOp *append_udata_cb(const struct qemu_plugin_dyn_cb *cb, | ||
41 | } | ||
42 | |||
43 | /* call */ | ||
44 | - op = copy_call(&begin_op, op, cb->f.vcpu_udata, cb_idx); | ||
45 | + op = copy_call(&begin_op, op, cb->regular.f.vcpu_udata, cb_idx); | ||
46 | |||
47 | return op; | ||
48 | } | ||
49 | @@ -XXX,XX +XXX,XX @@ static TCGOp *append_mem_cb(const struct qemu_plugin_dyn_cb *cb, | ||
50 | |||
51 | if (type == PLUGIN_GEN_CB_MEM) { | ||
52 | /* call */ | ||
53 | - op = copy_call(&begin_op, op, cb->f.vcpu_udata, cb_idx); | ||
54 | + op = copy_call(&begin_op, op, cb->regular.f.vcpu_udata, cb_idx); | ||
55 | } | ||
56 | |||
57 | return op; | ||
58 | diff --git a/plugins/core.c b/plugins/core.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/plugins/core.c | ||
61 | +++ b/plugins/core.c | ||
62 | @@ -XXX,XX +XXX,XX @@ void plugin_register_dyn_cb__udata(GArray **arr, | ||
63 | |||
64 | dyn_cb->userp = udata; | ||
65 | /* Note flags are discarded as unused. */ | ||
66 | - dyn_cb->f.vcpu_udata = cb; | ||
67 | + dyn_cb->regular.f.vcpu_udata = cb; | ||
68 | dyn_cb->type = PLUGIN_CB_REGULAR; | ||
69 | } | ||
70 | |||
71 | @@ -XXX,XX +XXX,XX @@ void plugin_register_vcpu_mem_cb(GArray **arr, | ||
72 | /* Note flags are discarded as unused. */ | ||
73 | dyn_cb->type = PLUGIN_CB_REGULAR; | ||
74 | dyn_cb->rw = rw; | ||
75 | - dyn_cb->f.generic = cb; | ||
76 | + dyn_cb->regular.f.vcpu_mem = cb; | ||
77 | } | ||
78 | |||
79 | /* | ||
80 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, | ||
81 | } | ||
82 | switch (cb->type) { | ||
83 | case PLUGIN_CB_REGULAR: | ||
84 | - cb->f.vcpu_mem(cpu->cpu_index, make_plugin_meminfo(oi, rw), | ||
85 | - vaddr, cb->userp); | ||
86 | + cb->regular.f.vcpu_mem(cpu->cpu_index, make_plugin_meminfo(oi, rw), | ||
87 | + vaddr, cb->userp); | ||
88 | break; | ||
89 | case PLUGIN_CB_INLINE: | ||
90 | exec_inline_op(cb, cpu->cpu_index); | ||
91 | -- | ||
92 | 2.34.1 | ||
93 | |||
94 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | TCGHelperInfo includes the ABI for every function call. | ||
1 | 2 | ||
3 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | include/qemu/plugin.h | 1 + | ||
7 | plugins/core.c | 51 ++++++++++++++++++++++++++++++++++++++----- | ||
8 | 2 files changed, 46 insertions(+), 6 deletions(-) | ||
9 | |||
10 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/include/qemu/plugin.h | ||
13 | +++ b/include/qemu/plugin.h | ||
14 | @@ -XXX,XX +XXX,XX @@ struct qemu_plugin_dyn_cb { | ||
15 | union { | ||
16 | struct { | ||
17 | union qemu_plugin_cb_sig f; | ||
18 | + TCGHelperInfo *info; | ||
19 | } regular; | ||
20 | struct { | ||
21 | qemu_plugin_u64 entry; | ||
22 | diff --git a/plugins/core.c b/plugins/core.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/plugins/core.c | ||
25 | +++ b/plugins/core.c | ||
26 | @@ -XXX,XX +XXX,XX @@ void plugin_register_dyn_cb__udata(GArray **arr, | ||
27 | enum qemu_plugin_cb_flags flags, | ||
28 | void *udata) | ||
29 | { | ||
30 | - struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr); | ||
31 | + static TCGHelperInfo info[3] = { | ||
32 | + [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, | ||
33 | + [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG | TCG_CALL_PLUGIN, | ||
34 | + [QEMU_PLUGIN_CB_RW_REGS].flags = TCG_CALL_PLUGIN, | ||
35 | + /* | ||
36 | + * Match qemu_plugin_vcpu_udata_cb_t: | ||
37 | + * void (*)(uint32_t, void *) | ||
38 | + */ | ||
39 | + [0 ... 2].typemask = (dh_typemask(void, 0) | | ||
40 | + dh_typemask(i32, 1) | | ||
41 | + dh_typemask(ptr, 2)) | ||
42 | + }; | ||
43 | |||
44 | + struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr); | ||
45 | dyn_cb->userp = udata; | ||
46 | - /* Note flags are discarded as unused. */ | ||
47 | - dyn_cb->regular.f.vcpu_udata = cb; | ||
48 | dyn_cb->type = PLUGIN_CB_REGULAR; | ||
49 | + dyn_cb->regular.f.vcpu_udata = cb; | ||
50 | + | ||
51 | + assert((unsigned)flags < ARRAY_SIZE(info)); | ||
52 | + dyn_cb->regular.info = &info[flags]; | ||
53 | } | ||
54 | |||
55 | void plugin_register_vcpu_mem_cb(GArray **arr, | ||
56 | @@ -XXX,XX +XXX,XX @@ void plugin_register_vcpu_mem_cb(GArray **arr, | ||
57 | enum qemu_plugin_mem_rw rw, | ||
58 | void *udata) | ||
59 | { | ||
60 | - struct qemu_plugin_dyn_cb *dyn_cb; | ||
61 | + /* | ||
62 | + * Expect that the underlying type for enum qemu_plugin_meminfo_t | ||
63 | + * is either int32_t or uint32_t, aka int or unsigned int. | ||
64 | + */ | ||
65 | + QEMU_BUILD_BUG_ON( | ||
66 | + !__builtin_types_compatible_p(qemu_plugin_meminfo_t, uint32_t) && | ||
67 | + !__builtin_types_compatible_p(qemu_plugin_meminfo_t, int32_t)); | ||
68 | |||
69 | - dyn_cb = plugin_get_dyn_cb(arr); | ||
70 | + static TCGHelperInfo info[3] = { | ||
71 | + [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, | ||
72 | + [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG | TCG_CALL_PLUGIN, | ||
73 | + [QEMU_PLUGIN_CB_RW_REGS].flags = TCG_CALL_PLUGIN, | ||
74 | + /* | ||
75 | + * Match qemu_plugin_vcpu_mem_cb_t: | ||
76 | + * void (*)(uint32_t, qemu_plugin_meminfo_t, uint64_t, void *) | ||
77 | + */ | ||
78 | + [0 ... 2].typemask = | ||
79 | + (dh_typemask(void, 0) | | ||
80 | + dh_typemask(i32, 1) | | ||
81 | + (__builtin_types_compatible_p(qemu_plugin_meminfo_t, uint32_t) | ||
82 | + ? dh_typemask(i32, 2) : dh_typemask(s32, 2)) | | ||
83 | + dh_typemask(i64, 3) | | ||
84 | + dh_typemask(ptr, 4)) | ||
85 | + }; | ||
86 | + | ||
87 | + struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr); | ||
88 | dyn_cb->userp = udata; | ||
89 | - /* Note flags are discarded as unused. */ | ||
90 | dyn_cb->type = PLUGIN_CB_REGULAR; | ||
91 | dyn_cb->rw = rw; | ||
92 | dyn_cb->regular.f.vcpu_mem = cb; | ||
93 | + | ||
94 | + assert((unsigned)flags < ARRAY_SIZE(info)); | ||
95 | + dyn_cb->regular.info = &info[flags]; | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | -- | ||
100 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Introduce a new plugin_cb op and migrate one operation. | ||
2 | By using emit_before_op, we do not need to emit opcodes | ||
3 | early and modify them later -- we can simply emit the | ||
4 | final set of opcodes once. | ||
1 | 5 | ||
6 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | --- | ||
9 | include/tcg/tcg-op-common.h | 1 + | ||
10 | include/tcg/tcg-opc.h | 1 + | ||
11 | accel/tcg/plugin-gen.c | 74 +++++++++++++++++++++---------------- | ||
12 | tcg/tcg-op.c | 5 +++ | ||
13 | 4 files changed, 50 insertions(+), 31 deletions(-) | ||
14 | |||
15 | diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/tcg/tcg-op-common.h | ||
18 | +++ b/include/tcg/tcg-op-common.h | ||
19 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_goto_tb(unsigned idx); | ||
20 | */ | ||
21 | void tcg_gen_lookup_and_goto_ptr(void); | ||
22 | |||
23 | +void tcg_gen_plugin_cb(unsigned from); | ||
24 | void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr); | ||
25 | void tcg_gen_plugin_cb_end(void); | ||
26 | |||
27 | diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/tcg/tcg-opc.h | ||
30 | +++ b/include/tcg/tcg-opc.h | ||
31 | @@ -XXX,XX +XXX,XX @@ DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
32 | DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
33 | DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
34 | |||
35 | +DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT) | ||
36 | DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) | ||
37 | DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) | ||
38 | |||
39 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/accel/tcg/plugin-gen.c | ||
42 | +++ b/accel/tcg/plugin-gen.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
44 | { | ||
45 | switch (from) { | ||
46 | case PLUGIN_GEN_AFTER_INSN: | ||
47 | - gen_wrapped(from, PLUGIN_GEN_DISABLE_MEM_HELPER, | ||
48 | - gen_empty_mem_helper); | ||
49 | + tcg_gen_plugin_cb(from); | ||
50 | break; | ||
51 | case PLUGIN_GEN_FROM_INSN: | ||
52 | /* | ||
53 | @@ -XXX,XX +XXX,XX @@ static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, | ||
54 | inject_mem_helper(begin_op, arr); | ||
55 | } | ||
56 | |||
57 | -static void inject_mem_disable_helper(struct qemu_plugin_insn *plugin_insn, | ||
58 | - TCGOp *begin_op) | ||
59 | -{ | ||
60 | - if (likely(!plugin_insn->mem_helper)) { | ||
61 | - rm_ops(begin_op); | ||
62 | - return; | ||
63 | - } | ||
64 | - inject_mem_helper(begin_op, NULL); | ||
65 | -} | ||
66 | - | ||
67 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ | ||
68 | void plugin_gen_disable_mem_helpers(void) | ||
69 | { | ||
70 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
71 | inject_mem_enable_helper(ptb, insn, begin_op); | ||
72 | } | ||
73 | |||
74 | -static void plugin_gen_disable_mem_helper(struct qemu_plugin_tb *ptb, | ||
75 | - TCGOp *begin_op, int insn_idx) | ||
76 | +static void gen_disable_mem_helper(struct qemu_plugin_tb *ptb, | ||
77 | + struct qemu_plugin_insn *insn) | ||
78 | { | ||
79 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
80 | - inject_mem_disable_helper(insn, begin_op); | ||
81 | + if (insn->mem_helper) { | ||
82 | + tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, | ||
83 | + offsetof(CPUState, plugin_mem_cbs) - | ||
84 | + offsetof(ArchCPU, env)); | ||
85 | + } | ||
86 | } | ||
87 | |||
88 | /* #define DEBUG_PLUGIN_GEN_OPS */ | ||
89 | @@ -XXX,XX +XXX,XX @@ static void pr_ops(void) | ||
90 | |||
91 | static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
92 | { | ||
93 | - TCGOp *op; | ||
94 | + TCGOp *op, *next; | ||
95 | int insn_idx = -1; | ||
96 | |||
97 | pr_ops(); | ||
98 | |||
99 | - QTAILQ_FOREACH(op, &tcg_ctx->ops, link) { | ||
100 | + /* | ||
101 | + * While injecting code, we cannot afford to reuse any ebb temps | ||
102 | + * that might be live within the existing opcode stream. | ||
103 | + * The simplest solution is to release them all and create new. | ||
104 | + */ | ||
105 | + memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps)); | ||
106 | + | ||
107 | + QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) { | ||
108 | switch (op->opc) { | ||
109 | case INDEX_op_insn_start: | ||
110 | insn_idx++; | ||
111 | break; | ||
112 | + | ||
113 | + case INDEX_op_plugin_cb: | ||
114 | + { | ||
115 | + enum plugin_gen_from from = op->args[0]; | ||
116 | + struct qemu_plugin_insn *insn = NULL; | ||
117 | + | ||
118 | + if (insn_idx >= 0) { | ||
119 | + insn = g_ptr_array_index(plugin_tb->insns, insn_idx); | ||
120 | + } | ||
121 | + | ||
122 | + tcg_ctx->emit_before_op = op; | ||
123 | + | ||
124 | + switch (from) { | ||
125 | + case PLUGIN_GEN_AFTER_INSN: | ||
126 | + assert(insn != NULL); | ||
127 | + gen_disable_mem_helper(plugin_tb, insn); | ||
128 | + break; | ||
129 | + default: | ||
130 | + g_assert_not_reached(); | ||
131 | + } | ||
132 | + | ||
133 | + tcg_ctx->emit_before_op = NULL; | ||
134 | + tcg_op_remove(tcg_ctx, op); | ||
135 | + break; | ||
136 | + } | ||
137 | + | ||
138 | case INDEX_op_plugin_cb_start: | ||
139 | { | ||
140 | enum plugin_gen_from from = op->args[0]; | ||
141 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
142 | |||
143 | break; | ||
144 | } | ||
145 | - case PLUGIN_GEN_AFTER_INSN: | ||
146 | - { | ||
147 | - g_assert(insn_idx >= 0); | ||
148 | - | ||
149 | - switch (type) { | ||
150 | - case PLUGIN_GEN_DISABLE_MEM_HELPER: | ||
151 | - plugin_gen_disable_mem_helper(plugin_tb, op, insn_idx); | ||
152 | - break; | ||
153 | - default: | ||
154 | - g_assert_not_reached(); | ||
155 | - } | ||
156 | - break; | ||
157 | - } | ||
158 | default: | ||
159 | g_assert_not_reached(); | ||
160 | } | ||
161 | diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/tcg/tcg-op.c | ||
164 | +++ b/tcg/tcg-op.c | ||
165 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_mb(TCGBar mb_type) | ||
166 | } | ||
167 | } | ||
168 | |||
169 | +void tcg_gen_plugin_cb(unsigned from) | ||
170 | +{ | ||
171 | + tcg_gen_op1(INDEX_op_plugin_cb, from); | ||
172 | +} | ||
173 | + | ||
174 | void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr) | ||
175 | { | ||
176 | tcg_gen_op3(INDEX_op_plugin_cb_start, from, type, wr); | ||
177 | -- | ||
178 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | By having the qemu_plugin_cb_flags be recorded in the TCGHelperInfo, | ||
2 | we no longer need to distinguish PLUGIN_CB_REGULAR from | ||
3 | PLUGIN_CB_REGULAR_R, so place all TB callbacks in the same queue. | ||
1 | 4 | ||
5 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | accel/tcg/plugin-gen.c | 96 +++++++++++++++++++++++++----------------- | ||
9 | plugins/api.c | 6 +-- | ||
10 | 2 files changed, 58 insertions(+), 44 deletions(-) | ||
11 | |||
12 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/accel/tcg/plugin-gen.c | ||
15 | +++ b/accel/tcg/plugin-gen.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
17 | { | ||
18 | switch (from) { | ||
19 | case PLUGIN_GEN_AFTER_INSN: | ||
20 | + case PLUGIN_GEN_FROM_TB: | ||
21 | tcg_gen_plugin_cb(from); | ||
22 | break; | ||
23 | case PLUGIN_GEN_FROM_INSN: | ||
24 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
25 | */ | ||
26 | gen_wrapped(from, PLUGIN_GEN_ENABLE_MEM_HELPER, | ||
27 | gen_empty_mem_helper); | ||
28 | - /* fall through */ | ||
29 | - case PLUGIN_GEN_FROM_TB: | ||
30 | gen_wrapped(from, PLUGIN_GEN_CB_UDATA, gen_empty_udata_cb_no_rwg); | ||
31 | gen_wrapped(from, PLUGIN_GEN_CB_UDATA_R, gen_empty_udata_cb_no_wg); | ||
32 | gen_wrapped(from, PLUGIN_GEN_CB_INLINE, gen_empty_inline_cb); | ||
33 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_disable_mem_helpers(void) | ||
34 | offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env)); | ||
35 | } | ||
36 | |||
37 | -static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb, | ||
38 | - TCGOp *begin_op) | ||
39 | -{ | ||
40 | - inject_udata_cb(ptb->cbs[PLUGIN_CB_REGULAR], begin_op); | ||
41 | -} | ||
42 | - | ||
43 | -static void plugin_gen_tb_udata_r(const struct qemu_plugin_tb *ptb, | ||
44 | - TCGOp *begin_op) | ||
45 | -{ | ||
46 | - inject_udata_cb(ptb->cbs[PLUGIN_CB_REGULAR_R], begin_op); | ||
47 | -} | ||
48 | - | ||
49 | -static void plugin_gen_tb_inline(const struct qemu_plugin_tb *ptb, | ||
50 | - TCGOp *begin_op) | ||
51 | -{ | ||
52 | - inject_inline_cb(ptb->cbs[PLUGIN_CB_INLINE], begin_op, op_ok); | ||
53 | -} | ||
54 | - | ||
55 | static void plugin_gen_insn_udata(const struct qemu_plugin_tb *ptb, | ||
56 | TCGOp *begin_op, int insn_idx) | ||
57 | { | ||
58 | @@ -XXX,XX +XXX,XX @@ static void gen_disable_mem_helper(struct qemu_plugin_tb *ptb, | ||
59 | } | ||
60 | } | ||
61 | |||
62 | +static void gen_udata_cb(struct qemu_plugin_dyn_cb *cb) | ||
63 | +{ | ||
64 | + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | ||
65 | + | ||
66 | + tcg_gen_ld_i32(cpu_index, tcg_env, | ||
67 | + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); | ||
68 | + tcg_gen_call2(cb->regular.f.vcpu_udata, cb->regular.info, NULL, | ||
69 | + tcgv_i32_temp(cpu_index), | ||
70 | + tcgv_ptr_temp(tcg_constant_ptr(cb->userp))); | ||
71 | + tcg_temp_free_i32(cpu_index); | ||
72 | +} | ||
73 | + | ||
74 | +static void gen_inline_cb(struct qemu_plugin_dyn_cb *cb) | ||
75 | +{ | ||
76 | + GArray *arr = cb->inline_insn.entry.score->data; | ||
77 | + size_t offset = cb->inline_insn.entry.offset; | ||
78 | + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | ||
79 | + TCGv_i64 val = tcg_temp_ebb_new_i64(); | ||
80 | + TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); | ||
81 | + | ||
82 | + tcg_gen_ld_i32(cpu_index, tcg_env, | ||
83 | + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); | ||
84 | + tcg_gen_muli_i32(cpu_index, cpu_index, g_array_get_element_size(arr)); | ||
85 | + tcg_gen_ext_i32_ptr(ptr, cpu_index); | ||
86 | + tcg_temp_free_i32(cpu_index); | ||
87 | + | ||
88 | + tcg_gen_addi_ptr(ptr, ptr, (intptr_t)arr->data); | ||
89 | + tcg_gen_ld_i64(val, ptr, offset); | ||
90 | + tcg_gen_addi_i64(val, val, cb->inline_insn.imm); | ||
91 | + tcg_gen_st_i64(val, ptr, offset); | ||
92 | + | ||
93 | + tcg_temp_free_i64(val); | ||
94 | + tcg_temp_free_ptr(ptr); | ||
95 | +} | ||
96 | + | ||
97 | /* #define DEBUG_PLUGIN_GEN_OPS */ | ||
98 | static void pr_ops(void) | ||
99 | { | ||
100 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
101 | { | ||
102 | enum plugin_gen_from from = op->args[0]; | ||
103 | struct qemu_plugin_insn *insn = NULL; | ||
104 | + const GArray *cbs; | ||
105 | + int i, n; | ||
106 | |||
107 | if (insn_idx >= 0) { | ||
108 | insn = g_ptr_array_index(plugin_tb->insns, insn_idx); | ||
109 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
110 | assert(insn != NULL); | ||
111 | gen_disable_mem_helper(plugin_tb, insn); | ||
112 | break; | ||
113 | + | ||
114 | + case PLUGIN_GEN_FROM_TB: | ||
115 | + assert(insn == NULL); | ||
116 | + | ||
117 | + cbs = plugin_tb->cbs[PLUGIN_CB_REGULAR]; | ||
118 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
119 | + struct qemu_plugin_dyn_cb *cb = | ||
120 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
121 | + gen_udata_cb(cb); | ||
122 | + } | ||
123 | + | ||
124 | + cbs = plugin_tb->cbs[PLUGIN_CB_INLINE]; | ||
125 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
126 | + struct qemu_plugin_dyn_cb *cb = | ||
127 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
128 | + gen_inline_cb(cb); | ||
129 | + } | ||
130 | + break; | ||
131 | + | ||
132 | default: | ||
133 | g_assert_not_reached(); | ||
134 | } | ||
135 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
136 | enum plugin_gen_cb type = op->args[1]; | ||
137 | |||
138 | switch (from) { | ||
139 | - case PLUGIN_GEN_FROM_TB: | ||
140 | - { | ||
141 | - g_assert(insn_idx == -1); | ||
142 | - | ||
143 | - switch (type) { | ||
144 | - case PLUGIN_GEN_CB_UDATA: | ||
145 | - plugin_gen_tb_udata(plugin_tb, op); | ||
146 | - break; | ||
147 | - case PLUGIN_GEN_CB_UDATA_R: | ||
148 | - plugin_gen_tb_udata_r(plugin_tb, op); | ||
149 | - break; | ||
150 | - case PLUGIN_GEN_CB_INLINE: | ||
151 | - plugin_gen_tb_inline(plugin_tb, op); | ||
152 | - break; | ||
153 | - default: | ||
154 | - g_assert_not_reached(); | ||
155 | - } | ||
156 | - break; | ||
157 | - } | ||
158 | case PLUGIN_GEN_FROM_INSN: | ||
159 | { | ||
160 | g_assert(insn_idx >= 0); | ||
161 | diff --git a/plugins/api.c b/plugins/api.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/plugins/api.c | ||
164 | +++ b/plugins/api.c | ||
165 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, | ||
166 | void *udata) | ||
167 | { | ||
168 | if (!tb->mem_only) { | ||
169 | - int index = flags == QEMU_PLUGIN_CB_R_REGS || | ||
170 | - flags == QEMU_PLUGIN_CB_RW_REGS ? | ||
171 | - PLUGIN_CB_REGULAR_R : PLUGIN_CB_REGULAR; | ||
172 | - | ||
173 | - plugin_register_dyn_cb__udata(&tb->cbs[index], | ||
174 | + plugin_register_dyn_cb__udata(&tb->cbs[PLUGIN_CB_REGULAR], | ||
175 | cb, flags, udata); | ||
176 | } | ||
177 | } | ||
178 | -- | ||
179 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Delay test of plugin_tb->mem_helper until the inject pass. | ||
1 | 2 | ||
3 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | accel/tcg/plugin-gen.c | 37 ++++++++++++++++--------------------- | ||
7 | 1 file changed, 16 insertions(+), 21 deletions(-) | ||
8 | |||
9 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/accel/tcg/plugin-gen.c | ||
12 | +++ b/accel/tcg/plugin-gen.c | ||
13 | @@ -XXX,XX +XXX,XX @@ enum plugin_gen_from { | ||
14 | PLUGIN_GEN_FROM_INSN, | ||
15 | PLUGIN_GEN_FROM_MEM, | ||
16 | PLUGIN_GEN_AFTER_INSN, | ||
17 | + PLUGIN_GEN_AFTER_TB, | ||
18 | PLUGIN_GEN_N_FROMS, | ||
19 | }; | ||
20 | |||
21 | @@ -XXX,XX +XXX,XX @@ static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, | ||
22 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ | ||
23 | void plugin_gen_disable_mem_helpers(void) | ||
24 | { | ||
25 | - /* | ||
26 | - * We could emit the clearing unconditionally and be done. However, this can | ||
27 | - * be wasteful if for instance plugins don't track memory accesses, or if | ||
28 | - * most TBs don't use helpers. Instead, emit the clearing iff the TB calls | ||
29 | - * helpers that might access guest memory. | ||
30 | - * | ||
31 | - * Note: we do not reset plugin_tb->mem_helper here; a TB might have several | ||
32 | - * exit points, and we want to emit the clearing from all of them. | ||
33 | - */ | ||
34 | - if (!tcg_ctx->plugin_tb->mem_helper) { | ||
35 | - return; | ||
36 | + if (tcg_ctx->plugin_insn) { | ||
37 | + tcg_gen_plugin_cb(PLUGIN_GEN_AFTER_TB); | ||
38 | } | ||
39 | - tcg_gen_st_ptr(tcg_constant_ptr(NULL), tcg_env, | ||
40 | - offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env)); | ||
41 | } | ||
42 | |||
43 | static void plugin_gen_insn_udata(const struct qemu_plugin_tb *ptb, | ||
44 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
45 | inject_mem_enable_helper(ptb, insn, begin_op); | ||
46 | } | ||
47 | |||
48 | -static void gen_disable_mem_helper(struct qemu_plugin_tb *ptb, | ||
49 | - struct qemu_plugin_insn *insn) | ||
50 | +static void gen_disable_mem_helper(void) | ||
51 | { | ||
52 | - if (insn->mem_helper) { | ||
53 | - tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, | ||
54 | - offsetof(CPUState, plugin_mem_cbs) - | ||
55 | - offsetof(ArchCPU, env)); | ||
56 | - } | ||
57 | + tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, | ||
58 | + offsetof(CPUState, plugin_mem_cbs) - | ||
59 | + offsetof(ArchCPU, env)); | ||
60 | } | ||
61 | |||
62 | static void gen_udata_cb(struct qemu_plugin_dyn_cb *cb) | ||
63 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
64 | tcg_ctx->emit_before_op = op; | ||
65 | |||
66 | switch (from) { | ||
67 | + case PLUGIN_GEN_AFTER_TB: | ||
68 | + if (plugin_tb->mem_helper) { | ||
69 | + gen_disable_mem_helper(); | ||
70 | + } | ||
71 | + break; | ||
72 | + | ||
73 | case PLUGIN_GEN_AFTER_INSN: | ||
74 | assert(insn != NULL); | ||
75 | - gen_disable_mem_helper(plugin_tb, insn); | ||
76 | + if (insn->mem_helper) { | ||
77 | + gen_disable_mem_helper(); | ||
78 | + } | ||
79 | break; | ||
80 | |||
81 | case PLUGIN_GEN_FROM_TB: | ||
82 | -- | ||
83 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | --- | ||
4 | include/qemu/plugin.h | 1 - | ||
5 | accel/tcg/plugin-gen.c | 286 ++++++++++------------------------------- | ||
6 | plugins/api.c | 8 +- | ||
7 | 3 files changed, 67 insertions(+), 228 deletions(-) | ||
1 | 8 | ||
9 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/include/qemu/plugin.h | ||
12 | +++ b/include/qemu/plugin.h | ||
13 | @@ -XXX,XX +XXX,XX @@ enum plugin_dyn_cb_type { | ||
14 | |||
15 | enum plugin_dyn_cb_subtype { | ||
16 | PLUGIN_CB_REGULAR, | ||
17 | - PLUGIN_CB_REGULAR_R, | ||
18 | PLUGIN_CB_INLINE, | ||
19 | PLUGIN_N_CB_SUBTYPES, | ||
20 | }; | ||
21 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/accel/tcg/plugin-gen.c | ||
24 | +++ b/accel/tcg/plugin-gen.c | ||
25 | @@ -XXX,XX +XXX,XX @@ void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, | ||
26 | void *userdata) | ||
27 | { } | ||
28 | |||
29 | -static void gen_empty_udata_cb(void (*gen_helper)(TCGv_i32, TCGv_ptr)) | ||
30 | -{ | ||
31 | - TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | ||
32 | - TCGv_ptr udata = tcg_temp_ebb_new_ptr(); | ||
33 | - | ||
34 | - tcg_gen_movi_ptr(udata, 0); | ||
35 | - tcg_gen_ld_i32(cpu_index, tcg_env, | ||
36 | - -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); | ||
37 | - gen_helper(cpu_index, udata); | ||
38 | - | ||
39 | - tcg_temp_free_ptr(udata); | ||
40 | - tcg_temp_free_i32(cpu_index); | ||
41 | -} | ||
42 | - | ||
43 | -static void gen_empty_udata_cb_no_wg(void) | ||
44 | -{ | ||
45 | - gen_empty_udata_cb(gen_helper_plugin_vcpu_udata_cb_no_wg); | ||
46 | -} | ||
47 | - | ||
48 | -static void gen_empty_udata_cb_no_rwg(void) | ||
49 | -{ | ||
50 | - gen_empty_udata_cb(gen_helper_plugin_vcpu_udata_cb_no_rwg); | ||
51 | -} | ||
52 | - | ||
53 | /* | ||
54 | * For now we only support addi_i64. | ||
55 | * When we support more ops, we can generate one empty inline cb for each. | ||
56 | @@ -XXX,XX +XXX,XX @@ static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info) | ||
57 | tcg_temp_free_i32(cpu_index); | ||
58 | } | ||
59 | |||
60 | -/* | ||
61 | - * Share the same function for enable/disable. When enabling, the NULL | ||
62 | - * pointer will be overwritten later. | ||
63 | - */ | ||
64 | -static void gen_empty_mem_helper(void) | ||
65 | -{ | ||
66 | - TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); | ||
67 | - | ||
68 | - tcg_gen_movi_ptr(ptr, 0); | ||
69 | - tcg_gen_st_ptr(ptr, tcg_env, offsetof(CPUState, plugin_mem_cbs) - | ||
70 | - offsetof(ArchCPU, env)); | ||
71 | - tcg_temp_free_ptr(ptr); | ||
72 | -} | ||
73 | - | ||
74 | static void gen_plugin_cb_start(enum plugin_gen_from from, | ||
75 | enum plugin_gen_cb type, unsigned wr) | ||
76 | { | ||
77 | tcg_gen_plugin_cb_start(from, type, wr); | ||
78 | } | ||
79 | |||
80 | -static void gen_wrapped(enum plugin_gen_from from, | ||
81 | - enum plugin_gen_cb type, void (*func)(void)) | ||
82 | -{ | ||
83 | - gen_plugin_cb_start(from, type, 0); | ||
84 | - func(); | ||
85 | - tcg_gen_plugin_cb_end(); | ||
86 | -} | ||
87 | - | ||
88 | static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
89 | { | ||
90 | switch (from) { | ||
91 | case PLUGIN_GEN_AFTER_INSN: | ||
92 | case PLUGIN_GEN_FROM_TB: | ||
93 | - tcg_gen_plugin_cb(from); | ||
94 | - break; | ||
95 | case PLUGIN_GEN_FROM_INSN: | ||
96 | - /* | ||
97 | - * Note: plugin_gen_inject() relies on ENABLE_MEM_HELPER being | ||
98 | - * the first callback of an instruction | ||
99 | - */ | ||
100 | - gen_wrapped(from, PLUGIN_GEN_ENABLE_MEM_HELPER, | ||
101 | - gen_empty_mem_helper); | ||
102 | - gen_wrapped(from, PLUGIN_GEN_CB_UDATA, gen_empty_udata_cb_no_rwg); | ||
103 | - gen_wrapped(from, PLUGIN_GEN_CB_UDATA_R, gen_empty_udata_cb_no_wg); | ||
104 | - gen_wrapped(from, PLUGIN_GEN_CB_INLINE, gen_empty_inline_cb); | ||
105 | + tcg_gen_plugin_cb(from); | ||
106 | break; | ||
107 | default: | ||
108 | g_assert_not_reached(); | ||
109 | @@ -XXX,XX +XXX,XX @@ static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) | ||
110 | return op; | ||
111 | } | ||
112 | |||
113 | -static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) | ||
114 | -{ | ||
115 | - if (UINTPTR_MAX == UINT32_MAX) { | ||
116 | - /* st_i32 */ | ||
117 | - op = copy_op(begin_op, op, INDEX_op_st_i32); | ||
118 | - } else { | ||
119 | - /* st_i64 */ | ||
120 | - op = copy_st_i64(begin_op, op); | ||
121 | - } | ||
122 | - return op; | ||
123 | -} | ||
124 | - | ||
125 | static TCGOp *copy_call(TCGOp **begin_op, TCGOp *op, void *func, int *cb_idx) | ||
126 | { | ||
127 | TCGOp *old_op; | ||
128 | @@ -XXX,XX +XXX,XX @@ static TCGOp *copy_call(TCGOp **begin_op, TCGOp *op, void *func, int *cb_idx) | ||
129 | return op; | ||
130 | } | ||
131 | |||
132 | -/* | ||
133 | - * When we append/replace ops here we are sensitive to changing patterns of | ||
134 | - * TCGOps generated by the tcg_gen_FOO calls when we generated the | ||
135 | - * empty callbacks. This will assert very quickly in a debug build as | ||
136 | - * we assert the ops we are replacing are the correct ones. | ||
137 | - */ | ||
138 | -static TCGOp *append_udata_cb(const struct qemu_plugin_dyn_cb *cb, | ||
139 | - TCGOp *begin_op, TCGOp *op, int *cb_idx) | ||
140 | -{ | ||
141 | - /* const_ptr */ | ||
142 | - op = copy_const_ptr(&begin_op, op, cb->userp); | ||
143 | - | ||
144 | - /* copy the ld_i32, but note that we only have to copy it once */ | ||
145 | - if (*cb_idx == -1) { | ||
146 | - op = copy_op(&begin_op, op, INDEX_op_ld_i32); | ||
147 | - } else { | ||
148 | - begin_op = QTAILQ_NEXT(begin_op, link); | ||
149 | - tcg_debug_assert(begin_op && begin_op->opc == INDEX_op_ld_i32); | ||
150 | - } | ||
151 | - | ||
152 | - /* call */ | ||
153 | - op = copy_call(&begin_op, op, cb->regular.f.vcpu_udata, cb_idx); | ||
154 | - | ||
155 | - return op; | ||
156 | -} | ||
157 | - | ||
158 | static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, | ||
159 | TCGOp *begin_op, TCGOp *op, | ||
160 | int *unused) | ||
161 | @@ -XXX,XX +XXX,XX @@ typedef TCGOp *(*inject_fn)(const struct qemu_plugin_dyn_cb *cb, | ||
162 | TCGOp *begin_op, TCGOp *op, int *intp); | ||
163 | typedef bool (*op_ok_fn)(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb); | ||
164 | |||
165 | -static bool op_ok(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb) | ||
166 | -{ | ||
167 | - return true; | ||
168 | -} | ||
169 | - | ||
170 | static bool op_rw(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb) | ||
171 | { | ||
172 | int w; | ||
173 | @@ -XXX,XX +XXX,XX @@ static void inject_cb_type(const GArray *cbs, TCGOp *begin_op, | ||
174 | rm_ops_range(begin_op, end_op); | ||
175 | } | ||
176 | |||
177 | -static void | ||
178 | -inject_udata_cb(const GArray *cbs, TCGOp *begin_op) | ||
179 | -{ | ||
180 | - inject_cb_type(cbs, begin_op, append_udata_cb, op_ok); | ||
181 | -} | ||
182 | - | ||
183 | static void | ||
184 | inject_inline_cb(const GArray *cbs, TCGOp *begin_op, op_ok_fn ok) | ||
185 | { | ||
186 | @@ -XXX,XX +XXX,XX @@ inject_mem_cb(const GArray *cbs, TCGOp *begin_op) | ||
187 | inject_cb_type(cbs, begin_op, append_mem_cb, op_rw); | ||
188 | } | ||
189 | |||
190 | -/* we could change the ops in place, but we can reuse more code by copying */ | ||
191 | -static void inject_mem_helper(TCGOp *begin_op, GArray *arr) | ||
192 | -{ | ||
193 | - TCGOp *orig_op = begin_op; | ||
194 | - TCGOp *end_op; | ||
195 | - TCGOp *op; | ||
196 | - | ||
197 | - end_op = find_op(begin_op, INDEX_op_plugin_cb_end); | ||
198 | - tcg_debug_assert(end_op); | ||
199 | - | ||
200 | - /* const ptr */ | ||
201 | - op = copy_const_ptr(&begin_op, end_op, arr); | ||
202 | - | ||
203 | - /* st_ptr */ | ||
204 | - op = copy_st_ptr(&begin_op, op); | ||
205 | - | ||
206 | - rm_ops_range(orig_op, end_op); | ||
207 | -} | ||
208 | - | ||
209 | -/* | ||
210 | - * Tracking memory accesses performed from helpers requires extra work. | ||
211 | - * If an instruction is emulated with helpers, we do two things: | ||
212 | - * (1) copy the CB descriptors, and keep track of it so that they can be | ||
213 | - * freed later on, and (2) point CPUState.plugin_mem_cbs to the descriptors, so | ||
214 | - * that we can read them at run-time (i.e. when the helper executes). | ||
215 | - * This run-time access is performed from qemu_plugin_vcpu_mem_cb. | ||
216 | - * | ||
217 | - * Note that plugin_gen_disable_mem_helpers undoes (2). Since it | ||
218 | - * is possible that the code we generate after the instruction is | ||
219 | - * dead, we also add checks before generating tb_exit etc. | ||
220 | - */ | ||
221 | -static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, | ||
222 | - struct qemu_plugin_insn *plugin_insn, | ||
223 | - TCGOp *begin_op) | ||
224 | -{ | ||
225 | - GArray *cbs[2]; | ||
226 | - GArray *arr; | ||
227 | - size_t n_cbs, i; | ||
228 | - | ||
229 | - cbs[0] = plugin_insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; | ||
230 | - cbs[1] = plugin_insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
231 | - | ||
232 | - n_cbs = 0; | ||
233 | - for (i = 0; i < ARRAY_SIZE(cbs); i++) { | ||
234 | - n_cbs += cbs[i]->len; | ||
235 | - } | ||
236 | - | ||
237 | - plugin_insn->mem_helper = plugin_insn->calls_helpers && n_cbs; | ||
238 | - if (likely(!plugin_insn->mem_helper)) { | ||
239 | - rm_ops(begin_op); | ||
240 | - return; | ||
241 | - } | ||
242 | - ptb->mem_helper = true; | ||
243 | - | ||
244 | - arr = g_array_sized_new(false, false, | ||
245 | - sizeof(struct qemu_plugin_dyn_cb), n_cbs); | ||
246 | - | ||
247 | - for (i = 0; i < ARRAY_SIZE(cbs); i++) { | ||
248 | - g_array_append_vals(arr, cbs[i]->data, cbs[i]->len); | ||
249 | - } | ||
250 | - | ||
251 | - qemu_plugin_add_dyn_cb_arr(arr); | ||
252 | - inject_mem_helper(begin_op, arr); | ||
253 | -} | ||
254 | - | ||
255 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ | ||
256 | void plugin_gen_disable_mem_helpers(void) | ||
257 | { | ||
258 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_disable_mem_helpers(void) | ||
259 | } | ||
260 | } | ||
261 | |||
262 | -static void plugin_gen_insn_udata(const struct qemu_plugin_tb *ptb, | ||
263 | - TCGOp *begin_op, int insn_idx) | ||
264 | -{ | ||
265 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
266 | - | ||
267 | - inject_udata_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], begin_op); | ||
268 | -} | ||
269 | - | ||
270 | -static void plugin_gen_insn_udata_r(const struct qemu_plugin_tb *ptb, | ||
271 | - TCGOp *begin_op, int insn_idx) | ||
272 | -{ | ||
273 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
274 | - | ||
275 | - inject_udata_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR_R], begin_op); | ||
276 | -} | ||
277 | - | ||
278 | -static void plugin_gen_insn_inline(const struct qemu_plugin_tb *ptb, | ||
279 | - TCGOp *begin_op, int insn_idx) | ||
280 | -{ | ||
281 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
282 | - inject_inline_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], | ||
283 | - begin_op, op_ok); | ||
284 | -} | ||
285 | - | ||
286 | static void plugin_gen_mem_regular(const struct qemu_plugin_tb *ptb, | ||
287 | TCGOp *begin_op, int insn_idx) | ||
288 | { | ||
289 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_mem_inline(const struct qemu_plugin_tb *ptb, | ||
290 | inject_inline_cb(cbs, begin_op, op_rw); | ||
291 | } | ||
292 | |||
293 | -static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
294 | - TCGOp *begin_op, int insn_idx) | ||
295 | +static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
296 | + struct qemu_plugin_insn *insn) | ||
297 | { | ||
298 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
299 | - inject_mem_enable_helper(ptb, insn, begin_op); | ||
300 | + GArray *cbs[2]; | ||
301 | + GArray *arr; | ||
302 | + size_t n_cbs; | ||
303 | + | ||
304 | + /* | ||
305 | + * Tracking memory accesses performed from helpers requires extra work. | ||
306 | + * If an instruction is emulated with helpers, we do two things: | ||
307 | + * (1) copy the CB descriptors, and keep track of it so that they can be | ||
308 | + * freed later on, and (2) point CPUState.plugin_mem_cbs to the | ||
309 | + * descriptors, so that we can read them at run-time | ||
310 | + * (i.e. when the helper executes). | ||
311 | + * This run-time access is performed from qemu_plugin_vcpu_mem_cb. | ||
312 | + * | ||
313 | + * Note that plugin_gen_disable_mem_helpers undoes (2). Since it | ||
314 | + * is possible that the code we generate after the instruction is | ||
315 | + * dead, we also add checks before generating tb_exit etc. | ||
316 | + */ | ||
317 | + if (!insn->calls_helpers) { | ||
318 | + return; | ||
319 | + } | ||
320 | + | ||
321 | + cbs[0] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; | ||
322 | + cbs[1] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
323 | + n_cbs = cbs[0]->len + cbs[1]->len; | ||
324 | + | ||
325 | + if (n_cbs == 0) { | ||
326 | + insn->mem_helper = false; | ||
327 | + return; | ||
328 | + } | ||
329 | + insn->mem_helper = true; | ||
330 | + ptb->mem_helper = true; | ||
331 | + | ||
332 | + arr = g_array_sized_new(false, false, | ||
333 | + sizeof(struct qemu_plugin_dyn_cb), n_cbs); | ||
334 | + g_array_append_vals(arr, cbs[0]->data, cbs[0]->len); | ||
335 | + g_array_append_vals(arr, cbs[1]->data, cbs[1]->len); | ||
336 | + | ||
337 | + qemu_plugin_add_dyn_cb_arr(arr); | ||
338 | + | ||
339 | + tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env, | ||
340 | + offsetof(CPUState, plugin_mem_cbs) - | ||
341 | + offsetof(ArchCPU, env)); | ||
342 | } | ||
343 | |||
344 | static void gen_disable_mem_helper(void) | ||
345 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
346 | } | ||
347 | break; | ||
348 | |||
349 | + case PLUGIN_GEN_FROM_INSN: | ||
350 | + assert(insn != NULL); | ||
351 | + | ||
352 | + gen_enable_mem_helper(plugin_tb, insn); | ||
353 | + | ||
354 | + cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR]; | ||
355 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
356 | + struct qemu_plugin_dyn_cb *cb = | ||
357 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
358 | + gen_udata_cb(cb); | ||
359 | + } | ||
360 | + | ||
361 | + cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE]; | ||
362 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
363 | + struct qemu_plugin_dyn_cb *cb = | ||
364 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
365 | + gen_inline_cb(cb); | ||
366 | + } | ||
367 | + break; | ||
368 | + | ||
369 | default: | ||
370 | g_assert_not_reached(); | ||
371 | } | ||
372 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
373 | enum plugin_gen_cb type = op->args[1]; | ||
374 | |||
375 | switch (from) { | ||
376 | - case PLUGIN_GEN_FROM_INSN: | ||
377 | - { | ||
378 | - g_assert(insn_idx >= 0); | ||
379 | - | ||
380 | - switch (type) { | ||
381 | - case PLUGIN_GEN_CB_UDATA: | ||
382 | - plugin_gen_insn_udata(plugin_tb, op, insn_idx); | ||
383 | - break; | ||
384 | - case PLUGIN_GEN_CB_UDATA_R: | ||
385 | - plugin_gen_insn_udata_r(plugin_tb, op, insn_idx); | ||
386 | - break; | ||
387 | - case PLUGIN_GEN_CB_INLINE: | ||
388 | - plugin_gen_insn_inline(plugin_tb, op, insn_idx); | ||
389 | - break; | ||
390 | - case PLUGIN_GEN_ENABLE_MEM_HELPER: | ||
391 | - plugin_gen_enable_mem_helper(plugin_tb, op, insn_idx); | ||
392 | - break; | ||
393 | - default: | ||
394 | - g_assert_not_reached(); | ||
395 | - } | ||
396 | - break; | ||
397 | - } | ||
398 | case PLUGIN_GEN_FROM_MEM: | ||
399 | { | ||
400 | g_assert(insn_idx >= 0); | ||
401 | diff --git a/plugins/api.c b/plugins/api.c | ||
402 | index XXXXXXX..XXXXXXX 100644 | ||
403 | --- a/plugins/api.c | ||
404 | +++ b/plugins/api.c | ||
405 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, | ||
406 | void *udata) | ||
407 | { | ||
408 | if (!insn->mem_only) { | ||
409 | - int index = flags == QEMU_PLUGIN_CB_R_REGS || | ||
410 | - flags == QEMU_PLUGIN_CB_RW_REGS ? | ||
411 | - PLUGIN_CB_REGULAR_R : PLUGIN_CB_REGULAR; | ||
412 | - | ||
413 | - plugin_register_dyn_cb__udata(&insn->cbs[PLUGIN_CB_INSN][index], | ||
414 | - cb, flags, udata); | ||
415 | + plugin_register_dyn_cb__udata( | ||
416 | + &insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], cb, flags, udata); | ||
417 | } | ||
418 | } | ||
419 | |||
420 | -- | ||
421 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Introduce a new plugin_mem_cb op to hold the address temp |
---|---|---|---|
2 | and meminfo computed by tcg-op-ldst.c. Because this now | ||
3 | has its own opcode, we no longer need PLUGIN_GEN_FROM_MEM. | ||
2 | 4 | ||
3 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | 5 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> |
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Message-Id: <20201015143217.29337-4-cfontana@suse.de> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | accel/tcg/tcg-cpus-icount.h | 6 +-- | 8 | include/exec/plugin-gen.h | 4 - |
9 | accel/tcg/tcg-cpus-rr.h | 2 +- | 9 | include/tcg/tcg-op-common.h | 1 + |
10 | accel/tcg/tcg-cpus.h | 6 +-- | 10 | include/tcg/tcg-opc.h | 1 + |
11 | accel/tcg/tcg-cpus-icount.c | 24 ++++++------ | 11 | accel/tcg/plugin-gen.c | 408 ++++-------------------------------- |
12 | accel/tcg/tcg-cpus-mttcg.c | 10 ++--- | 12 | tcg/tcg-op-ldst.c | 6 +- |
13 | accel/tcg/tcg-cpus-rr.c | 74 ++++++++++++++++++------------------- | 13 | tcg/tcg-op.c | 5 + |
14 | accel/tcg/tcg-cpus.c | 6 +-- | 14 | 6 files changed, 54 insertions(+), 371 deletions(-) |
15 | 7 files changed, 64 insertions(+), 64 deletions(-) | ||
16 | 15 | ||
17 | diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h | 16 | diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/accel/tcg/tcg-cpus-icount.h | 18 | --- a/include/exec/plugin-gen.h |
20 | +++ b/accel/tcg/tcg-cpus-icount.h | 19 | +++ b/include/exec/plugin-gen.h |
20 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db); | ||
21 | void plugin_gen_insn_end(void); | ||
22 | |||
23 | void plugin_gen_disable_mem_helpers(void); | ||
24 | -void plugin_gen_empty_mem_callback(TCGv_i64 addr, uint32_t info); | ||
25 | |||
26 | #else /* !CONFIG_PLUGIN */ | ||
27 | |||
28 | @@ -XXX,XX +XXX,XX @@ static inline void plugin_gen_tb_end(CPUState *cpu, size_t num_insns) | ||
29 | static inline void plugin_gen_disable_mem_helpers(void) | ||
30 | { } | ||
31 | |||
32 | -static inline void plugin_gen_empty_mem_callback(TCGv_i64 addr, uint32_t info) | ||
33 | -{ } | ||
34 | - | ||
35 | #endif /* CONFIG_PLUGIN */ | ||
36 | |||
37 | #endif /* QEMU_PLUGIN_GEN_H */ | ||
38 | diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/include/tcg/tcg-op-common.h | ||
41 | +++ b/include/tcg/tcg-op-common.h | ||
42 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_goto_tb(unsigned idx); | ||
43 | void tcg_gen_lookup_and_goto_ptr(void); | ||
44 | |||
45 | void tcg_gen_plugin_cb(unsigned from); | ||
46 | +void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo); | ||
47 | void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr); | ||
48 | void tcg_gen_plugin_cb_end(void); | ||
49 | |||
50 | diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/include/tcg/tcg-opc.h | ||
53 | +++ b/include/tcg/tcg-opc.h | ||
54 | @@ -XXX,XX +XXX,XX @@ DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
55 | DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
56 | |||
57 | DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT) | ||
58 | +DEF(plugin_mem_cb, 0, 1, 1, TCG_OPF_NOT_PRESENT) | ||
59 | DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) | ||
60 | DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) | ||
61 | |||
62 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/accel/tcg/plugin-gen.c | ||
65 | +++ b/accel/tcg/plugin-gen.c | ||
21 | @@ -XXX,XX +XXX,XX @@ | 66 | @@ -XXX,XX +XXX,XX @@ |
22 | #ifndef TCG_CPUS_ICOUNT_H | 67 | enum plugin_gen_from { |
23 | #define TCG_CPUS_ICOUNT_H | 68 | PLUGIN_GEN_FROM_TB, |
24 | 69 | PLUGIN_GEN_FROM_INSN, | |
25 | -void handle_icount_deadline(void); | 70 | - PLUGIN_GEN_FROM_MEM, |
26 | -void prepare_icount_for_run(CPUState *cpu); | 71 | PLUGIN_GEN_AFTER_INSN, |
27 | -void process_icount_data(CPUState *cpu); | 72 | PLUGIN_GEN_AFTER_TB, |
28 | +void icount_handle_deadline(void); | 73 | PLUGIN_GEN_N_FROMS, |
29 | +void icount_prepare_for_run(CPUState *cpu); | 74 | @@ -XXX,XX +XXX,XX @@ void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, |
30 | +void icount_process_data(CPUState *cpu); | 75 | void *userdata) |
31 | 76 | { } | |
32 | #endif /* TCG_CPUS_ICOUNT_H */ | 77 | |
33 | diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h | 78 | -/* |
34 | index XXXXXXX..XXXXXXX 100644 | 79 | - * For now we only support addi_i64. |
35 | --- a/accel/tcg/tcg-cpus-rr.h | 80 | - * When we support more ops, we can generate one empty inline cb for each. |
36 | +++ b/accel/tcg/tcg-cpus-rr.h | 81 | - */ |
37 | @@ -XXX,XX +XXX,XX @@ | 82 | -static void gen_empty_inline_cb(void) |
38 | #define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) | 83 | -{ |
39 | 84 | - TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | |
40 | /* Kick all RR vCPUs. */ | 85 | - TCGv_ptr cpu_index_as_ptr = tcg_temp_ebb_new_ptr(); |
41 | -void qemu_cpu_kick_rr_cpus(CPUState *unused); | 86 | - TCGv_i64 val = tcg_temp_ebb_new_i64(); |
42 | +void rr_kick_vcpu_thread(CPUState *unused); | 87 | - TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); |
43 | 88 | - | |
44 | /* start the round robin vcpu thread */ | 89 | - tcg_gen_ld_i32(cpu_index, tcg_env, |
45 | void rr_start_vcpu_thread(CPUState *cpu); | 90 | - -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); |
46 | diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h | 91 | - /* second operand will be replaced by immediate value */ |
47 | index XXXXXXX..XXXXXXX 100644 | 92 | - tcg_gen_mul_i32(cpu_index, cpu_index, cpu_index); |
48 | --- a/accel/tcg/tcg-cpus.h | 93 | - tcg_gen_ext_i32_ptr(cpu_index_as_ptr, cpu_index); |
49 | +++ b/accel/tcg/tcg-cpus.h | 94 | - |
50 | @@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg; | 95 | - tcg_gen_movi_ptr(ptr, 0); |
51 | extern const CpusAccel tcg_cpus_icount; | 96 | - tcg_gen_add_ptr(ptr, ptr, cpu_index_as_ptr); |
52 | extern const CpusAccel tcg_cpus_rr; | 97 | - tcg_gen_ld_i64(val, ptr, 0); |
53 | 98 | - /* second operand will be replaced by immediate value */ | |
54 | -void qemu_tcg_destroy_vcpu(CPUState *cpu); | 99 | - tcg_gen_add_i64(val, val, val); |
55 | -int tcg_cpu_exec(CPUState *cpu); | 100 | - |
56 | -void tcg_handle_interrupt(CPUState *cpu, int mask); | 101 | - tcg_gen_st_i64(val, ptr, 0); |
57 | +void tcg_cpus_destroy(CPUState *cpu); | 102 | - tcg_temp_free_ptr(ptr); |
58 | +int tcg_cpus_exec(CPUState *cpu); | 103 | - tcg_temp_free_i64(val); |
59 | +void tcg_cpus_handle_interrupt(CPUState *cpu, int mask); | 104 | - tcg_temp_free_ptr(cpu_index_as_ptr); |
60 | 105 | - tcg_temp_free_i32(cpu_index); | |
61 | #endif /* TCG_CPUS_H */ | 106 | -} |
62 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c | 107 | - |
63 | index XXXXXXX..XXXXXXX 100644 | 108 | -static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info) |
64 | --- a/accel/tcg/tcg-cpus-icount.c | 109 | -{ |
65 | +++ b/accel/tcg/tcg-cpus-icount.c | 110 | - TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); |
66 | @@ -XXX,XX +XXX,XX @@ | 111 | - TCGv_i32 meminfo = tcg_temp_ebb_new_i32(); |
67 | #include "tcg-cpus-icount.h" | 112 | - TCGv_ptr udata = tcg_temp_ebb_new_ptr(); |
68 | #include "tcg-cpus-rr.h" | 113 | - |
69 | 114 | - tcg_gen_movi_i32(meminfo, info); | |
70 | -static int64_t tcg_get_icount_limit(void) | 115 | - tcg_gen_movi_ptr(udata, 0); |
71 | +static int64_t icount_get_limit(void) | 116 | - tcg_gen_ld_i32(cpu_index, tcg_env, |
117 | - -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); | ||
118 | - | ||
119 | - gen_helper_plugin_vcpu_mem_cb(cpu_index, meminfo, addr, udata); | ||
120 | - | ||
121 | - tcg_temp_free_ptr(udata); | ||
122 | - tcg_temp_free_i32(meminfo); | ||
123 | - tcg_temp_free_i32(cpu_index); | ||
124 | -} | ||
125 | - | ||
126 | -static void gen_plugin_cb_start(enum plugin_gen_from from, | ||
127 | - enum plugin_gen_cb type, unsigned wr) | ||
128 | -{ | ||
129 | - tcg_gen_plugin_cb_start(from, type, wr); | ||
130 | -} | ||
131 | - | ||
132 | static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
72 | { | 133 | { |
73 | int64_t deadline; | 134 | switch (from) { |
74 | 135 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) | |
75 | @@ -XXX,XX +XXX,XX @@ static int64_t tcg_get_icount_limit(void) | ||
76 | } | 136 | } |
77 | } | 137 | } |
78 | 138 | ||
79 | -static void notify_aio_contexts(void) | 139 | -void plugin_gen_empty_mem_callback(TCGv_i64 addr, uint32_t info) |
80 | +static void icount_notify_aio_contexts(void) | 140 | -{ |
141 | - enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info); | ||
142 | - | ||
143 | - gen_plugin_cb_start(PLUGIN_GEN_FROM_MEM, PLUGIN_GEN_CB_MEM, rw); | ||
144 | - gen_empty_mem_cb(addr, info); | ||
145 | - tcg_gen_plugin_cb_end(); | ||
146 | - | ||
147 | - gen_plugin_cb_start(PLUGIN_GEN_FROM_MEM, PLUGIN_GEN_CB_INLINE, rw); | ||
148 | - gen_empty_inline_cb(); | ||
149 | - tcg_gen_plugin_cb_end(); | ||
150 | -} | ||
151 | - | ||
152 | -static TCGOp *find_op(TCGOp *op, TCGOpcode opc) | ||
153 | -{ | ||
154 | - while (op) { | ||
155 | - if (op->opc == opc) { | ||
156 | - return op; | ||
157 | - } | ||
158 | - op = QTAILQ_NEXT(op, link); | ||
159 | - } | ||
160 | - return NULL; | ||
161 | -} | ||
162 | - | ||
163 | -static TCGOp *rm_ops_range(TCGOp *begin, TCGOp *end) | ||
164 | -{ | ||
165 | - TCGOp *ret = QTAILQ_NEXT(end, link); | ||
166 | - | ||
167 | - QTAILQ_REMOVE_SEVERAL(&tcg_ctx->ops, begin, end, link); | ||
168 | - return ret; | ||
169 | -} | ||
170 | - | ||
171 | -/* remove all ops until (and including) plugin_cb_end */ | ||
172 | -static TCGOp *rm_ops(TCGOp *op) | ||
173 | -{ | ||
174 | - TCGOp *end_op = find_op(op, INDEX_op_plugin_cb_end); | ||
175 | - | ||
176 | - tcg_debug_assert(end_op); | ||
177 | - return rm_ops_range(op, end_op); | ||
178 | -} | ||
179 | - | ||
180 | -static TCGOp *copy_op_nocheck(TCGOp **begin_op, TCGOp *op) | ||
181 | -{ | ||
182 | - TCGOp *old_op = QTAILQ_NEXT(*begin_op, link); | ||
183 | - unsigned nargs = old_op->nargs; | ||
184 | - | ||
185 | - *begin_op = old_op; | ||
186 | - op = tcg_op_insert_after(tcg_ctx, op, old_op->opc, nargs); | ||
187 | - memcpy(op->args, old_op->args, sizeof(op->args[0]) * nargs); | ||
188 | - | ||
189 | - return op; | ||
190 | -} | ||
191 | - | ||
192 | -static TCGOp *copy_op(TCGOp **begin_op, TCGOp *op, TCGOpcode opc) | ||
193 | -{ | ||
194 | - op = copy_op_nocheck(begin_op, op); | ||
195 | - tcg_debug_assert((*begin_op)->opc == opc); | ||
196 | - return op; | ||
197 | -} | ||
198 | - | ||
199 | -static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr) | ||
200 | -{ | ||
201 | - if (UINTPTR_MAX == UINT32_MAX) { | ||
202 | - /* mov_i32 */ | ||
203 | - op = copy_op(begin_op, op, INDEX_op_mov_i32); | ||
204 | - op->args[1] = tcgv_i32_arg(tcg_constant_i32((uintptr_t)ptr)); | ||
205 | - } else { | ||
206 | - /* mov_i64 */ | ||
207 | - op = copy_op(begin_op, op, INDEX_op_mov_i64); | ||
208 | - op->args[1] = tcgv_i64_arg(tcg_constant_i64((uintptr_t)ptr)); | ||
209 | - } | ||
210 | - return op; | ||
211 | -} | ||
212 | - | ||
213 | -static TCGOp *copy_ld_i32(TCGOp **begin_op, TCGOp *op) | ||
214 | -{ | ||
215 | - return copy_op(begin_op, op, INDEX_op_ld_i32); | ||
216 | -} | ||
217 | - | ||
218 | -static TCGOp *copy_ext_i32_ptr(TCGOp **begin_op, TCGOp *op) | ||
219 | -{ | ||
220 | - if (UINTPTR_MAX == UINT32_MAX) { | ||
221 | - op = copy_op(begin_op, op, INDEX_op_mov_i32); | ||
222 | - } else { | ||
223 | - op = copy_op(begin_op, op, INDEX_op_ext_i32_i64); | ||
224 | - } | ||
225 | - return op; | ||
226 | -} | ||
227 | - | ||
228 | -static TCGOp *copy_add_ptr(TCGOp **begin_op, TCGOp *op) | ||
229 | -{ | ||
230 | - if (UINTPTR_MAX == UINT32_MAX) { | ||
231 | - op = copy_op(begin_op, op, INDEX_op_add_i32); | ||
232 | - } else { | ||
233 | - op = copy_op(begin_op, op, INDEX_op_add_i64); | ||
234 | - } | ||
235 | - return op; | ||
236 | -} | ||
237 | - | ||
238 | -static TCGOp *copy_ld_i64(TCGOp **begin_op, TCGOp *op) | ||
239 | -{ | ||
240 | - if (TCG_TARGET_REG_BITS == 32) { | ||
241 | - /* 2x ld_i32 */ | ||
242 | - op = copy_ld_i32(begin_op, op); | ||
243 | - op = copy_ld_i32(begin_op, op); | ||
244 | - } else { | ||
245 | - /* ld_i64 */ | ||
246 | - op = copy_op(begin_op, op, INDEX_op_ld_i64); | ||
247 | - } | ||
248 | - return op; | ||
249 | -} | ||
250 | - | ||
251 | -static TCGOp *copy_st_i64(TCGOp **begin_op, TCGOp *op) | ||
252 | -{ | ||
253 | - if (TCG_TARGET_REG_BITS == 32) { | ||
254 | - /* 2x st_i32 */ | ||
255 | - op = copy_op(begin_op, op, INDEX_op_st_i32); | ||
256 | - op = copy_op(begin_op, op, INDEX_op_st_i32); | ||
257 | - } else { | ||
258 | - /* st_i64 */ | ||
259 | - op = copy_op(begin_op, op, INDEX_op_st_i64); | ||
260 | - } | ||
261 | - return op; | ||
262 | -} | ||
263 | - | ||
264 | -static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op, uint64_t v) | ||
265 | -{ | ||
266 | - if (TCG_TARGET_REG_BITS == 32) { | ||
267 | - /* all 32-bit backends must implement add2_i32 */ | ||
268 | - g_assert(TCG_TARGET_HAS_add2_i32); | ||
269 | - op = copy_op(begin_op, op, INDEX_op_add2_i32); | ||
270 | - op->args[4] = tcgv_i32_arg(tcg_constant_i32(v)); | ||
271 | - op->args[5] = tcgv_i32_arg(tcg_constant_i32(v >> 32)); | ||
272 | - } else { | ||
273 | - op = copy_op(begin_op, op, INDEX_op_add_i64); | ||
274 | - op->args[2] = tcgv_i64_arg(tcg_constant_i64(v)); | ||
275 | - } | ||
276 | - return op; | ||
277 | -} | ||
278 | - | ||
279 | -static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) | ||
280 | -{ | ||
281 | - op = copy_op(begin_op, op, INDEX_op_mul_i32); | ||
282 | - op->args[2] = tcgv_i32_arg(tcg_constant_i32(v)); | ||
283 | - return op; | ||
284 | -} | ||
285 | - | ||
286 | -static TCGOp *copy_call(TCGOp **begin_op, TCGOp *op, void *func, int *cb_idx) | ||
287 | -{ | ||
288 | - TCGOp *old_op; | ||
289 | - int func_idx; | ||
290 | - | ||
291 | - /* copy all ops until the call */ | ||
292 | - do { | ||
293 | - op = copy_op_nocheck(begin_op, op); | ||
294 | - } while (op->opc != INDEX_op_call); | ||
295 | - | ||
296 | - /* fill in the op call */ | ||
297 | - old_op = *begin_op; | ||
298 | - TCGOP_CALLI(op) = TCGOP_CALLI(old_op); | ||
299 | - TCGOP_CALLO(op) = TCGOP_CALLO(old_op); | ||
300 | - tcg_debug_assert(op->life == 0); | ||
301 | - | ||
302 | - func_idx = TCGOP_CALLO(op) + TCGOP_CALLI(op); | ||
303 | - *cb_idx = func_idx; | ||
304 | - op->args[func_idx] = (uintptr_t)func; | ||
305 | - | ||
306 | - return op; | ||
307 | -} | ||
308 | - | ||
309 | -static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, | ||
310 | - TCGOp *begin_op, TCGOp *op, | ||
311 | - int *unused) | ||
312 | -{ | ||
313 | - char *ptr = cb->inline_insn.entry.score->data->data; | ||
314 | - size_t elem_size = g_array_get_element_size( | ||
315 | - cb->inline_insn.entry.score->data); | ||
316 | - size_t offset = cb->inline_insn.entry.offset; | ||
317 | - | ||
318 | - op = copy_ld_i32(&begin_op, op); | ||
319 | - op = copy_mul_i32(&begin_op, op, elem_size); | ||
320 | - op = copy_ext_i32_ptr(&begin_op, op); | ||
321 | - op = copy_const_ptr(&begin_op, op, ptr + offset); | ||
322 | - op = copy_add_ptr(&begin_op, op); | ||
323 | - op = copy_ld_i64(&begin_op, op); | ||
324 | - op = copy_add_i64(&begin_op, op, cb->inline_insn.imm); | ||
325 | - op = copy_st_i64(&begin_op, op); | ||
326 | - return op; | ||
327 | -} | ||
328 | - | ||
329 | -static TCGOp *append_mem_cb(const struct qemu_plugin_dyn_cb *cb, | ||
330 | - TCGOp *begin_op, TCGOp *op, int *cb_idx) | ||
331 | -{ | ||
332 | - enum plugin_gen_cb type = begin_op->args[1]; | ||
333 | - | ||
334 | - tcg_debug_assert(type == PLUGIN_GEN_CB_MEM); | ||
335 | - | ||
336 | - /* const_i32 == mov_i32 ("info", so it remains as is) */ | ||
337 | - op = copy_op(&begin_op, op, INDEX_op_mov_i32); | ||
338 | - | ||
339 | - /* const_ptr */ | ||
340 | - op = copy_const_ptr(&begin_op, op, cb->userp); | ||
341 | - | ||
342 | - /* copy the ld_i32, but note that we only have to copy it once */ | ||
343 | - if (*cb_idx == -1) { | ||
344 | - op = copy_op(&begin_op, op, INDEX_op_ld_i32); | ||
345 | - } else { | ||
346 | - begin_op = QTAILQ_NEXT(begin_op, link); | ||
347 | - tcg_debug_assert(begin_op && begin_op->opc == INDEX_op_ld_i32); | ||
348 | - } | ||
349 | - | ||
350 | - if (type == PLUGIN_GEN_CB_MEM) { | ||
351 | - /* call */ | ||
352 | - op = copy_call(&begin_op, op, cb->regular.f.vcpu_udata, cb_idx); | ||
353 | - } | ||
354 | - | ||
355 | - return op; | ||
356 | -} | ||
357 | - | ||
358 | -typedef TCGOp *(*inject_fn)(const struct qemu_plugin_dyn_cb *cb, | ||
359 | - TCGOp *begin_op, TCGOp *op, int *intp); | ||
360 | -typedef bool (*op_ok_fn)(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb); | ||
361 | - | ||
362 | -static bool op_rw(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb) | ||
363 | -{ | ||
364 | - int w; | ||
365 | - | ||
366 | - w = op->args[2]; | ||
367 | - return !!(cb->rw & (w + 1)); | ||
368 | -} | ||
369 | - | ||
370 | -static void inject_cb_type(const GArray *cbs, TCGOp *begin_op, | ||
371 | - inject_fn inject, op_ok_fn ok) | ||
372 | -{ | ||
373 | - TCGOp *end_op; | ||
374 | - TCGOp *op; | ||
375 | - int cb_idx = -1; | ||
376 | - int i; | ||
377 | - | ||
378 | - if (!cbs || cbs->len == 0) { | ||
379 | - rm_ops(begin_op); | ||
380 | - return; | ||
381 | - } | ||
382 | - | ||
383 | - end_op = find_op(begin_op, INDEX_op_plugin_cb_end); | ||
384 | - tcg_debug_assert(end_op); | ||
385 | - | ||
386 | - op = end_op; | ||
387 | - for (i = 0; i < cbs->len; i++) { | ||
388 | - struct qemu_plugin_dyn_cb *cb = | ||
389 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
390 | - | ||
391 | - if (!ok(begin_op, cb)) { | ||
392 | - continue; | ||
393 | - } | ||
394 | - op = inject(cb, begin_op, op, &cb_idx); | ||
395 | - } | ||
396 | - rm_ops_range(begin_op, end_op); | ||
397 | -} | ||
398 | - | ||
399 | -static void | ||
400 | -inject_inline_cb(const GArray *cbs, TCGOp *begin_op, op_ok_fn ok) | ||
401 | -{ | ||
402 | - inject_cb_type(cbs, begin_op, append_inline_cb, ok); | ||
403 | -} | ||
404 | - | ||
405 | -static void | ||
406 | -inject_mem_cb(const GArray *cbs, TCGOp *begin_op) | ||
407 | -{ | ||
408 | - inject_cb_type(cbs, begin_op, append_mem_cb, op_rw); | ||
409 | -} | ||
410 | - | ||
411 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ | ||
412 | void plugin_gen_disable_mem_helpers(void) | ||
81 | { | 413 | { |
82 | /* Wake up other AioContexts. */ | 414 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_disable_mem_helpers(void) |
83 | qemu_clock_notify(QEMU_CLOCK_VIRTUAL); | ||
84 | qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); | ||
85 | } | ||
86 | |||
87 | -void handle_icount_deadline(void) | ||
88 | +void icount_handle_deadline(void) | ||
89 | { | ||
90 | assert(qemu_in_vcpu_thread()); | ||
91 | int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | ||
92 | QEMU_TIMER_ATTR_ALL); | ||
93 | |||
94 | if (deadline == 0) { | ||
95 | - notify_aio_contexts(); | ||
96 | + icount_notify_aio_contexts(); | ||
97 | } | 415 | } |
98 | } | 416 | } |
99 | 417 | ||
100 | -void prepare_icount_for_run(CPUState *cpu) | 418 | -static void plugin_gen_mem_regular(const struct qemu_plugin_tb *ptb, |
101 | +void icount_prepare_for_run(CPUState *cpu) | 419 | - TCGOp *begin_op, int insn_idx) |
420 | -{ | ||
421 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
422 | - inject_mem_cb(insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], begin_op); | ||
423 | -} | ||
424 | - | ||
425 | -static void plugin_gen_mem_inline(const struct qemu_plugin_tb *ptb, | ||
426 | - TCGOp *begin_op, int insn_idx) | ||
427 | -{ | ||
428 | - const GArray *cbs; | ||
429 | - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); | ||
430 | - | ||
431 | - cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
432 | - inject_inline_cb(cbs, begin_op, op_rw); | ||
433 | -} | ||
434 | - | ||
435 | static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
436 | struct qemu_plugin_insn *insn) | ||
102 | { | 437 | { |
103 | int insns_left; | 438 | @@ -XXX,XX +XXX,XX @@ static void gen_inline_cb(struct qemu_plugin_dyn_cb *cb) |
104 | 439 | tcg_temp_free_ptr(ptr); | |
105 | /* | ||
106 | - * These should always be cleared by process_icount_data after | ||
107 | + * These should always be cleared by icount_process_data after | ||
108 | * each vCPU execution. However u16.high can be raised | ||
109 | - * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | ||
110 | + * asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt | ||
111 | */ | ||
112 | g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
113 | g_assert(cpu->icount_extra == 0); | ||
114 | |||
115 | - cpu->icount_budget = tcg_get_icount_limit(); | ||
116 | + cpu->icount_budget = icount_get_limit(); | ||
117 | insns_left = MIN(0xffff, cpu->icount_budget); | ||
118 | cpu_neg(cpu)->icount_decr.u16.low = insns_left; | ||
119 | cpu->icount_extra = cpu->icount_budget - insns_left; | ||
120 | @@ -XXX,XX +XXX,XX @@ void prepare_icount_for_run(CPUState *cpu) | ||
121 | replay_mutex_lock(); | ||
122 | |||
123 | if (cpu->icount_budget == 0 && replay_has_checkpoint()) { | ||
124 | - notify_aio_contexts(); | ||
125 | + icount_notify_aio_contexts(); | ||
126 | } | ||
127 | } | 440 | } |
128 | 441 | ||
129 | -void process_icount_data(CPUState *cpu) | 442 | +static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, |
130 | +void icount_process_data(CPUState *cpu) | 443 | + qemu_plugin_meminfo_t meminfo, TCGv_i64 addr) |
444 | +{ | ||
445 | + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | ||
446 | + | ||
447 | + tcg_gen_ld_i32(cpu_index, tcg_env, | ||
448 | + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); | ||
449 | + tcg_gen_call4(cb->regular.f.vcpu_mem, cb->regular.info, NULL, | ||
450 | + tcgv_i32_temp(cpu_index), | ||
451 | + tcgv_i32_temp(tcg_constant_i32(meminfo)), | ||
452 | + tcgv_i64_temp(addr), | ||
453 | + tcgv_ptr_temp(tcg_constant_ptr(cb->userp))); | ||
454 | + tcg_temp_free_i32(cpu_index); | ||
455 | +} | ||
456 | + | ||
457 | /* #define DEBUG_PLUGIN_GEN_OPS */ | ||
458 | static void pr_ops(void) | ||
131 | { | 459 | { |
132 | /* Account for executed instructions */ | 460 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) |
133 | icount_update(cpu); | ||
134 | @@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
135 | { | ||
136 | int old_mask = cpu->interrupt_request; | ||
137 | |||
138 | - tcg_handle_interrupt(cpu, mask); | ||
139 | + tcg_cpus_handle_interrupt(cpu, mask); | ||
140 | if (qemu_cpu_is_self(cpu) && | ||
141 | !cpu->can_do_io | ||
142 | && (mask & ~old_mask) != 0) { | ||
143 | @@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
144 | |||
145 | const CpusAccel tcg_cpus_icount = { | ||
146 | .create_vcpu_thread = rr_start_vcpu_thread, | ||
147 | - .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
148 | + .kick_vcpu_thread = rr_kick_vcpu_thread, | ||
149 | |||
150 | .handle_interrupt = icount_handle_interrupt, | ||
151 | .get_virtual_clock = icount_get, | ||
152 | diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/accel/tcg/tcg-cpus-mttcg.c | ||
155 | +++ b/accel/tcg/tcg-cpus-mttcg.c | ||
156 | @@ -XXX,XX +XXX,XX @@ | ||
157 | * current CPUState for a given thread. | ||
158 | */ | ||
159 | |||
160 | -static void *tcg_cpu_thread_fn(void *arg) | ||
161 | +static void *mttcg_cpu_thread_fn(void *arg) | ||
162 | { | ||
163 | CPUState *cpu = arg; | ||
164 | |||
165 | @@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg) | ||
166 | if (cpu_can_run(cpu)) { | ||
167 | int r; | ||
168 | qemu_mutex_unlock_iothread(); | ||
169 | - r = tcg_cpu_exec(cpu); | ||
170 | + r = tcg_cpus_exec(cpu); | ||
171 | qemu_mutex_lock_iothread(); | ||
172 | switch (r) { | ||
173 | case EXCP_DEBUG: | ||
174 | @@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg) | ||
175 | qemu_wait_io_event(cpu); | ||
176 | } while (!cpu->unplug || cpu_can_run(cpu)); | ||
177 | |||
178 | - qemu_tcg_destroy_vcpu(cpu); | ||
179 | + tcg_cpus_destroy(cpu); | ||
180 | qemu_mutex_unlock_iothread(); | ||
181 | rcu_unregister_thread(); | ||
182 | return NULL; | ||
183 | @@ -XXX,XX +XXX,XX @@ static void mttcg_start_vcpu_thread(CPUState *cpu) | ||
184 | snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", | ||
185 | cpu->cpu_index); | ||
186 | |||
187 | - qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn, | ||
188 | + qemu_thread_create(cpu->thread, thread_name, mttcg_cpu_thread_fn, | ||
189 | cpu, QEMU_THREAD_JOINABLE); | ||
190 | |||
191 | #ifdef _WIN32 | ||
192 | @@ -XXX,XX +XXX,XX @@ const CpusAccel tcg_cpus_mttcg = { | ||
193 | .create_vcpu_thread = mttcg_start_vcpu_thread, | ||
194 | .kick_vcpu_thread = mttcg_kick_vcpu_thread, | ||
195 | |||
196 | - .handle_interrupt = tcg_handle_interrupt, | ||
197 | + .handle_interrupt = tcg_cpus_handle_interrupt, | ||
198 | }; | ||
199 | diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c | ||
200 | index XXXXXXX..XXXXXXX 100644 | ||
201 | --- a/accel/tcg/tcg-cpus-rr.c | ||
202 | +++ b/accel/tcg/tcg-cpus-rr.c | ||
203 | @@ -XXX,XX +XXX,XX @@ | ||
204 | #include "tcg-cpus-icount.h" | ||
205 | |||
206 | /* Kick all RR vCPUs */ | ||
207 | -void qemu_cpu_kick_rr_cpus(CPUState *unused) | ||
208 | +void rr_kick_vcpu_thread(CPUState *unused) | ||
209 | { | ||
210 | CPUState *cpu; | ||
211 | |||
212 | @@ -XXX,XX +XXX,XX @@ void qemu_cpu_kick_rr_cpus(CPUState *unused) | ||
213 | * idleness is complete. | ||
214 | */ | ||
215 | |||
216 | -static QEMUTimer *tcg_kick_vcpu_timer; | ||
217 | -static CPUState *tcg_current_rr_cpu; | ||
218 | +static QEMUTimer *rr_kick_vcpu_timer; | ||
219 | +static CPUState *rr_current_cpu; | ||
220 | |||
221 | #define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) | ||
222 | |||
223 | -static inline int64_t qemu_tcg_next_kick(void) | ||
224 | +static inline int64_t rr_next_kick_time(void) | ||
225 | { | ||
226 | return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD; | ||
227 | } | ||
228 | |||
229 | /* Kick the currently round-robin scheduled vCPU to next */ | ||
230 | -static void qemu_cpu_kick_rr_next_cpu(void) | ||
231 | +static void rr_kick_next_cpu(void) | ||
232 | { | ||
233 | CPUState *cpu; | ||
234 | do { | ||
235 | - cpu = qatomic_mb_read(&tcg_current_rr_cpu); | ||
236 | + cpu = qatomic_mb_read(&rr_current_cpu); | ||
237 | if (cpu) { | ||
238 | cpu_exit(cpu); | ||
239 | } | ||
240 | - } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu)); | ||
241 | + } while (cpu != qatomic_mb_read(&rr_current_cpu)); | ||
242 | } | ||
243 | |||
244 | -static void kick_tcg_thread(void *opaque) | ||
245 | +static void rr_kick_thread(void *opaque) | ||
246 | { | ||
247 | - timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
248 | - qemu_cpu_kick_rr_next_cpu(); | ||
249 | + timer_mod(rr_kick_vcpu_timer, rr_next_kick_time()); | ||
250 | + rr_kick_next_cpu(); | ||
251 | } | ||
252 | |||
253 | -static void start_tcg_kick_timer(void) | ||
254 | +static void rr_start_kick_timer(void) | ||
255 | { | ||
256 | - if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { | ||
257 | - tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
258 | - kick_tcg_thread, NULL); | ||
259 | + if (!rr_kick_vcpu_timer && CPU_NEXT(first_cpu)) { | ||
260 | + rr_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
261 | + rr_kick_thread, NULL); | ||
262 | } | ||
263 | - if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) { | ||
264 | - timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
265 | + if (rr_kick_vcpu_timer && !timer_pending(rr_kick_vcpu_timer)) { | ||
266 | + timer_mod(rr_kick_vcpu_timer, rr_next_kick_time()); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | -static void stop_tcg_kick_timer(void) | ||
271 | +static void rr_stop_kick_timer(void) | ||
272 | { | ||
273 | - if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) { | ||
274 | - timer_del(tcg_kick_vcpu_timer); | ||
275 | + if (rr_kick_vcpu_timer && timer_pending(rr_kick_vcpu_timer)) { | ||
276 | + timer_del(rr_kick_vcpu_timer); | ||
277 | } | ||
278 | } | ||
279 | |||
280 | -static void qemu_tcg_rr_wait_io_event(void) | ||
281 | +static void rr_wait_io_event(void) | ||
282 | { | ||
283 | CPUState *cpu; | ||
284 | |||
285 | while (all_cpu_threads_idle()) { | ||
286 | - stop_tcg_kick_timer(); | ||
287 | + rr_stop_kick_timer(); | ||
288 | qemu_cond_wait_iothread(first_cpu->halt_cond); | ||
289 | } | ||
290 | |||
291 | - start_tcg_kick_timer(); | ||
292 | + rr_start_kick_timer(); | ||
293 | |||
294 | CPU_FOREACH(cpu) { | ||
295 | qemu_wait_io_event_common(cpu); | ||
296 | @@ -XXX,XX +XXX,XX @@ static void qemu_tcg_rr_wait_io_event(void) | ||
297 | * Destroy any remaining vCPUs which have been unplugged and have | ||
298 | * finished running | ||
299 | */ | ||
300 | -static void deal_with_unplugged_cpus(void) | ||
301 | +static void rr_deal_with_unplugged_cpus(void) | ||
302 | { | ||
303 | CPUState *cpu; | ||
304 | |||
305 | CPU_FOREACH(cpu) { | ||
306 | if (cpu->unplug && !cpu_can_run(cpu)) { | ||
307 | - qemu_tcg_destroy_vcpu(cpu); | ||
308 | + tcg_cpus_destroy(cpu); | ||
309 | break; | 461 | break; |
310 | } | 462 | } |
311 | } | 463 | |
312 | @@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void) | 464 | - case INDEX_op_plugin_cb_start: |
313 | * elsewhere. | 465 | + case INDEX_op_plugin_mem_cb: |
314 | */ | 466 | { |
315 | 467 | - enum plugin_gen_from from = op->args[0]; | |
316 | -static void *tcg_rr_cpu_thread_fn(void *arg) | 468 | - enum plugin_gen_cb type = op->args[1]; |
317 | +static void *rr_cpu_thread_fn(void *arg) | 469 | + TCGv_i64 addr = temp_tcgv_i64(arg_temp(op->args[0])); |
318 | { | 470 | + qemu_plugin_meminfo_t meminfo = op->args[1]; |
319 | CPUState *cpu = arg; | 471 | + struct qemu_plugin_insn *insn; |
320 | 472 | + const GArray *cbs; | |
321 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | 473 | + int i, n, rw; |
474 | |||
475 | - switch (from) { | ||
476 | - case PLUGIN_GEN_FROM_MEM: | ||
477 | - { | ||
478 | - g_assert(insn_idx >= 0); | ||
479 | + assert(insn_idx >= 0); | ||
480 | + insn = g_ptr_array_index(plugin_tb->insns, insn_idx); | ||
481 | + rw = qemu_plugin_mem_is_store(meminfo) ? 2 : 1; | ||
482 | |||
483 | - switch (type) { | ||
484 | - case PLUGIN_GEN_CB_MEM: | ||
485 | - plugin_gen_mem_regular(plugin_tb, op, insn_idx); | ||
486 | - break; | ||
487 | - case PLUGIN_GEN_CB_INLINE: | ||
488 | - plugin_gen_mem_inline(plugin_tb, op, insn_idx); | ||
489 | - break; | ||
490 | - default: | ||
491 | - g_assert_not_reached(); | ||
492 | + tcg_ctx->emit_before_op = op; | ||
493 | + | ||
494 | + cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; | ||
495 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
496 | + struct qemu_plugin_dyn_cb *cb = | ||
497 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
498 | + if (cb->rw & rw) { | ||
499 | + gen_mem_cb(cb, meminfo, addr); | ||
500 | } | ||
501 | + } | ||
502 | |||
503 | - break; | ||
504 | - } | ||
505 | - default: | ||
506 | - g_assert_not_reached(); | ||
507 | + cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
508 | + for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
509 | + struct qemu_plugin_dyn_cb *cb = | ||
510 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
511 | + if (cb->rw & rw) { | ||
512 | + gen_inline_cb(cb); | ||
513 | + } | ||
514 | } | ||
515 | + | ||
516 | + tcg_ctx->emit_before_op = NULL; | ||
517 | + tcg_op_remove(tcg_ctx, op); | ||
518 | break; | ||
519 | } | ||
520 | + | ||
521 | default: | ||
522 | /* plugins don't care about any other ops */ | ||
523 | break; | ||
524 | diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c | ||
525 | index XXXXXXX..XXXXXXX 100644 | ||
526 | --- a/tcg/tcg-op-ldst.c | ||
527 | +++ b/tcg/tcg-op-ldst.c | ||
528 | @@ -XXX,XX +XXX,XX @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi, | ||
529 | copy_addr = tcg_temp_ebb_new_i64(); | ||
530 | tcg_gen_extu_i32_i64(copy_addr, temp_tcgv_i32(orig_addr)); | ||
531 | } | ||
532 | - plugin_gen_empty_mem_callback(copy_addr, info); | ||
533 | + tcg_gen_plugin_mem_cb(copy_addr, info); | ||
534 | tcg_temp_free_i64(copy_addr); | ||
535 | } else { | ||
536 | if (copy_addr) { | ||
537 | - plugin_gen_empty_mem_callback(copy_addr, info); | ||
538 | + tcg_gen_plugin_mem_cb(copy_addr, info); | ||
539 | tcg_temp_free_i64(copy_addr); | ||
540 | } else { | ||
541 | - plugin_gen_empty_mem_callback(temp_tcgv_i64(orig_addr), info); | ||
542 | + tcg_gen_plugin_mem_cb(temp_tcgv_i64(orig_addr), info); | ||
543 | } | ||
322 | } | 544 | } |
323 | } | 545 | } |
324 | 546 | diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c | |
325 | - start_tcg_kick_timer(); | ||
326 | + rr_start_kick_timer(); | ||
327 | |||
328 | cpu = first_cpu; | ||
329 | |||
330 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
331 | * Run the timers here. This is much more efficient than | ||
332 | * waking up the I/O thread and waiting for completion. | ||
333 | */ | ||
334 | - handle_icount_deadline(); | ||
335 | + icount_handle_deadline(); | ||
336 | } | ||
337 | |||
338 | replay_mutex_unlock(); | ||
339 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
340 | |||
341 | while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { | ||
342 | |||
343 | - qatomic_mb_set(&tcg_current_rr_cpu, cpu); | ||
344 | + qatomic_mb_set(&rr_current_cpu, cpu); | ||
345 | current_cpu = cpu; | ||
346 | |||
347 | qemu_clock_enable(QEMU_CLOCK_VIRTUAL, | ||
348 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
349 | |||
350 | qemu_mutex_unlock_iothread(); | ||
351 | if (icount_enabled()) { | ||
352 | - prepare_icount_for_run(cpu); | ||
353 | + icount_prepare_for_run(cpu); | ||
354 | } | ||
355 | - r = tcg_cpu_exec(cpu); | ||
356 | + r = tcg_cpus_exec(cpu); | ||
357 | if (icount_enabled()) { | ||
358 | - process_icount_data(cpu); | ||
359 | + icount_process_data(cpu); | ||
360 | } | ||
361 | qemu_mutex_lock_iothread(); | ||
362 | |||
363 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
364 | } /* while (cpu && !cpu->exit_request).. */ | ||
365 | |||
366 | /* Does not need qatomic_mb_set because a spurious wakeup is okay. */ | ||
367 | - qatomic_set(&tcg_current_rr_cpu, NULL); | ||
368 | + qatomic_set(&rr_current_cpu, NULL); | ||
369 | |||
370 | if (cpu && cpu->exit_request) { | ||
371 | qatomic_mb_set(&cpu->exit_request, 0); | ||
372 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
373 | qemu_notify_event(); | ||
374 | } | ||
375 | |||
376 | - qemu_tcg_rr_wait_io_event(); | ||
377 | - deal_with_unplugged_cpus(); | ||
378 | + rr_wait_io_event(); | ||
379 | + rr_deal_with_unplugged_cpus(); | ||
380 | } | ||
381 | |||
382 | rcu_unregister_thread(); | ||
383 | @@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu) | ||
384 | /* share a single thread for all cpus with TCG */ | ||
385 | snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); | ||
386 | qemu_thread_create(cpu->thread, thread_name, | ||
387 | - tcg_rr_cpu_thread_fn, | ||
388 | + rr_cpu_thread_fn, | ||
389 | cpu, QEMU_THREAD_JOINABLE); | ||
390 | |||
391 | single_tcg_halt_cond = cpu->halt_cond; | ||
392 | @@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu) | ||
393 | |||
394 | const CpusAccel tcg_cpus_rr = { | ||
395 | .create_vcpu_thread = rr_start_vcpu_thread, | ||
396 | - .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
397 | + .kick_vcpu_thread = rr_kick_vcpu_thread, | ||
398 | |||
399 | - .handle_interrupt = tcg_handle_interrupt, | ||
400 | + .handle_interrupt = tcg_cpus_handle_interrupt, | ||
401 | }; | ||
402 | diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c | ||
403 | index XXXXXXX..XXXXXXX 100644 | 547 | index XXXXXXX..XXXXXXX 100644 |
404 | --- a/accel/tcg/tcg-cpus.c | 548 | --- a/tcg/tcg-op.c |
405 | +++ b/accel/tcg/tcg-cpus.c | 549 | +++ b/tcg/tcg-op.c |
406 | @@ -XXX,XX +XXX,XX @@ | 550 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_plugin_cb(unsigned from) |
407 | 551 | tcg_gen_op1(INDEX_op_plugin_cb, from); | |
408 | /* common functionality among all TCG variants */ | 552 | } |
409 | 553 | ||
410 | -void qemu_tcg_destroy_vcpu(CPUState *cpu) | 554 | +void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo) |
411 | +void tcg_cpus_destroy(CPUState *cpu) | 555 | +{ |
556 | + tcg_gen_op2(INDEX_op_plugin_mem_cb, tcgv_i64_arg(addr), meminfo); | ||
557 | +} | ||
558 | + | ||
559 | void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr) | ||
412 | { | 560 | { |
413 | cpu_thread_signal_destroyed(cpu); | 561 | tcg_gen_op3(INDEX_op_plugin_cb_start, from, type, wr); |
414 | } | ||
415 | |||
416 | -int tcg_cpu_exec(CPUState *cpu) | ||
417 | +int tcg_cpus_exec(CPUState *cpu) | ||
418 | { | ||
419 | int ret; | ||
420 | #ifdef CONFIG_PROFILER | ||
421 | @@ -XXX,XX +XXX,XX @@ int tcg_cpu_exec(CPUState *cpu) | ||
422 | } | ||
423 | |||
424 | /* mask must never be zero, except for A20 change call */ | ||
425 | -void tcg_handle_interrupt(CPUState *cpu, int mask) | ||
426 | +void tcg_cpus_handle_interrupt(CPUState *cpu, int mask) | ||
427 | { | ||
428 | g_assert(qemu_mutex_iothread_locked()); | ||
429 | |||
430 | -- | 562 | -- |
431 | 2.25.1 | 563 | 2.34.1 |
432 | |||
433 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | These placeholder helpers are no longer required. | ||
1 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | accel/tcg/plugin-helpers.h | 5 ----- | ||
7 | include/exec/helper-gen-common.h | 4 ---- | ||
8 | include/exec/helper-proto-common.h | 4 ---- | ||
9 | accel/tcg/plugin-gen.c | 20 -------------------- | ||
10 | 4 files changed, 33 deletions(-) | ||
11 | delete mode 100644 accel/tcg/plugin-helpers.h | ||
12 | |||
13 | diff --git a/accel/tcg/plugin-helpers.h b/accel/tcg/plugin-helpers.h | ||
14 | deleted file mode 100644 | ||
15 | index XXXXXXX..XXXXXXX | ||
16 | --- a/accel/tcg/plugin-helpers.h | ||
17 | +++ /dev/null | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | -#ifdef CONFIG_PLUGIN | ||
20 | -DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_wg, TCG_CALL_NO_WG | TCG_CALL_PLUGIN, void, i32, ptr) | ||
21 | -DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_rwg, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, ptr) | ||
22 | -DEF_HELPER_FLAGS_4(plugin_vcpu_mem_cb, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, i32, i64, ptr) | ||
23 | -#endif | ||
24 | diff --git a/include/exec/helper-gen-common.h b/include/exec/helper-gen-common.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/exec/helper-gen-common.h | ||
27 | +++ b/include/exec/helper-gen-common.h | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | #include "exec/helper-gen.h.inc" | ||
30 | #undef HELPER_H | ||
31 | |||
32 | -#define HELPER_H "accel/tcg/plugin-helpers.h" | ||
33 | -#include "exec/helper-gen.h.inc" | ||
34 | -#undef HELPER_H | ||
35 | - | ||
36 | #endif /* HELPER_GEN_COMMON_H */ | ||
37 | diff --git a/include/exec/helper-proto-common.h b/include/exec/helper-proto-common.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/include/exec/helper-proto-common.h | ||
40 | +++ b/include/exec/helper-proto-common.h | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | #include "exec/helper-proto.h.inc" | ||
43 | #undef HELPER_H | ||
44 | |||
45 | -#define HELPER_H "accel/tcg/plugin-helpers.h" | ||
46 | -#include "exec/helper-proto.h.inc" | ||
47 | -#undef HELPER_H | ||
48 | - | ||
49 | #endif /* HELPER_PROTO_COMMON_H */ | ||
50 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/accel/tcg/plugin-gen.c | ||
53 | +++ b/accel/tcg/plugin-gen.c | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | #include "exec/exec-all.h" | ||
56 | #include "exec/plugin-gen.h" | ||
57 | #include "exec/translator.h" | ||
58 | -#include "exec/helper-proto-common.h" | ||
59 | - | ||
60 | -#define HELPER_H "accel/tcg/plugin-helpers.h" | ||
61 | -#include "exec/helper-info.c.inc" | ||
62 | -#undef HELPER_H | ||
63 | |||
64 | /* | ||
65 | * plugin_cb_start TCG op args[]: | ||
66 | @@ -XXX,XX +XXX,XX @@ enum plugin_gen_cb { | ||
67 | PLUGIN_GEN_N_CBS, | ||
68 | }; | ||
69 | |||
70 | -/* | ||
71 | - * These helpers are stubs that get dynamically switched out for calls | ||
72 | - * direct to the plugin if they are subscribed to. | ||
73 | - */ | ||
74 | -void HELPER(plugin_vcpu_udata_cb_no_wg)(uint32_t cpu_index, void *udata) | ||
75 | -{ } | ||
76 | - | ||
77 | -void HELPER(plugin_vcpu_udata_cb_no_rwg)(uint32_t cpu_index, void *udata) | ||
78 | -{ } | ||
79 | - | ||
80 | -void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, | ||
81 | - qemu_plugin_meminfo_t info, uint64_t vaddr, | ||
82 | - void *userdata) | ||
83 | -{ } | ||
84 | - | ||
85 | static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
86 | { | ||
87 | switch (from) { | ||
88 | -- | ||
89 | 2.34.1 | ||
90 | |||
91 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Since we no longer emit plugin helpers during the initial code | ||
2 | translation phase, we don't need to specially mark plugin helpers. | ||
1 | 3 | ||
4 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | include/tcg/tcg.h | 2 -- | ||
8 | plugins/core.c | 10 ++++------ | ||
9 | tcg/tcg.c | 4 +--- | ||
10 | 3 files changed, 5 insertions(+), 11 deletions(-) | ||
11 | |||
12 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/tcg/tcg.h | ||
15 | +++ b/include/tcg/tcg.h | ||
16 | @@ -XXX,XX +XXX,XX @@ typedef TCGv_ptr TCGv_env; | ||
17 | #define TCG_CALL_NO_SIDE_EFFECTS 0x0004 | ||
18 | /* Helper is G_NORETURN. */ | ||
19 | #define TCG_CALL_NO_RETURN 0x0008 | ||
20 | -/* Helper is part of Plugins. */ | ||
21 | -#define TCG_CALL_PLUGIN 0x0010 | ||
22 | |||
23 | /* convenience version of most used call flags */ | ||
24 | #define TCG_CALL_NO_RWG TCG_CALL_NO_READ_GLOBALS | ||
25 | diff --git a/plugins/core.c b/plugins/core.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/plugins/core.c | ||
28 | +++ b/plugins/core.c | ||
29 | @@ -XXX,XX +XXX,XX @@ void plugin_register_dyn_cb__udata(GArray **arr, | ||
30 | void *udata) | ||
31 | { | ||
32 | static TCGHelperInfo info[3] = { | ||
33 | - [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, | ||
34 | - [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG | TCG_CALL_PLUGIN, | ||
35 | - [QEMU_PLUGIN_CB_RW_REGS].flags = TCG_CALL_PLUGIN, | ||
36 | + [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG, | ||
37 | + [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG, | ||
38 | /* | ||
39 | * Match qemu_plugin_vcpu_udata_cb_t: | ||
40 | * void (*)(uint32_t, void *) | ||
41 | @@ -XXX,XX +XXX,XX @@ void plugin_register_vcpu_mem_cb(GArray **arr, | ||
42 | !__builtin_types_compatible_p(qemu_plugin_meminfo_t, int32_t)); | ||
43 | |||
44 | static TCGHelperInfo info[3] = { | ||
45 | - [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, | ||
46 | - [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG | TCG_CALL_PLUGIN, | ||
47 | - [QEMU_PLUGIN_CB_RW_REGS].flags = TCG_CALL_PLUGIN, | ||
48 | + [QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG, | ||
49 | + [QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG, | ||
50 | /* | ||
51 | * Match qemu_plugin_vcpu_mem_cb_t: | ||
52 | * void (*)(uint32_t, qemu_plugin_meminfo_t, uint64_t, void *) | ||
53 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/tcg/tcg.c | ||
56 | +++ b/tcg/tcg.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_callN(void *func, TCGHelperInfo *info, | ||
58 | |||
59 | #ifdef CONFIG_PLUGIN | ||
60 | /* Flag helpers that may affect guest state */ | ||
61 | - if (tcg_ctx->plugin_insn && | ||
62 | - !(info->flags & TCG_CALL_PLUGIN) && | ||
63 | - !(info->flags & TCG_CALL_NO_SIDE_EFFECTS)) { | ||
64 | + if (tcg_ctx->plugin_insn && !(info->flags & TCG_CALL_NO_SIDE_EFFECTS)) { | ||
65 | tcg_ctx->plugin_insn->calls_helpers = true; | ||
66 | } | ||
67 | #endif | ||
68 | -- | ||
69 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | These opcodes are no longer used. | ||
1 | 2 | ||
3 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | include/tcg/tcg-op-common.h | 2 -- | ||
7 | include/tcg/tcg-opc.h | 2 -- | ||
8 | accel/tcg/plugin-gen.c | 18 ------------------ | ||
9 | tcg/tcg-op.c | 10 ---------- | ||
10 | 4 files changed, 32 deletions(-) | ||
11 | |||
12 | diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/tcg/tcg-op-common.h | ||
15 | +++ b/include/tcg/tcg-op-common.h | ||
16 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_lookup_and_goto_ptr(void); | ||
17 | |||
18 | void tcg_gen_plugin_cb(unsigned from); | ||
19 | void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo); | ||
20 | -void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr); | ||
21 | -void tcg_gen_plugin_cb_end(void); | ||
22 | |||
23 | /* 32 bit ops */ | ||
24 | |||
25 | diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/tcg/tcg-opc.h | ||
28 | +++ b/include/tcg/tcg-opc.h | ||
29 | @@ -XXX,XX +XXX,XX @@ DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) | ||
30 | |||
31 | DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT) | ||
32 | DEF(plugin_mem_cb, 0, 1, 1, TCG_OPF_NOT_PRESENT) | ||
33 | -DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) | ||
34 | -DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) | ||
35 | |||
36 | /* Replicate ld/st ops for 32 and 64-bit guest addresses. */ | ||
37 | DEF(qemu_ld_a32_i32, 1, 1, 1, | ||
38 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/accel/tcg/plugin-gen.c | ||
41 | +++ b/accel/tcg/plugin-gen.c | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | #include "exec/plugin-gen.h" | ||
44 | #include "exec/translator.h" | ||
45 | |||
46 | -/* | ||
47 | - * plugin_cb_start TCG op args[]: | ||
48 | - * 0: enum plugin_gen_from | ||
49 | - * 1: enum plugin_gen_cb | ||
50 | - * 2: set to 1 for mem callback that is a write, 0 otherwise. | ||
51 | - */ | ||
52 | - | ||
53 | enum plugin_gen_from { | ||
54 | PLUGIN_GEN_FROM_TB, | ||
55 | PLUGIN_GEN_FROM_INSN, | ||
56 | PLUGIN_GEN_AFTER_INSN, | ||
57 | PLUGIN_GEN_AFTER_TB, | ||
58 | - PLUGIN_GEN_N_FROMS, | ||
59 | -}; | ||
60 | - | ||
61 | -enum plugin_gen_cb { | ||
62 | - PLUGIN_GEN_CB_UDATA, | ||
63 | - PLUGIN_GEN_CB_UDATA_R, | ||
64 | - PLUGIN_GEN_CB_INLINE, | ||
65 | - PLUGIN_GEN_CB_MEM, | ||
66 | - PLUGIN_GEN_ENABLE_MEM_HELPER, | ||
67 | - PLUGIN_GEN_DISABLE_MEM_HELPER, | ||
68 | - PLUGIN_GEN_N_CBS, | ||
69 | }; | ||
70 | |||
71 | static void plugin_gen_empty_callback(enum plugin_gen_from from) | ||
72 | diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/tcg/tcg-op.c | ||
75 | +++ b/tcg/tcg-op.c | ||
76 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo) | ||
77 | tcg_gen_op2(INDEX_op_plugin_mem_cb, tcgv_i64_arg(addr), meminfo); | ||
78 | } | ||
79 | |||
80 | -void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr) | ||
81 | -{ | ||
82 | - tcg_gen_op3(INDEX_op_plugin_cb_start, from, type, wr); | ||
83 | -} | ||
84 | - | ||
85 | -void tcg_gen_plugin_cb_end(void) | ||
86 | -{ | ||
87 | - tcg_emit_op(INDEX_op_plugin_cb_end, 0); | ||
88 | -} | ||
89 | - | ||
90 | /* 32 bit ops */ | ||
91 | |||
92 | void tcg_gen_discard_i32(TCGv_i32 arg) | ||
93 | -- | ||
94 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We have qemu_plugin_dyn_cb.type to differentiate the various | ||
2 | callback types, so we do not need to keep them in separate queues. | ||
1 | 3 | ||
4 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | include/qemu/plugin.h | 35 ++++++---------- | ||
8 | accel/tcg/plugin-gen.c | 90 ++++++++++++++++++++++-------------------- | ||
9 | plugins/api.c | 18 +++------ | ||
10 | 3 files changed, 65 insertions(+), 78 deletions(-) | ||
11 | |||
12 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/qemu/plugin.h | ||
15 | +++ b/include/qemu/plugin.h | ||
16 | @@ -XXX,XX +XXX,XX @@ union qemu_plugin_cb_sig { | ||
17 | }; | ||
18 | |||
19 | enum plugin_dyn_cb_type { | ||
20 | - PLUGIN_CB_INSN, | ||
21 | - PLUGIN_CB_MEM, | ||
22 | - PLUGIN_N_CB_TYPES, | ||
23 | -}; | ||
24 | - | ||
25 | -enum plugin_dyn_cb_subtype { | ||
26 | PLUGIN_CB_REGULAR, | ||
27 | PLUGIN_CB_INLINE, | ||
28 | - PLUGIN_N_CB_SUBTYPES, | ||
29 | }; | ||
30 | |||
31 | /* | ||
32 | @@ -XXX,XX +XXX,XX @@ enum plugin_dyn_cb_subtype { | ||
33 | */ | ||
34 | struct qemu_plugin_dyn_cb { | ||
35 | void *userp; | ||
36 | - enum plugin_dyn_cb_subtype type; | ||
37 | + enum plugin_dyn_cb_type type; | ||
38 | /* @rw applies to mem callbacks only (both regular and inline) */ | ||
39 | enum qemu_plugin_mem_rw rw; | ||
40 | /* fields specific to each dyn_cb type go here */ | ||
41 | @@ -XXX,XX +XXX,XX @@ struct qemu_plugin_insn { | ||
42 | GByteArray *data; | ||
43 | uint64_t vaddr; | ||
44 | void *haddr; | ||
45 | - GArray *cbs[PLUGIN_N_CB_TYPES][PLUGIN_N_CB_SUBTYPES]; | ||
46 | + GArray *insn_cbs; | ||
47 | + GArray *mem_cbs; | ||
48 | bool calls_helpers; | ||
49 | |||
50 | /* if set, the instruction calls helpers that might access guest memory */ | ||
51 | @@ -XXX,XX +XXX,XX @@ static inline void qemu_plugin_insn_cleanup_fn(gpointer data) | ||
52 | |||
53 | static inline struct qemu_plugin_insn *qemu_plugin_insn_alloc(void) | ||
54 | { | ||
55 | - int i, j; | ||
56 | struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); | ||
57 | - insn->data = g_byte_array_sized_new(4); | ||
58 | |||
59 | - for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { | ||
60 | - for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { | ||
61 | - insn->cbs[i][j] = g_array_new(false, false, | ||
62 | - sizeof(struct qemu_plugin_dyn_cb)); | ||
63 | - } | ||
64 | - } | ||
65 | + insn->data = g_byte_array_sized_new(4); | ||
66 | return insn; | ||
67 | } | ||
68 | |||
69 | @@ -XXX,XX +XXX,XX @@ struct qemu_plugin_tb { | ||
70 | /* if set, the TB calls helpers that might access guest memory */ | ||
71 | bool mem_helper; | ||
72 | |||
73 | - GArray *cbs[PLUGIN_N_CB_SUBTYPES]; | ||
74 | + GArray *cbs; | ||
75 | }; | ||
76 | |||
77 | /** | ||
78 | @@ -XXX,XX +XXX,XX @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, | ||
79 | uint64_t pc) | ||
80 | { | ||
81 | struct qemu_plugin_insn *insn; | ||
82 | - int i, j; | ||
83 | |||
84 | if (unlikely(tb->n == tb->insns->len)) { | ||
85 | struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc(); | ||
86 | g_ptr_array_add(tb->insns, new_insn); | ||
87 | } | ||
88 | + | ||
89 | insn = g_ptr_array_index(tb->insns, tb->n++); | ||
90 | g_byte_array_set_size(insn->data, 0); | ||
91 | insn->calls_helpers = false; | ||
92 | insn->mem_helper = false; | ||
93 | insn->vaddr = pc; | ||
94 | - | ||
95 | - for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { | ||
96 | - for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { | ||
97 | - g_array_set_size(insn->cbs[i][j], 0); | ||
98 | - } | ||
99 | + if (insn->insn_cbs) { | ||
100 | + g_array_set_size(insn->insn_cbs, 0); | ||
101 | + } | ||
102 | + if (insn->mem_cbs) { | ||
103 | + g_array_set_size(insn->mem_cbs, 0); | ||
104 | } | ||
105 | |||
106 | return insn; | ||
107 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/accel/tcg/plugin-gen.c | ||
110 | +++ b/accel/tcg/plugin-gen.c | ||
111 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_disable_mem_helpers(void) | ||
112 | static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
113 | struct qemu_plugin_insn *insn) | ||
114 | { | ||
115 | - GArray *cbs[2]; | ||
116 | GArray *arr; | ||
117 | - size_t n_cbs; | ||
118 | + size_t len; | ||
119 | |||
120 | /* | ||
121 | * Tracking memory accesses performed from helpers requires extra work. | ||
122 | @@ -XXX,XX +XXX,XX @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb, | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | - cbs[0] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; | ||
127 | - cbs[1] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
128 | - n_cbs = cbs[0]->len + cbs[1]->len; | ||
129 | - | ||
130 | - if (n_cbs == 0) { | ||
131 | + if (!insn->mem_cbs || !insn->mem_cbs->len) { | ||
132 | insn->mem_helper = false; | ||
133 | return; | ||
134 | } | ||
135 | insn->mem_helper = true; | ||
136 | ptb->mem_helper = true; | ||
137 | |||
138 | + /* | ||
139 | + * TODO: It seems like we should be able to use ref/unref | ||
140 | + * to avoid needing to actually copy this array. | ||
141 | + * Alternately, perhaps we could allocate new memory adjacent | ||
142 | + * to the TranslationBlock itself, so that we do not have to | ||
143 | + * actively manage the lifetime after this. | ||
144 | + */ | ||
145 | + len = insn->mem_cbs->len; | ||
146 | arr = g_array_sized_new(false, false, | ||
147 | - sizeof(struct qemu_plugin_dyn_cb), n_cbs); | ||
148 | - g_array_append_vals(arr, cbs[0]->data, cbs[0]->len); | ||
149 | - g_array_append_vals(arr, cbs[1]->data, cbs[1]->len); | ||
150 | - | ||
151 | + sizeof(struct qemu_plugin_dyn_cb), len); | ||
152 | + memcpy(arr->data, insn->mem_cbs->data, | ||
153 | + len * sizeof(struct qemu_plugin_dyn_cb)); | ||
154 | qemu_plugin_add_dyn_cb_arr(arr); | ||
155 | |||
156 | tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env, | ||
157 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
158 | case PLUGIN_GEN_FROM_TB: | ||
159 | assert(insn == NULL); | ||
160 | |||
161 | - cbs = plugin_tb->cbs[PLUGIN_CB_REGULAR]; | ||
162 | + cbs = plugin_tb->cbs; | ||
163 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
164 | struct qemu_plugin_dyn_cb *cb = | ||
165 | &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
166 | - gen_udata_cb(cb); | ||
167 | - } | ||
168 | |||
169 | - cbs = plugin_tb->cbs[PLUGIN_CB_INLINE]; | ||
170 | - for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
171 | - struct qemu_plugin_dyn_cb *cb = | ||
172 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
173 | - gen_inline_cb(cb); | ||
174 | + switch (cb->type) { | ||
175 | + case PLUGIN_CB_REGULAR: | ||
176 | + gen_udata_cb(cb); | ||
177 | + break; | ||
178 | + case PLUGIN_CB_INLINE: | ||
179 | + gen_inline_cb(cb); | ||
180 | + break; | ||
181 | + default: | ||
182 | + g_assert_not_reached(); | ||
183 | + } | ||
184 | } | ||
185 | break; | ||
186 | |||
187 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
188 | |||
189 | gen_enable_mem_helper(plugin_tb, insn); | ||
190 | |||
191 | - cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR]; | ||
192 | + cbs = insn->insn_cbs; | ||
193 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
194 | struct qemu_plugin_dyn_cb *cb = | ||
195 | &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
196 | - gen_udata_cb(cb); | ||
197 | - } | ||
198 | |||
199 | - cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE]; | ||
200 | - for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
201 | - struct qemu_plugin_dyn_cb *cb = | ||
202 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
203 | - gen_inline_cb(cb); | ||
204 | + switch (cb->type) { | ||
205 | + case PLUGIN_CB_REGULAR: | ||
206 | + gen_udata_cb(cb); | ||
207 | + break; | ||
208 | + case PLUGIN_CB_INLINE: | ||
209 | + gen_inline_cb(cb); | ||
210 | + break; | ||
211 | + default: | ||
212 | + g_assert_not_reached(); | ||
213 | + } | ||
214 | } | ||
215 | break; | ||
216 | |||
217 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
218 | |||
219 | tcg_ctx->emit_before_op = op; | ||
220 | |||
221 | - cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; | ||
222 | + cbs = insn->mem_cbs; | ||
223 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
224 | struct qemu_plugin_dyn_cb *cb = | ||
225 | &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
226 | - if (cb->rw & rw) { | ||
227 | - gen_mem_cb(cb, meminfo, addr); | ||
228 | - } | ||
229 | - } | ||
230 | |||
231 | - cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; | ||
232 | - for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
233 | - struct qemu_plugin_dyn_cb *cb = | ||
234 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
235 | if (cb->rw & rw) { | ||
236 | - gen_inline_cb(cb); | ||
237 | + switch (cb->type) { | ||
238 | + case PLUGIN_CB_REGULAR: | ||
239 | + gen_mem_cb(cb, meminfo, addr); | ||
240 | + break; | ||
241 | + case PLUGIN_CB_INLINE: | ||
242 | + gen_inline_cb(cb); | ||
243 | + break; | ||
244 | + default: | ||
245 | + g_assert_not_reached(); | ||
246 | + } | ||
247 | } | ||
248 | } | ||
249 | |||
250 | @@ -XXX,XX +XXX,XX @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, | ||
251 | |||
252 | if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_state->event_mask)) { | ||
253 | struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; | ||
254 | - int i; | ||
255 | |||
256 | /* reset callbacks */ | ||
257 | - for (i = 0; i < PLUGIN_N_CB_SUBTYPES; i++) { | ||
258 | - if (ptb->cbs[i]) { | ||
259 | - g_array_set_size(ptb->cbs[i], 0); | ||
260 | - } | ||
261 | + if (ptb->cbs) { | ||
262 | + g_array_set_size(ptb->cbs, 0); | ||
263 | } | ||
264 | ptb->n = 0; | ||
265 | |||
266 | diff --git a/plugins/api.c b/plugins/api.c | ||
267 | index XXXXXXX..XXXXXXX 100644 | ||
268 | --- a/plugins/api.c | ||
269 | +++ b/plugins/api.c | ||
270 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, | ||
271 | void *udata) | ||
272 | { | ||
273 | if (!tb->mem_only) { | ||
274 | - plugin_register_dyn_cb__udata(&tb->cbs[PLUGIN_CB_REGULAR], | ||
275 | - cb, flags, udata); | ||
276 | + plugin_register_dyn_cb__udata(&tb->cbs, cb, flags, udata); | ||
277 | } | ||
278 | } | ||
279 | |||
280 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( | ||
281 | uint64_t imm) | ||
282 | { | ||
283 | if (!tb->mem_only) { | ||
284 | - plugin_register_inline_op_on_entry( | ||
285 | - &tb->cbs[PLUGIN_CB_INLINE], 0, op, entry, imm); | ||
286 | + plugin_register_inline_op_on_entry(&tb->cbs, 0, op, entry, imm); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, | ||
291 | void *udata) | ||
292 | { | ||
293 | if (!insn->mem_only) { | ||
294 | - plugin_register_dyn_cb__udata( | ||
295 | - &insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], cb, flags, udata); | ||
296 | + plugin_register_dyn_cb__udata(&insn->insn_cbs, cb, flags, udata); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( | ||
301 | uint64_t imm) | ||
302 | { | ||
303 | if (!insn->mem_only) { | ||
304 | - plugin_register_inline_op_on_entry( | ||
305 | - &insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], 0, op, entry, imm); | ||
306 | + plugin_register_inline_op_on_entry(&insn->insn_cbs, 0, op, entry, imm); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, | ||
311 | enum qemu_plugin_mem_rw rw, | ||
312 | void *udata) | ||
313 | { | ||
314 | - plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], | ||
315 | - cb, flags, rw, udata); | ||
316 | + plugin_register_vcpu_mem_cb(&insn->mem_cbs, cb, flags, rw, udata); | ||
317 | } | ||
318 | |||
319 | void qemu_plugin_register_vcpu_mem_inline_per_vcpu( | ||
320 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_register_vcpu_mem_inline_per_vcpu( | ||
321 | qemu_plugin_u64 entry, | ||
322 | uint64_t imm) | ||
323 | { | ||
324 | - plugin_register_inline_op_on_entry( | ||
325 | - &insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], rw, op, entry, imm); | ||
326 | + plugin_register_inline_op_on_entry(&insn->mem_cbs, rw, op, entry, imm); | ||
327 | } | ||
328 | |||
329 | void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, | ||
330 | -- | ||
331 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Use different enumerators for vcpu_udata and vcpu_mem callbacks. | ||
1 | 2 | ||
3 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | include/qemu/plugin.h | 1 + | ||
7 | accel/tcg/plugin-gen.c | 2 +- | ||
8 | plugins/core.c | 4 ++-- | ||
9 | 3 files changed, 4 insertions(+), 3 deletions(-) | ||
10 | |||
11 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/include/qemu/plugin.h | ||
14 | +++ b/include/qemu/plugin.h | ||
15 | @@ -XXX,XX +XXX,XX @@ union qemu_plugin_cb_sig { | ||
16 | |||
17 | enum plugin_dyn_cb_type { | ||
18 | PLUGIN_CB_REGULAR, | ||
19 | + PLUGIN_CB_MEM_REGULAR, | ||
20 | PLUGIN_CB_INLINE, | ||
21 | }; | ||
22 | |||
23 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/accel/tcg/plugin-gen.c | ||
26 | +++ b/accel/tcg/plugin-gen.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
28 | |||
29 | if (cb->rw & rw) { | ||
30 | switch (cb->type) { | ||
31 | - case PLUGIN_CB_REGULAR: | ||
32 | + case PLUGIN_CB_MEM_REGULAR: | ||
33 | gen_mem_cb(cb, meminfo, addr); | ||
34 | break; | ||
35 | case PLUGIN_CB_INLINE: | ||
36 | diff --git a/plugins/core.c b/plugins/core.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/plugins/core.c | ||
39 | +++ b/plugins/core.c | ||
40 | @@ -XXX,XX +XXX,XX @@ void plugin_register_vcpu_mem_cb(GArray **arr, | ||
41 | |||
42 | struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr); | ||
43 | dyn_cb->userp = udata; | ||
44 | - dyn_cb->type = PLUGIN_CB_REGULAR; | ||
45 | + dyn_cb->type = PLUGIN_CB_MEM_REGULAR; | ||
46 | dyn_cb->rw = rw; | ||
47 | dyn_cb->regular.f.vcpu_mem = cb; | ||
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, | ||
50 | break; | ||
51 | } | ||
52 | switch (cb->type) { | ||
53 | - case PLUGIN_CB_REGULAR: | ||
54 | + case PLUGIN_CB_MEM_REGULAR: | ||
55 | cb->regular.f.vcpu_mem(cpu->cpu_index, make_plugin_meminfo(oi, rw), | ||
56 | vaddr, cb->userp); | ||
57 | break; | ||
58 | -- | ||
59 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The DEBUG_PLUGIN_GEN_OPS ifdef is replaced with "-d op_plugin". | ||
2 | The second pr_ops call can be obtained with "-d op". | ||
1 | 3 | ||
4 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | include/qemu/log.h | 1 + | ||
8 | include/tcg/tcg.h | 1 + | ||
9 | accel/tcg/plugin-gen.c | 67 +++++++----------------------------------- | ||
10 | tcg/tcg.c | 29 +++++++++++++++++- | ||
11 | util/log.c | 4 +++ | ||
12 | 5 files changed, 45 insertions(+), 57 deletions(-) | ||
13 | |||
14 | diff --git a/include/qemu/log.h b/include/qemu/log.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/qemu/log.h | ||
17 | +++ b/include/qemu/log.h | ||
18 | @@ -XXX,XX +XXX,XX @@ bool qemu_log_separate(void); | ||
19 | #define LOG_STRACE (1 << 19) | ||
20 | #define LOG_PER_THREAD (1 << 20) | ||
21 | #define CPU_LOG_TB_VPU (1 << 21) | ||
22 | +#define LOG_TB_OP_PLUGIN (1 << 22) | ||
23 | |||
24 | /* Lock/unlock output. */ | ||
25 | |||
26 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/tcg/tcg.h | ||
29 | +++ b/include/tcg/tcg.h | ||
30 | @@ -XXX,XX +XXX,XX @@ static inline const TCGOpcode *tcg_swap_vecop_list(const TCGOpcode *n) | ||
31 | } | ||
32 | |||
33 | bool tcg_can_emit_vecop_list(const TCGOpcode *, TCGType, unsigned); | ||
34 | +void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs); | ||
35 | |||
36 | #endif /* TCG_H */ | ||
37 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/accel/tcg/plugin-gen.c | ||
40 | +++ b/accel/tcg/plugin-gen.c | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | */ | ||
43 | #include "qemu/osdep.h" | ||
44 | #include "qemu/plugin.h" | ||
45 | +#include "qemu/log.h" | ||
46 | #include "cpu.h" | ||
47 | #include "tcg/tcg.h" | ||
48 | #include "tcg/tcg-temp-internal.h" | ||
49 | @@ -XXX,XX +XXX,XX @@ static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, | ||
50 | tcg_temp_free_i32(cpu_index); | ||
51 | } | ||
52 | |||
53 | -/* #define DEBUG_PLUGIN_GEN_OPS */ | ||
54 | -static void pr_ops(void) | ||
55 | -{ | ||
56 | -#ifdef DEBUG_PLUGIN_GEN_OPS | ||
57 | - TCGOp *op; | ||
58 | - int i = 0; | ||
59 | - | ||
60 | - QTAILQ_FOREACH(op, &tcg_ctx->ops, link) { | ||
61 | - const char *name = ""; | ||
62 | - const char *type = ""; | ||
63 | - | ||
64 | - if (op->opc == INDEX_op_plugin_cb_start) { | ||
65 | - switch (op->args[0]) { | ||
66 | - case PLUGIN_GEN_FROM_TB: | ||
67 | - name = "tb"; | ||
68 | - break; | ||
69 | - case PLUGIN_GEN_FROM_INSN: | ||
70 | - name = "insn"; | ||
71 | - break; | ||
72 | - case PLUGIN_GEN_FROM_MEM: | ||
73 | - name = "mem"; | ||
74 | - break; | ||
75 | - case PLUGIN_GEN_AFTER_INSN: | ||
76 | - name = "after insn"; | ||
77 | - break; | ||
78 | - default: | ||
79 | - break; | ||
80 | - } | ||
81 | - switch (op->args[1]) { | ||
82 | - case PLUGIN_GEN_CB_UDATA: | ||
83 | - type = "udata"; | ||
84 | - break; | ||
85 | - case PLUGIN_GEN_CB_INLINE: | ||
86 | - type = "inline"; | ||
87 | - break; | ||
88 | - case PLUGIN_GEN_CB_MEM: | ||
89 | - type = "mem"; | ||
90 | - break; | ||
91 | - case PLUGIN_GEN_ENABLE_MEM_HELPER: | ||
92 | - type = "enable mem helper"; | ||
93 | - break; | ||
94 | - case PLUGIN_GEN_DISABLE_MEM_HELPER: | ||
95 | - type = "disable mem helper"; | ||
96 | - break; | ||
97 | - default: | ||
98 | - break; | ||
99 | - } | ||
100 | - } | ||
101 | - printf("op[%2i]: %s %s %s\n", i, tcg_op_defs[op->opc].name, name, type); | ||
102 | - i++; | ||
103 | - } | ||
104 | -#endif | ||
105 | -} | ||
106 | - | ||
107 | static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
108 | { | ||
109 | TCGOp *op, *next; | ||
110 | int insn_idx = -1; | ||
111 | |||
112 | - pr_ops(); | ||
113 | + if (unlikely(qemu_loglevel_mask(LOG_TB_OP_PLUGIN) | ||
114 | + && qemu_log_in_addr_range(plugin_tb->vaddr))) { | ||
115 | + FILE *logfile = qemu_log_trylock(); | ||
116 | + if (logfile) { | ||
117 | + fprintf(logfile, "OP before plugin injection:\n"); | ||
118 | + tcg_dump_ops(tcg_ctx, logfile, false); | ||
119 | + fprintf(logfile, "\n"); | ||
120 | + qemu_log_unlock(logfile); | ||
121 | + } | ||
122 | + } | ||
123 | |||
124 | /* | ||
125 | * While injecting code, we cannot afford to reuse any ebb temps | ||
126 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | - pr_ops(); | ||
131 | } | ||
132 | |||
133 | bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, | ||
134 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/tcg/tcg.c | ||
137 | +++ b/tcg/tcg.c | ||
138 | @@ -XXX,XX +XXX,XX @@ static const char bswap_flag_name[][6] = { | ||
139 | [TCG_BSWAP_IZ | TCG_BSWAP_OS] = "iz,os", | ||
140 | }; | ||
141 | |||
142 | +#ifdef CONFIG_PLUGIN | ||
143 | +static const char * const plugin_from_name[] = { | ||
144 | + "from-tb", | ||
145 | + "from-insn", | ||
146 | + "after-insn", | ||
147 | + "after-tb", | ||
148 | +}; | ||
149 | +#endif | ||
150 | + | ||
151 | static inline bool tcg_regset_single(TCGRegSet d) | ||
152 | { | ||
153 | return (d & (d - 1)) == 0; | ||
154 | @@ -XXX,XX +XXX,XX @@ static inline TCGReg tcg_regset_first(TCGRegSet d) | ||
155 | #define ne_fprintf(...) \ | ||
156 | ({ int ret_ = fprintf(__VA_ARGS__); ret_ >= 0 ? ret_ : 0; }) | ||
157 | |||
158 | -static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) | ||
159 | +void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) | ||
160 | { | ||
161 | char buf[128]; | ||
162 | TCGOp *op; | ||
163 | @@ -XXX,XX +XXX,XX @@ static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) | ||
164 | i = k = 1; | ||
165 | } | ||
166 | break; | ||
167 | +#ifdef CONFIG_PLUGIN | ||
168 | + case INDEX_op_plugin_cb: | ||
169 | + { | ||
170 | + TCGArg from = op->args[k++]; | ||
171 | + const char *name = NULL; | ||
172 | + | ||
173 | + if (from < ARRAY_SIZE(plugin_from_name)) { | ||
174 | + name = plugin_from_name[from]; | ||
175 | + } | ||
176 | + if (name) { | ||
177 | + col += ne_fprintf(f, "%s", name); | ||
178 | + } else { | ||
179 | + col += ne_fprintf(f, "$0x%" TCG_PRIlx, from); | ||
180 | + } | ||
181 | + i = 1; | ||
182 | + } | ||
183 | + break; | ||
184 | +#endif | ||
185 | default: | ||
186 | i = 0; | ||
187 | break; | ||
188 | diff --git a/util/log.c b/util/log.c | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/util/log.c | ||
191 | +++ b/util/log.c | ||
192 | @@ -XXX,XX +XXX,XX @@ const QEMULogItem qemu_log_items[] = { | ||
193 | "show micro ops after optimization" }, | ||
194 | { CPU_LOG_TB_OP_IND, "op_ind", | ||
195 | "show micro ops before indirect lowering" }, | ||
196 | +#ifdef CONFIG_PLUGIN | ||
197 | + { LOG_TB_OP_PLUGIN, "op_plugin", | ||
198 | + "show micro ops before plugin injection" }, | ||
199 | +#endif | ||
200 | { CPU_LOG_INT, "int", | ||
201 | "show interrupts/exceptions in short format" }, | ||
202 | { CPU_LOG_EXEC, "exec", | ||
203 | -- | ||
204 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> |
---|---|---|---|
2 | |||
3 | split up the CpusAccel tcg_cpus into three TCG variants: | ||
4 | |||
5 | tcg_cpus_rr (single threaded, round robin cpus) | ||
6 | tcg_cpus_icount (same as rr, but with instruction counting enabled) | ||
7 | tcg_cpus_mttcg (multi-threaded cpus) | ||
8 | |||
9 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-Id: <20201015143217.29337-2-cfontana@suse.de> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 3 | --- |
16 | accel/tcg/tcg-cpus-icount.h | 17 ++ | 4 | accel/tcg/plugin-gen.c | 84 +++++++++++++++++++++--------------------- |
17 | accel/tcg/tcg-cpus-mttcg.h | 21 ++ | 5 | 1 file changed, 41 insertions(+), 43 deletions(-) |
18 | accel/tcg/tcg-cpus-rr.h | 20 ++ | ||
19 | accel/tcg/tcg-cpus.h | 13 +- | ||
20 | accel/tcg/tcg-all.c | 8 +- | ||
21 | accel/tcg/tcg-cpus-icount.c | 147 +++++++++++ | ||
22 | accel/tcg/tcg-cpus-mttcg.c | 117 +++++++++ | ||
23 | accel/tcg/tcg-cpus-rr.c | 270 ++++++++++++++++++++ | ||
24 | accel/tcg/tcg-cpus.c | 484 ++---------------------------------- | ||
25 | softmmu/icount.c | 2 +- | ||
26 | accel/tcg/meson.build | 9 +- | ||
27 | 11 files changed, 646 insertions(+), 462 deletions(-) | ||
28 | create mode 100644 accel/tcg/tcg-cpus-icount.h | ||
29 | create mode 100644 accel/tcg/tcg-cpus-mttcg.h | ||
30 | create mode 100644 accel/tcg/tcg-cpus-rr.h | ||
31 | create mode 100644 accel/tcg/tcg-cpus-icount.c | ||
32 | create mode 100644 accel/tcg/tcg-cpus-mttcg.c | ||
33 | create mode 100644 accel/tcg/tcg-cpus-rr.c | ||
34 | 6 | ||
35 | diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h | 7 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c |
36 | new file mode 100644 | 8 | index XXXXXXX..XXXXXXX 100644 |
37 | index XXXXXXX..XXXXXXX | 9 | --- a/accel/tcg/plugin-gen.c |
38 | --- /dev/null | 10 | +++ b/accel/tcg/plugin-gen.c |
39 | +++ b/accel/tcg/tcg-cpus-icount.h | 11 | @@ -XXX,XX +XXX,XX @@ static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, |
40 | @@ -XXX,XX +XXX,XX @@ | 12 | tcg_temp_free_i32(cpu_index); |
41 | +/* | 13 | } |
42 | + * QEMU TCG Single Threaded vCPUs implementation using instruction counting | 14 | |
43 | + * | 15 | +static void inject_cb(struct qemu_plugin_dyn_cb *cb) |
44 | + * Copyright 2020 SUSE LLC | ||
45 | + * | ||
46 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
47 | + * See the COPYING file in the top-level directory. | ||
48 | + */ | ||
49 | + | 16 | + |
50 | +#ifndef TCG_CPUS_ICOUNT_H | ||
51 | +#define TCG_CPUS_ICOUNT_H | ||
52 | + | ||
53 | +void handle_icount_deadline(void); | ||
54 | +void prepare_icount_for_run(CPUState *cpu); | ||
55 | +void process_icount_data(CPUState *cpu); | ||
56 | + | ||
57 | +#endif /* TCG_CPUS_ICOUNT_H */ | ||
58 | diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h | ||
59 | new file mode 100644 | ||
60 | index XXXXXXX..XXXXXXX | ||
61 | --- /dev/null | ||
62 | +++ b/accel/tcg/tcg-cpus-mttcg.h | ||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | +/* | ||
65 | + * QEMU TCG Multi Threaded vCPUs implementation | ||
66 | + * | ||
67 | + * Copyright 2020 SUSE LLC | ||
68 | + * | ||
69 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
70 | + * See the COPYING file in the top-level directory. | ||
71 | + */ | ||
72 | + | ||
73 | +#ifndef TCG_CPUS_MTTCG_H | ||
74 | +#define TCG_CPUS_MTTCG_H | ||
75 | + | ||
76 | +/* | ||
77 | + * In the multi-threaded case each vCPU has its own thread. The TLS | ||
78 | + * variable current_cpu can be used deep in the code to find the | ||
79 | + * current CPUState for a given thread. | ||
80 | + */ | ||
81 | + | ||
82 | +void *tcg_cpu_thread_fn(void *arg); | ||
83 | + | ||
84 | +#endif /* TCG_CPUS_MTTCG_H */ | ||
85 | diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h | ||
86 | new file mode 100644 | ||
87 | index XXXXXXX..XXXXXXX | ||
88 | --- /dev/null | ||
89 | +++ b/accel/tcg/tcg-cpus-rr.h | ||
90 | @@ -XXX,XX +XXX,XX @@ | ||
91 | +/* | ||
92 | + * QEMU TCG Single Threaded vCPUs implementation | ||
93 | + * | ||
94 | + * Copyright 2020 SUSE LLC | ||
95 | + * | ||
96 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
97 | + * See the COPYING file in the top-level directory. | ||
98 | + */ | ||
99 | + | ||
100 | +#ifndef TCG_CPUS_RR_H | ||
101 | +#define TCG_CPUS_RR_H | ||
102 | + | ||
103 | +#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) | ||
104 | + | ||
105 | +/* Kick all RR vCPUs. */ | ||
106 | +void qemu_cpu_kick_rr_cpus(CPUState *unused); | ||
107 | + | ||
108 | +void *tcg_rr_cpu_thread_fn(void *arg); | ||
109 | + | ||
110 | +#endif /* TCG_CPUS_RR_H */ | ||
111 | diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/accel/tcg/tcg-cpus.h | ||
114 | +++ b/accel/tcg/tcg-cpus.h | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | /* | ||
117 | - * Accelerator CPUS Interface | ||
118 | + * QEMU TCG vCPU common functionality | ||
119 | + * | ||
120 | + * Functionality common to all TCG vcpu variants: mttcg, rr and icount. | ||
121 | * | ||
122 | * Copyright 2020 SUSE LLC | ||
123 | * | ||
124 | @@ -XXX,XX +XXX,XX @@ | ||
125 | |||
126 | #include "sysemu/cpus.h" | ||
127 | |||
128 | -extern const CpusAccel tcg_cpus; | ||
129 | +extern const CpusAccel tcg_cpus_mttcg; | ||
130 | +extern const CpusAccel tcg_cpus_icount; | ||
131 | +extern const CpusAccel tcg_cpus_rr; | ||
132 | + | ||
133 | +void tcg_start_vcpu_thread(CPUState *cpu); | ||
134 | +void qemu_tcg_destroy_vcpu(CPUState *cpu); | ||
135 | +int tcg_cpu_exec(CPUState *cpu); | ||
136 | +void tcg_handle_interrupt(CPUState *cpu, int mask); | ||
137 | |||
138 | #endif /* TCG_CPUS_H */ | ||
139 | diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c | ||
140 | index XXXXXXX..XXXXXXX 100644 | ||
141 | --- a/accel/tcg/tcg-all.c | ||
142 | +++ b/accel/tcg/tcg-all.c | ||
143 | @@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms) | ||
144 | |||
145 | tcg_exec_init(s->tb_size * 1024 * 1024); | ||
146 | mttcg_enabled = s->mttcg_enabled; | ||
147 | - cpus_register_accel(&tcg_cpus); | ||
148 | |||
149 | + if (mttcg_enabled) { | ||
150 | + cpus_register_accel(&tcg_cpus_mttcg); | ||
151 | + } else if (icount_enabled()) { | ||
152 | + cpus_register_accel(&tcg_cpus_icount); | ||
153 | + } else { | ||
154 | + cpus_register_accel(&tcg_cpus_rr); | ||
155 | + } | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c | ||
160 | new file mode 100644 | ||
161 | index XXXXXXX..XXXXXXX | ||
162 | --- /dev/null | ||
163 | +++ b/accel/tcg/tcg-cpus-icount.c | ||
164 | @@ -XXX,XX +XXX,XX @@ | ||
165 | +/* | ||
166 | + * QEMU TCG Single Threaded vCPUs implementation using instruction counting | ||
167 | + * | ||
168 | + * Copyright (c) 2003-2008 Fabrice Bellard | ||
169 | + * Copyright (c) 2014 Red Hat Inc. | ||
170 | + * | ||
171 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
172 | + * of this software and associated documentation files (the "Software"), to deal | ||
173 | + * in the Software without restriction, including without limitation the rights | ||
174 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
175 | + * copies of the Software, and to permit persons to whom the Software is | ||
176 | + * furnished to do so, subject to the following conditions: | ||
177 | + * | ||
178 | + * The above copyright notice and this permission notice shall be included in | ||
179 | + * all copies or substantial portions of the Software. | ||
180 | + * | ||
181 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
182 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
183 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
184 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
185 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
186 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
187 | + * THE SOFTWARE. | ||
188 | + */ | ||
189 | + | ||
190 | +#include "qemu/osdep.h" | ||
191 | +#include "qemu-common.h" | ||
192 | +#include "sysemu/tcg.h" | ||
193 | +#include "sysemu/replay.h" | ||
194 | +#include "qemu/main-loop.h" | ||
195 | +#include "qemu/guest-random.h" | ||
196 | +#include "exec/exec-all.h" | ||
197 | +#include "hw/boards.h" | ||
198 | + | ||
199 | +#include "tcg-cpus.h" | ||
200 | +#include "tcg-cpus-icount.h" | ||
201 | +#include "tcg-cpus-rr.h" | ||
202 | + | ||
203 | +static int64_t tcg_get_icount_limit(void) | ||
204 | +{ | 17 | +{ |
205 | + int64_t deadline; | 18 | + switch (cb->type) { |
206 | + | 19 | + case PLUGIN_CB_REGULAR: |
207 | + if (replay_mode != REPLAY_MODE_PLAY) { | 20 | + gen_udata_cb(cb); |
208 | + /* | 21 | + break; |
209 | + * Include all the timers, because they may need an attention. | 22 | + case PLUGIN_CB_INLINE: |
210 | + * Too long CPU execution may create unnecessary delay in UI. | 23 | + gen_inline_cb(cb); |
211 | + */ | 24 | + break; |
212 | + deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | 25 | + default: |
213 | + QEMU_TIMER_ATTR_ALL); | 26 | + g_assert_not_reached(); |
214 | + /* Check realtime timers, because they help with input processing */ | ||
215 | + deadline = qemu_soonest_timeout(deadline, | ||
216 | + qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME, | ||
217 | + QEMU_TIMER_ATTR_ALL)); | ||
218 | + | ||
219 | + /* | ||
220 | + * Maintain prior (possibly buggy) behaviour where if no deadline | ||
221 | + * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than | ||
222 | + * INT32_MAX nanoseconds ahead, we still use INT32_MAX | ||
223 | + * nanoseconds. | ||
224 | + */ | ||
225 | + if ((deadline < 0) || (deadline > INT32_MAX)) { | ||
226 | + deadline = INT32_MAX; | ||
227 | + } | ||
228 | + | ||
229 | + return icount_round(deadline); | ||
230 | + } else { | ||
231 | + return replay_get_instructions(); | ||
232 | + } | 27 | + } |
233 | +} | 28 | +} |
234 | + | 29 | + |
235 | +static void notify_aio_contexts(void) | 30 | +static void inject_mem_cb(struct qemu_plugin_dyn_cb *cb, |
31 | + enum qemu_plugin_mem_rw rw, | ||
32 | + qemu_plugin_meminfo_t meminfo, TCGv_i64 addr) | ||
236 | +{ | 33 | +{ |
237 | + /* Wake up other AioContexts. */ | 34 | + if (cb->rw & rw) { |
238 | + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); | 35 | + switch (cb->type) { |
239 | + qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); | 36 | + case PLUGIN_CB_MEM_REGULAR: |
240 | +} | 37 | + gen_mem_cb(cb, meminfo, addr); |
241 | + | 38 | + break; |
242 | +void handle_icount_deadline(void) | 39 | + default: |
243 | +{ | 40 | + inject_cb(cb); |
244 | + assert(qemu_in_vcpu_thread()); | ||
245 | + int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | ||
246 | + QEMU_TIMER_ATTR_ALL); | ||
247 | + | ||
248 | + if (deadline == 0) { | ||
249 | + notify_aio_contexts(); | ||
250 | + } | ||
251 | +} | ||
252 | + | ||
253 | +void prepare_icount_for_run(CPUState *cpu) | ||
254 | +{ | ||
255 | + int insns_left; | ||
256 | + | ||
257 | + /* | ||
258 | + * These should always be cleared by process_icount_data after | ||
259 | + * each vCPU execution. However u16.high can be raised | ||
260 | + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | ||
261 | + */ | ||
262 | + g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
263 | + g_assert(cpu->icount_extra == 0); | ||
264 | + | ||
265 | + cpu->icount_budget = tcg_get_icount_limit(); | ||
266 | + insns_left = MIN(0xffff, cpu->icount_budget); | ||
267 | + cpu_neg(cpu)->icount_decr.u16.low = insns_left; | ||
268 | + cpu->icount_extra = cpu->icount_budget - insns_left; | ||
269 | + | ||
270 | + replay_mutex_lock(); | ||
271 | + | ||
272 | + if (cpu->icount_budget == 0 && replay_has_checkpoint()) { | ||
273 | + notify_aio_contexts(); | ||
274 | + } | ||
275 | +} | ||
276 | + | ||
277 | +void process_icount_data(CPUState *cpu) | ||
278 | +{ | ||
279 | + /* Account for executed instructions */ | ||
280 | + icount_update(cpu); | ||
281 | + | ||
282 | + /* Reset the counters */ | ||
283 | + cpu_neg(cpu)->icount_decr.u16.low = 0; | ||
284 | + cpu->icount_extra = 0; | ||
285 | + cpu->icount_budget = 0; | ||
286 | + | ||
287 | + replay_account_executed_instructions(); | ||
288 | + | ||
289 | + replay_mutex_unlock(); | ||
290 | +} | ||
291 | + | ||
292 | +static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
293 | +{ | ||
294 | + int old_mask = cpu->interrupt_request; | ||
295 | + | ||
296 | + tcg_handle_interrupt(cpu, mask); | ||
297 | + if (qemu_cpu_is_self(cpu) && | ||
298 | + !cpu->can_do_io | ||
299 | + && (mask & ~old_mask) != 0) { | ||
300 | + cpu_abort(cpu, "Raised interrupt while not in I/O function"); | ||
301 | + } | ||
302 | +} | ||
303 | + | ||
304 | +const CpusAccel tcg_cpus_icount = { | ||
305 | + .create_vcpu_thread = tcg_start_vcpu_thread, | ||
306 | + .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
307 | + | ||
308 | + .handle_interrupt = icount_handle_interrupt, | ||
309 | + .get_virtual_clock = icount_get, | ||
310 | + .get_elapsed_ticks = icount_get, | ||
311 | +}; | ||
312 | diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c | ||
313 | new file mode 100644 | ||
314 | index XXXXXXX..XXXXXXX | ||
315 | --- /dev/null | ||
316 | +++ b/accel/tcg/tcg-cpus-mttcg.c | ||
317 | @@ -XXX,XX +XXX,XX @@ | ||
318 | +/* | ||
319 | + * QEMU TCG Multi Threaded vCPUs implementation | ||
320 | + * | ||
321 | + * Copyright (c) 2003-2008 Fabrice Bellard | ||
322 | + * Copyright (c) 2014 Red Hat Inc. | ||
323 | + * | ||
324 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
325 | + * of this software and associated documentation files (the "Software"), to deal | ||
326 | + * in the Software without restriction, including without limitation the rights | ||
327 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
328 | + * copies of the Software, and to permit persons to whom the Software is | ||
329 | + * furnished to do so, subject to the following conditions: | ||
330 | + * | ||
331 | + * The above copyright notice and this permission notice shall be included in | ||
332 | + * all copies or substantial portions of the Software. | ||
333 | + * | ||
334 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
335 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
336 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
337 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
338 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
339 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
340 | + * THE SOFTWARE. | ||
341 | + */ | ||
342 | + | ||
343 | +#include "qemu/osdep.h" | ||
344 | +#include "qemu-common.h" | ||
345 | +#include "sysemu/tcg.h" | ||
346 | +#include "sysemu/replay.h" | ||
347 | +#include "qemu/main-loop.h" | ||
348 | +#include "qemu/guest-random.h" | ||
349 | +#include "exec/exec-all.h" | ||
350 | +#include "hw/boards.h" | ||
351 | + | ||
352 | +#include "tcg-cpus.h" | ||
353 | +#include "tcg-cpus-mttcg.h" | ||
354 | + | ||
355 | +/* | ||
356 | + * In the multi-threaded case each vCPU has its own thread. The TLS | ||
357 | + * variable current_cpu can be used deep in the code to find the | ||
358 | + * current CPUState for a given thread. | ||
359 | + */ | ||
360 | + | ||
361 | +void *tcg_cpu_thread_fn(void *arg) | ||
362 | +{ | ||
363 | + CPUState *cpu = arg; | ||
364 | + | ||
365 | + assert(tcg_enabled()); | ||
366 | + g_assert(!icount_enabled()); | ||
367 | + | ||
368 | + rcu_register_thread(); | ||
369 | + tcg_register_thread(); | ||
370 | + | ||
371 | + qemu_mutex_lock_iothread(); | ||
372 | + qemu_thread_get_self(cpu->thread); | ||
373 | + | ||
374 | + cpu->thread_id = qemu_get_thread_id(); | ||
375 | + cpu->can_do_io = 1; | ||
376 | + current_cpu = cpu; | ||
377 | + cpu_thread_signal_created(cpu); | ||
378 | + qemu_guest_random_seed_thread_part2(cpu->random_seed); | ||
379 | + | ||
380 | + /* process any pending work */ | ||
381 | + cpu->exit_request = 1; | ||
382 | + | ||
383 | + do { | ||
384 | + if (cpu_can_run(cpu)) { | ||
385 | + int r; | ||
386 | + qemu_mutex_unlock_iothread(); | ||
387 | + r = tcg_cpu_exec(cpu); | ||
388 | + qemu_mutex_lock_iothread(); | ||
389 | + switch (r) { | ||
390 | + case EXCP_DEBUG: | ||
391 | + cpu_handle_guest_debug(cpu); | ||
392 | + break; | ||
393 | + case EXCP_HALTED: | ||
394 | + /* | ||
395 | + * during start-up the vCPU is reset and the thread is | ||
396 | + * kicked several times. If we don't ensure we go back | ||
397 | + * to sleep in the halted state we won't cleanly | ||
398 | + * start-up when the vCPU is enabled. | ||
399 | + * | ||
400 | + * cpu->halted should ensure we sleep in wait_io_event | ||
401 | + */ | ||
402 | + g_assert(cpu->halted); | ||
403 | + break; | ||
404 | + case EXCP_ATOMIC: | ||
405 | + qemu_mutex_unlock_iothread(); | ||
406 | + cpu_exec_step_atomic(cpu); | ||
407 | + qemu_mutex_lock_iothread(); | ||
408 | + default: | ||
409 | + /* Ignore everything else? */ | ||
410 | + break; | ||
411 | + } | ||
412 | + } | ||
413 | + | ||
414 | + qatomic_mb_set(&cpu->exit_request, 0); | ||
415 | + qemu_wait_io_event(cpu); | ||
416 | + } while (!cpu->unplug || cpu_can_run(cpu)); | ||
417 | + | ||
418 | + qemu_tcg_destroy_vcpu(cpu); | ||
419 | + qemu_mutex_unlock_iothread(); | ||
420 | + rcu_unregister_thread(); | ||
421 | + return NULL; | ||
422 | +} | ||
423 | + | ||
424 | +static void mttcg_kick_vcpu_thread(CPUState *cpu) | ||
425 | +{ | ||
426 | + cpu_exit(cpu); | ||
427 | +} | ||
428 | + | ||
429 | +const CpusAccel tcg_cpus_mttcg = { | ||
430 | + .create_vcpu_thread = tcg_start_vcpu_thread, | ||
431 | + .kick_vcpu_thread = mttcg_kick_vcpu_thread, | ||
432 | + | ||
433 | + .handle_interrupt = tcg_handle_interrupt, | ||
434 | +}; | ||
435 | diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c | ||
436 | new file mode 100644 | ||
437 | index XXXXXXX..XXXXXXX | ||
438 | --- /dev/null | ||
439 | +++ b/accel/tcg/tcg-cpus-rr.c | ||
440 | @@ -XXX,XX +XXX,XX @@ | ||
441 | +/* | ||
442 | + * QEMU TCG Single Threaded vCPUs implementation | ||
443 | + * | ||
444 | + * Copyright (c) 2003-2008 Fabrice Bellard | ||
445 | + * Copyright (c) 2014 Red Hat Inc. | ||
446 | + * | ||
447 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
448 | + * of this software and associated documentation files (the "Software"), to deal | ||
449 | + * in the Software without restriction, including without limitation the rights | ||
450 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
451 | + * copies of the Software, and to permit persons to whom the Software is | ||
452 | + * furnished to do so, subject to the following conditions: | ||
453 | + * | ||
454 | + * The above copyright notice and this permission notice shall be included in | ||
455 | + * all copies or substantial portions of the Software. | ||
456 | + * | ||
457 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
458 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
459 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
460 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
461 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
462 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
463 | + * THE SOFTWARE. | ||
464 | + */ | ||
465 | + | ||
466 | +#include "qemu/osdep.h" | ||
467 | +#include "qemu-common.h" | ||
468 | +#include "sysemu/tcg.h" | ||
469 | +#include "sysemu/replay.h" | ||
470 | +#include "qemu/main-loop.h" | ||
471 | +#include "qemu/guest-random.h" | ||
472 | +#include "exec/exec-all.h" | ||
473 | +#include "hw/boards.h" | ||
474 | + | ||
475 | +#include "tcg-cpus.h" | ||
476 | +#include "tcg-cpus-rr.h" | ||
477 | +#include "tcg-cpus-icount.h" | ||
478 | + | ||
479 | +/* Kick all RR vCPUs */ | ||
480 | +void qemu_cpu_kick_rr_cpus(CPUState *unused) | ||
481 | +{ | ||
482 | + CPUState *cpu; | ||
483 | + | ||
484 | + CPU_FOREACH(cpu) { | ||
485 | + cpu_exit(cpu); | ||
486 | + }; | ||
487 | +} | ||
488 | + | ||
489 | +/* | ||
490 | + * TCG vCPU kick timer | ||
491 | + * | ||
492 | + * The kick timer is responsible for moving single threaded vCPU | ||
493 | + * emulation on to the next vCPU. If more than one vCPU is running a | ||
494 | + * timer event with force a cpu->exit so the next vCPU can get | ||
495 | + * scheduled. | ||
496 | + * | ||
497 | + * The timer is removed if all vCPUs are idle and restarted again once | ||
498 | + * idleness is complete. | ||
499 | + */ | ||
500 | + | ||
501 | +static QEMUTimer *tcg_kick_vcpu_timer; | ||
502 | +static CPUState *tcg_current_rr_cpu; | ||
503 | + | ||
504 | +#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) | ||
505 | + | ||
506 | +static inline int64_t qemu_tcg_next_kick(void) | ||
507 | +{ | ||
508 | + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD; | ||
509 | +} | ||
510 | + | ||
511 | +/* Kick the currently round-robin scheduled vCPU to next */ | ||
512 | +static void qemu_cpu_kick_rr_next_cpu(void) | ||
513 | +{ | ||
514 | + CPUState *cpu; | ||
515 | + do { | ||
516 | + cpu = qatomic_mb_read(&tcg_current_rr_cpu); | ||
517 | + if (cpu) { | ||
518 | + cpu_exit(cpu); | ||
519 | + } | ||
520 | + } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu)); | ||
521 | +} | ||
522 | + | ||
523 | +static void kick_tcg_thread(void *opaque) | ||
524 | +{ | ||
525 | + timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
526 | + qemu_cpu_kick_rr_next_cpu(); | ||
527 | +} | ||
528 | + | ||
529 | +static void start_tcg_kick_timer(void) | ||
530 | +{ | ||
531 | + if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { | ||
532 | + tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
533 | + kick_tcg_thread, NULL); | ||
534 | + } | ||
535 | + if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) { | ||
536 | + timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
537 | + } | ||
538 | +} | ||
539 | + | ||
540 | +static void stop_tcg_kick_timer(void) | ||
541 | +{ | ||
542 | + if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) { | ||
543 | + timer_del(tcg_kick_vcpu_timer); | ||
544 | + } | ||
545 | +} | ||
546 | + | ||
547 | +static void qemu_tcg_rr_wait_io_event(void) | ||
548 | +{ | ||
549 | + CPUState *cpu; | ||
550 | + | ||
551 | + while (all_cpu_threads_idle()) { | ||
552 | + stop_tcg_kick_timer(); | ||
553 | + qemu_cond_wait_iothread(first_cpu->halt_cond); | ||
554 | + } | ||
555 | + | ||
556 | + start_tcg_kick_timer(); | ||
557 | + | ||
558 | + CPU_FOREACH(cpu) { | ||
559 | + qemu_wait_io_event_common(cpu); | ||
560 | + } | ||
561 | +} | ||
562 | + | ||
563 | +/* | ||
564 | + * Destroy any remaining vCPUs which have been unplugged and have | ||
565 | + * finished running | ||
566 | + */ | ||
567 | +static void deal_with_unplugged_cpus(void) | ||
568 | +{ | ||
569 | + CPUState *cpu; | ||
570 | + | ||
571 | + CPU_FOREACH(cpu) { | ||
572 | + if (cpu->unplug && !cpu_can_run(cpu)) { | ||
573 | + qemu_tcg_destroy_vcpu(cpu); | ||
574 | + break; | 41 | + break; |
575 | + } | 42 | + } |
576 | + } | 43 | + } |
577 | +} | 44 | +} |
578 | + | 45 | + |
579 | +/* | 46 | static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) |
580 | + * In the single-threaded case each vCPU is simulated in turn. If | 47 | { |
581 | + * there is more than a single vCPU we create a simple timer to kick | 48 | TCGOp *op, *next; |
582 | + * the vCPU and ensure we don't get stuck in a tight loop in one vCPU. | 49 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) |
583 | + * This is done explicitly rather than relying on side-effects | 50 | |
584 | + * elsewhere. | 51 | cbs = plugin_tb->cbs; |
585 | + */ | 52 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { |
586 | + | 53 | - struct qemu_plugin_dyn_cb *cb = |
587 | +void *tcg_rr_cpu_thread_fn(void *arg) | 54 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); |
588 | +{ | ||
589 | + CPUState *cpu = arg; | ||
590 | + | ||
591 | + assert(tcg_enabled()); | ||
592 | + rcu_register_thread(); | ||
593 | + tcg_register_thread(); | ||
594 | + | ||
595 | + qemu_mutex_lock_iothread(); | ||
596 | + qemu_thread_get_self(cpu->thread); | ||
597 | + | ||
598 | + cpu->thread_id = qemu_get_thread_id(); | ||
599 | + cpu->can_do_io = 1; | ||
600 | + cpu_thread_signal_created(cpu); | ||
601 | + qemu_guest_random_seed_thread_part2(cpu->random_seed); | ||
602 | + | ||
603 | + /* wait for initial kick-off after machine start */ | ||
604 | + while (first_cpu->stopped) { | ||
605 | + qemu_cond_wait_iothread(first_cpu->halt_cond); | ||
606 | + | ||
607 | + /* process any pending work */ | ||
608 | + CPU_FOREACH(cpu) { | ||
609 | + current_cpu = cpu; | ||
610 | + qemu_wait_io_event_common(cpu); | ||
611 | + } | ||
612 | + } | ||
613 | + | ||
614 | + start_tcg_kick_timer(); | ||
615 | + | ||
616 | + cpu = first_cpu; | ||
617 | + | ||
618 | + /* process any pending work */ | ||
619 | + cpu->exit_request = 1; | ||
620 | + | ||
621 | + while (1) { | ||
622 | + qemu_mutex_unlock_iothread(); | ||
623 | + replay_mutex_lock(); | ||
624 | + qemu_mutex_lock_iothread(); | ||
625 | + | ||
626 | + if (icount_enabled()) { | ||
627 | + /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ | ||
628 | + icount_account_warp_timer(); | ||
629 | + /* | ||
630 | + * Run the timers here. This is much more efficient than | ||
631 | + * waking up the I/O thread and waiting for completion. | ||
632 | + */ | ||
633 | + handle_icount_deadline(); | ||
634 | + } | ||
635 | + | ||
636 | + replay_mutex_unlock(); | ||
637 | + | ||
638 | + if (!cpu) { | ||
639 | + cpu = first_cpu; | ||
640 | + } | ||
641 | + | ||
642 | + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { | ||
643 | + | ||
644 | + qatomic_mb_set(&tcg_current_rr_cpu, cpu); | ||
645 | + current_cpu = cpu; | ||
646 | + | ||
647 | + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, | ||
648 | + (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); | ||
649 | + | ||
650 | + if (cpu_can_run(cpu)) { | ||
651 | + int r; | ||
652 | + | ||
653 | + qemu_mutex_unlock_iothread(); | ||
654 | + if (icount_enabled()) { | ||
655 | + prepare_icount_for_run(cpu); | ||
656 | + } | ||
657 | + r = tcg_cpu_exec(cpu); | ||
658 | + if (icount_enabled()) { | ||
659 | + process_icount_data(cpu); | ||
660 | + } | ||
661 | + qemu_mutex_lock_iothread(); | ||
662 | + | ||
663 | + if (r == EXCP_DEBUG) { | ||
664 | + cpu_handle_guest_debug(cpu); | ||
665 | + break; | ||
666 | + } else if (r == EXCP_ATOMIC) { | ||
667 | + qemu_mutex_unlock_iothread(); | ||
668 | + cpu_exec_step_atomic(cpu); | ||
669 | + qemu_mutex_lock_iothread(); | ||
670 | + break; | ||
671 | + } | ||
672 | + } else if (cpu->stop) { | ||
673 | + if (cpu->unplug) { | ||
674 | + cpu = CPU_NEXT(cpu); | ||
675 | + } | ||
676 | + break; | ||
677 | + } | ||
678 | + | ||
679 | + cpu = CPU_NEXT(cpu); | ||
680 | + } /* while (cpu && !cpu->exit_request).. */ | ||
681 | + | ||
682 | + /* Does not need qatomic_mb_set because a spurious wakeup is okay. */ | ||
683 | + qatomic_set(&tcg_current_rr_cpu, NULL); | ||
684 | + | ||
685 | + if (cpu && cpu->exit_request) { | ||
686 | + qatomic_mb_set(&cpu->exit_request, 0); | ||
687 | + } | ||
688 | + | ||
689 | + if (icount_enabled() && all_cpu_threads_idle()) { | ||
690 | + /* | ||
691 | + * When all cpus are sleeping (e.g in WFI), to avoid a deadlock | ||
692 | + * in the main_loop, wake it up in order to start the warp timer. | ||
693 | + */ | ||
694 | + qemu_notify_event(); | ||
695 | + } | ||
696 | + | ||
697 | + qemu_tcg_rr_wait_io_event(); | ||
698 | + deal_with_unplugged_cpus(); | ||
699 | + } | ||
700 | + | ||
701 | + rcu_unregister_thread(); | ||
702 | + return NULL; | ||
703 | +} | ||
704 | + | ||
705 | +const CpusAccel tcg_cpus_rr = { | ||
706 | + .create_vcpu_thread = tcg_start_vcpu_thread, | ||
707 | + .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
708 | + | ||
709 | + .handle_interrupt = tcg_handle_interrupt, | ||
710 | +}; | ||
711 | diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c | ||
712 | index XXXXXXX..XXXXXXX 100644 | ||
713 | --- a/accel/tcg/tcg-cpus.c | ||
714 | +++ b/accel/tcg/tcg-cpus.c | ||
715 | @@ -XXX,XX +XXX,XX @@ | ||
716 | /* | ||
717 | - * QEMU System Emulator | ||
718 | + * QEMU TCG vCPU common functionality | ||
719 | + * | ||
720 | + * Functionality common to all TCG vCPU variants: mttcg, rr and icount. | ||
721 | * | ||
722 | * Copyright (c) 2003-2008 Fabrice Bellard | ||
723 | * Copyright (c) 2014 Red Hat Inc. | ||
724 | @@ -XXX,XX +XXX,XX @@ | ||
725 | #include "hw/boards.h" | ||
726 | |||
727 | #include "tcg-cpus.h" | ||
728 | +#include "tcg-cpus-mttcg.h" | ||
729 | +#include "tcg-cpus-rr.h" | ||
730 | |||
731 | -/* Kick all RR vCPUs */ | ||
732 | -static void qemu_cpu_kick_rr_cpus(void) | ||
733 | -{ | ||
734 | - CPUState *cpu; | ||
735 | +/* common functionality among all TCG variants */ | ||
736 | |||
737 | - CPU_FOREACH(cpu) { | ||
738 | - cpu_exit(cpu); | ||
739 | - }; | ||
740 | -} | ||
741 | - | 55 | - |
742 | -static void tcg_kick_vcpu_thread(CPUState *cpu) | 56 | - switch (cb->type) { |
743 | -{ | 57 | - case PLUGIN_CB_REGULAR: |
744 | - if (qemu_tcg_mttcg_enabled()) { | 58 | - gen_udata_cb(cb); |
745 | - cpu_exit(cpu); | 59 | - break; |
746 | - } else { | 60 | - case PLUGIN_CB_INLINE: |
747 | - qemu_cpu_kick_rr_cpus(); | 61 | - gen_inline_cb(cb); |
748 | - } | 62 | - break; |
749 | -} | 63 | - default: |
64 | - g_assert_not_reached(); | ||
65 | - } | ||
66 | + inject_cb( | ||
67 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i)); | ||
68 | } | ||
69 | break; | ||
70 | |||
71 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
72 | |||
73 | cbs = insn->insn_cbs; | ||
74 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
75 | - struct qemu_plugin_dyn_cb *cb = | ||
76 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
750 | - | 77 | - |
751 | -/* | 78 | - switch (cb->type) { |
752 | - * TCG vCPU kick timer | 79 | - case PLUGIN_CB_REGULAR: |
753 | - * | 80 | - gen_udata_cb(cb); |
754 | - * The kick timer is responsible for moving single threaded vCPU | 81 | - break; |
755 | - * emulation on to the next vCPU. If more than one vCPU is running a | 82 | - case PLUGIN_CB_INLINE: |
756 | - * timer event with force a cpu->exit so the next vCPU can get | 83 | - gen_inline_cb(cb); |
757 | - * scheduled. | 84 | - break; |
758 | - * | 85 | - default: |
759 | - * The timer is removed if all vCPUs are idle and restarted again once | 86 | - g_assert_not_reached(); |
760 | - * idleness is complete. | 87 | - } |
761 | - */ | 88 | + inject_cb( |
89 | + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i)); | ||
90 | } | ||
91 | break; | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) | ||
94 | { | ||
95 | TCGv_i64 addr = temp_tcgv_i64(arg_temp(op->args[0])); | ||
96 | qemu_plugin_meminfo_t meminfo = op->args[1]; | ||
97 | + enum qemu_plugin_mem_rw rw = | ||
98 | + (qemu_plugin_mem_is_store(meminfo) | ||
99 | + ? QEMU_PLUGIN_MEM_W : QEMU_PLUGIN_MEM_R); | ||
100 | struct qemu_plugin_insn *insn; | ||
101 | const GArray *cbs; | ||
102 | - int i, n, rw; | ||
103 | + int i, n; | ||
104 | |||
105 | assert(insn_idx >= 0); | ||
106 | insn = g_ptr_array_index(plugin_tb->insns, insn_idx); | ||
107 | - rw = qemu_plugin_mem_is_store(meminfo) ? 2 : 1; | ||
108 | |||
109 | tcg_ctx->emit_before_op = op; | ||
110 | |||
111 | cbs = insn->mem_cbs; | ||
112 | for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) { | ||
113 | - struct qemu_plugin_dyn_cb *cb = | ||
114 | - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); | ||
762 | - | 115 | - |
763 | -static QEMUTimer *tcg_kick_vcpu_timer; | 116 | - if (cb->rw & rw) { |
764 | -static CPUState *tcg_current_rr_cpu; | 117 | - switch (cb->type) { |
765 | - | 118 | - case PLUGIN_CB_MEM_REGULAR: |
766 | -#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) | 119 | - gen_mem_cb(cb, meminfo, addr); |
767 | - | 120 | - break; |
768 | -static inline int64_t qemu_tcg_next_kick(void) | 121 | - case PLUGIN_CB_INLINE: |
769 | -{ | 122 | - gen_inline_cb(cb); |
770 | - return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD; | 123 | - break; |
771 | -} | 124 | - default: |
772 | - | 125 | - g_assert_not_reached(); |
773 | -/* Kick the currently round-robin scheduled vCPU to next */ | 126 | - } |
774 | -static void qemu_cpu_kick_rr_next_cpu(void) | ||
775 | -{ | ||
776 | - CPUState *cpu; | ||
777 | - do { | ||
778 | - cpu = qatomic_mb_read(&tcg_current_rr_cpu); | ||
779 | - if (cpu) { | ||
780 | - cpu_exit(cpu); | ||
781 | - } | ||
782 | - } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu)); | ||
783 | -} | ||
784 | - | ||
785 | -static void kick_tcg_thread(void *opaque) | ||
786 | -{ | ||
787 | - timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
788 | - qemu_cpu_kick_rr_next_cpu(); | ||
789 | -} | ||
790 | - | ||
791 | -static void start_tcg_kick_timer(void) | ||
792 | -{ | ||
793 | - assert(!mttcg_enabled); | ||
794 | - if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { | ||
795 | - tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
796 | - kick_tcg_thread, NULL); | ||
797 | - } | ||
798 | - if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) { | ||
799 | - timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); | ||
800 | - } | ||
801 | -} | ||
802 | - | ||
803 | -static void stop_tcg_kick_timer(void) | ||
804 | -{ | ||
805 | - assert(!mttcg_enabled); | ||
806 | - if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) { | ||
807 | - timer_del(tcg_kick_vcpu_timer); | ||
808 | - } | ||
809 | -} | ||
810 | - | ||
811 | -static void qemu_tcg_destroy_vcpu(CPUState *cpu) | ||
812 | -{ | ||
813 | -} | ||
814 | - | ||
815 | -static void qemu_tcg_rr_wait_io_event(void) | ||
816 | -{ | ||
817 | - CPUState *cpu; | ||
818 | - | ||
819 | - while (all_cpu_threads_idle()) { | ||
820 | - stop_tcg_kick_timer(); | ||
821 | - qemu_cond_wait_iothread(first_cpu->halt_cond); | ||
822 | - } | ||
823 | - | ||
824 | - start_tcg_kick_timer(); | ||
825 | - | ||
826 | - CPU_FOREACH(cpu) { | ||
827 | - qemu_wait_io_event_common(cpu); | ||
828 | - } | ||
829 | -} | ||
830 | - | ||
831 | -static int64_t tcg_get_icount_limit(void) | ||
832 | -{ | ||
833 | - int64_t deadline; | ||
834 | - | ||
835 | - if (replay_mode != REPLAY_MODE_PLAY) { | ||
836 | - /* | ||
837 | - * Include all the timers, because they may need an attention. | ||
838 | - * Too long CPU execution may create unnecessary delay in UI. | ||
839 | - */ | ||
840 | - deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | ||
841 | - QEMU_TIMER_ATTR_ALL); | ||
842 | - /* Check realtime timers, because they help with input processing */ | ||
843 | - deadline = qemu_soonest_timeout(deadline, | ||
844 | - qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME, | ||
845 | - QEMU_TIMER_ATTR_ALL)); | ||
846 | - | ||
847 | - /* | ||
848 | - * Maintain prior (possibly buggy) behaviour where if no deadline | ||
849 | - * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than | ||
850 | - * INT32_MAX nanoseconds ahead, we still use INT32_MAX | ||
851 | - * nanoseconds. | ||
852 | - */ | ||
853 | - if ((deadline < 0) || (deadline > INT32_MAX)) { | ||
854 | - deadline = INT32_MAX; | ||
855 | - } | ||
856 | - | ||
857 | - return icount_round(deadline); | ||
858 | - } else { | ||
859 | - return replay_get_instructions(); | ||
860 | - } | ||
861 | -} | ||
862 | - | ||
863 | -static void notify_aio_contexts(void) | ||
864 | -{ | ||
865 | - /* Wake up other AioContexts. */ | ||
866 | - qemu_clock_notify(QEMU_CLOCK_VIRTUAL); | ||
867 | - qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); | ||
868 | -} | ||
869 | - | ||
870 | -static void handle_icount_deadline(void) | ||
871 | -{ | ||
872 | - assert(qemu_in_vcpu_thread()); | ||
873 | - if (icount_enabled()) { | ||
874 | - int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | ||
875 | - QEMU_TIMER_ATTR_ALL); | ||
876 | - | ||
877 | - if (deadline == 0) { | ||
878 | - notify_aio_contexts(); | ||
879 | - } | ||
880 | - } | ||
881 | -} | ||
882 | - | ||
883 | -static void prepare_icount_for_run(CPUState *cpu) | ||
884 | -{ | ||
885 | - if (icount_enabled()) { | ||
886 | - int insns_left; | ||
887 | - | ||
888 | - /* | ||
889 | - * These should always be cleared by process_icount_data after | ||
890 | - * each vCPU execution. However u16.high can be raised | ||
891 | - * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | ||
892 | - */ | ||
893 | - g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
894 | - g_assert(cpu->icount_extra == 0); | ||
895 | - | ||
896 | - cpu->icount_budget = tcg_get_icount_limit(); | ||
897 | - insns_left = MIN(0xffff, cpu->icount_budget); | ||
898 | - cpu_neg(cpu)->icount_decr.u16.low = insns_left; | ||
899 | - cpu->icount_extra = cpu->icount_budget - insns_left; | ||
900 | - | ||
901 | - replay_mutex_lock(); | ||
902 | - | ||
903 | - if (cpu->icount_budget == 0 && replay_has_checkpoint()) { | ||
904 | - notify_aio_contexts(); | ||
905 | - } | ||
906 | - } | ||
907 | -} | ||
908 | - | ||
909 | -static void process_icount_data(CPUState *cpu) | ||
910 | -{ | ||
911 | - if (icount_enabled()) { | ||
912 | - /* Account for executed instructions */ | ||
913 | - icount_update(cpu); | ||
914 | - | ||
915 | - /* Reset the counters */ | ||
916 | - cpu_neg(cpu)->icount_decr.u16.low = 0; | ||
917 | - cpu->icount_extra = 0; | ||
918 | - cpu->icount_budget = 0; | ||
919 | - | ||
920 | - replay_account_executed_instructions(); | ||
921 | - | ||
922 | - replay_mutex_unlock(); | ||
923 | - } | ||
924 | -} | ||
925 | - | ||
926 | -static int tcg_cpu_exec(CPUState *cpu) | ||
927 | -{ | ||
928 | - int ret; | ||
929 | -#ifdef CONFIG_PROFILER | ||
930 | - int64_t ti; | ||
931 | -#endif | ||
932 | - | ||
933 | - assert(tcg_enabled()); | ||
934 | -#ifdef CONFIG_PROFILER | ||
935 | - ti = profile_getclock(); | ||
936 | -#endif | ||
937 | - cpu_exec_start(cpu); | ||
938 | - ret = cpu_exec(cpu); | ||
939 | - cpu_exec_end(cpu); | ||
940 | -#ifdef CONFIG_PROFILER | ||
941 | - qatomic_set(&tcg_ctx->prof.cpu_exec_time, | ||
942 | - tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti); | ||
943 | -#endif | ||
944 | - return ret; | ||
945 | -} | ||
946 | - | ||
947 | -/* | ||
948 | - * Destroy any remaining vCPUs which have been unplugged and have | ||
949 | - * finished running | ||
950 | - */ | ||
951 | -static void deal_with_unplugged_cpus(void) | ||
952 | -{ | ||
953 | - CPUState *cpu; | ||
954 | - | ||
955 | - CPU_FOREACH(cpu) { | ||
956 | - if (cpu->unplug && !cpu_can_run(cpu)) { | ||
957 | - qemu_tcg_destroy_vcpu(cpu); | ||
958 | - cpu_thread_signal_destroyed(cpu); | ||
959 | - break; | ||
960 | - } | ||
961 | - } | ||
962 | -} | ||
963 | - | ||
964 | -/* | ||
965 | - * Single-threaded TCG | ||
966 | - * | ||
967 | - * In the single-threaded case each vCPU is simulated in turn. If | ||
968 | - * there is more than a single vCPU we create a simple timer to kick | ||
969 | - * the vCPU and ensure we don't get stuck in a tight loop in one vCPU. | ||
970 | - * This is done explicitly rather than relying on side-effects | ||
971 | - * elsewhere. | ||
972 | - */ | ||
973 | - | ||
974 | -static void *tcg_rr_cpu_thread_fn(void *arg) | ||
975 | -{ | ||
976 | - CPUState *cpu = arg; | ||
977 | - | ||
978 | - assert(tcg_enabled()); | ||
979 | - rcu_register_thread(); | ||
980 | - tcg_register_thread(); | ||
981 | - | ||
982 | - qemu_mutex_lock_iothread(); | ||
983 | - qemu_thread_get_self(cpu->thread); | ||
984 | - | ||
985 | - cpu->thread_id = qemu_get_thread_id(); | ||
986 | - cpu->can_do_io = 1; | ||
987 | - cpu_thread_signal_created(cpu); | ||
988 | - qemu_guest_random_seed_thread_part2(cpu->random_seed); | ||
989 | - | ||
990 | - /* wait for initial kick-off after machine start */ | ||
991 | - while (first_cpu->stopped) { | ||
992 | - qemu_cond_wait_iothread(first_cpu->halt_cond); | ||
993 | - | ||
994 | - /* process any pending work */ | ||
995 | - CPU_FOREACH(cpu) { | ||
996 | - current_cpu = cpu; | ||
997 | - qemu_wait_io_event_common(cpu); | ||
998 | - } | ||
999 | - } | ||
1000 | - | ||
1001 | - start_tcg_kick_timer(); | ||
1002 | - | ||
1003 | - cpu = first_cpu; | ||
1004 | - | ||
1005 | - /* process any pending work */ | ||
1006 | - cpu->exit_request = 1; | ||
1007 | - | ||
1008 | - while (1) { | ||
1009 | - qemu_mutex_unlock_iothread(); | ||
1010 | - replay_mutex_lock(); | ||
1011 | - qemu_mutex_lock_iothread(); | ||
1012 | - /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ | ||
1013 | - icount_account_warp_timer(); | ||
1014 | - | ||
1015 | - /* | ||
1016 | - * Run the timers here. This is much more efficient than | ||
1017 | - * waking up the I/O thread and waiting for completion. | ||
1018 | - */ | ||
1019 | - handle_icount_deadline(); | ||
1020 | - | ||
1021 | - replay_mutex_unlock(); | ||
1022 | - | ||
1023 | - if (!cpu) { | ||
1024 | - cpu = first_cpu; | ||
1025 | - } | ||
1026 | - | ||
1027 | - while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { | ||
1028 | - | ||
1029 | - qatomic_mb_set(&tcg_current_rr_cpu, cpu); | ||
1030 | - current_cpu = cpu; | ||
1031 | - | ||
1032 | - qemu_clock_enable(QEMU_CLOCK_VIRTUAL, | ||
1033 | - (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); | ||
1034 | - | ||
1035 | - if (cpu_can_run(cpu)) { | ||
1036 | - int r; | ||
1037 | - | ||
1038 | - qemu_mutex_unlock_iothread(); | ||
1039 | - prepare_icount_for_run(cpu); | ||
1040 | - | ||
1041 | - r = tcg_cpu_exec(cpu); | ||
1042 | - | ||
1043 | - process_icount_data(cpu); | ||
1044 | - qemu_mutex_lock_iothread(); | ||
1045 | - | ||
1046 | - if (r == EXCP_DEBUG) { | ||
1047 | - cpu_handle_guest_debug(cpu); | ||
1048 | - break; | ||
1049 | - } else if (r == EXCP_ATOMIC) { | ||
1050 | - qemu_mutex_unlock_iothread(); | ||
1051 | - cpu_exec_step_atomic(cpu); | ||
1052 | - qemu_mutex_lock_iothread(); | ||
1053 | - break; | ||
1054 | - } | 127 | - } |
1055 | - } else if (cpu->stop) { | 128 | + inject_mem_cb(&g_array_index(cbs, struct qemu_plugin_dyn_cb, i), |
1056 | - if (cpu->unplug) { | 129 | + rw, meminfo, addr); |
1057 | - cpu = CPU_NEXT(cpu); | 130 | } |
1058 | - } | 131 | |
1059 | - break; | 132 | tcg_ctx->emit_before_op = NULL; |
1060 | - } | ||
1061 | - | ||
1062 | - cpu = CPU_NEXT(cpu); | ||
1063 | - } /* while (cpu && !cpu->exit_request).. */ | ||
1064 | - | ||
1065 | - /* Does not need qatomic_mb_set because a spurious wakeup is okay. */ | ||
1066 | - qatomic_set(&tcg_current_rr_cpu, NULL); | ||
1067 | - | ||
1068 | - if (cpu && cpu->exit_request) { | ||
1069 | - qatomic_mb_set(&cpu->exit_request, 0); | ||
1070 | - } | ||
1071 | - | ||
1072 | - if (icount_enabled() && all_cpu_threads_idle()) { | ||
1073 | - /* | ||
1074 | - * When all cpus are sleeping (e.g in WFI), to avoid a deadlock | ||
1075 | - * in the main_loop, wake it up in order to start the warp timer. | ||
1076 | - */ | ||
1077 | - qemu_notify_event(); | ||
1078 | - } | ||
1079 | - | ||
1080 | - qemu_tcg_rr_wait_io_event(); | ||
1081 | - deal_with_unplugged_cpus(); | ||
1082 | - } | ||
1083 | - | ||
1084 | - rcu_unregister_thread(); | ||
1085 | - return NULL; | ||
1086 | -} | ||
1087 | - | ||
1088 | -/* | ||
1089 | - * Multi-threaded TCG | ||
1090 | - * | ||
1091 | - * In the multi-threaded case each vCPU has its own thread. The TLS | ||
1092 | - * variable current_cpu can be used deep in the code to find the | ||
1093 | - * current CPUState for a given thread. | ||
1094 | - */ | ||
1095 | - | ||
1096 | -static void *tcg_cpu_thread_fn(void *arg) | ||
1097 | -{ | ||
1098 | - CPUState *cpu = arg; | ||
1099 | - | ||
1100 | - assert(tcg_enabled()); | ||
1101 | - g_assert(!icount_enabled()); | ||
1102 | - | ||
1103 | - rcu_register_thread(); | ||
1104 | - tcg_register_thread(); | ||
1105 | - | ||
1106 | - qemu_mutex_lock_iothread(); | ||
1107 | - qemu_thread_get_self(cpu->thread); | ||
1108 | - | ||
1109 | - cpu->thread_id = qemu_get_thread_id(); | ||
1110 | - cpu->can_do_io = 1; | ||
1111 | - current_cpu = cpu; | ||
1112 | - cpu_thread_signal_created(cpu); | ||
1113 | - qemu_guest_random_seed_thread_part2(cpu->random_seed); | ||
1114 | - | ||
1115 | - /* process any pending work */ | ||
1116 | - cpu->exit_request = 1; | ||
1117 | - | ||
1118 | - do { | ||
1119 | - if (cpu_can_run(cpu)) { | ||
1120 | - int r; | ||
1121 | - qemu_mutex_unlock_iothread(); | ||
1122 | - r = tcg_cpu_exec(cpu); | ||
1123 | - qemu_mutex_lock_iothread(); | ||
1124 | - switch (r) { | ||
1125 | - case EXCP_DEBUG: | ||
1126 | - cpu_handle_guest_debug(cpu); | ||
1127 | - break; | ||
1128 | - case EXCP_HALTED: | ||
1129 | - /* | ||
1130 | - * during start-up the vCPU is reset and the thread is | ||
1131 | - * kicked several times. If we don't ensure we go back | ||
1132 | - * to sleep in the halted state we won't cleanly | ||
1133 | - * start-up when the vCPU is enabled. | ||
1134 | - * | ||
1135 | - * cpu->halted should ensure we sleep in wait_io_event | ||
1136 | - */ | ||
1137 | - g_assert(cpu->halted); | ||
1138 | - break; | ||
1139 | - case EXCP_ATOMIC: | ||
1140 | - qemu_mutex_unlock_iothread(); | ||
1141 | - cpu_exec_step_atomic(cpu); | ||
1142 | - qemu_mutex_lock_iothread(); | ||
1143 | - default: | ||
1144 | - /* Ignore everything else? */ | ||
1145 | - break; | ||
1146 | - } | ||
1147 | - } | ||
1148 | - | ||
1149 | - qatomic_mb_set(&cpu->exit_request, 0); | ||
1150 | - qemu_wait_io_event(cpu); | ||
1151 | - } while (!cpu->unplug || cpu_can_run(cpu)); | ||
1152 | - | ||
1153 | - qemu_tcg_destroy_vcpu(cpu); | ||
1154 | - cpu_thread_signal_destroyed(cpu); | ||
1155 | - qemu_mutex_unlock_iothread(); | ||
1156 | - rcu_unregister_thread(); | ||
1157 | - return NULL; | ||
1158 | -} | ||
1159 | - | ||
1160 | -static void tcg_start_vcpu_thread(CPUState *cpu) | ||
1161 | +void tcg_start_vcpu_thread(CPUState *cpu) | ||
1162 | { | ||
1163 | char thread_name[VCPU_THREAD_NAME_SIZE]; | ||
1164 | static QemuCond *single_tcg_halt_cond; | ||
1165 | @@ -XXX,XX +XXX,XX @@ static void tcg_start_vcpu_thread(CPUState *cpu) | ||
1166 | } | ||
1167 | } | ||
1168 | |||
1169 | -static int64_t tcg_get_virtual_clock(void) | ||
1170 | +void qemu_tcg_destroy_vcpu(CPUState *cpu) | ||
1171 | { | ||
1172 | - if (icount_enabled()) { | ||
1173 | - return icount_get(); | ||
1174 | - } | ||
1175 | - return cpu_get_clock(); | ||
1176 | + cpu_thread_signal_destroyed(cpu); | ||
1177 | } | ||
1178 | |||
1179 | -static int64_t tcg_get_elapsed_ticks(void) | ||
1180 | +int tcg_cpu_exec(CPUState *cpu) | ||
1181 | { | ||
1182 | - if (icount_enabled()) { | ||
1183 | - return icount_get(); | ||
1184 | - } | ||
1185 | - return cpu_get_ticks(); | ||
1186 | + int ret; | ||
1187 | +#ifdef CONFIG_PROFILER | ||
1188 | + int64_t ti; | ||
1189 | +#endif | ||
1190 | + assert(tcg_enabled()); | ||
1191 | +#ifdef CONFIG_PROFILER | ||
1192 | + ti = profile_getclock(); | ||
1193 | +#endif | ||
1194 | + cpu_exec_start(cpu); | ||
1195 | + ret = cpu_exec(cpu); | ||
1196 | + cpu_exec_end(cpu); | ||
1197 | +#ifdef CONFIG_PROFILER | ||
1198 | + qatomic_set(&tcg_ctx->prof.cpu_exec_time, | ||
1199 | + tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti); | ||
1200 | +#endif | ||
1201 | + return ret; | ||
1202 | } | ||
1203 | |||
1204 | /* mask must never be zero, except for A20 change call */ | ||
1205 | -static void tcg_handle_interrupt(CPUState *cpu, int mask) | ||
1206 | +void tcg_handle_interrupt(CPUState *cpu, int mask) | ||
1207 | { | ||
1208 | - int old_mask; | ||
1209 | g_assert(qemu_mutex_iothread_locked()); | ||
1210 | |||
1211 | - old_mask = cpu->interrupt_request; | ||
1212 | cpu->interrupt_request |= mask; | ||
1213 | |||
1214 | /* | ||
1215 | @@ -XXX,XX +XXX,XX @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) | ||
1216 | qemu_cpu_kick(cpu); | ||
1217 | } else { | ||
1218 | qatomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1); | ||
1219 | - if (icount_enabled() && | ||
1220 | - !cpu->can_do_io | ||
1221 | - && (mask & ~old_mask) != 0) { | ||
1222 | - cpu_abort(cpu, "Raised interrupt while not in I/O function"); | ||
1223 | - } | ||
1224 | } | ||
1225 | } | ||
1226 | - | ||
1227 | -const CpusAccel tcg_cpus = { | ||
1228 | - .create_vcpu_thread = tcg_start_vcpu_thread, | ||
1229 | - .kick_vcpu_thread = tcg_kick_vcpu_thread, | ||
1230 | - | ||
1231 | - .handle_interrupt = tcg_handle_interrupt, | ||
1232 | - | ||
1233 | - .get_virtual_clock = tcg_get_virtual_clock, | ||
1234 | - .get_elapsed_ticks = tcg_get_elapsed_ticks, | ||
1235 | -}; | ||
1236 | diff --git a/softmmu/icount.c b/softmmu/icount.c | ||
1237 | index XXXXXXX..XXXXXXX 100644 | ||
1238 | --- a/softmmu/icount.c | ||
1239 | +++ b/softmmu/icount.c | ||
1240 | @@ -XXX,XX +XXX,XX @@ void icount_start_warp_timer(void) | ||
1241 | |||
1242 | void icount_account_warp_timer(void) | ||
1243 | { | ||
1244 | - if (!icount_enabled() || !icount_sleep) { | ||
1245 | + if (!icount_sleep) { | ||
1246 | return; | ||
1247 | } | ||
1248 | |||
1249 | diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build | ||
1250 | index XXXXXXX..XXXXXXX 100644 | ||
1251 | --- a/accel/tcg/meson.build | ||
1252 | +++ b/accel/tcg/meson.build | ||
1253 | @@ -XXX,XX +XXX,XX @@ tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c')) | ||
1254 | tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl]) | ||
1255 | specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) | ||
1256 | |||
1257 | -specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files('tcg-all.c', 'cputlb.c', 'tcg-cpus.c')) | ||
1258 | +specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( | ||
1259 | + 'tcg-all.c', | ||
1260 | + 'cputlb.c', | ||
1261 | + 'tcg-cpus.c', | ||
1262 | + 'tcg-cpus-mttcg.c', | ||
1263 | + 'tcg-cpus-icount.c', | ||
1264 | + 'tcg-cpus-rr.c' | ||
1265 | +)) | ||
1266 | -- | 133 | -- |
1267 | 2.25.1 | 134 | 2.34.1 |
1268 | |||
1269 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Merge qemu_plugin_insn_alloc and qemu_plugin_tb_insn_get into | ||
2 | plugin_gen_insn_start, since it is used nowhere else. | ||
1 | 3 | ||
4 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | include/qemu/plugin.h | 39 --------------------------------------- | ||
8 | accel/tcg/plugin-gen.c | 39 ++++++++++++++++++++++++++++++++------- | ||
9 | 2 files changed, 32 insertions(+), 46 deletions(-) | ||
10 | |||
11 | diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/include/qemu/plugin.h | ||
14 | +++ b/include/qemu/plugin.h | ||
15 | @@ -XXX,XX +XXX,XX @@ static inline void qemu_plugin_insn_cleanup_fn(gpointer data) | ||
16 | g_byte_array_free(insn->data, true); | ||
17 | } | ||
18 | |||
19 | -static inline struct qemu_plugin_insn *qemu_plugin_insn_alloc(void) | ||
20 | -{ | ||
21 | - struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); | ||
22 | - | ||
23 | - insn->data = g_byte_array_sized_new(4); | ||
24 | - return insn; | ||
25 | -} | ||
26 | - | ||
27 | /* Internal context for this TranslationBlock */ | ||
28 | struct qemu_plugin_tb { | ||
29 | GPtrArray *insns; | ||
30 | @@ -XXX,XX +XXX,XX @@ struct qemu_plugin_tb { | ||
31 | GArray *cbs; | ||
32 | }; | ||
33 | |||
34 | -/** | ||
35 | - * qemu_plugin_tb_insn_get(): get next plugin record for translation. | ||
36 | - * @tb: the internal tb context | ||
37 | - * @pc: address of instruction | ||
38 | - */ | ||
39 | -static inline | ||
40 | -struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, | ||
41 | - uint64_t pc) | ||
42 | -{ | ||
43 | - struct qemu_plugin_insn *insn; | ||
44 | - | ||
45 | - if (unlikely(tb->n == tb->insns->len)) { | ||
46 | - struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc(); | ||
47 | - g_ptr_array_add(tb->insns, new_insn); | ||
48 | - } | ||
49 | - | ||
50 | - insn = g_ptr_array_index(tb->insns, tb->n++); | ||
51 | - g_byte_array_set_size(insn->data, 0); | ||
52 | - insn->calls_helpers = false; | ||
53 | - insn->mem_helper = false; | ||
54 | - insn->vaddr = pc; | ||
55 | - if (insn->insn_cbs) { | ||
56 | - g_array_set_size(insn->insn_cbs, 0); | ||
57 | - } | ||
58 | - if (insn->mem_cbs) { | ||
59 | - g_array_set_size(insn->mem_cbs, 0); | ||
60 | - } | ||
61 | - | ||
62 | - return insn; | ||
63 | -} | ||
64 | - | ||
65 | /** | ||
66 | * struct CPUPluginState - per-CPU state for plugins | ||
67 | * @event_mask: plugin event bitmap. Modified only via async work. | ||
68 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/accel/tcg/plugin-gen.c | ||
71 | +++ b/accel/tcg/plugin-gen.c | ||
72 | @@ -XXX,XX +XXX,XX @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, | ||
73 | void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) | ||
74 | { | ||
75 | struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; | ||
76 | - struct qemu_plugin_insn *pinsn; | ||
77 | + struct qemu_plugin_insn *insn; | ||
78 | + size_t n = db->num_insns; | ||
79 | + vaddr pc; | ||
80 | |||
81 | - pinsn = qemu_plugin_tb_insn_get(ptb, db->pc_next); | ||
82 | - tcg_ctx->plugin_insn = pinsn; | ||
83 | - plugin_gen_empty_callback(PLUGIN_GEN_FROM_INSN); | ||
84 | + assert(n >= 1); | ||
85 | + ptb->n = n; | ||
86 | + if (n <= ptb->insns->len) { | ||
87 | + insn = g_ptr_array_index(ptb->insns, n - 1); | ||
88 | + g_byte_array_set_size(insn->data, 0); | ||
89 | + } else { | ||
90 | + assert(n - 1 == ptb->insns->len); | ||
91 | + insn = g_new0(struct qemu_plugin_insn, 1); | ||
92 | + insn->data = g_byte_array_sized_new(4); | ||
93 | + g_ptr_array_add(ptb->insns, insn); | ||
94 | + } | ||
95 | + | ||
96 | + tcg_ctx->plugin_insn = insn; | ||
97 | + insn->calls_helpers = false; | ||
98 | + insn->mem_helper = false; | ||
99 | + if (insn->insn_cbs) { | ||
100 | + g_array_set_size(insn->insn_cbs, 0); | ||
101 | + } | ||
102 | + if (insn->mem_cbs) { | ||
103 | + g_array_set_size(insn->mem_cbs, 0); | ||
104 | + } | ||
105 | + | ||
106 | + pc = db->pc_next; | ||
107 | + insn->vaddr = pc; | ||
108 | |||
109 | /* | ||
110 | * Detect page crossing to get the new host address. | ||
111 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) | ||
112 | * fetching instructions from a region not backed by RAM. | ||
113 | */ | ||
114 | if (ptb->haddr1 == NULL) { | ||
115 | - pinsn->haddr = NULL; | ||
116 | + insn->haddr = NULL; | ||
117 | } else if (is_same_page(db, db->pc_next)) { | ||
118 | - pinsn->haddr = ptb->haddr1 + pinsn->vaddr - ptb->vaddr; | ||
119 | + insn->haddr = ptb->haddr1 + pc - ptb->vaddr; | ||
120 | } else { | ||
121 | if (ptb->vaddr2 == -1) { | ||
122 | ptb->vaddr2 = TARGET_PAGE_ALIGN(db->pc_first); | ||
123 | get_page_addr_code_hostp(cpu_env(cpu), ptb->vaddr2, &ptb->haddr2); | ||
124 | } | ||
125 | - pinsn->haddr = ptb->haddr2 + pinsn->vaddr - ptb->vaddr2; | ||
126 | + insn->haddr = ptb->haddr2 + pc - ptb->vaddr2; | ||
127 | } | ||
128 | + | ||
129 | + plugin_gen_empty_callback(PLUGIN_GEN_FROM_INSN); | ||
130 | } | ||
131 | |||
132 | void plugin_gen_insn_end(void) | ||
133 | -- | ||
134 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Each caller can use tcg_gen_plugin_cb directly. |
---|---|---|---|
2 | 2 | ||
3 | after the initial split into 3 tcg variants, we proceed to also | 3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
4 | split tcg_start_vcpu_thread. | ||
5 | |||
6 | We actually split it in 2 this time, since the icount variant | ||
7 | just uses the round robin function. | ||
8 | |||
9 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
11 | Message-Id: <20201015143217.29337-3-cfontana@suse.de> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 5 | --- |
14 | accel/tcg/tcg-cpus-mttcg.h | 21 -------------- | 6 | accel/tcg/plugin-gen.c | 19 +++---------------- |
15 | accel/tcg/tcg-cpus-rr.h | 3 +- | 7 | 1 file changed, 3 insertions(+), 16 deletions(-) |
16 | accel/tcg/tcg-cpus.h | 1 - | ||
17 | accel/tcg/tcg-all.c | 5 ++++ | ||
18 | accel/tcg/tcg-cpus-icount.c | 2 +- | ||
19 | accel/tcg/tcg-cpus-mttcg.c | 29 +++++++++++++++++-- | ||
20 | accel/tcg/tcg-cpus-rr.c | 39 +++++++++++++++++++++++-- | ||
21 | accel/tcg/tcg-cpus.c | 58 ------------------------------------- | ||
22 | 8 files changed, 71 insertions(+), 87 deletions(-) | ||
23 | delete mode 100644 accel/tcg/tcg-cpus-mttcg.h | ||
24 | 8 | ||
25 | diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h | 9 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c |
26 | deleted file mode 100644 | ||
27 | index XXXXXXX..XXXXXXX | ||
28 | --- a/accel/tcg/tcg-cpus-mttcg.h | ||
29 | +++ /dev/null | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | -/* | ||
32 | - * QEMU TCG Multi Threaded vCPUs implementation | ||
33 | - * | ||
34 | - * Copyright 2020 SUSE LLC | ||
35 | - * | ||
36 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
37 | - * See the COPYING file in the top-level directory. | ||
38 | - */ | ||
39 | - | ||
40 | -#ifndef TCG_CPUS_MTTCG_H | ||
41 | -#define TCG_CPUS_MTTCG_H | ||
42 | - | ||
43 | -/* | ||
44 | - * In the multi-threaded case each vCPU has its own thread. The TLS | ||
45 | - * variable current_cpu can be used deep in the code to find the | ||
46 | - * current CPUState for a given thread. | ||
47 | - */ | ||
48 | - | ||
49 | -void *tcg_cpu_thread_fn(void *arg); | ||
50 | - | ||
51 | -#endif /* TCG_CPUS_MTTCG_H */ | ||
52 | diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/accel/tcg/tcg-cpus-rr.h | 11 | --- a/accel/tcg/plugin-gen.c |
55 | +++ b/accel/tcg/tcg-cpus-rr.h | 12 | +++ b/accel/tcg/plugin-gen.c |
56 | @@ -XXX,XX +XXX,XX @@ | 13 | @@ -XXX,XX +XXX,XX @@ enum plugin_gen_from { |
57 | /* Kick all RR vCPUs. */ | 14 | PLUGIN_GEN_AFTER_TB, |
58 | void qemu_cpu_kick_rr_cpus(CPUState *unused); | 15 | }; |
59 | 16 | ||
60 | -void *tcg_rr_cpu_thread_fn(void *arg); | 17 | -static void plugin_gen_empty_callback(enum plugin_gen_from from) |
61 | +/* start the round robin vcpu thread */ | ||
62 | +void rr_start_vcpu_thread(CPUState *cpu); | ||
63 | |||
64 | #endif /* TCG_CPUS_RR_H */ | ||
65 | diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/accel/tcg/tcg-cpus.h | ||
68 | +++ b/accel/tcg/tcg-cpus.h | ||
69 | @@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg; | ||
70 | extern const CpusAccel tcg_cpus_icount; | ||
71 | extern const CpusAccel tcg_cpus_rr; | ||
72 | |||
73 | -void tcg_start_vcpu_thread(CPUState *cpu); | ||
74 | void qemu_tcg_destroy_vcpu(CPUState *cpu); | ||
75 | int tcg_cpu_exec(CPUState *cpu); | ||
76 | void tcg_handle_interrupt(CPUState *cpu, int mask); | ||
77 | diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/accel/tcg/tcg-all.c | ||
80 | +++ b/accel/tcg/tcg-all.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms) | ||
82 | tcg_exec_init(s->tb_size * 1024 * 1024); | ||
83 | mttcg_enabled = s->mttcg_enabled; | ||
84 | |||
85 | + /* | ||
86 | + * Initialize TCG regions | ||
87 | + */ | ||
88 | + tcg_region_init(); | ||
89 | + | ||
90 | if (mttcg_enabled) { | ||
91 | cpus_register_accel(&tcg_cpus_mttcg); | ||
92 | } else if (icount_enabled()) { | ||
93 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/accel/tcg/tcg-cpus-icount.c | ||
96 | +++ b/accel/tcg/tcg-cpus-icount.c | ||
97 | @@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
98 | } | ||
99 | |||
100 | const CpusAccel tcg_cpus_icount = { | ||
101 | - .create_vcpu_thread = tcg_start_vcpu_thread, | ||
102 | + .create_vcpu_thread = rr_start_vcpu_thread, | ||
103 | .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
104 | |||
105 | .handle_interrupt = icount_handle_interrupt, | ||
106 | diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/accel/tcg/tcg-cpus-mttcg.c | ||
109 | +++ b/accel/tcg/tcg-cpus-mttcg.c | ||
110 | @@ -XXX,XX +XXX,XX @@ | ||
111 | #include "hw/boards.h" | ||
112 | |||
113 | #include "tcg-cpus.h" | ||
114 | -#include "tcg-cpus-mttcg.h" | ||
115 | |||
116 | /* | ||
117 | * In the multi-threaded case each vCPU has its own thread. The TLS | ||
118 | @@ -XXX,XX +XXX,XX @@ | ||
119 | * current CPUState for a given thread. | ||
120 | */ | ||
121 | |||
122 | -void *tcg_cpu_thread_fn(void *arg) | ||
123 | +static void *tcg_cpu_thread_fn(void *arg) | ||
124 | { | ||
125 | CPUState *cpu = arg; | ||
126 | |||
127 | @@ -XXX,XX +XXX,XX @@ static void mttcg_kick_vcpu_thread(CPUState *cpu) | ||
128 | cpu_exit(cpu); | ||
129 | } | ||
130 | |||
131 | +static void mttcg_start_vcpu_thread(CPUState *cpu) | ||
132 | +{ | ||
133 | + char thread_name[VCPU_THREAD_NAME_SIZE]; | ||
134 | + | ||
135 | + g_assert(tcg_enabled()); | ||
136 | + | ||
137 | + parallel_cpus = (current_machine->smp.max_cpus > 1); | ||
138 | + | ||
139 | + cpu->thread = g_malloc0(sizeof(QemuThread)); | ||
140 | + cpu->halt_cond = g_malloc0(sizeof(QemuCond)); | ||
141 | + qemu_cond_init(cpu->halt_cond); | ||
142 | + | ||
143 | + /* create a thread per vCPU with TCG (MTTCG) */ | ||
144 | + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", | ||
145 | + cpu->cpu_index); | ||
146 | + | ||
147 | + qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn, | ||
148 | + cpu, QEMU_THREAD_JOINABLE); | ||
149 | + | ||
150 | +#ifdef _WIN32 | ||
151 | + cpu->hThread = qemu_thread_get_handle(cpu->thread); | ||
152 | +#endif | ||
153 | +} | ||
154 | + | ||
155 | const CpusAccel tcg_cpus_mttcg = { | ||
156 | - .create_vcpu_thread = tcg_start_vcpu_thread, | ||
157 | + .create_vcpu_thread = mttcg_start_vcpu_thread, | ||
158 | .kick_vcpu_thread = mttcg_kick_vcpu_thread, | ||
159 | |||
160 | .handle_interrupt = tcg_handle_interrupt, | ||
161 | diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/accel/tcg/tcg-cpus-rr.c | ||
164 | +++ b/accel/tcg/tcg-cpus-rr.c | ||
165 | @@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void) | ||
166 | * elsewhere. | ||
167 | */ | ||
168 | |||
169 | -void *tcg_rr_cpu_thread_fn(void *arg) | ||
170 | +static void *tcg_rr_cpu_thread_fn(void *arg) | ||
171 | { | ||
172 | CPUState *cpu = arg; | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ void *tcg_rr_cpu_thread_fn(void *arg) | ||
175 | return NULL; | ||
176 | } | ||
177 | |||
178 | +void rr_start_vcpu_thread(CPUState *cpu) | ||
179 | +{ | ||
180 | + char thread_name[VCPU_THREAD_NAME_SIZE]; | ||
181 | + static QemuCond *single_tcg_halt_cond; | ||
182 | + static QemuThread *single_tcg_cpu_thread; | ||
183 | + | ||
184 | + g_assert(tcg_enabled()); | ||
185 | + parallel_cpus = false; | ||
186 | + | ||
187 | + if (!single_tcg_cpu_thread) { | ||
188 | + cpu->thread = g_malloc0(sizeof(QemuThread)); | ||
189 | + cpu->halt_cond = g_malloc0(sizeof(QemuCond)); | ||
190 | + qemu_cond_init(cpu->halt_cond); | ||
191 | + | ||
192 | + /* share a single thread for all cpus with TCG */ | ||
193 | + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); | ||
194 | + qemu_thread_create(cpu->thread, thread_name, | ||
195 | + tcg_rr_cpu_thread_fn, | ||
196 | + cpu, QEMU_THREAD_JOINABLE); | ||
197 | + | ||
198 | + single_tcg_halt_cond = cpu->halt_cond; | ||
199 | + single_tcg_cpu_thread = cpu->thread; | ||
200 | +#ifdef _WIN32 | ||
201 | + cpu->hThread = qemu_thread_get_handle(cpu->thread); | ||
202 | +#endif | ||
203 | + } else { | ||
204 | + /* we share the thread */ | ||
205 | + cpu->thread = single_tcg_cpu_thread; | ||
206 | + cpu->halt_cond = single_tcg_halt_cond; | ||
207 | + cpu->thread_id = first_cpu->thread_id; | ||
208 | + cpu->can_do_io = 1; | ||
209 | + cpu->created = true; | ||
210 | + } | ||
211 | +} | ||
212 | + | ||
213 | const CpusAccel tcg_cpus_rr = { | ||
214 | - .create_vcpu_thread = tcg_start_vcpu_thread, | ||
215 | + .create_vcpu_thread = rr_start_vcpu_thread, | ||
216 | .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
217 | |||
218 | .handle_interrupt = tcg_handle_interrupt, | ||
219 | diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/accel/tcg/tcg-cpus.c | ||
222 | +++ b/accel/tcg/tcg-cpus.c | ||
223 | @@ -XXX,XX +XXX,XX @@ | ||
224 | #include "hw/boards.h" | ||
225 | |||
226 | #include "tcg-cpus.h" | ||
227 | -#include "tcg-cpus-mttcg.h" | ||
228 | -#include "tcg-cpus-rr.h" | ||
229 | |||
230 | /* common functionality among all TCG variants */ | ||
231 | |||
232 | -void tcg_start_vcpu_thread(CPUState *cpu) | ||
233 | -{ | 18 | -{ |
234 | - char thread_name[VCPU_THREAD_NAME_SIZE]; | 19 | - switch (from) { |
235 | - static QemuCond *single_tcg_halt_cond; | 20 | - case PLUGIN_GEN_AFTER_INSN: |
236 | - static QemuThread *single_tcg_cpu_thread; | 21 | - case PLUGIN_GEN_FROM_TB: |
237 | - static int tcg_region_inited; | 22 | - case PLUGIN_GEN_FROM_INSN: |
238 | - | 23 | - tcg_gen_plugin_cb(from); |
239 | - assert(tcg_enabled()); | 24 | - break; |
240 | - /* | 25 | - default: |
241 | - * Initialize TCG regions--once. Now is a good time, because: | 26 | - g_assert_not_reached(); |
242 | - * (1) TCG's init context, prologue and target globals have been set up. | ||
243 | - * (2) qemu_tcg_mttcg_enabled() works now (TCG init code runs before the | ||
244 | - * -accel flag is processed, so the check doesn't work then). | ||
245 | - */ | ||
246 | - if (!tcg_region_inited) { | ||
247 | - tcg_region_inited = 1; | ||
248 | - tcg_region_init(); | ||
249 | - parallel_cpus = qemu_tcg_mttcg_enabled() && current_machine->smp.max_cpus > 1; | ||
250 | - } | ||
251 | - | ||
252 | - if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) { | ||
253 | - cpu->thread = g_malloc0(sizeof(QemuThread)); | ||
254 | - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); | ||
255 | - qemu_cond_init(cpu->halt_cond); | ||
256 | - | ||
257 | - if (qemu_tcg_mttcg_enabled()) { | ||
258 | - /* create a thread per vCPU with TCG (MTTCG) */ | ||
259 | - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", | ||
260 | - cpu->cpu_index); | ||
261 | - | ||
262 | - qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn, | ||
263 | - cpu, QEMU_THREAD_JOINABLE); | ||
264 | - | ||
265 | - } else { | ||
266 | - /* share a single thread for all cpus with TCG */ | ||
267 | - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); | ||
268 | - qemu_thread_create(cpu->thread, thread_name, | ||
269 | - tcg_rr_cpu_thread_fn, | ||
270 | - cpu, QEMU_THREAD_JOINABLE); | ||
271 | - | ||
272 | - single_tcg_halt_cond = cpu->halt_cond; | ||
273 | - single_tcg_cpu_thread = cpu->thread; | ||
274 | - } | ||
275 | -#ifdef _WIN32 | ||
276 | - cpu->hThread = qemu_thread_get_handle(cpu->thread); | ||
277 | -#endif | ||
278 | - } else { | ||
279 | - /* For non-MTTCG cases we share the thread */ | ||
280 | - cpu->thread = single_tcg_cpu_thread; | ||
281 | - cpu->halt_cond = single_tcg_halt_cond; | ||
282 | - cpu->thread_id = first_cpu->thread_id; | ||
283 | - cpu->can_do_io = 1; | ||
284 | - cpu->created = true; | ||
285 | - } | 27 | - } |
286 | -} | 28 | -} |
287 | - | 29 | - |
288 | void qemu_tcg_destroy_vcpu(CPUState *cpu) | 30 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ |
31 | void plugin_gen_disable_mem_helpers(void) | ||
289 | { | 32 | { |
290 | cpu_thread_signal_destroyed(cpu); | 33 | @@ -XXX,XX +XXX,XX @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, |
34 | ptb->mem_only = mem_only; | ||
35 | ptb->mem_helper = false; | ||
36 | |||
37 | - plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB); | ||
38 | + tcg_gen_plugin_cb(PLUGIN_GEN_FROM_TB); | ||
39 | } | ||
40 | |||
41 | tcg_ctx->plugin_insn = NULL; | ||
42 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) | ||
43 | insn->haddr = ptb->haddr2 + pc - ptb->vaddr2; | ||
44 | } | ||
45 | |||
46 | - plugin_gen_empty_callback(PLUGIN_GEN_FROM_INSN); | ||
47 | + tcg_gen_plugin_cb(PLUGIN_GEN_FROM_INSN); | ||
48 | } | ||
49 | |||
50 | void plugin_gen_insn_end(void) | ||
51 | { | ||
52 | - plugin_gen_empty_callback(PLUGIN_GEN_AFTER_INSN); | ||
53 | + tcg_gen_plugin_cb(PLUGIN_GEN_AFTER_INSN); | ||
54 | } | ||
55 | |||
56 | /* | ||
291 | -- | 57 | -- |
292 | 2.25.1 | 58 | 2.34.1 |
293 | 59 | ||
294 | 60 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | --- | ||
4 | accel/tcg/plugin-gen.c | 31 ++++--------------------------- | ||
5 | 1 file changed, 4 insertions(+), 27 deletions(-) | ||
1 | 6 | ||
7 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c | ||
8 | index XXXXXXX..XXXXXXX 100644 | ||
9 | --- a/accel/tcg/plugin-gen.c | ||
10 | +++ b/accel/tcg/plugin-gen.c | ||
11 | @@ -XXX,XX +XXX,XX @@ | ||
12 | * Injecting the desired instrumentation could be done with a second | ||
13 | * translation pass that combined the instrumentation requests, but that | ||
14 | * would be ugly and inefficient since we would decode the guest code twice. | ||
15 | - * Instead, during TB translation we add "empty" instrumentation calls for all | ||
16 | - * possible instrumentation events, and then once we collect the instrumentation | ||
17 | - * requests from plugins, we either "fill in" those empty events or remove them | ||
18 | - * if they have no requests. | ||
19 | - * | ||
20 | - * When "filling in" an event we first copy the empty callback's TCG ops. This | ||
21 | - * might seem unnecessary, but it is done to support an arbitrary number | ||
22 | - * of callbacks per event. Take for example a regular instruction callback. | ||
23 | - * We first generate a callback to an empty helper function. Then, if two | ||
24 | - * plugins register one callback each for this instruction, we make two copies | ||
25 | - * of the TCG ops generated for the empty callback, substituting the function | ||
26 | - * pointer that points to the empty helper function with the plugins' desired | ||
27 | - * callback functions. After that we remove the empty callback's ops. | ||
28 | - * | ||
29 | - * Note that the location in TCGOp.args[] of the pointer to a helper function | ||
30 | - * varies across different guest and host architectures. Instead of duplicating | ||
31 | - * the logic that figures this out, we rely on the fact that the empty | ||
32 | - * callbacks point to empty functions that are unique pointers in the program. | ||
33 | - * Thus, to find the right location we just have to look for a match in | ||
34 | - * TCGOp.args[]. This is the main reason why we first copy an empty callback's | ||
35 | - * TCG ops and then fill them in; regardless of whether we have one or many | ||
36 | - * callbacks for that event, the logic to add all of them is the same. | ||
37 | - * | ||
38 | - * When generating more than one callback per event, we make a small | ||
39 | - * optimization to avoid generating redundant operations. For instance, for the | ||
40 | - * second and all subsequent callbacks of an event, we do not need to reload the | ||
41 | - * CPU's index into a TCG temp, since the first callback did it already. | ||
42 | + * Instead, during TB translation we add "plugin_cb" marker opcodes | ||
43 | + * for all possible instrumentation events, and then once we collect the | ||
44 | + * instrumentation requests from plugins, we generate code for those markers | ||
45 | + * or remove them if they have no requests. | ||
46 | */ | ||
47 | #include "qemu/osdep.h" | ||
48 | #include "qemu/plugin.h" | ||
49 | -- | ||
50 | 2.34.1 | diff view generated by jsdifflib |