[PATCH] Get closer to FreeBSD compile
authorJens Axboe <axboe@suse.de>
Wed, 7 Jun 2006 11:40:40 +0000 (13:40 +0200)
committerJens Axboe <axboe@suse.de>
Wed, 7 Jun 2006 11:40:40 +0000 (13:40 +0200)
Makefile.FreeBSD [new file with mode: 0644]
fio.c
os-freebsd.h
os-linux.h

diff --git a/Makefile.FreeBSD b/Makefile.FreeBSD
new file mode 100644 (file)
index 0000000..a223289
--- /dev/null
@@ -0,0 +1,26 @@
+CC     = gcc
+CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+PROGS  = fio
+SCRIPTS = fio_generate_plots
+
+all: depend $(PROGS) $(SCRIPTS)
+
+fio: fio.o ioengines.o init.o stat.o log.o time.o md5.o crc32.o
+       $(CC) $(CFLAGS) -o $@ $(filter %.o,$^) -lpthread -laio -lm -lrt
+
+clean:
+       -rm -f *.o .depend cscope.out $(PROGS)
+
+depend:
+       @$(CC) -MM $(ALL_CFLAGS) *.c 1> .depend
+
+cscope:
+       @cscope -b
+
+INSTALL = install
+prefix = /usr/local
+bindir = $(prefix)/bin
+
+install: $(PROGS) $(SCRIPTS)
+       $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
+       $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
diff --git a/fio.c b/fio.c
index 241e64e6cee1c0f3e018357933f2447d3daf2443..1e94cc6fe984515cb026e52a0a4d8fd40bfe221e 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -737,6 +737,10 @@ static void do_verify(struct thread_data *td)
        td_set_runstate(td, TD_RUNNING);
 }
 
+/*
+ * Main IO worker functions. It retrieves io_u's to process and queues
+ * and reaps them, checking for rate and errors along the way.
+ */
 static void do_io(struct thread_data *td)
 {
        struct io_completion_data icd;
@@ -1670,7 +1674,7 @@ static void fio_unpin_memory(void *pinned)
 
 static void *fio_pin_memory(void)
 {
-       long pagesize, pages;
+       unsigned long long phys_mem;
        void *ptr;
 
        if (!mlock_size)
@@ -1679,13 +1683,10 @@ static void *fio_pin_memory(void)
        /*
         * Don't allow mlock of more than real_mem-128MB
         */
-       pagesize = sysconf(_SC_PAGESIZE);
-       pages = sysconf(_SC_PHYS_PAGES);
-       if (pages != -1 && pagesize != -1) {
-               unsigned long long real_mem = pages * pagesize;
-
-               if ((mlock_size + 128 * 1024 * 1024) > real_mem) {
-                       mlock_size = real_mem - 128 * 1024 * 1024;
+       phys_mem = os_phys_mem();
+       if (phys_mem) {
+               if ((mlock_size + 128 * 1024 * 1024) > phys_mem) {
+                       mlock_size = phys_mem - 128 * 1024 * 1024;
                        printf("fio: limiting mlocked memory to %lluMiB\n",
                                                        mlock_size >> 20);
                }
index bd6d6d0ec9d5185cc062f3b896e2d8136da0c217..31fa01071aaf283410a4059bcd40cdb670cd8268 100644 (file)
@@ -20,4 +20,14 @@ static inline int blockdev_size(int fd, unsigned long long *bytes)
        return 1;
 }
 
+static inline unsigned long long os_phys_mem(void)
+{
+       int mib[2] = { CTL_HW, HW_PHYSMEM };
+       unsigned long long mem;
+       size_t len = sizeof(mem);
+
+       sysctl(mib, 2, &mem, &len, NULL, 0);
+       return mem;
+}
+
 #endif
index 421baffb25342458d4005111a8cf804156853724..f2df97d3bf2588f7dc1dae447ed27988097a2078 100644 (file)
@@ -87,4 +87,16 @@ static inline int blockdev_size(int fd, unsigned long long *bytes)
        return errno;
 }
 
+static inline unsigned long long os_phys_mem(void)
+{
+       long pagesize, pages;
+
+       pagesize = sysconf(_SC_PAGESIZE);
+       pages = sysconf(_SC_PHYS_PAGES);
+       if (pages == -1 || pagesize == -1)
+               return 0;
+
+       return (unsigned long long) pages * (unsigned long long) pagesize;
+}
+
 #endif