@@ -162,6 +162,8 @@ void init_apic(unsigned int cpu, apic_mode_t mode) {
162162 apic_write (APIC_SPIV , spiv .reg );
163163}
164164
165+ #define CAL_SLEEP_TIME 20
166+ #define CAL_ITERATIONS 10
165167void init_apic_timer (void ) {
166168 ASSERT (apic_get_mode () >= APIC_MODE_XAPIC );
167169 uint32_t min_ticks = _U32 (-1 );
@@ -170,21 +172,21 @@ void init_apic_timer(void) {
170172 apic_lvt_timer_t timer ;
171173 printk ("Initializing local APIC timer\n" );
172174
173- /* Spend 1s calibrating the timer, 10 iterations of 100ms each */
174- for (i = 0 ; i < 10 ; ++ i ) {
175+ /* Spend 200ms calibrating the timer, 10 iterations of 20ms each */
176+ for (i = 0 ; i < CAL_ITERATIONS ; ++ i ) {
175177 /* Set the counter to the max value (0xFFFFFFFF) */
176178 apic_write (APIC_TMR_DCR , APIC_TIMER_DIVIDE_BY_16 );
177179 apic_write (APIC_TMR_ICR , _U32 (-1 ));
178180
179- /* One shot mode to see how many ticks over 100ms */
181+ /* One shot mode to see how many ticks over 20ms */
180182 timer .timer_mode = APIC_LVT_TIMER_ONE_SHOT ;
181183 apic_write (APIC_LVT_TIMER , timer .reg );
182184
183- /* Sleep for 100ms to calibrate, count the ticks */
184- pit_sleep (100 );
185+ /* Sleep for 20ms to calibrate, count the ticks */
186+ pit_sleep (CAL_SLEEP_TIME );
185187
186188 /* Calibrate */
187- uint32_t elapsed_ticks = (_U32 (-1 ) - apic_read (APIC_TMR_CCR )) / 100 ;
189+ uint32_t elapsed_ticks = (_U32 (-1 ) - apic_read (APIC_TMR_CCR )) / CAL_SLEEP_TIME ;
188190 min_ticks = min (min_ticks , elapsed_ticks );
189191 }
190192
0 commit comments