AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
timer.c File Reference

The tick: the virtual timer of ARM's generic timer, which is each CPU's own (PPI 27). More...

#include <core/system.h>
#include <cpu/cpu.h>
#include <dev/irq.h>
#include <platform/virt.h>

Go to the source code of this file.

Functions

static void timer_irq (void *arg)
 Handles the timer's interrupt: arms the next tick, and runs the tick's handler.
uint64_t timer_setup (uint64_t period_ns, void(*handler)(void))
 Starts the tick.
uint64_t arch_rtime_ns (void)
 Reads the monotonic clock, which starts at boot.
uint64_t arch_rtime_us (void)
 Reads the monotonic clock, in microseconds.
uint64_t arch_rtime_ms (void)
 Reads the monotonic clock, in milliseconds.
uint64_t arch_cycles (void)
 Reads a counter that changes as fast as the CPU runs, which the kernel uses as a source of randomness.

Variables

static uint64_t freq
static uint64_t interval
static void(*) tick (void)

Detailed Description

The tick: the virtual timer of ARM's generic timer, which is each CPU's own (PPI 27).

Its counter (CNTVCT_EL0) runs at CNTFRQ_EL0 from boot, so it's the kernel's clock too (arch_rtime_ns()).

References: [1] - Arm Architecture Reference Manual for A-profile, chapter D11 (The Generic Timer in AArch64 state)

Definition in file timer.c.

Function Documentation

◆ arch_cycles()

uint64_t arch_cycles ( void )

Reads a counter that changes as fast as the CPU runs, which the kernel uses as a source of randomness.

Returns
the counter's value

Definition at line 82 of file timer.c.

References arch_cycles(), and read_sysreg.

Referenced by arch_cycles(), random_stir(), and sched_timer_tick().

◆ arch_rtime_ms()

uint64_t arch_rtime_ms ( void )

Reads the monotonic clock, in milliseconds.

Returns
the time since the clock started, in milliseconds

Definition at line 73 of file timer.c.

References arch_rtime_ms(), and arch_rtime_ns().

Referenced by arch_rtime_ms(), arp_lookup(), arp_update(), and procfs_uptime().

◆ arch_rtime_ns()

◆ arch_rtime_us()

uint64_t arch_rtime_us ( void )

Reads the monotonic clock, in microseconds.

Returns
the time since the clock started, in microseconds

Definition at line 65 of file timer.c.

References arch_rtime_ns(), and arch_rtime_us().

Referenced by arch_rtime_us().

◆ timer_irq()

void timer_irq ( void * arg)
static

Handles the timer's interrupt: arms the next tick, and runs the tick's handler.

Definition at line 21 of file timer.c.

References interval, tick, timer_irq(), and write_sysreg.

Referenced by timer_irq(), and timer_setup().

◆ timer_setup()

uint64_t timer_setup ( uint64_t period_ns,
void(* handler )(void) )

Starts the tick.

Parameters
period_nshow often it comes, in ns
handlerwhat it calls
Returns
the period it really has, in ns (a whole number of counts)

Definition at line 37 of file timer.c.

References freq, interval, irq_install(), isb, NULL, printk(), read_sysreg, tick, timer_irq(), timer_setup(), VIRT_TIMER_IRQ, and write_sysreg.

Referenced by arch_sched_init(), and timer_setup().

Variable Documentation

◆ freq

uint64_t freq
static

Definition at line 16 of file timer.c.

Referenced by timer_setup().

◆ interval

uint64_t interval
static

Definition at line 16 of file timer.c.

Referenced by sched_alarm(), sched_alarm_get(), scheduler_init(), timer_irq(), and timer_setup().

◆ tick

void(*) tick(void) ( void )
static

Definition at line 17 of file timer.c.

Referenced by sys_times(), timer_irq(), and timer_setup().