diff options
-rw-r--r-- | include/linux/perf_event.h | 4 | ||||
-rw-r--r-- | kernel/perf_event.c | 66 | ||||
-rw-r--r-- | tools/perf/Makefile | 9 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 6 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 10 |
5 files changed, 65 insertions, 30 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 2e6d95f97419..9e7012689a84 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -471,8 +471,8 @@ struct hw_perf_event { | |||
471 | unsigned long event_base; | 471 | unsigned long event_base; |
472 | int idx; | 472 | int idx; |
473 | }; | 473 | }; |
474 | union { /* software */ | 474 | struct { /* software */ |
475 | atomic64_t count; | 475 | s64 remaining; |
476 | struct hrtimer hrtimer; | 476 | struct hrtimer hrtimer; |
477 | }; | 477 | }; |
478 | }; | 478 | }; |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index afb7ef3dbc44..7f29643c8985 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -3959,8 +3959,9 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer) | |||
3959 | regs = task_pt_regs(current); | 3959 | regs = task_pt_regs(current); |
3960 | 3960 | ||
3961 | if (regs) { | 3961 | if (regs) { |
3962 | if (perf_event_overflow(event, 0, &data, regs)) | 3962 | if (!(event->attr.exclude_idle && current->pid == 0)) |
3963 | ret = HRTIMER_NORESTART; | 3963 | if (perf_event_overflow(event, 0, &data, regs)) |
3964 | ret = HRTIMER_NORESTART; | ||
3964 | } | 3965 | } |
3965 | 3966 | ||
3966 | period = max_t(u64, 10000, event->hw.sample_period); | 3967 | period = max_t(u64, 10000, event->hw.sample_period); |
@@ -3969,6 +3970,42 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer) | |||
3969 | return ret; | 3970 | return ret; |
3970 | } | 3971 | } |
3971 | 3972 | ||
3973 | static void perf_swevent_start_hrtimer(struct perf_event *event) | ||
3974 | { | ||
3975 | struct hw_perf_event *hwc = &event->hw; | ||
3976 | |||
3977 | hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
3978 | hwc->hrtimer.function = perf_swevent_hrtimer; | ||
3979 | if (hwc->sample_period) { | ||
3980 | u64 period; | ||
3981 | |||
3982 | if (hwc->remaining) { | ||
3983 | if (hwc->remaining < 0) | ||
3984 | period = 10000; | ||
3985 | else | ||
3986 | period = hwc->remaining; | ||
3987 | hwc->remaining = 0; | ||
3988 | } else { | ||
3989 | period = max_t(u64, 10000, hwc->sample_period); | ||
3990 | } | ||
3991 | __hrtimer_start_range_ns(&hwc->hrtimer, | ||
3992 | ns_to_ktime(period), 0, | ||
3993 | HRTIMER_MODE_REL, 0); | ||
3994 | } | ||
3995 | } | ||
3996 | |||
3997 | static void perf_swevent_cancel_hrtimer(struct perf_event *event) | ||
3998 | { | ||
3999 | struct hw_perf_event *hwc = &event->hw; | ||
4000 | |||
4001 | if (hwc->sample_period) { | ||
4002 | ktime_t remaining = hrtimer_get_remaining(&hwc->hrtimer); | ||
4003 | hwc->remaining = ktime_to_ns(remaining); | ||
4004 | |||
4005 | hrtimer_cancel(&hwc->hrtimer); | ||
4006 | } | ||
4007 | } | ||
4008 | |||
3972 | /* | 4009 | /* |
3973 | * Software event: cpu wall time clock | 4010 | * Software event: cpu wall time clock |
3974 | */ | 4011 | */ |
@@ -3991,22 +4028,14 @@ static int cpu_clock_perf_event_enable(struct perf_event *event) | |||
3991 | int cpu = raw_smp_processor_id(); | 4028 | int cpu = raw_smp_processor_id(); |
3992 | 4029 | ||
3993 | atomic64_set(&hwc->prev_count, cpu_clock(cpu)); | 4030 | atomic64_set(&hwc->prev_count, cpu_clock(cpu)); |
3994 | hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 4031 | perf_swevent_start_hrtimer(event); |
3995 | hwc->hrtimer.function = perf_swevent_hrtimer; | ||
3996 | if (hwc->sample_period) { | ||
3997 | u64 period = max_t(u64, 10000, hwc->sample_period); | ||
3998 | __hrtimer_start_range_ns(&hwc->hrtimer, | ||
3999 | ns_to_ktime(period), 0, | ||
4000 | HRTIMER_MODE_REL, 0); | ||
4001 | } | ||
4002 | 4032 | ||
4003 | return 0; | 4033 | return 0; |
4004 | } | 4034 | } |
4005 | 4035 | ||
4006 | static void cpu_clock_perf_event_disable(struct perf_event *event) | 4036 | static void cpu_clock_perf_event_disable(struct perf_event *event) |
4007 | { | 4037 | { |
4008 | if (event->hw.sample_period) | 4038 | perf_swevent_cancel_hrtimer(event); |
4009 | hrtimer_cancel(&event->hw.hrtimer); | ||
4010 | cpu_clock_perf_event_update(event); | 4039 | cpu_clock_perf_event_update(event); |
4011 | } | 4040 | } |
4012 | 4041 | ||
@@ -4043,22 +4072,15 @@ static int task_clock_perf_event_enable(struct perf_event *event) | |||
4043 | now = event->ctx->time; | 4072 | now = event->ctx->time; |
4044 | 4073 | ||
4045 | atomic64_set(&hwc->prev_count, now); | 4074 | atomic64_set(&hwc->prev_count, now); |
4046 | hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 4075 | |
4047 | hwc->hrtimer.function = perf_swevent_hrtimer; | 4076 | perf_swevent_start_hrtimer(event); |
4048 | if (hwc->sample_period) { | ||
4049 | u64 period = max_t(u64, 10000, hwc->sample_period); | ||
4050 | __hrtimer_start_range_ns(&hwc->hrtimer, | ||
4051 | ns_to_ktime(period), 0, | ||
4052 | HRTIMER_MODE_REL, 0); | ||
4053 | } | ||
4054 | 4077 | ||
4055 | return 0; | 4078 | return 0; |
4056 | } | 4079 | } |
4057 | 4080 | ||
4058 | static void task_clock_perf_event_disable(struct perf_event *event) | 4081 | static void task_clock_perf_event_disable(struct perf_event *event) |
4059 | { | 4082 | { |
4060 | if (event->hw.sample_period) | 4083 | perf_swevent_cancel_hrtimer(event); |
4061 | hrtimer_cancel(&event->hw.hrtimer); | ||
4062 | task_clock_perf_event_update(event, event->ctx->time); | 4084 | task_clock_perf_event_update(event, event->ctx->time); |
4063 | 4085 | ||
4064 | } | 4086 | } |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 742a32eee8fc..7e190d522cd5 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -177,8 +177,7 @@ endif | |||
177 | # Include saner warnings here, which can catch bugs: | 177 | # Include saner warnings here, which can catch bugs: |
178 | # | 178 | # |
179 | 179 | ||
180 | EXTRA_WARNINGS := -Wcast-align | 180 | EXTRA_WARNINGS := -Wformat |
181 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat | ||
182 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security | 181 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security |
183 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k | 182 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k |
184 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow | 183 | EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow |
@@ -422,7 +421,11 @@ ifeq ($(uname_S),Darwin) | |||
422 | PTHREAD_LIBS = | 421 | PTHREAD_LIBS = |
423 | endif | 422 | endif |
424 | 423 | ||
425 | ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y) | 424 | ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y) |
425 | ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y) | ||
426 | BASIC_CFLAGS += -DLIBELF_NO_MMAP | ||
427 | endif | ||
428 | else | ||
426 | msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); | 429 | msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); |
427 | endif | 430 | endif |
428 | 431 | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 47ea0609a760..226f44a2357d 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -413,7 +413,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int v) | |||
413 | if (fd < 0) | 413 | if (fd < 0) |
414 | goto out; | 414 | goto out; |
415 | 415 | ||
416 | elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); | 416 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
417 | if (elf == NULL) | 417 | if (elf == NULL) |
418 | goto out_close; | 418 | goto out_close; |
419 | 419 | ||
@@ -533,7 +533,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name, | |||
533 | Elf *elf; | 533 | Elf *elf; |
534 | int nr = 0, kernel = !strcmp("[kernel]", self->name); | 534 | int nr = 0, kernel = !strcmp("[kernel]", self->name); |
535 | 535 | ||
536 | elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); | 536 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
537 | if (elf == NULL) { | 537 | if (elf == NULL) { |
538 | if (v) | 538 | if (v) |
539 | fprintf(stderr, "%s: cannot read %s ELF file.\n", | 539 | fprintf(stderr, "%s: cannot read %s ELF file.\n", |
@@ -675,7 +675,7 @@ static char *dso__read_build_id(struct dso *self, int v) | |||
675 | if (fd < 0) | 675 | if (fd < 0) |
676 | goto out; | 676 | goto out; |
677 | 677 | ||
678 | elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); | 678 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
679 | if (elf == NULL) { | 679 | if (elf == NULL) { |
680 | if (v) | 680 | if (v) |
681 | fprintf(stderr, "%s: cannot read %s ELF file.\n", | 681 | fprintf(stderr, "%s: cannot read %s ELF file.\n", |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 6e8490716408..829da9edba64 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -27,6 +27,16 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, | |||
27 | #endif | 27 | #endif |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | /* | ||
31 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | ||
32 | * for newer versions we can use mmap to reduce memory usage: | ||
33 | */ | ||
34 | #ifdef LIBELF_NO_MMAP | ||
35 | # define PERF_ELF_C_READ_MMAP ELF_C_READ | ||
36 | #else | ||
37 | # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP | ||
38 | #endif | ||
39 | |||
30 | #ifndef DMGL_PARAMS | 40 | #ifndef DMGL_PARAMS |
31 | #define DMGL_PARAMS (1 << 0) /* Include function args */ | 41 | #define DMGL_PARAMS (1 << 0) /* Include function args */ |
32 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | 42 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ |