Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf btf: Make the sigtrap test helper to find a member by name widely available

By introducing a tools/perf/util/btf.c to collect utilities not yet
available via libbpf, the first being a way to find a member by name
once we get the type_id for the struct.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+41 -17
+3 -17
tools/perf/tests/sigtrap.c
··· 56 56 57 57 #ifdef HAVE_BPF_SKEL 58 58 #include <bpf/btf.h> 59 + #include <util/btf.h> 59 60 60 61 static struct btf *btf; 61 62 ··· 74 73 btf = NULL; 75 74 } 76 75 77 - static const struct btf_member *__btf_type__find_member_by_name(int type_id, const char *member_name) 78 - { 79 - const struct btf_type *t = btf__type_by_id(btf, type_id); 80 - const struct btf_member *m; 81 - int i; 82 - 83 - for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) { 84 - const char *current_member_name = btf__name_by_offset(btf, m->name_off); 85 - if (!strcmp(current_member_name, member_name)) 86 - return m; 87 - } 88 - 89 - return NULL; 90 - } 91 - 92 76 static bool attr_has_sigtrap(void) 93 77 { 94 78 int id; ··· 87 101 if (id < 0) 88 102 return false; 89 103 90 - return __btf_type__find_member_by_name(id, "sigtrap") != NULL; 104 + return __btf_type__find_member_by_name(btf, id, "sigtrap") != NULL; 91 105 } 92 106 93 107 static bool kernel_with_sleepable_spinlocks(void) ··· 105 119 return false; 106 120 107 121 // Only RT has a "lock" member for "struct spinlock" 108 - member = __btf_type__find_member_by_name(id, "lock"); 122 + member = __btf_type__find_member_by_name(btf, id, "lock"); 109 123 if (member == NULL) 110 124 return false; 111 125
+1
tools/perf/util/Build
··· 168 168 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf-filter.o 169 169 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf-filter-flex.o 170 170 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf-filter-bison.o 171 + perf-util-$(CONFIG_PERF_BPF_SKEL) += btf.o 171 172 172 173 ifeq ($(CONFIG_LIBTRACEEVENT),y) 173 174 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_lock_contention.o
+27
tools/perf/util/btf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Arnaldo Carvalho de Melo <acme@redhat.com> 4 + * 5 + * Copyright (C) 2024, Red Hat, Inc 6 + */ 7 + 8 + #include <bpf/btf.h> 9 + #include <util/btf.h> 10 + #include <string.h> 11 + 12 + const struct btf_member *__btf_type__find_member_by_name(struct btf *btf, 13 + int type_id, const char *member_name) 14 + { 15 + const struct btf_type *t = btf__type_by_id(btf, type_id); 16 + const struct btf_member *m; 17 + int i; 18 + 19 + for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) { 20 + const char *current_member_name = btf__name_by_offset(btf, m->name_off); 21 + 22 + if (!strcmp(current_member_name, member_name)) 23 + return m; 24 + } 25 + 26 + return NULL; 27 + }
+10
tools/perf/util/btf.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __PERF_UTIL_BTF 3 + #define __PERF_UTIL_BTF 1 4 + 5 + struct btf; 6 + struct btf_member; 7 + 8 + const struct btf_member *__btf_type__find_member_by_name(struct btf *btf, 9 + int type_id, const char *member_name); 10 + #endif // __PERF_UTIL_BTF