From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759697AbbLCKdO (ORCPT ); Thu, 3 Dec 2015 05:33:14 -0500 Received: from mga01.intel.com ([192.55.52.88]:24946 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759678AbbLCKdI (ORCPT ); Thu, 3 Dec 2015 05:33:08 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,377,1444719600"; d="scan'208";a="863762852" From: Alexander Shishkin To: Peter Zijlstra Cc: Ingo Molnar , linux-kernel@vger.kernel.org, vince@deater.net, eranian@google.com, johannes@sipsolutions.net, Arnaldo Carvalho de Melo , Alexander Shishkin Subject: [PATCH 3/7] perf: Add a helper to stop running events Date: Thu, 3 Dec 2015 12:32:38 +0200 Message-Id: <1449138762-15194-4-git-send-email-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1449138762-15194-1-git-send-email-alexander.shishkin@linux.intel.com> References: <1449138762-15194-1-git-send-email-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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