Skip to content

Commit 74e76cb

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Add resource_info_file_exists()
Feature checking done by resctrl_mon_feature_exists() covers features represented by the feature name presence inside the 'mon_features' file in /sys/fs/resctrl/info/L3_MON directory. There exists a different way to represent feature support and that is by the presence of 0 or 1 in a single file in the info/resource directory. In this case the filename represents what feature support is being indicated. Add a generic function to check file presence in the /sys/fs/resctrl/info/<RESOURCE> directory. 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 0061641 commit 74e76cb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ int umount_resctrlfs(void);
138138
int validate_bw_report_request(char *bw_report);
139139
bool resctrl_resource_exists(const char *resource);
140140
bool resctrl_mon_feature_exists(const char *resource, const char *feature);
141+
bool resource_info_file_exists(const char *resource, const char *file);
141142
bool test_resource_feature_check(const struct resctrl_test *test);
142143
char *fgrep(FILE *inf, const char *str);
143144
int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity);

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,31 @@ bool resctrl_mon_feature_exists(const char *resource, const char *feature)
764764
return !!res;
765765
}
766766

767+
/*
768+
* resource_info_file_exists - Check if a file is present inside
769+
* /sys/fs/resctrl/info/@resource.
770+
* @resource: Required resource (Eg: MB, L3, L2, etc.)
771+
* @file: Required file.
772+
*
773+
* Return: True if the /sys/fs/resctrl/info/@resource/@file exists, else false.
774+
*/
775+
bool resource_info_file_exists(const char *resource, const char *file)
776+
{
777+
char res_path[PATH_MAX];
778+
struct stat statbuf;
779+
780+
if (!file || !resource)
781+
return false;
782+
783+
snprintf(res_path, sizeof(res_path), "%s/%s/%s", INFO_PATH, resource,
784+
file);
785+
786+
if (stat(res_path, &statbuf))
787+
return false;
788+
789+
return true;
790+
}
791+
767792
bool test_resource_feature_check(const struct resctrl_test *test)
768793
{
769794
return resctrl_resource_exists(test->resource);

0 commit comments

Comments
 (0)