perf: Do not POLLHUP event if it has children
Jiri Olsa
reviewerPATCH 1/3 perf: Do not POLLHUP event if it has children
Currently we return POLLHUP in event polling if the monitored process is done, but we didn't consider possible children, that might be still running and producing data.
Before returning POLLHUP making sure that
1) the monitored task has exited and that
2) we don't have any children to monitor
Also adding parent wakeup when the child event is gone.
--- kernel/events/core.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
kernel/events/core.c +20 -1
@@ -3586,6 +3586,19 @@ static int perf_event_read_one(struct perf_event *event,return n *sizeof (u64); } +static bool is_event_hup (struct perf_event *event) +{ +bool no_children; + +if (event->state !=PERF_EVENT_STATE_EXIT ) +return false; + +mutex_lock (&event->child_mutex); + no_children =list_empty (&event->child_list); +mutex_unlock (&event->child_mutex); +return no_children; +} +/* * Read the performance event - simple non blocking version for now */
@@ -3632,7 +3645,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)poll_wait (file, &event->waitq, wait); -if (event->state ==PERF_EVENT_STATE_EXIT ) +if (is_event_hup (event))return events;/*
@@ -7560,6 +7573,12 @@ static void sync_child_event(struct perf_event *child_event,mutex_unlock (&parent_event->child_mutex);/* +* Make sure user/parent get notified, that we just +* lost one event. +*/ +perf_event_wakeup (parent_event); + +/* * Release the parent event, if this was the last * reference to it. */
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 2/3 perf: Fix child event initial state setup
From: Jiri Olsa <[email protected]>
Currently we initialize the child event based on the original parent state. This is wrong, because the original parent event (and its state) is not related to current fork and also could be already gone.
We need to initialize the child state based on the immediate parent event state.
--- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +2 -1
@@ -7798,6 +7798,7 @@ inherit_event(struct perf_event *parent_event,struct perf_event *group_leader, struct perf_event_context *child_ctx) { + enum perf_event_active_state parent_state = parent_event->state;struct perf_event *child_event;unsigned long flags;
@@ -7831,7 +7832,7 @@ inherit_event(struct perf_event *parent_event,* not its attr.disabled bit. We hold the parent's mutex, * so we won't race with perf_event_{en, dis}able_family. */ -if (parent_event->state >=PERF_EVENT_STATE_INACTIVE ) +if (parent_state >=PERF_EVENT_STATE_INACTIVE ) child_event->state =PERF_EVENT_STATE_INACTIVE ;else child_event->state =PERF_EVENT_STATE_OFF ;
Signature · 1 line
1.8.3.1
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf: Fix child event initial state setup
perf: Fix child event initial state setup
Commit-ID: 1929def9e609d1a8cdb1626d85eda3da66921a7d Gitweb: http://git.kernel.org/tip/1929def9e609d1a8cdb1626d85eda3da66921a7d Author: Jiri Olsa <[email protected]> AuthorDate: Fri, 12 Sep 2014 13:18:27 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:48:12 +0200
perf: Fix child event initial state setup
Currently we initialize the child event based on the original parent state. This is wrong, because the original parent event (and its state) is not related to current fork and also could be already gone.
We need to initialize the child state based on the immediate parent event state.
--- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +2 -1
@@ -7818,6 +7818,7 @@ inherit_event(struct perf_event *parent_event,struct perf_event *group_leader, struct perf_event_context *child_ctx) { + enum perf_event_active_state parent_state = parent_event->state;struct perf_event *child_event;unsigned long flags;
@@ -7851,7 +7852,7 @@ inherit_event(struct perf_event *parent_event,* not its attr.disabled bit. We hold the parent's mutex, * so we won't race with perf_event_{en, dis}able_family. */ -if (parent_event->state >=PERF_EVENT_STATE_INACTIVE ) +if (parent_state >=PERF_EVENT_STATE_INACTIVE ) child_event->state =PERF_EVENT_STATE_INACTIVE ;else child_event->state =PERF_EVENT_STATE_OFF ;
Jiri Olsa
reviewerPATCH 3/3 Revert "perf: Do not allow optimized switch for non-cloned events"
In reply to Jiri OlsaFrom: Jiri Olsa <[email protected]>
This reverts commit 1f9a7268c67f0290837aada443d28fd953ddca90.
With the fix of the initial state for the cloned event we now correctly handle the error described in:
1f9a7268c67f perf: Do not allow optimized switch for non-cloned events
so we can revert it.
I made an automated test for this, but its not suitable for automated perf tests framework. It needs to be customized for each machine (the more cpu the higher numbers for GROUPS/WORKERS/BYTES) and it could take longer time to hit the issue. Adding at least a lkml link with test patch.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -2374,7 +2374,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, next_parent =rcu_dereference (next_ctx->parent_ctx);/* If neither context have a parent context; they cannot be clones. */ -if (!parent || !next_parent) +if (!parent && !next_parent) goto unlock;if (next_parent == ctx || next_ctx == parent || next_parent == parent) {
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerQuoted 18 lines · Jiri Olsa
Currently we return POLLHUP in event polling if the monitored process is done, but we didn't consider possible children, that might be still running and producing data.
Before returning POLLHUP making sure that
1) the monitored task has exited and that
2) we don't have any children to monitorAlso adding parent wakeup when the child event is gone.
Suggested-by Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Quoted 1 line
---
Thanks Jiri (for all three patches)!
tip-bot for Jiri Olsa
merge botperf: Do not POLLHUP event if it has children
Commit-ID: dc633982ff3f4fd74cdc11b5a6ae53d39a0b2451 Gitweb: http://git.kernel.org/tip/dc633982ff3f4fd74cdc11b5a6ae53d39a0b2451 Author: Jiri Olsa <[email protected]> AuthorDate: Fri, 12 Sep 2014 13:18:26 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:48:11 +0200
perf: Do not POLLHUP event if it has children
Currently we return POLLHUP in event polling if the monitored process is done, but we didn't consider possible children, that might be still running and producing data.
Before returning POLLHUP making sure that:
1) the monitored task has exited and that
2) we don't have any children to monitor
Also adding parent wakeup when the child event is gone.
--- kernel/events/core.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
kernel/events/core.c +20 -1
@@ -3587,6 +3587,19 @@ static int perf_event_read_one(struct perf_event *event,return n *sizeof (u64); } +static bool is_event_hup (struct perf_event *event) +{ +bool no_children; + +if (event->state !=PERF_EVENT_STATE_EXIT ) +return false; + +mutex_lock (&event->child_mutex); + no_children =list_empty (&event->child_list); +mutex_unlock (&event->child_mutex); +return no_children; +} +/* * Read the performance event - simple non blocking version for now */
@@ -3632,7 +3645,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)poll_wait (file, &event->waitq, wait); -if (event->state ==PERF_EVENT_STATE_EXIT ) +if (is_event_hup (event))return events;/*
@@ -7580,6 +7593,12 @@ static void sync_child_event(struct perf_event *child_event,mutex_unlock (&parent_event->child_mutex);/* +* Make sure user/parent get notified, that we just +* lost one event. +*/ +perf_event_wakeup (parent_event); + +/* * Release the parent event, if this was the last * reference to it. */