The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
scheduler.h
Go to the documentation of this file.
1#pragma once
2
3#include "kernel/cpu/cpu.h"
6
7/** number of PIT ticks per scheduling time slice (~20ms at 100Hz). */
8#define SCHED_TIME_SLICE 2
9
10/**
11 * initialize the scheduler.
12 * must be called after process_init().
13 */
14void scheduler_init(void);
15
16/**
17 * make the code that runs the call the idle task of its core, and run
18 * processes on the core from now on. call it once on each core other
19 * than the boot core, with interrupts off, after scheduler_init().
20 * @return false if there is no memory for the idle task. on success it
21 * does not return.
22 */
23bool scheduler_run_core(void);
24
25/**
26 * add a process to a run queue: the queue of the core it last ran on, or
27 * of an idle core (scheduler.c). an idle core gets a reschedule IPI.
28 * @param proc the process to enqueue.
29 */
30void scheduler_ready(process_t *proc);
31
32/**
33 * remove a process from its run queue.
34 * used when a process exits or blocks.
35 * @param proc the process to remove.
36 */
37void scheduler_remove(process_t *proc);
38
39/**
40 * make a process that runs on another core enter the kernel now (a
41 * reschedule IPI), so that it acts on a new signal at once and not at the
42 * end of its time slice (Linux's kick_process). nothing is done for a
43 * process that does not run, or that runs on this core.
44 * @param proc the process.
45 */
46void scheduler_kick(process_t *proc);
47
48/**
49 * the lock of the run queues, the state of each process and the list of
50 * each wait queue. the innermost lock: take no other lock while it is
51 * held. take it with spin_lock_irqsave() and release it with
52 * scheduler_unlock().
53 */
55
56/**
57 * scheduler_ready() for a caller that holds sched_lock.
58 * @param proc the process to enqueue.
59 */
61
62/**
63 * scheduler_remove() for a caller that holds sched_lock.
64 * @param proc the process to remove.
65 */
67
68/**
69 * move the process at the head of the queue of the busiest other core to
70 * the queue of a core (load balancing). the load of a core is the
71 * processes in its queue, plus one if it runs a process.
72 * @param cpu the core that takes the process.
73 * @param min_load the least load that the busiest core must have.
74 * @return the process that moved, or NULL if no core has a process in
75 * its queue and at least min_load.
76 */
78
79/**
80 * switch to the next ready process. call it with sched_lock held and
81 * interrupts masked. it returns when this process runs again, with
82 * sched_lock held again (by the core that switched back to it).
83 */
84void schedule_locked(void);
85
86/**
87 * release sched_lock and restore the interrupt state.
88 * @param flags the value from spin_lock_irqsave(&sched_lock).
89 */
91
92/**
93 * scheduler_unlock() after schedule_locked(): it also frees the orphans
94 * that exited on the stack this core left.
95 * @param flags the value from spin_lock_irqsave(&sched_lock).
96 */
98
99/**
100 * the first call of a new process (the idle task, the start of a program,
101 * a fork child): release the sched_lock that the switch to it holds.
102 */
103void scheduler_tail(void);
104
105/**
106 * called from the PIT IRQ handler on every tick.
107 * decrements the time slice counter and triggers a context switch
108 * when the slice expires.
109 */
110void scheduler_tick(void);
111
112/**
113 * voluntarily yield the CPU to the next ready process.
114 * can be called from kernel code (e.g. when a process blocks).
115 */
116void scheduler_yield(void);
117
118/**
119 * check whether the scheduler has started switching processes. it starts
120 * with the first scheduler_ready(); until then (the first /bin/sh runs on
121 * the boot stack) scheduler_yield() returns at once, so nothing can block.
122 * @return true once processes can be switched.
123 */
124bool scheduler_is_active(void);
the data of each core (per-CPU data).
struct cpu cpu_t
the data of one core
uint8_t flags
Definition idt.c:3
unsigned int uint32_t
Definition fb.h:17
struct process process_t
process control block.
void scheduler_tick(void)
called from the PIT IRQ handler on every tick.
Definition scheduler.c:546
void scheduler_remove(process_t *proc)
remove a process from its run queue.
Definition scheduler.c:396
bool scheduler_is_active(void)
check whether the scheduler has started switching processes.
Definition scheduler.c:541
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...
Definition scheduler.c:326
void scheduler_ready_locked(process_t *proc)
scheduler_ready() for a caller that holds sched_lock.
Definition scheduler.c:346
void scheduler_unlock(uint32_t flags)
release sched_lock and restore the interrupt state.
Definition scheduler.c:408
void scheduler_tail(void)
the first call of a new process (the idle task, the start of a program, a fork child): release the sc...
Definition scheduler.c:440
void schedule_locked(void)
switch to the next ready process.
Definition scheduler.c:457
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 ...
Definition scheduler.c:374
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 bala...
Definition scheduler.c:250
spinlock_t sched_lock
the lock of the run queues, the state of each process and the list of each wait queue.
Definition scheduler.c:41
void scheduler_finish(uint32_t flags)
scheduler_unlock() after schedule_locked(): it also frees the orphans that exited on the stack this c...
Definition scheduler.c:414
void scheduler_init(void)
initialize the scheduler.
Definition scheduler.c:305
void scheduler_yield(void)
voluntarily yield the CPU to the next ready process.
Definition scheduler.c:579
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....
Definition scheduler.c:384
void scheduler_remove_locked(process_t *proc)
scheduler_remove() for a caller that holds sched_lock.
Definition scheduler.c:364
the data of one core
Definition cpu.h:39
kernel locking rules:
Definition spinlock.h:67