diff --git a/bsd/porting/_callout.h b/bsd/porting/_callout.h index e1411619ac5c959d5d700bb785954d930af4d30d..6953d11cf8df20396f03cd09e77863f0ea2e2581 100644 --- a/bsd/porting/_callout.h +++ b/bsd/porting/_callout.h @@ -39,6 +39,7 @@ #define _SYS__CALLOUT_H #include <osv/mutex.h> +#include <osv/clock.hh> struct callout { /* OSv waiter thread for drain (drain) */ @@ -48,7 +49,7 @@ struct callout { uint64_t c_ticks; /* Time when callout will be dispatched, both in ticks and in ns */ uint64_t c_time; - uint64_t c_to_ns; + osv::clock::uptime::time_point c_to_ns; /* Callout Handler */ void (*c_fn)(void *); void* c_arg; diff --git a/bsd/porting/callout.cc b/bsd/porting/callout.cc index 1eb294a3ecf015d088fe4854d404411a9756cab3..b8621a0ea62176e2a12b1e684311b60f8b656f2b 100644 --- a/bsd/porting/callout.cc +++ b/bsd/porting/callout.cc @@ -7,10 +7,11 @@ #include <mutex> #include <set> -#include "drivers/clock.hh" #include "osv/trace.hh" #include <osv/debug.hh> #include <osv/sched.hh> +#include <osv/clock.hh> +using namespace osv::clock::literals; #include <bsd/porting/rwlock.h> #include <bsd/porting/callout.h> @@ -127,9 +128,9 @@ static void _callout_thread(void) // Wait for timeout // ////////////////////// - uint64_t cur = clock::get()->time(); + auto cur = osv::clock::uptime::now(); bool expired = true; - if (cur < c->c_to_ns-TMILISECOND) { + if (cur < c->c_to_ns-1_ms) { sched::timer t(*sched::thread::current()); t.set(c->c_to_ns); @@ -213,8 +214,10 @@ static void _callout_thread(void) int callout_reset_on(struct callout *c, u64 to_ticks, void (*fn)(void *), void *arg, int ignore_cpu) { - u64 cur = clock::get()->time(); - int cur_ticks = ns2ticks(cur); + auto cur = osv::clock::uptime::now(); + int cur_ticks = ns2ticks( + std::chrono::duration_cast<std::chrono::nanoseconds> + (cur.time_since_epoch()).count()); int result = 0; bool queued_first = false; @@ -227,7 +230,7 @@ int callout_reset_on(struct callout *c, u64 to_ticks, void (*fn)(void *), // Reset the callout c->c_ticks = to_ticks; c->c_time = cur_ticks + to_ticks; // for freebsd compatibility - c->c_to_ns = cur + ticks2ns(to_ticks); // this is what we use + c->c_to_ns = cur + ticks2ns(to_ticks) * 1_ns; // this is what we use c->c_fn = fn; c->c_arg = arg; c->c_flags |= (CALLOUT_PENDING | CALLOUT_ACTIVE);