Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3367592rdb; Wed, 13 Sep 2023 09:51:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFyc/+W4/N7I/Z5nODt941HHZ8RQaqq4Y3deqFuO/8VP/acxwuDfc6GQWnLGScJP1UlaCB X-Received: by 2002:a05:6870:4209:b0:1d5:3389:8a01 with SMTP id u9-20020a056870420900b001d533898a01mr3123586oac.34.1694623883093; Wed, 13 Sep 2023 09:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694623883; cv=none; d=google.com; s=arc-20160816; b=f7lY2WcPwg+BHLIoEAlg6WEbw/WPw00I4Sc2xxEa3Cp/dDUkYnR3kkBjcbQDph4qlu 1bt/yx9fhqL9XIpP6+x8O6uXqcCDYV7Uih8glLym8IzJPniobMSCOSmsRDo06szbl3MI 7wRL3LKr7IBayPJTtQ9M1wFBsjSh0763i5fALhAVF6hOUCAR/ljvbS4fVwHbmJaYoH6N IwuKwLffRStAaOdxbUbFaptpMj5zoIhWgVs5lRCAS8mCmUsRXercTnvgC/a/lVb+dXCG W+NG5B/YhHPwnzYq7aXJozZ2PRWqfur4rHwkOQS28nnYyk1zRfagCjNt84SkfNPe8pSz yKuw== 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=qi0Pf5goCeCqPv40frmbcyEQJGVwlp02boYxSHsZLss=; fh=2nhVWB0fZ+8YH0lLFpnF/Mo8eq+n1VMLe+b+IpvS0g0=; b=ky5sXMXJR47sFF5mVspPuqzDszWrbYvKU13UECTb2A7nTqrN1DG7vLdoNWkQVybTQy HO+U2U2SEKeCMxzZPBYVNAjMDr7nnGY3XQ6aO0XXM8YtcAm/IpkBCgK2Sc5gdTODaOi6 NdgMBNooTdv4LKclanDKTQ9BMDX/1XYOlKQ3cUewO5DhZnai4hiV6u1jdXm6qZb8ZTtI qbyIfNYogzIeuMqnn59Wa6BJUP5EQ3oLzuQkm9BX2qEs7USnWbyL3FhCvAz8JJ/sJJZl sma02z1ttQ+zf2MLnWTfNiYbJPS5hZ1iZJbVCJMueTo/+rfzDF4hZyUCqCNzlyNwkByX Whrg== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id q28-20020a638c5c000000b005533647f7c5si10241967pgn.420.2023.09.13.09.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 09:51:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6249D8108BDC; Wed, 13 Sep 2023 09:39:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230459AbjIMQj7 (ORCPT + 99 others); Wed, 13 Sep 2023 12:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjIMQji (ORCPT ); Wed, 13 Sep 2023 12:39:38 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B8E71FE5; Wed, 13 Sep 2023 09:39:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C192C15; Wed, 13 Sep 2023 09:39:52 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 416BC3F5A1; Wed, 13 Sep 2023 09:39:13 -0700 (PDT) From: James Morse 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 Cc: x86@kernel.org, Salil Mehta , Russell King , Jean-Philippe Brucker , jianyong.wu@arm.com, justin.he@arm.com Subject: [RFC PATCH v2 11/35] arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs Date: Wed, 13 Sep 2023 16:37:59 +0000 Message-Id: <20230913163823.7880-12-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230913163823.7880-1-james.morse@arm.com> References: <20230913163823.7880-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:39:59 -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 groat.vger.email 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 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; } -- 2.39.2