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:00 +0300
committerShuah Khan <skhan@linuxfoundation.org>2024-02-13 23:56:44 +0300
commit3c6bfc9cc7f0e3bed76ff0a7ed5bf89059b7b0bd (patch)
tree84e6b5900fa7e221074a33ddef9f28bd19a02339 /tools/testing/selftests/resctrl
parent33403bc7fe2ec35cd87e4f11db4d1a1da1e5ce12 (diff)
downloadlinux-3c6bfc9cc7f0e3bed76ff0a7ed5bf89059b7b0bd.tar.xz
selftests/resctrl: Remove nested calls in perf event handling
Perf event handling has functions that are the sole caller of another perf event handling related function: - reset_enable_llc_perf() calls perf_event_open_llc_miss() - perf_event_measure() calls get_llc_perf() Remove the extra layer of calls to make the code easier to follow by moving the code into the calling function. 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/cache.c64
1 files changed, 14 insertions, 50 deletions
diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 11d1a6ce14c2..4f846a2e5e26 100644
--- a/tools/testing/selftests/resctrl/cache.c
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -29,24 +29,13 @@ static void initialize_perf_event_attr(void)
pea_llc_miss.disabled = 1;
}
+/* Start counters to log values */
static void ioctl_perf_event_ioc_reset_enable(void)
{
ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0);
ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0);
}
-static int perf_event_open_llc_miss(pid_t pid, int cpu_no)
-{
- fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1,
- PERF_FLAG_FD_CLOEXEC);
- if (fd_lm == -1) {
- ksft_perror("Error opening leader");
- return -1;
- }
-
- return 0;
-}
-
static void initialize_llc_perf(void)
{
memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr));
@@ -62,42 +51,13 @@ static void initialize_llc_perf(void)
static int reset_enable_llc_perf(pid_t pid, int cpu_no)
{
- int ret = 0;
-
- ret = perf_event_open_llc_miss(pid, cpu_no);
- if (ret < 0)
- return ret;
-
- /* Start counters to log values */
- ioctl_perf_event_ioc_reset_enable();
-
- return 0;
-}
-
-/*
- * get_llc_perf: llc cache miss through perf events
- * @llc_perf_miss: LLC miss counter that is filled on success
- *
- * Perf events like HW_CACHE_MISSES could be used to validate number of
- * cache lines allocated.
- *
- * Return: =0 on success. <0 on failure.
- */
-static int get_llc_perf(__u64 *llc_perf_miss)
-{
- int ret;
-
- /* Stop counters after one span to get miss rate */
-
- ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0);
-
- ret = read(fd_lm, &rf_cqm, sizeof(struct read_format));
- if (ret == -1) {
- ksft_perror("Could not get llc misses through perf");
+ fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
+ if (fd_lm == -1) {
+ ksft_perror("Error opening leader");
return -1;
}
- *llc_perf_miss = rf_cqm.values[0].value;
+ ioctl_perf_event_ioc_reset_enable();
return 0;
}
@@ -178,14 +138,18 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value
*/
static int perf_event_measure(const char *filename, int bm_pid)
{
- __u64 llc_perf_miss = 0;
int ret;
- ret = get_llc_perf(&llc_perf_miss);
- if (ret < 0)
- return ret;
+ /* Stop counters after one span to get miss rate */
+ ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0);
+
+ ret = read(fd_lm, &rf_cqm, sizeof(struct read_format));
+ if (ret == -1) {
+ ksft_perror("Could not get perf value");
+ return -1;
+ }
- return print_results_cache(filename, bm_pid, llc_perf_miss);
+ return print_results_cache(filename, bm_pid, rf_cqm.values[0].value);
}
/*