From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795979973; b=gsyphzIFP5UT68/zzNCKsyIcMcC4YSWw4ya1hzAQnAn72bcYiQeCg2c/juRtl5okzq7z 9GUNpt2sPKBDMyYv+RQ5sFfzclDDUnFUNFySZTrBXT1vugriyN0i8oC2HEKuECYrFqpH4 HUDKBkS3MdeyucTkAOXRroPjKbMqDi+uN9YAPbEJUsE5obxDHisP5FdKuNBzBuHkr0dJL uo7MMSnZ7mUeVPi9f1++1kz/KT9mNOSScikhDRAjfQhQ25znycFmU47pizdPckBE7dalV SiX+jK75lDGQpOT+fVyP3ePESJPI0tnsVGkLSulQ++ABRr1aefg5iUkXNrt5qz2dhHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795979973; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=AhESQQosG5Lw1exXj8RlKEAoi7z7acgxHjux9T450e8=; b=xp20h+IqVtJjBJPgXQWi8E6EmQarxA29V23kaYP7ZeSVejt2DJmPzxoYuZ8fLiD8Mfxz lqsHh3hdiRCYl/fFnS8xiR5N0GOip0Q1YOXj9WIZW2em4+0EdGhPFBlTJk2RthhuBf1a2 b3E9zpK3GgYIBgdaziPaWnUMZ/Qux2pA1oQsTEVFkI/BRthAKGWS7FqFMSC8C5JpSA6nf 5XvkhLBqlokgf91rDhByEFpSYmDnQ2IcuvdRdSWsj8djig4xf40ULxCunfOrpxHzrqsSU re1NqU0iQLM/HxTzvNJDfqjmkEHRMa0JkMFhRV2TBTgN3p5V16zaewmNLTSu+cYtlFQ== 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=YzbNhyXc; arc=none smtp.remote-ip=209.85.128.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 60592606A31C for ; Sun, 29 Nov 2026 19:19:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 60592606A31C 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YzbNhyXc Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4bb6886d30aso93087815e9.3 for ; Sun, 29 Nov 2026 11:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795979972; x=1796584772; darn=vger.kernel.org; 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=AhESQQosG5Lw1exXj8RlKEAoi7z7acgxHjux9T450e8=; b=YzbNhyXc/CoWmAj8rUyI8tLPElxBcKSPoOheJfe3iyTwRQ3dIly2Dz+wNUlFVQypLG uf7485lsqGgy8mkw4IAhkohwRLZCgXlCGE//Ng+PXFiozSKbqULlO+7DgycLsxz5jo83 ABWIpz5IAGfc1BpyTOOiXOE6dL9QVqcNGYbYU1RXefx9Jn+LX1SHSzpLTekUiOXqGz/s 5nvnGZ1A5WltPWWEO3tV5JB8VBN3nsvui2beX7jnp+soQIje/sARYBy/kAscC6S6kxb3 IuSHO221qa+k4LCnDhk04i0gfO9Bm9LdDEk81fvNySLKUgEQfvUyQIqPLZIAzS65bVGy yRsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795979972; x=1796584772; 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=AhESQQosG5Lw1exXj8RlKEAoi7z7acgxHjux9T450e8=; b=u9b6z+CsOdDixIfeUNe1UhpsfnTFu0fyBqQHTjgsok4CFt7d+cTsqURlp8FXzbq/pE hWQEQVgKCRHvN8f5y7lnbz4ADRcOFmO9b/qYYS6EzfgTYRaHLxYe6GruRnrx0ByiVgbL 2JWU28QjWNDH0/dCsTvlSCr2MPeztJSBVex6C3pOJ9UUitEjKktYy15OU5dhv039e6Qx joC+/hcmb0JejqTux2hvO+cEnqU4RFX/VSMLyKVGEy/k3eoGDOEsooRnq1/LqwhKWZEh DFERysNAoLkY8oxcvzELoHl34yV8/UAlwowdHp7v35NEFIjRjNmHg6E5MPMjTWrbCMst H9Pg== X-Forwarded-Encrypted: i=1; AL+hErERElBwGrk8oWX7jSTSvOUbzhMaQ+iqkRh872VkGukqH0m1YLOhLle7HvVEbVeY8RgutpYtDwkieIA5I6c=@vger.kernel.org X-Gm-Message-State: APuU4Z9W6ViigzqJG0lTS5iLfEiVffa+DZ/u0NhRvEY3Jk4u4bx6ADkf XPbk+Nff7tAH+RL9BNpaP8lL3LB5wsOpyxfxQ9npvG6GwMRq0mqLID5F X-Gm-Gg: AZFdTZeuqAKMM8paRhWwTFd0enBy/37mgCTjfqeOUEByFzEHVCcgLSAtniNucot+MlL N2OwGBNn5qCk+OsdKdK65w7Zt2fDzB5wkO3WbR2VaeQUJNxERRNXxAlR3hjcYXT78APFTjb2xBy WnGjWQNmY/QCdHNGAkTLNyc1mlAcdU15Aj11Bep/wmc3SrmFSirSCtymYD4hKX7jxnc/TEkj1qU pmxcqQm2xp0SuNuKm7+CesCh9cHnBp1dat/OjgUce/dDiSxij+oQdbY74r1kz/Q2cEady/yk/S7 d6ZLl4eNs0eYICquyYs9b5kPjEYV/IJ9rRFRcs/znCD8EkBc03PlA8q+x8xFnqwJk48K28KgBTJ 9w7AnQNhNqYnHGe114k49b767yCEWui/ZZuyW3XTZyLCWVWaSdR4nVXPep9W92e2pMlfOuDpB/b icBw3P1ess0njI3949/xuZ/+6ByaUmRSApX2/XomiXGqRzdz4099zQsNikx2HufR+V49ySGxbVl 03alhYhxdjd2xwJ5JREtH0hNv2SmJM2I647A1v6vbswgPQonJ84UmINbsf2rWI6DzKq7UAb7hN0 rJUpbaGvHzJi6KO+70payS7BphjvcKRK0vw= X-Received: by 2002:a05:600c:4f4a:b0:4bb:6752:8413 with SMTP id 5b1f17b1804b1-4bb8880015bmr709594265e9.8.1795979971459; Sun, 29 Nov 2026 11:19:31 -0800 (PST) Received: from deb05.proceq.com ([213.160.61.66]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb97e5356sm203840765e9.4.2026.11.29.11.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 11:19:30 -0800 (PST) From: Mehmet Fide To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , linux-kernel@vger.kernel.org Subject: [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP Date: Sun, 29 Nov 2026 20:19:29 +0100 Message-ID: <20261129191929.854496-1-mehmet.fide@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since commit cac5cefbade9 ("sched/smp: Make SMP unconditional") a CONFIG_SMP=n kernel runs the PELT updates of the fair class. Before it, !SMP had stubs for update_load_avg(), which only called cfs_rq_util_change(), for {attach,detach,remove}_entity_load_avg() and for util_est_{enqueue,dequeue}(). On a single CPU nothing needs these averages: there is nothing to balance, and schedutil, and with it UCLAMP_TASK, depends on SMP. The group shares read them, but on one CPU a runnable group gets tg->shares in every cgroup_mode with or without them, but for "tasks", which scales tg->shares by the runnable average. Return early from these functions again on !CONFIG_SMP, with the IS_ENABLED(CONFIG_SMP) toggles the cover letter of the series suggested for the UP overhead. detach_entity_cfs_rq() again tests se->avg.last_update_time, which stays 0 without the updates, only on SMP. Round trips between two tasks on a Toradex Colibri VF50 (NXP Vybrid VF500, a single Cortex-A5, CONFIG_SMP=n, PREEMPT_VOLUNTARY, HZ=100, FAIR_GROUP_SCHED), in us, the mean of three boots, and of two boots for a build with -falign-functions=32: default build -falign-functions=32 before after before after pipe 224 178 189 148 futex 272 221 248 213 unix stream 397 367 372 322 sched_yield, 2 calls 35 40 43 28 In both builds the instructions per round trip go from 11800-11840 to 10170 for the pipe and from 4805 to 4020 for sched_yield. sched_yield depends on the code layout: its L1 I-cache misses per round trip go from 66 to 98 in the default build, and from 98 to 45 in the other. Link: https://lore.kernel.org/all/20250528080924.2273858-1-mingo@kernel.org/ Signed-off-by: Mehmet Fide --- Notes: RFC because I do not know whether the PELT updates on UP are wanted for something I missed, and whether the RT, DL, IRQ and HW pressure averages should get the same treatment: they were !SMP stubs before cac5cefbade9 too and still run, as I measured only the fair class. With the patch, /proc//sched and the sched debugfs files show the initial averages, and cgroup_mode "tasks" uses one task per group. Tested on the VF50 before and after: cgroup v2 cpu.weight 100:300 gives a 1:3 split, cpu.max of 20 % gives 2010 of 10000 ms, cgroup moves, policy and nice changes, fork and exec; the same on a PROVE_LOCKING and DEBUG_ATOMIC_SLEEP kernel without a report. kernel/sched builds with W=1 without new warnings for ARM multi_v7_defconfig, x86_64 defconfig, x86_64 with SMP=n, FAIR_GROUP_SCHED and CFS_BANDWIDTH, and tinyconfig. systemd reported the boot 0.18 s (0.6 %) faster, the median of ten each. kernel/sched/fair.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2d9d3d68626..159b3eb53c2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5908,11 +5908,16 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) */ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { + u32 divider; + + if (!IS_ENABLED(CONFIG_SMP)) + return; + /* * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. * See ___update_load_avg() for details. */ - u32 divider = get_pelt_divider(&cfs_rq->avg); + divider = get_pelt_divider(&cfs_rq->avg); /* * When we attach the @se to the @cfs_rq, we must align the decay @@ -5963,6 +5968,9 @@ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s */ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { + if (!IS_ENABLED(CONFIG_SMP)) + return; + dequeue_load_avg(cfs_rq, se); __update_sa(&cfs_rq->avg, util, -se->avg.util_avg, -se->avg.util_sum); __update_sa(&cfs_rq->avg, runnable, -se->avg.runnable_avg, -se->avg.runnable_sum); @@ -6058,9 +6066,17 @@ static inline void util_est_update(struct sched_entity *se) /* Update task and its cfs_rq load average */ static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { - u64 now = cfs_rq_clock_pelt(cfs_rq); + u64 now; int decayed; + /* Load balancing and schedutil, the users of PELT, need SMP */ + if (!IS_ENABLED(CONFIG_SMP)) { + cfs_rq_util_change(cfs_rq, 0); + return; + } + + now = cfs_rq_clock_pelt(cfs_rq); + /* * Track task load average for carrying it to new CPU after migrated, and * track group sched_entity load average for task_h_load calculation in migration @@ -6123,6 +6139,9 @@ static void remove_entity_load_avg(struct sched_entity *se) struct cfs_rq *cfs_rq = cfs_rq_of(se); unsigned long flags; + if (!IS_ENABLED(CONFIG_SMP)) + return; + /* * tasks cannot exit without having gone through wake_up_new_task() -> * enqueue_task_fair() which will have added things to the cfs_rq, @@ -6172,7 +6191,7 @@ static inline void util_est_enqueue(struct cfs_rq *cfs_rq, { unsigned int enqueued; - if (!sched_feat(UTIL_EST)) + if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST)) return; /* Update root cfs_rq's estimated utilization */ @@ -6188,7 +6207,7 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq, { unsigned int enqueued; - if (!sched_feat(UTIL_EST)) + if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST)) return; /* Update root cfs_rq's estimated utilization */ @@ -15495,7 +15514,7 @@ static void detach_entity_cfs_rq(struct sched_entity *se) * - A task which has been woken up by try_to_wake_up() but is * waiting for actually being woken up by sched_ttwu_pending(). */ - if (!se->avg.last_update_time) + if (IS_ENABLED(CONFIG_SMP) && !se->avg.last_update_time) return; /* Catch up with the cfs_rq and remove our load when we leave */ -- 2.56.0