perf fixes
Subsystems (2)
Ingo,
Please pull the perf/urgent branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgent
It fixes the conflict against latest linus's tree that raised build errors (you can find a merge commit inside).
I am not yet totally sure about Peter's opinion concerning the context switch event that is now captured from the kernel. Our latest discussion on the strict exclude_kernel meaning seems in favour of this change but I'd prefer to wait for his final approval before you pull this.
(I'm not reposting the alignment fix as it is unchanged)
Thanks,
Frederic
---
Frederic Weisbecker (2):
perf: Correctly align perf event tracing buffer
perf: Use hot regs with software sched switch/migrate events
Jason Wessel (1):
x86,kgdb: Always initialize the hw breakpoint attribute
arch/x86/kernel/cpu/perf_event.c | 2 -- arch/x86/kernel/kgdb.c | 2 +- include/linux/perf_event.h | 21 ++++++++++++++------- kernel/perf_event.c | 4 +--- kernel/trace/trace_event_perf.c | 11 +++++++++-- 5 files changed, 25 insertions(+), 15 deletions(-)
PATCH v2 1/2 perf: Use hot regs with software sched switch/migrate events
Scheduler's task migration events don't work because they always pass NULL regs perf_sw_event(). The event hence gets filtered in perf_swevent_add().
Scheduler's context switches events use task_pt_regs() to get the context when the event occured which is a wrong thing to do as this won't give us the place in the kernel where we went to sleep but the place where we left userspace. The result is even more wrong if we switch from a kernel thread.
Use the hot regs snapshot for both events as they belong to the non-interrupt/exception based events family. Unlike page faults or so that provide the regs matching the exact origin of the event, we need to save the current context.
This makes the task migration event working and fix the context switch callchains and origin ip.
Example: perf record -a -e cs
Before:
10.91% ksoftirqd/0 0 [k] 0000000000000000
|
--- (nil)
perf_callchain
perf_prepare_sample
__perf_event_overflow
perf_swevent_overflow
perf_swevent_add
perf_swevent_ctx_event
do_perf_sw_event
__perf_sw_event
perf_event_task_sched_out
schedule
run_ksoftirqd
kthread
kernel_thread_helperAfter:
23.77% hald-addon-stor [kernel.kallsyms] [k] schedule
|
--- schedule
|
|--60.00%-- schedule_timeout
| wait_for_common
| wait_for_completion
| blk_execute_rq
| scsi_execute
| scsi_execute_req
| sr_test_unit_ready
| |
| |--66.67%-- sr_media_change
| | media_changed
| | cdrom_media_changed
| | sr_block_media_changed
| | check_disk_change
| | cdrom_open
v2: Always build perf_arch_fetch_caller_regs() now that software events need that too. They don't need it from modules, unlike trace events, so we keep the EXPORT_SYMBOL in trace_event_perf.c
--- arch/x86/kernel/cpu/perf_event.c | 2 -- include/linux/perf_event.h | 21 ++++++++++++++------- kernel/perf_event.c | 4 +--- 3 files changed, 15 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/perf_event.c +0 -2
@@ -1702,7 +1702,6 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)return entry; } -#ifdef CONFIG_EVENT_TRACING void perf_arch_fetch_caller_regs (struct pt_regs *regs,unsigned long ip,int skip) { regs->ip = ip;
@@ -1714,4 +1713,3 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski regs->cs = __KERNEL_CS;local_save_flags (regs->flags); } -#endif
include/linux/perf_event.h +14 -7
@@ -842,13 +842,6 @@ extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX];extern void __perf_sw_event (u32 ,u64 ,int ,struct pt_regs *,u64 ); -static inline void -perf_sw_event (u32 event_id,u64 nr,int nmi,struct pt_regs *regs,u64 addr) -{ -if (atomic_read (&perf_swevent_enabled[event_id])) -__perf_sw_event (event_id, nr, nmi, regs, addr); -} -extern void perf_arch_fetch_caller_regs (struct pt_regs *regs,unsigned long ip,int skip);
@@ -887,6 +880,20 @@ static inline void perf_fetch_caller_regs(struct pt_regs *regs, int skip)return perf_arch_fetch_caller_regs (regs, ip, skip); } +static inline void +perf_sw_event (u32 event_id,u64 nr,int nmi,struct pt_regs *regs,u64 addr) +{ +if (atomic_read (&perf_swevent_enabled[event_id])) { +struct pt_regs hot_regs; + +if (!regs) { +perf_fetch_caller_regs (&hot_regs,1 ); + regs = &hot_regs; + } +__perf_sw_event (event_id, nr, nmi, regs, addr); + } +} +extern void __perf_event_mmap (struct vm_area_struct *vma);static inline void perf_event_mmap (struct vm_area_struct *vma)
kernel/perf_event.c +1 -3
@@ -1164,11 +1164,9 @@ void perf_event_task_sched_out(struct task_struct *task,struct perf_event_context *ctx = task->perf_event_ctxp;struct perf_event_context *next_ctx;struct perf_event_context *parent; -struct pt_regs *regs;int do_switch =1 ; - regs =task_pt_regs (task); -perf_sw_event (PERF_COUNT_SW_CONTEXT_SWITCHES ,1 ,1 , regs,0 ); +perf_sw_event (PERF_COUNT_SW_CONTEXT_SWITCHES ,1 ,1 ,NULL ,0 );if (likely (!ctx || !cpuctx->task_ctx))return ;
Signature · 1 line
1.6.2.3
PATCH 2/2 x86,kgdb: Always initialize the hw breakpoint attribute
In reply to Frederic WeisbeckerFrom: Jason Wessel <[email protected]>
It is required to call hw_breakpoint_init() on an attr before using it in any other calls. This fixes the problem where kgdb will sometimes fail to initialize on x86_64.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/kgdb.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/kgdb.c +1 -1
@@ -618,8 +618,8 @@ int kgdb_arch_init(void)* portion of kgdb because this operation requires mutexs to * complete. */ +hw_breakpoint_init (&attr); attr.bp_addr = (unsigned long )kgdb_arch_init; - attr.type =PERF_TYPE_BREAKPOINT ; attr.bp_len =HW_BREAKPOINT_LEN_1 ; attr.bp_type =HW_BREAKPOINT_W ; attr.disabled =1 ;
Signature · 1 line
1.6.2.3
Quoted 6 lines · Frederic Weisbecker
Ingo,
Please pull the perf/urgent branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgent
I have updated the tree. There was a leftover patch for perf/core inside (not listed here). Also, since you've merged linus tree in perf/urgent lately, I've zapped my merge commit. Other than that, the three fixes remain.
Thanks.
Quoted 30 lines
It fixes the conflict against latest linus's tree that raised build errors (you can find a merge commit inside).
I am not yet totally sure about Peter's opinion concerning the context switch event that is now captured from the kernel. Our latest discussion on the strict
exclude_kernelmeaning seems in favour of this change but I'd prefer to wait for his final approval before you pull this.(I'm not reposting the alignment fix as it is unchanged)
Thanks,
Frederic
---Frederic Weisbecker (2):
perf: Correctly align perf event tracing buffer
perf: Use hot regs with software sched switch/migrate eventsJason Wessel (1):
x86,kgdb: Always initialize the hw breakpoint attributearch/x86/kernel/cpu/perf_event.c | 2 -- arch/x86/kernel/kgdb.c | 2 +- include/linux/perf_event.h | 21 ++++++++++++++------- kernel/perf_event.c | 4 +--- kernel/trace/trace_event_perf.c | 11 +++++++++-- 5 files changed, 25 insertions(+), 15 deletions(-)
Quoted 9 lines · Frederic Weisbecker
Quoted 6 lines · Frederic Weisbecker
Ingo,
Please pull the perf/urgent branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgent
Quoted 6 lines
I have updated the tree. There was a leftover patch for perf/core inside (not listed here). Also, since you've merged linus tree in perf/urgent lately, I've zapped my merge commit. Other than that, the three fixes remain.
Thanks.
Pulled, thanks Frederic!
Note, i also queued up this patch from Edwin:
257ef9d: perf, x86: Fix callgraphs of 32-bit processes on 64-bit kernels
with your Acked-by added.
Thanks,
Ingo
Quoted 23 lines · Ingo Molnar
Quoted 9 lines · Frederic Weisbecker
Quoted 6 lines · Frederic Weisbecker
Ingo,
Please pull the perf/urgent branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgentQuoted 6 lines
I have updated the tree. There was a leftover patch for perf/core inside (not listed here). Also, since you've merged linus tree in perf/urgent lately, I've zapped my merge commit. Other than that, the three fixes remain.
Thanks.
Pulled, thanks Frederic!
Note, i also queued up this patch from Edwin:
Quoted 7 lines
257ef9d: perf, x86: Fix callgraphs of 32-bit processes on 64-bit kernels
with your Acked-by added.
Thanks,
Ingo
Ah ok. I was too cautious and eventually queued it for perf/core, but if you think it's fine, no problem.
Thanks.