]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virhostcpu.c: skip non x86 hosts in virHostCPUGetMicrocodeVersion()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 24 Aug 2020 13:27:53 +0000 (10:27 -0300)
committerJán Tomko <jtomko@redhat.com>
Tue, 25 Aug 2020 17:44:39 +0000 (19:44 +0200)
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@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/cpu/cpu_x86.c
src/qemu/qemu_capabilities.c
src/util/virhostcpu.c
src/util/virhostcpu.h

index 0a53e6968af14b64b19dc83b3214d4f6a7064233..fdb665b01d3b6471817adb03af1e620ad3d3cd9c 100644 (file)
@@ -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). */
index f47dcc36edff0e4e67b590711e76b1df564bd211..dcfd7cdd4eb54716a91addb70b171ad1db3d256a 100644 (file)
@@ -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);
 
index d7aa39c13134c5d723f69334dae0b4c987c5ba07..ebb91ebb54c94e692e3816afee1f81a1294913cf 100644 (file)
@@ -1239,12 +1239,15 @@ virHostCPUGetKVMMaxVCPUs(void)
  * some reason.
  */
 unsigned int
-virHostCPUGetMicrocodeVersion(void)
+virHostCPUGetMicrocodeVersion(virArch hostArch)
 {
     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));
@@ -1268,7 +1271,7 @@ virHostCPUGetMicrocodeVersion(void)
 #else
 
 unsigned int
-virHostCPUGetMicrocodeVersion(void)
+virHostCPUGetMicrocodeVersion(virArch hostArch G_GNUC_UNUSED)
 {
     return 0;
 }
index d07503857effe76d026b08320cf75876d7adb85a..11cbcd72a30078646326eca143d8e276f0d466b1 100644 (file)
@@ -75,7 +75,7 @@ virBitmapPtr virHostCPUGetSiblingsList(unsigned int cpu);
 
 int virHostCPUGetOnline(unsigned int cpu, bool *online);
 
-unsigned int virHostCPUGetMicrocodeVersion(void);
+unsigned int virHostCPUGetMicrocodeVersion(virArch hostArch);
 
 int virHostCPUGetMSR(unsigned long index,
                      uint64_t *msr);