1 IMPLEMENTATION [apic_timer]:
10 #include "std_macros.h"
12 // no IRQ line for the LAPIC
13 PUBLIC static inline int Timer::irq() { return -1; }
17 Timer::init(Cpu_number)
19 Apic::timer_assign_irq_vector(Config::Apic_timer_vector);
21 if (Config::Scheduler_one_shot)
23 Apic::timer_set_one_shot();
24 Apic::timer_reg_write(0xffffffff);
28 Apic::timer_set_periodic();
29 Apic::timer_reg_write(Apic::us_to_apic(Config::Scheduler_granularity));
32 // make sure that PIT does pull its interrupt line
35 if (!Config::Scheduler_one_shot)
36 // from now we can save energy in getchar()
37 Config::getchar_does_hlt_works_ok = false && Config::hlt_works_ok;
39 printf ("Using the Local APIC timer on vector %x (%s Mode) for scheduling\n",
40 Config::Apic_timer_vector,
41 Config::Scheduler_one_shot ? "One-Shot" : "Periodic");
51 Timer::update_one_shot(Unsigned64 wakeup)
54 Unsigned64 now = Kip::k()->clock;
55 if (EXPECT_FALSE (wakeup <= now))
60 Unsigned64 delta = wakeup - now;
61 if (delta < Config::One_shot_min_interval_us)
62 apic = Apic::us_to_apic(Config::One_shot_min_interval_us);
63 else if (delta > Config::One_shot_max_interval_us)
64 apic = Apic::us_to_apic(Config::One_shot_max_interval_us);
66 apic = Apic::us_to_apic(delta);
68 if (EXPECT_FALSE (apic < 1))
73 Apic::timer_reg_write(apic);
78 Timer::update_timer(Unsigned64 wakeup)
80 if (Config::Scheduler_one_shot)
81 update_one_shot(wakeup);