Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp123659rwe; Tue, 18 Apr 2023 18:54:56 -0700 (PDT) X-Google-Smtp-Source: AKy350YTHPQlz2yGxC2vccW4UaITUpKWhQIXFwhiEo7FJX/7aZ6h/b/paSWwNlTkRQTgUVM7PBQr X-Received: by 2002:a05:6a20:840a:b0:f0:98ff:97e3 with SMTP id c10-20020a056a20840a00b000f098ff97e3mr1923142pzd.37.1681869296533; Tue, 18 Apr 2023 18:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681869296; cv=none; d=google.com; s=arc-20160816; b=Y01futGutI6crNIJrA7DVSJnnFiiYUvSZux0nsTCFClv8vDdKLb3IbSkT+QJfGT9WV 9PZuX08i1PkMWiRnHwNOjmif7wKWITefS7b47FayiDPJXFf00OnyNKkkypgZOftPIVnp RjGPMBvbmBJeJOhUisK+cZo7HA2XPGezb3S44vpBBtTOraf5uxbq4kB8ib2L+bompPZa CnteP8xV+arxF9S4WdFUp172xMn+Tuddq8pKAnOVX6vzQRbQosWCkGzDObdiz2P/+1u1 Med2rIuT2fBZ7zp4s4OWKD9VHuZIAI1S7yXGeYOkLdwE9gv2Ir/l9t46/qcuO0pkf3Ic yCWA== 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=vW+ZFqUQmG5lIo4GqjyhaE36z9db9BaWUaJksJ6V4tI=; b=ds/qhdv5G37lbUPEVlBfr/TCABUuRxuTxbDETbxQOsI2HzkK14etRfFheXyoiZAOLr 1W8cvgzPgNWkoSqa1Bs3e/+FHuEB6w4AyZKsAvEl+03nKiriYC9953dbYSXUYjrN4eYG czNqJDPMIWxoIt8QZyzk5wBJXXxsB9RJLNJ9L300m6VZGpOzWnouJ39Oq6jZ5DLPuAaP BvasjyVTLEAYvJA8j8joCtu1H2Wr0/JnKnLQGc5viJz1jTASIloyS/TFhEqN2HGWxi/s wan5hL9Aar1qUE2h4AmKwbG/4qDye/FhoK8OdZMDtHvgrVotXHKqxTLqKuL4+1JYY2VU QBjg== 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 202-20020a6301d3000000b0051b6f3b2467si13361606pgb.811.2023.04.18.18.54.45; Tue, 18 Apr 2023 18:54:56 -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 S231615AbjDSBjh (ORCPT + 99 others); Tue, 18 Apr 2023 21:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbjDSBjf (ORCPT ); Tue, 18 Apr 2023 21:39:35 -0400 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32BC81FD3; Tue, 18 Apr 2023 18:39:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VgSP52n_1681868370; Received: from 30.97.56.117(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VgSP52n_1681868370) by smtp.aliyun-inc.com; Wed, 19 Apr 2023 09:39:31 +0800 Message-ID: <2dc023c9-7805-3dfa-f902-31468a2d3f7e@linux.alibaba.com> Date: Wed, 19 Apr 2023 09:39:28 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v2 2/3] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-US To: Baolin Wang , helgaas@kernel.org, yangyicong@huawei.com, will@kernel.org, Jonathan.Cameron@huawei.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, mark.rutland@arm.com, zhuo.song@linux.alibaba.com References: <20220917121036.14864-1-xueshuai@linux.alibaba.com> <20230410031702.68355-3-xueshuai@linux.alibaba.com> <713d8162-dd3c-483c-b984-7707ef8aaa36@linux.alibaba.com> From: Shuai Xue In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 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/4/18 AM9:51, Baolin Wang wrote: > > > On 4/17/2023 9:16 AM, Shuai Xue wrote: > > [snip] > >>>> + >>>> +static void dwc_pcie_pmu_event_update(struct perf_event *event) >>>> +{ >>>> +    u64 counter; >>>> +    struct dwc_pcie_pmu *pcie_pmu = to_dwc_pcie_pmu(event->pmu); >>>> +    struct dwc_pcie_rp_info *rp_info = pmu_to_pcie_info(event->pmu); >>>> +    struct pci_dev *pdev = rp_info->pdev; >>>> +    u16 ras_des = rp_info->ras_des; >>>> +    struct hw_perf_event *hwc = &event->hw; >>>> +    enum dwc_pcie_event_type type = DWC_PCIE_EVENT_TYPE(event); >>>> +    u64 delta, prev, now; >>>> + >>>> +    do { >>>> +        prev = local64_read(&hwc->prev_count); >>>> + >>>> +        if (type == DWC_PCIE_LANE_EVENT) >>>> +            dwc_pcie_pmu_read_event_counter(pdev, ras_des, &counter); >>>> +        else if (type == DWC_PCIE_TIME_BASE_EVENT) >>>> +            dwc_pcie_pmu_read_base_time_counter(pdev, ras_des, >>>> +                                &counter); >>>> +        else >>>> +            dev_err(pcie_pmu->dev, "invalid event type: 0x%x\n", type); >>>> + >>>> +        now = counter; >>>> +    } while (local64_cmpxchg(&hwc->prev_count, prev, now) != prev); >>>> + >>>> +    delta = now - prev; >>> >>> This can be overflow? better to add a mask to avoid possible overflow. >> >> I think it can not. This Root Complex supports up to PCIe Gen5 (32 GT/s) >> and one root port support up to x16 lanes, with peek bandwidth 64 GB/s. >> On Yitian 710, one root port is x4 lane with peak bandwidth 16 GB/s. >> The counter is 64 bit width with 16 bytes unit. >> >>     2^64*16/(64*10^9)/60/60/24/365 = 146 years >> >> For x16 root port, it will not overflow within 146 yeasr and for yitian 710, >> it will never overflow in my life too. > > However the lane event counter is 32bit, so still a maximum counter mask is preferable. You are right, will mask it in next version. Thank you. Best Regards, Shuai