plugin and testing updates
- don't duplicate options for microbit test - don't spam the linux source tree when importing headers - add STORE_U64 inline op to TCG plugins - add conditional callback op to TCG plugins -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmZFvCMACgkQ+9DbCVqe KkSrYQf/aj9+eCWCKZk3Hym0lT+qNKxUeNSx3juUN8h7iG1vkA1f/XaQle5XvKDr ROIdo8urcr8onJ4PBH+4C7VZhUmnpL8zLH80pCuuTkF03MCNhaW/5qJ67niWmPVM QJHVqNomkykKOMBh+WtD5M0m/BYPT5lsa10sE3bDH8ziGjp0An2v24R89tzYEXnf 1QePItQN5vzEvhrZj6oKWVmeucqLsqS6yqS8V3sEpmF0+zqNjGZlrI86A4SAp74k 8vuduVuRbeyki7zWBTOLUeoiuHM2Zmh7v74zm/Hc1ITBaDjWMwPctcI/vFjsrCI/ yoFRhgrV87DtIZdkrJzk5qBYFOWoeQ== =znN0 -----END PGP SIGNATURE----- Merge tag 'pull-maintainer-may24-160524-2' of https://gitlab.com/stsquad/qemu into staging plugin and testing updates - don't duplicate options for microbit test - don't spam the linux source tree when importing headers - add STORE_U64 inline op to TCG plugins - add conditional callback op to TCG plugins # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmZFvCMACgkQ+9DbCVqe # KkSrYQf/aj9+eCWCKZk3Hym0lT+qNKxUeNSx3juUN8h7iG1vkA1f/XaQle5XvKDr # ROIdo8urcr8onJ4PBH+4C7VZhUmnpL8zLH80pCuuTkF03MCNhaW/5qJ67niWmPVM # QJHVqNomkykKOMBh+WtD5M0m/BYPT5lsa10sE3bDH8ziGjp0An2v24R89tzYEXnf # 1QePItQN5vzEvhrZj6oKWVmeucqLsqS6yqS8V3sEpmF0+zqNjGZlrI86A4SAp74k # 8vuduVuRbeyki7zWBTOLUeoiuHM2Zmh7v74zm/Hc1ITBaDjWMwPctcI/vFjsrCI/ # yoFRhgrV87DtIZdkrJzk5qBYFOWoeQ== # =znN0 # -----END PGP SIGNATURE----- # gpg: Signature made Thu 16 May 2024 09:56:19 AM CEST # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [full] * tag 'pull-maintainer-may24-160524-2' of https://gitlab.com/stsquad/qemu: plugins: remove op from qemu_plugin_inline_cb plugins: extract cpu_index generate plugins: distinct types for callbacks tests/plugin/inline: add test for conditional callback plugins: conditional callbacks tests/plugin/inline: add test for STORE_U64 inline op plugins: add new inline op STORE_U64 plugins: extract generate ptr for qemu_plugin_u64 plugins: prepare introduction of new inline ops scripts/update-linux-header.sh: be more src tree friendly tests/tcg: don't append QEMU_OPTS for armv6m-undef test Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
85ef20f167
@ -101,49 +101,111 @@ static void gen_disable_mem_helper(void)
|
||||
offsetof(ArchCPU, env));
|
||||
}
|
||||
|
||||
static void gen_udata_cb(struct qemu_plugin_dyn_cb *cb)
|
||||
static TCGv_i32 gen_cpu_index(void)
|
||||
{
|
||||
TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
|
||||
|
||||
tcg_gen_ld_i32(cpu_index, tcg_env,
|
||||
-offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
|
||||
tcg_gen_call2(cb->regular.f.vcpu_udata, cb->regular.info, NULL,
|
||||
return cpu_index;
|
||||
}
|
||||
|
||||
static void gen_udata_cb(struct qemu_plugin_regular_cb *cb)
|
||||
{
|
||||
TCGv_i32 cpu_index = gen_cpu_index();
|
||||
tcg_gen_call2(cb->f.vcpu_udata, cb->info, NULL,
|
||||
tcgv_i32_temp(cpu_index),
|
||||
tcgv_ptr_temp(tcg_constant_ptr(cb->userp)));
|
||||
tcg_temp_free_i32(cpu_index);
|
||||
}
|
||||
|
||||
static void gen_inline_cb(struct qemu_plugin_dyn_cb *cb)
|
||||
static TCGv_ptr gen_plugin_u64_ptr(qemu_plugin_u64 entry)
|
||||
{
|
||||
GArray *arr = cb->inline_insn.entry.score->data;
|
||||
size_t offset = cb->inline_insn.entry.offset;
|
||||
TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
|
||||
TCGv_i64 val = tcg_temp_ebb_new_i64();
|
||||
TCGv_ptr ptr = tcg_temp_ebb_new_ptr();
|
||||
|
||||
tcg_gen_ld_i32(cpu_index, tcg_env,
|
||||
-offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
|
||||
tcg_gen_muli_i32(cpu_index, cpu_index, g_array_get_element_size(arr));
|
||||
GArray *arr = entry.score->data;
|
||||
char *base_ptr = arr->data + entry.offset;
|
||||
size_t entry_size = g_array_get_element_size(arr);
|
||||
|
||||
TCGv_i32 cpu_index = gen_cpu_index();
|
||||
tcg_gen_muli_i32(cpu_index, cpu_index, entry_size);
|
||||
tcg_gen_ext_i32_ptr(ptr, cpu_index);
|
||||
tcg_temp_free_i32(cpu_index);
|
||||
tcg_gen_addi_ptr(ptr, ptr, (intptr_t) base_ptr);
|
||||
|
||||
tcg_gen_addi_ptr(ptr, ptr, (intptr_t)arr->data);
|
||||
tcg_gen_ld_i64(val, ptr, offset);
|
||||
tcg_gen_addi_i64(val, val, cb->inline_insn.imm);
|
||||
tcg_gen_st_i64(val, ptr, offset);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static TCGCond plugin_cond_to_tcgcond(enum qemu_plugin_cond cond)
|
||||
{
|
||||
switch (cond) {
|
||||
case QEMU_PLUGIN_COND_EQ:
|
||||
return TCG_COND_EQ;
|
||||
case QEMU_PLUGIN_COND_NE:
|
||||
return TCG_COND_NE;
|
||||
case QEMU_PLUGIN_COND_LT:
|
||||
return TCG_COND_LTU;
|
||||
case QEMU_PLUGIN_COND_LE:
|
||||
return TCG_COND_LEU;
|
||||
case QEMU_PLUGIN_COND_GT:
|
||||
return TCG_COND_GTU;
|
||||
case QEMU_PLUGIN_COND_GE:
|
||||
return TCG_COND_GEU;
|
||||
default:
|
||||
/* ALWAYS and NEVER conditions should never reach */
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
static void gen_udata_cond_cb(struct qemu_plugin_conditional_cb *cb)
|
||||
{
|
||||
TCGv_ptr ptr = gen_plugin_u64_ptr(cb->entry);
|
||||
TCGv_i64 val = tcg_temp_ebb_new_i64();
|
||||
TCGLabel *after_cb = gen_new_label();
|
||||
|
||||
/* Condition should be negated, as calling the cb is the "else" path */
|
||||
TCGCond cond = tcg_invert_cond(plugin_cond_to_tcgcond(cb->cond));
|
||||
|
||||
tcg_gen_ld_i64(val, ptr, 0);
|
||||
tcg_gen_brcondi_i64(cond, val, cb->imm, after_cb);
|
||||
TCGv_i32 cpu_index = gen_cpu_index();
|
||||
tcg_gen_call2(cb->f.vcpu_udata, cb->info, NULL,
|
||||
tcgv_i32_temp(cpu_index),
|
||||
tcgv_ptr_temp(tcg_constant_ptr(cb->userp)));
|
||||
tcg_temp_free_i32(cpu_index);
|
||||
gen_set_label(after_cb);
|
||||
|
||||
tcg_temp_free_i64(val);
|
||||
tcg_temp_free_ptr(ptr);
|
||||
}
|
||||
|
||||
static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb,
|
||||
static void gen_inline_add_u64_cb(struct qemu_plugin_inline_cb *cb)
|
||||
{
|
||||
TCGv_ptr ptr = gen_plugin_u64_ptr(cb->entry);
|
||||
TCGv_i64 val = tcg_temp_ebb_new_i64();
|
||||
|
||||
tcg_gen_ld_i64(val, ptr, 0);
|
||||
tcg_gen_addi_i64(val, val, cb->imm);
|
||||
tcg_gen_st_i64(val, ptr, 0);
|
||||
|
||||
tcg_temp_free_i64(val);
|
||||
tcg_temp_free_ptr(ptr);
|
||||
}
|
||||
|
||||
static void gen_inline_store_u64_cb(struct qemu_plugin_inline_cb *cb)
|
||||
{
|
||||
TCGv_ptr ptr = gen_plugin_u64_ptr(cb->entry);
|
||||
TCGv_i64 val = tcg_constant_i64(cb->imm);
|
||||
|
||||
tcg_gen_st_i64(val, ptr, 0);
|
||||
|
||||
tcg_temp_free_ptr(ptr);
|
||||
}
|
||||
|
||||
static void gen_mem_cb(struct qemu_plugin_regular_cb *cb,
|
||||
qemu_plugin_meminfo_t meminfo, TCGv_i64 addr)
|
||||
{
|
||||
TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
|
||||
|
||||
tcg_gen_ld_i32(cpu_index, tcg_env,
|
||||
-offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
|
||||
tcg_gen_call4(cb->regular.f.vcpu_mem, cb->regular.info, NULL,
|
||||
TCGv_i32 cpu_index = gen_cpu_index();
|
||||
tcg_gen_call4(cb->f.vcpu_mem, cb->info, NULL,
|
||||
tcgv_i32_temp(cpu_index),
|
||||
tcgv_i32_temp(tcg_constant_i32(meminfo)),
|
||||
tcgv_i64_temp(addr),
|
||||
@ -156,10 +218,16 @@ static void inject_cb(struct qemu_plugin_dyn_cb *cb)
|
||||
{
|
||||
switch (cb->type) {
|
||||
case PLUGIN_CB_REGULAR:
|
||||
gen_udata_cb(cb);
|
||||
gen_udata_cb(&cb->regular);
|
||||
break;
|
||||
case PLUGIN_CB_INLINE:
|
||||
gen_inline_cb(cb);
|
||||
case PLUGIN_CB_COND:
|
||||
gen_udata_cond_cb(&cb->cond);
|
||||
break;
|
||||
case PLUGIN_CB_INLINE_ADD_U64:
|
||||
gen_inline_add_u64_cb(&cb->inline_insn);
|
||||
break;
|
||||
case PLUGIN_CB_INLINE_STORE_U64:
|
||||
gen_inline_store_u64_cb(&cb->inline_insn);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
@ -170,15 +238,21 @@ static void inject_mem_cb(struct qemu_plugin_dyn_cb *cb,
|
||||
enum qemu_plugin_mem_rw rw,
|
||||
qemu_plugin_meminfo_t meminfo, TCGv_i64 addr)
|
||||
{
|
||||
if (cb->rw & rw) {
|
||||
switch (cb->type) {
|
||||
case PLUGIN_CB_MEM_REGULAR:
|
||||
gen_mem_cb(cb, meminfo, addr);
|
||||
break;
|
||||
default:
|
||||
inject_cb(cb);
|
||||
break;
|
||||
switch (cb->type) {
|
||||
case PLUGIN_CB_MEM_REGULAR:
|
||||
if (rw && cb->regular.rw) {
|
||||
gen_mem_cb(&cb->regular, meminfo, addr);
|
||||
}
|
||||
break;
|
||||
case PLUGIN_CB_INLINE_ADD_U64:
|
||||
case PLUGIN_CB_INLINE_STORE_U64:
|
||||
if (rw && cb->inline_insn.rw) {
|
||||
inject_cb(cb);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,32 @@ union qemu_plugin_cb_sig {
|
||||
|
||||
enum plugin_dyn_cb_type {
|
||||
PLUGIN_CB_REGULAR,
|
||||
PLUGIN_CB_COND,
|
||||
PLUGIN_CB_MEM_REGULAR,
|
||||
PLUGIN_CB_INLINE,
|
||||
PLUGIN_CB_INLINE_ADD_U64,
|
||||
PLUGIN_CB_INLINE_STORE_U64,
|
||||
};
|
||||
|
||||
struct qemu_plugin_regular_cb {
|
||||
union qemu_plugin_cb_sig f;
|
||||
TCGHelperInfo *info;
|
||||
void *userp;
|
||||
enum qemu_plugin_mem_rw rw;
|
||||
};
|
||||
|
||||
struct qemu_plugin_inline_cb {
|
||||
qemu_plugin_u64 entry;
|
||||
uint64_t imm;
|
||||
enum qemu_plugin_mem_rw rw;
|
||||
};
|
||||
|
||||
struct qemu_plugin_conditional_cb {
|
||||
union qemu_plugin_cb_sig f;
|
||||
TCGHelperInfo *info;
|
||||
void *userp;
|
||||
qemu_plugin_u64 entry;
|
||||
enum qemu_plugin_cond cond;
|
||||
uint64_t imm;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -78,21 +102,11 @@ enum plugin_dyn_cb_type {
|
||||
* instance of a callback to be called upon the execution of a particular TB.
|
||||
*/
|
||||
struct qemu_plugin_dyn_cb {
|
||||
void *userp;
|
||||
enum plugin_dyn_cb_type type;
|
||||
/* @rw applies to mem callbacks only (both regular and inline) */
|
||||
enum qemu_plugin_mem_rw rw;
|
||||
/* fields specific to each dyn_cb type go here */
|
||||
union {
|
||||
struct {
|
||||
union qemu_plugin_cb_sig f;
|
||||
TCGHelperInfo *info;
|
||||
} regular;
|
||||
struct {
|
||||
qemu_plugin_u64 entry;
|
||||
enum qemu_plugin_op op;
|
||||
uint64_t imm;
|
||||
} inline_insn;
|
||||
struct qemu_plugin_regular_cb regular;
|
||||
struct qemu_plugin_conditional_cb cond;
|
||||
struct qemu_plugin_inline_cb inline_insn;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -262,6 +262,29 @@ enum qemu_plugin_mem_rw {
|
||||
QEMU_PLUGIN_MEM_RW,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum qemu_plugin_cond - condition to enable callback
|
||||
*
|
||||
* @QEMU_PLUGIN_COND_NEVER: false
|
||||
* @QEMU_PLUGIN_COND_ALWAYS: true
|
||||
* @QEMU_PLUGIN_COND_EQ: is equal?
|
||||
* @QEMU_PLUGIN_COND_NE: is not equal?
|
||||
* @QEMU_PLUGIN_COND_LT: is less than?
|
||||
* @QEMU_PLUGIN_COND_LE: is less than or equal?
|
||||
* @QEMU_PLUGIN_COND_GT: is greater than?
|
||||
* @QEMU_PLUGIN_COND_GE: is greater than or equal?
|
||||
*/
|
||||
enum qemu_plugin_cond {
|
||||
QEMU_PLUGIN_COND_NEVER,
|
||||
QEMU_PLUGIN_COND_ALWAYS,
|
||||
QEMU_PLUGIN_COND_EQ,
|
||||
QEMU_PLUGIN_COND_NE,
|
||||
QEMU_PLUGIN_COND_LT,
|
||||
QEMU_PLUGIN_COND_LE,
|
||||
QEMU_PLUGIN_COND_GT,
|
||||
QEMU_PLUGIN_COND_GE,
|
||||
};
|
||||
|
||||
/**
|
||||
* typedef qemu_plugin_vcpu_tb_trans_cb_t - translation callback
|
||||
* @id: unique plugin id
|
||||
@ -301,16 +324,42 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* qemu_plugin_register_vcpu_tb_exec_cond_cb() - register conditional callback
|
||||
* @tb: the opaque qemu_plugin_tb handle for the translation
|
||||
* @cb: callback function
|
||||
* @cond: condition to enable callback
|
||||
* @entry: first operand for condition
|
||||
* @imm: second operand for condition
|
||||
* @flags: does the plugin read or write the CPU's registers?
|
||||
* @userdata: any plugin data to pass to the @cb?
|
||||
*
|
||||
* The @cb function is called when a translated unit executes if
|
||||
* entry @cond imm is true.
|
||||
* If condition is QEMU_PLUGIN_COND_ALWAYS, condition is never interpreted and
|
||||
* this function is equivalent to qemu_plugin_register_vcpu_tb_exec_cb.
|
||||
* If condition QEMU_PLUGIN_COND_NEVER, condition is never interpreted and
|
||||
* callback is never installed.
|
||||
*/
|
||||
QEMU_PLUGIN_API
|
||||
void qemu_plugin_register_vcpu_tb_exec_cond_cb(struct qemu_plugin_tb *tb,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* enum qemu_plugin_op - describes an inline op
|
||||
*
|
||||
* @QEMU_PLUGIN_INLINE_ADD_U64: add an immediate value uint64_t
|
||||
*
|
||||
* Note: currently only a single inline op is supported.
|
||||
* @QEMU_PLUGIN_INLINE_STORE_U64: store an immediate value uint64_t
|
||||
*/
|
||||
|
||||
enum qemu_plugin_op {
|
||||
QEMU_PLUGIN_INLINE_ADD_U64,
|
||||
QEMU_PLUGIN_INLINE_STORE_U64,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -344,6 +393,33 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* qemu_plugin_register_vcpu_insn_exec_cond_cb() - conditional insn execution cb
|
||||
* @insn: the opaque qemu_plugin_insn handle for an instruction
|
||||
* @cb: callback function
|
||||
* @flags: does the plugin read or write the CPU's registers?
|
||||
* @cond: condition to enable callback
|
||||
* @entry: first operand for condition
|
||||
* @imm: second operand for condition
|
||||
* @userdata: any plugin data to pass to the @cb?
|
||||
*
|
||||
* The @cb function is called when an instruction executes if
|
||||
* entry @cond imm is true.
|
||||
* If condition is QEMU_PLUGIN_COND_ALWAYS, condition is never interpreted and
|
||||
* this function is equivalent to qemu_plugin_register_vcpu_insn_exec_cb.
|
||||
* If condition QEMU_PLUGIN_COND_NEVER, condition is never interpreted and
|
||||
* callback is never installed.
|
||||
*/
|
||||
QEMU_PLUGIN_API
|
||||
void qemu_plugin_register_vcpu_insn_exec_cond_cb(
|
||||
struct qemu_plugin_insn *insn,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inline op
|
||||
* @insn: the opaque qemu_plugin_insn handle for an instruction
|
||||
|
@ -102,6 +102,25 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb,
|
||||
}
|
||||
}
|
||||
|
||||
void qemu_plugin_register_vcpu_tb_exec_cond_cb(struct qemu_plugin_tb *tb,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *udata)
|
||||
{
|
||||
if (cond == QEMU_PLUGIN_COND_NEVER || tb_is_mem_only()) {
|
||||
return;
|
||||
}
|
||||
if (cond == QEMU_PLUGIN_COND_ALWAYS) {
|
||||
qemu_plugin_register_vcpu_tb_exec_cb(tb, cb, flags, udata);
|
||||
return;
|
||||
}
|
||||
plugin_register_dyn_cond_cb__udata(&tb->cbs, cb, flags,
|
||||
cond, entry, imm, udata);
|
||||
}
|
||||
|
||||
void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
|
||||
struct qemu_plugin_tb *tb,
|
||||
enum qemu_plugin_op op,
|
||||
@ -123,6 +142,26 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn,
|
||||
}
|
||||
}
|
||||
|
||||
void qemu_plugin_register_vcpu_insn_exec_cond_cb(
|
||||
struct qemu_plugin_insn *insn,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *udata)
|
||||
{
|
||||
if (cond == QEMU_PLUGIN_COND_NEVER || tb_is_mem_only()) {
|
||||
return;
|
||||
}
|
||||
if (cond == QEMU_PLUGIN_COND_ALWAYS) {
|
||||
qemu_plugin_register_vcpu_insn_exec_cb(insn, cb, flags, udata);
|
||||
return;
|
||||
}
|
||||
plugin_register_dyn_cond_cb__udata(&insn->insn_cbs, cb, flags,
|
||||
cond, entry, imm, udata);
|
||||
}
|
||||
|
||||
void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
|
||||
struct qemu_plugin_insn *insn,
|
||||
enum qemu_plugin_op op,
|
||||
|
109
plugins/core.c
109
plugins/core.c
@ -316,6 +316,18 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr)
|
||||
return &g_array_index(cbs, struct qemu_plugin_dyn_cb, cbs->len - 1);
|
||||
}
|
||||
|
||||
static enum plugin_dyn_cb_type op_to_cb_type(enum qemu_plugin_op op)
|
||||
{
|
||||
switch (op) {
|
||||
case QEMU_PLUGIN_INLINE_ADD_U64:
|
||||
return PLUGIN_CB_INLINE_ADD_U64;
|
||||
case QEMU_PLUGIN_INLINE_STORE_U64:
|
||||
return PLUGIN_CB_INLINE_STORE_U64;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
void plugin_register_inline_op_on_entry(GArray **arr,
|
||||
enum qemu_plugin_mem_rw rw,
|
||||
enum qemu_plugin_op op,
|
||||
@ -324,13 +336,12 @@ void plugin_register_inline_op_on_entry(GArray **arr,
|
||||
{
|
||||
struct qemu_plugin_dyn_cb *dyn_cb;
|
||||
|
||||
struct qemu_plugin_inline_cb inline_cb = { .rw = rw,
|
||||
.entry = entry,
|
||||
.imm = imm };
|
||||
dyn_cb = plugin_get_dyn_cb(arr);
|
||||
dyn_cb->userp = NULL;
|
||||
dyn_cb->type = PLUGIN_CB_INLINE;
|
||||
dyn_cb->rw = rw;
|
||||
dyn_cb->inline_insn.entry = entry;
|
||||
dyn_cb->inline_insn.op = op;
|
||||
dyn_cb->inline_insn.imm = imm;
|
||||
dyn_cb->type = op_to_cb_type(op);
|
||||
dyn_cb->inline_insn = inline_cb;
|
||||
}
|
||||
|
||||
void plugin_register_dyn_cb__udata(GArray **arr,
|
||||
@ -349,14 +360,46 @@ void plugin_register_dyn_cb__udata(GArray **arr,
|
||||
dh_typemask(i32, 1) |
|
||||
dh_typemask(ptr, 2))
|
||||
};
|
||||
assert((unsigned)flags < ARRAY_SIZE(info));
|
||||
|
||||
struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr);
|
||||
dyn_cb->userp = udata;
|
||||
struct qemu_plugin_regular_cb regular_cb = { .f.vcpu_udata = cb,
|
||||
.userp = udata,
|
||||
.info = &info[flags] };
|
||||
dyn_cb->type = PLUGIN_CB_REGULAR;
|
||||
dyn_cb->regular.f.vcpu_udata = cb;
|
||||
dyn_cb->regular = regular_cb;
|
||||
}
|
||||
|
||||
void plugin_register_dyn_cond_cb__udata(GArray **arr,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *udata)
|
||||
{
|
||||
static TCGHelperInfo info[3] = {
|
||||
[QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG,
|
||||
[QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG,
|
||||
/*
|
||||
* Match qemu_plugin_vcpu_udata_cb_t:
|
||||
* void (*)(uint32_t, void *)
|
||||
*/
|
||||
[0 ... 2].typemask = (dh_typemask(void, 0) |
|
||||
dh_typemask(i32, 1) |
|
||||
dh_typemask(ptr, 2))
|
||||
};
|
||||
assert((unsigned)flags < ARRAY_SIZE(info));
|
||||
dyn_cb->regular.info = &info[flags];
|
||||
|
||||
struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr);
|
||||
struct qemu_plugin_conditional_cb cond_cb = { .userp = udata,
|
||||
.f.vcpu_udata = cb,
|
||||
.cond = cond,
|
||||
.entry = entry,
|
||||
.imm = imm,
|
||||
.info = &info[flags] };
|
||||
dyn_cb->type = PLUGIN_CB_COND;
|
||||
dyn_cb->cond = cond_cb;
|
||||
}
|
||||
|
||||
void plugin_register_vcpu_mem_cb(GArray **arr,
|
||||
@ -388,15 +431,15 @@ void plugin_register_vcpu_mem_cb(GArray **arr,
|
||||
dh_typemask(i64, 3) |
|
||||
dh_typemask(ptr, 4))
|
||||
};
|
||||
assert((unsigned)flags < ARRAY_SIZE(info));
|
||||
|
||||
struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr);
|
||||
dyn_cb->userp = udata;
|
||||
struct qemu_plugin_regular_cb regular_cb = { .userp = udata,
|
||||
.rw = rw,
|
||||
.f.vcpu_mem = cb,
|
||||
.info = &info[flags] };
|
||||
dyn_cb->type = PLUGIN_CB_MEM_REGULAR;
|
||||
dyn_cb->rw = rw;
|
||||
dyn_cb->regular.f.vcpu_mem = cb;
|
||||
|
||||
assert((unsigned)flags < ARRAY_SIZE(info));
|
||||
dyn_cb->regular.info = &info[flags];
|
||||
dyn_cb->regular = regular_cb;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -513,17 +556,22 @@ void qemu_plugin_flush_cb(void)
|
||||
plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH);
|
||||
}
|
||||
|
||||
void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index)
|
||||
void exec_inline_op(enum plugin_dyn_cb_type type,
|
||||
struct qemu_plugin_inline_cb *cb,
|
||||
int cpu_index)
|
||||
{
|
||||
char *ptr = cb->inline_insn.entry.score->data->data;
|
||||
char *ptr = cb->entry.score->data->data;
|
||||
size_t elem_size = g_array_get_element_size(
|
||||
cb->inline_insn.entry.score->data);
|
||||
size_t offset = cb->inline_insn.entry.offset;
|
||||
cb->entry.score->data);
|
||||
size_t offset = cb->entry.offset;
|
||||
uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size);
|
||||
|
||||
switch (cb->inline_insn.op) {
|
||||
case QEMU_PLUGIN_INLINE_ADD_U64:
|
||||
*val += cb->inline_insn.imm;
|
||||
switch (type) {
|
||||
case PLUGIN_CB_INLINE_ADD_U64:
|
||||
*val += cb->imm;
|
||||
break;
|
||||
case PLUGIN_CB_INLINE_STORE_U64:
|
||||
*val = cb->imm;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
@ -543,16 +591,19 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr,
|
||||
struct qemu_plugin_dyn_cb *cb =
|
||||
&g_array_index(arr, struct qemu_plugin_dyn_cb, i);
|
||||
|
||||
if (!(rw & cb->rw)) {
|
||||
break;
|
||||
}
|
||||
switch (cb->type) {
|
||||
case PLUGIN_CB_MEM_REGULAR:
|
||||
cb->regular.f.vcpu_mem(cpu->cpu_index, make_plugin_meminfo(oi, rw),
|
||||
vaddr, cb->userp);
|
||||
if (rw && cb->regular.rw) {
|
||||
cb->regular.f.vcpu_mem(cpu->cpu_index,
|
||||
make_plugin_meminfo(oi, rw),
|
||||
vaddr, cb->regular.userp);
|
||||
}
|
||||
break;
|
||||
case PLUGIN_CB_INLINE:
|
||||
exec_inline_op(cb, cpu->cpu_index);
|
||||
case PLUGIN_CB_INLINE_ADD_U64:
|
||||
case PLUGIN_CB_INLINE_STORE_U64:
|
||||
if (rw && cb->inline_insn.rw) {
|
||||
exec_inline_op(cb->type, &cb->inline_insn, cpu->cpu_index);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
|
@ -93,6 +93,14 @@ plugin_register_dyn_cb__udata(GArray **arr,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags, void *udata);
|
||||
|
||||
void
|
||||
plugin_register_dyn_cond_cb__udata(GArray **arr,
|
||||
qemu_plugin_vcpu_udata_cb_t cb,
|
||||
enum qemu_plugin_cb_flags flags,
|
||||
enum qemu_plugin_cond cond,
|
||||
qemu_plugin_u64 entry,
|
||||
uint64_t imm,
|
||||
void *udata);
|
||||
|
||||
void plugin_register_vcpu_mem_cb(GArray **arr,
|
||||
void *cb,
|
||||
@ -100,7 +108,9 @@ void plugin_register_vcpu_mem_cb(GArray **arr,
|
||||
enum qemu_plugin_mem_rw rw,
|
||||
void *udata);
|
||||
|
||||
void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index);
|
||||
void exec_inline_op(enum plugin_dyn_cb_type type,
|
||||
struct qemu_plugin_inline_cb *cb,
|
||||
int cpu_index);
|
||||
|
||||
int plugin_num_vcpus(void);
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
qemu_plugin_register_vcpu_idle_cb;
|
||||
qemu_plugin_register_vcpu_init_cb;
|
||||
qemu_plugin_register_vcpu_insn_exec_cb;
|
||||
qemu_plugin_register_vcpu_insn_exec_cond_cb;
|
||||
qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu;
|
||||
qemu_plugin_register_vcpu_mem_cb;
|
||||
qemu_plugin_register_vcpu_mem_inline_per_vcpu;
|
||||
@ -34,6 +35,7 @@
|
||||
qemu_plugin_register_vcpu_syscall_cb;
|
||||
qemu_plugin_register_vcpu_syscall_ret_cb;
|
||||
qemu_plugin_register_vcpu_tb_exec_cb;
|
||||
qemu_plugin_register_vcpu_tb_exec_cond_cb;
|
||||
qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu;
|
||||
qemu_plugin_register_vcpu_tb_trans_cb;
|
||||
qemu_plugin_reset;
|
||||
|
@ -27,6 +27,8 @@
|
||||
# types like "__u64". This work is done in the cp_portable function.
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
hdrdir="$tmpdir/headers"
|
||||
blddir="$tmpdir/build"
|
||||
linux="$1"
|
||||
output="$2"
|
||||
|
||||
@ -110,56 +112,56 @@ for arch in $ARCHLIST; do
|
||||
arch_var=ARCH
|
||||
fi
|
||||
|
||||
make -C "$linux" INSTALL_HDR_PATH="$tmpdir" $arch_var=$arch headers_install
|
||||
make -C "$linux" O="$blddir" INSTALL_HDR_PATH="$hdrdir" $arch_var=$arch headers_install
|
||||
|
||||
rm -rf "$output/linux-headers/asm-$arch"
|
||||
mkdir -p "$output/linux-headers/asm-$arch"
|
||||
for header in kvm.h unistd.h bitsperlong.h mman.h; do
|
||||
cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
|
||||
cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch"
|
||||
done
|
||||
|
||||
if [ $arch = mips ]; then
|
||||
cp "$tmpdir/include/asm/sgidefs.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$tmpdir/include/asm/unistd_o32.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$tmpdir/include/asm/unistd_n32.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$tmpdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$hdrdir/include/asm/sgidefs.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$hdrdir/include/asm/unistd_o32.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$hdrdir/include/asm/unistd_n32.h" "$output/linux-headers/asm-mips/"
|
||||
cp "$hdrdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/"
|
||||
fi
|
||||
if [ $arch = powerpc ]; then
|
||||
cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/"
|
||||
cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"
|
||||
cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/"
|
||||
cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"
|
||||
fi
|
||||
|
||||
rm -rf "$output/include/standard-headers/asm-$arch"
|
||||
mkdir -p "$output/include/standard-headers/asm-$arch"
|
||||
if [ $arch = s390 ]; then
|
||||
cp_portable "$tmpdir/include/asm/virtio-ccw.h" "$output/include/standard-headers/asm-s390/"
|
||||
cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-s390/"
|
||||
cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s390/"
|
||||
cp_portable "$hdrdir/include/asm/virtio-ccw.h" "$output/include/standard-headers/asm-s390/"
|
||||
cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-s390/"
|
||||
cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s390/"
|
||||
fi
|
||||
if [ $arch = arm ]; then
|
||||
cp "$tmpdir/include/asm/unistd-eabi.h" "$output/linux-headers/asm-arm/"
|
||||
cp "$tmpdir/include/asm/unistd-oabi.h" "$output/linux-headers/asm-arm/"
|
||||
cp "$tmpdir/include/asm/unistd-common.h" "$output/linux-headers/asm-arm/"
|
||||
cp "$hdrdir/include/asm/unistd-eabi.h" "$output/linux-headers/asm-arm/"
|
||||
cp "$hdrdir/include/asm/unistd-oabi.h" "$output/linux-headers/asm-arm/"
|
||||
cp "$hdrdir/include/asm/unistd-common.h" "$output/linux-headers/asm-arm/"
|
||||
fi
|
||||
if [ $arch = arm64 ]; then
|
||||
cp "$tmpdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/"
|
||||
cp "$hdrdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/"
|
||||
fi
|
||||
if [ $arch = x86 ]; then
|
||||
cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/"
|
||||
cp "$tmpdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/"
|
||||
cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/"
|
||||
cp_portable "$tmpdir/include/asm/kvm_para.h" "$output/include/standard-headers/asm-$arch"
|
||||
cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/"
|
||||
cp "$hdrdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/"
|
||||
cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/"
|
||||
cp_portable "$hdrdir/include/asm/kvm_para.h" "$output/include/standard-headers/asm-$arch"
|
||||
# Remove everything except the macros from bootparam.h avoiding the
|
||||
# unnecessary import of several video/ist/etc headers
|
||||
sed -e '/__ASSEMBLY__/,/__ASSEMBLY__/d' \
|
||||
"$tmpdir/include/asm/bootparam.h" > "$tmpdir/bootparam.h"
|
||||
cp_portable "$tmpdir/bootparam.h" \
|
||||
"$hdrdir/include/asm/bootparam.h" > "$hdrdir/bootparam.h"
|
||||
cp_portable "$hdrdir/bootparam.h" \
|
||||
"$output/include/standard-headers/asm-$arch"
|
||||
cp_portable "$tmpdir/include/asm/setup_data.h" \
|
||||
cp_portable "$hdrdir/include/asm/setup_data.h" \
|
||||
"$output/standard-headers/asm-x86"
|
||||
fi
|
||||
if [ $arch = riscv ]; then
|
||||
cp "$tmpdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/"
|
||||
cp "$hdrdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/"
|
||||
fi
|
||||
done
|
||||
arch=
|
||||
@ -169,13 +171,13 @@ mkdir -p "$output/linux-headers/linux"
|
||||
for header in const.h stddef.h kvm.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h \
|
||||
psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h \
|
||||
vduse.h iommufd.h bits.h; do
|
||||
cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
|
||||
cp "$hdrdir/include/linux/$header" "$output/linux-headers/linux"
|
||||
done
|
||||
|
||||
rm -rf "$output/linux-headers/asm-generic"
|
||||
mkdir -p "$output/linux-headers/asm-generic"
|
||||
for header in unistd.h bitsperlong.h mman-common.h mman.h hugetlb_encode.h; do
|
||||
cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
|
||||
cp "$hdrdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
|
||||
done
|
||||
|
||||
if [ -L "$linux/source" ]; then
|
||||
@ -210,23 +212,23 @@ EOF
|
||||
|
||||
rm -rf "$output/include/standard-headers/linux"
|
||||
mkdir -p "$output/include/standard-headers/linux"
|
||||
for i in "$tmpdir"/include/linux/*virtio*.h \
|
||||
"$tmpdir/include/linux/qemu_fw_cfg.h" \
|
||||
"$tmpdir/include/linux/fuse.h" \
|
||||
"$tmpdir/include/linux/input.h" \
|
||||
"$tmpdir/include/linux/input-event-codes.h" \
|
||||
"$tmpdir/include/linux/udmabuf.h" \
|
||||
"$tmpdir/include/linux/pci_regs.h" \
|
||||
"$tmpdir/include/linux/ethtool.h" \
|
||||
"$tmpdir/include/linux/const.h" \
|
||||
"$tmpdir/include/linux/kernel.h" \
|
||||
"$tmpdir/include/linux/vhost_types.h" \
|
||||
"$tmpdir/include/linux/sysinfo.h" \
|
||||
"$tmpdir/include/misc/pvpanic.h"; do
|
||||
for i in "$hdrdir"/include/linux/*virtio*.h \
|
||||
"$hdrdir/include/linux/qemu_fw_cfg.h" \
|
||||
"$hdrdir/include/linux/fuse.h" \
|
||||
"$hdrdir/include/linux/input.h" \
|
||||
"$hdrdir/include/linux/input-event-codes.h" \
|
||||
"$hdrdir/include/linux/udmabuf.h" \
|
||||
"$hdrdir/include/linux/pci_regs.h" \
|
||||
"$hdrdir/include/linux/ethtool.h" \
|
||||
"$hdrdir/include/linux/const.h" \
|
||||
"$hdrdir/include/linux/kernel.h" \
|
||||
"$hdrdir/include/linux/vhost_types.h" \
|
||||
"$hdrdir/include/linux/sysinfo.h" \
|
||||
"$hdrdir/include/misc/pvpanic.h"; do
|
||||
cp_portable "$i" "$output/include/standard-headers/linux"
|
||||
done
|
||||
mkdir -p "$output/include/standard-headers/drm"
|
||||
cp_portable "$tmpdir/include/drm/drm_fourcc.h" \
|
||||
cp_portable "$hdrdir/include/drm/drm_fourcc.h" \
|
||||
"$output/include/standard-headers/drm"
|
||||
|
||||
cat <<EOF >$output/include/standard-headers/linux/types.h
|
||||
|
@ -20,8 +20,20 @@ typedef struct {
|
||||
uint64_t count_insn_inline;
|
||||
uint64_t count_mem;
|
||||
uint64_t count_mem_inline;
|
||||
uint64_t tb_cond_num_trigger;
|
||||
uint64_t tb_cond_track_count;
|
||||
uint64_t insn_cond_num_trigger;
|
||||
uint64_t insn_cond_track_count;
|
||||
} CPUCount;
|
||||
|
||||
static const uint64_t cond_trigger_limit = 100;
|
||||
|
||||
typedef struct {
|
||||
uint64_t data_insn;
|
||||
uint64_t data_tb;
|
||||
uint64_t data_mem;
|
||||
} CPUData;
|
||||
|
||||
static struct qemu_plugin_scoreboard *counts;
|
||||
static qemu_plugin_u64 count_tb;
|
||||
static qemu_plugin_u64 count_tb_inline;
|
||||
@ -29,6 +41,14 @@ static qemu_plugin_u64 count_insn;
|
||||
static qemu_plugin_u64 count_insn_inline;
|
||||
static qemu_plugin_u64 count_mem;
|
||||
static qemu_plugin_u64 count_mem_inline;
|
||||
static qemu_plugin_u64 tb_cond_num_trigger;
|
||||
static qemu_plugin_u64 tb_cond_track_count;
|
||||
static qemu_plugin_u64 insn_cond_num_trigger;
|
||||
static qemu_plugin_u64 insn_cond_track_count;
|
||||
static struct qemu_plugin_scoreboard *data;
|
||||
static qemu_plugin_u64 data_insn;
|
||||
static qemu_plugin_u64 data_tb;
|
||||
static qemu_plugin_u64 data_mem;
|
||||
|
||||
static uint64_t global_count_tb;
|
||||
static uint64_t global_count_insn;
|
||||
@ -46,12 +66,19 @@ static void stats_insn(void)
|
||||
const uint64_t per_vcpu = qemu_plugin_u64_sum(count_insn);
|
||||
const uint64_t inl_per_vcpu =
|
||||
qemu_plugin_u64_sum(count_insn_inline);
|
||||
const uint64_t cond_num_trigger =
|
||||
qemu_plugin_u64_sum(insn_cond_num_trigger);
|
||||
const uint64_t cond_track_left = qemu_plugin_u64_sum(insn_cond_track_count);
|
||||
const uint64_t conditional =
|
||||
cond_num_trigger * cond_trigger_limit + cond_track_left;
|
||||
printf("insn: %" PRIu64 "\n", expected);
|
||||
printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu);
|
||||
printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
|
||||
printf("insn: %" PRIu64 " (cond cb)\n", conditional);
|
||||
g_assert(expected > 0);
|
||||
g_assert(per_vcpu == expected);
|
||||
g_assert(inl_per_vcpu == expected);
|
||||
g_assert(conditional == expected);
|
||||
}
|
||||
|
||||
static void stats_tb(void)
|
||||
@ -60,12 +87,18 @@ static void stats_tb(void)
|
||||
const uint64_t per_vcpu = qemu_plugin_u64_sum(count_tb);
|
||||
const uint64_t inl_per_vcpu =
|
||||
qemu_plugin_u64_sum(count_tb_inline);
|
||||
const uint64_t cond_num_trigger = qemu_plugin_u64_sum(tb_cond_num_trigger);
|
||||
const uint64_t cond_track_left = qemu_plugin_u64_sum(tb_cond_track_count);
|
||||
const uint64_t conditional =
|
||||
cond_num_trigger * cond_trigger_limit + cond_track_left;
|
||||
printf("tb: %" PRIu64 "\n", expected);
|
||||
printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu);
|
||||
printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
|
||||
printf("tb: %" PRIu64 " (conditional cb)\n", conditional);
|
||||
g_assert(expected > 0);
|
||||
g_assert(per_vcpu == expected);
|
||||
g_assert(inl_per_vcpu == expected);
|
||||
g_assert(conditional == expected);
|
||||
}
|
||||
|
||||
static void stats_mem(void)
|
||||
@ -94,14 +127,35 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata)
|
||||
const uint64_t insn_inline = qemu_plugin_u64_get(count_insn_inline, i);
|
||||
const uint64_t mem = qemu_plugin_u64_get(count_mem, i);
|
||||
const uint64_t mem_inline = qemu_plugin_u64_get(count_mem_inline, i);
|
||||
printf("cpu %d: tb (%" PRIu64 ", %" PRIu64 ") | "
|
||||
"insn (%" PRIu64 ", %" PRIu64 ") | "
|
||||
const uint64_t tb_cond_trigger =
|
||||
qemu_plugin_u64_get(tb_cond_num_trigger, i);
|
||||
const uint64_t tb_cond_left =
|
||||
qemu_plugin_u64_get(tb_cond_track_count, i);
|
||||
const uint64_t insn_cond_trigger =
|
||||
qemu_plugin_u64_get(insn_cond_num_trigger, i);
|
||||
const uint64_t insn_cond_left =
|
||||
qemu_plugin_u64_get(insn_cond_track_count, i);
|
||||
printf("cpu %d: tb (%" PRIu64 ", %" PRIu64
|
||||
", %" PRIu64 " * %" PRIu64 " + %" PRIu64
|
||||
") | "
|
||||
"insn (%" PRIu64 ", %" PRIu64
|
||||
", %" PRIu64 " * %" PRIu64 " + %" PRIu64
|
||||
") | "
|
||||
"mem (%" PRIu64 ", %" PRIu64 ")"
|
||||
"\n",
|
||||
i, tb, tb_inline, insn, insn_inline, mem, mem_inline);
|
||||
i,
|
||||
tb, tb_inline,
|
||||
tb_cond_trigger, cond_trigger_limit, tb_cond_left,
|
||||
insn, insn_inline,
|
||||
insn_cond_trigger, cond_trigger_limit, insn_cond_left,
|
||||
mem, mem_inline);
|
||||
g_assert(tb == tb_inline);
|
||||
g_assert(insn == insn_inline);
|
||||
g_assert(mem == mem_inline);
|
||||
g_assert(tb_cond_trigger == tb / cond_trigger_limit);
|
||||
g_assert(tb_cond_left == tb % cond_trigger_limit);
|
||||
g_assert(insn_cond_trigger == insn / cond_trigger_limit);
|
||||
g_assert(insn_cond_left == insn % cond_trigger_limit);
|
||||
}
|
||||
|
||||
stats_tb();
|
||||
@ -109,20 +163,41 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata)
|
||||
stats_mem();
|
||||
|
||||
qemu_plugin_scoreboard_free(counts);
|
||||
qemu_plugin_scoreboard_free(data);
|
||||
}
|
||||
|
||||
static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
|
||||
{
|
||||
qemu_plugin_u64_add(count_tb, cpu_index, 1);
|
||||
g_assert(qemu_plugin_u64_get(data_tb, cpu_index) == (uintptr_t) udata);
|
||||
g_mutex_lock(&tb_lock);
|
||||
max_cpu_index = MAX(max_cpu_index, cpu_index);
|
||||
global_count_tb++;
|
||||
g_mutex_unlock(&tb_lock);
|
||||
}
|
||||
|
||||
static void vcpu_tb_cond_exec(unsigned int cpu_index, void *udata)
|
||||
{
|
||||
g_assert(qemu_plugin_u64_get(tb_cond_track_count, cpu_index) ==
|
||||
cond_trigger_limit);
|
||||
g_assert(qemu_plugin_u64_get(data_tb, cpu_index) == (uintptr_t) udata);
|
||||
qemu_plugin_u64_set(tb_cond_track_count, cpu_index, 0);
|
||||
qemu_plugin_u64_add(tb_cond_num_trigger, cpu_index, 1);
|
||||
}
|
||||
|
||||
static void vcpu_insn_cond_exec(unsigned int cpu_index, void *udata)
|
||||
{
|
||||
g_assert(qemu_plugin_u64_get(insn_cond_track_count, cpu_index) ==
|
||||
cond_trigger_limit);
|
||||
g_assert(qemu_plugin_u64_get(data_insn, cpu_index) == (uintptr_t) udata);
|
||||
qemu_plugin_u64_set(insn_cond_track_count, cpu_index, 0);
|
||||
qemu_plugin_u64_add(insn_cond_num_trigger, cpu_index, 1);
|
||||
}
|
||||
|
||||
static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
|
||||
{
|
||||
qemu_plugin_u64_add(count_insn, cpu_index, 1);
|
||||
g_assert(qemu_plugin_u64_get(data_insn, cpu_index) == (uintptr_t) udata);
|
||||
g_mutex_lock(&insn_lock);
|
||||
global_count_insn++;
|
||||
g_mutex_unlock(&insn_lock);
|
||||
@ -131,9 +206,10 @@ static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
|
||||
static void vcpu_mem_access(unsigned int cpu_index,
|
||||
qemu_plugin_meminfo_t info,
|
||||
uint64_t vaddr,
|
||||
void *userdata)
|
||||
void *udata)
|
||||
{
|
||||
qemu_plugin_u64_add(count_mem, cpu_index, 1);
|
||||
g_assert(qemu_plugin_u64_get(data_mem, cpu_index) == (uintptr_t) udata);
|
||||
g_mutex_lock(&mem_lock);
|
||||
global_count_mem++;
|
||||
g_mutex_unlock(&mem_lock);
|
||||
@ -141,20 +217,47 @@ static void vcpu_mem_access(unsigned int cpu_index,
|
||||
|
||||
static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
|
||||
{
|
||||
void *tb_store = tb;
|
||||
qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
|
||||
tb, QEMU_PLUGIN_INLINE_STORE_U64, data_tb, (uintptr_t) tb_store);
|
||||
qemu_plugin_register_vcpu_tb_exec_cb(
|
||||
tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, 0);
|
||||
tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, tb_store);
|
||||
qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
|
||||
tb, QEMU_PLUGIN_INLINE_ADD_U64, count_tb_inline, 1);
|
||||
|
||||
qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
|
||||
tb, QEMU_PLUGIN_INLINE_ADD_U64, tb_cond_track_count, 1);
|
||||
qemu_plugin_register_vcpu_tb_exec_cond_cb(
|
||||
tb, vcpu_tb_cond_exec, QEMU_PLUGIN_CB_NO_REGS,
|
||||
QEMU_PLUGIN_COND_EQ, tb_cond_track_count, cond_trigger_limit, tb_store);
|
||||
|
||||
for (int idx = 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) {
|
||||
struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, idx);
|
||||
void *insn_store = insn;
|
||||
void *mem_store = (char *)insn_store + 0xff;
|
||||
|
||||
qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
|
||||
insn, QEMU_PLUGIN_INLINE_STORE_U64, data_insn,
|
||||
(uintptr_t) insn_store);
|
||||
qemu_plugin_register_vcpu_insn_exec_cb(
|
||||
insn, vcpu_insn_exec, QEMU_PLUGIN_CB_NO_REGS, 0);
|
||||
insn, vcpu_insn_exec, QEMU_PLUGIN_CB_NO_REGS, insn_store);
|
||||
qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
|
||||
insn, QEMU_PLUGIN_INLINE_ADD_U64, count_insn_inline, 1);
|
||||
|
||||
qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
|
||||
insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_cond_track_count, 1);
|
||||
qemu_plugin_register_vcpu_insn_exec_cond_cb(
|
||||
insn, vcpu_insn_cond_exec, QEMU_PLUGIN_CB_NO_REGS,
|
||||
QEMU_PLUGIN_COND_EQ, insn_cond_track_count, cond_trigger_limit,
|
||||
insn_store);
|
||||
|
||||
qemu_plugin_register_vcpu_mem_inline_per_vcpu(
|
||||
insn, QEMU_PLUGIN_MEM_RW,
|
||||
QEMU_PLUGIN_INLINE_STORE_U64,
|
||||
data_mem, (uintptr_t) mem_store);
|
||||
qemu_plugin_register_vcpu_mem_cb(insn, &vcpu_mem_access,
|
||||
QEMU_PLUGIN_CB_NO_REGS,
|
||||
QEMU_PLUGIN_MEM_RW, 0);
|
||||
QEMU_PLUGIN_MEM_RW, mem_store);
|
||||
qemu_plugin_register_vcpu_mem_inline_per_vcpu(
|
||||
insn, QEMU_PLUGIN_MEM_RW,
|
||||
QEMU_PLUGIN_INLINE_ADD_U64,
|
||||
@ -179,6 +282,19 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
|
||||
counts, CPUCount, count_insn_inline);
|
||||
count_mem_inline = qemu_plugin_scoreboard_u64_in_struct(
|
||||
counts, CPUCount, count_mem_inline);
|
||||
tb_cond_num_trigger = qemu_plugin_scoreboard_u64_in_struct(
|
||||
counts, CPUCount, tb_cond_num_trigger);
|
||||
tb_cond_track_count = qemu_plugin_scoreboard_u64_in_struct(
|
||||
counts, CPUCount, tb_cond_track_count);
|
||||
insn_cond_num_trigger = qemu_plugin_scoreboard_u64_in_struct(
|
||||
counts, CPUCount, insn_cond_num_trigger);
|
||||
insn_cond_track_count = qemu_plugin_scoreboard_u64_in_struct(
|
||||
counts, CPUCount, insn_cond_track_count);
|
||||
data = qemu_plugin_scoreboard_new(sizeof(CPUData));
|
||||
data_insn = qemu_plugin_scoreboard_u64_in_struct(data, CPUData, data_insn);
|
||||
data_tb = qemu_plugin_scoreboard_u64_in_struct(data, CPUData, data_tb);
|
||||
data_mem = qemu_plugin_scoreboard_u64_in_struct(data, CPUData, data_mem);
|
||||
|
||||
qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
|
||||
qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
|
||||
|
||||
|
@ -16,7 +16,7 @@ test-armv6m-undef: test-armv6m-undef.S
|
||||
$< -o $@ -nostdlib -N -static \
|
||||
-T $(ARM_SRC)/$@.ld
|
||||
|
||||
run-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel
|
||||
run-test-armv6m-undef: QEMU_OPTS=-semihosting-config enable=on,target=native,chardev=output -M microbit -kernel
|
||||
|
||||
ARM_TESTS+=test-armv6m-undef
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user