AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
sched.h
Go to the documentation of this file.
1#ifndef _SYS_SCHED_H
2#define _SYS_SCHED_H
3
4#include <core/system.h>
5#include <sys/proc.h>
6#include <sys/cpu.h>
7#include <sys/waitq.h>
8
9/* The scheduler (sys/sched.c). */
10
11/* The thread running on this CPU (NULL when it's idle), and its process. */
12#define curthread (curcpu()->thread)
13#define curproc (curthread->owner)
14
15/* Whether processes run, and a thread may sleep (before that, at boot,
16 * only the kernel runs). */
17extern int sched_running;
18void kernel_idle(void);
19void scheduler_init(void);
20void sched_thread_spawn(struct thread *thread);
21void sched_init_spawn(struct proc *init);
22void schedule(void);
23void sched_idle_wakeup(void);
24
25/* Makes a thread ready to run; makes a woken thread ready. */
26void sched_thread_ready(struct thread *thread);
27void sched_thread_wake(struct thread *thread);
28
29/* An urgent thread was woken up (thread->urgent): it runs once the
30 * interrupt returns. */
31extern int sched_urgent;
32
33/* The ticks: the boot CPU's, and every CPU's. */
34void sched_timer_tick(uint32_t period, int user);
35void sched_cpu_tick(uint32_t period, int user);
36
37/* Finds the other CPU that runs `thread`; makes it enter the kernel now;
38 * ends the current thread, which was killed. */
39struct cpu *sched_thread_cpu(struct thread *thread);
40void sched_thread_kick(struct thread *thread);
41void sched_thread_killed(void);
42
43/* Sleeping until a time, or on a wait queue with a deadline; the real
44 * time timers. */
45int sched_sleep(uint64_t until);
46int sched_wait(struct waitq *waitq, uint64_t until);
47void sched_timer_cancel(struct thread *thread);
48void sched_alarm(struct proc *proc, uint64_t value, uint64_t interval,
49 uint64_t *old_value, uint64_t *old_interval);
50void sched_alarm_get(struct proc *proc, uint64_t *value, uint64_t *interval);
51
52#endif /* ! _SYS_SCHED_H */
void sched_init_spawn(struct proc *init)
Starts the scheduler with the first process, init, and runs it.
Definition sched.c:375
void sched_idle_wakeup(void)
Runs a ready thread now if an interrupt made one ready while this CPU was idle, rather than at the ne...
Definition sched.c:347
int sched_urgent
Definition sched.c:306
void sched_cpu_tick(uint32_t period, int user)
Charges a timer tick to the process that was running on this CPU.
Definition sched.c:54
void sched_alarm_get(struct proc *proc, uint64_t *value, uint64_t *interval)
Reads what is left of a process's real time timer.
Definition sched.c:121
void sched_thread_killed(void)
Ends the current thread, which was killed while it ran on this CPU (thread->killed).
Definition sched.c:258
int sched_wait(struct waitq *waitq, uint64_t until)
Puts the current thread to sleep on a wait queue until it is woken up, a signal ends the sleep,...
Definition sched.c:187
void sched_timer_cancel(struct thread *thread)
Takes a thread off the list of threads waiting with a deadline, when it no longer waits (it was woken...
Definition sched.c:173
void sched_alarm(struct proc *proc, uint64_t value, uint64_t interval, uint64_t *old_value, uint64_t *old_interval)
Sets a process's real time timer, which setitimer() and alarm() use: the process gets SIGALRM once va...
Definition sched.c:144
int sched_running
Definition sched.c:367
int sched_sleep(uint64_t until)
Puts the current thread to sleep until a time comes, for nanosleep().
Definition sched.c:212
void kernel_idle(void)
Gives up the CPU when the current thread can't run anymore (it sleeps, or it exited): the next ready ...
Definition sched.c:332
void scheduler_init(void)
void schedule(void)
Switches to the next ready thread.
Definition sched.c:400
void sched_timer_tick(uint32_t period, int user)
Runs the boot CPU's timer tick.
Definition sched.c:74
struct cpu * sched_thread_cpu(struct thread *thread)
Finds the CPU that is running a thread, if it's another CPU than this one.
Definition sched.c:229
void sched_thread_kick(struct thread *thread)
Makes a thread that runs on another CPU enter the kernel now, rather than at its next tick: a signal ...
Definition sched.c:244
void sched_thread_ready(struct thread *thread)
Puts a thread at the end of the ready list, to run in its turn.
Definition sched.c:298
void sched_thread_spawn(struct thread *thread)
Starts running a thread for the first time.
Definition sched.c:361
void sched_thread_wake(struct thread *thread)
Makes a thread that was sleeping ready to run.
Definition sched.c:315
unsigned int uint32_t
Definition stddef.h:22
unsigned long long int uint64_t
Definition stddef.h:23
A processor, and what runs on it.
Definition cpu.h:11
A process.
Definition proc.h:75
A thread.
Definition thread.h:23
Definition waitq.h:19
static uint64_t interval
Definition timer.c:16