Skip to content

Commit e8f60cd

Browse files
committed
Merge tag 'perf-tools-fixes-for-v6.2-2-2023-01-11' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Make 'perf kmem' cope with the removal of some kmem:kmem_cache_alloc_node and kmem:kmalloc_node in the 11e9734 ("mm/slab_common: unify NUMA and UMA version of tracepoints") commit, making sure it works with Linux >= 6.2 as well as with older kernels where those tracepoints are present. - Also make it handle the new "node" kmem:kmalloc and kmem:kmem_cache_alloc tracepoint field introduced in that same commit. - Fix hardware tracing PMU address filter duplicate symbol selection, that was preventing to match with static functions with the same name present in different object files. - Fix regression on what linux/types.h file gets used to build the "BPF prologue" 'perf test' entry, the system one lacks the fmode_t definition used in this test, so provide that type in the test itself. - Avoid build breakage with libbpf < 0.8.0 + LIBBPF_DYNAMIC=1. If the user asks for linking with the libbpf package provided by the distro, then it has to be >= 0.8.0. Using the libbpf supplied with the kernel would be a fallback in that case. - Fix the build when libbpf isn't available or explicitly disabled via NO_LIBBPF=1. - Don't try to install libtraceevent plugins as its not anymore in the kernel sources and will thus always fail. * tag 'perf-tools-fixes-for-v6.2-2-2023-01-11' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf auxtrace: Fix address filter duplicate symbol selection perf bpf: Avoid build breakage with libbpf < 0.8.0 + LIBBPF_DYNAMIC=1 perf build: Fix build error when NO_LIBBPF=1 perf tools: Don't install libtraceevent plugins as its not anymore in the kernel sources perf kmem: Support field "node" in evsel__process_alloc_event() coping with recent tracepoint restructuring perf kmem: Support legacy tracepoints perf build: Properly guard libbpf includes perf tests bpf prologue: Fix bpf-script-test-prologue test compile issue with clang
2 parents 7dd4b80 + cf12983 commit e8f60cd

File tree

8 files changed

+77
-45
lines changed

8 files changed

+77
-45
lines changed

tools/perf/Makefile.config

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ ifndef NO_LIBELF
589589
$(call feature_check,libbpf-bpf_program__set_insns)
590590
ifeq ($(feature-libbpf-bpf_program__set_insns), 1)
591591
CFLAGS += -DHAVE_LIBBPF_BPF_PROGRAM__SET_INSNS
592+
else
593+
dummy := $(error Error: libbpf devel library needs to be >= 0.8.0 to build with LIBBPF_DYNAMIC, update or build statically with the version that comes with the kernel sources);
592594
endif
593595
$(call feature_check,libbpf-btf__raw_data)
594596
ifeq ($(feature-libbpf-btf__raw_data), 1)
@@ -602,6 +604,8 @@ ifndef NO_LIBELF
602604
dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
603605
endif
604606
else
607+
# Libbpf will be built as a static library from tools/lib/bpf.
608+
LIBBPF_STATIC := 1
605609
CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
606610
CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
607611
CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
@@ -1314,14 +1318,6 @@ tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
13141318

13151319
export perfexec_instdir_SQ
13161320

1317-
# If we install to $(HOME) we keep the traceevent default:
1318-
# $(HOME)/.traceevent/plugins
1319-
# Otherwise we install plugins into the global $(libdir).
1320-
ifdef DESTDIR
1321-
plugindir=$(libdir)/traceevent/plugins
1322-
plugindir_SQ= $(subst ','\'',$(plugindir))
1323-
endif
1324-
13251321
print_var = $(eval $(print_var_code)) $(info $(MSG))
13261322
define print_var_code
13271323
MSG = $(shell printf '...%40s: %s' $(1) $($(1)))

tools/perf/Makefile.perf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ ifneq ($(OUTPUT),)
303303
else
304304
LIBBPF_OUTPUT = $(CURDIR)/libbpf
305305
endif
306-
LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
307-
LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
308-
LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
309-
CFLAGS += -I$(LIBBPF_OUTPUT)/include
306+
ifdef LIBBPF_STATIC
307+
LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
308+
LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
309+
LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
310+
CFLAGS += -I$(LIBBPF_OUTPUT)/include
311+
endif
310312

311313
ifneq ($(OUTPUT),)
312314
LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
@@ -393,10 +395,8 @@ endif
393395
export PERL_PATH
394396

395397
PERFLIBS = $(LIBAPI) $(LIBPERF) $(LIBSUBCMD) $(LIBSYMBOL)
396-
ifndef NO_LIBBPF
397-
ifndef LIBBPF_DYNAMIC
398-
PERFLIBS += $(LIBBPF)
399-
endif
398+
ifdef LIBBPF_STATIC
399+
PERFLIBS += $(LIBBPF)
400400
endif
401401

