linux/tools/testing/selftests/resctrl/resctrl.h
<<
>>
Prefs
   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                exit(EXIT_FAILURE);             \
  37        } while (0)
  38
  39/*
  40 * resctrl_val_param:   resctrl test parameters
  41 * @resctrl_val:        Resctrl feature (Eg: mbm, mba.. etc)
  42 * @ctrlgrp:            Name of the control monitor group (con_mon grp)
  43 * @mongrp:             Name of the monitor group (mon grp)
  44 * @cpu_no:             CPU number to which the benchmark would be binded
  45 * @span:               Memory bytes accessed in each benchmark iteration
  46 * @mum_resctrlfs:      Should the resctrl FS be remounted?
  47 * @filename:           Name of file to which the o/p should be written
  48 * @bw_report:          Bandwidth report type (reads vs writes)
  49 * @setup:              Call back function to setup test environment
  50 */
  51struct resctrl_val_param {
  52        char            *resctrl_val;
  53        char            ctrlgrp[64];
  54        char            mongrp[64];
  55        int             cpu_no;
  56        unsigned long   span;
  57        int             mum_resctrlfs;
  58        char            filename[64];
  59        char            *bw_report;
  60        unsigned long   mask;
  61        int             num_of_runs;
  62        int             (*setup)(int num, ...);
  63};
  64
  65pid_t bm_pid, ppid;
  66int tests_run;
  67
  68char llc_occup_path[1024];
  69bool is_amd;
  70
  71bool check_resctrlfs_support(void);
  72int filter_dmesg(void);
  73int remount_resctrlfs(bool mum_resctrlfs);
  74int get_resource_id(int cpu_no, int *resource_id);
  75int umount_resctrlfs(void);
  76int validate_bw_report_request(char *bw_report);
  77bool validate_resctrl_feature_request(char *resctrl_val);
  78char *fgrep(FILE *inf, const char *str);
  79int taskset_benchmark(pid_t bm_pid, int cpu_no);
  80void run_benchmark(int signum, siginfo_t *info, void *ucontext);
  81int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
  82                   char *resctrl_val);
  83int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
  84                            char *resctrl_val);
  85int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
  86                    int group_fd, unsigned long flags);
  87int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
  88                 int op, char *resctrl_va);
  89int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
  90int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
  91void tests_cleanup(void);
  92void mbm_test_cleanup(void);
  93int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
  94void mba_test_cleanup(void);
  95int get_cbm_mask(char *cache_type);
  96int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
  97void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
  98int cat_val(struct resctrl_val_param *param);
  99void cat_test_cleanup(void);
 100int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
 101int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd);
 102unsigned int count_bits(unsigned long n);
 103void cqm_test_cleanup(void);
 104int get_core_sibling(int cpu_no);
 105int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
 106
 107#endif /* RESCTRL_H */
 108