Add new timeval_to_sec function
PATCH 2/4 Add new timeval_to_sec function
A new function for converting timeval to time_t is added in time.h. Its a common function used in different places. The timeout is now rounded up as per the suggestion.
--- include/linux/time.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
include/linux/time.h +11 -0
@@ -147,6 +147,17 @@ static inline s64 timeval_to_ns(const st }/** +* timeval_to_sec - Convert timeval to seconds +* @tv: pointer to the timeval variable to be converted +* +* Returns the seconds representation of timeval parameter. +*/ +static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +999999 )/1000000 ); +} + +/** * ns_to_timespec - Convert nanoseconds to timespec * @nsec: the nanoseconds value to be converted *
Signature · 1 line
1.4.3.4
Quoted 17 lines · Varun Chandramohan
A new function for converting timeval to
time_tis added intime.h. Its a common function used in different places. The timeout is now rounded up as per the suggestion.Signed-off-by Varun Chandramohan <[email protected]>--- include/linux/time.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)include/linux/time.h +1
-0@@ -147,6 +147,17 @@ static inline s64 timeval_to_ns(const st }/** +* timeval_to_sec - Convert timeval to seconds
include/linux/time.h static inline s64 timeval_to_ns(const st · line 160
Quoted 10 lines
include/linux/time.h +10
-0+* @tv: pointer to the timeval variable to be converted +* +* Returns the seconds representation of timeval parameter. +*/ +static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +999999 )/1000000 ); +} + +/**
return tv->tv_sec + (tv->tv_usec ? 1 : 0);
is much faster
Also, the comment is not accurate, as it doesnt mention the roundup at all.
Quoted 7 lines · Eric Dumazet
Quoted 2 lines · Varun Chandramohan
+ return (
tv->tv_sec+ (tv->tv_usec+ 999999)/1000000);return
tv->tv_sec+ (tv->tv_usec? 1 : 0);is much faster
It additionally wins the design award in opposite to my suggestion ;-) Thanks!