XenevaOS
Loading...
Searching...
No Matches
Macros | Functions | Variables
sched.c File Reference
#include <stdint.h>
#include <Hal/AA64/aa64cpu.h>
#include <Hal/AA64/sched.h>
#include <Mm/pmmngr.h>
#include <Mm/kmalloc.h>
#include <Mm/vmmngr.h>
#include <string.h>
#include <_null.h>
#include <Hal/AA64/aa64lowlevel.h>
#include <Drivers/uart.h>
#include <Hal/AA64/gic.h>
#include <aucon.h>
#include <process.h>
#include <aurora.h>
#include <signal.h>
#include <timer.h>
#include <Sync/spinlock.h>
#include <Serv/sysserv.h>
Include dependency graph for sched.c:

Macros

#define SCHED_VALIDATE_STEPS   8192
 

Functions

void aa64_store_context (AA64Thread *thr)
 
void store_syscall (AA64Thread *thr)
 
bool aa64_restore_context (AA64Thread *thr)
 
void aa64_restore_sp (AA64Thread *thr)
 
void aa64_schedule_init (AA64Thread *current, AA64Thread *init, uint64_t va)
 
void ret_from_syscall (AA64Thread *thr)
 
void aa64_resume_exception_frame (AA64Registers *regs, uint64_t elr_el1, uint64_t spsr_el1) __attribute__((noreturn))
 
bool AuSchedValidateLists (void)
 AuSchedValidateLists – consistency-check all scheduler lists.
 
void first_time_sex (AA64Thread *thr)
 
void first_time_sex2 (AA64Thread *thr)
 
uint64_t read_sp ()
 
uint64_t AuSchedLock (void)
 
void AuSchedUnlock (uint64_t d)
 
void AuThreadInsert (AA64Thread *new_task)
 
void AuThreadDelete (AA64Thread *thread)
 
void AuThreadInsertBlock (AA64Thread *new_task)
 
void AuThreadDeleteBlock (AA64Thread *thread)
 
void AuThreadInsertTrash (AA64Thread *new_task)
 
void AuThreadDeleteTrash (AA64Thread *thread)
 
void AuThreadInsertSleep (AA64Thread *new_task)
 
void AuThreadDeleteSleep (AA64Thread *thread)
 
void AA64NextThread ()
 
AA64Thread * AuCreateKthread (void(*entry)(uint64_t), uint64_t *pml, char *name)
 AuCreateKthread – create kernel thread.
 
AA64Thread * AuCreateSubKthread (void(*entry)(uint64_t), uint64_t stack, uint64_t *pml, char *name)
 AuCreateSubKthread – create sub kernel thread of parent kthread.
 
void PrintThreadInfo ()
 
void AuIdleLoop (void)
 
void AuIdleThread (uint64_t ctx)
 
void resume_user (AA64Thread *thr, void *ksp)
 
void AuResumeUserThread ()
 
uint64_t read_x30 ()
 
void settimerdebug ()
 
void enscheddebug ()
 
void AuHandleSleepThreads ()
 
void PrintThrIn ()
 
void AuThreadSafeReturn (uint64_t rcx)
 
void AuScheduleThread (AA64Registers *regs)
 AuScheduleThread – the core of multi-tasking. It schedules threads next to be runned.
 
int AuSchedYieldMs (uint64_t ms)
 
void AuScheduleNext ()
 AuScheduleNext – forcefully schedule to idle thread.
 
uint64_t AuCreateKernelStack (uint64_t *pml)
 AuCreateKernelStack – maps kernel stack and return the top of the stack, it only maps 4KiB of stack.
 
uint64_t AuCreateSubKernelStack (AuProcess *proc, uint64_t *pml)
 AuCreateSubKernelStack – maps sub kernel stack and return the top of the stack, it only maps 4KiB of stack.
 
void AuSchedulerInitialize ()
 AuSchedulerInitialize – initialize the scheduler.
 
void AuSchedulerStart ()
 AuSchedulerStart – start the scheduler.
 
AA64Thread * AuGetIdleThread ()
 
AA64Thread * AuGetCurrentThread ()
 
