From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0809537C92E; Tue, 30 Jun 2026 09:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810225; cv=none; b=J0uJD8grb6XdzwvfWLu32pAcBySPIqiuX6OFFvhLorCJeX1uuKWJzP6+m2Pm9HvgMEH4LHEOAPRl+hxTVx6IabuupdbcZeo8tTQQUVubRvBiExuHE6Bp6cHaffBQ7JdK2oVIL8E5GKf8NfA7LlDMAeU/nPaV4WEiedCLffxezec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810225; c=relaxed/simple; bh=uyif3yzeUPOpOYABbbmwOyI4bq2mlo8viqZlOzWUexk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sd9rSEQ/vhDuIvLbEP87qbqd1zPDRL9cT1IeDcPGTZzGHb0sbni/rG910mBeSwNcg7Xpy2Kdvh7ES8UJ32+hrAmuvbpWl9gNAPwRiFdF41u7bZbLlCPTSeZYZ9wxbh9V7f1+G2iZRReD8DG4nQ6+NCoMW9mBVfxr5ryjftqhpjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RuxdBz5E; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=h8GIiGVs; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RuxdBz5E"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="h8GIiGVs" Date: Tue, 30 Jun 2026 09:03:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1782810221; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/rafcOasFvBs8RYqpU38I/PcUIcEBL2aXp5qAf7Qkzw=; b=RuxdBz5E46XQB5w4cJRAHiubA5LRXR0zQbd7I4amsvKxb6ILIN9lB+m87hn6j2CELg8ytW KA39yYnWcO69WXI96CQlW6a2xshcfrtxSfwIgIZF67syff3YajLAhCg/4MLqdRtTeAGvPA obV2rXYOvkx9bYiYkgL10qepk0Y5wf3Yw4ZikGVfMbs+uCT0JQyYkaUlO+mZbd3o4bJE3+ lVrMcTMuy6lhIbVArYN13Cb5opu9LUeNtXQoDs2bR4lLUBtIIyscY1D9cJMeVuga9riN84 H3jfT9bZnEEjSH5zJ37WJlBYkomXMgH81k9AuLIKWDhJB4ZZKe8hSpbFNUUSnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1782810221; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/rafcOasFvBs8RYqpU38I/PcUIcEBL2aXp5qAf7Qkzw=; b=h8GIiGVs1ZM5d0qeP1BNHrapWBLK9r2zvW1MiFg/w5pjpIEMLDKE3L17hHwz9hCNiTJ5hT j/LcTl1dJDm8ZICw== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/eevdf: Speedup short slice task scheduling Cc: Vincent Guittot , "Peter Zijlstra (Intel)" , K Prateek Nayak , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260624151229.1710703-7-vincent.guittot@linaro.org> References: <20260624151229.1710703-7-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178281021944.3843924.13242155820515469077.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 0d1e7a2bab35dbc898e8a6aa29fd074dafbbccda Gitweb: https://git.kernel.org/tip/0d1e7a2bab35dbc898e8a6aa29fd074dafb= bccda Author: Vincent Guittot AuthorDate: Wed, 24 Jun 2026 17:12:29 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Jun 2026 10:56:55 +02:00 sched/eevdf: Speedup short slice task scheduling When a task with a shorter slice is enqueued, we protect the running task which has a longer slice until it becomes ineligible instead of a full slice in order to speedup the switch to other tasks until the task with the shortest slice is scheduled. This helps to the task to not wait too many full slices before running. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Tested-by: K Prateek Nayak Link: https://patch.msgid.link/20260624151229.1710703-7-vincent.guittot@linar= o.org --- kernel/sched/fair.c | 71 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2547a97..c575910 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -777,6 +777,67 @@ u64 avg_vruntime(struct cfs_rq *cfs_rq) return cfs_rq->zero_vruntime; } =20 +/* + * \Sum (v_i - v0)*w_i + * V =3D ------------------- + v0 + * \Sum w_i + * + * Let W =3D \Sum w_i, and move v_j such that 'v_j =3D=3D V', thus: + * + * V =3D 1/W * {(v_j - v0)*w_j + \Sum_i!=3Dj (v_i - v0)*w_i} + v0 + * + * v_j =3D 1/W * {(v_j - v0)*w_j + \Sum_i!=3Dj (v_i - v0)*w_i} + v0 + * + * v_j =3D 1/W * (v_j - v0)*w_j + 1/W * \Sum_i!=3Dj (v_i - v0)*w_i + v0 + * + * v_j - 1/W * (v_j - v0)*w_j =3D 1/W * \Sum_i!=3Dj (v_i - v0)*w_i + v0 + * + * v_j*W - (v_j - v0)*w_j =3D \Sum_i!=3Dj (v_i - v0)*w_i + v0*W + * + * v_j*(W - w_j) + v0*w_j =3D \Sum_i!=3Dj (v_i - v0)*w_i + v0*W + * + * v_j*(W - w_j) =3D \Sum_i!=3Dj (v_i - v0)*w_i + v0*(W - w_j) + * + * \Sum_i!=3Dj (v_i - v0)*w_i + * v_j =3D ------------------------ + v0 + * W - w_j + * + * When v_j happens to be curr, then '\Sum_i!=3Dj (v_i - v0)*w_i' + * is cfs_rq->sum_w_runtime, and 'W - w_j' is cfs_rq->sum_weight, since curr + * is not included in the sum. + */ +static u64 ineligible_vruntime(struct cfs_rq *cfs_rq) +{ + struct sched_entity *curr =3D cfs_rq->curr; + long weight =3D cfs_rq->sum_weight; + s64 delta =3D 0; + + if (curr && !curr->on_rq) + curr =3D NULL; + + /* + * This is called from set_next_task_fair(.first=3Dtrue) / + * set_protect_slice() so curr had better be set and on_rq. + */ + WARN_ON_ONCE(!curr); + + if (weight) { + s64 runtime =3D cfs_rq->sum_w_vruntime; + + /* + * Do not add @curr to obtain the effective '- w_j' terms. + */ + + /* sign flips effective floor / ceiling */ + if (runtime < 0) + runtime -=3D (weight - 1); + + delta =3D div64_long(runtime, weight); + } + + return cfs_rq->zero_vruntime + delta + 1; +} + static inline u64 cfs_rq_max_slice(struct cfs_rq *cfs_rq); =20 /* @@ -1058,8 +1119,14 @@ static inline void set_protect_slice(struct cfs_rq *cf= s_rq, struct sched_entity=20 slice =3D cfs_rq_min_slice(cfs_rq); =20 slice =3D min(slice, se->slice); - if (slice !=3D se->slice) - vprot =3D min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se)); + + /* If there are shorter slices than se's one */ + if (slice !=3D se->slice) { + if (sched_feat(PREEMPT_SHORT)) + vprot =3D min_vruntime(vprot, ineligible_vruntime(cfs_rq)); + else + vprot =3D min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se)); + } =20 se->vprot =3D vprot; }