]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/resctrl: Simplify perf usage in CAT test
authorReinette Chatre <reinette.chatre@intel.com>
Sat, 4 Apr 2026 01:56:08 +0000 (18:56 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 5 May 2026 00:40:02 +0000 (18:40 -0600)
The CAT test relies on the PERF_COUNT_HW_CACHE_MISSES event to determine if
modifying a cache portion size is successful. This event is configured to
report the data as part of an event group, but no other events are added to
the group.

Remove the unnecessary PERF_FORMAT_GROUP format setting. This eliminates
the need for struct perf_event_read and results in read() of the associated
file descriptor to return just one value associated with the
PERF_COUNT_HW_CACHE_MISSES event of interest.

Link: https://lore.kernel.org/r/fb69325eba5031b735fa79effaaacd797c9c6040.1775266384.git.reinette.chatre@intel.com
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Chen Yu <yu.c.chen@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/cache.c
tools/testing/selftests/resctrl/cat_test.c
tools/testing/selftests/resctrl/resctrl.h

index bef71b6feacc608fe4cdfb56f32357758a337b11..df9bea584a2d476cfe3bd7d4d594cfcfb5f8bf13 100644 (file)
@@ -10,7 +10,6 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config)
        memset(pea, 0, sizeof(*pea));
        pea->type = PERF_TYPE_HARDWARE;
        pea->size = sizeof(*pea);
-       pea->read_format = PERF_FORMAT_GROUP;
        pea->exclude_kernel = 1;
        pea->exclude_hv = 1;
        pea->exclude_idle = 1;
@@ -37,19 +36,13 @@ int perf_event_reset_enable(int pe_fd)
        return 0;
 }
 
-void perf_event_initialize_read_format(struct perf_event_read *pe_read)
-{
-       memset(pe_read, 0, sizeof(*pe_read));
-       pe_read->nr = 1;
-}
-
 int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no)
 {
        int pe_fd;
 
        pe_fd = perf_event_open(pea, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
        if (pe_fd == -1) {
-               ksft_perror("Error opening leader");
+               ksft_perror("Unable to set up performance monitoring");
                return -1;
        }
 
@@ -132,9 +125,9 @@ static int print_results_cache(const char *filename, pid_t bm_pid, __u64 llc_val
  *
  * Return: =0 on success. <0 on failure.
  */
-int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
-                      const char *filename, pid_t bm_pid)
+int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid)
 {
+       __u64 value;
        int ret;
 
        /* Stop counters after one span to get miss rate */
@@ -142,13 +135,13 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
        if (ret < 0)
                return ret;
 
-       ret = read(pe_fd, pe_read, sizeof(*pe_read));
+       ret = read(pe_fd, &value, sizeof(value));
        if (ret == -1) {
                ksft_perror("Could not get perf value");
                return -1;
        }
 
-       return print_results_cache(filename, bm_pid, pe_read->values[0].value);
+       return print_results_cache(filename, bm_pid, value);
 }
 
 /*
index 8bc47f06679a686c76d86f9c578e855bfbc10283..6aac03147d411804832b153fa07125672267f2da 100644 (file)
@@ -135,7 +135,6 @@ static int cat_test(const struct resctrl_test *test,
                    struct resctrl_val_param *param,
                    size_t span, unsigned long current_mask)
 {
-       struct perf_event_read pe_read;
        struct perf_event_attr pea;
        cpu_set_t old_affinity;
        unsigned char *buf;
@@ -159,7 +158,6 @@ static int cat_test(const struct resctrl_test *test,
                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, uparams->cpu);
        if (pe_fd < 0) {
                ret = -1;
@@ -192,7 +190,7 @@ static int cat_test(const struct resctrl_test *test,
 
                        fill_cache_read(buf, span, true);
 
-                       ret = perf_event_measure(pe_fd, &pe_read, param->filename, bm_pid);
+                       ret = perf_event_measure(pe_fd, param->filename, bm_pid);
                        if (ret)
                                goto free_buf;
                }
index 3bad2d80c09b2f3646fd8645a6fbe1017e633722..175101022bf3c46c2e82bdeb751fe194ec6df126 100644 (file)
@@ -148,13 +148,6 @@ struct resctrl_val_param {
        struct fill_buf_param   *fill_buf;
 };
 
-struct perf_event_read {
-       __u64 nr;                       /* The number of events */
-       struct {
-               __u64 value;            /* The value of the event */
-       } values[2];
-};
-
 /*
  * Memory location that consumes values compiler must not optimize away.
  * Volatile ensures writes to this location cannot be optimized away by
@@ -210,11 +203,9 @@ unsigned int count_bits(unsigned long n);
 int snc_kernel_support(void);
 
 void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
-void perf_event_initialize_read_format(struct perf_event_read *pe_read);
 int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no);
 int perf_event_reset_enable(int pe_fd);
-int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
-                      const char *filename, pid_t bm_pid);
+int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid);
 int measure_llc_resctrl(const char *filename, pid_t bm_pid);
 int minimize_l2_occupancy(const struct resctrl_test *test,
                          const struct user_params *uparams,