How phucnguyenlamp/btl-os-hcmut works
Overview and Project Type
• This project is a small-scale operating system kernel implemented in C. The purpose seems to be an educational or experimental OS (perhaps for a final project), as evidenced by modules for CPU handling, memory management (paging, virtual memory management), scheduling, and loading.
• There’s an emphasis on multi-level queue (MLQ) scheduling and paging techniques. The README’s playful tone (“GG BTL OS, mày mạnh, tao công nhận”) underscores that the project is experimental and possibly intended as a learning tool.
Analyzing the File Structure to Determine System Components
• Top-level Modules:
• Contains all header files defining interfaces for various modules (CPU, loader, memory, mm, scheduler, timer, queue, etc.).
• src: Houses the implementation files for critical components (cpu-tlb, cpu, loader, mem, mm, paging, queue, sched, timer). Notice modules like "mm-vm.c", "paging.c" indicate different strategies for memory management.
• input: Organized test cases/scripts for different configurations (various OS scheduling and paging implementations, process tests, scheduler tests). This shows that the project is designed to test different OS configurations.
• Makefile: Indicates an automated build process.
Main Components
a. OS Kernel Core:
• Central component that likely initializes and coordinates the other subsystems.
• Includes the "os.c" module which glues together functionalities.
b. CPU and TLB Modules:
• Components associated with CPU instruction execution, and TLB caching (see cpu-tlb.c, cpu-tlbcache.c).
• These modules indicate handling of low-level CPU simulation and caching for address translation.
c. Memory Management System:
• Includes modules for basic memory operations (mem, mm.c) and more sophisticated virtual memory management routines (mm-vm.c, mm-memphy.c, paging.c).
• This part handles allocation/deallocation, paging, and possibly translation lookaside buffer (TLB) operations.
d. Process Loader:
• The "loader.c/h" module is responsible for loading and initializing processes.
e. Scheduler and Queue Subsystems:
• Scheduler (sched.c/h) which likely implements multi-level queue (MLQ) scheduling (as hinted by various input test cases) and queue management (queue.c/h).
f. Timer:
• The timer module (timer.c/h) which probably drives preemptive scheduling and system ticks.
g. Testing / Input Scenarios:
• How different test cases (from the input directories) provide configurations for various scheduler and memory management setups.
Relationships and Interactions
• OS Kernel Core is at the heart, calling into:
• Loader to initiate process structures.
• Scheduler (and underlying queue management) to decide process execution order.
• Memory Management to allocate and manage process memory via virtual memory and paging services.
• CPU modules that simulate instruction execution along with TLB caching.
• Timer to trigger scheduling interrupts.
• The flow is likely as follows:
• Bootstrapping: The OS Kernel (os.c) initializes, invoking the loader and memory systems.
• Process Scheduling: Scheduler and queue modules manage process execution queues.
• CPU Execution: CPU modules (with TLB support) fetch and process instructions, relying on memory management for address translation.
• Timer Interrupts: Timer module issues interrupts that prompt scheduling decisions.
• External Test Inputs (from the input directory) are used to configure and validate the behavior of these modules.
Architectural Patterns and Design Principles
• Modular Design: Each subsystem (CPU, memory, scheduler, loader, timer) is encapsulated in its own source/header files, enabling separation of concerns.
• Layered Architecture: OS kernel core layers on top of hardware abstraction (CPU, memory) with dedicated support for scheduling and process management.
• Configurability: Use of multiple test configurations (evident in the various input directories) shows support for testing multiple algorithmic or operational strategies.