From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, vince@deater.net,
eranian@google.com, johannes@sipsolutions.net,
Arnaldo Carvalho de Melo <acme@infradead.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH 3/7] perf: Add a helper to stop running events
Date: Thu, 3 Dec 2015 12:32:38 +0200 [thread overview]
Message-ID: <1449138762-15194-4-git-send-email-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <1449138762-15194-1-git-send-email-alexander.shishkin@linux.intel.com>
This patch adds a helper function that stops running events without
changing their state. The use case at the moment is stopping active AUX
events while their ring buffer's AUX area is getting unmapped. Since we
know that a new AUX transaction can't be started once ring buffer's
aux_mmap_count drops to zero, the only thing we need to do is stop the
active transactions.
This does a cross-cpu call that will only look at active events that are
running on their cpus.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
kernel/events/core.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0d3296f600..66f835a2df 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2314,6 +2314,50 @@ void perf_event_enable(struct perf_event *event)
}
EXPORT_SYMBOL_GPL(perf_event_enable);
+static int __perf_event_stop(void *info)
+{
+ int ret = -EINVAL;
+ struct perf_event *event = info;
+ struct perf_event_context *ctx = event->ctx;
+ struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
+
+ raw_spin_lock(&ctx->lock);
+ /* scheduler had a chance to do its thing */
+ if (ctx->task && cpuctx->task_ctx != ctx)
+ goto unlock;
+
+ ret = 0;
+ if (event->state < PERF_EVENT_STATE_ACTIVE)
+ goto unlock;
+
+ perf_pmu_disable(event->pmu);
+ event->pmu->stop(event, PERF_EF_UPDATE);
+ perf_pmu_enable(event->pmu);
+
+unlock:
+ raw_spin_unlock(&ctx->lock);
+
+ return ret;
+}
+
+/*
+ * Stop an event without touching its state;
+ * useful if you know that it won't get restarted when you let go of
+ * the context lock, such as aux path in perf_mmap_close().
+ */
+static void perf_event_stop(struct perf_event *event)
+{
+ struct perf_event_context *ctx;
+
+ ctx = perf_event_ctx_lock(event);
+
+ if (remote_call_or_ctx_lock(event, __perf_event_stop, event,
+ PERF_EVENT_STATE_NONE))
+ raw_spin_unlock_irq(&event->ctx->lock);
+
+ perf_event_ctx_unlock(event, ctx);
+}
+
static int _perf_event_refresh(struct perf_event *event, int refresh)
{
/*
--
2.6.2
next prev parent reply other threads:[~2015-12-03 10:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 10:32 [PATCH 0/7] perf: Untangle aux refcounting Alexander Shishkin
2015-12-03 10:32 ` [PATCH 1/7] perf: Refuse to begin aux transaction after aux_mmap_count drops Alexander Shishkin
2015-12-03 10:32 ` [PATCH 2/7] perf: Generalize task_function_call()ers Alexander Shishkin
2015-12-03 17:34 ` Peter Zijlstra
2015-12-08 16:42 ` Alexander Shishkin
2015-12-08 16:57 ` Peter Zijlstra
2015-12-17 13:40 ` Peter Zijlstra
2015-12-17 14:25 ` Alexander Shishkin
2015-12-17 15:07 ` Peter Zijlstra
2015-12-18 9:01 ` Peter Zijlstra
2015-12-18 15:07 ` Alexander Shishkin
2015-12-18 16:47 ` Peter Zijlstra
2015-12-18 17:41 ` Alexander Shishkin
2015-12-21 14:39 ` Alexander Shishkin
2016-01-11 10:44 ` Alexander Shishkin
2015-12-03 10:32 ` Alexander Shishkin [this message]
2015-12-03 10:32 ` [PATCH 4/7] perf: Free aux pages in unmap path Alexander Shishkin
2015-12-04 17:02 ` Peter Zijlstra
2015-12-04 22:17 ` Peter Zijlstra
2015-12-07 16:16 ` Peter Zijlstra
2015-12-09 9:57 ` Alexander Shishkin
2015-12-09 10:56 ` Peter Zijlstra
2015-12-10 11:20 ` Alexander Shishkin
2015-12-10 12:58 ` Alexander Shishkin
2015-12-03 10:32 ` [PATCH 5/7] perf: Document aux api usage Alexander Shishkin
2015-12-03 20:36 ` Mathieu Poirier
2015-12-03 10:32 ` [PATCH 6/7] perf/x86/intel/pt: Move transaction start/stop to pmu start/stop callbacks Alexander Shishkin
2015-12-03 10:32 ` [PATCH 7/7] perf/x86/intel/bts: Move transaction start/stop to " Alexander Shishkin
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=1449138762-15194-4-git-send-email-alexander.shishkin@linux.intel.com \
--to=alexander.shishkin@linux.intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@infradead.org \
--cc=eranian@google.com \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=vince@deater.net \
/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;
as well as URLs for NNTP newsgroup(s).