Skip to content

Commit e331ac1

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Add a helper for the non-contiguous test
The CAT non-contiguous selftests have to read the file responsible for reporting support of non-contiguous CBMs in kernel (resctrl). Then the test compares if that information matches what is reported by CPUID output. Add a generic helper function to read an unsigned number from /sys/fs/resctrl/info/<RESOURCE>/<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 5339792 commit e331ac1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
162162
int get_full_cbm(const char *cache_type, unsigned long *mask);
163163
int get_mask_no_shareable(const char *cache_type, unsigned long *mask);
164164
int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size);
165+
int resource_info_unsigned_get(const char *resource, const char *filename, unsigned int *val);
165166
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
166167
int signal_handler_register(void);
167168
void signal_handler_unregister(void);

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,42 @@ static int get_bit_mask(const char *filename, unsigned long *mask)
249249
return 0;
250250
}
251251

252+
/*
253+
* resource_info_unsigned_get - Read an unsigned value from
254+
* /sys/fs/resctrl/info/@resource/@filename
255+
* @resource: Resource name that matches directory name in
256+
* /sys/fs/resctrl/info
257+
* @filename: File in /sys/fs/resctrl/info/@resource
258+
* @val: Contains read value on success.
259+
*
260+
* Return: = 0 on success, < 0 on failure. On success the read
261+
* value is saved into @val.
262+
*/
263+
int resource_info_unsigned_get(const char *resource, const char *filename,
264+
unsigned int *val)
265+
{
266+
char file_path[PATH_MAX];
267+
FILE *fp;
268+
269+
snprintf(file_path, sizeof(file_path), "%s/%s/%s", INFO_PATH, resource,
270+
filename);
271+
272+
fp = fopen(file_path, "r");
273+
if (!fp) {
274+
ksft_print_msg("Error opening %s: %m\n", file_path);
275+
return -1;
276+
}
277+
278+
if (fscanf(fp, "%u", val) <= 0) {
279+
ksft_print_msg("Could not get contents of %s: %m\n", file_path);
280+
fclose(fp);
281+
return -1;
282+
}
283+
284+
fclose(fp);
285+
return 0;
286+
}
287+
252288
/*
253289
* create_bit_mask- Create bit mask from start, len pair
254290
* @start: LSB of the mask

0 commit comments

Comments
 (0)