public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>, Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	linux-kernel@vger.kernel.org, jolsa@redhat.com,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH v1 6/6] perf: Allow set-output for task contexts of different types
Date: Tue, 12 Jun 2018 10:51:17 +0300	[thread overview]
Message-ID: <20180612075117.65420-7-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20180612075117.65420-1-alexander.shishkin@linux.intel.com>

From: Adrian Hunter <adrian.hunter@intel.com>

Set-output must be limited to events that cannot be active on different
cpus at the same time.  Thus either the event cpu must be the same, or
the event task must be the same.  Current logic does not check the task
directly but checks whether the perf_event_context is the same, however
there are separate contexts for hardware and software events so in that
case the perf_event_context is different even though the task is the same.
This patch changes the logic to check the task directly.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 kernel/events/core.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 9bf5c7abb621..9ab9f21f58da 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -9848,9 +9848,21 @@ perf_event_set_output(struct perf_event *event, struct perf_event *output_event)
 		goto out;
 
 	/*
-	 * If its not a per-cpu rb, it must be the same task.
+	 * If it's not a per-cpu rb, it must be the same task.
+	 *
+	 * Since output_event is a per-task event, ->ctx is stable
+	 * and should be around for as long as the file is around.
+	 *
+	 * The context switch optimization doesn't apply to output_event
+	 * as well, so we can look at its ctx->task, which will be either
+	 * a valid task or TASK_TOMBSTONE.
+	 *
+	 * The source event's task can also be TASK_TOMBSTONE, so look out
+	 * for that also.
 	 */
-	if (output_event->cpu == -1 && output_event->ctx != event->ctx)
+	if (output_event->cpu == -1 &&
+	    (output_event->ctx->task != event->ctx->task ||
+	     output_event->ctx->task == TASK_TOMBSTONE))
 		goto out;
 
 	/*
-- 
2.17.1


  parent reply	other threads:[~2018-06-12  7:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12  7:51 [PATCH v1 0/6] perf: Add AUX data sampling Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 1/6] perf: Disable PMU around address filter adjustment Alexander Shishkin
2018-06-12 20:11   ` Peter Zijlstra
2018-06-12  7:51 ` [PATCH v1 2/6] perf: Disable IRQs in address filter sync path Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 3/6] perf: Add an iterator for AUX data Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 4/6] perf: Allow using AUX data in perf samples Alexander Shishkin
2018-06-14 19:25   ` Peter Zijlstra
2018-06-14 19:39     ` Peter Zijlstra
2018-06-19 10:51       ` Alexander Shishkin
2018-06-14 19:30   ` Peter Zijlstra
2018-06-14 19:47   ` Peter Zijlstra
2018-06-19 11:00     ` Alexander Shishkin
2018-06-14 20:03   ` Peter Zijlstra
2018-06-14 20:20   ` Peter Zijlstra
2018-06-19 10:47     ` Alexander Shishkin
2018-06-21 20:16       ` Peter Zijlstra
2018-10-02 14:00         ` Alexander Shishkin
2019-08-09 12:32         ` Alexander Shishkin
2019-09-26 12:04           ` Alexander Shishkin
2019-09-26 14:44           ` Peter Zijlstra
2019-09-30 11:50             ` Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 5/6] perf: Drop PERF_FLAG_FD_OUTPUT Alexander Shishkin
2018-06-12  7:51 ` Alexander Shishkin [this message]
2018-06-14 19:36   ` [PATCH v1 6/6] perf: Allow set-output for task contexts of different types Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180612075117.65420-7-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox