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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B84CED3000A for ; Fri, 18 Oct 2024 13:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:CC: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=pN2ypICIiPSTvHhbKaPVnCTJPiyL4bExuo8ik46FEIo=; b=Sx5xf5pccFY6JUCtFk1E9xNfqq gsDlFixFQK3mTOoWeGWJINzeSJlxgeV0gsfLGn0sVx8KT9olis4EWwVHJWPk4Gz4+Ss2sLY428nXe phtukvmAOF5s/x990t76yVP8NrwcGyAQL5xnGldWMEITQopUbCaSlom1qjGwypYjpc28zPtERgYE4 FCAWcBiJ5iWznfYUeCDCVjSDfC3EdTGCCObygVyFJfrWrFfXmhwoj4GXv0wQHXmxeChhgckDBAAnh 8muGbyuYqq8RY9ZfrI8/7cBfPnIwHdiz1qqFksLTxfXE9CwFmP9U3QEh45w+6R7A53CihTvr/86nF 9fwmpwsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1nOu-00000000xnH-3QOn; Fri, 18 Oct 2024 13:52:20 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1nKP-00000000wvM-3KeN for linux-arm-kernel@lists.infradead.org; Fri, 18 Oct 2024 13:47:45 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XVQvX569yz6GBLQ; Fri, 18 Oct 2024 21:45:44 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E84E3140B3C; Fri, 18 Oct 2024 21:47:31 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 18 Oct 2024 15:47:31 +0200 Date: Fri, 18 Oct 2024 14:47:29 +0100 From: Jonathan Cameron To: Yicong Yang CC: , , , , , , , Subject: Re: [PATCH 5/8] drivers/perf: hisi: Refactor the attributes creation Message-ID: <20241018144729.00005ea3@Huawei.com> In-Reply-To: <20241018095745.57057-6-yangyicong@huawei.com> References: <20241018095745.57057-1-yangyicong@huawei.com> <20241018095745.57057-6-yangyicong@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_064742_190594_724555C5 X-CRM114-Status: GOOD ( 21.74 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 18 Oct 2024 17:57:42 +0800 Yicong Yang wrote: > From: Yicong Yang > > Each type of HiSilicon Uncore PMU has the following sysfs attributes: > > - format: bitmask in perf_event_attr::config[012] of corresponding > attribute > - event: events name and corresponding event code > - cpumask: range of CPUs the events can be opened on > - identifier: the version of this PMU > > Different types of PMU have different implementations of the "format" > and "event" but all share the same implementation of the "cpumask" > and "identifier". Thus we can move cpumask and identifier to the > hisi_uncore_pmu framework and drivers can use the generic > implementation. > > Signed-off-by: Yicong Yang Is there a reason to move to code setting all 4 elements vs just using the extern struct attribute_group in the static const arrays? e.g. static const struct attribute_group *hisi_uc_pmu_attr_groups[] = { &hisi_uc_pmu_format_group, &hisi_uc_pmu_events_group, &hisi_pmu_cpumask_attr_group, &hisi_pmu_identifier_group, NULL }; mixing attributes defined in each module with those coming from the core module? For the cases where it varies between versions of the PMU, just have a bunch of such arrays to pick from. I might be missing some subtle issue, but a really quick hack shows it builds fine. Jonathan > --- > drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c | 41 +++---------- > drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c | 55 +++++------------- > drivers/perf/hisilicon/hisi_uncore_hha_pmu.c | 57 ++++++------------- > drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c | 55 +++++------------- > drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 39 +++---------- > drivers/perf/hisilicon/hisi_uncore_pmu.c | 45 +++++++++++---- > drivers/perf/hisilicon/hisi_uncore_pmu.h | 14 ++++- > drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c | 41 +++---------- > drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 41 +++---------- > 9 files changed, 128 insertions(+), 260 deletions(-) > > diff --git a/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c > index bd1c1799f935..4dd52eba9f27 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c > @@ -225,37 +225,6 @@ static const struct attribute_group hisi_cpa_pmu_events_group = { > .attrs = hisi_cpa_pmu_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_cpa_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_cpa_pmu_cpumask_attr_group = { > - .attrs = hisi_cpa_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_cpa_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_cpa_pmu_identifier_attrs[] = { > - &hisi_cpa_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_cpa_pmu_identifier_group = { > - .attrs = hisi_cpa_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_cpa_pmu_attr_groups[] = { > - &hisi_cpa_pmu_format_group, > - &hisi_cpa_pmu_events_group, > - &hisi_cpa_pmu_cpumask_attr_group, > - &hisi_cpa_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_cpa_pmu_ops = { > .write_evtype = hisi_cpa_pmu_write_evtype, > .get_event_idx = hisi_uncore_pmu_get_event_idx, > @@ -274,6 +243,7 @@ static const struct hisi_uncore_ops hisi_uncore_cpa_pmu_ops = { > static int hisi_cpa_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *cpa_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &cpa_pmu->pmu_events; > int ret; > > ret = hisi_cpa_pmu_init_data(pdev, cpa_pmu); > @@ -286,7 +256,14 @@ static int hisi_cpa_pmu_dev_probe(struct platform_device *pdev, > > cpa_pmu->counter_bits = CPA_COUNTER_BITS; > cpa_pmu->check_event = CPA_NR_EVENTS; > - cpa_pmu->pmu_events.attr_groups = hisi_cpa_pmu_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_cpa_pmu_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_cpa_pmu_events_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > cpa_pmu->ops = &hisi_uncore_cpa_pmu_ops; > cpa_pmu->num_counters = CPA_NR_COUNTERS; > cpa_pmu->dev = &pdev->dev; > diff --git a/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c > index 415a95e24993..6d805ca4562f 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c > @@ -380,45 +380,6 @@ static const struct attribute_group hisi_ddrc_pmu_v2_events_group = { > .attrs = hisi_ddrc_pmu_v2_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_ddrc_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL, > -}; > - > -static const struct attribute_group hisi_ddrc_pmu_cpumask_attr_group = { > - .attrs = hisi_ddrc_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_ddrc_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_ddrc_pmu_identifier_attrs[] = { > - &hisi_ddrc_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_ddrc_pmu_identifier_group = { > - .attrs = hisi_ddrc_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_ddrc_pmu_v1_attr_groups[] = { > - &hisi_ddrc_pmu_v1_format_group, > - &hisi_ddrc_pmu_v1_events_group, > - &hisi_ddrc_pmu_cpumask_attr_group, > - &hisi_ddrc_pmu_identifier_group, > - NULL, > -}; > - > -static const struct attribute_group *hisi_ddrc_pmu_v2_attr_groups[] = { > - &hisi_ddrc_pmu_v2_format_group, > - &hisi_ddrc_pmu_v2_events_group, > - &hisi_ddrc_pmu_cpumask_attr_group, > - &hisi_ddrc_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_ddrc_v1_ops = { > .write_evtype = hisi_ddrc_pmu_write_evtype, > .get_event_idx = hisi_ddrc_pmu_v1_get_event_idx, > @@ -452,6 +413,7 @@ static const struct hisi_uncore_ops hisi_uncore_ddrc_v2_ops = { > static int hisi_ddrc_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *ddrc_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &ddrc_pmu->pmu_events; > int ret; > > ret = hisi_ddrc_pmu_init_data(pdev, ddrc_pmu); > @@ -465,15 +427,26 @@ static int hisi_ddrc_pmu_dev_probe(struct platform_device *pdev, > if (ddrc_pmu->identifier >= HISI_PMU_V2) { > ddrc_pmu->counter_bits = 48; > ddrc_pmu->check_event = DDRC_V2_NR_EVENTS; > - ddrc_pmu->pmu_events.attr_groups = hisi_ddrc_pmu_v2_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_ddrc_pmu_v2_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_ddrc_pmu_v2_events_group; > ddrc_pmu->ops = &hisi_uncore_ddrc_v2_ops; > } else { > ddrc_pmu->counter_bits = 32; > ddrc_pmu->check_event = DDRC_V1_NR_EVENTS; > - ddrc_pmu->pmu_events.attr_groups = hisi_ddrc_pmu_v1_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_ddrc_pmu_v1_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_ddrc_pmu_v1_events_group; > ddrc_pmu->ops = &hisi_uncore_ddrc_v1_ops; > } > > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > + > ddrc_pmu->num_counters = DDRC_NR_COUNTERS; > ddrc_pmu->dev = &pdev->dev; > ddrc_pmu->on_cpu = -1; > diff --git a/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c b/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c > index 43554e4f8a36..07cab6cf4897 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c > @@ -405,45 +405,6 @@ static const struct attribute_group hisi_hha_pmu_v2_events_group = { > .attrs = hisi_hha_pmu_v2_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_hha_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL, > -}; > - > -static const struct attribute_group hisi_hha_pmu_cpumask_attr_group = { > - .attrs = hisi_hha_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_hha_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_hha_pmu_identifier_attrs[] = { > - &hisi_hha_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_hha_pmu_identifier_group = { > - .attrs = hisi_hha_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_hha_pmu_v1_attr_groups[] = { > - &hisi_hha_pmu_v1_format_group, > - &hisi_hha_pmu_v1_events_group, > - &hisi_hha_pmu_cpumask_attr_group, > - &hisi_hha_pmu_identifier_group, > - NULL, > -}; > - > -static const struct attribute_group *hisi_hha_pmu_v2_attr_groups[] = { > - &hisi_hha_pmu_v2_format_group, > - &hisi_hha_pmu_v2_events_group, > - &hisi_hha_pmu_cpumask_attr_group, > - &hisi_hha_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_hha_ops = { > .write_evtype = hisi_hha_pmu_write_evtype, > .get_event_idx = hisi_uncore_pmu_get_event_idx, > @@ -464,6 +425,7 @@ static const struct hisi_uncore_ops hisi_uncore_hha_ops = { > static int hisi_hha_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *hha_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &hha_pmu->pmu_events; > int ret; > > ret = hisi_hha_pmu_init_data(pdev, hha_pmu); > @@ -477,14 +439,27 @@ static int hisi_hha_pmu_dev_probe(struct platform_device *pdev, > if (hha_pmu->identifier >= HISI_PMU_V2) { > hha_pmu->counter_bits = 64; > hha_pmu->check_event = HHA_V2_NR_EVENT; > - hha_pmu->pmu_events.attr_groups = hisi_hha_pmu_v2_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_hha_pmu_v2_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_hha_pmu_v2_events_group; > hha_pmu->num_counters = HHA_V2_NR_COUNTERS; > } else { > hha_pmu->counter_bits = 48; > hha_pmu->check_event = HHA_V1_NR_EVENT; > - hha_pmu->pmu_events.attr_groups = hisi_hha_pmu_v1_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_hha_pmu_v1_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_hha_pmu_v1_events_group; > hha_pmu->num_counters = HHA_V1_NR_COUNTERS; > } > + > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > + > + > hha_pmu->ops = &hisi_uncore_hha_ops; > hha_pmu->dev = &pdev->dev; > hha_pmu->on_cpu = -1; > diff --git a/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c b/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c > index b113620d27f9..6f540ab1f451 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c > @@ -441,45 +441,6 @@ static const struct attribute_group hisi_l3c_pmu_v2_events_group = { > .attrs = hisi_l3c_pmu_v2_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_l3c_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL, > -}; > - > -static const struct attribute_group hisi_l3c_pmu_cpumask_attr_group = { > - .attrs = hisi_l3c_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_l3c_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_l3c_pmu_identifier_attrs[] = { > - &hisi_l3c_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_l3c_pmu_identifier_group = { > - .attrs = hisi_l3c_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_l3c_pmu_v1_attr_groups[] = { > - &hisi_l3c_pmu_v1_format_group, > - &hisi_l3c_pmu_v1_events_group, > - &hisi_l3c_pmu_cpumask_attr_group, > - &hisi_l3c_pmu_identifier_group, > - NULL, > -}; > - > -static const struct attribute_group *hisi_l3c_pmu_v2_attr_groups[] = { > - &hisi_l3c_pmu_v2_format_group, > - &hisi_l3c_pmu_v2_events_group, > - &hisi_l3c_pmu_cpumask_attr_group, > - &hisi_l3c_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_l3c_ops = { > .write_evtype = hisi_l3c_pmu_write_evtype, > .get_event_idx = hisi_uncore_pmu_get_event_idx, > @@ -500,6 +461,7 @@ static const struct hisi_uncore_ops hisi_uncore_l3c_ops = { > static int hisi_l3c_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *l3c_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &l3c_pmu->pmu_events; > int ret; > > ret = hisi_l3c_pmu_init_data(pdev, l3c_pmu); > @@ -513,13 +475,24 @@ static int hisi_l3c_pmu_dev_probe(struct platform_device *pdev, > if (l3c_pmu->identifier >= HISI_PMU_V2) { > l3c_pmu->counter_bits = 64; > l3c_pmu->check_event = L3C_V2_NR_EVENTS; > - l3c_pmu->pmu_events.attr_groups = hisi_l3c_pmu_v2_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_l3c_pmu_v2_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_l3c_pmu_v2_events_group; > } else { > l3c_pmu->counter_bits = 48; > l3c_pmu->check_event = L3C_V1_NR_EVENTS; > - l3c_pmu->pmu_events.attr_groups = hisi_l3c_pmu_v1_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_l3c_pmu_v1_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_l3c_pmu_v1_events_group; > } > > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > + > l3c_pmu->num_counters = L3C_NR_COUNTERS; > l3c_pmu->ops = &hisi_uncore_l3c_ops; > l3c_pmu->dev = &pdev->dev; > diff --git a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c > index dbe4d7b97b2b..69931e73a3cd 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c > @@ -353,29 +353,6 @@ static const struct attribute_group hisi_h60pa_pmu_events_group = { > .attrs = hisi_h60pa_pmu_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_pa_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_pa_pmu_cpumask_attr_group = { > - .attrs = hisi_pa_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_pa_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_pa_pmu_identifier_attrs[] = { > - &hisi_pa_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_pa_pmu_identifier_group = { > - .attrs = hisi_pa_pmu_identifier_attrs, > -}; > - > static struct hisi_pa_pmu_int_regs hisi_pa_pmu_regs = { > .mask_offset = PA_INT_MASK, > .clear_offset = PA_INT_CLEAR, > @@ -385,8 +362,6 @@ static struct hisi_pa_pmu_int_regs hisi_pa_pmu_regs = { > static const struct attribute_group *hisi_pa_pmu_v2_attr_groups[] = { > &hisi_pa_pmu_v2_format_group, > &hisi_pa_pmu_v2_events_group, > - &hisi_pa_pmu_cpumask_attr_group, > - &hisi_pa_pmu_identifier_group, > NULL > }; > > @@ -399,8 +374,6 @@ static const struct hisi_pmu_dev_info hisi_h32pa_v2 = { > static const struct attribute_group *hisi_pa_pmu_v3_attr_groups[] = { > &hisi_pa_pmu_v2_format_group, > &hisi_pa_pmu_v3_events_group, > - &hisi_pa_pmu_cpumask_attr_group, > - &hisi_pa_pmu_identifier_group, > NULL > }; > > @@ -419,8 +392,6 @@ static struct hisi_pa_pmu_int_regs hisi_h60pa_pmu_regs = { > static const struct attribute_group *hisi_h60pa_pmu_attr_groups[] = { > &hisi_pa_pmu_v2_format_group, > &hisi_h60pa_pmu_events_group, > - &hisi_pa_pmu_cpumask_attr_group, > - &hisi_pa_pmu_identifier_group, > NULL > }; > > @@ -450,6 +421,7 @@ static const struct hisi_uncore_ops hisi_uncore_pa_ops = { > static int hisi_pa_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *pa_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &pa_pmu->pmu_events; > int ret; > > ret = hisi_pa_pmu_init_data(pdev, pa_pmu); > @@ -460,7 +432,14 @@ static int hisi_pa_pmu_dev_probe(struct platform_device *pdev, > if (ret) > return ret; > > - pa_pmu->pmu_events.attr_groups = pa_pmu->dev_info->attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + pa_pmu->dev_info->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT]; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + pa_pmu->dev_info->attr_groups[HISI_PMU_ATTR_GROUP_EVENT]; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > pa_pmu->num_counters = PA_NR_COUNTERS; > pa_pmu->ops = &hisi_uncore_pa_ops; > pa_pmu->check_event = 0xB0; > diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c > index e1756e639784..648d0e5e08ed 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c > @@ -49,6 +49,41 @@ ssize_t hisi_cpumask_sysfs_show(struct device *dev, > } > EXPORT_SYMBOL_NS_GPL(hisi_cpumask_sysfs_show, HISI_PMU); > > +static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > + > +static struct attribute *hisi_pmu_cpumask_attrs[] = { > + &dev_attr_cpumask.attr, > + NULL > +}; > + > +const struct attribute_group hisi_pmu_cpumask_attr_group = { > + .attrs = hisi_pmu_cpumask_attrs, > +}; > +EXPORT_SYMBOL_NS_GPL(hisi_pmu_cpumask_attr_group, HISI_PMU); > + > +ssize_t hisi_uncore_pmu_identifier_attr_show(struct device *dev, > + struct device_attribute *attr, > + char *page) > +{ > + struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev)); > + > + return sysfs_emit(page, "0x%08x\n", hisi_pmu->identifier); > +} > +EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_identifier_attr_show, HISI_PMU); > + > +static struct device_attribute hisi_pmu_identifier_attr = > + __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > + > +static struct attribute *hisi_pmu_identifier_attrs[] = { > + &hisi_pmu_identifier_attr.attr, > + NULL > +}; > + > +const struct attribute_group hisi_pmu_identifier_group = { > + .attrs = hisi_pmu_identifier_attrs, > +}; > +EXPORT_SYMBOL_NS_GPL(hisi_pmu_identifier_group, HISI_PMU); > + > static bool hisi_validate_event_group(struct perf_event *event) > { > struct perf_event *sibling, *leader = event->group_leader; > @@ -99,16 +134,6 @@ int hisi_uncore_pmu_get_event_idx(struct perf_event *event) > } > EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_get_event_idx, HISI_PMU); > > -ssize_t hisi_uncore_pmu_identifier_attr_show(struct device *dev, > - struct device_attribute *attr, > - char *page) > -{ > - struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev)); > - > - return sysfs_emit(page, "0x%08x\n", hisi_pmu->identifier); > -} > -EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_identifier_attr_show, HISI_PMU); > - > static void hisi_uncore_pmu_clear_event_idx(struct hisi_pmu *hisi_pmu, int idx) > { > clear_bit(idx, hisi_pmu->pmu_events.used_mask); > diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h > index 239c45d847b3..ac2be8c337b7 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_pmu.h > +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h > @@ -77,10 +77,22 @@ struct hisi_pmu_dev_info { > void *private; > }; > > +enum hisi_pmu_attr_groups { > + HISI_PMU_ATTR_GROUP_FORMAT, > + HISI_PMU_ATTR_GROUP_EVENT, > + HISI_PMU_ATTR_GROUP_CPUMASK, > + HISI_PMU_ATTR_GROUP_IDENTIFIER, > + HISI_PMU_ATTR_GROUP_NR > +}; > + > +/* Generic implementation of cpumask/identifier group */ > +extern const struct attribute_group hisi_pmu_cpumask_attr_group; > +extern const struct attribute_group hisi_pmu_identifier_group; > + > struct hisi_pmu_hwevents { > struct perf_event *hw_events[HISI_MAX_COUNTERS]; > DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS); > - const struct attribute_group **attr_groups; > + const struct attribute_group *attr_groups[HISI_PMU_ATTR_GROUP_NR + 1]; > }; > > /** > diff --git a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c > index 43cbdf0fb7c7..676a7078f2ef 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c > @@ -344,37 +344,6 @@ static const struct attribute_group hisi_sllc_pmu_v2_events_group = { > .attrs = hisi_sllc_pmu_v2_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_sllc_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_sllc_pmu_cpumask_attr_group = { > - .attrs = hisi_sllc_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_sllc_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_sllc_pmu_identifier_attrs[] = { > - &hisi_sllc_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_sllc_pmu_identifier_group = { > - .attrs = hisi_sllc_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_sllc_pmu_v2_attr_groups[] = { > - &hisi_sllc_pmu_v2_format_group, > - &hisi_sllc_pmu_v2_events_group, > - &hisi_sllc_pmu_cpumask_attr_group, > - &hisi_sllc_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_sllc_ops = { > .write_evtype = hisi_sllc_pmu_write_evtype, > .get_event_idx = hisi_uncore_pmu_get_event_idx, > @@ -395,6 +364,7 @@ static const struct hisi_uncore_ops hisi_uncore_sllc_ops = { > static int hisi_sllc_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *sllc_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &sllc_pmu->pmu_events; > int ret; > > ret = hisi_sllc_pmu_init_data(pdev, sllc_pmu); > @@ -405,7 +375,14 @@ static int hisi_sllc_pmu_dev_probe(struct platform_device *pdev, > if (ret) > return ret; > > - sllc_pmu->pmu_events.attr_groups = hisi_sllc_pmu_v2_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_sllc_pmu_v2_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_sllc_pmu_v2_events_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > sllc_pmu->ops = &hisi_uncore_sllc_ops; > sllc_pmu->check_event = SLLC_NR_EVENTS; > sllc_pmu->counter_bits = 64; > diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > index 2040f6a8871e..c2ae852f6b19 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > @@ -437,37 +437,6 @@ static const struct attribute_group hisi_uc_pmu_events_group = { > .attrs = hisi_uc_pmu_events_attr, > }; > > -static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL); > - > -static struct attribute *hisi_uc_pmu_cpumask_attrs[] = { > - &dev_attr_cpumask.attr, > - NULL, > -}; > - > -static const struct attribute_group hisi_uc_pmu_cpumask_attr_group = { > - .attrs = hisi_uc_pmu_cpumask_attrs, > -}; > - > -static struct device_attribute hisi_uc_pmu_identifier_attr = > - __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL); > - > -static struct attribute *hisi_uc_pmu_identifier_attrs[] = { > - &hisi_uc_pmu_identifier_attr.attr, > - NULL > -}; > - > -static const struct attribute_group hisi_uc_pmu_identifier_group = { > - .attrs = hisi_uc_pmu_identifier_attrs, > -}; > - > -static const struct attribute_group *hisi_uc_pmu_attr_groups[] = { > - &hisi_uc_pmu_format_group, > - &hisi_uc_pmu_events_group, > - &hisi_uc_pmu_cpumask_attr_group, > - &hisi_uc_pmu_identifier_group, > - NULL > -}; > - > static const struct hisi_uncore_ops hisi_uncore_uc_pmu_ops = { > .check_filter = hisi_uc_pmu_check_filter, > .write_evtype = hisi_uc_pmu_write_evtype, > @@ -489,6 +458,7 @@ static const struct hisi_uncore_ops hisi_uncore_uc_pmu_ops = { > static int hisi_uc_pmu_dev_probe(struct platform_device *pdev, > struct hisi_pmu *uc_pmu) > { > + struct hisi_pmu_hwevents *pmu_events = &uc_pmu->pmu_events; > int ret; > > ret = hisi_uc_pmu_init_data(pdev, uc_pmu); > @@ -499,7 +469,14 @@ static int hisi_uc_pmu_dev_probe(struct platform_device *pdev, > if (ret) > return ret; > > - uc_pmu->pmu_events.attr_groups = hisi_uc_pmu_attr_groups; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_FORMAT] = > + &hisi_uc_pmu_format_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_EVENT] = > + &hisi_uc_pmu_events_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_CPUMASK] = > + &hisi_pmu_cpumask_attr_group; > + pmu_events->attr_groups[HISI_PMU_ATTR_GROUP_IDENTIFIER] = > + &hisi_pmu_identifier_group; > uc_pmu->check_event = HISI_UC_EVTYPE_MASK; > uc_pmu->ops = &hisi_uncore_uc_pmu_ops; > uc_pmu->counter_bits = HISI_UC_CNTR_REG_BITS;