PatchworkOS
Loading...
Searching...
No Matches
sched.c File Reference
#include <kernel/sched/sched.h>
#include <kernel/cpu/cpu.h>
#include <kernel/cpu/gdt.h>
#include <kernel/cpu/interrupt.h>
#include <kernel/cpu/smp.h>
#include <kernel/cpu/syscalls.h>
#include <kernel/drivers/apic.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/proc/process.h>
#include <kernel/sched/thread.h>
#include <kernel/sched/timer.h>
#include <kernel/sched/wait.h>
#include <kernel/sync/lock.h>
#include <assert.h>
#include <sys/list.h>
#include <sys/math.h>
#include <sys/proc.h>

Go to the source code of this file.

Functions

static void sched_queues_init (sched_queues_t *queues)
 
static void sched_queues_push (sched_queues_t *queues, thread_t *thread)
 
static thread_tsched_queues_pop (sched_queues_t *queues, priority_t minPriority)
 
void sched_thread_ctx_init (sched_thread_ctx_t *ctx)
 Initializes a thread's scheduling context.
 
static void sched_timer_handler (interrupt_frame_t *frame, cpu_t *self)
 
void sched_cpu_ctx_init (sched_cpu_ctx_t *ctx, cpu_t *self)
 Initializes a CPU's scheduling context.
 
void sched_done_with_boot_thread (void)
 Specify that the boot thread is no longer needed.
 
uint64_t sched_nanosleep (clock_t timeout)
 Puts the current thread to sleep.
 
 SYSCALL_DEFINE (SYS_NANOSLEEP, uint64_t, clock_t nanoseconds)
 
bool sched_is_idle (cpu_t *cpu)
 Checks if the CPU is idle.
 
thread_tsched_thread (void)
 Retrieves the currently running thread.
 
process_tsched_process (void)
 Retrieves the process of the currently running thread.
 
thread_tsched_thread_unsafe (void)
 Retrieves the currently running thread without disabling interrupts.
 
process_tsched_process_unsafe (void)
 Retrieves the process of the currently running thread without disabling interrupts.
 
void sched_process_exit (uint64_t status)
 Exits the current process.
 
 SYSCALL_DEFINE (SYS_PROCESS_EXIT, void, uint64_t status)
 
void sched_thread_exit (void)
 Exits the current thread.
 
 SYSCALL_DEFINE (SYS_THREAD_EXIT, void)
 
static void sched_update_recent_idle_time (thread_t *thread, bool wasBlocking, clock_t uptime)
 
static void sched_compute_time_slice (thread_t *thread, thread_t *parent)
 
static void sched_compute_actual_priority (thread_t *thread)
 
void sched_yield (void)
 Yields the CPU to another thread.
 
 SYSCALL_DEFINE (SYS_YIELD, uint64_t)
 
static bool sched_should_notify (cpu_t *target, priority_t priority)
 
void sched_push (thread_t *thread, cpu_t *target)
 Pushes a thread onto a scheduling queue.
 
static uint64_t sched_get_load (sched_cpu_ctx_t *ctx)
 
static cpu_tsched_find_least_loaded_cpu (cpu_t *exclude)
 
void sched_push_new_thread (thread_t *thread, thread_t *parent)
 Pushes a newly created thread onto the scheduling queue.
 
static cpu_tsched_get_neighbor (cpu_t *self)
 
static void sched_load_balance (cpu_t *self)
 
void sched_invoke (interrupt_frame_t *frame, cpu_t *self, schedule_flags_t flags)
 The main scheduling function.
 

Variables

static wait_queue_t sleepQueue = WAIT_QUEUE_CREATE(sleepQueue)
 

Function Documentation

◆ sched_compute_actual_priority()

◆ sched_compute_time_slice()

◆ sched_find_least_loaded_cpu()

static cpu_t * sched_find_least_loaded_cpu ( cpu_t exclude)
static

Definition at line 348 of file sched.c.

References NULL, cpu_t::sched, sched_get_load(), smp_cpu(), smp_cpu_amount(), and UINT64_MAX.

Referenced by sched_push_new_thread().

◆ sched_get_load()

◆ sched_get_neighbor()

static cpu_t * sched_get_neighbor ( cpu_t self)
static

Definition at line 420 of file sched.c.

References cpu_t::id, NULL, smp_cpu(), and smp_cpu_amount().

Referenced by sched_load_balance().

◆ sched_load_balance()

◆ sched_queues_init()

static void sched_queues_init ( sched_queues_t queues)
inlinestatic

◆ sched_queues_pop()

static thread_t * sched_queues_pop ( sched_queues_t queues,
priority_t  minPriority 
)
inlinestatic

◆ sched_queues_push()

◆ sched_should_notify()

static bool sched_should_notify ( cpu_t target,
priority_t  priority 
)
static

◆ sched_timer_handler()

static void sched_timer_handler ( interrupt_frame_t frame,
cpu_t self 
)
static

Definition at line 78 of file sched.c.

References sched_invoke(), and SCHED_NORMAL.

Referenced by sched_cpu_ctx_init().

◆ sched_update_recent_idle_time()

static void sched_update_recent_idle_time ( thread_t thread,
bool  wasBlocking,
clock_t  uptime 
)
static

◆ SYSCALL_DEFINE() [1/4]

SYSCALL_DEFINE ( SYS_NANOSLEEP  ,
uint64_t  ,
clock_t  nanoseconds 
)

Definition at line 144 of file sched.c.

References sched_nanosleep().

◆ SYSCALL_DEFINE() [2/4]

SYSCALL_DEFINE ( SYS_PROCESS_EXIT  ,
void  ,
uint64_t  status 
)

Definition at line 199 of file sched.c.

References NULL, panic(), and sched_process_exit().

◆ SYSCALL_DEFINE() [3/4]

SYSCALL_DEFINE ( SYS_THREAD_EXIT  ,
void   
)

Definition at line 211 of file sched.c.

References NULL, panic(), and sched_thread_exit().

◆ SYSCALL_DEFINE() [4/4]

SYSCALL_DEFINE ( SYS_YIELD  ,
uint64_t   
)

Definition at line 284 of file sched.c.

References sched_yield(), and timer_notify_self().

Variable Documentation

◆ sleepQueue

wait_queue_t sleepQueue = WAIT_QUEUE_CREATE(sleepQueue)
static

Definition at line 23 of file sched.c.

Referenced by sched_nanosleep().