1 IMPLEMENTATION [apic_timer]:
10 #include "std_macros.h"
12 // no IRQ line for the LAPIC
13 IMPLEMENT inline int Timer::irq_line() { return -1; }
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 = 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");
44 IMPLEMENT inline NEEDS["apic.h"]
51 IMPLEMENT inline NEEDS["apic.h"]
55 Apic::timer_enable_irq();
59 IMPLEMENT inline NEEDS["apic.h"]
63 Apic::timer_disable_irq();
68 Timer::update_one_shot(Unsigned64 wakeup)
70 //unsigned cpu = current_cpu();
72 Unsigned64 now = Kip::k()->clock; //Cpu::cpus.cpu(cpu).time_us();
73 if (EXPECT_FALSE (wakeup <= now))
78 Unsigned64 delta = wakeup - now;
79 if (delta < Config::One_shot_min_interval_us)
80 apic = Apic::us_to_apic(Config::One_shot_min_interval_us);
81 else if (delta > Config::One_shot_max_interval_us)
82 apic = Apic::us_to_apic(Config::One_shot_max_interval_us);
84 apic = Apic::us_to_apic(delta);
86 if (EXPECT_FALSE (apic < 1))
91 Apic::timer_reg_write(apic);
96 Timer::update_timer(Unsigned64 wakeup)
98 if (Config::scheduler_one_shot)
99 update_one_shot(wakeup);