mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 19:16:02 +00:00
Kernel: Correctly calculate delta_ticks when 64-bit counter wraps around
We never caught this bug in the HPET, since it takes ages for a 64-bit counter to wrap around. Also remove an unnecessary if check.
This commit is contained in:
parent
6680241773
commit
de0bb99893
Notes:
sideshowbarker
2024-07-17 05:24:17 +09:00
Author: https://github.com/FireFox317
Commit: de0bb99893
Pull-request: https://github.com/SerenityOS/serenity/pull/15667
Reviewed-by: https://github.com/gunnarbeutner ✅
Reviewed-by: https://github.com/nico ✅
1 changed files with 8 additions and 8 deletions
|
@ -262,18 +262,18 @@ u64 HPET::update_time(u64& seconds_since_boot, u32& ticks_this_second, bool quer
|
|||
delta_ticks += current_value - m_main_counter_last_read;
|
||||
} else {
|
||||
// the counter wrapped around
|
||||
delta_ticks += m_main_counter_last_read - current_value;
|
||||
if (!m_main_counter_64bits)
|
||||
if (m_main_counter_64bits) {
|
||||
delta_ticks += (NumericLimits<u64>::max() - m_main_counter_last_read + 1) + current_value;
|
||||
} else {
|
||||
delta_ticks += (NumericLimits<u32>::max() - m_main_counter_last_read + 1) + current_value;
|
||||
m_32bit_main_counter_wraps++;
|
||||
}
|
||||
}
|
||||
|
||||
u64 ticks_since_last_second = (u64)ticks_this_second + delta_ticks;
|
||||
auto ticks_per_second = frequency();
|
||||
if (ticks_since_last_second >= ticks_per_second) {
|
||||
seconds_since_boot += ticks_since_last_second / ticks_per_second;
|
||||
ticks_this_second = ticks_since_last_second % ticks_per_second;
|
||||
} else {
|
||||
ticks_this_second = ticks_since_last_second;
|
||||
}
|
||||
seconds_since_boot += ticks_since_last_second / ticks_per_second;
|
||||
ticks_this_second = ticks_since_last_second % ticks_per_second;
|
||||
|
||||
if (!query_only) {
|
||||
m_main_counter_drift = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue