mirror of
https://github.com/qemu/qemu.git
synced 2026-05-18 02:12:22 +00:00
rust/hpet: Borrow HPETState.regs once in HPETState::post_load()
Timers in post_load() access the same HPETState, which is the "self" HPETState. So there's no need to access HPETState from child HPETTimer again and again. Instead, just cache and borrow HPETState.regs at the beginning, and this could save some CPU cycles and reduce borrow() calls. It's safe, because post_load() is called with BQL protection, so that there's no other chance to modify the regs. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20251113051937.4017675-15-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
@@ -882,9 +882,11 @@ impl HPETState {
|
||||
}
|
||||
|
||||
fn post_load(&self, _version_id: u8) -> Result<(), migration::Infallible> {
|
||||
let regs = self.regs.borrow();
|
||||
|
||||
for timer in self.timers.iter().take(self.num_timers) {
|
||||
let mut t = timer.borrow_mut();
|
||||
let cnt = t.get_state().regs.borrow().counter;
|
||||
let cnt = regs.counter;
|
||||
|
||||
t.cmp64 = t.calculate_cmp64(cnt, t.regs.cmp);
|
||||
t.last = CLOCK_VIRTUAL.get_ns() - NANOSECONDS_PER_SECOND;
|
||||
@@ -893,7 +895,7 @@ impl HPETState {
|
||||
// Recalculate the offset between the main counter and guest time
|
||||
if !self.hpet_offset_saved {
|
||||
self.hpet_offset
|
||||
.set(ticks_to_ns(self.regs.borrow().counter) - CLOCK_VIRTUAL.get_ns());
|
||||
.set(ticks_to_ns(regs.counter) - CLOCK_VIRTUAL.get_ns());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user