All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: aaron@os.amperecomputing.com, cota@braap.org,
	"Alex Bennée" <alex.bennee@linaro.org>,
	robert.foley@futurewei.com, peter.puhov@futurewei.com
Subject: [PATCH  v5 52/55] plugins: make howvec plugin more generic
Date: Mon, 14 Oct 2019 11:49:45 +0100	[thread overview]
Message-ID: <20191014104948.4291-53-alex.bennee@linaro.org> (raw)
In-Reply-To: <20191014104948.4291-1-alex.bennee@linaro.org>

Now the plugins interface indicates what guest architecture we are
running we can attempt to select the instruction classification based
on it. For now we still only classify aarch64 instructions and fall
back to decoding individual instructions. We also wave our hands about
irregular instruction encoding.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/plugin/howvec.c | 76 +++++++++++++++++++++++++++++++------------
 1 file changed, 56 insertions(+), 20 deletions(-)

diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c
index 3b1d177ef3..5f7c740833 100644
--- a/tests/plugin/howvec.c
+++ b/tests/plugin/howvec.c
@@ -4,8 +4,7 @@
  * How vectorised is this code?
  *
  * Attempt to measure the amount of vectorisation that has been done
- * on some code by counting classes of instruction. This is very much
- * ARM specific.
+ * on some code by counting classes of instruction.
  *
  * License: GNU GPL, version 2 or later.
  *   See the COPYING file in the top-level directory.
