From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 5EC78400E1A for ; Wed, 27 May 2026 11:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779883196; cv=none; b=OOArUtakKF1xkTg2RTaDuTLMas3++7DO2BnmnoJYuuKwTnXfL1GyyTgk54fXGrPdRvSXxuWAe7mMLtptJ8ECPJaaZsgtPoywkpW9Wd4uZu570j6ok4WnaTGuWZHJ/cL4RlubVFUHfUMlvpNML16kPFZJqyJsh/qFnsZJp/4fjKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779883196; c=relaxed/simple; bh=vnpUWkuPi5Tc+BPopPKWqMfBY3GGxRzDOH903yXbtUo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Dx+vFYfqDo/1rEm6kT8wY+PZyJxy9WQ14U3Dr8p25JUIYNlR7qTHfIM8UDaBcIvN5l5UAf6CPqRGr/9zPS7bRIXAnD5cFogoyK0n8sxNxw8+PYXjYJyyBqg2LjP2iOkmFG0NY5X2l4rb2WreraCR2u8sJtmsPA9Gzo3RgMrgzrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bmsBrOmb; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none 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="bmsBrOmb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=hvcFSXLgNoqbux/fy7ZnAXO5CjEmQe7s3EXgtcN4pKk=; b=bmsBrOmbFVmzDmwR7q1Dclg596 Gnk1le/S7HQbH6W/ZAv/zHwGNIN72u2wu6/c4vD51ORz2aubq0TYE2i9fQ/dRCQKxyKf8b84s5ThQ 5TrTG69FVWABHuntNwt9RTuwmCz8Pp+IkC2cFqZtulGwsxO7wz25QF+IRO5Mtrm9UlXCZ0I5Z15L1 oUPJmEZF7Y6ifDRaQgIKdWmboDAJm1aF0Bcvyse5T37dJhqSdI9n/H9d1RAXo2/TPxVNvtT4N+wY1 GfaEcsZNEtKfWxpEQsnMdCVQ8WDNy7VB/kpObt7flMIzysqVCdid8cbrugEnzUW0ZF/j30ddAAMZ6 c0eEgNYg==; Received: from 2001-1c00-8d85-4b00-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:4b00:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wSCvA-00000002Jq0-2PEe; Wed, 27 May 2026 11:59:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 84B7E300673; Wed, 27 May 2026 13:59:35 +0200 (CEST) Date: Wed, 27 May 2026 13:59:35 +0200 From: Peter Zijlstra To: Li kunyu Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] kernel/sched/fair: Fix the issue of virtual runtime conversion error Message-ID: <20260527115935.GU3126523@noisy.programming.kicks-ass.net> References: <20260526071537.17460-1-likunyu10@163.com> <20260527072113.359604-1-likunyu10@163.com> 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: <20260527072113.359604-1-likunyu10@163.com> On Wed, May 27, 2026 at 03:21:13PM +0800, Li kunyu wrote: > The logic of the function here should be to convert the virtual runtime > into actual time by combining it with the weight of the scheduling > entity. > However, it cannot be converted by simply converting actual time into > virtual running time. A reverse conversion is required to obtain the > correct time. > > Signed-off-by: Li kunyu > --- > v2: Use the div64_ul function to perform division operation > > kernel/sched/fair.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 69361c63353a..53f3373c1735 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7033,7 +7033,9 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p) > resched_curr(rq); > return; > } > - delta = (se->load.weight * vdelta) / NICE_0_LOAD; > + > + if (unlikely(se->load.weight != NICE_0_LOAD)) > + delta = div64_ul(NICE_0_LOAD * vdelta, se->load.weight); > > /* > * Correct for instantaneous load of other classes. This seems wrong. Note that calc_delta_fair() does: vdelta := (delta * NICE_0_LOAD) / se->load.weight which gets us time -> vtime. Therefore the vtime -> time transform is the inverse of that: delta := (vdelta * se->load.weight) / NICE_0_LOAD; which is exactly what the current code does. Specifically: NICE_0_LOAD se->load.weight (delta * ---------------) * --------------- = delta se->load.weight NICE_0_LOAD