2020-01-16 21:32:35 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#ifndef RESCTRL_H
|
|
|
|
#define RESCTRL_H
|
|
|
|
#include <stdio.h>
|
2020-01-16 21:32:37 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <math.h>
|
2020-01-16 21:32:35 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2020-01-16 21:32:41 +00:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/eventfd.h>
|
2020-01-16 21:32:35 +00:00
|
|
|
#include <asm/unistd.h>
|
|
|
|
#include <linux/perf_event.h>
|
2021-03-17 02:22:42 +00:00
|
|
|
#include "../kselftest.h"
|
2020-01-16 21:32:35 +00:00
|
|
|
|
2020-01-16 21:32:37 +00:00
|
|
|
#define MB (1024 * 1024)
|
2020-01-16 21:32:35 +00:00
|
|
|
#define RESCTRL_PATH "/sys/fs/resctrl"
|
|
|
|
#define PHYS_ID_PATH "/sys/devices/system/cpu/cpu"
|
2020-01-16 21:32:41 +00:00
|
|
|
#define CBM_MASK_PATH "/sys/fs/resctrl/info"
|
2020-01-16 21:32:35 +00:00
|
|
|
|
|
|
|
#define PARENT_EXIT(err_msg) \
|
|
|
|
do { \
|
|
|
|
perror(err_msg); \
|
|
|
|
kill(ppid, SIGKILL); \
|
|
|
|
exit(EXIT_FAILURE); \
|
|
|
|
} while (0)
|
|
|
|
|
2020-01-16 21:32:37 +00:00
|
|
|
/*
|
|
|
|
* resctrl_val_param: resctrl test parameters
|
|
|
|
* @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc)
|
|
|
|
* @ctrlgrp: Name of the control monitor group (con_mon grp)
|
|
|
|
* @mongrp: Name of the monitor group (mon grp)
|
|
|
|
* @cpu_no: CPU number to which the benchmark would be binded
|
|
|
|
* @span: Memory bytes accessed in each benchmark iteration
|
|
|
|
* @mum_resctrlfs: Should the resctrl FS be remounted?
|
|
|
|
* @filename: Name of file to which the o/p should be written
|
|
|
|
* @bw_report: Bandwidth report type (reads vs writes)
|
|
|
|
* @setup: Call back function to setup test environment
|
|
|
|
*/
|
|
|
|
struct resctrl_val_param {
|
|
|
|
char *resctrl_val;
|
|
|
|
char ctrlgrp[64];
|
|
|
|
char mongrp[64];
|
|
|
|
int cpu_no;
|
|
|
|
unsigned long span;
|
|
|
|
int mum_resctrlfs;
|
|
|
|
char filename[64];
|
|
|
|
char *bw_report;
|
2020-01-16 21:32:41 +00:00
|
|
|
unsigned long mask;
|
|
|
|
int num_of_runs;
|
2020-01-16 21:32:37 +00:00
|
|
|
int (*setup)(int num, ...);
|
|
|
|
};
|
|
|
|
|
2021-03-17 02:22:38 +00:00
|
|
|
#define MBM_STR "mbm"
|
|
|
|
#define MBA_STR "mba"
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
#define CMT_STR "cmt"
|
2021-03-17 02:22:38 +00:00
|
|
|
#define CAT_STR "cat"
|
|
|
|
|
2021-03-17 02:22:37 +00:00
|
|
|
extern pid_t bm_pid, ppid;
|
2020-01-16 21:32:35 +00:00
|
|
|
|
2021-03-17 02:22:37 +00:00
|
|
|
extern char llc_occup_path[1024];
|
|
|
|
extern bool is_amd;
|
2020-01-16 21:32:41 +00:00
|
|
|
|
2020-01-16 21:32:39 +00:00
|
|
|
bool check_resctrlfs_support(void);
|
|
|
|
int filter_dmesg(void);
|
2020-01-16 21:32:35 +00:00
|
|
|
int remount_resctrlfs(bool mum_resctrlfs);
|
|
|
|
int get_resource_id(int cpu_no, int *resource_id);
|
2020-01-16 21:32:37 +00:00
|
|
|
int umount_resctrlfs(void);
|
2020-01-16 21:32:35 +00:00
|
|
|
int validate_bw_report_request(char *bw_report);
|
|
|
|
bool validate_resctrl_feature_request(char *resctrl_val);
|
|
|
|
char *fgrep(FILE *inf, const char *str);
|
|
|
|
int taskset_benchmark(pid_t bm_pid, int cpu_no);
|
|
|
|
void run_benchmark(int signum, siginfo_t *info, void *ucontext);
|
|
|
|
int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
|
|
|
|
char *resctrl_val);
|
|
|
|
int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
|
|
|
|
char *resctrl_val);
|
|
|
|
int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
|
|
|
|
int group_fd, unsigned long flags);
|
|
|
|
int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
|
|
|
|
int op, char *resctrl_va);
|
2020-01-16 21:32:37 +00:00
|
|
|
int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
|
2020-01-16 21:32:39 +00:00
|
|
|
int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
|
|
|
|
void tests_cleanup(void);
|
|
|
|
void mbm_test_cleanup(void);
|
2020-01-16 21:32:40 +00:00
|
|
|
int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
|
|
|
|
void mba_test_cleanup(void);
|
2021-03-17 02:22:36 +00:00
|
|
|
int get_cbm_mask(char *cache_type, char *cbm_mask);
|
2020-01-16 21:32:41 +00:00
|
|
|
int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
|
|
|
|
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
|
2020-01-16 21:32:42 +00:00
|
|
|
int cat_val(struct resctrl_val_param *param);
|
|
|
|
void cat_test_cleanup(void);
|
|
|
|
int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd);
|
2020-01-16 21:32:41 +00:00
|
|
|
unsigned int count_bits(unsigned long n);
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
void cmt_test_cleanup(void);
|
2020-01-16 21:32:41 +00:00
|
|
|
int get_core_sibling(int cpu_no);
|
|
|
|
int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
|
2020-01-16 21:32:35 +00:00
|
|
|
|
|
|
|
#endif /* RESCTRL_H */
|