Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3856662rdb; Thu, 14 Sep 2023 05:05:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSssFnDlF992s4sTr2NdZmH2958hZjVFJpMb5fnDpNrN0M9vmntzXEfor3FayLB0DjmJNK X-Received: by 2002:a05:6a00:150b:b0:68c:3f2:5ff8 with SMTP id q11-20020a056a00150b00b0068c03f25ff8mr5413874pfu.1.1694693114549; Thu, 14 Sep 2023 05:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694693114; cv=none; d=google.com; s=arc-20160816; b=Vjk81rmNCPIylj6X5KzfUqiDJyV+Dc8t+LJZkRPP3zkKbT8vdVFfpngPi1/R703rWl pyRN5V3fRM0nLvzDt7ywF3aFlPTHXv/e3Hy5PiHsQ4uaU968aeEGHgW5kJy+OWt+1oMK eQB85Wxh/31JEV379FGZdl6dGBvDO+k5AgS4Bvoi2nwA6m2cL/FQEFF18YW0OXbmFb6d LbaULipkDsNIhaCyFuxOOyNaIhbWyb315vHYiBfx2sdxw9K2vbVQGR6LbZMpQLKGWQ3N AraDD4FZwMdffJ9JgYjdmXoG15CaDo+ssmmjJQNJDxergAbis5Ms6tclgFS9VFjVMMtD 3L7Q== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=nvw9Ah+cv359bIWYhzl8Ee4YhUXYy/SEnF8IlJvnWK0=; fh=3VuM1P+HTRAYk0mk4FHX8h0P+ueY2VRFhWEkjkR9/ec=; b=uLjb+GFDCIZgL8kFlYgTa+J7dT4CRzRG70xoGbSeHvj5eOj4nO8AOral6Z91tnhjZe d6ZDYIrOLK5088L0G/WpaRb1dRj6x4R+6UHVvD2jkySPUeFnH7/2Gfex3pQGcyUVfu3d Fn+bMPYpSCNbNsk54TeQw05ixXgaAeHtBN3z2VusdyENg2LgUNwbv8dcztL04QmUZsza 61r806mFgiD9gfxYdaIWn3745DF2ex7LuveBzrTeCWibjcgO9keTHQot3WbbqbqO2ETs RIsj6idmj6ZI4ZmDVSFxhXv9v2Bfc5HEkRQXgOfqinpawc3NHbkDGs2+1igblZhL0Djl fiig== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 140-20020a630192000000b0056554a8edb1si1392913pgb.219.2023.09.14.05.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:05:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DA4D281A4464; Thu, 14 Sep 2023 05:01:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238293AbjINMBg (ORCPT + 99 others); Thu, 14 Sep 2023 08:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237316AbjINMBf (ORCPT ); Thu, 14 Sep 2023 08:01:35 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5301BE8; Thu, 14 Sep 2023 05:01:30 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RmbQR00lDz68944; Thu, 14 Sep 2023 19:56:46 +0800 (CST) Received: from localhost (10.202.227.76) 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.31; Thu, 14 Sep 2023 13:01:27 +0100 Date: Thu, 14 Sep 2023 13:01:26 +0100 From: Jonathan Cameron To: James Morse CC: , , , , , , , , , Salil Mehta , Russell King , Jean-Philippe Brucker , , , Subject: Re: [RFC PATCH v2 11/35] arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs Message-ID: <20230914130126.000069db@Huawei.com> In-Reply-To: <20230913163823.7880-12-james.morse@arm.com> References: <20230913163823.7880-1-james.morse@arm.com> <20230913163823.7880-12-james.morse@arm.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected 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 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 05:01:45 -0700 (PDT) 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 pete.vger.email On Wed, 13 Sep 2023 16:37:59 +0000 James Morse wrote: > register_cpu_capacity_sysctl() adds a property to sysfs that describes > the CPUs capacity. This is done from a subsys_initcall() that assumes > all possible CPUs are registered. > > With CPU hotplug, possible CPUs aren't registered until they become > present, (or for arm64 enabled). This leads to messages during boot: > | register_cpu_capacity_sysctl: too early to get CPU1 device! > and once these CPUs are added to the system, the file is missing. > > Move this to a cpuhp callback, so that the file is created once > CPUs are brought online. This covers CPUs that are added late by > mechanisms like hotplug. > One observable difference is the file is now missing for offline CPUs. > > Signed-off-by: James Morse > --- > If the offline CPUs thing is a problem for the tools that consume > this value, we'd need to move cpu_capacity to be part of cpu.c's > common_cpu_attr_groups. I think we should do that anyway and then use an is_visible() if we want to change whether it is visible in offline cpus. Dynamic sysfs file creation is horrible - particularly when done from an totally different file from where the rest of the attributes are registered. I'm curious what the history behind that is. Whilst here, why is there a common_cpu_attr_groups which is identical to the hotpluggable_cpu_attr_groups in base/cpu.c? +CC GregKH Given changes in drivers/base/ > --- > drivers/base/arch_topology.c | 38 ++++++++++++++++++++++++------------ > 1 file changed, 26 insertions(+), 12 deletions(-) > > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c > index b741b5ba82bd..9ccb7daee78e 100644 > --- a/drivers/base/arch_topology.c > +++ b/drivers/base/arch_topology.c > @@ -220,20 +220,34 @@ static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn); > > static DEVICE_ATTR_RO(cpu_capacity); > > +static int cpu_capacity_sysctl_add(unsigned int cpu) > +{ > + struct device *cpu_dev = get_cpu_device(cpu); > + > + if (!cpu_dev) > + return -ENOENT; > + > + device_create_file(cpu_dev, &dev_attr_cpu_capacity); > + > + return 0; > +} > + > +static int cpu_capacity_sysctl_remove(unsigned int cpu) > +{ > + struct device *cpu_dev = get_cpu_device(cpu); > + > + if (!cpu_dev) > + return -ENOENT; > + > + device_remove_file(cpu_dev, &dev_attr_cpu_capacity); > + > + return 0; > +} > + > static int register_cpu_capacity_sysctl(void) > { > - int i; > - struct device *cpu; > - > - for_each_possible_cpu(i) { > - cpu = get_cpu_device(i); > - if (!cpu) { > - pr_err("%s: too early to get CPU%d device!\n", > - __func__, i); > - continue; > - } > - device_create_file(cpu, &dev_attr_cpu_capacity); > - } > + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity", > + cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove); > > return 0; > }