diff options
Diffstat (limited to 'include/linux/time.h')
| -rw-r--r-- | include/linux/time.h | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index e7447958ece1..d9f9c6a340d8 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -12,6 +12,16 @@ struct timespec { }; #endif /* _STRUCT_TIMESPEC */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* microseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + #ifdef __KERNEL__ /* @@ -48,6 +58,27 @@ jiffies_to_timespec(unsigned long jiffies, struct timespec *value) value->tv_sec = jiffies / HZ; } +/* Same for "timeval" */ +static __inline__ unsigned long +timeval_to_jiffies(struct timeval *value) +{ + unsigned long sec = value->tv_sec; + long usec = value->tv_usec; + + if (sec >= (MAX_JIFFY_OFFSET / HZ)) + return MAX_JIFFY_OFFSET; + usec += 1000000L / HZ - 1; + usec /= 1000000L / HZ; + return HZ * sec + usec; +} + +static __inline__ void +jiffies_to_timeval(unsigned long jiffies, struct timeval *value) +{ + value->tv_usec = (jiffies % HZ) * (1000000L / HZ); + value->tv_sec = jiffies / HZ; +} + /* Converts Gregorian date to seconds since 1970-01-01 00:00:00. * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 @@ -88,17 +119,6 @@ extern struct timeval xtime; #endif /* __KERNEL__ */ - -struct timeval { - time_t tv_sec; /* seconds */ - suseconds_t tv_usec; /* microseconds */ -}; - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - #define NFDBITS __NFDBITS #ifdef __KERNEL__ |
