Skip to content

Commit da707d9

Browse files
rchatreshuahkh
authored andcommitted
selftests/resctrl: Simplify perf usage in CAT test
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>
1 parent ca2e4f4 commit da707d9

3 files changed

Lines changed: 7 additions & 25 deletions

File tree

tools/testing/selftests/resctrl/cache.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config)
1010
memset(pea, 0, sizeof(*pea));
1111
pea->type = PERF_TYPE_HARDWARE;
1212
pea->size = sizeof(*pea);
13-
pea->read_format = PERF_FORMAT_GROUP;
1413
pea->exclude_kernel = 1;
1514
pea->exclude_hv = 1;
1615
pea->exclude_idle = 1;
@@ -37,19 +36,13 @@ int perf_event_reset_enable(int pe_fd)
3736
return 0;
3837
}
3938

40-
void perf_event_initialize_read_format(struct perf_event_read *pe_read)
41-
{
42-
memset(pe_read, 0, sizeof(*pe_read));
43-
pe_read->nr = 1;
44-
}
45-
4639
int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no)
4740
{
4841
int pe_fd;
4942

5043
pe_fd = perf_event_open(pea, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
5144
if (pe_fd == -1) {
52-
ksft_perror("Error opening leader");
45+
ksft_perror("Unable to set up performance monitoring");
5346
return -1;
5447
}
5548

@@ -132,23 +125,23 @@ static int print_results_cache(const char *filename, pid_t bm_pid, __u64 llc_val
132125
*
133126
* Return: =0 on success. <0 on failure.
134127
*/
135-
int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
136-
const char *filename, pid_t bm_pid)
128+
int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid)
137129
{
130+
__u64 value;
138131
int ret;
139132

140133
/* Stop counters after one span to get miss rate */
141134
ret = ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);
142135
if (ret < 0)
143136
return ret;
144137

145-
ret = read(pe_fd, pe_read, sizeof(*pe_read));
138+
ret = read(pe_fd, &value, sizeof(value));
146139
if (ret == -1) {
147140
ksft_perror("Could not get perf value");
148141
return -1;
149142
}
150143

151-
return print_results_cache(filename, bm_pid, pe_read->values[0].value);
144+
return print_results_cache(filename, bm_pid, value);
152145
}
153146

154147
/*

tools/testing/selftests/resctrl/cat_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static int cat_test(const struct resctrl_test *test,
135135
struct resctrl_val_param *param,
136136
size_t span, unsigned long current_mask)
137137
{
138-
struct perf_event_read pe_read;
139138
struct perf_event_attr pea;
140139
cpu_set_t old_affinity;
141140
unsigned char *buf;
@@ -159,7 +158,6 @@ static int cat_test(const struct resctrl_test *test,
159158
goto reset_affinity;
160159

161160
perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES);
162-
perf_event_initialize_read_format(&pe_read);
163161
pe_fd = perf_open(&pea, bm_pid, uparams->cpu);
164162
if (pe_fd < 0) {
165163
ret = -1;
@@ -192,7 +190,7 @@ static int cat_test(const struct resctrl_test *test,
192190

193191
fill_cache_read(buf, span, true);
194192

195-
ret = perf_event_measure(pe_fd, &pe_read, param->filename, bm_pid);
193+
ret = perf_event_measure(pe_fd, param->filename, bm_pid);
196194
if (ret)
197195
goto free_buf;
198196
}

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ struct resctrl_val_param {
148148
struct fill_buf_param *fill_buf;
149149
};
150150

151-
struct perf_event_read {
152-
__u64 nr; /* The number of events */
153-
struct {
154-
__u64 value; /* The value of the event */
155-
} values[2];
156-
};
157-
158151
/*
159152
* Memory location that consumes values compiler must not optimize away.
160153
* Volatile ensures writes to this location cannot be optimized away by
@@ -210,11 +203,9 @@ unsigned int count_bits(unsigned long n);
210203
int snc_kernel_support(void);
211204

212205
void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
213-
void perf_event_initialize_read_format(struct perf_event_read *pe_read);
214206
int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no);
215207
int perf_event_reset_enable(int pe_fd);
216-
int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
217-
const char *filename, pid_t bm_pid);
208+
int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid);
218209
int measure_llc_resctrl(const char *filename, pid_t bm_pid);
219210
int minimize_l2_occupancy(const struct resctrl_test *test,
220211
const struct user_params *uparams,

0 commit comments

Comments
 (0)