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; }
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");
51 Timer::update_one_shot(Unsigned64 wakeup)
53 //unsigned cpu = current_cpu();
55 Unsigned64 now = Kip::k()->clock; //Cpu::cpus.cpu(cpu).time_us();
56 if (EXPECT_FALSE (wakeup <= now))
61 Unsigned64 delta = wakeup - now;
62 if (delta < Config::One_shot_min_interval_us)
63 apic = Apic::us_to_apic(Config::One_shot_min_interval_us);
64 else if (delta > Config::One_shot_max_interval_us)
65 apic = Apic::us_to_apic(Config::One_shot_max_interval_us);
67 apic = Apic::us_to_apic(delta);
69 if (EXPECT_FALSE (apic < 1))
74 Apic::timer_reg_write(apic);
79 Timer::update_timer(Unsigned64 wakeup)
81 if (Config::Scheduler_one_shot)
82 update_one_shot(wakeup);