Skip to content

Commit 91416a4

Browse files
committed
Merge remote-tracking branch 'remotes/stsquad/tags/pull-plugin-updates-180221-1' into staging
Plugin updates: - expose vdev name in PCI memory registration - new hwprofile plugin - bunch of style cleanups to contrib/plugins - fix call signature of inline instrumentation - re-factor the io_recompile code to push specialisation into hooks - add some acceptance tests for the plugins - clean-up and remove CF_NOCACHE handling from TCG - fix instrumentation of cpu_io_recompile sections - expand tests to check inline and cb count the same # gpg: Signature made Thu 18 Feb 2021 08:24:57 GMT # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <[email protected]>" [full] # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * remotes/stsquad/tags/pull-plugin-updates-180221-1: (23 commits) tests/acceptance: add a memory callback check tests/plugin: allow memory plugin to do both inline and callbacks tests/acceptance: add a new tests to detect counting errors accel/tcg: allow plugin instrumentation to be disable via cflags accel/tcg: remove CF_NOCACHE and special cases accel/tcg: re-factor non-RAM execution code accel/tcg: cache single instruction TB on pending replay exception accel/tcg: actually cache our partial icount TB tests/acceptance: add a new set of tests to exercise plugins tests/plugin: expand insn test to detect duplicate instructions target/sh4: Create superh_io_recompile_replay_branch target/mips: Create mips_io_recompile_replay_branch accel/tcg: Create io_recompile_replay_branch hook exec: Move TranslationBlock typedef to qemu/typedefs.h accel/tcg/plugin-gen: fix the call signature for inline callbacks contrib: Open brace '{' following struct go on the same line contrib: space required after that ',' contrib: Add spaces around operator contrib: Fix some code style problems, ERROR: "foo * bar" should be "foo *bar" contrib: Don't use '#' flag of printf format ... Signed-off-by: Peter Maydell <[email protected]>
2 parents 1af5629 + df55e2a commit 91416a4

36 files changed

+769
-215
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,7 @@ S: Maintained
29032903
F: docs/devel/tcg-plugins.rst
29042904
F: plugins/
29052905
F: tests/plugin/
2906+
F: tests/acceptance/tcg_plugins.py
29062907
F: contrib/plugins/
29072908

29082909
AArch64 TCG target

accel/tcg/cpu-exec.c

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -224,40 +224,6 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
224224
return last_tb;
225225
}
226226

227-
#ifndef CONFIG_USER_ONLY
228-
/* Execute the code without caching the generated code. An interpreter
229-
could be used if available. */
230-
static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
231-
TranslationBlock *orig_tb, bool ignore_icount)
232-
{
233-
TranslationBlock *tb;
234-
uint32_t cflags = curr_cflags() | CF_NOCACHE;
235-
int tb_exit;
236-
237-
if (ignore_icount) {
238-
cflags &= ~CF_USE_ICOUNT;
239-
}
240-
241-
/* Should never happen.
242-
We only end up here when an existing TB is too long. */
243-
cflags |= MIN(max_cycles, CF_COUNT_MASK);
244-
245-
mmap_lock();
246-
tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base,
247-
orig_tb->flags, cflags);
248-
tb->orig_tb = orig_tb;
249-
mmap_unlock();
250-
251-
/* execute the generated code */
252-
trace_exec_tb_nocache(tb, tb->pc);
253-
cpu_tb_exec(cpu, tb, &tb_exit);
254-
255-
mmap_lock();
256-
tb_phys_invalidate(tb, -1);
257-
mmap_unlock();
258-
tcg_tb_remove(tb);
259-
}
260-
#endif
261227

