perf: Split it some more
cover perf: Split it some more
From: Borislav Petkov <[email protected]>
Hi guys,
here's some more perf_event.c splitting, more specifically cgroup and callchain-related stuff. Builds fine here. I'll add the persistent.c stuff later after cooking it a bit longer and incorporating the latest review comments.
The two patches are also available in a pullable form:
git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git perf-split
Thanks.
PATCH 1/2 perf: Carve out cgroup-related code
From: Borislav Petkov <[email protected]>
Move cgroup perf support into a different compilation module - kernel/events/cgroup.c - thus slimming perf_event.c some more.
While at it,
* push some oneliners into perf_event.h now that they're used in multiple .c files.
* drop is_cgroup_event() check for perf_cgroup_defer_enabled() at its callsite in __perf_event_enable since the latter does the check anyway.
No functional change.
--- include/linux/perf_event.h | 126 +++++++++++- kernel/events/Makefile | 1 + kernel/events/cgroup.c | 324 +++++++++++++++++++++++++++++ kernel/events/core.c | 496 +------------------------------------------- 4 files changed, 461 insertions(+), 486 deletions(-) create mode 100644 kernel/events/cgroup.c
include/linux/perf_event.h +125 -1
@@ -954,8 +954,15 @@ struct perf_output_handle {int sample; }; +enum event_type_t { +EVENT_FLEXIBLE =0x1 , +EVENT_PINNED =0x2 , +EVENT_ALL =EVENT_FLEXIBLE |EVENT_PINNED , +}; +#ifdef CONFIG_PERF_EVENTS +extern struct list_head pmus;extern int perf_pmu_register (struct pmu *pmu,char *name,int type);extern void perf_pmu_unregister (struct pmu *pmu);
@@ -1153,6 +1160,47 @@ extern void perf_swevent_put_recursion_context(int rctx);extern void perf_event_enable (struct perf_event *event);extern void perf_event_disable (struct perf_event *event);extern void perf_event_task_tick (void ); + +static inline struct perf_cpu_context * +__get_cpu_context (struct perf_event_context *ctx) +{ +return this_cpu_ptr (ctx->pmu->pmu_cpu_context); +} + +static inline u64 perf_clock (void ) +{ +return local_clock (); +} + +extern void ctx_sched_out (struct perf_event_context *ctx, +struct perf_cpu_context *cpuctx, +enum event_type_t event_type); +/* +* Called with IRQs disabled +*/ +static inline void cpu_ctx_sched_out (struct perf_cpu_context *cpuctx, +enum event_type_t event_type) +{ +ctx_sched_out (&cpuctx->ctx, cpuctx, event_type); +} + +extern void ctx_sched_in (struct perf_event_context *ctx, +struct perf_cpu_context *cpuctx, +enum event_type_t event_type, +struct task_struct *task); + +static inline void cpu_ctx_sched_in (struct perf_cpu_context *cpuctx, +enum event_type_t event_type, +struct task_struct *task) +{ +struct perf_event_context *ctx = &cpuctx->ctx; + +ctx_sched_in (ctx, cpuctx, event_type, task); +} + +extern int +task_function_call (struct task_struct *p,int (*func) (void *info),void *info); +extern u64 perf_event_time (struct perf_event *event);#else static inline void perf_event_task_sched_in (struct task_struct *task) { }
@@ -1187,7 +1235,83 @@ static inline void perf_swevent_put_recursion_context(int rctx) { }static inline void perf_event_enable (struct perf_event *event) { }static inline void perf_event_disable (struct perf_event *event) { }static inline void perf_event_task_tick (void ) { } -#endif +#endif /* CONFIG_PERF_EVENTS */ + +#ifdef CONFIG_CGROUP_PERF +extern struct perf_cgroup * +perf_cgroup_from_task (struct task_struct *task); +extern bool perf_cgroup_match (struct perf_event *event); +extern int +perf_cgroup_connect (pid_t pid,struct perf_event *event, +struct perf_event_attr *attr, +struct perf_event *group_leader); +extern void perf_detach_cgroup (struct perf_event *event); + +static inline int is_cgroup_event (struct perf_event *event) +{ +return event->cgrp !=NULL ; +} + +extern u64 perf_cgroup_event_time (struct perf_event *event); +extern void update_cgrp_time_from_event (struct perf_event *event); +extern void +update_cgrp_time_from_cpuctx (struct perf_cpu_context *cpuctx); +extern void +perf_cgroup_set_timestamp (struct task_struct *task, +struct perf_event_context *ctx); + +extern void perf_cgroup_sched_out (struct task_struct *task); +extern void perf_cgroup_sched_in (struct task_struct *task); + +static inline void +perf_cgroup_set_shadow_time (struct perf_event *event,u64 now) +{ +struct perf_cgroup_info *t; + t =per_cpu_ptr (event->cgrp->info, event->cpu); + event->shadow_ctx_time = now - t->timestamp; +} + +static inline void +perf_cgroup_defer_enabled (struct perf_event *event) +{ +/* +* when the current task's perf cgroup does not match +* the event's, we need to remember to call the +* perf_mark_enable() function the first time a task with +* a matching perf cgroup is scheduled in. +*/ +if (is_cgroup_event (event) && !perf_cgroup_match (event)) + event->cgrp_defer_enabled =1 ; +} +extern inline void +perf_cgroup_mark_enabled (struct perf_event *event, +struct perf_event_context *ctx); +#else +static inline struct perf_cgroup * +perf_cgroup_from_task (struct task_struct *task) {return NULL ; } +static inline bool perf_cgroup_match (struct perf_event *event) {return true; } +static inline int +perf_cgroup_connect (pid_t pid,struct perf_event *event, +struct perf_event_attr *attr, +struct perf_event *group_leader) {return -EINVAL ; } +static inline void perf_detach_cgroup (struct perf_event *event) { } +static inline int is_cgroup_event (struct perf_event *event) {return 0 ; } +static inline u64 perf_cgroup_event_time (struct perf_event *event) {return 0 ; } +static inline void update_cgrp_time_from_event (struct perf_event *e) { } +static inline void +update_cgrp_time_from_cpuctx (struct perf_cpu_context *cpuctx) { } +static inline void +perf_cgroup_set_timestamp (struct task_struct *task, +struct perf_event_context *ctx) { } +static inline void perf_cgroup_sched_out (struct task_struct *task) { } +static inline void perf_cgroup_sched_in (struct task_struct *task) { } +static inline void +perf_cgroup_set_shadow_time (struct perf_event *event,u64 now) { } +static inline void perf_cgroup_defer_enabled (struct perf_event *event) { } +static inline void +perf_cgroup_mark_enabled (struct perf_event *event, +struct perf_event_context *ctx) { } +#endif /* CONFIG_CGROUP_PERF */ #define perf_output_put (handle, x) perf_output_copy((handle), &(x), sizeof(x))
kernel/events/Makefile +1 -0
@@ -4,3 +4,4 @@ endif obj-y := core.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +obj-$(CONFIG_CGROUP_PERF) += cgroup.o
kernel/events/cgroup.c new file +324 -0
324 lines not on this page · raw message
kernel/events/core.c +11 -485
566 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
Re: [PATCH 1/2] perf: Carve out cgroup-related code
(Adding Stephane in Cc)
Quoted 10 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Move cgroup perf support into a different compilation module -
kernel/events/cgroup.c- thus slimmingperf_event.csome more.While at it,
* push some oneliners into
perf_event.hnow that they're used in multiple .c files.
Quoted 6 lines
* drop
is_cgroup_event()check forperf_cgroup_defer_enabled()at its callsite in__perf_event_enablesince the latter does the check anyway.No functional change.
Signed-off-by Borislav Petkov <[email protected]>
BTW, before you do it yourself, I have a patch pending that splits the buffer part from the core.
Just to avoid effort duplicates... :)
Re: [PATCH 1/2] perf: Carve out cgroup-related code
Quoted 2 lines · Frederic Weisbecker
BTW, before you do it yourself, I have a patch pending that splits the buffer part from the core.
Cool. But no, callchain.c and cgroup.c were the low hanging fruits I saw so I have no plans for the buffer part. Go ahead and send it too.
Quoted 1 line
Just to avoid effort duplicates... :)
Yep.
Signature · 8 lines
Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
PATCH 2/2 perf: Carve out callchain functionality
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Move callchain-related code into its own module:kernel/events/callchain.c
No functionality change.
--- include/linux/perf_event.h | 7 +- kernel/events/Makefile | 2 +- kernel/events/callchain.c | 182 +++++++++++++++++++++++++++++++++ kernel/events/core.c | 237 +++++-------------------------------------- 4 files changed, 217 insertions(+), 211 deletions(-) create mode 100644 kernel/events/callchain.c
include/linux/perf_event.h +6 -1
@@ -961,7 +961,6 @@ enum event_type_t { };#ifdef CONFIG_PERF_EVENTS -extern struct list_head pmus;extern int perf_pmu_register (struct pmu *pmu,char *name,int type);extern void perf_pmu_unregister (struct pmu *pmu);
@@ -1201,6 +1200,12 @@ static inline void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx,extern int task_function_call (struct task_struct *p,int (*func) (void *info),void *info);extern u64 perf_event_time (struct perf_event *event); + +extern int get_recursion_context (int *recursion); +extern inline void put_recursion_context (int *recursion,int rctx); +extern void put_callchain_buffers (void ); +extern struct perf_callchain_entry *perf_callchain (struct pt_regs *regs); +extern int get_callchain_buffers (void );#else static inline void perf_event_task_sched_in (struct task_struct *task) { }
kernel/events/Makefile +1 -1
@@ -2,6 +2,6 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_core.o = -pg endif -obj-y := core.o +obj-y := core.o callchain.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_CGROUP_PERF) += cgroup.o
kernel/events/callchain.c new file +182 -0
182 lines not on this page · raw message
kernel/events/core.c +28 -209
249 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
Re: [PATCH 2/2] perf: Carve out callchain functionality
Quoted 29 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Move callchain-related code into its own module:
kernel/events/callchain.cNo functionality change.
Signed-off-by Borislav Petkov <[email protected]>--- include/linux/perf_event.h | 7 +- kernel/events/Makefile | 2 +- kernel/events/callchain.c | 182 +++++++++++++++++++++++++++++++++ kernel/events/core.c | 237 +++++-------------------------------------- 4 files changed, 217 insertions(+), 211 deletions(-) create mode 100644 kernel/events/callchain.cinclude/linux/perf_event.h +0
-1@@ -961,7 +961,6 @@ enum event_type_t { };#ifdef CONFIG_PERF_EVENTS -extern struct list_head pmus;extern int perf_pmu_register (struct pmu *pmu,char *name,int type);extern void perf_pmu_unregister (struct pmu *pmu);
include/linux/perf_event.h static inline void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx, · line 1208
Quoted 9 lines
include/linux/perf_event.h +6
-0@@ -1201,6 +1200,12 @@ static inline void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx,extern int task_function_call (struct task_struct *p,int (*func) (void *info),void *info);extern u64 perf_event_time (struct perf_event *event); + +extern int get_recursion_context (int *recursion); +extern inline void put_recursion_context (int *recursion,int rctx); +extern void put_callchain_buffers (void ); +extern struct perf_callchain_entry *perf_callchain (struct pt_regs *regs); +extern int get_callchain_buffers (void );
I think it would be better to have these in a private kernel/events/events.h
Other than that, looks good, thanks.
Re: [PATCH 2/2] perf: Carve out callchain functionality
Quoted 9 lines · Frederic Weisbecker
include/linux/perf_event.h static inline void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx, · line 1208
Quoted 5 lines
include/linux/perf_event.h +5
-0+extern int get_recursion_context (int *recursion); +extern inline void put_recursion_context (int *recursion,int rctx); +extern void put_callchain_buffers (void ); +extern struct perf_callchain_entry *perf_callchain (struct pt_regs *regs); +extern int get_callchain_buffers (void );I think it would be better to have these in a private
kernel/events/events.hOther than that, looks good, thanks.
Yeah, I suggested a new header originally too but Ingo wanted to keep perf_event.h as is, for now.
Quoted 1 line
Thanks.
Signature · 8 lines
Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632