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