Re: [libvirt] [PATH V10 12/12] Resctrl: Add nodecachestats

2017-03-06 Thread Eli Qiao


--  
Best regards  
Eli

天涯无处不重逢
a leaf duckweed belongs to the sea, where not to meet in life  

Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Tuesday, 7 March 2017 at 5:33 AM, Marcelo Tosatti wrote:

> On Mon, Mar 06, 2017 at 05:50:43PM +0800, Eli Qiao wrote:
> > Add new virsh command line `nodecachestats` to expose the cache usage
> > on a node.
> >  
> > Signed-off-by: Eli Qiao  > (mailto:liyong.q...@intel.com)>
> > ---
> > src/libvirt_private.syms | 3 ++-
> > src/qemu/qemu_driver.c | 12 ++
> > src/util/virresctrl.c | 62 
> > src/util/virresctrl.h | 8 +++
> > tools/virsh-host.c | 49 ++
> > 5 files changed, 133 insertions(+), 1 deletion(-)
> >  
>  
>  
> It perhaps would be good to also report the largest contiguous region
> available: So that if the space is fragmented, management software
> can detect the situation beforehand.
>  
> Like this perhaps:
>  
>  
> # LD_LIBRARY_PATH=/root/git/libvirt/src/.libs/
> # /root/git/virshnodegetcachestats  
> ret=0 nparams=10
> L3.0: free=11520, max_contiguous=X.
> L3.1: free=11520, max_contiguous=X.
>  
>  


Marclo, thanks for your testing and comments.

Actually, I only expose the contiguous cache which can be allocated to VMs for 
now.

so

free == max_contiguous.

Othere will be one case:

