[1/3] x86/nmi: Corrections and improvements to do_nmi_stats()
diff mbox series

Message ID 20200217111740.7298-2-andrew.cooper3@citrix.com
State New, archived
Headers show
Series
  • xen: async_exception_* cleanup
Related show

Commit Message

Andrew Cooper Feb. 17, 2020, 11:17 a.m. UTC
The hardware domain doesn't necessarily have the domid 0.  Render v instead,
adjusting the strings to avoid printing trailing whitespace.

Rename i to cpu, and use separate booleans for pending/masked.  Drop the
unnecessary domain local variable.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/nmi.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

Comments

Jan Beulich Feb. 18, 2020, 4:07 p.m. UTC | #1
On 17.02.2020 12:17, Andrew Cooper wrote:
> --- a/xen/arch/x86/nmi.c
> +++ b/xen/arch/x86/nmi.c
> @@ -587,25 +587,25 @@ static void do_nmi_trigger(unsigned char key)
>  
>  static void do_nmi_stats(unsigned char key)
>  {
> -    int i;
> -    struct domain *d;
> -    struct vcpu *v;
> +    const struct vcpu *v;
> +    unsigned int cpu;
> +    bool pend, mask;
>  
>      printk("CPU\tNMI\n");
> -    for_each_online_cpu ( i )
> -        printk("%3d\t%3d\n", i, nmi_count(i));
> +    for_each_online_cpu ( cpu )
> +        printk("%3d\t%3d\n", cpu, nmi_count(cpu));

%3u twice then please. With this
Reviewed-by: Jan Beulich <jbeulich@suse.com>
but I have one more remark:

> -    if ( ((d = hardware_domain) == NULL) || (d->vcpu == NULL) ||
> -         ((v = d->vcpu[0]) == NULL) )
> +    if ( !hardware_domain || !hardware_domain->vcpu ||
> +         !(v = hardware_domain->vcpu[0]) )

Perhaps, just for readability and consistency, use domain_vcpu()
here?

Jan

Patch
diff mbox series

diff --git a/xen/arch/x86/nmi.c b/xen/arch/x86/nmi.c
index a5c6bdd0ce..638677a5fe 100644
--- a/xen/arch/x86/nmi.c
+++ b/xen/arch/x86/nmi.c
@@ -587,25 +587,25 @@  static void do_nmi_trigger(unsigned char key)
 
 static void do_nmi_stats(unsigned char key)
 {
-    int i;
-    struct domain *d;
-    struct vcpu *v;
+    const struct vcpu *v;
+    unsigned int cpu;
+    bool pend, mask;
 
     printk("CPU\tNMI\n");
-    for_each_online_cpu ( i )
-        printk("%3d\t%3d\n", i, nmi_count(i));
+    for_each_online_cpu ( cpu )
+        printk("%3d\t%3d\n", cpu, nmi_count(cpu));
 
-    if ( ((d = hardware_domain) == NULL) || (d->vcpu == NULL) ||
-         ((v = d->vcpu[0]) == NULL) )
+    if ( !hardware_domain || !hardware_domain->vcpu ||
+         !(v = hardware_domain->vcpu[0]) )
         return;
 
-    i = v->async_exception_mask & (1 << VCPU_TRAP_NMI);
-    if ( v->nmi_pending || i )
-        printk("dom0 vpu0: NMI %s%s\n",
-               v->nmi_pending ? "pending " : "",
-               i ? "masked " : "");
+    pend = v->nmi_pending;
+    mask = v->async_exception_mask & (1 << VCPU_TRAP_NMI);
+    if ( pend || mask )
+        printk("%pv: NMI%s%s\n",
+               v, pend ? " pending" : "", mask ? " masked" : "");
     else
-        printk("dom0 vcpu0: NMI neither pending nor masked\n");
+        printk("%pv: NMI neither pending nor masked\n", v);
 }
 
 static __init int register_nmi_trigger(void)