Message ID | 20230404134225.13408-2-Jonathan.Cameron@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3043484vqo; Tue, 4 Apr 2023 06:49:45 -0700 (PDT) X-Google-Smtp-Source: AKy350ZhPllLw2o4/BU8dS/5BlsmlUQ/8YzyjiHeW6A6i3H8kKu0j5zGVa4PWgbRzAq7+1chLju0 X-Received: by 2002:a05:6a20:811a:b0:d6:8c70:85ce with SMTP id g26-20020a056a20811a00b000d68c7085cemr2054542pza.54.1680616185379; Tue, 04 Apr 2023 06:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680616185; cv=none; d=google.com; s=arc-20160816; b=LwX//aEJH7DYe2/kyLv9RivG+jtyqjwEU32etTK0mrBA48TJej8sYlqG1nm1PJH0eN 4E6hsQDgQNpKFvznmdaqxZsVNgYJ9MTj/ba7SqwexzbPLhE04k1pZO0wWwOnIBiEIfWX PMjxOoGKPkTVxBRd+oz/KnnCjw2qsOF4wqWmYF+P9FUYqUNnbiFfQVf79nHDGeKUTlRS i32X2210Sg9YTu3JFBwPWJyYzliKRoxQYBm8X7zQKL7DcW/Qy0wmMCbwpO7c1QqYxSwd q4h8Mz8Y0+druPX5IhrtWTdPdGEvWEszMH1uOKZRgDA+/6UGcCpMlF0dzbDL340U3Q+k OVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vR7Tj4itEEj3R0vhbfH04WfsZVqbNRf/z0F4kcZjGAA=; b=vVCiecuv69cJM9Rnivdwo+Wx0EulN4dndNdU9f8nRPrSjHMBHp7Kw1g4o0Mc4aquWl ic/Q7ekH8wEBi7YRVqPgCB6H118c+kaRwByV6oLFzG5RaTs+XwxVdneysVt6Wzf6l9fP OUiLMbjIrZFo4j1ayUgRKRLkm5mOw5/P/zZ1VeUYmMd5+46Lg4Mds28fKuzbj59O1H6C 0Z6prqd+5nbSzW6gSe9xBX0rV8stGqqZR3ylkpm3szg7VVxQtiJKHl3OfbYE/h5VjPIW zBlCBL+9CjDhe55O4u7vXS4xYaB1rhNBCb2Ja3aXpG+f2PERqN+Az/pEMdTKT67YQ4gY hEzA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y190-20020a638ac7000000b00503a029385asi11029181pgd.849.2023.04.04.06.49.30; Tue, 04 Apr 2023 06:49:45 -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 S235174AbjDDNmx (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Tue, 4 Apr 2023 09:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234493AbjDDNmv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 4 Apr 2023 09:42:51 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C11C186; Tue, 4 Apr 2023 06:42:49 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4PrTT50JLsz67ZTx; Tue, 4 Apr 2023 21:42:01 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 4 Apr 2023 14:42:46 +0100 From: Jonathan Cameron <Jonathan.Cameron@huawei.com> To: Mark Rutland <mark.rutland@arm.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Will Deacon <will@kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <gregkh@linuxfoundation.org> CC: <linuxarm@huawei.com>, Dan Williams <dan.j.williams@intel.com>, Shaokun Zhang <zhangshaokun@hisilicon.com>, Yicong Yang <yangyicong@hisilicon.com>, Jiucheng Xu <jiucheng.xu@amlogic.com>, Khuong Dinh <khuong@os.amperecomputing.com>, Robert Richter <rric@kernel.org>, Atish Patra <atishp@atishpatra.org>, Anup Patel <anup@brainfault.org>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Frank Li <Frank.li@nxp.com>, Shuai Xue <xueshuai@linux.alibaba.com>, Vineet Gupta <vgupta@kernel.org>, Shawn Guo <shawnguo@kernel.org>, Fenghua Yu <fenghua.yu@intel.com>, Dave Jiang <dave.jiang@intel.com>, Wu Hao <hao.wu@intel.com>, Tom Rix <trix@redhat.com>, <linux-fpga@vger.kernel.org>, Suzuki K Poulose <suzuki.poulose@arm.com>, Liang Kan <kan.liang@linux.intel.com> Subject: [PATCH 01/32] perf: Allow a PMU to have a parent Date: Tue, 4 Apr 2023 14:41:54 +0100 Message-ID: <20230404134225.13408-2-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230404134225.13408-1-Jonathan.Cameron@huawei.com> References: <20230404134225.13408-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762253797286323690?= X-GMAIL-MSGID: =?utf-8?q?1762253797286323690?= |
Series |
Add parents to struct pmu -> dev
|
|
Commit Message
Jonathan Cameron
April 4, 2023, 1:41 p.m. UTC
Some PMUs have well defined parents such as PCI devices. As the device_initialize() and device_add() are all within pmu_dev_alloc() which is called from perf_pmu_register() there is no opportunity to set the parent from within a driver. Add a struct device *parent field to struct pmu and use that to set the parent. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> --- Previously posted in CPMU series hence the change log. v3: No change --- include/linux/perf_event.h | 1 + kernel/events/core.c | 1 + 2 files changed, 2 insertions(+)
Comments
On Tue, Apr 04, 2023 at 02:41:54PM +0100, Jonathan Cameron wrote: > Some PMUs have well defined parents such as PCI devices. > As the device_initialize() and device_add() are all within > pmu_dev_alloc() which is called from perf_pmu_register() > there is no opportunity to set the parent from within a driver. > > Add a struct device *parent field to struct pmu and use that > to set the parent. > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > Reviewed-by: Dan Williams <dan.j.williams@intel.com> > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
On 2023/4/4 21:41, Jonathan Cameron wrote: > Some PMUs have well defined parents such as PCI devices. > As the device_initialize() and device_add() are all within > pmu_dev_alloc() which is called from perf_pmu_register() > there is no opportunity to set the parent from within a driver. > > Add a struct device *parent field to struct pmu and use that > to set the parent. > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > Reviewed-by: Dan Williams <dan.j.williams@intel.com> > > --- > Previously posted in CPMU series hence the change log. > v3: No change > --- > include/linux/perf_event.h | 1 + > kernel/events/core.c | 1 + > 2 files changed, 2 insertions(+) > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index d5628a7b5eaa..b99db1eda72c 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -303,6 +303,7 @@ struct pmu { > > struct module *module; > struct device *dev; > + struct device *parent; > const struct attribute_group **attr_groups; > const struct attribute_group **attr_update; > const char *name; > diff --git a/kernel/events/core.c b/kernel/events/core.c > index fb3e436bcd4a..a84c282221f2 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -11367,6 +11367,7 @@ static int pmu_dev_alloc(struct pmu *pmu) > > dev_set_drvdata(pmu->dev, pmu); > pmu->dev->bus = &pmu_bus; > + pmu->dev->parent = pmu->parent; If there's no parent assigned, is it ok to add some check here? Then we can find it earlier maybe at develop stage. Thanks. > pmu->dev->release = pmu_dev_release; > > ret = dev_set_name(pmu->dev, "%s", pmu->name); >
On Thu, 6 Apr 2023 12:03:27 +0800 Yicong Yang <yangyicong@huawei.com> wrote: > On 2023/4/4 21:41, Jonathan Cameron wrote: > > Some PMUs have well defined parents such as PCI devices. > > As the device_initialize() and device_add() are all within > > pmu_dev_alloc() which is called from perf_pmu_register() > > there is no opportunity to set the parent from within a driver. > > > > Add a struct device *parent field to struct pmu and use that > > to set the parent. > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > Reviewed-by: Dan Williams <dan.j.williams@intel.com> > > > > --- > > Previously posted in CPMU series hence the change log. > > v3: No change > > --- > > include/linux/perf_event.h | 1 + > > kernel/events/core.c | 1 + > > 2 files changed, 2 insertions(+) > > > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > index d5628a7b5eaa..b99db1eda72c 100644 > > --- a/include/linux/perf_event.h > > +++ b/include/linux/perf_event.h > > @@ -303,6 +303,7 @@ struct pmu { > > > > struct module *module; > > struct device *dev; > > + struct device *parent; > > const struct attribute_group **attr_groups; > > const struct attribute_group **attr_update; > > const char *name; > > diff --git a/kernel/events/core.c b/kernel/events/core.c > > index fb3e436bcd4a..a84c282221f2 100644 > > --- a/kernel/events/core.c > > +++ b/kernel/events/core.c > > @@ -11367,6 +11367,7 @@ static int pmu_dev_alloc(struct pmu *pmu) > > > > dev_set_drvdata(pmu->dev, pmu); > > pmu->dev->bus = &pmu_bus; > > + pmu->dev->parent = pmu->parent; > > If there's no parent assigned, is it ok to add some check here? Then we can find it earlier > maybe at develop stage. In the long run I agree it would be good. Short term there are more instances of struct pmu that don't have parents than those that do (even after this series). We need to figure out what to do about those before adding checks on it being set. Jonathan > > Thanks. > > > pmu->dev->release = pmu_dev_release; > > > > ret = dev_set_name(pmu->dev, "%s", pmu->name); > >
On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > In the long run I agree it would be good. Short term there are more instances of > struct pmu that don't have parents than those that do (even after this series). > We need to figure out what to do about those before adding checks on it being > set. Right, I don't think you've touched *any* of the x86 PMUs for example, and getting everybody that boots an x86 kernel a warning isn't going to go over well :-)
On Thu, 6 Apr 2023 14:40:40 +0200 Peter Zijlstra <peterz@infradead.org> wrote: > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > In the long run I agree it would be good. Short term there are more instances of > > struct pmu that don't have parents than those that do (even after this series). > > We need to figure out what to do about those before adding checks on it being > > set. > > Right, I don't think you've touched *any* of the x86 PMUs for example, > and getting everybody that boots an x86 kernel a warning isn't going to > go over well :-) > It was tempting :) "Warning: Parentless PMU: try a different architecture." I'd love some inputs on what the x86 PMU devices parents should be? CPU counters in general tend to just spin out of deep in the architecture code. My overall favorite is an l2 cache related PMU that is spun up in arch/arm/kernel/irq.c init_IRQ() I'm just not going to try and figure out why... Jonathan
On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > On Thu, 6 Apr 2023 14:40:40 +0200 > Peter Zijlstra <peterz@infradead.org> wrote: > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > In the long run I agree it would be good. Short term there are more instances of > > > struct pmu that don't have parents than those that do (even after this series). > > > We need to figure out what to do about those before adding checks on it being > > > set. > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > and getting everybody that boots an x86 kernel a warning isn't going to > > go over well :-) > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > I'd love some inputs on what the x86 PMU devices parents should be? > CPU counters in general tend to just spin out of deep in the architecture code. > > My overall favorite is an l2 cache related PMU that is spun up in > arch/arm/kernel/irq.c init_IRQ() > > I'm just not going to try and figure out why... Why not change the api to force a parent to be passed in? And if one isn't, we make it a "virtual" device and throw it in the class for them? thanks, greg k-h
On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > On Thu, 6 Apr 2023 14:40:40 +0200 > Peter Zijlstra <peterz@infradead.org> wrote: > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > In the long run I agree it would be good. Short term there are more instances of > > > struct pmu that don't have parents than those that do (even after this series). > > > We need to figure out what to do about those before adding checks on it being > > > set. > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > and getting everybody that boots an x86 kernel a warning isn't going to > > go over well :-) > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." Haha! > I'd love some inputs on what the x86 PMU devices parents should be? > CPU counters in general tend to just spin out of deep in the architecture code. For the 'simple' ones I suppose we can use the CPU device. > My overall favorite is an l2 cache related PMU that is spun up in > arch/arm/kernel/irq.c init_IRQ() Yeah, we're going to have a ton of them as well. Some of them are PCI devices and have a clear parent, others, not so much :/
On Thu, 6 Apr 2023 19:08:45 +0200 Greg KH <gregkh@linuxfoundation.org> wrote: > On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > > On Thu, 6 Apr 2023 14:40:40 +0200 > > Peter Zijlstra <peterz@infradead.org> wrote: > > > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > > > In the long run I agree it would be good. Short term there are more instances of > > > > struct pmu that don't have parents than those that do (even after this series). > > > > We need to figure out what to do about those before adding checks on it being > > > > set. > > > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > > and getting everybody that boots an x86 kernel a warning isn't going to > > > go over well :-) > > > > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > > > I'd love some inputs on what the x86 PMU devices parents should be? > > CPU counters in general tend to just spin out of deep in the architecture code. > > > > My overall favorite is an l2 cache related PMU that is spun up in > > arch/arm/kernel/irq.c init_IRQ() > > > > I'm just not going to try and figure out why... > > Why not change the api to force a parent to be passed in? And if one > isn't, we make it a "virtual" device and throw it in the class for them? Longer term I'd be fine doing that, but I'd like to identify the right parents rather than end up sweeping it under the carpet. Anything we either get completely stuck on (or decide we don't care about) could indeed fall back to a virtual device. Jonathan > > thanks, > > greg k-h
On 2023-04-06 17:44, Jonathan Cameron wrote: > On Thu, 6 Apr 2023 14:40:40 +0200 > Peter Zijlstra <peterz@infradead.org> wrote: > >> On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: >> >>> In the long run I agree it would be good. Short term there are more instances of >>> struct pmu that don't have parents than those that do (even after this series). >>> We need to figure out what to do about those before adding checks on it being >>> set. >> >> Right, I don't think you've touched *any* of the x86 PMUs for example, >> and getting everybody that boots an x86 kernel a warning isn't going to >> go over well :-) >> > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > I'd love some inputs on what the x86 PMU devices parents should be? > CPU counters in general tend to just spin out of deep in the architecture code. > > My overall favorite is an l2 cache related PMU that is spun up in > arch/arm/kernel/irq.c init_IRQ() > > I'm just not going to try and figure out why... I think that's simply because the PMU support was hung off the existing PL310 configuration code, which still supports non-DT boardfiles. The PMU shouldn't strictly need to be registered that early, it would just be a bunch more work to ensure that a platform device is available for it to bind to as a regular driver model driver, which wasn't justifiable at the time. Thanks, Robin.
On Thu, Apr 06, 2023 at 09:49:38PM +0200, Peter Zijlstra wrote: > On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > > On Thu, 6 Apr 2023 14:40:40 +0200 > > Peter Zijlstra <peterz@infradead.org> wrote: > > > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > > > In the long run I agree it would be good. Short term there are more instances of > > > > struct pmu that don't have parents than those that do (even after this series). > > > > We need to figure out what to do about those before adding checks on it being > > > > set. > > > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > > and getting everybody that boots an x86 kernel a warning isn't going to > > > go over well :-) > > > > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > Haha! > > > I'd love some inputs on what the x86 PMU devices parents should be? > > CPU counters in general tend to just spin out of deep in the architecture code. > > For the 'simple' ones I suppose we can use the CPU device. Uh, *which* CPU device? Do we have a container device for all CPUs? > > My overall favorite is an l2 cache related PMU that is spun up in > > arch/arm/kernel/irq.c init_IRQ() That's an artifact of the L2 cache controller driver getting initialized there; ideally we'd have a device for the L2 cache itself (which presumably should hang off an aggregate CPU device). > Yeah, we're going to have a ton of them as well. Some of them are PCI > devices and have a clear parent, others, not so much :/ In a number of places the only thing we have is the PMU driver, and we don't have a driver (or device) for the HW block it's a part of. Largely that's interconnect PMUs; we could create container devices there. Mark.
On Tue, Jun 06, 2023 at 02:06:24PM +0100, Mark Rutland wrote: > On Thu, Apr 06, 2023 at 09:49:38PM +0200, Peter Zijlstra wrote: > > On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > > > On Thu, 6 Apr 2023 14:40:40 +0200 > > > Peter Zijlstra <peterz@infradead.org> wrote: > > > > > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > > > > > In the long run I agree it would be good. Short term there are more instances of > > > > > struct pmu that don't have parents than those that do (even after this series). > > > > > We need to figure out what to do about those before adding checks on it being > > > > > set. > > > > > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > > > and getting everybody that boots an x86 kernel a warning isn't going to > > > > go over well :-) > > > > > > > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > > > Haha! > > > > > I'd love some inputs on what the x86 PMU devices parents should be? > > > CPU counters in general tend to just spin out of deep in the architecture code. > > > > For the 'simple' ones I suppose we can use the CPU device. > > Uh, *which* CPU device? Do we have a container device for all CPUs? drivers/base/cpu.c:per_cpu(cpu_sys_devices, cpu) for whatever the core pmu is for that cpu ? > > > My overall favorite is an l2 cache related PMU that is spun up in > > > arch/arm/kernel/irq.c init_IRQ() > > That's an artifact of the L2 cache controller driver getting initialized there; > ideally we'd have a device for the L2 cache itself (which presumably should > hang off an aggregate CPU device). /sys/devices/system/cpu/cpuN/cache/indexM has a struct device somewhere in drivers/base/cacheinfo.c:ci_index_dev or somesuch. > > Yeah, we're going to have a ton of them as well. Some of them are PCI > > devices and have a clear parent, others, not so much :/ > > In a number of places the only thing we have is the PMU driver, and we don't > have a driver (or device) for the HW block it's a part of. Largely that's > interconnect PMUs; we could create container devices there. Dont they have a PCI device? But yeah, some are going to be a wee bit challenging.
On Tue, Jun 06, 2023 at 03:18:59PM +0200, Peter Zijlstra wrote: > On Tue, Jun 06, 2023 at 02:06:24PM +0100, Mark Rutland wrote: > > On Thu, Apr 06, 2023 at 09:49:38PM +0200, Peter Zijlstra wrote: > > > On Thu, Apr 06, 2023 at 05:44:45PM +0100, Jonathan Cameron wrote: > > > > On Thu, 6 Apr 2023 14:40:40 +0200 > > > > Peter Zijlstra <peterz@infradead.org> wrote: > > > > > > > > > On Thu, Apr 06, 2023 at 11:16:07AM +0100, Jonathan Cameron wrote: > > > > > > > > > > > In the long run I agree it would be good. Short term there are more instances of > > > > > > struct pmu that don't have parents than those that do (even after this series). > > > > > > We need to figure out what to do about those before adding checks on it being > > > > > > set. > > > > > > > > > > Right, I don't think you've touched *any* of the x86 PMUs for example, > > > > > and getting everybody that boots an x86 kernel a warning isn't going to > > > > > go over well :-) > > > > > > > > > > > > > It was tempting :) "Warning: Parentless PMU: try a different architecture." > > > > > > Haha! > > > > > > > I'd love some inputs on what the x86 PMU devices parents should be? > > > > CPU counters in general tend to just spin out of deep in the architecture code. > > > > > > For the 'simple' ones I suppose we can use the CPU device. > > > > Uh, *which* CPU device? Do we have a container device for all CPUs? > > drivers/base/cpu.c:per_cpu(cpu_sys_devices, cpu) for whatever the core > pmu is for that cpu ? ... but the struct pmu covers several CPUs, so I don't have a single 'cpu', no? If I have a system where cpu{0,1,2} are Cortex-A53 and cpu{3,4} are Cortex-A57, I have two struct pmu instances, each associated with several CPUs. When I probe each of those I determine a cpumask for each. > > > > My overall favorite is an l2 cache related PMU that is spun up in > > > > arch/arm/kernel/irq.c init_IRQ() > > > > That's an artifact of the L2 cache controller driver getting initialized there; > > ideally we'd have a device for the L2 cache itself (which presumably should > > hang off an aggregate CPU device). > > /sys/devices/system/cpu/cpuN/cache/indexM > > has a struct device somewhere in > drivers/base/cacheinfo.c:ci_index_dev or somesuch. I guess, but I don't think the L2 cache controller (the PL310) is actually tied to that today. > > > Yeah, we're going to have a ton of them as well. Some of them are PCI > > > devices and have a clear parent, others, not so much :/ > > > > In a number of places the only thing we have is the PMU driver, and we don't > > have a driver (or device) for the HW block it's a part of. Largely that's > > interconnect PMUs; we could create container devices there. > > Dont they have a PCI device? But yeah, some are going to be a wee bit > challenging. The system might not even have PCI, so it's arguable that they should just hang off an MMIO bus (which is effectively what the platofrm bus is). Thanks, Mark.
On Tue, Jun 06, 2023 at 02:30:52PM +0100, Mark Rutland wrote: > > > Uh, *which* CPU device? Do we have a container device for all CPUs? > > > > drivers/base/cpu.c:per_cpu(cpu_sys_devices, cpu) for whatever the core > > pmu is for that cpu ? > > ... but the struct pmu covers several CPUs, so I don't have a single 'cpu', no? > > If I have a system where cpu{0,1,2} are Cortex-A53 and cpu{3,4} are Cortex-A57, > I have two struct pmu instances, each associated with several CPUs. When I > probe each of those I determine a cpumask for each. Bah :/ Clearly I overlooked the disparity there. > > > > > My overall favorite is an l2 cache related PMU that is spun up in > > > > > arch/arm/kernel/irq.c init_IRQ() > > > > > > That's an artifact of the L2 cache controller driver getting initialized there; > > > ideally we'd have a device for the L2 cache itself (which presumably should > > > hang off an aggregate CPU device). > > > > /sys/devices/system/cpu/cpuN/cache/indexM > > > > has a struct device somewhere in > > drivers/base/cacheinfo.c:ci_index_dev or somesuch. > > I guess, but I don't think the L2 cache controller (the PL310) is actually tied > to that today. All it would do is make fancy links in sysfs I think, who cares ;-) > > > > Yeah, we're going to have a ton of them as well. Some of them are PCI > > > > devices and have a clear parent, others, not so much :/ > > > > > > In a number of places the only thing we have is the PMU driver, and we don't > > > have a driver (or device) for the HW block it's a part of. Largely that's > > > interconnect PMUs; we could create container devices there. > > > > Dont they have a PCI device? But yeah, some are going to be a wee bit > > challenging. > > The system might not even have PCI, so it's arguable that they should just hang > off an MMIO bus (which is effectively what the platofrm bus is). You and your dodgy platforms :-)
On 2023-06-06 14:48, Peter Zijlstra wrote: > On Tue, Jun 06, 2023 at 02:30:52PM +0100, Mark Rutland wrote: > >>>> Uh, *which* CPU device? Do we have a container device for all CPUs? >>> >>> drivers/base/cpu.c:per_cpu(cpu_sys_devices, cpu) for whatever the core >>> pmu is for that cpu ? >> >> ... but the struct pmu covers several CPUs, so I don't have a single 'cpu', no? >> >> If I have a system where cpu{0,1,2} are Cortex-A53 and cpu{3,4} are Cortex-A57, >> I have two struct pmu instances, each associated with several CPUs. When I >> probe each of those I determine a cpumask for each. > > Bah :/ Clearly I overlooked the disparity there. > >>>>>> My overall favorite is an l2 cache related PMU that is spun up in >>>>>> arch/arm/kernel/irq.c init_IRQ() >>>> >>>> That's an artifact of the L2 cache controller driver getting initialized there; >>>> ideally we'd have a device for the L2 cache itself (which presumably should >>>> hang off an aggregate CPU device). >>> >>> /sys/devices/system/cpu/cpuN/cache/indexM >>> >>> has a struct device somewhere in >>> drivers/base/cacheinfo.c:ci_index_dev or somesuch. >> >> I guess, but I don't think the L2 cache controller (the PL310) is actually tied >> to that today. > > All it would do is make fancy links in sysfs I think, who cares ;-) > >>>>> Yeah, we're going to have a ton of them as well. Some of them are PCI >>>>> devices and have a clear parent, others, not so much :/ >>>> >>>> In a number of places the only thing we have is the PMU driver, and we don't >>>> have a driver (or device) for the HW block it's a part of. Largely that's >>>> interconnect PMUs; we could create container devices there. >>> >>> Dont they have a PCI device? But yeah, some are going to be a wee bit >>> challenging. >> >> The system might not even have PCI, so it's arguable that they should just hang >> off an MMIO bus (which is effectively what the platofrm bus is). > > You and your dodgy platforms :-) For system PMUs we'll pretty much always have a platform device corresponding to a DT/ACPI entry used to describe MMIO registers and/or interrupts. In many cases the PMU is going to be the only part of the underlying device that is meaningful to Linux anyway, so I don't see any issue with just hanging the PMU device off its corresponding platform device - it still gives the user a way to map a PMU instance back to some understandable system topology (i.e. ACPI/DT) to disambiguate, and that's the most important thing. Thanks, Robin.
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index d5628a7b5eaa..b99db1eda72c 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -303,6 +303,7 @@ struct pmu { struct module *module; struct device *dev; + struct device *parent; const struct attribute_group **attr_groups; const struct attribute_group **attr_update; const char *name; diff --git a/kernel/events/core.c b/kernel/events/core.c index fb3e436bcd4a..a84c282221f2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11367,6 +11367,7 @@ static int pmu_dev_alloc(struct pmu *pmu) dev_set_drvdata(pmu->dev, pmu); pmu->dev->bus = &pmu_bus; + pmu->dev->parent = pmu->parent; pmu->dev->release = pmu_dev_release; ret = dev_set_name(pmu->dev, "%s", pmu->name);