@@ -29,7 +29,7 @@ static guint64 limit = 20;
29
29
*
30
30
* The internals of the TCG are not exposed to plugins so we can only
31
31
* 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
33
33
* differentiate.
34
34
*/
35
35
typedef struct {
@@ -50,6 +50,20 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)
50
50
return count_a > count_b ? -1 : 1 ;
51
51
}
52
52
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
+
53
67
static void exec_count_free (gpointer key , gpointer value , gpointer user_data )
54
68
{
55
69
ExecCount * cnt = value ;
@@ -91,7 +105,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
91
105
92
106
static void plugin_init (void )
93
107
{
94
- hotblocks = g_hash_table_new (NULL , g_direct_equal );
108
+ hotblocks = g_hash_table_new (exec_count_hash , exec_count_equal );
95
109
}
96
110
97
111
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)
111
125
ExecCount * cnt ;
112
126
uint64_t pc = qemu_plugin_tb_vaddr (tb );
113
127
size_t insns = qemu_plugin_tb_n_insns (tb );
114
- uint64_t hash = pc ^ insns ;
115
128
116
129
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
+
118
137
if (cnt ) {
119
138
cnt -> trans_count ++ ;
120
139
} else {
@@ -123,7 +142,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
123
142
cnt -> trans_count = 1 ;
124
143
cnt -> insns = insns ;
125
144
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 );
127
146
}
128
147
129
148
g_mutex_unlock (& lock );
0 commit comments