netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/4] Add new timeval_to_sec function
@ 2007-07-23  4:41 Varun Chandramohan
  2007-07-23 11:24 ` Patrick McHardy
  0 siblings, 1 reply; 8+ messages in thread
From: Varun Chandramohan @ 2007-07-23  4:41 UTC (permalink / raw)
  To: netdev; +Cc: sri, dlstevens, varuncha

A new function for converting timeval to time_t is added in time.h. Its a common function used in different
places.

Signed-off-by: Varun Chandramohan <varunc@linux.vnet.ibm.com>
---
 include/linux/time.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index dda9be6..c81baa6 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -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
  *
-- 
1.4.3.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-23  4:41 [PATCH 2/4] Add new timeval_to_sec function Varun Chandramohan
@ 2007-07-23 11:24 ` Patrick McHardy
  2007-07-24  4:15   ` Varun Chandramohan
  0 siblings, 1 reply; 8+ messages in thread
From: Patrick McHardy @ 2007-07-23 11:24 UTC (permalink / raw)
  To: Varun Chandramohan; +Cc: netdev, sri, dlstevens, varuncha

Varun Chandramohan wrote:
>  /**
> + * 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);
> +}


I don't think you should round down timeout values.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-23 11:24 ` Patrick McHardy
@ 2007-07-24  4:15   ` Varun Chandramohan
  2007-07-24  6:22     ` Oliver Hartkopp
  0 siblings, 1 reply; 8+ messages in thread
From: Varun Chandramohan @ 2007-07-24  4:15 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netdev, sri, dlstevens, varuncha

Patrick McHardy wrote:
> Varun Chandramohan wrote:
>   
>>  /**
>> + * 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);
>> +}
>>     
>
>
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-24  4:15   ` Varun Chandramohan
@ 2007-07-24  6:22     ` Oliver Hartkopp
  2007-07-24  6:40       ` Varun Chandramohan
  2007-07-24 19:54       ` David Stevens
  0 siblings, 2 replies; 8+ messages in thread
From: Oliver Hartkopp @ 2007-07-24  6:22 UTC (permalink / raw)
  To: Varun Chandramohan
  Cc: Patrick McHardy, netdev, sri, dlstevens, varuncha,
	Thomas Gleixner

Varun Chandramohan wrote:
> Patrick McHardy wrote:
>   
>> Varun Chandramohan wrote:
>>   
>>     
>>>  /**
>>> + * 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);
>>> +}
>>>     
>>>       
>> 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);

???

Btw. isn't here already any solution based on ktime conversions?

Regards,
Oliver



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-24  6:22     ` Oliver Hartkopp
@ 2007-07-24  6:40       ` Varun Chandramohan
  2007-07-24 13:43         ` Patrick McHardy
  2007-07-24 19:54       ` David Stevens
  1 sibling, 1 reply; 8+ messages in thread
From: Varun Chandramohan @ 2007-07-24  6:40 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: Patrick McHardy, netdev, sri, dlstevens, varuncha,
	Thomas Gleixner

Oliver Hartkopp wrote:
> Varun Chandramohan wrote:
>   
>> Patrick McHardy wrote:
>>   
>>     
>>> Varun Chandramohan wrote:
>>>   
>>>     
>>>       
>>>>  /**
>>>> + * 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);
>>>> +}
>>>>     
>>>>       
>>>>         
>>> 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);
>
> ???
>
>   
This can done.  Is this what you were ref to me, Patrick?
> 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.
> Regards,
> Oliver
>
>
>   
Regards,
Varun
> -
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-24  6:40       ` Varun Chandramohan
@ 2007-07-24 13:43         ` Patrick McHardy
  2007-07-24 13:50           ` Varun Chandramohan
  0 siblings, 1 reply; 8+ messages in thread
From: Patrick McHardy @ 2007-07-24 13:43 UTC (permalink / raw)
  To: Varun Chandramohan
  Cc: Oliver Hartkopp, netdev, sri, dlstevens, varuncha,
	Thomas Gleixner

Varun Chandramohan wrote:
> Oliver Hartkopp wrote:
> 
>>>>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);
>>
>>???
>>
>>  
> 
> This can done.  Is this what you were ref to me, Patrick?


Yes, timeouts should usually be at least as long as specified.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-24 13:43         ` Patrick McHardy
@ 2007-07-24 13:50           ` Varun Chandramohan
  0 siblings, 0 replies; 8+ messages in thread
From: Varun Chandramohan @ 2007-07-24 13:50 UTC (permalink / raw)
  To: Patrick McHardy
  Cc: Oliver Hartkopp, netdev, sri, dlstevens, varuncha,
	Thomas Gleixner

Patrick McHardy wrote:
> Varun Chandramohan wrote:
>   
>> Oliver Hartkopp wrote:
>>
>>     
>>>>> 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);
>>>
>>> ???
>>>
>>>  
>>>       
>> 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. :-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Add new timeval_to_sec function
  2007-07-24  6:22     ` Oliver Hartkopp
  2007-07-24  6:40       ` Varun Chandramohan
@ 2007-07-24 19:54       ` David Stevens
  1 sibling, 0 replies; 8+ messages in thread
From: David Stevens @ 2007-07-24 19:54 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: Patrick McHardy, netdev, sri, Thomas Gleixner, Varun Chandramohan,
	varuncha

Oliver Hartkopp <socketcan@hartkopp.net> wrote on 07/23/2007 11:22:39 PM:

> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-07-24 19:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-23  4:41 [PATCH 2/4] Add new timeval_to_sec function Varun Chandramohan
2007-07-23 11:24 ` Patrick McHardy
2007-07-24  4:15   ` Varun Chandramohan
2007-07-24  6:22     ` Oliver Hartkopp
2007-07-24  6:40       ` Varun Chandramohan
2007-07-24 13:43         ` Patrick McHardy
2007-07-24 13:50           ` Varun Chandramohan
2007-07-24 19:54       ` David Stevens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).