perf/core improvements and fixes
Subsystems (4)
Arnaldo Carvalho de Melo
maintainerPATCH 49/107 perf evlist: Rename perf_evlist__disable() to evlist__disable()
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Rename perf_evlist__disable() to evlist__disable(), so we don't have a name clash when we add perf_evlist__disable() in libperf.
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-trace.c | 4 ++-- tools/perf/tests/backward-ring-buffer.c | 2 +- tools/perf/tests/bpf.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/keep-tracking.c | 6 +++--- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 4 ++-- tools/perf/util/evlist.c | 4 ++-- tools/perf/util/evlist.h | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -107,7 +107,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe comm2 ="Test COMM 2" ;CHECK__ (prctl (PR_SET_NAME , (unsigned long )comm2,0 ,0 ,0 )); -perf_evlist__disable (evlist); +evlist__disable (evlist);for (i =0 ; i < evlist->nr_mmaps; i++) { md = &evlist->mmap[i];
tools/perf/builtin-kvm.c +1 -1
@@ -993,7 +993,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) err =fdarray__poll (fda,100 ); } -perf_evlist__disable (kvm->evlist); +evlist__disable (kvm->evlist);if (err ==0 ) {sort_result (kvm);
tools/perf/builtin-record.c +1 -1
@@ -1605,7 +1605,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)*/ if (done && !disabled && !target__none (&opts->target)) {trigger_off (&auxtrace_snapshot_trigger); -perf_evlist__disable (rec->evlist); +evlist__disable (rec->evlist); disabled = true; } }
tools/perf/builtin-stat.c +1 -1
@@ -373,7 +373,7 @@ static void disable_counters(void)* from counting before reading their constituent counters. */ if (!target__none (&target)) -perf_evlist__disable (evsel_list); +evlist__disable (evsel_list); }static volatile int workload_exec_errno;
tools/perf/builtin-trace.c +2 -2
@@ -3451,7 +3451,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) goto out_disable;if (done && !draining) { -perf_evlist__disable (evlist); +evlist__disable (evlist); draining = true; } }
@@ -3477,7 +3477,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) out_disable:thread__zput (trace->current); -perf_evlist__disable (evlist); +evlist__disable (evlist);if (trace->sort_events)ordered_events__flush (&trace->oe.data,OE_FLUSH__FINAL );
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -70,7 +70,7 @@ static int do_test(struct evlist *evlist, int mmap_pages,evlist__enable (evlist);testcase (); -perf_evlist__disable (evlist); +evlist__disable (evlist); err =count_samples (evlist, sample_count, comm_count);perf_evlist__munmap (evlist);
tools/perf/tests/bpf.c +1 -1
@@ -173,7 +173,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),evlist__enable (evlist); (*func)(); -perf_evlist__disable (evlist); +evlist__disable (evlist);for (i =0 ; i < evlist->nr_mmaps; i++) {union perf_event *event;
tools/perf/tests/code-reading.c +1 -1
@@ -684,7 +684,7 @@ static int do_test_code_reading(bool try_kcore)do_something (); -perf_evlist__disable (evlist); +evlist__disable (evlist); ret =process_events (machine, evlist, &state);if (ret <0 )
tools/perf/tests/keep-tracking.c +3 -3
@@ -112,7 +112,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un comm ="Test COMM 1" ;CHECK__ (prctl (PR_SET_NAME , (unsigned long )comm,0 ,0 ,0 )); -perf_evlist__disable (evlist); +evlist__disable (evlist); found =find_comm (evlist, comm);if (found !=1 ) {
@@ -134,7 +134,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un comm ="Test COMM 2" ;CHECK__ (prctl (PR_SET_NAME , (unsigned long )comm,0 ,0 ,0 )); -perf_evlist__disable (evlist); +evlist__disable (evlist); found =find_comm (evlist, comm);if (found !=1 ) {
@@ -146,7 +146,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un out_err:if (evlist) { -perf_evlist__disable (evlist); +evlist__disable (evlist);evlist__delete (evlist); }else {cpu_map__put (cpus);
tools/perf/tests/sw-clock.c +1 -1
@@ -92,7 +92,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)for (i =0 ; i <NR_LOOPS ; i++) tmp++; -perf_evlist__disable (evlist); +evlist__disable (evlist); md = &evlist->mmap[0 ];if (perf_mmap__read_init (md) <0 )
tools/perf/tests/switch-tracking.c +2 -2
@@ -528,7 +528,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ goto out_err; } -perf_evlist__disable (evlist); +evlist__disable (evlist); switch_tracking.switch_evsel = switch_evsel; switch_tracking.cycles_evsel = cycles_evsel;
@@ -566,7 +566,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ } out:if (evlist) { -perf_evlist__disable (evlist); +evlist__disable (evlist);evlist__delete (evlist); }else {cpu_map__put (cpus);
tools/perf/util/evlist.c +2 -2
@@ -343,7 +343,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,return thread_map__nr (evlist->threads); } -void perf_evlist__disable (struct evlist *evlist) +void evlist__disable (struct evlist *evlist) {struct evsel *pos;
@@ -371,7 +371,7 @@ void evlist__enable(struct evlist *evlist)void perf_evlist__toggle_enable (struct evlist *evlist) { - (evlist->enabled ? perf_evlist__disable : evlist__enable)(evlist); + (evlist->enabled ? evlist__disable : evlist__enable)(evlist); } static int perf_evlist__enable_event_cpu(struct evlist *evlist,
tools/perf/util/evlist.h +1 -1
@@ -184,7 +184,7 @@ void perf_evlist__munmap(struct evlist *evlist);size_t perf_evlist__mmap_size (unsigned long pages); -void perf_evlist__disable (struct evlist *evlist); +void evlist__disable (struct evlist *evlist);void evlist__enable (struct evlist *evlist);void perf_evlist__toggle_enable (struct evlist *evlist);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 50/107 libperf: Make libperf.a part of the perf build
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add an empty libperf.a under tools/perf/lib and link it with perf.
It can also be built separately with:
$ cd tools/perf/lib && make
CC core.o
LD libperf-in.o
AR libperf.a
LINK libperf.soCommitter testing:
$ make O=/tmp/build/perf -C tools/perf/lib/
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$ ls -la /tmp/build/perf/libperf.so
-rwxrwxr-x. 1 acme acme 16232 Jul 22 15:30 /tmp/build/perf/libperf.so
$ file /tmp/build/perf/libperf.so
/tmp/build/perf/libperf.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=7a51d227d871b381ddb686dcf94145c4dd908221, not stripped
$ git status tools/perf
On branch perf/core
nothing to commit, working tree clean
$
$ ls -lart tools/perf/lib/
total 16
drwxrwxr-x. 16 acme acme 4096 Jul 22 15:29 ..
-rw-rw-r--. 1 acme acme 1633 Jul 22 15:29 Makefile
-rw-rw-r--. 1 acme acme 0 Jul 22 15:29 core.c
-rw-rw-r--. 1 acme acme 20 Jul 22 15:29 Build
drwxrwxr-x. 2 acme acme 4096 Jul 22 15:29 .
$Committer notes:
Need to add -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi to tools/perf/lib/Makefile's INCLUDE variable to pick up the latest versions of kernel headers, even in older systems, this is in line with what is in tools/lib/bpf/Makefile.
--- tools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 30 ++++++++-------- tools/perf/lib/Build | 1 + tools/perf/lib/Makefile | 74 ++++++++++++++++++++++++++++++++++++++ tools/perf/lib/core.c | 0 5 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 tools/perf/lib/Build create mode 100644 tools/perf/lib/Makefile create mode 100644 tools/perf/lib/core.c
tools/perf/Makefile.config +1 -0
@@ -277,6 +277,7 @@ ifeq ($(DEBUG),0) endif endif +INC_FLAGS += -I$(src-perf)/lib/include INC_FLAGS += -I$(src-perf)/util/include INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include INC_FLAGS += -I$(srctree)/tools/include/uapi
tools/perf/Makefile.perf +16 -14
@@ -224,6 +224,7 @@ LIB_DIR = $(srctree)/tools/lib/api/ TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/ BPF_DIR = $(srctree)/tools/lib/bpf/ SUBCMD_DIR = $(srctree)/tools/lib/subcmd/ +LIBPERF_DIR = $(srctree)/tools/perf/lib/ # Set FEATURE_TESTS to 'all' so all possible feature checkers are executed. # Without this setting the output feature dump file misses some features, for
@@ -272,6 +273,7 @@ ifneq ($(OUTPUT),) TE_PATH=$(OUTPUT) BPF_PATH=$(OUTPUT) SUBCMD_PATH=$(OUTPUT) + LIBPERF_PATH=$(OUTPUT) ifneq ($(subdir),) API_PATH=$(OUTPUT)/../lib/api/ else
@@ -282,6 +284,7 @@ else API_PATH=$(LIB_DIR) BPF_PATH=$(BPF_DIR) SUBCMD_PATH=$(SUBCMD_DIR) + LIBPERF_PATH=$(LIBPERF_DIR) endif LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -303,6 +306,8 @@ LIBBPF = $(BPF_PATH)libbpf.a LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a +LIBPERF = $(LIBPERF_PATH)libperf.a + # python extension build directories PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -348,9 +353,7 @@ endif export PERL_PATH -LIBPERF_A=$(OUTPUT)libperf.a - -PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) +PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF) ifndef NO_LIBBPF PERFLIBS += $(LIBBPF) endif
@@ -583,8 +586,6 @@ JEVENTS_IN := $(OUTPUT)pmu-events/jevents-in.o PMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o -LIBPERF_IN := $(OUTPUT)libperf-in.o - export JEVENTS build := -f $(srctree)/tools/build/Makefile.build dir=. obj
@@ -601,12 +602,9 @@ $(JEVENTS): $(JEVENTS_IN) $(PMU_EVENTS_IN): $(JEVENTS) FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events -$(LIBPERF_IN): prepare FORCE - $(Q)$(MAKE) $(build)=libperf - -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBPERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \ - $(PERF_IN) $(PMU_EVENTS_IN) $(LIBPERF_IN) $(LIBS) -o $@ + $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@ $(GTK_IN): FORCE $(Q)$(MAKE) $(build)=gtk
@@ -727,9 +725,6 @@ endif $(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h) -$(LIBPERF_A): $(LIBPERF_IN) - $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) $(LIB_OBJS) - LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ) 'EXTRA_CFLAGS=$(EXTRA_CFLAGS)' 'LDFLAGS=$(LDFLAGS)' $(LIBTRACEEVENT): FORCE
@@ -762,6 +757,13 @@ $(LIBBPF)-clean: $(call QUIET_CLEAN, libbpf) $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null +$(LIBPERF): FORCE + $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) $(OUTPUT)libperf.a + +$(LIBPERF)-clean: + $(call QUIET_CLEAN, libperf) + $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) clean >/dev/null + $(LIBSUBCMD): FORCE $(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
@@ -948,7 +950,7 @@ config-clean: python-clean: $(python-clean) -clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean python-clean +clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean config-clean fixdep-clean python-clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detected
tools/perf/lib/Build new file +1 -0
@@ -0,0 +1 @@ +libperf-y += core.o
tools/perf/lib/Makefile new file +74 -0
74 lines not on this page · raw message
tools/perf/lib/core.c new file +0 -0
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 51/107 libperf: Add build version support
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add a shared library version, generating the following files:
$ ll tools/perf/lib/libperf.so* libperf.so -> libperf.so.0.0.1 libperf.so.0 -> libperf.so.0.0.1 libperf.so.0.0.1
Committer testing:
One has to build just libbperf to get this, building perf so far doesn't trigger this, i.e. I tried:
$ make O=/tmp/build/perf -C tools/perf
And the files above were not created, so one has to do:
$ make O=/tmp/build/perf -C tools/perf/lib/
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so.0.0.1
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$ ls -la /tmp/build/perf/*.so.*
lrwxrwxrwx. 1 acme acme 16 Jul 22 15:37 /tmp/build/perf/libperf.so.0 -> libperf.so.0.0.1
-rwxrwxr-x. 1 acme acme 16368 Jul 22 15:37 /tmp/build/perf/libperf.so.0.0.1
$--- tools/perf/lib/Makefile | 20 +++++++++++++++++--- tools/perf/lib/libperf.map | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tools/perf/lib/libperf.map
tools/perf/lib/Makefile +17 -3
@@ -1,6 +1,10 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) # Most of this file is copied from tools/lib/bpf/Makefile +LIBPERF_VERSION = 0 +LIBPERF_PATCHLEVEL = 0 +LIBPERF_EXTRAVERSION = 1 + MAKEFLAGS += --no-print-directory ifeq ($(srctree),)
@@ -47,7 +51,13 @@ all: export srctree OUTPUT CC LD CFLAGS V include $(srctree)/tools/build/Makefile.include -LIBPERF_SO := $(OUTPUT)libperf.so +VERSION_SCRIPT := libperf.map + +PATCHLEVEL = $(LIBPERF_PATCHLEVEL) +EXTRAVERSION = $(LIBPERF_EXTRAVERSION) +VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION) + +LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) LIBPERF_A := $(OUTPUT)libperf.a LIBPERF_IN := $(OUTPUT)libperf-in.o
@@ -58,7 +68,11 @@ $(LIBPERF_A): $(LIBPERF_IN) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) $(LIBPERF_SO): $(LIBPERF_IN) - $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so $^ -o $@ + $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \ + -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@ + @ln -sf $(@F) $(OUTPUT)libperf.so + @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION) + libs: $(LIBPERF_A) $(LIBPERF_SO)
@@ -67,7 +81,7 @@ all: fixdep clean: $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ - *.o *~ *.a *.so .*.d .*.cmd LIBPERF-CFLAGS + *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS FORCE:
tools/perf/lib/libperf.map new file +4 -0
@@ -0,0 +1,4 @@ +LIBPERF_0.0.1 { + local: + *; +};
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 52/107 libperf: Add libperf to the python.so build
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Link libperf.a with python.so.
Committer testing:
Continues to work:
# perf test python 18: 'import perf' in python : Ok #
--- tools/perf/Makefile.perf | 1 + tools/perf/util/setup.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -0
@@ -307,6 +307,7 @@ LIBBPF = $(BPF_PATH)libbpf.a LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a LIBPERF = $(LIBPERF_PATH)libperf.a +export LIBPERF # python extension build directories PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
tools/perf/util/setup.py +2 -1
@@ -48,6 +48,7 @@ build_lib = getenv('PYTHON_EXTBUILD_LIB') build_tmp = getenv('PYTHON_EXTBUILD_TMP') libtraceevent = getenv('LIBTRACEEVENT') libapikfs = getenv('LIBAPI') +libperf = getenv('LIBPERF') ext_sources = [f.strip() for f in open('util/python-ext-sources') if len(f.strip()) > 0 and f[0] != '#']
@@ -64,7 +65,7 @@ perf = Extension('perf', include_dirs = ['util/include'], libraries = extra_libraries, extra_compile_args = cflags, - extra_objects = [libtraceevent, libapikfs], + extra_objects = [libtraceevent, libapikfs, libperf], ) setup(name='perf',
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 53/107 libperf: Add perf/core.h header
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add perf/core.h header to be used in header files coming in the following patches.
--- tools/perf/lib/include/perf/core.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/perf/lib/include/perf/core.h
tools/perf/lib/include/perf/core.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_CORE_H +#define __LIBPERF_CORE_H + +#ifndef LIBPERF_API +#define LIBPERF_API __attribute__((visibility("default"))) +#endif + +#endif /* __LIBPERF_CORE_H */
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 54/107 libperf: Add debug output support
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_set_print() function to allow setting an output function for warn/info/debug messages.
--- tools/perf/lib/core.c | 34 ++++++++++++++++++++++++++++++ tools/perf/lib/include/perf/core.h | 13 ++++++++++++ tools/perf/lib/internal.h | 18 ++++++++++++++++ tools/perf/lib/libperf.map | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 tools/perf/lib/internal.h
tools/perf/lib/core.c +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define __printf (a, b) __attribute__((format(printf, a, b))) + +#include <stdio.h> +#include <stdarg.h> +#include <perf/core.h> +#include "internal.h" + +static int __base_pr (enum libperf_print_level level,const char *format, +va_list args) +{ +return vfprintf (stderr, format, args); +} + +static libperf_print_fn_t __libperf_pr = __base_pr; + +void libperf_set_print (libperf_print_fn_t fn) +{ + __libperf_pr = fn; +} + +__printf(2, 3) +void libperf_print (enum libperf_print_level level,const char *format, ...) +{ +va_list args; + +if (!__libperf_pr) +return ; + +va_start (args, format); +__libperf_pr (level, format, args); +va_end (args); +}
tools/perf/lib/include/perf/core.h +13 -0
@@ -2,8 +2,21 @@#ifndef __LIBPERF_CORE_H#define __LIBPERF_CORE_H +#include <stdarg.h> +#ifndef LIBPERF_API #define LIBPERF_API __attribute__((visibility("default")))#endif +enum libperf_print_level { +LIBPERF_WARN , +LIBPERF_INFO , +LIBPERF_DEBUG , +}; + +typedef int (*libperf_print_fn_t )(enum libperf_print_level level, +const char *,va_list ap); + +LIBPERF_API void libperf_set_print(libperf_print_fn_t fn); +#endif /* __LIBPERF_CORE_H */
tools/perf/lib/internal.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_H +#define __LIBPERF_INTERNAL_H + +void libperf_print (enum libperf_print_level level, +const char *format, ...) + __attribute__((format (printf,2 ,3 ))); + +#define __pr (level, fmt, ...) \ +do { \ + libperf_print(level, "libperf: " fmt, ##__VA_ARGS__); \ +} while (0) + +#define pr_warning (fmt, ...) __pr(LIBPERF_WARN, fmt, ##__VA_ARGS__) +#define pr_info (fmt, ...) __pr(LIBPERF_INFO, fmt, ##__VA_ARGS__) +#define pr_debug (fmt, ...) __pr(LIBPERF_DEBUG, fmt, ##__VA_ARGS__) + +#endif /* __LIBPERF_INTERNAL_H */
tools/perf/lib/libperf.map +2 -0
@@ -1,4 +1,6 @@ LIBPERF_0.0.1 { + global: + libperf_set_print; local: *; };
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 55/107 libperf: Add perf_cpu_map struct
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add perf_cpu_map struct to libperf.
It's added as a declaration into:
include/perf/cpumap.h
which will be included by users.
The perf_cpu_map struct definition is added into:
include/internal/cpumap.h
which is not to be included by users, but shared within perf and libperf.
We tried the total separation of the perf_cpu_map struct in libperf, but it lead to complications and much bigger changes in perf code, so we decided to share the declaration.
--- tools/perf/lib/Build | 1 + tools/perf/lib/cpumap.c | 5 +++++ tools/perf/lib/include/internal/cpumap.h | 13 +++++++++++++ tools/perf/lib/include/perf/cpumap.h | 7 +++++++ tools/perf/util/cpumap.h | 7 +------ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 tools/perf/lib/cpumap.c create mode 100644 tools/perf/lib/include/internal/cpumap.h create mode 100644 tools/perf/lib/include/perf/cpumap.h
tools/perf/lib/Build +1 -0
@@ -1 +1,2 @@ libperf-y += core.o +libperf-y += cpumap.o
tools/perf/lib/cpumap.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <perf/cpumap.h> +#include <stdlib.h> +#include <linux/refcount.h> +#include <internal/cpumap.h>
tools/perf/lib/include/internal/cpumap.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_CPUMAP_H +#define __LIBPERF_INTERNAL_CPUMAP_H + +#include <linux/refcount.h> + +struct perf_cpu_map { +refcount_t refcnt; +int nr; +int map[]; +}; + +#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
tools/perf/lib/include/perf/cpumap.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_CPUMAP_H +#define __LIBPERF_CPUMAP_H + +struct perf_cpu_map ; + +#endif /* __LIBPERF_CPUMAP_H */
tools/perf/util/cpumap.h +1 -6
@@ -5,16 +5,11 @@#include <stdio.h> #include <stdbool.h> #include <linux/refcount.h> +#include <internal/cpumap.h> #include "perf.h" #include "util/debug.h" -struct perf_cpu_map { -refcount_t refcnt; -int nr; -int map[]; -}; -struct perf_cpu_map *cpu_map__new (const char *cpu_list);struct perf_cpu_map *cpu_map__empty_new (int nr);struct perf_cpu_map *cpu_map__dummy_new (void );
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 56/107 libperf: Add perf_cpu_map__dummy_new() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move cpu_map__dummy_new() to libperf as perf_cpu_map__dummy_new() function.
--- tools/perf/lib/cpumap.c | 13 +++++++++++++ tools/perf/lib/include/perf/cpumap.h | 4 ++++ tools/perf/lib/libperf.map | 1 + tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/util/cpumap.c | 15 +-------------- tools/perf/util/cpumap.h | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 2 +- 9 files changed, 24 insertions(+), 19 deletions(-)
tools/perf/lib/cpumap.c +13 -0
@@ -3,3 +3,16 @@#include <stdlib.h> #include <linux/refcount.h> #include <internal/cpumap.h> + +struct perf_cpu_map *perf_cpu_map__dummy_new (void ) +{ +struct perf_cpu_map *cpus =malloc (sizeof (*cpus) +sizeof (int )); + +if (cpus !=NULL ) { + cpus->nr =1 ; + cpus->map[0 ] =-1 ; +refcount_set (&cpus->refcnt,1 ); + } + +return cpus; +}
tools/perf/lib/include/perf/cpumap.h +4 -0
@@ -2,6 +2,10 @@#ifndef __LIBPERF_CPUMAP_H#define __LIBPERF_CPUMAP_H +#include <perf/core.h> +struct perf_cpu_map ; +LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); +#endif /* __LIBPERF_CPUMAP_H */
tools/perf/lib/libperf.map +1 -0
@@ -1,6 +1,7 @@ LIBPERF_0.0.1 { global: libperf_set_print; + perf_cpu_map__dummy_new; local: *; };
tools/perf/tests/sw-clock.c +1 -1
@@ -56,7 +56,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) }evlist__add (evlist, evsel); - cpus =cpu_map__dummy_new (); + cpus =perf_cpu_map__dummy_new (); threads =thread_map__new_by_tid (getpid ());if (!cpus || !threads) { err = -ENOMEM ;
tools/perf/tests/task-exit.c +1 -1
@@ -63,7 +63,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused* perf_evlist__prepare_workload we'll fill in the only thread * we're monitoring, the one forked there. */ - cpus =cpu_map__dummy_new (); + cpus =perf_cpu_map__dummy_new (); threads =thread_map__new_by_tid (-1 );if (!cpus || !threads) { err = -ENOMEM ;
tools/perf/util/cpumap.c +1 -14
@@ -189,7 +189,7 @@ struct perf_cpu_map *cpu_map__new(const char *cpu_list)else if (*cpu_list !='\0' ) cpus =cpu_map__default_new ();else - cpus =cpu_map__dummy_new (); + cpus =perf_cpu_map__dummy_new (); invalid:free (tmp_cpus); out:
@@ -256,19 +256,6 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)#undef BUFSIZE } -struct perf_cpu_map *cpu_map__dummy_new (void ) -{ -struct perf_cpu_map *cpus =malloc (sizeof (*cpus) +sizeof (int )); - -if (cpus !=NULL ) { - cpus->nr =1 ; - cpus->map[0 ] =-1 ; -refcount_set (&cpus->refcnt,1 ); - } - -return cpus; -} -struct perf_cpu_map *cpu_map__empty_new (int nr) {struct perf_cpu_map *cpus =malloc (sizeof (*cpus) +sizeof (int ) * nr);
tools/perf/util/cpumap.h +1 -1
@@ -6,13 +6,13 @@#include <stdbool.h> #include <linux/refcount.h> #include <internal/cpumap.h> +#include <perf/cpumap.h> #include "perf.h" #include "util/debug.h" struct perf_cpu_map *cpu_map__new (const char *cpu_list);struct perf_cpu_map *cpu_map__empty_new (int nr); -struct perf_cpu_map *cpu_map__dummy_new (void );struct perf_cpu_map *cpu_map__new_data (struct cpu_map_data *data);struct perf_cpu_map *cpu_map__read (FILE *file);size_t cpu_map__snprint (struct perf_cpu_map *map,char *buf,size_t size);
tools/perf/util/evlist.c +1 -1
@@ -1086,7 +1086,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)return -1 ;if (target__uses_dummy_map (target)) - cpus =cpu_map__dummy_new (); + cpus =perf_cpu_map__dummy_new ();else cpus =cpu_map__new (target->cpu_list);
tools/perf/util/evsel.c +1 -1
@@ -1840,7 +1840,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,static struct perf_cpu_map *empty_cpu_map;if (empty_cpu_map ==NULL ) { - empty_cpu_map =cpu_map__dummy_new (); + empty_cpu_map =perf_cpu_map__dummy_new ();if (empty_cpu_map ==NULL )return -ENOMEM ; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 57/107 libperf: Add perf_cpu_map__get()/perf_cpu_map__put()
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Moving the following functions:
cpu_map__get()
cpu_map__put()
to libperf with following names:
perf_cpu_map__get()
perf_cpu_map__put()
Committer notes:
Added fixes for arm/arm64
--- tools/perf/arch/arm/util/cs-etm.c | 6 +++--- tools/perf/arch/arm64/util/header.c | 4 ++-- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-stat.c | 4 ++-- tools/perf/lib/cpumap.c | 24 ++++++++++++++++++++++ tools/perf/lib/include/perf/cpumap.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ tools/perf/tests/bitmap.c | 2 +- tools/perf/tests/code-reading.c | 4 ++-- tools/perf/tests/cpumap.c | 8 ++++---- tools/perf/tests/event-times.c | 4 ++-- tools/perf/tests/event_update.c | 4 ++-- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mem2node.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 22 -------------------- tools/perf/util/cpumap.h | 3 --- tools/perf/util/cputopo.c | 4 ++-- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/evlist.c | 16 +++++++-------- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/pmu.c | 2 +- tools/perf/util/python.c | 2 +- tools/perf/util/record.c | 6 +++--- tools/perf/util/session.c | 2 +- tools/perf/util/svghelper.c | 2 +- 33 files changed, 78 insertions(+), 75 deletions(-)
tools/perf/arch/arm/util/cs-etm.c +3 -3
@@ -181,7 +181,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr, err =0 ; out: -cpu_map__put (online_cpus); +perf_cpu_map__put (online_cpus);return err; }
@@ -517,7 +517,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, } } -cpu_map__put (online_cpus); +perf_cpu_map__put (online_cpus); return (CS_ETM_HEADER_SIZE + (etmv4 * CS_ETMV4_PRIV_SIZE) +
@@ -679,7 +679,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,if (cpu_map__has (cpu_map, i))cs_etm_get_metadata (i, &offset, itr, info); -cpu_map__put (online_cpus); +perf_cpu_map__put (online_cpus);return 0 ; }
tools/perf/arch/arm64/util/header.c +2 -2
@@ -27,7 +27,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)return NULL ;/* read midr from list of cpus mapped to this pmu */ - cpus =cpu_map__get (pmu->cpus); + cpus =perf_cpu_map__get (pmu->cpus);for (cpu =0 ; cpu < cpus->nr; cpu++) {scnprintf (path,PATH_MAX ,"%s/devices/system/cpu/cpu%d" MIDR , sysfs, cpus->map[cpu]);
@@ -60,6 +60,6 @@ char *get_cpuid_str(struct perf_pmu *pmu) buf =NULL ; } -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return buf; }
tools/perf/builtin-ftrace.c +1 -1
@@ -206,7 +206,7 @@ static int reset_tracing_cpu(void)int ret; ret =set_tracing_cpumask (cpumap); -cpu_map__put (cpumap); +perf_cpu_map__put (cpumap);return ret; }
tools/perf/builtin-stat.c +2 -2
@@ -933,8 +933,8 @@ static int perf_stat_init_aggr_mode(void)static void perf_stat__exit_aggr_mode (void ) { -cpu_map__put (stat_config.aggr_map); -cpu_map__put (stat_config.cpus_aggr_map); +perf_cpu_map__put (stat_config.aggr_map); +perf_cpu_map__put (stat_config.cpus_aggr_map); stat_config.aggr_map =NULL ; stat_config.cpus_aggr_map =NULL ; }
tools/perf/lib/cpumap.c +24 -0
@@ -3,6 +3,8 @@#include <stdlib.h> #include <linux/refcount.h> #include <internal/cpumap.h> +#include <asm/bug.h> +#include <stdio.h> struct perf_cpu_map *perf_cpu_map__dummy_new (void ) {
@@ -16,3 +18,25 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void)return cpus; } + +static void cpu_map__delete (struct perf_cpu_map *map) +{ +if (map) { +WARN_ONCE (refcount_read (&map->refcnt) !=0 , +"cpu_map refcnt unbalanced\n" ); +free (map); + } +} + +struct perf_cpu_map *perf_cpu_map__get (struct perf_cpu_map *map) +{ +if (map) +refcount_inc (&map->refcnt); +return map; +} + +void perf_cpu_map__put (struct perf_cpu_map *map) +{ +if (map &&refcount_dec_and_test (&map->refcnt)) +cpu_map__delete (map); +}
tools/perf/lib/include/perf/cpumap.h +2 -0
@@ -7,5 +7,7 @@struct perf_cpu_map ; LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); +LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);#endif /* __LIBPERF_CPUMAP_H */
tools/perf/lib/libperf.map +2 -0
@@ -2,6 +2,8 @@ LIBPERF_0.0.1 { global: libperf_set_print; perf_cpu_map__dummy_new; + perf_cpu_map__get; + perf_cpu_map__put; local: *; };
tools/perf/tests/bitmap.c +1 -1
@@ -21,7 +21,7 @@ static unsigned long *get_bitmap(const char *str, int nbits) }if (map) -cpu_map__put (map); +perf_cpu_map__put (map);return bm; }
tools/perf/tests/code-reading.c +2 -2
@@ -655,7 +655,7 @@ static int do_test_code_reading(bool try_kcore)* and will be freed by following perf_evlist__set_maps * call. Getting refference to keep them alive. */ -cpu_map__get (cpus); +perf_cpu_map__get (cpus);thread_map__get (threads);perf_evlist__set_maps (evlist,NULL ,NULL );evlist__delete (evlist);
@@ -705,7 +705,7 @@ static int do_test_code_reading(bool try_kcore)if (evlist) {evlist__delete (evlist); }else { -cpu_map__put (cpus); +perf_cpu_map__put (cpus);thread_map__put (threads); }machine__delete_threads (machine);
tools/perf/tests/cpumap.c +4 -4
@@ -39,7 +39,7 @@ static int process_event_mask(struct perf_tool *tool __maybe_unused,TEST_ASSERT_VAL ("wrong cpu" , map->map[i] == i); } -cpu_map__put (map); +perf_cpu_map__put (map);return 0 ; }
@@ -68,7 +68,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,TEST_ASSERT_VAL ("wrong cpu" , map->map[0 ] ==1 );TEST_ASSERT_VAL ("wrong cpu" , map->map[1 ] ==256 );TEST_ASSERT_VAL ("wrong refcnt" ,refcount_read (&map->refcnt) ==1 ); -cpu_map__put (map); +perf_cpu_map__put (map);return 0 ; }
@@ -83,7 +83,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __mayTEST_ASSERT_VAL ("failed to synthesize map" , !perf_event__synthesize_cpu_map (NULL , cpus, process_event_mask,NULL )); -cpu_map__put (cpus); +perf_cpu_map__put (cpus);/* This one is better stores in cpu values. */ cpus =cpu_map__new ("1,256" );
@@ -91,7 +91,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __mayTEST_ASSERT_VAL ("failed to synthesize map" , !perf_event__synthesize_cpu_map (NULL , cpus, process_event_cpus,NULL )); -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return 0 ; }
tools/perf/tests/event-times.c +2 -2
@@ -132,7 +132,7 @@ static int attach__cpu_disabled(struct evlist *evlist)return err; } -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return evsel__enable (evsel); }
@@ -154,7 +154,7 @@ static int attach__cpu_enabled(struct evlist *evlist)if (err == -EACCES )return TEST_SKIP ; -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return err ?TEST_FAIL :TEST_OK ; }
tools/perf/tests/event_update.c +2 -2
@@ -73,7 +73,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,TEST_ASSERT_VAL ("wrong cpus" , map->map[0 ] ==1 );TEST_ASSERT_VAL ("wrong cpus" , map->map[1 ] ==2 );TEST_ASSERT_VAL ("wrong cpus" , map->map[2 ] ==3 ); -cpu_map__put (map); +perf_cpu_map__put (map);return 0 ; }
@@ -113,6 +113,6 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unuTEST_ASSERT_VAL ("failed to synthesize attr update cpus" , !perf_event__synthesize_event_update_cpus (&tmp.tool, evsel, process_event_cpus)); -cpu_map__put (evsel->own_cpus); +perf_cpu_map__put (evsel->own_cpus);return 0 ; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -149,7 +149,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_unevlist__disable (evlist);evlist__delete (evlist); }else { -cpu_map__put (cpus); +perf_cpu_map__put (cpus);thread_map__put (threads); }
tools/perf/tests/mem2node.c +1 -1
@@ -32,7 +32,7 @@ static unsigned long *get_bitmap(const char *str, int nbits) }if (map) -cpu_map__put (map); +perf_cpu_map__put (map);else free (bm);
tools/perf/tests/mmap-basic.c +1 -1
@@ -155,7 +155,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse cpus =NULL ; threads =NULL ; out_free_cpus: -cpu_map__put (cpus); +perf_cpu_map__put (cpus); out_free_threads:thread_map__put (threads);return err;
tools/perf/tests/openat-syscall-all-cpus.c +1 -1
@@ -120,7 +120,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int out_evsel_delete:evsel__delete (evsel); out_cpu_map_delete: -cpu_map__put (cpus); +perf_cpu_map__put (cpus); out_thread_map_delete:thread_map__put (threads);return err;
tools/perf/tests/sw-clock.c +1 -1
@@ -125,7 +125,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) } out_free_maps: -cpu_map__put (cpus); +perf_cpu_map__put (cpus);thread_map__put (threads); out_delete_evlist:evlist__delete (evlist);
tools/perf/tests/switch-tracking.c +1 -1
@@ -569,7 +569,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_evlist__disable (evlist);evlist__delete (evlist); }else { -cpu_map__put (cpus); +perf_cpu_map__put (cpus);thread_map__put (threads); }
tools/perf/tests/task-exit.c +1 -1
@@ -135,7 +135,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused } out_free_maps: -cpu_map__put (cpus); +perf_cpu_map__put (cpus);thread_map__put (threads); out_delete_evlist:evlist__delete (evlist);
tools/perf/tests/topology.c +1 -1
@@ -133,7 +133,7 @@ int test__session_topology(struct test *test __maybe_unused, int subtest __maybe } ret =check_cpu_topology (path, map); -cpu_map__put (map); +perf_cpu_map__put (map); free_path:unlink (path);
tools/perf/util/cpumap.c +0 -22
@@ -273,28 +273,6 @@ struct perf_cpu_map *cpu_map__empty_new(int nr)return cpus; } -static void cpu_map__delete (struct perf_cpu_map *map) -{ -if (map) { -WARN_ONCE (refcount_read (&map->refcnt) !=0 , -"cpu_map refcnt unbalanced\n" ); -free (map); - } -} - -struct perf_cpu_map *cpu_map__get (struct perf_cpu_map *map) -{ -if (map) -refcount_inc (&map->refcnt); -return map; -} - -void cpu_map__put (struct perf_cpu_map *map) -{ -if (map &&refcount_dec_and_test (&map->refcnt)) -cpu_map__delete (map); -} -static int cpu__get_topology_int (int cpu,const char *name,int *value) {char path[PATH_MAX ];
tools/perf/util/cpumap.h +0 -3
@@ -29,9 +29,6 @@ int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diepint cpu_map__build_core_map (struct perf_cpu_map *cpus,struct perf_cpu_map **corep);const struct perf_cpu_map *cpu_map__online (void );/* thread unsafe */ -struct perf_cpu_map *cpu_map__get (struct perf_cpu_map *map); -void cpu_map__put (struct perf_cpu_map *map); -static inline int cpu_map__socket (struct perf_cpu_map *sock,int s) {if (!sock || s > sock->nr || s <0 )
tools/perf/util/cputopo.c +2 -2
@@ -219,7 +219,7 @@ struct cpu_topology *cpu_topology__new(void) } out_free: -cpu_map__put (map); +perf_cpu_map__put (map);if (ret) {cpu_topology__delete (tp); tp =NULL ;
@@ -335,7 +335,7 @@ struct numa_topology *numa_topology__new(void) out:free (buf);fclose (fp); -cpu_map__put (node_map); +perf_cpu_map__put (node_map);return tp; }
tools/perf/util/env.c +1 -1
@@ -179,7 +179,7 @@ void perf_env__exit(struct perf_env *env)zfree (&env->cpu);for (i =0 ; i < env->nr_numa_nodes; i++) -cpu_map__put (env->numa_nodes[i].map); +perf_cpu_map__put (env->numa_nodes[i].map);zfree (&env->numa_nodes);for (i =0 ; i < env->caches_cnt; i++)
tools/perf/util/event.c +1 -1
@@ -1403,7 +1403,7 @@ size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp)else ret +=fprintf (fp,"failed to get cpumap from event\n" ); -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return ret; }
tools/perf/util/evlist.c +8 -8
@@ -141,7 +141,7 @@ void evlist__delete(struct evlist *evlist)perf_evlist__munmap (evlist);evlist__close (evlist); -cpu_map__put (evlist->cpus); +perf_cpu_map__put (evlist->cpus);thread_map__put (evlist->threads); evlist->cpus =NULL ; evlist->threads =NULL ;
@@ -158,11 +158,11 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,* keep it, if there's no target cpu list defined. */ if (!evsel->own_cpus || evlist->has_user_cpus) { -cpu_map__put (evsel->cpus); - evsel->cpus =cpu_map__get (evlist->cpus); +perf_cpu_map__put (evsel->cpus); + evsel->cpus =perf_cpu_map__get (evlist->cpus); }else if (evsel->cpus != evsel->own_cpus) { -cpu_map__put (evsel->cpus); - evsel->cpus =cpu_map__get (evsel->own_cpus); +perf_cpu_map__put (evsel->cpus); + evsel->cpus =perf_cpu_map__get (evsel->own_cpus); }thread_map__put (evsel->threads);
@@ -1115,8 +1115,8 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus,* the caller to increase the reference count. */ if (cpus != evlist->cpus) { -cpu_map__put (evlist->cpus); - evlist->cpus =cpu_map__get (cpus); +perf_cpu_map__put (evlist->cpus); + evlist->cpus =perf_cpu_map__get (cpus); }if (threads != evlist->threads) {
@@ -1383,7 +1383,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist) out:return err; out_put: -cpu_map__put (cpus); +perf_cpu_map__put (cpus); goto out; }
tools/perf/util/evsel.c +2 -2
@@ -1325,8 +1325,8 @@ void perf_evsel__exit(struct evsel *evsel)perf_evsel__free_id (evsel);perf_evsel__free_config_terms (evsel);cgroup__put (evsel->cgrp); -cpu_map__put (evsel->cpus); -cpu_map__put (evsel->own_cpus); +perf_cpu_map__put (evsel->cpus); +perf_cpu_map__put (evsel->own_cpus);thread_map__put (evsel->threads);zfree (&evsel->group_name);zfree (&evsel->name);
tools/perf/util/parse-events.c +2 -2
@@ -332,8 +332,8 @@ __add_event(struct list_head *list, int *idx,return NULL ; (*idx)++; - evsel->cpus =cpu_map__get (cpus); - evsel->own_cpus =cpu_map__get (cpus); + evsel->cpus =perf_cpu_map__get (cpus); + evsel->own_cpus =perf_cpu_map__get (cpus); evsel->system_wide = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats;
tools/perf/util/pmu.c +1 -1
@@ -626,7 +626,7 @@ static bool pmu_is_uncore(const char *name)snprintf (path,PATH_MAX ,CPUS_TEMPLATE_UNCORE , sysfs, name); cpus =__pmu_cpumask (path); -cpu_map__put (cpus); +perf_cpu_map__put (cpus);return !!cpus; }
tools/perf/util/python.c +1 -1
@@ -557,7 +557,7 @@ static int pyrf_cpu_map__init(struct pyrf_cpu_map *pcpus,static void pyrf_cpu_map__delete (struct pyrf_cpu_map *pcpus) { -cpu_map__put (pcpus->cpus); +perf_cpu_map__put (pcpus->cpus);Py_TYPE (pcpus)->tp_free ((PyObject *)pcpus); }
tools/perf/util/record.c +3 -3
@@ -67,7 +67,7 @@ static bool perf_probe_api(setup_probe_fn_t fn)if (!cpus)return false; cpu = cpus->map[0 ]; -cpu_map__put (cpus); +perf_cpu_map__put (cpus); do { ret = perf_do_probe_api(fn, cpu, try[i++]);
@@ -122,7 +122,7 @@ bool perf_can_record_cpu_wide(void)if (!cpus)return false; cpu = cpus->map[0 ]; -cpu_map__put (cpus); +perf_cpu_map__put (cpus); fd =sys_perf_event_open (&attr,-1 , cpu,-1 ,0 );if (fd <0 )
@@ -278,7 +278,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str)struct perf_cpu_map *cpus =cpu_map__new (NULL ); cpu = cpus ? cpus->map[0 ] :0 ; -cpu_map__put (cpus); +perf_cpu_map__put (cpus); }else { cpu = evlist->cpus->map[0 ]; }
tools/perf/util/session.c +1 -1
@@ -2310,7 +2310,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, err =0 ; out_delete_map: -cpu_map__put (map); +perf_cpu_map__put (map);return err; }
tools/perf/util/svghelper.c +1 -1
@@ -745,7 +745,7 @@ static int str_to_bitmap(char *s, cpumask_t *b)set_bit (c,cpumask_bits (b)); } -cpu_map__put (m); +perf_cpu_map__put (m);return ret; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 58/107 libperf: Add perf_thread_map struct
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add perf_thread_map struct to libperf.
It's added as a declaration into into:
include/perf/threadmap.h
which will be included by users.
The perf_thread_map struct definition is added into:
include/internal/threadmap.h
which is not to be included by users, but shared within perf and libperf.
We tried the total separation of the perf_thread_map struct in libperf, but it lead to complications and much bigger changes in perf code, so we decided to share the declaration.
--- tools/perf/lib/Build | 1 + tools/perf/lib/include/internal/threadmap.h | 21 +++++++++++++++++++++ tools/perf/lib/include/perf/threadmap.h | 7 +++++++ tools/perf/lib/threadmap.c | 5 +++++ tools/perf/util/thread_map.h | 13 +------------ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 tools/perf/lib/include/internal/threadmap.h create mode 100644 tools/perf/lib/include/perf/threadmap.h create mode 100644 tools/perf/lib/threadmap.c
tools/perf/lib/Build +1 -0
@@ -1,2 +1,3 @@ libperf-y += core.o libperf-y += cpumap.o +libperf-y += threadmap.o
tools/perf/lib/include/internal/threadmap.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_THREADMAP_H +#define __LIBPERF_INTERNAL_THREADMAP_H + +#include <linux/refcount.h> +#include <sys/types.h> +#include <unistd.h> + +struct thread_map_data { +pid_t pid; +char *comm; +}; + +struct perf_thread_map { +refcount_t refcnt; +int nr; +int err_thread; +struct thread_map_data map[]; +}; + +#endif /* __LIBPERF_INTERNAL_THREADMAP_H */
tools/perf/lib/include/perf/threadmap.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_THREADMAP_H +#define __LIBPERF_THREADMAP_H + +struct perf_thread_map ; + +#endif /* __LIBPERF_THREADMAP_H */
tools/perf/lib/threadmap.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <perf/threadmap.h> +#include <stdlib.h> +#include <linux/refcount.h> +#include <internal/threadmap.h>
tools/perf/util/thread_map.h +1 -12
@@ -5,18 +5,7 @@#include <sys/types.h> #include <stdio.h> #include <linux/refcount.h> - -struct thread_map_data { -pid_t pid; -char *comm; -}; - -struct perf_thread_map { -refcount_t refcnt; -int nr; -int err_thread; -struct thread_map_data map[]; -}; +#include <internal/threadmap.h> struct thread_map_event ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 59/107 libperf: Add perf_thread_map__new_dummy() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Moving the following functions:
thread_map__new_dummy()
thread_map__realloc()
thread_map__set_pid()
to libperf with the following names:
perf_thread_map__new_dummy()
perf_thread_map__realloc()
perf_thread_map__set_pid()
the other 2 functions are dependencies of theperf_thread_map__new_dummy() function.
The perf_thread_map__realloc() function is not exported.
--- tools/perf/lib/include/internal/threadmap.h | 2 + tools/perf/lib/include/perf/threadmap.h | 7 +++ tools/perf/lib/libperf.map | 2 + tools/perf/lib/threadmap.c | 43 +++++++++++++++ tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/thread-map.c | 2 +- tools/perf/util/evlist.c | 4 +- tools/perf/util/thread_map.c | 59 +++++---------------- tools/perf/util/thread_map.h | 7 +-- 9 files changed, 71 insertions(+), 57 deletions(-)
tools/perf/lib/include/internal/threadmap.h +2 -0
@@ -18,4 +18,6 @@ struct perf_thread_map { struct thread_map_data map[]; }; +struct perf_thread_map *perf_thread_map__realloc (struct perf_thread_map *map,int nr); +#endif /* __LIBPERF_INTERNAL_THREADMAP_H */
tools/perf/lib/include/perf/threadmap.h +7 -0
@@ -2,6 +2,13 @@#ifndef __LIBPERF_THREADMAP_H#define __LIBPERF_THREADMAP_H +#include <perf/core.h> +#include <sys/types.h> +struct perf_thread_map ; +LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void); + +LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid); +#endif /* __LIBPERF_THREADMAP_H */
tools/perf/lib/libperf.map +2 -0
@@ -4,6 +4,8 @@ LIBPERF_0.0.1 { perf_cpu_map__dummy_new; perf_cpu_map__get; perf_cpu_map__put; + perf_thread_map__new_dummy; + perf_thread_map__set_pid; local: *; };
tools/perf/lib/threadmap.c +43 -0
46 lines not on this page · raw message
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -58,7 +58,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestperf_evsel__config (evsel, &opts,NULL ); -thread_map__set_pid (evlist->threads,0 ,getpid ()); +perf_thread_map__set_pid (evlist->threads,0 ,getpid ()); err =evlist__open (evlist);if (err <0 ) {
tools/perf/tests/thread-map.c +1 -1
@@ -35,7 +35,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unusethread_map__put (map);/* test dummy pid */ - map =thread_map__new_dummy (); + map =perf_thread_map__new_dummy ();TEST_ASSERT_VAL ("failed to alloc map" , map);thread_map__read_comms (map);
tools/perf/util/evlist.c +2 -2
@@ -1375,7 +1375,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)if (!cpus) goto out; - threads =thread_map__new_dummy (); + threads =perf_thread_map__new_dummy ();if (!threads) goto out_put;
@@ -1504,7 +1504,7 @@ int perf_evlist__prepare_workload(struct evlist *evlist, struct target *target, __func__, __LINE__); goto out_close_pipes; } -thread_map__set_pid (evlist->threads,0 , evlist->workload.pid); +perf_thread_map__set_pid (evlist->threads,0 , evlist->workload.pid); }close (child_ready_pipe[1 ]);
tools/perf/util/thread_map.c +12 -47
130 lines not on this page · raw message
tools/perf/util/thread_map.h +1 -6
@@ -6,6 +6,7 @@#include <stdio.h> #include <linux/refcount.h> #include <internal/threadmap.h> +#include <perf/threadmap.h> struct thread_map_event ;
@@ -37,12 +38,6 @@ static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)return map->map[thread].pid; } -static inline void -thread_map__set_pid (struct perf_thread_map *map,int thread,pid_t pid) -{ - map->map[thread].pid = pid; -} -static inline char *thread_map__comm (struct perf_thread_map *map,int thread) {return map->map[thread].comm;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 60/107 libperf: Add perf_thread_map__get()/perf_thread_map__put()
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the following functions:
thread_map__get()
thread_map__put()
thread_map__comm()
to libperf with the following names:
perf_thread_map__get()
perf_thread_map__put()
perf_thread_map__comm()
Add the perf_thread_map__comm() function for it to work/compile.
--- tools/perf/builtin-record.c | 2 +- tools/perf/lib/include/perf/threadmap.h | 4 +++ tools/perf/lib/libperf.map | 3 ++ tools/perf/lib/threadmap.c | 33 ++++++++++++++++++++++ tools/perf/tests/code-reading.c | 4 +-- tools/perf/tests/event-times.c | 4 +-- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/mmap-thread-lookup.c | 2 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/openat-syscall.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/tests/thread-map.c | 18 ++++++------ tools/perf/util/event.c | 4 +-- tools/perf/util/evlist.c | 12 ++++---- tools/perf/util/evsel.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/python.c | 2 +- tools/perf/util/stat-display.c | 2 +- tools/perf/util/thread_map.c | 26 ----------------- tools/perf/util/thread_map.h | 8 ------ 23 files changed, 74 insertions(+), 68 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -1060,7 +1060,7 @@ static int record__synthesize_workload(struct record *rec, bool tail) process_synthesized_event, &rec->session->machines.host, rec->opts.sample_address); -thread_map__put (thread_map); +perf_thread_map__put (thread_map);return err; }
tools/perf/lib/include/perf/threadmap.h +4 -0
@@ -10,5 +10,9 @@ struct perf_thread_map; LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void); LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid); +LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread); + +LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map); +LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);#endif /* __LIBPERF_THREADMAP_H */
tools/perf/lib/libperf.map +3 -0
@@ -6,6 +6,9 @@ LIBPERF_0.0.1 { perf_cpu_map__put; perf_thread_map__new_dummy; perf_thread_map__set_pid; + perf_thread_map__comm; + perf_thread_map__get; + perf_thread_map__put; local: *; };
tools/perf/lib/threadmap.c +33 -0
@@ -4,6 +4,8 @@#include <linux/refcount.h> #include <internal/threadmap.h> #include <string.h> +#include <asm/bug.h> +#include <stdio.h> static void perf_thread_map__reset (struct perf_thread_map *map,int start,int nr) {
@@ -35,6 +37,11 @@ void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid map->map[thread].pid = pid; } +char *perf_thread_map__comm (struct perf_thread_map *map,int thread) +{ +return map->map[thread].comm; +} +struct perf_thread_map *perf_thread_map__new_dummy (void ) {struct perf_thread_map *threads =thread_map__alloc (1 );
@@ -46,3 +53,29 @@ struct perf_thread_map *perf_thread_map__new_dummy(void) }return threads; } + +static void perf_thread_map__delete (struct perf_thread_map *threads) +{ +if (threads) { +int i; + +WARN_ONCE (refcount_read (&threads->refcnt) !=0 , +"thread map refcnt unbalanced\n" ); +for (i =0 ; i < threads->nr; i++) +free (perf_thread_map__comm (threads, i)); +free (threads); + } +} + +struct perf_thread_map *perf_thread_map__get (struct perf_thread_map *map) +{ +if (map) +refcount_inc (&map->refcnt); +return map; +} + +void perf_thread_map__put (struct perf_thread_map *map) +{ +if (map &&refcount_dec_and_test (&map->refcnt)) +perf_thread_map__delete (map); +}
tools/perf/tests/code-reading.c +2 -2
@@ -656,7 +656,7 @@ static int do_test_code_reading(bool try_kcore)* call. Getting refference to keep them alive. */ perf_cpu_map__get (cpus); -thread_map__get (threads); +perf_thread_map__get (threads);perf_evlist__set_maps (evlist,NULL ,NULL );evlist__delete (evlist); evlist =NULL ;
@@ -706,7 +706,7 @@ static int do_test_code_reading(bool try_kcore)evlist__delete (evlist); }else {perf_cpu_map__put (cpus); -thread_map__put (threads); +perf_thread_map__put (threads); }machine__delete_threads (machine);machine__delete (machine);
tools/perf/tests/event-times.c +2 -2
@@ -76,7 +76,7 @@ static int attach__current_disabled(struct evlist *evlist)return err; } -thread_map__put (threads); +perf_thread_map__put (threads);return evsel__enable (evsel) ==0 ?TEST_OK :TEST_FAIL ; }
@@ -96,7 +96,7 @@ static int attach__current_enabled(struct evlist *evlist) err =perf_evsel__open_per_thread (evsel, threads); -thread_map__put (threads); +perf_thread_map__put (threads);return err ==0 ?TEST_OK :TEST_FAIL ; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -150,7 +150,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_unevlist__delete (evlist); }else {perf_cpu_map__put (cpus); -thread_map__put (threads); +perf_thread_map__put (threads); }return err;
tools/perf/tests/mmap-basic.c +1 -1
@@ -157,6 +157,6 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse out_free_cpus:perf_cpu_map__put (cpus); out_free_threads: -thread_map__put (threads); +perf_thread_map__put (threads);return err; }
tools/perf/tests/mmap-thread-lookup.c +1 -1
@@ -147,7 +147,7 @@ static int synth_process(struct machine *machine) perf_event__process, machine, 0); -thread_map__put (map); +perf_thread_map__put (map);return err; }
tools/perf/tests/openat-syscall-all-cpus.c +1 -1
@@ -122,6 +122,6 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int out_cpu_map_delete:perf_cpu_map__put (cpus); out_thread_map_delete: -thread_map__put (threads); +perf_thread_map__put (threads);return err; }
tools/perf/tests/openat-syscall.c +1 -1
@@ -61,6 +61,6 @@ int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __m out_evsel_delete:evsel__delete (evsel); out_thread_map_delete: -thread_map__put (threads); +perf_thread_map__put (threads);return err; }
tools/perf/tests/sw-clock.c +1 -1
@@ -126,7 +126,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) out_free_maps:perf_cpu_map__put (cpus); -thread_map__put (threads); +perf_thread_map__put (threads); out_delete_evlist:evlist__delete (evlist);return err;
tools/perf/tests/switch-tracking.c +1 -1
@@ -570,7 +570,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_evlist__delete (evlist); }else {perf_cpu_map__put (cpus); -thread_map__put (threads); +perf_thread_map__put (threads); }return err;
tools/perf/tests/task-exit.c +1 -1
@@ -136,7 +136,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused out_free_maps:perf_cpu_map__put (cpus); -thread_map__put (threads); +perf_thread_map__put (threads); out_delete_evlist:evlist__delete (evlist);return err;
tools/perf/tests/thread-map.c +9 -9
@@ -28,11 +28,11 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuseTEST_ASSERT_VAL ("wrong pid" ,thread_map__pid (map,0 ) ==getpid ());TEST_ASSERT_VAL ("wrong comm" , -thread_map__comm (map,0 ) && - !strcmp (thread_map__comm (map,0 ),NAME )); +perf_thread_map__comm (map,0 ) && + !strcmp (perf_thread_map__comm (map,0 ),NAME ));TEST_ASSERT_VAL ("wrong refcnt" ,refcount_read (&map->refcnt) ==1 ); -thread_map__put (map); +perf_thread_map__put (map);/* test dummy pid */ map =perf_thread_map__new_dummy ();
@@ -43,11 +43,11 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuseTEST_ASSERT_VAL ("wrong nr" , map->nr ==1 );TEST_ASSERT_VAL ("wrong pid" ,thread_map__pid (map,0 ) ==-1 );TEST_ASSERT_VAL ("wrong comm" , -thread_map__comm (map,0 ) && - !strcmp (thread_map__comm (map,0 ),"dummy" )); +perf_thread_map__comm (map,0 ) && + !strcmp (perf_thread_map__comm (map,0 ),"dummy" ));TEST_ASSERT_VAL ("wrong refcnt" ,refcount_read (&map->refcnt) ==1 ); -thread_map__put (map); +perf_thread_map__put (map);return 0 ; }
@@ -70,11 +70,11 @@ static int process_event(struct perf_tool *tool __maybe_unused,TEST_ASSERT_VAL ("wrong pid" ,thread_map__pid (threads,0 ) ==getpid ());TEST_ASSERT_VAL ("wrong comm" , -thread_map__comm (threads,0 ) && - !strcmp (thread_map__comm (threads,0 ),NAME )); +perf_thread_map__comm (threads,0 ) && + !strcmp (perf_thread_map__comm (threads,0 ),NAME ));TEST_ASSERT_VAL ("wrong refcnt" ,refcount_read (&threads->refcnt) ==1 ); -thread_map__put (threads); +perf_thread_map__put (threads);return 0 ; }
tools/perf/util/event.c +2 -2
@@ -992,7 +992,7 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,for (i =0 ; i < threads->nr; i++) {struct thread_map_event_entry *entry = &event->thread_map.entries[i]; -char *comm =thread_map__comm (threads, i); +char *comm =perf_thread_map__comm (threads, i);if (!comm) comm = (char *)"" ;
@@ -1387,7 +1387,7 @@ size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp)else ret +=fprintf (fp,"failed to get threads from event\n" ); -thread_map__put (threads); +perf_thread_map__put (threads);return ret; }
tools/perf/util/evlist.c +6 -6
@@ -142,7 +142,7 @@ void evlist__delete(struct evlist *evlist)perf_evlist__munmap (evlist);evlist__close (evlist);perf_cpu_map__put (evlist->cpus); -thread_map__put (evlist->threads); +perf_thread_map__put (evlist->threads); evlist->cpus =NULL ; evlist->threads =NULL ;perf_evlist__purge (evlist);
@@ -165,8 +165,8 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist, evsel->cpus =perf_cpu_map__get (evsel->own_cpus); } -thread_map__put (evsel->threads); - evsel->threads =thread_map__get (evlist->threads); +perf_thread_map__put (evsel->threads); + evsel->threads =perf_thread_map__get (evlist->threads); }static void perf_evlist__propagate_maps (struct evlist *evlist)
@@ -1100,7 +1100,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)return 0 ; out_delete_threads: -thread_map__put (threads); +perf_thread_map__put (threads);return -1 ; }
@@ -1120,8 +1120,8 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus, }if (threads != evlist->threads) { -thread_map__put (evlist->threads); - evlist->threads =thread_map__get (threads); +perf_thread_map__put (evlist->threads); + evlist->threads =perf_thread_map__get (threads); }perf_evlist__propagate_maps (evlist);
tools/perf/util/evsel.c +1 -1
@@ -1327,7 +1327,7 @@ void perf_evsel__exit(struct evsel *evsel)cgroup__put (evsel->cgrp);perf_cpu_map__put (evsel->cpus);perf_cpu_map__put (evsel->own_cpus); -thread_map__put (evsel->threads); +perf_thread_map__put (evsel->threads);zfree (&evsel->group_name);zfree (&evsel->name); perf_evsel__object.fini (evsel);
tools/perf/util/parse-events.c +1 -1
@@ -2337,7 +2337,7 @@ static bool is_event_supported(u8 type, unsigned config)evsel__delete (evsel); } -thread_map__put (tmap); +perf_thread_map__put (tmap);return ret; }
tools/perf/util/python.c +1 -1
@@ -626,7 +626,7 @@ static int pyrf_thread_map__init(struct pyrf_thread_map *pthreads,static void pyrf_thread_map__delete (struct pyrf_thread_map *pthreads) { -thread_map__put (pthreads->threads); +perf_thread_map__put (pthreads->threads);Py_TYPE (pthreads)->tp_free ((PyObject *)pthreads); }
tools/perf/util/stat-display.c +1 -1
@@ -116,7 +116,7 @@ static void aggr_printout(struct perf_stat_config *config,case AGGR_THREAD :fprintf (config->output,"%*s-%*d%s" , config->csv_output ?0 :16 , -thread_map__comm (evsel->threads, id), +perf_thread_map__comm (evsel->threads, id), config->csv_output ?0 :-8 ,thread_map__pid (evsel->threads, id), config->csv_sep);
tools/perf/util/thread_map.c +0 -26
@@ -304,32 +304,6 @@ struct perf_thread_map *thread_map__new_str(const char *pid, const char *tid,return thread_map__new_by_tid_str (tid); } -static void thread_map__delete (struct perf_thread_map *threads) -{ -if (threads) { -int i; - -WARN_ONCE (refcount_read (&threads->refcnt) !=0 , -"thread map refcnt unbalanced\n" ); -for (i =0 ; i < threads->nr; i++) -free (thread_map__comm (threads, i)); -free (threads); - } -} - -struct perf_thread_map *thread_map__get (struct perf_thread_map *map) -{ -if (map) -refcount_inc (&map->refcnt); -return map; -} - -void thread_map__put (struct perf_thread_map *map) -{ -if (map &&refcount_dec_and_test (&map->refcnt)) -thread_map__delete (map); -} -size_t thread_map__fprintf (struct perf_thread_map *threads,FILE *fp) {int i;
tools/perf/util/thread_map.h +0 -8
@@ -18,9 +18,6 @@ struct perf_thread_map *thread_map__new_all_cpus(void);struct perf_thread_map *thread_map__new (pid_t pid,pid_t tid,uid_t uid);struct perf_thread_map *thread_map__new_event (struct thread_map_event *event); -struct perf_thread_map *thread_map__get (struct perf_thread_map *map); -void thread_map__put (struct perf_thread_map *map); -struct perf_thread_map *thread_map__new_str (const char *pid,const char *tid,uid_t uid,bool all_threads);
@@ -38,11 +35,6 @@ static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)return map->map[thread].pid; } -static inline char *thread_map__comm (struct perf_thread_map *map,int thread) -{ -return map->map[thread].comm; -} -void thread_map__read_comms (struct perf_thread_map *threads);bool thread_map__has (struct perf_thread_map *threads,pid_t pid);int thread_map__remove (struct perf_thread_map *threads,int idx);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 61/107 libperf: Add perf_evlist and perf_evsel structs
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evlist and perf_evsel structs to libperf.
It's added as a declarations into:
include/perf/evlist.h
include/perf/evsel.h
which will be included by users.
The definitions are added into:
include/internal/evlist.h
include/internal/evsel.h
which is not to be included by users, but shared
within perf and libperf.
--- tools/perf/lib/Build | 2 ++ tools/perf/lib/evlist.c | 4 ++++ tools/perf/lib/evsel.c | 4 ++++ tools/perf/lib/include/internal/evlist.h | 9 +++++++++ tools/perf/lib/include/internal/evsel.h | 9 +++++++++ tools/perf/lib/include/perf/evlist.h | 7 +++++++ tools/perf/lib/include/perf/evsel.h | 7 +++++++ 7 files changed, 42 insertions(+) create mode 100644 tools/perf/lib/evlist.c create mode 100644 tools/perf/lib/evsel.c create mode 100644 tools/perf/lib/include/internal/evlist.h create mode 100644 tools/perf/lib/include/internal/evsel.h create mode 100644 tools/perf/lib/include/perf/evlist.h create mode 100644 tools/perf/lib/include/perf/evsel.h
tools/perf/lib/Build +2 -0
@@ -1,3 +1,5 @@ libperf-y += core.o libperf-y += cpumap.o libperf-y += threadmap.o +libperf-y += evsel.o +libperf-y += evlist.o
tools/perf/lib/evlist.c new file +4 -0
@@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <perf/evlist.h> +#include <linux/list.h> +#include <internal/evlist.h>
tools/perf/lib/evsel.c new file +4 -0
@@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <perf/evsel.h> +#include <linux/list.h> +#include <internal/evsel.h>
tools/perf/lib/include/internal/evlist.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_EVLIST_H +#define __LIBPERF_INTERNAL_EVLIST_H + +struct perf_evlist { +struct list_head entries; +}; + +#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/lib/include/internal/evsel.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_EVSEL_H +#define __LIBPERF_INTERNAL_EVSEL_H + +struct perf_evsel { +struct list_head node; +}; + +#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/lib/include/perf/evlist.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_EVLIST_H +#define __LIBPERF_EVLIST_H + +struct perf_evlist ; + +#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/include/perf/evsel.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_EVSEL_H +#define __LIBPERF_EVSEL_H + +struct perf_evsel ; + +#endif /* __LIBPERF_EVSEL_H */
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 62/107 libperf: Include perf_evsel in evsel object
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Including perf_evsel in evsel object, will continue to move other generic things into libperf's perf_evsel struct.
--- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/ui/browsers/hists.c | 8 ++++---- tools/perf/util/evlist.c | 16 ++++++++-------- tools/perf/util/evlist.h | 12 ++++++------ tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 16 ++++++++-------- tools/perf/util/parse-events.c | 20 ++++++++++---------- tools/perf/util/stat-display.c | 4 ++-- tools/perf/util/trace-event-info.c | 4 ++-- 10 files changed, 44 insertions(+), 44 deletions(-)
tools/perf/builtin-sched.c +1 -1
@@ -2929,7 +2929,7 @@ static int timehist_check_attr(struct perf_sched *sched,struct evsel *evsel;struct evsel_runtime *er; -list_for_each_entry (evsel, &evlist->entries, node) { +list_for_each_entry (evsel, &evlist->entries, core.node) { er =perf_evsel__get_runtime (evsel);if (er ==NULL ) {pr_err ("Failed to allocate memory for evsel runtime data\n" );
tools/perf/builtin-trace.c +1 -1
@@ -2636,7 +2636,7 @@ static bool evlist__add_vfs_getname(struct evlist *evlist)continue ; } -list_del_init (&evsel->node); +list_del_init (&evsel->core.node); evsel->evlist =NULL ;evsel__delete (evsel); }
tools/perf/ui/browsers/hists.c +4 -4
@@ -3212,7 +3212,7 @@ static void perf_evsel_menu__write(struct ui_browser *browser, {struct evsel_menu *menu =container_of (browser, struct evsel_menu, b); - struct evsel *evsel = list_entry(entry, struct evsel, node); + struct evsel *evsel = list_entry(entry, struct evsel, core.node);struct hists *hists =evsel__hists (evsel);bool current_entry =ui_browser__is_current_entry (browser, row);unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE ];
@@ -3309,13 +3309,13 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,ui_browser__show_title (&menu->b, title);switch (key) {case K_TAB : -if (pos->node.next == &evlist->entries) +if (pos->core.node.next == &evlist->entries) pos =perf_evlist__first (evlist);else pos =perf_evsel__next (pos); goto browse_hists;case K_UNTAB : -if (pos->node.prev == &evlist->entries) +if (pos->core.node.prev == &evlist->entries) pos =perf_evlist__last (evlist);else pos =perf_evsel__prev (pos);
@@ -3351,7 +3351,7 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,static bool filter_group_entries (struct ui_browser *browser__maybe_unused ,void *entry) { - struct evsel *evsel = list_entry(entry, struct evsel, node); + struct evsel *evsel = list_entry(entry, struct evsel, core.node);if (symbol_conf.event_group && !perf_evsel__is_group_leader (evsel))return true;
tools/perf/util/evlist.c +8 -8
@@ -119,7 +119,7 @@ static void perf_evlist__purge(struct evlist *evlist)struct evsel *pos, *n;evlist__for_each_entry_safe (evlist, n, pos) { -list_del_init (&pos->node); +list_del_init (&pos->core.node); pos->evlist =NULL ;evsel__delete (pos); }
@@ -180,7 +180,7 @@ static void perf_evlist__propagate_maps(struct evlist *evlist)void evlist__add (struct evlist *evlist,struct evsel *entry) { entry->evlist = evlist; -list_add_tail (&entry->node, &evlist->entries); +list_add_tail (&entry->core.node, &evlist->entries); entry->idx = evlist->nr_entries; entry->tracking = !entry->idx;
@@ -193,7 +193,7 @@ void evlist__add(struct evlist *evlist, struct evsel *entry)void evlist__remove (struct evlist *evlist,struct evsel *evsel) { evsel->evlist =NULL ; -list_del_init (&evsel->node); +list_del_init (&evsel->core.node); evlist->nr_entries -=1 ; }
@@ -203,7 +203,7 @@ void perf_evlist__splice_list_tail(struct evlist *evlist,struct evsel *evsel, *temp;__evlist__for_each_entry_safe (list, temp, evsel) { -list_del_init (&evsel->node); +list_del_init (&evsel->core.node);evlist__add (evlist, evsel); } }
@@ -212,8 +212,8 @@ void __perf_evlist__set_leader(struct list_head *list) {struct evsel *evsel, *leader; - leader = list_entry(list->next, struct evsel, node); - evsel = list_entry(list->prev, struct evsel, node); + leader = list_entry(list->next, struct evsel, core.node); + evsel = list_entry(list->prev, struct evsel, core.node); leader->nr_members = evsel->idx - leader->idx +1 ;
@@ -268,7 +268,7 @@ static int evlist__add_attrs(struct evlist *evlist, evsel =perf_evsel__new_idx (attrs + i, evlist->nr_entries + i);if (evsel ==NULL ) goto out_delete_partial_list; -list_add_tail (&evsel->node, &head); +list_add_tail (&evsel->core.node, &head); }perf_evlist__splice_list_tail (evlist, &head);
@@ -1680,7 +1680,7 @@ void perf_evlist__to_front(struct evlist *evlist,evlist__for_each_entry_safe (evlist, n, evsel) {if (evsel->leader == move_evsel->leader) -list_move_tail (&evsel->node, &move); +list_move_tail (&evsel->core.node, &move); }list_splice (&move, &evlist->entries);
tools/perf/util/evlist.h +6 -6
@@ -230,12 +230,12 @@ static inline bool perf_evlist__empty(struct evlist *evlist)static inline struct evsel *perf_evlist__first (struct evlist *evlist) { - return list_entry(evlist->entries.next, struct evsel, node); + return list_entry(evlist->entries.next, struct evsel, core.node); }static inline struct evsel *perf_evlist__last (struct evlist *evlist) { - return list_entry(evlist->entries.prev, struct evsel, node); + return list_entry(evlist->entries.prev, struct evsel, core.node); }size_t perf_evlist__fprintf (struct evlist *evlist,FILE *fp);
@@ -253,7 +253,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define __evlist__for_each_entry (list, evsel) \ - list_for_each_entry(evsel, list, node) + list_for_each_entry(evsel, list, core.node)/** * evlist__for_each_entry - iterate thru all the evsels
@@ -269,7 +269,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define __evlist__for_each_entry_continue (list, evsel) \ - list_for_each_entry_continue(evsel, list, node) + list_for_each_entry_continue(evsel, list, core.node)/** * evlist__for_each_entry_continue - continue iteration thru all the evsels
@@ -285,7 +285,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define __evlist__for_each_entry_reverse (list, evsel) \ - list_for_each_entry_reverse(evsel, list, node) + list_for_each_entry_reverse(evsel, list, core.node)/** * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
@@ -302,7 +302,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define __evlist__for_each_entry_safe (list, tmp, evsel) \ - list_for_each_entry_safe(evsel, tmp, list, node) + list_for_each_entry_safe(evsel, tmp, list, core.node)/** * evlist__for_each_entry_safe - safely iterate thru all the evsels
tools/perf/util/evsel.c +2 -2
@@ -236,7 +236,7 @@ void evsel__init(struct evsel *evsel, evsel->evlist =NULL ; evsel->bpf_obj =NULL ; evsel->bpf_fd =-1 ; -INIT_LIST_HEAD (&evsel->node); +INIT_LIST_HEAD (&evsel->core.node);INIT_LIST_HEAD (&evsel->config_terms); perf_evsel__object.init (evsel); evsel->sample_size =__perf_evsel__sample_size (attr->sample_type);
@@ -1318,7 +1318,7 @@ void perf_evsel__close_fd(struct evsel *evsel)void perf_evsel__exit (struct evsel *evsel) { -assert (list_empty (&evsel->node)); +assert (list_empty (&evsel->core.node));assert (evsel->evlist ==NULL );perf_evsel__free_counts (evsel);perf_evsel__free_fd (evsel);
tools/perf/util/evsel.h +8 -8
@@ -7,6 +7,7 @@#include <stddef.h> #include <linux/perf_event.h> #include <linux/types.h> +#include <internal/evsel.h> #include "xyarray.h" #include "symbol_conf.h" #include "cpumap.h"
@@ -87,8 +88,7 @@ struct bpf_object;/** struct evsel - event selector * * @evlist - evlist this evsel is in, if it is in one. -* @node - To insert it into evlist->entries or in other list_heads, say in -* the event parsing routines. +* @core - libperf evsel object * @name - Can be set to retain the original event name passed by the user, * so that when showing results in tools such as 'perf stat', we * show the name used, not some alias.
@@ -101,7 +101,7 @@ struct bpf_object;* @priv: And what is in its containing unnamed union are tool specific */ struct evsel { -struct list_head node; +struct perf_evsel core;struct evlist *evlist;struct perf_event_attr attr;char *filter;
@@ -386,12 +386,12 @@ int perf_evsel__parse_sample_timestamp(struct evsel *evsel,static inline struct evsel *perf_evsel__next (struct evsel *evsel) { - return list_entry(evsel->node.next, struct evsel, node); + return list_entry(evsel->core.node.next, struct evsel, core.node); }static inline struct evsel *perf_evsel__prev (struct evsel *evsel) { - return list_entry(evsel->node.prev, struct evsel, node); + return list_entry(evsel->core.node.prev, struct evsel, core.node); }/**
@@ -478,15 +478,15 @@ static inline int perf_evsel__group_idx(struct evsel *evsel)/* Iterates group WITHOUT the leader. */ #define for_each_group_member (_evsel, _leader) \ -for ((_evsel) = list_entry((_leader)->node.next, struct evsel, node); \ +for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \ (_evsel) && (_evsel)->leader == (_leader); \ - (_evsel) = list_entry((_evsel)->node.next, struct evsel, node)) + (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))/* Iterates group WITH the leader. */ #define for_each_group_evsel (_evsel, _leader) \ for ((_evsel) = _leader; \ (_evsel) && (_evsel)->leader == (_leader); \ - (_evsel) = list_entry((_evsel)->node.next, struct evsel, node)) + (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))static inline bool perf_evsel__has_branch_callstack (const struct evsel *evsel) {
tools/perf/util/parse-events.c +10 -10
@@ -343,7 +343,7 @@ __add_event(struct list_head *list, int *idx,if (config_terms)list_splice (config_terms, &evsel->config_terms); -list_add_tail (&evsel->node, list); +list_add_tail (&evsel->core.node, list);return evsel; }
@@ -526,7 +526,7 @@ static int add_tracepoint(struct list_head *list, int *idx,list_splice (&config_terms, &evsel->config_terms); } -list_add_tail (&evsel->node, list); +list_add_tail (&evsel->core.node, list);return 0 ; }
@@ -660,15 +660,15 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bppr_debug ("Failed to add BPF event %s:%s\n" , group, event); -list_for_each_entry_safe (evsel, tmp, &new_evsels, node) { -list_del_init (&evsel->node); +list_for_each_entry_safe (evsel, tmp, &new_evsels, core.node) { +list_del_init (&evsel->core.node);evsel__delete (evsel); }return err; }pr_debug ("adding %s:%s\n" , group, event); -list_for_each_entry (pos, &new_evsels, node) { +list_for_each_entry (pos, &new_evsels, core.node) {pr_debug ("adding %s:%s to %p\n" , group, event, pos); pos->bpf_fd = fd;
@@ -1458,8 +1458,8 @@ parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list,bool is_leader = true;int i, nr_pmu =0 , total_members, ret =0 ; - leader = list_first_entry(list, struct evsel, node); - evsel = list_last_entry(list, struct evsel, node); + leader = list_first_entry(list, struct evsel, core.node); + evsel = list_last_entry(list, struct evsel, core.node); total_members = evsel->idx - leader->idx +1 ; leaders =calloc (total_members,sizeof (uintptr_t ));
@@ -1555,7 +1555,7 @@ void parse_events__set_leader(char *name, struct list_head *list,return ;__perf_evlist__set_leader (list); - leader = list_entry(list->next, struct evsel, node); + leader = list_entry(list->next, struct evsel, core.node); leader->group_name = name ?strdup (name) :NULL ; }
@@ -2050,9 +2050,9 @@ foreach_evsel_in_last_glob(struct evlist *evlist,if (!last)return 0 ; -if (last->node.prev == &evlist->entries) +if (last->core.node.prev == &evlist->entries)return 0 ; - last = list_entry(last->node.prev, struct evsel, node); + last = list_entry(last->core.node.prev, struct evsel, core.node); }while (!last->cmdline_group_boundary);return 0 ;
tools/perf/util/stat-display.c +2 -2
@@ -548,8 +548,8 @@ static void collect_all_aliases(struct perf_stat_config *config, struct evsel *cstruct evlist *evlist = counter->evlist;struct evsel *alias; - alias =list_prepare_entry (counter, &(evlist->entries), node); - list_for_each_entry_continue (alias, &evlist->entries, node) { + alias =list_prepare_entry (counter, &(evlist->entries), core.node); + list_for_each_entry_continue (alias, &evlist->entries, core.node) { if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) || alias->scale != counter->scale || alias->cgrp != counter->cgrp ||
tools/perf/util/trace-event-info.c +2 -2
@@ -408,7 +408,7 @@ get_tracepoints_path(struct list_head *pattrs)struct evsel *pos;int nr_tracepoints =0 ; -list_for_each_entry (pos, pattrs, node) { +list_for_each_entry (pos, pattrs, core.node) {if (pos->attr.type !=PERF_TYPE_TRACEPOINT )continue ; ++nr_tracepoints;
@@ -443,7 +443,7 @@ bool have_tracepoints(struct list_head *pattrs) {struct evsel *pos; -list_for_each_entry (pos, pattrs, node) +list_for_each_entry (pos, pattrs, core.node)if (pos->attr.type ==PERF_TYPE_TRACEPOINT )return true;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 63/107 libperf: Include perf_evlist in evlist object
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Include perf_evlist in the evlist object, will continue to move other generic things into libperf's perf_evlist.
--- tools/perf/builtin-record.c | 4 ++-- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/ui/browsers/hists.c | 6 +++--- tools/perf/util/cgroup.c | 2 +- tools/perf/util/evlist.c | 8 ++++---- tools/perf/util/evlist.h | 17 +++++++++-------- tools/perf/util/header.c | 4 ++-- tools/perf/util/parse-events.c | 2 +- tools/perf/util/stat-display.c | 4 ++-- 10 files changed, 26 insertions(+), 25 deletions(-)
tools/perf/builtin-record.c +2 -2
@@ -1002,7 +1002,7 @@ static void record__init_features(struct record *rec)if (rec->no_buildid)perf_header__clear_feat (&session->header,HEADER_BUILD_ID ); -if (!have_tracepoints (&rec->evlist->entries)) +if (!have_tracepoints (&rec->evlist->core.entries))perf_header__clear_feat (&session->header,HEADER_TRACING_DATA );if (!rec->opts.branch_stack)
@@ -1218,7 +1218,7 @@ static int record__synthesize(struct record *rec, bool tail)return err; } -if (have_tracepoints (&rec->evlist->entries)) { +if (have_tracepoints (&rec->evlist->core.entries)) {/* * FIXME err <= 0 here actually means that * there were no tracepoints so its not really
tools/perf/builtin-sched.c +1 -1
@@ -2929,7 +2929,7 @@ static int timehist_check_attr(struct perf_sched *sched,struct evsel *evsel;struct evsel_runtime *er; -list_for_each_entry (evsel, &evlist->entries, core.node) { +list_for_each_entry (evsel, &evlist->core.entries, core.node) { er =perf_evsel__get_runtime (evsel);if (er ==NULL ) {pr_err ("Failed to allocate memory for evsel runtime data\n" );
tools/perf/builtin-trace.c +1 -1
@@ -3980,7 +3980,7 @@ static int trace__parse_cgroups(const struct option *opt, const char *str, int u {struct trace *trace = opt->value; -if (!list_empty (&trace->evlist->entries)) +if (!list_empty (&trace->evlist->core.entries))return parse_cgroups (opt, str, unset); trace->cgroup =evlist__findnew_cgroup (trace->evlist, str);
tools/perf/ui/browsers/hists.c +3 -3
@@ -3309,13 +3309,13 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,ui_browser__show_title (&menu->b, title);switch (key) {case K_TAB : -if (pos->core.node.next == &evlist->entries) +if (pos->core.node.next == &evlist->core.entries) pos =perf_evlist__first (evlist);else pos =perf_evsel__next (pos); goto browse_hists;case K_UNTAB : -if (pos->core.node.prev == &evlist->entries) +if (pos->core.node.prev == &evlist->core.entries) pos =perf_evlist__last (evlist);else pos =perf_evsel__prev (pos);
@@ -3370,7 +3370,7 @@ static int __perf_evlist__tui_browse_hists(struct evlist *evlist,struct evsel *pos;struct evsel_menu menu = { .b = { - .entries = &evlist->entries, + .entries = &evlist->core.entries, .refresh = ui_browser__list_head_refresh, .seek = ui_browser__list_head_seek, .write = perf_evsel_menu__write,
tools/perf/util/cgroup.c +1 -1
@@ -208,7 +208,7 @@ int parse_cgroups(const struct option *opt, const char *str,char *s;int ret, i; -if (list_empty (&evlist->entries)) { +if (list_empty (&evlist->core.entries)) {fprintf (stderr,"must define events before cgroups\n" );return -1 ; }
tools/perf/util/evlist.c +4 -4
@@ -48,7 +48,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,for (i =0 ; i <PERF_EVLIST__HLIST_SIZE ; ++i)INIT_HLIST_HEAD (&evlist->heads[i]); -INIT_LIST_HEAD (&evlist->entries); +INIT_LIST_HEAD (&evlist->core.entries);perf_evlist__set_maps (evlist, cpus, threads);fdarray__init (&evlist->pollfd,64 ); evlist->workload.pid =-1 ;
@@ -180,7 +180,7 @@ static void perf_evlist__propagate_maps(struct evlist *evlist)void evlist__add (struct evlist *evlist,struct evsel *entry) { entry->evlist = evlist; -list_add_tail (&entry->core.node, &evlist->entries); +list_add_tail (&entry->core.node, &evlist->core.entries); entry->idx = evlist->nr_entries; entry->tracking = !entry->idx;
@@ -226,7 +226,7 @@ void perf_evlist__set_leader(struct evlist *evlist) {if (evlist->nr_entries) { evlist->nr_groups = evlist->nr_entries >1 ?1 :0 ; -__perf_evlist__set_leader (&evlist->entries); +__perf_evlist__set_leader (&evlist->core.entries); } }
@@ -1683,7 +1683,7 @@ void perf_evlist__to_front(struct evlist *evlist,list_move_tail (&evsel->core.node, &move); } -list_splice (&move, &evlist->entries); +list_splice (&move, &evlist->core.entries); } void perf_evlist__set_tracking_event(struct evlist *evlist,
tools/perf/util/evlist.h +9 -8
@@ -8,6 +8,7 @@#include <linux/list.h> #include <api/fd/array.h> #include <stdio.h> +#include <internal/evlist.h> #include "../perf.h" #include "event.h" #include "evsel.h"
@@ -25,7 +26,7 @@ struct record_opts;#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)struct evlist { -struct list_head entries; +struct perf_evlist core;struct hlist_head heads[PERF_EVLIST__HLIST_SIZE ];int nr_entries;int nr_groups;
@@ -225,17 +226,17 @@ void perf_evlist__splice_list_tail(struct evlist *evlist,static inline bool perf_evlist__empty (struct evlist *evlist) { -return list_empty (&evlist->entries); +return list_empty (&evlist->core.entries); }static inline struct evsel *perf_evlist__first (struct evlist *evlist) { - return list_entry(evlist->entries.next, struct evsel, core.node); + return list_entry(evlist->core.entries.next, struct evsel, core.node); }static inline struct evsel *perf_evlist__last (struct evlist *evlist) { - return list_entry(evlist->entries.prev, struct evsel, core.node); + return list_entry(evlist->core.entries.prev, struct evsel, core.node); }size_t perf_evlist__fprintf (struct evlist *evlist,FILE *fp);
@@ -261,7 +262,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define evlist__for_each_entry (evlist, evsel) \ - __evlist__for_each_entry(&(evlist)->entries, evsel) + __evlist__for_each_entry(&(evlist)->core.entries, evsel)/** * __evlist__for_each_entry_continue - continue iteration thru all the evsels
@@ -277,7 +278,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define evlist__for_each_entry_continue (evlist, evsel) \ - __evlist__for_each_entry_continue(&(evlist)->entries, evsel) + __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)/** * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
@@ -293,7 +294,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @evsel: struct evsel iterator */ #define evlist__for_each_entry_reverse (evlist, evsel) \ - __evlist__for_each_entry_reverse(&(evlist)->entries, evsel) + __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)/** * __evlist__for_each_entry_safe - safely iterate thru all the evsels
@@ -311,7 +312,7 @@ void perf_evlist__to_front(struct evlist *evlist,* @tmp: struct evsel temp iterator */ #define evlist__for_each_entry_safe (evlist, tmp, evsel) \ - __evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel) + __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)void perf_evlist__set_tracking_event (struct evlist *evlist,struct evsel *tracking_evsel);
tools/perf/util/header.c +2 -2
@@ -304,7 +304,7 @@ static int write_tracing_data(struct feat_fd *ff,if (WARN (ff->buf,"Error: calling %s in pipe-mode.\n" , __func__))return -1 ; -return read_tracing_data (ff->fd, &evlist->entries); +return read_tracing_data (ff->fd, &evlist->core.entries); } static int write_build_id(struct feat_fd *ff,
@@ -4112,7 +4112,7 @@ int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd,* - write the tracing data from the temp file * to the pipe */ - tdata =tracing_data_get (&evlist->entries, fd, true); + tdata =tracing_data_get (&evlist->core.entries, fd, true);if (!tdata)return -1 ;
tools/perf/util/parse-events.c +1 -1
@@ -2050,7 +2050,7 @@ foreach_evsel_in_last_glob(struct evlist *evlist,if (!last)return 0 ; -if (last->core.node.prev == &evlist->entries) +if (last->core.node.prev == &evlist->core.entries)return 0 ; last = list_entry(last->core.node.prev, struct evsel, core.node); }while (!last->cmdline_group_boundary);
tools/perf/util/stat-display.c +2 -2
@@ -548,8 +548,8 @@ static void collect_all_aliases(struct perf_stat_config *config, struct evsel *cstruct evlist *evlist = counter->evlist;struct evsel *alias; - alias =list_prepare_entry (counter, &(evlist->entries), core.node); - list_for_each_entry_continue (alias, &evlist->entries, core.node) { + alias =list_prepare_entry (counter, &(evlist->core.entries), core.node); + list_for_each_entry_continue (alias, &evlist->core.entries, core.node) { if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) || alias->scale != counter->scale || alias->cgrp != counter->cgrp ||
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 64/107 libperf: Add perf_evsel__init function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evsel__init() function to initialize perf_evsel struct.
--- tools/perf/lib/evsel.c | 5 +++++ tools/perf/lib/include/perf/evsel.h | 4 ++++ tools/perf/lib/libperf.map | 1 + tools/perf/util/evsel.c | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/lib/evsel.c +5 -0
@@ -2,3 +2,8 @@#include <perf/evsel.h> #include <linux/list.h> #include <internal/evsel.h> + +void perf_evsel__init (struct perf_evsel *evsel) +{ +INIT_LIST_HEAD (&evsel->node); +}
tools/perf/lib/include/perf/evsel.h +4 -0
@@ -2,6 +2,10 @@#ifndef __LIBPERF_EVSEL_H#define __LIBPERF_EVSEL_H +#include <perf/core.h> +struct perf_evsel ; +LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel); +#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -9,6 +9,7 @@ LIBPERF_0.0.1 { perf_thread_map__comm; perf_thread_map__get; perf_thread_map__put; + perf_evsel__init; local: *; };
tools/perf/util/evsel.c +2 -1
@@ -22,6 +22,7 @@#include <sys/resource.h> #include <sys/types.h> #include <dirent.h> +#include <perf/evsel.h> #include "asm/bug.h" #include "callchain.h" #include "cgroup.h"
@@ -226,6 +227,7 @@ bool perf_evsel__is_function_event(struct evsel *evsel)void evsel__init (struct evsel *evsel,struct perf_event_attr *attr,int idx) { +perf_evsel__init (&evsel->core); evsel->idx = idx; evsel->tracking = !idx; evsel->attr = *attr;
@@ -236,7 +238,6 @@ void evsel__init(struct evsel *evsel, evsel->evlist =NULL ; evsel->bpf_obj =NULL ; evsel->bpf_fd =-1 ; -INIT_LIST_HEAD (&evsel->core.node);INIT_LIST_HEAD (&evsel->config_terms); perf_evsel__object.init (evsel); evsel->sample_size =__perf_evsel__sample_size (attr->sample_type);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 65/107 libperf: Add perf_evlist__init() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evlist__init() function to initialize a perf_evlist struct.
Committer testing:
Fix a change in init ordering that was causing this backtrace:
(gdb) run stat sleep 1
Starting program: /root/bin/perf stat sleep 1
Program received signal SIGSEGV, Segmentation fault.
0x00000000004f6b55 in __perf_evlist__propagate_maps (evlist=0xbb34c0, evsel=0x0) at util/evlist.c:161
161 if (!evsel->own_cpus || evlist->has_user_cpus) {
Missing separate debuginfos, use: dnf debuginfo-install bzip2-libs-1.0.6-29.fc30.x86_64 elfutils-libelf-0.176-3.fc30.x86_64 elfutils-libs-0.176-3.fc30.x86_64 glib2-2.60.4-1.fc30.x86_64 libbabeltrace-1.5.6-2.fc30.x86_64 libgcc-9.1.1-1.fc30.x86_64 libunwind-1.3.1-2.fc30.x86_64 libuuid-2.33.2-1.fc30.x86_64 libxcrypt-4.4.6-2.fc30.x86_64 libzstd-1.4.0-1.fc30.x86_64 numactl-libs-2.0.12-2.fc30.x86_64 pcre-8.43-2.fc30.x86_64 perl-libs-5.28.2-436.fc30.x86_64 popt-1.16-17.fc30.x86_64 python2-libs-2.7.16-2.fc30.x86_64 slang-2.3.2-5.fc30.x86_64 xz-libs-5.2.4-5.fc30.x86_64 zlib-1.2.11-15.fc30.x86_64 (gdb) bt
#0 0x00000000004f6b55 in __perf_evlist__propagate_maps (evlist=0xbb34c0, evsel=0x0) at util/evlist.c:161 #1 0x00000000004f6c7a in perf_evlist__propagate_maps (evlist=0xbb34c0) at util/evlist.c:178 #2 0x00000000004f955e in perf_evlist__set_maps (evlist=0xbb34c0, cpus=0x0, threads=0x0) at util/evlist.c:1128 #3 0x00000000004f66f8 in evlist__init (evlist=0xbb34c0, cpus=0x0, threads=0x0) at util/evlist.c:52 #4 0x00000000004f6790 in evlist__new () at util/evlist.c:64 #5 0x0000000000456071 in cmd_stat (argc=3, argv=0x7fffffffd670) at builtin-stat.c:1705 #6 0x00000000004dd0fa in run_builtin (p=0xa21e00 <commands+288>, argc=3, argv=0x7fffffffd670) at perf.c:304 #7 0x00000000004dd367 in handle_internal_command (argc=3, argv=0x7fffffffd670) at perf.c:356 #8 0x00000000004dd4ae in run_argv (argcp=0x7fffffffd4cc, argv=0x7fffffffd4c0) at perf.c:400 #9 0x00000000004dd81a in main (argc=3, argv=0x7fffffffd670) at perf.c:522
(gdb) bt
So move the initialization of the core evlist (calling perf_evlist__init()) to before perf_evlist__set_maps() in evlist__init().
--- tools/perf/lib/evlist.c | 5 +++++ tools/perf/lib/include/perf/evlist.h | 4 ++++ tools/perf/lib/libperf.map | 1 + tools/perf/util/evlist.c | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/lib/evlist.c +5 -0
@@ -2,3 +2,8 @@#include <perf/evlist.h> #include <linux/list.h> #include <internal/evlist.h> + +void perf_evlist__init (struct perf_evlist *evlist) +{ +INIT_LIST_HEAD (&evlist->entries); +}
tools/perf/lib/include/perf/evlist.h +4 -0
@@ -2,6 +2,10 @@#ifndef __LIBPERF_EVLIST_H#define __LIBPERF_EVLIST_H +#include <perf/core.h> +struct perf_evlist ; +LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist); +#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -10,6 +10,7 @@ LIBPERF_0.0.1 { perf_thread_map__get; perf_thread_map__put; perf_evsel__init; + perf_evlist__init; local: *; };
tools/perf/util/evlist.c +2 -1
@@ -33,6 +33,7 @@#include <linux/log2.h> #include <linux/err.h> #include <linux/zalloc.h> +#include <perf/evlist.h> #ifdef LACKS_SIGQUEUE_PROTOTYPE int sigqueue (pid_t pid,int sig,const union sigval value);
@@ -48,7 +49,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,for (i =0 ; i <PERF_EVLIST__HLIST_SIZE ; ++i)INIT_HLIST_HEAD (&evlist->heads[i]); -INIT_LIST_HEAD (&evlist->core.entries); +perf_evlist__init (&evlist->core);perf_evlist__set_maps (evlist, cpus, threads);fdarray__init (&evlist->pollfd,64 ); evlist->workload.pid =-1 ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 66/107 libperf: Add perf_evlist__add() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evlist__add() function to add a perf_evsel in a perf_evlist struct.
--- tools/perf/lib/evlist.c | 7 +++++++ tools/perf/lib/include/perf/evlist.h | 3 +++ tools/perf/lib/libperf.map | 1 + tools/perf/util/evlist.c | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/lib/evlist.c +7 -0
@@ -2,8 +2,15 @@#include <perf/evlist.h> #include <linux/list.h> #include <internal/evlist.h> +#include <internal/evsel.h> void perf_evlist__init (struct perf_evlist *evlist) {INIT_LIST_HEAD (&evlist->entries); } + +void perf_evlist__add (struct perf_evlist *evlist, +struct perf_evsel *evsel) +{ +list_add_tail (&evsel->node, &evlist->entries); +}
tools/perf/lib/include/perf/evlist.h +3 -0
@@ -5,7 +5,10 @@#include <perf/core.h> struct perf_evlist ; +struct perf_evsel ; LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist); +LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, +struct perf_evsel *evsel);#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -11,6 +11,7 @@ LIBPERF_0.0.1 { perf_thread_map__put; perf_evsel__init; perf_evlist__init; + perf_evlist__add; local: *; };
tools/perf/util/evlist.c +1 -1
@@ -180,8 +180,8 @@ static void perf_evlist__propagate_maps(struct evlist *evlist)void evlist__add (struct evlist *evlist,struct evsel *entry) { +perf_evlist__add (&evlist->core, &entry->core); entry->evlist = evlist; -list_add_tail (&entry->core.node, &evlist->core.entries); entry->idx = evlist->nr_entries; entry->tracking = !entry->idx;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 67/107 libperf: Add perf_evlist__remove() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding perf_evlist__remove() function to remove a perf_evsel from a perf_evlist struct.
--- tools/perf/lib/evlist.c | 6 ++++++ tools/perf/lib/include/perf/evlist.h | 2 ++ tools/perf/lib/libperf.map | 1 + tools/perf/util/evlist.c | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/lib/evlist.c +6 -0
@@ -14,3 +14,9 @@ void perf_evlist__add(struct perf_evlist *evlist, {list_add_tail (&evsel->node, &evlist->entries); } + +void perf_evlist__remove (struct perf_evlist *evlist, +struct perf_evsel *evsel) +{ +list_del_init (&evsel->node); +}
tools/perf/lib/include/perf/evlist.h +2 -0
@@ -10,5 +10,7 @@ struct perf_evsel; LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist); LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,struct perf_evsel *evsel); +LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist, +struct perf_evsel *evsel);#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 { perf_evsel__init; perf_evlist__init; perf_evlist__add; + perf_evlist__remove; local: *; };
tools/perf/util/evlist.c +1 -1
@@ -194,7 +194,7 @@ void evlist__add(struct evlist *evlist, struct evsel *entry)void evlist__remove (struct evlist *evlist,struct evsel *evsel) { evsel->evlist =NULL ; -list_del_init (&evsel->core.node); +perf_evlist__remove (&evlist->core, &evsel->core); evlist->nr_entries -=1 ; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 68/107 libperf: Add nr_entries to struct perf_evlist
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move nr_entries count from 'struct perf' to into perf_evlist struct.
Committer notes:
Fix tools/perf/arch/s390/util/auxtrace.c case. And also the comment in tools/perf/util/annotate.h.
--- tools/perf/arch/s390/util/auxtrace.c | 2 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-stat.c | 4 +- tools/perf/builtin-top.c | 12 ++-- tools/perf/builtin-trace.c | 4 +- tools/perf/lib/evlist.c | 3 + tools/perf/lib/include/internal/evlist.h | 1 + tools/perf/tests/parse-events.c | 76 ++++++++++++------------ tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/annotate.c | 2 +- tools/perf/util/annotate.h | 2 +- tools/perf/util/evlist.c | 26 ++++---- tools/perf/util/evlist.h | 1 - tools/perf/util/header.c | 4 +- tools/perf/util/parse-events.c | 4 +- tools/perf/util/python.c | 8 +-- tools/perf/util/record.c | 2 +- tools/perf/util/sort.c | 2 +- tools/perf/util/top.c | 2 +- 20 files changed, 83 insertions(+), 80 deletions(-)
tools/perf/arch/s390/util/auxtrace.c +1 -1
@@ -90,7 +90,7 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,int diagnose =0 ; *err =0 ; -if (evlist->nr_entries ==0 ) +if (evlist->core.nr_entries ==0 )return NULL ;evlist__for_each_entry (evlist, pos) {
tools/perf/builtin-record.c +2 -2
@@ -1375,7 +1375,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)* because we synthesize event name through the pipe * and need the id for that. */ -if (data->is_pipe && rec->evlist->nr_entries ==1 ) +if (data->is_pipe && rec->evlist->core.nr_entries ==1 ) rec->opts.sample_id = true;if (record__open (rec) !=0 ) {
@@ -2386,7 +2386,7 @@ int cmd_record(int argc, const char **argv)if (record.opts.overwrite) record.opts.tail_synthesize = true; -if (rec->evlist->nr_entries ==0 && +if (rec->evlist->core.nr_entries ==0 &&__perf_evlist__add_default (rec->evlist, !record.opts.no_samples) <0 ) {pr_err ("Not enough memory for event selector list\n" ); goto out;
tools/perf/builtin-stat.c +2 -2
@@ -1366,7 +1366,7 @@ static int add_default_attributes(void)free (str); } -if (!evsel_list->nr_entries) { +if (!evsel_list->core.nr_entries) {if (target__has_cpu (&target)) default_attrs0[0 ].config =PERF_COUNT_SW_CPU_CLOCK ;
@@ -1683,7 +1683,7 @@ static void setup_system_wide(int forks)return ; } -if (evsel_list->nr_entries) +if (evsel_list->core.nr_entries) target.system_wide = true; } }
tools/perf/builtin-top.c +6 -6
@@ -129,7 +129,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) notes =symbol__annotation (sym);pthread_mutex_lock (¬es->lock); -if (!symbol__hists (sym, top->evlist->nr_entries)) { +if (!symbol__hists (sym, top->evlist->core.nr_entries)) {pthread_mutex_unlock (¬es->lock);pr_err ("Not enough memory for annotating '%s' symbol!\n" , sym->name);
@@ -404,7 +404,7 @@ static void perf_top__print_mapped_keys(struct perf_top *top)fprintf (stdout,"\t[d] display refresh delay. \t(%d)\n" , top->delay_secs);fprintf (stdout,"\t[e] display entries (lines). \t(%d)\n" , top->print_entries); -if (top->evlist->nr_entries >1 ) +if (top->evlist->core.nr_entries >1 )fprintf (stdout,"\t[E] active event counter. \t(%s)\n" ,perf_evsel__name (top->sym_evsel));fprintf (stdout,"\t[f] profile display filter (count). \t(%d)\n" , top->count_filter);
@@ -439,7 +439,7 @@ static int perf_top__key_mapped(struct perf_top *top, int c)case 'S' :return 1 ;case 'E' : -return top->evlist->nr_entries >1 ?1 :0 ; +return top->evlist->core.nr_entries >1 ?1 :0 ;default :break ; }
@@ -485,7 +485,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c) }break ;case 'E' : -if (top->evlist->nr_entries >1 ) { +if (top->evlist->core.nr_entries >1 ) {/* Select 0 as the default event: */ int counter =0 ;
@@ -496,7 +496,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)prompt_integer (&counter,"Enter details event counter" ); -if (counter >= top->evlist->nr_entries) { +if (counter >= top->evlist->core.nr_entries) { top->sym_evsel =perf_evlist__first (top->evlist);fprintf (stderr,"Sorry, no such event, using %s.\n" ,perf_evsel__name (top->sym_evsel));sleep (1 );
@@ -1536,7 +1536,7 @@ int cmd_top(int argc, const char **argv)if (argc)usage_with_options (top_usage, options); -if (!top.evlist->nr_entries && +if (!top.evlist->core.nr_entries &&perf_evlist__add_default (top.evlist) <0 ) {pr_err ("Not enough memory for event selector list\n" ); goto out_delete_evlist;
tools/perf/builtin-trace.c +2 -2
@@ -4270,7 +4270,7 @@ int cmd_trace(int argc, const char **argv) symbol_conf.use_callchain = true; } -if (trace.evlist->nr_entries >0 ) { +if (trace.evlist->core.nr_entries >0 ) {evlist__set_evsel_handler (trace.evlist, trace__event_handler);if (evlist__set_syscall_tp_fields (trace.evlist)) {perror ("failed to set syscalls:* tracepoint fields" );
@@ -4368,7 +4368,7 @@ int cmd_trace(int argc, const char **argv) trace.summary = trace.summary_only;if (!trace.trace_syscalls && !trace.trace_pgfaults && - trace.evlist->nr_entries ==0 /* Was --events used? */ ) { + trace.evlist->core.nr_entries ==0 /* Was --events used? */ ) { trace.trace_syscalls = true; }
tools/perf/lib/evlist.c +3 -0
@@ -7,16 +7,19 @@void perf_evlist__init (struct perf_evlist *evlist) {INIT_LIST_HEAD (&evlist->entries); + evlist->nr_entries =0 ; }void perf_evlist__add (struct perf_evlist *evlist,struct perf_evsel *evsel) {list_add_tail (&evsel->node, &evlist->entries); + evlist->nr_entries +=1 ; }void perf_evlist__remove (struct perf_evlist *evlist,struct perf_evsel *evsel) {list_del_init (&evsel->node); + evlist->nr_entries -=1 ; }
tools/perf/lib/include/internal/evlist.h +1 -0
@@ -4,6 +4,7 @@struct perf_evlist {struct list_head entries; +int nr_entries; };#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/tests/parse-events.c +38 -38
304 lines not on this page · raw message
tools/perf/ui/browsers/annotate.c +1 -1
@@ -422,7 +422,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser, notes =symbol__annotation (dl->ops.target.sym);pthread_mutex_lock (¬es->lock); -if (!symbol__hists (dl->ops.target.sym, evsel->evlist->nr_entries)) { +if (!symbol__hists (dl->ops.target.sym, evsel->evlist->core.nr_entries)) {pthread_mutex_unlock (¬es->lock);ui__warning ("Not enough memory for annotating '%s' symbol!\n" , dl->ops.target.sym->name);
tools/perf/ui/browsers/hists.c +1 -1
@@ -3404,7 +3404,7 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,bool warn_lost_event, struct annotation_options *annotation_opts) { - int nr_entries = evlist->nr_entries; + int nr_entries = evlist->core.nr_entries; single_entry:if (nr_entries ==1 ) {
tools/perf/util/annotate.c +1 -1
@@ -936,7 +936,7 @@ static int symbol__inc_addr_samples(struct symbol *sym, struct map *map,if (sym ==NULL )return 0 ; - src =symbol__hists (sym, evsel->evlist->nr_entries); + src =symbol__hists (sym, evsel->evlist->core.nr_entries);return (src) ?__symbol__inc_addr_samples (sym, map, src, evsel->idx, addr, sample) :0 ; }
tools/perf/util/annotate.h +1 -1
@@ -245,7 +245,7 @@ struct cyc_hist {/** struct annotated_source - symbols with hits have this attached as in sannotation * * @histograms: Array of addr hit histograms per event being monitored -* nr_histograms: This may not be the same as evsel->evlist->nr_entries if +* nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if * we have more than a group in a evlist, where we will want * to see each group separately, that is why symbol__annotate2() * sets src->nr_histograms to evsel->nr_members.
tools/perf/util/evlist.c +13 -13
@@ -125,7 +125,7 @@ static void perf_evlist__purge(struct evlist *evlist)evsel__delete (pos); } - evlist->nr_entries =0 ; + evlist->core.nr_entries =0 ; }void perf_evlist__exit (struct evlist *evlist)
@@ -180,12 +180,13 @@ static void perf_evlist__propagate_maps(struct evlist *evlist)void evlist__add (struct evlist *evlist,struct evsel *entry) { -perf_evlist__add (&evlist->core, &entry->core); entry->evlist = evlist; - entry->idx = evlist->nr_entries; + entry->idx = evlist->core.nr_entries; entry->tracking = !entry->idx; -if (!evlist->nr_entries++) +perf_evlist__add (&evlist->core, &entry->core); + +if (evlist->core.nr_entries ==1 )perf_evlist__set_id_pos (evlist);__perf_evlist__propagate_maps (evlist, entry);
@@ -195,7 +196,6 @@ void evlist__remove(struct evlist *evlist, struct evsel *evsel) { evsel->evlist =NULL ;perf_evlist__remove (&evlist->core, &evsel->core); - evlist->nr_entries -=1 ; } void perf_evlist__splice_list_tail(struct evlist *evlist,
@@ -225,8 +225,8 @@ void __perf_evlist__set_leader(struct list_head *list)void perf_evlist__set_leader (struct evlist *evlist) { -if (evlist->nr_entries) { - evlist->nr_groups = evlist->nr_entries >1 ?1 :0 ; +if (evlist->core.nr_entries) { + evlist->nr_groups = evlist->core.nr_entries >1 ?1 :0 ;__perf_evlist__set_leader (&evlist->core.entries); } }
@@ -249,7 +249,7 @@ int perf_evlist__add_dummy(struct evlist *evlist) .config = PERF_COUNT_SW_DUMMY, .size = sizeof(attr), /* to capture ABI version */ }; -struct evsel *evsel =perf_evsel__new_idx (&attr, evlist->nr_entries); +struct evsel *evsel =perf_evsel__new_idx (&attr, evlist->core.nr_entries);if (evsel ==NULL )return -ENOMEM ;
@@ -266,7 +266,7 @@ static int evlist__add_attrs(struct evlist *evlist,size_t i;for (i =0 ; i < nr_attrs; i++) { - evsel =perf_evsel__new_idx (attrs + i, evlist->nr_entries + i); + evsel =perf_evsel__new_idx (attrs + i, evlist->core.nr_entries + i);if (evsel ==NULL ) goto out_delete_partial_list;list_add_tail (&evsel->core.node, &head);
@@ -581,7 +581,7 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id) {struct perf_sample_id *sid; -if (evlist->nr_entries ==1 || !id) +if (evlist->core.nr_entries ==1 || !id)return perf_evlist__first (evlist); sid =perf_evlist__id2sid (evlist, id);
@@ -639,7 +639,7 @@ struct evsel *perf_evlist__event2evsel(struct evlist *evlist,int hash;u64 id; -if (evlist->nr_entries ==1 ) +if (evlist->core.nr_entries ==1 )return first; if (!first->attr.sample_id_all &&
@@ -1222,7 +1222,7 @@ bool perf_evlist__valid_sample_type(struct evlist *evlist) {struct evsel *pos; -if (evlist->nr_entries ==1 ) +if (evlist->core.nr_entries ==1 )return true;if (evlist->id_pos <0 || evlist->is_pos <0 )
@@ -1849,7 +1849,7 @@ int perf_evlist__add_sb_event(struct evlist **evlist, attr->sample_id_all =1 ; } - evsel =perf_evsel__new_idx (attr, (*evlist)->nr_entries); + evsel =perf_evsel__new_idx (attr, (*evlist)->core.nr_entries);if (!evsel) goto out_err;
tools/perf/util/evlist.h +0 -1
@@ -28,7 +28,6 @@ struct record_opts;struct evlist {struct perf_evlist core;struct hlist_head heads[PERF_EVLIST__HLIST_SIZE ]; -int nr_entries;int nr_groups;int nr_mmaps;bool enabled;
tools/perf/util/header.c +2 -2
@@ -476,7 +476,7 @@ static int write_event_desc(struct feat_fd *ff,u32 nre, nri, sz;int ret; - nre = evlist->nr_entries; + nre = evlist->core.nr_entries;/* * write number of events
@@ -3100,7 +3100,7 @@ int perf_session__write_header(struct perf_session *session, .attr_size = sizeof(f_attr), .attrs = { .offset = attr_offset, - .size = evlist->nr_entries * sizeof(f_attr), + .size = evlist->core.nr_entries * sizeof(f_attr), }, .data = { .offset = header->data_offset,
tools/perf/util/parse-events.c +2 -2
@@ -1909,7 +1909,7 @@ int parse_events(struct evlist *evlist, const char *str, {struct parse_events_state parse_state = { .list =LIST_HEAD_INIT (parse_state.list), - .idx = evlist->nr_entries, + .idx = evlist->core.nr_entries, .error = err, .evlist = evlist, };
@@ -2040,7 +2040,7 @@ foreach_evsel_in_last_glob(struct evlist *evlist,* * So no need to WARN here, let *func do this. */ -if (evlist->nr_entries >0 ) +if (evlist->core.nr_entries >0 ) last =perf_evlist__last (evlist); do {
tools/perf/util/python.c +4 -4
@@ -973,10 +973,10 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist *pevlist,Py_INCREF (pevsel); evsel = &((struct pyrf_evsel *)pevsel)->evsel; - evsel->idx = evlist->nr_entries; + evsel->idx = evlist->core.nr_entries;evlist__add (evlist, evsel); -return Py_BuildValue ("i" , evlist->nr_entries); +return Py_BuildValue ("i" , evlist->core.nr_entries); }static struct perf_mmap *get_md (struct evlist *evlist,int cpu)
@@ -1112,7 +1112,7 @@ static Py_ssize_t pyrf_evlist__length(PyObject *obj) {struct pyrf_evlist *pevlist = (void *)obj; -return pevlist->evlist.nr_entries; +return pevlist->evlist.core.nr_entries; }static PyObject *pyrf_evlist__item (PyObject *obj,Py_ssize_t i)
@@ -1120,7 +1120,7 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i)struct pyrf_evlist *pevlist = (void *)obj;struct evsel *pos; -if (i >= pevlist->evlist.nr_entries) +if (i >= pevlist->evlist.core.nr_entries)return NULL ;evlist__for_each_entry (&pevlist->evlist, pos) {
tools/perf/util/record.c +1 -1
@@ -166,7 +166,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,*/ use_sample_identifier =perf_can_sample_identifier (); sample_id = true; - }else if (evlist->nr_entries >1 ) { + }else if (evlist->core.nr_entries >1 ) {struct evsel *first =perf_evlist__first (evlist);evlist__for_each_entry (evlist, evsel) {
tools/perf/util/sort.c +1 -1
@@ -2323,7 +2323,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name)if (event_name[0 ] =='%' ) {int nr =strtol (event_name+1 ,NULL ,0 ); -if (nr > evlist->nr_entries) +if (nr > evlist->core.nr_entries)return NULL ; evsel =perf_evlist__first (evlist);
tools/perf/util/top.c +1 -1
@@ -70,7 +70,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) esamples_percent); } -if (top->evlist->nr_entries ==1 ) { +if (top->evlist->core.nr_entries ==1 ) {struct evsel *first =perf_evlist__first (top->evlist); ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ", (uint64_t)first->attr.sample_period,
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 69/107 libperf: Move perf_event_attr field from perf's evsel to libperf's perf_evsel
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the perf_event_attr struct fron 'struct evsel' to 'struct perf_evsel'.
Committer notes:
Fixed up these:
tools/perf/arch/arm/util/auxtrace.c
tools/perf/arch/arm/util/cs-etm.c
tools/perf/arch/arm64/util/arm-spe.c
tools/perf/arch/s390/util/auxtrace.c
tools/perf/util/cs-etm.c
Also
cc1: warnings being treated as errors
tests/sample-parsing.c: In function 'do_test':
tests/sample-parsing.c:162: error: missing initializer tests/sample-parsing.c:162: error: (near initialization for 'evsel.core.cpus')
struct evsel evsel = {
.needs_swap = false,
- .core.attr = {
- .sample_type = sample_type,
- .read_format = read_format,
+ .core = {
+ . attr = {
+ .sample_type = sample_type,
+ .read_format = read_format,
+ },
[perfbuilder@a70e4eeb5549 /]$ gcc --version |& head -1 gcc (GCC) 4.4.7
Also we don't need to include perf_event.h in tools/perf/lib/include/perf/evsel.h, forward declaring 'struct perf_event_attr' is enough. And this even fixes the build in some systems where things are used somewhere down the include path from perf_event.h without defining __always_inline.
--- tools/perf/arch/arm/util/auxtrace.c | 4 +- tools/perf/arch/arm/util/cs-etm.c | 28 +- tools/perf/arch/arm64/util/arm-spe.c | 12 +- tools/perf/arch/s390/util/auxtrace.c | 2 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 6 +- tools/perf/arch/x86/util/auxtrace.c | 4 +- tools/perf/arch/x86/util/intel-bts.c | 16 +- tools/perf/arch/x86/util/intel-pt.c | 40 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-inject.c | 14 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-script.c | 52 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 32 +- tools/perf/lib/evsel.c | 3 +- tools/perf/lib/include/internal/evsel.h | 4 + tools/perf/lib/include/perf/evsel.h | 4 +- tools/perf/tests/code-reading.c | 6 +- tools/perf/tests/event-times.c | 8 +- tools/perf/tests/keep-tracking.c | 6 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/parse-events.c | 872 +++++++++--------- tools/perf/tests/sample-parsing.c | 12 +- tools/perf/tests/switch-tracking.c | 8 +- tools/perf/tests/task-exit.c | 14 +- tools/perf/ui/browsers/res_sample.c | 2 +- tools/perf/ui/browsers/scripts.c | 2 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf-loader.c | 2 +- tools/perf/util/cs-etm.c | 20 +- tools/perf/util/data-convert-bt.c | 14 +- tools/perf/util/db-export.c | 4 +- tools/perf/util/evlist.c | 50 +- tools/perf/util/evsel.c | 167 ++-- tools/perf/util/evsel.h | 17 +- tools/perf/util/evsel_fprintf.c | 8 +- tools/perf/util/header.c | 28 +- tools/perf/util/hist.c | 2 +- tools/perf/util/intel-bts.c | 18 +- tools/perf/util/intel-pt.c | 50 +- tools/perf/util/jitdump.c | 4 +- tools/perf/util/machine.c | 4 +- tools/perf/util/parse-events.c | 40 +- tools/perf/util/python.c | 6 +- tools/perf/util/record.c | 16 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/s390-sample-raw.c | 2 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 14 +- tools/perf/util/session.c | 20 +- tools/perf/util/sort.c | 12 +- tools/perf/util/stat-display.c | 8 +- tools/perf/util/stat-shadow.c | 30 +- tools/perf/util/stat.c | 2 +- tools/perf/util/top.c | 2 +- tools/perf/util/trace-event-info.c | 6 +- 59 files changed, 864 insertions(+), 857 deletions(-)
tools/perf/arch/arm/util/auxtrace.c +2 -2
@@ -70,14 +70,14 @@ struct auxtrace_recordevlist__for_each_entry (evlist, evsel) {if (cs_etm_pmu && - evsel->attr.type == cs_etm_pmu->type) + evsel->core.attr.type == cs_etm_pmu->type) found_etm = true;if (!nr_spes)continue ;for (i =0 ; i < nr_spes; i++) { -if (evsel->attr.type == arm_spe_pmus[i]->type) { +if (evsel->core.attr.type == arm_spe_pmus[i]->type) { found_spe = true;break ; }
tools/perf/arch/arm/util/cs-etm.c +14 -14
@@ -95,7 +95,7 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, }/* All good, let the kernel know */ - evsel->attr.config |= (1 <<ETM_OPT_CTXTID ); + evsel->core.attr.config |= (1 <<ETM_OPT_CTXTID ); err =0 ; out:
@@ -144,7 +144,7 @@ static int cs_etm_set_timestamp(struct auxtrace_record *itr, }/* All good, let the kernel know */ - evsel->attr.config |= (1 <<ETM_OPT_TS ); + evsel->core.attr.config |= (1 <<ETM_OPT_TS ); err =0 ; out:
@@ -215,7 +215,7 @@ static int cs_etm_set_sink_attr(struct perf_pmu *pmu,int ret = -EINVAL ;u32 hash; -if (evsel->attr.config2 &GENMASK (31 ,0 )) +if (evsel->core.attr.config2 &GENMASK (31 ,0 ))return 0 ;list_for_each_entry (term, &evsel->config_terms, list) {
@@ -233,7 +233,7 @@ static int cs_etm_set_sink_attr(struct perf_pmu *pmu,return ret; } - evsel->attr.config2 |= hash; + evsel->core.attr.config2 |= hash;return 0 ; }
@@ -264,14 +264,14 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, opts->record_switch_events = true;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == cs_etm_pmu->type) { +if (evsel->core.attr.type == cs_etm_pmu->type) {if (cs_etm_evsel) {pr_err ("There may be only one %s event\n" ,CORESIGHT_ETM_PMU_NAME );return -EINVAL ; } - evsel->attr.freq =0 ; - evsel->attr.sample_period =1 ; + evsel->core.attr.freq =0 ; + evsel->core.attr.sample_period =1 ; cs_etm_evsel = evsel; opts->full_auxtrace = true; }
@@ -416,8 +416,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, tracking_evsel =perf_evlist__last (evlist);perf_evlist__set_tracking_event (evlist, tracking_evsel); - tracking_evsel->attr.freq =0 ; - tracking_evsel->attr.sample_period =1 ; + tracking_evsel->core.attr.freq =0 ; + tracking_evsel->core.attr.sample_period =1 ;/* In per-cpu case, always need the time of mmap events etc */ if (!cpu_map__empty (cpus))
@@ -438,7 +438,7 @@ static u64 cs_etm_get_config(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == cs_etm_pmu->type) { +if (evsel->core.attr.type == cs_etm_pmu->type) {/* * Variable perf_event_attr::config is assigned to * ETMv3/PTM. The bit fields have been made to match
@@ -447,7 +447,7 @@ static u64 cs_etm_get_config(struct auxtrace_record *itr)* drivers/hwtracing/coresight/coresight-perf.c for * details. */ - config = evsel->attr.config; + config = evsel->core.attr.config;break ; } }
@@ -820,7 +820,7 @@ static int cs_etm_snapshot_start(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->cs_etm_pmu->type) +if (evsel->core.attr.type == ptr->cs_etm_pmu->type)return evsel__disable (evsel); }return -EINVAL ;
@@ -833,7 +833,7 @@ static int cs_etm_snapshot_finish(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->cs_etm_pmu->type) +if (evsel->core.attr.type == ptr->cs_etm_pmu->type)return evsel__enable (evsel); }return -EINVAL ;
@@ -861,7 +861,7 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->cs_etm_pmu->type) +if (evsel->core.attr.type == ptr->cs_etm_pmu->type)return perf_evlist__enable_event_idx (ptr->evlist, evsel, idx); }
tools/perf/arch/arm64/util/arm-spe.c +6 -6
@@ -73,13 +73,13 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, sper->evlist = evlist;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == arm_spe_pmu->type) { +if (evsel->core.attr.type == arm_spe_pmu->type) {if (arm_spe_evsel) {pr_err ("There may be only one " ARM_SPE_PMU_NAME "x event\n" );return -EINVAL ; } - evsel->attr.freq =0 ; - evsel->attr.sample_period =1 ; + evsel->core.attr.freq =0 ; + evsel->core.attr.sample_period =1 ; arm_spe_evsel = evsel; opts->full_auxtrace = true; }
@@ -130,8 +130,8 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, tracking_evsel =perf_evlist__last (evlist);perf_evlist__set_tracking_event (evlist, tracking_evsel); - tracking_evsel->attr.freq =0 ; - tracking_evsel->attr.sample_period =1 ; + tracking_evsel->core.attr.freq =0 ; + tracking_evsel->core.attr.sample_period =1 ;perf_evsel__set_sample_bit (tracking_evsel,TIME );perf_evsel__set_sample_bit (tracking_evsel,CPU );perf_evsel__reset_sample_bit (tracking_evsel,BRANCH_STACK );
@@ -163,7 +163,7 @@ static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)struct evsel *evsel;evlist__for_each_entry (sper->evlist, evsel) { -if (evsel->attr.type == sper->arm_spe_pmu->type) +if (evsel->core.attr.type == sper->arm_spe_pmu->type)return perf_evlist__enable_event_idx (sper->evlist, evsel, idx); }
tools/perf/arch/s390/util/auxtrace.c +1 -1
@@ -94,7 +94,7 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,return NULL ;evlist__for_each_entry (evlist, pos) { -if (pos->attr.config ==PERF_EVENT_CPUM_SF_DIAG ) { +if (pos->core.attr.config ==PERF_EVENT_CPUM_SF_DIAG ) { diagnose =1 ;break ; }
tools/perf/arch/x86/tests/perf-time-to-tsc.c +3 -3
@@ -79,9 +79,9 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe evsel =perf_evlist__first (evlist); - evsel->attr.comm =1 ; - evsel->attr.disabled =1 ; - evsel->attr.enable_on_exec =0 ; + evsel->core.attr.comm =1 ; + evsel->core.attr.disabled =1 ; + evsel->core.attr.enable_on_exec =0 ;CHECK__ (evlist__open (evlist));
tools/perf/arch/x86/util/auxtrace.c +2 -2
@@ -29,9 +29,9 @@ struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist, intel_bts_pmu =perf_pmu__find (INTEL_BTS_PMU_NAME );evlist__for_each_entry (evlist, evsel) { -if (intel_pt_pmu && evsel->attr.type == intel_pt_pmu->type) +if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type) found_pt = true; -if (intel_bts_pmu && evsel->attr.type == intel_bts_pmu->type) +if (intel_bts_pmu && evsel->core.attr.type == intel_bts_pmu->type) found_bts = true; }
tools/perf/arch/x86/util/intel-bts.c +8 -8
@@ -113,13 +113,13 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, btsr->snapshot_mode = opts->auxtrace_snapshot_mode;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == intel_bts_pmu->type) { +if (evsel->core.attr.type == intel_bts_pmu->type) {if (intel_bts_evsel) {pr_err ("There may be only one " INTEL_BTS_PMU_NAME " event\n" );return -EINVAL ; } - evsel->attr.freq =0 ; - evsel->attr.sample_period =1 ; + evsel->core.attr.freq =0 ; + evsel->core.attr.sample_period =1 ; intel_bts_evsel = evsel; opts->full_auxtrace = true; }
@@ -231,8 +231,8 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,perf_evlist__set_tracking_event (evlist, tracking_evsel); - tracking_evsel->attr.freq =0 ; - tracking_evsel->attr.sample_period =1 ; + tracking_evsel->core.attr.freq =0 ; + tracking_evsel->core.attr.sample_period =1 ; }return 0 ;
@@ -316,7 +316,7 @@ static int intel_bts_snapshot_start(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (btsr->evlist, evsel) { -if (evsel->attr.type == btsr->intel_bts_pmu->type) +if (evsel->core.attr.type == btsr->intel_bts_pmu->type)return evsel__disable (evsel); }return -EINVAL ;
@@ -329,7 +329,7 @@ static int intel_bts_snapshot_finish(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (btsr->evlist, evsel) { -if (evsel->attr.type == btsr->intel_bts_pmu->type) +if (evsel->core.attr.type == btsr->intel_bts_pmu->type)return evsel__enable (evsel); }return -EINVAL ;
@@ -411,7 +411,7 @@ static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)struct evsel *evsel;evlist__for_each_entry (btsr->evlist, evsel) { -if (evsel->attr.type == btsr->intel_bts_pmu->type) +if (evsel->core.attr.type == btsr->intel_bts_pmu->type)return perf_evlist__enable_event_idx (btsr->evlist, evsel, idx); }
tools/perf/arch/x86/util/intel-pt.c +20 -20
@@ -122,8 +122,8 @@ static int intel_pt_read_config(struct perf_pmu *intel_pt_pmu, const char *str,return -EINVAL ;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == intel_pt_pmu->type) { - *res =intel_pt_masked_bits (mask, evsel->attr.config); +if (evsel->core.attr.type == intel_pt_pmu->type) { + *res =intel_pt_masked_bits (mask, evsel->core.attr.config);return 0 ; } }
@@ -274,7 +274,7 @@ static const char *intel_pt_find_filter(struct evlist *evlist,struct evsel *evsel;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == intel_pt_pmu->type) +if (evsel->core.attr.type == intel_pt_pmu->type)return evsel->filter; }
@@ -526,26 +526,26 @@ static int intel_pt_validate_config(struct perf_pmu *intel_pt_pmu,* sets pt=0, which avoids senseless kernel errors. */ if (perf_pmu__scan_file (intel_pt_pmu,"format/pt" ,"%c" , &c) ==1 && - !(evsel->attr.config &1 )) { + !(evsel->core.attr.config &1 )) {pr_warning ("pt=0 doesn't make sense, forcing pt=1\n" ); - evsel->attr.config |=1 ; + evsel->core.attr.config |=1 ; } err =intel_pt_val_config_term (intel_pt_pmu,"caps/cycle_thresholds" ,"cyc_thresh" ,"caps/psb_cyc" , - evsel->attr.config); + evsel->core.attr.config);if (err)return err; err =intel_pt_val_config_term (intel_pt_pmu,"caps/mtc_periods" ,"mtc_period" ,"caps/mtc" , - evsel->attr.config); + evsel->core.attr.config);if (err)return err;return intel_pt_val_config_term (intel_pt_pmu,"caps/psb_periods" ,"psb_period" ,"caps/psb_cyc" , - evsel->attr.config); + evsel->core.attr.config); } static int intel_pt_recording_options(struct auxtrace_record *itr,
@@ -566,13 +566,13 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, ptr->snapshot_mode = opts->auxtrace_snapshot_mode;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == intel_pt_pmu->type) { +if (evsel->core.attr.type == intel_pt_pmu->type) {if (intel_pt_evsel) {pr_err ("There may be only one " INTEL_PT_PMU_NAME " event\n" );return -EINVAL ; } - evsel->attr.freq =0 ; - evsel->attr.sample_period =1 ; + evsel->core.attr.freq =0 ; + evsel->core.attr.sample_period =1 ; intel_pt_evsel = evsel; opts->full_auxtrace = true; }
@@ -670,7 +670,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,intel_pt_parse_terms (&intel_pt_pmu->format,"tsc" , &tsc_bit); -if (opts->full_auxtrace && (intel_pt_evsel->attr.config & tsc_bit)) +if (opts->full_auxtrace && (intel_pt_evsel->core.attr.config & tsc_bit)) have_timing_info = true;else have_timing_info = false;
@@ -693,9 +693,9 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, switch_evsel =perf_evlist__last (evlist); - switch_evsel->attr.freq =0 ; - switch_evsel->attr.sample_period =1 ; - switch_evsel->attr.context_switch =1 ; + switch_evsel->core.attr.freq =0 ; + switch_evsel->core.attr.sample_period =1 ; + switch_evsel->core.attr.context_switch =1 ; switch_evsel->system_wide = true; switch_evsel->no_aux_samples = true;
@@ -753,8 +753,8 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,perf_evlist__set_tracking_event (evlist, tracking_evsel); - tracking_evsel->attr.freq =0 ; - tracking_evsel->attr.sample_period =1 ; + tracking_evsel->core.attr.freq =0 ; + tracking_evsel->core.attr.sample_period =1 ; tracking_evsel->no_aux_samples = true;if (need_immediate)
@@ -787,7 +787,7 @@ static int intel_pt_snapshot_start(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->intel_pt_pmu->type) +if (evsel->core.attr.type == ptr->intel_pt_pmu->type)return evsel__disable (evsel); }return -EINVAL ;
@@ -800,7 +800,7 @@ static int intel_pt_snapshot_finish(struct auxtrace_record *itr)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->intel_pt_pmu->type) +if (evsel->core.attr.type == ptr->intel_pt_pmu->type)return evsel__enable (evsel); }return -EINVAL ;
@@ -1073,7 +1073,7 @@ static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)struct evsel *evsel;evlist__for_each_entry (ptr->evlist, evsel) { -if (evsel->attr.type == ptr->intel_pt_pmu->type) +if (evsel->core.attr.type == ptr->intel_pt_pmu->type)return perf_evlist__enable_event_idx (ptr->evlist, evsel, idx); }
tools/perf/builtin-evlist.c +1 -1
@@ -36,7 +36,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *detailsevlist__for_each_entry (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); -if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) +if (pos->core.attr.type ==PERF_TYPE_TRACEPOINT ) has_tracepoint = true; }
tools/perf/builtin-inject.c +7 -7
@@ -530,8 +530,8 @@ static int perf_inject__sched_stat(struct perf_tool *tool, sample_sw.period = sample->period; sample_sw.time = sample->time; -perf_event__synthesize_sample (event_sw, evsel->attr.sample_type, - evsel->attr.read_format, &sample_sw); +perf_event__synthesize_sample (event_sw, evsel->core.attr.sample_type, + evsel->core.attr.read_format, &sample_sw);build_id__mark_dso_hit (tool, event_sw, &sample_sw, evsel, machine);return perf_event__repipe (tool, event_sw, &sample_sw, machine); }
@@ -544,7 +544,7 @@ static void sig_handler(int sig __maybe_unused)static int perf_evsel__check_stype (struct evsel *evsel,u64 sample_type,const char *sample_msg) { -struct perf_event_attr *attr = &evsel->attr; +struct perf_event_attr *attr = &evsel->core.attr;const char *name =perf_evsel__name (evsel);if (!(attr->sample_type & sample_type)) {
@@ -578,8 +578,8 @@ static void strip_init(struct perf_inject *inject)static bool has_tracking (struct evsel *evsel) { -return evsel->attr.mmap || evsel->attr.mmap2 || evsel->attr.comm || - evsel->attr.task; +return evsel->core.attr.mmap || evsel->core.attr.mmap2 || evsel->core.attr.comm || + evsel->core.attr.task; }#define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
@@ -603,8 +603,8 @@ static bool ok_to_remove(struct evlist *evlist,evlist__for_each_entry (evlist, evsel) {if (evsel->handler != drop_sample) { cnt +=1 ; -if ((evsel->attr.sample_type &COMPAT_MASK ) == - (evsel_to_remove->attr.sample_type &COMPAT_MASK )) +if ((evsel->core.attr.sample_type &COMPAT_MASK ) == + (evsel_to_remove->core.attr.sample_type &COMPAT_MASK )) ok = true; } }
tools/perf/builtin-kvm.c +1 -1
@@ -1022,7 +1022,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)* This command processes KVM tracepoints from host only */ evlist__for_each_entry (evlist, pos) { -struct perf_event_attr *attr = &pos->attr; +struct perf_event_attr *attr = &pos->core.attr;/* make sure these *are* set */ perf_evsel__set_sample_bit (pos,TID );
tools/perf/builtin-record.c +1 -1
@@ -732,7 +732,7 @@ static int record__open(struct record *rec) pos->tracking =0 ; pos =perf_evlist__last (evlist); pos->tracking =1 ; - pos->attr.enable_on_exec =1 ; + pos->core.attr.enable_on_exec =1 ; }perf_evlist__config (evlist, opts, &callchain_param);
tools/perf/builtin-script.c +26 -26
191 lines not on this page · raw message
tools/perf/builtin-stat.c +1 -1
@@ -391,7 +391,7 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *infstatic bool perf_evsel__should_store_id (struct evsel *counter) { -return STAT_RECORD || counter->attr.read_format &PERF_FORMAT_ID ; +return STAT_RECORD || counter->core.attr.read_format &PERF_FORMAT_ID ; } static bool is_target_alive(struct target *_target,
tools/perf/builtin-timechart.c +1 -1
@@ -557,7 +557,7 @@ static int process_sample_event(struct perf_tool *tool, { struct timechart *tchart = container_of(tool, struct timechart, tool); -if (evsel->attr.sample_type &PERF_SAMPLE_TIME ) { +if (evsel->core.attr.sample_type &PERF_SAMPLE_TIME ) {if (!tchart->first_time || tchart->first_time > sample->time) tchart->first_time = sample->time;if (tchart->last_time < sample->time)
tools/perf/builtin-top.c +1 -1
@@ -966,7 +966,7 @@ static int perf_top_overwrite_fallback(struct perf_top *top,return 0 ;evlist__for_each_entry (evlist, counter) - counter->attr.write_backward = false; + counter->core.attr.write_backward = false; opts->overwrite = false;pr_debug2 ("fall back to non-overwrite mode\n" );return 1 ;
tools/perf/builtin-trace.c +16 -16
@@ -2046,8 +2046,8 @@ static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, struct callchain_cursor *cursor) {struct addr_location al; -int max_stack = evsel->attr.sample_max_stack ? - evsel->attr.sample_max_stack : +int max_stack = evsel->core.attr.sample_max_stack ? + evsel->core.attr.sample_max_stack : trace->max_stack;int err;
@@ -2462,7 +2462,7 @@ static int trace__pgfault(struct trace *trace,if (ttrace ==NULL ) goto out_put; -if (evsel->attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ ) +if (evsel->core.attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ ) ttrace->pfmaj++;else ttrace->pfmin++;
@@ -2475,7 +2475,7 @@ static int trace__pgfault(struct trace *trace,trace__fprintf_entry_head (trace, thread,0 , true, sample->time, trace->output);fprintf (trace->output,"%sfault [" , - evsel->attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ ? + evsel->core.attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ ?"maj" :"min" );print_location (trace->output, sample, &al, false, true);
@@ -2523,7 +2523,7 @@ static void trace__set_base_time(struct trace *trace,* appears in our event stream (vfs_getname comes to mind). */ if (trace->base_time ==0 && !trace->full_time && - (evsel->attr.sample_type &PERF_SAMPLE_TIME )) + (evsel->core.attr.sample_type &PERF_SAMPLE_TIME )) trace->base_time = sample->time; }
@@ -2682,7 +2682,7 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, sttrace__set_base_time (trace, evsel, sample); -if (evsel->attr.type ==PERF_TYPE_TRACEPOINT && +if (evsel->core.attr.type ==PERF_TYPE_TRACEPOINT && sample->raw_data ==NULL ) { fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", perf_evsel__name(evsel), sample->tid,
@@ -2728,7 +2728,7 @@ static int trace__add_syscall_newtp(struct trace *trace)* leading to the syscall, allow overriding that for * debugging reasons using --kernel_syscall_callchains */ - sys_exit->attr.exclude_callchain_kernel =1 ; + sys_exit->core.attr.exclude_callchain_kernel =1 ; } trace->syscalls.events.sys_enter = sys_enter;
@@ -3414,18 +3414,18 @@ static int trace__run(struct trace *trace, int argc, const char **argv) trace->multiple_threads =thread_map__pid (evlist->threads,0 ) ==-1 || evlist->threads->nr >1 || -perf_evlist__first (evlist)->attr.inherit; +perf_evlist__first (evlist)->core.attr.inherit;/* -* Now that we already used evsel->attr to ask the kernel to setup the -* events, lets reuse evsel->attr.sample_max_stack as the limit in +* Now that we already used evsel->core.attr to ask the kernel to setup the +* events, lets reuse evsel->core.attr.sample_max_stack as the limit in * trace__resolve_callchain(), allowing per-event max-stack settings * to override an explicitly set --max-stack global setting. */ evlist__for_each_entry (evlist, evsel) {if (evsel__has_callchain (evsel) && - evsel->attr.sample_max_stack ==0 ) - evsel->attr.sample_max_stack = trace->max_stack; + evsel->core.attr.sample_max_stack ==0 ) + evsel->core.attr.sample_max_stack = trace->max_stack; } again: before = trace->nr_events;
@@ -3618,10 +3618,10 @@ static int trace__replay(struct trace *trace) }evlist__for_each_entry (session->evlist, evsel) { -if (evsel->attr.type ==PERF_TYPE_SOFTWARE && - (evsel->attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ || - evsel->attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MIN || - evsel->attr.config ==PERF_COUNT_SW_PAGE_FAULTS )) +if (evsel->core.attr.type ==PERF_TYPE_SOFTWARE && + (evsel->core.attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ || + evsel->core.attr.config ==PERF_COUNT_SW_PAGE_FAULTS_MIN || + evsel->core.attr.config ==PERF_COUNT_SW_PAGE_FAULTS )) evsel->handler = trace__pgfault; }
tools/perf/lib/evsel.c +2 -1
@@ -3,7 +3,8 @@#include <linux/list.h> #include <internal/evsel.h> -void perf_evsel__init (struct perf_evsel *evsel) +void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr) {INIT_LIST_HEAD (&evsel->node); + evsel->attr = *attr; }
tools/perf/lib/include/internal/evsel.h +4 -0
@@ -2,8 +2,12 @@#ifndef __LIBPERF_INTERNAL_EVSEL_H#define __LIBPERF_INTERNAL_EVSEL_H +#include <linux/types.h> +#include <linux/perf_event.h> +struct perf_evsel {struct list_head node; +struct perf_event_attr attr; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/lib/include/perf/evsel.h +3 -1
@@ -5,7 +5,9 @@#include <perf/core.h> struct perf_evsel ; +struct perf_event_attr ; -LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel); +LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel, +struct perf_event_attr *attr);#endif /* __LIBPERF_EVSEL_H */
tools/perf/tests/code-reading.c +3 -3
@@ -642,9 +642,9 @@ static int do_test_code_reading(bool try_kcore) evsel =perf_evlist__first (evlist); - evsel->attr.comm =1 ; - evsel->attr.disabled =1 ; - evsel->attr.enable_on_exec =0 ; + evsel->core.attr.comm =1 ; + evsel->core.attr.disabled =1 ; + evsel->core.attr.enable_on_exec =0 ; ret =evlist__open (evlist);if (ret <0 ) {
tools/perf/tests/event-times.c +4 -4
@@ -36,7 +36,7 @@ static int attach__enable_on_exec(struct evlist *evlist)return err; } - evsel->attr.enable_on_exec =1 ; + evsel->core.attr.enable_on_exec =1 ; err =evlist__open (evlist);if (err <0 ) {
@@ -68,7 +68,7 @@ static int attach__current_disabled(struct evlist *evlist)return -1 ; } - evsel->attr.disabled =1 ; + evsel->core.attr.disabled =1 ; err =perf_evsel__open_per_thread (evsel, threads);if (err) {
@@ -121,7 +121,7 @@ static int attach__cpu_disabled(struct evlist *evlist)return -1 ; } - evsel->attr.disabled =1 ; + evsel->core.attr.disabled =1 ; err =perf_evsel__open_per_cpu (evsel, cpus);if (err) {
@@ -179,7 +179,7 @@ static int test_times(int (attach)(struct evlist *), } evsel =perf_evlist__last (evlist); - evsel->attr.read_format |= + evsel->core.attr.read_format |=PERF_FORMAT_TOTAL_TIME_ENABLED |PERF_FORMAT_TOTAL_TIME_RUNNING ;
tools/perf/tests/keep-tracking.c +3 -3
@@ -90,9 +90,9 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un evsel =perf_evlist__first (evlist); - evsel->attr.comm =1 ; - evsel->attr.disabled =1 ; - evsel->attr.enable_on_exec =0 ; + evsel->core.attr.comm =1 ; + evsel->core.attr.disabled =1 ; + evsel->core.attr.enable_on_exec =0 ;if (evlist__open (evlist) <0 ) {pr_debug ("Unable to open dummy and cycles event\n" );
tools/perf/tests/mmap-basic.c +1 -1
@@ -79,7 +79,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse goto out_delete_evlist; } - evsels[i]->attr.wakeup_events =1 ; + evsels[i]->core.attr.wakeup_events =1 ;perf_evsel__set_sample_id (evsels[i], false);evlist__add (evlist, evsels[i]);
tools/perf/tests/parse-events.c +436 -436
1,420 lines not on this page · raw message
tools/perf/tests/sample-parsing.c +7 -5
@@ -155,9 +155,11 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) {struct evsel evsel = { .needs_swap = false, - .attr = { - .sample_type = sample_type, - .read_format = read_format, + .core = { + . attr = { + .sample_type = sample_type, + .read_format = read_format, + }, }, };union perf_event *event;
@@ -221,10 +223,10 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)int err, ret =-1 ;if (sample_type &PERF_SAMPLE_REGS_USER ) - evsel.attr.sample_regs_user = sample_regs; + evsel.core.attr.sample_regs_user = sample_regs;if (sample_type &PERF_SAMPLE_REGS_INTR ) - evsel.attr.sample_regs_intr = sample_regs; + evsel.core.attr.sample_regs_intr = sample_regs;for (i =0 ; i <sizeof (regs); i++) *(i + (u8 *)regs) = i &0xfe ;
tools/perf/tests/switch-tracking.c +4 -4
@@ -420,8 +420,8 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_perf_evlist__set_tracking_event (evlist, tracking_evsel); - tracking_evsel->attr.freq =0 ; - tracking_evsel->attr.sample_period =1 ; + tracking_evsel->core.attr.freq =0 ; + tracking_evsel->core.attr.sample_period =1 ;perf_evsel__set_sample_bit (tracking_evsel,TIME );
@@ -435,7 +435,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ }/* Check tracking event is tracking */ -if (!tracking_evsel->attr.mmap || !tracking_evsel->attr.comm) { +if (!tracking_evsel->core.attr.mmap || !tracking_evsel->core.attr.comm) {pr_debug ("Tracking event not tracking\n" ); goto out_err; }
@@ -443,7 +443,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_/* Check non-tracking events are not tracking */ evlist__for_each_entry (evlist, evsel) {if (evsel != tracking_evsel) { -if (evsel->attr.mmap || evsel->attr.comm) { +if (evsel->core.attr.mmap || evsel->core.attr.comm) {pr_debug ("Non-tracking event is tracking\n" ); goto out_err; }
tools/perf/tests/task-exit.c +7 -7
@@ -84,16 +84,16 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused } evsel =perf_evlist__first (evlist); - evsel->attr.task =1 ; + evsel->core.attr.task =1 ;#ifdef __s390x__ - evsel->attr.sample_freq =1000000 ; + evsel->core.attr.sample_freq =1000000 ;#else - evsel->attr.sample_freq =1 ; + evsel->core.attr.sample_freq =1 ;#endif - evsel->attr.inherit =0 ; - evsel->attr.watermark =0 ; - evsel->attr.wakeup_events =1 ; - evsel->attr.exclude_kernel =1 ; + evsel->core.attr.inherit =0 ; + evsel->core.attr.watermark =0 ; + evsel->core.attr.wakeup_events =1 ; + evsel->core.attr.exclude_kernel =1 ; err =evlist__open (evlist);if (err <0 ) {
tools/perf/ui/browsers/res_sample.c +1 -1
@@ -66,7 +66,7 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,timestamp__scnprintf_nsec (r->time, tsample,sizeof tsample); -attr_to_script (extra_format, &evsel->attr); +attr_to_script (extra_format, &evsel->core.attr); if (asprintf(&cmd, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s %s | less +/%s", perf,
tools/perf/ui/browsers/scripts.c +1 -1
@@ -100,7 +100,7 @@ static int list_scripts(char *script_name, bool *custom,return -1 ;if (evsel) -attr_to_script (scriptc.extra_format, &evsel->attr); +attr_to_script (scriptc.extra_format, &evsel->core.attr);add_script_option ("Show individual samples" ,"" , &scriptc);add_script_option ("Show individual samples with assembler" ,"-F +insn --xed" , &scriptc);
tools/perf/util/auxtrace.c +1 -1
@@ -2140,7 +2140,7 @@ static struct perf_pmu *perf_evsel__find_pmu(struct evsel *evsel)struct perf_pmu *pmu =NULL ;while ((pmu =perf_pmu__scan (pmu)) !=NULL ) { -if (pmu->type == evsel->attr.type) +if (pmu->type == evsel->core.attr.type)break ; }
tools/perf/util/bpf-loader.c +1 -1
@@ -1421,7 +1421,7 @@ apply_config_evsel_for_key(const char *name, int map_fd, void *pkey,return -BPF_LOADER_ERRNO__OBJCONF_MAP_EVTDIM ; } - attr = &evsel->attr; + attr = &evsel->core.attr;if (attr->inherit) {pr_debug ("ERROR: Can't put inherit event into map %s\n" , name);return -BPF_LOADER_ERRNO__OBJCONF_MAP_EVTINH ;
tools/perf/util/cs-etm.c +10 -10
@@ -1230,7 +1230,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,int err;evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == etm->pmu_type) { +if (evsel->core.attr.type == etm->pmu_type) { found = true;break ; }
@@ -1244,7 +1244,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,memset (&attr,0 ,sizeof (struct perf_event_attr )); attr.size =sizeof (struct perf_event_attr ); attr.type =PERF_TYPE_HARDWARE ; - attr.sample_type = evsel->attr.sample_type &PERF_SAMPLE_MASK ; + attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_PERIOD ;if (etm->timeless_decoding)
@@ -1252,13 +1252,13 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,else attr.sample_type |=PERF_SAMPLE_TIME ; - attr.exclude_user = evsel->attr.exclude_user; - attr.exclude_kernel = evsel->attr.exclude_kernel; - attr.exclude_hv = evsel->attr.exclude_hv; - attr.exclude_host = evsel->attr.exclude_host; - attr.exclude_guest = evsel->attr.exclude_guest; - attr.sample_id_all = evsel->attr.sample_id_all; - attr.read_format = evsel->attr.read_format; + attr.exclude_user = evsel->core.attr.exclude_user; + attr.exclude_kernel = evsel->core.attr.exclude_kernel; + attr.exclude_hv = evsel->core.attr.exclude_hv; + attr.exclude_host = evsel->core.attr.exclude_host; + attr.exclude_guest = evsel->core.attr.exclude_guest; + attr.sample_id_all = evsel->core.attr.sample_id_all; + attr.read_format = evsel->core.attr.read_format;/* create new id val to be a fixed offset from evsel id */ id = evsel->id[0 ] +1000000000 ;
@@ -2303,7 +2303,7 @@ static bool cs_etm__is_timeless_decoding(struct cs_etm_auxtrace *etm)* with the time bit set. */ evlist__for_each_entry (evlist, evsel) { -if ((evsel->attr.sample_type &PERF_SAMPLE_TIME )) +if ((evsel->core.attr.sample_type &PERF_SAMPLE_TIME )) timeless_decoding = false; }
tools/perf/util/data-convert-bt.c +7 -7
@@ -587,7 +587,7 @@ static int add_generic_values(struct ctf_writer *cw,struct evsel *evsel, struct perf_sample *sample) { - u64 type = evsel->attr.sample_type; + u64 type = evsel->core.attr.sample_type;int ret;/*
@@ -757,7 +757,7 @@ static int get_sample_cpu(struct ctf_writer *cw, struct perf_sample *sample, {int cpu =0 ; -if (evsel->attr.sample_type &PERF_SAMPLE_CPU ) +if (evsel->core.attr.sample_type &PERF_SAMPLE_CPU ) cpu = sample->cpu;if (cpu > cw->stream_cnt) {
@@ -795,7 +795,7 @@ static int process_sample_event(struct perf_tool *tool,struct bt_ctf_event_class *event_class;struct bt_ctf_event *event;int ret; -unsigned long type = evsel->attr.sample_type; +unsigned long type = evsel->core.attr.sample_type;if (WARN_ONCE (!priv,"Failed to setup all events.\n" ))return 0 ;
@@ -820,7 +820,7 @@ static int process_sample_event(struct perf_tool *tool,if (ret)return -1 ; -if (evsel->attr.type ==PERF_TYPE_TRACEPOINT ) { +if (evsel->core.attr.type ==PERF_TYPE_TRACEPOINT ) { ret =add_tracepoint_values (cw, event_class, event, evsel, sample);if (ret)
@@ -1087,7 +1087,7 @@ static int add_bpf_output_types(struct ctf_writer *cw,static int add_generic_types (struct ctf_writer *cw,struct evsel *evsel,struct bt_ctf_event_class *event_class) { -u64 type = evsel->attr.sample_type; +u64 type = evsel->core.attr.sample_type;/* * missing:
@@ -1157,7 +1157,7 @@ static int add_event(struct ctf_writer *cw, struct evsel *evsel)const char *name =perf_evsel__name (evsel);int ret; -pr ("Adding event '%s' (type %d)\n" , name, evsel->attr.type); +pr ("Adding event '%s' (type %d)\n" , name, evsel->core.attr.type); event_class =bt_ctf_event_class_create (name);if (!event_class)
@@ -1167,7 +1167,7 @@ static int add_event(struct ctf_writer *cw, struct evsel *evsel)if (ret) goto err; -if (evsel->attr.type ==PERF_TYPE_TRACEPOINT ) { +if (evsel->core.attr.type ==PERF_TYPE_TRACEPOINT ) { ret =add_tracepoint_types (cw, evsel, event_class);if (ret) goto err;
tools/perf/util/db-export.c +2 -2
@@ -388,8 +388,8 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, } } -if ((evsel->attr.sample_type &PERF_SAMPLE_ADDR ) && -sample_addr_correlates_sym (&evsel->attr)) { +if ((evsel->core.attr.sample_type &PERF_SAMPLE_ADDR ) && +sample_addr_correlates_sym (&evsel->core.attr)) {struct addr_location addr_al;thread__resolve (thread, &addr_al, sample);
tools/perf/util/evlist.c +25 -25
172 lines not on this page · raw message
tools/perf/util/evsel.c +83 -84
383 lines not on this page · raw message
tools/perf/util/intel-pt.c +25 -25
50 lines not on this page · raw message
tools/perf/util/scripting-engines/trace-event-perl.c +3 -3
Lines of this file are not shown. View the raw message.
tools/perf/util/scripting-engines/trace-event-python.c +7 -7
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.21.0
Part of the diff is not shown here. View the raw message.
Arnaldo Carvalho de Melo
maintainerPATCH 70/107 libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Moving the following functions from tools/perf:
cpu_map__new()
cpu_map__read()
to libperf with the following names:
perf_cpu_map__new()
perf_cpu_map__read()
Committer notes:
Fixed up this one:
tools/perf/arch/arm/util/cs-etm.c
--- tools/perf/arch/arm/util/cs-etm.c | 6 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 3 +- tools/perf/bench/epoll-ctl.c | 3 +- tools/perf/bench/epoll-wait.c | 3 +- tools/perf/bench/futex-hash.c | 3 +- tools/perf/bench/futex-lock-pi.c | 3 +- tools/perf/bench/futex-requeue.c | 3 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 3 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/lib/cpumap.c | 184 +++++++++++++++++++ tools/perf/lib/include/internal/cpumap.h | 4 + tools/perf/lib/include/perf/cpumap.h | 3 + tools/perf/lib/libperf.map | 2 + tools/perf/tests/bitmap.c | 3 +- tools/perf/tests/code-reading.c | 5 +- tools/perf/tests/cpumap.c | 7 +- tools/perf/tests/event-times.c | 9 +- tools/perf/tests/event_update.c | 3 +- tools/perf/tests/keep-tracking.c | 3 +- tools/perf/tests/mem2node.c | 3 +- tools/perf/tests/mmap-basic.c | 3 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/switch-tracking.c | 5 +- tools/perf/tests/topology.c | 3 +- tools/perf/util/cpumap.c | 181 +----------------- tools/perf/util/cpumap.h | 2 - tools/perf/util/cputopo.c | 5 +- tools/perf/util/evlist.c | 5 +- tools/perf/util/header.c | 3 +- tools/perf/util/parse-events.c | 3 +- tools/perf/util/pmu.c | 3 +- tools/perf/util/python.c | 3 +- tools/perf/util/record.c | 7 +- tools/perf/util/session.c | 3 +- tools/perf/util/svghelper.c | 3 +- 37 files changed, 265 insertions(+), 227 deletions(-)
tools/perf/arch/arm/util/cs-etm.c +3 -3
@@ -156,7 +156,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr, {int i, err = -EINVAL ;struct perf_cpu_map *event_cpus = evsel->evlist->cpus; -struct perf_cpu_map *online_cpus =cpu_map__new (NULL ); +struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );/* Set option of each CPU we have */ for (i =0 ; i <cpu__max_cpu (); i++) {
@@ -490,7 +490,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,int i;int etmv3 =0 , etmv4 =0 ;struct perf_cpu_map *event_cpus = evlist->cpus; -struct perf_cpu_map *online_cpus =cpu_map__new (NULL ); +struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );/* cpu map is not empty, we have specific CPUs to work with */ if (!cpu_map__empty (event_cpus)) {
@@ -637,7 +637,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,u64 nr_cpu, type;struct perf_cpu_map *cpu_map;struct perf_cpu_map *event_cpus = session->evlist->cpus; -struct perf_cpu_map *online_cpus =cpu_map__new (NULL ); +struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );struct cs_etm_recording *ptr = container_of(itr, struct cs_etm_recording, itr);struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
tools/perf/arch/x86/tests/perf-time-to-tsc.c +2 -1
@@ -5,6 +5,7 @@#include <unistd.h> #include <linux/types.h> #include <sys/prctl.h> +#include <perf/cpumap.h> #include "parse-events.h" #include "evlist.h"
@@ -65,7 +66,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe threads =thread_map__new (-1 ,getpid (),UINT_MAX );CHECK_NOT_NULL__ (threads); - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );CHECK_NOT_NULL__ (cpus); evlist =evlist__new ();
tools/perf/bench/epoll-ctl.c +2 -1
@@ -20,6 +20,7 @@#include <sys/resource.h> #include <sys/epoll.h> #include <sys/eventfd.h> +#include <perf/cpumap.h> #include "../util/stat.h" #include <subcmd/parse-options.h>
@@ -315,7 +316,7 @@ int bench_epoll_ctl(int argc, const char **argv) act.sa_sigaction = toggle_done;sigaction (SIGINT , &act,NULL ); - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu) goto errmem;
tools/perf/bench/epoll-wait.c +2 -1
@@ -75,6 +75,7 @@#include <sys/epoll.h> #include <sys/eventfd.h> #include <sys/types.h> +#include <perf/cpumap.h> #include "../util/stat.h" #include <subcmd/parse-options.h>
@@ -429,7 +430,7 @@ int bench_epoll_wait(int argc, const char **argv) act.sa_sigaction = toggle_done;sigaction (SIGINT , &act,NULL ); - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu) goto errmem;
tools/perf/bench/futex-hash.c +2 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/zalloc.h> #include <sys/time.h> +#include <perf/cpumap.h> #include "../util/stat.h" #include <subcmd/parse-options.h>
@@ -132,7 +133,7 @@ int bench_futex_hash(int argc, const char **argv)exit (EXIT_FAILURE ); } - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu) goto errmem;
tools/perf/bench/futex-lock-pi.c +2 -1
@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/zalloc.h> #include <errno.h> +#include <perf/cpumap.h> #include "bench.h" #include "futex.h" #include "cpumap.h"
@@ -156,7 +157,7 @@ int bench_futex_lock_pi(int argc, const char **argv)if (argc) goto err; - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu)err (EXIT_FAILURE ,"calloc" );
tools/perf/bench/futex-requeue.c +2 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/time64.h> #include <errno.h> +#include <perf/cpumap.h> #include "bench.h" #include "futex.h" #include "cpumap.h"
@@ -123,7 +124,7 @@ int bench_futex_requeue(int argc, const char **argv)if (argc) goto err; - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu)err (EXIT_FAILURE ,"cpu_map__new" );
tools/perf/bench/futex-wake-parallel.c +1 -1
@@ -237,7 +237,7 @@ int bench_futex_wake_parallel(int argc, const char **argv) act.sa_sigaction = toggle_done;sigaction (SIGINT , &act,NULL ); - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu)err (EXIT_FAILURE ,"calloc" );
tools/perf/bench/futex-wake.c +2 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/time64.h> #include <errno.h> +#include <perf/cpumap.h> #include "bench.h" #include "futex.h" #include "cpumap.h"
@@ -131,7 +132,7 @@ int bench_futex_wake(int argc, const char **argv)exit (EXIT_FAILURE ); } - cpu =cpu_map__new (NULL ); + cpu =perf_cpu_map__new (NULL );if (!cpu)err (EXIT_FAILURE ,"calloc" );
tools/perf/builtin-ftrace.c +1 -1
@@ -202,7 +202,7 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace)static int reset_tracing_cpu (void ) { -struct perf_cpu_map *cpumap =cpu_map__new (NULL ); +struct perf_cpu_map *cpumap =perf_cpu_map__new (NULL );int ret; ret =set_tracing_cpumask (cpumap);
tools/perf/builtin-sched.c +2 -2
@@ -3183,7 +3183,7 @@ static int setup_map_cpus(struct perf_sched *sched)if (!sched->map.cpus_str)return 0 ; - map =cpu_map__new (sched->map.cpus_str); + map =perf_cpu_map__new (sched->map.cpus_str);if (!map) {pr_err ("failed to get cpus map from %s\n" , sched->map.cpus_str);return -1 ;
@@ -3217,7 +3217,7 @@ static int setup_color_cpus(struct perf_sched *sched)if (!sched->map.color_cpus_str)return 0 ; - map =cpu_map__new (sched->map.color_cpus_str); + map =perf_cpu_map__new (sched->map.color_cpus_str);if (!map) {pr_err ("failed to get thread map from %s\n" , sched->map.color_cpus_str);return -1 ;
tools/perf/lib/cpumap.c +184 -0
193 lines not on this page · raw message
tools/perf/lib/include/internal/cpumap.h +4 -0
@@ -10,4 +10,8 @@ struct perf_cpu_map { int map[]; }; +#ifndef MAX_NR_CPUS +#define MAX_NR_CPUS 2048 +#endif +#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
tools/perf/lib/include/perf/cpumap.h +3 -0
@@ -3,10 +3,13 @@#define __LIBPERF_CPUMAP_H#include <perf/core.h> +#include <stdio.h> struct perf_cpu_map ; LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
tools/perf/lib/libperf.map +2 -0
@@ -4,6 +4,8 @@ LIBPERF_0.0.1 { perf_cpu_map__dummy_new; perf_cpu_map__get; perf_cpu_map__put; + perf_cpu_map__new; + perf_cpu_map__read; perf_thread_map__new_dummy; perf_thread_map__set_pid; perf_thread_map__comm;
tools/perf/tests/bitmap.c +2 -1
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> #include <linux/bitmap.h> +#include <perf/cpumap.h> #include "tests.h" #include "cpumap.h" #include "debug.h"
@@ -9,7 +10,7 @@static unsigned long *get_bitmap (const char *str,int nbits) { -struct perf_cpu_map *map =cpu_map__new (str); +struct perf_cpu_map *map =perf_cpu_map__new (str);unsigned long *bm =NULL ;int i;
tools/perf/tests/code-reading.c +3 -2
@@ -8,6 +8,7 @@#include <stdio.h> #include <string.h> #include <sys/param.h> +#include <perf/cpumap.h> #include "parse-events.h" #include "evlist.h"
@@ -613,9 +614,9 @@ static int do_test_code_reading(bool try_kcore) goto out_put; } - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (!cpus) { -pr_debug ("cpu_map__new failed\n" ); +pr_debug ("perf_cpu_map__new failed\n" ); goto out_put; }
tools/perf/tests/cpumap.c +4 -3
@@ -5,6 +5,7 @@#include "event.h" #include <string.h> #include <linux/bitops.h> +#include <perf/cpumap.h> #include "debug.h" struct machine ;
@@ -78,7 +79,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __maystruct perf_cpu_map *cpus;/* This one is better stores in mask. */ - cpus =cpu_map__new ("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19" ); + cpus =perf_cpu_map__new ("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19" );TEST_ASSERT_VAL ("failed to synthesize map" , !perf_event__synthesize_cpu_map (NULL , cpus, process_event_mask,NULL ));
@@ -86,7 +87,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __mayperf_cpu_map__put (cpus);/* This one is better stores in cpu values. */ - cpus =cpu_map__new ("1,256" ); + cpus =perf_cpu_map__new ("1,256" );TEST_ASSERT_VAL ("failed to synthesize map" , !perf_event__synthesize_cpu_map (NULL , cpus, process_event_cpus,NULL ));
@@ -97,7 +98,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __maystatic int cpu_map_print (const char *str) { -struct perf_cpu_map *map =cpu_map__new (str); +struct perf_cpu_map *map =perf_cpu_map__new (str);char buf[100 ];if (!map)
tools/perf/tests/event-times.c +5 -4
@@ -4,6 +4,7 @@#include <inttypes.h> #include <string.h> #include <sys/wait.h> +#include <perf/cpumap.h> #include "tests.h" #include "evlist.h" #include "evsel.h"
@@ -115,9 +116,9 @@ static int attach__cpu_disabled(struct evlist *evlist)pr_debug ("attaching to CPU 0 as enabled\n" ); - cpus =cpu_map__new ("0" ); + cpus =perf_cpu_map__new ("0" );if (cpus ==NULL ) { -pr_debug ("failed to call cpu_map__new\n" ); +pr_debug ("failed to call perf_cpu_map__new\n" );return -1 ; }
@@ -144,9 +145,9 @@ static int attach__cpu_enabled(struct evlist *evlist)pr_debug ("attaching to CPU 0 as enabled\n" ); - cpus =cpu_map__new ("0" ); + cpus =perf_cpu_map__new ("0" );if (cpus ==NULL ) { -pr_debug ("failed to call cpu_map__new\n" ); +pr_debug ("failed to call perf_cpu_map__new\n" );return -1 ; }
tools/perf/tests/event_update.c +2 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> +#include <perf/cpumap.h> #include "evlist.h" #include "evsel.h" #include "machine.h"
@@ -108,7 +109,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unuTEST_ASSERT_VAL ("failed to synthesize attr update name" , !perf_event__synthesize_event_update_name (&tmp.tool, evsel, process_event_name)); - evsel->own_cpus =cpu_map__new ("1,2,3" ); + evsel->own_cpus =perf_cpu_map__new ("1,2,3" );TEST_ASSERT_VAL ("failed to synthesize attr update cpus" , !perf_event__synthesize_event_update_cpus (&tmp.tool, evsel, process_event_cpus));
tools/perf/tests/keep-tracking.c +2 -1
@@ -2,6 +2,7 @@#include <linux/types.h> #include <unistd.h> #include <sys/prctl.h> +#include <perf/cpumap.h> #include "parse-events.h" #include "evlist.h"
@@ -75,7 +76,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un threads =thread_map__new (-1 ,getpid (),UINT_MAX );CHECK_NOT_NULL__ (threads); - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );CHECK_NOT_NULL__ (cpus); evlist =evlist__new ();
tools/perf/tests/mem2node.c +2 -1
@@ -2,6 +2,7 @@#include <linux/compiler.h> #include <linux/bitmap.h> #include <linux/zalloc.h> +#include <perf/cpumap.h> #include "cpumap.h" #include "mem2node.h" #include "tests.h"
@@ -19,7 +20,7 @@ static struct node {static unsigned long *get_bitmap (const char *str,int nbits) { -struct perf_cpu_map *map =cpu_map__new (str); +struct perf_cpu_map *map =perf_cpu_map__new (str);unsigned long *bm =NULL ;int i;
tools/perf/tests/mmap-basic.c +2 -1
@@ -3,6 +3,7 @@#include <inttypes.h> /* For the CLR_() macros */ #include <pthread.h> +#include <perf/cpumap.h> #include "evlist.h" #include "evsel.h"
@@ -46,7 +47,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unusereturn -1 ; } - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (cpus ==NULL ) {pr_debug ("cpu_map__new\n" ); goto out_free_threads;
tools/perf/tests/openat-syscall-all-cpus.c +1 -1
@@ -33,7 +33,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, intreturn -1 ; } - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (cpus ==NULL ) {pr_debug ("cpu_map__new\n" ); goto out_thread_map_delete;
tools/perf/tests/switch-tracking.c +3 -2
@@ -5,6 +5,7 @@#include <time.h> #include <stdlib.h> #include <linux/zalloc.h> +#include <perf/cpumap.h> #include "parse-events.h" #include "evlist.h"
@@ -341,9 +342,9 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ goto out_err; } - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (!cpus) { -pr_debug ("cpu_map__new failed!\n" ); +pr_debug ("perf_cpu_map__new failed!\n" ); goto out_err; }
tools/perf/tests/topology.c +2 -1
@@ -2,6 +2,7 @@#include <string.h> #include <stdlib.h> #include <stdio.h> +#include <perf/cpumap.h> #include "tests.h" #include "util.h" #include "session.h"
@@ -126,7 +127,7 @@ int test__session_topology(struct test *test __maybe_unused, int subtest __maybeif (session_write_header (path)) goto free_path; - map =cpu_map__new (NULL ); + map =perf_cpu_map__new (NULL );if (map ==NULL ) {pr_debug ("failed to get system cpumap\n" ); goto free_path;
tools/perf/util/cpumap.c +1 -180
193 lines not on this page · raw message
tools/perf/util/cpumap.h +0 -2
@@ -11,10 +11,8 @@#include "perf.h" #include "util/debug.h" -struct perf_cpu_map *cpu_map__new (const char *cpu_list);struct perf_cpu_map *cpu_map__empty_new (int nr);struct perf_cpu_map *cpu_map__new_data (struct cpu_map_data *data); -struct perf_cpu_map *cpu_map__read (FILE *file);size_t cpu_map__snprint (struct perf_cpu_map *map,char *buf,size_t size);size_t cpu_map__snprint_mask (struct perf_cpu_map *map,char *buf,size_t size);size_t cpu_map__fprintf (struct perf_cpu_map *map,FILE *fp);
tools/perf/util/cputopo.c +3 -2
@@ -5,6 +5,7 @@#include <stdlib.h> #include <api/fs/fs.h> #include <linux/zalloc.h> +#include <perf/cpumap.h> #include "cputopo.h" #include "cpumap.h"
@@ -182,7 +183,7 @@ struct cpu_topology *cpu_topology__new(void) ncpus =cpu__max_present_cpu ();/* build online CPU map */ - map =cpu_map__new (NULL ); + map =perf_cpu_map__new (NULL );if (map ==NULL ) {pr_debug ("failed to get system cpumap\n" );return NULL ;
@@ -312,7 +313,7 @@ struct numa_topology *numa_topology__new(void)if (c) *c ='\0' ; - node_map =cpu_map__new (buf); + node_map =perf_cpu_map__new (buf);if (!node_map) goto out;
tools/perf/util/evlist.c +3 -2
@@ -34,6 +34,7 @@#include <linux/err.h> #include <linux/zalloc.h> #include <perf/evlist.h> +#include <perf/cpumap.h> #ifdef LACKS_SIGQUEUE_PROTOTYPE int sigqueue (pid_t pid,int sig,const union sigval value);
@@ -1089,7 +1090,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)if (target__uses_dummy_map (target)) cpus =perf_cpu_map__dummy_new ();else - cpus =cpu_map__new (target->cpu_list); + cpus =perf_cpu_map__new (target->cpu_list);if (!cpus) goto out_delete_threads;
@@ -1372,7 +1373,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)* error, and we may not want to do that fallback to a * default cpu identity map :-\ */ - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (!cpus) goto out;
tools/perf/util/header.c +2 -1
@@ -20,6 +20,7 @@#include <linux/time64.h> #include <dirent.h> #include <bpf/libbpf.h> +#include <perf/cpumap.h> #include "evlist.h" #include "evsel.h"
@@ -2348,7 +2349,7 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)if (!str) goto error; - n->map =cpu_map__new (str); + n->map =perf_cpu_map__new (str);if (!n->map) goto error;
tools/perf/util/parse-events.c +2 -1
@@ -24,6 +24,7 @@#include "bpf-loader.h" #include "debug.h" #include <api/fs/tracing_path.h> +#include <perf/cpumap.h> #include "parse-events-bison.h" #define YY_EXTRA_TYPE int#include "parse-events-flex.h"
@@ -323,7 +324,7 @@ __add_event(struct list_head *list, int *idx, {struct evsel *evsel;struct perf_cpu_map *cpus = pmu ? pmu->cpus : - cpu_list ?cpu_map__new (cpu_list) :NULL ; + cpu_list ?perf_cpu_map__new (cpu_list) :NULL ;event_attr_init (attr);
tools/perf/util/pmu.c +2 -1
@@ -15,6 +15,7 @@#include <api/fs/fs.h> #include <locale.h> #include <regex.h> +#include <perf/cpumap.h> #include "pmu.h" #include "parse-events.h" #include "cpumap.h"
@@ -581,7 +582,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path)if (!file)return NULL ; - cpus =cpu_map__read (file); + cpus =perf_cpu_map__read (file);fclose (file);return cpus; }
tools/perf/util/python.c +2 -1
@@ -4,6 +4,7 @@#include <inttypes.h> #include <poll.h> #include <linux/err.h> +#include <perf/cpumap.h> #include "evlist.h" #include "callchain.h" #include "evsel.h"
@@ -549,7 +550,7 @@ static int pyrf_cpu_map__init(struct pyrf_cpu_map *pcpus, kwlist, &cpustr))return -1 ; - pcpus->cpus =cpu_map__new (cpustr); + pcpus->cpus =perf_cpu_map__new (cpustr);if (pcpus->cpus ==NULL )return -1 ;return 0 ;
tools/perf/util/record.c +4 -3
@@ -6,6 +6,7 @@#include <errno.h> #include <api/fs/fs.h> #include <subcmd/parse-options.h> +#include <perf/cpumap.h> #include "util.h" #include "cloexec.h"
@@ -63,7 +64,7 @@ static bool perf_probe_api(setup_probe_fn_t fn)struct perf_cpu_map *cpus;int cpu, ret, i =0 ; - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (!cpus)return false; cpu = cpus->map[0 ];
@@ -118,7 +119,7 @@ bool perf_can_record_cpu_wide(void)struct perf_cpu_map *cpus;int cpu, fd; - cpus =cpu_map__new (NULL ); + cpus =perf_cpu_map__new (NULL );if (!cpus)return false; cpu = cpus->map[0 ];
@@ -275,7 +276,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) evsel =perf_evlist__last (temp_evlist);if (!evlist ||cpu_map__empty (evlist->cpus)) { -struct perf_cpu_map *cpus =cpu_map__new (NULL ); +struct perf_cpu_map *cpus =perf_cpu_map__new (NULL ); cpu = cpus ? cpus->map[0 ] :0 ;perf_cpu_map__put (cpus);
tools/perf/util/session.c +2 -1
@@ -10,6 +10,7 @@#include <unistd.h> #include <sys/types.h> #include <sys/mman.h> +#include <perf/cpumap.h> #include "evlist.h" #include "evsel.h"
@@ -2289,7 +2290,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, } } - map =cpu_map__new (cpu_list); + map =perf_cpu_map__new (cpu_list);if (map ==NULL ) {pr_err ("Invalid cpu_list\n" );return -1 ;
tools/perf/util/svghelper.c +2 -1
@@ -16,6 +16,7 @@#include <linux/bitmap.h> #include <linux/time64.h> #include <linux/zalloc.h> +#include <perf/cpumap.h> #include "perf.h" #include "svghelper.h"
@@ -731,7 +732,7 @@ static int str_to_bitmap(char *s, cpumask_t *b)struct perf_cpu_map *m;int c; - m =cpu_map__new (s); + m =perf_cpu_map__new (s);if (!m)return -1 ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 71/107 libperf: Move zalloc.o into libperf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
We need it in both perf and libperf, thus moving it to libperf.
--- tools/perf/lib/Build | 5 +++++ tools/perf/util/Build | 5 ----- tools/perf/util/python-ext-sources | 1 - 3 files changed, 5 insertions(+), 6 deletions(-)
tools/perf/lib/Build +5 -0
@@ -3,3 +3,8 @@ libperf-y += cpumap.o libperf-y += threadmap.o libperf-y += evsel.o libperf-y += evlist.o +libperf-y += zalloc.o + +$(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c)
tools/perf/util/Build +0 -5
@@ -26,7 +26,6 @@ perf-y += rbtree.o perf-y += libstring.o perf-y += bitmap.o perf-y += hweight.o -perf-y += zalloc.o perf-y += smt.o perf-y += strbuf.o perf-y += string.o
@@ -243,7 +242,3 @@ $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE $(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) - -$(OUTPUT)util/zalloc.o: ../lib/zalloc.c FORCE - $(call rule_mkdir) - $(call if_changed_dep,cc_o_c)
tools/perf/util/python-ext-sources +0 -1
@@ -18,7 +18,6 @@ util/namespaces.c ../lib/hweight.c ../lib/string.c ../lib/vsprintf.c -../lib/zalloc.c util/thread_map.c util/util.c util/xyarray.c
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 72/107 libperf: Add perf_evlist__new() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add perf_evlist__new() function to create and init a perf_evlist struct dynamicaly.
--- tools/perf/lib/evlist.c | 11 +++++++++++ tools/perf/lib/include/perf/evlist.h | 1 + tools/perf/lib/libperf.map | 1 + 3 files changed, 13 insertions(+)
tools/perf/lib/evlist.c +11 -0
@@ -3,6 +3,7 @@#include <linux/list.h> #include <internal/evlist.h> #include <internal/evsel.h> +#include <linux/zalloc.h> void perf_evlist__init (struct perf_evlist *evlist) {
@@ -23,3 +24,13 @@ void perf_evlist__remove(struct perf_evlist *evlist,list_del_init (&evsel->node); evlist->nr_entries -=1 ; } + +struct perf_evlist *perf_evlist__new (void ) +{ +struct perf_evlist *evlist =zalloc (sizeof (*evlist)); + +if (evlist !=NULL ) +perf_evlist__init (evlist); + +return evlist; +}
tools/perf/lib/include/perf/evlist.h +1 -0
@@ -12,5 +12,6 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *evsel); LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,struct perf_evsel *evsel); +LIBPERF_API struct perf_evlist *perf_evlist__new(void);#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 { perf_thread_map__get; perf_thread_map__put; perf_evsel__init; + perf_evlist__new; perf_evlist__init; perf_evlist__add; perf_evlist__remove;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 73/107 libperf: Add perf_evsel__new() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add a perf_evsel__new() function to create and init a perf_evsel struct dynamicaly.
--- tools/perf/lib/evsel.c | 11 +++++++++++ tools/perf/lib/include/perf/evsel.h | 1 + tools/perf/lib/libperf.map | 1 + 3 files changed, 13 insertions(+)
tools/perf/lib/evsel.c +11 -0
@@ -2,9 +2,20 @@#include <perf/evsel.h> #include <linux/list.h> #include <internal/evsel.h> +#include <linux/zalloc.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr) {INIT_LIST_HEAD (&evsel->node); evsel->attr = *attr; } + +struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr) +{ +struct perf_evsel *evsel =zalloc (sizeof (*evsel)); + +if (evsel !=NULL ) +perf_evsel__init (evsel, attr); + +return evsel; +}
tools/perf/lib/include/perf/evsel.h +1 -0
@@ -9,5 +9,6 @@ struct perf_event_attr; LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,struct perf_event_attr *attr); +LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -11,6 +11,7 @@ LIBPERF_0.0.1 { perf_thread_map__comm; perf_thread_map__get; perf_thread_map__put; + perf_evsel__new; perf_evsel__init; perf_evlist__new; perf_evlist__init;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 74/107 libperf: Add perf_evlist__for_each_evsel() iterator
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add a perf_evlist__for_each_evsel() macro to iterate perf_evsel objects in evlist.
Introduce the perf_evlist__next() function to do that without exposing 'struct perf_evlist' internals.
--- tools/perf/lib/evlist.c | 20 ++++++++++++++++++++ tools/perf/lib/include/perf/evlist.h | 7 +++++++ tools/perf/lib/libperf.map | 1 + 3 files changed, 28 insertions(+)
tools/perf/lib/evlist.c +20 -0
@@ -34,3 +34,23 @@ struct perf_evlist *perf_evlist__new(void)return evlist; } + +struct perf_evsel * +perf_evlist__next (struct perf_evlist *evlist,struct perf_evsel *prev) +{ +struct perf_evsel *next; + +if (!prev) { + next =list_first_entry (&evlist->entries, + struct perf_evsel, + node); + }else { + next =list_next_entry (prev, node); + } + +/* Empty list is noticed here so don't need checking on entry. */ +if (&next->node == &evlist->entries) +return NULL ; + +return next; +}
tools/perf/lib/include/perf/evlist.h +7 -0
@@ -13,5 +13,12 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,struct perf_evsel *evsel); LIBPERF_API struct perf_evlist *perf_evlist__new(void); +LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist, +struct perf_evsel *evsel); + +#define perf_evlist__for_each_evsel (evlist, pos) \ + for ((pos) = perf_evlist__next((evlist), NULL); \ + (pos) != NULL; \ + (pos) = perf_evlist__next((evlist), (pos)))#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -17,6 +17,7 @@ LIBPERF_0.0.1 { perf_evlist__init; perf_evlist__add; perf_evlist__remove; + perf_evlist__next; local: *; };
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 75/107 libperf: Add perf_evlist__delete() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evlist__delete() function to delete a perf_evlist instance.
--- tools/perf/lib/evlist.c | 6 ++++++ tools/perf/lib/include/perf/evlist.h | 1 + tools/perf/lib/libperf.map | 1 + 3 files changed, 8 insertions(+)
tools/perf/lib/evlist.c +6 -0
@@ -4,6 +4,7 @@#include <internal/evlist.h> #include <internal/evsel.h> #include <linux/zalloc.h> +#include <stdlib.h> void perf_evlist__init (struct perf_evlist *evlist) {
@@ -54,3 +55,8 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)return next; } + +void perf_evlist__delete (struct perf_evlist *evlist) +{ +free (evlist); +}
tools/perf/lib/include/perf/evlist.h +1 -0
@@ -13,6 +13,7 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,struct perf_evsel *evsel); LIBPERF_API struct perf_evlist *perf_evlist__new(void); +LIBPERF_API void perf_evlist__delete(struct perf_evlist *evlist); LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,struct perf_evsel *evsel);
tools/perf/lib/libperf.map +1 -0
@@ -14,6 +14,7 @@ LIBPERF_0.0.1 { perf_evsel__new; perf_evsel__init; perf_evlist__new; + perf_evlist__delete; perf_evlist__init; perf_evlist__add; perf_evlist__remove;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 76/107 libperf: Add perf_evsel__delete() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the perf_evsel__delete() function to delete a perf_evsel instance.
--- tools/perf/lib/evsel.c | 6 ++++++ tools/perf/lib/include/perf/evsel.h | 1 + tools/perf/lib/libperf.map | 1 + 3 files changed, 8 insertions(+)
tools/perf/lib/evsel.c +6 -0
@@ -3,6 +3,7 @@#include <linux/list.h> #include <internal/evsel.h> #include <linux/zalloc.h> +#include <stdlib.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr) {
@@ -19,3 +20,8 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)return evsel; } + +void perf_evsel__delete (struct perf_evsel *evsel) +{ +free (evsel); +}
tools/perf/lib/include/perf/evsel.h +1 -0
@@ -10,5 +10,6 @@ struct perf_event_attr; LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,struct perf_event_attr *attr); LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr); +LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 { perf_thread_map__get; perf_thread_map__put; perf_evsel__new; + perf_evsel__delete; perf_evsel__init; perf_evlist__new; perf_evlist__delete;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 77/107 libperf: Add cpus to struct perf_evsel
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Mov the 'cpus' field from tools/perf's evsel to libperf's perf_evsel.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-script.c | 2 +- tools/perf/lib/include/internal/evsel.h | 7 +++++-- tools/perf/util/evlist.c | 14 +++++++------- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 3 +-- tools/perf/util/parse-events.c | 2 +- .../util/scripting-engines/trace-event-python.c | 2 +- tools/perf/util/stat-display.c | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -739,7 +739,7 @@ static int record__open(struct record *rec)evlist__for_each_entry (evlist, pos) { try_again: -if (evsel__open (pos, pos->cpus, pos->threads) <0 ) { +if (evsel__open (pos, pos->core.cpus, pos->threads) <0 ) {if (perf_evsel__fallback (pos, errno, msg,sizeof (msg))) {if (verbose >0 )ui__warning ("%s\n" , msg);
tools/perf/builtin-script.c +1 -1
@@ -1920,7 +1920,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp) counts =perf_counts (counter->counts, cpu, thread); printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", - counter->cpus->map[cpu], + counter->core.cpus->map[cpu], thread_map__pid(counter->threads, thread), counts->val, counts->ena,
tools/perf/lib/include/internal/evsel.h +5 -2
@@ -5,9 +5,12 @@#include <linux/types.h> #include <linux/perf_event.h> +struct perf_cpu_map ; +struct perf_evsel { -struct list_head node; -struct perf_event_attr attr; +struct list_head node; +struct perf_event_attr attr; +struct perf_cpu_map *cpus; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/util/evlist.c +7 -7
@@ -160,11 +160,11 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,* keep it, if there's no target cpu list defined. */ if (!evsel->own_cpus || evlist->has_user_cpus) { -perf_cpu_map__put (evsel->cpus); - evsel->cpus =perf_cpu_map__get (evlist->cpus); - }else if (evsel->cpus != evsel->own_cpus) { -perf_cpu_map__put (evsel->cpus); - evsel->cpus =perf_cpu_map__get (evsel->own_cpus); +perf_cpu_map__put (evsel->core.cpus); + evsel->core.cpus =perf_cpu_map__get (evlist->cpus); + }else if (evsel->core.cpus != evsel->own_cpus) { +perf_cpu_map__put (evsel->core.cpus); + evsel->core.cpus =perf_cpu_map__get (evsel->own_cpus); }perf_thread_map__put (evsel->threads);
@@ -786,7 +786,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,if (evsel->system_wide && thread)continue ; - cpu =cpu_map__idx (evsel->cpus, evlist_cpu); + cpu =cpu_map__idx (evsel->core.cpus, evlist_cpu);if (cpu ==-1 )continue ;
@@ -1407,7 +1407,7 @@ int evlist__open(struct evlist *evlist)perf_evlist__update_id_pos (evlist);evlist__for_each_entry (evlist, evsel) { - err =evsel__open (evsel, evsel->cpus, evsel->threads); + err =evsel__open (evsel, evsel->core.cpus, evsel->threads);if (err <0 ) goto out_err; }
tools/perf/util/evsel.c +2 -2
@@ -1325,7 +1325,7 @@ void perf_evsel__exit(struct evsel *evsel)perf_evsel__free_id (evsel);perf_evsel__free_config_terms (evsel);cgroup__put (evsel->cgrp); -perf_cpu_map__put (evsel->cpus); +perf_cpu_map__put (evsel->core.cpus);perf_cpu_map__put (evsel->own_cpus);perf_thread_map__put (evsel->threads);zfree (&evsel->group_name);
@@ -3064,7 +3064,7 @@ static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)int perf_evsel__store_ids (struct evsel *evsel,struct evlist *evlist) { -struct perf_cpu_map *cpus = evsel->cpus; +struct perf_cpu_map *cpus = evsel->core.cpus;struct perf_thread_map *threads = evsel->threads;if (perf_evsel__alloc_id (evsel, cpus->nr, threads->nr))
tools/perf/util/evsel.h +1 -2
@@ -123,7 +123,6 @@ struct evsel {u64 db_id;struct cgroup *cgrp;void *handler; -struct perf_cpu_map *cpus;struct perf_cpu_map *own_cpus;struct perf_thread_map *threads;unsigned int sample_size;
@@ -198,7 +197,7 @@ struct record_opts;static inline struct perf_cpu_map *evsel__cpus (struct evsel *evsel) { -return evsel->cpus; +return evsel->core.cpus; }static inline int perf_evsel__nr_cpus (struct evsel *evsel)
tools/perf/util/parse-events.c +1 -1
@@ -333,7 +333,7 @@ __add_event(struct list_head *list, int *idx,return NULL ; (*idx)++; - evsel->cpus =perf_cpu_map__get (cpus); + evsel->core.cpus =perf_cpu_map__get (cpus); evsel->own_cpus =perf_cpu_map__get (cpus); evsel->system_wide = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats;
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -1393,7 +1393,7 @@ static void python_process_stat(struct perf_stat_config *config, struct evsel *counter, u64 tstamp) {struct perf_thread_map *threads = counter->threads; -struct perf_cpu_map *cpus = counter->cpus; +struct perf_cpu_map *cpus = counter->core.cpus;int cpu, thread;if (config->aggr_mode ==AGGR_GLOBAL ) {
tools/perf/util/stat-display.c +1 -1
@@ -745,7 +745,7 @@ static void print_aggr_thread(struct perf_stat_config *config, {FILE *output = config->output;int nthreads =thread_map__nr (counter->threads); -int ncpus =cpu_map__nr (counter->cpus); +int ncpus =cpu_map__nr (counter->core.cpus);int thread, sorted_threads, id;struct perf_aggr_thread_value *buf;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 78/107 libperf: Add own_cpus to struct perf_evsel
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move own_cpus from tools/perf's evsel to libbpf's perf_evsel.
--- tools/perf/lib/include/internal/evsel.h | 1 + tools/perf/tests/event_update.c | 4 ++-- tools/perf/util/evlist.c | 6 +++--- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 1 - tools/perf/util/header.c | 10 +++++----- tools/perf/util/parse-events.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-)
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -11,6 +11,7 @@ struct perf_evsel {struct list_head node;struct perf_event_attr attr;struct perf_cpu_map *cpus; + struct perf_cpu_map *own_cpus; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/tests/event_update.c +2 -2
@@ -109,11 +109,11 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unuTEST_ASSERT_VAL ("failed to synthesize attr update name" , !perf_event__synthesize_event_update_name (&tmp.tool, evsel, process_event_name)); - evsel->own_cpus =perf_cpu_map__new ("1,2,3" ); + evsel->core.own_cpus =perf_cpu_map__new ("1,2,3" );TEST_ASSERT_VAL ("failed to synthesize attr update cpus" , !perf_event__synthesize_event_update_cpus (&tmp.tool, evsel, process_event_cpus)); -perf_cpu_map__put (evsel->own_cpus); +perf_cpu_map__put (evsel->core.own_cpus);return 0 ; }
tools/perf/util/evlist.c +3 -3
@@ -159,12 +159,12 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,* We already have cpus for evsel (via PMU sysfs) so * keep it, if there's no target cpu list defined. */ -if (!evsel->own_cpus || evlist->has_user_cpus) { +if (!evsel->core.own_cpus || evlist->has_user_cpus) {perf_cpu_map__put (evsel->core.cpus); evsel->core.cpus =perf_cpu_map__get (evlist->cpus); - }else if (evsel->core.cpus != evsel->own_cpus) { + }else if (evsel->core.cpus != evsel->core.own_cpus) {perf_cpu_map__put (evsel->core.cpus); - evsel->core.cpus =perf_cpu_map__get (evsel->own_cpus); + evsel->core.cpus =perf_cpu_map__get (evsel->core.own_cpus); }perf_thread_map__put (evsel->threads);
tools/perf/util/evsel.c +2 -2
@@ -1125,7 +1125,7 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts, attr->exclude_user =1 ; } -if (evsel->own_cpus || evsel->unit) +if (evsel->core.own_cpus || evsel->unit) evsel->core.attr.read_format |=PERF_FORMAT_ID ;/*
@@ -1326,7 +1326,7 @@ void perf_evsel__exit(struct evsel *evsel)perf_evsel__free_config_terms (evsel);cgroup__put (evsel->cgrp);perf_cpu_map__put (evsel->core.cpus); -perf_cpu_map__put (evsel->own_cpus); +perf_cpu_map__put (evsel->core.own_cpus);perf_thread_map__put (evsel->threads);zfree (&evsel->group_name);zfree (&evsel->name);
tools/perf/util/evsel.h +0 -1
@@ -123,7 +123,6 @@ struct evsel {u64 db_id;struct cgroup *cgrp;void *handler; -struct perf_cpu_map *own_cpus;struct perf_thread_map *threads;unsigned int sample_size;int id_pos;
tools/perf/util/header.c +5 -5
@@ -3861,10 +3861,10 @@ perf_event__synthesize_event_update_cpus(struct perf_tool *tool,int max, err;u16 type; -if (!evsel->own_cpus) +if (!evsel->core.own_cpus)return 0 ; - ev =cpu_map_data__alloc (evsel->own_cpus, &size, &type, &max); + ev =cpu_map_data__alloc (evsel->core.own_cpus, &size, &type, &max);if (!ev)return -ENOMEM ;
@@ -3874,7 +3874,7 @@ perf_event__synthesize_event_update_cpus(struct perf_tool *tool, ev->id = evsel->id[0 ];cpu_map_data__synthesize ((struct cpu_map_data *) ev->data, - evsel->own_cpus, + evsel->core.own_cpus, type, max); err =process (tool, (union perf_event *) ev,NULL ,NULL );
@@ -3985,7 +3985,7 @@ int perf_event__synthesize_extra_attr(struct perf_tool *tool, } } -if (counter->own_cpus) { +if (counter->core.own_cpus) { err =perf_event__synthesize_event_update_cpus (tool, counter, process);if (err <0 ) {pr_err ("Couldn't synthesize evsel cpus.\n" );
@@ -4082,7 +4082,7 @@ int perf_event__process_event_update(struct perf_tool *tool __maybe_unused, map =cpu_map__new_data (&ev_cpus->cpus);if (map) - evsel->own_cpus = map; + evsel->core.own_cpus = map;else pr_err ("failed to get event_update cpus\n" );default :
tools/perf/util/parse-events.c +1 -1
@@ -334,7 +334,7 @@ __add_event(struct list_head *list, int *idx, (*idx)++; evsel->core.cpus =perf_cpu_map__get (cpus); - evsel->own_cpus =perf_cpu_map__get (cpus); + evsel->core.own_cpus =perf_cpu_map__get (cpus); evsel->system_wide = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 79/107 libperf: Add threads to struct perf_evsel
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move 'threads' from tools/perf's evsel to libperf's perf_evsel struct.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-script.c | 4 ++-- tools/perf/lib/include/internal/evsel.h | 2 ++ tools/perf/util/evlist.c | 6 +++--- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 1 - tools/perf/util/scripting-engines/trace-event-python.c | 2 +- tools/perf/util/stat-display.c | 6 +++--- tools/perf/util/stat.c | 6 +++--- 9 files changed, 17 insertions(+), 16 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -739,7 +739,7 @@ static int record__open(struct record *rec)evlist__for_each_entry (evlist, pos) { try_again: -if (evsel__open (pos, pos->core.cpus, pos->threads) <0 ) { +if (evsel__open (pos, pos->core.cpus, pos->core.threads) <0 ) {if (perf_evsel__fallback (pos, errno, msg,sizeof (msg))) {if (verbose >0 )ui__warning ("%s\n" , msg);
tools/perf/builtin-script.c +2 -2
@@ -1899,7 +1899,7 @@ static struct scripting_ops *scripting_ops;static void __process_stat (struct evsel *counter,u64 tstamp) { -int nthreads =thread_map__nr (counter->threads); +int nthreads =thread_map__nr (counter->core.threads);int ncpus =perf_evsel__nr_cpus (counter);int cpu, thread;static int header_printed;
@@ -1921,7 +1921,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp) printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", counter->core.cpus->map[cpu], - thread_map__pid(counter->threads, thread), + thread_map__pid(counter->core.threads, thread), counts->val, counts->ena, counts->run,
tools/perf/lib/include/internal/evsel.h +2 -0
@@ -6,12 +6,14 @@#include <linux/perf_event.h> struct perf_cpu_map ; +struct perf_thread_map ;struct perf_evsel {struct list_head node;struct perf_event_attr attr;struct perf_cpu_map *cpus;struct perf_cpu_map *own_cpus; +struct perf_thread_map *threads; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/util/evlist.c +3 -3
@@ -167,8 +167,8 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist, evsel->core.cpus =perf_cpu_map__get (evsel->core.own_cpus); } -perf_thread_map__put (evsel->threads); - evsel->threads =perf_thread_map__get (evlist->threads); +perf_thread_map__put (evsel->core.threads); + evsel->core.threads =perf_thread_map__get (evlist->threads); }static void perf_evlist__propagate_maps (struct evlist *evlist)
@@ -1407,7 +1407,7 @@ int evlist__open(struct evlist *evlist)perf_evlist__update_id_pos (evlist);evlist__for_each_entry (evlist, evsel) { - err =evsel__open (evsel, evsel->core.cpus, evsel->threads); + err =evsel__open (evsel, evsel->core.cpus, evsel->core.threads);if (err <0 ) goto out_err; }
tools/perf/util/evsel.c +2 -2
@@ -1327,7 +1327,7 @@ void perf_evsel__exit(struct evsel *evsel)cgroup__put (evsel->cgrp);perf_cpu_map__put (evsel->core.cpus);perf_cpu_map__put (evsel->core.own_cpus); -perf_thread_map__put (evsel->threads); +perf_thread_map__put (evsel->core.threads);zfree (&evsel->group_name);zfree (&evsel->name); perf_evsel__object.fini (evsel);
@@ -3065,7 +3065,7 @@ static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)int perf_evsel__store_ids (struct evsel *evsel,struct evlist *evlist) {struct perf_cpu_map *cpus = evsel->core.cpus; -struct perf_thread_map *threads = evsel->threads; +struct perf_thread_map *threads = evsel->core.threads;if (perf_evsel__alloc_id (evsel, cpus->nr, threads->nr))return -ENOMEM ;
tools/perf/util/evsel.h +0 -1
@@ -123,7 +123,6 @@ struct evsel {u64 db_id;struct cgroup *cgrp;void *handler; -struct perf_thread_map *threads;unsigned int sample_size;int id_pos;int is_pos;
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -1392,7 +1392,7 @@ process_stat(struct evsel *counter, int cpu, int thread, u64 tstamp,static void python_process_stat (struct perf_stat_config *config,struct evsel *counter,u64 tstamp) { -struct perf_thread_map *threads = counter->threads; +struct perf_thread_map *threads = counter->core.threads;struct perf_cpu_map *cpus = counter->core.cpus;int cpu, thread;
tools/perf/util/stat-display.c +3 -3
@@ -116,9 +116,9 @@ static void aggr_printout(struct perf_stat_config *config,case AGGR_THREAD :fprintf (config->output,"%*s-%*d%s" , config->csv_output ?0 :16 , -perf_thread_map__comm (evsel->threads, id), +perf_thread_map__comm (evsel->core.threads, id), config->csv_output ?0 :-8 , -thread_map__pid (evsel->threads, id), +thread_map__pid (evsel->core.threads, id), config->csv_sep);break ;case AGGR_GLOBAL :
@@ -744,7 +744,7 @@ static void print_aggr_thread(struct perf_stat_config *config, struct evsel *counter, char *prefix) { FILE *output = config->output; -int nthreads =thread_map__nr (counter->threads); +int nthreads =thread_map__nr (counter->core.threads);int ncpus =cpu_map__nr (counter->core.cpus);int thread, sorted_threads, id;struct perf_aggr_thread_value *buf;
tools/perf/util/stat.c +3 -3
@@ -158,7 +158,7 @@ static void perf_evsel__free_prev_raw_counts(struct evsel *evsel)static int perf_evsel__alloc_stats (struct evsel *evsel,bool alloc_raw) {int ncpus =perf_evsel__nr_cpus (evsel); -int nthreads =thread_map__nr (evsel->threads); +int nthreads =thread_map__nr (evsel->core.threads); if (perf_evsel__alloc_stat_priv(evsel) < 0 || perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
@@ -308,7 +308,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,static int process_counter_maps (struct perf_stat_config *config,struct evsel *counter) { -int nthreads =thread_map__nr (counter->threads); +int nthreads =thread_map__nr (counter->core.threads);int ncpus =perf_evsel__nr_cpus (counter);int cpu, thread;
@@ -485,7 +485,7 @@ int create_perf_stat_counter(struct evsel *evsel,if (target__has_cpu (target) && !target__has_per_thread (target))return perf_evsel__open_per_cpu (evsel,evsel__cpus (evsel)); -return perf_evsel__open_per_thread (evsel, evsel->threads); +return perf_evsel__open_per_thread (evsel, evsel->core.threads); } int perf_stat_synthesize_config(struct perf_stat_config *config,
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 80/107 libperf: Add has_user_cpus to struct perf_evlist
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move has_user_cpus from tools/perf's evlist to libbperf's perf_evlist struct.
--- tools/perf/lib/include/internal/evlist.h | 1 + tools/perf/util/evlist.c | 4 ++-- tools/perf/util/evlist.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/lib/include/internal/evlist.h +1 -0
@@ -5,6 +5,7 @@struct perf_evlist {struct list_head entries;int nr_entries; +bool has_user_cpus; };#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/util/evlist.c +2 -2
@@ -159,7 +159,7 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,* We already have cpus for evsel (via PMU sysfs) so * keep it, if there's no target cpu list defined. */ -if (!evsel->core.own_cpus || evlist->has_user_cpus) { +if (!evsel->core.own_cpus || evlist->core.has_user_cpus) {perf_cpu_map__put (evsel->core.cpus); evsel->core.cpus =perf_cpu_map__get (evlist->cpus); }else if (evsel->core.cpus != evsel->core.own_cpus) {
@@ -1095,7 +1095,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)if (!cpus) goto out_delete_threads; - evlist->has_user_cpus = !!target->cpu_list; + evlist->core.has_user_cpus = !!target->cpu_list;perf_evlist__set_maps (evlist, cpus, threads);
tools/perf/util/evlist.h +0 -1
@@ -31,7 +31,6 @@ struct evlist {int nr_groups;int nr_mmaps;bool enabled; -bool has_user_cpus;size_t mmap_len;int id_pos;int is_pos;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 81/107 libperf: Add cpus to struct perf_evlist
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move cpus from tools/perf's evlist to libperf's perf_evlist struct.
Committer notes:
Fixed up this one:
tools/perf/arch/arm/util/cs-etm.c
--- tools/perf/arch/arm/util/cs-etm.c | 8 +++--- tools/perf/arch/x86/util/intel-bts.c | 2 +- tools/perf/arch/x86/util/intel-pt.c | 4 +-- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-stat.c | 16 +++++------ tools/perf/builtin-top.c | 2 +- tools/perf/lib/include/internal/evlist.h | 9 ++++-- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/evlist.c | 36 ++++++++++++------------ tools/perf/util/evlist.h | 1 - tools/perf/util/record.c | 6 ++-- tools/perf/util/stat-display.c | 6 ++-- tools/perf/util/stat.c | 2 +- tools/perf/util/top.c | 6 ++-- 15 files changed, 53 insertions(+), 51 deletions(-)
tools/perf/arch/arm/util/cs-etm.c +4 -4
@@ -155,7 +155,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr, struct evsel *evsel, u32 option) { int i, err = -EINVAL; -struct perf_cpu_map *event_cpus = evsel->evlist->cpus; +struct perf_cpu_map *event_cpus = evsel->evlist->core.cpus;struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );/* Set option of each CPU we have */
@@ -253,7 +253,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, container_of(itr, struct cs_etm_recording, itr);struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;struct evsel *evsel, *cs_etm_evsel =NULL ; -struct perf_cpu_map *cpus = evlist->cpus; +struct perf_cpu_map *cpus = evlist->core.cpus;bool privileged = (geteuid () ==0 ||perf_event_paranoid () <0 );int err =0 ;
@@ -489,7 +489,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, {int i;int etmv3 =0 , etmv4 =0 ; -struct perf_cpu_map *event_cpus = evlist->cpus; +struct perf_cpu_map *event_cpus = evlist->core.cpus;struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );/* cpu map is not empty, we have specific CPUs to work with */
@@ -636,7 +636,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,u32 offset;u64 nr_cpu, type;struct perf_cpu_map *cpu_map; -struct perf_cpu_map *event_cpus = session->evlist->cpus; +struct perf_cpu_map *event_cpus = session->evlist->core.cpus;struct perf_cpu_map *online_cpus =perf_cpu_map__new (NULL );struct cs_etm_recording *ptr = container_of(itr, struct cs_etm_recording, itr);
tools/perf/arch/x86/util/intel-bts.c +1 -1
@@ -106,7 +106,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, container_of(itr, struct intel_bts_recording, itr);struct perf_pmu *intel_bts_pmu = btsr->intel_bts_pmu;struct evsel *evsel, *intel_bts_evsel =NULL ; -const struct perf_cpu_map *cpus = evlist->cpus; +const struct perf_cpu_map *cpus = evlist->core.cpus;bool privileged =geteuid () ==0 ||perf_event_paranoid () <0 ; btsr->evlist = evlist;
tools/perf/arch/x86/util/intel-pt.c +2 -2
@@ -365,7 +365,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,ui__warning ("Intel Processor Trace: TSC not available\n" ); } - per_cpu_mmaps = !cpu_map__empty (session->evlist->cpus); + per_cpu_mmaps = !cpu_map__empty (session->evlist->core.cpus); auxtrace_info->type =PERF_AUXTRACE_INTEL_PT ; auxtrace_info->priv[INTEL_PT_PMU_TYPE ] = intel_pt_pmu->type;
@@ -557,7 +557,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu;bool have_timing_info, need_immediate = false;struct evsel *evsel, *intel_pt_evsel =NULL ; -const struct perf_cpu_map *cpus = evlist->cpus; +const struct perf_cpu_map *cpus = evlist->core.cpus;bool privileged =geteuid () ==0 ||perf_event_paranoid () <0 ;u64 tsc_bit;int err;
tools/perf/builtin-ftrace.c +1 -1
@@ -192,7 +192,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap)static int set_tracing_cpu (struct perf_ftrace *ftrace) { -struct perf_cpu_map *cpumap = ftrace->evlist->cpus; +struct perf_cpu_map *cpumap = ftrace->evlist->core.cpus;if (!target__has_cpu (&ftrace->target))return 0 ;
tools/perf/builtin-record.c +1 -1
@@ -1283,7 +1283,7 @@ static int record__synthesize(struct record *rec, bool tail)return err; } - err =perf_event__synthesize_cpu_map (&rec->tool, rec->evlist->cpus, + err =perf_event__synthesize_cpu_map (&rec->tool, rec->evlist->core.cpus, process_synthesized_event,NULL );if (err <0 ) {pr_err ("Couldn't synthesize cpu map.\n" );
tools/perf/builtin-stat.c +8 -8
@@ -884,21 +884,21 @@ static int perf_stat_init_aggr_mode(void)switch (stat_config.aggr_mode) {case AGGR_SOCKET : -if (cpu_map__build_socket_map (evsel_list->cpus, &stat_config.aggr_map)) { +if (cpu_map__build_socket_map (evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build socket map" );return -1 ; } stat_config.aggr_get_id = perf_stat__get_socket_cached;break ;case AGGR_DIE : -if (cpu_map__build_die_map (evsel_list->cpus, &stat_config.aggr_map)) { +if (cpu_map__build_die_map (evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build die map" );return -1 ; } stat_config.aggr_get_id = perf_stat__get_die_cached;break ;case AGGR_CORE : -if (cpu_map__build_core_map (evsel_list->cpus, &stat_config.aggr_map)) { +if (cpu_map__build_core_map (evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build core map" );return -1 ; }
@@ -906,7 +906,7 @@ static int perf_stat_init_aggr_mode(void)break ;case AGGR_NONE :if (term_percore_set ()) { -if (cpu_map__build_core_map (evsel_list->cpus, +if (cpu_map__build_core_map (evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build core map" );return -1 ;
@@ -926,7 +926,7 @@ static int perf_stat_init_aggr_mode(void)* taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - nr =cpu_map__get_max (evsel_list->cpus); + nr =cpu_map__get_max (evsel_list->core.cpus); stat_config.cpus_aggr_map =cpu_map__empty_new (nr +1 );return stat_config.cpus_aggr_map ?0 : -ENOMEM ; }
@@ -1057,21 +1057,21 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)switch (stat_config.aggr_mode) {case AGGR_SOCKET : -if (perf_env__build_socket_map (env, evsel_list->cpus, &stat_config.aggr_map)) { +if (perf_env__build_socket_map (env, evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build socket map" );return -1 ; } stat_config.aggr_get_id = perf_stat__get_socket_file;break ;case AGGR_DIE : -if (perf_env__build_die_map (env, evsel_list->cpus, &stat_config.aggr_map)) { +if (perf_env__build_die_map (env, evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build die map" );return -1 ; } stat_config.aggr_get_id = perf_stat__get_die_file;break ;case AGGR_CORE : -if (perf_env__build_core_map (env, evsel_list->cpus, &stat_config.aggr_map)) { +if (perf_env__build_core_map (env, evsel_list->core.cpus, &stat_config.aggr_map)) {perror ("cannot build core map" );return -1 ; }
tools/perf/builtin-top.c +1 -1
@@ -989,7 +989,7 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->cpus, +if (evsel__open (counter, top->evlist->core.cpus, top->evlist->threads) <0 ) {/*
tools/perf/lib/include/internal/evlist.h +6 -3
@@ -2,10 +2,13 @@#ifndef __LIBPERF_INTERNAL_EVLIST_H#define __LIBPERF_INTERNAL_EVLIST_H +struct perf_cpu_map ; +struct perf_evlist { -struct list_head entries; -int nr_entries; -bool has_user_cpus; +struct list_head entries; +int nr_entries; +bool has_user_cpus; +struct perf_cpu_map *cpus; };#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/util/auxtrace.c +1 -1
@@ -130,7 +130,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, mp->idx = idx;if (per_cpu) { - mp->cpu = evlist->cpus->map[idx]; + mp->cpu = evlist->core.cpus->map[idx];if (evlist->threads) mp->tid =thread_map__pid (evlist->threads,0 );else
tools/perf/util/evlist.c +18 -18
@@ -143,9 +143,9 @@ void evlist__delete(struct evlist *evlist)perf_evlist__munmap (evlist);evlist__close (evlist); -perf_cpu_map__put (evlist->cpus); +perf_cpu_map__put (evlist->core.cpus);perf_thread_map__put (evlist->threads); - evlist->cpus =NULL ; + evlist->core.cpus =NULL ; evlist->threads =NULL ;perf_evlist__purge (evlist);perf_evlist__exit (evlist);
@@ -161,7 +161,7 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,*/ if (!evsel->core.own_cpus || evlist->core.has_user_cpus) {perf_cpu_map__put (evsel->core.cpus); - evsel->core.cpus =perf_cpu_map__get (evlist->cpus); + evsel->core.cpus =perf_cpu_map__get (evlist->core.cpus); }else if (evsel->core.cpus != evsel->core.own_cpus) {perf_cpu_map__put (evsel->core.cpus); evsel->core.cpus =perf_cpu_map__get (evsel->core.own_cpus);
@@ -398,7 +398,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist, int thread) {int cpu; -int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_cpus =cpu_map__nr (evlist->core.cpus);if (!evsel->fd)return -EINVAL ;
@@ -414,7 +414,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,int perf_evlist__enable_event_idx (struct evlist *evlist,struct evsel *evsel,int idx) { -bool per_cpu_mmaps = !cpu_map__empty (evlist->cpus); +bool per_cpu_mmaps = !cpu_map__empty (evlist->core.cpus);if (per_cpu_mmaps)return perf_evlist__enable_event_cpu (evlist, evsel, idx);
@@ -424,7 +424,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,int perf_evlist__alloc_pollfd (struct evlist *evlist) { -int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_cpus =cpu_map__nr (evlist->core.cpus);int nr_threads =thread_map__nr (evlist->threads);int nfds =0 ;struct evsel *evsel;
@@ -552,8 +552,8 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist, {struct perf_sample_id *sid =SID (evsel, cpu, thread); sid->idx = idx; -if (evlist->cpus && cpu >=0 ) - sid->cpu = evlist->cpus->map[cpu]; +if (evlist->core.cpus && cpu >=0 ) + sid->cpu = evlist->core.cpus->map[cpu];else sid->cpu =-1 ;if (!evsel->system_wide && evlist->threads && thread >=0 )
@@ -720,8 +720,8 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,int i;struct perf_mmap *map; - evlist->nr_mmaps =cpu_map__nr (evlist->cpus); -if (cpu_map__empty (evlist->cpus)) + evlist->nr_mmaps =cpu_map__nr (evlist->core.cpus); +if (cpu_map__empty (evlist->core.cpus)) evlist->nr_mmaps =thread_map__nr (evlist->threads); map =zalloc (evlist->nr_mmaps *sizeof (struct perf_mmap ));if (!map)
@@ -759,7 +759,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx, {struct evsel *evsel;int revent; -int evlist_cpu =cpu_map__cpu (evlist->cpus, cpu_idx); +int evlist_cpu =cpu_map__cpu (evlist->core.cpus, cpu_idx);evlist__for_each_entry (evlist, evsel) {struct perf_mmap *maps = evlist->mmap;
@@ -835,7 +835,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist, struct mmap_params *mp) {int cpu, thread; -int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_cpus =cpu_map__nr (evlist->core.cpus);int nr_threads =thread_map__nr (evlist->threads);pr_debug2 ("perf event ring buffer mmapped per cpu\n" );
@@ -1014,7 +1014,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages, int comp_level) {struct evsel *evsel; -const struct perf_cpu_map *cpus = evlist->cpus; +const struct perf_cpu_map *cpus = evlist->core.cpus;const struct perf_thread_map *threads = evlist->threads;/* * Delay setting mp.prot: set it before calling perf_mmap__mmap.
@@ -1116,9 +1116,9 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus,* original reference count of 1. If that is not the case it is up to * the caller to increase the reference count. */ -if (cpus != evlist->cpus) { -perf_cpu_map__put (evlist->cpus); - evlist->cpus =perf_cpu_map__get (cpus); +if (cpus != evlist->core.cpus) { +perf_cpu_map__put (evlist->core.cpus); + evlist->core.cpus =perf_cpu_map__get (cpus); }if (threads != evlist->threads) {
@@ -1398,7 +1398,7 @@ int evlist__open(struct evlist *evlist)* Default: one fd per CPU, all threads, aka systemwide * as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL */ -if (evlist->threads ==NULL && evlist->cpus ==NULL ) { +if (evlist->threads ==NULL && evlist->core.cpus ==NULL ) { err =perf_evlist__create_syswide_maps (evlist);if (err <0 ) goto out_err;
@@ -1920,7 +1920,7 @@ int perf_evlist__start_sb_thread(struct evlist *evlist, goto out_delete_evlist;evlist__for_each_entry (evlist, counter) { -if (evsel__open (counter, evlist->cpus, +if (evsel__open (counter, evlist->core.cpus, evlist->threads) <0 ) goto out_delete_evlist; }
tools/perf/util/evlist.h +0 -1
@@ -44,7 +44,6 @@ struct evlist {struct perf_mmap *mmap;struct perf_mmap *overwrite_mmap;struct perf_thread_map *threads; -struct perf_cpu_map *cpus;struct evsel *selected;struct events_stats stats;struct perf_env *env;
tools/perf/util/record.c +3 -3
@@ -148,7 +148,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,if (opts->group)perf_evlist__set_leader (evlist); -if (evlist->cpus->map[0 ] <0 ) +if (evlist->core.cpus->map[0 ] <0 ) opts->no_inherit = true; use_comm_exec =perf_can_comm_exec ();
@@ -275,13 +275,13 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) evsel =perf_evlist__last (temp_evlist); -if (!evlist ||cpu_map__empty (evlist->cpus)) { +if (!evlist ||cpu_map__empty (evlist->core.cpus)) {struct perf_cpu_map *cpus =perf_cpu_map__new (NULL ); cpu = cpus ? cpus->map[0 ] :0 ;perf_cpu_map__put (cpus); }else { - cpu = evlist->cpus->map[0 ]; + cpu = evlist->core.cpus->map[0 ]; }while (1 ) {
tools/perf/util/stat-display.c +3 -3
@@ -327,7 +327,7 @@ static int first_shadow_cpu(struct perf_stat_config *config,for (i =0 ; i <perf_evsel__nr_cpus (evsel); i++) {int cpu2 =evsel__cpus (evsel)->map[i]; -if (config->aggr_get_id (config, evlist->cpus, cpu2) == id) +if (config->aggr_get_id (config, evlist->core.cpus, cpu2) == id)return cpu2; }return 0 ;
@@ -500,7 +500,7 @@ static void aggr_update_shadow(struct perf_stat_config *config,evlist__for_each_entry (evlist, counter) { val =0 ;for (cpu =0 ; cpu <perf_evsel__nr_cpus (counter); cpu++) { - s2 = config->aggr_get_id (config, evlist->cpus, cpu); + s2 = config->aggr_get_id (config, evlist->core.cpus, cpu);if (s2 != id)continue ; val +=perf_counts (counter->counts, cpu,0 )->val;
@@ -868,7 +868,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config,u64 ena, run, val;double uval; - nrcpus = evlist->cpus->nr; + nrcpus = evlist->core.cpus->nr;for (cpu =0 ; cpu < nrcpus; cpu++) {bool first = true;
tools/perf/util/stat.c +1 -1
@@ -514,7 +514,7 @@ int perf_stat_synthesize_config(struct perf_stat_config *config,return err; } - err =perf_event__synthesize_cpu_map (tool, evlist->cpus, + err =perf_event__synthesize_cpu_map (tool, evlist->core.cpus, process,NULL );if (err <0 ) {pr_err ("Couldn't synthesize thread map.\n" );
tools/perf/util/top.c +3 -3
@@ -95,15 +95,15 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)if (target->cpu_list) ret +=SNPRINTF (bf + ret, size - ret,", CPU%s: %s)" , - top->evlist->cpus->nr >1 ?"s" :"" , + top->evlist->core.cpus->nr >1 ?"s" :"" , target->cpu_list);else {if (target->tid) ret +=SNPRINTF (bf + ret, size - ret,")" );else ret +=SNPRINTF (bf + ret, size - ret,", %d CPU%s)" , - top->evlist->cpus->nr, - top->evlist->cpus->nr >1 ?"s" :"" ); + top->evlist->core.cpus->nr, + top->evlist->core.cpus->nr >1 ?"s" :"" ); }perf_top__reset_sample_counters (top);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 82/107 libperf: Add threads to struct perf_evlist
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move threads from tools/perf's evlist to libperf's perf_evlist struct.
--- tools/perf/builtin-ftrace.c | 4 +-- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 4 +-- tools/perf/builtin-stat.c | 18 +++++------ tools/perf/builtin-top.c | 4 +-- tools/perf/builtin-trace.c | 8 ++--- tools/perf/lib/include/internal/evlist.h | 2 ++ tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/util/auxtrace.c | 6 ++-- tools/perf/util/evlist.c | 36 ++++++++++----------- tools/perf/util/evlist.h | 1 - tools/perf/util/stat.c | 2 +- 12 files changed, 45 insertions(+), 44 deletions(-)
tools/perf/builtin-ftrace.c +2 -2
@@ -156,9 +156,9 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)if (target__has_cpu (&ftrace->target))return 0 ; -for (i =0 ; i <thread_map__nr (ftrace->evlist->threads); i++) { +for (i =0 ; i <thread_map__nr (ftrace->evlist->core.threads); i++) {scnprintf (buf,sizeof (buf),"%d" , - ftrace->evlist->threads->map[i]); + ftrace->evlist->core.threads->map[i]);if (append_tracing_file ("set_ftrace_pid" , buf) <0 )return -1 ; }
tools/perf/builtin-kvm.c +1 -1
@@ -1450,7 +1450,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,perf_session__set_id_hdr_size (kvm->session);ordered_events__set_copy_on_queue (&kvm->session->ordered_events, true);machine__synthesize_threads (&kvm->session->machines.host, &kvm->opts.target, - kvm->evlist->threads, false,1 ); + kvm->evlist->core.threads, false,1 ); err =kvm_live_open_events (kvm);if (err) goto out;
tools/perf/builtin-record.c +2 -2
@@ -1275,7 +1275,7 @@ static int record__synthesize(struct record *rec, bool tail)if (err) goto out; - err =perf_event__synthesize_thread_map2 (&rec->tool, rec->evlist->threads, + err =perf_event__synthesize_thread_map2 (&rec->tool, rec->evlist->core.threads, process_synthesized_event,NULL );if (err <0 ) {
@@ -1295,7 +1295,7 @@ static int record__synthesize(struct record *rec, bool tail)if (err <0 )pr_warning ("Couldn't synthesize bpf events.\n" ); - err =__machine__synthesize_threads (machine, tool, &opts->target, rec->evlist->threads, + err =__machine__synthesize_threads (machine, tool, &opts->target, rec->evlist->core.threads, process_synthesized_event, opts->sample_address,1 ); out:
tools/perf/builtin-stat.c +9 -9
@@ -263,7 +263,7 @@ static int read_single_counter(struct evsel *counter, int cpu,*/ static int read_counter (struct evsel *counter,struct timespec *rs) { -int nthreads =thread_map__nr (evsel_list->threads); +int nthreads =thread_map__nr (evsel_list->core.threads);int ncpus, cpu, thread;if (target__has_cpu (&target) && !target__has_per_thread (&target))
@@ -485,15 +485,15 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)ui__warning ("%s\n" , msg); goto try_again; }else if (target__has_per_thread (&target) && - evsel_list->threads && - evsel_list->threads->err_thread !=-1 ) { + evsel_list->core.threads && + evsel_list->core.threads->err_thread !=-1 ) {/* * For global --per-thread case, skip current * error thread. */ -if (!thread_map__remove (evsel_list->threads, - evsel_list->threads->err_thread)) { - evsel_list->threads->err_thread =-1 ; +if (!thread_map__remove (evsel_list->core.threads, + evsel_list->core.threads->err_thread)) { + evsel_list->core.threads->err_thread =-1 ; goto try_again; } }
@@ -579,7 +579,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)enable_counters ();while (!done) {nanosleep (&ts,NULL ); -if (!is_target_alive (&target, evsel_list->threads)) +if (!is_target_alive (&target, evsel_list->core.threads))break ;if (timeout)break ;
@@ -1889,10 +1889,10 @@ int cmd_stat(int argc, const char **argv)* so we could print it out on output. */ if (stat_config.aggr_mode ==AGGR_THREAD ) { -thread_map__read_comms (evsel_list->threads); +thread_map__read_comms (evsel_list->core.threads);if (target.system_wide) {if (runtime_stat_new (&stat_config, -thread_map__nr (evsel_list->threads))) { +thread_map__nr (evsel_list->core.threads))) { goto out; } }
tools/perf/builtin-top.c +2 -2
@@ -990,7 +990,7 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again:if (evsel__open (counter, top->evlist->core.cpus, - top->evlist->threads) <0 ) { + top->evlist->core.threads) <0 ) {/* * Specially handle overwrite fall back.
@@ -1222,7 +1222,7 @@ static int __cmd_top(struct perf_top *top)pr_debug ("Couldn't synthesize BPF events: Pre-existing BPF programs won't have symbols resolved.\n" );machine__synthesize_threads (&top->session->machines.host, &opts->target, - top->evlist->threads, false, + top->evlist->core.threads, false, top->nr_threads_synthesize);if (top->nr_threads_synthesize >1 )
tools/perf/builtin-trace.c +4 -4
@@ -1404,7 +1404,7 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist) goto out; err =__machine__synthesize_threads (trace->host, &trace->tool, &trace->opts.target, - evlist->threads, trace__tool_process, false, + evlist->core.threads, trace__tool_process, false,1 ); out:if (err)
@@ -3183,7 +3183,7 @@ static int trace__set_filter_pids(struct trace *trace) err =bpf_map__set_filter_pids (trace->filter_pids.map, trace->filter_pids.nr, trace->filter_pids.entries); } - }else if (thread_map__pid (trace->evlist->threads,0 ) ==-1 ) { + }else if (thread_map__pid (trace->evlist->core.threads,0 ) ==-1 ) { err =trace__set_filter_loop_pids (trace); }
@@ -3412,8 +3412,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)evlist__enable (evlist); } - trace->multiple_threads =thread_map__pid (evlist->threads,0 ) ==-1 || - evlist->threads->nr >1 || + trace->multiple_threads =thread_map__pid (evlist->core.threads,0 ) ==-1 || + evlist->core.threads->nr >1 ||perf_evlist__first (evlist)->core.attr.inherit;/*
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -3,12 +3,14 @@#define __LIBPERF_INTERNAL_EVLIST_Hstruct perf_cpu_map ; +struct perf_thread_map ;struct perf_evlist {struct list_head entries;int nr_entries;bool has_user_cpus;struct perf_cpu_map *cpus; +struct perf_thread_map *threads; };#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -58,7 +58,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestperf_evsel__config (evsel, &opts,NULL ); -perf_thread_map__set_pid (evlist->threads,0 ,getpid ()); +perf_thread_map__set_pid (evlist->core.threads,0 ,getpid ()); err =evlist__open (evlist);if (err <0 ) {
tools/perf/util/auxtrace.c +3 -3
@@ -131,13 +131,13 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,if (per_cpu) { mp->cpu = evlist->core.cpus->map[idx]; -if (evlist->threads) - mp->tid =thread_map__pid (evlist->threads,0 ); +if (evlist->core.threads) + mp->tid =thread_map__pid (evlist->core.threads,0 );else mp->tid =-1 ; }else { mp->cpu =-1 ; - mp->tid =thread_map__pid (evlist->threads, idx); + mp->tid =thread_map__pid (evlist->core.threads, idx); } }
tools/perf/util/evlist.c +18 -18
@@ -144,9 +144,9 @@ void evlist__delete(struct evlist *evlist)perf_evlist__munmap (evlist);evlist__close (evlist);perf_cpu_map__put (evlist->core.cpus); -perf_thread_map__put (evlist->threads); +perf_thread_map__put (evlist->core.threads); evlist->core.cpus =NULL ; - evlist->threads =NULL ; + evlist->core.threads =NULL ;perf_evlist__purge (evlist);perf_evlist__exit (evlist);free (evlist);
@@ -168,7 +168,7 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist, }perf_thread_map__put (evsel->core.threads); - evsel->core.threads =perf_thread_map__get (evlist->threads); + evsel->core.threads =perf_thread_map__get (evlist->core.threads); }static void perf_evlist__propagate_maps (struct evlist *evlist)
@@ -342,7 +342,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,if (evsel->system_wide)return 1 ;else -return thread_map__nr (evlist->threads); +return thread_map__nr (evlist->core.threads); }void evlist__disable (struct evlist *evlist)
@@ -425,7 +425,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,int perf_evlist__alloc_pollfd (struct evlist *evlist) {int nr_cpus =cpu_map__nr (evlist->core.cpus); -int nr_threads =thread_map__nr (evlist->threads); +int nr_threads =thread_map__nr (evlist->core.threads);int nfds =0 ;struct evsel *evsel;
@@ -556,8 +556,8 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist, sid->cpu = evlist->core.cpus->map[cpu]; else sid->cpu = -1; -if (!evsel->system_wide && evlist->threads && thread >=0 ) - sid->tid =thread_map__pid (evlist->threads, thread); +if (!evsel->system_wide && evlist->core.threads && thread >=0 ) + sid->tid =thread_map__pid (evlist->core.threads, thread);else sid->tid =-1 ; }
@@ -722,7 +722,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist, evlist->nr_mmaps =cpu_map__nr (evlist->core.cpus);if (cpu_map__empty (evlist->core.cpus)) - evlist->nr_mmaps =thread_map__nr (evlist->threads); + evlist->nr_mmaps =thread_map__nr (evlist->core.threads); map =zalloc (evlist->nr_mmaps *sizeof (struct perf_mmap ));if (!map)return NULL ;
@@ -836,7 +836,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist, {int cpu, thread;int nr_cpus =cpu_map__nr (evlist->core.cpus); -int nr_threads =thread_map__nr (evlist->threads); +int nr_threads =thread_map__nr (evlist->core.threads);pr_debug2 ("perf event ring buffer mmapped per cpu\n" );for (cpu =0 ; cpu < nr_cpus; cpu++) {
@@ -864,7 +864,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist, struct mmap_params *mp) {int thread; -int nr_threads =thread_map__nr (evlist->threads); +int nr_threads =thread_map__nr (evlist->core.threads);pr_debug2 ("perf event ring buffer mmapped per thread\n" );for (thread =0 ; thread < nr_threads; thread++) {
@@ -1015,7 +1015,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages, {struct evsel *evsel;const struct perf_cpu_map *cpus = evlist->core.cpus; -const struct perf_thread_map *threads = evlist->threads; +const struct perf_thread_map *threads = evlist->core.threads;/* * Delay setting mp.prot: set it before calling perf_mmap__mmap. * Its value is decided by evsel's write_backward.
@@ -1121,9 +1121,9 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus, evlist->core.cpus =perf_cpu_map__get (cpus); } -if (threads != evlist->threads) { -perf_thread_map__put (evlist->threads); - evlist->threads =perf_thread_map__get (threads); +if (threads != evlist->core.threads) { +perf_thread_map__put (evlist->core.threads); + evlist->core.threads =perf_thread_map__get (threads); }perf_evlist__propagate_maps (evlist);
@@ -1398,7 +1398,7 @@ int evlist__open(struct evlist *evlist)* Default: one fd per CPU, all threads, aka systemwide * as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL */ -if (evlist->threads ==NULL && evlist->core.cpus ==NULL ) { +if (evlist->core.threads ==NULL && evlist->core.cpus ==NULL ) { err =perf_evlist__create_syswide_maps (evlist);if (err <0 ) goto out_err;
@@ -1501,12 +1501,12 @@ int perf_evlist__prepare_workload(struct evlist *evlist, struct target *target, }if (target__none (target)) { -if (evlist->threads ==NULL ) { +if (evlist->core.threads ==NULL ) {fprintf (stderr,"FATAL: evlist->threads need to be set at this point (%s:%d).\n" , __func__, __LINE__); goto out_close_pipes; } -perf_thread_map__set_pid (evlist->threads,0 , evlist->workload.pid); +perf_thread_map__set_pid (evlist->core.threads,0 , evlist->workload.pid); }close (child_ready_pipe[1 ]);
@@ -1921,7 +1921,7 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,evlist__for_each_entry (evlist, counter) {if (evsel__open (counter, evlist->core.cpus, - evlist->threads) <0 ) + evlist->core.threads) <0 ) goto out_delete_evlist; }
tools/perf/util/evlist.h +0 -1
@@ -43,7 +43,6 @@ struct evlist {struct fdarray pollfd;struct perf_mmap *mmap;struct perf_mmap *overwrite_mmap; -struct perf_thread_map *threads;struct evsel *selected;struct events_stats stats;struct perf_env *env;
tools/perf/util/stat.c +1 -1
@@ -507,7 +507,7 @@ int perf_stat_synthesize_config(struct perf_stat_config *config, err =perf_event__synthesize_extra_attr (tool, evlist, process, attrs); - err =perf_event__synthesize_thread_map2 (tool, evlist->threads, + err =perf_event__synthesize_thread_map2 (tool, evlist->core.threads, process,NULL );if (err <0 ) {pr_err ("Couldn't synthesize thread map.\n" );
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 83/107 libperf: Add perf_evlist__set_maps() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the evlist__set_maps() function from tools/perf to libperf.
Committer notes:
Fix up reject due to earlier inversion in calling perf_evlist__init().
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 3 +- tools/perf/builtin-script.c | 3 +- tools/perf/builtin-stat.c | 3 +- tools/perf/lib/evlist.c | 54 ++++++++++++++++++ tools/perf/lib/include/perf/evlist.h | 6 ++ tools/perf/lib/libperf.map | 1 + tools/perf/tests/code-reading.c | 5 +- tools/perf/tests/keep-tracking.c | 3 +- tools/perf/tests/mmap-basic.c | 3 +- tools/perf/tests/sw-clock.c | 3 +- tools/perf/tests/switch-tracking.c | 3 +- tools/perf/tests/task-exit.c | 3 +- tools/perf/util/evlist.c | 58 +------------------- tools/perf/util/evlist.h | 2 - 14 files changed, 83 insertions(+), 67 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +2 -1
@@ -6,6 +6,7 @@#include <linux/types.h> #include <sys/prctl.h> #include <perf/cpumap.h> +#include <perf/evlist.h> #include "parse-events.h" #include "evlist.h"
@@ -72,7 +73,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe evlist =evlist__new ();CHECK_NOT_NULL__ (evlist); -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads);CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));
tools/perf/builtin-script.c +2 -1
@@ -48,6 +48,7 @@#include <fcntl.h> #include <unistd.h> #include <subcmd/pager.h> +#include <perf/evlist.h> #include <linux/ctype.h>
@@ -3264,7 +3265,7 @@ static int set_maps(struct perf_script *script)if (WARN_ONCE (script->allocated,"stats double allocation\n" ))return -EINVAL ; -perf_evlist__set_maps (evlist, script->cpus, script->threads); +perf_evlist__set_maps (&evlist->core, script->cpus, script->threads);if (perf_evlist__alloc_stats (evlist, true))return -ENOMEM ;
tools/perf/builtin-stat.c +2 -1
@@ -83,6 +83,7 @@#include <sys/resource.h> #include <linux/ctype.h> +#include <perf/evlist.h> #define DEFAULT_SEPARATOR " "#define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi"
@@ -1517,7 +1518,7 @@ static int set_maps(struct perf_stat *st)if (WARN_ONCE (st->maps_allocated,"stats double allocation\n" ))return -EINVAL ; -perf_evlist__set_maps (evsel_list, st->cpus, st->threads); +perf_evlist__set_maps (&evsel_list->core, st->cpus, st->threads);if (perf_evlist__alloc_stats (evsel_list, true))return -ENOMEM ;
tools/perf/lib/evlist.c +54 -0
74 lines not on this page · raw message
tools/perf/lib/include/perf/evlist.h +6 -0
@@ -6,6 +6,8 @@struct perf_evlist ;struct perf_evsel ; +struct perf_cpu_map ; +struct perf_thread_map ; LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist); LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
@@ -22,4 +24,8 @@ LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist, (pos) !=NULL ; \ (pos) = perf_evlist__next((evlist), (pos))) +LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist, +struct perf_cpu_map *cpus, +struct perf_thread_map *threads); +#endif /* __LIBPERF_EVLIST_H */
tools/perf/lib/libperf.map +1 -0
@@ -20,6 +20,7 @@ LIBPERF_0.0.1 { perf_evlist__add; perf_evlist__remove; perf_evlist__next; + perf_evlist__set_maps; local: *; };
tools/perf/tests/code-reading.c +3 -2
@@ -9,6 +9,7 @@#include <string.h> #include <sys/param.h> #include <perf/cpumap.h> +#include <perf/evlist.h> #include "parse-events.h" #include "evlist.h"
@@ -629,7 +630,7 @@ static int do_test_code_reading(bool try_kcore) goto out_put; } -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads); str =do_determine_event (excl_kernel);pr_debug ("Parsing event '%s'\n" , str);
@@ -658,7 +659,7 @@ static int do_test_code_reading(bool try_kcore)*/ perf_cpu_map__get (cpus);perf_thread_map__get (threads); -perf_evlist__set_maps (evlist,NULL ,NULL ); +perf_evlist__set_maps (&evlist->core,NULL ,NULL );evlist__delete (evlist); evlist =NULL ;continue ;
tools/perf/tests/keep-tracking.c +2 -1
@@ -3,6 +3,7 @@#include <unistd.h> #include <sys/prctl.h> #include <perf/cpumap.h> +#include <perf/evlist.h> #include "parse-events.h" #include "evlist.h"
@@ -82,7 +83,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un evlist =evlist__new ();CHECK_NOT_NULL__ (evlist); -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads);CHECK__ (parse_events (evlist,"dummy:u" ,NULL ));CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));
tools/perf/tests/mmap-basic.c +2 -1
@@ -12,6 +12,7 @@#include "tests.h" #include <linux/err.h> #include <linux/kernel.h> +#include <perf/evlist.h> /* * This test will generate random numbers of calls to some getpid syscalls,
@@ -68,7 +69,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse goto out_free_cpus; } -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads);for (i =0 ; i < nsyscalls; ++i) {char name[64 ];
tools/perf/tests/sw-clock.c +2 -1
@@ -11,6 +11,7 @@#include "util/evlist.h" #include "util/cpumap.h" #include "util/thread_map.h" +#include <perf/evlist.h> #define NR_LOOPS 10000000
@@ -64,7 +65,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) goto out_free_maps; } -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads); cpus =NULL ; threads =NULL ;
tools/perf/tests/switch-tracking.c +2 -1
@@ -6,6 +6,7 @@#include <stdlib.h> #include <linux/zalloc.h> #include <perf/cpumap.h> +#include <perf/evlist.h> #include "parse-events.h" #include "evlist.h"
@@ -354,7 +355,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ goto out_err; } -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads);/* First event */ err =parse_events (evlist,"cpu-clock:u" ,NULL );
tools/perf/tests/task-exit.c +2 -1
@@ -7,6 +7,7 @@#include <errno.h> #include <signal.h> +#include <perf/evlist.h> static int exited;static int nr_exit;
@@ -71,7 +72,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused goto out_free_maps; } -perf_evlist__set_maps (evlist, cpus, threads); +perf_evlist__set_maps (&evlist->core, cpus, threads); cpus =NULL ; threads =NULL ;
tools/perf/util/evlist.c +3 -55
94 lines not on this page · raw message
tools/perf/util/evlist.h +0 -2
@@ -191,8 +191,6 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,void perf_evlist__set_selected (struct evlist *evlist,struct evsel *evsel); -void perf_evlist__set_maps (struct evlist *evlist,struct perf_cpu_map *cpus, -struct perf_thread_map *threads);int perf_evlist__create_maps (struct evlist *evlist,struct target *target);int perf_evlist__apply_filters (struct evlist *evlist,struct evsel **err_evsel);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 84/107 libperf: Adopt xyarray class from perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the xyarray class from perf to libperf, because it's going to be used in both.
---
tools/perf/builtin-top.c | 1 -
tools/perf/lib/Build | 1 +
.../{util => lib/include/internal}/xyarray.h | 6 ++--
tools/perf/lib/xyarray.c | 33 +++++++++++++++++++
tools/perf/util/Build | 1 -
tools/perf/util/counts.h | 2 +-
tools/perf/util/evsel.h | 2 +-
tools/perf/util/python-ext-sources | 1 -
tools/perf/util/stat.h | 1 -
9 files changed, 39 insertions(+), 9 deletions(-)
rename tools/perf/{util => lib/include/internal}/xyarray.h (84%)
create mode 100644 tools/perf/lib/xyarray.ctools/perf/builtin-top.c +0 -1
@@ -38,7 +38,6 @@#include <subcmd/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" -#include "util/xyarray.h" #include "util/sort.h" #include "util/string2.h" #include "util/term.h"
tools/perf/lib/Build +1 -0
@@ -4,6 +4,7 @@ libperf-y += threadmap.o libperf-y += evsel.o libperf-y += evlist.o libperf-y += zalloc.o +libperf-y += xyarray.o $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE $(call rule_mkdir)
tools/perf/lib/include/internal/xyarray.h renamed from tools/perf/util/xyarray.h +3 -3
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _PERF_XYARRAY_H_ -#define _PERF_XYARRAY_H_ 1 +#ifndef __LIBPERF_INTERNAL_XYARRAY_H +#define __LIBPERF_INTERNAL_XYARRAY_H#include <sys/types.h>
@@ -32,4 +32,4 @@ static inline int xyarray__max_x(struct xyarray *xy) return xy->max_x; } -#endif /* _PERF_XYARRAY_H_ */ +#endif /* __LIBPERF_INTERNAL_XYARRAY_H */
tools/perf/lib/xyarray.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <internal/xyarray.h> +#include <linux/zalloc.h> +#include <stdlib.h> +#include <string.h> + +struct xyarray *xyarray__new (int xlen,int ylen,size_t entry_size) +{ +size_t row_size = ylen * entry_size; +struct xyarray *xy =zalloc (sizeof (*xy) + xlen * row_size); + +if (xy !=NULL ) { + xy->entry_size = entry_size; + xy->row_size = row_size; + xy->entries = xlen * ylen; + xy->max_x = xlen; + xy->max_y = ylen; + } + +return xy; +} + +void xyarray__reset (struct xyarray *xy) +{ +size_t n = xy->entries * xy->entry_size; + +memset (xy->contents,0 , n); +} + +void xyarray__delete (struct xyarray *xy) +{ +free (xy); +}
tools/perf/util/Build +0 -1
@@ -69,7 +69,6 @@ perf-y += svghelper.o perf-y += sort.o perf-y += hist.o perf-y += util.o -perf-y += xyarray.o perf-y += cpumap.o perf-y += cputopo.o perf-y += cgroup.o
tools/perf/util/counts.h +1 -1
@@ -2,7 +2,7 @@ #ifndef __PERF_COUNTS_H #define __PERF_COUNTS_H -#include "xyarray.h" +#include <internal/xyarray.h> struct perf_counts_values { union {
tools/perf/util/evsel.h +1 -1
@@ -8,7 +8,7 @@#include <linux/perf_event.h> #include <linux/types.h> #include <internal/evsel.h> -#include "xyarray.h" +#include <internal/xyarray.h> #include "symbol_conf.h" #include "cpumap.h" #include "counts.h"
tools/perf/util/python-ext-sources +0 -1
@@ -20,7 +20,6 @@ util/namespaces.c ../lib/vsprintf.c util/thread_map.c util/util.c -util/xyarray.c util/cgroup.c util/parse-branch-options.c util/rblist.c
tools/perf/util/stat.h +0 -1
@@ -8,7 +8,6 @@#include <sys/time.h> #include <sys/resource.h> #include <sys/wait.h> -#include "xyarray.h" #include "rblist.h" #include "perf.h" #include "event.h"
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 85/107 libperf: Move fd array from perf's evsel to lobperf's perf_evsel class
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the fd array from perf's evsel to libperf's perf_evsel class.
--- tools/perf/lib/include/internal/evsel.h | 1 + tools/perf/util/bpf-loader.c | 2 +- tools/perf/util/evlist.c | 10 ++++----- tools/perf/util/evsel.c | 30 ++++++++++++------------- tools/perf/util/evsel.h | 1 - 5 files changed, 22 insertions(+), 22 deletions(-)
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -14,6 +14,7 @@ struct perf_evsel {struct perf_cpu_map *cpus;struct perf_cpu_map *own_cpus;struct perf_thread_map *threads; + struct xyarray *fd; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/util/bpf-loader.c +1 -1
@@ -1403,7 +1403,7 @@ static int apply_config_evsel_for_key(const char *name, int map_fd, void *pkey, struct evsel *evsel) { - struct xyarray *xy = evsel->fd; + struct xyarray *xy = evsel->core.fd;struct perf_event_attr *attr;unsigned int key, events;bool check_pass = false;
tools/perf/util/evlist.c +5 -5
@@ -40,7 +40,7 @@int sigqueue (pid_t pid,int sig,const union sigval value);#endif -#define FD (e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) +#define FD (e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))#define SID (e, x, y) xyarray__entry(e->sample_id, x, y) void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
@@ -321,7 +321,7 @@ void evlist__disable(struct evlist *evlist)struct evsel *pos;evlist__for_each_entry (evlist, pos) { -if (pos->disabled || !perf_evsel__is_group_leader (pos) || !pos->fd) +if (pos->disabled || !perf_evsel__is_group_leader (pos) || !pos->core.fd)continue ;evsel__disable (pos); }
@@ -334,7 +334,7 @@ void evlist__enable(struct evlist *evlist)struct evsel *pos;evlist__for_each_entry (evlist, pos) { -if (!perf_evsel__is_group_leader (pos) || !pos->fd) +if (!perf_evsel__is_group_leader (pos) || !pos->core.fd)continue ;evsel__enable (pos); }
@@ -353,7 +353,7 @@ static int perf_evlist__enable_event_cpu(struct evlist *evlist,int thread;int nr_threads =perf_evlist__nr_threads (evlist, evsel); -if (!evsel->fd) +if (!evsel->core.fd)return -EINVAL ;for (thread =0 ; thread < nr_threads; thread++) {
@@ -371,7 +371,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,int cpu;int nr_cpus =cpu_map__nr (evlist->core.cpus); -if (!evsel->fd) +if (!evsel->core.fd)return -EINVAL ;for (cpu =0 ; cpu < nr_cpus; cpu++) {
tools/perf/util/evsel.c +15 -15
@@ -90,7 +90,7 @@ int perf_evsel__object_config(size_t object_size,return 0 ; } -#define FD (e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) +#define FD (e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))int __perf_evsel__sample_size (u64 sample_type) {
@@ -1155,9 +1155,9 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,static int perf_evsel__alloc_fd (struct evsel *evsel,int ncpus,int nthreads) { - evsel->fd =xyarray__new (ncpus, nthreads,sizeof (int )); + evsel->core.fd =xyarray__new (ncpus, nthreads,sizeof (int )); -if (evsel->fd) { +if (evsel->core.fd) {int cpu, thread;for (cpu =0 ; cpu < ncpus; cpu++) {for (thread =0 ; thread < nthreads; thread++) {
@@ -1166,7 +1166,7 @@ static int perf_evsel__alloc_fd(struct evsel *evsel, int ncpus, int nthreads) } } -return evsel->fd !=NULL ?0 : -ENOMEM ; +return evsel->core.fd !=NULL ?0 : -ENOMEM ; } static int perf_evsel__run_ioctl(struct evsel *evsel,
@@ -1174,8 +1174,8 @@ static int perf_evsel__run_ioctl(struct evsel *evsel, {int cpu, thread; -for (cpu =0 ; cpu <xyarray__max_x (evsel->fd); cpu++) { -for (thread =0 ; thread <xyarray__max_y (evsel->fd); thread++) { +for (cpu =0 ; cpu <xyarray__max_x (evsel->core.fd); cpu++) { +for (thread =0 ; thread <xyarray__max_y (evsel->core.fd); thread++) {int fd =FD (evsel, cpu, thread), err =ioctl (fd, ioc, arg);
@@ -1283,8 +1283,8 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)static void perf_evsel__free_fd (struct evsel *evsel) { -xyarray__delete (evsel->fd); - evsel->fd =NULL ; +xyarray__delete (evsel->core.fd); + evsel->core.fd =NULL ; }static void perf_evsel__free_id (struct evsel *evsel)
@@ -1309,8 +1309,8 @@ void perf_evsel__close_fd(struct evsel *evsel) {int cpu, thread; -for (cpu =0 ; cpu <xyarray__max_x (evsel->fd); cpu++) -for (thread =0 ; thread <xyarray__max_y (evsel->fd); ++thread) { +for (cpu =0 ; cpu <xyarray__max_x (evsel->core.fd); cpu++) +for (thread =0 ; thread <xyarray__max_y (evsel->core.fd); ++thread) {close (FD (evsel, cpu, thread));FD (evsel, cpu, thread) =-1 ; }
@@ -1555,7 +1555,7 @@ static int get_group_fd(struct evsel *evsel, int cpu, int thread)* Leader must be already processed/open, * if not it's a bug. */ -BUG_ON (!leader->fd); +BUG_ON (!leader->core.fd); fd =FD (leader, cpu, thread);BUG_ON (fd ==-1 );
@@ -1865,7 +1865,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,else nthreads = threads->nr; -if (evsel->fd ==NULL && +if (evsel->core.fd ==NULL &&perf_evsel__alloc_fd (evsel, cpus->nr, nthreads) <0 )return -ENOMEM ;
@@ -2075,7 +2075,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,void perf_evsel__close (struct evsel *evsel) { -if (evsel->fd ==NULL ) +if (evsel->core.fd ==NULL )return ;perf_evsel__close_fd (evsel);
@@ -3048,8 +3048,8 @@ static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist) {int cpu, thread; -for (cpu =0 ; cpu <xyarray__max_x (evsel->fd); cpu++) { -for (thread =0 ; thread <xyarray__max_y (evsel->fd); +for (cpu =0 ; cpu <xyarray__max_x (evsel->core.fd); cpu++) { +for (thread =0 ; thread <xyarray__max_y (evsel->core.fd); thread++) {int fd =FD (evsel, cpu, thread);
tools/perf/util/evsel.h +0 -1
@@ -104,7 +104,6 @@ struct evsel {struct perf_evsel core;struct evlist *evlist;char *filter; -struct xyarray *fd;struct xyarray *sample_id;u64 *id;struct perf_counts *counts;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 86/107 libperf: Move nr_members from perf's evsel to libperf's perf_evsel
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the nr_members member from perf's evsel to libperf's perf_evsel.
--- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/lib/include/internal/evsel.h | 3 +++ tools/perf/tests/parse-events.c | 22 +++++++++++----------- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/ui/gtk/hists.c | 2 +- tools/perf/ui/hist.c | 6 +++--- tools/perf/util/annotate.c | 8 ++++---- tools/perf/util/evlist.c | 6 +++--- tools/perf/util/evsel.c | 6 +++--- tools/perf/util/evsel.h | 3 +-- tools/perf/util/evsel_fprintf.c | 4 ++-- tools/perf/util/header.c | 12 ++++++------ tools/perf/util/hist.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/stat-display.c | 2 +- tools/perf/util/stat.c | 2 +- 18 files changed, 45 insertions(+), 43 deletions(-)
tools/perf/builtin-report.c +1 -1
@@ -436,7 +436,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report ret =fprintf (fp,"# Samples: %lu%c" , nr_samples, unit);if (evname !=NULL ) { ret +=fprintf (fp," of event%s '%s'" , - evsel->nr_members >1 ?"s" :"" , evname); + evsel->core.nr_members >1 ?"s" :"" , evname); }if (rep->time_str)
tools/perf/builtin-script.c +1 -1
@@ -1734,7 +1734,7 @@ static void perf_sample__fprint_metric(struct perf_script *script, sample->cpu, &rt_stat);evsel_script (evsel)->val = val; -if (evsel_script (evsel->leader)->gnum == evsel->leader->nr_members) { +if (evsel_script (evsel->leader)->gnum == evsel->leader->core.nr_members) { for_each_group_member (ev2, evsel->leader) { perf_stat__print_shadow_stats(&stat_config, ev2, evsel_script(ev2)->val,
tools/perf/builtin-stat.c +1 -1
@@ -479,7 +479,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) counter->supported = false;if ((counter->leader != counter) || - !(counter->leader->nr_members >1 )) + !(counter->leader->core.nr_members >1 ))continue ; }else if (perf_evsel__fallback (counter, errno, msg,sizeof (msg))) {if (verbose >0 )
tools/perf/lib/include/internal/evsel.h +3 -0
@@ -15,6 +15,9 @@ struct perf_evsel {struct perf_cpu_map *own_cpus;struct perf_thread_map *threads;struct xyarray *fd; + +/* parse modifier helper */ + int nr_members; };#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/tests/parse-events.c +11 -11
@@ -653,7 +653,7 @@ static int test__group1(struct evlist *evlist)TEST_ASSERT_VAL ("wrong exclude host" , !evsel->core.attr.exclude_host);TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -695,7 +695,7 @@ static int test__group2(struct evlist *evlist)TEST_ASSERT_VAL ("wrong exclude host" , !evsel->core.attr.exclude_host);TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -753,7 +753,7 @@ static int test__group3(struct evlist *evlist __maybe_unused)TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel));TEST_ASSERT_VAL ("wrong group name" , !strcmp (leader->group_name,"group1" )); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -788,7 +788,7 @@ static int test__group3(struct evlist *evlist __maybe_unused)TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel));TEST_ASSERT_VAL ("wrong group name" , !strcmp (leader->group_name,"group2" )); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -844,7 +844,7 @@ static int test__group4(struct evlist *evlist __maybe_unused)TEST_ASSERT_VAL ("wrong precise_ip" , evsel->core.attr.precise_ip ==1 );TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -887,7 +887,7 @@ static int test__group5(struct evlist *evlist __maybe_unused)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -919,7 +919,7 @@ static int test__group5(struct evlist *evlist __maybe_unused)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );TEST_ASSERT_VAL ("wrong sample_read" , !evsel->sample_read);
@@ -973,7 +973,7 @@ static int test__group_gh1(struct evlist *evlist)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );/* cache-misses:G + :H group modifier */
@@ -1013,7 +1013,7 @@ static int test__group_gh2(struct evlist *evlist)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );/* cache-misses:H + :G group modifier */
@@ -1053,7 +1053,7 @@ static int test__group_gh3(struct evlist *evlist)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );/* cache-misses:H + :u group modifier */
@@ -1093,7 +1093,7 @@ static int test__group_gh4(struct evlist *evlist)TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->core.attr.precise_ip);TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name);TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); -TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong core.nr_members" , evsel->core.nr_members ==2 );TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 );/* cache-misses:H + :uG group modifier */
tools/perf/ui/gtk/annotate.c +1 -1
@@ -129,7 +129,7 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,gtk_list_store_append (store, &iter);if (perf_evsel__is_group_event (evsel)) { -for (i =0 ; i < evsel->nr_members; i++) { +for (i =0 ; i < evsel->core.nr_members; i++) { ret += perf_gtk__get_percent(s + ret, sizeof(s) - ret, sym, pos,
tools/perf/ui/gtk/hists.c +1 -1
@@ -645,7 +645,7 @@ int perf_evlist__gtk_browse_hists(struct evlist *evlist,if (!perf_evsel__is_group_leader (pos))continue ; -if (pos->nr_members >1 ) { +if (pos->core.nr_members >1 ) {perf_evsel__group_desc (pos, buf, size); evname = buf; }
tools/perf/ui/hist.c +3 -3
@@ -43,7 +43,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,if (perf_evsel__is_group_event (evsel)) {int prev_idx, idx_delta;struct hist_entry *pair; -int nr_members = evsel->nr_members; +int nr_members = evsel->core.nr_members; prev_idx =perf_evsel__group_idx (evsel);
@@ -165,7 +165,7 @@ static int __hpp__sort(struct hist_entry *a, struct hist_entry *b,if (!perf_evsel__is_group_event (evsel))return ret; - nr_members = evsel->nr_members; + nr_members = evsel->core.nr_members; fields_a =calloc (nr_members,sizeof (*fields_a)); fields_b =calloc (nr_members,sizeof (*fields_b));
@@ -226,7 +226,7 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt,struct evsel *evsel =hists_to_evsel (hists);if (symbol_conf.event_group) - len =max (len, evsel->nr_members * fmt->len); + len =max (len, evsel->core.nr_members * fmt->len);if (len < (int )strlen (fmt->name)) len =strlen (fmt->name);
tools/perf/util/annotate.c +4 -4
@@ -1170,7 +1170,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)int nr =1 ;if (perf_evsel__is_group_event (evsel)) - nr = evsel->nr_members; + nr = evsel->core.nr_members; size +=sizeof (al->data[0 ]) * nr;
@@ -1448,7 +1448,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 startreturn -1 ;if (perf_evsel__is_group_event (evsel)) - width *= evsel->nr_members; + width *= evsel->core.nr_members;if (!*al->line)printf (" %*s:\n" , width," " );
@@ -2272,7 +2272,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, len =symbol__size (sym);if (perf_evsel__is_group_event (evsel)) { - width *= evsel->nr_members; + width *= evsel->core.nr_members;perf_evsel__group_desc (evsel, buf,sizeof (buf)); evsel_name = buf; }
@@ -2968,7 +2968,7 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct evsel *evsel,return -1 ;if (perf_evsel__is_group_event (evsel)) - nr_pcnt = evsel->nr_members; + nr_pcnt = evsel->core.nr_members; err =symbol__annotate (sym, map, evsel,0 , options, parch);if (err)
tools/perf/util/evlist.c +3 -3
@@ -188,7 +188,7 @@ void __perf_evlist__set_leader(struct list_head *list) leader = list_entry(list->next, struct evsel, core.node); evsel = list_entry(list->prev, struct evsel, core.node); - leader->nr_members = evsel->idx - leader->idx +1 ; + leader->core.nr_members = evsel->idx - leader->idx +1 ;__evlist__for_each_entry (list, evsel) { evsel->leader = leader;
@@ -1761,7 +1761,7 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, leader = evsel->leader;pr_debug ("Weak group for %s/%d failed\n" , - leader->name, leader->nr_members); + leader->name, leader->core.nr_members);/* * for_each_group_member doesn't work here because it doesn't
@@ -1774,7 +1774,7 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,if (is_open)perf_evsel__close (c2); c2->leader = c2; - c2->nr_members =0 ; + c2->core.nr_members =0 ; } }return leader;
tools/perf/util/evsel.c +3 -3
@@ -948,7 +948,7 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,* Apply group format only if we belong to group * with more than one members. */ -if (leader->nr_members >1 ) { +if (leader->core.nr_members >1 ) { attr->read_format |=PERF_FORMAT_GROUP ; attr->inherit =0 ; }
@@ -1396,7 +1396,7 @@ static int perf_evsel__read_size(struct evsel *evsel) entry +=sizeof (u64);if (read_format &PERF_FORMAT_GROUP ) { - nr = evsel->nr_members; + nr = evsel->core.nr_members; size +=sizeof (u64); }
@@ -1453,7 +1453,7 @@ perf_evsel__process_group_data(struct evsel *leader, nr = *data++; -if (nr != (u64 ) leader->nr_members) +if (nr != (u64 ) leader->core.nr_members)return -EINVAL ;if (read_format &PERF_FORMAT_TOTAL_TIME_ENABLED )
tools/perf/util/evsel.h +1 -2
@@ -142,7 +142,6 @@ struct evsel {bool use_uncore_alias;/* parse modifier helper */ int exclude_GH; -int nr_members;int sample_read;unsigned long *per_pkg_mask;struct evsel *leader;
@@ -414,7 +413,7 @@ static inline bool perf_evsel__is_group_event(struct evsel *evsel)if (!symbol_conf.event_group)return false; -return perf_evsel__is_group_leader (evsel) && evsel->nr_members >1 ; +return perf_evsel__is_group_leader (evsel) && evsel->core.nr_members >1 ; }bool perf_evsel__is_function_event (struct evsel *evsel);
tools/perf/util/evsel_fprintf.c +2 -2
@@ -45,14 +45,14 @@ int perf_evsel__fprintf(struct evsel *evsel,if (!perf_evsel__is_group_leader (evsel))return 0 ; -if (evsel->nr_members >1 ) +if (evsel->core.nr_members >1 ) printed +=fprintf (fp,"%s{" , evsel->group_name ?:"" ); printed +=fprintf (fp,"%s" ,perf_evsel__name (evsel));for_each_group_member (pos, evsel) printed +=fprintf (fp,",%s" ,perf_evsel__name (pos)); -if (evsel->nr_members >1 ) +if (evsel->core.nr_members >1 ) printed +=fprintf (fp,"}" ); goto out; }
tools/perf/util/header.c +6 -6
@@ -772,10 +772,10 @@ static int write_group_desc(struct feat_fd *ff,evlist__for_each_entry (evlist, evsel) {if (perf_evsel__is_group_leader (evsel) && - evsel->nr_members >1 ) { + evsel->core.nr_members >1 ) {const char *name = evsel->group_name ?:"{anon_group}" ;u32 leader_idx = evsel->idx; -u32 nr_members = evsel->nr_members; +u32 nr_members = evsel->core.nr_members; ret =do_write_string (ff, name);if (ret <0 )
@@ -1812,11 +1812,11 @@ static void print_group_desc(struct feat_fd *ff, FILE *fp)evlist__for_each_entry (session->evlist, evsel) {if (perf_evsel__is_group_leader (evsel) && - evsel->nr_members >1 ) { + evsel->core.nr_members >1 ) {fprintf (fp,"# group: %s{%s" , evsel->group_name ?:"" ,perf_evsel__name (evsel)); - nr = evsel->nr_members -1 ; + nr = evsel->core.nr_members -1 ; }else if (nr) {fprintf (fp,",%s" ,perf_evsel__name (evsel));
@@ -2463,7 +2463,7 @@ static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused) evsel->group_name = desc[i].name; desc[i].name =NULL ; } - evsel->nr_members = desc[i].nr_members; + evsel->core.nr_members = desc[i].nr_members;if (i >= nr_groups || nr >0 ) {pr_debug ("invalid group desc\n" );
@@ -2471,7 +2471,7 @@ static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused) } leader = evsel; - nr = evsel->nr_members -1 ; + nr = evsel->core.nr_members -1 ; i++; }else if (nr) {/* This is a group member */
tools/perf/util/hist.c +1 -1
@@ -2643,7 +2643,7 @@ int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool sh nr_samples =convert_unit (nr_samples, &unit); printed =scnprintf (bf, size,"Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64, - nr_samples, unit, evsel->nr_members >1 ?"s" :"" , + nr_samples, unit, evsel->core.nr_members >1 ?"s" :"" , ev_name, sample_freq_str, enable_ref ? ref :" " , nr_events);
tools/perf/util/parse-events.c +1 -1
@@ -1528,7 +1528,7 @@ parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list,/* The number of members and group name are same for each group */ for (i =0 ; i < nr_pmu; i++) { evsel = (struct evsel *) leaders[i]; - evsel->nr_members = total_members / nr_pmu; + evsel->core.nr_members = total_members / nr_pmu; evsel->group_name = name ?strdup (name) :NULL ; }
tools/perf/util/stat-display.c +1 -1
@@ -369,7 +369,7 @@ static bool is_mixed_hw_group(struct evsel *counter)u32 pmu_type = counter->core.attr.type;struct evsel *pos; -if (counter->nr_members <2 ) +if (counter->core.nr_members <2 )return false;evlist__for_each_entry (evlist, pos) {
tools/perf/util/stat.c +1 -1
@@ -452,7 +452,7 @@ int create_perf_stat_counter(struct evsel *evsel,* the group read (for leader) and ID retrieval for all * members. */ -if (leader->nr_members >1 ) +if (leader->core.nr_members >1 ) attr->read_format |=PERF_FORMAT_ID |PERF_FORMAT_GROUP ; attr->inherit = !config->no_inherit;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 87/107 libperf: Adopt the readn()/writen() functions from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the readn()/writen() functions into libperf.
Keep those non-namespaced names because they will be shared only between perf and libperf.
Again, these are not exported functions.
--- tools/perf/lib/Build | 1 + tools/perf/lib/include/internal/lib.h | 10 ++++++ tools/perf/lib/lib.c | 46 +++++++++++++++++++++++++++ tools/perf/util/util.c | 40 ----------------------- tools/perf/util/util.h | 4 +-- 5 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 tools/perf/lib/include/internal/lib.h create mode 100644 tools/perf/lib/lib.c
tools/perf/lib/Build +1 -0
@@ -5,6 +5,7 @@ libperf-y += evsel.o libperf-y += evlist.o libperf-y += zalloc.o libperf-y += xyarray.o +libperf-y += lib.o $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE $(call rule_mkdir)
tools/perf/lib/include/internal/lib.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_LIB_H +#define __LIBPERF_INTERNAL_LIB_H + +#include <unistd.h> + +ssize_t readn (int fd,void *buf,size_t n); +ssize_t writen (int fd,const void *buf,size_t n); + +#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
tools/perf/lib/lib.c new file +46 -0
46 lines not on this page · raw message
tools/perf/util/util.c +0 -40
@@ -384,46 +384,6 @@ int copyfile(const char *from, const char *to)return copyfile_mode (from, to,0755 ); } -static ssize_t ion (bool is_read,int fd,void *buf,size_t n) -{ -void *buf_start = buf; -size_t left = n; - -while (left) { -/* buf must be treated as const if !is_read. */ -ssize_t ret = is_read ?read (fd, buf, left) : -write (fd, buf, left); - -if (ret <0 && errno ==EINTR ) -continue ; -if (ret <=0 ) -return ret; - - left -= ret; - buf += ret; - } - -BUG_ON ((size_t )(buf - buf_start) != n); -return n; -} - -/* -* Read exactly 'n' bytes or return an error. -*/ -ssize_t readn (int fd,void *buf,size_t n) -{ -return ion (true, fd, buf, n); -} - -/* -* Write exactly 'n' bytes or return an error. -*/ -ssize_t writen (int fd,const void *buf,size_t n) -{ -/* ion does not modify buf. */ -return ion (false, fd, (void *)buf, n); -} -size_t hex_width (u64 v) {size_t n =1 ;
tools/perf/util/util.h +1 -3
@@ -11,6 +11,7 @@#include <stddef.h> #include <linux/compiler.h> #include <sys/types.h> +#include <internal/lib.h> /* General helper functions */ void usage (const char *err)__noreturn ;
@@ -30,9 +31,6 @@ int copyfile_mode(const char *from, const char *to, mode_t mode);int copyfile_ns (const char *from,const char *to,struct nsinfo *nsi);int copyfile_offset (int ifd,loff_t off_in,int ofd,loff_t off_out,u64 size); -ssize_t readn (int fd,void *buf,size_t n); -ssize_t writen (int fd,const void *buf,size_t n); -size_t hex_width (u64 v);extern unsigned int page_size;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 88/107 libperf: Adopt perf_evsel__alloc_fd() function from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the perf_evsel__alloc_fd() function from perf to libperf.
It's not exported.
--- tools/perf/lib/evsel.c | 21 +++++++++++++++++++++ tools/perf/lib/include/internal/evsel.h | 2 ++ tools/perf/util/evsel.c | 18 +----------------- 3 files changed, 24 insertions(+), 17 deletions(-)
tools/perf/lib/evsel.c +21 -0
@@ -1,9 +1,12 @@// SPDX-License-Identifier: GPL-2.0 +#include <errno.h> #include <perf/evsel.h> #include <linux/list.h> #include <internal/evsel.h> #include <linux/zalloc.h> #include <stdlib.h> +#include <internal/xyarray.h> +#include <linux/string.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr) {
@@ -25,3 +28,21 @@ void perf_evsel__delete(struct perf_evsel *evsel) {free (evsel); } + +#define FD (e, x, y) (*(int *) xyarray__entry(e->fd, x, y)) + +int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads) +{ + evsel->fd =xyarray__new (ncpus, nthreads,sizeof (int )); + +if (evsel->fd) { +int cpu, thread; +for (cpu =0 ; cpu < ncpus; cpu++) { +for (thread =0 ; thread < nthreads; thread++) { +FD (evsel, cpu, thread) =-1 ; + } + } + } + +return evsel->fd !=NULL ?0 : -ENOMEM ; +}
tools/perf/lib/include/internal/evsel.h +2 -0
@@ -20,4 +20,6 @@ struct perf_evsel { int nr_members; }; +int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads); +#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/util/evsel.c +1 -17
@@ -1153,22 +1153,6 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,perf_evsel__reset_sample_bit (evsel,BRANCH_STACK ); } -static int perf_evsel__alloc_fd (struct evsel *evsel,int ncpus,int nthreads) -{ - evsel->core.fd =xyarray__new (ncpus, nthreads,sizeof (int )); - -if (evsel->core.fd) { -int cpu, thread; -for (cpu =0 ; cpu < ncpus; cpu++) { -for (thread =0 ; thread < nthreads; thread++) { -FD (evsel, cpu, thread) =-1 ; - } - } - } - -return evsel->core.fd !=NULL ?0 : -ENOMEM ; -} -static int perf_evsel__run_ioctl (struct evsel *evsel,int ioc,void *arg) {
@@ -1866,7 +1850,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, nthreads = threads->nr;if (evsel->core.fd ==NULL && -perf_evsel__alloc_fd (evsel, cpus->nr, nthreads) <0 ) +perf_evsel__alloc_fd (&evsel->core, cpus->nr, nthreads) <0 )return -ENOMEM ;if (evsel->cgrp) {
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 89/107 libperf: Adopt simplified perf_evsel__open() function from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add a perf_evsel__open() function to libperf.
It's a simplified version of evsel__open() without the fallback mechanism.
We can try to merge it in the future to libperf, but it has many details, lets start simple, requiring the latest kernel, perf should continue using its evsel__open() version, continuing to support running on older kernels when possible.
--- tools/perf/lib/evsel.c | 65 +++++++++++++++++++++++++++++ tools/perf/lib/include/perf/evsel.h | 4 ++ tools/perf/lib/libperf.map | 1 + 3 files changed, 70 insertions(+)
tools/perf/lib/evsel.c +65 -0
@@ -1,11 +1,17 @@// SPDX-License-Identifier: GPL-2.0 #include <errno.h> +#include <unistd.h> +#include <sys/syscall.h> #include <perf/evsel.h> +#include <perf/cpumap.h> +#include <perf/threadmap.h> #include <linux/list.h> #include <internal/evsel.h> #include <linux/zalloc.h> #include <stdlib.h> #include <internal/xyarray.h> +#include <internal/cpumap.h> +#include <internal/threadmap.h> #include <linux/string.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr)
@@ -46,3 +52,62 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)return evsel->fd !=NULL ?0 : -ENOMEM ; } + +static int +sys_perf_event_open (struct perf_event_attr *attr, +pid_t pid,int cpu,int group_fd, +unsigned long flags) +{ +return syscall (__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +} + +int perf_evsel__open (struct perf_evsel *evsel,struct perf_cpu_map *cpus, +struct perf_thread_map *threads) +{ +int cpu, thread, err =0 ; + +if (cpus ==NULL ) { +static struct perf_cpu_map *empty_cpu_map; + +if (empty_cpu_map ==NULL ) { + empty_cpu_map =perf_cpu_map__dummy_new (); +if (empty_cpu_map ==NULL ) +return -ENOMEM ; + } + + cpus = empty_cpu_map; + } + +if (threads ==NULL ) { +static struct perf_thread_map *empty_thread_map; + +if (empty_thread_map ==NULL ) { + empty_thread_map =perf_thread_map__new_dummy (); +if (empty_thread_map ==NULL ) +return -ENOMEM ; + } + + threads = empty_thread_map; + } + +if (evsel->fd ==NULL && +perf_evsel__alloc_fd (evsel, cpus->nr, threads->nr) <0 ) +return -ENOMEM ; + +for (cpu =0 ; cpu < cpus->nr; cpu++) { +for (thread =0 ; thread < threads->nr; thread++) { +int fd; + + fd =sys_perf_event_open (&evsel->attr, + threads->map[thread].pid, + cpus->map[cpu],-1 ,0 ); + +if (fd <0 ) +return -errno; + +FD (evsel, cpu, thread) = fd; + } + } + +return err; +}
tools/perf/lib/include/perf/evsel.h +4 -0
@@ -6,10 +6,14 @@struct perf_evsel ;struct perf_event_attr ; +struct perf_cpu_map ; +struct perf_thread_map ; LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,struct perf_event_attr *attr); LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr); LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, +struct perf_thread_map *threads);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -14,6 +14,7 @@ LIBPERF_0.0.1 { perf_evsel__new; perf_evsel__delete; perf_evsel__init; + perf_evsel__open; perf_evlist__new; perf_evlist__delete; perf_evlist__init;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 90/107 libperf: Adopt simplified perf_evsel__close() function from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add perf_evsel__close() function to libperf while keeping a tools/perf specific evsel__close() to free ids.
--- tools/perf/builtin-trace.c | 2 +- tools/perf/lib/evsel.c | 26 +++++++++++++++++++++ tools/perf/lib/include/internal/evsel.h | 2 ++ tools/perf/lib/include/perf/evsel.h | 1 + tools/perf/lib/libperf.map | 1 + tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/openat-syscall.c | 2 +- tools/perf/util/evlist.c | 5 ++-- tools/perf/util/evsel.c | 27 +++------------------- tools/perf/util/evsel.h | 3 +-- 10 files changed, 40 insertions(+), 31 deletions(-)
tools/perf/builtin-trace.c +1 -1
@@ -2401,7 +2401,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel->max_events !=ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) {evsel__disable (evsel); -perf_evsel__close (evsel); +evsel__close (evsel); } } }
tools/perf/lib/evsel.c +26 -0
@@ -111,3 +111,29 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,return err; } + +void perf_evsel__close_fd (struct perf_evsel *evsel) +{ +int cpu, thread; + +for (cpu =0 ; cpu <xyarray__max_x (evsel->fd); cpu++) +for (thread =0 ; thread <xyarray__max_y (evsel->fd); ++thread) { +close (FD (evsel, cpu, thread)); +FD (evsel, cpu, thread) =-1 ; + } +} + +void perf_evsel__free_fd (struct perf_evsel *evsel) +{ +xyarray__delete (evsel->fd); + evsel->fd =NULL ; +} + +void perf_evsel__close (struct perf_evsel *evsel) +{ +if (evsel->fd ==NULL ) +return ; + +perf_evsel__close_fd (evsel); +perf_evsel__free_fd (evsel); +}
tools/perf/lib/include/internal/evsel.h +2 -0
@@ -21,5 +21,7 @@ struct perf_evsel { };int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads); +void perf_evsel__close_fd (struct perf_evsel *evsel); +void perf_evsel__free_fd (struct perf_evsel *evsel);#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/lib/include/perf/evsel.h +1 -0
@@ -15,5 +15,6 @@ LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr); LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,struct perf_thread_map *threads); +LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -15,6 +15,7 @@ LIBPERF_0.0.1 { perf_evsel__delete; perf_evsel__init; perf_evsel__open; + perf_evsel__close; perf_evlist__new; perf_evlist__delete; perf_evlist__init;
tools/perf/tests/openat-syscall-all-cpus.c +1 -1
@@ -116,7 +116,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, intperf_evsel__free_counts (evsel); out_close_fd: -perf_evsel__close_fd (evsel); +perf_evsel__close_fd (&evsel->core); out_evsel_delete:evsel__delete (evsel); out_cpu_map_delete:
tools/perf/tests/openat-syscall.c +1 -1
@@ -57,7 +57,7 @@ int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __m err =0 ; out_close_fd: -perf_evsel__close_fd (evsel); +perf_evsel__close_fd (&evsel->core); out_evsel_delete:evsel__delete (evsel); out_thread_map_delete:
tools/perf/util/evlist.c +3 -2
@@ -34,6 +34,7 @@#include <linux/err.h> #include <linux/zalloc.h> #include <perf/evlist.h> +#include <perf/evsel.h> #include <perf/cpumap.h> #ifdef LACKS_SIGQUEUE_PROTOTYPE
@@ -1303,7 +1304,7 @@ void evlist__close(struct evlist *evlist)struct evsel *evsel;evlist__for_each_entry_reverse (evlist, evsel) -perf_evsel__close (evsel); +evsel__close (evsel); }static int perf_evlist__create_syswide_maps (struct evlist *evlist)
@@ -1772,7 +1773,7 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, is_open = false;if (c2->leader == leader) {if (is_open) -perf_evsel__close (c2); +evsel__close (c2); c2->leader = c2; c2->core.nr_members =0 ; }
tools/perf/util/evsel.c +3 -24
@@ -1265,12 +1265,6 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)return 0 ; } -static void perf_evsel__free_fd (struct evsel *evsel) -{ -xyarray__delete (evsel->core.fd); - evsel->core.fd =NULL ; -} -static void perf_evsel__free_id (struct evsel *evsel) {xyarray__delete (evsel->sample_id);
@@ -1289,23 +1283,12 @@ static void perf_evsel__free_config_terms(struct evsel *evsel) } } -void perf_evsel__close_fd (struct evsel *evsel) -{ -int cpu, thread; - -for (cpu =0 ; cpu <xyarray__max_x (evsel->core.fd); cpu++) -for (thread =0 ; thread <xyarray__max_y (evsel->core.fd); ++thread) { -close (FD (evsel, cpu, thread)); -FD (evsel, cpu, thread) =-1 ; - } -} -void perf_evsel__exit (struct evsel *evsel) {assert (list_empty (&evsel->core.node));assert (evsel->evlist ==NULL );perf_evsel__free_counts (evsel); -perf_evsel__free_fd (evsel); +perf_evsel__free_fd (&evsel->core);perf_evsel__free_id (evsel);perf_evsel__free_config_terms (evsel);cgroup__put (evsel->cgrp);
@@ -2057,13 +2040,9 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,return err; } -void perf_evsel__close (struct evsel *evsel) +void evsel__close (struct evsel *evsel) { -if (evsel->core.fd ==NULL ) -return ; - -perf_evsel__close_fd (evsel); -perf_evsel__free_fd (evsel); +perf_evsel__close (&evsel->core);perf_evsel__free_id (evsel); }
tools/perf/util/evsel.h +1 -2
@@ -268,7 +268,6 @@ const char *perf_evsel__group_name(struct evsel *evsel);int perf_evsel__group_desc (struct evsel *evsel,char *buf,size_t size);int perf_evsel__alloc_id (struct evsel *evsel,int ncpus,int nthreads); -void perf_evsel__close_fd (struct evsel *evsel);void __perf_evsel__set_sample_bit (struct evsel *evsel,enum perf_event_sample_format bit);
@@ -298,7 +297,7 @@ int perf_evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);int evsel__open (struct evsel *evsel,struct perf_cpu_map *cpus,struct perf_thread_map *threads); -void perf_evsel__close (struct evsel *evsel); +void evsel__close (struct evsel *evsel);struct perf_sample ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 91/107 libperf: Adopt perf_evsel__read() function from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the perf_evsel__read() function to libperf as a public interface together with struct perf_counts_values for returning counter values.
--- tools/perf/lib/evsel.c | 42 +++++++++++++++++++++++ tools/perf/lib/include/internal/evsel.h | 1 + tools/perf/lib/include/perf/evsel.h | 14 ++++++++ tools/perf/lib/libperf.map | 1 + tools/perf/tests/event-times.c | 2 +- tools/perf/util/counts.h | 12 +------ tools/perf/util/evsel.c | 45 ++----------------------- tools/perf/util/evsel.h | 3 -- 8 files changed, 62 insertions(+), 58 deletions(-)
tools/perf/lib/evsel.c +42 -0
@@ -12,6 +12,7 @@#include <internal/xyarray.h> #include <internal/cpumap.h> #include <internal/threadmap.h> +#include <internal/lib.h> #include <linux/string.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr)
@@ -137,3 +138,44 @@ void perf_evsel__close(struct perf_evsel *evsel)perf_evsel__close_fd (evsel);perf_evsel__free_fd (evsel); } + +int perf_evsel__read_size (struct perf_evsel *evsel) +{ +u64 read_format = evsel->attr.read_format; +int entry =sizeof (u64);/* value */ +int size =0 ; +int nr =1 ; + +if (read_format &PERF_FORMAT_TOTAL_TIME_ENABLED ) + size +=sizeof (u64); + +if (read_format &PERF_FORMAT_TOTAL_TIME_RUNNING ) + size +=sizeof (u64); + +if (read_format &PERF_FORMAT_ID ) + entry +=sizeof (u64); + +if (read_format &PERF_FORMAT_GROUP ) { + nr = evsel->nr_members; + size +=sizeof (u64); + } + + size += entry * nr; +return size; +} + +int perf_evsel__read (struct perf_evsel *evsel,int cpu,int thread, +struct perf_counts_values *count) +{ +size_t size =perf_evsel__read_size (evsel); + +memset (count,0 ,sizeof (*count)); + +if (FD (evsel, cpu, thread) <0 ) +return -EINVAL ; + +if (readn (FD (evsel, cpu, thread), count->values, size) <=0 ) +return -errno; + +return 0 ; +}
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -23,5 +23,6 @@ struct perf_evsel {int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads);void perf_evsel__close_fd (struct perf_evsel *evsel);void perf_evsel__free_fd (struct perf_evsel *evsel); +int perf_evsel__read_size (struct perf_evsel *evsel);#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/lib/include/perf/evsel.h +14 -0
@@ -2,6 +2,7 @@#ifndef __LIBPERF_EVSEL_H#define __LIBPERF_EVSEL_H +#include <stdint.h> #include <perf/core.h> struct perf_evsel ;
@@ -9,6 +10,17 @@ struct perf_event_attr;struct perf_cpu_map ;struct perf_thread_map ; +struct perf_counts_values { +union { +struct { +uint64_t val; +uint64_t ena; +uint64_t run; + }; +uint64_t values[3 ]; + }; +}; + LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,struct perf_event_attr *attr); LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
@@ -16,5 +28,7 @@ LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,struct perf_thread_map *threads); LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, +struct perf_counts_values *count);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -16,6 +16,7 @@ LIBPERF_0.0.1 { perf_evsel__init; perf_evsel__open; perf_evsel__close; + perf_evsel__read; perf_evlist__new; perf_evlist__delete; perf_evlist__init;
tools/perf/tests/event-times.c +1 -1
@@ -196,7 +196,7 @@ static int test_times(int (attach)(struct evlist *),TEST_ASSERT_VAL ("failed to detach" , !detach (evlist)); -perf_evsel__read (evsel,0 ,0 , &count); +perf_evsel__read (&evsel->core,0 ,0 , &count); err = !(count.ena == count.run);
tools/perf/util/counts.h +1 -11
@@ -3,17 +3,7 @@#define __PERF_COUNTS_H#include <internal/xyarray.h> - -struct perf_counts_values { -union { -struct { -u64 val; -u64 ena; -u64 run; - }; -u64 values[3 ]; - }; -}; +#include <perf/evsel.h> struct perf_counts {s8 scaled;
tools/perf/util/evsel.c +2 -43
62 lines not on this page · raw message
tools/perf/util/evsel.h +0 -3
@@ -336,9 +336,6 @@ static inline bool perf_evsel__match2(struct evsel *e1, (a)->core.attr.type == (b)->core.attr.type && \ (a)->core.attr.config == (b)->core.attr.config) -int perf_evsel__read (struct evsel *evsel,int cpu,int thread, -struct perf_counts_values *count); -int perf_evsel__read_counter (struct evsel *evsel,int cpu,int thread); int __perf_evsel__read_on_cpu(struct evsel *evsel,
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 92/107 libperf: Adopt perf_evsel__enable()/disable()/apply_filter() functions
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Move the following functions:
evsel__enable()
evsel__disable()
evsel__apply_filter()
to libperf with the following names:
perf_evsel__enable()
perf_evsel__disable()
perf_evsel__apply_filter()
Export only perf_evsel__enable()/disable(), keeping the perf_evsel__apply_filter() one private for the moment.
--- tools/perf/lib/evsel.c | 36 +++++++++++++++++++++++++ tools/perf/lib/include/internal/evsel.h | 1 + tools/perf/lib/include/perf/evsel.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 29 ++------------------ tools/perf/util/evsel.h | 1 - 7 files changed, 44 insertions(+), 29 deletions(-)
tools/perf/lib/evsel.c +36 -0
@@ -14,6 +14,7 @@#include <internal/threadmap.h> #include <internal/lib.h> #include <linux/string.h> +#include <sys/ioctl.h> void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr) {
@@ -179,3 +180,38 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,return 0 ; } + +static int perf_evsel__run_ioctl (struct perf_evsel *evsel, +int ioc,void *arg) +{ +int cpu, thread; + +for (cpu =0 ; cpu <xyarray__max_x (evsel->fd); cpu++) { +for (thread =0 ; thread <xyarray__max_y (evsel->fd); thread++) { +int fd =FD (evsel, cpu, thread), + err =ioctl (fd, ioc, arg); + +if (err) +return err; + } + } + +return 0 ; +} + +int perf_evsel__enable (struct perf_evsel *evsel) +{ +return perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_ENABLE ,0 ); +} + +int perf_evsel__disable (struct perf_evsel *evsel) +{ +return perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_DISABLE ,0 ); +} + +int perf_evsel__apply_filter (struct perf_evsel *evsel,const char *filter) +{ +return perf_evsel__run_ioctl (evsel, +PERF_EVENT_IOC_SET_FILTER , + (void *)filter); +}
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -24,5 +24,6 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);void perf_evsel__close_fd (struct perf_evsel *evsel);void perf_evsel__free_fd (struct perf_evsel *evsel);int perf_evsel__read_size (struct perf_evsel *evsel); +int perf_evsel__apply_filter (struct perf_evsel *evsel,const char *filter);#endif /* __LIBPERF_INTERNAL_EVSEL_H */
tools/perf/lib/include/perf/evsel.h +2 -0
@@ -30,5 +30,7 @@ LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map * LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,struct perf_counts_values *count); +LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +2 -0
@@ -13,6 +13,8 @@ LIBPERF_0.0.1 { perf_thread_map__put; perf_evsel__new; perf_evsel__delete; + perf_evsel__enable; + perf_evsel__disable; perf_evsel__init; perf_evsel__open; perf_evsel__close;
tools/perf/util/evlist.c +1 -1
@@ -1109,7 +1109,7 @@ int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel)* filters only work for tracepoint event, which doesn't have cpu limit. * So evlist and evsel should always be same. */ - err =evsel__apply_filter (evsel, evsel->filter); + err =perf_evsel__apply_filter (&evsel->core, evsel->filter);if (err) { *err_evsel = evsel;break ;
tools/perf/util/evsel.c +2 -27
@@ -1153,31 +1153,6 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,perf_evsel__reset_sample_bit (evsel,BRANCH_STACK ); } -static int perf_evsel__run_ioctl (struct evsel *evsel, -int ioc,void *arg) -{ -int cpu, thread; - -for (cpu =0 ; cpu <xyarray__max_x (evsel->core.fd); cpu++) { -for (thread =0 ; thread <xyarray__max_y (evsel->core.fd); thread++) { -int fd =FD (evsel, cpu, thread), - err =ioctl (fd, ioc, arg); - -if (err) -return err; - } - } - -return 0 ; -} - -int evsel__apply_filter (struct evsel *evsel,const char *filter) -{ -return perf_evsel__run_ioctl (evsel, -PERF_EVENT_IOC_SET_FILTER , - (void *)filter); -} -int perf_evsel__set_filter (struct evsel *evsel,const char *filter) {char *new_filter =strdup (filter);
@@ -1220,7 +1195,7 @@ int perf_evsel__append_addr_filter(struct evsel *evsel, const char *filter)int evsel__enable (struct evsel *evsel) { -int err =perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_ENABLE ,0 ); +int err =perf_evsel__enable (&evsel->core);if (!err) evsel->disabled = false;
@@ -1230,7 +1205,7 @@ int evsel__enable(struct evsel *evsel)int evsel__disable (struct evsel *evsel) { -int err =perf_evsel__run_ioctl (evsel,PERF_EVENT_IOC_DISABLE ,0 ); +int err =perf_evsel__disable (&evsel->core);/* * We mark it disabled here so that tools that disable a event can * ignore events after they disable it. I.e. the ring buffer may have
tools/perf/util/evsel.h +0 -1
@@ -287,7 +287,6 @@ int perf_evsel__set_filter(struct evsel *evsel, const char *filter);int perf_evsel__append_tp_filter (struct evsel *evsel,const char *filter);int perf_evsel__append_addr_filter (struct evsel *evsel,const char *filter); -int evsel__apply_filter (struct evsel *evsel,const char *filter);int evsel__enable (struct evsel *evsel);int evsel__disable (struct evsel *evsel);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 93/107 libperf: Add perf_cpu_map__for_each_cpu() macro
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the following macro to libperf:
perf_cpu_map__for_each_cpu()
And its related functions:
perf_cpu_map__cpu()
perf_cpu_map__nr()
That will allow hiding how it is implemented.
--- tools/perf/lib/cpumap.c | 13 +++++++++++++ tools/perf/lib/include/perf/cpumap.h | 7 +++++++ tools/perf/lib/libperf.map | 2 ++ 3 files changed, 22 insertions(+)
tools/perf/lib/cpumap.c +13 -0
@@ -224,3 +224,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) out:return cpus; } + +int perf_cpu_map__cpu (const struct perf_cpu_map *cpus,int idx) +{ +if (idx < cpus->nr) +return cpus->map[idx]; + +return -1 ; +} + +int perf_cpu_map__nr (const struct perf_cpu_map *cpus) +{ +return cpus ? cpus->nr :1 ; +}
tools/perf/lib/include/perf/cpumap.h +7 -0
@@ -12,5 +12,12 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); +LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); +LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); + +#define perf_cpu_map__for_each_cpu (cpu, idx, cpus) \ + for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ + (idx) < perf_cpu_map__nr(cpus); \ + (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))#endif /* __LIBPERF_CPUMAP_H */
tools/perf/lib/libperf.map +2 -0
@@ -6,6 +6,8 @@ LIBPERF_0.0.1 { perf_cpu_map__put; perf_cpu_map__new; perf_cpu_map__read; + perf_cpu_map__nr; + perf_cpu_map__cpu; perf_thread_map__new_dummy; perf_thread_map__set_pid; perf_thread_map__comm;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 94/107 libperf: Add perf_evsel__cpus()/threads() functions
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the following functions:
perf_evsel__cpus()
perf_evsel__threads()
to access the evsel's cpus and threads objects.
--- tools/perf/lib/evsel.c | 10 ++++++++++ tools/perf/lib/include/perf/evsel.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ tools/perf/util/evsel.h | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-)
tools/perf/lib/evsel.c +10 -0
@@ -215,3 +215,13 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)PERF_EVENT_IOC_SET_FILTER , (void *)filter); } + +struct perf_cpu_map *perf_evsel__cpus (struct perf_evsel *evsel) +{ +return evsel->cpus; +} + +struct perf_thread_map *perf_evsel__threads (struct perf_evsel *evsel) +{ +return evsel->threads; +}
tools/perf/lib/include/perf/evsel.h +2 -0
@@ -32,5 +32,7 @@ LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, struct perf_counts_values *count); LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); +LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); +LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +2 -0
@@ -21,6 +21,8 @@ LIBPERF_0.0.1 { perf_evsel__open; perf_evsel__close; perf_evsel__read; + perf_evsel__cpus; + perf_evsel__threads; perf_evlist__new; perf_evlist__delete; perf_evlist__init;
tools/perf/util/evsel.h +1 -1
@@ -193,7 +193,7 @@ struct record_opts;static inline struct perf_cpu_map *evsel__cpus (struct evsel *evsel) { -return evsel->core.cpus; +return perf_evsel__cpus (&evsel->core); }static inline int perf_evsel__nr_cpus (struct evsel *evsel)
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 95/107 libperf: Adopt simplified perf_evlist__open()/close() functions from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add the following functions:
perf_evlist__open()
perf_evlist__close()
It's a simplified version of perf's evlist__open() without the sampling id index calculations. We can try to merge it in the future when we need it in some new libperf user.
Also adopt some helper evlist traversing macros. In the future we can remove them from util/evlist.h, but that requires also some other changes.
--- tools/perf/lib/evlist.c | 27 +++++++++++++++++++ tools/perf/lib/include/internal/evlist.h | 34 ++++++++++++++++++++++++ tools/perf/lib/include/perf/evlist.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ 4 files changed, 65 insertions(+)
tools/perf/lib/evlist.c +27 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <perf/evlist.h> +#include <perf/evsel.h> #include <linux/list.h> #include <internal/evlist.h> #include <internal/evsel.h>
@@ -114,3 +115,29 @@ void perf_evlist__set_maps(struct perf_evlist *evlist,perf_evlist__propagate_maps (evlist); } + +int perf_evlist__open (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; +int err; + +perf_evlist__for_each_entry (evlist, evsel) { + err =perf_evsel__open (evsel, evsel->cpus, evsel->threads); +if (err <0 ) + goto out_err; + } + +return 0 ; + +out_err: +perf_evlist__close (evlist); +return err; +} + +void perf_evlist__close (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; + +perf_evlist__for_each_entry_reverse (evlist, evsel) +perf_evsel__close (evsel); +}
tools/perf/lib/include/internal/evlist.h +34 -0
@@ -2,6 +2,8 @@#ifndef __LIBPERF_INTERNAL_EVLIST_H#define __LIBPERF_INTERNAL_EVLIST_H +#include <linux/list.h> +struct perf_cpu_map ;struct perf_thread_map ;
@@ -13,4 +15,36 @@ struct perf_evlist { struct perf_thread_map *threads; }; +/** +* __perf_evlist__for_each_entry - iterate thru all the evsels +* @list: list_head instance to iterate +* @evsel: struct perf_evsel iterator +*/ +#define __perf_evlist__for_each_entry (list, evsel) \ + list_for_each_entry(evsel, list, node) + +/** +* evlist__for_each_entry - iterate thru all the evsels +* @evlist: perf_evlist instance to iterate +* @evsel: struct perf_evsel iterator +*/ +#define perf_evlist__for_each_entry (evlist, evsel) \ + __perf_evlist__for_each_entry(&(evlist)->entries, evsel) + +/** +* __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order +* @list: list_head instance to iterate +* @evsel: struct evsel iterator +*/ +#define __perf_evlist__for_each_entry_reverse (list, evsel) \ + list_for_each_entry_reverse(evsel, list, node) + +/** +* perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order +* @evlist: evlist instance to iterate +* @evsel: struct evsel iterator +*/ +#define perf_evlist__for_each_entry_reverse (evlist, evsel) \ + __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) +#endif /* __LIBPERF_INTERNAL_EVLIST_H */
tools/perf/lib/include/perf/evlist.h +2 -0
@@ -18,6 +18,8 @@ LIBPERF_API struct perf_evlist *perf_evlist__new(void); LIBPERF_API void perf_evlist__delete(struct perf_evlist *evlist); LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,struct perf_evsel *evsel); +LIBPERF_API int perf_evlist__open(struct perf_evlist *evlist); +LIBPERF_API void perf_evlist__close(struct perf_evlist *evlist);#define perf_evlist__for_each_evsel (evlist, pos) \ for ((pos) = perf_evlist__next((evlist), NULL); \
tools/perf/lib/libperf.map +2 -0
@@ -25,6 +25,8 @@ LIBPERF_0.0.1 { perf_evsel__threads; perf_evlist__new; perf_evlist__delete; + perf_evlist__open; + perf_evlist__close; perf_evlist__init; perf_evlist__add; perf_evlist__remove;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 96/107 libperf: Adopt perf_evlist__enable()/disable() functions from perf
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adopt the following functions from tools/perf:
perf_evlist__enable()
perf_evlist__disable()
--- tools/perf/lib/evlist.c | 16 ++++++++++++++++ tools/perf/lib/include/perf/evlist.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ 3 files changed, 20 insertions(+)
tools/perf/lib/evlist.c +16 -0
@@ -141,3 +141,19 @@ void perf_evlist__close(struct perf_evlist *evlist)perf_evlist__for_each_entry_reverse (evlist, evsel)perf_evsel__close (evsel); } + +void perf_evlist__enable (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; + +perf_evlist__for_each_entry (evlist, evsel) +perf_evsel__enable (evsel); +} + +void perf_evlist__disable (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; + +perf_evlist__for_each_entry (evlist, evsel) +perf_evsel__disable (evsel); +}
tools/perf/lib/include/perf/evlist.h +2 -0
@@ -20,6 +20,8 @@ LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *evsel); LIBPERF_API int perf_evlist__open(struct perf_evlist *evlist); LIBPERF_API void perf_evlist__close(struct perf_evlist *evlist); +LIBPERF_API void perf_evlist__enable(struct perf_evlist *evlist); +LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist);#define perf_evlist__for_each_evsel (evlist, pos) \ for ((pos) = perf_evlist__next((evlist), NULL); \
tools/perf/lib/libperf.map +2 -0
@@ -27,6 +27,8 @@ LIBPERF_0.0.1 { perf_evlist__delete; perf_evlist__open; perf_evlist__close; + perf_evlist__enable; + perf_evlist__disable; perf_evlist__init; perf_evlist__add; perf_evlist__remove;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 97/107 libperf: Add perf_evsel__attr() function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add a perf_evsel__attr() function to get attr pointer from a perf_evsel instance.
--- tools/perf/lib/evsel.c | 5 +++++ tools/perf/lib/include/perf/evsel.h | 1 + tools/perf/lib/libperf.map | 1 + 3 files changed, 7 insertions(+)
tools/perf/lib/evsel.c +5 -0
@@ -225,3 +225,8 @@ struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel) {return evsel->threads; } + +struct perf_event_attr *perf_evsel__attr (struct perf_evsel *evsel) +{ +return &evsel->attr; +}
tools/perf/lib/include/perf/evsel.h +1 -0
@@ -34,5 +34,6 @@ LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); +LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);#endif /* __LIBPERF_EVSEL_H */
tools/perf/lib/libperf.map +1 -0
@@ -23,6 +23,7 @@ LIBPERF_0.0.1 { perf_evsel__read; perf_evsel__cpus; perf_evsel__threads; + perf_evsel__attr; perf_evlist__new; perf_evlist__delete; perf_evlist__open;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 98/107 libperf: Add install targets
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add install targets (mostly copied from tools/lib/bpf), it's now possible to install libperf with:
$ make DESTDIR=/tmp/krava install
INSTALL libperf.a
INSTALL libperf.so
INSTALL libperf.so.0
INSTALL libperf.so.0.0.1
INSTALL headers
INSTALL libperf.pc$ find /tmp/krava/ /tmp/krava/ /tmp/krava/include /tmp/krava/include/perf /tmp/krava/include/perf/evsel.h /tmp/krava/include/perf/evlist.h /tmp/krava/include/perf/threadmap.h /tmp/krava/include/perf/cpumap.h /tmp/krava/include/perf/core.h /tmp/krava/lib64 /tmp/krava/lib64/pkgconfig /tmp/krava/lib64/pkgconfig/libperf.pc /tmp/krava/lib64/libperf.so.0.0.1 /tmp/krava/lib64/libperf.so.0 /tmp/krava/lib64/libperf.so /tmp/krava/lib64/libperf.a
--- tools/perf/lib/Makefile | 69 +++++++++++++++++++++++++++++- tools/perf/lib/libperf.pc.template | 11 +++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tools/perf/lib/libperf.pc.template
tools/perf/lib/Makefile +67 -2
@@ -14,9 +14,31 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) #$(info Determined 'srctree' to be $(srctree)) endif +INSTALL = install + +# Use DESTDIR for installing into a different root directory. +# This is useful for building a package. The program will be +# installed in this directory as if it was the root directory. +# Then the build tool can move it later. +DESTDIR ?= +DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' + include $(srctree)/tools/scripts/Makefile.include include $(srctree)/tools/scripts/Makefile.arch +ifeq ($(LP64), 1) + libdir_relative = lib64 +else + libdir_relative = lib +endif + +prefix ?= +libdir = $(prefix)/$(libdir_relative) + +# Shell quotes +libdir_SQ = $(subst ','\'',$(libdir)) +libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) + ifeq ("$(origin V)", "command line") VERBOSE = $(V) endif
@@ -49,6 +71,8 @@ override CFLAGS += -fvisibility=hidden all: export srctree OUTPUT CC LD CFLAGS V +export DESTDIR DESTDIR_SQ + include $(srctree)/tools/build/Makefile.include VERSION_SCRIPT := libperf.map
@@ -60,6 +84,9 @@ VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION) LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) LIBPERF_A := $(OUTPUT)libperf.a LIBPERF_IN := $(OUTPUT)libperf-in.o +LIBPERF_PC := $(OUTPUT)libperf.pc + +LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so* $(LIBPERF_IN): FORCE $(Q)$(MAKE) $(build)=libperf
@@ -74,14 +101,52 @@ $(LIBPERF_SO): $(LIBPERF_IN) @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION) -libs: $(LIBPERF_A) $(LIBPERF_SO) +libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) all: fixdep $(Q)$(MAKE) libs clean: $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ - *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS + *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC) + +$(LIBPERF_PC): + $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ + -e "s|@LIBDIR@|$(libdir_SQ)|" \ + -e "s|@VERSION@|$(VERSION)|" \ + < libperf.pc.template > $@ + +define do_install_mkdir + if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ + fi +endef + +define do_install + if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ + fi; \ + $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2' +endef + +install_lib: libs + $(call QUIET_INSTALL, $(LIBPERF_ALL)) \ + $(call do_install_mkdir,$(libdir_SQ)); \ + cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) + +install_headers: + $(call QUIET_INSTALL, headers) \ + $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \ + $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \ + $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \ + $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \ + $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); + +install_pkgconfig: $(LIBPERF_PC) + $(call QUIET_INSTALL, $(LIBPERF_PC)) \ + $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644) + +install: install_lib install_headers install_pkgconfig FORCE:
tools/perf/lib/libperf.pc.template new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libperf +Description: perf library +Version: @VERSION@ +Libs: -L${libdir} -lperf +Cflags: -I${includedir}
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 99/107 libperf: Add tests support
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding simple test framework, now empty.
--- tools/perf/lib/Makefile | 7 ++++- tools/perf/lib/include/internal/tests.h | 19 +++++++++++++ tools/perf/lib/tests/Makefile | 38 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tools/perf/lib/include/internal/tests.h create mode 100644 tools/perf/lib/tests/Makefile
tools/perf/lib/Makefile +6 -1
@@ -109,6 +109,11 @@ all: fixdep clean: $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC) + $(Q)$(MAKE) -C tests clean + +tests: + $(Q)$(MAKE) -C tests + $(Q)$(MAKE) -C tests run $(LIBPERF_PC): $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
@@ -150,4 +155,4 @@ install: install_lib install_headers install_pkgconfig FORCE: -.PHONY: all install clean FORCE +.PHONY: all install clean tests FORCE
tools/perf/lib/include/internal/tests.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_TESTS_H +#define __LIBPERF_INTERNAL_TESTS_H + +#include <stdio.h> + +#define __T_START fprintf(stdout, "- running %s...", __FILE__) +#define __T_OK fprintf(stdout, "OK\n") +#define __T_FAIL fprintf(stdout, "FAIL\n") + +#define __T (text, cond) \ +do { \ + if (!(cond)) { \ + fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ + return -1; \ + } \ +} while (0) + +#endif /* __LIBPERF_INTERNAL_TESTS_H */
tools/perf/lib/tests/Makefile new file +38 -0
@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +TESTS = + +TESTS_SO := $(addsuffix -so,$(TESTS)) +TESTS_A := $(addsuffix -a,$(TESTS)) + +# Set compile option CFLAGS +ifdef EXTRA_CFLAGS + CFLAGS := $(EXTRA_CFLAGS) +else + CFLAGS := -g -Wall +endif + +all: + +include $(srctree)/tools/scripts/Makefile.include + +INCLUDE = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include + +$(TESTS_A): FORCE + $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) ../libperf.a + +$(TESTS_SO): FORCE + $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) -lperf + +all: $(TESTS_A) $(TESTS_SO) + +run: + @echo "running static:" + @for i in $(TESTS_A); do ./$$i; done + @echo "running dynamic:" + @for i in $(TESTS_SO); do LD_LIBRARY_PATH=../ ./$$i; done + +clean: + $(call QUIET_CLEAN, tests)$(RM) $(TESTS_A) $(TESTS_SO) + +.PHONY: all clean FORCE
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 100/107 libperf: Add perf_cpu_map test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add simple perf_cpu_map tests.
Committer testing:
One has to build it in the source tree, a limitation that should be fixed in followup patches:
$ make O=/tmp/build/perf -C tools/perf/lib
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so.0.0.1
GEN /tmp/build/perf/libperf.pc
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$ make O=/tmp/build/perf -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
gcc: error: ../libperf.a: No such file or directory
make[1]: *** [Makefile:22: test-cpumap-a] Error 1
make: *** [Makefile:115: tests] Error 2
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
[acme@quaco perf]$ make -C tools/perf/lib
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
HOSTCC fixdep.o
HOSTLD fixdep-in.o
LINK fixdep
CC core.o
CC cpumap.o
CC threadmap.o
CC evsel.o
CC evlist.o
CC zalloc.o
CC xyarray.o
CC lib.o
LD libperf-in.o
AR libperf.a
LINK libperf.so.0.0.1
GEN libperf.pc
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$ make O=/tmp/build/perf -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-cpumap-so
running static:
- running test-cpumap.c...OK
running dynamic:
- running test-cpumap.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$--- tools/perf/lib/tests/Makefile | 2 +- tools/perf/lib/tests/test-cpumap.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tools/perf/lib/tests/test-cpumap.c
tools/perf/lib/tests/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -TESTS = +TESTS = test-cpumap TESTS_SO := $(addsuffix -so,$(TESTS)) TESTS_A := $(addsuffix -a,$(TESTS))
tools/perf/lib/tests/test-cpumap.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <perf/cpumap.h> +#include <internal/tests.h> + +int main (int argc,char **argv) +{ +struct perf_cpu_map *cpus; + + __T_START; + + cpus =perf_cpu_map__dummy_new (); +if (!cpus) +return -1 ; + +perf_cpu_map__get (cpus); +perf_cpu_map__put (cpus); +perf_cpu_map__put (cpus); + + __T_OK; +return 0 ; +}
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 101/107 libperf: Add perf_thread_map test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add simple perf_thread_map tests.
Committer testing:
$ make O=/tmp/build/perf -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-cpumap-so
LINK test-threadmap-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
$--- tools/perf/lib/tests/Makefile | 2 +- tools/perf/lib/tests/test-threadmap.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tools/perf/lib/tests/test-threadmap.c
tools/perf/lib/tests/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -TESTS = test-cpumap +TESTS = test-cpumap test-threadmap TESTS_SO := $(addsuffix -so,$(TESTS)) TESTS_A := $(addsuffix -a,$(TESTS))
tools/perf/lib/tests/test-threadmap.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <perf/threadmap.h> +#include <internal/tests.h> + +int main (int argc,char **argv) +{ +struct perf_thread_map *threads; + + __T_START; + + threads =perf_thread_map__new_dummy (); +if (!threads) +return -1 ; + +perf_thread_map__get (threads); +perf_thread_map__put (threads); +perf_thread_map__put (threads); + + __T_OK; +return 0 ; +}
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 102/107 libperf: Add perf_evlist test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add 2 simple perf_evlist tests to test counters reading interface through the struct evlist object.
Committer testing:
# make -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
#--- tools/perf/lib/tests/Makefile | 2 +- tools/perf/lib/tests/test-evlist.c | 123 +++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 tools/perf/lib/tests/test-evlist.c
tools/perf/lib/tests/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -TESTS = test-cpumap test-threadmap +TESTS = test-cpumap test-threadmap test-evlist TESTS_SO := $(addsuffix -so,$(TESTS)) TESTS_A := $(addsuffix -a,$(TESTS))
tools/perf/lib/tests/test-evlist.c new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 103/107 libperf: Add perf_evsel tests
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add 2 simple perf_evsel tests to test counters reading interface through the struct evsel object.
Committer testing:
# make -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
#--- tools/perf/lib/tests/Makefile | 2 +- tools/perf/lib/tests/test-evsel.c | 82 +++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tools/perf/lib/tests/test-evsel.c
tools/perf/lib/tests/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -TESTS = test-cpumap test-threadmap test-evlist +TESTS = test-cpumap test-threadmap test-evlist test-evsel TESTS_SO := $(addsuffix -so,$(TESTS)) TESTS_A := $(addsuffix -a,$(TESTS))
tools/perf/lib/tests/test-evsel.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 104/107 libperf: Add perf_evlist__enable/disable test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add simple perf_evlist enable/disable test together with evlist counter reading interface.
Committer testing:
# make -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
#--- tools/perf/lib/tests/test-evlist.c | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
tools/perf/lib/tests/test-evlist.c +63 -0
@@ -111,12 +111,75 @@ static int test_stat_thread(void)return 0 ; } +static int test_stat_thread_enable (void ) +{ +struct perf_counts_values counts = { .val =0 }; +struct perf_thread_map *threads; +struct perf_evlist *evlist; +struct perf_evsel *evsel; +struct perf_event_attr attr1 = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_CPU_CLOCK , + .disabled =1 , + }; +struct perf_event_attr attr2 = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_TASK_CLOCK , + .disabled =1 , + }; +int err; + + threads =perf_thread_map__new_dummy (); +__T ("failed to create threads" , threads); + +perf_thread_map__set_pid (threads,0 ,0 ); + + evlist =perf_evlist__new (); +__T ("failed to create evlist" , evlist); + + evsel =perf_evsel__new (&attr1); +__T ("failed to create evsel1" , evsel); + +perf_evlist__add (evlist, evsel); + + evsel =perf_evsel__new (&attr2); +__T ("failed to create evsel2" , evsel); + +perf_evlist__add (evlist, evsel); + +perf_evlist__set_maps (evlist,NULL , threads); + + err =perf_evlist__open (evlist); +__T ("failed to open evsel" , err ==0 ); + +perf_evlist__for_each_evsel (evlist, evsel) { +perf_evsel__read (evsel,0 ,0 , &counts); +__T ("failed to read value for evsel" , counts.val ==0 ); + } + +perf_evlist__enable (evlist); + +perf_evlist__for_each_evsel (evlist, evsel) { +perf_evsel__read (evsel,0 ,0 , &counts); +__T ("failed to read value for evsel" , counts.val !=0 ); + } + +perf_evlist__disable (evlist); + +perf_evlist__close (evlist); +perf_evlist__delete (evlist); + +perf_thread_map__put (threads); +return 0 ; +} +int main (int argc,char **argv) { __T_START;test_stat_cpu ();test_stat_thread (); +test_stat_thread_enable (); __T_OK;return 0 ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 105/107 libperf: Add perf_evsel__enable/disable test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add simple perf_evsel enable/disable test together with evsel counter reading interface.
Committer testing:
# make -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
#--- tools/perf/lib/tests/test-evsel.c | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
tools/perf/lib/tests/test-evsel.c +43 -0
@@ -70,12 +70,55 @@ static int test_stat_thread(void)return 0 ; } +static int test_stat_thread_enable (void ) +{ +struct perf_counts_values counts = { .val =0 }; +struct perf_thread_map *threads; +struct perf_evsel *evsel; +struct perf_event_attr attr = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_TASK_CLOCK , + .disabled =1 , + }; +int err; + + threads =perf_thread_map__new_dummy (); +__T ("failed to create threads" , threads); + +perf_thread_map__set_pid (threads,0 ,0 ); + + evsel =perf_evsel__new (&attr); +__T ("failed to create evsel" , evsel); + + err =perf_evsel__open (evsel,NULL , threads); +__T ("failed to open evsel" , err ==0 ); + +perf_evsel__read (evsel,0 ,0 , &counts); +__T ("failed to read value for evsel" , counts.val ==0 ); + + err =perf_evsel__enable (evsel); +__T ("failed to enable evsel" , err ==0 ); + +perf_evsel__read (evsel,0 ,0 , &counts); +__T ("failed to read value for evsel" , counts.val !=0 ); + + err =perf_evsel__disable (evsel); +__T ("failed to enable evsel" , err ==0 ); + +perf_evsel__close (evsel); +perf_evsel__delete (evsel); + +perf_thread_map__put (threads); +return 0 ; +} +int main (int argc,char **argv) { __T_START;test_stat_cpu ();test_stat_thread (); +test_stat_thread_enable (); __T_OK;return 0 ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 106/107 libperf: Initial documentation
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add initial drafts of documentation files, hugely unfinished.
--- tools/perf/lib/Documentation/Makefile | 7 + tools/perf/lib/Documentation/man/libperf.rst | 100 ++++++++++++++ .../lib/Documentation/tutorial/tutorial.rst | 123 ++++++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 tools/perf/lib/Documentation/Makefile create mode 100644 tools/perf/lib/Documentation/man/libperf.rst create mode 100644 tools/perf/lib/Documentation/tutorial/tutorial.rst
tools/perf/lib/Documentation/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +all: + rst2man man/libperf.rst > man/libperf.7 + rst2pdf tutorial/tutorial.rst + +clean: + rm -f man/libperf.7 + rm -f tutorial/tutorial.pdf
tools/perf/lib/Documentation/man/libperf.rst new file +100 -0
100 lines not on this page · raw message
tools/perf/lib/Documentation/tutorial/tutorial.rst new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 107/107 perf vendor events power9: Added missing event descriptions
In reply to Arnaldo Carvalho de MeloFrom: Michael Petlan <[email protected]>
Documentation source:
https://wiki.raptorcs.com/w/images/6/6b/POWER9_PMU_UG_v12_28NOV2018_pub.pdf
LPU-Reference: [email protected]
--- tools/perf/pmu-events/arch/powerpc/power9/memory.json | 2 +- tools/perf/pmu-events/arch/powerpc/power9/other.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/pmu-events/arch/powerpc/power9/memory.json +1 -1
@@ -52,7 +52,7 @@ {, "EventCode": "0x4D02C", "EventName": "PM_PMC1_REWIND", - "BriefDescription": "" + "BriefDescription": "PMC1 rewind event" }, {, "EventCode": "0x15158",
tools/perf/pmu-events/arch/powerpc/power9/other.json +4 -4
@@ -237,7 +237,7 @@ {, "EventCode": "0xD0B0", "EventName": "PM_HWSYNC", - "BriefDescription": "" + "BriefDescription": "A hwsync instruction was decoded and transferred" }, {, "EventCode": "0x168B0",
@@ -1232,7 +1232,7 @@ {, "EventCode": "0xD8AC", "EventName": "PM_LWSYNC", - "BriefDescription": "" + "BriefDescription": "An lwsync instruction was decoded and transferred" }, {, "EventCode": "0x2094",
@@ -1747,7 +1747,7 @@ {, "EventCode": "0xD8B0", "EventName": "PM_PTESYNC", - "BriefDescription": "" + "BriefDescription": "A ptesync instruction was counted when the instruction is decoded and transmitted" }, {, "EventCode": "0x26086",
@@ -2107,7 +2107,7 @@ {, "EventCode": "0xF080", "EventName": "PM_LSU_STCX_FAIL", - "BriefDescription": "" + "BriefDescription": "The LSU detects the condition that a stcx instruction failed. No requirement to wait for a response from the nest" }, {, "EventCode": "0x30038",
Signature · 1 line
2.21.0
Re: [PATCH 107/107] perf vendor events power9: Added missing event descriptions
Quoted 15 lines · Arnaldo Carvalho de Melo
From: Michael Petlan <[email protected]>
Documentation source:
https://wiki.raptorcs.com/w/images/6/6b/POWER9_PMU_UG_v12_28NOV2018_pub.pdf
Signed-off-by Michael Petlan <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Cc Carl Love <[email protected]>Cc Michael Ellerman <[email protected]>Cc Naveen N. Rao <[email protected]>Cc Paul Clarke <[email protected]>Cc Sukadev Bhattiprolu <[email protected]>
Quoted 2 lines
LPU-Reference: [email protected]
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
cheers
Quoted 398 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
b3c303be4c35856945cb17ec639b94637447dae2:Merge tag 'perf-urgent-for-mingo-5.3-20190729' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/urgent (2019-07-29 23:24:07 +0200)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-5.4-20190729for you to fetch changes up to
123a039d0d54de6d5bafd551e7aa17569e13e315:perf vendor events power9: Added missing event descriptions (2019-07-29 18:34:47 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:perf trace:
Arnaldo Carvalho de Melo:
- Use
BPF_MAP_TYPE_PROG_ARRAY+bpf_tail_call()for augmenting raw syscalls, i.e. copy pointers passed to/from userspace. The use of a table per syscall to tell the BPF program what to copy made the raw_syscalls:sys_enter/exit programs a bit complex, the scratch space would have to be bigger to allow for checking all args to see which ones were a pathname, so use aPROG_ARRAYmap instead, test it with syscalls that receive multiple pathnames at different pairs of arguments (rename, renameat, etc).- Beautify various syscalls using this new infrastructure, and also add code that looks for syscalls with BPF augmenters, such as "open", and then reuse it with syscalls not yet having a specific augmenter, but that copies the same argument with the same type, say "statfs" can initially reuse "open", beautifier, as both have as its first arg a "const char *".
- Do not using
fd->pathnamebeautifier when the 'close' syscall isn't enabled, as we can't invalidate that mapping.core:
Jiri Olsa:
- Introduce
tools/perf/lib/, that eventually will move totools/lib/perf/, to allow other tools to use the abstractions and code perf uses to set up the perf ring buffer and set up the many possible combinations in allowed by the kernel, starting with 'structperf_evsel' and 'structperf_evlist'.perf vendor events:
Michael Petlan:
- Add missing event description to power9 event definitions.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (27):
perf include bpf: Addbpf_tail_call()prototype
perf bpf: Do not attach a BPF prog to a tracepoint if its name starts with ! perf evsel: Store backpointer to attachedbpf_object
perf trace: Add pointer to BPF object containing__augmented_syscalls__perf trace: Look up maps just on the__augmented_syscalls__BPF object perf trace: Order -e syscalls table
perf trace: Add BPF handler for unaugmented syscalls
perf trace: Allow specifying the bpf prog to augment specific syscalls perf trace: Put the per-syscall entry/exitprog_arrayBPF map infrastructure in place perf trace: Handle raw_syscalls:sys_enter just like theBPF_OUTPUTaugmented event perfaugmented_raw_syscalls: Add handler for "openat"
perfaugmented_raw_syscalls: Switch to usingBPF_MAP_TYPE_PROG_ARRAY
perfaugmented_raw_syscalls: Support copying two string syscall args
perf trace: Look for default name for entries in the syscalls prog array perfaugmented_raw_syscalls: Renameaugmented_args_filenametoaugmented_args_payloadperfaugmented_raw_syscalls: Augment sockaddr arg in 'connect'
perf trace beauty: Make connect's addrlen be printed as an int, not hex perf trace beauty: Disablefd->pathnamewhenclose()not enabled
perf trace beauty: Do not try to use thefd->pathnamebeautifier for bind/connect fd arg perf trace beauty: Beautify 'sendto's sockaddr arg
perf trace beauty: Beautify bind's sockaddr arg
perf trace beauty: Add BPF augmenter for the 'rename' syscall
perf trace: Forward error codes when trying to read syscall info
perf trace: Mark syscall ids that are not allocated to avoid unnecessary error messages perf trace: Preallocate the syscall table
perf trace: Reuse BPF augmenters from syscalls with similar args signature perf trace: Add "sendfile64" alias to the "sendfile" syscallJiri Olsa (79):
perf stat: Move loaded out of structperf_counts_values
perfcpu_map: Rename structcpu_mapto structperf_cpu_map
perf tools: Rename structthread_mapto structperf_thread_mapperf evsel: Rename structperf_evselto struct evsel
perf evlist: Rename structperf_evlistto struct evlist
perf evsel: Renameperf_evsel__init()toevsel__init()
perf evlist: Renameperf_evlist__init()toevlist__init()
perf evlist: Renameperf_evlist__new()toevlist__new()
perf evlist: Renameperf_evlist__delete()toevlist__delete()perf evsel: Renameperf_evsel__delete()toevsel__delete()
perf evsel: Renameperf_evsel__new()toevsel__new()
perf evlist: Renameperf_evlist__add()toevlist__add()
perf evlist: Renameperf_evlist__remove()toevlist__remove()perf evsel: Renameperf_evsel__open()toevsel__open()
perf evsel: Renameperf_evsel__enable()toevsel__enable()
perf evsel: Renameperf_evsel__disable()toevsel__disable()
perf evsel: Renameperf_evsel__apply_filter()toevsel__apply_filter()perf evsel: Renameperf_evsel__cpus()toevsel__cpus()
perf evlist: Renameperf_evlist__open()toevlist__open()
perf evlist: Renameperf_evlist__close()toevlist__close()
perf evlist: Renameperf_evlist__enable()toevlist__enable()perf evlist: Renameperf_evlist__disable()toevlist__disable()
libperf: Make libperf.a part of the perf build
libperf: Add build version support
libperf: Add libperf to the python.so build
libperf: Addperf/core.hheader
libperf: Add debug output support
libperf: Addperf_cpu_mapstruct
libperf: Addperf_cpu_map__dummy_new()function
libperf: Add perf_cpu_map__get()/perf_cpu_map__put()
libperf: Addperf_thread_mapstruct
libperf: Addperf_thread_map__new_dummy()function
libperf: Add perf_thread_map__get()/perf_thread_map__put()
libperf: Addperf_evlistandperf_evselstructs
libperf: Includeperf_evselin evsel object
libperf: Includeperf_evlistin evlist object
libperf: Addperf_evsel__initfunction
libperf: Addperf_evlist__init()function
libperf: Addperf_evlist__add()function
libperf: Addperf_evlist__remove()function
libperf: Addnr_entriesto structperf_evlist
libperf: Moveperf_event_attrfield from perf's evsel to libperf'sperf_evsel
libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions
libperf: Move zalloc.o into libperf
libperf: Addperf_evlist__new()function
libperf: Addperf_evsel__new()function
libperf: Addperf_evlist__for_each_evsel()iterator
libperf: Addperf_evlist__delete()function
libperf: Addperf_evsel__delete()function
libperf: Add cpus to structperf_evsel
libperf: Addown_cpusto structperf_evsel
libperf: Add threads to structperf_evsel
libperf: Addhas_user_cpusto structperf_evlist
libperf: Add cpus to structperf_evlist
libperf: Add threads to structperf_evlist
libperf: Addperf_evlist__set_maps()function
libperf: Adopt xyarray class from perf
libperf: Move fd array from perf's evsel to lobperf'sperf_evselclass
libperf: Movenr_membersfrom perf's evsel to libperf'sperf_evsel
libperf: Adopt the readn()/writen() functions fromtools/perf
libperf: Adoptperf_evsel__alloc_fd()function fromtools/perf
libperf: Adopt simplifiedperf_evsel__open()function fromtools/perf
libperf: Adopt simplifiedperf_evsel__close()function fromtools/perf
libperf: Adoptperf_evsel__read()function fromtools/perf
libperf: Adopt perf_evsel__enable()/disable()/apply_filter() functions
libperf: Addperf_cpu_map__for_each_cpu()macro
libperf: Add perf_evsel__cpus()/threads() functions
libperf: Adopt simplified perf_evlist__open()/close() functions fromtools/perf
libperf: Adopt perf_evlist__enable()/disable() functions from perf
libperf: Addperf_evsel__attr()function
libperf: Add install targets
libperf: Add tests support
libperf: Addperf_cpu_maptest
libperf: Addperf_thread_maptest
libperf: Addperf_evlisttest
libperf: Addperf_evseltests
libperf: Add perf_evlist__enable/disable test
libperf: Add perf_evsel__enable/disable test
libperf: Initial documentationMichael Petlan (1):
perf vendor events power9: Added missing event descriptionstools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 31 +- tools/perf/arch/arm/util/auxtrace.c | 8 +- tools/perf/arch/arm/util/cs-etm.c | 82 +- tools/perf/arch/arm64/util/arm-spe.c | 24 +- tools/perf/arch/arm64/util/header.c | 6 +- tools/perf/arch/powerpc/util/kvm-stat.c | 12 +- tools/perf/arch/s390/util/auxtrace.c | 12 +- tools/perf/arch/s390/util/kvm-stat.c | 8 +- tools/perf/arch/x86/tests/intel-cqm.c | 8 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 30 +- tools/perf/arch/x86/util/auxtrace.c | 10 +- tools/perf/arch/x86/util/intel-bts.c | 38 +- tools/perf/arch/x86/util/intel-pt.c | 82 +- tools/perf/arch/x86/util/kvm-stat.c | 12 +- tools/perf/bench/epoll-ctl.c | 7 +- tools/perf/bench/epoll-wait.c | 7 +- tools/perf/bench/futex-hash.c | 5 +- tools/perf/bench/futex-lock-pi.c | 7 +- tools/perf/bench/futex-requeue.c | 7 +- tools/perf/bench/futex-wake-parallel.c | 6 +- tools/perf/bench/futex-wake.c | 7 +- tools/perf/builtin-annotate.c | 16 +- tools/perf/builtin-c2c.c | 10 +- tools/perf/builtin-diff.c | 20 +- tools/perf/builtin-evlist.c | 4 +- tools/perf/builtin-ftrace.c | 18 +- tools/perf/builtin-inject.c | 60 +- tools/perf/builtin-kmem.c | 24 +- tools/perf/builtin-kvm.c | 46 +- tools/perf/builtin-lock.c | 30 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-record.c | 50 +- tools/perf/builtin-report.c | 32 +- tools/perf/builtin-sched.c | 96 +- tools/perf/builtin-script.c | 167 +-- tools/perf/builtin-stat.c | 135 +-- tools/perf/builtin-timechart.c | 46 +- tools/perf/builtin-top.c | 71 +- tools/perf/builtin-trace.c | 619 +++++++--- tools/perf/examples/bpf/augmented_raw_syscalls.c | 284 +++-- tools/perf/include/bpf/bpf.h | 2 + tools/perf/lib/Build | 12 + tools/perf/lib/Documentation/Makefile | 7 + tools/perf/lib/Documentation/man/libperf.rst | 100 ++ tools/perf/lib/Documentation/tutorial/tutorial.rst | 123 ++ tools/perf/lib/Makefile | 158 +++ tools/perf/lib/core.c | 34 + tools/perf/lib/cpumap.c | 239 ++++ tools/perf/lib/evlist.c | 159 +++ tools/perf/lib/evsel.c | 232 ++++ tools/perf/lib/include/internal/cpumap.h | 17 + tools/perf/lib/include/internal/evlist.h | 50 + tools/perf/lib/include/internal/evsel.h | 29 + tools/perf/lib/include/internal/lib.h | 10 + tools/perf/lib/include/internal/tests.h | 19 + tools/perf/lib/include/internal/threadmap.h | 23 + .../perf/{util => lib/include/internal}/xyarray.h | 6 +- tools/perf/lib/include/perf/core.h | 22 + tools/perf/lib/include/perf/cpumap.h | 23 + tools/perf/lib/include/perf/evlist.h | 35 + tools/perf/lib/include/perf/evsel.h | 39 + tools/perf/lib/include/perf/threadmap.h | 18 + tools/perf/lib/internal.h | 18 + tools/perf/lib/lib.c | 46 + tools/perf/lib/libperf.map | 40 + tools/perf/lib/libperf.pc.template | 11 + tools/perf/lib/tests/Makefile | 38 + tools/perf/lib/tests/test-cpumap.c | 21 + tools/perf/lib/tests/test-evlist.c | 186 +++ tools/perf/lib/tests/test-evsel.c | 125 ++ tools/perf/lib/tests/test-threadmap.c | 21 + tools/perf/lib/threadmap.c | 81 ++ tools/perf/lib/xyarray.c | 33 + .../pmu-events/arch/powerpc/power9/memory.json | 2 +- .../perf/pmu-events/arch/powerpc/power9/other.json | 8 +- tools/perf/tests/backward-ring-buffer.c | 18 +- tools/perf/tests/bitmap.c | 5 +- tools/perf/tests/bpf.c | 12 +- tools/perf/tests/code-reading.c | 50 +- tools/perf/tests/cpumap.c | 21 +- tools/perf/tests/event-times.c | 81 +- tools/perf/tests/event_update.c | 13 +- tools/perf/tests/evsel-roundtrip-name.c | 12 +- tools/perf/tests/evsel-tp-sched.c | 8 +- tools/perf/tests/hists_cumulate.c | 18 +- tools/perf/tests/hists_filter.c | 10 +- tools/perf/tests/hists_link.c | 10 +- tools/perf/tests/hists_output.c | 20 +- tools/perf/tests/keep-tracking.c | 44 +- tools/perf/tests/mem2node.c | 5 +- tools/perf/tests/mmap-basic.c | 28 +- tools/perf/tests/mmap-thread-lookup.c | 4 +- tools/perf/tests/openat-syscall-all-cpus.c | 18 +- tools/perf/tests/openat-syscall-tp-fields.c | 14 +- tools/perf/tests/openat-syscall.c | 10 +- tools/perf/tests/parse-events.c | 1220 ++++++++++---------- tools/perf/tests/parse-no-sample-id-all.c | 6 +- tools/perf/tests/perf-record.c | 10 +- tools/perf/tests/sample-parsing.c | 14 +- tools/perf/tests/sw-clock.c | 33 +- tools/perf/tests/switch-tracking.c | 64 +- tools/perf/tests/task-exit.c | 35 +- tools/perf/tests/thread-map.c | 28 +- tools/perf/tests/time-utils-test.c | 2 +- tools/perf/tests/topology.c | 9 +- tools/perf/ui/browsers/annotate.c | 16 +- tools/perf/ui/browsers/hists.c | 54 +- tools/perf/ui/browsers/res_sample.c | 4 +- tools/perf/ui/browsers/scripts.c | 6 +- tools/perf/ui/gtk/annotate.c | 8 +- tools/perf/ui/gtk/gtk.h | 8 +- tools/perf/ui/gtk/hists.c | 6 +- tools/perf/ui/hist.c | 16 +- tools/perf/util/Build | 6 - tools/perf/util/annotate.c | 42 +- tools/perf/util/annotate.h | 28 +- tools/perf/util/auxtrace.c | 28 +- tools/perf/util/auxtrace.h | 24 +- tools/perf/util/bpf-event.c | 2 +- tools/perf/util/bpf-event.h | 4 +- tools/perf/util/bpf-loader.c | 38 +- tools/perf/util/bpf-loader.h | 30 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/build-id.h | 2 +- tools/perf/util/callchain.c | 2 +- tools/perf/util/callchain.h | 2 +- tools/perf/util/cgroup.c | 22 +- tools/perf/util/cgroup.h | 6 +- tools/perf/util/counts.c | 17 +- tools/perf/util/counts.h | 34 +- tools/perf/util/cpumap.c | 264 +---- tools/perf/util/cpumap.h | 54 +- tools/perf/util/cputopo.c | 13 +- tools/perf/util/cs-etm.c | 28 +- tools/perf/util/data-convert-bt.c | 38 +- tools/perf/util/db-export.c | 10 +- tools/perf/util/db-export.h | 10 +- tools/perf/util/env.c | 2 +- tools/perf/util/env.h | 2 +- tools/perf/util/event.c | 30 +- tools/perf/util/event.h | 14 +- tools/perf/util/evlist.c | 607 +++++----- tools/perf/util/evlist.h | 215 ++-- tools/perf/util/evsel.c | 497 ++++---- tools/perf/util/evsel.h | 197 ++-- tools/perf/util/evsel_fprintf.c | 16 +- tools/perf/util/header.c | 225 ++-- tools/perf/util/header.h | 24 +- tools/perf/util/hist.c | 32 +- tools/perf/util/hist.h | 38 +- tools/perf/util/intel-bts.c | 22 +- tools/perf/util/intel-pt.c | 94 +- tools/perf/util/jitdump.c | 8 +- tools/perf/util/kvm-stat.h | 22 +- tools/perf/util/machine.c | 12 +- tools/perf/util/machine.h | 8 +- tools/perf/util/map.h | 2 +- tools/perf/util/metricgroup.c | 26 +- tools/perf/util/metricgroup.h | 6 +- tools/perf/util/mmap.c | 4 +- tools/perf/util/parse-events.c | 155 +-- tools/perf/util/parse-events.h | 8 +- tools/perf/util/pmu.c | 15 +- tools/perf/util/pmu.h | 2 +- tools/perf/util/python-ext-sources | 2 - tools/perf/util/python.c | 73 +- tools/perf/util/record.c | 73 +- tools/perf/util/s390-cpumsf.c | 4 +- tools/perf/util/s390-sample-raw.c | 6 +- tools/perf/util/sample-raw.c | 2 +- tools/perf/util/sample-raw.h | 6 +- .../perf/util/scripting-engines/trace-event-perl.c | 14 +- .../util/scripting-engines/trace-event-python.c | 40 +- tools/perf/util/session.c | 81 +- tools/perf/util/session.h | 12 +- tools/perf/util/setup.py | 3 +- tools/perf/util/sort.c | 60 +- tools/perf/util/sort.h | 6 +- tools/perf/util/stat-display.c | 112 +- tools/perf/util/stat-shadow.c | 70 +- tools/perf/util/stat.c | 64 +- tools/perf/util/stat.h | 35 +- tools/perf/util/svghelper.c | 7 +- tools/perf/util/syscalltbl.c | 1 + tools/perf/util/syscalltbl.h | 1 + tools/perf/util/thread_map.c | 131 +-- tools/perf/util/thread_map.h | 58 +- tools/perf/util/tool.h | 8 +- tools/perf/util/top.c | 12 +- tools/perf/util/top.h | 8 +- tools/perf/util/trace-event-info.c | 14 +- tools/perf/util/trace-event-scripting.c | 2 +- tools/perf/util/trace-event.h | 4 +- tools/perf/util/util.c | 40 - tools/perf/util/util.h | 4 +- 196 files changed, 5958 insertions(+), 4051 deletions(-) create mode 100644 tools/perf/lib/Build create mode 100644 tools/perf/lib/Documentation/Makefile create mode 100644 tools/perf/lib/Documentation/man/libperf.rst create mode 100644 tools/perf/lib/Documentation/tutorial/tutorial.rst create mode 100644 tools/perf/lib/Makefile create mode 100644 tools/perf/lib/core.c create mode 100644 tools/perf/lib/cpumap.c create mode 100644 tools/perf/lib/evlist.c create mode 100644 tools/perf/lib/evsel.c create mode 100644 tools/perf/lib/include/internal/cpumap.h create mode 100644 tools/perf/lib/include/internal/evlist.h create mode 100644 tools/perf/lib/include/internal/evsel.h create mode 100644 tools/perf/lib/include/internal/lib.h create mode 100644 tools/perf/lib/include/internal/tests.h create mode 100644 tools/perf/lib/include/internal/threadmap.h rename tools/perf/{util => lib/include/internal}/xyarray.h (84%) create mode 100644 tools/perf/lib/include/perf/core.h create mode 100644 tools/perf/lib/include/perf/cpumap.h create mode 100644 tools/perf/lib/include/perf/evlist.h create mode 100644 tools/perf/lib/include/perf/evsel.h create mode 100644 tools/perf/lib/include/perf/threadmap.h create mode 100644 tools/perf/lib/internal.h create mode 100644 tools/perf/lib/lib.c create mode 100644 tools/perf/lib/libperf.map
Quoted 8 lines
create mode 100644 tools/perf/lib/libperf.pc.template create mode 100644 tools/perf/lib/tests/Makefile create mode 100644 tools/perf/lib/tests/test-cpumap.c create mode 100644 tools/perf/lib/tests/test-evlist.c create mode 100644 tools/perf/lib/tests/test-evsel.c create mode 100644 tools/perf/lib/tests/test-threadmap.c create mode 100644 tools/perf/lib/threadmap.c create mode 100644 tools/perf/lib/xyarray.c
Pulled, thanks a lot Arnaldo!
Ingo