1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2018 Intel Corporation
8 * Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
9 * Fenghua Yu <fenghua.yu@intel.com>
13 #define BENCHMARK_ARGS 64
14 #define BENCHMARK_ARG_SIZE 64
20 FILE *inf = fopen("/proc/cpuinfo", "r");
26 res = fgrep(inf, "vendor_id");
29 char *s = strchr(res, ':');
31 is_amd = s && !strcmp(s, ": AuthenticAMD\n");
37 static void cmd_help(void)
39 printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n");
40 printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CMT");
41 printf("\t default benchmark is builtin fill_buf\n");
42 printf("\t-t test list: run tests specified in the test list, ");
43 printf("e.g. -t mbm, mba, cmt, cat\n");
44 printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n");
45 printf("\t-p cpu_no: specify CPU number to run the test. 1 is default\n");
46 printf("\t-h: help\n");
49 void tests_cleanup(void)
57 int main(int argc, char **argv)
59 bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true;
60 int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 5;
61 char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64];
62 char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE];
63 int ben_ind, ben_count, tests = 0;
66 for (i = 0; i < argc; i++) {
67 if (strcmp(argv[i], "-b") == 0) {
69 ben_count = argc - ben_ind;
70 argc_new = ben_ind - 1;
76 while ((c = getopt(argc_new, argv, "ht:b:n:p:")) != -1) {
81 token = strtok(optarg, ",");
88 if (!strncmp(token, MBM_STR, sizeof(MBM_STR))) {
91 } else if (!strncmp(token, MBA_STR, sizeof(MBA_STR))) {
94 } else if (!strncmp(token, CMT_STR, sizeof(CMT_STR))) {
97 } else if (!strncmp(token, CAT_STR, sizeof(CAT_STR))) {
101 printf("invalid argument\n");
105 token = strtok(NULL, ":\t");
109 cpu_no = atoi(optarg);
112 no_of_bits = atoi(optarg);
119 printf("invalid argument\n");
128 * Typically we need root privileges, because:
129 * 1. We write to resctrl FS
130 * 2. We execute perf commands
133 return ksft_exit_fail_msg("Not running as root, abort testing.\n");
135 /* Detect AMD vendor */
139 /* Extract benchmark command from command line. */
140 for (i = ben_ind; i < argc; i++) {
141 benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i];
142 sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]);
144 benchmark_cmd[ben_count] = NULL;
146 /* If no benchmark is given by "-b" argument, use fill_buf. */
147 for (i = 0; i < 6; i++)
148 benchmark_cmd[i] = benchmark_cmd_area[i];
150 strcpy(benchmark_cmd[0], "fill_buf");
151 sprintf(benchmark_cmd[1], "%d", span);
152 strcpy(benchmark_cmd[2], "1");
153 strcpy(benchmark_cmd[3], "1");
154 strcpy(benchmark_cmd[4], "0");
155 strcpy(benchmark_cmd[5], "");
156 benchmark_cmd[6] = NULL;
159 sprintf(bw_report, "reads");
160 sprintf(bm_type, "fill_buf");
162 if (!check_resctrlfs_support())
163 return ksft_exit_fail_msg("resctrl FS does not exist\n");
167 ksft_set_plan(tests ? : 4);
169 if (!is_amd && mbm_test) {
170 ksft_print_msg("Starting MBM BW change ...\n");
172 sprintf(benchmark_cmd[5], "%s", MBA_STR);
173 res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd);
174 ksft_test_result(!res, "MBM: bw change\n");
178 if (!is_amd && mba_test) {
179 ksft_print_msg("Starting MBA Schemata change ...\n");
181 sprintf(benchmark_cmd[1], "%d", span);
182 res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd);
183 ksft_test_result(!res, "MBA: schemata change\n");
188 ksft_print_msg("Starting CMT test ...\n");
190 sprintf(benchmark_cmd[5], "%s", CMT_STR);
191 res = cmt_resctrl_val(cpu_no, no_of_bits, benchmark_cmd);
192 ksft_test_result(!res, "CMT: test\n");
197 ksft_print_msg("Starting CAT test ...\n");
198 res = cat_perf_miss_val(cpu_no, no_of_bits, "L3");
199 ksft_test_result(!res, "CAT: test\n");
203 return ksft_exit_pass();