Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/resctrl: Fix incorrect parsing of iMC counters

iMC (Integrated Memory Controller) counters are usually at
"/sys/bus/event_source/devices/" and are named as "uncore_imc_<n>".
num_of_imcs() function tries to count number of such iMC counters so that
it could appropriately initialize required number of perf_attr structures
that could be used to read these iMC counters.

num_of_imcs() function assumes that all the directories under this path
that start with "uncore_imc" are iMC counters. But, on some systems there
could be directories named as "uncore_imc_free_running" which aren't iMC
counters. Trying to read from such directories will result in "not found
file" errors and MBM/MBA tests will fail.

Hence, fix the logic in num_of_imcs() such that it looks at the first
character after "uncore_imc_" to check if it's a numerical digit or not. If
it's a digit then the directory represents an iMC counter, else, skip the
directory.

Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Fenghua Yu and committed by
Shuah Khan
d81343b5 4e5cb354

+20 -2
+20 -2
tools/testing/selftests/resctrl/resctrl_val.c
··· 221 221 */ 222 222 static int num_of_imcs(void) 223 223 { 224 + char imc_dir[512], *temp; 224 225 unsigned int count = 0; 225 - char imc_dir[512]; 226 226 struct dirent *ep; 227 227 int ret; 228 228 DIR *dp; ··· 230 230 dp = opendir(DYN_PMU_PATH); 231 231 if (dp) { 232 232 while ((ep = readdir(dp))) { 233 - if (strstr(ep->d_name, UNCORE_IMC)) { 233 + temp = strstr(ep->d_name, UNCORE_IMC); 234 + if (!temp) 235 + continue; 236 + 237 + /* 238 + * imc counters are named as "uncore_imc_<n>", hence 239 + * increment the pointer to point to <n>. Note that 240 + * sizeof(UNCORE_IMC) would count for null character as 241 + * well and hence the last underscore character in 242 + * uncore_imc'_' need not be counted. 243 + */ 244 + temp = temp + sizeof(UNCORE_IMC); 245 + 246 + /* 247 + * Some directories under "DYN_PMU_PATH" could have 248 + * names like "uncore_imc_free_running", hence, check if 249 + * first character is a numerical digit or not. 250 + */ 251 + if (temp[0] >= '0' && temp[0] <= '9') { 234 252 sprintf(imc_dir, "%s/%s/", DYN_PMU_PATH, 235 253 ep->d_name); 236 254 ret = read_from_imc_dir(imc_dir, count);