diff mbox series

[ovs-dev,v4,5/7] timeval: Introduce time_usec().

Message ID 1507215962-17692-6-git-send-email-i.maximets@samsung.com
State Superseded
Headers show
Series Output packet batching. | expand

Commit Message

Ilya Maximets Oct. 5, 2017, 3:06 p.m. UTC
This fanction will provide monotonic time in microseconds.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 lib/timeval.c | 22 ++++++++++++++++++++++
 lib/timeval.h |  2 ++
 2 files changed, 24 insertions(+)

Comments

Eelco Chaudron Oct. 11, 2017, 9:07 a.m. UTC | #1
On 05/10/17 17:06, Ilya Maximets wrote:
> This fanction will provide monotonic time in microseconds.
>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>

This change looks good to me.

Acked-by: Eelco Chaudron <echaudro@redhat.com>

---8<---
Bodireddy, Bhanuprakash Oct. 13, 2017, 1:03 p.m. UTC | #2
>This fanction will provide monotonic time in microseconds.

[BHANU] Typo here with function.

>
>Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>---
> lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
> 2 files changed, 24 insertions(+)
>
>diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
>--- a/lib/timeval.c
>+++ b/lib/timeval.c
>@@ -233,6 +233,22 @@ time_wall_msec(void)
>     return time_msec__(&wall_clock);
> }
>
>+static long long int
>+time_usec__(struct clock *c)
>+{
>+    struct timespec ts;
>+
>+    time_timespec__(c, &ts);
>+    return timespec_to_usec(&ts);
>+}
>+
>+/* Returns a monotonic timer, in microseconds. */ long long int
>+time_usec(void)
>+{
>+    return time_usec__(&monotonic_clock); }
>+

[BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?
The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 

> /* Configures the program to die with SIGALRM 'secs' seconds from now, if
>  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
>+376,12 @@ timeval_to_msec(const struct timeval *tv)
>     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
>
>+long long int
>+timespec_to_usec(const struct timespec *ts) {
>+    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
>+1000; }
>+

[BHANU] how about adding timeval_to_usec()?
Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.

- Bhanuprakash.
Ben Pfaff Oct. 25, 2017, 5:28 p.m. UTC | #3
On Fri, Oct 13, 2017 at 01:03:18PM +0000, Bodireddy, Bhanuprakash wrote:
> >This fanction will provide monotonic time in microseconds.
> 
> [BHANU] Typo here with function.
> 
> >
> >Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> >---
> > lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
> > 2 files changed, 24 insertions(+)
> >
> >diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
> >--- a/lib/timeval.c
> >+++ b/lib/timeval.c
> >@@ -233,6 +233,22 @@ time_wall_msec(void)
> >     return time_msec__(&wall_clock);
> > }
> >
> >+static long long int
> >+time_usec__(struct clock *c)
> >+{
> >+    struct timespec ts;
> >+
> >+    time_timespec__(c, &ts);
> >+    return timespec_to_usec(&ts);
> >+}
> >+
> >+/* Returns a monotonic timer, in microseconds. */ long long int
> >+time_usec(void)
> >+{
> >+    return time_usec__(&monotonic_clock); }
> >+
> 
> [BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?
> The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 
> 
> > /* Configures the program to die with SIGALRM 'secs' seconds from now, if
> >  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
> >+376,12 @@ timeval_to_msec(const struct timeval *tv)
> >     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
> >
> >+long long int
> >+timespec_to_usec(const struct timespec *ts) {
> >+    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
> >+1000; }
> >+
> 
> [BHANU] how about adding timeval_to_usec()?
> Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.

I'd appreciate those changes too; with those changes, I'd be happy to
apply this, independent of anything else in the series.

Thanks,

Ben.
Ilya Maximets Oct. 26, 2017, 7:12 a.m. UTC | #4
On 25.10.2017 20:28, Ben Pfaff wrote:
> On Fri, Oct 13, 2017 at 01:03:18PM +0000, Bodireddy, Bhanuprakash wrote:
>>> This fanction will provide monotonic time in microseconds.
>>
>> [BHANU] Typo here with function.
>>
>>>
>>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>>> ---
>>> lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
>>> 2 files changed, 24 insertions(+)
>>>
>>> diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
>>> --- a/lib/timeval.c
>>> +++ b/lib/timeval.c
>>> @@ -233,6 +233,22 @@ time_wall_msec(void)
>>>     return time_msec__(&wall_clock);
>>> }
>>>
>>> +static long long int
>>> +time_usec__(struct clock *c)
>>> +{
>>> +    struct timespec ts;
>>> +
>>> +    time_timespec__(c, &ts);
>>> +    return timespec_to_usec(&ts);
>>> +}
>>> +
>>> +/* Returns a monotonic timer, in microseconds. */ long long int
>>> +time_usec(void)
>>> +{
>>> +    return time_usec__(&monotonic_clock); }
>>> +
>>
>> [BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?

I'm not sure what you meant under 'time_wall_usec__()'. There is no such function for msec.

>> The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 
>>
>>> /* Configures the program to die with SIGALRM 'secs' seconds from now, if
>>>  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
>>> +376,12 @@ timeval_to_msec(const struct timeval *tv)
>>>     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
>>>
>>> +long long int
>>> +timespec_to_usec(const struct timespec *ts) {
>>> +    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
>>> +1000; }
>>> +
>>
>> [BHANU] how about adding timeval_to_usec()?
>> Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.
> 
> I'd appreciate those changes too; with those changes, I'd be happy to
> apply this, independent of anything else in the series.


OK. Cool.
I'm going to implement additionally:

time_wall_usec()
usec_to_timespec()
timeval_to_usec()
timeval_diff_usec()

Please, correct me if I missed something.

Best regards, Ilya Maximets.
Ilya Maximets Oct. 26, 2017, 10:57 a.m. UTC | #5
On 26.10.2017 10:12, Ilya Maximets wrote:
> On 25.10.2017 20:28, Ben Pfaff wrote:
>> On Fri, Oct 13, 2017 at 01:03:18PM +0000, Bodireddy, Bhanuprakash wrote:
>>>> This fanction will provide monotonic time in microseconds.
>>>
>>> [BHANU] Typo here with function.
>>>
>>>>
>>>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>>>> ---
>>>> lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
>>>> 2 files changed, 24 insertions(+)
>>>>
>>>> diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
>>>> --- a/lib/timeval.c
>>>> +++ b/lib/timeval.c
>>>> @@ -233,6 +233,22 @@ time_wall_msec(void)
>>>>     return time_msec__(&wall_clock);
>>>> }
>>>>
>>>> +static long long int
>>>> +time_usec__(struct clock *c)
>>>> +{
>>>> +    struct timespec ts;
>>>> +
>>>> +    time_timespec__(c, &ts);
>>>> +    return timespec_to_usec(&ts);
>>>> +}
>>>> +
>>>> +/* Returns a monotonic timer, in microseconds. */ long long int
>>>> +time_usec(void)
>>>> +{
>>>> +    return time_usec__(&monotonic_clock); }
>>>> +
>>>
>>> [BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?
> 
> I'm not sure what you meant under 'time_wall_usec__()'. There is no such function for msec.
> 
>>> The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 
>>>
>>>> /* Configures the program to die with SIGALRM 'secs' seconds from now, if
>>>>  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
>>>> +376,12 @@ timeval_to_msec(const struct timeval *tv)
>>>>     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
>>>>
>>>> +long long int
>>>> +timespec_to_usec(const struct timespec *ts) {
>>>> +    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
>>>> +1000; }
>>>> +
>>>
>>> [BHANU] how about adding timeval_to_usec()?
>>> Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.
>>
>> I'd appreciate those changes too; with those changes, I'd be happy to
>> apply this, independent of anything else in the series.
> 
> 
> OK. Cool.
> I'm going to implement additionally:
> 
> time_wall_usec()
> usec_to_timespec()
> timeval_to_usec()
> timeval_diff_usec()
> 
> Please, correct me if I missed something.

I figured out that usec_to_timespec() and timeval_diff_usec() are static and
will produce 'defined but not used' warning. And, actually, they are used only
for poll logging and time warping, so those are not important to have usec
granularity.
I will add only two functions:

time_wall_usec()
timeval_to_usec()

because they are part of the public timeval interface.

> Best regards, Ilya Maximets.
>
Ben Pfaff Oct. 26, 2017, 4:48 p.m. UTC | #6
On Thu, Oct 26, 2017 at 10:12:19AM +0300, Ilya Maximets wrote:
> On 25.10.2017 20:28, Ben Pfaff wrote:
> > On Fri, Oct 13, 2017 at 01:03:18PM +0000, Bodireddy, Bhanuprakash wrote:
> >>> This fanction will provide monotonic time in microseconds.
> >>
> >> [BHANU] Typo here with function.
> >>
> >>>
> >>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> >>> ---
> >>> lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
> >>> 2 files changed, 24 insertions(+)
> >>>
> >>> diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
> >>> --- a/lib/timeval.c
> >>> +++ b/lib/timeval.c
> >>> @@ -233,6 +233,22 @@ time_wall_msec(void)
> >>>     return time_msec__(&wall_clock);
> >>> }
> >>>
> >>> +static long long int
> >>> +time_usec__(struct clock *c)
> >>> +{
> >>> +    struct timespec ts;
> >>> +
> >>> +    time_timespec__(c, &ts);
> >>> +    return timespec_to_usec(&ts);
> >>> +}
> >>> +
> >>> +/* Returns a monotonic timer, in microseconds. */ long long int
> >>> +time_usec(void)
> >>> +{
> >>> +    return time_usec__(&monotonic_clock); }
> >>> +
> >>
> >> [BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?
> 
> I'm not sure what you meant under 'time_wall_usec__()'. There is no such function for msec.
> 
> >> The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 
> >>
> >>> /* Configures the program to die with SIGALRM 'secs' seconds from now, if
> >>>  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
> >>> +376,12 @@ timeval_to_msec(const struct timeval *tv)
> >>>     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
> >>>
> >>> +long long int
> >>> +timespec_to_usec(const struct timespec *ts) {
> >>> +    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
> >>> +1000; }
> >>> +
> >>
> >> [BHANU] how about adding timeval_to_usec()?
> >> Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.
> > 
> > I'd appreciate those changes too; with those changes, I'd be happy to
> > apply this, independent of anything else in the series.
> 
> 
> OK. Cool.
> I'm going to implement additionally:
> 
> time_wall_usec()
> usec_to_timespec()
> timeval_to_usec()
> timeval_diff_usec()
> 
> Please, correct me if I missed something.

Thanks, that's what I mean, and I'd appreciate it.
Ben Pfaff Oct. 26, 2017, 4:58 p.m. UTC | #7
On Thu, Oct 26, 2017 at 01:57:59PM +0300, Ilya Maximets wrote:
> On 26.10.2017 10:12, Ilya Maximets wrote:
> > On 25.10.2017 20:28, Ben Pfaff wrote:
> >> On Fri, Oct 13, 2017 at 01:03:18PM +0000, Bodireddy, Bhanuprakash wrote:
> >>>> This fanction will provide monotonic time in microseconds.
> >>>
> >>> [BHANU] Typo here with function.
> >>>
> >>>>
> >>>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> >>>> ---
> >>>> lib/timeval.c | 22 ++++++++++++++++++++++  lib/timeval.h |  2 ++
> >>>> 2 files changed, 24 insertions(+)
> >>>>
> >>>> diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..be2eddc 100644
> >>>> --- a/lib/timeval.c
> >>>> +++ b/lib/timeval.c
> >>>> @@ -233,6 +233,22 @@ time_wall_msec(void)
> >>>>     return time_msec__(&wall_clock);
> >>>> }
> >>>>
> >>>> +static long long int
> >>>> +time_usec__(struct clock *c)
> >>>> +{
> >>>> +    struct timespec ts;
> >>>> +
> >>>> +    time_timespec__(c, &ts);
> >>>> +    return timespec_to_usec(&ts);
> >>>> +}
> >>>> +
> >>>> +/* Returns a monotonic timer, in microseconds. */ long long int
> >>>> +time_usec(void)
> >>>> +{
> >>>> +    return time_usec__(&monotonic_clock); }
> >>>> +
> >>>
> >>> [BHANU]  As you are introducing the support for microsecond granularity, can you also add time_wall_usec() and time_wall_usec__() here?
> > 
> > I'm not sure what you meant under 'time_wall_usec__()'. There is no such function for msec.
> > 
> >>> The ipfix code (ipfix_now()) can be the first one to use it for now. May be more in the future! 
> >>>
> >>>> /* Configures the program to die with SIGALRM 'secs' seconds from now, if
> >>>>  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */  void @@ -360,6
> >>>> +376,12 @@ timeval_to_msec(const struct timeval *tv)
> >>>>     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;  }
> >>>>
> >>>> +long long int
> >>>> +timespec_to_usec(const struct timespec *ts) {
> >>>> +    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec /
> >>>> +1000; }
> >>>> +
> >>>
> >>> [BHANU] how about adding timeval_to_usec()?
> >>> Also it would be nice to have the usec_to_timespec() and  timeval_diff_usec() implemented to make this commit complete.
> >>
> >> I'd appreciate those changes too; with those changes, I'd be happy to
> >> apply this, independent of anything else in the series.
> > 
> > 
> > OK. Cool.
> > I'm going to implement additionally:
> > 
> > time_wall_usec()
> > usec_to_timespec()
> > timeval_to_usec()
> > timeval_diff_usec()
> > 
> > Please, correct me if I missed something.
> 
> I figured out that usec_to_timespec() and timeval_diff_usec() are static and
> will produce 'defined but not used' warning. And, actually, they are used only
> for poll logging and time warping, so those are not important to have usec
> granularity.
> I will add only two functions:
> 
> time_wall_usec()
> timeval_to_usec()
> 
> because they are part of the public timeval interface.

OK.  It's only the public interface I care about.
diff mbox series

Patch

diff --git a/lib/timeval.c b/lib/timeval.c
index dd63f03..be2eddc 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -233,6 +233,22 @@  time_wall_msec(void)
     return time_msec__(&wall_clock);
 }
 
+static long long int
+time_usec__(struct clock *c)
+{
+    struct timespec ts;
+
+    time_timespec__(c, &ts);
+    return timespec_to_usec(&ts);
+}
+
+/* Returns a monotonic timer, in microseconds. */
+long long int
+time_usec(void)
+{
+    return time_usec__(&monotonic_clock);
+}
+
 /* Configures the program to die with SIGALRM 'secs' seconds from now, if
  * 'secs' is nonzero, or disables the feature if 'secs' is zero. */
 void
@@ -360,6 +376,12 @@  timeval_to_msec(const struct timeval *tv)
     return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;
 }
 
+long long int
+timespec_to_usec(const struct timespec *ts)
+{
+    return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec / 1000;
+}
+
 /* Returns the monotonic time at which the "time" module was initialized, in
  * milliseconds. */
 long long int
diff --git a/lib/timeval.h b/lib/timeval.h
index 7957dad..8e74551 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -54,6 +54,7 @@  time_t time_now(void);
 time_t time_wall(void);
 long long int time_msec(void);
 long long int time_wall_msec(void);
+long long int time_usec(void);
 void time_timespec(struct timespec *);
 void time_wall_timespec(struct timespec *);
 void time_alarm(unsigned int secs);
@@ -62,6 +63,7 @@  int time_poll(struct pollfd *, int n_pollfds, HANDLE *handles,
 
 long long int timespec_to_msec(const struct timespec *);
 long long int timeval_to_msec(const struct timeval *);
+long long int timespec_to_usec(const struct timespec *);
 
 struct tm_msec *localtime_msec(long long int now, struct tm_msec *result);
 struct tm_msec *gmtime_msec(long long int now, struct tm_msec *result);