summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/resctrl/cache.c
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2023-12-15 17:05:05 +0200
committerShuah Khan <skhan@linuxfoundation.org>2024-02-13 13:56:44 -0700
commit2892731ec2893252cdbc256a2bd5436b7fd94cf7 (patch)
tree832d49d9b5237cc11dc96ff23b914ba31231abad /tools/testing/selftests/resctrl/cache.c
parent433f437b3ae2ed4e318ecd5233c82f6936e78e82 (diff)
downloadlinux-next-2892731ec2893252cdbc256a2bd5436b7fd94cf7.tar.gz
linux-next-2892731ec2893252cdbc256a2bd5436b7fd94cf7.zip
selftests/resctrl: Open perf fd before start & add error handling
Perf fd (pe_fd) is opened, reset, and enabled during every test the CAT selftest runs. Also, ioctl(pe_fd, ...) calls are not error checked even if ioctl() could return an error. Open perf fd only once before the tests and only reset and enable the counter within the test loop. Add error checking to pe_fd ioctl() calls. 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/cache.c')
-rw-r--r--tools/testing/selftests/resctrl/cache.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 319d0cdd7225..1b339d6bbff1 100644
--- a/tools/testing/selftests/resctrl/cache.c
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -22,10 +22,19 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config)
}
/* Start counters to log values */
-static void perf_event_reset_enable(int pe_fd)
+int perf_event_reset_enable(int pe_fd)
{
- ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0);
- ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0);
+ int ret;
+
+ ret = ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0);
+ if (ret < 0)
+ return ret;
+
+ ret = ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0);
+ if (ret < 0)
+ return ret;
+
+ return 0;
}
void perf_event_initialize_read_format(struct perf_event_read *pe_read)
@@ -129,7 +138,9 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
int ret;
/* Stop counters after one span to get miss rate */
- ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);
+ ret = ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);
+ if (ret < 0)
+ return ret;
ret = read(pe_fd, pe_read, sizeof(*pe_read));
if (ret == -1) {