Add sparc and sparc64 support
authorJens Axboe <jens.axboe@oracle.com>
Fri, 30 May 2008 22:04:45 +0000 (00:04 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 30 May 2008 22:04:45 +0000 (00:04 +0200)
Also get rid of the arch private ffz functions, the generic
one is just fine.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
12 files changed:
arch/arch-alpha.h
arch/arch-ia64.h
arch/arch-ppc.h
arch/arch-s390.h
arch/arch-sparc.h [new file with mode: 0644]
arch/arch-sparc64.h [new file with mode: 0644]
arch/arch-x86.h
arch/arch-x86_64.h
arch/arch.h
fio.c
io_u.c
smalloc.c

index a476891aecf4cbe4268a4c617e41c4aa33526905..2b6832018f76baedcaea13e41bcf69f1f4c6e648 100644 (file)
@@ -13,7 +13,6 @@
 #endif
 
 #define nop            do { } while (0)
-#define fio_ffz(v)     generic_ffz((v))
 #define read_barrier() __asm__ __volatile__("mb": : :"memory")
 
 #endif
index 3268acc51ea02fe1528e1f2477ff3bc42186d5e1..9c8b406c1bc3e29bd495f0c5cab699e4e583203a 100644 (file)
 #define nop            asm volatile ("hint @pause" ::: "memory");
 #define read_barrier() asm volatile ("mf" ::: "memory")
 
-#define ia64_popcnt(x)                                                 \
-({                                                                     \
-       unsigned long ia64_intri_res;                                   \
-       asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x));         \
-       ia64_intri_res;                                                 \
-})
-
-static inline unsigned long fio_ffz(unsigned long bitmask)
-{
-       return ia64_popcnt(bitmask & (~bitmask - 1));
-}
-
 #endif
index 978313196d4c885690d47a7a6a67542b523b6d60..4d7710520dc06574c64f74793551d85842cd4b8b 100644 (file)
        __asm__ __volatile__ ("sync" : : : "memory")
 #endif
 
-static inline int __ilog2(unsigned long bitmask)
-{
-       int lz;
-
-       asm ("cntlzw %0,%1" : "=r" (lz) : "r" (bitmask));
-       return 31 - lz;
-}
-
-static inline int fio_ffz(unsigned long bitmask)
-{
-       if ((bitmask = ~bitmask) == 0)
-               return 32;
-       return  __ilog2(bitmask & -bitmask);
-}
-
 #endif
index 5e13155951111876c6878b8a707c037970ece2ea..c4ec1d12478cd17a5a0fd8943a4ca93264a6aff4 100644 (file)
@@ -13,7 +13,6 @@
 #endif
 
 #define nop            asm volatile ("diag 0,0,68" : : : "memory")
-#define fio_ffz(v)     generic_ffz((v))
 #define read_barrier() asm volatile("bcr 15,0" : : : "memory")
 
 #endif
diff --git a/arch/arch-sparc.h b/arch/arch-sparc.h
new file mode 100644 (file)
index 0000000..be3b394
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef ARCH_SPARC_H
+#define ARCH_SPARC_H
+
+#define ARCH   (arch_sparc)
+
+#ifndef __NR_ioprio_set
+#define __NR_ioprio_set                196
+#define __NR_ioprio_get                218
+#endif
+
+#ifndef __NR_fadvise64
+#define __NR_fadvise64         209
+#endif
+
+#ifndef __NR_sys_splice
+#define __NR_sys_splice                232
+#define __NR_sys_tee           280
+#define __NR_sys_vmsplice      25
+#endif
+
+#define nop    do { } while (0)
+
+#define read_barrier() __asm__ __volatile__ ("" : : : "memory")
+
+#endif
diff --git a/arch/arch-sparc64.h b/arch/arch-sparc64.h
new file mode 100644 (file)
index 0000000..b916882
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef ARCH_SPARC64_H
+#define ARCH_SPARC64_H
+
+#define ARCH   (arch_sparc64)
+
+#ifndef __NR_ioprio_set
+#define __NR_ioprio_set                196
+#define __NR_ioprio_get                218
+#endif
+
+#ifndef __NR_fadvise64
+#define __NR_fadvise64         209
+#endif
+
+#ifndef __NR_sys_splice
+#define __NR_sys_splice                232
+#define __NR_sys_tee           280
+#define __NR_sys_vmsplice      25
+#endif
+
+#define nop    do { } while (0)
+
+#define membar_safe(type) \
+       do {    __asm__ __volatile__("ba,pt     %%xcc, 1f\n\t" \
+                                       " membar   " type "\n" \
+                                       "1:\n" \
+                                       : : : "memory"); \
+       } while (0)
+
+#define read_barrier() \
+       membar_safe("#LoadLoad")
+
+#endif
index 343e51ab5b0853a5ea94f3f1f3a6f5e4033ad922..4d7ea49dd1cdde71d004050875a95dc9c4c3ea80 100644 (file)
 #define nop            __asm__ __volatile__("rep;nop": : :"memory")
 #define read_barrier() asm volatile ("": : :"memory")
 
-static inline unsigned long fio_ffz(unsigned long bitmask)
-{
-       __asm__("bsfl %1,%0" :"=r" (bitmask) :"r" (~bitmask));
-       return bitmask;
-}
-
 #endif
index 979c3206185f87334488d60179ff9918e13642cf..b49fd5f1344625f559a67a2071dfde226be11b01 100644 (file)
 #define nop            __asm__ __volatile__("rep;nop": : :"memory")
 #define read_barrier() asm volatile("lfence":::"memory")
 
