Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1052868rwd; Thu, 15 Jun 2023 05:54:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SWi13ZSaNsDCarcOB7i+FKdz2gF8E826b8BBOwjkATNUwlYNatH8Smx9cMHdnkWx7GauF X-Received: by 2002:a05:6808:14cf:b0:397:f6c7:c5b3 with SMTP id f15-20020a05680814cf00b00397f6c7c5b3mr16781273oiw.16.1686833675923; Thu, 15 Jun 2023 05:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686833675; cv=none; d=google.com; s=arc-20160816; b=XgomJxLI5EFIVYWCHgSmEc4DGwL5V7u111zuAnyRXcNvnlenS5OqolfrylIFwNM/RU 3jtcMKkZDsqVwmCk+fOvX5DEn39yzBAiFpXEG928Znl/VpHFuxzp25+bbhjV2Kzav8ue zj3R7zUcnAzeOufgAYR5poNLRpDDQ57Rj+lqlqkLhY0aMXcCqbEHUGuMBmmkgmN/Ub1Z +Z6fCTnotdoSAor9q8K1JPFMZqyJqbixTMet3mM/wCGQ/D5QhHSMioof7693CAlgskOx 2iWR1D1igSD8xJKxSEeWn8zM8HgfrwVNKJ/nx2XX5tqQ+XAaqxawLDwq1z7Y7q5Sh/UU tF1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=A63IJX3KC8Y+nus7+DsSWREIxAO0mvpMgpfyNd9tIhg=; b=NCmvqIsTZGlZeGjdt7aUwQB9RCtVOeIh024fuqUjX68i0R7Rl+b5+aU3riOrLZPIG5 /k/pLrSHJ+vWCB73YyQ/4Qw5N3ASXcF2H0GPg/nIn2DyD4bLKcis4Kj11wDewK6z+7xD FaB2Xv0B4JlgHqaHdngUOkeq2SyJ+MtpolvOT9HA24s/HRIJTbvoJtdak7xFgktr1t7p ggSth2d5okBJSIgBa+nu7ybVchR3W9tD+3HH5PWkyCDV6jWMVj3/4lLEKY1d2ntoatEP H6a7J2mhOlMXZxWOFYVTZzL0p6lAyhnj0pVvcyYAK624rOEloopWNSzQJApvkACyp0Q7 Jrkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a63b250000000b0053f265b0ef2si129650pgo.471.2023.06.15.05.54.23; Thu, 15 Jun 2023 05:54:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344617AbjFOMF0 (ORCPT + 99 others); Thu, 15 Jun 2023 08:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344771AbjFOMEy (ORCPT ); Thu, 15 Jun 2023 08:04:54 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD262978; Thu, 15 Jun 2023 05:02:52 -0700 (PDT) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QhgM33RrkzqTt6; Thu, 15 Jun 2023 19:39:59 +0800 (CST) Received: from [10.67.103.44] (10.67.103.44) by dggpeml500002.china.huawei.com (7.185.36.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 15 Jun 2023 19:44:58 +0800 Subject: Re: [PATCH v4 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver To: Mark Rutland References: <20230609075608.36559-1-hejunhao3@huawei.com> <20230609075608.36559-2-hejunhao3@huawei.com> CC: , , , , , , , , From: hejunhao Message-ID: <1041ca74-9e63-f232-c0dd-fd14cc4b1e11@huawei.com> Date: Thu, 15 Jun 2023 19:44:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.103.44] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500002.china.huawei.com (7.185.36.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Mark Thanks for your comments. On 2023/6/9 16:53, Mark Rutland wrote: > Hi, > > This generally looks ok, but I have a few minor comments. > > On Fri, Jun 09, 2023 at 03:56:06PM +0800, Junhao He wrote: >> Compared to the original PA device, H60PA offers higher bandwidth. >> The H60PA is a new device and we use HID to differentiate them. >> >> The events supported by PAv3 and PAv2 are different. They use the >> same HID. > That's a bit unfortunate -- doesn't that mean an older kernel that knows about > v2 will try to probe v3 as v2? Presumably things will go wrong if it pokes the > MMIO registers? > > I appreciate it may be too late to change that now, but it seems like something > to consider in future (e.g. any changes not backwards compatible with v3 should > use a new HID). Yes, The older PA PMU driver will probe v3 as v2. And the PAv3 PMU removed some events which are supported by PAv2 PMU. Therefore, the PA events displayed by "perf list" cannot work properly. We plan to add new HID for PAv3 PMU in next version. Thanks. >> The PMU version register is used in the driver to >> distinguish different versions. >> >> For each H60PA PMU, except for the overflow interrupt register, other >> functions of the H60PA PMU are the same as the original PA PMU module. >> It has 8-programable counters and each counter is free-running. >> Interrupt is supported to handle counter (64-bits) overflow. >> >> Signed-off-by: Junhao He >> Reviewed-by: Jonathan Cameron >> Reviewed-by: Yicong Yang >> --- >> drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 142 +++++++++++++++++--- >> drivers/perf/hisilicon/hisi_uncore_pmu.h | 9 ++ >> 2 files changed, 136 insertions(+), 15 deletions(-) >> @@ -284,6 +302,15 @@ static int hisi_pa_pmu_init_data(struct platform_device *pdev, >> >> pa_pmu->identifier = readl(pa_pmu->base + PA_PMU_VERSION); >> >> + /* When running on v3 or later, returns the largest version supported */ >> + if (pa_pmu->identifier >= HISI_PMU_V3) >> + pa_pmu->dev_info = &pa_pmu_info[2]; >> + else if (pa_pmu->identifier == HISI_PMU_V2) >> + pa_pmu->dev_info = &pa_pmu_info[1]; >> + >> + if (!pa_pmu->dev_info || !pa_pmu->dev_info->name) >> + return -EINVAL; >> + > Why does this use indices '2' and '1'? What happened to '0'? > > It would be a bit clearer with something like: > > enum pmu_dev_info_idx { > HISI_PMU_DEV_INFO_V2, > HISI_PMU_DEV_INFO_V3, > NR_HISI_PMU_DEV_INFO > } > > Then the above can be: > > if (pa_pmu->identifier >= HISI_PMU_V3) > pa_pmu->dev_info = &pa_pmu_info[PMU_DEV_INFO_V3]; > else if (pa_pmu->identifier == HISI_PMU_V2) > pa_pmu->dev_info = &pa_pmu_info[PMU_DEV_INFO_V2]; > else > return -EINVAL; > > if (!pa_pmu->dev_info->name) > return -EINVAL; > > ... and when you define the dev_info instances: Because of add new HID for PAv3, I'm going to replace the code with the following: pa_pmu->dev_info = pa_pmu_info; >> +static const struct hisi_pmu_dev_info hisi_h32pa[] = { >> + [1] = { >> + .name = "pa", >> + .attr_groups = hisi_pa_pmu_v2_attr_groups, >> + .private = &hisi_pa_pmu_regs, >> + }, >> + [2] = { >> + .name = "pa", >> + .attr_groups = hisi_pa_pmu_v3_attr_groups, >> + .private = &hisi_pa_pmu_regs, >> + }, >> + {} >> +}; > ... you could have: > > static const struct hisi_pmu_dev_info hisi_h32pa[NR_HISI_PMU_DEV_INFO] = { > [HISI_PMU_DEV_INFO_V2] = { > .name = "pa", > .attr_groups = hisi_pa_pmu_v2_attr_groups, > .private = &hisi_pa_pmu_regs, > }, > [HISI_PMU_DEV_INFO_V3] = { > .name = "pa", > .attr_groups = hisi_pa_pmu_v3_attr_groups, > .private = &hisi_pa_pmu_regs, > }, > }; > > ... which would clearly match up with the probe path, and would ensure the > arrays are always correctly sized if there's a v4, etc. and the initialization of the xxx_dev_info structure is as follows: struct hisi_pmu_dev_info hisi_h32pa_v2 = { ... } struct hisi_pmu_dev_info hisi_h32pa_v3 = { ... } > >> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h >> index 07890a8e96ca..a8d6d6905f3f 100644 >> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.h >> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h >> @@ -24,6 +24,7 @@ >> #define pr_fmt(fmt) "hisi_pmu: " fmt >> >> #define HISI_PMU_V2 0x30 >> +#define HISI_PMU_V3 0x40 >> #define HISI_MAX_COUNTERS 0x10 >> #define to_hisi_pmu(p) (container_of(p, struct hisi_pmu, pmu)) >> >> @@ -62,6 +63,13 @@ struct hisi_uncore_ops { >> void (*disable_filter)(struct perf_event *event); >> }; >> >> +/* Describes the HISI PMU chip features information */ >> +struct hisi_pmu_dev_info { >> + const char *name; >> + const struct attribute_group **attr_groups; >> + void *private; >> +}; >> + >> struct hisi_pmu_hwevents { >> struct perf_event *hw_events[HISI_MAX_COUNTERS]; >> DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS); >> @@ -72,6 +80,7 @@ struct hisi_pmu_hwevents { >> struct hisi_pmu { >> struct pmu pmu; >> const struct hisi_uncore_ops *ops; >> + const struct hisi_pmu_dev_info *dev_info; >> struct hisi_pmu_hwevents pmu_events; >> /* associated_cpus: All CPUs associated with the PMU */ >> cpumask_t associated_cpus; > Will other hisi pmu drivers use the hisi_pmu_dev_info field in future? yes, It is. and the member of private is also a general interface. If other uncore PMU have private implementations in registers or other, this member can also be used. Best regards, Junhao. > > I ask because otherwise you could make this local to hisi_uncore_pa_pmu.c if > you structured this as: > > struct hisi_pa_pmu { > struct hisi_pmu; > const char *name; > const struct attribute_group **attr_groups; > const struct hisi_pa_pmu_int_regs *regs; > } > > ... which would give you some additional type-safety. > > Thanks, > Mark > > . >