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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 F0D4EC4338F for ; Wed, 25 Aug 2021 16:17:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D552A61151 for ; Wed, 25 Aug 2021 16:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241424AbhHYQSl (ORCPT ); Wed, 25 Aug 2021 12:18:41 -0400 Received: from foss.arm.com ([217.140.110.172]:54768 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240924AbhHYQSW (ORCPT ); Wed, 25 Aug 2021 12:18:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FE5D142F; Wed, 25 Aug 2021 09:17:36 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4C2A3F66F; Wed, 25 Aug 2021 09:17:34 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 15/39] drivers/perf: Expose the cpumask of CPUs that support SPE Date: Wed, 25 Aug 2021 17:17:51 +0100 Message-Id: <20210825161815.266051-16-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KVM SPE emulation will require the list of CPUs that have hardware support for SPE. Add a function that returns the cpumask of supported CPUs discovered by the driver during probing. CC: Will Deacon Signed-off-by: Alexandru Elisei --- drivers/perf/arm_spe_pmu.c | 30 ++++++++++++++++++------------ include/linux/perf/arm_pmu.h | 7 +++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index d44bcc29d99c..40749665f102 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -50,7 +50,6 @@ struct arm_spe_pmu_buf { struct arm_spe_pmu { struct pmu pmu; struct platform_device *pdev; - cpumask_t supported_cpus; struct hlist_node hotplug_node; int irq; /* PPI */ @@ -72,6 +71,8 @@ struct arm_spe_pmu { struct perf_output_handle __percpu *handle; }; +static cpumask_t supported_cpus; + #define to_spe_pmu(p) (container_of(p, struct arm_spe_pmu, pmu)) /* Convert a free-running index from perf into an SPE buffer offset */ @@ -234,9 +235,7 @@ static const struct attribute_group arm_spe_pmu_format_group = { static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev); - - return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); + return cpumap_print_to_pagebuf(true, buf, &supported_cpus); } static DEVICE_ATTR_RO(cpumask); @@ -677,7 +676,7 @@ static int arm_spe_pmu_event_init(struct perf_event *event) return -ENOENT; if (event->cpu >= 0 && - !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus)) + !cpumask_test_cpu(event->cpu, &supported_cpus)) return -ENOENT; if (arm_spe_event_to_pmsevfr(event) & arm_spe_pmsevfr_res0(spe_pmu->pmsver)) @@ -797,11 +796,10 @@ static void arm_spe_pmu_stop(struct perf_event *event, int flags) static int arm_spe_pmu_add(struct perf_event *event, int flags) { int ret = 0; - struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu); struct hw_perf_event *hwc = &event->hw; int cpu = event->cpu == -1 ? smp_processor_id() : event->cpu; - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return -ENOENT; hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; @@ -883,6 +881,13 @@ static void arm_spe_pmu_free_aux(void *aux) kfree(buf); } +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +const cpumask_t *arm_spe_pmu_supported_cpus(void) +{ + return &supported_cpus; +} +#endif + /* Initialisation and teardown functions */ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu) { @@ -1039,7 +1044,7 @@ static void __arm_spe_pmu_dev_probe(void *info) dev_info(dev, "probed for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n", - cpumask_pr_args(&spe_pmu->supported_cpus), + cpumask_pr_args(&supported_cpus), spe_pmu->max_record_sz, spe_pmu->align, spe_pmu->features); spe_pmu->features |= SPE_PMU_FEAT_DEV_PROBED; @@ -1083,7 +1088,7 @@ static int arm_spe_pmu_cpu_startup(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_setup_one(spe_pmu); @@ -1095,7 +1100,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_stop_one(spe_pmu); @@ -1105,7 +1110,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) static int arm_spe_pmu_dev_init(struct arm_spe_pmu *spe_pmu) { int ret; - cpumask_t *mask = &spe_pmu->supported_cpus; + cpumask_t *mask = &supported_cpus; /* Make sure we probe the hardware on a relevant CPU */ ret = smp_call_function_any(mask, __arm_spe_pmu_dev_probe, spe_pmu, 1); @@ -1151,7 +1156,7 @@ static int arm_spe_pmu_irq_probe(struct arm_spe_pmu *spe_pmu) return -EINVAL; } - if (irq_get_percpu_devid_partition(irq, &spe_pmu->supported_cpus)) { + if (irq_get_percpu_devid_partition(irq, &supported_cpus)) { dev_err(&pdev->dev, "failed to get PPI partition (%d)\n", irq); return -EINVAL; } @@ -1216,6 +1221,7 @@ static int arm_spe_pmu_device_probe(struct platform_device *pdev) arm_spe_pmu_dev_teardown(spe_pmu); out_free_handle: free_percpu(spe_pmu->handle); + cpumask_clear(&supported_cpus); return ret; } diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 505480217cf1..3121d95c575b 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -8,6 +8,7 @@ #ifndef __ARM_PMU_H__ #define __ARM_PMU_H__ +#include #include #include #include @@ -177,4 +178,10 @@ void armpmu_free_irq(int irq, int cpu); #define ARMV8_SPE_PDEV_NAME "arm,spe-v1" +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +extern const cpumask_t *arm_spe_pmu_supported_cpus(void); +#else +static inline const cpumask_t *arm_spe_pmu_supported_cpus(void) { return NULL; }; +#endif + #endif /* __ARM_PMU_H__ */ -- 2.33.0 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 49418C4338F for ; Wed, 25 Aug 2021 16:18:33 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id E3D8861153 for ; Wed, 25 Aug 2021 16:18:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E3D8861153 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 8817F4B23B; Wed, 25 Aug 2021 12:18:32 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wM2N-ERJogqa; Wed, 25 Aug 2021 12:18:28 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id AFDF54B28A; Wed, 25 Aug 2021 12:17:53 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D7E624B214 for ; Wed, 25 Aug 2021 12:17:51 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ctWSWOaFPuHr for ; Wed, 25 Aug 2021 12:17:48 -0400 (EDT) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A6FE44B266 for ; Wed, 25 Aug 2021 12:17:36 -0400 (EDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FE5D142F; Wed, 25 Aug 2021 09:17:36 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4C2A3F66F; Wed, 25 Aug 2021 09:17:34 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 15/39] drivers/perf: Expose the cpumask of CPUs that support SPE Date: Wed, 25 Aug 2021 17:17:51 +0100 Message-Id: <20210825161815.266051-16-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu KVM SPE emulation will require the list of CPUs that have hardware support for SPE. Add a function that returns the cpumask of supported CPUs discovered by the driver during probing. CC: Will Deacon Signed-off-by: Alexandru Elisei --- drivers/perf/arm_spe_pmu.c | 30 ++++++++++++++++++------------ include/linux/perf/arm_pmu.h | 7 +++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index d44bcc29d99c..40749665f102 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -50,7 +50,6 @@ struct arm_spe_pmu_buf { struct arm_spe_pmu { struct pmu pmu; struct platform_device *pdev; - cpumask_t supported_cpus; struct hlist_node hotplug_node; int irq; /* PPI */ @@ -72,6 +71,8 @@ struct arm_spe_pmu { struct perf_output_handle __percpu *handle; }; +static cpumask_t supported_cpus; + #define to_spe_pmu(p) (container_of(p, struct arm_spe_pmu, pmu)) /* Convert a free-running index from perf into an SPE buffer offset */ @@ -234,9 +235,7 @@ static const struct attribute_group arm_spe_pmu_format_group = { static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev); - - return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); + return cpumap_print_to_pagebuf(true, buf, &supported_cpus); } static DEVICE_ATTR_RO(cpumask); @@ -677,7 +676,7 @@ static int arm_spe_pmu_event_init(struct perf_event *event) return -ENOENT; if (event->cpu >= 0 && - !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus)) + !cpumask_test_cpu(event->cpu, &supported_cpus)) return -ENOENT; if (arm_spe_event_to_pmsevfr(event) & arm_spe_pmsevfr_res0(spe_pmu->pmsver)) @@ -797,11 +796,10 @@ static void arm_spe_pmu_stop(struct perf_event *event, int flags) static int arm_spe_pmu_add(struct perf_event *event, int flags) { int ret = 0; - struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu); struct hw_perf_event *hwc = &event->hw; int cpu = event->cpu == -1 ? smp_processor_id() : event->cpu; - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return -ENOENT; hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; @@ -883,6 +881,13 @@ static void arm_spe_pmu_free_aux(void *aux) kfree(buf); } +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +const cpumask_t *arm_spe_pmu_supported_cpus(void) +{ + return &supported_cpus; +} +#endif + /* Initialisation and teardown functions */ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu) { @@ -1039,7 +1044,7 @@ static void __arm_spe_pmu_dev_probe(void *info) dev_info(dev, "probed for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n", - cpumask_pr_args(&spe_pmu->supported_cpus), + cpumask_pr_args(&supported_cpus), spe_pmu->max_record_sz, spe_pmu->align, spe_pmu->features); spe_pmu->features |= SPE_PMU_FEAT_DEV_PROBED; @@ -1083,7 +1088,7 @@ static int arm_spe_pmu_cpu_startup(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_setup_one(spe_pmu); @@ -1095,7 +1100,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_stop_one(spe_pmu); @@ -1105,7 +1110,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) static int arm_spe_pmu_dev_init(struct arm_spe_pmu *spe_pmu) { int ret; - cpumask_t *mask = &spe_pmu->supported_cpus; + cpumask_t *mask = &supported_cpus; /* Make sure we probe the hardware on a relevant CPU */ ret = smp_call_function_any(mask, __arm_spe_pmu_dev_probe, spe_pmu, 1); @@ -1151,7 +1156,7 @@ static int arm_spe_pmu_irq_probe(struct arm_spe_pmu *spe_pmu) return -EINVAL; } - if (irq_get_percpu_devid_partition(irq, &spe_pmu->supported_cpus)) { + if (irq_get_percpu_devid_partition(irq, &supported_cpus)) { dev_err(&pdev->dev, "failed to get PPI partition (%d)\n", irq); return -EINVAL; } @@ -1216,6 +1221,7 @@ static int arm_spe_pmu_device_probe(struct platform_device *pdev) arm_spe_pmu_dev_teardown(spe_pmu); out_free_handle: free_percpu(spe_pmu->handle); + cpumask_clear(&supported_cpus); return ret; } diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 505480217cf1..3121d95c575b 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -8,6 +8,7 @@ #ifndef __ARM_PMU_H__ #define __ARM_PMU_H__ +#include #include #include #include @@ -177,4 +178,10 @@ void armpmu_free_irq(int irq, int cpu); #define ARMV8_SPE_PDEV_NAME "arm,spe-v1" +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +extern const cpumask_t *arm_spe_pmu_supported_cpus(void); +#else +static inline const cpumask_t *arm_spe_pmu_supported_cpus(void) { return NULL; }; +#endif + #endif /* __ARM_PMU_H__ */ -- 2.33.0 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 936CFC4338F for ; Wed, 25 Aug 2021 16:27:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 54A7760F21 for ; Wed, 25 Aug 2021 16:27:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 54A7760F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WJcI9WvskzaEEqtReqLAI7zW0M9rUfDj0loc5JP5mpU=; b=NW76EHg2CnEWVY c2FpV7uiV/FGB9m28lsiJohLxnASLgP/NQiwI5BSbJmoFXuaH2IJnXS1fjlgs4MHXnw4jJU56HuT7 8Vz1O1f/bj8da1GJRt4nXKyA6rUSz27NaLxuGJ61ajm/YDgbs/Qi1ey14BbYYQV8NhT9GKLv3PetV DrDvZspFQFzmHKOkFq0RB3xxxkCdzx8VfBt/XUr1/epGc13orllu0TZcErgq75vYtOfCKEU5JnZAs Rfc+zPkXX1mEEr/cLm4cZlazqXbTfKSQxu5Z9qTbBtVyL5G1OG+GSj0N0cFXU1P1n0ukctigUXGmp fC2gqIzvi9g20JAxE9pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIviO-007kSX-1q; Wed, 25 Aug 2021 16:25:25 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIvaq-007gXn-IC for linux-arm-kernel@lists.infradead.org; Wed, 25 Aug 2021 16:17:38 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FE5D142F; Wed, 25 Aug 2021 09:17:36 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4C2A3F66F; Wed, 25 Aug 2021 09:17:34 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 15/39] drivers/perf: Expose the cpumask of CPUs that support SPE Date: Wed, 25 Aug 2021 17:17:51 +0100 Message-Id: <20210825161815.266051-16-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210825_091736_741806_FBA70D32 X-CRM114-Status: GOOD ( 17.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 KVM SPE emulation will require the list of CPUs that have hardware support for SPE. Add a function that returns the cpumask of supported CPUs discovered by the driver during probing. CC: Will Deacon Signed-off-by: Alexandru Elisei --- drivers/perf/arm_spe_pmu.c | 30 ++++++++++++++++++------------ include/linux/perf/arm_pmu.h | 7 +++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index d44bcc29d99c..40749665f102 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -50,7 +50,6 @@ struct arm_spe_pmu_buf { struct arm_spe_pmu { struct pmu pmu; struct platform_device *pdev; - cpumask_t supported_cpus; struct hlist_node hotplug_node; int irq; /* PPI */ @@ -72,6 +71,8 @@ struct arm_spe_pmu { struct perf_output_handle __percpu *handle; }; +static cpumask_t supported_cpus; + #define to_spe_pmu(p) (container_of(p, struct arm_spe_pmu, pmu)) /* Convert a free-running index from perf into an SPE buffer offset */ @@ -234,9 +235,7 @@ static const struct attribute_group arm_spe_pmu_format_group = { static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev); - - return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); + return cpumap_print_to_pagebuf(true, buf, &supported_cpus); } static DEVICE_ATTR_RO(cpumask); @@ -677,7 +676,7 @@ static int arm_spe_pmu_event_init(struct perf_event *event) return -ENOENT; if (event->cpu >= 0 && - !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus)) + !cpumask_test_cpu(event->cpu, &supported_cpus)) return -ENOENT; if (arm_spe_event_to_pmsevfr(event) & arm_spe_pmsevfr_res0(spe_pmu->pmsver)) @@ -797,11 +796,10 @@ static void arm_spe_pmu_stop(struct perf_event *event, int flags) static int arm_spe_pmu_add(struct perf_event *event, int flags) { int ret = 0; - struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu); struct hw_perf_event *hwc = &event->hw; int cpu = event->cpu == -1 ? smp_processor_id() : event->cpu; - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return -ENOENT; hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; @@ -883,6 +881,13 @@ static void arm_spe_pmu_free_aux(void *aux) kfree(buf); } +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +const cpumask_t *arm_spe_pmu_supported_cpus(void) +{ + return &supported_cpus; +} +#endif + /* Initialisation and teardown functions */ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu) { @@ -1039,7 +1044,7 @@ static void __arm_spe_pmu_dev_probe(void *info) dev_info(dev, "probed for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n", - cpumask_pr_args(&spe_pmu->supported_cpus), + cpumask_pr_args(&supported_cpus), spe_pmu->max_record_sz, spe_pmu->align, spe_pmu->features); spe_pmu->features |= SPE_PMU_FEAT_DEV_PROBED; @@ -1083,7 +1088,7 @@ static int arm_spe_pmu_cpu_startup(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_setup_one(spe_pmu); @@ -1095,7 +1100,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) struct arm_spe_pmu *spe_pmu; spe_pmu = hlist_entry_safe(node, struct arm_spe_pmu, hotplug_node); - if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus)) + if (!cpumask_test_cpu(cpu, &supported_cpus)) return 0; __arm_spe_pmu_stop_one(spe_pmu); @@ -1105,7 +1110,7 @@ static int arm_spe_pmu_cpu_teardown(unsigned int cpu, struct hlist_node *node) static int arm_spe_pmu_dev_init(struct arm_spe_pmu *spe_pmu) { int ret; - cpumask_t *mask = &spe_pmu->supported_cpus; + cpumask_t *mask = &supported_cpus; /* Make sure we probe the hardware on a relevant CPU */ ret = smp_call_function_any(mask, __arm_spe_pmu_dev_probe, spe_pmu, 1); @@ -1151,7 +1156,7 @@ static int arm_spe_pmu_irq_probe(struct arm_spe_pmu *spe_pmu) return -EINVAL; } - if (irq_get_percpu_devid_partition(irq, &spe_pmu->supported_cpus)) { + if (irq_get_percpu_devid_partition(irq, &supported_cpus)) { dev_err(&pdev->dev, "failed to get PPI partition (%d)\n", irq); return -EINVAL; } @@ -1216,6 +1221,7 @@ static int arm_spe_pmu_device_probe(struct platform_device *pdev) arm_spe_pmu_dev_teardown(spe_pmu); out_free_handle: free_percpu(spe_pmu->handle); + cpumask_clear(&supported_cpus); return ret; } diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 505480217cf1..3121d95c575b 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -8,6 +8,7 @@ #ifndef __ARM_PMU_H__ #define __ARM_PMU_H__ +#include #include #include #include @@ -177,4 +178,10 @@ void armpmu_free_irq(int irq, int cpu); #define ARMV8_SPE_PDEV_NAME "arm,spe-v1" +#if IS_BUILTIN(CONFIG_ARM_SPE_PMU) +extern const cpumask_t *arm_spe_pmu_supported_cpus(void); +#else +static inline const cpumask_t *arm_spe_pmu_supported_cpus(void) { return NULL; }; +#endif + #endif /* __ARM_PMU_H__ */ -- 2.33.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel