util: virsysinfo: parse frequency information on S390

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>
This commit is contained in:
Bjoern Walk 2018-01-12 12:38:01 +01:00 committed by John Ferlan
parent 85604bc332
commit 4be9959b41

View File

@ -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 '%u' 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;
}