Submitted By: Igor Živković Date: 2014-07-26 Initial Package Version: 3.15.6 Upstream Status: Unknown Origin: sabotage Description: Replaces timeconst.bc with the C version thus removing dependency on bc. --- linux-3.17.orig/kernel/time/Makefile +++ linux-3.17/kernel/time/Makefile @@ -17,17 +17,11 @@ $(obj)/time.o: $(obj)/timeconst.h -quiet_cmd_hzfile = HZFILE $@ - cmd_hzfile = echo "hz=$(CONFIG_HZ)" > $@ +hostprogs-y += mktimeconst +quiet_cmd_mktimeconst = TIMEC $@ + cmd_mktimeconst = $(obj)/mktimeconst $(CONFIG_HZ) $@ || ( rm -f $@ && exit 1 ) -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: $(obj)/hz.bc $(src)/timeconst.bc FORCE - $(call if_changed,bc) +$(obj)/timeconst.h: $(obj)/mktimeconst FORCE + $(call if_changed,mktimeconst) --- /dev/null +++ linux-3.17/kernel/time/mktimeconst.c @@ -0,0 +1,110 @@ +/* Copyright 2010 Parallels Inc, licensed under GPLv2 */ +/* Copyright 2010-2013 Rob Landley */ + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + uint64_t hz, periods[] = {1000, 1000000}; + char *names[] = {"MSEC", "USEC"}; + FILE *file; + int i, j; + + if (argc != 3 || (hz = atol(argv[1])) < 1 + || !(file = fopen(argv[2], "w"))) + { + fprintf(stderr, "Usage: mktimeconst HZ FILENAME\n\n"); + fprintf(stderr, "Generate a header file with constants to convert between\n"); + fprintf(stderr, "decimal HZ timer ticks and milisecond or microsecond delays,\n"); + fprintf(stderr, "using reciprocal multiplication to avoid 64 bit division.\n"); + exit(1); + } + + fprintf(file, + "/* Automatically generated by kernel/mktimeconst */\n" + "/* Conversion constants for HZ == %"PRIu64" */\n\n" + "#ifndef __KERNEL_TIMECONST_H\n" + "#define __KERNEL_TIMECONST_H\n\n" + "#include \n" + "#include \n\n" + "#if HZ != %"PRIu64"\n" + "#error \"kernel/timeconst.h has the wrong HZ value!\"\n" + "#endif\n\n", hz, hz); + + /* Repeat for MSEC and USEC */ + + for (i = 0; i < 2; i++) { + uint64_t gcd, period; + + /* Find greatest common denominator using Euclid's algorithm. */ + + gcd = hz; + period = periods[i]; + while (period) { + uint64_t temp = gcd % period; + gcd = period; + period = temp; + } + + /* Output both directions (HZ_TO_PERIOD and PERIOD_TO_HZ) */ + + for (j = 0; j < 2; j++) { + char name[16]; + uint64_t from = j ? periods[i] : hz; + uint64_t to = j ? hz : periods[i]; + uint64_t mul32 = 0, adj32 = 0, shift = 0; + + sprintf(name, j ? "%s_TO_HZ" : "HZ_TO_%s", names[i]); + + /* Figure out what shift value gives 32 significant + bits of MUL32 data. (Worst case to=1 from=1000000 + uses 52 bits, to<= (1UL<<31)) + break; + shift++; + } + + /* ADJ32 is is just (((FROM/GCD)-1)< 32) { + uint64_t upper, lower; + + upper = (adj32 - 1) << (shift - 32); + lower = (upper % adj32) << 32; + adj32 = ((upper/adj32) << 32) + (lower/adj32); + } else + adj32 = ((adj32 - 1) << shift) / adj32; + + /* Emit the constants into the header file. */ + + fprintf(file, "#define %s_MUL32\tU64_C(0x%"PRIx64")\n", + name, mul32); + fprintf(file, "#define %s_ADJ32\tU64_C(0x%"PRIx64")\n", + name, adj32); + fprintf(file, "#define %s_SHR32\t%"PRIu64"\n", + name, shift); + fprintf(file, "#define %s_NUM\t\tU64_C(%"PRIu64")\n", + name, to/gcd); + fprintf(file, "#define %s_DEN\t\tU64_C(%"PRIu64")\n\n", + name, from/gcd); + } + } + fprintf(file, "#endif /* __KERNEL_TIMECONST_H */\n"); + + /* Notice if the disk fills up. */ + + fflush(stdout); + return ferror(stdout); +}