402402
# We choose to avoid "if .. else if .. else .. endif endif"
@@ -756,12 +756,15 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc
756756
$(arch_errno_name_array) \
757757
$(sync_file_range_arrays) \
758758
$(LIBAPI) \
759-
$(LIBBPF) \
760759
$(LIBPERF) \
761760
$(LIBSUBCMD) \
762761
$(LIBSYMBOL) \
763762
bpf-skel
764763

764+
ifdef LIBBPF_STATIC
765+
prepare: $(LIBBPF)
766+
endif
767+
765768
$(OUTPUT)%.o: %.c prepare FORCE
766769
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
767770

tools/perf/builtin-kmem.c

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "util/string2.h"
2727

2828
#include <linux/kernel.h>
29+
#include <linux/numa.h>
2930
#include <linux/rbtree.h>
3031
#include <linux/string.h>
3132
#include <linux/zalloc.h>
@@ -185,22 +186,33 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s
185186
total_allocated += bytes_alloc;
186187

187188
nr_allocs++;
188-
return 0;
189-
}
190189

191-
static int evsel__process_alloc_node_event(struct evsel *evsel, struct perf_sample *sample)
192-
{
193-
int ret = evsel__process_alloc_event(evsel, sample);
190+
/*
191+
* Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA
192+
* version of tracepoints") adds the field "node" into the
193+
* tracepoints 'kmalloc' and 'kmem_cache_alloc'.
194+
*
195+
* The legacy tracepoints 'kmalloc_node' and 'kmem_cache_alloc_node'
196+
* also contain the field "node".
197+
*
198+
* If the tracepoint contains the field "node" the tool stats the
199+
* cross allocation.
200+
*/
201+
if (evsel__field(evsel, "node")) {
202+
int node1, node2;
194203

195-
if (!ret) {
196-
int node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}),
197-
node2 = evsel__intval(evsel, sample, "node");
204+
node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu});
205+
node2 = evsel__intval(evsel, sample, "node");
198206

199-
if (node1 != node2)
207+
/*
208+
* If the field "node" is NUMA_NO_NODE (-1), we don't take it
209+
* as a cross allocation.
210+
*/
211+
if ((node2 != NUMA_NO_NODE) && (node1 != node2))
200212
nr_cross_allocs++;
201213
}
202214

203-
return ret;
215+
return 0;
204216
}
205217

206218
static int ptr_cmp(void *, void *);
@@ -1369,8 +1381,8 @@ static int __cmd_kmem(struct perf_session *session)
13691381
/* slab allocator */
13701382
{ "kmem:kmalloc", evsel__process_alloc_event, },
13711383
{ "kmem:kmem_cache_alloc", evsel__process_alloc_event, },
1372-
{ "kmem:kmalloc_node", evsel__process_alloc_node_event, },
1373-
{ "kmem:kmem_cache_alloc_node", evsel__process_alloc_node_event, },
1384+
{ "kmem:kmalloc_node", evsel__process_alloc_event, },
1385+
{ "kmem:kmem_cache_alloc_node", evsel__process_alloc_event, },
13741386
{ "kmem:kfree", evsel__process_free_event, },
13751387
{ "kmem:kmem_cache_free", evsel__process_free_event, },
13761388
/* page allocator */
@@ -1824,29 +1836,48 @@ static int parse_line_opt(const struct option *opt __maybe_unused,
18241836
return 0;
18251837
}
18261838

