Skip to content

Commit

Permalink
feat(hal-x86_64): store LAPIC timer calibration (#505)
Browse files Browse the repository at this point in the history
This way, we don't re-calibrate every time we call
`start_periodic_timer`. This will also be used when adding the one-shot
timer mode (see #498).
  • Loading branch information
hawkw committed Jan 5, 2025
1 parent 696f26a commit b3f700d
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 76 deletions.
10 changes: 7 additions & 3 deletions hal-x86_64/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ pub enum PeriodicTimerError {
Pit(#[from] time::PitError),
#[error(transparent)]
InvalidDuration(#[from] time::InvalidDuration),
#[error("could not start local APIC periodic timer: {0}")]
#[error("could access local APIC: {0}")]
Apic(#[from] apic::local::LocalApicError),
#[error("could not start local APIC periodic timer: {0}")]
ApicTimer(#[from] apic::local::TimerError),
}

#[derive(Debug)]
Expand Down Expand Up @@ -379,8 +381,10 @@ impl Controller {
.start_periodic_timer(interval)
.map_err(Into::into),
InterruptModel::Apic { ref local, .. } => local.with(|apic| {
apic.start_periodic_timer(interval, Idt::LOCAL_APIC_TIMER as u8)
.map_err(PeriodicTimerError::from)
// divide by 16 is chosen kinda arbitrarily lol
apic.calibrate_timer(apic::local::register::TimerDivisor::By16);
apic.start_periodic_timer(interval, Idt::LOCAL_APIC_TIMER as u8)?;
Ok(())
})?,
}
}
Expand Down
Loading

0 comments on commit b3f700d

Please sign in to comment.