Commit 0889c9ed authored by Philippe Gerum's avatar Philippe Gerum Committed by Jan Kiszka

demo/cyclictest: fix time delta calculation

Otherwise, weird results could be seen when the second wraps, leading
to t1.nsec < t2.nsec, e.g.:

T: 0 ( 1107) P:98 I:1000 C:1886710 Min:      0 Act:    4 Avg:2147483647 Max:      -1
Signed-off-by: Philippe Gerum's avatarPhilippe Gerum <rpm@xenomai.org>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent 64f207dc
......@@ -340,20 +340,23 @@ static inline int tsgreater(struct timespec *a, struct timespec *b)
(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
}
static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
{
int64_t diff;
diff = USEC_PER_SEC * (long long)(t1.tv_sec - t2.tv_sec);
diff += (t1.tv_nsec - t2.tv_nsec) / 1000;
return diff;
struct timespec r;
r.tv_sec = t1.tv_sec - t2.tv_sec;
r.tv_nsec = t1.tv_nsec - t2.tv_nsec;
if (r.tv_nsec < 0) {
r.tv_sec--;
r.tv_nsec += NSEC_PER_SEC;
}
return r.tv_sec * NSEC_PER_SEC + r.tv_nsec;
}
static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
{
int64_t diff;
diff = NSEC_PER_SEC * (int64_t)(t1.tv_sec - t2.tv_sec);
diff += (t1.tv_nsec - t2.tv_nsec);
return diff;
return calcdiff_ns(t1, t2) / 1000;
}
void traceopt(char *option)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment