Initial HP-UX port

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
diff --git a/Makefile b/Makefile
index b609deb..dade0ae 100644
--- a/Makefile
+++ b/Makefile
@@ -13,45 +13,49 @@
 		eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
 		rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
 		lib/num2str.c $(wildcard crc/*.c) engines/cpu.c \
-		engines/mmap.c engines/sync.c engines/null.c engines/net.c \
-		memalign.c
+		engines/mmap.c engines/sync.c engines/null.c memalign.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
 		engines/libaio.c engines/posixaio.c engines/sg.c \
 		engines/splice.c engines/syslet-rw.c engines/guasi.c \
-		engines/binject.c profiles/tiobench.c
+		engines/binject.c profiles/tiobench.c engines/net.c
   LIBS += -lpthread -ldl -lrt -laio
   CFLAGS += -rdynamic
 endif
 ifeq ($(UNAME), SunOS)
   SOURCE += fifo.c lib/strsep.c helpers.c engines/posixaio.c \
-		engines/solarisaio.c
+		engines/solarisaio.c engines/net.c
   LIBS	 += -lpthread -ldl -laio -lrt -lnsl -lsocket
   CPPFLAGS += -D__EXTENSIONS__
 endif
 ifeq ($(UNAME), FreeBSD)
-  SOURCE += helpers.c engines/posixaio.c
+  SOURCE += helpers.c engines/posixaio.c engines/net.c
   LIBS	 += -lpthread -lrt
   CFLAGS += -rdynamic
 endif
 ifeq ($(UNAME), NetBSD)
-  SOURCE += helpers.c engines/posixaio.c
+  SOURCE += helpers.c engines/posixaio.c engines/net.c
   LIBS	 += -lpthread -lrt
   CFLAGS += -rdynamic
 endif
 ifeq ($(UNAME), AIX)
-  SOURCE += fifo.c helpers.c lib/getopt_long.c engines/posixaio.c
+  SOURCE += fifo.c helpers.c lib/getopt_long.c engines/posixaio.c engines/net.c
   LIBS	 += -lpthread -ldl -lrt
   CFLAGS += -rdynamic
   CPPFLAGS += -D_LARGE_FILES -D__ppc__
 endif
+ifeq ($(UNAME), HP-UX)
+  SOURCE += fifo.c helpers.c lib/getopt_long.c lib/strsep.c
+  LIBS   += -lpthread -dl -lrt
+  CPPFLAGS += -D_LARGE_FILES
+endif
 ifeq ($(UNAME), Darwin)
-  SOURCE += helpers.c engines/posixaio.c
+  SOURCE += helpers.c engines/posixaio.c engines/net.c
   LIBS	 += -lpthread -ldl
 endif
 ifneq (,$(findstring CYGWIN,$(UNAME)))
-  SOURCE += engines/windowsaio.c
+  SOURCE += engines/windowsaio.c engines/net.c
   LIBS	 += -lpthread -lrt
 endif
 
diff --git a/lib/getopt.h b/lib/getopt.h
index 56fe3bf..0dd4608 100644
--- a/lib/getopt.h
+++ b/lib/getopt.h
@@ -1,4 +1,5 @@
 #ifndef _AIX
+#ifndef __hpux
 
 #include <getopt.h>
 
@@ -23,4 +24,5 @@
 int getopt_long_only(int, char *const *, const char *, const struct option *, int *);
 
 #endif /* _GETOPT_H */
+#endif /* __hpux */
 #endif /* _AIX */
diff --git a/options.c b/options.c
index bd7dc99..f1c0ea7 100644
--- a/options.c
+++ b/options.c
@@ -329,7 +329,7 @@
 		return 1;
 	}
 
-	max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
+	max_cpu = cpus_online();
 
 	for (i = 0; i < sizeof(int) * 8; i++) {
 		if ((1 << i) & *val) {
@@ -366,7 +366,7 @@
 	strip_blank_front(&str);
 	strip_blank_end(str);
 
-	max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
+	max_cpu = cpus_online();
 
 	while ((cpu = strsep(&str, ",")) != NULL) {
 		char *str2, *cpu2;
@@ -2095,7 +2095,7 @@
 	sprintf(buf, "%llu", mb_memory);
 	fio_keywords[1].replace = strdup(buf);
 
-	l = sysconf(_SC_NPROCESSORS_ONLN);
+	l = cpus_online();
 	sprintf(buf, "%lu", l);
 	fio_keywords[2].replace = strdup(buf);
 }
diff --git a/os/os-hpux.h b/os/os-hpux.h
new file mode 100644
index 0000000..a36cb70
--- /dev/null
+++ b/os/os-hpux.h
@@ -0,0 +1,72 @@
+#ifndef FIO_OS_HPUX_H
+#define FIO_OS_HPUX_H
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/fcntl.h>
+#include <sys/fadvise.h>
+#include <sys/mman.h>
+#include <sys/mpctl.h>
+
+#include "../file.h"
+
+#define FIO_HAVE_POSIXAIO
+#define FIO_HAVE_ODIRECT
+#define FIO_USE_GENERIC_RAND
+#define FIO_HAVE_CLOCK_MONOTONIC
+#define FIO_HAVE_PSHARED_MUTEX
+#define FIO_HAVE_FADVISE
+
+#define OS_MAP_ANON		MAP_ANONYMOUS
+#define OS_MSG_DONTWAIT		0
+
+#define POSIX_MADV_DONTNEED	MADV_DONTNEED
+#define POSIX_MADV_SEQUENTIAL	MADV_SEQUENTIAL
+#define POSIX_MADV_RANDOM	MADV_RANDOM
+#define posix_madvise(ptr, sz, hint)	madvise((ptr), (sz), (hint))
+
+static inline int blockdev_invalidate_cache(struct fio_file *f)
+{
+	return EINVAL;
+}
+
+static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
+{
+#if 0
+	struct devinfo info;
+
+	if (!ioctl(f->fd, IOCINFO, &info)) {
+        	*bytes = (unsigned long long)info.un.scdk.numblks *
+				info.un.scdk.blksize;
+		return 0;
+	}
+
+	return errno;
+#else
+	return 0;
+#endif
+}
+
+static inline unsigned long long os_phys_mem(void)
+{
+#if 0
+	long mem = sysconf(_SC_AIX_REALMEM);
+
+	if (mem == -1)
+		return 0;
+
+	return (unsigned long long) mem * 1024;
+#else
+	return 0;
+#endif
+}
+
+#define FIO_HAVE_CPU_ONLINE_SYSCONF
+
+static inline unsigned int cpus_online(void)
+{
+	return mpctl(MPC_GETNUMSPUS, 0, NULL);
+}
+
+#endif
diff --git a/os/os.h b/os/os.h
index 4bbdd62..3df7b41 100644
--- a/os/os.h
+++ b/os/os.h
@@ -18,6 +18,8 @@
 #include "os-mac.h"
 #elif defined(_AIX)
 #include "os-aix.h"
+#elif defined(__hpux)
+#include "os-hpux.h"
 #elif defined(__CYGWIN__)
 #include "os-windows.h"
 #else
@@ -178,4 +180,11 @@
 }
 #endif
 
+#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
+static inline unsigned int cpus_online(void)
+{
+	return sysconf(_SC_NPROCESSORS_ONLN);
+}
+#endif
+
 #endif