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 B1ADF3A2561 for ; Fri, 1 May 2026 13:43:15 +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=1777642997; cv=none; b=K7eWvZUrnQHOHPT42DBNHOAntiZf0E+Cx1+Ny3N728TvuYAVFH28doeRWYuh0GtpURiFTkl2U4Gx6YHJaN08cXg8GyUYFfjqk8ihvmZP6YRvo4GzkFvgCYPy3ye3VFg9MlDhG6dL3ivzUcrh/ZSO9cLX1qy0Zy2O76mGbVHTgSg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777642997; c=relaxed/simple; bh=DdfNX74Tn15ennAPVf8qEGfgxtlFxjehAIyZLjorQMs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZGa95p6IIf/6netf/4flGYfIdkE96MYTR7n1WlP2Hux6oKMU/qas9YBT7L1oegWf4ZV5xHUiUuVVv9JJjo5U0xQZ3FibvIl1lHyU+np7D0JtA6cqlcXYiSzmc6BNx/aEZM+qrA4fWttWyrnsqXpzTY5vH6LH5DR1+/NAuA16jqo= 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=fm5tPju/; 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=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="fm5tPju/" 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=5iIRnd09VuDLnU/oYA0B3q1RGlPlx5LJW4GtXu4au6A=; b=fm5tPju/WCYJ9w/Zrj0DddO5m5 p2hSeDXeCwuuau+S1Ki0ugjzi2bya//G624MgJBMxSK792eW/m19vSnPgmw7YEUfaxsWKI9q7Xlnc bdT4KwSeERrUxzZPePxO/N+pg+1ojpN+i6A6buEzmKcrYsYrKisMXoGfxUlu3s21rer/fSU+zrPeV bCdUiWa1XIjTpvh3+lV8zYrT0G382OdyX055brP6dx4Eo9u0C/q926tGSCjO6pp/SDGNpLzRsqsEM tJxFMmZ12Cp7RUBZdI6wWeX2xRz28s/WmgmFo/495/3yQATqrsGb7DyMy2rDpMfFpr4jV1e/LjnGm nJdf8IMw==; 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 desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1wIo96-00000008z76-2XUK; Fri, 01 May 2026 13:43:08 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id EA4A33006CD; Fri, 01 May 2026 15:43:07 +0200 (CEST) Date: Fri, 1 May 2026 15:43:07 +0200 From: Peter Zijlstra To: David Laight Cc: K Prateek Nayak , Zhan Xusheng , Ingo Molnar , Vincent Guittot , Juri Lelli , linux-kernel@vger.kernel.org, Zhan Xusheng , Dietmar Eggemann , Valentin Schneider , Ben Segall , Steven Rostedt , Mel Gorman Subject: Re: [PATCH RESEND] sched/fair: Fix overflow in vruntime_eligible() Message-ID: <20260501134307.GD1026330@noisy.programming.kicks-ass.net> References: <20260415145742.10359-1-zhanxusheng@xiaomi.com> <20260428144951.121765-1-zhanxusheng@xiaomi.com> <57e94d7e-b8fb-49bc-a914-8a7401e43af3@amd.com> <20260428173521.GK3126523@noisy.programming.kicks-ass.net> <4870ea19-78d4-44b2-9f18-14c3f8782726@amd.com> <20260501104006.GA3102624@noisy.programming.kicks-ass.net> <20260501140521.27be883d@pumpkin> 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: <20260501140521.27be883d@pumpkin> On Fri, May 01, 2026 at 02:05:21PM +0100, David Laight wrote: > > Anyway, I had a poke around with godbolt, and the below seems to > > generate the best code for things like x86_64 and arm64. > > > > Specifically, the __builtin_mul_overflow() already has to compute the > > 128 bit product anyway for most architectures, so using that directly > > then leads to saner asm and easier to understand code. > > Older versions of gcc (maybe before 10?) generate a call to the full > 128 bit multiply (_muldid3 ?) on mips64 - rather than just using the instruction > that generates the high part of the product. > The library function is now included but is slightly more complex because > it does the high*low multiples as well. > > The same happens on sparc64 and the asm multiply code looks strange. godbolt only has mips64 gcc-9.5 (no 8.1 which is the very oldest gcc we support) and that doesn't seem to generate calls to library functions. I don't particularly care about the quality of old compiler output, nor do I really care for the performance aspect on these fringe architectures. As long as it builds and isn't obviously broken, things are good. Using the gcc-8.5 toolchains from kernel.org (the oldest still supported set) I see no library calls for MIPS64. I do see them for Sparc64, but that actually has that library call implemented. Anyway, I'll throw it at the robots, see what if anything pops out. > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > > index 9f63b15d309d..f15f4468efe5 100644 > > --- a/kernel/sched/sched.h > > +++ b/kernel/sched/sched.h > > @@ -146,7 +146,7 @@ extern struct list_head asym_cap_list; > > * Really only required when CONFIG_FAIR_GROUP_SCHED=y is also set, but to > > * increase coverage and consistency always enable it on 64-bit platforms. > > */ > > -#ifdef CONFIG_64BIT > > +#if defined(CONFIG_64BIT) && defined(__SIZEOF_INT128__) > > # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT + SCHED_FIXEDPOINT_SHIFT) > > # define scale_load(w) ((w) << SCHED_FIXEDPOINT_SHIFT) > > # define scale_load_down(w) \ > > @@ -157,10 +157,12 @@ extern struct list_head asym_cap_list; > > __w = max(2UL, __w >> SCHED_FIXEDPOINT_SHIFT); \ > > __w; \ > > }) > > +typedef __int128 sched_double_long_t; > > #else > > # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT) > > # define scale_load(w) (w) > > # define scale_load_down(w) (w) > > +typedef s64 sched_double_long_t; > > Seems strange that this is signed but the 64bit one is unsigned. They both signed. __int128 is a signed type.