Skip to content

Commit

Permalink
selftests/resctrl: Introduce generalized test framework
Browse files Browse the repository at this point in the history
Each test currently has a "run test" function in per test file and
another resctrl_tests.c. The functions in resctrl_tests.c are almost
identical.

Generalize the one in resctrl_tests.c such that it can be shared
between all of the tests. It makes adding new tests easier and removes
the per test if () forests.

Also add comment to CPU vendor IDs that they must be defined as bits
for a bitmask.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Ilpo Järvinen authored and Shuah Khan committed Feb 13, 2024
1 parent 15f2988 commit c603ff5
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 121 deletions.
18 changes: 13 additions & 5 deletions tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static int cat_test(const struct user_params *uparams, struct resctrl_val_param
return ret;
}

int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)
static int cat_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
unsigned long long_mask, start_mask, full_cache_mask;
unsigned long cache_total_size = 0;
Expand All @@ -241,16 +241,16 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)
size_t span;
int ret;

ret = get_full_cbm(cache_type, &full_cache_mask);
ret = get_full_cbm(test->resource, &full_cache_mask);
if (ret)
return ret;
/* Get the largest contiguous exclusive portion of the cache */
ret = get_mask_no_shareable(cache_type, &long_mask);
ret = get_mask_no_shareable(test->resource, &long_mask);
if (ret)
return ret;

/* Get L3/L2 cache size */
ret = get_cache_size(uparams->cpu, cache_type, &cache_total_size);
ret = get_cache_size(uparams->cpu, test->resource, &cache_total_size);
if (ret)
return ret;
ksft_print_msg("Cache size :%lu\n", cache_total_size);
Expand Down Expand Up @@ -283,9 +283,17 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)
if (ret)
goto out;

ret = check_results(&param, cache_type, cache_total_size, full_cache_mask, start_mask);
ret = check_results(&param, test->resource,
cache_total_size, full_cache_mask, start_mask);
out:
cat_test_cleanup();

return ret;
}

struct resctrl_test l3_cat_test = {
.name = "CAT",
.resource = "L3",
.feature_check = test_resource_feature_check,
.run_test = cat_run_test,
};
17 changes: 16 additions & 1 deletion tools/testing/selftests/resctrl/cmt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void cmt_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int cmt_resctrl_val(const struct user_params *uparams)
static int cmt_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
const char * const *cmd = uparams->benchmark_cmd;
const char *new_cmd[BENCHMARK_ARGS];
Expand Down Expand Up @@ -155,10 +155,25 @@ int cmt_resctrl_val(const struct user_params *uparams)
goto out;

ret = check_results(&param, span, n);
if (ret && (get_vendor() == ARCH_INTEL))
ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");

out:
cmt_test_cleanup();
free(span_str);

return ret;
}

static bool cmt_feature_check(const struct resctrl_test *test)
{
return test_resource_feature_check(test) &&
validate_resctrl_feature_request("L3_MON", "llc_occupancy");
}

struct resctrl_test cmt_test = {
.name = "CMT",
.resource = "L3",
.feature_check = cmt_feature_check,
.run_test = cmt_run_test,
};
16 changes: 15 additions & 1 deletion tools/testing/selftests/resctrl/mba_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void mba_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int mba_schemata_change(const struct user_params *uparams)
static int mba_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
struct resctrl_val_param param = {
.resctrl_val = MBA_STR,
Expand All @@ -166,3 +166,17 @@ int mba_schemata_change(const struct user_params *uparams)

return ret;
}

static bool mba_feature_check(const struct resctrl_test *test)
{
return test_resource_feature_check(test) &&
validate_resctrl_feature_request("L3_MON", "mbm_local_bytes");
}

