PatchworkOS
Loading...
Searching...
No Matches
sched.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/defs.h>
4#include <kernel/sched/wait.h>
5#include <kernel/sync/lock.h>
6
7#include <sys/list.h>
8#include <sys/proc.h>
9
10typedef struct process process_t;
11typedef struct thread thread_t;
12
47
86
132
139
149
157NORETURN extern void sched_idle_loop(void);
158
167
175
182bool sched_is_idle(cpu_t* cpu);
183
190
200
207
217
227
236
244void sched_yield(void);
245
255void sched_push(thread_t* thread, cpu_t* target);
256
266void sched_push_new_thread(thread_t* thread, thread_t* parent);
267
274typedef enum
275{
277 SCHED_DIE = 1 << 0,
279
289void sched_invoke(interrupt_frame_t* frame, cpu_t* self, schedule_flags_t flags);
290
#define NORETURN
GCC noreturn function attribute.
Definition defs.h:39
void sched_push_new_thread(thread_t *thread, thread_t *parent)
Pushes a newly created thread onto the scheduling queue.
Definition sched.c:385
void sched_push(thread_t *thread, cpu_t *target)
Pushes a thread onto a scheduling queue.
Definition sched.c:305
process_t * sched_process(void)
Retrieves the process of the currently running thread.
Definition sched.c:164
NORETURN void sched_done_with_boot_thread(void)
Specify that the boot thread is no longer needed.
Definition sched.c:121
thread_t * sched_thread(void)
Retrieves the currently running thread.
Definition sched.c:157
void sched_thread_ctx_init(sched_thread_ctx_t *ctx)
Initializes a thread's scheduling context.
Definition sched.c:69
void sched_yield(void)
Yields the CPU to another thread.
Definition sched.c:277
void sched_cpu_ctx_init(sched_cpu_ctx_t *ctx, cpu_t *self)
Initializes a CPU's scheduling context.
Definition sched.c:83
thread_t * sched_thread_unsafe(void)
Retrieves the currently running thread without disabling interrupts.
Definition sched.c:175
bool sched_is_idle(cpu_t *cpu)
Checks if the CPU is idle.
Definition sched.c:149
_NORETURN void sched_process_exit(uint64_t status)
Exits the current process.
Definition sched.c:191
void sched_invoke(interrupt_frame_t *frame, cpu_t *self, schedule_flags_t flags)
The main scheduling function.
Definition sched.c:480
uint64_t sched_nanosleep(clock_t timeout)
Puts the current thread to sleep.
Definition sched.c:139
process_t * sched_process_unsafe(void)
Retrieves the process of the currently running thread without disabling interrupts.
Definition sched.c:180
NORETURN void sched_idle_loop(void)
The idle loop for a CPU.
schedule_flags_t
Scheduling flags.
Definition sched.h:275
_NORETURN void sched_thread_exit(void)
Exits the current thread.
Definition sched.c:205
@ SCHED_NORMAL
No special flags.
Definition sched.h:276
@ SCHED_DIE
Kill and free the currently running thread.
Definition sched.h:277
#define PRIORITY_MAX
Definition proc.h:42
uint8_t priority_t
Priority type.
Definition proc.h:41
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
#define _NORETURN
Definition config.h:28
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
CPU structure.
Definition cpu.h:42
Trap Frame Structure.
Definition interrupt.h:42
A doubly linked list.
Definition list.h:51
A simple ticket lock implementation.
Definition lock.h:43
Process structure.
Definition process.h:53
Per-CPU scheduling context.
Definition sched.h:95
cpu_t * owner
The cpu that owns this scheduling context.
Definition sched.h:130
thread_t * runThread
The currently running thread.
Definition sched.h:119
sched_queues_t * expired
Pointer to the currently expired queue.
Definition sched.h:110
sched_queues_t * active
Pointer to the currently active queue.
Definition sched.h:106
thread_t * idleThread
The thread that runs when the owner CPU is idling.
Definition sched.h:125
lock_t lock
The lock that protects this context, except the zombieThreads list.
Definition sched.h:129
Scheduling queues structure.
Definition sched.h:33
uint64_t length
The total number of threads in all lists.
Definition sched.h:37
uint64_t bitmap
A bitmap indicating which of the lists have threads in them.
Definition sched.h:41
Per-thread scheduling context.
Definition sched.h:56
clock_t recentBlockTime
The amount of time within the last CONFIG_MAX_RECENT_BLOCK_TIME nanoseconds that the thread was block...
Definition sched.h:80
clock_t prevBlockCheck
The previous time when the recentBlockTime member was updated.
Definition sched.h:84
priority_t actualPriority
The actual priority of the thread.
Definition sched.h:72
clock_t deadline
The time when the time slice will actually expire, only valid while the thread is running.
Definition sched.h:64
clock_t timeSlice
The length of the threads time slice, used to determine its deadline when its scheduled.
Definition sched.h:60
Thread of execution structure.
Definition thread.h:55