void AuForceScheduler ()
 AuForceScheduler – force the scheduler to switch next thread.
 
void AuBlockThread (AA64Thread *thread)
 AuBlockThread – blocks a running thread.
 
void AuUnblockThread (AA64Thread *thread)
 AuUnblockThread – unblocks a thread and insert it to ready list.
 
void AuThreadWakePoller (AA64Thread *t)
 AuThreadWakePoller – wake up a thread that was left in sleep/block while polling.
 
void AuSleepThread (AA64Thread *thread, uint64_t ms)
 AuSleepThread – block a running thread and put it into sleep list.
 
void AuThreadMakeReady (AA64Thread *thread)
 AuThreadMakeReady – make a thread forcefully ready for next.
 
AA64Thread * AuThreadFindByID (uint64_t id)
 AuThreadFindByID – finds a thread by its id from ready queue.
 
AA64Thread * AuThreadFindByIDBlockList (uint64_t id)
 AuThreadFindByIDBlockList – finds a thread by its id from the block queue.
 
AA64Thread * AuThreadFindByIDSleepList (uint64_t id)
 AuThreadFindByIDSleepList – finds a thread by its id from the sleep queue.
 
void AuThreadMoveToTrash (AA64Thread *t)
 AuThreadMoveToTrash – move given thread to trash.
 
void AuThreadCleanTrash (AA64Thread *t)
 AuThreadCleanTrash – clean a thread from trash list.
 
uint64_t AuGetSystemTimerTick ()
 AuGetSystemTimerTick – return the current system timer tick.
 
void AuSetIdleThread (AA64Thread *thr)
 AuSetIdleThread – change the idle thread pointer.
 
int AuThreadWaitForTermination (int thread_id)
 AuThreadWaitForTermination – wait for desired thread termination.
 
void AuThreadAwakeWaiters (AA64Thread *thread)
 AuThreadAwakeWaiters – unblock all awaiting threads for the current thread @praram thread – current thread which waitlist needs to be freed.
 

Variables

AA64Thread * thread_list_head
 
AA64Thread * thread_list_last
 
AA64Thread * blocked_thr_head
 
AA64Thread * blocked_thr_last
 
AA64Thread * trash_thr_head
 
AA64Thread * trash_thr_last
 
AA64Thread * sleep_thr_head
 
AA64Thread * sleep_thr_last
 
AA64Thread * current_thread
 
AA64Thread * _idle_thr
 
uint64_t thread_id
 
bool _scheduler_initialized
 
uint64_t scheduler_tick
 
bool debug = 0
 

Detailed Description

BSD 2-Clause License

Copyright (c) 2022-2025, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ SCHED_VALIDATE_STEPS

#define SCHED_VALIDATE_STEPS   8192

Function Documentation

◆ aa64_restore_context()

bool aa64_restore_context ( AA64Thread *  thr)
extern

◆ aa64_restore_sp()

void aa64_restore_sp ( AA64Thread *  thr)
extern

◆ aa64_resume_exception_frame()

void aa64_resume_exception_frame ( AA64Registers *  regs,
uint64_t  elr_el1,
uint64_t  spsr_el1 
)
extern

◆ aa64_schedule_init()

void aa64_schedule_init ( AA64Thread *  current,
AA64Thread *  init,
uint64_t  va 
)
extern

◆ aa64_store_context()

void aa64_store_context ( AA64Thread *  thr)
extern

◆ AA64NextThread()

void AA64NextThread ( )

◆ AuBlockThread()

void AuBlockThread ( AA64Thread *  thread)

AuBlockThread – blocks a running thread.

Parameters
thread– Pointer to AA64 Thread

◆ AuCreateKernelStack()

uint64_t AuCreateKernelStack ( uint64_t *  pml)

AuCreateKernelStack – maps kernel stack and return the top of the stack, it only maps 4KiB of stack.

Parameters
pml– Pointer to page directory
Returns
kernel stack address

◆ AuCreateKthread()

AA64Thread * AuCreateKthread ( void(*)(uint64_t)  entry,
uint64_t *  pml,
char *  name 
)

