Make lib/pattern.c a stand-alone library
[fio.git] / time.c
diff --git a/time.c b/time.c
index f1c5d3fe613e85c4ce0713701aee5c45afdcabdd..279ee48492302ebd5a1080e5422cc48ecd6b7a59 100644 (file)
--- a/time.c
+++ b/time.c
@@ -8,8 +8,16 @@ static unsigned long ns_granularity;
 
 void timeval_add_msec(struct timeval *tv, unsigned int msec)
 {
-       tv->tv_usec += 1000 * msec;
-       if (tv->tv_usec >= 1000000) {
+       unsigned long adj_usec = 1000 * msec;
+
+       tv->tv_usec += adj_usec;
+       if (adj_usec >= 1000000) {
+               unsigned long adj_sec = adj_usec / 1000000;
+
+               tv->tv_usec -=  adj_sec * 1000000;
+               tv->tv_sec += adj_sec;
+       }
+       if (tv->tv_usec >= 1000000){
                tv->tv_usec -= 1000000;
                tv->tv_sec++;
        }
@@ -151,6 +159,17 @@ void set_genesis_time(void)
        fio_gettime(&genesis, NULL);
 }
 
+void set_epoch_time(struct thread_data *td, int log_unix_epoch)
+{
+       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;
+       }
+}
+
 void fill_start_time(struct timeval *t)
 {
        memcpy(t, &genesis, sizeof(genesis));