From 9c01ceb5769ff67cc26f4d133c059246d53c5089 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Mon, 4 Jul 2011 02:51:12 +0200 Subject: [PATCH] introduce sqrt_approx() in -lsys . use this to avoid -lm dependency in mfs --- common/include/minix/sysutil.h | 1 + lib/libsys/Makefile | 2 ++ lib/libsys/sqrt_approx.c | 14 ++++++++++++++ servers/mfs/Makefile | 2 +- servers/mfs/cache.c | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 lib/libsys/sqrt_approx.c diff --git a/common/include/minix/sysutil.h b/common/include/minix/sysutil.h index 67dc218ab..c40e89189 100644 --- a/common/include/minix/sysutil.h +++ b/common/include/minix/sysutil.h @@ -65,6 +65,7 @@ _PROTOTYPE( u32_t tsc_get_khz, (void)); _PROTOTYPE( u32_t micros_to_ticks, (u32_t micros)); _PROTOTYPE( void ser_putc, (char c)); _PROTOTYPE( void get_randomness, (struct k_randomness *, int)); +_PROTOTYPE( u32_t sqrt_approx, (u32_t)); #define asynsend(ep, msg) asynsend3(ep, msg, 0) _PROTOTYPE( int asynsend3, (endpoint_t ep, message *msg, int flags)); diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index 069c3ae54..f5bdc73bc 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -57,6 +57,7 @@ SRCS= \ sef_signal.c \ ser_putc.c \ spin.c \ + sqrt_approx.c \ stacktrace.c \ sys_abort.c \ sys_clear.c \ @@ -127,6 +128,7 @@ SRCS= \ vm_yield_get_block.c \ vprintf.c \ + CPPFLAGS.sched_start.c+= -I${MINIXSRCDIR} .if (${NBSD_LIBC} != "no") diff --git a/lib/libsys/sqrt_approx.c b/lib/libsys/sqrt_approx.c new file mode 100644 index 000000000..07eeaec4f --- /dev/null +++ b/lib/libsys/sqrt_approx.c @@ -0,0 +1,14 @@ +#include + +u32_t sqrt_approx(u32_t in) +{ + int b, v = 0; + for(b = (sizeof(in)*8)/2-1; b >= 0; b--) { + u32_t n = v | (1UL << b); + if(n*n <= in) + v = n; + } + + return v; +} + diff --git a/servers/mfs/Makefile b/servers/mfs/Makefile index e893c37b5..3730c4400 100644 --- a/servers/mfs/Makefile +++ b/servers/mfs/Makefile @@ -6,7 +6,7 @@ SRCS= cache.c device.c link.c \ write.c inode.c main.c path.c super.c DPADD+= ${LIBM} ${LIBSYS} -LDADD+= -lm -lsys +LDADD+= -lsys MAN= diff --git a/servers/mfs/cache.c b/servers/mfs/cache.c index 2833f94dd..7ff36d0a4 100644 --- a/servers/mfs/cache.c +++ b/servers/mfs/cache.c @@ -601,7 +601,7 @@ PRIVATE int bufs_heuristic(struct super_block *sp) /* heuristic for a desired cache size based on FS usage; * but never bigger than half of the total filesystem */ - kb_fsmax = sqrt(kbytes_used_fs)*40; + kb_fsmax = sqrt_approx(kbytes_used_fs)*40; kb_fsmax = MIN(kb_fsmax, kbytes_total_fs/2); /* heuristic for a maximum usage - 10% of remaining memory */ -- 2.44.0