Skip to contentSkip to conversation

monitor/ppc: Access all SPRs from the monitor

Qemu-devel Benjamin Herrenschmidt 3 participants 5 messages Sep 27, 2015 – Sep 30, 2015

lore
Share & tools
lore
#0 lore raw

We already have a table with all supported SPRs along with their names, so let's use that rather than a duplicate table that is perpetually out of sync in the monitor code.

This adds a new monitor hook target_extra_monitor_def() which is called if nothing is found is the normal table. We still use the old mechanism for anything that isn't an SPR.

---
 include/monitor/hmp-target.h     |  1 +
 monitor.c                        |  8 +++-
 stubs/Makefile.objs              |  1 +
 stubs/target-extra-monitor-def.c | 10 +++++
 target-ppc/monitor.c             | 93 +++++++++-------------------------------
 5 files changed, 39 insertions(+), 74 deletions(-)
 create mode 100644 stubs/target-extra-monitor-def.c
include/monitor/hmp-target.h +1 -0
index 213566c..b946e32 100644
@@ -35,6 +35,7 @@ struct MonitorDef {
 };
 
 const MonitorDef *target_monitor_defs(void);
+int target_extra_monitor_def(uint64_t *pval, const char *name);
 
 CPUArchState *mon_get_cpu_env(void);
 CPUState *mon_get_cpu(void);
monitor.c +7 -1
index 881d869..43cfcf8 100644
@@ -2106,7 +2106,9 @@ expr_error(Monitor *mon, const char *fmt, ...)
 static int get_monitor_def(target_long *pval, const char *name)
 {
     const MonitorDef *md = target_monitor_defs();
+    uint64_t val;
     void *ptr;
+    int rc;
 
     if (md == NULL) {
         return -1;
@@ -2134,7 +2136,11 @@ static int get_monitor_def(target_long *pval, const char *name)
             return 0;
         }
     }
-    return -1;
+    rc = target_extra_monitor_def(&val, name);
+    if (rc >= 0) {
+        *pval = val;
+    }
+    return rc;
 }
 
 static void next(void)
stubs/Makefile.objs +1 -0
index 85e4e81..c042f73 100644
@@ -39,3 +39,4 @@ stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
 stub-obj-y += target-monitor-defs.o
+stub-obj-y += target-extra-monitor-def.o
stubs/target-extra-monitor-def.c new file +10 -0
new file mode 100644
index 0000000..6f108f3
@@ -0,0 +1,10 @@
+#include "stddef.h"
+#include "qemu/typedefs.h"
+#include <stdint.h>
+
+int target_extra_monitor_def(uint64_t *pval, const char *name);
+
+int target_extra_monitor_def(uint64_t *pval, const char *name)
+{
+    return -1;
+}
target-ppc/monitor.c +20 -73

108 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Benjamin Herrenschmidt

We already have a table with all supported SPRs along with their names, so let's use that rather than a duplicate table that is perpetually out of sync in the monitor code.

This adds a new monitor hook target_extra_monitor_def() which is called if nothing is found is the normal table. We still use the old mechanism for anything that isn't an SPR.

This looks like a good idea, but it seems to be a slightly different approach from the one taken by some rather similar patches Alexey posted recently.

Would you care to co-ordinate on which of those approaches to go ahead with?

[snip]

target-ppc/monitor.c const MonitorDef *target_monitor_defs(void) · line 187

Quoted 9 lines
target-ppc/monitor.c +5 -0
@@ -253,3 +180,23 @@ const MonitorDef *target_monitor_defs(void)
 {
     return monitor_defs;
 }
+
+int target_extra_monitor_def(uint64_t *pval, const char *name)
+{
+     /* On ppc, search through the SPRs so we can print any of them */
+    {
       ^

Also, this appears to be a redundant set of braces.

Quoted 18 lines
target-ppc/monitor.c +15 -0
+        CPUArchState *env = mon_get_cpu_env();
+        ppc_spr_t *spr_cb = env->spr_cb;
+        int i;
+
+        for (i = 0; i < 1024; i++) {
+            if (!spr_cb[i].name || strcasecmp(name, spr_cb[i].name)) {
+                continue;
+            }
+            *pval = env->spr[i];
+            return 0;
+        }
+    }
+    return -1;
+}
+
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 9 lines · David Gibson
Quoted 8 lines · Benjamin Herrenschmidt

We already have a table with all supported SPRs along with their names, so let's use that rather than a duplicate table that is perpetually out of sync in the monitor code.

This adds a new monitor hook target_extra_monitor_def() which is called if nothing is found is the normal table. We still use the old mechanism for anything that isn't an SPR.

Quoted 8 lines
Quoted 1 line

This looks like a good idea, but it seems to be a slightly different approach from the one taken by some rather similar patches Alexey posted recently.

Would you care to co-ordinate on which of those approaches to go ahead with?

The code upstream has changed quite a bit...

Quoted 11 lines

[snip]

target-ppc/monitor.c const MonitorDef *target_monitor_defs(void) · line 187