struct resctrl_test mba_test = {
.name = "MBA",
.resource = "MB",
.vendor_specific = ARCH_INTEL,
.feature_check = mba_feature_check,
.run_test = mba_run_test,
};
18 changes: 17 additions & 1 deletion tools/testing/selftests/resctrl/mbm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void mbm_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int mbm_bw_change(const struct user_params *uparams)
static int mbm_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
struct resctrl_val_param param = {
.resctrl_val = MBM_STR,
Expand All @@ -128,9 +128,25 @@ int mbm_bw_change(const struct user_params *uparams)
goto out;

ret = check_results(DEFAULT_SPAN);
if (ret && (get_vendor() == ARCH_INTEL))
ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");

out:
mbm_test_cleanup();

return ret;
}

static bool mbm_feature_check(const struct resctrl_test *test)
{
return validate_resctrl_feature_request("L3_MON", "mbm_total_bytes") &&
validate_resctrl_feature_request("L3_MON", "mbm_local_bytes");
}

struct resctrl_test mbm_test = {
.name = "MBM",
.resource = "MB",
.vendor_specific = ARCH_INTEL,
.feature_check = mbm_feature_check,
.run_test = mbm_run_test,
};
35 changes: 31 additions & 4 deletions tools/testing/selftests/resctrl/resctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#define PHYS_ID_PATH "/sys/devices/system/cpu/cpu"
#define INFO_PATH "/sys/fs/resctrl/info"

/*
* CPU vendor IDs
*
* Define as bits because they're used for vendor_specific bitmask in
* the struct resctrl_test.
*/
#define ARCH_INTEL 1
#define ARCH_AMD 2

Expand Down Expand Up @@ -56,6 +62,25 @@ struct user_params {
const char *benchmark_cmd[BENCHMARK_ARGS];
};

/*
* resctrl_test: resctrl test definition
* @name: Test name
* @resource: Resource to test (e.g., MB, L3, L2, etc.)
* @vendor_specific: Bitmask for vendor-specific tests (can be 0 for universal tests)
* @disabled: Test is disabled
* @feature_check: Callback to check required resctrl features
* @run_test: Callback to run the test
*/
struct resctrl_test {
const char *name;
const char *resource;
unsigned int vendor_specific;
bool disabled;
bool (*feature_check)(const struct resctrl_test *test);
int (*run_test)(const struct resctrl_test *test,
const struct user_params *uparams);
};

/*
* resctrl_val_param: resctrl test parameters
* @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc)
Expand Down Expand Up @@ -108,6 +133,7 @@ int mount_resctrlfs(void);
int umount_resctrlfs(void);
int validate_bw_report_request(char *bw_report);
bool validate_resctrl_feature_request(const char *resource, const char *feature);
bool test_resource_feature_check(const struct resctrl_test *test);
char *fgrep(FILE *inf, const char *str);
int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity);
int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity);
Expand All @@ -123,10 +149,8 @@ void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
int run_fill_buf(size_t buf_size, int memflush, int op, bool once);
int resctrl_val(const struct user_params *uparams, const char * const *benchmark_cmd,
struct resctrl_val_param *param);
int mbm_bw_change(const struct user_params *uparams);
void tests_cleanup(void);
void mbm_test_cleanup(void);
int mba_schemata_change(const struct user_params *uparams);
void mba_test_cleanup(void);
unsigned long create_bit_mask(unsigned int start, unsigned int len);
unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
Expand All @@ -137,8 +161,6 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
int signal_handler_register(void);
void signal_handler_unregister(void);
void cat_test_cleanup(void);
int cat_perf_miss_val(const struct user_params *uparams, char *cache_type);
int cmt_resctrl_val(const struct user_params *uparams);
unsigned int count_bits(unsigned long n);
void cmt_test_cleanup(void);

Expand Down Expand Up @@ -175,4 +197,9 @@ static inline unsigned long cache_portion_size(unsigned long cache_size,
return cache_size * count_bits(portion_mask) / bits;
}

extern struct resctrl_test mbm_test;
extern struct resctrl_test mba_test;
extern struct resctrl_test cmt_test;
extern struct resctrl_test l3_cat_test;

#endif /* RESCTRL_H */
Loading

0 comments on commit c603ff5

Please sign in to comment.