Revert "tty: hvc: Fix data abort due to race in hvc_open"
[linux/fpc-iii.git] / tools / testing / selftests / resctrl / cqm_test.c
blobc8756152bd615015cf1bfa0ac65d2296878e7f6c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Cache Monitoring Technology (CQM) test
5 * Copyright (C) 2018 Intel Corporation
7 * Authors:
8 * Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
9 * Fenghua Yu <fenghua.yu@intel.com>
11 #include "resctrl.h"
12 #include <unistd.h>
14 #define RESULT_FILE_NAME "result_cqm"
15 #define NUM_OF_RUNS 5
16 #define MAX_DIFF 2000000
17 #define MAX_DIFF_PERCENT 15
19 int count_of_bits;
20 char cbm_mask[256];
21 unsigned long long_mask;
22 unsigned long cache_size;
24 static int cqm_setup(int num, ...)
26 struct resctrl_val_param *p;
27 va_list param;
29 va_start(param, num);
30 p = va_arg(param, struct resctrl_val_param *);
31 va_end(param);
33 /* Run NUM_OF_RUNS times */
34 if (p->num_of_runs >= NUM_OF_RUNS)
35 return -1;
37 p->num_of_runs++;
39 return 0;
42 static void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits,
43 unsigned long span)
45 unsigned long avg_llc_occu_resc = 0;
46 float diff_percent;
47 long avg_diff = 0;
48 bool res;
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))
57 res = true;
58 else
59 res = false;
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);
71 tests_run++;
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;
78 int runs = 0;
79 FILE *fp;
81 printf("# checking for pass/fail\n");
82 fp = fopen(param->filename, "r");
83 if (!fp) {
84 perror("# Error in opening file\n");
86 return errno;
89 while (fgets(temp, 1024, fp)) {
90 char *token = strtok(temp, ":\t");
91 int fields = 0;
93 while (token) {
94 token_array[fields++] = token;
95 token = strtok(NULL, ":\t");
98 /* Field 3 is llc occ resc value */
99 if (runs > 0)
100 sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
101 runs++;
103 fclose(fp);
104 show_cache_info(sum_llc_occu_resc, no_of_bits, param->span);
106 return 0;
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;
118 cache_size = 0;
119 mum_resctrlfs = 1;
121 ret = remount_resctrlfs(mum_resctrlfs);
122 if (ret)
123 return ret;
125 if (!validate_resctrl_feature_request("cqm"))
126 return -1;
128 ret = get_cbm_mask("L3");
129 if (ret)
130 return ret;
132 long_mask = strtoul(cbm_mask, NULL, 16);
134 ret = get_cache_size(cpu_no, "L3", &cache_size);
135 if (ret)
136 return ret;
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);
144 return -1;
147 struct resctrl_val_param param = {
148 .resctrl_val = "cqm",
149 .ctrlgrp = "c1",
150 .mongrp = "m1",
151 .cpu_no = cpu_no,
152 .mum_resctrlfs = 0,
153 .filename = RESULT_FILE_NAME,
154 .mask = ~(long_mask << n) & long_mask,
155 .span = cache_size * n / count_of_bits,
156 .num_of_runs = 0,
157 .setup = cqm_setup,
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, &param);
166 if (ret)
167 return ret;
169 ret = check_results(&param, n);
170 if (ret)
171 return ret;
173 cqm_test_cleanup();
175 return 0;