Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #define _GNU_SOURCE
0003 #ifndef RESCTRL_H
0004 #define RESCTRL_H
0005 #include <stdio.h>
0006 #include <stdarg.h>
0007 #include <math.h>
0008 #include <errno.h>
0009 #include <sched.h>
0010 #include <stdlib.h>
0011 #include <unistd.h>
0012 #include <string.h>
0013 #include <signal.h>
0014 #include <dirent.h>
0015 #include <stdbool.h>
0016 #include <sys/stat.h>
0017 #include <sys/ioctl.h>
0018 #include <sys/mount.h>
0019 #include <sys/types.h>
0020 #include <sys/wait.h>
0021 #include <sys/select.h>
0022 #include <sys/time.h>
0023 #include <sys/eventfd.h>
0024 #include <asm/unistd.h>
0025 #include <linux/perf_event.h>
0026 #include "../kselftest.h"
0027 
0028 #define MB          (1024 * 1024)
0029 #define RESCTRL_PATH        "/sys/fs/resctrl"
0030 #define PHYS_ID_PATH        "/sys/devices/system/cpu/cpu"
0031 #define CBM_MASK_PATH       "/sys/fs/resctrl/info"
0032 #define L3_PATH         "/sys/fs/resctrl/info/L3"
0033 #define MB_PATH         "/sys/fs/resctrl/info/MB"
0034 #define L3_MON_PATH     "/sys/fs/resctrl/info/L3_MON"
0035 #define L3_MON_FEATURES_PATH    "/sys/fs/resctrl/info/L3_MON/mon_features"
0036 
0037 #define ARCH_INTEL     1
0038 #define ARCH_AMD       2
0039 
0040 #define PARENT_EXIT(err_msg)            \
0041     do {                    \
0042         perror(err_msg);        \
0043         kill(ppid, SIGKILL);        \
0044         exit(EXIT_FAILURE);     \
0045     } while (0)
0046 
0047 /*
0048  * resctrl_val_param:   resctrl test parameters
0049  * @resctrl_val:    Resctrl feature (Eg: mbm, mba.. etc)
0050  * @ctrlgrp:        Name of the control monitor group (con_mon grp)
0051  * @mongrp:     Name of the monitor group (mon grp)
0052  * @cpu_no:     CPU number to which the benchmark would be binded
0053  * @span:       Memory bytes accessed in each benchmark iteration
0054  * @mum_resctrlfs:  Should the resctrl FS be remounted?
0055  * @filename:       Name of file to which the o/p should be written
0056  * @bw_report:      Bandwidth report type (reads vs writes)
0057  * @setup:      Call back function to setup test environment
0058  */
0059 struct resctrl_val_param {
0060     char        *resctrl_val;
0061     char        ctrlgrp[64];
0062     char        mongrp[64];
0063     int     cpu_no;
0064     unsigned long   span;
0065     int     mum_resctrlfs;
0066     char        filename[64];
0067     char        *bw_report;
0068     unsigned long   mask;
0069     int     num_of_runs;
0070     int     (*setup)(int num, ...);
0071 };
0072 
0073 #define MBM_STR         "mbm"
0074 #define MBA_STR         "mba"
0075 #define CMT_STR         "cmt"
0076 #define CAT_STR         "cat"
0077 
0078 extern pid_t bm_pid, ppid;
0079 
0080 extern char llc_occup_path[1024];
0081 
0082 int get_vendor(void);
0083 bool check_resctrlfs_support(void);
0084 int filter_dmesg(void);
0085 int remount_resctrlfs(bool mum_resctrlfs);
0086 int get_resource_id(int cpu_no, int *resource_id);
0087 int umount_resctrlfs(void);
0088 int validate_bw_report_request(char *bw_report);
0089 bool validate_resctrl_feature_request(const char *resctrl_val);
0090 char *fgrep(FILE *inf, const char *str);
0091 int taskset_benchmark(pid_t bm_pid, int cpu_no);
0092 void run_benchmark(int signum, siginfo_t *info, void *ucontext);
0093 int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
0094            char *resctrl_val);
0095 int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
0096                 char *resctrl_val);
0097 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
0098             int group_fd, unsigned long flags);
0099 int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
0100          int op, char *resctrl_va);
0101 int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
0102 int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
0103 void tests_cleanup(void);
0104 void mbm_test_cleanup(void);
0105 int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
0106 void mba_test_cleanup(void);
0107 int get_cbm_mask(char *cache_type, char *cbm_mask);
0108 int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
0109 void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
0110 int cat_val(struct resctrl_val_param *param);
0111 void cat_test_cleanup(void);
0112 int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
0113 int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd);
0114 unsigned int count_bits(unsigned long n);
0115 void cmt_test_cleanup(void);
0116 int get_core_sibling(int cpu_no);
0117 int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
0118 int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
0119             unsigned long cache_span, unsigned long max_diff,
0120             unsigned long max_diff_percent, unsigned long num_of_runs,
0121             bool platform, bool cmt);
0122 
0123 #endif /* RESCTRL_H */