Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795970165; b=LuGvVeQUxlQ1nqgCKE26OzBELW556L9TvXYTJpuCji5WIljlOt0ZSCJncnWjaCli86rT QQSellKX1comCn9zEZV2Tjm94CLCGXFRp2OVZU1PfpIC8dUdX2zjw1dtLZYLi3V6DyM0V wcGyRH/S4HqVD1cYtwIr2BnMBAXBe7nAXUtyuOSeap6GkliDfheNnoKiyLbBwY984NL64 ZI7DKgdieNrMEsXY0NhhNYsP9VpWxNhxB/ehg/HhO/z2krwepxvTJ/BlSy2H+RZAwxPnI 9JrdVi6guQMc0snDPwmOFdjJ1otKD2Rh0+ilnDxCQhPLWYT8ZhUfdMj93mu/WpC4tTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795970165; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=+EiLB3vbXkhJBuqTyYsjFXrtcbbwocrco7S/8m37TGE=; b=wKZyq4CRS66FPSgIVqX7gi9bw5YGxTHT76tS6ybG6Jv0ulOSgm2qH8G7iFAOiE6Szn9z 3JN6d7c9L5V3NmearLzmUhcuavnZhZBiWqj98fq2i5Soj1wWwXTpu6rCt4mm/wfTWckEZ lmJn2FzXqmmlbL30KD+vXRdxQaXuknDA4WJbP7YY8lgKftAvosKCPyCAR5MUBF8CYTHiS nVwRNpTOoDK2g67SavglzhQ+aU9tmMAfnznQ8rFVUgVdKJ252KNkBxzaMkHyJTFGBgRJJ ofs3q/0zNDf6TjD8WjOSK/rin+fzBz1xNfFvPntqeEL+WtOB9dj8r5VKFc07NVWVSeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YTutk61G; arc=none smtp.remote-ip=209.85.210.177 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B815606A334 for ; Sun, 29 Nov 2026 16:36:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B815606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YTutk61G Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-8a05b210703so4454349b3a.0 for ; Sun, 29 Nov 2026 08:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795970165; x=1796574965; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+EiLB3vbXkhJBuqTyYsjFXrtcbbwocrco7S/8m37TGE=; b=YTutk61GRtPQfipO4Touaha/C2h5ioeF0/cLDYg7Zlb+J96Xsk/sYfH65YvTB7KhYy gcDKvaK8KdWVOwVBnzMlZWmaprtAs36dOnRXowUEhQ+hsqT5mDiJ5/gj+UsoTddJ6wtz fedGSc4mcwMhipDLiiJPxdnSzq4sC7lBXa4il8euaxwc+RxmStLHtGWFlAcHWNFkkSbI fe2FAeZ6JQ1ZQaOgqGyAoZ5ImfomBrNzo9pJDTRcbC63vUn0spNUBGxO2ueso6zjBRjB UmKNFIJAG+bCk5mwSh/Ncog6Sl62pHoFRlAqhcMDrGQ1Ait3KarhOQNZB3Jwi6VW4acY bhVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795970165; x=1796574965; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+EiLB3vbXkhJBuqTyYsjFXrtcbbwocrco7S/8m37TGE=; b=v4mqp5ggLr29y6R7i1YY5A8b/64m2fJqvmLoCdoIdW0sOF/FeEbdN+n/6Fp7R+xqm1 qQkkXV81H5K1G0VI0jHJ7scBoMIJbcCrdRqHaDsXHL22LGEBIMF/kBLxDGN96XxiumnW veGRHyjoKSZTq4HFUabCwO/9Jtk8at/uKaAbl79OnAzwTvJdulB5bo/tWnRKHHvIKfvb wrjW8UcESSRRixOZzdjbRBqL8ZewVBr5QWo3e1bu57a2RNbvoIQl731KUGvilpozijp9 az9YuvFzXBHte2ITelM4Bf6MTg278xB1AVZ+I5Q8sP0WnBn6Ow8Bj3huPsfnfsTIQ23L HYUw== X-Gm-Message-State: APuU4Z8HCFFGmCZMwL7fvyxuCzuIMmM1kTQcLc/eQkKFnA59Cu0Njaqz gmoc10psLBN2Hm8SETsfvajxaPMSwyUBMzucqPO6stEm5jxz34jw37g4WrhIFw== X-Gm-Gg: AZFdTZdlVWmNZOzwzRP51IzsklbUDn+Bj6WCzqjuca4tIUvY5qoxqE5d9WKlFBYqr3/ oW+5ILaoWQ25y3oiSO4DFEEr+m3dLnmVkr4rPhjGQ9Im8iFa7yRVUUHNiwoJNxbT9oivgyYJZsc kWGTjzOjjJ3GJBobo/cKkQ2gor0PwRIoIX6ZD8cO1QMFwelL/MTD56WShj6+lB/X0arZPfyOx4P qYsvNUBEWlKzT1Ti2bNCrNO3BZmNV2HmR8wVPpp8fge4K0DfhS87ZMEU9Bw+c9I+EK2MBF5G8SW 03sQHEPjd3xPxXMU+E0rnj7Ai6k6TxoQSQP5fG0kF1xzJhXsACHtLyg3kLvQkd4Iqcwy+4bAWan HGYvAY6tSKggD9RQAVl/JjOtspva+THfjxxwSuGgY7EyHsP6ogca/T0fw/x5Wyh/bWsMWcpBOMR viYluKcRjPcPYdRQsCHVv83xxVbRgNM7CAV9rtec7KRsgyaYpgDhF+NGokiN3jwtCgw7L2l8K4k Aj1RDjf2+v0ee5aFXfQCqgIqu1UipUlhoo/hRoXDtF1dNE2uC1/F7uHkFFjF1+Sfw/Zr2aHA3ud F4pyOZseOafFvqrD+uiosjhJJmsPh+oPbypJOcAP8OsIq1Erk0UAN/TBia3VtGkuftk/owGXy6m XuBDt2z6fAIC2V2CN5bVcnZHpfzY+CKHDXpyaJDFJE29lPOzTOqhjC06Lxg== X-Received: by 2002:a05:6a20:3219:b0:407:957:5e2 with SMTP id adf61e73a8af0-407095706a9mr16548029637.9.1795970164703; Sun, 29 Nov 2026 08:36:04 -0800 (PST) Received: from cchengyang.duckdns.org (1-164-77-103.dynamic-ip.hinet.net. [1.164.77.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87285c89dsm15834682b3a.13.2026.11.29.08.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 08:36:03 -0800 (PST) From: Cheng-Yang Chou To: sched-ext@lists.linux.dev, Tejun Heo , David Vernet , Andrea Righi , Changwoo Min Cc: Ching-Chun Huang , Chia-Ping Tsai , chengyang.chou@mediatek.com, Cheng-Yang Chou Subject: [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs Date: Mon, 30 Nov 2026 00:35:20 +0800 Message-ID: <20261129163536.15478-1-yphbchou0911@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit With SCX_OPS_BUILTIN_IDLE_PER_NODE, a CPU is tracked in the idle cpumask of cpu_to_node(cpu). When the starting node has no idle CPU, pick_idle_cpu_from_online_nodes() walks the other online nodes in distance order. Nodes that own no CPU can't have an idle one, but the walk still visits them. On a Raspberry Pi 5, the firmware adds numa=fake=8. That gives eight online nodes, but cpu_to_node() puts every CPU in node 0, so a search that leaves node 0 visits seven nodes that can't have an idle CPU. Walk only the nodes that have an active CPU, kept up to date across CPU hotplug. Nothing changes when every online node has an active CPU. On that rpi, five hackbench -p -g 10 -l 10000 runs under scx_simple gave these means (ops.select_cpu() time per call, run time): global idle cpumask per-node idle cpumasks before 135ns, 7.39s 484ns, 7.49s after 134ns, 7.35s 141ns, 7.39s With the patch, the per-node cost is close to the global one. The walk itself came up before and was left alone because the node count is usually low [1]. This doesn't change the walk. It only skips nodes that can't have an idle CPU able to take tasks. [1] https://lore.kernel.org/all/abmQRgwQZhZk9-_S@slm.duckdns.org/ Signed-off-by: Cheng-Yang Chou --- I'm not sure why the rpi does this, but I don't think this fix only matters downstream. Nothing changes when every online node has an active CPU, and other setups may run into the same problem as the rpi. kernel/sched/ext/idle.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/kernel/sched/ext/idle.c b/kernel/sched/ext/idle.c index 922fbc3065cc..73af83231f74 100644 --- a/kernel/sched/ext/idle.c +++ b/kernel/sched/ext/idle.c @@ -145,6 +145,24 @@ static s32 pick_idle_cpu_in_node(const struct cpumask *cpus_allowed, int node, u */ static DEFINE_PER_CPU(nodemask_t, per_cpu_unvisited); +/* + * Nodes with an active CPU. Idle CPUs are tracked per cpu_to_node(), so other + * nodes can't have one that can take tasks. Updated on enable and on CPU + * hotplug after cpu_active_mask changes. + */ +static nodemask_t scx_idle_cpu_nodes; + +static void update_idle_cpu_nodes(void) +{ + nodemask_t nodes = NODE_MASK_NONE; + s32 cpu; + + for_each_cpu(cpu, cpu_active_mask) + node_set(cpu_to_node(cpu), nodes); + + nodes_copy(scx_idle_cpu_nodes, nodes); +} + /* * Search for an idle CPU across all nodes, excluding @node. */ @@ -168,10 +186,10 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i unvisited = this_cpu_ptr(&per_cpu_unvisited); /* - * Restrict the search to the online nodes (excluding the current - * node that has been visited already). + * Restrict the search to the nodes with active CPUs (excluding the + * current node that has been visited already). */ - nodes_copy(*unvisited, node_states[N_ONLINE]); + nodes_copy(*unvisited, scx_idle_cpu_nodes); node_clear(node, *unvisited); /* @@ -198,6 +216,8 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i return cpu; } #else +static inline void update_idle_cpu_nodes(void) {} + static inline s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, int node, u64 flags) { @@ -414,6 +434,8 @@ void scx_idle_update_selcpu_topology(struct sched_ext_ops *ops) static_branch_enable_cpuslocked(&scx_selcpu_topo_numa); else static_branch_disable_cpuslocked(&scx_selcpu_topo_numa); + + update_idle_cpu_nodes(); } /* base-commit: 95a4df9944cd5d57a92662269114ba99cb972394 -- 2.56.0