From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B64A4C43466 for ; Mon, 21 Sep 2020 13:56:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64ECF2084C for ; Mon, 21 Sep 2020 13:56:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="G1fqWdda"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="t7krJPdj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64ECF2084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XiGuOJudWv6lgEarFTHNMw4Q9fex7UD621vVQ7uibZo=; b=G1fqWdda14Rd34trL2bIk9p0m LQ05CbhxECY/aFzYE+C/vrSHWO1CPwsJJYPvYBW4ng0x/1SRnIgEwoIlBWpotVjuW22jAlMoOymeW vQIbLwmcg9g39gK8CrkaE1xLAlom9ZLPdT95+haojpq5txwThs60kfxnBb7M3UKRW6LR1qlcQkrXe kNAFuFjjIQzpZoHlSC6pnoTFSIkFZqt9iG/yIBaAxd+treTNjMv9cTrwolD/uOvMLjQ6rdZ6eWH0m n12vrBpDnLT3oFGrtWS81fyw7UFdPz/mc0YKzeMj5zBpYkNCic7QW180/Epop+ZgnrblCqs93iBz8 9o1SVBZIA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKMHo-0005tH-4Y; Mon, 21 Sep 2020 13:55:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKMHl-0005si-D6 for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 13:55:18 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F2492084C; Mon, 21 Sep 2020 13:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600696516; bh=giup4Dg5WhpWJ857PpfPZHU63m06kkHcvu6+1h1OTGM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=t7krJPdjhg+bDMgb1GVhKtpKbKGCt2WMKioDi8bjOQhDdP+tN2VRUVawBcplmHqRv ITVPksJ7H1kyELjQqLg+2bW3krseriR1pBihUVKjeV7ym6Qs2LqGtC0nTmhIcYUmk/ SSChRCFTfvuO7Ns8kaiJEEo5SJ0icrtDusNJm3qE= Date: Mon, 21 Sep 2020 14:55:11 +0100 From: Will Deacon To: Alexandru Elisei Subject: Re: [PATCH v6 6/7] arm_pmu: Introduce pmu_irq_ops Message-ID: <20200921135510.GM2139@willie-the-truck> References: <20200819133419.526889-1-alexandru.elisei@arm.com> <20200819133419.526889-7-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200819133419.526889-7-alexandru.elisei@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_095517_579570_63B127A6 X-CRM114-Status: GOOD ( 22.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, sumit.garg@linaro.org, Julien Thierry , maz@kernel.org, Will Deacon , linux-kernel@vger.kernel.org, swboyd@chromium.org, Julien Thierry , catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 19, 2020 at 02:34:18PM +0100, Alexandru Elisei wrote: > From: Julien Thierry > > Currently the PMU interrupt can either be a normal irq or a percpu irq. > Supporting NMI will introduce two cases for each existing one. It becomes > a mess of 'if's when managing the interrupt. > > Define sets of callbacks for operations commonly done on the interrupt. The > appropriate set of callbacks is selected at interrupt request time and > simplifies interrupt enabling/disabling and freeing. > > Cc: Julien Thierry > Cc: Will Deacon > Cc: Mark Rutland > Signed-off-by: Julien Thierry > Signed-off-by: Alexandru Elisei > --- > drivers/perf/arm_pmu.c | 86 ++++++++++++++++++++++++++++++++++-------- > 1 file changed, 70 insertions(+), 16 deletions(-) > > diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c > index df352b334ea7..17e5952d21e4 100644 > --- a/drivers/perf/arm_pmu.c > +++ b/drivers/perf/arm_pmu.c > @@ -26,8 +26,46 @@ > > #include > > +static int armpmu_count_irq_users(const int irq); > + > +struct pmu_irq_ops { > + void (*enable_pmuirq)(unsigned int irq); > + void (*disable_pmuirq)(unsigned int irq); > + void (*free_pmuirq)(unsigned int irq, int cpu, void __percpu *devid); > +}; > + > +static void armpmu_free_pmuirq(unsigned int irq, int cpu, void __percpu *devid) > +{ > + free_irq(irq, per_cpu_ptr(devid, cpu)); > +} > + > +static const struct pmu_irq_ops pmuirq_ops = { > + .enable_pmuirq = enable_irq, > + .disable_pmuirq = disable_irq_nosync, > + .free_pmuirq = armpmu_free_pmuirq > +}; > + > +static void armpmu_enable_percpu_pmuirq(unsigned int irq) > +{ > + enable_percpu_irq(irq, IRQ_TYPE_NONE); > +} > + > +static void armpmu_free_percpu_pmuirq(unsigned int irq, int cpu, > + void __percpu *devid) > +{ > + if (armpmu_count_irq_users(irq) == 1) > + free_percpu_irq(irq, devid); > +} > + > +static const struct pmu_irq_ops percpu_pmuirq_ops = { > + .enable_pmuirq = armpmu_enable_percpu_pmuirq, > + .disable_pmuirq = disable_percpu_irq, > + .free_pmuirq = armpmu_free_percpu_pmuirq > +}; > + > static DEFINE_PER_CPU(struct arm_pmu *, cpu_armpmu); > static DEFINE_PER_CPU(int, cpu_irq); > +static DEFINE_PER_CPU(const struct pmu_irq_ops *, cpu_irq_ops); Would it make sense to put this in a structure alongside the irq? > > static inline u64 arm_pmu_event_max_period(struct perf_event *event) > { > @@ -544,6 +582,19 @@ static int armpmu_count_irq_users(const int irq) > return count; > } > > +static const struct pmu_irq_ops *armpmu_find_irq_ops(int irq) > +{ > + int cpu; > + > + for_each_possible_cpu(cpu) { > + if (per_cpu(cpu_irq, cpu) == irq > + && per_cpu(cpu_irq_ops, cpu)) > + return per_cpu(cpu_irq_ops, cpu); > + } nit, but you could make this a bit more readable: struct pmu_irq_ops *ops = NULL; for_each_possible_cpu(cpu) { if (per_cpu(cpu_irq, cpu) != irq) continue; ops = per_cpu(cpu_irq_ops, cpu); if (ops) break; } return ops; Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel