PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
sched.c File Reference
#include <kernel/config.h>
#include <kernel/cpu/ipi.h>
#include <kernel/cpu/irq.h>
#include <kernel/sched/sched.h>
#include <kernel/cpu/cpu.h>
#include <kernel/cpu/gdt.h>
#include <kernel/cpu/interrupt.h>
#include <kernel/cpu/syscall.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/proc/process.h>
#include <kernel/sched/clock.h>
#include <kernel/sched/thread.h>
#include <kernel/sched/timer.h>
#include <kernel/sched/wait.h>
#include <kernel/sync/lock.h>
#include <kernel/utils/rbtree.h>
#include <assert.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/bitmap.h>
#include <sys/list.h>
#include <sys/math.h>
#include <sys/proc.h>
#include <time.h>
Include dependency graph for sched.c:

Go to the source code of this file.

Functions

static _Atomic (clock_t)
 
static int64_t sched_node_compare (const rbnode_t *aNode, const rbnode_t *bNode)
 
static void sched_node_update (rbnode_t *node)
 
 PERCPU_DEFINE_CTOR (sched_t, _pcpu_sched)
 
static bool sched_is_cache_hot (thread_t *thread, clock_t uptime)
 
void sched_client_init (sched_client_t *client)
 Initialize the scheduler context for a thread.
 
void sched_client_update_veligible (sched_client_t *client, vclock_t newVeligible)
 
static void sched_vtime_reset (sched_t *sched, clock_t uptime)
 
static void sched_vtime_update (sched_t *sched, clock_t uptime)
 
static void sched_enter (sched_t *sched, thread_t *thread, clock_t uptime)
 
static void sched_leave (sched_t *sched, thread_t *thread, clock_t uptime)
 
static cpu_tsched_get_least_loaded (void)
 
static thread_tsched_steal (void)
 
static thread_tsched_first_eligible (sched_t *sched)
 
void sched_start (thread_t *bootThread)
 Starts the scheduler by jumping to the boot thread.
 
void sched_submit (thread_t *thread)
 Submits a thread to the scheduler.
 
static void sched_verify_min_eligible (sched_t *sched, rbnode_t *node)
 
static void sched_verify (sched_t *sched)
 
void sched_do (interrupt_frame_t *frame)
 Perform a scheduling operation.
 
bool sched_is_idle (cpu_t *cpu)
 Checks if the CPU is currently idle.
 
uint64_t sched_nanosleep (clock_t timeout)
 Sleeps the current thread for a specified duration in nanoseconds.
 
void sched_yield (void)
 Yield the current thread's time slice to allow other threads to run.
 
void sched_disable (void)
 Disables preemption on the current CPU.
 
void sched_enable (void)
 Enables preemption on the current CPU.
 
void sched_exits (const char *status)
 Terminates the currently executing process and all it's threads.
 
void sched_thread_exit (void)
 Terminates the currently executing thread.
 
 SYSCALL_DEFINE (SYS_NANOSLEEP, uint64_t, clock_t nanoseconds)
 
 SYSCALL_DEFINE (SYS_EXITS, void, const char *status)
 
 SYSCALL_DEFINE (SYS_THREAD_EXIT, void)
 
 SYSCALL_DEFINE (SYS_YIELD, uint64_t)
 

Variables

static wait_queue_t sleepQueue = WAIT_QUEUE_CREATE(sleepQueue)
 

Function Documentation

◆ _Atomic()

static _Atomic ( clock_t  )
static

Definition at line 32 of file sched.c.

◆ sched_node_compare()

static int64_t sched_node_compare ( const rbnode_t aNode,
const rbnode_t bNode 
)
static

Definition at line 50 of file sched.c.

Here is the caller graph for this function:

◆ sched_node_update()

static void sched_node_update ( rbnode_t node)
static

Definition at line 78 of file sched.c.

Here is the caller graph for this function:

◆ PERCPU_DEFINE_CTOR()

PERCPU_DEFINE_CTOR ( sched_t  ,
_pcpu_sched   
)

Definition at line 100 of file sched.c.

Here is the call graph for this function:

◆ sched_is_cache_hot()

static bool sched_is_cache_hot ( thread_t thread,
clock_t  uptime 
)
static

Definition at line 127 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_client_update_veligible()

void sched_client_update_veligible ( sched_client_t client,
vclock_t  newVeligible 
)

Definition at line 145 of file sched.c.

Here is the caller graph for this function:

◆ sched_vtime_reset()

static void sched_vtime_reset ( sched_t sched,
clock_t  uptime 
)
static

Definition at line 155 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_vtime_update()

static void sched_vtime_update ( sched_t sched,
clock_t  uptime 
)
static

Definition at line 164 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_enter()

static void sched_enter ( sched_t sched,
thread_t thread,
clock_t  uptime 
)
static

Definition at line 187 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_leave()

static void sched_leave ( sched_t sched,
thread_t thread,
clock_t  uptime 
)
static

Definition at line 206 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_get_least_loaded()

static cpu_t * sched_get_least_loaded ( void  )
static

Definition at line 229 of file sched.c.

Here is the caller graph for this function:

◆ sched_steal()

static thread_t * sched_steal ( void  )
static

Definition at line 252 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_first_eligible()

static thread_t * sched_first_eligible ( sched_t sched)
static

Definition at line 302 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_verify_min_eligible()

static void sched_verify_min_eligible ( sched_t sched,
rbnode_t node 
)
static

Definition at line 415 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched_verify()

static void sched_verify ( sched_t sched)
static

Definition at line 449 of file sched.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCALL_DEFINE() [1/4]

SYSCALL_DEFINE ( SYS_NANOSLEEP  ,
uint64_t  ,
clock_t  nanoseconds 
)

Definition at line 672 of file sched.c.

Here is the call graph for this function:

◆ SYSCALL_DEFINE() [2/4]

SYSCALL_DEFINE ( SYS_EXITS  ,
void  ,
const char *  status 
)

Definition at line 677 of file sched.c.

Here is the call graph for this function:

◆ SYSCALL_DEFINE() [3/4]

SYSCALL_DEFINE ( SYS_THREAD_EXIT  ,
void   
)

Definition at line 684 of file sched.c.

Here is the call graph for this function:

◆ SYSCALL_DEFINE() [4/4]

SYSCALL_DEFINE ( SYS_YIELD  ,
uint64_t   
)

Definition at line 691 of file sched.c.

Here is the call graph for this function:

Variable Documentation

◆ sleepQueue

wait_queue_t sleepQueue = WAIT_QUEUE_CREATE(sleepQueue)
static

Definition at line 30 of file sched.c.