262228
static void cpu_exec_enter(CPUState *cpu)
263229
{
@@ -524,15 +490,12 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
524490
#ifndef CONFIG_USER_ONLY
525491
if (replay_has_exception()
526492
&& cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) {
527-
/* try to cause an exception pending in the log */
528-
cpu_exec_nocache(cpu, 1, tb_find(cpu, NULL, 0, curr_cflags()), true);
493+
/* Execute just one insn to trigger exception pending in the log */
494+
cpu->cflags_next_tb = (curr_cflags() & ~CF_USE_ICOUNT) | 1;
529495
}
530496
#endif
531-
if (cpu->exception_index < 0) {
532-
return false;
533-
}
497+
return false;
534498
}
535-
536499
if (cpu->exception_index >= EXCP_INTERRUPT) {
537500
/* exit request from the cpu execution loop */
538501
*ret = cpu->exception_index;
@@ -688,6 +651,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
688651
/* Finally, check if we need to exit to the main loop. */
689652
if (unlikely(qatomic_read(&cpu->exit_request))
690653
|| (icount_enabled()
654+
&& (cpu->cflags_next_tb == -1 || cpu->cflags_next_tb & CF_USE_ICOUNT)
691655
&& cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0)) {
692656
qatomic_set(&cpu->exit_request, 0);
693657
if (cpu->exception_index == -1) {
@@ -730,16 +694,17 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
730694
/* Ensure global icount has gone forward */
731695
icount_update(cpu);
732696
/* Refill decrementer and continue execution. */
733-
insns_left = MIN(0xffff, cpu->icount_budget);
697+
insns_left = MIN(CF_COUNT_MASK, cpu->icount_budget);
734698
cpu_neg(cpu)->icount_decr.u16.low = insns_left;
735699
cpu->icount_extra = cpu->icount_budget - insns_left;
736-
if (!cpu->icount_extra && insns_left < tb->icount) {
737-
/* Execute any remaining instructions, then let the main loop
738-
* handle the next event.
739-
*/
740-
if (insns_left > 0) {
741-
cpu_exec_nocache(cpu, insns_left, tb, false);
742-
}
700+
701+
/*
702+
* If the next tb has more instructions than we have left to
703+
* execute we need to ensure we find/generate a TB with exactly
704+
* insns_left instructions in it.
705+
*/
706+
if (!cpu->icount_extra && insns_left > 0 && insns_left < tb->icount) {
707+
cpu->cflags_next_tb = (tb->cflags & ~CF_COUNT_MASK) | insns_left;
743708
}
744709
#endif
745710
}

accel/tcg/plugin-gen.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,6 @@ static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr)
320320
return op;
321321
}
322322

323-
static TCGOp *copy_const_i64(TCGOp **begin_op, TCGOp *op, uint64_t v)
324-
{
325-
if (TCG_TARGET_REG_BITS == 32) {
326-
/* 2x mov_i32 */
327-
op = copy_op(begin_op, op, INDEX_op_mov_i32);
328-
op->args[1] = tcgv_i32_arg(tcg_constant_i32(v));
329-
op = copy_op(begin_op, op, INDEX_op_mov_i32);
330-
op->args[1] = tcgv_i32_arg(tcg_constant_i32(v >> 32));
331-
} else {
332-
/* mov_i64 */
333-
op = copy_op(begin_op, op, INDEX_op_mov_i64);
334-
op->args[1] = tcgv_i64_arg(tcg_constant_i64(v));
335-
}
336-
return op;
337-
}
338-
339323
static TCGOp *copy_extu_tl_i64(TCGOp **begin_op, TCGOp *op)
340324
{
341325
if (TARGET_LONG_BITS == 32) {
@@ -374,14 +358,17 @@ static TCGOp *copy_st_i64(TCGOp **begin_op, TCGOp *op)
374358
return op;
375359
}
376360

377-
static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op)
361+
static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op, uint64_t v)
378362
{
379363
if (TCG_TARGET_REG_BITS == 32) {
380364
/* all 32-bit backends must implement add2_i32 */
381365
g_assert(TCG_TARGET_HAS_add2_i32);
382366
op = copy_op(begin_op, op, INDEX_op_add2_i32);
367+
op->args[4] = tcgv_i32_arg(tcg_constant_i32(v));
368+
op->args[5] = tcgv_i32_arg(tcg_constant_i32(v >> 32));
383369
} else {
384370
op = copy_op(begin_op, op, INDEX_op_add_i64);
371+
op->args[2] = tcgv_i64_arg(tcg_constant_i64(v));
385372
}
386373
return op;
387374
}
@@ -431,6 +418,12 @@ static TCGOp *copy_call(TCGOp **begin_op, TCGOp *op, void *empty_func,
431418
return op;
432419
}
433420

421+
/*
422+
* When we append/replace ops here we are sensitive to changing patterns of
423+
* TCGOps generated by the tcg_gen_FOO calls when we generated the
424+
* empty callbacks. This will assert very quickly in a debug build as
425+
* we assert the ops we are replacing are the correct ones.
426+
*/
434427
static TCGOp *append_udata_cb(const struct qemu_plugin_dyn_cb *cb,
435428
TCGOp *begin_op, TCGOp *op, int *cb_idx)
436429
{
@@ -462,11 +455,8 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb,
462455
/* ld_i64 */
463456
op = copy_ld_i64(&begin_op, op);
464457

465-
/* const_i64 */
466-
op = copy_const_i64(&begin_op, op, cb->inline_insn.imm);
467-
468458
/* add_i64 */
469-
op = copy_add_i64(&begin_op, op);
459+
op = copy_add_i64(&begin_op, op, cb->inline_insn.imm);
470460

471461
/* st_i64 */
472462
op = copy_st_i64(&begin_op, op);
@@ -852,7 +842,7 @@ static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb)
852842
pr_ops();
853843
}
854844

855-
bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb)
845+
bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool mem_only)
856846
{
857847
struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb;
858848
bool ret = false;
@@ -865,6 +855,7 @@ bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb)
865855
ptb->vaddr2 = -1;
866856
get_page_addr_code_hostp(cpu->env_ptr, tb->pc, &ptb->haddr1);
867857
ptb->haddr2 = NULL;
858+
ptb->mem_only = mem_only;
868859

869860
plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB);
870861
}

0 commit comments

Comments
 (0)