schemata 1 = 1000 
schemata 2 = 0010 
default schemata should be 0001  (schemata should be contiguous, so it 
can’t be 0101

and free_size = 5 * min_cache_unit

virsh nodecachestats will report free=5 * min_cache_unit

next if a new vm requires cache of 1 * min_cache_unit

schemata 1 = 1000 
schemata 2 = 0010 
new VM’s schemata = 0100 
default schemata should be 0001 


so free_size is still 5 * min_cache_unit.

and   
virsh nodecachestats will report free=5 * min_cache_unit



I am not sure if that will meaningful to user we expose (fragmented) cache 
which can not be allocated to VMs.

>  
> Or:
>  
> L3.0.free: 11520
> L3.0.max_contiguous=X.
> L3.1.free: 11520
> L3.1.max_contiguous=X.
>  
> Not sure what is the preferred way to do this in libvirt.
>  
> Otherwise, testing looks good now.  

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

Re: [libvirt] [PATH V10 12/12] Resctrl: Add nodecachestats

2017-03-06 Thread Marcelo Tosatti
On Mon, Mar 06, 2017 at 05:50:43PM +0800, Eli Qiao wrote:
> Add new virsh command line `nodecachestats` to expose the cache usage
> on a node.
> 
> Signed-off-by: Eli Qiao 
> ---
>  src/libvirt_private.syms |  3 ++-
>  src/qemu/qemu_driver.c   | 12 ++
>  src/util/virresctrl.c| 62 
> 
>  src/util/virresctrl.h|  8 +++
>  tools/virsh-host.c   | 49 ++
>  5 files changed, 133 insertions(+), 1 deletion(-)

It perhaps would be good to also report the largest contiguous region
available: So that if the space is fragmented, management software
can detect the situation beforehand.

Like this perhaps:


# LD_LIBRARY_PATH=/root/git/libvirt/src/.libs/
# /root/git/virshnodegetcachestats  
ret=0 nparams=10
L3.0: free=11520, max_contiguous=X.
L3.1: free=11520, max_contiguous=X.

Or:

L3.0.free: 11520
L3.0.max_contiguous=X.
L3.1.free: 11520
L3.1.max_contiguous=X.

Not sure what is the preferred way to do this in libvirt.

Otherwise, testing looks good now.

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


[libvirt] [PATH V10 12/12] Resctrl: Add nodecachestats

2017-03-06 Thread Eli Qiao
Add new virsh command line `nodecachestats` to expose the cache usage
on a node.

Signed-off-by: Eli Qiao 
---
 src/libvirt_private.syms |  3 ++-
 src/qemu/qemu_driver.c   | 12 ++
 src/util/virresctrl.c| 62 
 src/util/virresctrl.h|  8 +++
 tools/virsh-host.c   | 49 ++
 5 files changed, 133 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9cfffb8..75a4c98 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2323,13 +2323,14 @@ virRandomInt;
 
 # util/virresctrl.h
 virResCtrlAvailable;
+virResCtrlCacheGetStats;
 virResCtrlGet;
 virResCtrlInit;
 virResCtrlSetCacheBanks;
 virResCtrlTypeFromString;
 virResCtrlTypeToString;
 virResCtrlUpdate;
-#
+
 
 # util/virrotatingfile.h
 virRotatingFileReaderConsume;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0f11ae2..4677406 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18285,6 +18285,17 @@ qemuNodeGetCPUStats(virConnectPtr conn,
 return virHostCPUGetStats(cpuNum, params, nparams, flags);
 }
 
+static int
+qemuNodeGetCacheStats(virConnectPtr conn,
+virNodeCacheStatsPtr params,
+int *nparams,
+unsigned int flags)
+{
+if (virNodeGetCacheStatsEnsureACL(conn) < 0)
+return -1;
+
+return virResCtrlCacheGetStats(params, nparams, flags);
+}
 
 static int
 qemuNodeGetMemoryStats(virConnectPtr conn,
@@ -20391,6 +20402,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
 .domainMemoryPeek = qemuDomainMemoryPeek, /* 0.4.4 */
 .domainGetBlockInfo = qemuDomainGetBlockInfo, /* 0.8.1 */
 .nodeGetCPUStats = qemuNodeGetCPUStats, /* 0.9.3 */
+.nodeGetCacheStats = qemuNodeGetCacheStats, /* 3.1.0 */
 .nodeGetMemoryStats = qemuNodeGetMemoryStats, /* 0.9.3 */
 .nodeGetCellsFreeMemory = qemuNodeGetCellsFreeMemory, /* 0.4.4 */
 .nodeGetFreeMemory = qemuNodeGetFreeMemory, /* 0.4.4 */
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 16c01a2..97f7e84 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1034,3 +1034,65 @@ virResCtrlGet(int type)
 {
 return [type];
 }
+
+int virResCtrlCacheGetStats(virNodeCacheStatsPtr params,
+int *nparams,
+unsigned int flags)
+{
+virCheckFlags(0, -1);
+size_t i, j, k;
+char *value;
+int rc = -1;
+int lockfd;
+
+if (*nparams == 0) {
+for (i = 0; i < VIR_RDT_RESOURCE_LAST; i++) {
+if (VIR_RESCTRL_ENABLED(i))
+*nparams += resctrlall[i].num_banks;
+}
+}
+if (params == NULL)
+return 0;
+
+if ((lockfd = open(RESCTRL_DIR, O_RDONLY)) < 0)
+goto cleanup;
+
+if (VIR_RESCTRL_LOCK(lockfd, LOCK_SH) < 0) {
+virReportSystemError(errno, _("Unable to lock '%s'"), RESCTRL_DIR);
+goto cleanup;
+}
+if (virResCtrlScan() < 0) {
+VIR_ERROR(_("Failed to scan resctrl domain dir"));
+goto cleanup;
+}
+
+virResCtrlRefreshSchemata();
+
+if ((rc = virResCtrlFlushDomainToSysfs(domainall.domains)) < 0)
+goto cleanup;
+
+k = 0;
+
+for (i = 0; i < VIR_RDT_RESOURCE_LAST; i++) {
+if (VIR_RESCTRL_ENABLED(i)) {
+for (j = 0; j < resctrlall[i].num_banks; j++) {
+
+if (virAsprintf(, "%s.%zu",
+resctrlall[i].name, j) < 0)
+goto cleanup;
+
+if (virStrcpyStatic(([k])->field, value) == NULL)
+goto cleanup;
+
+([k++])->value = 
resctrlall[i].cache_banks[j].cache_left;
+}
+}
+}
+
+rc = 0;
+
+ cleanup:
+VIR_FREE(value);
+VIR_RESCTRL_UNLOCK(lockfd);
+return rc;
+}
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 968e0dc..eef5370 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -80,9 +80,17 @@ struct _virResCtrl {
 };
 
 bool virResCtrlAvailable(void);
+
 int virResCtrlInit(void);
+
 virResCtrlPtr virResCtrlGet(int);
+
 int virResCtrlSetCacheBanks(virDomainCachetunePtr,
 unsigned char *, pid_t *, int);
+
 int virResCtrlUpdate(unsigned char *);
+
+int virResCtrlCacheGetStats(virNodeCacheStatsPtr params,
+int *nparams,
+unsigned int flags);
 #endif
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 24ebde2..c90bd2e 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -946,6 +946,49 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
 VIR_FREE(params);
 return ret;
 }
+/* "nodecachestats" command
+ */
+static const vshCmdInfo info_nodecachestats[] = {
+{.name = "help",
+ .data = N_("Prints cache stats of the node.")
+},
+{.name = "desc",
+ .data = N_("Returns cache stats of the node, in