@@ -1986,6 +1986,12 @@ static int perf_get_aux_event(struct perf_event *event,
19861986 return 1 ;
19871987}
19881988
1989+ static inline struct list_head * get_event_list (struct perf_event * event )
1990+ {
1991+ struct perf_event_context * ctx = event -> ctx ;
1992+ return event -> attr .pinned ? & ctx -> pinned_active : & ctx -> flexible_active ;
1993+ }
1994+
19891995static void perf_group_detach (struct perf_event * event )
19901996{
19911997 struct perf_event * sibling , * tmp ;
@@ -2028,12 +2034,8 @@ static void perf_group_detach(struct perf_event *event)
20282034 if (!RB_EMPTY_NODE (& event -> group_node )) {
20292035 add_event_to_groups (sibling , event -> ctx );
20302036
2031- if (sibling -> state == PERF_EVENT_STATE_ACTIVE ) {
2032- struct list_head * list = sibling -> attr .pinned ?
2033- & ctx -> pinned_active : & ctx -> flexible_active ;
2034-
2035- list_add_tail (& sibling -> active_list , list );
2036- }
2037+ if (sibling -> state == PERF_EVENT_STATE_ACTIVE )
2038+ list_add_tail (& sibling -> active_list , get_event_list (sibling ));
20372039 }
20382040
20392041 WARN_ON_ONCE (sibling -> ctx != event -> ctx );
@@ -2350,6 +2352,8 @@ event_sched_in(struct perf_event *event,
23502352{
23512353 int ret = 0 ;
23522354
2355+ WARN_ON_ONCE (event -> ctx != ctx );
2356+
23532357 lockdep_assert_held (& ctx -> lock );
23542358
23552359 if (event -> state <= PERF_EVENT_STATE_OFF )
@@ -3425,10 +3429,12 @@ struct sched_in_data {
34253429 int can_add_hw ;
34263430};
34273431
3428- static int pinned_sched_in (struct perf_event * event , void * data )
3432+ static int merge_sched_in (struct perf_event * event , void * data )
34293433{
34303434 struct sched_in_data * sid = data ;
34313435
3436+ WARN_ON_ONCE (event -> ctx != sid -> ctx );
3437+
34323438 if (event -> state <= PERF_EVENT_STATE_OFF )
34333439 return 0 ;
34343440
@@ -3437,37 +3443,15 @@ static int pinned_sched_in(struct perf_event *event, void *data)
34373443
34383444 if (group_can_go_on (event , sid -> cpuctx , sid -> can_add_hw )) {
34393445 if (!group_sched_in (event , sid -> cpuctx , sid -> ctx ))
3440- list_add_tail (& event -> active_list , & sid -> ctx -> pinned_active );
3446+ list_add_tail (& event -> active_list , get_event_list ( event ) );
34413447 }
34423448
3443- /*
3444- * If this pinned group hasn't been scheduled,
3445- * put it in error state.
3446- */
3447- if (event -> state == PERF_EVENT_STATE_INACTIVE )
3448- perf_event_set_state (event , PERF_EVENT_STATE_ERROR );
3449-
3450- return 0 ;
3451- }
3452-
3453- static int flexible_sched_in (struct perf_event * event , void * data )
3454- {
3455- struct sched_in_data * sid = data ;
3456-
3457- if (event -> state <= PERF_EVENT_STATE_OFF )
3458- return 0 ;
3459-
3460- if (!event_filter_match (event ))
3461- return 0 ;
3449+ if (event -> state == PERF_EVENT_STATE_INACTIVE ) {
3450+ if (event -> attr .pinned )
3451+ perf_event_set_state (event , PERF_EVENT_STATE_ERROR );
34623452
3463- if (group_can_go_on (event , sid -> cpuctx , sid -> can_add_hw )) {
3464- int ret = group_sched_in (event , sid -> cpuctx , sid -> ctx );
3465- if (ret ) {
3466- sid -> can_add_hw = 0 ;
3467- sid -> ctx -> rotate_necessary = 1 ;
3468- return 0 ;
3469- }
3470- list_add_tail (& event -> active_list , & sid -> ctx -> flexible_active );
3453+ sid -> can_add_hw = 0 ;
3454+ sid -> ctx -> rotate_necessary = 1 ;
34713455 }
34723456
34733457 return 0 ;
@@ -3485,7 +3469,7 @@ ctx_pinned_sched_in(struct perf_event_context *ctx,
34853469
34863470 visit_groups_merge (& ctx -> pinned_groups ,
34873471 smp_processor_id (),
3488- pinned_sched_in , & sid );
3472+ merge_sched_in , & sid );
34893473}
34903474
34913475static void
@@ -3500,7 +3484,7 @@ ctx_flexible_sched_in(struct perf_event_context *ctx,
35003484
35013485 visit_groups_merge (& ctx -> flexible_groups ,
35023486 smp_processor_id (),
3503- flexible_sched_in , & sid );
3487+ merge_sched_in , & sid );
35043488}
35053489
35063490static void
0 commit comments