1 /* SPDX-License-Identifier: GPL-2.0 */
17 #include <sys/ioctl.h>
18 #include <sys/mount.h>
19 #include <sys/types.h>
21 #include <sys/select.h>
23 #include <sys/eventfd.h>
24 #include <asm/unistd.h>
25 #include <linux/perf_event.h>
26 #include "../kselftest.h"
28 #define MB (1024 * 1024)
29 #define RESCTRL_PATH "/sys/fs/resctrl"
30 #define PHYS_ID_PATH "/sys/devices/system/cpu/cpu"
31 #define CBM_MASK_PATH "/sys/fs/resctrl/info"
32 #define L3_PATH "/sys/fs/resctrl/info/L3"
33 #define MB_PATH "/sys/fs/resctrl/info/MB"
34 #define L3_MON_PATH "/sys/fs/resctrl/info/L3_MON"
35 #define L3_MON_FEATURES_PATH "/sys/fs/resctrl/info/L3_MON/mon_features"
40 #define PARENT_EXIT(err_msg) \
43 kill(ppid, SIGKILL); \
48 * resctrl_val_param: resctrl test parameters
49 * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc)
50 * @ctrlgrp: Name of the control monitor group (con_mon grp)
51 * @mongrp: Name of the monitor group (mon grp)
52 * @cpu_no: CPU number to which the benchmark would be binded
53 * @span: Memory bytes accessed in each benchmark iteration
54 * @mum_resctrlfs: Should the resctrl FS be remounted?
55 * @filename: Name of file to which the o/p should be written
56 * @bw_report: Bandwidth report type (reads vs writes)
57 * @setup: Call back function to setup test environment
59 struct resctrl_val_param {
70 int (*setup)(int num, ...);
78 extern pid_t bm_pid, ppid;
80 extern char llc_occup_path[1024];
83 bool check_resctrlfs_support(void);
84 int filter_dmesg(void);
85 int remount_resctrlfs(bool mum_resctrlfs);
86 int get_resource_id(int cpu_no, int *resource_id);
87 int umount_resctrlfs(void);
88 int validate_bw_report_request(char *bw_report);
89 bool validate_resctrl_feature_request(const char *resctrl_val);
90 char *fgrep(FILE *inf, const char *str);
91 int taskset_benchmark(pid_t bm_pid, int cpu_no);
92 void run_benchmark(int signum, siginfo_t *info, void *ucontext);
93 int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
95 int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
97 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
98 int group_fd, unsigned long flags);
99 int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
100 int op, char *resctrl_va);
101 int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
102 int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
103 void tests_cleanup(void);
104 void mbm_test_cleanup(void);
105 int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
106 void mba_test_cleanup(void);
107 int get_cbm_mask(char *cache_type, char *cbm_mask);
108 int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
109 void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
110 int cat_val(struct resctrl_val_param *param);
111 void cat_test_cleanup(void);
112 int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
113 int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd);
114 unsigned int count_bits(unsigned long n);
115 void cmt_test_cleanup(void);
116 int get_core_sibling(int cpu_no);
117 int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
118 int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
119 unsigned long cache_span, unsigned long max_diff,
120 unsigned long max_diff_percent, unsigned long num_of_runs,
121 bool platform, bool cmt);
123 #endif /* RESCTRL_H */