linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] refperf: work around 64-bit division
@ 2020-05-29 20:15 Arnd Bergmann
  2020-05-29 21:41 ` Paul E. McKenney
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Arnd Bergmann @ 2020-05-29 20:15 UTC (permalink / raw)
  To: Paul E. McKenney, Josh Triplett
  Cc: Arnd Bergmann, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

A 64-bit division was introduced in refperf, breaking compilation
on all 32-bit architectures:

kernel/rcu/refperf.o: in function `main_func':
refperf.c:(.text+0x57c): undefined reference to `__aeabi_uldivmod'

Work it by using div_u64 to mark the expensive operation.

Fixes: bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/rcu/refperf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/refperf.c b/kernel/rcu/refperf.c
index 47df72c492b3..c2366648981d 100644
--- a/kernel/rcu/refperf.c
+++ b/kernel/rcu/refperf.c
@@ -386,7 +386,7 @@ static int main_func(void *arg)
 		if (torture_must_stop())
 			goto end;
 
-		result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
+		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
 	}
 
 	// Print the average of all experiments
@@ -397,9 +397,14 @@ static int main_func(void *arg)
 	strcat(buf, "Threads\tTime(ns)\n");
 
 	for (exp = 0; exp < nruns; exp++) {
+		u64 avg;
+		u32 rem;
+
 		if (errexit)
 			break;
-		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
+
+		avg = div_s64_rem(result_avg[exp], 1000, &rem);
+		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
 		strcat(buf, buf1);
 	}
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-29 20:15 [PATCH] refperf: work around 64-bit division Arnd Bergmann
@ 2020-05-29 21:41 ` Paul E. McKenney
  2020-05-29 22:12 ` Randy Dunlap
  2020-05-30  3:52 ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2020-05-29 21:41 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Josh Triplett, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> A 64-bit division was introduced in refperf, breaking compilation
> on all 32-bit architectures:
> 
> kernel/rcu/refperf.o: in function `main_func':
> refperf.c:(.text+0x57c): undefined reference to `__aeabi_uldivmod'
> 
> Work it by using div_u64 to mark the expensive operation.
> 
> Fixes: bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Many thanks, Arnd!

I queued this and reverted my earlier 64-bit-only restriction, pushing
the result out on the -rcu tree's "dev" branch.  I also added a couple
of Reported-by entries.

							Thanx, Paul

> ---
>  kernel/rcu/refperf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/refperf.c b/kernel/rcu/refperf.c
> index 47df72c492b3..c2366648981d 100644
> --- a/kernel/rcu/refperf.c
> +++ b/kernel/rcu/refperf.c
> @@ -386,7 +386,7 @@ static int main_func(void *arg)
>  		if (torture_must_stop())
>  			goto end;
>  
> -		result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
> +		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
>  	}
>  
>  	// Print the average of all experiments
> @@ -397,9 +397,14 @@ static int main_func(void *arg)
>  	strcat(buf, "Threads\tTime(ns)\n");
>  
>  	for (exp = 0; exp < nruns; exp++) {
> +		u64 avg;
> +		u32 rem;
> +
>  		if (errexit)
>  			break;
> -		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> +
> +		avg = div_s64_rem(result_avg[exp], 1000, &rem);
> +		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
>  		strcat(buf, buf1);
>  	}
>  
> -- 
> 2.26.2
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-29 20:15 [PATCH] refperf: work around 64-bit division Arnd Bergmann
  2020-05-29 21:41 ` Paul E. McKenney
