Skip to contentSkip to conversation

kernel: Replace timeconst.pl with a bc script

RFC PATCH In review H. Peter Anvin 3 participants 8 messages Feb 14, 2013 – Feb 16, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 kernel: Replace timeconst.pl with a bc script

From: "H. Peter Anvin" <[email protected]>

bc is the standard tool for multi-precision arithmetic. We switched to Perl because akpm reported a hard-to-reproduce build hang, which was very odd because affected and unaffected machines were all running the same version of GNU bc.

Unfortunately switching to Perl required a really ugly "canning" mechanism to support Perl < 5.8 installations lacking the Math::BigInt module.

It was recently pointed out to me that some very old versions of GNU make had problems with pipes in subshells, which was indeed the construct used in the Makefile rules in that version of the patch; Perl didn't need it so switching to Perl fixed the problem for unrelated reasons. With the problem (hopefully) root-caused, we can switch back to bc and do the arbitrary-precision arithmetic naturally.

Cc Andrew Morton <[email protected]>
Cc Michal Marek <[email protected]>
Cc Sam Ravnborg <[email protected]>
---
 kernel/Makefile     |  16 ++-
 kernel/timeconst.bc | 108 +++++++++++++++
 kernel/timeconst.pl | 376 ----------------------------------------------------
 3 files changed, 120 insertions(+), 380 deletions(-)
 create mode 100644 kernel/timeconst.bc
 delete mode 100644 kernel/timeconst.pl

Comments appreciated; including the preferred way to merge this.

kernel/Makefile +12 -4
index 86e3285..be55a34 100644
@@ -126,11 +126,19 @@ $(obj)/config_data.h: $(obj)/config_data.gz FORCE
 
 $(obj)/time.o: $(obj)/timeconst.h
 
