Skip to contentSkip to conversation

tools/misc/xenpm: fix getting info when some CPUs are offline

PATCH Superseded Marek Marczykowski-Górecki 3 participants 5 messages Oct 30, 2018 – Oct 31, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/misc/xenpm: fix getting info when some CPUs are offline

Use physinfo.max_cpu_id instead of physinfo.nr_cpus to get max CPU id. This fixes for example 'xenpm get-cpufreq-para' with smt=off, which otherwise would miss half of the cores.

---
Reported by @tfm1:
https://github.com/QubesOS/qubes-issues/isues/4456

---
 tools/misc/xenpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/misc/xenpm.c +1 -1
index 86c12ea5fb..112590fb67 100644
@@ -1231,7 +1231,7 @@ int main(int argc, char *argv[])
         xc_interface_close(xc_handle);
         return ret;
     }
-    max_cpu_nr = physinfo.nr_cpus;
+    max_cpu_nr = physinfo.max_cpu_id;
 
     /* calculate how many options match with user's input */
     for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
Signature · 7 lines
2.17.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 8 lines · Marek Marczykowski-Górecki

Use physinfo.max_cpu_id instead of physinfo.nr_cpus to get max CPU id. This fixes for example 'xenpm get-cpufreq-para' with smt=off, which otherwise would miss half of the cores.

---
Reported by @tfm1:
https://github.com/QubesOS/qubes-issues/isues/4456

Thats a 404, but /issues/ looks to work.

Either way, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 9 lines
---
 tools/misc/xenpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/misc/xenpm.c +0 -0
index 86c12ea5fb..112590fb67 100644

tools/misc/xenpm.c int main(int argc, char *argv[]) · line 1237

Quoted 8 lines
tools/misc/xenpm.c +1 -1
@@ -1231,7 +1231,7 @@ int main(int argc, char *argv[])
         xc_interface_close(xc_handle);
         return ret;
     }
-    max_cpu_nr = physinfo.nr_cpus;
+    max_cpu_nr = physinfo.max_cpu_id;
 
     /* calculate how many options match with user's input */
     for ( i = 0; i < ARRAY_SIZE(main_options); i++ )

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Marek Marczykowski-Górecki

tools/misc/xenpm.c int main(int argc, char *argv[]) · line 1234

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 23:16, <[email protected]> wrote:
tools/misc/xenpm.c +1 -1
@@ -1231,7 +1231,7 @@ int main(int argc, char *argv[])
         xc_interface_close(xc_handle);
         return ret;
     }
-    max_cpu_nr = physinfo.nr_cpus;
+    max_cpu_nr = physinfo.max_cpu_id;

Isn't this off by 1 then? max_cpu_nr is misnamed, all loops using it are of the form

    for ( i = 0; i < max_cpu_nr; i++ )

I'm also afraid there are further quirks here, with various constructs along the lines of (as bodies of aforementioned for())

        if ( show_cxstat_by_cpuid(xc_handle, i) == -ENODEV )
            break;

which I suspect would terminate processing early when hitting a true gap (i.e. not one resulting from a parked CPU). But I guess it wouldn't be appropriate to ask you to deal with this at the same time.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 13 lines · Jan Beulich

tools/misc/xenpm.c int main(int argc, char *argv[]) · line 1234

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 23:16, <[email protected]> wrote:
tools/misc/xenpm.c +1 -1
@@ -1231,7 +1231,7 @@ int main(int argc, char *argv[])
         xc_interface_close(xc_handle);
         return ret;
     }
-    max_cpu_nr = physinfo.nr_cpus;
+    max_cpu_nr = physinfo.max_cpu_id;

Isn't this off by 1 then? max_cpu_nr is misnamed, all loops using it are of the form

Quoted 1 line
    for ( i = 0; i < max_cpu_nr; i++ )

Oh, you're right. This doesn't affect smt=off case, because the last cpu is offline anyway...

Quoted 8 lines

I'm also afraid there are further quirks here, with various constructs along the lines of (as bodies of aforementioned for())

        if ( show_cxstat_by_cpuid(xc_handle, i) == -ENODEV )
            break;

which I suspect would terminate processing early when hitting a true gap (i.e. not one resulting from a parked CPU).

How that would happen? Hotplug?
Also I've tried to look at error codes to distinguish offline cpu and avoid printing that error, but looks EINVAL is used for a lot of cases.

Quoted 6 lines

But I guess it wouldn't
be appropriate to ask you to deal with this at the same time.

Jan

Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 31.10.18 at 11:53, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

I'm also afraid there are further quirks here, with various constructs along the lines of (as bodies of aforementioned for())

Quoted 7 lines
Quoted 5 lines
        if ( show_cxstat_by_cpuid(xc_handle, i) == -ENODEV )
            break;

which I suspect would terminate processing early when hitting a true gap (i.e. not one resulting from a parked CPU).

How that would happen? Hotplug?

xen-hptool on AMD might trigger this, afaict.

Quoted 2 lines

Also I've tried to look at error codes to distinguish offline cpu and avoid printing that error, but looks EINVAL is used for a lot of cases.

Yeah, the common problem with EINVAL.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel