[PATCH 2/3] virhostcpu.c: skip non x86 hosts in virHostCPUGetMicrocodeVersion()

Ján Tomko jtomko at redhat.com
Tue Aug 25 17:46:15 UTC 2020


On a Monday in 2020, Daniel Henrique Barboza wrote:
>Non-x86 archs does not have a 'microcode' version like x86. This is
>covered already inside the function - just return 0 if no microcode
>is found. Regardless of that, a read of /proc/cpuinfo is always made.
>Each read will invoke the kernel to fill in the CPU details every time.
>
>Now let's consider a non-x86 host, like a Power 9 server with 128 CPUs.
>Each /proc/cpuinfo read will need to fetch data for each CPU and it
>won't even matter because we know beforehand that PowerPC chips don't
>have microcode information.
>
>We can do better for non-x86 hosts by skipping this process entirely.
>
>Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
>---
> src/cpu/cpu_x86.c            | 2 +-
> src/qemu/qemu_capabilities.c | 4 ++--
> src/util/virhostcpu.c        | 5 ++++-
> src/util/virhostcpu.h        | 2 +-
> 4 files changed, 8 insertions(+), 5 deletions(-)
>
>diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
>index 1e5cd93abb..aa982589be 100644
>--- a/src/cpu/cpu_x86.c
>+++ b/src/cpu/cpu_x86.c
>@@ -2759,7 +2759,7 @@ virCPUx86GetHost(virCPUDefPtr cpu,
>     }
>
>     ret = x86DecodeCPUData(cpu, cpuData, models);
>-    cpu->microcodeVersion = virHostCPUGetMicrocodeVersion();
>+    cpu->microcodeVersion = virHostCPUGetMicrocodeVersion(cpuData->arch);
>
>     /* Probing for TSC frequency makes sense only if the CPU supports
>      * invariant TSC (Linux calls this constant_tsc in /proc/cpuinfo). */
>diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
>index ff6ba8c9e9..da743ecbe0 100644
>--- a/src/qemu/qemu_capabilities.c
>+++ b/src/qemu/qemu_capabilities.c
>@@ -5502,7 +5502,7 @@ virQEMUCapsNewData(const char *binary,
>                                            priv->runUid,
>                                            priv->runGid,
>                                            priv->hostCPUSignature,
>-                                           virHostCPUGetMicrocodeVersion(),
>+                                           virHostCPUGetMicrocodeVersion(priv->hostArch),
>                                            priv->kernelVersion);
> }
>
>@@ -5636,7 +5636,7 @@ virQEMUCapsCacheLookup(virFileCachePtr cache,
>     virQEMUCapsCachePrivPtr priv = virFileCacheGetPriv(cache);
>     virQEMUCapsPtr ret = NULL;
>
>-    priv->microcodeVersion = virHostCPUGetMicrocodeVersion();
>+    priv->microcodeVersion = virHostCPUGetMicrocodeVersion(priv->hostArch);
>
>     ret = virFileCacheLookup(cache, binary);
>
>diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
>index d7aa39c131..aafc3a14c6 100644
>--- a/src/util/virhostcpu.c
>+++ b/src/util/virhostcpu.c
>@@ -1239,12 +1239,15 @@ virHostCPUGetKVMMaxVCPUs(void)
>  * some reason.
>  */
> unsigned int
>-virHostCPUGetMicrocodeVersion(void)
>+virHostCPUGetMicrocodeVersion(virArch hostArch)

The corresponding non-Linux stub also needed the argument change.

I fixed that before pushing.

Jano

> {
>     g_autofree char *outbuf = NULL;
>     char *cur;
>     unsigned int version = 0;
>
>+    if (!ARCH_IS_X86(hostArch))
>+        return 0;
>+
>     if (virFileReadHeaderQuiet(CPUINFO_PATH, 4096, &outbuf) < 0) {
>         VIR_DEBUG("Failed to read microcode version from %s: %s",
>                   CPUINFO_PATH, g_strerror(errno));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200825/9b8e6311/attachment-0001.sig>


More information about the libvir-list mailing list