From 2afd826bf6cd19900aee70ae14ede92d91b6f4c0 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 14 Dec 2009 23:08:42 +0100 Subject: [PATCH] Support for Mac OS 10.6.2 Contributed by Small Tree, adopted to newer fio version by me. Signed-off-by: Jens Axboe --- Makefile.mac | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/arch.h | 2 +- helpers.c | 13 ++++++++++ helpers.h | 1 + os/os-mac.h | 52 +++++++++++++++++++++++++++++++++++++ os/os.h | 2 ++ 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 Makefile.mac create mode 100644 os/os-mac.h diff --git a/Makefile.mac b/Makefile.mac new file mode 100644 index 00000000..7574f00c --- /dev/null +++ b/Makefile.mac @@ -0,0 +1,73 @@ +CC = gcc +DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG +OPTFLAGS= -O2 -g $(EXTFLAGS) +CFLAGS = -Wwrite-strings -Wall -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(DEBUGFLAGS) -rdynamic -arch i386 -arch x86_64 -arch ppc +PROGS = fio +SCRIPTS = fio_generate_plots +OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \ + eta.o verify.o memory.o io_u.o parse.o mutex.o options.o \ + rbtree.o smalloc.o filehash.o helpers.o + +OBJS += crc/crc7.o +OBJS += crc/crc16.o +OBJS += crc/crc32.o +OBJS += crc/crc32c.o +OBJS += crc/crc32c-intel.o +OBJS += crc/crc64.o +OBJS += crc/sha256.o +OBJS += crc/sha512.o +OBJS += crc/md5.o + +OBJS += engines/cpu.o +OBJS += engines/mmap.o +OBJS += engines/posixaio.o +OBJS += engines/sync.o +OBJS += engines/null.o +OBJS += engines/net.o + +SOURCE = eta.c filehash.c filesetup.c fio.c gettime.c init.c ioengines.c \ + io_u.c log.c memory.c mutex.c options.c parse.c rbtree.c smalloc.c \ + stat.c parse.c crc/*.c engines/cpu.c engines/mmap.c \ + engines/posixaio.c engines/sync.c engines/null.c engines/net.c \ + *.h */*.h + +ifneq ($(findstring $(MAKEFLAGS),s),s) +ifndef V + QUIET_CC = @echo ' ' CC $@; + QUIET_DEP = @echo ' ' DEP $@; +endif +endif + +INSTALL = install +prefix = /usr/local +bindir = $(prefix)/bin +mandir = $(prefix)/man + +%.o: %.c + $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< +fio: $(OBJS) + $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $(filter %.o,$^) $(EXTLIBS) -lpthread -lm + +depend: + $(QUIET_DEP)$(CC) -MM $(ALL_CFLAGS) $(SOURCE) 1> .depend + +$(PROGS): depend + +all: depend $(PROGS) $(SCRIPTS) + +clean: + -rm -f .depend cscope.out $(OBJS) $(PROGS) core.* core + +cscope: + @cscope -b + +install: $(PROGS) $(SCRIPTS) + $(INSTALL) -m755 -d $(DESTDIR)$(bindir) + $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir) + $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1 + $(INSTALL) -m 644 fio.1 $(DESTDIR)$(mandir)/man1 + $(INSTALL) -m 644 fio_generate_plots.1 $(DESTDIR)$(mandir)/man1 + +ifneq ($(wildcard .depend),) +include .depend +endif diff --git a/arch/arch.h b/arch/arch.h index 64593748..9f2a566e 100644 --- a/arch/arch.h +++ b/arch/arch.h @@ -23,7 +23,7 @@ enum { #include "arch-x86.h" #elif defined(__x86_64__) #include "arch-x86_64.h" -#elif defined(__powerpc__) || defined(__powerpc64__) +#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) #include "arch-ppc.h" #elif defined(__ia64__) #include "arch-ia64.h" diff --git a/helpers.c b/helpers.c index f314ebb9..9c76d305 100644 --- a/helpers.c +++ b/helpers.c @@ -24,3 +24,16 @@ int __weak inet_aton(const char *cp, struct in_addr *inp) { return 0; } + +int __weak clock_gettime(clockid_t clk_id, struct timespec *ts) +{ + struct timeval tv; + int ret; + + ret = gettimeofday(&tv, NULL); + + ts->ts_sec = tv.tv_sec; + ts->ts_nsec = tv.tv_usec * 1000; + + return ret; +} diff --git a/helpers.h b/helpers.h index a3a773bc..61a3f2b2 100644 --- a/helpers.h +++ b/helpers.h @@ -6,5 +6,6 @@ struct in_addr; extern int __weak posix_memalign(void **ptr, size_t align, size_t size); extern int __weak posix_fallocate(int fd, off_t offset, off_t len); extern int __weak inet_aton(const char *cp, struct in_addr *inp); +extern int __weak clock_gettime(clockid_t clk_id, struct timespec *ts); #endif diff --git a/os/os-mac.h b/os/os-mac.h new file mode 100644 index 00000000..77c21656 --- /dev/null +++ b/os/os-mac.h @@ -0,0 +1,52 @@ +#ifndef FIO_OS_APPLE_H +#define FIO_OS_APPLE_H + +#include +#include + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 1 +#endif + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 1 +#endif + +#define FIO_HAVE_POSIXAIO +#define FIO_USE_GENERIC_BDEV_SIZE + +#define OS_MAP_ANON MAP_ANON + +typedef unsigned long os_cpu_mask_t; +typedef unsigned int os_random_state_t; +typedef unsigned int clockid_t; + +static inline int blockdev_invalidate_cache(int fd) +{ + return EINVAL; +} + +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; +} + +static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) +{ + srand(seed); +} + +static inline long os_random_long(os_random_state_t *rs) +{ + long val; + + val = rand_r(rs); + return val; +} + +#endif diff --git a/os/os.h b/os/os.h index 1afb4b22..bed12814 100644 --- a/os/os.h +++ b/os/os.h @@ -7,6 +7,8 @@ #include "os-freebsd.h" #elif defined(__sun__) #include "os-solaris.h" +#elif defined(__APPLE__) +#include "os-mac.h" #else #error "unsupported os" #endif -- 2.25.1