diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-21 19:38:45 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-21 19:38:45 +0300 |
| commit | 1a5248bb177242a34fd51efadb4af941853d5e35 (patch) | |
| tree | 669565c49217876611565c42867dcf0126e08933 /common/timer.c | |
| parent | 7967a9ab13214543041e4408086668b4db8d3e62 (diff) | |
| download | kmi-1a5248bb177242a34fd51efadb4af941853d5e35.tar.gz kmi-1a5248bb177242a34fd51efadb4af941853d5e35.zip | |
use uint64_t for timer ticks
+ GCC seems to provide this even on 32bit platforms, though I should
really check.
Diffstat (limited to 'common/timer.c')
| -rw-r--r-- | common/timer.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/common/timer.c b/common/timer.c index b48e455..f35c983 100644 --- a/common/timer.c +++ b/common/timer.c @@ -26,9 +26,9 @@ static struct sp_root *__cpu_timers() return &cpu_timers[cpu_id()]; } -void init_timer() +void init_timer(const void *fdt) { - ticks_per_sec = stat_timer(); + ticks_per_sec = stat_timer(fdt); init_nodes(&node_root, sizeof(struct timer_node)); } @@ -39,8 +39,17 @@ static id_t __insert_timer(struct timer_node *ti) enum sp_dir d; while (n) { struct timer_node *t = container_of(n, struct timer_node, sp_n); - if (ti->timer.cid == t->timer.cid) - ti->timer.cid--; + if (ti->timer.cid == t->timer.cid) { + /* if there's an identical ID, we'll just increment our + * ID until we get and ID that doesn't exist yet. There + * is a very small possibility that this will set a + * timer that's very slightly ahead of some other timer + * to be handled after the one that's very close, but + * the timescales that we're dealing with are probably + * tiny enough that this won't matter, even if it + * occurs. */ + ti->timer.cid++; + } p = n; @@ -66,6 +75,7 @@ static id_t __new_timer(id_t tid, ticks_t ticks) { struct timer_node *ti = (struct timer_node *)get_node(&node_root); ti->timer.ticks = ticks; + /* preliminary ID, may change after actual insertion */ ti->timer.cid = ticks; ti->timer.tid = tid; return __insert_timer(ti); @@ -117,8 +127,8 @@ void remove_timer(struct timer *t) sp_remove(&sp_root(__cpu_timers()), n); } -/* TODO: does this overflow too early? */ ticks_t nsecs_to_ticks(tunit_t nsecs) { - return (nsecs * ticks_per_sec) / 1000000000; + ticks_t t = (nsecs * ticks_per_sec) / 1000000000; + return t == 0 ? 1 : t; } |
