Skip to content

Commit 179033b

Browse files
olsajiriacmel
authored andcommitted
perf: Add PERF_EVENT_STATE_EXIT state for events with exited task
Adding new perf event state to indicate that the monitored task has exited. In this case the event stays alive until the owner task exits or close the event fd while providing the last data through the read syscall and ring buffer. Instead it needs to propagate the error info (monitored task has died) via poll and read syscalls by returning POLLHUP and 0 respectively. Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Cc: Adrian Hunter <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Corey Ashford <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jean Pihet <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 61b6768 commit 179033b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/linux/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ struct pmu {
269269
* enum perf_event_active_state - the states of a event
270270
*/
271271
enum perf_event_active_state {
272+
PERF_EVENT_STATE_EXIT = -3,
272273
PERF_EVENT_STATE_ERROR = -2,
273274
PERF_EVENT_STATE_OFF = -1,
274275
PERF_EVENT_STATE_INACTIVE = 0,

kernel/events/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3600,7 +3600,8 @@ perf_read_hw(struct perf_event *event, char __user *buf, size_t count)
36003600
* error state (i.e. because it was pinned but it couldn't be
36013601
* scheduled on to the CPU at some point).
36023602
*/
3603-
if (event->state == PERF_EVENT_STATE_ERROR)
3603+
if ((event->state == PERF_EVENT_STATE_ERROR) ||
3604+
(event->state == PERF_EVENT_STATE_EXIT))
36043605
return 0;
36053606

36063607
if (count < event->read_size)
@@ -3630,6 +3631,10 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
36303631
unsigned int events = POLLHUP;
36313632

36323633
poll_wait(file, &event->waitq, wait);
3634+
3635+
if (event->state == PERF_EVENT_STATE_EXIT)
3636+
return events;
3637+
36333638
/*
36343639
* Pin the event->rb by taking event->mmap_mutex; otherwise
36353640
* perf_event_set_output() can swizzle our rb and make us miss wakeups.
@@ -7588,6 +7593,9 @@ __perf_event_exit_task(struct perf_event *child_event,
75887593
if (child_event->parent) {
75897594
sync_child_event(child_event, child);
75907595
free_event(child_event);
7596+
} else {
7597+
child_event->state = PERF_EVENT_STATE_EXIT;
7598+
perf_event_wakeup(child_event);
75917599
}
75927600
}
75937601

0 commit comments

Comments
 (0)