Re: [libvirt] [PATCH V2] Expose resource control capabilites on cache bank

2017-04-06 Thread Daniel P. Berrange
On Thu, Apr 06, 2017 at 08:09:35PM +0800, Eli Qiao wrote:
> 
> 
> On Thursday, 6 April 2017 at 7:56 PM, Daniel P. Berrange wrote:
> 
> > On Thu, Apr 06, 2017 at 07:32:59PM +0800, Eli Qiao wrote:
> > > This patch is based on Martin's cache branch.
> > >  
> > > This patch amends the cache bank capability as follow:
> > >  
> > > 
> > > 
> > > 
> > >  > > cpus='6-11'/>
> > > 
> > > 
> > >  
> >  
> >  
> > This is still wrong per my previous comments.
> >  
> >  
> I will repost V3 to change it as your comments.
> 
> one question, if there’s no `control`, what’s the bank should be like?
> 
>  

Re: [libvirt] [PATCH V2] Expose resource control capabilites on cache bank

2017-04-06 Thread Eli Qiao


On Thursday, 6 April 2017 at 7:56 PM, Daniel P. Berrange wrote:

> On Thu, Apr 06, 2017 at 07:32:59PM +0800, Eli Qiao wrote:
> > This patch is based on Martin's cache branch.
> >  
> > This patch amends the cache bank capability as follow:
> >  
> > 
> > 
> > 
> > 
> > 
> > 
> >  
>  
>  
> This is still wrong per my previous comments.
>  
>  
I will repost V3 to change it as your comments.

one question, if there’s no `control`, what’s the bank should be like?

 

Re: [libvirt] [PATCH V2] Expose resource control capabilites on cache bank

2017-04-06 Thread Daniel P. Berrange
On Thu, Apr 06, 2017 at 07:32:59PM +0800, Eli Qiao wrote:
> This patch is based on Martin's cache branch.
> 
> This patch amends the cache bank capability as follow:
> 
> 
>   
> 
>   
> 
> 

This is still wrong per my previous comments.


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://entangle-photo.org   -o-http://search.cpan.org/~danberr/ :|

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


[libvirt] [PATCH V2] Expose resource control capabilites on cache bank

2017-04-06 Thread Eli Qiao
This patch is based on Martin's cache branch.

This patch amends the cache bank capability as follow:


  

  



Along with vircaps2xmltest case updated.

Signed-off-by: Eli Qiao 
---
 src/conf/capabilities.c  | 110 +++
 src/conf/capabilities.h  |  13 ++-
 tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml |   2 +
 tests/vircaps2xmltest.c  |   9 ++
 4 files changed, 132 insertions(+), 2 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 416dd1a..3ea518e 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -52,6 +52,7 @@
 #define VIR_FROM_THIS VIR_FROM_CAPABILITIES

 #define SYSFS_SYSTEM_PATH "/sys/devices/system/"
+#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl/"

 VIR_LOG_INIT("conf.capabilities")

@@ -873,6 +874,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
 virCapsHostCacheBankPtr *caches)
 {
 size_t i = 0;
+size_t j = 0;

 if (!ncaches)
 return 0;
@@ -900,6 +902,18 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
   bank->size >> (kilos * 10),
   kilos ? "KiB" : "B",
   cpus_str);
+virBufferAdjustIndent(buf, 2);
+for (j = 0; j < bank->ncontrol; j++) {
+bool min_kilos = !(bank->controls[j]->min % 1024);
+virBufferAsprintf(buf,
+  "\n",
+  bank->controls[j]->min >> (min_kilos * 10),
+  min_kilos ? "KiB" : "B",
+  virCacheTypeToString(bank->controls[j]->type),
+  bank->controls[j]->nallocations);
+}
+virBufferAdjustIndent(buf, -2);

 VIR_FREE(cpus_str);
 }
@@ -1513,13 +1527,97 @@ virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a,
 void
 virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr)
 {
+size_t i;
+
 if (!ptr)
 return;

 virBitmapFree(ptr->cpus);
+for (i = 0; i < ptr->ncontrol; i++)
+VIR_FREE(ptr->controls[i]);
+VIR_FREE(ptr->controls);
 VIR_FREE(ptr);
 }

+/* test which kinds of cache control supported
+ * -1: don't support
+ *  0: cat
+ *  1: cdp
+ */
+static int
+virCapabilitiesGetCacheControlType(virCapsHostCacheBankPtr bank)
+{
+int ret = -1;
+char *path = NULL;
+if (virAsprintf(, SYSFS_RESCTRL_PATH "info/L%u", bank->level) < 0)
+return -1;
+
+if (virFileExists(path)) {
+ret = 0;
+} else {
+VIR_FREE(path);
+if (virAsprintf(, SYSFS_RESCTRL_PATH "info/L%uCODE", bank->level) 
< 0)
+return -1;
+if (virFileExists(path))
+ret = 1;
+}
+
+VIR_FREE(path);
+return ret;
+}
+
+static int
+virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank, const char* type)
+{
+int ret = -1;
+char *path = NULL;
+char *cbm_mask = NULL;
+virCapsHostCacheControlPtr control;
+
+if (VIR_ALLOC(control) < 0)
+goto cleanup;
+
+if (virFileReadValueUint(>nallocations,
+ SYSFS_RESCTRL_PATH "info/L%u%s/num_closids",
+ bank->level,
+ type) < 0)
+goto cleanup;
+
+if (virFileReadValueString(_mask,
+   SYSFS_RESCTRL_PATH
+   "info/L%u%s/cbm_mask",
+   bank->level,
+   type) < 0)
+goto cleanup;
+
+virStringTrimOptionalNewline(cbm_mask);
+
+control->min = bank->size / (strlen(cbm_mask) * 4);
+
+if (STREQ("", type))
+control->type = VIR_CACHE_TYPE_UNIFIED;
+else if (STREQ("CODE", type))
+control->type = VIR_CACHE_TYPE_INSTRUCTION;
+else if (STREQ("DATA", type))
+control->type = VIR_CACHE_TYPE_DATA;
+else
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(bank->controls,
+   bank->ncontrol,
+   control) < 0)
+goto error;
+
+ret = 0;
+
+ cleanup:
+VIR_FREE(path);
+return ret;
+ error:
+VIR_FREE(control);
+return -1;
+}
+
 int
 virCapabilitiesInitCaches(virCapsPtr caps)
 {
@@ -1601,6 +1699,17 @@ virCapabilitiesInitCaches(virCapsPtr caps)
 continue;
 }

+ret = virCapabilitiesGetCacheControlType(bank);
+
+if (ret == 0) {
+if (virCapabilitiesGetCacheControl(bank, "") < 0)
+goto cleanup;
+} else if (ret == 1) {
+if ((virCapabilitiesGetCacheControl(bank, "CODE") < 0) ||
+(virCapabilitiesGetCacheControl(bank, "DATA") < 0))
+goto cleanup;
+}
+
 for (tmp_c = type; *tmp_c != '\0'; tmp_c++)
 *tmp_c = c_tolower(*tmp_c);

@@ -1617,6 +1726,7 @@