Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2348808rdb; Tue, 10 Oct 2023 00:46:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEI8FN/l+TTj3LyFj9XA5Z+OyfzuraMdHvYKr7btkyko5RvmC6onXZkjmc/1aEvJuQZY1aL X-Received: by 2002:a05:6870:71ce:b0:1dd:7fa9:ebe9 with SMTP id p14-20020a05687071ce00b001dd7fa9ebe9mr17803540oag.12.1696923985564; Tue, 10 Oct 2023 00:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696923985; cv=none; d=google.com; s=arc-20160816; b=wcjKtlYwPO+1ExzBLahP/FFJbAl1VjM5VfG6fEhnkhcEfZVSZ6kjKvQufGGtxH4RdC yZXfkQNbIm3f0yHvtGoObI0+oIY2Y1VZn2t6jmXLQzIsZGNs4t6gCzF9iJZA+SGTUnXk rr6d4P0Soa7L3scu6EwfLMMEqRV4KXKYOgbXVnYRwV7kCSBWMBpmD0cNEXCvUOQph95m a21RobQ3kUSL+YCweYMXVYNMqtxX5JEfckO3NYmTpbhy0ik2lhXNzh4LD49ustuE3XR/ TCR0pRjjRMcI+Qk2fPAvOrcA3mk5z6zUrNplSIEcpWLYUkauErbvN+U8SJXvP6KbJgkf e6Zw== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=jh04fJQepTs5RedhC/JEPRs/Cqlw/UqC4zKlG5vkg00=; fh=VMEsxdYIliYA/VyfOPSr0m29bXh3TKXrhNyYK0wiSqk=; b=CQJoo95BAhgb8cZjNHH0734c/D1mMGMo7ttQRLZ8RbU70j3A1x5qMuQqGuhSDmMcJg PSh4D5kl7IL7pignyOmi0cpDNWqm+fJXTEgdEXE4ySZzxmMmEbeawjkWAvxa0lNnfV7F EJVw+SavkFuZxXsVhbzTwAbIfr/2zokZ4UWu9Gc+Gwa49vCyWsECMStT56PiehfXHdKD 1HWbMorzHTmLR9bx4loZkLNux64TytRk8HdTjHonDCyo+azgZdKKnmIKgvxWnFikTIk8 l/b1S8EX7W8ZQdPOEA+i5MaTapzKK8vYN8VDjigWINSxihDgS3AdXWpZApgk12f0ZI5X sc0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u62-20020a638541000000b005784d9e065dsi11216466pgd.25.2023.10.10.00.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 00:46:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 35077812AD1A; Tue, 10 Oct 2023 00:45:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442506AbjJJHpl (ORCPT + 99 others); Tue, 10 Oct 2023 03:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442419AbjJJHpk (ORCPT ); Tue, 10 Oct 2023 03:45:40 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A44F92; Tue, 10 Oct 2023 00:45:37 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0Vts15mk_1696923932; Received: from 30.240.114.194(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0Vts15mk_1696923932) by smtp.aliyun-inc.com; Tue, 10 Oct 2023 15:45:34 +0800 Message-ID: Date: Tue, 10 Oct 2023 15:45:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v6 3/4] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-US To: Yicong Yang , Jonathan Cameron Cc: yangyicong@hisilicon.com, chengyou@linux.alibaba.com, kaishen@linux.alibaba.com, helgaas@kernel.org, will@kernel.org, baolin.wang@linux.alibaba.com, robin.murphy@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, rdunlap@infradead.org, mark.rutland@arm.com, zhuo.song@linux.alibaba.com References: <20230606074938.97724-1-xueshuai@linux.alibaba.com> <20230606074938.97724-4-xueshuai@linux.alibaba.com> <31e2b012-3a29-d063-842d-e3f7736816e7@huawei.com> <20230727103929.00000544@Huawei.com> <12958abe-4bdb-8532-bf67-8e772ed2a9dd@linux.alibaba.com> <10176239-78c1-e276-e74f-a6e79b9c0751@linux.alibaba.com> <1ebf5862-441f-729a-32c1-8e59ac452168@linux.alibaba.com> <262abac1-39ea-7612-e198-6bc08c76dd39@linux.alibaba.com> <0e4f5e36-57bb-8c3e-4757-b1b8ff76c09d@huawei.com> From: Shuai Xue In-Reply-To: <0e4f5e36-57bb-8c3e-4757-b1b8ff76c09d@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 00:45:44 -0700 (PDT) On 2023/10/10 15:35, Yicong Yang wrote: > On 2023/10/9 21:08, Shuai Xue wrote: >> >> >> On 2023/8/4 11:09, Shuai Xue wrote: >>> >>> >>> On 2023/8/4 10:28, Yicong Yang wrote: >>>> On 2023/8/4 9:39, Shuai Xue wrote: >>>>> >>>>> >>>>> On 2023/8/1 19:46, Yicong Yang wrote: >>>>>> On 2023/7/28 20:41, Shuai Xue wrote: >>>>>>> >>>>>>> >>>>>>> On 2023/7/27 17:39, Jonathan Cameron wrote: >>>>>>>> On Tue, 6 Jun 2023 23:14:07 +0800 >>>>>>>> Yicong Yang wrote: >>>>>>>> >>>>>>>>> On 2023/6/6 15:49, Shuai Xue wrote: >>>>>>>>>> This commit adds the PCIe Performance Monitoring Unit (PMU) driver support >>>>>>>>>> for T-Head Yitian SoC chip. Yitian is based on the Synopsys PCI Express >>>>>>>>>> Core controller IP which provides statistics feature. The PMU is not a PCIe >>>>>>>>>> Root Complex integrated End Point(RCiEP) device but only register counters >>>>>>>>>> provided by each PCIe Root Port. >>>>>>>>>> >>>>>>>>>> To facilitate collection of statistics the controller provides the >>>>>>>>>> following two features for each Root Port: >>>>>>>>>> >>>>>>>>>> - Time Based Analysis (RX/TX data throughput and time spent in each >>>>>>>>>> low-power LTSSM state) >>>>>>>>>> - Event counters (Error and Non-Error for lanes) >>>>>>>>>> >>>>>>>>>> Note, only one counter for each type and does not overflow interrupt. >>>>>>>>>> >>>>>>>>>> This driver adds PMU devices for each PCIe Root Port. And the PMU device is >>>>>>>>>> named based the BDF of Root Port. For example, >>>>>>>>>> >>>>>>>>>> 30:03.0 PCI bridge: Device 1ded:8000 (rev 01) >>>>>>>>>> >>>>>>>>>> the PMU device name for this Root Port is dwc_rootport_3018. >>>>>>>>>> >>>>>>>>>> Example usage of counting PCIe RX TLP data payload (Units of 16 bytes):: >>>>>>>>>> >>>>>>>>>> $# perf stat -a -e dwc_rootport_3018/Rx_PCIe_TLP_Data_Payload/ >>>>>>>>>> >>>>>>>>>> average RX bandwidth can be calculated like this: >>>>>>>>>> >>>>>>>>>> PCIe TX Bandwidth = PCIE_TX_DATA * 16B / Measure_Time_Window >>>>>>>>>> >>>>>>>>>> Signed-off-by: Shuai Xue >>>>>>>>>> Reported-by: kernel test robot >>>>>>>>>> Link: https://lore.kernel.org/oe-kbuild-all/202305170639.XU3djFZX-lkp@intel.com/ >>>>>>>>>> Reviewed-by: Baolin Wang >>>>>>>> >>>>>>>> I'll review on top to avoid any duplication with Yicong. >>>>>>> >>>>>>> Thank you! It also served as a reminder that I missed Yicong's email. It appears >>>>>>> that Thunderbird mistakenly moved his email to the junk folder, resulting in me >>>>>>> overlooking it. >>>>>>> >>>>>>>> >>>>>>>> Note I've cropped the stuff neither of us commented on so it's >>>>>>>> easier to spot the feedback. >>>>>>> >>>>>>> Thank you for noting that. My feedback is replied inline. >>>>>>> >>>>>>>> >>>>>>>> Jonathan >>>>>>>> >>>>>>>>>> --- >>>>>>>>>> drivers/perf/Kconfig | 7 + >>>>>>>>>> drivers/perf/Makefile | 1 + >>>>>>>>>> drivers/perf/dwc_pcie_pmu.c | 706 ++++++++++++++++++++++++++++++++++++ >>>>>>>>>> 3 files changed, 714 insertions(+) >>>>>>>>>> create mode 100644 drivers/perf/dwc_pcie_pmu.c >>>>>>>>>> >>>>>>>>>> diff --git a/drivers/perf/Kconfig b/drivers/perf/Kconfig >>>>>>>>>> index 711f82400086..6ff3921d7a62 100644 >>>>>>>>>> --- a/drivers/perf/Kconfig >>>>>>>>>> +++ b/drivers/perf/Kconfig >>>>>>>>>> @@ -209,6 +209,13 @@ config MARVELL_CN10K_DDR_PMU >>>>>>>>>> Enable perf support for Marvell DDR Performance monitoring >>>>>>>>>> event on CN10K platform. >>>>>>>>>> >>>>>>>>>> +config DWC_PCIE_PMU >>>>>>>>>> + tristate "Enable Synopsys DesignWare PCIe PMU Support" >>>>>>>>>> + depends on (ARM64 && PCI) >>>>>>>>>> + help >>>>>>>>>> + Enable perf support for Synopsys DesignWare PCIe PMU Performance >>>>>>>>>> + monitoring event on Yitian 710 platform. >>>>>>>> >>>>>>>> The documentation kind of implies this isn't platform specific. >>>>>>>> If some parts are (such as which events exist) then you may want to push >>>>>>>> that to userspace / perftool with appropriate matching against specific SoC. >>>>>>>> >>>>>>>> If it is generic, then change this text to "event on platform including the Yitian 710." >>>>>>> >>>>>>> It is generic without any platform specific, so I will change it as you expected. >>>>>>> >>>>>>>> >>>>>>>>>> + >>>>>>>>>> source "drivers/perf/arm_cspmu/Kconfig" >>>>>>>>>> >>>>>>>>>> source "drivers/perf/amlogic/Kconfig" >>>>>>>> >>>>>>>>>> new file mode 100644 >>>>>>>>>> index 000000000000..8bfcf6e0662d >>>>>>>>>> --- /dev/null >>>>>>>>>> +++ b/drivers/perf/dwc_pcie_pmu.c >>>>>>>>>> @@ -0,0 +1,706 @@ >>>>>>>> >>>>>>>> ... >>>>>>>> >>>>>>>>>> + >>>>>>>>>> +struct dwc_pcie_pmu { >>>>>>>>>> + struct pci_dev *pdev; /* Root Port device */ >>>>>>>>> >>>>>>>>> If the root port removed after the probe of this PCIe PMU driver, we'll access the NULL >>>>>>>>> pointer. I didn't see you hold the root port to avoid the removal. >>>>>>> >>>>>>> Do you mean that I should have a reference count of rootport by pci_dev_get() when allocating >>>>>>> pcie_pmu? >>>>>>> >>>>>>> pcie_pmu->pdev = pci_dev_get(); >>>>>> >>>>>> It could be one option, but will block the removal of device from userspace. Another option >>>>>> is to register a PCI bus notifier then on removal/added the driver can get notified and handle >>>>>> it, for example, remove the related PMU on the removal of the root ports. >>>>> >>>>> I see, but can root port be removed from userspace? I check the hotplug slot interface, no root >>>>> port is available to power off. >>>>> >>>> >>>> For hotplug maybe not, but user can remove certian device through sysfs: >>>> >>>> echo 1 > /sys/bus/pci/devices//remove >>>> >>> >>> Thank you, I will add a notifier for removal/added action. >>> >>> Best Regards, >>> Shuai >> >> Hi, Yicong, >> >> I am confused when adding a notifier by bus_register_notifier(). If I have added a action to >> pdev->dev to unregister pmu: >> >> ret = perf_pmu_register(&pcie_pmu->pmu, name, -1); >> if (ret) { >> pci_err(pcie_pmu->pdev, >> "Error %d registering PMU @%x\n", ret, bdf); >> goto out; >> } >> ret = devm_add_action_or_reset( >> &pdev->dev, dwc_pcie_pmu_unregister_pmu, &pcie_pmu->pmu); >> >> the pmu will be unregister when the port removes, so accessing the NULL pointer will never happen, >> right? Do we still need the bus_register_notifier()? >> > > Not necessary, a notifier is used to notice the device removal and avoid dereferencing the > NULL pointer. If you find another way like above to avoid the issue it will be ok. Since > your pmu is 1:1 related to the root port, add a devm action to unregister the PMU on root > port removal looks better. > > Thanks. Hi, Yicong, Got it. Thank you for your quick feedback:) Best Regards. Shuai