11#include < kernel/timers.hpp>
22
33#include < kernel/os.hpp>
4+ #include < kernel/events.hpp>
45#include < service>
56#include < smp>
67#include < statman>
@@ -58,6 +59,7 @@ struct alignas(SMP_ALIGN) timer_system
5859{
5960 bool is_running = false ;
6061 uint32_t dead_timers = 0 ;
62+ int interrupt = 0 ;
6163 Timers::start_func_t arch_start_func;
6264 Timers::stop_func_t arch_stop_func;
6365 std::vector<SystemTimer> timers;
@@ -79,6 +81,8 @@ static inline timer_system& get() {
7981void Timers::init (const start_func_t & start, const stop_func_t & stop)
8082{
8183 auto & system = get ();
84+ // event for processing timers
85+ system.interrupt = Events::get ().subscribe (&Timers::timers_handler);
8286 // architecture specific start and stop functions
8387 system.arch_start_func = start;
8488 system.arch_stop_func = stop;
@@ -88,6 +92,7 @@ void Timers::init(const start_func_t& start, const stop_func_t& stop)
8892 system.oneshot_stopped = (int64_t *) &Statman::get ().create (Stat::UINT64, CPU + " .timers.oneshot_stopped" ).get_uint64 ();
8993 system.periodic_started = &Statman::get ().create (Stat::UINT32, CPU + " .timers.periodic_started" ).get_uint32 ();
9094 system.periodic_stopped = &Statman::get ().create (Stat::UINT32, CPU + " .timers.periodic_stopped" ).get_uint32 ();
95+
9196}
9297
9398bool Timers::is_ready ()
@@ -283,11 +288,12 @@ static void sched_timer(duration_t when, Timers::id_t id)
283288
284289 // if the hardware timer is not running, try starting it
285290 if (UNLIKELY (system.is_running == false )) {
286- Timers::timers_handler ( );
291+ Events::get (). trigger_event (system. interrupt );
287292 return ;
288293 }
289294 // if the scheduled timer is the new front, restart timer
290295 auto it = system.scheduled .begin ();
291- if (it->second == id)
292- Timers::timers_handler ();
296+ if (it->second == id) {
297+ Events::get ().trigger_event (system.interrupt );
298+ }
293299}
0 commit comments