Signed-off-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
---
 contrib/plugins/howvec.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c
index 644a7856bb2..46230a43927 100644
--- a/contrib/plugins/howvec.c
+++ b/contrib/plugins/howvec.c
@@ -22,8 +22,18 @@
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
 
+#define MAX_CPUS 8
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
+static uint64_t count(uint64_t *arr)
+{
+    uint64_t res = 0;
+    for (int i = 0; i < MAX_CPUS; ++i) {
+        res += arr[i];
+    }
+    return res;
+}
+
 typedef enum {
     COUNT_CLASS,
     COUNT_INDIVIDUAL,
@@ -43,13 +53,13 @@ typedef struct {
     uint32_t mask;
     uint32_t pattern;
     CountType what;
-    uint64_t count;
+    uint64_t count[MAX_CPUS];
 } InsnClassExecCount;
 
 typedef struct {
     char *insn;
     uint32_t opcode;
-    uint64_t count;
+    uint64_t count[MAX_CPUS];
     InsnClassExecCount *class;
 } InsnExecCount;
 
@@ -159,7 +169,7 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)
 {
     InsnExecCount *ea = (InsnExecCount *) a;
     InsnExecCount *eb = (InsnExecCount *) b;
-    return ea->count > eb->count ? -1 : 1;
+    return count(ea->count) > count(eb->count) ? -1 : 1;
 }
 
 static void free_record(gpointer data)
@@ -180,11 +190,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
         class = &class_table[i];
         switch (class->what) {
         case COUNT_CLASS:
-            if (class->count || verbose) {
+            if (count(class->count) || verbose) {
                 g_string_append_printf(report,
                                        "Class: %-24s\t(%" PRId64 " hits)\n",
                                        class->class,
-                                       class->count);
+                                       count(class->count));
             }
             break;
         case COUNT_INDIVIDUAL:
@@ -212,7 +222,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
                                    "Instr: %-24s\t(%" PRId64 " hits)"
                                    "\t(op=0x%08x/%s)\n",
                                    rec->insn,
-                                   rec->count,
+                                   count(rec->count),
                                    rec->opcode,
                                    rec->class ?
                                    rec->class->class : "un-categorised");
@@ -233,7 +243,7 @@ static void plugin_init(void)
 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)
 {
     uint64_t *count = (uint64_t *) udata;
-    (*count)++;
+    count[cpu_index]++;
 }
 
 static uint64_t *find_counter(struct qemu_plugin_insn *insn)
@@ -265,7 +275,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn)
     case COUNT_NONE:
         return NULL;
     case COUNT_CLASS:
-        return &class->count;
+        return class->count;
     case COUNT_INDIVIDUAL:
     {
         InsnExecCount *icount;
@@ -285,7 +295,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn)
         }
         g_mutex_unlock(&lock);
 
-        return &icount->count;
+        return icount->count;
     }
     default:
         g_assert_not_reached();
@@ -306,8 +316,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct 
qemu_plugin_tb *tb)
 
         if (cnt) {
             if (do_inline) {
-                qemu_plugin_register_vcpu_insn_exec_inline(
-                    insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1);
+                qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
+                    insn, QEMU_PLUGIN_INLINE_ADD_U64,
+                    cnt, sizeof(uint64_t), 1);
             } else {
                 qemu_plugin_register_vcpu_insn_exec_cb(
                     insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt);
-- 
2.43.0


Reply via email to