Quoted 9 lines
target-ppc/monitor.c +5 -0
@@ -253,3 +180,23 @@ const MonitorDef *target_monitor_defs(void)
 {
     return monitor_defs;
 }
+
+int target_extra_monitor_def(uint64_t *pval, const char *name)
+{
+     /* On ppc, search through the SPRs so we can print any of them */
+    {
       ^
Quoted 1 line

Also, this appears to be a redundant set of braces.

Ah right, that used to be inside the caller (monitor_defs()) and I moved it to a hook and forgot to take out the extra braces.

I'll respin.

Quoted 19 lines

+ CPUArchState *env = mon_get_cpu_env();

Quoted 17 lines
target-ppc/monitor.c +14 -0
+        ppc_spr_t *spr_cb = env->spr_cb;
+        int i;
+
+        for (i = 0; i < 1024; i++) {
+            if (!spr_cb[i].name || strcasecmp(name, spr_cb[i].name)) {
+                continue;
+            }
+            *pval = env->spr[i];
+            return 0;
+        }
+    }
+    return -1;
+}
+
#3 lore raw
In reply to Benjamin Herrenschmidt
Quoted 23 lines · Benjamin Herrenschmidt

We already have a table with all supported SPRs along with their names, so let's use that rather than a duplicate table that is perpetually out of sync in the monitor code.

This adds a new monitor hook target_extra_monitor_def() which is called if nothing is found is the normal table. We still use the old mechanism for anything that isn't an SPR.

---
 include/monitor/hmp-target.h     |  1 +
 monitor.c                        |  8 +++-
 stubs/Makefile.objs              |  1 +
 stubs/target-extra-monitor-def.c | 10 +++++
 target-ppc/monitor.c             | 93 +++++++++-------------------------------
 5 files changed, 39 insertions(+), 74 deletions(-)
 create mode 100644 stubs/target-extra-monitor-def.c
include/monitor/hmp-target.h +0 -0
index 213566c..b946e32 100644

include/monitor/hmp-target.h struct MonitorDef { · line 38

Quoted 4 lines
include/monitor/hmp-target.h +1 -0
@@ -35,6 +35,7 @@ struct MonitorDef {
 };
 
 const MonitorDef *target_monitor_defs(void);
+int target_extra_monitor_def(uint64_t *pval, const char *name);

This would be a good place to put a doc comment documenting the semantics of this new hook.

MonitorDef structs treat the value to be obtained as a target_long, but this uses uint64_t, which is a bit inconsistent.

It might be better to:
(a) fix the core monitor code to deal in int64_t rather than target_long
(b) consider whether it would be better to have the ppc code generate a bunch of MonitorDef structs to return for the SPRs rather than having an extra hook function

stubs/target-extra-monitor-def.c line 10

Quoted 13 lines
stubs/target-extra-monitor-def.c new file +10 -0
@@ -0,0 +1,10 @@
+#include "stddef.h"
+#include "qemu/typedefs.h"
+#include <stdint.h>
+
+int target_extra_monitor_def(uint64_t *pval, const char *name);
+
+int target_extra_monitor_def(uint64_t *pval, const char *name)
+{
+    return -1;
+}

It would be better to put the prototype for the hook somewhere the stub file can include it rather than having it just rewritten here.

thanks
-- PMM

#4 lore raw
Quoted 9 lines · Peter Maydell
Quoted 2 lines

const MonitorDef *target_monitor_defs(void);
+int target_extra_monitor_def(uint64_t *pval, const char *name);

This would be a good place to put a doc comment documenting the semantics of this new hook.

MonitorDef structs treat the value to be obtained as a target_long, but this uses uint64_t, which is a bit inconsistent.

I couldn't get the definition of target_ulong in the stubs.

[ Note: Alexey has a different approach which completely replaces monitor_defs() with a CPU specific one via a method in the CPU class. I don't care which way you prefer as long as the functionality is there ]

Quoted 6 lines

It might be better to:
(a) fix the core monitor code to deal in int64_t rather than target_long
(b) consider whether it would be better to have the ppc code generate a bunch of MonitorDef structs to return for the SPRs rather than having an extra hook function

That sounds like the most bloated way to handle this :)

Quoted 9 lines
Quoted 9 lines
stubs/target-extra-monitor-def.c new file +6 -0
@@ -0,0 +1,10 @@
+#include "stddef.h"
+#include "qemu/typedefs.h"
+#include 
+
+int target_extra_monitor_def(uint64_t *pval, const char *name);
+
Quoted 8 lines

stubs/target-extra-monitor-def.c line 10

Quoted 4 lines
stubs/target-extra-monitor-def.c new file +4 -0
+int target_extra_monitor_def(uint64_t *pval, const char *name)
+{
+    return -1;
+}

It would be better to put the prototype for the hook somewhere the stub file can include it rather than having it just rewritten here.

I just copied the existing practice in get_monitor_defs()... but yes, I agree.

Ben.

Quoted 2 lines

thanks
-- PMM