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.
--- 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 +500000 )/1000000 ); +} + +/** * ns_to_timespec - Convert nanoseconds to timespec * @nsec: the nanoseconds value to be converted *
Signature · 1 line
1.4.3.4
include/linux/time.h static inline s64 timeval_to_ns(const st · line 158
Quoted 10 lines · Varun Chandramohan
/**
+ *timeval_to_sec- Convert timeval to seconds
+ * @tv: pointer to the timeval variable to be converted
+ *
+ * Returns the seconds representation of timeval parameter.
+ */include/linux/time.h +4
-0+static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +500000 )/1000000 ); +}
I don't think you should round down timeout values.
Quoted 17 lines · Patrick McHardy
include/linux/time.h static inline s64 timeval_to_ns(const st · line 158
Quoted 11 lines · Varun Chandramohan
/**
+ *timeval_to_sec- Convert timeval to seconds
+ * @tv: pointer to the timeval variable to be converted
+ *
+ * Returns the seconds representation of timeval parameter.
+ */include/linux/time.h +4
-0+static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +500000 )/1000000 ); +}I don't think you should round down timeout values.
Can you elaborate on that? As per the RFC of MIB ,we need only seconds granularity. Taking that as the case i dont understand why round down should not be done?
Regards,
Varun
Quoted 20 lines · Varun Chandramohan
Quoted 18 lines · Patrick McHardy
include/linux/time.h static inline s64 timeval_to_ns(const st · line 158
Quoted 12 lines · Varun Chandramohan
/**
+ *timeval_to_sec- Convert timeval to seconds
+ * @tv: pointer to the timeval variable to be converted
+ *
+ * Returns the seconds representation of timeval parameter.
+ */include/linux/time.h +4
-0+static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +500000 )/1000000 ); +}I don't think you should round down timeout values.
Quoted 4 lines
Can you elaborate on that? As per the RFC of MIB ,we need only seconds granularity. Taking that as the case i dont understand why round down should not be done?
When you like to create any timeout based on your calculated value, you might run into the problem that your calculated value is set to _zero_ even if there was "some time" before the conversion. This might probably not what you indented to get.
So what about rounding up with
return (tv->tv_sec + (tv->tv_usec + 999999)/1000000);
???
Btw. isn't here already any solution based on ktime conversions?
Regards,
Oliver
Quoted 37 lines · Oliver Hartkopp
Quoted 24 lines · Varun Chandramohan
Quoted 4 lines · Patrick McHardy
Varun Chandramohan wrote:
Quoted 17 lines
include/linux/time.h static inline s64 timeval_to_ns(const st · line 158
Quoted 13 lines
/**
+ *timeval_to_sec- Convert timeval to seconds
+ * @tv: pointer to the timeval variable to be converted
+ *
+ * Returns the seconds representation of timeval parameter.
+ */include/linux/time.h +4
-0+static inline time_t timeval_to_sec (const struct timeval *tv) +{ +return (tv->tv_sec + (tv->tv_usec +500000 )/1000000 ); +}I don't think you should round down timeout values.
Quoted 5 lines
Can you elaborate on that? As per the RFC of MIB ,we need only seconds granularity. Taking that as the case i dont understand why round down should not be done?
When you like to create any timeout based on your calculated value, you might run into the problem that your calculated value is set to _zero_ even if there was "some time" before the conversion. This might probably not what you indented to get.
Quoted 7 lines
So what about rounding up with
return (
tv->tv_sec+ (tv->tv_usec+ 999999)/1000000);???
This can done. Is this what you were ref to me, Patrick?
Quoted 3 lines
Btw. isn't here already any solution based on ktime conversions?
AFAIK there isint any conversion function to secs. Correct me if iam wrong. But we can have a function or macro to do this conversion.
Quoted 5 lines
Regards,
Oliver
Regards,
Varun
Quoted 5 lines
-
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 20 lines · Varun Chandramohan
Quoted 18 lines · Oliver Hartkopp
Quoted 10 lines
Quoted 4 lines
I don't think you should round down timeout values.
Can you elaborate on that? As per the RFC of MIB ,we need only seconds granularity. Taking that as the case i dont understand why round down should not be done?
When you like to create any timeout based on your calculated value, you might run into the problem that your calculated value is set to _zero_ even if there was "some time" before the conversion. This might probably not what you indented to get.
So what about rounding up with
Quoted 7 lines
Quoted 5 lines
return (
tv->tv_sec+ (tv->tv_usec+ 999999)/1000000);???
This can done. Is this what you were ref to me, Patrick?
Yes, timeouts should usually be at least as long as specified.
Quoted 29 lines · Patrick McHardy
Quoted 27 lines · Varun Chandramohan
Quoted 24 lines · Oliver Hartkopp
Quoted 11 lines
Quoted 5 lines
I don't think you should round down timeout values.
Can you elaborate on that? As per the RFC of MIB ,we need only seconds granularity. Taking that as the case i dont understand why round down should not be done?
When you like to create any timeout based on your calculated value, you might run into the problem that your calculated value is set to _zero_ even if there was "some time" before the conversion. This might probably not what you indented to get.
So what about rounding up with
return (
tv->tv_sec+ (tv->tv_usec+ 999999)/1000000);???
Quoted 6 lines
Quoted 2 lines
This can done. Is this what you were ref to me, Patrick?
Yes, timeouts should usually be at least as long as specified.
Thanks Patrick and Oliver, ill round it up. :-)
Oliver Hartkopp <[email protected]> wrote on 07/23/2007 11:22:39 PM:
Quoted 4 lines
When you like to create any timeout based on your calculated value, you might run into the problem that your calculated value is set to _zero_ even if there was "some time" before the conversion. This might probably not what you indented to get.
BTW, these are stats (for human consumption), not timers.
+-DLS