Skip to contentSkip to conversation

refperf: work around 64-bit division

PATCH In review Arnd Bergmann 4 participants 7 messages May 29, 2020 – May 31, 2020 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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'

Work it by using div_u64 to mark the expensive operation.

Fixes bd5b16d6c88d ("refperf: Allow decimal nanoseconds")
---
 kernel/rcu/refperf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/refperf.c +7 -2
index 47df72c492b3..c2366648981d 100644
@@ -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);
 	}
 
Signature · 1 line
2.26.2
maintainer
#1 lore raw
Quoted 10 lines · Arnd Bergmann

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")

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

Quoted 36 lines
---
 kernel/rcu/refperf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/refperf.c +7 -2
index 47df72c492b3..c2366648981d 100644
@@ -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);
 	}
 
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

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")

Thanks.

Quoted 34 lines
---
 kernel/rcu/refperf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/refperf.c +7 -2
index 47df72c492b3..c2366648981d 100644
@@ -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);
 	}
 
Signature · 1 line
~Randy
#3 lore raw
In reply to Arnd Bergmann
Quoted 29 lines · Arnd Bergmann

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")
---
 kernel/rcu/refperf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/refperf.c +1 -1
index 47df72c492b3..c2366648981d 100644
@@ -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");

kernel/rcu/refperf.c static int main_func(void *arg) · line 406

Quoted 10 lines
kernel/rcu/refperf.c +5 -1
 
 	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.

kernel/rcu/refperf.c static int main_func(void *arg) · line 407

Quoted 1 line
kernel/rcu/refperf.c +1 -0
+		sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);

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

Quoted 6 lines
kernel/rcu/refperf.c +0 -0
 		strcat(buf, buf1);
 	}
 
Signature · 1 line
2.26.2

Cheers,
Nathan

#4 lore raw
Quoted 14 lines · Nathan Chancellor

kernel/rcu/refperf.c static int main_func(void *arg) · line 406

Quoted 11 lines · Arnd Bergmann
      strcat(buf, "Threads\tTime(ns)\n");

      for (exp = 0; exp < nruns; exp++) {
kernel/rcu/refperf.c +5 -1
+             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.

Quoted 3 lines
Quoted 1 line

+ 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

maintainer
#5 lore raw
Quoted 21 lines · Arnd Bergmann
Quoted 14 lines · Nathan Chancellor

kernel/rcu/refperf.c static int main_func(void *arg) · line 406

Quoted 11 lines · Arnd Bergmann
      strcat(buf, "Threads\tTime(ns)\n");

      for (exp = 0; exp < nruns; exp++) {
kernel/rcu/refperf.c +5 -1
+             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.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+ 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

maintainer Acked-by Randy Dunlap
#6 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann
Quoted 14 lines · Nathan Chancellor

Review

Quoted 11 lines · Arnd Bergmann
      strcat(buf, "Threads\tTime(ns)\n");

      for (exp = 0; exp < nruns; exp++) {
(quoted diff) +5 -1
+             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.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+ 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 <[email protected]>
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")
kernel/rcu/refperf.c +6 -2
index 99434e7..3b72925 100644
@@ -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);
 	}