Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1962179rda; Tue, 24 Oct 2023 08:20:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5j4byt987rpZZnZuQFEOsaJI7ppBpiY4QystKXeHNoU8NKsklxwIVFAIvvnKbC+YptDit X-Received: by 2002:a05:6a21:3d8a:b0:138:2fb8:6a14 with SMTP id bj10-20020a056a213d8a00b001382fb86a14mr2811878pzc.3.1698160804801; Tue, 24 Oct 2023 08:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698160804; cv=none; d=google.com; s=arc-20160816; b=QH0dH47EYEoD/qvgbnHJWRgHmsW3dcmzTv4SYbo/n4U4S8oWaq1d/J59oJktSTFjb7 FbqeMkoFO6UdHYzWuYtpf4HL1GusW2Y8KBWE8bu9c6+e+KXi2Lz6EikshYUgLCQpwq8t ibF3iLoZt3zqGjibUjle8LLUq9qOnNo3wYXLumMik5kZRPRw3R+Uy66Mdlzpggz4bVTu EpNwmrBb2fq8dRyaeK5z9CWUBl6S4B48k4Fa5PhvC343Ha1ZwXdNNNRL7IMpwAr46jrR BLCk7LqcS6BkDnw/jY7hiFXxPsp+1lWYOZAo6q3oIPKDtSx7S8UwxQNExNn+RATr757f xZeQ== 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=XGhpKk09pdERl3TLuSkcjp8wddtxgCnM/F8wNa+d4Ds=; fh=5x3d26Qz6ERs/5V0XcGUEhmIwiM9O4PWyRYwE+rmnhk=; b=SkQjPXkF7tMsoPZr63mMI16Dg1Ha8WkCgv2W7jVvIgOq5oQp+4mPmaNKzQJ6k+wvdm aWZgRXXAeEWIvAvBgWeMVYGAFQ8QmFssH/IOhxLbmhfQQG9U2SiA1/wurUmPcs9xuPYA O0n1rlMZWsPlPhTkhacriqF4xwasOJ65oXOyydYgh5DYb+aZHi01a/KAA5jWDR/TmAsB ep9Nf09tLxHBwTQop3YcCpKhspH2SNgENEPTeLo4efNWUbw/gkExwBEqYEiET/iqihdn DQMttgArw3dKFvs6oywmsNSViVUDi0MFd27vYJPJY3sPBWyZrusjPK6jomISghgKDJBe U8hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=BaRzQs9R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y62-20020a638a41000000b005b8f401a3a6si769409pgd.41.2023.10.24.08.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 08:20:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=BaRzQs9R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 6B13C80BA97C; Tue, 24 Oct 2023 08:20:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343577AbjJXPTd (ORCPT + 99 others); Tue, 24 Oct 2023 11:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343740AbjJXPSz (ORCPT ); Tue, 24 Oct 2023 11:18:55 -0400 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 0AB5C19A5; Tue, 24 Oct 2023 08:17:40 -0700 (PDT) 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=XGhpKk09pdERl3TLuSkcjp8wddtxgCnM/F8wNa+d4Ds=; b=BaRzQs9RvF3vLCxNwFRxtjE6ks wG2NaWwkOXyUT2VHE/A3pWr8BxpYPLcrVCvY7kZ8127m2eL2srXo4sXT7vfm30D5MBa/Bw1gIh1hD v9aK0QW1Gfhj89CyI+h0062CIXcrogZdeY5hrauhc8Ep5dLRrMsSDBLjZwqa9uOI00kgtTDaXWyJ/ Cs/eEoRzj/niuEj9vq34jJwjfsrdLFMkKMbHbKWilyR5CO6KkvKlUabW/kgmZff9YrW8EeJJWVAMX HxcW7NNOFovYMbqcpXDvqlfORQ00w00zpq6D/oEnhIchOBNNPRAw5GSIm3ujZTIICK23YJBZ3lrLZ pW687WYA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:33446 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 1qvJ9z-0004Ql-0y; Tue, 24 Oct 2023 16:17:35 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qvJA0-00AqQU-Or; Tue, 24 Oct 2023 16:17:36 +0100 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 17/39] 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, 24 Oct 2023 16:17:36 +0100 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 24 Oct 2023 08:20:01 -0700 (PDT) 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 --- 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. --- 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