perf: Simplify/fix perf_event_enable() event scheduling
authorPeter Zijlstra <peterz@infradead.org>
Fri, 8 Jan 2016 09:45:11 +0000 (10:45 +0100)
committerIngo Molnar <mingo@kernel.org>
Thu, 21 Jan 2016 17:54:22 +0000 (18:54 +0100)
Like perf_enable_on_exec(), perf_event_enable() event scheduling has problems
respecting the context hierarchy when trying to schedule events (for
example, it will try and add a pinned event without first removing
existing flexible events).

So simplify it by using the new ctx_resched() call which will DTRT.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/events/core.c

index 12f1d4a52da9f817ad58123505e7b4c004b42d46..079eb9fcaaa8a622449747435934cb002b777010 100644 (file)
@@ -2188,7 +2188,7 @@ static int __perf_event_enable(void *info)
        struct perf_event_context *ctx = event->ctx;
        struct perf_event *leader = event->group_leader;
        struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
-       int err;
+       struct perf_event_context *task_ctx = cpuctx->task_ctx;
 
        /*
         * There's a time window between 'ctx->is_active' check
@@ -2202,7 +2202,8 @@ static int __perf_event_enable(void *info)
        if (!ctx->is_active)
                return -EINVAL;
 
-       raw_spin_lock(&ctx->lock);
+       perf_ctx_lock(cpuctx, task_ctx);
+       WARN_ON_ONCE(&cpuctx->ctx != ctx && task_ctx != ctx);
        update_context_time(ctx);
 
        if (event->state >= PERF_EVENT_STATE_INACTIVE)
@@ -2228,32 +2229,10 @@ static int __perf_event_enable(void *info)
        if (leader != event && leader->state != PERF_EVENT_STATE_ACTIVE)
                goto unlock;
 
-       if (!group_can_go_on(event, cpuctx, 1)) {
-               err = -EEXIST;
-       } else {
-               if (event == leader)
-                       err = group_sched_in(event, cpuctx, ctx);
-               else
-                       err = event_sched_in(event, cpuctx, ctx);
-       }
-
-       if (err) {
-               /*
-                * If this event can't go on and it's part of a
-                * group, then the whole group has to come off.
-                */
-               if (leader != event) {
-                       group_sched_out(leader, cpuctx, ctx);
-                       perf_mux_hrtimer_restart(cpuctx);
-               }
-               if (leader->attr.pinned) {
-                       update_group_times(leader);
-                       leader->state = PERF_EVENT_STATE_ERROR;
-               }
-       }
+       ctx_resched(cpuctx, task_ctx);
 
 unlock:
-       raw_spin_unlock(&ctx->lock);
+       perf_ctx_unlock(cpuctx, task_ctx);
 
        return 0;
 }
This page took 0.029868 seconds and 5 git commands to generate.