diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-01-28 20:44:15 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-01-28 20:44:15 +0300 |
commit | c0e809e244804d428bcd976eaf9369f60508ea8a (patch) | |
tree | 99fa85899a3c11d2ebeb6d090f218fda968a0e6a /tools/perf/lib/evsel.c | |
parent | 2180f214f4a5d8e2d8b7138d9a59246ee05753b9 (diff) | |
parent | 0cc4bd8f70d1ea2940295f1050508c663fe9eff9 (diff) | |
download | linux-c0e809e244804d428bcd976eaf9369f60508ea8a.tar.xz |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar:
"Kernel side changes:
- Ftrace is one of the last W^X violators (after this only KLP is
left). These patches move it over to the generic text_poke()
interface and thereby get rid of this oddity. This requires a
surprising amount of surgery, by Peter Zijlstra.
- x86/AMD PMUs: add support for 'Large Increment per Cycle Events' to
count certain types of events that have a special, quirky hw ABI
(by Kim Phillips)
- kprobes fixes by Masami Hiramatsu
Lots of tooling updates as well, the following subcommands were
updated: annotate/report/top, c2c, clang, record, report/top TUI,
sched timehist, tests; plus updates were done to the gtk ui, libperf,
headers and the parser"
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (57 commits)
perf/x86/amd: Add support for Large Increment per Cycle Events
perf/x86/amd: Constrain Large Increment per Cycle events
perf/x86/intel/rapl: Add Comet Lake support
tracing: Initialize ret in syscall_enter_define_fields()
perf header: Use last modification time for timestamp
perf c2c: Fix return type for histogram sorting comparision functions
perf beauty sockaddr: Fix augmented syscall format warning
perf/ui/gtk: Fix gtk2 build
perf ui gtk: Add missing zalloc object
perf tools: Use %define api.pure full instead of %pure-parser
libperf: Setup initial evlist::all_cpus value
perf report: Fix no libunwind compiled warning break s390 issue
perf tools: Support --prefix/--prefix-strip
perf report: Clarify in help that --children is default
tools build: Fix test-clang.cpp with Clang 8+
perf clang: Fix build with Clang 9
kprobes: Fix optimize_kprobe()/unoptimize_kprobe() cancellation logic
tools lib: Fix builds when glibc contains strlcpy()
perf report/top: Make 'e' visible in the help and make it toggle showing callchains
perf report/top: Do not offer annotation for symbols without samples
...
Diffstat (limited to 'tools/perf/lib/evsel.c')
-rw-r--r-- | tools/perf/lib/evsel.c | 301 |
1 files changed, 0 insertions, 301 deletions
diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c deleted file mode 100644 index 4dc06289f4c7..000000000000 --- a/tools/perf/lib/evsel.c +++ /dev/null @@ -1,301 +0,0 @@ -// 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 <internal/lib.h> -#include <linux/string.h> -#include <sys/ioctl.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; -} - -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; -} - -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; -} - -static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu) -{ - int thread; - - for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) { - if (FD(evsel, cpu, thread) >= 0) - close(FD(evsel, cpu, thread)); - FD(evsel, cpu, thread) = -1; - } -} - -void perf_evsel__close_fd(struct perf_evsel *evsel) -{ - int cpu; - - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) - perf_evsel__close_fd_cpu(evsel, cpu); -} - -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); -} - -void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu) -{ - if (evsel->fd == NULL) - return; - - perf_evsel__close_fd_cpu(evsel, cpu); -} - -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; -} - -static int perf_evsel__run_ioctl(struct perf_evsel *evsel, - int ioc, void *arg, - int cpu) -{ - int thread; - - 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_cpu(struct perf_evsel *evsel, int cpu) -{ - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu); -} - -int perf_evsel__enable(struct perf_evsel *evsel) -{ - int i; - int err = 0; - - for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i); - return err; -} - -int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu) -{ - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu); -} - -int perf_evsel__disable(struct perf_evsel *evsel) -{ - int i; - int err = 0; - - for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i); - return err; -} - -int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) -{ - int err = 0, i; - - for (i = 0; i < evsel->cpus->nr && !err; i++) - err = perf_evsel__run_ioctl(evsel, - PERF_EVENT_IOC_SET_FILTER, - (void *)filter, i); - return err; -} - -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; -} - -struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel) -{ - return &evsel->attr; -} - -int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) -{ - if (ncpus == 0 || nthreads == 0) - return 0; - - if (evsel->system_wide) - nthreads = 1; - - evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); - if (evsel->sample_id == NULL) - return -ENOMEM; - - evsel->id = zalloc(ncpus * nthreads * sizeof(u64)); - if (evsel->id == NULL) { - xyarray__delete(evsel->sample_id); - evsel->sample_id = NULL; - return -ENOMEM; - } - - return 0; -} - -void perf_evsel__free_id(struct perf_evsel *evsel) -{ - xyarray__delete(evsel->sample_id); - evsel->sample_id = NULL; - zfree(&evsel->id); - evsel->ids = 0; -} |