Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2759691rwd; Sun, 28 May 2023 23:52:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ATAG7ouXh6pRVSooAH2xxErGorUCPeEr+Sfrtn2VYyyiaulB41Akv1SW9YHpJTa4kkdLf X-Received: by 2002:a17:90a:7842:b0:253:5728:f631 with SMTP id y2-20020a17090a784200b002535728f631mr9694658pjl.15.1685343169994; Sun, 28 May 2023 23:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685343169; cv=none; d=google.com; s=arc-20160816; b=l3Qb8H1ezudObvl3n6IauyrFH+OxaL3ilY2nSzURdnxLfmWfbCYJcJSMcraF0PXUJS nGiQIsboxg936dXkJJegLrz6FKmRQODGp7/YfZlMUa5jBWSdhqfHXGX3PRkzAIk034T/ 6DdT8afdss3Ncu6UIPcohTneuooofrM1v6RH4r8FoNU+Q0mdGRJRlJ/FTZDyKtTToaxR xsKAHsxqC986Lwvy9RLNmkUvcMpDa7Q1UKi/6NPHBK4QiHgm0XtKuwoXpLTb7msjEqWR g5BteniIZDgQhHQIEoz+kt0zYYWjS18+QvvD8xY1xf4KsIdyzAYxcN2MTCh/Np9FeNUj Z6EA== 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=HeopLM6HzH4fJxlOE6zubFIaDhyWHxyXizW2cDN7MpY=; b=CUw//gZ28Snu+tmTThQXjcMbSePfb6B1EgPqrWxac70qZHSQvpgwJ18S8D4z1pV5dk 2yHqxHJlT6Qcp1KUXmDXpzXcUwm6VPTtx4zLpLO7rESbVsDZuCnIm29CLRxJg8aa3sqj q77WEIXExt0yu91HRS/3dXwFaQimKmWSJzpbNz2auc1O9sW8Mii5WpcdrrCl+0FhcaKR JrTZib6V4ySkx0Z3Au087ouya0YoUyXmj6UBM0BiV90VWmDPTm+3i0Ip6Dg6ZXkGKinD +em8GyYXj0zIHBmSgwLc67YBTpIapI1V5+aYCZE94ifUyznVXdfp+FHDi18uurbr1VjL 4jIA== 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=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a17090acf8e00b0025699253314si159798pju.39.2023.05.28.23.52.36; Sun, 28 May 2023 23:52:49 -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=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbjE2Gdo (ORCPT + 99 others); Mon, 29 May 2023 02:33:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbjE2Gdn (ORCPT ); Mon, 29 May 2023 02:33:43 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150B4E8; Sun, 28 May 2023 23:33:26 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0Vjgj2wz_1685342001; Received: from 30.240.113.228(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0Vjgj2wz_1685342001) by smtp.aliyun-inc.com; Mon, 29 May 2023 14:33:22 +0800 Message-ID: <1a1af428-0794-514d-1d79-52e3796a0707@linux.alibaba.com> Date: Mon, 29 May 2023 14:33:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH v5 3/4] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-US To: Baolin Wang , chengyou@linux.alibaba.com, kaishen@linux.alibaba.com, helgaas@kernel.org, yangyicong@huawei.com, will@kernel.org, Jonathan.Cameron@huawei.com, robin.murphy@arm.com Cc: 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: <20220917121036.14864-1-xueshuai@linux.alibaba.com> <20230522035428.69441-4-xueshuai@linux.alibaba.com> <505a5d3a-c970-8d15-ea60-444a3630c199@linux.alibaba.com> From: Shuai Xue In-Reply-To: <505a5d3a-c970-8d15-ea60-444a3630c199@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,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 On 2023/5/29 14:13, Baolin Wang wrote: > > > On 5/22/2023 11:54 AM, 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/ >> --- > > [snip] > >> +static int dwc_pcie_pmu_remove(struct platform_device *pdev) >> +{ >> +    struct dwc_pcie_pmu_priv *priv = platform_get_drvdata(pdev); >> +    struct dwc_pcie_pmu *pcie_pmu; >> + >> +    list_for_each_entry(pcie_pmu, &priv->pmu_nodes, pmu_node) { >> +        cpuhp_state_remove_instance(dwc_pcie_pmu_hp_state, >> +                        &pcie_pmu->cpuhp_node); >> +        perf_pmu_unregister(&pcie_pmu->pmu); >> +    } >> + >> +    return 0; >> +} >> + >> +static int dwc_pcie_pmu_probe(struct platform_device *pdev) >> +{ >> +    struct dwc_pcie_pmu_priv *priv; >> + >> +    priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); >> +    if (!priv) >> +        return -ENOMEM; >> + >> +    priv->dev = &pdev->dev; >> +    platform_set_drvdata(pdev, priv); >> + >> +    /* If one PMU registration fails, remove all. */ >> +    if (__dwc_pcie_pmu_probe(priv)) >> +        dwc_pcie_pmu_remove(pdev); > > In this case, you should return error from __dwc_pcie_pmu_probe() instead of returning 0, to release the requested resources of the PMU deivce. You are right, will fix it in next version. > >> + >> +    return 0; >> +} >> + >> +static void dwc_pcie_pmu_migrate(struct dwc_pcie_pmu *pcie_pmu, unsigned int cpu) >> +{ >> +    /* This PMU does NOT support interrupt, just migrate context. */ >> +    perf_pmu_migrate_context(&pcie_pmu->pmu, pcie_pmu->oncpu, cpu); >> +    pcie_pmu->oncpu = cpu; >> +} >> + >> +static int dwc_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *cpuhp_node) >> +{ >> +    struct dwc_pcie_pmu *pcie_pmu; >> +    struct pci_dev *pdev; >> +    int node; >> + >> +    pcie_pmu = hlist_entry_safe(cpuhp_node, struct dwc_pcie_pmu, cpuhp_node); >> +    pdev = pcie_pmu->pdev; >> +    node = dev_to_node(&pdev->dev); >> + >> +    if (node != NUMA_NO_NODE && cpu_to_node(pcie_pmu->oncpu) != node && >> +        cpu_to_node(cpu) == node) >> +        dwc_pcie_pmu_migrate(pcie_pmu, cpu); >> + >> +    return 0; >> +} >> + >> +static int dwc_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *cpuhp_node) >> +{ >> +    struct dwc_pcie_pmu *pcie_pmu; >> +    struct pci_dev *pdev; >> +    int node; >> +    cpumask_t mask; >> +    unsigned int target; >> + >> +    pcie_pmu = hlist_entry_safe(cpuhp_node, struct dwc_pcie_pmu, cpuhp_node); >> +    if (cpu != pcie_pmu->oncpu) >> +        return 0; >> + >> +    pdev = pcie_pmu->pdev; >> +    node = dev_to_node(&pdev->dev); >> +    if (cpumask_and(&mask, cpumask_of_node(node), cpu_online_mask) && >> +        cpumask_andnot(&mask, &mask, cpumask_of(cpu))) >> +        target = cpumask_any(&mask); >> +    else >> +        target = cpumask_any_but(cpu_online_mask, cpu); >> +    if (target < nr_cpu_ids) >> +        dwc_pcie_pmu_migrate(pcie_pmu, target); >> + >> +    return 0; >> +} >> + >> +static struct platform_driver dwc_pcie_pmu_driver = { >> +    .probe = dwc_pcie_pmu_probe, >> +    .remove = dwc_pcie_pmu_remove, >> +    .driver = {.name = "dwc_pcie_pmu",}, >> +}; >> + >> +static int __init dwc_pcie_pmu_init(void) >> +{ >> +    int ret; >> + >> +    ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, >> +                      "perf/dwc_pcie_pmu:online", >> +                      dwc_pcie_pmu_online_cpu, >> +                      dwc_pcie_pmu_offline_cpu); >> +    if (ret < 0) >> +        return ret; >> + >> +    dwc_pcie_pmu_hp_state = ret; >> + >> +    ret = platform_driver_register(&dwc_pcie_pmu_driver); >> +    if (ret) { >> +        cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); >> +        return ret; >> +    } >> + >> +    dwc_pcie_pmu_dev = platform_device_register_simple( >> +                "dwc_pcie_pmu", PLATFORM_DEVID_NONE, NULL, 0); >> +    if (IS_ERR(dwc_pcie_pmu_dev)) { >> +        platform_driver_unregister(&dwc_pcie_pmu_driver); >> +        return PTR_ERR(dwc_pcie_pmu_dev); >> +    } >> + >> +    return 0; >> +} >> + >> +static void __exit dwc_pcie_pmu_exit(void) >> +{ >> +    platform_device_unregister(dwc_pcie_pmu_dev); >> +    platform_driver_unregister(&dwc_pcie_pmu_driver); > > You should also call 'cpuhp_remove_multi_state()' when exiting the driver. Good catch, will add it in next version. > > With above issues fixed, you can add: > Reviewed-by: Baolin Wang Thank you :) Best Regards, Shuai