Perf updates
Subsystems (3)
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core
Thanks,
Frederic
---
Frederic Weisbecker (3):
perf lock: Drop the buffers multiplexing dependency
perf: Remove pointless breakpoint union x86/hw-breakpoints: Remove the name field
Hitoshi Mitake (1):
perf lock: Fix and add misc documentally things
Tejun Heo (1):
percpu: Add __percpu sparse annotations to hw_breakpoint
arch/x86/include/asm/hw_breakpoint.h | 1 - arch/x86/kernel/hw_breakpoint.c | 7 -- include/linux/hw_breakpoint.h | 8 +- include/linux/perf_event.h | 5 +- kernel/hw_breakpoint.c | 10 +- lib/Kconfig.debug | 8 ++ samples/hw_breakpoint/data_breakpoint.c | 6 +- tools/perf/Documentation/perf-lock.txt | 29 ++++++ tools/perf/builtin-lock.c | 148 ++++++++++++++++++++++++++++++- tools/perf/command-list.txt | 1 + 10 files changed, 198 insertions(+), 25 deletions(-)
PATCH 1/5 percpu: Add __percpu sparse annotations to hw_breakpoint
From: Tejun Heo <[email protected]>
Add __percpu sparse annotations to hw_breakpoint.
These annotations are to make sparse consider percpu variables to be in a different address space and warn if accessed without going through percpu accessors. This patch doesn't affect normal builds.
In kernel/hw_breakpoint.c, per_cpu(nr_task_bp_pinned, cpu)'s will trigger spurious noderef related warnings from sparse. Changing it to &per_cpu(nr_task_bp_pinned[0], cpu) will work around the problem but deemed to ugly by the maintainer. Leave it alone until better solution can be found.
LKML-Reference: <[email protected]>
--- include/linux/hw_breakpoint.h | 8 ++++---- kernel/hw_breakpoint.c | 10 +++++----- samples/hw_breakpoint/data_breakpoint.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-)
include/linux/hw_breakpoint.h +4 -4
@@ -66,14 +66,14 @@ register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,perf_overflow_handler_t triggered, int cpu); -extern struct perf_event ** +extern struct perf_event *__percpu *register_wide_hw_breakpoint (struct perf_event_attr *attr,perf_overflow_handler_t triggered);extern int register_perf_hw_breakpoint (struct perf_event *bp);extern int __register_perf_hw_breakpoint (struct perf_event *bp);extern void unregister_hw_breakpoint (struct perf_event *bp); -extern void unregister_wide_hw_breakpoint (struct perf_event **cpu_events); +extern void unregister_wide_hw_breakpoint (struct perf_event *__percpu *cpu_events);extern int dbg_reserve_bp_slot (struct perf_event *bp);extern int dbg_release_bp_slot (struct perf_event *bp);
@@ -100,7 +100,7 @@ static inline struct perf_event * register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, perf_overflow_handler_t triggered, int cpu) { return NULL; } -static inline struct perf_event ** +static inline struct perf_event *__percpu *register_wide_hw_breakpoint (struct perf_event_attr *attr,perf_overflow_handler_t triggered) {return NULL ; } static inline int
@@ -109,7 +109,7 @@ static inline int __register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }static inline void unregister_hw_breakpoint (struct perf_event *bp) { }static inline void -unregister_wide_hw_breakpoint (struct perf_event **cpu_events) { } +unregister_wide_hw_breakpoint (struct perf_event *__percpu *cpu_events) { }static inline int reserve_bp_slot (struct perf_event *bp) {return -ENOSYS ; }static inline void release_bp_slot (struct perf_event *bp) { }
kernel/hw_breakpoint.c +5 -5
@@ -413,17 +413,17 @@ EXPORT_SYMBOL_GPL(unregister_hw_breakpoint);* * @return a set of per_cpu pointers to perf events */ -struct perf_event ** +struct perf_event *__percpu *register_wide_hw_breakpoint (struct perf_event_attr *attr,perf_overflow_handler_t triggered) { -struct perf_event **cpu_events, **pevent, *bp; +struct perf_event *__percpu *cpu_events, **pevent, *bp;long err;int cpu; cpu_events =alloc_percpu (typeof (*cpu_events));if (!cpu_events) -return ERR_PTR (-ENOMEM ); +return (void __percpu __force *)ERR_PTR (-ENOMEM );get_online_cpus ();for_each_online_cpu (cpu) {
@@ -451,7 +451,7 @@ fail:put_online_cpus ();free_percpu (cpu_events); -return ERR_PTR (err); +return (void __percpu __force *)ERR_PTR (err); }EXPORT_SYMBOL_GPL (register_wide_hw_breakpoint);
@@ -459,7 +459,7 @@ EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint);* unregister_wide_hw_breakpoint - unregister a wide breakpoint in the kernel * @cpu_events: the per cpu set of events to unregister */ -void unregister_wide_hw_breakpoint (struct perf_event **cpu_events) +void unregister_wide_hw_breakpoint (struct perf_event *__percpu *cpu_events) {int cpu;struct perf_event **pevent;
samples/hw_breakpoint/data_breakpoint.c +3 -3
@@ -34,7 +34,7 @@#include <linux/perf_event.h> #include <linux/hw_breakpoint.h> -struct perf_event **sample_hbp; +struct perf_event *__percpu *sample_hbp;static char ksym_name[KSYM_NAME_LEN ] ="pid_max" ;module_param_string (ksym, ksym_name,KSYM_NAME_LEN ,S_IRUGO );
@@ -61,8 +61,8 @@ static int __init hw_break_module_init(void) attr.bp_type =HW_BREAKPOINT_W |HW_BREAKPOINT_R ; sample_hbp =register_wide_hw_breakpoint (&attr, sample_hbp_handler); -if (IS_ERR (sample_hbp)) { - ret =PTR_ERR (sample_hbp); +if (IS_ERR ((void __force *)sample_hbp)) { + ret =PTR_ERR ((void __force *)sample_hbp); goto fail; }
Signature · 1 line
1.6.2.3
PATCH 2/5 perf lock: Fix and add misc documentally things
In reply to Frederic WeisbeckerFrom: Hitoshi Mitake <[email protected]>
I've forgot to add 'perf lock' line to command-list.txt, so users of perf could not find perf lock when they type 'perf'.
Fixing command-list.txt requires document (tools/perf/Documentation/perf-lock.txt).
But perf lock is too much "under construction" to write a stable document, so this is something like pseudo document for now.
And I wrote description of perf lock at help section of CONFIG_LOCK_STAT, this will navigate users of lock trace events.
LKML-Reference: <[email protected]>
--- lib/Kconfig.debug | 6 ++++++ tools/perf/Documentation/perf-lock.txt | 29 +++++++++++++++++++++++++++++ tools/perf/command-list.txt | 1 + 3 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 tools/perf/Documentation/perf-lock.txt
lib/Kconfig.debug +6 -0
@@ -520,6 +520,12 @@ config LOCK_STAT For more details, see Documentation/lockstat.txt + You can analyze lock events with "perf lock", subcommand of perf. + If you want to use "perf lock", you need to turn on CONFIG_EVENT_TRACING. + + CONFIG_LOCK_STAT defines "contended" and "acquired" lock events. + (CONFIG_LOCKDEP defines "acquire" and "release" events.) + config DEBUG_LOCKDEP bool "Lock dependency engine debugging" depends on DEBUG_KERNEL && LOCKDEP
tools/perf/Documentation/perf-lock.txt new file +29 -0
@@ -0,0 +1,29 @@ +perf-lock(1) +============ + +NAME +---- +perf-lock - Analyze lock events + +SYNOPSIS +-------- +[verse] +'perf lock' {record|report|trace} + +DESCRIPTION +----------- +You can analyze various lock behaviours +and statistics with this 'perf lock' command. + + 'perf lock record <command>' records lock events + between start and end <command>. And this command + produces the file "perf.data" which contains tracing + results of lock events. + + 'perf lock trace' shows raw lock events. + + 'perf lock report' reports statistical data. + +SEE ALSO +-------- +linkperf:perf[1]
tools/perf/command-list.txt +1 -0
@@ -18,3 +18,4 @@ perf-top mainporcelain common perf-trace mainporcelain common perf-probe mainporcelain common perf-kmem mainporcelain common +perf-lock mainporcelain common
Signature · 1 line
1.6.2.3
PATCH 3/5 perf lock: Drop the buffers multiplexing dependency
In reply to Frederic WeisbeckerWe need to deal with time ordered events to build a correct state machine of lock events. This is why we multiplex the lock events buffers. But the ordering is done from the kernel, on the tracing fast path, leading to high contention between cpus.
Without multiplexing, the events appears in a weak order. If we have four events, each split per cpu, perf record will read the events buffers in the following order:
[ CPU0 ev0, CPU0 ev1, CPU0 ev3, CPU0 ev4, CPU1 ev0, CPU1 ev0....]
To handle a post processing reordering, we could just read and sort the whole in memory, but it just doesn't scale with high amounts of events: lock events can fill huge amounts in few times.
Basically we need to sort in memory and find a "grace period" point when we know that a given slice of previously sorted events can be committed for post-processing, so that we can unload the memory usage step by step and keep a scalable sorting list.
There is no strong rules about how to define such "grace period". What does this patch is:
We define a FLUSH_PERIOD value that defines a grace period in seconds.
We want to have a slice of events covering 2 * FLUSH_PERIOD in our sorted list.
If FLUSH_PERIOD is big enough, it ensures every events that occured in the first half of the timeslice have all been buffered and there are none remaining and there won't be further to put inside this first timeslice. Then once we reach the 2 * FLUSH_PERIOD timeslice, we flush the first half to be gentle with the memory (the second half can still get new events in the middle, so wait another period to flush it)
FLUSH_PERIOD is defined to 5 seconds. Say the first event started on time t0. We can safely assume that at the time we are processing events of t0 + 10 seconds, ther won't be anymore events to read from perf.data that occured between t0 and t0 + 5 seconds. Hence we can safely flush the first half.
To point out funky bugs, we have a guardian that checks a new event timestamp is not below the last event's timestamp flushed and that displays a warning in this case.
--- tools/perf/builtin-lock.c | 148 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 146 insertions(+), 2 deletions(-)
tools/perf/builtin-lock.c +146 -2
@@ -460,6 +460,150 @@ process_raw_event(void *data, int cpu,process_lock_release_event (data, event, cpu, timestamp, thread); } +struct raw_event_queue { +u64 timestamp; +int cpu; +void *data; +struct thread *thread; +struct list_head list; +}; + +static LIST_HEAD (raw_event_head); + +#define FLUSH_PERIOD (5 * NSEC_PER_SEC) + +static u64 flush_limit =ULLONG_MAX ; +static u64 last_flush =0 ; +struct raw_event_queue *last_inserted; + +static void flush_raw_event_queue (u64 limit) +{ +struct raw_event_queue *tmp, *iter; + +list_for_each_entry_safe (iter, tmp, &raw_event_head, list) { +if (iter->timestamp > limit) +return ; + +if (iter == last_inserted) + last_inserted =NULL ; + +process_raw_event (iter->data, iter->cpu, iter->timestamp, + iter->thread); + + last_flush = iter->timestamp; +list_del (&iter->list); +free (iter->data); +free (iter); + } +} + +static void __queue_raw_event_end (struct raw_event_queue *new) +{ +struct raw_event_queue *iter; + +list_for_each_entry_reverse (iter, &raw_event_head, list) { +if (iter->timestamp < new->timestamp) { +list_add (&new->list, &iter->list); +return ; + } + } + +list_add (&new->list, &raw_event_head); +} + +static void __queue_raw_event_before (struct raw_event_queue *new, +struct raw_event_queue *iter) +{ +list_for_each_entry_continue_reverse (iter, &raw_event_head, list) { +if (iter->timestamp < new->timestamp) { +list_add (&new->list, &iter->list); +return ; + } + } + +list_add (&new->list, &raw_event_head); +} + +static void __queue_raw_event_after (struct raw_event_queue *new, +struct raw_event_queue *iter) +{ +list_for_each_entry_continue (iter, &raw_event_head, list) { +if (iter->timestamp > new->timestamp) { +list_add_tail (&new->list, &iter->list); +return ; + } + } +list_add_tail (&new->list, &raw_event_head); +} + +/* The queue is ordered by time */ +static void __queue_raw_event (struct raw_event_queue *new) +{ +if (!last_inserted) { +__queue_raw_event_end (new); +return ; + } + +/* +* Most of the time the current event has a timestamp +* very close to the last event inserted, unless we just switched +* to another event buffer. Having a sorting based on a list and +* on the last inserted event that is close to the current one is +* probably more efficient than an rbtree based sorting. +*/ +if (last_inserted->timestamp >= new->timestamp) +__queue_raw_event_before (new, last_inserted); +else +__queue_raw_event_after (new, last_inserted); +} + +static void queue_raw_event (void *data,int raw_size,int cpu, +u64 timestamp,struct thread *thread) +{ +struct raw_event_queue *new; + +if (flush_limit ==ULLONG_MAX ) + flush_limit = timestamp +FLUSH_PERIOD ; + +if (timestamp < last_flush) { +printf ("Warning: Timestamp below last timeslice flush\n" ); +return ; + } + + new =malloc (sizeof (*new)); +if (!new) +die ("Not enough memory\n" ); + + new->timestamp = timestamp; + new->cpu = cpu; + new->thread = thread; + + new->data =malloc (raw_size); +if (!new->data) +die ("Not enough memory\n" ); + +memcpy (new->data, data, raw_size); + +__queue_raw_event (new); + last_inserted = new; + +/* +* We want to have a slice of events covering 2 * FLUSH_PERIOD +* If FLUSH_PERIOD is big enough, it ensures every events that occured +* in the first half of the timeslice have all been buffered and there +* are none remaining (we need that because of the weakly ordered +* event recording we have). Then once we reach the 2 * FLUSH_PERIOD +* timeslice, we flush the first half to be gentle with the memory +* (the second half can still get new events in the middle, so wait +* another period to flush it) +*/ +if (new->timestamp > flush_limit && + new->timestamp - flush_limit >FLUSH_PERIOD ) { + flush_limit +=FLUSH_PERIOD ; +flush_raw_event_queue (flush_limit); + } +} +static int process_sample_event (event_t *event,struct perf_session *session) {struct thread *thread;
@@ -480,7 +624,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)if (profile_cpu !=-1 && profile_cpu != (int ) data.cpu)return 0 ; -process_raw_event (data.raw_data, data.cpu, data.time, thread); +queue_raw_event (data.raw_data, data.raw_size, data.cpu, data.time, thread);return 0 ; }
@@ -576,6 +720,7 @@ static void __cmd_report(void)setup_pager ();select_key ();read_events (); +flush_raw_event_queue (ULLONG_MAX );sort_result ();print_result (); }
@@ -608,7 +753,6 @@ static const char *record_args[] = {"record" ,"-a" ,"-R" , -"-M" ,"-f" ,"-m" ,"1024" , "-c", "1",
Signature · 1 line
1.6.2.3
PATCH 4/5 perf: Remove pointless breakpoint union
In reply to Frederic WeisbeckerRemove pointless union in the breakpoint field of hw_perf_event.
--- include/linux/perf_event.h | 5 ++--- lib/Kconfig.debug | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/perf_event.h +2 -3
@@ -487,9 +487,8 @@ struct hw_perf_event {struct hrtimer hrtimer; };#ifdef CONFIG_HAVE_HW_BREAKPOINT -union {/* breakpoint */ -struct arch_hw_breakpoint info; - }; +/* breakpoint */ +struct arch_hw_breakpoint info;#endif };atomic64_t prev_count;
lib/Kconfig.debug +5 -3
@@ -520,11 +520,13 @@ config LOCK_STAT For more details, see Documentation/lockstat.txt - You can analyze lock events with "perf lock", subcommand of perf. - If you want to use "perf lock", you need to turn on CONFIG_EVENT_TRACING. + This also enables lock events required by "perf lock", + subcommand of perf. + If you want to use "perf lock", you also need to turn on + CONFIG_EVENT_TRACING. CONFIG_LOCK_STAT defines "contended" and "acquired" lock events. - (CONFIG_LOCKDEP defines "acquire" and "release" events.) + (CONFIG_LOCKDEP defines "acquire" and "release" events.) config DEBUG_LOCKDEP bool "Lock dependency engine debugging"
Signature · 1 line
1.6.2.3
PATCH 5/5 x86/hw-breakpoints: Remove the name field
In reply to Frederic WeisbeckerRemove the name field from the arch_hw_breakpoint. We never deal with target symbols in the arch level, neither do we need to ever store it. It's a legacy for the previous version of the x86 breakpoint backend.
Let's remove it.
--- arch/x86/include/asm/hw_breakpoint.h | 1 - arch/x86/kernel/hw_breakpoint.c | 7 ------- 2 files changed, 0 insertions(+), 8 deletions(-)
arch/x86/include/asm/hw_breakpoint.h +0 -1
@@ -10,7 +10,6 @@* (display/resolving) */ struct arch_hw_breakpoint { -char *name;/* Contains name of the symbol to set bkpt */ unsigned long address;u8 len;u8 type;
arch/x86/kernel/hw_breakpoint.c +0 -7
@@ -344,13 +344,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp, }/* -* For kernel-addresses, either the address or symbol name can be -* specified. -*/ -if (info->name) - info->address = (unsigned long ) -kallsyms_lookup_name (info->name); -/* * Check that the low-order bits of the address are appropriate * for the alignment implied by len. */
Signature · 1 line
1.6.2.3