[libvirt PATCH 2/3] cpu: Only retrieve AT_HWCAP once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No need to fetch the same information twice.

As a side effect, this solves a bug where, on platforms where
elf_aux_info() is used instead of getauxval(), we would not
make sure the CPUID feature is available before attempting to
use it.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/cpu/cpu_arm.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index aa3e5d8980..71702dbc91 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -557,12 +557,19 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data)
     size_t i;
 
 # if defined(WITH_GETAUXVAL)
-    if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
+    hwcaps = getauxval(AT_HWCAP);
+# elif defined(WITH_ELF_AUX_INFO)
+    elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
+# else
+#  error No routines to retrieve a value from the auxiliary vector
+# endif
+    VIR_DEBUG("CPU flags read from register:  0x%016lx", hwcaps);
+
+    if (!(hwcaps & HWCAP_CPUID)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("CPUID registers unavailable"));
             return -1;
     }
-# endif
 
     /* read the cpuid data from MIDR_EL1 register */
     asm("mrs %0, MIDR_EL1" : "=r" (cpuid));
@@ -573,15 +580,6 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data)
     /* parse the corresponding vendor_id bits */
     data->vendor_id = (cpuid >> 24) & 0xff;
 
-# if defined(WITH_GETAUXVAL)
-    hwcaps = getauxval(AT_HWCAP);
-# elif defined(WITH_ELF_AUX_INFO)
-    elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
-# else
-#  error No routines to retrieve a value from the auxiliary vector
-# endif
-    VIR_DEBUG("CPU flags read from register:  0x%016lx", hwcaps);
-
     features = g_new0(char *, MAX_CPU_FLAGS + 1);
 
     /* shift bit map mask to parse for CPU flags */
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux