[PATCH V2 2/4] capabilities: Report number of host CPU physical address bits

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

 



Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---
 src/cpu/cpu_x86.c     |  8 +++++++
 src/util/virhostcpu.c | 55 +++++++++++++++++++++++++++++++++++++++++++
 src/util/virhostcpu.h |  3 +++
 3 files changed, 66 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 4bb2ea4bae..9fcd6b8add 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2738,6 +2738,7 @@ virCPUx86GetHost(virCPUDef *cpu,
                  virDomainCapsCPUModels *models)
 {
     g_autoptr(virCPUData) cpuData = NULL;
+    unsigned int addrsz;
     int ret;
 
     if (virCPUx86DriverInitialize() < 0)
@@ -2784,6 +2785,13 @@ virCPUx86GetHost(virCPUDef *cpu,
         VIR_DEBUG("Host CPU does not support invariant TSC");
     }
 
+    if (virHostCPUGetPhysAddrSize(&addrsz) == 0) {
+        virCPUMaxPhysAddrDef *addr = g_new0(virCPUMaxPhysAddrDef, 1);
+
+        addr->bits = addrsz;
+        cpu->addr = addr;
+    }
+
     return ret;
 }
 #endif
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 639dd9b51e..668e468f2a 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -570,6 +570,41 @@ virHostCPUParseFrequency(FILE *cpuinfo,
 }
 
 
+static int
+virHostCPUParsePhysAddrSize(FILE *cpuinfo, unsigned int *addrsz)
+{
+    char line[1024];
+
+    while (fgets(line, sizeof(line), cpuinfo) != NULL) {
+        char *str;
+        char *endptr;
+
+        if (!STRPREFIX(line, "address sizes"))
+            continue;
+
+        str = line;
+        str += strlen("address sizes");
+
+        /* Skip the colon. */
+        if ((str = strstr(str, ":")) == NULL)
+            goto error;
+        str++;
+
+        /* Parse the number of physical address bits */
+        if (virStrToLong_ui(str, &endptr, 10, addrsz) < 0)
+            goto error;
+
+        return 0;
+    }
+
+ error:
+    virReportError(VIR_ERR_INTERNAL_ERROR,
+                   _("Missing or invalid CPU address size in %s"),
+                   CPUINFO_PATH);
+    return -1;
+}
+
+
 int
 virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                                virArch arch,
@@ -1616,6 +1651,20 @@ virHostCPUGetSignature(char **signature)
     return virHostCPUReadSignature(virArchFromHost(), cpuinfo, signature);
 }
 
+int
+virHostCPUGetPhysAddrSize(unsigned int *size)
+{
+    g_autoptr(FILE) cpuinfo = NULL;
+
+    if (!(cpuinfo = fopen(CPUINFO_PATH, "r"))) {
+        virReportSystemError(errno, _("Failed to open cpuinfo file '%s'"),
+                             CPUINFO_PATH);
+        return -1;
+    }
+
+    return virHostCPUParsePhysAddrSize(cpuinfo, size);
+}
+
 #else
 
 int
@@ -1625,6 +1674,12 @@ virHostCPUGetSignature(char **signature)
     return 0;
 }
 
+int
+virHostCPUGetPhysAddrSize(unsigned int *size)
+{
+    return 0;
+}
+
 #endif /* __linux__ */
 
 int
diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h
index b8ea7aafad..5232fee36d 100644
--- a/src/util/virhostcpu.h
+++ b/src/util/virhostcpu.h
@@ -58,6 +58,7 @@ int virHostCPUGetInfo(virArch hostarch,
                       unsigned int *cores,
                       unsigned int *threads);
 
+
 int virHostCPUGetKVMMaxVCPUs(void) G_NO_INLINE;
 
 int virHostCPUStatsAssign(virNodeCPUStatsPtr param,
@@ -86,6 +87,8 @@ virHostCPUTscInfo *virHostCPUGetTscInfo(void);
 
 int virHostCPUGetSignature(char **signature);
 
+int virHostCPUGetPhysAddrSize(unsigned int *size);
+
 int virHostCPUGetHaltPollTime(pid_t pid,
                               unsigned long long *haltPollSuccess,
                               unsigned long long *haltPollFail);
-- 
2.36.1





[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