@ 2020-05-29 22:12 ` Randy Dunlap
  2020-05-30  3:52 ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2020-05-29 22:12 UTC (permalink / raw)
  To: Arnd Bergmann, Paul E. McKenney, Josh Triplett
  Cc: Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On 5/29/20 1:15 PM, Arnd Bergmann wrote:
> A 64-bit division was introduced in refperf, breaking compilation
> on all 32-bit architectures:
> 
> kernel/rcu/refperf.o: in function `main_func':
> refperf.c:(.text+0x57c): undefined reference to `__aeabi_uldivmod'
> 
> Work it by using div_u64 to mark the expensive operation.
> 
> Fixes: bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

Thanks.

> ---
>  kernel/rcu/refperf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/refperf.c b/kernel/rcu/refperf.c
> index 47df72c492b3..c2366648981d 100644
> --- a/kernel/rcu/refperf.c
> +++ b/kernel/rcu/refperf.c
> @@ -386,7 +386,7 @@ static int main_func(void *arg)
>  		if (torture_must_stop())
>  			goto end;
>  
> -		result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
> +		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
>  	}
>  
>  	// Print the average of all experiments
> @@ -397,9 +397,14 @@ static int main_func(void *arg)
>  	strcat(buf, "Threads\tTime(ns)\n");
>  
>  	for (exp = 0; exp < nruns; exp++) {
> +		u64 avg;
> +		u32 rem;
> +
>  		if (errexit)
>  			break;
> -		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> +
> +		avg = div_s64_rem(result_avg[exp], 1000, &rem);
> +		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
>  		strcat(buf, buf1);
>  	}
>  
> 


-- 
~Randy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-29 20:15 [PATCH] refperf: work around 64-bit division Arnd Bergmann
  2020-05-29 21:41 ` Paul E. McKenney
  2020-05-29 22:12 ` Randy Dunlap
@ 2020-05-30  3:52 ` Nathan Chancellor
  2020-05-30  8:01   ` Arnd Bergmann
  2 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2020-05-30  3:52 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul E. McKenney, Josh Triplett, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> A 64-bit division was introduced in refperf, breaking compilation
> on all 32-bit architectures:
> 
> kernel/rcu/refperf.o: in function `main_func':
> refperf.c:(.text+0x57c): undefined reference to `__aeabi_uldivmod'
> 
> Work it by using div_u64 to mark the expensive operation.
> 
> Fixes: bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  kernel/rcu/refperf.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/refperf.c b/kernel/rcu/refperf.c
> index 47df72c492b3..c2366648981d 100644
> --- a/kernel/rcu/refperf.c
> +++ b/kernel/rcu/refperf.c
> @@ -386,7 +386,7 @@ static int main_func(void *arg)
>  		if (torture_must_stop())
>  			goto end;
>  
> -		result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
> +		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
>  	}
>  
>  	// Print the average of all experiments
> @@ -397,9 +397,14 @@ static int main_func(void *arg)
>  	strcat(buf, "Threads\tTime(ns)\n");
>  
>  	for (exp = 0; exp < nruns; exp++) {
> +		u64 avg;
> +		u32 rem;
> +
>  		if (errexit)
>  			break;
> -		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> +
> +		avg = div_s64_rem(result_avg[exp], 1000, &rem);

Shouldn't this be div_u64_rem? result_avg is u64.

> +		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);

Would %03u be the better specifier since rem is u32?

>  		strcat(buf, buf1);
>  	}
>  
> -- 
> 2.26.2
> 

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-30  3:52 ` Nathan Chancellor
@ 2020-05-30  8:01   ` Arnd Bergmann
  2020-05-30 12:47     ` Paul E. McKenney
  2020-05-31 20:03     ` Paul E. McKenney
  0 siblings, 2 replies; 7+ messages in thread
From: Arnd Bergmann @ 2020-05-30  8:01 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Paul E. McKenney, Josh Triplett, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On Sat, May 30, 2020 at 5:52 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
> On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> >       strcat(buf, "Threads\tTime(ns)\n");
> >
> >       for (exp = 0; exp < nruns; exp++) {
> > +             u64 avg;
> > +             u32 rem;
> > +
> >               if (errexit)
> >                       break;
> > -             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> > +
> > +             avg = div_s64_rem(result_avg[exp], 1000, &rem);
>
> Shouldn't this be div_u64_rem? result_avg is u64.

Yes, you are right. Actually that would be an important optimization
since div_u64_rem() optimizes for constant divisors while div_s64_rem
uses the slow path.

> > +             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
>
> Would %03u be the better specifier since rem is u32?

Yes, though this makes no difference in practice.

Paul, should I send a fixup for these two, or do you prefer to just
edit it in place?

    Arnd

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-30  8:01   ` Arnd Bergmann
@ 2020-05-30 12:47     ` Paul E. McKenney
  2020-05-31 20:03     ` Paul E. McKenney
  1 sibling, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2020-05-30 12:47 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nathan Chancellor, Josh Triplett, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On Sat, May 30, 2020 at 10:01:36AM +0200, Arnd Bergmann wrote:
