Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1282919 > unrolled thread

[PATCH 3/7] perf: Add a helper to stop running events

Started byAlexander Shishkin <alexander.shishkin@linux.intel.com>
First post2015-12-03 11:40 +0100
Last post2015-12-03 11:40 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3/7] perf: Add a helper to stop running events Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-03 11:40 +0100

#1282919 — [PATCH 3/7] perf: Add a helper to stop running events

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2015-12-03 11:40 +0100
Subject[PATCH 3/7] perf: Add a helper to stop running events
Message-ID<qBzsT-3Jm-39@gated-at.bofh.it>
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web