Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp447242rdb; Thu, 30 Nov 2023 08:47:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1NaRKvUL3dkGNHm8iJj+JsYblAoWPrU2d2fvCmb/on9nSzU6b8OBjumKgA4Rgg411gNW5 X-Received: by 2002:a92:c14d:0:b0:35d:421a:4b27 with SMTP id b13-20020a92c14d000000b0035d421a4b27mr2117996ilh.8.1701362849083; Thu, 30 Nov 2023 08:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701362849; cv=none; d=google.com; s=arc-20160816; b=PomzhYM0QXSNr5kFiGQFsgMIciO7eFZ77CHkn466yQiLrD4JgKDIqEqTS0ytlffk2h 5QNS65VNVnaf1EA9zY5vrZIcn7BOcdv93pO+e/259pDZligIJEDWWm8T9cmAGx4ql3Td tYmBQlOgCN27OYEKyHjmzXt8bkaP0MnI6v9ihieHo0P4qkO90uYwtvG4AeWmHci50FDN cQz6PFtf52RlSLeBTA47DpHVr2MtwOIY5A+odBF9atsN1lYO8VuLYyKzdjHb7lZVJkLr ac6+MI/jczeYHISZnhHPCerko3+CIF31ewTC3Qw8b0LP0jw7cvKWMvznCkgNi4P25Lks Iw1w== 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=04WzdNdg5LV1nkecKW2Mr6AZIyZ+k+WCO+WyZb60vVM=; fh=NcXtE6ywlIXhJKTicenMknMD6QAkvORNgU+DhT6/iVU=; b=iP1pcHNotn4FmibImd4TzsUZ6I7JO2AbXEczVifegHoXJ5FaCBGTMHMbxkJB1PoNT/ NR+mpa+0Wq10u2o8bS0xfOaDvt/uiZrq7RpVwGOsDdfVdDKh9LcpFn0KiuUfEpcGTVLg 5KscSNgD5AE1NpplWce3I+DFITEYU00IhT/osfMeR/IOUPuLlFstIWJujRMIocclyliE zdNK8MKOgDsWttc7qnj0EnxtsouGHySM4/b+Dp+FTLiSV8UP47yw2JtPdgVixVCutl3Q SV/WZUdHM5jo+hfgb0L4WVhyDviDJsUZCFHqRDtFaB98RDyYM60Pr5wtEdKcJiyc1xCU 3cJQ== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bg7-20020a056a02010700b005bdfb77e552si1761699pgb.439.2023.11.30.08.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 08:47:29 -0800 (PST) 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CF80384E989D; Thu, 30 Nov 2023 08:47:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345536AbjK3Qqv (ORCPT + 99 others); Thu, 30 Nov 2023 11:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235227AbjK3Qqn (ORCPT ); Thu, 30 Nov 2023 11:46:43 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D96810D0; Thu, 30 Nov 2023 08:46:49 -0800 (PST) Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sh2685pFkz6K5lJ; Fri, 1 Dec 2023 00:42:08 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 96EBF14058E; Fri, 1 Dec 2023 00:46:47 +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.35; Thu, 30 Nov 2023 16:46:46 +0000 Date: Thu, 30 Nov 2023 16:46:46 +0000 From: Jonathan Cameron To: Russell King CC: , , , , , , , , , , , , , Salil Mehta , Jean-Philippe Brucker , , , James Morse , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: Re: [PATCH 01/21] arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs Message-ID: <20231130164646.00006770@Huawei.com> In-Reply-To: References: 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: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500005.china.huawei.com (7.191.163.240) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Thu, 30 Nov 2023 08:47:06 -0800 (PST) On Tue, 21 Nov 2023 13:43:54 +0000 Russell King wrote: > From: James Morse > > 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 > Reviewed-by: Gavin Shan > Signed-off-by: Russell King (Oracle) Reviewed-by: Jonathan Cameron > --- > 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. However, attempts to discuss this just end > up in a black hole, so this is a non-starter. Thus, if this needs > to be done, it can be done as a separate patch. > --- > 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 register_cpu_capacity_sysctl(void) > +static int cpu_capacity_sysctl_add(unsigned int cpu) > { > - int i; > - struct device *cpu; > + struct device *cpu_dev = get_cpu_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); > - } > + 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) > +{ > + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity", > + cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove); > > return 0; > }