arch/x86/include/asm/div64.h | 13 ++++++++----- block/blk-throttle.c | 6 ------ 2 files changed, 8 insertions(+), 11 deletions(-)
Hello, Changes since V2: 1/2 - added the acks from David and Li (thank you) 2/2 - new and trivial Oleg. --- arch/x86/include/asm/div64.h | 13 ++++++++----- block/blk-throttle.c | 6 ------ 2 files changed, 8 insertions(+), 11 deletions(-)
On Fri, 15 Aug 2025 18:40:09 +0200 Oleg Nesterov <oleg@redhat.com> wrote: One of my 'idea patches' is to make mul_u64_u64_div_u64() a wrapper for another function that takes in extra 'int *overflowed' parameter that is set zero/non-zero for success/overflow. The 'overflowed' parameter can either be a compile-time NULL or a valid pointer. So the x86-x64 asm implementation would use different code - you need the 'jump around fail label' to write the ~0 return value to *overflowed. The extra pointer check in the C version normal path may not be worth worrying about (but the '*overflow = 0' could easily be inlined). The typical use would be: quotient = mul_u64_u64_div_u64_overflow(..., &overflowed); if (quotient == ~0ull && overflowed) ... That will generate better code than returning 'overflowed' and the quotient by reference. Although I wonder how often ~0ull is a valid result? David
David, We had a lengthy discussion and you have already acked this fix. I thought that we agreed on that a) we need to fix the problem first and b) x86 version should be consistent with the generic implementation regarding ~0ull on overflow. Can we finally merge this fix, then discuss the possible improvements and possibly change both implementation? Oleg. On 08/17, David Laight wrote: > > On Fri, 15 Aug 2025 18:40:09 +0200 > Oleg Nesterov <oleg@redhat.com> wrote: > > One of my 'idea patches' is to make mul_u64_u64_div_u64() a wrapper for > another function that takes in extra 'int *overflowed' parameter that is > set zero/non-zero for success/overflow. > The 'overflowed' parameter can either be a compile-time NULL or a > valid pointer. > > So the x86-x64 asm implementation would use different code - you need > the 'jump around fail label' to write the ~0 return value to *overflowed. > The extra pointer check in the C version normal path may not be worth > worrying about (but the '*overflow = 0' could easily be inlined). > > The typical use would be: > quotient = mul_u64_u64_div_u64_overflow(..., &overflowed); > if (quotient == ~0ull && overflowed) > ... > That will generate better code than returning 'overflowed' and the > quotient by reference. > > Although I wonder how often ~0ull is a valid result? > > David >
On Mon, 18 Aug 2025 14:39:01 +0200 Oleg Nesterov <oleg@redhat.com> wrote: > David, > > We had a lengthy discussion and you have already acked this fix. > > I thought that we agreed on that a) we need to fix the problem first > and b) x86 version should be consistent with the generic implementation > regarding ~0ull on overflow. > > Can we finally merge this fix, then discuss the possible improvements > and possibly change both implementation? I deliberately put this comment on 0/2 because it is 'future thought'. I didn't want to delay the patch going in. David > > Oleg. > > On 08/17, David Laight wrote: > > > > On Fri, 15 Aug 2025 18:40:09 +0200 > > Oleg Nesterov <oleg@redhat.com> wrote: > > > > One of my 'idea patches' is to make mul_u64_u64_div_u64() a wrapper for > > another function that takes in extra 'int *overflowed' parameter that is > > set zero/non-zero for success/overflow. > > The 'overflowed' parameter can either be a compile-time NULL or a > > valid pointer. > > > > So the x86-x64 asm implementation would use different code - you need > > the 'jump around fail label' to write the ~0 return value to *overflowed. > > The extra pointer check in the C version normal path may not be worth > > worrying about (but the '*overflow = 0' could easily be inlined). > > > > The typical use would be: > > quotient = mul_u64_u64_div_u64_overflow(..., &overflowed); > > if (quotient == ~0ull && overflowed) > > ... > > That will generate better code than returning 'overflowed' and the > > quotient by reference. > > > > Although I wonder how often ~0ull is a valid result? > > > > David > > >
© 2016 - 2025 Red Hat, Inc.