Re: [PATCH 14/24] selftests/resctrl: Move cat_val() to cat_test.c and rename to cat_test()

From: Maciej Wieczór-Retman
Date: Fri Oct 27 2023 - 07:51:37 EST


On 2023-10-24 at 12:26:24 +0300, Ilpo Järvinen wrote:
>diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
>index 2106cc3601d9..e71690a9bbb3 100644
>--- a/tools/testing/selftests/resctrl/cat_test.c
>+++ b/tools/testing/selftests/resctrl/cat_test.c
>@@ -111,6 +111,77 @@ void cat_test_cleanup(void)
> remove(RESULT_FILE_NAME2);
> }
>
>+/*
>+ * cat_test: execute CAT benchmark and measure LLC cache misses
>+ * @param: parameters passed to cat_test()
>+ * @span: buffer size for the benchmark
>+ *
>+ * Return: 0 on success. non-zero on failure.
>+ */
>+static int cat_test(struct resctrl_val_param *param, size_t span)
>+{
>+ int memflush = 1, operation = 0, ret = 0;
>+ char *resctrl_val = param->resctrl_val;
>+ static struct perf_event_read pe_read;

Is there a reason why this struct is declared as static?

>+ struct perf_event_attr pea;
>+ pid_t bm_pid;
>+ int pe_fd;
>+
>+ if (strcmp(param->filename, "") == 0)
>+ sprintf(param->filename, "stdio");
>+
>+ bm_pid = getpid();
>+
>+ /* Taskset benchmark to specified cpu */
>+ ret = taskset_benchmark(bm_pid, param->cpu_no);
>+ if (ret)
>+ return ret;
>+
>+ /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/
>+ ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp,
>+ resctrl_val);
>+ if (ret)
>+ return ret;
>+
>+ perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES);
>+ perf_event_initialize_read_format(&pe_read);
>+
>+ /* Test runs until the callback setup() tells the test to stop. */
>+ while (1) {
>+ ret = param->setup(param);
>+ if (ret == END_OF_TESTS) {
>+ ret = 0;
>+ break;
>+ }
>+ if (ret < 0)
>+ break;
>+ pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no);
>+ if (pe_fd < 0) {
>+ ret = -1;
>+ break;
>+ }
>+
>+ if (run_fill_buf(span, memflush, operation, true)) {
>+ fprintf(stderr, "Error-running fill buffer\n");
>+ ret = -1;
>+ goto pe_close;
>+ }
>+
>+ sleep(1);
>+ ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid);
>+ if (ret)
>+ goto pe_close;
>+
>+ close(pe_fd);
>+ }
>+
>+ return ret;
>+
>+pe_close:
>+ close(pe_fd);
>+ return ret;
>+}
>+
> int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
> {
> unsigned long l_mask, l_mask_1;

--
Kind regards
Maciej Wieczór-Retman