Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1415957rda; Mon, 23 Oct 2023 11:51:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG18II+jBCm7a8YpTPip8wsBxZLz6nMyEBBGc8mr22iz80liwt4CBJittOGVzy3rITF/vSC X-Received: by 2002:a05:6a20:9381:b0:130:d5a:e40e with SMTP id x1-20020a056a20938100b001300d5ae40emr582596pzh.7.1698087111200; Mon, 23 Oct 2023 11:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698087111; cv=none; d=google.com; s=arc-20160816; b=BKPJTQtrcBuoGg43CXdb/FCgQ36wbqPl9vXZjtdJdwBqJ21lpnhwmaHUxiHd16uImH e1eOYpehkABfTstD4RNjLcoqsc0CaYwROH782d/RF/VeWpdewdOp1f9aAN/RRkiFi200 K2tNELGIFx72gkiKyTpR1AtKXt4PCGIkq0UWVhLM4VrNZKqWU4mMw3TWHYDlsp38q5OM YgOw8No4o6HU8AeIVG8FG4taJeGn38ZxCOkU526L4oroXQkIb2+nwOI62RrUylm7QS11 SBgB0N/sSpQBsY24Kxuv5fO3FeGjMuw2JLLlCfPQ1Yd4WdkmWhRR/rfRZdZ1CscNYKG0 eMpA== 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=N4u1UstVcjxXuDKJwiQRxTAdyEpm+npgM473ttek6YQ=; fh=3fqxhPkDp35+ItmmpEOIerQ4lxtd1oeoknbvpCEYZV0=; b=wvQu3+pvyVBTnzB4lVNj7JCNZhGTy7f2/v7K9uSxvbAu1puauLxgUDOsBdOwKEgOrQ 2W9s7Y6RB0S/nAGyDrbpCU5r5R+dIY0ZYv0+IRUKYqLrYaE5kpIb6F4Fjh80v3tyf2/g YL9EpwruPzmgurllXDvI7jTD6SzYkO1M+od418pGJmlP3WdvaBKTGniyPwExm88GP7ho v4+29X2fuwtJyy/F8ySuNGcfNqr7WSktVZgW7ej1/Bwj7w2PxxkgPmFejGZPe2ZY5J/F EyrU02kZiiAlo/ELfB3cHS8RCf7bMGrk4QGYmRYYuli2vcr43a3ukpyVS9hY7KT1QQKR xjKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id fa8-20020a056a002d0800b006be0559d029si6987500pfb.109.2023.10.23.11.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 541DC805BCAF; Mon, 23 Oct 2023 11:51:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbjJWSvh (ORCPT + 99 others); Mon, 23 Oct 2023 14:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjJWSvg (ORCPT ); Mon, 23 Oct 2023 14:51:36 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4C3BC2; Mon, 23 Oct 2023 11:51:33 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5F7D22F4; Mon, 23 Oct 2023 11:52:14 -0700 (PDT) Received: from [10.57.5.125] (unknown [10.57.5.125]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B5393F762; Mon, 23 Oct 2023 11:51:30 -0700 (PDT) Message-ID: Date: Mon, 23 Oct 2023 19:51:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 3/4] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-GB To: Will Deacon , Shuai Xue Cc: chengyou@linux.alibaba.com, kaishen@linux.alibaba.com, helgaas@kernel.org, yangyicong@huawei.com, Jonathan.Cameron@huawei.com, baolin.wang@linux.alibaba.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, renyu.zj@linux.alibaba.com References: <20231020134230.53342-1-xueshuai@linux.alibaba.com> <20231020134230.53342-4-xueshuai@linux.alibaba.com> <20231023123202.GA3515@willie-the-truck> From: Robin Murphy In-Reply-To: <20231023123202.GA3515@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Mon, 23 Oct 2023 11:51:48 -0700 (PDT) On 2023-10-23 13:32, Will Deacon wrote: [...] >> + >> + /* >> + * The Group#1 event measures the amount of data processed in 16-byte >> + * units. Simplify the end-user interface by multiplying the counter >> + * at the point of read. >> + */ >> + if (event_id >= 0x20 && event_id <= 0x23) >> + return (((u64)hi << 32) | lo) << 4; >> + else >> + return (((u64)hi << 32) | lo); > > nit, but I think it would be clearer to do: > > ret = ((u64)hi << 32) | lo; > > /* ... */ > if (event_id >= 0x20 && event_id <= 0x23) > ret <<= 4; Nit: "ret *= 16;" since the comment says it's multiplying a value, not moving a bitfield. The compiler already knows the most efficient way to implement constant multiplication. > > return ret; > [...] >> +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) >> + goto platform_driver_register_err; >> + >> + dwc_pcie_pmu_dev = platform_device_register_simple( >> + "dwc_pcie_pmu", PLATFORM_DEVID_NONE, NULL, 0); >> + if (IS_ERR(dwc_pcie_pmu_dev)) { >> + ret = PTR_ERR(dwc_pcie_pmu_dev); >> + goto platform_device_register_error; >> + } > > I'm a bit confused as to why you're having to create a platform device > for a PCI device -- is this because the main designware driver has already > bound to it? A comment here explaining why you need to do this would be > very helpful. In particular, is there any dependency on another driver > to make sure that e.g. config space accesses work properly? If so, we > probably need to enforce module load ordering or something like that. AFAICS the platform device/driver serve no purpose other than being a hilariously roundabout way to run the for_each_pci_dev() loop in dwc_pcie_pmu_probe() upon module init, and to save explicitly freeing the PMU name/data. Furthermore the devres action for dwc_pcie_pmu_remove_cpuhp_instance() is apparently going for even more style points at module exit by not even relying on the corresponding .remove callback of the tenuous platform driver to undo what its .probe did, but (ab)using the device's devres list to avoid having to keep track of an explicit list of PMU instances at all. Frankly I think it would be a lot more straightforward to just maintain that explicit list of PMU instances, do the PMU creation directly in dwc_pcie_pmu_init(), then unregister and free them in dwc_pcie_pmu_exit(). Not every driver has to contain a literal struct device_driver. It also smells a bit odd that it handles PCI hot-remove but not hot-add - if the underlying device really is hotpluggable, wouldn't we also want to handle new ones turning up after module load? Conversely if it isn't, why pretend to handle it being removed? Even if it's not to do with physical hotplug of the PMU but with the user unloading the PCI controller driver itself (since there's no module/driver-level dependency enforced) and thus tearing down the whole PCI bus, then the same point still applies - if that *can* happen, then what if the user then re-loads it again, or indeed if this module loads first to begin with; wouldn't we want to be able to (re-)discover the PMUs rather than leave the whole PMU driver degraded to a useless state? Thanks, Robin.