-quiet_cmd_timeconst  = TIMEC   $@
-      cmd_timeconst  = $(PERL) $< $(CONFIG_HZ) > $@
+quiet_cmd_hzfile = HZFILE  $@
+      cmd_hzfile = echo "hz=$(CONFIG_HZ)" > $@
+
+targets += hz.bc
+$(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE
+	$(call if_changed,hzfile)
+
+quiet_cmd_bc  = BC      $@
+      cmd_bc  = bc -q $(filter-out FORCE,$^) > $@
+
 targets += timeconst.h
-$(obj)/timeconst.h: $(src)/timeconst.pl FORCE
-	$(call if_changed,timeconst)
+$(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE
+	$(call if_changed,bc)
 
 ifeq ($(CONFIG_MODULE_SIG),y)
 #
kernel/timeconst.bc new file +108 -0

108 lines not on this page · raw message

kernel/timeconst.pl deleted +0 -376

376 lines not on this page · raw message

Signature · 1 line
1.7.11.7
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · H. Peter Anvin

From: "H. Peter Anvin" <[email protected]>

bc is the standard tool for multi-precision arithmetic. We switched to Perl because akpm reported a hard-to-reproduce build hang, which was very odd because affected and unaffected machines were all running the same version of GNU bc.

Unfortunately switching to Perl required a really ugly "canning" mechanism to support Perl < 5.8 installations lacking the Math::BigInt module.

It was recently pointed out to me that some very old versions of GNU make had problems with pipes in subshells, which was indeed the construct used in the Makefile rules in that version of the patch; Perl didn't need it so switching to Perl fixed the problem for unrelated reasons. With the problem (hopefully) root-caused, we can switch back to bc and do the arbitrary-precision arithmetic naturally.

Quoted 4 lines
Cc Andrew Morton <[email protected]>
Cc Michal Marek <[email protected]>
Cc Sam Ravnborg <[email protected]>

The kbuild stuff looks fine. The bc stuff I do not know about.

Acked-by on v1 1/1
#2 lore raw
In reply to H. Peter Anvin

Dne 15.2.2013 00:13, H. Peter Anvin napsal(a):

Quoted 3 lines

Unfortunately switching to Perl required a really ugly "canning" mechanism to support Perl < 5.8 installations lacking the Math::BigInt module.

Yes, this was really ugly.

Quoted 6 lines

It was recently pointed out to me that some very old versions of GNU make had problems with pipes in subshells, which was indeed the construct used in the Makefile rules in that version of the patch; Perl didn't need it so switching to Perl fixed the problem for unrelated reasons. With the problem (hopefully) root-caused, we can switch back to bc and do the arbitrary-precision arithmetic naturally.

Great.

Quoted 13 lines
Cc Andrew Morton <[email protected]>
Cc Michal Marek <[email protected]>
Cc Sam Ravnborg <[email protected]>
---
 kernel/Makefile     |  16 ++-
 kernel/timeconst.bc | 108 +++++++++++++++
 kernel/timeconst.pl | 376 ----------------------------------------------------
 3 files changed, 120 insertions(+), 380 deletions(-)
 create mode 100644 kernel/timeconst.bc
 delete mode 100644 kernel/timeconst.pl
Quoted 1 line

Comments appreciated; including the preferred way to merge this.

I can merge it into the kbuild tree if wanted. I only have one nipick:

kernel/timeconst.bc line 16

Quoted 4 lines
kernel/timeconst.bc new file +4 -0
+/* Division by reciprocal multiplication. */
+define fmul(b,n,d) {
+       return (2^b*n+d-1)/d;
+}

For readability reasons, I suggest to use the same formatting of expressions and argument lists like in C:

define fmul(b, n, d) {
       return (2^b * n + d - 1) / d;
}

Otherwise, you can add

Michal

#3 lore raw
Quoted 10 lines · Michal Marek

I can merge it into the kbuild tree if wanted. I only have one nipick:

kernel/timeconst.bc line 16

Quoted 4 lines
kernel/timeconst.bc new file +4 -0
+/* Division by reciprocal multiplication. */
+define fmul(b,n,d) {
+       return (2^b*n+d-1)/d;
+}

For readability reasons, I suggest to use the same formatting of expressions and argument lists like in C:

Quoted 6 lines
define fmul(b, n, d) {
        return (2^b * n + d - 1) / d;
}

Otherwise, you can add

Do you actually think that is more readable? Personally, I think it made it harder to read just because it takes up more space than one can quickly glance at.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw

Dne 16.2.2013 00:44, H. Peter Anvin napsal(a):

Quoted 15 lines · Michal Marek
Quoted 14 lines

I can merge it into the kbuild tree if wanted. I only have one nipick:

kernel/timeconst.bc line 16

Quoted 4 lines
kernel/timeconst.bc new file +4 -0
+/* Division by reciprocal multiplication. */
+define fmul(b,n,d) {
+       return (2^b*n+d-1)/d;
+}

For readability reasons, I suggest to use the same formatting of expressions and argument lists like in C:

define fmul(b, n, d) {
        return (2^b * n + d - 1) / d;
}
Quoted 6 lines
Quoted 2 lines

Otherwise, you can add

Do you actually think that is more readable? Personally, I think it made it harder to read just because it takes up more space than one can quickly glance at.

I personally find the wider version more readable, but I don't care that much.

Michal

#5 lore raw
Quoted 8 lines · Michal Marek
Quoted 4 lines

Do you actually think that is more readable? Personally, I think it made it harder to read just because it takes up more space than one can quickly glance at.

I personally find the wider version more readable, but I don't care that much.

Either way... if you could pick the patch up with or without extra space that would be great.

-hpa

#6 lore raw

Dne 16.2.2013 23:10, H. Peter Anvin napsal(a):

Quoted 6 lines · Michal Marek
Quoted 5 lines
Quoted 4 lines

Do you actually think that is more readable? Personally, I think it made it harder to read just because it takes up more space than one can quickly glance at.

Quoted 6 lines
Quoted 3 lines

I personally find the wider version more readable, but I don't care that much.

Either way... if you could pick the patch up with or without extra space that would be great.

Done.

Michal

#7 lore raw
In reply to Michal Marek
Quoted 3 lines · Michal Marek

I can merge it into the kbuild tree if wanted.

That probably makes most sense.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.