From 32cd46a085ac60f4f8b085e2d65ebfc6100bb8c5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 7 Jun 2006 13:40:40 +0200 Subject: [PATCH] [PATCH] Get closer to FreeBSD compile --- Makefile.FreeBSD | 26 ++++++++++++++++++++++++++ fio.c | 17 +++++++++-------- os-freebsd.h | 10 ++++++++++ os-linux.h | 12 ++++++++++++ 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 Makefile.FreeBSD diff --git a/Makefile.FreeBSD b/Makefile.FreeBSD new file mode 100644 index 00000000..a2232890 --- /dev/null +++ b/Makefile.FreeBSD @@ -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 241e64e6..1e94cc6f 100644 --- 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); } diff --git a/os-freebsd.h b/os-freebsd.h index bd6d6d0e..31fa0107 100644 --- a/os-freebsd.h +++ b/os-freebsd.h @@ -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 diff --git a/os-linux.h b/os-linux.h index 421baffb..f2df97d3 100644 --- a/os-linux.h +++ b/os-linux.h @@ -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 -- 2.25.1