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

aarch64: the timer tick, the idle loop, and the running thread giving up its CPU. More...

#include <core/arch.h>
#include <core/time.h>
#include <mm/mm.h>
#include <sys/cpu.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/lock.h>
#include <platform/virt.h>

Go to the source code of this file.

Functions

void aarch64_preempt (void)
 Switches away from this CPU's running thread, which stays ready, to the next ready thread.
static void sched_tick (void)
 Runs the timer tick: charges the running process for it, and asks for a switch, which happens once the GIC is done with the interrupt (cpu/trap.c).
void arch_sched_init (void)
 Starts the timer tick on every CPU, and the clock where it needs to be started.
static void __arch_idle (void)
 Runs the idle loop, on the CPU's idle stack.
void arch_idle (void)
 Makes this CPU idle, on its idle stack, until an interrupt makes a thread ready.
static void __arch_cur_thread_kill (void)
 Frees the running thread, from the CPU's idle stack, and idles.
void arch_cur_thread_kill (void)
 Ends the current thread.
void arch_yield (void)
 Puts the current thread at the end of the ready list, and runs the next ready thread.
void arch_sleep (void)
 Puts the current thread to sleep.

Variables

static uint64_t timer_period
static uint64_t timer_ticks
struct aarch64_regs * aarch64_irq_regs

Detailed Description

aarch64: the timer tick, the idle loop, and the running thread giving up its CPU.

The running thread gives up its CPU when it sleeps, yields, or is killed. A thread that is killed is freed from the CPU's idle stack, since its own stack goes with it.

Definition in file sched.c.

Function Documentation

◆ __arch_cur_thread_kill()

void __arch_cur_thread_kill ( void )
static

Frees the running thread, from the CPU's idle stack, and idles.

Definition at line 69 of file sched.c.

References __arch_cur_thread_kill(), curthread, kernel_idle(), kfree(), NULL, thread_kill(), and ZOMBIE.

Referenced by __arch_cur_thread_kill(), and arch_cur_thread_kill().

◆ __arch_idle()

void __arch_idle ( void )
static

Runs the idle loop, on the CPU's idle stack.

It lets go of the kernel lock first; an interrupt takes it, and lets go of it again if it comes back here.

Definition at line 51 of file sched.c.

References __arch_idle(), kernel_lock_held(), and kernel_unlock().

Referenced by __arch_idle(), and arch_idle().

◆ aarch64_preempt()

void aarch64_preempt ( void )

Switches away from this CPU's running thread, which stays ready, to the next ready thread.

When the thread is chosen again, it goes on from here.

Definition at line 188 of file trap.c.

◆ arch_cur_thread_kill()

void arch_cur_thread_kill ( void )

Ends the current thread.

Its kernel stack is freed with it, so this switches to the CPU's idle stack first. It doesn't return.

Definition at line 87 of file sched.c.

References __arch_cur_thread_kill(), aarch64_goto(), and arch_cur_thread_kill().

Referenced by arch_cur_thread_kill(), proc_kill(), sched_thread_killed(), and sys_thread_exit().

◆ arch_idle()

void arch_idle ( void )

Makes this CPU idle, on its idle stack, until an interrupt makes a thread ready.

It doesn't return.

Definition at line 62 of file sched.c.

References __arch_idle(), aarch64_goto(), arch_idle(), curthread, and NULL.

Referenced by arch_idle(), kernel_idle(), and x86_ap_start().

◆ arch_sched_init()

void arch_sched_init ( void )

Starts the timer tick on every CPU, and the clock where it needs to be started.

Definition at line 43 of file sched.c.

References arch_sched_init(), sched_tick(), timer_period, and timer_setup().

Referenced by arch_sched_init(), and sched_init_spawn().

◆ arch_sleep()

void arch_sleep ( void )

Puts the current thread to sleep.

It stops here, and the next ready thread runs, or the CPU idles; it returns once the thread is woken up and chosen to run again.

Definition at line 101 of file sched.c.

References aarch64_ctx_save(), arch_sleep(), aarch64_thread::ctx, curthread, and kernel_idle().

Referenced by arch_sleep(), proc_execve(), signal_exit(), sleep_on(), and sys_exit().

◆ arch_yield()

void arch_yield ( void )

Puts the current thread at the end of the ready list, and runs the next ready thread.

Definition at line 94 of file sched.c.

References aarch64_preempt(), and arch_yield().

Referenced by arch_yield(), and net_main().

◆ sched_tick()

void sched_tick ( void )
static

Runs the timer tick: charges the running process for it, and asks for a switch, which happens once the GIC is done with the interrupt (cpu/trap.c).

Definition at line 28 of file sched.c.

References aarch64_irq_regs, REGS_USER, sched_tick(), sched_timer_tick(), time_resync(), timer_period, and timer_ticks.

Referenced by arch_sched_init(), and sched_tick().

Variable Documentation

◆ aarch64_irq_regs

struct aarch64_regs* aarch64_irq_regs
extern

Definition at line 183 of file trap.c.

Referenced by aarch64_irq(), and sched_tick().

◆ timer_period

uint64_t timer_period
static

Definition at line 19 of file sched.c.

Referenced by arch_sched_init(), sched_tick(), and x86_sched_handler().

◆ timer_ticks

uint64_t timer_ticks
static

Definition at line 20 of file sched.c.

Referenced by sched_tick(), and x86_sched_handler().