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