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

selftests/resctrl: Share show_cache_info() by CAT and CMT tests

show_cache_info() functions are defined separately in CAT and CMT
tests. But the functions are same for the tests and unnecessary
to be defined separately. Share the function by the tests.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
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
03216ed7 ca2f4214

+52 -55
+42
tools/testing/selftests/resctrl/cache.c
··· 270 270 271 271 return ret; 272 272 } 273 + 274 + /* 275 + * show_cache_info: show cache test result information 276 + * @sum_llc_val: sum of LLC cache result data 277 + * @no_of_bits: number of bits 278 + * @cache_span: cache span in bytes for CMT or in lines for CAT 279 + * @max_diff: max difference 280 + * @max_diff_percent: max difference percentage 281 + * @num_of_runs: number of runs 282 + * @platform: show test information on this platform 283 + * @cmt: CMT test or CAT test 284 + * 285 + * Return: 0 on success. non-zero on failure. 286 + */ 287 + int show_cache_info(unsigned long sum_llc_val, int no_of_bits, 288 + unsigned long cache_span, unsigned long max_diff, 289 + unsigned long max_diff_percent, unsigned long num_of_runs, 290 + bool platform, bool cmt) 291 + { 292 + unsigned long avg_llc_val = 0; 293 + float diff_percent; 294 + long avg_diff = 0; 295 + int ret; 296 + 297 + avg_llc_val = sum_llc_val / (num_of_runs - 1); 298 + avg_diff = (long)abs(cache_span - avg_llc_val); 299 + diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100; 300 + 301 + ret = platform && abs((int)diff_percent) > max_diff_percent && 302 + (cmt ? (abs(avg_diff) > max_diff) : true); 303 + 304 + ksft_print_msg("%s cache miss rate within %d%%\n", 305 + ret ? "Fail:" : "Pass:", max_diff_percent); 306 + 307 + ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); 308 + ksft_print_msg("Number of bits: %d\n", no_of_bits); 309 + ksft_print_msg("Average LLC val: %lu\n", avg_llc_val); 310 + ksft_print_msg("Cache span (%s): %lu\n", cmt ? "bytes" : "lines", 311 + cache_span); 312 + 313 + return ret; 314 + }
+3 -25
tools/testing/selftests/resctrl/cat_test.c
··· 52 52 return ret; 53 53 } 54 54 55 - static int show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits, 56 - unsigned long span) 57 - { 58 - unsigned long allocated_cache_lines = span / 64; 59 - unsigned long avg_llc_perf_miss = 0; 60 - float diff_percent; 61 - int ret; 62 - 63 - avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1); 64 - diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) / 65 - allocated_cache_lines * 100; 66 - 67 - ret = !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT; 68 - ksft_print_msg("Cache miss rate %swithin %d%%\n", 69 - ret ? "not " : "", MAX_DIFF_PERCENT); 70 - 71 - ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); 72 - ksft_print_msg("Number of bits: %d\n", no_of_bits); 73 - ksft_print_msg("Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss); 74 - ksft_print_msg("Allocated cache lines: %lu\n", allocated_cache_lines); 75 - 76 - return ret; 77 - } 78 - 79 55 static int check_results(struct resctrl_val_param *param) 80 56 { 81 57 char *token_array[8], temp[512]; ··· 87 111 fclose(fp); 88 112 no_of_bits = count_bits(param->mask); 89 113 90 - return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span); 114 + return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64, 115 + MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS, 116 + !is_amd, false); 91 117 } 92 118 93 119 void cat_test_cleanup(void)
+3 -30
tools/testing/selftests/resctrl/cmt_test.c
··· 39 39 return 0; 40 40 } 41 41 42 - static int show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits, 43 - unsigned long span) 44 - { 45 - unsigned long avg_llc_occu_resc = 0; 46 - float diff_percent; 47 - long avg_diff = 0; 48 - int ret; 49 - 50 - avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1); 51 - avg_diff = (long)abs(span - avg_llc_occu_resc); 52 - 53 - diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100; 54 - 55 - ret = (abs((int)diff_percent) > MAX_DIFF_PERCENT) && 56 - (abs(avg_diff) > MAX_DIFF); 57 - 58 - ksft_print_msg("%s cache miss diff within %d, %d\%%\n", 59 - ret ? "Fail:" : "Pass:", MAX_DIFF, (int)MAX_DIFF_PERCENT); 60 - 61 - ksft_print_msg("Diff: %ld\n", avg_diff); 62 - ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); 63 - ksft_print_msg("Results are displayed in (Bytes)\n"); 64 - ksft_print_msg("Number of bits: %d\n", no_of_bits); 65 - ksft_print_msg("Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc); 66 - ksft_print_msg("llc_occu_exp (span): %lu\n", span); 67 - 68 - return ret; 69 - } 70 - 71 42 static int check_results(struct resctrl_val_param *param, int no_of_bits) 72 43 { 73 44 char *token_array[8], temp[512]; ··· 70 99 } 71 100 fclose(fp); 72 101 73 - return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span); 102 + return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span, 103 + MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS, 104 + true, true); 74 105 } 75 106 76 107 void cmt_test_cleanup(void)
+4
tools/testing/selftests/resctrl/resctrl.h
··· 108 108 void cmt_test_cleanup(void); 109 109 int get_core_sibling(int cpu_no); 110 110 int measure_cache_vals(struct resctrl_val_param *param, int bm_pid); 111 + int show_cache_info(unsigned long sum_llc_val, int no_of_bits, 112 + unsigned long cache_span, unsigned long max_diff, 113 + unsigned long max_diff_percent, unsigned long num_of_runs, 114 + bool platform, bool cmt); 111 115 112 116 #endif /* RESCTRL_H */