Skip to contentSkip to conversation

monitor: Support specified vCPU registers

PATCH In review zhenwei pi 3 participants 7 messages Aug 2, 2022 – Sep 15, 2022

lore
Share & tools
lore

zhenwei pi

author
#0 lore raw

v4 cover monitor: Support specified vCPU registers

v3 -> v4:
- Tweake a few document and output '\n' prefix.

v2 -> v3:
- Add more document in help info.
- Use 'qemu_get_cpu()' to simplify code.

v1 -> v2:
- Typo fix in commit message.
- Suggested by Darren, use '[-a|vcpu]' instead of '[-a] [vcpu]', becase only one of these may be specified at a time.

v1:
- Support specified vCPU registers for monitor command.

Zhenwei Pi (1):
monitor: Support specified vCPU registers

 hmp-commands-info.hx |  8 +++++---
 monitor/misc.c       | 10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v4 1/1 monitor: Support specified vCPU registers

Originally we have to get all the vCPU registers and parse the specified one. To improve the performance of this usage, allow user specified vCPU id to query registers.

Run a VM with 16 vCPU, use bcc tool to track the latency of 'hmp_info_registers':
'info registers -a' uses about 3ms;
'info registers 12' uses about 150us.

---
 hmp-commands-info.hx |  8 +++++---
 monitor/misc.c       | 10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)
hmp-commands-info.hx +5 -3
index 188d9ece3b..e012035541 100644
@@ -100,9 +100,11 @@ ERST
 
     {
         .name       = "registers",
-        .args_type  = "cpustate_all:-a",
-        .params     = "[-a]",
-        .help       = "show the cpu registers (-a: all - show register info for all cpus)",
+        .args_type  = "cpustate_all:-a,vcpu:i?",
+        .params     = "[-a|vcpu]",
+        .help       = "show the cpu registers (-a: show register info for all cpus;"
+                      " vcpu: specific vCPU to query; show the current CPU's registers if"
+                      " no argument is specified)",
         .cmd        = hmp_info_registers,
     },
 
monitor/misc.c +8 -2
index 3d2312ba8d..6436a8786b 100644
@@ -307,6 +307,7 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+    int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
     CPUState *cs;
 
     if (all_cpus) {
@@ -315,13 +316,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
             cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
         }
     } else {
-        cs = mon_get_cpu(mon);
+        cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
 
         if (!cs) {
-            monitor_printf(mon, "No CPU available\n");
+            if (vcpu >= 0) {
+                monitor_printf(mon, "CPU#%d not available\n", vcpu);
+            } else {
+                monitor_printf(mon, "No CPU available\n");
+            }
             return;
         }
 
+        monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
         cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
     }
 }
Signature · 1 line
2.20.1
Reviewed-by on v4 1/1
#2 lore raw

This looks good to me...

Quoted 4 lines · zhenwei pi

Originally we have to get all the vCPU registers and parse the specified one. To improve the performance of this usage, allow user specified vCPU id to query registers.

Quoted 8 lines

Run a VM with 16 vCPU, use bcc tool to track the latency of 'hmp_info_registers':
'info registers -a' uses about 3ms;
'info registers 12' uses about 150us.

Thanks,

Darren.

Quoted 59 lines
---
 hmp-commands-info.hx |  8 +++++---
 monitor/misc.c       | 10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)
hmp-commands-info.hx +5 -3
index 188d9ece3b..e012035541 100644
@@ -100,9 +100,11 @@ ERST
 
     {
         .name       = "registers",
-        .args_type  = "cpustate_all:-a",
-        .params     = "[-a]",
-        .help       = "show the cpu registers (-a: all - show register info for all cpus)",
+        .args_type  = "cpustate_all:-a,vcpu:i?",
+        .params     = "[-a|vcpu]",
+        .help       = "show the cpu registers (-a: show register info for all cpus;"
+                      " vcpu: specific vCPU to query; show the current CPU's registers if"
+                      " no argument is specified)",
         .cmd        = hmp_info_registers,
     },
 