-static inline unsigned long fio_ffz(unsigned long bitmask)
-{
-       __asm__("bsfq %1,%0" :"=r" (bitmask) :"r" (~bitmask));
-       return bitmask;
-}
-
-
 #endif
index 3962c9291bebf1abe4babee787f253198a913e98..8d06c911abc33dee73331cefa3e7b0933464903b 100644 (file)
@@ -8,19 +8,10 @@ enum {
        arch_ia64,
        arch_s390,
        arch_alpha,
+       arch_sparc,
+       arch_sparc64,
 };
 
-static inline unsigned long generic_ffz(unsigned long word)
-{
-       unsigned int i;
-
-       for (i = 0; i < sizeof(word) * 8; i++)
-               if ((word & (1UL << i)) == 0)
-                       return i;
-
-       return -1;
-}
-
 #if defined(__i386__)
 #include "arch-x86.h"
 #elif defined(__x86_64__)
@@ -33,6 +24,10 @@ static inline unsigned long generic_ffz(unsigned long word)
 #include "arch-alpha.h"
 #elif defined(__s390x__) || defined(__s390__)
 #include "arch-s390.h"
+#elif defined(__sparc__)
+#include "arch-sparc.h"
+#elif defined(__sparc64__)
+#include "arch-sparc64.h"
 #else
 #error "Unsupported arch"
 #endif
diff --git a/fio.c b/fio.c
index 7a420daf909afb84009792d63d2b146d85ce520d..bcabe3354b34c313fa77bda95463065d324a4176 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -107,36 +107,42 @@ static void status_timer_arm(void)
        setitimer(ITIMER_REAL, &itimer, NULL);
 }
 
-/*
- * We need to rearm on BSD/solaris. Switch this to sigaction in the future...
- */
-static void set_sig_handlers(void (*sighandler)(int))
-{
-       signal(SIGINT, sighandler);
-       signal(SIGALRM, sighandler);
-}
-
-static void sig_handler(int sig)
+static void sig_alrm(int sig)
 {
-       set_sig_handlers(sig_handler);
-
-       if (!threads)
-               return;
-
-       switch (sig) {
-       case SIGALRM:
+       if (threads) {
                update_io_ticks();
                print_thread_status();
                status_timer_arm();
-               break;
-       default:
+       }
+}
+
+static void sig_int(int sig)
+{
+       if (threads) {
                printf("\nfio: terminating on signal %d\n", sig);
                fflush(stdout);
                terminate_threads(TERMINATE_ALL);
-               break;
        }
 }
 
+/*
+ * We need to rearm on BSD/solaris. Switch this to sigaction in the future...
+ */
+static void set_sig_handlers(void)
+{
+       struct sigaction act;
+
+       memset(&act, 0, sizeof(act));
+       act.sa_handler = sig_alrm;
+       act.sa_flags = SA_RESTART;
+       sigaction(SIGALRM, &act, NULL);
+
+       memset(&act, 0, sizeof(act));
+       act.sa_handler = sig_int;
+       act.sa_flags = SA_RESTART;
+       sigaction(SIGINT, &act, NULL);
+}
+
 /*
  * Check if we are above the minimum rate given.
  */
@@ -1156,7 +1162,7 @@ static void run_threads(void)
                fflush(stdout);
        }
 
-       set_sig_handlers(sig_handler);
+       set_sig_handlers();
 
        todo = thread_number;
        nr_running = 0;
diff --git a/io_u.c b/io_u.c
index e4e169311a80aa2eb4c43645f733fc8b281c169d..1637b74daf69ede187ad5c063ac95e1dcee31cd5 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -7,6 +7,7 @@
 
 #include "fio.h"
 #include "hash.h"
+#include "lib/ffz.h"
 
 /*
  * Change this define to play with the timeout handling
@@ -108,7 +109,7 @@ static int get_next_free_block(struct thread_data *td, struct fio_file *f,
        *b = (i * BLOCKS_PER_MAP);
        while ((*b) * min_bs < f->real_file_size) {
                if (f->file_map[i] != -1UL) {
-                       *b += fio_ffz(f->file_map[i]);
+                       *b += ffz(f->file_map[i]);
                        if (*b > last_block(td, f, ddir))
                                break;
                        f->last_free_lookup = i;
index dfddfba9fcc0eef0246af80b566fec0d8171c97f..6cbf59cf320a0eb0fcf1bf9166f6b581bfe0c983 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -12,6 +12,7 @@
 #include <limits.h>
 
 #include "mutex.h"
+#include "lib/ffz.h"
 
 #define MP_SAFE                        /* define to make thread safe */
 #define SMALLOC_REDZONE                /* define to detect memory corruption */
@@ -173,34 +174,6 @@ static void clear_blocks(struct pool *pool, unsigned int pool_idx,
        blocks_iter(pool, pool_idx, idx, nr_blocks, mask_clear);
 }
 
-static inline int __ffs(int word)
-{
-       int r = 0;
-
-       if (!(word & 0xffff)) {
-               word >>= 16;
-               r += 16;
-       }
-       if (!(word & 0xff)) {
-               word >>= 8;
-               r += 8;
-       }
-       if (!(word & 0xf)) {
-               word >>= 4;
-               r += 4;
-       }
-       if (!(word & 3)) {
-               word >>= 2;
-               r += 2;
-       }
-       if (!(word & 1)) {
-               word >>= 1;
-               r += 1;
-       }
-
-       return r;
-}
-
 static int find_next_zero(int word, int start)
 {
        assert(word != -1U);