Current perf assumes that events in a group are independent. Close an event doesn't impact the value of the other events in the same group. If the closed event is a member, after the event closure, other events are still running like a group. If the closed event is a leader, other events are running as singleton events. Add PERF_EV_CAP_SIBLING to allow events to indicate they require being part of a group, and when the leader dies they cannot exist independently.
Showing the changes to kernel (1 of 2 files). Show all
Unified · Split
| @@ -2133,8 +2133,24 @@ static inline struct list_head *get_event_list(struct perf_event *event) · 2132 unmodified lines | |||
| 2133 | return event->attr.pinned ? &ctx->pinned_active : &ctx->flexible_active; | 2133 | return event->attr.pinned ? &ctx->pinned_active : &ctx->flexible_active; |
| 2134 | } | 2134 | } |
| 2135 | 2135 | ||
| 2136 | /* | ||
| 2137 | * Events that have PERF_EV_CAP_SIBLING require being part of a group and | ||
| 2138 | * cannot exist on their own, schedule them out and move them into the ERROR | ||
| 2139 | * state. Also see _perf_event_enable(), it will not be able to recover | ||
| 2140 | * this ERROR state. | ||
| 2141 | */ | ||
| 2142 | static inline void perf_remove_sibling_event(struct perf_event *event) | ||
| 2143 | { | ||
| 2144 | struct perf_event_context *ctx = event->ctx; | ||
| 2145 | struct perf_cpu_context *cpuctx = __get_cpu_context(ctx); | ||
| 2146 | |||
| 2147 | event_sched_out(event, cpuctx, ctx); | ||
| 2148 | perf_event_set_state(event, PERF_EVENT_STATE_ERROR); | ||
| 2149 | } | ||
| 2150 | |||
| 2136 | static void perf_group_detach(struct perf_event *event) | 2151 | static void perf_group_detach(struct perf_event *event) |
| 2137 | { | 2152 | { |
| 2153 | struct perf_event *leader = event->group_leader; | ||
| 2138 | struct perf_event *sibling, *tmp; | 2154 | struct perf_event *sibling, *tmp; |
| 2139 | struct perf_event_context *ctx = event->ctx; | 2155 | struct perf_event_context *ctx = event->ctx; |
| 2140 | 2156 | ||
| @@ -2153,7 +2169,7 @@ static void perf_group_detach(struct perf_event *event) · 12 unmodified lines | |||
| 2153 | /* | 2169 | /* |
| 2154 | * If this is a sibling, remove it from its group. | 2170 | * If this is a sibling, remove it from its group. |
| 2155 | */ | 2171 | */ |
| 2156 | if (event->group_leader != event) { | 2172 | if (leader != event) { |
| 2157 | list_del_init(&event->sibling_list); | 2173 | list_del_init(&event->sibling_list); |
| 2158 | event->group_leader->nr_siblings--; | 2174 | event->group_leader->nr_siblings--; |
| 2159 | goto out; | 2175 | goto out; |
| @@ -2166,6 +2182,9 @@ static void perf_group_detach(struct perf_event *event) · 6 unmodified lines | |||
| 2166 | */ | 2182 | */ |
| 2167 | list_for_each_entry_safe(sibling, tmp, &event->sibling_list, sibling_list) { | 2183 | list_for_each_entry_safe(sibling, tmp, &event->sibling_list, sibling_list) { |
| 2168 | 2184 | ||
| 2185 | if (sibling->event_caps & PERF_EV_CAP_SIBLING) | ||
| 2186 | perf_remove_sibling_event(sibling); | ||
| 2187 | |||
| 2169 | sibling->group_leader = sibling; | 2188 | sibling->group_leader = sibling; |
| 2170 | list_del_init(&sibling->sibling_list); | 2189 | list_del_init(&sibling->sibling_list); |
| 2171 | 2190 | ||
| @@ -2183,10 +2202,10 @@ static void perf_group_detach(struct perf_event *event) · 11 unmodified lines | |||
| 2183 | } | 2202 | } |
| 2184 | 2203 | ||
| 2185 | out: | 2204 | out: |
| 2186 | perf_event__header_size(event->group_leader); | 2205 | for_each_sibling_event(tmp, leader) |
| 2187 | |||
| 2188 | for_each_sibling_event(tmp, event->group_leader) | ||
| 2189 | perf_event__header_size(tmp); | 2206 | perf_event__header_size(tmp); |
| 2207 | |||
| 2208 | perf_event__header_size(leader); | ||
| 2190 | } | 2209 | } |
| 2191 | 2210 | ||
| 2192 | static bool is_orphaned_event(struct perf_event *event) | 2211 | static bool is_orphaned_event(struct perf_event *event) |
| @@ -2979,6 +2998,7 @@ static void _perf_event_enable(struct perf_event *event) · 786 unmodified lines | |||
| 2979 | raw_spin_lock_irq(&ctx->lock); | 2998 | raw_spin_lock_irq(&ctx->lock); |
| 2980 | if (event->state >= PERF_EVENT_STATE_INACTIVE || | 2999 | if (event->state >= PERF_EVENT_STATE_INACTIVE || |
| 2981 | event->state < PERF_EVENT_STATE_ERROR) { | 3000 | event->state < PERF_EVENT_STATE_ERROR) { |
| 3001 | out: | ||
| 2982 | raw_spin_unlock_irq(&ctx->lock); | 3002 | raw_spin_unlock_irq(&ctx->lock); |
| 2983 | return; | 3003 | return; |
| 2984 | } | 3004 | } |
| @@ -2990,8 +3010,16 @@ static void _perf_event_enable(struct perf_event *event) · 5 unmodified lines | |||
| 2990 | * has gone back into error state, as distinct from the task having | 3010 | * has gone back into error state, as distinct from the task having |
| 2991 | * been scheduled away before the cross-call arrived. | 3011 | * been scheduled away before the cross-call arrived. |
| 2992 | */ | 3012 | */ |
| 2993 | if (event->state == PERF_EVENT_STATE_ERROR) | 3013 | if (event->state == PERF_EVENT_STATE_ERROR) { |
| 3014 | /* | ||
| 3015 | * Detached SIBLING events cannot leave ERROR state. | ||
| 3016 | */ | ||
| 3017 | if (event->event_caps & PERF_EV_CAP_SIBLING && | ||
| 3018 | event->group_leader == event) | ||
| 3019 | goto out; | ||
| 3020 | |||
| 2994 | event->state = PERF_EVENT_STATE_OFF; | 3021 | event->state = PERF_EVENT_STATE_OFF; |
| 3022 | } | ||
| 2995 | raw_spin_unlock_irq(&ctx->lock); | 3023 | raw_spin_unlock_irq(&ctx->lock); |
| 2996 | 3024 | ||
| 2997 | event_function_call(event, __perf_event_enable, NULL); | 3025 | event_function_call(event, __perf_event_enable, NULL); |