Skip to content

Commit 2fb2aa0

Browse files
pbo-linarostsquad
authored andcommitted
contrib/plugins/hotblocks: fix 32-bit build
Signed-off-by: Pierrick Bouvier <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent aa47f44 commit 2fb2aa0

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

contrib/plugins/hotblocks.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static guint64 limit = 20;
2929
*
3030
* The internals of the TCG are not exposed to plugins so we can only
3131
* get the starting PC for each block. We cheat this slightly by
32-
* xor'ing the number of instructions to the hash to help
32+
* checking the number of instructions as well to help
3333
* differentiate.
3434
*/
3535
typedef struct {
@@ -50,6 +50,20 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)
5050
return count_a > count_b ? -1 : 1;
5151
}
5252

53+
static guint exec_count_hash(gconstpointer v)
54+
{
55+
const ExecCount *e = v;
56+
return e->start_addr ^ e->insns;
57+
}
58+
59+
static gboolean exec_count_equal(gconstpointer v1, gconstpointer v2)
60+
{
61+
const ExecCount *ea = v1;
62+
const ExecCount *eb = v2;
63+
return (ea->start_addr == eb->start_addr) &&
64+
(ea->insns == eb->insns);
65+
}
66+
5367
static void exec_count_free(gpointer key, gpointer value, gpointer user_data)
5468
{
5569
ExecCount *cnt = value;
@@ -91,7 +105,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
91105

92106
static void plugin_init(void)
93107
{
94-
hotblocks = g_hash_table_new(NULL, g_direct_equal);
108+
hotblocks = g_hash_table_new(exec_count_hash, exec_count_equal);
95109
}
96110

97111
static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
@@ -111,10 +125,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
111125
ExecCount *cnt;
112126
uint64_t pc = qemu_plugin_tb_vaddr(tb);
113127
size_t insns = qemu_plugin_tb_n_insns(tb);
114-
uint64_t hash = pc ^ insns;
115128

116129
g_mutex_lock(&lock);
117-
cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash);
130+
{
131+
ExecCount e;
132+
e.start_addr = pc;
133+
e.insns = insns;
134+
cnt = (ExecCount *) g_hash_table_lookup(hotblocks, &e);
135+
}
136+
118137
if (cnt) {
119138
cnt->trans_count++;
120139
} else {
@@ -123,7 +142,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
123142
cnt->trans_count = 1;
124143
cnt->insns = insns;
125144
cnt->exec_count = qemu_plugin_scoreboard_new(sizeof(uint64_t));
126-
g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt);
145+
g_hash_table_insert(hotblocks, cnt, cnt);
127146
}
128147

129148
g_mutex_unlock(&lock);

0 commit comments

Comments
 (0)