/* * Performance events core code: * * Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de> * Copyright (C) 2008-2011 Red Hat, Inc., Ingo Molnar * Copyright (C) 2008-2011 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> * Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com> * * For licensing details see kernel-base/COPYING */ #include <linux/fs.h>#include <linux/mm.h>#include <linux/cpu.h>#include <linux/smp.h>#include <linux/idr.h>#include <linux/file.h>#include <linux/poll.h>#include <linux/slab.h>#include <linux/hash.h>#include <linux/sysfs.h>#include <linux/dcache.h>#include <linux/percpu.h>#include <linux/ptrace.h>#include <linux/reboot.h>#include <linux/vmstat.h>#include <linux/device.h>#include <linux/export.h>#include <linux/vmalloc.h>#include <linux/hardirq.h>#include <linux/rculist.h>#include <linux/uaccess.h>#include <linux/syscalls.h>#include <linux/anon_inodes.h>#include <linux/kernel_stat.h>#include <linux/perf_event.h>#include <linux/ftrace_event.h>#include <linux/hw_breakpoint.h> #include "internal.h" #include <asm/irq_regs.h> struct remote_function_call { struct task_struct *p; int (*func)(void *info); void *info; int ret;}; static void remote_function(void *data){ struct remote_function_call *tfc = data; struct task_struct *p = tfc->p; if (p) { tfc->ret = -EAGAIN; if (task_cpu(p) != smp_processor_id() || !task_curr(p)) return; } tfc->ret = tfc->func(tfc->info);} /** * task_function_call - call a function on the cpu on which a task runs * @p: the task to evaluate * @func: the function to be called * @info: the function call argument * * Calls the function @func when the task is currently running. This might * be on the current CPU, which just calls the function directly * * returns: @func return value, or * -ESRCH - when the process isn't running * -EAGAIN - when the process moved away */static inttask_function_call(struct task_struct *p, int (*func) (void *info), void *info){ struct remote_function_call data = { .p = p, .func = func, .info = info, .ret = -ESRCH, /* No such (running) process */ }; if (task_curr(p)) smp_call_function_single(task_cpu(p), remote_function, &data, 1); return data.ret;} /** * cpu_function_call - call a function on the cpu * @func: the function to be called * @info: the function call argument * * Calls the function @func on the remote cpu. * * returns: @func return value or -ENXIO when the cpu is offline */static int cpu_function_call(int cpu, int (*func) (void *info), void *info){ struct remote_function_call data = { .p = NULL, .func = func, .info = info, .ret = -ENXIO, /* No such CPU */ }; smp_call_function_single(cpu, remote_function, &data, 1); return data.ret;} #define PERF_FLAG_ALL (PERF_FLAG_FD_NO_GROUP |\ PERF_FLAG_FD_OUTPUT |\ PERF_FLAG_PID_CGROUP) enum event_type_t { EVENT_FLEXIBLE = 0x1, EVENT_PINNED = 0x2, EVENT_ALL = EVENT_FLEXIBLE | EVENT_PINNED,}; /* * perf_sched_events : >0 events exist * perf_cgroup_events: >0 per-cpu cgroup events exist on this cpu */struct jump_label_key_deferred perf_sched_events __read_mostly;static DEFINE_PER_CPU(atomic_t, perf_cgroup_events); static atomic_t nr_mmap_events __read_mostly;static atomic_t nr_comm_events __read_mostly;static atomic_t nr_task_events __read_mostly; static LIST_HEAD(pmus);static DEFINE_MUTEX(pmus_lock);static struct srcu_struct pmus_srcu; /* * perf event paranoia level: * -1 - not paranoid at all * 0 - disallow raw tracepoint access for unpriv * 1 - disallow cpu events for unpriv * 2 - disallow kernel profiling for unpriv */int sysctl_perf_event_paranoid __read_mostly = 1; /* Minimum for 512 kiB + 1 user control page */int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */ /* * max perf event sample rate */#define DEFAULT_MAX_SAMPLE_RATE 100000int sysctl_perf_event_sample_rate __read_mostly = DEFAULT_MAX_SAMPLE_RATE;static int max_samples_per_tick __read_mostly = DIV_ROUND_UP(DEFAULT_MAX_SAMPLE_RATE, HZ); int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos){ int ret = proc_dointvec(table, write, buffer, lenp, ppos); if (ret || !write) return ret; max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ); return 0;} static atomic64_t perf_event_id; static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx, enum event_type_t event_type); static void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx, enum event_type_t event_type, struct task_struct *task); static void update_context_time(struct perf_event_context *ctx);static u64 perf_event_time(struct perf_event *event); static void ring_buffer_attach(struct perf_event *event, struct ring_buffer *rb); void __weak perf_event_print_debug(void) { } extern __weak const char *perf_pmu_name(void){ return "pmu";} static inline u64 perf_clock(void){ return local_clock();} static inline struct perf_cpu_context *__get_cpu_context(struct perf_event_context *ctx){ return this_cpu_ptr(ctx->pmu->pmu_cpu_context);} static void perf_ctx_lock(struct perf_cpu_context *cpuctx, struct perf_event_context *ctx){ raw_spin_lock(&cpuctx->ctx.lock); if (ctx) raw_spin_lock(&ctx->lock);} static void perf_ctx_unlock(struct perf_cpu_context *cpuctx, struct perf_event_context *ctx){ if (ctx) raw_spin_unlock(&ctx->lock); raw_spin_unlock(&cpuctx->ctx.lock);} #ifdef CONFIG_CGROUP_PERF /* * Must ensure cgroup is pinned (css_get) before calling * this function. In other words, we cannot call this function * if there is no cgroup event for the current CPU context. */static inline struct perf_cgroup *perf_cgroup_from_task(struct task_struct *task){ return container_of(task_subsys_state(task, perf_subsys_id), struct perf_cgroup, css);} static inline boolperf_cgroup_match(struct perf_event *event){ struct perf_event_context *ctx = event->ctx; struct perf_cpu_context *cpuctx = __get_cpu_context(ctx); return !event->cgrp || event->cgrp == cpuctx->cgrp;} static inline void perf_get_cgroup(struct perf_event *event){ css_get(&event->cgrp->css);} static inline void perf_put_cgroup(struct perf_event *event){ css_put(&event->cgrp->css);} static inline void perf_detach_cgroup(struct perf_event *event){ perf_put_cgroup(event); event->cgrp = NULL;} static inline int is_cgroup_event(struct perf_event *event){ return event->cgrp != NULL;} static inline u64 perf_cgroup_event_time(struct perf_event *event){ struct perf_cgroup_info *t; t = per_cpu_ptr(event->cgrp->info, event->cpu); return t->time;} static inline void __update_cgrp_time(struct perf_cgroup *cgrp){ struct perf_cgroup_info *info; u64 now; now = perf_clock(); info = this_cpu_ptr(cgrp->info); info->time += now - info->timestamp; info->timestamp = now;} static inline void update_cgrp_time_from_cpuctx(struct perf_cpu_context *cpuctx){ struct perf_cgroup *cgrp_out = cpuctx->cgrp; if (cgrp_out) __update_cgrp_time(cgrp_out);} static inline void update_cgrp_time_from_event(struct perf_event *event){ struct perf_cgroup *cgrp; /* * ensure we access cgroup data only when needed and * when we know the cgroup is pinned (css_get) */ if (!is_cgroup_event(event)) return; cgrp = perf_cgroup_from_task(current); /* * Do not update time when cgroup is not active */ if (cgrp == event->cgrp) __update_cgrp_time(event->cgrp);} static inline voidperf_cgroup_set_timestamp(struct task_struct *task, struct perf_event_context *ctx){ struct perf_cgroup *cgrp; struct perf_cgroup_info *info; /* * ctx->lock held by caller * ensure we do not access cgroup data * unless we have the cgroup pinned (css_get) */ if (!task || !ctx->nr_cgroups) return; cgrp = perf_cgroup_from_task(task); info = this_cpu_ptr(cgrp->info); info->timestamp = ctx->timestamp;} #define PERF_CGROUP_SWOUT 0x1 /* cgroup switch out every event */#define PERF_CGROUP_SWIN 0x2 /* cgroup switch in events based on task */ /* * reschedule events based on the cgroup constraint of task. * * mode SWOUT : schedule out everything * mode SWIN : schedule in based on cgroup for next */void perf_cgroup_switch(struct task_struct *task, int mode){ struct perf_cpu_context *cpuctx; struct pmu *pmu; unsigned long flags; /* * disable interrupts to avoid geting nr_cgroup * changes via __perf_event_disable(). Also * avoids preemption. */ local_irq_save(flags); /* * we reschedule only in the presence of cgroup * constrained events. */ rcu_read_lock(); list_for_each_entry_rcu(pmu, &pmus, entry) { cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); /* * perf_cgroup_events says at least one * context on this CPU has cgroup events. * * ctx->nr_cgroups reports the number of cgroup * events for a context. */ if (cpuctx->ctx.nr_cgroups > 0) { perf_ctx_lock(cpuctx, cpuctx->task_ctx); perf_pmu_disable(cpuctx->ctx.pmu); if (mode & PERF_CGROUP_SWOUT) { cpu_ctx_sched_out(cpuctx, EVENT_ALL); /* * must not be done before ctxswout due * to event_filter_match() in event_sched_out() */ cpuctx->cgrp = NULL; } if (mode & PERF_CGROUP_SWIN) { WARN_ON_ONCE(cpuctx->cgrp); /* set cgrp before ctxsw in to * allow event_filter_match() to not * have to pass task around */ cpuctx->cgrp = perf_cgroup_from_task(task); cpu_ctx_sched_in(cpuctx, EVENT_ALL, task); } perf_pmu_enable(cpuctx->ctx.pmu); perf_ctx_unlock(cpuctx, cpuctx->task_ctx); } } rcu_read_unlock(); local_irq_restore(flags);} static inline void perf_cgroup_sched_out(struct task_struct *task, struct task_struct *next){ struct perf_cgroup *cgrp1; struct perf_cgroup *cgrp2 = NULL; /* * we come here when we know perf_cgroup_events > 0 */ cgrp1 = perf_cgroup_from_task(task); /* * next is NULL when called from perf_event_enable_on_exec() * that will systematically cause a cgroup_switch() */ if (next) cgrp2 = perf_cgroup_from_task(next); /* * only schedule out current cgroup events if we know * that we are switching to a different cgroup. Otherwise, * do no touch the cgroup events. */ if (cgrp1 != cgrp2) perf_cgroup_switch(task, PERF_CGROUP_SWOUT);} static inline void perf_cgroup_sched_in(struct task_struct *prev, struct task_struct *task){ struct perf_cgroup *cgrp1; struct perf_cgroup *cgrp2 = NULL; /* * we come here when we know perf_cgroup_events > 0 */ cgrp1 = perf_cgroup_from_task(task); /* prev can never be NULL */ cgrp2 = perf_cgroup_from_task(prev); /* * only need to schedule in cgroup events if we are changing * cgroup during ctxsw. Cgroup events were not scheduled * out of ctxsw out if that was not the case. */ if (cgrp1 != cgrp2) perf_cgroup_switch(task, PERF_CGROUP_SWIN);} static inline int perf_cgroup_connect(int fd, struct perf_event *event, struct perf_event_attr *attr, struct perf_event *group_leader){ struct perf_cgroup *cgrp; struct cgroup_subsys_state *css; struct file *file; int ret = 0, fput_needed; file = fget_light(fd, &fput_needed); if (!file) return -EBADF; css = cgroup_css_from_dir(file, perf_subsys_id); if (IS_ERR(css)) { ret = PTR_ERR(css); goto out; } cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp; /* must be done before we fput() the file */ perf_get_cgroup(event); /* * all events in a group must monitor * the same cgroup because a task belongs * to only one perf cgroup at a time */ if (group_leader && group_leader->cgrp != cgrp) { perf_detach_cgroup(event); ret = -EINVAL; }out: fput_light(file, fput_needed); return ret;} static inline voidperf_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;Lines 1–500 of 7012. Load more
/* * Performance events core code: * * Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de> * Copyright (C) 2008-2011 Red Hat, Inc., Ingo Molnar * Copyright (C) 2008-2011 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> * Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com> * * For licensing details see kernel-base/COPYING */ #include <linux/fs.h> #include <linux/mm.h> #include <linux/cpu.h> #include <linux/smp.h> #include <linux/idr.h> #include <linux/file.h> #include <linux/poll.h> #include <linux/slab.h> #include <linux/hash.h> #include <linux/sysfs.h> #include <linux/dcache.h> #include <linux/percpu.h> #include <linux/ptrace.h> #include <linux/reboot.h> #include <linux/vmstat.h> #include <linux/device.h> #include <linux/export.h> #include <linux/vmalloc.h> #include <linux/hardirq.h> #include <linux/rculist.h> #include <linux/uaccess.h> #include <linux/syscalls.h> #include <linux/anon_inodes.h> #include <linux/kernel_stat.h> #include <linux/perf_event.h> #include <linux/ftrace_event.h> #include <linux/hw_breakpoint.h> #include "internal.h" #include <asm/irq_regs.h> struct remote_function_call { struct task_struct *p; int (*func)(void *info); void *info; int ret; }; static void remote_function(void *data) { struct remote_function_call *tfc = data; struct task_struct *p = tfc->p; if (p) { tfc->ret = -EAGAIN; if (task_cpu(p) != smp_processor_id() || !task_curr(p)) return; } tfc->ret = tfc->func(tfc->info); } /** * task_function_call - call a function on the cpu on which a task runs * @p: the task to evaluate * @func: the function to be called * @info: the function call argument * * Calls the function @func when the task is currently running. This might * be on the current CPU, which just calls the function directly * * returns: @func return value, or * -ESRCH - when the process isn't running * -EAGAIN - when the process moved away */ static int task_function_call(struct task_struct *p, int (*func) (void *info), void *info) { struct remote_function_call data = { .p = p, .func = func, .info = info, .ret = -ESRCH, /* No such (running) process */ }; if (task_curr(p)) smp_call_function_single(task_cpu(p), remote_function, &data, 1); return data.ret; } /** * cpu_function_call - call a function on the cpu * @func: the function to be called * @info: the function call argument * * Calls the function @func on the remote cpu. * * returns: @func return value or -ENXIO when the cpu is offline */ static int cpu_function_call(int cpu, int (*func) (void *info), void *info) { struct remote_function_call data = { .p = NULL, .func = func, .info = info, .ret = -ENXIO, /* No such CPU */ }; smp_call_function_single(cpu, remote_function, &data, 1); return data.ret; } #define PERF_FLAG_ALL (PERF_FLAG_FD_NO_GROUP |\ PERF_FLAG_FD_OUTPUT |\ PERF_FLAG_PID_CGROUP) enum event_type_t { EVENT_FLEXIBLE = 0x1, EVENT_PINNED = 0x2, EVENT_ALL = EVENT_FLEXIBLE | EVENT_PINNED, }; /* * perf_sched_events : >0 events exist * perf_cgroup_events: >0 per-cpu cgroup events exist on this cpu */ struct jump_label_key_deferred perf_sched_events __read_mostly; static DEFINE_PER_CPU(atomic_t, perf_cgroup_events); static atomic_t nr_mmap_events __read_mostly; static atomic_t nr_comm_events __read_mostly; static atomic_t nr_task_events __read_mostly; static LIST_HEAD(pmus); static DEFINE_MUTEX(pmus_lock); static struct srcu_struct pmus_srcu; /* * perf event paranoia level: * -1 - not paranoid at all * 0 - disallow raw tracepoint access for unpriv * 1 - disallow cpu events for unpriv * 2 - disallow kernel profiling for unpriv */ int sysctl_perf_event_paranoid __read_mostly = 1; /* Minimum for 512 kiB + 1 user control page */ int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */ /* * max perf event sample rate */ #define DEFAULT_MAX_SAMPLE_RATE 100000 int sysctl_perf_event_sample_rate __read_mostly = DEFAULT_MAX_SAMPLE_RATE; static int max_samples_per_tick __read_mostly = DIV_ROUND_UP(DEFAULT_MAX_SAMPLE_RATE, HZ); int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { int ret = proc_dointvec(table, write, buffer, lenp, ppos); if (ret || !write) return ret; max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ); return 0; } static atomic64_t perf_event_id; static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx, enum event_type_t event_type); static void cpu_ctx_sched_in(struct perf_cpu_context *cpuctx, enum event_type_t event_type, struct task_struct *task); static void update_context_time(struct perf_event_context *ctx); static u64 perf_event_time(struct perf_event *event); static void ring_buffer_attach(struct perf_event *event, struct ring_buffer *rb); void __weak perf_event_print_debug(void) { } extern __weak const char *perf_pmu_name(void) { return "pmu"; } static inline u64 perf_clock(void) { return local_clock(); } static inline struct perf_cpu_context * __get_cpu_context(struct perf_event_context *ctx) { return this_cpu_ptr(ctx->pmu->pmu_cpu_context); } static void perf_ctx_lock(struct perf_cpu_context *cpuctx, struct perf_event_context *ctx) { raw_spin_lock(&cpuctx->ctx.lock); if (ctx) raw_spin_lock(&ctx->lock); } static void perf_ctx_unlock(struct perf_cpu_context *cpuctx, struct perf_event_context *ctx) { if (ctx) raw_spin_unlock(&ctx->lock); raw_spin_unlock(&cpuctx->ctx.lock); } #ifdef CONFIG_CGROUP_PERF /* * Must ensure cgroup is pinned (css_get) before calling * this function. In other words, we cannot call this function * if there is no cgroup event for the current CPU context. */ static inline struct perf_cgroup * perf_cgroup_from_task(struct task_struct *task) { return container_of(task_subsys_state(task, perf_subsys_id), struct perf_cgroup, css); } static inline bool perf_cgroup_match(struct perf_event *event) { struct perf_event_context *ctx = event->ctx; struct perf_cpu_context *cpuctx = __get_cpu_context(ctx); return !event->cgrp || event->cgrp == cpuctx->cgrp; } static inline void perf_get_cgroup(struct perf_event *event) { css_get(&event->cgrp->css); } static inline void perf_put_cgroup(struct perf_event *event) { css_put(&event->cgrp->css); } static inline void perf_detach_cgroup(struct perf_event *event) { perf_put_cgroup(event); event->cgrp = NULL; } static inline int is_cgroup_event(struct perf_event *event) { return event->cgrp != NULL; } static inline u64 perf_cgroup_event_time(struct perf_event *event) { struct perf_cgroup_info *t; t = per_cpu_ptr(event->cgrp->info, event->cpu); return t->time; } static inline void __update_cgrp_time(struct perf_cgroup *cgrp) { struct perf_cgroup_info *info; u64 now; now = perf_clock(); info = this_cpu_ptr(cgrp->info); info->time += now - info->timestamp; info->timestamp = now; } static inline void update_cgrp_time_from_cpuctx(struct perf_cpu_context *cpuctx) { struct perf_cgroup *cgrp_out = cpuctx->cgrp; if (cgrp_out) __update_cgrp_time(cgrp_out); } static inline void update_cgrp_time_from_event(struct perf_event *event) { struct perf_cgroup *cgrp; /* * ensure we access cgroup data only when needed and * when we know the cgroup is pinned (css_get) */ if (!is_cgroup_event(event)) return; cgrp = perf_cgroup_from_task(current); /* * Do not update time when cgroup is not active */ if (cgrp == event->cgrp) __update_cgrp_time(event->cgrp); } static inline void perf_cgroup_set_timestamp(struct task_struct *task, struct perf_event_context *ctx) { struct perf_cgroup *cgrp; struct perf_cgroup_info *info; /* * ctx->lock held by caller * ensure we do not access cgroup data * unless we have the cgroup pinned (css_get) */ if (!task || !ctx->nr_cgroups) return; cgrp = perf_cgroup_from_task(task); info = this_cpu_ptr(cgrp->info); info->timestamp = ctx->timestamp; } #define PERF_CGROUP_SWOUT 0x1 /* cgroup switch out every event */ #define PERF_CGROUP_SWIN 0x2 /* cgroup switch in events based on task */ /* * reschedule events based on the cgroup constraint of task. * * mode SWOUT : schedule out everything * mode SWIN : schedule in based on cgroup for next */ void perf_cgroup_switch(struct task_struct *task, int mode) { struct perf_cpu_context *cpuctx; struct pmu *pmu; unsigned long flags; /* * disable interrupts to avoid geting nr_cgroup * changes via __perf_event_disable(). Also * avoids preemption. */ local_irq_save(flags); /* * we reschedule only in the presence of cgroup * constrained events. */ rcu_read_lock(); list_for_each_entry_rcu(pmu, &pmus, entry) { cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); /* * perf_cgroup_events says at least one * context on this CPU has cgroup events. * * ctx->nr_cgroups reports the number of cgroup * events for a context. */ if (cpuctx->ctx.nr_cgroups > 0) { perf_ctx_lock(cpuctx, cpuctx->task_ctx); perf_pmu_disable(cpuctx->ctx.pmu); if (mode & PERF_CGROUP_SWOUT) { cpu_ctx_sched_out(cpuctx, EVENT_ALL); /* * must not be done before ctxswout due * to event_filter_match() in event_sched_out() */ cpuctx->cgrp = NULL; } if (mode & PERF_CGROUP_SWIN) { WARN_ON_ONCE(cpuctx->cgrp); /* set cgrp before ctxsw in to * allow event_filter_match() to not * have to pass task around */ cpuctx->cgrp = perf_cgroup_from_task(task); cpu_ctx_sched_in(cpuctx, EVENT_ALL, task); } perf_pmu_enable(cpuctx->ctx.pmu); perf_ctx_unlock(cpuctx, cpuctx->task_ctx); } } rcu_read_unlock(); local_irq_restore(flags); } static inline void perf_cgroup_sched_out(struct task_struct *task, struct task_struct *next) { struct perf_cgroup *cgrp1; struct perf_cgroup *cgrp2 = NULL; /* * we come here when we know perf_cgroup_events > 0 */ cgrp1 = perf_cgroup_from_task(task); /* * next is NULL when called from perf_event_enable_on_exec() * that will systematically cause a cgroup_switch() */ if (next) cgrp2 = perf_cgroup_from_task(next); /* * only schedule out current cgroup events if we know * that we are switching to a different cgroup. Otherwise, * do no touch the cgroup events. */ if (cgrp1 != cgrp2) perf_cgroup_switch(task, PERF_CGROUP_SWOUT); } static inline void perf_cgroup_sched_in(struct task_struct *prev, struct task_struct *task) { struct perf_cgroup *cgrp1; struct perf_cgroup *cgrp2 = NULL; /* * we come here when we know perf_cgroup_events > 0 */ cgrp1 = perf_cgroup_from_task(task); /* prev can never be NULL */ cgrp2 = perf_cgroup_from_task(prev); /* * only need to schedule in cgroup events if we are changing * cgroup during ctxsw. Cgroup events were not scheduled * out of ctxsw out if that was not the case. */ if (cgrp1 != cgrp2) perf_cgroup_switch(task, PERF_CGROUP_SWIN); } static inline int perf_cgroup_connect(int fd, struct perf_event *event, struct perf_event_attr *attr, struct perf_event *group_leader) { struct perf_cgroup *cgrp; struct cgroup_subsys_state *css; struct file *file; int ret = 0, fput_needed; file = fget_light(fd, &fput_needed); if (!file) return -EBADF; css = cgroup_css_from_dir(file, perf_subsys_id); if (IS_ERR(css)) { ret = PTR_ERR(css); goto out; } cgrp = container_of(css, struct perf_cgroup, css); event->cgrp = cgrp; /* must be done before we fput() the file */ perf_get_cgroup(event); /* * all events in a group must monitor * the same cgroup because a task belongs * to only one perf cgroup at a time */ if (group_leader && group_leader->cgrp != cgrp) { perf_detach_cgroup(event); ret = -EINVAL; } out: fput_light(file, fput_needed); return ret; } 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;