diff options
| author | Mark Brown <broonie@kernel.org> | 2026-10-08 11:39:03 +0200 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2026-10-08 11:39:03 +0200 |
| commit | b41c4e782aee047ea1160e0f7a412d093bc72df8 (patch) | |
| tree | 0f2e7ad12de2c9c3226e9fa16aef383246cfbd66 | |
| parent | d50f8c8271e9670195160656681039cc83ba39fb (diff) | |
| parent | 30af56a227e27b892d34bc44c23298b5274913e3 (diff) | |
| download | linux-next-b41c4e782aee047ea1160e0f7a412d093bc72df8.tar.gz linux-next-b41c4e782aee047ea1160e0f7a412d093bc72df8.zip | |
Merge branch 'next' of https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
| -rw-r--r-- | tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/resctrl/cat_test.c | 23 | ||||
| -rw-r--r-- | tools/testing/selftests/resctrl/mba_test.c | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/resctrl/mbm_test.c | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/resctrl/resctrl.h | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/resctrl/resctrl_val.c | 169 |
6 files changed, 115 insertions, 83 deletions
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc index ba19b81cef39..0688a5c47d1e 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc @@ -5,7 +5,7 @@ :;: "Add an event on function without name" ;: -FUNC=`grep " [tT] .*vfs_read$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "` +FUNC=`grep " [tT] .*vfs_read$" /proc/kallsyms | grep -v __gcov | tail -n 1 | cut -f 3 -d " "` [ "x" != "x$FUNC" ] || exit_unresolved echo "p $FUNC" > kprobe_events PROBE_NAME=`echo $FUNC | tr ".:" "_"` diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 371a2f26dc47..0a417267dd74 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -357,11 +357,32 @@ static bool noncont_cat_feature_check(const struct resctrl_test *test) return resource_info_file_exists(test->resource, "sparse_masks"); } +static bool cat_feature_check(const struct resctrl_test *test) +{ + unsigned long mask; + + if (!test_resource_feature_check(test)) + return false; + + /* + * Test requires an exclusive cache portion. Some platforms may + * legitimately report all bits as shareable, skip the test if that + * is the case. + */ + if (get_mask_no_shareable(test->resource, &mask)) { + ksft_print_msg("All %s bits are shareable, test requires an exclusive cache portion\n", + test->resource); + return false; + } + + return true; +} + struct resctrl_test l3_cat_test = { .name = "L3_CAT", .group = "CAT", .resource = "L3", - .feature_check = test_resource_feature_check, + .feature_check = cat_feature_check, .run_test = cat_run_test, .cleanup = cat_test_cleanup, }; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 39cee9898359..4bb1a82eb195 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -166,6 +166,7 @@ static int check_results(void) static void mba_test_cleanup(void) { + cleanup_read_mem_bw_imc(); remove(RESULT_FILE_NAME); } diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 6dbbc3b76003..68c89f50a34a 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -125,6 +125,7 @@ static int mbm_measure(const struct user_params *uparams, static void mbm_test_cleanup(void) { + cleanup_read_mem_bw_imc(); remove(RESULT_FILE_NAME); } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 175101022bf3..a7556cdae0de 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -24,6 +24,7 @@ #include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/bits.h> +#include <linux/list.h> #include "kselftest.h" #define MB (1024 * 1024) @@ -183,6 +184,7 @@ void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); ssize_t get_fill_buf_size(int cpu_no, const char *cache_type); int initialize_read_mem_bw_imc(void); +void cleanup_read_mem_bw_imc(void); int measure_read_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid); void initialize_mem_bw_resctrl(const struct resctrl_val_param *param, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index f20d2194c35f..7e7d0f9cc249 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -14,7 +14,6 @@ #define READ_FILE_NAME "cas_count_read" #define DYN_PMU_PATH "/sys/bus/event_source/devices" #define SCALE 0.00006103515625 -#define MAX_IMCS 40 #define MAX_TOKENS 5 #define CON_MBM_LOCAL_BYTES_PATH \ @@ -28,6 +27,7 @@ struct membw_read_format { }; struct imc_counter_config { + struct list_head entry; __u32 type; __u64 event; __u64 umask; @@ -36,44 +36,40 @@ struct imc_counter_config { }; static char mbm_total_path[1024]; -static int imcs; -static struct imc_counter_config imc_counters_config[MAX_IMCS]; +LIST_HEAD(imc_counters_list); static const struct resctrl_test *current_test; -static void read_mem_bw_initialize_perf_event_attr(int i) +static void read_mem_bw_initialize_perf_event_attr(struct imc_counter_config *imc_counter) { - memset(&imc_counters_config[i].pe, 0, - sizeof(struct perf_event_attr)); - imc_counters_config[i].pe.type = imc_counters_config[i].type; - imc_counters_config[i].pe.size = sizeof(struct perf_event_attr); - imc_counters_config[i].pe.disabled = 1; - imc_counters_config[i].pe.inherit = 1; - imc_counters_config[i].pe.exclude_guest = 0; - imc_counters_config[i].pe.config = - imc_counters_config[i].umask << 8 | - imc_counters_config[i].event; - imc_counters_config[i].pe.sample_type = PERF_SAMPLE_IDENTIFIER; - imc_counters_config[i].pe.read_format = + memset(&imc_counter->pe, 0, sizeof(struct perf_event_attr)); + imc_counter->pe.type = imc_counter->type; + imc_counter->pe.size = sizeof(struct perf_event_attr); + imc_counter->pe.disabled = 1; + imc_counter->pe.inherit = 1; + imc_counter->pe.exclude_guest = 0; + imc_counter->pe.config = imc_counter->umask << 8 | imc_counter->event; + imc_counter->pe.sample_type = PERF_SAMPLE_IDENTIFIER; + imc_counter->pe.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING; } -static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(int i) +static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(struct imc_counter_config *imc_counter) { - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_RESET, 0); - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_ENABLE, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_RESET, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_ENABLE, 0); } -static void read_mem_bw_ioctl_perf_event_ioc_disable(int i) +static void read_mem_bw_ioctl_perf_event_ioc_disable(struct imc_counter_config *imc_counter) { - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_DISABLE, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_DISABLE, 0); } /* * get_read_event_and_umask: Parse config into event and umask * @cas_count_cfg: Config - * @count: iMC number + * @imc_counter: iMC counter config */ -static void get_read_event_and_umask(char *cas_count_cfg, unsigned int count) +static void get_read_event_and_umask(char *cas_count_cfg, struct imc_counter_config *imc_counter) { char *token[MAX_TOKENS]; int i = 0; @@ -87,21 +83,20 @@ static void get_read_event_and_umask(char *cas_count_cfg, unsigned int count) if (!token[i]) break; if (strcmp(token[i], "event") == 0) - imc_counters_config[count].event = strtol(token[i + 1], NULL, 16); + imc_counter->event = strtol(token[i + 1], NULL, 16); if (strcmp(token[i], "umask") == 0) - imc_counters_config[count].umask = strtol(token[i + 1], NULL, 16); + imc_counter->umask = strtol(token[i + 1], NULL, 16); } } -static int open_perf_read_event(int i, int cpu_no) +static int open_perf_read_event(int cpu_no, struct imc_counter_config *imc_counter) { - imc_counters_config[i].fd = - perf_event_open(&imc_counters_config[i].pe, -1, cpu_no, -1, - PERF_FLAG_FD_CLOEXEC); + imc_counter->fd = perf_event_open(&imc_counter->pe, -1, cpu_no, -1, + PERF_FLAG_FD_CLOEXEC); - if (imc_counters_config[i].fd == -1) { + if (imc_counter->fd == -1) { fprintf(stderr, "Error opening leader %llx\n", - imc_counters_config[i].pe.config); + imc_counter->pe.config); return -1; } @@ -109,11 +104,11 @@ static int open_perf_read_event(int i, int cpu_no) return 0; } -static int parse_imc_read_bw_events(char *imc_dir, unsigned int type, - unsigned int *count) +static int parse_imc_read_bw_events(char *imc_dir, unsigned int type) { char imc_events_dir[PATH_MAX], imc_counter_cfg[PATH_MAX]; - unsigned int orig_count = *count; + struct imc_counter_config *imc_counter; + bool found_event = false; char cas_count_cfg[1024]; struct dirent *ep; int path_len; @@ -126,13 +121,13 @@ static int parse_imc_read_bw_events(char *imc_dir, unsigned int type, imc_dir); if (path_len >= sizeof(imc_events_dir)) { ksft_print_msg("Unable to create path to %sevents\n", imc_dir); - return -1; + goto out; } dp = opendir(imc_events_dir); if (!dp) { ksft_perror("Unable to open PMU events directory"); - return -1; + goto out; } while ((ep = readdir(dp))) { @@ -163,28 +158,33 @@ static int parse_imc_read_bw_events(char *imc_dir, unsigned int type, ksft_perror("Could not get iMC cas count read"); goto out_close; } - if (*count >= MAX_IMCS) { - ksft_print_msg("Maximum iMC count exceeded\n"); + imc_counter = calloc(1, sizeof(*imc_counter)); + if (!imc_counter) { + ksft_perror("Unable to allocate memory for iMC counters"); goto out_close; } - imc_counters_config[*count].type = type; - get_read_event_and_umask(cas_count_cfg, *count); - /* Do not fail after incrementing *count. */ - *count += 1; + imc_counter->type = type; + get_read_event_and_umask(cas_count_cfg, imc_counter); + list_add(&imc_counter->entry, &imc_counters_list); + found_event = true; } - if (*count == orig_count) { + if (!found_event) { ksft_print_msg("Unable to find events in %s\n", imc_events_dir); goto out_close; } ret = 0; out_close: closedir(dp); +out: + if (ret) + cleanup_read_mem_bw_imc(); + return ret; } /* Get type and config of an iMC counter's read event. */ -static int read_from_imc_dir(char *imc_dir, unsigned int *count) +static int read_from_imc_dir(char *imc_dir) { char imc_counter_type[PATH_MAX]; unsigned int type; @@ -212,7 +212,7 @@ static int read_from_imc_dir(char *imc_dir, unsigned int *count) ksft_perror("Could not get iMC type"); return -1; } - ret = parse_imc_read_bw_events(imc_dir, type, count); + ret = parse_imc_read_bw_events(imc_dir, type); if (ret) { ksft_print_msg("Unable to parse bandwidth event and umask\n"); return ret; @@ -222,21 +222,18 @@ static int read_from_imc_dir(char *imc_dir, unsigned int *count) } /* - * A system can have 'n' number of iMC (Integrated Memory Controller) - * counters, get that 'n'. Discover the properties of the available - * counters in support of needed performance measurement via perf. - * For each iMC counter get it's type and config. Also obtain each - * counter's event and umask for the memory read events that will be - * measured. + * Discover the properties of the available iMC (Integrated Memory Controller) + * counters in support of needed performance measurement via perf. For each iMC + * counter get it's type and config. Also obtain each counter's event and umask + * for the memory read events that will be measured. * - * Enumerate all these details into an array of structures. + * Enumerate all these details into a linked list of structures. * * Return: >= 0 on success. < 0 on failure. */ -static int num_of_imcs(void) +static int enumerate_imcs(void) { char imc_dir[512], *temp; - unsigned int count = 0; struct dirent *ep; int ret; DIR *dp; @@ -265,7 +262,7 @@ static int num_of_imcs(void) if (temp[0] >= '0' && temp[0] <= '9') { sprintf(imc_dir, "%s/%s/", DYN_PMU_PATH, ep->d_name); - ret = read_from_imc_dir(imc_dir, &count); + ret = read_from_imc_dir(imc_dir); if (ret) { closedir(dp); @@ -274,7 +271,7 @@ static int num_of_imcs(void) } } closedir(dp); - if (count == 0) { + if (list_empty(&imc_counters_list)) { ksft_print_msg("Unable to find iMC counters\n"); return -1; @@ -285,31 +282,42 @@ static int num_of_imcs(void) return -1; } - return count; + return 0; } int initialize_read_mem_bw_imc(void) { - int imc; + struct imc_counter_config *imc_counter; + int ret; - imcs = num_of_imcs(); - if (imcs <= 0) - return imcs; + ret = enumerate_imcs(); + if (ret < 0) + return ret; /* Initialize perf_event_attr structures for all iMC's */ - for (imc = 0; imc < imcs; imc++) - read_mem_bw_initialize_perf_event_attr(imc); + list_for_each_entry(imc_counter, &imc_counters_list, entry) + read_mem_bw_initialize_perf_event_attr(imc_counter); return 0; } +void cleanup_read_mem_bw_imc(void) +{ + struct imc_counter_config *imc_counter, *tmp; + + list_for_each_entry_safe(imc_counter, tmp, &imc_counters_list, entry) { + list_del(&imc_counter->entry); + free(imc_counter); + } +} + static void perf_close_imc_read_mem_bw(void) { - int mc; + struct imc_counter_config *imc_counter; - for (mc = 0; mc < imcs; mc++) { - if (imc_counters_config[mc].fd != -1) - close(imc_counters_config[mc].fd); + list_for_each_entry(imc_counter, &imc_counters_list, entry) { + if (imc_counter->fd != -1) + close(imc_counter->fd); } } @@ -321,13 +329,14 @@ static void perf_close_imc_read_mem_bw(void) */ static int perf_open_imc_read_mem_bw(int cpu_no) { - int imc, ret; + struct imc_counter_config *imc_counter; + int ret; - for (imc = 0; imc < imcs; imc++) - imc_counters_config[imc].fd = -1; + list_for_each_entry(imc_counter, &imc_counters_list, entry) + imc_counter->fd = -1; - for (imc = 0; imc < imcs; imc++) { - ret = open_perf_read_event(imc, cpu_no); + list_for_each_entry(imc_counter, &imc_counters_list, entry) { + ret = open_perf_read_event(cpu_no, imc_counter); if (ret) goto close_fds; } @@ -347,16 +356,16 @@ close_fds: */ static void do_imc_read_mem_bw_test(void) { - int imc; + struct imc_counter_config *imc_counter; - for (imc = 0; imc < imcs; imc++) - read_mem_bw_ioctl_perf_event_ioc_reset_enable(imc); + list_for_each_entry(imc_counter, &imc_counters_list, entry) + read_mem_bw_ioctl_perf_event_ioc_reset_enable(imc_counter); sleep(1); /* Stop counters after a second to get results. */ - for (imc = 0; imc < imcs; imc++) - read_mem_bw_ioctl_perf_event_ioc_disable(imc); + list_for_each_entry(imc_counter, &imc_counters_list, entry) + read_mem_bw_ioctl_perf_event_ioc_disable(imc_counter); } /* @@ -371,17 +380,15 @@ static void do_imc_read_mem_bw_test(void) static int get_read_mem_bw_imc(float *bw_imc) { float reads = 0, of_mul_read = 1; - int imc; + struct imc_counter_config *r; /* * Log read event values from all iMC counters into * struct imc_counter_config. * Take overflow into consideration before calculating total bandwidth. */ - for (imc = 0; imc < imcs; imc++) { + list_for_each_entry(r, &imc_counters_list, entry) { struct membw_read_format measurement; - struct imc_counter_config *r = - &imc_counters_config[imc]; if (read(r->fd, &measurement, sizeof(measurement)) == -1) { ksft_perror("Couldn't get read bandwidth through iMC"); |
