Add sparc and sparc64 support
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index c5926289b34475bd511e8b8b5fadb0ce44b50c06..bcabe3354b34c313fa77bda95463065d324a4176 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -54,6 +54,7 @@ unsigned long done_secs = 0;
 static struct fio_mutex *startup_mutex;
 static volatile int fio_abort;
 static int exit_value;
+static struct itimerval itimer;
 
 struct io_log *agg_io_log[2];
 
@@ -99,25 +100,49 @@ static void terminate_threads(int group_id)
        }
 }
 
-static void sig_handler(int sig)
+static void status_timer_arm(void)
 {
-       if (!threads)
-               return;
+       itimer.it_value.tv_sec = 0;
+       itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000;
+       setitimer(ITIMER_REAL, &itimer, NULL);
+}
 
-       switch (sig) {
-       case SIGALRM:
+static void sig_alrm(int sig)
+{
+       if (threads) {
                update_io_ticks();
-               disk_util_timer_arm();
                print_thread_status();
-               break;
-       default:
+               status_timer_arm();
+       }
+}
+
+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.
  */
@@ -1137,8 +1162,7 @@ static void run_threads(void)
                fflush(stdout);
        }
 
-       signal(SIGINT, sig_handler);
-       signal(SIGALRM, sig_handler);
+       set_sig_handlers();
 
        todo = thread_number;
        nr_running = 0;
@@ -1356,7 +1380,7 @@ int main(int argc, char *argv[])
 
        set_genesis_time();
 
-       disk_util_timer_arm();
+       status_timer_arm();
 
        run_threads();