monitor/misc.c +8 -2
index 3d2312ba8d..6436a8786b 100644
@@ -307,6 +307,7 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+    int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
     CPUState *cs;
 
     if (all_cpus) {
@@ -315,13 +316,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
             cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
         }
     } else {
-        cs = mon_get_cpu(mon);
+        cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
 
         if (!cs) {
-            monitor_printf(mon, "No CPU available\n");
+            if (vcpu >= 0) {
+                monitor_printf(mon, "CPU#%d not available\n", vcpu);
+            } else {
+                monitor_printf(mon, "No CPU available\n");
+            }
             return;
         }
 
+        monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
         cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
     }
 }
Signature · 1 line
2.20.1
Reviewed-by on v4 1/1
#3 lore raw
In reply to zhenwei pi
Quoted 4 lines · * zhenwei pi ([email protected]) wrote:

Originally we have to get all the vCPU registers and parse the specified one. To improve the performance of this usage, allow user specified vCPU id to query registers.

Quoted 8 lines

Run a VM with 16 vCPU, use bcc tool to track the latency of 'hmp_info_registers':
'info registers -a' uses about 3ms;
'info registers 12' uses about 150us.

Quoted 60 lines
---
 hmp-commands-info.hx |  8 +++++---
 monitor/misc.c       | 10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)
hmp-commands-info.hx +5 -3
index 188d9ece3b..e012035541 100644
@@ -100,9 +100,11 @@ ERST
 
     {
         .name       = "registers",
-        .args_type  = "cpustate_all:-a",
-        .params     = "[-a]",
-        .help       = "show the cpu registers (-a: all - show register info for all cpus)",
+        .args_type  = "cpustate_all:-a,vcpu:i?",
+        .params     = "[-a|vcpu]",
+        .help       = "show the cpu registers (-a: show register info for all cpus;"
+                      " vcpu: specific vCPU to query; show the current CPU's registers if"
+                      " no argument is specified)",
         .cmd        = hmp_info_registers,
     },
 
monitor/misc.c +8 -2
index 3d2312ba8d..6436a8786b 100644
@@ -307,6 +307,7 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+    int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
     CPUState *cs;
 
     if (all_cpus) {
@@ -315,13 +316,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
             cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
         }
     } else {
-        cs = mon_get_cpu(mon);
+        cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
 
         if (!cs) {
-            monitor_printf(mon, "No CPU available\n");
+            if (vcpu >= 0) {
+                monitor_printf(mon, "CPU#%d not available\n", vcpu);
+            } else {
+                monitor_printf(mon, "No CPU available\n");
+            }
             return;
         }
 
+        monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
         cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
     }
 }
Signature · 1 line
2.20.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#4 lore raw

PING: Re: [PATCH v4 1/1] monitor: Support specified vCPU registers

PING!

Quoted 76 lines · Dr. David Alan Gilbert
Quoted 4 lines · * zhenwei pi ([email protected]) wrote:

Originally we have to get all the vCPU registers and parse the specified one. To improve the performance of this usage, allow user specified vCPU id to query registers.

Quoted 8 lines

Run a VM with 16 vCPU, use bcc tool to track the latency of 'hmp_info_registers':
'info registers -a' uses about 3ms;
'info registers 12' uses about 150us.

Quoted 60 lines
---
  hmp-commands-info.hx |  8 +++++---
  monitor/misc.c       | 10 ++++++++--
  2 files changed, 13 insertions(+), 5 deletions(-)
hmp-commands-info.hx +5 -3
index 188d9ece3b..e012035541 100644
@@ -100,9 +100,11 @@ ERST
 
      {
          .name       = "registers",
-        .args_type  = "cpustate_all:-a",
-        .params     = "[-a]",
-        .help       = "show the cpu registers (-a: all - show register info for all cpus)",
+        .args_type  = "cpustate_all:-a,vcpu:i?",
+        .params     = "[-a|vcpu]",
+        .help       = "show the cpu registers (-a: show register info for all cpus;"
+                      " vcpu: specific vCPU to query; show the current CPU's registers if"
+                      " no argument is specified)",
          .cmd        = hmp_info_registers,
      },
 
