xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/resctrl/resctrl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #define _GNU_SOURCE
3*4882a593Smuzhiyun #ifndef RESCTRL_H
4*4882a593Smuzhiyun #define RESCTRL_H
5*4882a593Smuzhiyun #include <stdio.h>
6*4882a593Smuzhiyun #include <stdarg.h>
7*4882a593Smuzhiyun #include <math.h>
8*4882a593Smuzhiyun #include <errno.h>
9*4882a593Smuzhiyun #include <sched.h>
10*4882a593Smuzhiyun #include <stdlib.h>
11*4882a593Smuzhiyun #include <unistd.h>
12*4882a593Smuzhiyun #include <string.h>
13*4882a593Smuzhiyun #include <signal.h>
14*4882a593Smuzhiyun #include <dirent.h>
15*4882a593Smuzhiyun #include <stdbool.h>
16*4882a593Smuzhiyun #include <sys/stat.h>
17*4882a593Smuzhiyun #include <sys/ioctl.h>
18*4882a593Smuzhiyun #include <sys/mount.h>
19*4882a593Smuzhiyun #include <sys/types.h>
20*4882a593Smuzhiyun #include <sys/wait.h>
21*4882a593Smuzhiyun #include <sys/select.h>
22*4882a593Smuzhiyun #include <sys/time.h>
23*4882a593Smuzhiyun #include <sys/eventfd.h>
24*4882a593Smuzhiyun #include <asm/unistd.h>
25*4882a593Smuzhiyun #include <linux/perf_event.h>
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define MB			(1024 * 1024)
28*4882a593Smuzhiyun #define RESCTRL_PATH		"/sys/fs/resctrl"
29*4882a593Smuzhiyun #define PHYS_ID_PATH		"/sys/devices/system/cpu/cpu"
30*4882a593Smuzhiyun #define CBM_MASK_PATH		"/sys/fs/resctrl/info"
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #define PARENT_EXIT(err_msg)			\
33*4882a593Smuzhiyun 	do {					\
34*4882a593Smuzhiyun 		perror(err_msg);		\
35*4882a593Smuzhiyun 		kill(ppid, SIGKILL);		\
36*4882a593Smuzhiyun 		exit(EXIT_FAILURE);		\
37*4882a593Smuzhiyun 	} while (0)
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * resctrl_val_param:	resctrl test parameters
41*4882a593Smuzhiyun  * @resctrl_val:	Resctrl feature (Eg: mbm, mba.. etc)
42*4882a593Smuzhiyun  * @ctrlgrp:		Name of the control monitor group (con_mon grp)
43*4882a593Smuzhiyun  * @mongrp:		Name of the monitor group (mon grp)
44*4882a593Smuzhiyun  * @cpu_no:		CPU number to which the benchmark would be binded
45*4882a593Smuzhiyun  * @span:		Memory bytes accessed in each benchmark iteration
46*4882a593Smuzhiyun  * @mum_resctrlfs:	Should the resctrl FS be remounted?
47*4882a593Smuzhiyun  * @filename:		Name of file to which the o/p should be written
48*4882a593Smuzhiyun  * @bw_report:		Bandwidth report type (reads vs writes)
49*4882a593Smuzhiyun  * @setup:		Call back function to setup test environment
50*4882a593Smuzhiyun  */
51*4882a593Smuzhiyun struct resctrl_val_param {
52*4882a593Smuzhiyun 	char		*resctrl_val;
53*4882a593Smuzhiyun 	char		ctrlgrp[64];
54*4882a593Smuzhiyun 	char		mongrp[64];
55*4882a593Smuzhiyun 	int		cpu_no;
56*4882a593Smuzhiyun 	unsigned long	span;
57*4882a593Smuzhiyun 	int		mum_resctrlfs;
58*4882a593Smuzhiyun 	char		filename[64];
59*4882a593Smuzhiyun 	char		*bw_report;
60*4882a593Smuzhiyun 	unsigned long	mask;
61*4882a593Smuzhiyun 	int		num_of_runs;
62*4882a593Smuzhiyun 	int		(*setup)(int num, ...);
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #define MBM_STR			"mbm"
66*4882a593Smuzhiyun #define MBA_STR			"mba"
67*4882a593Smuzhiyun #define CQM_STR			"cqm"
68*4882a593Smuzhiyun #define CAT_STR			"cat"
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun extern pid_t bm_pid, ppid;
71*4882a593Smuzhiyun extern int tests_run;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun extern char llc_occup_path[1024];
74*4882a593Smuzhiyun extern bool is_amd;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun bool check_resctrlfs_support(void);
77*4882a593Smuzhiyun int filter_dmesg(void);
78*4882a593Smuzhiyun int remount_resctrlfs(bool mum_resctrlfs);
79*4882a593Smuzhiyun int get_resource_id(int cpu_no, int *resource_id);
80*4882a593Smuzhiyun int umount_resctrlfs(void);
81*4882a593Smuzhiyun int validate_bw_report_request(char *bw_report);
82*4882a593Smuzhiyun bool validate_resctrl_feature_request(char *resctrl_val);
83*4882a593Smuzhiyun char *fgrep(FILE *inf, const char *str);
84*4882a593Smuzhiyun int taskset_benchmark(pid_t bm_pid, int cpu_no);
85*4882a593Smuzhiyun void run_benchmark(int signum, siginfo_t *info, void *ucontext);
86*4882a593Smuzhiyun int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
87*4882a593Smuzhiyun 		   char *resctrl_val);
88*4882a593Smuzhiyun int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
89*4882a593Smuzhiyun 			    char *resctrl_val);
90*4882a593Smuzhiyun int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
91*4882a593Smuzhiyun 		    int group_fd, unsigned long flags);
92*4882a593Smuzhiyun int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
93*4882a593Smuzhiyun 		 int op, char *resctrl_va);
94*4882a593Smuzhiyun int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
95*4882a593Smuzhiyun int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
96*4882a593Smuzhiyun void tests_cleanup(void);
97*4882a593Smuzhiyun void mbm_test_cleanup(void);
98*4882a593Smuzhiyun int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
99*4882a593Smuzhiyun void mba_test_cleanup(void);
100*4882a593Smuzhiyun int get_cbm_mask(char *cache_type, char *cbm_mask);
101*4882a593Smuzhiyun int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
102*4882a593Smuzhiyun void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
103*4882a593Smuzhiyun int cat_val(struct resctrl_val_param *param);
104*4882a593Smuzhiyun void cat_test_cleanup(void);
105*4882a593Smuzhiyun int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
106*4882a593Smuzhiyun int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd);
107*4882a593Smuzhiyun unsigned int count_bits(unsigned long n);
108*4882a593Smuzhiyun void cqm_test_cleanup(void);
109*4882a593Smuzhiyun int get_core_sibling(int cpu_no);
110*4882a593Smuzhiyun int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #endif /* RESCTRL_H */
113