1 // SPDX-License-Identifier: GPL-2.0
3 * Cache Monitoring Technology (CMT) test
5 * Copyright (C) 2018 Intel Corporation
8 * Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
9 * Fenghua Yu <fenghua.yu@intel.com>
14 #define RESULT_FILE_NAME "result_cmt"
16 #define MAX_DIFF 2000000
17 #define MAX_DIFF_PERCENT 15
19 static int cmt_setup(struct resctrl_val_param *p)
21 /* Run NUM_OF_RUNS times */
22 if (p->num_of_runs >= NUM_OF_RUNS)
30 static int check_results(struct resctrl_val_param *param, size_t span, int no_of_bits)
32 char *token_array[8], temp[512];
33 unsigned long sum_llc_occu_resc = 0;
37 ksft_print_msg("Checking for pass/fail\n");
38 fp = fopen(param->filename, "r");
40 perror("# Error in opening file\n");
45 while (fgets(temp, sizeof(temp), fp)) {
46 char *token = strtok(temp, ":\t");
50 token_array[fields++] = token;
51 token = strtok(NULL, ":\t");
54 /* Field 3 is llc occ resc value */
56 sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
61 return show_cache_info(sum_llc_occu_resc, no_of_bits, span,
62 MAX_DIFF, MAX_DIFF_PERCENT, runs - 1,
66 void cmt_test_cleanup(void)
68 remove(RESULT_FILE_NAME);
71 int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
73 const char * const *cmd = benchmark_cmd;
74 const char *new_cmd[BENCHMARK_ARGS];
75 unsigned long cache_size = 0;
76 unsigned long long_mask;
77 char *span_str = NULL;
83 ret = get_cbm_mask("L3", cbm_mask);
87 long_mask = strtoul(cbm_mask, NULL, 16);
89 ret = get_cache_size(cpu_no, "L3", &cache_size);
92 ksft_print_msg("Cache size :%lu\n", cache_size);
94 count_of_bits = count_bits(long_mask);
96 if (n < 1 || n > count_of_bits) {
97 ksft_print_msg("Invalid input value for numbr_of_bits n!\n");
98 ksft_print_msg("Please enter value in range 1 to %d\n", count_of_bits);
102 struct resctrl_val_param param = {
103 .resctrl_val = CMT_STR,
107 .filename = RESULT_FILE_NAME,
108 .mask = ~(long_mask << n) & long_mask,
113 span = cache_size * n / count_of_bits;
115 if (strcmp(cmd[0], "fill_buf") == 0) {
116 /* Duplicate the command to be able to replace span in it */
117 for (i = 0; benchmark_cmd[i]; i++)
118 new_cmd[i] = benchmark_cmd[i];
121 ret = asprintf(&span_str, "%zu", span);
124 new_cmd[1] = span_str;
128 remove(RESULT_FILE_NAME);
130 ret = resctrl_val(cmd, ¶m);
134 ret = check_results(¶m, span, n);