monitor/misc.c +8 -2
index 3d2312ba8d..6436a8786b 100644
@@ -307,6 +307,7 @@ int monitor_get_cpu_index(Monitor *mon)
  static void hmp_info_registers(Monitor *mon, const QDict *qdict)
  {
      bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+    int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
      CPUState *cs;
 
      if (all_cpus) {
@@ -315,13 +316,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
              cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
          }
      } else {
-        cs = mon_get_cpu(mon);
+        cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
 
          if (!cs) {
-            monitor_printf(mon, "No CPU available\n");
+            if (vcpu >= 0) {
+                monitor_printf(mon, "CPU#%d not available\n", vcpu);
+            } else {
+                monitor_printf(mon, "No CPU available\n");
+            }
              return;
          }
 
+        monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
          cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
      }
  }
Signature · 1 line
2.20.1
Signature · 1 line
zhenwei pi
#5 lore raw

Re: PING: Re: [PATCH v4 1/1] monitor: Support specified vCPU registers

Quoted 1 line · * zhenwei pi ([email protected]) wrote:

PING!

It's OK, I've got it lined up for a pull I'll do in a few days time.

Dave

Quoted 76 lines · Dr. David Alan Gilbert
Quoted 71 lines · * zhenwei pi ([email protected]) wrote:
Quoted 4 lines

Originally we have to get all the vCPU registers and parse the specified one. To improve the performance of this usage, allow user specified vCPU id to query registers.

Quoted 8 lines

Run a VM with 16 vCPU, use bcc tool to track the latency of 'hmp_info_registers':
'info registers -a' uses about 3ms;
'info registers 12' uses about 150us.

Quoted 55 lines
---
  hmp-commands-info.hx |  8 +++++---
  monitor/misc.c       | 10 ++++++++--
  2 files changed, 13 insertions(+), 5 deletions(-)
hmp-commands-info.hx +5 -3
index 188d9ece3b..e012035541 100644
@@ -100,9 +100,11 @@ ERST
      {
          .name       = "registers",
-        .args_type  = "cpustate_all:-a",
-        .params     = "[-a]",
-        .help       = "show the cpu registers (-a: all - show register info for all cpus)",
+        .args_type  = "cpustate_all:-a,vcpu:i?",
+        .params     = "[-a|vcpu]",
+        .help       = "show the cpu registers (-a: show register info for all cpus;"
+                      " vcpu: specific vCPU to query; show the current CPU's registers if"
+                      " no argument is specified)",
          .cmd        = hmp_info_registers,
      },
monitor/misc.c +8 -2
index 3d2312ba8d..6436a8786b 100644
@@ -307,6 +307,7 @@ int monitor_get_cpu_index(Monitor *mon)
  static void hmp_info_registers(Monitor *mon, const QDict *qdict)
  {
      bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+    int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
      CPUState *cs;
      if (all_cpus) {
@@ -315,13 +316,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
              cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
          }
      } else {
-        cs = mon_get_cpu(mon);
+        cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
          if (!cs) {
-            monitor_printf(mon, "No CPU available\n");
+            if (vcpu >= 0) {
+                monitor_printf(mon, "CPU#%d not available\n", vcpu);
+            } else {
+                monitor_printf(mon, "No CPU available\n");
+            }
              return;
          }
+        monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
          cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
      }
  }
Signature · 1 line
2.20.1
Signature · 1 line
zhenwei pi
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#6 lore raw
In reply to zhenwei pi
Quoted 15 lines · * zhenwei pi ([email protected]) wrote:

v3 -> v4:
- Tweake a few document and output '\n' prefix.

v2 -> v3:
- Add more document in help info.
- Use 'qemu_get_cpu()' to simplify code.

v1 -> v2:
- Typo fix in commit message.
- Suggested by Darren, use '[-a|vcpu]' instead of '[-a] [vcpu]', becase only one of these may be specified at a time.

v1:
- Support specified vCPU registers for monitor command.

Quoted 6 lines

Zhenwei Pi (1):
monitor: Support specified vCPU registers

 hmp-commands-info.hx |  8 +++++---
 monitor/misc.c       | 10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

Queued. Sorry for the delay.

Dave

Quoted 5 lines
Signature · 2 lines
-- 
2.20.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK