From 697a606cc0af1c39ac18998c344a522199accb36 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 31 May 2008 00:04:45 +0200 Subject: [PATCH] Add sparc and sparc64 support Also get rid of the arch private ffz functions, the generic one is just fine. Signed-off-by: Jens Axboe --- arch/arch-alpha.h | 1 - arch/arch-ia64.h | 12 ------------ arch/arch-ppc.h | 15 -------------- arch/arch-s390.h | 1 - arch/arch-sparc.h | 25 +++++++++++++++++++++++ arch/arch-sparc64.h | 33 +++++++++++++++++++++++++++++++ arch/arch-x86.h | 6 ------ arch/arch-x86_64.h | 7 ------- arch/arch.h | 17 ++++++---------- fio.c | 48 +++++++++++++++++++++++++-------------------- io_u.c | 3 ++- smalloc.c | 29 +-------------------------- 12 files changed, 94 insertions(+), 103 deletions(-) create mode 100644 arch/arch-sparc.h create mode 100644 arch/arch-sparc64.h diff --git a/arch/arch-alpha.h b/arch/arch-alpha.h index a476891a..2b683201 100644 --- a/arch/arch-alpha.h +++ b/arch/arch-alpha.h @@ -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 diff --git a/arch/arch-ia64.h b/arch/arch-ia64.h index 3268acc5..9c8b406c 100644 --- a/arch/arch-ia64.h +++ b/arch/arch-ia64.h @@ -21,16 +21,4 @@ #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 diff --git a/arch/arch-ppc.h b/arch/arch-ppc.h index 97831319..4d771052 100644 --- a/arch/arch-ppc.h +++ b/arch/arch-ppc.h @@ -28,19 +28,4 @@ __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 diff --git a/arch/arch-s390.h b/arch/arch-s390.h index 5e131559..c4ec1d12 100644 --- a/arch/arch-s390.h +++ b/arch/arch-s390.h @@ -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 index 00000000..be3b394a --- /dev/null +++ b/arch/arch-sparc.h @@ -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 index 00000000..b916882a --- /dev/null +++ b/arch/arch-sparc64.h @@ -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 diff --git a/arch/arch-x86.h b/arch/arch-x86.h index 343e51ab..4d7ea49d 100644 --- a/arch/arch-x86.h +++ b/arch/arch-x86.h @@ -32,10 +32,4 @@ #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 diff --git a/arch/arch-x86_64.h b/arch/arch-x86_64.h index 979c3206..b49fd5f1 100644 --- a/arch/arch-x86_64.h +++ b/arch/arch-x86_64.h @@ -32,11 +32,4 @@ #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 diff --git a/arch/arch.h b/arch/arch.h index 3962c929..8d06c911 100644 --- a/arch/arch.h +++ b/arch/arch.h @@ -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 7a420daf..bcabe335 100644 --- 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 e4e16931..1637b74d 100644 --- 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; diff --git a/smalloc.c b/smalloc.c index dfddfba9..6cbf59cf 100644 --- a/smalloc.c +++ b/smalloc.c @@ -12,6 +12,7 @@ #include #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); -- 2.25.1