@@ -61,7 +60,7 @@ typedef struct {
  *
  * 31..28 27..24 23..20 19..16 15..12 11..8 7..4 3..0
  */
-InsnClassExecCount insn_classes[] = {
+InsnClassExecCount aarch64_insn_classes[] = {
     /* "Reserved"" */
     { "  UDEF",              "udef",   0xffff0000, 0x00000000, COUNT_NONE},
     { "  SVE",               "sve",    0x1e000000, 0x04000000, COUNT_CLASS},
@@ -110,9 +109,29 @@ InsnClassExecCount insn_classes[] = {
     /* Scalar FP */
     { "Scalar FP ",          "fpsimd", 0x0e000000, 0x0e000000, COUNT_CLASS},
     /* Unclassified */
-    { "Unclassified",        "unclas", 0x00000000, 0x00000000, COUNT_CLASS}
+    { "Unclassified",        "unclas", 0x00000000, 0x00000000, COUNT_CLASS},
 };
 
+/* Default matcher for currently unclassified architectures */
+InsnClassExecCount default_insn_classes[] = {
+    { "Unclassified",        "unclas", 0x00000000, 0x00000000, COUNT_INDIVIDUAL},
+};
+
+typedef struct {
+    const char *qemu_target;
+    InsnClassExecCount *table;
+    int table_sz;
+} ClassSelector;
+
+ClassSelector class_tables[] =
+{
+    { "aarch64", aarch64_insn_classes, ARRAY_SIZE(aarch64_insn_classes) },
+    { NULL, default_insn_classes, ARRAY_SIZE(default_insn_classes) },
+};
+
+static InsnClassExecCount *class_table;
+static int class_table_sz;
+
 static gint cmp_exec_count(gconstpointer a, gconstpointer b)
 {
     InsnExecCount *ea = (InsnExecCount *) a;
@@ -125,23 +144,25 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
     GString *report = g_string_new("Instruction Classes:\n");
     int i;
     GList *counts;
+    InsnClassExecCount *class = NULL;
 
-    for (i = 0; i < ARRAY_SIZE(insn_classes); i++) {
-        switch (insn_classes[i].what) {
+    for (i = 0; i < class_table_sz; i++) {
+        class = &class_table[i];
+        switch (class->what) {
         case COUNT_CLASS:
-            if (insn_classes[i].count || verbose) {
+            if (class->count || verbose) {
                 g_string_append_printf(report, "Class: %-24s\t(%ld hits)\n",
-                                       insn_classes[i].class,
-                                       insn_classes[i].count);
+                                       class->class,
+                                       class->count);
             }
             break;
         case COUNT_INDIVIDUAL:
             g_string_append_printf(report, "Class: %-24s\tcounted individually\n",
-                                   insn_classes[i].class);
+                                   class->class);
             break;
         case COUNT_NONE:
             g_string_append_printf(report, "Class: %-24s\tnot counted\n",
-                                   insn_classes[i].class);
+                                   class->class);
             break;
         default:
             break;
@@ -190,14 +211,18 @@ static uint64_t * find_counter(struct qemu_plugin_insn *insn)
     uint32_t opcode;
     InsnClassExecCount *class = NULL;
 
-    /* we expect all instructions to by 32 bits for ARM */
-    g_assert(qemu_plugin_insn_size(insn) == 4);
+    /*
+     * We only match the first 32 bits of the instruction which is
+     * fine for most RISCs but a bit limiting for CISC architectures.
+     * They would probably benefit from a more tailored plugin.
+     * However we can fall back to individual instruction counting.
+     */
     opcode = *((uint32_t *)qemu_plugin_insn_data(insn));
 
-    for (i = 0; !cnt && i < ARRAY_SIZE(insn_classes); i++) {
-        uint32_t masked_bits = opcode & insn_classes[i].mask;
-        if (masked_bits == insn_classes[i].pattern) {
-            class = &insn_classes[i];
+    for (i = 0; !cnt && i < class_table_sz; i++) {
+        class = &class_table[i];
+        uint32_t masked_bits = opcode & class->mask;
+        if (masked_bits == class->pattern) {
             break;
         }
     }
@@ -270,6 +295,17 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
 {
     int i;
 
+    /* Select a class table appropriate to the guest architecture */
+    for (i = 0; i < ARRAY_SIZE(class_tables); i++) {
+        ClassSelector *entry = &class_tables[i];
+        if (!entry->qemu_target ||
+            strcmp(entry->qemu_target, info->target_name) == 0) {
+            class_table = entry->table;
+            class_table_sz = entry->table_sz;
+            break;
+        }
+    }
+
     for (i = 0; i < argc; i++) {
         char *p = argv[i];
         if (strcmp(p, "inline") == 0) {
@@ -283,9 +319,9 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
                 type = COUNT_NONE;
                 p++;
             }
-            for (j = 0; j < ARRAY_SIZE(insn_classes); j++) {
-                if (strcmp(p, insn_classes[j].opt) == 0) {
-                    insn_classes[j].what = type;
+            for (j = 0; j < class_table_sz; j++) {
+                if (strcmp(p, class_table[j].opt) == 0) {
+                    class_table[j].what = type;
                     break;
                 }
             }
-- 
2.20.1



  parent reply	other threads:[~2019-10-14 11:16 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 10:48 [PATCH for 4.2 v5 00/55] Support for TCG plugins Alex Bennée
2019-10-14 10:48 ` [PATCH v5 01/55] trace: expand mem_info:size_shift to 4 bits Alex Bennée
2019-10-14 14:35   ` Richard Henderson
2019-10-14 10:48 ` [PATCH v5 02/55] trace: add mmu_index to mem_info Alex Bennée
2019-10-14 14:53   ` Richard Henderson
2019-10-15 11:15     ` Alex Bennée
2019-10-14 10:48 ` [PATCH v5 03/55] cpu: introduce cpu_in_exclusive_context() Alex Bennée
2019-10-14 10:48 ` [PATCH v5 04/55] translate-all: use cpu_in_exclusive_work_context() in tb_flush Alex Bennée
2019-10-14 10:48 ` [PATCH v5 05/55] docs/devel: add plugins.rst design document Alex Bennée
2019-10-14 10:48 ` [PATCH v5 06/55] configure: add --enable-plugins (MOVE TO END) Alex Bennée
2019-10-14 10:49 ` [PATCH v5 07/55] plugin: add user-facing API Alex Bennée
2019-10-14 10:49 ` [PATCH v5 08/55] plugin: add core code Alex Bennée
2019-10-14 10:49 ` [PATCH v5 09/55] plugin: add implementation of the api Alex Bennée
2019-10-14 10:49 ` [PATCH v5 10/55] queue: add QTAILQ_REMOVE_SEVERAL Alex Bennée
2019-10-14 10:49 ` [PATCH v5 11/55] cputlb: document get_page_addr_code Alex Bennée
2019-10-14 10:49 ` [PATCH v5 12/55] cputlb: introduce get_page_addr_code_hostp Alex Bennée
2019-10-14 10:49 ` [PATCH v5 13/55] tcg: add tcg_gen_st_ptr Alex Bennée
2019-10-14 10:49 ` [PATCH v5 14/55] plugin-gen: add module for TCG-related code Alex Bennée
2019-10-14 15:23   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 15/55] atomic_template: add inline trace/plugin helpers Alex Bennée
2019-10-14 10:49 ` [PATCH v5 16/55] tcg: let plugins instrument virtual memory accesses Alex Bennée
2019-10-14 10:49 ` [PATCH v5 17/55] plugins: implement helpers for resolving hwaddr Alex Bennée
2019-10-14 15:45   ` Richard Henderson
2019-10-14 15:54   ` Peter Maydell
2019-10-14 16:34     ` Alex Bennée
2019-10-14 16:56       ` Peter Maydell
2019-10-14 10:49 ` [PATCH v5 18/55] translate-all: notify plugin code of tb_flush Alex Bennée
2019-10-14 10:49 ` [PATCH v5 19/55] *-user: notify plugin of exit Alex Bennée
2019-10-14 10:49 ` [PATCH v5 20/55] *-user: plugin syscalls Alex Bennée
2019-10-14 10:49 ` [PATCH v5 21/55] cpu: hook plugin vcpu events Alex Bennée
2019-10-14 10:49 ` [PATCH v5 22/55] plugin-gen: add plugin_insn_append Alex Bennée
2019-10-14 10:49 ` [PATCH v5 23/55] translator: add translator_ld{ub,sw,uw,l,q} Alex Bennée
2019-10-14 16:08   ` Richard Henderson
2019-10-14 17:31   ` Peter Maydell
2019-10-15 18:55     ` Alex Bennée
2019-10-15 21:34       ` Alex Bennée
2019-10-15 19:03     ` Alex Bennée
2019-10-14 10:49 ` [PATCH v5 24/55] target/arm: fetch code with translator_ld Alex Bennée
2019-10-14 10:49 ` [PATCH v5 25/55] target/ppc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 26/55] target/sh4: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 27/55] target/i386: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 28/55] target/hppa: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 29/55] target/m68k: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 30/55] target/alpha: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 31/55] target/riscv: " Alex Bennée
2019-10-14 10:49   ` Alex Bennée
2019-10-14 17:59   ` Alistair Francis
2019-10-14 17:59     ` Alistair Francis
2019-10-18 18:32     ` Palmer Dabbelt
2019-10-18 18:32       ` Palmer Dabbelt
2019-10-14 10:49 ` [PATCH v5 32/55] target/sparc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 33/55] target/xtensa: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 34/55] target/openrisc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 35/55] translator: inject instrumentation from plugins Alex Bennée
2019-10-14 10:49 ` [PATCH v5 36/55] plugin: add API symbols to qemu-plugins.symbols Alex Bennée
2019-10-14 16:13   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 37/55] vl: support -plugin option Alex Bennée
2019-10-14 10:49 ` [PATCH v5 38/55] linux-user: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 39/55] tests/plugin: add sample plugins Alex Bennée
2019-10-14 16:14   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 40/55] tests/tcg/Makefile.target: fix path to config-host.mak Alex Bennée
2019-10-14 16:15   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 41/55] tests/tcg: set QEMU_OPTS for all cris runs Alex Bennée
2019-10-14 16:16   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 42/55] tests/tcg: move "virtual" tests to EXTRA_TESTS Alex Bennée
2019-10-14 16:16   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 43/55] tests/tcg: drop test-i386-fprem from TESTS when not SLOW Alex Bennée
2019-10-14 16:44   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 44/55] tests/tcg: enable plugin testing Alex Bennée
2019-10-14 16:46   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 45/55] tests/plugin: add a hotblocks plugin Alex Bennée
2019-10-14 16:49   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 46/55] plugin: add qemu_plugin_insn_disas helper Alex Bennée
2019-10-14 10:49 ` [PATCH v5 47/55] tests/plugin: add instruction execution breakdown Alex Bennée
2019-10-14 16:50   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 48/55] tests/plugin: add hotpages plugin to breakdown memory access patterns Alex Bennée
2019-10-14 16:51   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 49/55] accel/stubs: reduce headers from tcg-stub Alex Bennée
2019-10-14 10:49 ` [PATCH v5 50/55] include/exec: wrap cpu_ldst.h in CONFIG_TCG Alex Bennée
2019-10-14 10:49 ` [PATCH v5 51/55] plugins: expand the plugin_init function to include an info block Alex Bennée
2019-10-14 16:54   ` Richard Henderson
2019-10-14 10:49 ` Alex Bennée [this message]
2019-10-14 16:59   ` [PATCH v5 52/55] plugins: make howvec plugin more generic Richard Henderson
2019-10-14 17:14     ` Alex Bennée
2019-10-14 17:39       ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 53/55] plugins: add sparc64 instruction classification table Alex Bennée
2019-10-14 17:01   ` Richard Henderson
2019-10-15 19:09     ` Alex Bennée
2019-10-15 19:37       ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 54/55] plugins: add qemu_plugin_outs and use it Alex Bennée
2019-10-14 17:03   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 55/55] .travis.yml: add --enable-plugins tests Alex Bennée
2019-10-14 17:04   ` Richard Henderson
2019-10-15  4:36 ` [PATCH for 4.2 v5 00/55] Support for TCG plugins no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191014104948.4291-53-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aaron@os.amperecomputing.com \
    --cc=cota@braap.org \
    --cc=peter.puhov@futurewei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=robert.foley@futurewei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.