1 IMPLEMENTATION [apic_timer]:
10 #include "std_macros.h"
16 Apic::timer_assign_irq_vector(Config::scheduler_irq_vector);
18 if (Config::scheduler_one_shot)
20 Apic::timer_set_one_shot();
21 Apic::timer_reg_write(0xffffffff);
25 Apic::timer_set_periodic();
26 Apic::timer_reg_write(Apic::us_to_apic(Config::scheduler_granularity));
29 // make sure that PIT does pull its interrupt line
32 if (!Config::scheduler_one_shot)
33 // from now we can save energy in getchar()
34 Config::getchar_does_hlt_works_ok = Config::hlt_works_ok;
36 printf ("Using the Local APIC timer on vector %x (%s Mode) for scheduling\n",
37 Config::scheduler_irq_vector,
38 Config::scheduler_one_shot ? "One-Shot" : "Periodic");
41 IMPLEMENT inline NEEDS["apic.h"]
48 IMPLEMENT inline NEEDS["apic.h"]
52 Apic::timer_enable_irq();
56 IMPLEMENT inline NEEDS["apic.h"]
60 Apic::timer_disable_irq();
65 Timer::update_one_shot(Unsigned64 wakeup)
67 //unsigned cpu = current_cpu();
69 Unsigned64 now = Kip::k()->clock; //Cpu::cpus.cpu(cpu).time_us();
70 if (EXPECT_FALSE (wakeup <= now))
75 Unsigned64 delta = wakeup - now;
76 if (delta < Config::One_shot_min_interval_us)
77 apic = Apic::us_to_apic(Config::One_shot_min_interval_us);
78 else if (delta > Config::One_shot_max_interval_us)
79 apic = Apic::us_to_apic(Config::One_shot_max_interval_us);
81 apic = Apic::us_to_apic(delta);
83 if (EXPECT_FALSE (apic < 1))
88 Apic::timer_reg_write(apic);
93 Timer::update_timer(Unsigned64 wakeup)
95 if (Config::scheduler_one_shot)
96 update_one_shot(wakeup);