From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 C4CB63446CA for ; Thu, 25 Jun 2026 22:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782426542; cv=none; b=HjS9ZpF/JbaUPaBoss9UX1kHZMv9lw2CGEWjbF22phRLswHJZQ876aGKJvYlbxqmxKEnwaNBqJDdI59ZLD7Re5+PGZP3xG0Sy0GWnwZfJY8XL1MQmCyBr1oIngYMqETmVu2GoR4fVzDYWLreB1xQNXSaCDW/67a80JkCxcZO+LY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782426542; c=relaxed/simple; bh=jG4GpbsIX3ualKtGsKmKxuqVi8Jk+TtAqZsAgaJoSr0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VX8TE5gQ5gE1NB+GKgjdfCm99LFNNRgJ8iITKU0u0i7CW9u62dycDN0gxljHllQkfORKrHkLoJkckWsC8Ccr6V8D+zwK5APIc74nK5yCsmnMtpf7souoWeKJKGaDevNpb/EifbQs+csNhhntVlQP3ZEUtO3JFcf34htT9DhMfmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=I4CbGS0c; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="I4CbGS0c" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wbKc89q6AC2ReWnFpuPThqyIAmRjRDaxOLAg/E1a3Qg=; b=I4CbGS0cMRAOlrOYXgNZwTOogY yLFTkKdoJzLiUdQE++MbiBAISqGYnq53Kx8gQssdh7R5Bh46bqb4VKzbfhnBG8xLT0hLV3Xps9RCs 5xMnxGuF8GU4FwHse1Gu6j35mamvH6J5mhtDXO9/+4cZae/Jcdoo6hMju8N4qEbqUD0kCibeXCSpo U6HFbeVxrdmJBpuYx3QUK1AhuMjFbpI6ZfX9/7BRVRg7O9+/iXysl06h0JPMCC6C+8QiRoH6qSzKZ e7PLzGYArjNUAOczPWuGrzvXMCWJP5kMAXzGZ/jHACQVvmjsmihiwe6AlgIUb0+WBch1O94jzGkuO HHZQGQYQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1wcsYv-000000049UT-1H38; Thu, 25 Jun 2026 22:28:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id A0C2B3014C0; Fri, 26 Jun 2026 00:28:43 +0200 (CEST) Date: Fri, 26 Jun 2026 00:28:43 +0200 From: Peter Zijlstra To: Vincent Guittot Cc: K Prateek Nayak , mingo@redhat.com, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, qyousef@layalina.io Subject: Re: [PATCH 6/6 v3] sched/eevdf: Speedup short slice task scheduling Message-ID: <20260625222843.GE1181229@noisy.programming.kicks-ass.net> References: <20260624151229.1710703-1-vincent.guittot@linaro.org> <20260624151229.1710703-7-vincent.guittot@linaro.org> <613c1bde-4152-493f-b103-f1fda035b4af@amd.com> <20260625083720.GR42921@noisy.programming.kicks-ass.net> <20260625100957.GA2568396@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 25, 2026 at 02:59:16PM +0200, Vincent Guittot wrote: > On Thu, 25 Jun 2026 at 14:57, Vincent Guittot > wrote: > > > > On Thu, 25 Jun 2026 at 12:10, Peter Zijlstra wrote: > > > > > > On Thu, Jun 25, 2026 at 10:37:20AM +0200, Peter Zijlstra wrote: > > > > On Thu, Jun 25, 2026 at 01:07:43PM +0530, K Prateek Nayak wrote: > > > > > > > > > > +static u64 eligible_vruntime(struct cfs_rq *cfs_rq, struct sched_entity *se) > > > > > > +{ > > > > > > + struct sched_entity *curr = cfs_rq->curr; > > > > > > > > > > curr seems to be unused here and is NULL anyways when > > > > > set_protect_slice() is called ;-) > > > > > > > > Ah, but it is not with the flat patches on, which is why I was a little > > > > confused ;-) > > > > > > > > That said; I now see se == curr. So let me go have another look at all > > > > that. > > > > > > I might be slow -- it is definitely waay to warm already -- but I'm not > > > seeing how you don't want avg_vruntime() here. > > > > It is somehow related to avg_vruntime() except that I don't want the > > current avg_vruntime but the avg_vruntime when entity_key(se) will be > > null and se will become ineligible > > > > If I use current avg_vruntime(), once se will have run enough to get > > its vruntime == (now old) avg_vruntime, the new avg_vruntime will have > > move forward and the se's vruntime will still be eligible > > And I should name it ineligible_vruntime because of the +1 I've ended up with something like so. --- --- 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; } +/* + * \Sum (v_i - v0)*w_i + * V = ------------------- + v0 + * \Sum w_i + * + * Let W = \Sum w_i, and move v_j such that 'v_j == V', thus: + * + * V = 1/W * {(v_j - v0)*w_j + \Sum_i!=j (v_i - v0)*w_i} + v0 + * + * v_j = 1/W * {(v_j - v0)*w_j + \Sum_i!=j (v_i - v0)*w_i} + v0 + * + * v_j = 1/W * (v_j - v0)*w_j + 1/W * \Sum_i!=j (v_i - v0)*w_i + v0 + * + * v_j - 1/W * (v_j - v0)*w_j = 1/W * \Sum_i!=j (v_i - v0)*w_i + v0 + * + * v_j*W - (v_j - v0)*w_j = \Sum_i!=j (v_i - v0)*w_i + v0*W + * + * v_j*(W - w_j) + v0*w_j = \Sum_i!=j (v_i - v0)*w_i + v0*W + * + * v_j*(W - w_j) = \Sum_i!=j (v_i - v0)*w_i + v0*(W - w_j) + * + * \Sum_i!=j (v_i - v0)*w_i + * v_j = ------------------------ + v0 + * W - w_j + * + * When v_j happens to be curr, then '\Sum_i!=j (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 = cfs_rq->curr; + long weight = cfs_rq->sum_weight; + s64 delta = 0; + + if (curr && !curr->on_rq) + curr = NULL; + + /* + * This is called from set_next_task_fair(.first=true) / + * set_protect_slice() so curr had better be set and on_rq. + */ + WARN_ON_ONCE(!curr); + + if (weight) { + s64 runtime = 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 -= (weight - 1); + + delta = div64_long(runtime, weight); + } + + return cfs_rq->zero_vruntime + delta + 1; +} + static inline u64 cfs_rq_max_slice(struct cfs_rq *cfs_rq); /* @@ -1058,8 +1119,14 @@ static inline void set_protect_slice(str slice = cfs_rq_min_slice(cfs_rq); slice = min(slice, se->slice); - if (slice != se->slice) - vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se)); + + /* If there are shorter slices than se's one */ + if (slice != se->slice) { + if (sched_feat(PREEMPT_SHORT)) + vprot = min_vruntime(vprot, ineligible_vruntime(cfs_rq)); + else + vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se)); + } se->vprot = vprot; }