1 // SPDX-License-Identifier: GPL-2.0
3 * Cache Monitoring Technology (CQM) 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_cqm"
16 #define MAX_DIFF 2000000
17 #define MAX_DIFF_PERCENT 15
21 unsigned long long_mask;
22 unsigned long cache_size;
24 static int cqm_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 void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits,
45 unsigned long avg_llc_occu_resc = 0;
50 avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1);
51 avg_diff = (long)abs(span - avg_llc_occu_resc);
53 diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100;
55 if ((abs((int)diff_percent) <= MAX_DIFF_PERCENT) ||
56 (abs(avg_diff) <= MAX_DIFF))
61 printf("%sok CQM: diff within %d, %d\%%\n", res ? "" : "not",
62 MAX_DIFF, (int)MAX_DIFF_PERCENT);
64 printf("# diff: %ld\n", avg_diff);
65 printf("# percent diff=%d\n", abs((int)diff_percent));
66 printf("# Results are displayed in (Bytes)\n");
67 printf("# Number of bits: %d\n", no_of_bits);
68 printf("# Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc);
69 printf("# llc_occu_exp (span): %lu\n", span);
74 static int check_results(struct resctrl_val_param *param, int no_of_bits)
76 char *token_array[8], temp[512];
77 unsigned long sum_llc_occu_resc = 0;
81 printf("# checking for pass/fail\n");
82 fp = fopen(param->filename, "r");
84 perror("# Error in opening file\n");
89 while (fgets(temp, 1024, fp)) {
90 char *token = strtok(temp, ":\t");
94 token_array[fields++] = token;
95 token = strtok(NULL, ":\t");
98 /* Field 3 is llc occ resc value */
100 sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
104 show_cache_info(sum_llc_occu_resc, no_of_bits, param->span);
109 void cqm_test_cleanup(void)
111 remove(RESULT_FILE_NAME);
114 int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
116 int ret, mum_resctrlfs;
121 ret = remount_resctrlfs(mum_resctrlfs);
125 if (!validate_resctrl_feature_request("cqm"))
128 ret = get_cbm_mask("L3");
132 long_mask = strtoul(cbm_mask, NULL, 16);
134 ret = get_cache_size(cpu_no, "L3", &cache_size);
137 printf("cache size :%lu\n", cache_size);
139 count_of_bits = count_bits(long_mask);
141 if (n < 1 || n > count_of_bits) {
142 printf("Invalid input value for numbr_of_bits n!\n");
143 printf("Please Enter value in range 1 to %d\n", count_of_bits);
147 struct resctrl_val_param param = {
148 .resctrl_val = "cqm",
153 .filename = RESULT_FILE_NAME,
154 .mask = ~(long_mask << n) & long_mask,
155 .span = cache_size * n / count_of_bits,
160 if (strcmp(benchmark_cmd[0], "fill_buf") == 0)
161 sprintf(benchmark_cmd[1], "%lu", param.span);
163 remove(RESULT_FILE_NAME);
165 ret = resctrl_val(benchmark_cmd, ¶m);
169 ret = check_results(¶m, n);