> On Sat, May 30, 2020 at 5:52 AM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> > On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> > >       strcat(buf, "Threads\tTime(ns)\n");
> > >
> > >       for (exp = 0; exp < nruns; exp++) {
> > > +             u64 avg;
> > > +             u32 rem;
> > > +
> > >               if (errexit)
> > >                       break;
> > > -             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> > > +
> > > +             avg = div_s64_rem(result_avg[exp], 1000, &rem);
> >
> > Shouldn't this be div_u64_rem? result_avg is u64.
> 
> Yes, you are right. Actually that would be an important optimization
> since div_u64_rem() optimizes for constant divisors while div_s64_rem
> uses the slow path.
> 
> > > +             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
> >
> > Would %03u be the better specifier since rem is u32?
> 
> Yes, though this makes no difference in practice.
> 
> Paul, should I send a fixup for these two, or do you prefer to just
> edit it in place?

I will apply it with Randy's Ack, thank you all!

							Thanx, Paul

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] refperf: work around 64-bit division
  2020-05-30  8:01   ` Arnd Bergmann
  2020-05-30 12:47     ` Paul E. McKenney
@ 2020-05-31 20:03     ` Paul E. McKenney
  1 sibling, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2020-05-31 20:03 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nathan Chancellor, Josh Triplett, Joel Fernandes (Google),
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Stephen Rothwell, rcu, linux-kernel

On Sat, May 30, 2020 at 10:01:36AM +0200, Arnd Bergmann wrote:
> On Sat, May 30, 2020 at 5:52 AM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> > On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> > >       strcat(buf, "Threads\tTime(ns)\n");
> > >
> > >       for (exp = 0; exp < nruns; exp++) {
> > > +             u64 avg;
> > > +             u32 rem;
> > > +
> > >               if (errexit)
> > >                       break;
> > > -             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> > > +
> > > +             avg = div_s64_rem(result_avg[exp], 1000, &rem);
> >
> > Shouldn't this be div_u64_rem? result_avg is u64.
> 
> Yes, you are right. Actually that would be an important optimization
> since div_u64_rem() optimizes for constant divisors while div_s64_rem
> uses the slow path.
> 
> > > +             sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
> >
> > Would %03u be the better specifier since rem is u32?
> 
> Yes, though this makes no difference in practice.
> 
> Paul, should I send a fixup for these two, or do you prefer to just
> edit it in place?

And here is the update, thank you all!

							Thanx, Paul

------------------------------------------------------------------------

commit 0dd4132157c2cf6bec2a0a6e04163067323abdb1
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Fri May 29 14:36:26 2020 -0700

    refperf: Work around 64-bit division
    
    A 64-bit division was introduced in refperf, breaking compilation
    on all 32-bit architectures:
    
    kernel/rcu/refperf.o: in function `main_func':
    refperf.c:(.text+0x57c): undefined reference to `__aeabi_uldivmod'
    
    Fix this by using div_u64 to mark the expensive operation.
    
    [ paulmck: Update primitive and format per Nathan Chancellor. ]
    Fixes: bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
    Reported-by: kbuild test robot <lkp@intel.com>
    Reported-by: Valdis Klētnieks <valdis.kletnieks@vt.edu>
    Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

diff --git a/kernel/rcu/refperf.c b/kernel/rcu/refperf.c
index 99434e7..3b72925 100644
--- a/kernel/rcu/refperf.c
+++ b/kernel/rcu/refperf.c
@@ -478,7 +478,7 @@ static int main_func(void *arg)
 		if (torture_must_stop())
 			goto end;
 
-		result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
+		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
 	}
 
 	// Print the average of all experiments
@@ -489,9 +489,13 @@ static int main_func(void *arg)
 	strcat(buf, "Runs\tTime(ns)\n");
 
 	for (exp = 0; exp < nruns; exp++) {
+		u64 avg;
+		u32 rem;
+
 		if (errexit)
 			break;
-		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
+		avg = div_u64_rem(result_avg[exp], 1000, &rem);
+		sprintf(buf1, "%d\t%llu.%03u\n", exp + 1, avg, rem);
 		strcat(buf, buf1);
 	}
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-31 20:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 20:15 [PATCH] refperf: work around 64-bit division Arnd Bergmann
2020-05-29 21:41 ` Paul E. McKenney
2020-05-29 22:12 ` Randy Dunlap
2020-05-30  3:52 ` Nathan Chancellor
2020-05-30  8:01   ` Arnd Bergmann
2020-05-30 12:47     ` Paul E. McKenney
2020-05-31 20:03     ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).