AuCreateKthread – create kernel thread.

Parameters
entry– Pointer to entry point
pml– Pointer to Page directory
name– Name of the thread
Returns
Pointer to newly created thread

◆ AuCreateSubKernelStack()

uint64_t AuCreateSubKernelStack ( AuProcess *  proc,
uint64_t *  pml 
)

AuCreateSubKernelStack – maps sub kernel stack and return the top of the stack, it only maps 4KiB of stack.

Parameters
pml– Pointer to page directory
Returns
kernel stack address

◆ AuCreateSubKthread()

AA64Thread * AuCreateSubKthread ( void(*)(uint64_t)  entry,
uint64_t  stack,
uint64_t *  pml,
char *  name 
)

AuCreateSubKthread – create sub kernel thread of parent kthread.

Parameters
entry– Pointer to entry point
pml– Pointer to Page directory
name– Name of the thread
Returns
Pointer to newly created thread

◆ AuForceScheduler()

void AuForceScheduler ( )

AuForceScheduler – force the scheduler to switch next thread.

◆ AuGetCurrentThread()

AA64Thread * AuGetCurrentThread ( )

◆ AuGetIdleThread()

AA64Thread * AuGetIdleThread ( )

◆ AuGetSystemTimerTick()

uint64_t AuGetSystemTimerTick ( )

AuGetSystemTimerTick – return the current system timer tick.

◆ AuHandleSleepThreads()

void AuHandleSleepThreads ( )

◆ AuIdleLoop()

void AuIdleLoop ( void  )

◆ AuIdleThread()

void AuIdleThread ( uint64_t  ctx)

◆ AuResumeUserThread()

void AuResumeUserThread ( )

◆ AuSchedLock()

uint64_t AuSchedLock ( void  )

◆ AuScheduleNext()

void AuScheduleNext ( )

AuScheduleNext – forcefully schedule to idle thread.

◆ AuSchedulerInitialize()

void AuSchedulerInitialize ( )

AuSchedulerInitialize – initialize the scheduler.

◆ AuSchedulerStart()

void AuSchedulerStart ( )

AuSchedulerStart – start the scheduler.

◆ AuScheduleThread()

void AuScheduleThread ( AA64Registers *  regs)

AuScheduleThread – the core of multi-tasking. It schedules threads next to be runned.

Parameters
regs– Passed by Timer ISR

change thread's running state to ready state

check if the thread was left somewhere in kernel space

◆ AuSchedUnlock()

void AuSchedUnlock ( uint64_t  d)

◆ AuSchedValidateLists()

bool AuSchedValidateLists ( void  )

AuSchedValidateLists – consistency-check all scheduler lists.

Returns
true when every list is well-formed (linkage, tail, states)

◆ AuSchedYieldMs()

int AuSchedYieldMs ( uint64_t  ms)

◆ AuSetIdleThread()

void AuSetIdleThread ( AA64Thread *  thr)

AuSetIdleThread – change the idle thread pointer.

Parameters
thr– Pointer to idle thread

◆ AuSleepThread()

void AuSleepThread ( AA64Thread *  thread,
uint64_t  ms 
)

AuSleepThread – block a running thread and put it into sleep list.

Parameters
thread– Pointer to AA64 Thread

◆ AuThreadAwakeWaiters()

void AuThreadAwakeWaiters ( AA64Thread *  thread)

AuThreadAwakeWaiters – unblock all awaiting threads for the current thread @praram thread – current thread which waitlist needs to be freed.

remove all waiters

◆ AuThreadCleanTrash()

void AuThreadCleanTrash ( AA64Thread *  t)

AuThreadCleanTrash – clean a thread from trash list.

◆ AuThreadDelete()

void AuThreadDelete ( AA64Thread *  thread)

◆ AuThreadDeleteBlock()

void AuThreadDeleteBlock ( AA64Thread *  thread)

◆ AuThreadDeleteSleep()

void AuThreadDeleteSleep ( AA64Thread *  thread)

◆ AuThreadDeleteTrash()

void AuThreadDeleteTrash ( AA64Thread *  thread)

◆ AuThreadFindByID()

