mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Kernel/riscv64: Clean up Timer class
I just copy-pasted microseconds_since_boot and set_interrupt_interval_usec from aarch64. However, on RISC-V, they are not in microseconds. The TimerRegisters struct is also unused. current_time and set_compare can also be private and static.
This commit is contained in:
parent
8582f0720f
commit
d061da4cf5
Notes:
sideshowbarker
2024-07-18 01:43:16 +09:00
Author: https://github.com/spholz Commit: https://github.com/SerenityOS/serenity/commit/d061da4cf5 Pull-request: https://github.com/SerenityOS/serenity/pull/22845 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 8 additions and 17 deletions
|
@ -15,12 +15,13 @@ Timer::Timer()
|
|||
: HardwareTimer(to_underlying(CSR::SCAUSE::SupervisorTimerInterrupt) & ~CSR::SCAUSE_INTERRUPT_MASK)
|
||||
{
|
||||
// FIXME: Actually query the frequency of the timer from the device tree.
|
||||
|
||||
// Based on the "/cpus/timebase-frequency" device tree node for the QEMU virt machine
|
||||
m_frequency = 10'000'000; // in Hz
|
||||
|
||||
set_interrupt_interval_usec(m_frequency / OPTIMAL_TICKS_PER_SECOND_RATE);
|
||||
m_interrupt_interval = m_frequency / OPTIMAL_TICKS_PER_SECOND_RATE;
|
||||
|
||||
set_compare(microseconds_since_boot() + m_interrupt_interval);
|
||||
set_compare(current_ticks() + m_interrupt_interval);
|
||||
RISCV64::CSR::set_bits(RISCV64::CSR::Address::SIE, 1 << interrupt_number());
|
||||
}
|
||||
|
||||
|
@ -31,7 +32,7 @@ NonnullLockRefPtr<Timer> Timer::initialize()
|
|||
return timer;
|
||||
}
|
||||
|
||||
u64 Timer::microseconds_since_boot()
|
||||
u64 Timer::current_ticks()
|
||||
{
|
||||
return RISCV64::CSR::read(RISCV64::CSR::Address::TIME);
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ bool Timer::handle_interrupt(RegisterState const& regs)
|
|||
{
|
||||
auto result = HardwareTimer::handle_interrupt(regs);
|
||||
|
||||
set_compare(microseconds_since_boot() + m_interrupt_interval);
|
||||
set_compare(current_ticks() + m_interrupt_interval);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -48,7 +49,7 @@ bool Timer::handle_interrupt(RegisterState const& regs)
|
|||
u64 Timer::update_time(u64& seconds_since_boot, u32& ticks_this_second, bool query_only)
|
||||
{
|
||||
// Should only be called by the time keeper interrupt handler!
|
||||
u64 current_value = microseconds_since_boot();
|
||||
u64 current_value = current_ticks();
|
||||
u64 delta_ticks = m_main_counter_drift;
|
||||
if (current_value >= m_main_counter_last_read) {
|
||||
delta_ticks += current_value - m_main_counter_last_read;
|
||||
|
@ -71,11 +72,6 @@ u64 Timer::update_time(u64& seconds_since_boot, u32& ticks_this_second, bool que
|
|||
return (delta_ticks * 1000000000ull) / ticks_per_second;
|
||||
}
|
||||
|
||||
void Timer::set_interrupt_interval_usec(u32 interrupt_interval)
|
||||
{
|
||||
m_interrupt_interval = interrupt_interval;
|
||||
}
|
||||
|
||||
void Timer::set_compare(u64 compare)
|
||||
{
|
||||
if (SBI::Timer::set_timer(compare).is_error())
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
namespace Kernel::RISCV64 {
|
||||
|
||||
struct TimerRegisters;
|
||||
|
||||
class Timer final : public HardwareTimer<GenericInterruptHandler> {
|
||||
public:
|
||||
static NonnullLockRefPtr<Timer> initialize();
|
||||
|
@ -37,14 +35,11 @@ public:
|
|||
// FIXME: Share code with HPET::update_time
|
||||
u64 update_time(u64& seconds_since_boot, u32& ticks_this_second, bool query_only);
|
||||
|
||||
u64 microseconds_since_boot();
|
||||
|
||||
void set_interrupt_interval_usec(u32);
|
||||
|
||||
private:
|
||||
Timer();
|
||||
|
||||
void set_compare(u64 compare);
|
||||
static u64 current_ticks();
|
||||
static void set_compare(u64 compare);
|
||||
|
||||
//^ GenericInterruptHandler
|
||||
virtual bool handle_interrupt(RegisterState const&) override;
|
||||
|
|
Loading…
Reference in a new issue