diff options
author | Bryan O'Donoghue <bryan.odonoghue@linaro.org> | 2015-08-11 13:50:54 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2015-08-11 20:06:58 -0700 |
commit | fd489e1ac617d662e248557afd8aa06ee731440b (patch) | |
tree | 46ae2134c3f22cf917856edc5c151d95369d225f /drivers | |
parent | 4c192665f0183150cff38b6954687752f3461e13 (diff) |
greybus: loopback: handle timestamp roll-over
This patch ensures we account for roll-over in the loopback driver.
do_gettimeofday() is used to grab a timestamp. Two timestamps are derived
one before and one after a gb_operation_sync(), however since
do_gettimeofday() returns the number of seconds and mircoseconds that have
elapsed today - we need to account for a situation where the timestamp
starts at say 23:59:999us rolls over and the end time is now earlier than
the start time.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/greybus/loopback.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c index ac38644c4a48..852b6beaecac 100644 --- a/drivers/staging/greybus/loopback.c +++ b/drivers/staging/greybus/loopback.c @@ -22,6 +22,8 @@ #include "greybus.h" +#define NSEC_PER_DAY 86400000000000ULL + struct gb_loopback_stats { u32 min; u32 max; @@ -226,7 +228,10 @@ static void gb_loopback_calc_latency(struct gb_loopback *gb, t1 = timeval_to_ns(ts); t2 = timeval_to_ns(te); - gb->elapsed_nsecs = t2 - t1; + if (t2 > t1) + gb->elapsed_nsecs = t2 - t1; + else + gb->elapsed_nsecs = NSEC_PER_DAY - t2 + t1; } static int gb_loopback_sink(struct gb_loopback *gb, u32 len) |