The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
scheduler.h File Reference

Go to the source code of this file.

Macros

#define SCHED_TIME_SLICE   2
 number of PIT ticks per scheduling time slice (~20ms at 100Hz).

Functions

void scheduler_init (void)
 initialize the scheduler.
bool scheduler_run_core (void)
 make the code that runs the call the idle task of its core, and run processes on the core from now on.
void scheduler_ready (process_t *proc)
 add a process to a run queue: the queue of the core it last ran on, or of an idle core (scheduler.c).
void scheduler_remove (process_t *proc)
 remove a process from its run queue.
void scheduler_kick (process_t *proc)
 make a process that runs on another core enter the kernel now (a reschedule IPI), so that it acts on a new signal at once and not at the end of its time slice (Linux's kick_process).
void scheduler_ready_locked (process_t *proc)
 scheduler_ready() for a caller that holds sched_lock.
void scheduler_remove_locked (process_t *proc)
 scheduler_remove() for a caller that holds sched_lock.
process_t * scheduler_pull_locked (cpu_t *cpu, uint32_t min_load)
 move the process at the head of the queue of the busiest other core to the queue of a core (load balancing).
void schedule_locked (void)
 switch to the next ready process.
void scheduler_unlock (uint32_t flags)
 release sched_lock and restore the interrupt state.
void scheduler_finish (uint32_t flags)
 scheduler_unlock() after schedule_locked(): it also frees the orphans that exited on the stack this core left.
void scheduler_tail (void)
 the first call of a new process (the idle task, the start of a program, a fork child): release the sched_lock that the switch to it holds.
void scheduler_tick (void)
 called from the PIT IRQ handler on every tick.
void scheduler_yield (void)
 voluntarily yield the CPU to the next ready process.
bool scheduler_is_active (void)
 check whether the scheduler has started switching processes.

Variables

spinlock_t sched_lock
 the lock of the run queues, the state of each process and the list of each wait queue.

Macro Definition Documentation

◆ SCHED_TIME_SLICE

#define SCHED_TIME_SLICE   2

number of PIT ticks per scheduling time slice (~20ms at 100Hz).

Function Documentation

◆ scheduler_init()

void scheduler_init ( void )

initialize the scheduler.

must be called after process_init().

◆ scheduler_run_core()

bool scheduler_run_core ( void )

make the code that runs the call the idle task of its core, and run processes on the core from now on.

call it once on each core other than the boot core, with interrupts off, after scheduler_init().

Returns
false if there is no memory for the idle task. on success it does not return.

◆ scheduler_ready()

void scheduler_ready ( process_t * proc)

add a process to a run queue: the queue of the core it last ran on, or of an idle core (scheduler.c).

an idle core gets a reschedule IPI.

Parameters
procthe process to enqueue.

◆ scheduler_remove()

void scheduler_remove ( process_t * proc)

remove a process from its run queue.

used when a process exits or blocks.

Parameters
procthe process to remove.

◆ scheduler_kick()

void scheduler_kick ( process_t * proc)

make a process that runs on another core enter the kernel now (a reschedule IPI), so that it acts on a new signal at once and not at the end of its time slice (Linux's kick_process).

nothing is done for a process that does not run, or that runs on this core.

Parameters
procthe process.

◆ scheduler_ready_locked()

void scheduler_ready_locked ( process_t * proc)

scheduler_ready() for a caller that holds sched_lock.

Parameters
procthe process to enqueue.

◆ scheduler_remove_locked()

void scheduler_remove_locked ( process_t * proc)

scheduler_remove() for a caller that holds sched_lock.

Parameters
procthe process to remove.

◆ scheduler_pull_locked()

process_t * scheduler_pull_locked ( cpu_t * cpu,
uint32_t min_load )

move the process at the head of the queue of the busiest other core to the queue of a core (load balancing).

the load of a core is the processes in its queue, plus one if it runs a process.

Parameters
cputhe core that takes the process.
min_loadthe least load that the busiest core must have.
Returns
the process that moved, or NULL if no core has a process in its queue and at least min_load.

◆ schedule_locked()

void schedule_locked ( void )

switch to the next ready process.

call it with sched_lock held and interrupts masked. it returns when this process runs again, with sched_lock held again (by the core that switched back to it).

◆ scheduler_unlock()

void scheduler_unlock ( uint32_t flags)

release sched_lock and restore the interrupt state.

Parameters
flagsthe value from spin_lock_irqsave(&sched_lock).

◆ scheduler_finish()

void scheduler_finish ( uint32_t flags)

scheduler_unlock() after schedule_locked(): it also frees the orphans that exited on the stack this core left.

Parameters
flagsthe value from spin_lock_irqsave(&sched_lock).

◆ scheduler_tail()

void scheduler_tail ( void )

the first call of a new process (the idle task, the start of a program, a fork child): release the sched_lock that the switch to it holds.

◆ scheduler_tick()

void scheduler_tick ( void )

called from the PIT IRQ handler on every tick.

decrements the time slice counter and triggers a context switch when the slice expires.

◆ scheduler_yield()

void scheduler_yield ( void )

voluntarily yield the CPU to the next ready process.

can be called from kernel code (e.g. when a process blocks).

◆ scheduler_is_active()

bool scheduler_is_active ( void )

check whether the scheduler has started switching processes.

it starts with the first scheduler_ready(); until then (the first /bin/sh runs on the boot stack) scheduler_yield() returns at once, so nothing can block.

Returns
true once processes can be switched.

Variable Documentation

◆ sched_lock

spinlock_t sched_lock
extern

the lock of the run queues, the state of each process and the list of each wait queue.

the innermost lock: take no other lock while it is held. take it with spin_lock_irqsave() and release it with scheduler_unlock().