perf/core: don't find side-band event from all pmus
PATCH v2 1/1 perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
perf_event_aux funciton goes through all pmus and all events in whatever contexts to find the side-band event to output, which is unnecessary and expensive.
For example, the brk test case in lkp triggers many mmap operations, at the time, perf with cycles:pp is also running on the system. As a result, many perf_event_aux are invoked, and each would search all pmus and all events. If we enable the uncore support (even when uncore event are not really used), dozens of uncore pmus will be added into pmus list, which can significantly decrease brk_test's ops_per_sec. Based on our test, the ops_per_sec without uncore patch is 2647573, while the ops_per_sec with uncore patch is only 1768444, which is a 33.2% reduction.
To get at the per cpu side-band event, this patch put the side-band events to four categories, which are tracked by 4 per-cpu lists. It only finds the interested events from masked category.
To get at the per task side-band event, each task context for current task will be searched. Because we don't want to go update more global state on context switch.
---
The V1 patch is "perf/core: find auxiliary events in running pmus list"
https://lkml.org/lkml/2016/2/24/961.
This V2 patch almost changes everything compare with V1.
The V2 patch is mainly based on Peter's suggestion. But I didn't rename perf_event_aux to perf_event_sb. Because it looks there are many aux things in the codes, e.g. AUX area in ring buffer. I'm not sure if we need to change all aux to sb. We may do the rename later in separate patch.
include/linux/perf_event.h | 26 +++++++++ kernel/events/core.c | 135 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 144 insertions(+), 17 deletions(-)
include/linux/perf_event.h +26 -0
@@ -437,6 +437,31 @@ struct swevent_hlist {struct perf_cgroup ;struct ring_buffer ; +struct pmu_event_list { +raw_spinlock_t lock; +struct list_head list; +}; + +/* +* {mmap,mmap_data,mmap2} -> mmap +* {comm,comm_exec} -> comm +* task +* context_switch +*/ +enum event_sb_channel { + sb_mmap =0 , + sb_comm, + sb_task, + sb_switch, + + sb_nr, +}; + +#define IS_SB_MMAP (attr) \ + (attr.mmap || attr.mmap_data || attr.mmap2) +#define IS_SB_COMM (attr) \ + (attr.comm || attr.comm_exec) +/** * struct perf_event - performance event kernel representation: */
@@ -589,6 +614,7 @@ struct perf_event {int cgrp_defer_enabled;#endif +struct list_head sb_list[sb_nr];#endif /* CONFIG_PERF_EVENTS */ };
kernel/events/core.c +118 -17
233 lines not on this page · raw message
Signature · 1 line
2.5.0
Peter Zijlstra
maintainerQuoted 4 lines · On Wed, Mar 23, 2016 at 11:24:37AM -0700, [email protected] wrote:
The V2 patch is mainly based on Peter's suggestion. But I didn't rename
perf_event_auxtoperf_event_sb. Because it looks there are many aux things in the codes, e.g. AUX area in ring buffer. I'm not sure if we need to change all aux to sb. We may do the rename later in separate patch.
Right.. no problem doing that in a separate patch.
Quoted 14 lines
kernel/events/core.c +12
-0+static void perf_event_sb_mask (unsigned int sb_mask, +perf_event_aux_output_cb output, +void *data) +{ +int sb; + +for (sb =0 ; sb < sb_nr; sb++) { +if (!(sb_mask & (1 << sb))) +continue ; +perf_event_sb_iterate (sb, output, data); + } +}
kernel/events/core.c static void perf_event_task(struct task_struct *task, · line 5915
Quoted 7 lines
kernel/events/core.c +2
-1@@ -5852,7 +5910,8 @@ static void perf_event_task(struct task_struct *task,perf_event_aux (perf_event_task_output, &task_event, - task_ctx); + task_ctx, + (1 << sb_task) | (1 << sb_mmap) | (1 << sb_comm)); }
So one side-effect of this change is that the above event can be delivered 3 times if you're 'lucky'.
Acme; does userspace care?
Quoted 28 lines
Quoted 16 lines
kernel/events/core.c +12
-0+static void perf_event_sb_mask (unsigned int sb_mask, +perf_event_aux_output_cb output, +void *data) +{ +int sb; + +for (sb =0 ; sb < sb_nr; sb++) { +if (!(sb_mask & (1 << sb))) +continue ; +perf_event_sb_iterate (sb, output, data); + } +}kernel/events/core.c static void perf_event_task(struct task_struct · line 5916
Quoted 8 lines
kernel/events/core.c +2
-1@@ -5852,7 +5910,8 @@ static void perf_event_task(struct task_struct *task,perf_event_aux (perf_event_task_output, &task_event, - task_ctx); + task_ctx, + (1 << sb_task) | (1 << sb_mmap) | (1 << sb_comm)); }So one side-effect of this change is that the above event can be delivered 3 times if you're 'lucky'.
Quoted 1 line
Acme; does userspace care?
Hi Arnaldo,
Do you think if it's an issue for userspace?
Thanks,
Kan
[email protected]
maintainerEm Thu, Mar 31, 2016 at 02:05:46PM +0000, Liang, Kan escreveu:
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
kernel/events/core.c +12
-0+static void perf_event_sb_mask (unsigned int sb_mask, +perf_event_aux_output_cb output, +void *data) +{ +int sb; + +for (sb =0 ; sb < sb_nr; sb++) { +if (!(sb_mask & (1 << sb))) +continue ; +perf_event_sb_iterate (sb, output, data); + } +}kernel/events/core.c static void perf_event_task(struct task_struct · line 5916
Quoted 8 lines
kernel/events/core.c +2
-1@@ -5852,7 +5910,8 @@ static void perf_event_task(struct task_struct *task,perf_event_aux (perf_event_task_output, &task_event, - task_ctx); + task_ctx, + (1 << sb_task) | (1 << sb_mmap) | (1 << sb_comm)); }So one side-effect of this change is that the above event can be delivered 3 times if you're 'lucky'.
Quoted 5 lines
Quoted 1 line
Acme; does userspace care?
Hi Arnaldo,
Do you think if it's an issue for userspace?
Trying to get context and decode what you guys wrote...
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Tue, Mar 29, 2016 at 02:06:09PM +0200, Peter Zijlstra escreveu:
Quoted 33 lines · On Wed, Mar 23, 2016 at 11:24:37AM -0700, [email protected] wrote:
Quoted 4 lines
The V2 patch is mainly based on Peter's suggestion. But I didn't rename
perf_event_auxtoperf_event_sb. Because it looks there are many aux things in the codes, e.g. AUX area in ring buffer. I'm not sure if we need to change all aux to sb. We may do the rename later in separate patch.Right.. no problem doing that in a separate patch.
Quoted 14 lines
kernel/events/core.c +12
-0+static void perf_event_sb_mask (unsigned int sb_mask, +perf_event_aux_output_cb output, +void *data) +{ +int sb; + +for (sb =0 ; sb < sb_nr; sb++) { +if (!(sb_mask & (1 << sb))) +continue ; +perf_event_sb_iterate (sb, output, data); + } +}kernel/events/core.c static void perf_event_task(struct task_struct *task, · line 5915
Quoted 7 lines
kernel/events/core.c +2
-1@@ -5852,7 +5910,8 @@ static void perf_event_task(struct task_struct *task,perf_event_aux (perf_event_task_output, &task_event, - task_ctx); + task_ctx, + (1 << sb_task) | (1 << sb_mmap) | (1 << sb_comm)); }So one side-effect of this change is that the above event can be delivered 3 times if you're 'lucky'.
Quoted 1 line
Acme; does userspace care?
So, when processing a PERF_RECORD_FORK there is some sanity checks in machine__process_fork_event() (tools/perf/util/machine.c), and one that is affected by copies is:
struct thread *thread = machine__find_thread(machine,
event->fork.pid,
event->fork.tid);
<SNIP>
/* if a thread currently exists for the thread id remove it */
if (thread != NULL) {
machine__remove_thread(machine, thread);
thread__put(thread);
}
thread = machine__findnew_thread(machine, event->fork.pid,
event->fork.tid);<SNIP>
So we conceivably may end up with multiple 'struct thread' pointing to the same kernel thread, being held as references somewhere (in a hist_entry, for instance, if a PERF_RECORD_SAMPLE happens mid sentence).
It probably will cope, but can't we just emit one single record?
PERF_RECORD_EXIT are ok:
int machine__process_exit_event(struct machine *machine, union perf_event *event,
struct perf_sample *sample __maybe_unused)
{
struct thread *thread = machine__find_thread(machine,
event->fork.pid,
event->fork.tid);
if (dump_trace)
perf_event__fprintf_task(event, stdout);
if (thread != NULL) {
thread__exited(thread);
thread__put(thread);
}
return 0;
}PERF_RECORD_COMM will unecessarily add a new COMM to its list, leading tooling to think that there was a prctl(PR_SET_NAME). This could conceivably be annoyed away by checking if the "new" COMM is the current one, again, can't the kernel emit just one record?
- Arnaldo
Peter Zijlstra
maintainerQuoted 1 line · Arnaldo Carvalho de Melo
It probably will cope, but can't we just emit one single record?
I'll try and figure something out...
Peter Zijlstra
maintainerQuoted 4 lines · Peter Zijlstra
Quoted 1 line · Arnaldo Carvalho de Melo
It probably will cope, but can't we just emit one single record?
I'll try and figure something out...
less clever but probably good enough..
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700
perf_event_aux funciton goes through all pmus and all events in whatever contexts to find the side-band event to output, which is unnecessary and expensive.
For example, the brk test case in lkp triggers many mmap operations, at the time, perf with cycles:pp is also running on the system. As a result, many perf_event_aux are invoked, and each would search all pmus and all events. If we enable the uncore support (even when uncore event are not really used), dozens of uncore pmus will be added into pmus list, which can significantly decrease brk_test's ops_per_sec. Based on our test, the ops_per_sec without uncore patch is 2647573, while the ops_per_sec with uncore patch is only 1768444, which is a 33.2% reduction.
To get at the per cpu side-band event, this patch put the side-band events to four categories, which are tracked by 4 per-cpu lists. It only finds the interested events from masked category.
To get at the per task side-band event, each task context for current task will be searched. Because we don't want to go update more global state on context switch.
---
The V1 patch is "perf/core: find auxiliary events in running pmus list"
https://lkml.org/lkml/2016/2/24/961.
This V2 patch almost changes everything compare with V1.
The V2 patch is mainly based on Peter's suggestion. But I didn't rename perf_event_aux to perf_event_sb. Because it looks there are many aux things in the codes, e.g. AUX area in ring buffer. I'm not sure if we need to change all aux to sb. We may do the rename later in separate patch.
include/linux/perf_event.h | 26 ++++++++ kernel/events/core.c | 134 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 143 insertions(+), 17 deletions(-)
include/linux/perf_event.h +26 -0
@@ -437,6 +437,31 @@ struct swevent_hlist {struct perf_cgroup ;struct ring_buffer ; +struct pmu_event_list { +raw_spinlock_t lock; +struct list_head list; +}; + +/* +* {mmap,mmap_data,mmap2} -> mmap +* {comm,comm_exec} -> comm +* task +* context_switch +*/ +enum event_sb_channel { + sb_mmap =0 , + sb_comm, + sb_task, + sb_switch, + + sb_nr, +}; + +#define IS_SB_MMAP (attr) \ + (attr.mmap || attr.mmap_data || attr.mmap2) +#define IS_SB_COMM (attr) \ + (attr.comm || attr.comm_exec) +/** * struct perf_event - performance event kernel representation: */
@@ -589,6 +614,7 @@ struct perf_event {int cgrp_defer_enabled;#endif +struct list_head sb_list[sb_nr];#endif /* CONFIG_PERF_EVENTS */ };
kernel/events/core.c +117 -17
231 lines not on this page · raw message
Peter Zijlstra
maintainerQuoted 7 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Arnaldo Carvalho de Melo
It probably will cope, but can't we just emit one single record?
I'll try and figure something out...
less clever but probably good enough..
I'm an idiot; quilt refresh is needed..
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700
perf_event_aux funciton goes through all pmus and all events in whatever contexts to find the side-band event to output, which is unnecessary and expensive.
For example, the brk test case in lkp triggers many mmap operations, at the time, perf with cycles:pp is also running on the system. As a result, many perf_event_aux are invoked, and each would search all pmus and all events. If we enable the uncore support (even when uncore event are not really used), dozens of uncore pmus will be added into pmus list, which can significantly decrease brk_test's ops_per_sec. Based on our test, the ops_per_sec without uncore patch is 2647573, while the ops_per_sec with uncore patch is only 1768444, which is a 33.2% reduction.
To get at the per cpu side-band event, this patch put the side-band events to four categories, which are tracked by 4 per-cpu lists. It only finds the interested events from masked category.
To get at the per task side-band event, each task context for current task will be searched. Because we don't want to go update more global state on context switch.
---
include/linux/perf_event.h | 6 +++ kernel/events/core.c | 87 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 13 deletions(-)
include/linux/perf_event.h +6 -0
@@ -437,6 +437,11 @@ struct swevent_hlist {struct perf_cgroup ;struct ring_buffer ; +struct pmu_event_list { +raw_spinlock_t lock; +struct list_head list; +}; +/** * struct perf_event - performance event kernel representation: */
@@ -589,6 +594,7 @@ struct perf_event {int cgrp_defer_enabled;#endif +struct list_head sb_list;#endif /* CONFIG_PERF_EVENTS */ };
kernel/events/core.c +74 -13
150 lines not on this page · raw message
Peter Zijlstra
maintainerQuoted 7 lines · Peter Zijlstra
I'm an idiot; quilt refresh is needed..
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700
Kan, does this patch work for you?
Quoted 17 lines
-----Original Message-----
From: Peter Zijlstra [mailto:[email protected]]
Sent: Wednesday, April 06, 2016 4:10 AM
To: Arnaldo Carvalho de Melo <[email protected]>
Cc: Liang, Kan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH V2 1/1] perf/core: don't find side-band event from all pmusQuoted 2 lines · Peter Zijlstra
I'm an idiot; quilt refresh is needed..
Quoted 7 lines
Quoted 5 lines
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700Kan, does this patch work for you?
Yes. I did some tests on my machine. It looks good.
Thanks,
Kan
Quoted 7 lines
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700
Hi Peter,
Is there something wrong with the patch?
The last time I saw this patch was in your personal tree (kernel/git/peterz/queue.git). But now I cannot find it anymore.
Thanks,
Kan
Quoted 35 lines
perf_event_auxfunciton goes through all pmus and all events in whatever contexts to find the side-band event to output, which is unnecessary and expensive.For example, the brk test case in lkp triggers many mmap operations, at the time, perf with cycles:pp is also running on the system. As a result, many
perf_event_auxare invoked, and each would search all pmus and all events. If we enable the uncore support (even when uncore event are not really used), dozens of uncore pmus will be added into pmus list, which can significantly decrease brk_test'sops_per_sec. Based on our test, theops_per_secwithout uncore patch is 2647573, while theops_per_secwith uncore patch is only 1768444, which is a 33.2% reduction.To get at the per cpu side-band event, this patch put the side-band events to four categories, which are tracked by 4 per-cpu lists. It only finds the interested events from masked category.
To get at the per task side-band event, each task context for current task will be searched. Because we don't want to go update more global state on context switch.Reported-by Huang, Ying <[email protected]>Suggested-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Kan Liang <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Peter Zijlstra
maintainerQuoted 7 lines · Kan
Quoted 7 lines
---
Subject: perf/core: don't find side-band event from all pmus
From: Kan Liang <[email protected]>
Date: Wed, 23 Mar 2016 11:24:37 -0700
Quoted 5 lines
Hi Peter,
Is there something wrong with the patch?
The last time I saw this patch was in your personal tree (kernel/git/peterz/queue.git). But now I cannot find it anymore.
Hurm; I seem to have lost it, sorry about that.
Let me go find where its gone.
tip-bot for Kan Liang
merge bot[tip:perf/core] perf/core: Optimize side-band event delivery
In reply to [email protected]perf/core: Optimize side-band event delivery
Commit-ID: f2fb6bef92514432398a653df1c2f1041d79ac46 Gitweb: http://git.kernel.org/tip/f2fb6bef92514432398a653df1c2f1041d79ac46 Author: Kan Liang <[email protected]> AuthorDate: Wed, 23 Mar 2016 11:24:37 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 3 Jun 2016 09:40:15 +0200
perf/core: Optimize side-band event delivery
The perf_event_aux() function iterates all PMUs and all events in their respective per-CPU contexts to find the events to deliver side-band records to.
For example, the brk test case in lkp triggers many mmap() operations, which, if we're also running perf, results in many perf_event_aux() invocations.
If we enable uncore PMU support (even when uncore events are not used), dozens of uncore PMUs will be iterated, which can significantly decrease brk_test's throughput.
For example, the brk throughput:
without uncore PMUs: 2647573 ops_per_sec
with uncore PMUs: 1768444 ops_per_sec
... a 33% reduction.
To get at the per-CPU events that need side-band records, this patch puts these events on a per-CPU list, this avoids iterating the PMUs and any events that do not need side-band records.
Per task events are unchanged to avoid extra overhead on the context switch paths.
--- include/linux/perf_event.h | 6 ++++ kernel/events/core.c | 85 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 12 deletions(-)
include/linux/perf_event.h +6 -0
@@ -517,6 +517,11 @@ struct swevent_hlist {struct perf_cgroup ;struct ring_buffer ; +struct pmu_event_list { +raw_spinlock_t lock; +struct list_head list; +}; +/** * struct perf_event - performance event kernel representation: */
@@ -675,6 +680,7 @@ struct perf_event {int cgrp_defer_enabled;#endif +struct list_head sb_list;#endif /* CONFIG_PERF_EVENTS */ };
kernel/events/core.c +73 -12
142 lines not on this page · raw message