summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/resctrl
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2023-12-15 18:05:13 +0300
committerShuah Khan <skhan@linuxfoundation.org>2024-02-13 23:56:45 +0300
commite73dda7ffd858a58ddeb9c53603ae14f2af8927c (patch)
tree4c82cbd67b593be648bd7829c648d0765fba1330 /tools/testing/selftests/resctrl
parentca1608875ae21bb40a7731b81bc0e2c95622d502 (diff)
downloadlinux-e73dda7ffd858a58ddeb9c53603ae14f2af8927c.tar.xz
selftests/resctrl: Add helper to convert L2/3 to integer
"L2"/"L3" conversion to integer is embedded into get_cache_size() which prevents reuse. Create a helper for the cache string to integer conversion to make it reusable. 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>
Diffstat (limited to 'tools/testing/selftests/resctrl')
-rw-r--r--tools/testing/selftests/resctrl/resctrlfs.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c
index fed6741edc5f..eab928c46f98 100644
--- a/tools/testing/selftests/resctrl/resctrlfs.c
+++ b/tools/testing/selftests/resctrl/resctrlfs.c
@@ -95,6 +95,23 @@ int umount_resctrlfs(void)
}
/*
+ * get_cache_level - Convert cache level from string to integer
+ * @cache_type: Cache level as string
+ *
+ * Return: cache level as integer or -1 if @cache_type is invalid.
+ */
+static int get_cache_level(const char *cache_type)
+{
+ if (!strcmp(cache_type, "L3"))
+ return 3;
+ if (!strcmp(cache_type, "L2"))
+ return 2;
+
+ ksft_print_msg("Invalid cache level\n");
+ return -1;
+}
+
+/*
* get_resource_id - Get socket number/l3 id for a specified CPU
* @cpu_no: CPU number
* @resource_id: Socket number or l3_id
@@ -144,14 +161,9 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size
int length, i, cache_num;
FILE *fp;
- if (!strcmp(cache_type, "L3")) {
- cache_num = 3;
- } else if (!strcmp(cache_type, "L2")) {
- cache_num = 2;
- } else {
- ksft_print_msg("Invalid cache level\n");
- return -1;
- }
+ cache_num = get_cache_level(cache_type);
+ if (cache_num < 0)
+ return cache_num;
sprintf(cache_path, "/sys/bus/cpu/devices/cpu%d/cache/index%d/size",
cpu_no, cache_num);