Skip to content

Commit 1e0fb9e

Browse files
amlutoIngo Molnar
authored andcommitted
perf: Add pmu callbacks to track event mapping and unmapping
Signed-off-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Vince Weaver <vince@deater.net> Cc: "hillf.zj" <hillf.zj@alibaba-inc.com> Cc: Valdis Kletnieks <Valdis.Kletnieks@vt.edu> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/266afcba1d1f91ea5501e4e16e94bbbc1a9339b6.1414190806.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 22c4bd9 commit 1e0fb9e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/linux/perf_event.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ struct pmu {
202202
*/
203203
int (*event_init) (struct perf_event *event);
204204

205+
/*
206+
* Notification that the event was mapped or unmapped. Called
207+
* in the context of the mapping task.
208+
*/
209+
void (*event_mapped) (struct perf_event *event); /*optional*/
210+
void (*event_unmapped) (struct perf_event *event); /*optional*/
211+
205212
#define PERF_EF_START 0x01 /* start the counter when adding */
206213
#define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
207214
#define PERF_EF_UPDATE 0x04 /* update the counter when stopping */

kernel/events/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,9 @@ static void perf_mmap_open(struct vm_area_struct *vma)
42934293

42944294
atomic_inc(&event->mmap_count);
42954295
atomic_inc(&event->rb->mmap_count);
4296+
4297+
if (event->pmu->event_mapped)
4298+
event->pmu->event_mapped(event);
42964299
}
42974300

42984301
/*
@@ -4312,6 +4315,9 @@ static void perf_mmap_close(struct vm_area_struct *vma)
43124315
int mmap_locked = rb->mmap_locked;
43134316
unsigned long size = perf_data_size(rb);
43144317

4318+
if (event->pmu->event_unmapped)
4319+
event->pmu->event_unmapped(event);
4320+
43154321
atomic_dec(&rb->mmap_count);
43164322

43174323
if (!atomic_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex))
@@ -4513,6 +4519,9 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
45134519
vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND | VM_DONTDUMP;
45144520
vma->vm_ops = &perf_mmap_vmops;
45154521

4522+
if (event->pmu->event_mapped)
4523+
event->pmu->event_mapped(event);
4524+
45164525
return ret;
45174526
}
45184527

0 commit comments

Comments
 (0)