hi Martin
The code looks good to me, I have 1 comment for the granularity’s comment, and another one for the test data.
Otherwise, looks perfect, good to learn how to deal with hex
On Monday, 5 June 2017 at 9:14 PM, Martin Kletzander wrote:
On some platforms the number of bits in the cbm_mask might not bedivisible by 4 (and not even by 2), so we need to properly count thebits. Similar file, min_cbm_bits, is properly parsed and used, but ifthe number is greater than one, we lose the information aboutgranularity when reporting the data in capabilities. For that matteralways report granularity, but if it is not the same as the minimum,add that information in there as well.Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>---docs/schemas/capability.rng | 7 ++++-src/conf/capabilities.c | 34 ++++++++++++++++++----src/conf/capabilities.h | 1 +.../linux-resctrl-skx/resctrl/info/L3/cbm_mask | 1 +.../linux-resctrl-skx/resctrl/info/L3/min_cbm_bits | 1 +.../linux-resctrl-skx/resctrl/info/L3/num_closids | 1 +.../linux-resctrl-skx/resctrl/schemata | 1 +.../system/cpu/cpu0/cache/index0/id | 1 +.../system/cpu/cpu0/cache/index0/level | 1 +.../system/cpu/cpu0/cache/index0/shared_cpu_list | 1 +.../system/cpu/cpu0/cache/index0/shared_cpu_map | 1 +.../system/cpu/cpu0/cache/index0/size | 1 +.../system/cpu/cpu0/cache/index0/type | 1 +.../linux-resctrl-skx/system/cpu/cpu0/online | 1 +.../system/cpu/cpu0/topology/core_id | 1 +.../system/cpu/cpu0/topology/core_siblings | 1 +.../system/cpu/cpu0/topology/core_siblings_list | 1 +.../system/cpu/cpu0/topology/physical_package_id | 1 +.../system/cpu/cpu0/topology/thread_siblings | 1 +.../system/cpu/cpu0/topology/thread_siblings_list | 1 +.../linux-resctrl-skx/system/cpu/online | 1 +.../linux-resctrl-skx/system/cpu/present | 1 +.../linux-resctrl-skx/system/node/node0/cpu0 | 1 +.../linux-resctrl-skx/system/node/node0/cpulist | 1 +.../linux-resctrl-skx/system/node/node0/cpumap | 1 +.../linux-resctrl-skx/system/node/node0/distance | 1 +.../linux-resctrl-skx/system/node/online | 1 +.../vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml | 8 ++---.../vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml | 31 ++++++++++++++++++++tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml | 4 +--tests/vircaps2xmltest.c | 1 +31 files changed, 97 insertions(+), 13 deletions(-)create mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_maskcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bitscreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closidscreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schematacreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/idcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/levelcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_listcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_mapcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/sizecreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type
It seems you miss cache/index3 ?
create mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/onlinecreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_idcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblingscreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_listcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_idcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblingscreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_listcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/onlinecreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/presentcreate mode 120000 tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0create mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulistcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumapcreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distancecreate mode 100644 tests/vircaps2xmldata/linux-resctrl-skx/system/node/onlinecreate mode 100644 tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xmldiff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rngindex e5cbfa362ec0..071090c2d991 100644--- a/docs/schemas/capability.rng+++ b/docs/schemas/capability.rng@@ -273,9 +273,14 @@</attribute><zeroOrMore><element name='control'>- <attribute name='min'>+ <attribute name='granularity'><ref name='unsignedInt'/></attribute>+ <optional>+ <attribute name='min'>+ <ref name='unsignedInt'/>+ </attribute>+ </optional><attribute name='unit'><ref name='unit'/></attribute>diff --git a/src/conf/capabilities.c b/src/conf/capabilities.cindex 3becc7e18c62..0f99f3096292 100644--- a/src/conf/capabilities.c+++ b/src/conf/capabilities.c@@ -31,6 +31,7 @@#include <unistd.h>#include "capabilities.h"+#include "c-ctype.h"#include "count-one-bits.h"#include "cpu_conf.h"#include "domain_conf.h"@@ -906,11 +907,24 @@ virCapabilitiesFormatCaches(virBufferPtr buf,virBufferAdjustIndent(&controlBuf, indent + 4);for (j = 0; j < bank->ncontrols; j++) {- bool min_kilos = !(bank->controls[j]->min % 1024);+ bool min_kilos = !(bank->controls[j]->granularity % 1024);++ /* Only use KiB if both values are divisible */+ if (bank->controls[j]->min)+ min_kilos = min_kilos && !(bank->controls[j]->min % 1024);++ virBufferAsprintf(&controlBuf,+ "<control granularity='%llu'",+ bank->controls[j]->granularity >> (min_kilos * 10));++ if (bank->controls[j]->min) {+ virBufferAsprintf(&controlBuf,+ " min='%llu'",+ bank->controls[j]->min >> (min_kilos * 10));+ }+virBufferAsprintf(&controlBuf,- "<control min='%llu' unit='%s' "- "type='%s' maxAllocs='%u'/>\n",- bank->controls[j]->min >> (min_kilos * 10),+ " unit='%s' type='%s' maxAllocs='%u'/>\n",min_kilos ? "KiB" : "B",virCacheTypeToString(bank->controls[j]->scope),bank->controls[j]->max_allocation);@@ -1598,9 +1612,11 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,virCacheType scope){int ret = -1;+ char *tmp = NULL;char *path = NULL;char *cbm_mask = NULL;char *type_upper = NULL;+ unsigned int bits = 0;unsigned int min_cbm_bits = 0;virCapsHostCacheControlPtr control;@@ -1632,8 +1648,14 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,virStringTrimOptionalNewline(cbm_mask);- /* cbm_mask: cache bit mask, it's in hex, eg: fffff */- control->min = min_cbm_bits * bank->size / (strlen(cbm_mask) * 4);+ for (tmp = cbm_mask; *tmp != '\0'; tmp++) {+ if (c_isxdigit(*tmp))+ bits += count_one_bits(virHexToBin(*tmp));+ }++ control->granularity = bank->size / bits;+ if (min_cbm_bits != 1)+ control->min = min_cbm_bits * control->granularity;control->scope = scope;diff --git a/src/conf/capabilities.h b/src/conf/capabilities.hindex ee87d598ef66..d4753db0beec 100644--- a/src/conf/capabilities.h+++ b/src/conf/capabilities.h@@ -152,6 +152,7 @@ typedef struct _virCapsHostCacheControl virCapsHostCacheControl;typedef virCapsHostCacheControl *virCapsHostCacheControlPtr;struct _virCapsHostCacheControl {unsigned long long min; /* minimum cache control size in B */+ unsigned long long granularity; /* minimum increase step for min in B */
The comments may look confused, and it will be better to describe min will be optional if min equal to granularity.
virCacheType scope; /* data, code or both */unsigned int max_allocation; /* max number of supported allocations */};diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_mask b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_masknew file mode 100644index 000000000000..d482bbb26931--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_mask@@ -0,0 +1 @@+7ffdiff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bits b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bitsnew file mode 100644index 000000000000..d00491fd7e5b--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bits@@ -0,0 +1 @@+1diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closids b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closidsnew file mode 100644index 000000000000..b6a7d89c68e0--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closids@@ -0,0 +1 @@+16diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schemata b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schematanew file mode 100644index 000000000000..4a4913735386--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schemata@@ -0,0 +1 @@+L3:0=7ff;1=7ffdiff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/idnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/id@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/level b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/levelnew file mode 100644index 000000000000..00750edc07d6--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/level@@ -0,0 +1 @@+3diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_listnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_list@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_map b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_mapnew file mode 100644index 000000000000..5325a8dff751--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_map@@ -0,0 +1 @@+001diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/size b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/sizenew file mode 100644index 000000000000..24a7d60e7fb9--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/size@@ -0,0 +1 @@+11264K
I checked that on SKX, the cache size is 33792K (33M), it’s good that it can be divided by 11.
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/typenew file mode 100644index 000000000000..e4fd9dccda2c--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type@@ -0,0 +1 @@+Unifieddiff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/onlinenew file mode 100644index 000000000000..d00491fd7e5b--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/online@@ -0,0 +1 @@+1diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_idnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_id@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblingsnew file mode 100644index 000000000000..5325a8dff751--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings@@ -0,0 +1 @@+001diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_listnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_list@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_idnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_id@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblingsnew file mode 100644index 000000000000..5325a8dff751--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings@@ -0,0 +1 @@+001diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_listnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_list@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/onlinenew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/online@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/present b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/presentnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/present@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0 b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0new file mode 120000index 000000000000..c841bea28b2b--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0@@ -0,0 +1 @@+../../cpu/cpu0\ No newline at end of filediff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulist b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulistnew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulist@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumap b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumapnew file mode 100644index 000000000000..5325a8dff751--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumap@@ -0,0 +1 @@+001diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distance b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distancenew file mode 100644index 000000000000..f599e28b8ab0--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distance@@ -0,0 +1 @@+10diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/onlinenew file mode 100644index 000000000000..573541ac9702--- /dev/null+++ b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/online@@ -0,0 +1 @@+0diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xmlindex 49aa0b98ca88..7361537bfb56 100644--- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml@@ -42,12 +42,12 @@</topology><cache><bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>- <control min='768' unit='KiB' type='code' maxAllocs='8'/>- <control min='768' unit='KiB' type='data' maxAllocs='8'/>+ <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>+ <control granularity='768' unit='KiB' type='data' maxAllocs='8'/></bank><bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>- <control min='768' unit='KiB' type='code' maxAllocs='8'/>- <control min='768' unit='KiB' type='data' maxAllocs='8'/>+ <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>+ <control granularity='768' unit='KiB' type='data' maxAllocs='8'/></bank></cache></host>diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xmlnew file mode 100644index 000000000000..f582581148f7--- /dev/null+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml@@ -0,0 +1,31 @@+<capabilities>++ <host>+ <cpu>+ <arch>x86_64</arch>+ </cpu>+ <power_management/>+ <migration_features>+ <live/>+ </migration_features>+ <topology>+ <cells num='1'>+ <cell id='0'>+ <memory unit='KiB'>1048576</memory>+ <pages unit='KiB' size='4'>2048</pages>+ <pages unit='KiB' size='2048'>4096</pages>+ <pages unit='KiB' size='1048576'>6144</pages>+ <cpus num='1'>+ <cpu id='0' socket_id='0' core_id='0' siblings='0'/>+ </cpus>+ </cell>+ </cells>+ </topology>+ <cache>+ <bank id='0' level='3' type='both' size='11264' unit='KiB' cpus='0'>+ <control granularity='1024' unit='KiB' type='both' maxAllocs='16'/>+ </bank>+ </cache>+ </host>++</capabilities>diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xmlindex cb78b4ab788d..eb02ad3322a2 100644--- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml@@ -42,10 +42,10 @@</topology><cache><bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>- <control min='1536' unit='KiB' type='both' maxAllocs='4'/>+ <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/></bank><bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>- <control min='1536' unit='KiB' type='both' maxAllocs='4'/>+ <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/></bank></cache></host>diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.cindex ae1cd521111e..c0a67858fec3 100644--- a/tests/vircaps2xmltest.c+++ b/tests/vircaps2xmltest.c@@ -120,6 +120,7 @@ mymain(void)DO_TEST_FULL("resctrl", VIR_ARCH_X86_64, true, true, true);DO_TEST_FULL("resctrl-cdp", VIR_ARCH_X86_64, true, true, true);+ DO_TEST_FULL("resctrl-skx", VIR_ARCH_X86_64, true, true, true);return ret;}--2.13.0--libvir-list mailing list
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list