summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/resctrl/cat_test.c
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2023-12-15 18:05:09 +0300
committerShuah Khan <skhan@linuxfoundation.org>2024-02-13 23:56:45 +0300
commit6c8cb747d071cf72c2930e09bb20ab3eabfe62ff (patch)
treef8d901c3a8c414569a524e033c606830ae17d00d /tools/testing/selftests/resctrl/cat_test.c
parent205de6ddd7fff9340bd5e4b68105f28120671c6b (diff)
downloadlinux-6c8cb747d071cf72c2930e09bb20ab3eabfe62ff.tar.xz
selftests/resctrl: Restore the CPU affinity after CAT test
CAT test does not reset the CPU affinity after the benchmark. This is relatively harmless as is because CAT test is the last benchmark to run, however, more tests may be added later. Store the CPU affinity the first time taskset_benchmark() is run and add taskset_restore() which the test can call to reset the CPU mask to its original value. 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/cat_test.c')
-rw-r--r--tools/testing/selftests/resctrl/cat_test.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index b79916069788..fa95433297c9 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -156,6 +156,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
char *resctrl_val = param->resctrl_val;
struct perf_event_read pe_read;
struct perf_event_attr pea;
+ cpu_set_t old_affinity;
unsigned char *buf;
char schemata[64];
int ret, i, pe_fd;
@@ -167,7 +168,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
bm_pid = getpid();
/* Taskset benchmark to specified cpu */
- ret = taskset_benchmark(bm_pid, param->cpu_no);
+ ret = taskset_benchmark(bm_pid, param->cpu_no, &old_affinity);
if (ret)
return ret;
@@ -175,13 +176,15 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp,
resctrl_val);
if (ret)
- return ret;
+ goto reset_affinity;
perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES);
perf_event_initialize_read_format(&pe_read);
pe_fd = perf_open(&pea, bm_pid, param->cpu_no);
- if (pe_fd < 0)
- return pe_fd;
+ if (pe_fd < 0) {
+ ret = -1;
+ goto reset_affinity;
+ }
buf = alloc_buffer(span, 1);
if (!buf) {
@@ -220,6 +223,8 @@ free_buf:
free(buf);
pe_close:
close(pe_fd);
+reset_affinity:
+ taskset_restore(bm_pid, &old_affinity);
return ret;
}