From nobody Mon Jun 8 18:56:51 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B47D3DEAE3 for ; Wed, 27 May 2026 09:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779874847; cv=none; b=Lh45gQLKvQWEV+77EE1zMh6jKnfyLNJIGCDJ8tXYWX6b4/wQaBvKM9veBbmjx+sIRWws3l+l5XMq0UpPPnkNGbTTMSxOU+EMGyvvZpUxXdMrIuQntjf0nsDecprAk3TX5H69ir8uyFomMY6V/varY4ui45aQGkhWWBVf/xQOFhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779874847; c=relaxed/simple; bh=WtgAnpJGi8d2V5T2iU0SmPo8DW5jzZPXxYgeNriIfvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CVhoL8u741ImnPFNiASxV27/g3YT413MwF6XWA/ShxSE/ZySwEOolzPxcG9lcKLSy2GTZ5DfInjVZoO6RxaTcae9SCL6iU4pOnvAbgxAdvK2MuhRWooC0b2o5prAKuyipI9U7KA3SZsCSeujZerVNOdZNjQv0AUVlSZqfyEbUl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M3Ifa53l; arc=none smtp.client-ip=209.85.216.45 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.b="M3Ifa53l" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-365d8e43759so5790925a91.0 for ; Wed, 27 May 2026 02:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779874845; x=1780479645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tT5ovlXV2hwYWFaDR0cFf/KGNdIRaHnP1CwRs2YeKmU=; b=M3Ifa53lIbRq35h6QC3Tl1vseaFugrybc7cnM8p+n2QGwLS0pGPaVoVw1aYGYIUOEo bwIDmPzG1fxaotgBWrgWtYMmlK2BGGCuoKgJkDHu+VQZRn0Q0Ar94RZXwLG8SAhkG+mY 8L4FlJnoQZZcsDlH3lekEASpvqxLsH8byXbqQF8u6UK7+EDs7NIdfFQDEmt+AES5FYnz OGTrHAubpknD/1nSUUlg8KVtDtiJK1igK0Wa6F0fWCpwYaTIxCfdD0mLD/0j50p6WRS+ nUiaTIxilk0ch4+Mmp78UeIFSWHXia7cDAB2yNVW7udTljCJe2guRpSnVkiWn/+iNn2w aFhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779874845; x=1780479645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tT5ovlXV2hwYWFaDR0cFf/KGNdIRaHnP1CwRs2YeKmU=; b=fdQfwEEw+M6cpmnnyiFMmJoQfwO5bZHGTJGblGpugSVMzwKlxA6uym8mrACkSadFL5 +gXpqq+0rL5B9cOi8f9HkicvMd0xHaYIxkd54KNVyNeLqZwWqZojDJGiTKdh8i3tc1Fq dy8olqJCj0KHj4KtnFvOV9gCAn9mGsfH3p7OhF5dnsC+kycAK47eYoclHoyxsdswO0B+ bXE95CLR2vfYuRsv6zMp9Bbtvsv8bHIcujHYsKgFjcnWx3nHvMTBNY9aKGDx1RTzcldt 5bgdaw+18wqCjZWQ7WePyv9jWKALaXEHtM+hlgICKOza4/ALWqYvKlCgwvNDtdo5C2xS ejYQ== X-Forwarded-Encrypted: i=1; AFNElJ9O+md1MZZObMOjqiofqJk8nG0Xte3qHv1Rj3BE6NtudwoJHMeIEGJ8VcYzNURTvIgTEa1hTHjBAgbTXxI=@vger.kernel.org X-Gm-Message-State: AOJu0YyLNfu8zoUSJ6wirgXq4VpGhNWhvSnN9rPiJSzjJh4C5tmJMvg3 UlgDwWrQcHNixV4AzjAkhgXIlzFhGag0xWoGfL2VaWHQH66RZdBovdS0 X-Gm-Gg: Acq92OHml45JP8uDdncE+6xGmXQbIRBEatQR0ypMUkZ/q0rcPmmJJEkhBF3Q3G2eHBX uBnvKq7PqTnxcyKHoLFI5JDpyxI42BzG+nHI79m1C1zjYAeyz/JMr9NZLI5KHdfiiLg1i8MZ/69 sr+kI4Jy1xbZVRS2B3CfkUawoxNoifDvxqeUJ3waLbyTRddGwYtj+sG76sMmyc1jHSo7hSLjN8C 06dcCpD0/BMvizrFLk9v8k68nOMSmuqz31HsUIIrtZg3WmeQohKF8XJxhInLMgY/b7xzysuA2IP WWHfRWxnKfD+oNDxjGYJNqwBVvlgdoymbITYxQ134k+DmnerdMMD8JFitddR8UT1LCAB5LPRL+E rJa7Jce8BspIhREho8gGbL6XfpDFjP1BdfF7tJZ26FhIYLZ2Lr5otlZH4UdfvShPuAVlZqqC1Q4 kcgLhWBzwQFhsMSiiLrHxKDbh6Nnxgxs7qeUsm7bdPJMo= X-Received: by 2002:a17:903:2ace:b0:2b0:badc:c9cf with SMTP id d9443c01a7336-2bea2227affmr236833765ad.13.1779874845418; Wed, 27 May 2026 02:40:45 -0700 (PDT) Received: from VM-0-14-ubuntu.. ([124.156.198.44]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb56bc46esm157388715ad.25.2026.05.27.02.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 02:40:44 -0700 (PDT) From: quzicheng315@gmail.com To: arighi@nvidia.com Cc: brho@google.com, bsegall@google.com, changwoo@igalia.com, dietmar.eggemann@arm.com, haoluo@google.com, joshdon@google.com, juri.lelli@redhat.co, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, quzicheng315@gmail.com, quzicheng@huawei.com, rostedt@goodmis.org, sched-ext@lists.linux.dev, tanghui20@huawei.com, tj@kernel.org, vincent.guittot@linaro.org, void@manifault.com, vschneid@redhat.com, zhangqiao22@huawei.com Subject: [PATCH v2] sched_ext: Rebuild fair weight on ext to fair switches Date: Wed, 27 May 2026 17:40:37 +0800 Message-ID: <20260527094037.3494671-1-quzicheng315@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zicheng Qu Tasks running on sched_ext do not use p->se.load as their active scheduling weight. Their nice-derived weight is maintained as p->scx.weight instead. When such a task switches back to fair, CFS expects p->se.load to match the task's current policy/static_prio before the task is enqueued. However, not all ext to fair transitions rebuild p->se.load. For example, scx_root_disable() switches tasks back to fair directly, and partial mode can move a task from SCHED_EXT to SCHED_NORMAL through sched_setscheduler(). In the latter case, set_load_weight(p, true) runs while p->sched_class is still ext_sched_class, so reweight_task_scx() updates p->scx.weight but leaves p->se.load stale. Rebuild the fair load weight in sched_change_end() when the class switch is from ext_sched_class to fair_sched_class. This is after the class has been changed and before the task is enqueued on fair, so CFS sees a native load_weight derived from the task's current policy/static_prio. Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class") Signed-off-by: Zicheng Qu --- Changes in v2: - Move the fix from scx_root_disable() to sched_change_end() so the same ext-to-fair rebuild also covers partial mode SCHED_EXT to SCHED_NORMAL transitions through sched_setscheduler(), as Andrea pointed out. kernel/sched/core.c | 2 ++ kernel/sched/ext.h | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b8871449d3c6..c694aabc451a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11200,6 +11200,8 @@ void sched_change_end(struct sched_change_ctx *ctx) */ WARN_ON_ONCE(p->sched_class !=3D ctx->class && !(ctx->flags & ENQUEUE_CLA= SS)); =20 + scx_rebuild_fair_weight_on_class_switch(p, ctx->class, p->sched_class); + if ((ctx->flags & ENQUEUE_CLASS) && p->sched_class->switching_to) p->sched_class->switching_to(rq, p); =20 diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h index 0b7fc46aee08..1f8248c897af 100644 --- a/kernel/sched/ext.h +++ b/kernel/sched/ext.h @@ -35,6 +35,14 @@ static inline bool task_on_scx(const struct task_struct = *p) return scx_enabled() && p->sched_class =3D=3D &ext_sched_class; } =20 +static inline void scx_rebuild_fair_weight_on_class_switch(struct task_str= uct *p, + const struct sched_class *old_class, + const struct sched_class *new_class) +{ + if (old_class =3D=3D &ext_sched_class && new_class =3D=3D &fair_sched_cla= ss) + set_load_weight(p, false); +} + #ifdef CONFIG_SCHED_CORE bool scx_prio_less(const struct task_struct *a, const struct task_struct *= b, bool in_fi); @@ -55,6 +63,9 @@ static inline int scx_check_setscheduler(struct task_stru= ct *p, int policy) { re static inline bool task_on_scx(const struct task_struct *p) { return false= ; } static inline bool scx_allow_ttwu_queue(const struct task_struct *p) { ret= urn true; } static inline void init_sched_ext_class(void) {} +static inline void scx_rebuild_fair_weight_on_class_switch(struct task_str= uct *p, + const struct sched_class *old_class, + const struct sched_class *new_class) {} =20 #endif /* CONFIG_SCHED_CLASS_EXT */ =20 --=20 2.43.0