6 static struct timeval genesis;
7 static unsigned long ns_granularity;
10 * busy looping version for the last few usec
12 uint64_t usec_spin(unsigned int usec)
17 fio_gettime(&start, NULL);
18 while ((t = utime_since_now(&start)) < usec)
24 uint64_t usec_sleep(struct thread_data *td, unsigned long usec)
31 unsigned long ts = usec;
33 if (usec < ns_granularity) {
38 ts = usec - ns_granularity;
41 req.tv_sec = ts / 1000000;
42 ts -= 1000000 * req.tv_sec;
46 req.tv_nsec = ts * 1000;
47 fio_gettime(&tv, NULL);
49 if (nanosleep(&req, NULL) < 0)
52 ts = utime_since_now(&tv);
58 } while (!td->terminate);
63 uint64_t time_since_genesis(void)
65 return time_since_now(&genesis);
68 uint64_t mtime_since_genesis(void)
70 return mtime_since_now(&genesis);
73 uint64_t utime_since_genesis(void)
75 return utime_since_now(&genesis);
78 int in_ramp_time(struct thread_data *td)
80 return td->o.ramp_time && !td->ramp_time_over;
83 int ramp_time_over(struct thread_data *td)
87 if (!td->o.ramp_time || td->ramp_time_over)
90 fio_gettime(&tv, NULL);
91 if (utime_since(&td->epoch, &tv) >= td->o.ramp_time) {
92 td->ramp_time_over = 1;
94 td_set_runstate(td, TD_RAMP);
101 void fio_time_init(void)
108 * Check the granularity of the nanosleep function
110 for (i = 0; i < 10; i++) {
113 unsigned long elapsed;
115 fio_gettime(&tv, NULL);
119 nanosleep(&ts, NULL);
120 elapsed = utime_since_now(&tv);
122 if (elapsed > ns_granularity)
123 ns_granularity = elapsed;
127 void set_genesis_time(void)
129 fio_gettime(&genesis, NULL);
132 void fill_start_time(struct timeval *t)
134 memcpy(t, &genesis, sizeof(genesis));