Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Makefile
cmake-build-*
target
.venv
*cache*
__pycache__
.amazonq
*backup
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ cmake_minimum_required(VERSION 3.20)
project(VoidFrame VERSION 0.0.2 LANGUAGES C CXX ASM_NASM)
enable_language(ASM_NASM)

# ============================================================================
# Module Path & Includes
# ============================================================================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(cache)
include(features)
include(variable)
include(dependencies)
include(flags)
include(configuration)

# ============================================================================
# Platform Checks
# ============================================================================
Expand Down Expand Up @@ -37,6 +48,7 @@ message(STATUS "CMake Current Source Directory: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMake Current Binary Directory: ${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "CMake Host System Name: ${CMAKE_HOST_SYSTEM_NAME}")
message(STATUS "CMake Host System Processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(STATUS "VoidFrame Scheduler: ${VF_SCHEDULER}")

# ============================================================================
# Standard Configuration
Expand All @@ -46,16 +58,6 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ============================================================================
# Module Path & Includes
# ============================================================================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(features)
include(variable)
include(dependencies)
include(flags)
include(configuration)

# ============================================================================
# Source Files Organization
# ============================================================================
Expand All @@ -77,6 +79,7 @@ set(KERNEL_CORE_SOURCES

set(SCHED_SOURCES
kernel/sched/MLFQ.c
kernel/sched/EEVDF.c
)

set(KERNEL_ETC_SOURCES
Expand Down
5 changes: 5 additions & 0 deletions cmake/cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ============================================================================
# Cache variables
# ============================================================================
set(VF_SCHEDULER "MLFQ" CACHE STRING "Scheduler type: MLFQ or EEVDF")
set_property(CACHE VF_SCHEDULER PROPERTY STRINGS MLFQ EEVDF)
9 changes: 8 additions & 1 deletion cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ add_compile_definitions(
VF_CONFIG_USE_ASTRA
VF_CONFIG_USE_CERBERUS
VF_CONFIG_CERBERUS_STACK_PROTECTION
VF_CONFIG_SCHED_MLFQ
VF_CONFIG_INTEL
)

Expand All @@ -41,4 +40,12 @@ endif()

if(AUTOMATIC_POST)
add_compile_definitions(VF_CONFIG_AUTOMATIC_POST)
endif()

if(VF_SCHEDULER STREQUAL "MLFQ")
add_compile_definitions(VF_CONFIG_SCHED_MLFQ)
elseif(VF_SCHEDULER STREQUAL "EEVDF")
add_compile_definitions(VF_CONFIG_SCHED_EEVDF)
else()
message(FATAL_ERROR "Invalid scheduler: ${VF_SCHEDULER}. Have you pass: -DVF_SCHEDULER=<MLFQ/EEVDF>?.")
endif()
77 changes: 54 additions & 23 deletions include/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,117 @@
#ifndef VOIDFRAME_SCHEDULER_H
#define VOIDFRAME_SCHEDULER_H
#include "MLFQ.h"
#include "EEVDF.h"
#include "Shared.h"

// Initialize the active scheduler
static inline __attribute__((always_inline)) int SchedulerInit() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQSchedInit();
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFSchedInit();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return 0; // not implemented
#endif
return -1;
}

// Create a new process
static inline __attribute__((always_inline)) uint32_t CreateProcess(const char * name, void (*entry_point)()) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQCreateProcess(name ,entry_point);
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFCreateProcess(name, entry_point);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return 0; // not implemented
#endif
return -1;
}

static inline __attribute__((always_inline))
#if defined(VF_CONFIG_SCHED_MLFQ)
MLFQProcessControlBlock*
#elif defined(VF_CONFIG_SCHED_CFS)
void // not implemented
#else
void
#endif
GetCurrentProcess() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQGetCurrentProcess();
MLFQProcessControlBlock *
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
EEVDFProcessControlBlock *
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
void *
#endif
}

static inline __attribute__((always_inline))
#if defined(VF_CONFIG_SCHED_MLFQ)
MLFQProcessControlBlock*
#elif defined(VF_CONFIG_SCHED_CFS)
void // not implemented
#else
void
#endif
GetProcessByPID(uint32_t pid) {
GetCurrentProcess() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQGetCurrentProcessByPID(pid);
return MLFQGetCurrentProcess();
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFGetCurrentProcess();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
return NULL;
#endif
}

// Yield CPU
static inline __attribute__((always_inline)) void Yield() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQYield();
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFYield();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

// Main scheduler function (called from interrupt handler)
static inline __attribute__((always_inline)) void Schedule(Registers* regs) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQSchedule(regs);
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFSchedule(regs);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

// Kill a process
static inline __attribute__((always_inline)) void KillProcess(uint32_t pid) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQKillProcess(pid);
#endif
#ifdef VF_CONFIG_SCHED_EEVDF
return EEVDFKillProcess(pid);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

// Scheduler-specific PCB access (for when you need the full scheduler-specific data)
#ifdef VF_CONFIG_SCHED_MLFQ
typedef MLFQProcessControlBlock SchedulerSpecificPCB;
static inline MLFQProcessControlBlock* GetMLFQCurrentProcess() {
return MLFQGetCurrentProcess();
}
static inline MLFQProcessControlBlock* GetMLFQProcessByPID(uint32_t pid) {
return MLFQGetCurrentProcessByPID(pid);
}
#endif

#ifdef VF_CONFIG_SCHED_EEVDF
typedef EEVDFProcessControlBlock SchedulerSpecificPCB;
static inline EEVDFProcessControlBlock* GetEEVDFCurrentProcess() {
return EEVDFGetCurrentProcess();
}
static inline EEVDFProcessControlBlock* GetEEVDFProcessByPID(uint32_t pid) {
return EEVDFGetCurrentProcessByPID(pid);
}
#endif

#endif // VOIDFRAME_SCHEDULER_H
Loading