1839+
static bool slab_legacy_tp_is_exposed(void)
1840+
{
1841+
/*
1842+
* The tracepoints "kmem:kmalloc_node" and
1843+
* "kmem:kmem_cache_alloc_node" have been removed on the latest
1844+
* kernel, if the tracepoint "kmem:kmalloc_node" is existed it
1845+
* means the tool is running on an old kernel, we need to
1846+
* rollback to support these legacy tracepoints.
1847+
*/
1848+
return IS_ERR(trace_event__tp_format("kmem", "kmalloc_node")) ?
1849+
false : true;
1850+
}
1851+
18271852
static int __cmd_record(int argc, const char **argv)
18281853
{
18291854
const char * const record_args[] = {
18301855
"record", "-a", "-R", "-c", "1",
18311856
};
18321857
const char * const slab_events[] = {
18331858
"-e", "kmem:kmalloc",
1834-
"-e", "kmem:kmalloc_node",
18351859
"-e", "kmem:kfree",
18361860
"-e", "kmem:kmem_cache_alloc",
1837-
"-e", "kmem:kmem_cache_alloc_node",
18381861
"-e", "kmem:kmem_cache_free",
18391862
};
1863+
const char * const slab_legacy_events[] = {
1864+
"-e", "kmem:kmalloc_node",
1865+
"-e", "kmem:kmem_cache_alloc_node",
1866+
};
18401867
const char * const page_events[] = {
18411868
"-e", "kmem:mm_page_alloc",
18421869
"-e", "kmem:mm_page_free",
18431870
};
18441871
unsigned int rec_argc, i, j;
18451872
const char **rec_argv;
1873+
unsigned int slab_legacy_tp_exposed = slab_legacy_tp_is_exposed();
18461874

18471875
rec_argc = ARRAY_SIZE(record_args) + argc - 1;
1848-
if (kmem_slab)
1876+
if (kmem_slab) {
18491877
rec_argc += ARRAY_SIZE(slab_events);
1878+
if (slab_legacy_tp_exposed)
1879+
rec_argc += ARRAY_SIZE(slab_legacy_events);
1880+
}
18501881
if (kmem_page)
18511882
rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */
18521883

@@ -1861,6 +1892,10 @@ static int __cmd_record(int argc, const char **argv)
18611892
if (kmem_slab) {
18621893
for (j = 0; j < ARRAY_SIZE(slab_events); j++, i++)
18631894
rec_argv[i] = strdup(slab_events[j]);
1895+
if (slab_legacy_tp_exposed) {
1896+
for (j = 0; j < ARRAY_SIZE(slab_legacy_events); j++, i++)
1897+
rec_argv[i] = strdup(slab_legacy_events[j]);
1898+
}
18641899
}
18651900
if (kmem_page) {
18661901
rec_argv[i++] = strdup("-g");

tools/perf/builtin-trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
#include "util/record.h"
1818
#include <api/fs/tracing_path.h>
19+
#ifdef HAVE_LIBBPF_SUPPORT
1920
#include <bpf/bpf.h>
21+
#endif
2022
#include "util/bpf_map.h"
2123
#include "util/rlimit.h"
2224
#include "builtin.h"

tools/perf/tests/bpf-script-test-prologue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# undef if
2121
#endif
2222

23+
typedef unsigned int __bitwise fmode_t;
24+
2325
#define FMODE_READ 0x1
2426
#define FMODE_WRITE 0x2
2527

tools/perf/tests/make

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,7 @@ installed_files_bin := bin/perf
222222
installed_files_bin += etc/bash_completion.d/perf
223223
installed_files_bin += libexec/perf-core/perf-archive
224224

225-
installed_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so
226-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so
227-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so
228-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_function.so
229-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so
230-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so
231-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so
232-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so
233-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so
234-
installed_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so
235-
236225
installed_files_all := $(installed_files_bin)
237-
installed_files_all += $(installed_files_plugins)
238226

239227
test_make_install := $(call test_dest_files,$(installed_files_all))
240228
test_make_install_O := $(call test_dest_files,$(installed_files_all))

tools/perf/util/auxtrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ static int find_dso_sym(struct dso *dso, const char *sym_name, u64 *start,
26112611
*size = sym->start - *start;
26122612
if (idx > 0) {
26132613
if (*size)
2614-
return 1;
2614+
return 0;
26152615
} else if (dso_sym_match(sym, sym_name, &cnt, idx)) {
26162616
print_duplicate_syms(dso, sym_name);
26172617
return -EINVAL;

tools/perf/util/bpf_counter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
#include <linux/list.h>
66
#include <sys/resource.h>
7+
8+
#ifdef HAVE_LIBBPF_SUPPORT
79
#include <bpf/bpf.h>
810
#include <bpf/btf.h>
911
#include <bpf/libbpf.h>
12+
#endif
1013

1114
struct evsel;
1215
struct target;
@@ -87,6 +90,8 @@ static inline void set_max_rlimit(void)
8790
setrlimit(RLIMIT_MEMLOCK, &rinf);
8891
}
8992

93+
#ifdef HAVE_BPF_SKEL
94+
9095
static inline __u32 bpf_link_get_id(int fd)
9196
{
9297
struct bpf_link_info link_info = { .id = 0, };
@@ -127,5 +132,6 @@ static inline int bperf_trigger_reading(int prog_fd, int cpu)
127132

128133
return bpf_prog_test_run_opts(prog_fd, &opts);
129134
}
135+
#endif /* HAVE_BPF_SKEL */
130136

131137
#endif /* __PERF_BPF_COUNTER_H */

0 commit comments

Comments
 (0)