History

perf/core: Add a new PERF_EV_CAP_SIBLING event capability

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.

Kan Liang committed 6 years ago

Commit 9f0c4fa1 parent 58da7db2 files · +37 −5Browse files

Showing the changes to kernel (1 of 2 files). Show all

Unified · Split

kernel/events/core.c+33−5
@@ -2133,8 +2133,24 @@ static inline struct list_head *get_event_list(struct perf_event *event) · 2132 unmodified lines
21332133 return event->attr.pinned ? &ctx->pinned_active : &ctx->flexible_active;
21342134 }
21352135
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+
21362151 static void perf_group_detach(struct perf_event *event)
21372152 {
2153+ struct perf_event *leader = event->group_leader;
21382154 struct perf_event *sibling, *tmp;
21392155 struct perf_event_context *ctx = event->ctx;
21402156
@@ -2153,7 +2169,7 @@ static void perf_group_detach(struct perf_event *event) · 12 unmodified lines
21532169 /*
21542170 * If this is a sibling, remove it from its group.
21552171 */
2156− if (event->group_leader != event) {
2172+ if (leader != event) {
21572173 list_del_init(&event->sibling_list);
21582174 event->group_leader->nr_siblings--;
21592175 goto out;
@@ -2166,6 +2182,9 @@ static void perf_group_detach(struct perf_event *event) · 6 unmodified lines
21662182 */
21672183 list_for_each_entry_safe(sibling, tmp, &event->sibling_list, sibling_list) {
21682184
2185+ if (sibling->event_caps & PERF_EV_CAP_SIBLING)
2186+ perf_remove_sibling_event(sibling);
2187+
21692188 sibling->group_leader = sibling;
21702189 list_del_init(&sibling->sibling_list);
21712190
@@ -2183,10 +2202,10 @@ static void perf_group_detach(struct perf_event *event) · 11 unmodified lines
21832202 }
21842203
21852204 out:
2186− perf_event__header_size(event->group_leader);
2187−
2188− for_each_sibling_event(tmp, event->group_leader)
2205+ for_each_sibling_event(tmp, leader)
21892206 perf_event__header_size(tmp);
2207+
2208+ perf_event__header_size(leader);
21902209 }
21912210
21922211 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
29792998 raw_spin_lock_irq(&ctx->lock);
29802999 if (event->state >= PERF_EVENT_STATE_INACTIVE ||
29813000 event->state < PERF_EVENT_STATE_ERROR) {
3001+out:
29823002 raw_spin_unlock_irq(&ctx->lock);
29833003 return;
29843004 }
@@ -2990,8 +3010,16 @@ static void _perf_event_enable(struct perf_event *event) · 5 unmodified lines
29903010 * has gone back into error state, as distinct from the task having
29913011 * been scheduled away before the cross-call arrived.
29923012 */
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+
29943021 event->state = PERF_EVENT_STATE_OFF;
3022+ }
29953023 raw_spin_unlock_irq(&ctx->lock);
29963024
29973025 event_function_call(event, __perf_event_enable, NULL);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t