]> Zhao Yanbai Git Server - minix.git/commitdiff
introduce sqrt_approx() in -lsys
authorBen Gras <ben@minix3.org>
Mon, 4 Jul 2011 00:51:12 +0000 (02:51 +0200)
committerBen Gras <ben@minix3.org>
Mon, 4 Jul 2011 00:51:12 +0000 (02:51 +0200)
  . use this to avoid -lm dependency in mfs

common/include/minix/sysutil.h
lib/libsys/Makefile
lib/libsys/sqrt_approx.c [new file with mode: 0644]
servers/mfs/Makefile
servers/mfs/cache.c

index 67dc218ab08754faec12f3c7f4f5ebf09171ac5f..c40e891890b669c5cdfb700922aa5cbf547cd503 100644 (file)
@@ -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));
index 069c3ae546e7f7593e22d1e357125b7dde7ff86d..f5bdc73bc77ec353af4e5958c6f9c7f8305458a3 100644 (file)
@@ -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 (file)
index 0000000..07eeaec
--- /dev/null
@@ -0,0 +1,14 @@
+#include <minix/sysutil.h>
+
+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;
+}
+
index e893c37b5caa4bb1bea3381f490bf044097dc7fc..3730c4400f65e4ab1d7433f73e5e58caecc5a862 100644 (file)
@@ -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=
 
index 2833f94dd20e4cbf716f9672a2670183c99e8343..7ff36d0a470c8d222f2d989b2b7d900a9f43091d 100644 (file)
@@ -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 */