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

selftests/resctrl: Extend CPU vendor detection

Currently, the resctrl_tests only has a function to detect AMD vendor.
Since when the Intel Sub-NUMA Clustering feature is enabled,
Intel CMT and MBM counters may not be accurate,
the resctrl_tests also need a function to detect Intel vendor.
And in the future, resctrl_tests will need a function to detect different
vendors, such as Arm.

Extend the function to detect Intel vendor as well. Also,
this function can be easily extended to detect other vendors.

Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Shaopeng Tan and committed by
Shuah Khan
6220f69e 170d1c23

+33 -17
+1 -1
tools/testing/selftests/resctrl/cat_test.c
··· 89 89 90 90 return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64, 91 91 MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS, 92 - !is_amd, false); 92 + get_vendor() == ARCH_INTEL, false); 93 93 } 94 94 95 95 void cat_test_cleanup(void)
+4 -1
tools/testing/selftests/resctrl/resctrl.h
··· 34 34 #define L3_MON_PATH "/sys/fs/resctrl/info/L3_MON" 35 35 #define L3_MON_FEATURES_PATH "/sys/fs/resctrl/info/L3_MON/mon_features" 36 36 37 + #define ARCH_INTEL 1 38 + #define ARCH_AMD 2 39 + 37 40 #define PARENT_EXIT(err_msg) \ 38 41 do { \ 39 42 perror(err_msg); \ ··· 78 75 extern pid_t bm_pid, ppid; 79 76 80 77 extern char llc_occup_path[1024]; 81 - extern bool is_amd; 82 78 79 + int get_vendor(void); 83 80 bool check_resctrlfs_support(void); 84 81 int filter_dmesg(void); 85 82 int remount_resctrlfs(bool mum_resctrlfs);
+27 -14
tools/testing/selftests/resctrl/resctrl_tests.c
··· 13 13 #define BENCHMARK_ARGS 64 14 14 #define BENCHMARK_ARG_SIZE 64 15 15 16 - bool is_amd; 17 - 18 - void detect_amd(void) 16 + static int detect_vendor(void) 19 17 { 20 18 FILE *inf = fopen("/proc/cpuinfo", "r"); 19 + int vendor_id = 0; 20 + char *s = NULL; 21 21 char *res; 22 22 23 23 if (!inf) 24 - return; 24 + return vendor_id; 25 25 26 26 res = fgrep(inf, "vendor_id"); 27 27 28 - if (res) { 29 - char *s = strchr(res, ':'); 28 + if (res) 29 + s = strchr(res, ':'); 30 30 31 - is_amd = s && !strcmp(s, ": AuthenticAMD\n"); 32 - free(res); 33 - } 31 + if (s && !strcmp(s, ": GenuineIntel\n")) 32 + vendor_id = ARCH_INTEL; 33 + else if (s && !strcmp(s, ": AuthenticAMD\n")) 34 + vendor_id = ARCH_AMD; 35 + 34 36 fclose(inf); 37 + free(res); 38 + return vendor_id; 39 + } 40 + 41 + int get_vendor(void) 42 + { 43 + static int vendor = -1; 44 + 45 + if (vendor == -1) 46 + vendor = detect_vendor(); 47 + if (vendor == 0) 48 + ksft_print_msg("Can not get vendor info...\n"); 49 + 50 + return vendor; 35 51 } 36 52 37 53 static void cmd_help(void) ··· 223 207 if (geteuid() != 0) 224 208 return ksft_exit_fail_msg("Not running as root, abort testing.\n"); 225 209 226 - /* Detect AMD vendor */ 227 - detect_amd(); 228 - 229 210 if (has_ben) { 230 211 /* Extract benchmark command from command line. */ 231 212 for (i = ben_ind; i < argc; i++) { ··· 254 241 255 242 ksft_set_plan(tests ? : 4); 256 243 257 - if (!is_amd && mbm_test) 244 + if ((get_vendor() == ARCH_INTEL) && mbm_test) 258 245 run_mbm_test(has_ben, benchmark_cmd, span, cpu_no, bw_report); 259 246 260 - if (!is_amd && mba_test) 247 + if ((get_vendor() == ARCH_INTEL) && mba_test) 261 248 run_mba_test(has_ben, benchmark_cmd, span, cpu_no, bw_report); 262 249 263 250 if (cmt_test)
+1 -1
tools/testing/selftests/resctrl/resctrlfs.c
··· 106 106 char phys_pkg_path[1024]; 107 107 FILE *fp; 108 108 109 - if (is_amd) 109 + if (get_vendor() == ARCH_AMD) 110 110 sprintf(phys_pkg_path, "%s%d/cache/index3/id", 111 111 PHYS_ID_PATH, cpu_no); 112 112 else