also add a test for under running.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/tlist.h | 4 +++-
tests/check_loop.c | 8 +++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/tlist.h b/include/tlist.h
index 3600013..a005f81 100644
--- a/include/tlist.h
+++ b/include/tlist.h
@@ -32,6 +32,7 @@ typedef void *timer_handle;
#define TIMER_HANDLE
#endif
+static int64_t timerlist_hertz = HZ;
struct timerlist {
struct qb_list_head timer_head;
@@ -50,6 +51,7 @@ struct timerlist_timer {
static inline void timerlist_init(struct timerlist *timerlist)
{
qb_list_init(&timerlist->timer_head);
+ timerlist_hertz = qb_util_nano_monotonic_hz();
}
static inline void timerlist_add(struct timerlist *timerlist,
@@ -208,7 +210,7 @@ static inline uint64_t timerlist_msec_duration_to_expire(struct
timerlist *timer
msec_duration_to_expire =
((timer_from_list->expire_time -
- current_time) / QB_TIME_NS_IN_MSEC) + (1000 / HZ);
+ current_time) / QB_TIME_NS_IN_MSEC) + (1000 / timerlist_hertz);
return (msec_duration_to_expire);
}
diff --git a/tests/check_loop.c b/tests/check_loop.c
index f34e026..18edbcc 100644
--- a/tests/check_loop.c
+++ b/tests/check_loop.c
@@ -212,11 +212,17 @@ static void stop_watch_tmo(void*data)
{
struct qb_stop_watch *sw = (struct qb_stop_watch *)data;
float per;
+ int64_t diff;
sw->end = qb_util_nano_current_get();
- sw->total += sw->end - sw->start;
+
+ diff = sw->end - sw->start;
+ ck_assert(diff >= (sw->ms_timer * QB_TIME_NS_IN_MSEC));
+
+ sw->total += diff;
sw->total -= sw->ms_timer * QB_TIME_NS_IN_MSEC;
sw->start = sw->end;
+
sw->count++;
if (sw->count < 50) {
qb_loop_timer_add(sw->l, QB_LOOP_LOW, sw->ms_timer, data, stop_watch_tmo,
&sw->th);
--
1.7.3.1