@samitouri / QOSamiQemu / commits / fdff1c864a

plugins/execlog: fix execlog vcpu_exit execution print loss

Executed instructions are cached in string format inside the execlog plugin. These strings are flushed on exit of a TB, improving performance. This causes executed instructions to be lost when an 'ecall' (riscv system call) occurs that causes the thread to terminate. The fix in this patch registers a 'vcpu_exit' callback, and flushes any content in the c->last_exec buffer, to ensure all instructions are present in the final instruction log. Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Tested-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Harry van Haaren <harry.vanhaaren@openchip.com> Link: https://lore.kernel.org/qemu-devel/20260716094126.787556-3-harry.vanhaaren@openchip.com Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>

Harry van Haaren committed Jul 16, 2026 at 09:41 UTC fdff1c864aaab3c2458c2d6802a5cfe9dfcbdff4
1 file changed +20
contrib/plugins/execlog.c
+20
@@ -380,6 +380,25 @@ static void vcpu_init(unsigned int vcpu_index, void *userdata)
380 c->registers = registers_init(vcpu_index);
381 }
382
383 +/**
384 + * On vCPU exit, flush the last cached instruction for this vCPU.
385 + *
386 + * The one-instruction-delay pattern stores each instruction in last_exec and
387 + * only prints it when the *next* callback fires. When a thread exits via
388 + * syscall (e.g. ecall/exit), no subsequent callback fires for that vCPU and
389 + * the final instruction is silently dropped. Flushing here guarantees it is
390 + * written before the vCPU is torn down.
391 + */
392 +static void vcpu_exit(unsigned int vcpu_index, void *udata)
393 +{
394 + CPU *c = qemu_plugin_scoreboard_find(cpus, vcpu_index);
395 + if (c->last_exec && c->last_exec->len) {
396 + g_string_append_c(c->last_exec, '\n');
397 + qemu_plugin_outs(c->last_exec->str);
398 + g_string_truncate(c->last_exec, 0);
399 + }
400 +}
401 +
402 /**
403 * On plugin exit, flush any remaining cached instructions and free state.
404 */
@@ -461,6 +480,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
480 /* Register init, translation block and exit callbacks */
481 qemu_plugin_register_vcpu_init_cb(id, vcpu_init, NULL);
482 qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans, NULL);
483 + qemu_plugin_register_vcpu_exit_cb(id, vcpu_exit, NULL);
484 qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
485
486 return 0;