This project simulates core components of an operating system, focusing on process scheduling and memory management using a paging mechanism. It provides a framework for loading processes defined in external files, scheduling them using a Multi-Level Queue (MLQ) scheduler (if enabled), and managing their memory requirements within simulated physical RAM and swap space when paging is enabled.
- Process Management:
- Loads process descriptions from files (
loader.c). Process files define instructions likeCALC,ALLOC,FREE,READ,WRITE, andMALLOC(only ifMM_PAGINGis enabled). - Represents processes using Process Control Blocks (PCBs) (
common.h). - Simulates CPU execution of process instructions (
cpu.c).
- Loads process descriptions from files (
- Scheduling:
- Implements a Multi-Level Queue (MLQ) scheduler if
MLQ_SCHEDis defined inos-cfg.h(sched.c,sched.h). - Supports process priorities when MLQ is enabled.
- Includes basic ready/run queues otherwise (
queue.c).
- Implements a Multi-Level Queue (MLQ) scheduler if
- Memory Management:
- Supports two modes via the
MM_PAGINGflag inos-cfg.h:- Paging Enabled (
MM_PAGINGdefined):- Simulates physical memory (RAM) and swap space(s) (
mm-memphy.c,os-mm.h). - Implements virtual memory management using paging (
mm-vm.c,mm.c). - Manages Virtual Memory Areas (VMAs) and memory regions (
os-mm.h). - Handles page allocation, page table management (PGD in
mm_struct), and memory access (read/write) operations (mm.h,mm-vm.c). - Supports dynamic memory allocation (
pgmalloc) within the simulated environment (mm-vm.c). - Optional heap growth direction configuration via
MM_PAGING_HEAP_GODOWN(os-cfg.h).
- Simulates physical memory (RAM) and swap space(s) (
- Paging Disabled (
MM_PAGINGnot defined):- Uses a simpler, likely segmented, memory model (
mem.c,mem.h). (Note: This appears to be a legacy or alternative implementation).
- Uses a simpler, likely segmented, memory model (
- Paging Enabled (
- Supports two modes via the
- Concurrency:
- Uses pthreads for simulating concurrent CPU execution and process loading (
os.c). - Uses a timer mechanism for time slicing (
timer.c,timer.h).
- Uses pthreads for simulating concurrent CPU execution and process loading (
- Configuration:
- Reads simulation parameters (time slice, number of CPUs, process details, memory sizes) from a configuration file (
os.c-read_config).
- Reads simulation parameters (time slice, number of CPUs, process details, memory sizes) from a configuration file (
- Debugging:
- Includes options for dumping I/O operations, page tables, and memory contents (
IODUMP,PAGETBL_DUMPinos-cfg.h). - Memory dump functions available in
mm-memphy.c(MEMPHY_dump) andmem.c(dump).
- Includes options for dumping I/O operations, page tables, and memory contents (
The simulation behavior is controlled by a configuration file (e.g., input/os_1_mlq_paging). This file specifies:
<time_slice> <num_cpus> <num_processes>- (Only if
MM_PAGINGis defined ANDMM_FIXED_MEMSZis NOT defined inos-cfg.h)<mem_ram_sz> <mem_swp0_sz> [mem_swp1_sz] [mem_swp2_sz] [mem_swp3_sz](Up to 4 swap sizes) - (Only if
MM_PAGINGANDMM_PAGING_HEAP_GODOWNare defined ANDMM_FIXED_MEMSZis NOT defined inos-cfg.h)<vmemsz>(Virtual memory size for heap) - For each process (repeated
<num_processes>times):<proc_start_time> <proc_file_name> [<proc_prio>]<proc_prio>is only read ifMLQ_SCHEDis defined inos-cfg.h.<proc_file_name>is relative to theinput/proc/directory.
Example config.txt structure (assuming MLQ and Paging with dynamic memory sizes):
10 2 3
1048576 16777216 0 0 0
3145728
0 p0 137
1 p1 138
2 p2 139
Process description files (e.g., input/proc/p0) contain:
<default_priority> <num_instructions>- A list of instructions (e.g.,
CALC,ALLOC,MALLOC,FREE,READ,WRITE) with their arguments, one per line.
Use the provided Makefile to build the project.
- Ensure a C compiler (like GCC) and
makeare installed. - Navigate to the project's root directory in your terminal.
- Run the make command:
This will compile the source files located in the
make
srcdirectory, placing object files in anobjdirectory (created if it doesn't exist) and creating the final executable namedosin the root directory. - To clean up build files:
make clean
Run the compiled simulator by providing the path to the configuration file as a command-line argument:
.\os <path_to_config_file>Example:
.\os input/os_1_mlq_pagingThe simulator will then:
- Read the specified configuration file (
os.c-read_config). - Initialize memory structures (RAM, Swap if
MM_PAGING) (os.c,mm-memphy.c). - Initialize the scheduler (
os.c,sched.c). - Start the timer thread (
timer.c). - Start CPU threads (
os.c-cpu_routine) and the loader thread (os.c-ld_routine). - The loader thread loads processes according to their start times, initializing their memory management structures if
MM_PAGINGis enabled (os.c,loader.c,mm.c). - CPUs fetch processes from the scheduler (
sched.c-get_proc) and execute their instructions (cpu.c-run). - The simulation runs until all processes are loaded and completed. Output is printed based on simulation events and debugging flags set in
os-cfg.h.
- Makefile: Defines build rules for the project.
- include: Header files defining structures, constants, and function prototypes.
common.h: Common data structures (PCB, Instruction).os-cfg.h: Build-time configuration flags (likeMM_PAGING,MLQ_SCHED).os-mm.h: Paging-specific memory structures (VMA, MM struct, MemPhy).mm.h: Main memory management interface (Paging).mem.h: Interface for the alternative/legacy memory model.loader.h: Process loader interface.sched.h: Scheduler interface.queue.h: Basic queue implementation.timer.h: Timer interface.cpu.h: CPU execution interface.bitops.h: Bit manipulation macros.
- src: Source code files implementing the simulator logic.
os.c: Main simulation driver, configuration reading, thread management.cpu.c: CPU instruction execution simulation.loader.c: Loading process code from files.sched.c: Scheduler implementation (MLQ if enabled).queue.c: Basic queue implementation.timer.c: Timer implementation.mm.c: Core memory management logic (Paging).mm-vm.c: Virtual memory management logic (Paging).mm-memphy.c: Physical memory/swap simulation (Paging).mem.c: Alternative/legacy memory management implementation.paging.c: Standalone test file (not part of the mainosexecutable).
- input: Directory for configuration and process files.
- Contains various configuration files (e.g.,
os_1_mlq_paging). proc/: Contains process description files (e.g.,p0,p1).
- Contains various configuration files (e.g.,
obj/: Directory created by the Makefile to store intermediate object files.