Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp389465rdf; Tue, 21 Nov 2023 05:44:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzkcbqPx8EnWnDXzNAYRrDBXemXouhSEDWTrCh5w4hiIrFD7cKjBcuUrD82XLwiRngtcBR X-Received: by 2002:a05:6a00:39aa:b0:68b:e29c:b69 with SMTP id fi42-20020a056a0039aa00b0068be29c0b69mr3852691pfb.9.1700574250617; Tue, 21 Nov 2023 05:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700574250; cv=none; d=google.com; s=arc-20160816; b=fdBZMzkn0125Hm9uQteIeyTA+ETWrW8OrroNNZZG1O5EtSX5PdbuwIkMJfTe7ZtHZC MVU/1XoDZ4MMK9dJJiMczZtawBDKvkyPtw07apmWDERzCMFZp6mDYTpkaffMisIroJPZ Kaa7zL0ZVwY3I9UZjF1LeHTYWn/P2MPE9842F4vpd9ZtDpCnCIzwxlejjzIyabC5Enxh rbOIpA9dmCSXX4cdIkGqh6Dv8cfqpXsx9P4zYo8o31RRpZo5qfcb1Wx2hCtBSpPGKti2 AK3MaJ9BtHAapwPsb4iXJ7MC0GdPORtfw7FJIL0//zdHSkfEv3/LWDFC35XFfHtKBCWT tFrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:sender:message-id:content-transfer-encoding :content-disposition:mime-version:subject:cc:to:from:references :in-reply-to:dkim-signature; bh=hwKW27BSIGP2vflIk8amXw2dHCnmehVyW/SsrBiOkzo=; fh=5x3d26Qz6ERs/5V0XcGUEhmIwiM9O4PWyRYwE+rmnhk=; b=InUepX9Hrw0msWlXRwOlBdnX9547pziln5hRLlzLKb0Si+JxQhhZLZ7bzTsx1gzAJC neThy5nieGOddQ30PwPShQvuqCw0/Sv78Lg9BXei680BIlkhblrbBRxKfikVTJqmmTur NASBjY6cbwezP0EBhvYCyHTOIHWjG1Paq5c1eURdwgLkxn/GDZfDWKKzg1t878u+OVdw SeW/qGlysosLCOhP02o9QZ0qswX+HIswBQHAvwW/qESldzZFyRAKNaWQ9vEY9NVvbaeG eTwSjUw4fFvkUqJgfQAZD7H44q5IQ2/j8X21CmRRvAAA7ldkIafZuRQpTP27qaiXbabk fcYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="bIssjw2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u16-20020a056a00159000b006a68a46431bsi10748985pfk.50.2023.11.21.05.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 05:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="bIssjw2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 949628106825; Tue, 21 Nov 2023 05:44:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234359AbjKUNoE (ORCPT + 99 others); Tue, 21 Nov 2023 08:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233844AbjKUNoB (ORCPT ); Tue, 21 Nov 2023 08:44:01 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B70D6C; Tue, 21 Nov 2023 05:43:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hwKW27BSIGP2vflIk8amXw2dHCnmehVyW/SsrBiOkzo=; b=bIssjw2/Mjk8O39ibBLN9vbHhT AO1nUkBs1ooF6MG5CJ/+2w24+qAMjviTQtWGFKqEDdKTV4mfY27SkS3FkOAOpHnW1PFOAD8uT8Zp2 RqUVA7bBpUV1aLYNeMjvFHK/Y6exbo/7COEIWDUFiXkHTTXHvIgiaptrim4n/8jXT3TPoQjfRXQ7l JpGSMktyj8lalUTFrsiko8bqfDqQV8ukWVcE9pbN0rweblQxnwGyVjdtFNOWLix5HhWRbBwbrSbIS uo3sobHGnSt1GYpIyZKFfxg7SW9VyDL7qF27QbJRteFQQBvAu5VPaF/MQQs7p26MhAFKXqu2qBAbI Ff2RLkfA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:32876 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1r5R2e-000762-39; Tue, 21 Nov 2023 13:43:53 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1r5R2g-00CsyV-Ss; Tue, 21 Nov 2023 13:43:54 +0000 In-Reply-To: References: From: Russell King (Oracle) To: linux-pm@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, kvmarm@lists.linux.dev, x86@kernel.org, linux-csky@vger.kernel.org, linux-doc@vger.kernel.org, linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org Cc: Salil Mehta , Jean-Philippe Brucker , jianyong.wu@arm.com, justin.he@arm.com, James Morse , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 01/21] arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 21 Nov 2023 13:43:54 +0000 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 05:44:08 -0800 (PST) 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) --- 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; } -- 2.30.2