Skip to content

Commit 0061641

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Split validate_resctrl_feature_request()
validate_resctrl_feature_request() is used to test both if a resource is present in the info directory, and if a passed monitoring feature is present in the mon_features file. Refactor validate_resctrl_feature_request() into two smaller functions that each accomplish one check to give feature checking more granularity: - Resource directory presence in the /sys/fs/resctrl/info directory. - Feature name presence in the /sys/fs/resctrl/info/<RESOURCE>/mon_features file. Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> Reviewed-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>
1 parent e331ac1 commit 0061641

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
170170
static bool cmt_feature_check(const struct resctrl_test *test)
171171
{
172172
return test_resource_feature_check(test) &&
173-
validate_resctrl_feature_request("L3_MON", "llc_occupancy");
173+
resctrl_mon_feature_exists("L3_MON", "llc_occupancy");
174174
}
175175

176176
struct resctrl_test cmt_test = {

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
171171
static bool mba_feature_check(const struct resctrl_test *test)
172172
{
173173
return test_resource_feature_check(test) &&
174-
validate_resctrl_feature_request("L3_MON", "mbm_local_bytes");
174+
resctrl_mon_feature_exists("L3_MON", "mbm_local_bytes");
175175
}
176176

177177
struct resctrl_test mba_test = {

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int mbm_setup(const struct resctrl_test *test,
9797
return END_OF_TESTS;
9898

9999
/* Set up shemata with 100% allocation on the first run. */
100-
if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL))
100+
if (p->num_of_runs == 0 && resctrl_resource_exists("MB"))
101101
ret = write_schemata(p->ctrlgrp, "100", uparams->cpu, test->resource);
102102

103103
p->num_of_runs++;
@@ -140,8 +140,8 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
140140

141141
static bool mbm_feature_check(const struct resctrl_test *test)
142142
{
143-
return validate_resctrl_feature_request("L3_MON", "mbm_total_bytes") &&
144-
validate_resctrl_feature_request("L3_MON", "mbm_local_bytes");
143+
return resctrl_mon_feature_exists("L3_MON", "mbm_total_bytes") &&
144+
resctrl_mon_feature_exists("L3_MON", "mbm_local_bytes");
145145
}
146146

147147
struct resctrl_test mbm_test = {

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ int get_domain_id(const char *resource, int cpu_no, int *domain_id);
136136
int mount_resctrlfs(void);
137137
int umount_resctrlfs(void);
138138
int validate_bw_report_request(char *bw_report);
139-
bool validate_resctrl_feature_request(const char *resource, const char *feature);
139+
bool resctrl_resource_exists(const char *resource);
140+
bool resctrl_mon_feature_exists(const char *resource, const char *feature);
140141
bool test_resource_feature_check(const struct resctrl_test *test);
141142
char *fgrep(FILE *inf, const char *str);
142143
int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity);

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -708,20 +708,16 @@ char *fgrep(FILE *inf, const char *str)
708708
}
709709

710710
/*
711-
* validate_resctrl_feature_request - Check if requested feature is valid.
712-
* @resource: Required resource (e.g., MB, L3, L2, L3_MON, etc.)
713-
* @feature: Required monitor feature (in mon_features file). Can only be
714-
* set for L3_MON. Must be NULL for all other resources.
711+
* resctrl_resource_exists - Check if a resource is supported.
712+
* @resource: Resctrl resource (e.g., MB, L3, L2, L3_MON, etc.)
715713
*
716-
* Return: True if the resource/feature is supported, else false. False is
714+
* Return: True if the resource is supported, else false. False is
717715
* also returned if resctrl FS is not mounted.
718716
*/
719-
bool validate_resctrl_feature_request(const char *resource, const char *feature)
717+
bool resctrl_resource_exists(const char *resource)
720718
{
721719
char res_path[PATH_MAX];
722720
struct stat statbuf;
723-
char *res;
724-
FILE *inf;
725721
int ret;
726722

727723
if (!resource)
@@ -736,8 +732,25 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature)
736732
if (stat(res_path, &statbuf))
737733
return false;
738734

739-
if (!feature)
740-
return true;
735+
return true;
736+
}
737+
738+
/*
739+
* resctrl_mon_feature_exists - Check if requested monitoring feature is valid.
740+
* @resource: Resource that uses the mon_features file. Currently only L3_MON
741+
* is valid.
742+
* @feature: Required monitor feature (in mon_features file).
743+
*
744+
* Return: True if the feature is supported, else false.
745+
*/
746+
bool resctrl_mon_feature_exists(const char *resource, const char *feature)
747+
{
748+
char res_path[PATH_MAX];
749+
char *res;
750+
FILE *inf;
751+
752+
if (!feature || !resource)
753+
return false;
741754

742755
snprintf(res_path, sizeof(res_path), "%s/%s/mon_features", INFO_PATH, resource);
743756
inf = fopen(res_path, "r");
@@ -753,7 +766,7 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature)
753766

754767
bool test_resource_feature_check(const struct resctrl_test *test)
755768
{
756-
return validate_resctrl_feature_request(test->resource, NULL);
769+
return resctrl_resource_exists(test->resource);
757770
}
758771

759772
int filter_dmesg(void)

0 commit comments

Comments
 (0)