[libvirt] [PATCH v2 1/2] util: virsysinfo: parse frequency information on S390

Bjoern Walk posted 2 patches 7 years, 4 months ago
[libvirt] [PATCH v2 1/2] util: virsysinfo: parse frequency information on S390
Posted by Bjoern Walk 7 years, 4 months ago
Let's also parse the available processor frequency information on S390
so that it can be utilized by virsh sysinfo:

    # virsh sysinfo

    <sysinfo type='smbios'>
      ...
      <processor>
	<entry name='family'>2964</entry>
	<entry name='manufacturer'>IBM/S390</entry>
	<entry name='version'>00</entry>
	<entry name='max_speed'>5000</entry>
	<entry name='serial_number'>145F07</entry>
      </processor>
      ...
    </sysinfo>

Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
---
 src/util/virsysinfo.c | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index ab81b1f7..dc309a7c 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -34,6 +34,7 @@
 #include "virsysinfo.h"
 #include "viralloc.h"
 #include "vircommand.h"
+#include "virlog.h"
 #include "virfile.h"
 #include "virstring.h"
 
@@ -42,6 +43,7 @@
 
 #define VIR_FROM_THIS VIR_FROM_SYSINFO
 
+VIR_LOG_INIT("util.sysinfo");
 
 VIR_ENUM_IMPL(virSysinfo, VIR_SYSINFO_LAST,
               "smbios");
@@ -495,11 +497,12 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
     char *tmp_base;
     char *manufacturer = NULL;
     char *procline = NULL;
+    char *ncpu = NULL;
     int result = -1;
     virSysinfoProcessorDefPtr processor;
 
     if (!(tmp_base = virSysinfoParseS390Line(base, "vendor_id", &manufacturer)))
-        goto cleanup;
+        goto error;
 
     /* Find processor N: line and gather the processor manufacturer,
        version, serial number, and family */
@@ -507,10 +510,10 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
            && (tmp_base = virSysinfoParseS390Line(tmp_base, "processor ",
                                                   &procline))) {
         if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
-            goto cleanup;
+            goto error;
         processor = &ret->processor[ret->nprocessor - 1];
         if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0)
-            goto cleanup;
+            goto error;
         if (!virSysinfoParseS390Delimited(procline, "version",
                                           &processor->processor_version,
                                           '=', ',') ||
@@ -520,15 +523,43 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
             !virSysinfoParseS390Delimited(procline, "machine",
                                           &processor->processor_family,
                                           '=', '\n'))
-            goto cleanup;
+            goto error;
 
         VIR_FREE(procline);
     }
-    result = 0;
+
+    /* now, for each processor found, extract the frequency information */
+    tmp_base = (char *) base;
+
+    while ((tmp_base = strstr(tmp_base, "cpu number")) &&
+           (tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) {
+        unsigned int n;
+        char *mhz = NULL;
+
+        if (virStrToLong_uip(ncpu, NULL, 10, &n) < 0)
+            goto error;
+
+        if (n >= ret->nprocessor) {
+            VIR_DEBUG("CPU number '%d' out of range", n);
+            goto cleanup;
+        }
+
+        if (!(tmp_base = strstr(tmp_base, "cpu MHz static")) ||
+            !virSysinfoParseS390Line(tmp_base, "cpu MHz static", &mhz))
+            goto cleanup;
+
+        ret->processor[n].processor_max_speed = mhz;
+
+        VIR_FREE(ncpu);
+    }
 
  cleanup:
+    result = 0;
+
+ error:
     VIR_FREE(manufacturer);
     VIR_FREE(procline);
+    VIR_FREE(ncpu);
     return result;
 }
 
-- 
2.13.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 1/2] util: virsysinfo: parse frequency information on S390
Posted by Pino Toscano 7 years, 4 months ago
On Friday, 12 January 2018 12:38:01 CET Bjoern Walk wrote:
> +    while ((tmp_base = strstr(tmp_base, "cpu number")) &&
> +           (tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) {
> +        unsigned int n;
> +        char *mhz = NULL;
> [...]
> +        if (n >= ret->nprocessor) {
> +            VIR_DEBUG("CPU number '%d' out of range", n);

Since 'n' is unsigned int, then the right printf format is %u.

The rest of the patch seems good to me.

Thanks,
-- 
Pino Toscano--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 1/2] util: virsysinfo: parse frequency information on S390
Posted by Bjoern Walk 7 years, 4 months ago
Pino Toscano <ptoscano@redhat.com> [2018-01-12, 01:37PM +0100]:
> On Friday, 12 January 2018 12:38:01 CET Bjoern Walk wrote:
> > +    while ((tmp_base = strstr(tmp_base, "cpu number")) &&
> > +           (tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) {
> > +        unsigned int n;
> > +        char *mhz = NULL;
> > [...]
> > +        if (n >= ret->nprocessor) {
> > +            VIR_DEBUG("CPU number '%d' out of range", n);
> 
> Since 'n' is unsigned int, then the right printf format is %u.

You are right, of course. Expected to get a compiler warning or
syntax-check error, though.

> The rest of the patch seems good to me.

Thanks.

> 
> Thanks,
> -- 
> Pino Toscano


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list