1 // SPDX-License-Identifier: GPL-2.0
3 * Cache Monitoring Technology (CMT) test
5 * Copyright (C) 2018 Intel Corporation
14 #define RESULT_FILE_NAME "result_cmt"
16 #define MAX_DIFF 2000000
17 #define MAX_DIFF_PERCENT 15
19 static int count_of_bits;
20 static char cbm_mask[256];
21 static unsigned long long_mask;
22 static unsigned long cache_size;
24 static int cmt_setup(int num, ...)
26 struct resctrl_val_param *p;
30 p = va_arg(param, struct resctrl_val_param *);
33 /* Run NUM_OF_RUNS times */
34 if (p->num_of_runs >= NUM_OF_RUNS)
42 static int check_results(struct resctrl_val_param *param, int no_of_bits)
44 char *token_array[8], temp[512];
45 unsigned long sum_llc_occu_resc = 0;
49 ksft_print_msg("Checking for pass/fail\n");
50 fp = fopen(param->filename, "r");
52 perror("# Error in opening file\n");
57 while (fgets(temp, sizeof(temp), fp)) {
58 char *token = strtok(temp, ":\t");
62 token_array[fields++] = token;
63 token = strtok(NULL, ":\t");
66 /* Field 3 is llc occ resc value */
68 sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
73 return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span,
74 MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS,
78 void cmt_test_cleanup(void)
80 remove(RESULT_FILE_NAME);
83 int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
89 ret = remount_resctrlfs(true);
93 if (!validate_resctrl_feature_request(CMT_STR))
96 ret = get_cbm_mask("L3", cbm_mask);
100 long_mask = strtoul(cbm_mask, NULL, 16);
102 ret = get_cache_size(cpu_no, "L3", &cache_size);
105 ksft_print_msg("Cache size :%lu\n", cache_size);
107 count_of_bits = count_bits(long_mask);
109 if (n < 1 || n > count_of_bits) {
110 ksft_print_msg("Invalid input value for numbr_of_bits n!\n");
111 ksft_print_msg("Please enter value in range 1 to %d\n", count_of_bits);
115 struct resctrl_val_param param = {
116 .resctrl_val = CMT_STR,
120 .mum_resctrlfs = false,
121 .filename = RESULT_FILE_NAME,
122 .mask = ~(long_mask << n) & long_mask,
123 .span = cache_size * n / count_of_bits,
128 if (strcmp(benchmark_cmd[0], "fill_buf") == 0)
129 sprintf(benchmark_cmd[1], "%lu", param.span);
131 remove(RESULT_FILE_NAME);
133 ret = resctrl_val(benchmark_cmd, ¶m);
137 ret = check_results(¶m, n);