[PATCH] Extend l3 cache to nodeinfo

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

 



This patch extends l3 cache infomation to nodeinfo output.

Signed-off-by: Eli Qiao <liyong.qiao@xxxxxxxxx>
---
 include/libvirt/libvirt-host.h |  1 +
 src/nodeinfo.c                 |  3 ++-
 src/remote/remote_protocol.x   |  1 +
 src/test/test_driver.c         |  1 +
 src/util/virhostcpu.c          | 29 +++++++++++++++++++++++++----
 src/util/virhostcpu.h          |  3 ++-
 src/util/virhostcpupriv.h      |  3 ++-
 tests/virhostcputest.c         |  3 ++-
 tools/virsh-host.c             |  1 +
 9 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 07b5d15..ba926df 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -167,6 +167,7 @@ struct _virNodeInfo {
                              processors in case of unusual NUMA topology*/
     unsigned int threads; /* number of threads per core, 1 in case of
                              unusual numa topology */
+    unsigned int l3_cache; /* l3 cache in kilobytes */
 };
 
 /**
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index f2ded02..f54972b 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -152,7 +152,8 @@ nodeGetInfo(virNodeInfoPtr nodeinfo)
     if (virHostCPUGetInfo(hostarch,
                           &nodeinfo->cpus, &nodeinfo->mhz,
                           &nodeinfo->nodes, &nodeinfo->sockets,
-                          &nodeinfo->cores, &nodeinfo->threads) < 0)
+                          &nodeinfo->cores, &nodeinfo->threads,
+                          &nodeinfo->l3_cache) < 0)
         return -1;
 
     return 0;
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index b846ef2..6a16b4e 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -489,6 +489,7 @@ struct remote_node_get_info_ret { /* insert@1 */
     int sockets;
     int cores;
     int threads;
+    int l3_cache;
 };
 
 struct remote_connect_get_capabilities_ret {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index de92a01..b49c07b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -138,6 +138,7 @@ static const virNodeInfo defaultNodeInfo = {
     2,
     2,
     2,
+    4096,
 };
 
 static void
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index f29f312..698813b 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -530,7 +530,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                                unsigned int *nodes,
                                unsigned int *sockets,
                                unsigned int *cores,
-                               unsigned int *threads)
+                               unsigned int *threads,
+                               unsigned int *l3_cache)
 {
     virBitmapPtr present_cpus_map = NULL;
     virBitmapPtr online_cpus_map = NULL;
@@ -546,7 +547,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
     int direrr;
 
     *mhz = 0;
-    *cpus = *nodes = *sockets = *cores = *threads = 0;
+    *cpus = *nodes = *sockets = *cores = *threads = *l3_cache = 0;
 
     /* Start with parsing CPU clock speed from /proc/cpuinfo */
     while (fgets(line, sizeof(line), cpuinfo) != NULL) {
@@ -571,6 +572,24 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                     (*p == '\0' || *p == '.' || c_isspace(*p)))
                     *mhz = ui;
             }
+            if (STRPREFIX(buf, "cache size")) {
+                char *p;
+                unsigned int ui;
+                buf += 10;
+
+                while (*buf && c_isspace(*buf))
+                    buf++;
+
+                if (*buf != ':' || !buf[1]) {
+                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                            _("parsing cache size from cpuinfo"));
+                    goto cleanup;
+                }
+
+                if (virStrToLong_ui(buf+1, &p, 10, &ui) == 0 &&
+                        *(p+1)=='K' && *(p+2)=='B')
+                    *l3_cache = ui;
+            }
         } else if (ARCH_IS_PPC(arch)) {
             char *buf = line;
             if (STRPREFIX(buf, "clock")) {
@@ -960,7 +979,8 @@ virHostCPUGetInfo(virArch hostarch ATTRIBUTE_UNUSED,
                   unsigned int *nodes ATTRIBUTE_UNUSED,
                   unsigned int *sockets ATTRIBUTE_UNUSED,
                   unsigned int *cores ATTRIBUTE_UNUSED,
-                  unsigned int *threads ATTRIBUTE_UNUSED)
+                  unsigned int *threads ATTRIBUTE_UNUSED,
+                  unsigned int *l3_cache ATTRIBUTE_UNUSED)
 {
 #ifdef __linux__
     int ret = -1;
@@ -974,7 +994,8 @@ virHostCPUGetInfo(virArch hostarch ATTRIBUTE_UNUSED,
 
     ret = virHostCPUGetInfoPopulateLinux(cpuinfo, hostarch,
                                          cpus, mhz, nodes,
-                                         sockets, cores, threads);
+                                         sockets, cores, threads,
+                                         l3_cache);
     if (ret < 0)
         goto cleanup;
 
diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h
index 39f7cf8..fc579fe 100644
--- a/src/util/virhostcpu.h
+++ b/src/util/virhostcpu.h
@@ -50,7 +50,8 @@ int virHostCPUGetInfo(virArch hostarch,
                       unsigned int *nodes,
                       unsigned int *sockets,
                       unsigned int *cores,
-                      unsigned int *threads);
+                      unsigned int *threads,
+                      unsigned int *l3_cache);
 
 int virHostCPUGetKVMMaxVCPUs(void);
 
diff --git a/src/util/virhostcpupriv.h b/src/util/virhostcpupriv.h
index de30983..69d5e34 100644
--- a/src/util/virhostcpupriv.h
+++ b/src/util/virhostcpupriv.h
@@ -34,7 +34,8 @@ int virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                                    unsigned int *nodes,
                                    unsigned int *sockets,
                                    unsigned int *cores,
-                                   unsigned int *threads);
+                                   unsigned int *threads,
+                                   unsigned int *l3_cache);
 
 int virHostCPUGetStatsLinux(FILE *procstat,
                             int cpuNum,
diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c
index 8387956..2b2a680 100644
--- a/tests/virhostcputest.c
+++ b/tests/virhostcputest.c
@@ -44,7 +44,8 @@ linuxTestCompareFiles(const char *cpuinfofile,
     if (virHostCPUGetInfoPopulateLinux(cpuinfo, arch,
                                        &nodeinfo.cpus, &nodeinfo.mhz,
                                        &nodeinfo.nodes, &nodeinfo.sockets,
-                                       &nodeinfo.cores, &nodeinfo.threads) < 0) {
+                                       &nodeinfo.cores, &nodeinfo.threads,
+                                       &nodeinfo.l3_cache) < 0) {
         if (virTestGetDebug()) {
             if (virGetLastError())
                 VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage());
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 24ebde2..2b85372 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -671,6 +671,7 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     vshPrint(ctl, "%-20s %d\n", _("Thread(s) per core:"), info.threads);
     vshPrint(ctl, "%-20s %d\n", _("NUMA cell(s):"), info.nodes);
     vshPrint(ctl, "%-20s %lu KiB\n", _("Memory size:"), info.memory);
+    vshPrint(ctl, "%-20s %d KiB\n", _("L3 cache size:"), info.l3_cache);
 
     return true;
 }
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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