AA64Thread * AuThreadFindByID ( uint64_t  id)

AuThreadFindByID – finds a thread by its id from ready queue.

Parameters
id– id of the thread

◆ AuThreadFindByIDBlockList()

AA64Thread * AuThreadFindByIDBlockList ( uint64_t  id)

AuThreadFindByIDBlockList – finds a thread by its id from the block queue.

Parameters
id– id of the thread

◆ AuThreadFindByIDSleepList()

AA64Thread * AuThreadFindByIDSleepList ( uint64_t  id)

AuThreadFindByIDSleepList – finds a thread by its id from the sleep queue.

Parameters
id– thread id

◆ AuThreadInsert()

void AuThreadInsert ( AA64Thread *  new_task)

◆ AuThreadInsertBlock()

void AuThreadInsertBlock ( AA64Thread *  new_task)

◆ AuThreadInsertSleep()

void AuThreadInsertSleep ( AA64Thread *  new_task)

◆ AuThreadInsertTrash()

void AuThreadInsertTrash ( AA64Thread *  new_task)

◆ AuThreadMakeReady()

void AuThreadMakeReady ( AA64Thread *  thread)

AuThreadMakeReady – make a thread forcefully ready for next.

Parameters
thread– pointer to thread struct

◆ AuThreadMoveToTrash()

void AuThreadMoveToTrash ( AA64Thread *  t)

AuThreadMoveToTrash – move given thread to trash.

Parameters
t– Thread to move to trash

◆ AuThreadSafeReturn()

void AuThreadSafeReturn ( uint64_t  rcx)

◆ AuThreadWaitForTermination()

int AuThreadWaitForTermination ( int  thread_id)

AuThreadWaitForTermination – wait for desired thread termination.

Parameters
thread_id– desired thread id

we mark it's belonging process non killable because, untill the child thread is terminated, the process should not be terminated anyhow, or else dead thread-dead process

explicitly call pause thread on user space

◆ AuThreadWakePoller()

void AuThreadWakePoller ( AA64Thread *  t)

AuThreadWakePoller – wake up a thread that was left in sleep/block while polling.

Parameters
t– Pointer to thread

◆ AuUnblockThread()

void AuUnblockThread ( AA64Thread *  thread)

AuUnblockThread – unblocks a thread and insert it to ready list.

Parameters
t– pointer to thread

◆ enscheddebug()

void enscheddebug ( )

◆ first_time_sex()

void first_time_sex ( AA64Thread *  thr)
extern

◆ first_time_sex2()

void first_time_sex2 ( AA64Thread *  thr)
extern

◆ PrintThreadInfo()

void PrintThreadInfo ( )
extern

◆ PrintThrIn()

void PrintThrIn ( )

◆ read_sp()

uint64_t read_sp ( )
extern

◆ read_x30()

uint64_t read_x30 ( )
extern

◆ resume_user()

void resume_user ( AA64Thread *  thr,
void *  ksp 
)
extern

◆ ret_from_syscall()

void ret_from_syscall ( AA64Thread *  thr)
extern

◆ settimerdebug()

void settimerdebug ( )
extern

◆ store_syscall()

void store_syscall ( AA64Thread *  thr)
extern

Variable Documentation

◆ _idle_thr

AA64Thread* _idle_thr

◆ _scheduler_initialized

bool _scheduler_initialized

◆ blocked_thr_head

AA64Thread* blocked_thr_head

◆ blocked_thr_last

AA64Thread* blocked_thr_last

◆ current_thread

AA64Thread* current_thread

◆ debug

bool debug = 0

◆ scheduler_tick

uint64_t scheduler_tick

◆ sleep_thr_head

AA64Thread* sleep_thr_head

◆ sleep_thr_last

AA64Thread* sleep_thr_last

◆ thread_id

uint64_t thread_id

◆ thread_list_head

AA64Thread* thread_list_head

BSD 2-Clause License

Copyright (c) 2022-2023, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ thread_list_last

AA64Thread* thread_list_last

◆ trash_thr_head

AA64Thread* trash_thr_head

◆ trash_thr_last

AA64Thread* trash_thr_last