t/zbd: avoid test case 31 failure with small devices
[fio.git] / time.c
diff --git a/time.c b/time.c
index c8876829a367ede755453f6b255b2f4139ee8a74..7f85c8de3bcbd2cb40eabe9c5f5c465551539b3a 100644 (file)
--- a/time.c
+++ b/time.c
@@ -38,6 +38,17 @@ uint64_t usec_spin(unsigned int usec)
        return t;
 }
 
+/*
+ * busy loop for a fixed amount of cycles
+ */
+void cycles_spin(unsigned int n)
+{
+       unsigned long i;
+
+       for (i=0; i < n; i++)
+               nop;
+}
+
 uint64_t usec_sleep(struct thread_data *td, unsigned long usec)
 {
        struct timespec req;
@@ -57,6 +68,13 @@ uint64_t usec_sleep(struct thread_data *td, unsigned long usec)
                if (ts >= 1000000) {
                        req.tv_sec = ts / 1000000;
                        ts -= 1000000 * req.tv_sec;
+                       /*
+                        * Limit sleep to ~1 second at most, otherwise we
+                        * don't notice then someone signaled the job to
+                        * exit manually.
+                        */
+                       if (req.tv_sec > 1)
+                               req.tv_sec = 1;
                } else
                        req.tv_sec = 0;
 
@@ -118,6 +136,7 @@ bool ramp_time_over(struct thread_data *td)
        if (utime_since_now(&td->epoch) >= td->o.ramp_time) {
                td->ramp_time_over = true;
                reset_all_stats(td);
+               reset_io_stats(td);
                td_set_runstate(td, TD_RAMP);
 
                /*
@@ -164,14 +183,22 @@ void set_genesis_time(void)
        fio_gettime(&genesis, NULL);
 }
 
-void set_epoch_time(struct thread_data *td, int log_unix_epoch)
+void set_epoch_time(struct thread_data *td, clockid_t log_alternate_epoch_clock_id, clockid_t job_start_clock_id)
 {
+       struct timespec ts;
        fio_gettime(&td->epoch, NULL);
-       if (log_unix_epoch) {
-               struct timeval tv;
-               gettimeofday(&tv, NULL);
-               td->unix_epoch = (unsigned long long)(tv.tv_sec) * 1000 +
-                                (unsigned long long)(tv.tv_usec) / 1000;
+       clock_gettime(log_alternate_epoch_clock_id, &ts);
+       td->alternate_epoch = (unsigned long long)(ts.tv_sec) * 1000 +
+                                                 (unsigned long long)(ts.tv_nsec) / 1000000;
+       if (job_start_clock_id == log_alternate_epoch_clock_id)
+       {
+               td->job_start = td->alternate_epoch;
+       }
+       else
+       {
+               clock_gettime(job_start_clock_id, &ts);
+               td->job_start = (unsigned long long)(ts.tv_sec) * 1000 +
+                                               (unsigned long long)(ts.tv_nsec) / 1000000;
        }
 }