PatchworkOS  da8a090
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/sched/process.h>
#include <kernel/sched/sys_time.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)
 
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_init (sched_t *sched)
 Initialize the scheduler for a CPU.
 
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, cpu_t *self)
 Perform a scheduling operation.
 
bool sched_is_idle (cpu_t *cpu)
 Checks if the CPU is currently 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.
 
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_process_exit (int32_t 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_PROCESS_EXIT, void, int32_t 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 49 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 75 of file sched.c.

Here is the caller graph for this function:

◆ sched_is_cache_hot()

static bool sched_is_cache_hot ( thread_t thread,
clock_t  uptime 
)
static

Definition at line 97 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 115 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 125 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 134 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 157 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 176 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 199 of file sched.c.

Here is the caller graph for this function:

◆ sched_steal()

static thread_t * sched_steal ( void  )
static

Definition at line 222 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 276 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 409 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 443 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 669 of file sched.c.

Here is the call graph for this function:

◆ SYSCALL_DEFINE() [2/4]

SYSCALL_DEFINE ( SYS_PROCESS_EXIT  ,
void  ,
int32_t  status 
)

Definition at line 674 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 681 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 688 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.