Report_Final_OS
Report_Final_OS
Report_Final_OS
HANOI, 1-2025
1
Table of Contents
1. Overview....................................................................................5
2. Introduction................................................................................ 9
3. Model Overview..........................................................................14
4. Model Implementation..................................................................14
5. Experiment................................................................................. 5
5.1. Training Model...................................................................... 5
5.2. Test Model........................................................................... 5
6. Conclusion..................................................................................5
6.1. Key Achievements...................................................................5
6.2. Limitations...........................................................................5
7. Other Models.............................................................................. 5
2
1. Overview
Pintos is a simple operating system framework for the 80x86 architecture.
It supports kernel threads, loading and running user programs, and a file system,
but it implements all of these in a very simple way. In the Pintos projects, you
and your project team will strengthen its support in all three of these areas. You
will also add a virtual memory implementation.
Pintos could, theoretically, run on a regular IBM-compatible PC. We will
run Pintos projects in a system simulator, that is, a program that simulates an
80x86 CPU and its peripheral devices accurately enough that unmodified
operating systems and software can run under it.
Pintos was created at Stanford University by Ben Pfaff in 2004. It
originated as a replacement for Not Another Completely Heuristic Operating
System (Nachos), a similar system originally developed at UC Berkeley by
Thomas E. Anderson, and was designed along similar lines.
Implemented in the C programming language, Pintos provides a
streamlined yet functional operating system environment. Offering features such
as threads, virtual memory, file systems, and user programs, Pintos serves as a
practical platform for students to delve into and implement fundamental
operating system concepts.
A notable aspect of Pintos is its modular structure, facilitating a step-by-
step approach to the implementation of various operating system components.
Through a series of projects, students incrementally improve Pintos' capabilities,
gaining valuable insights into the complexities of real-world operating systems.
Stanford introduces CS140 Problem Set 0: Synchronization -
Synchronization for students to familiarize themselves with the source code of
Pintos. When students successfully deploy (i.e., PASS the TEST tasks) the
content outlined in this set, the Pintos operating system will operate efficiently,
with high performance, conserving the computer's memory, energy, and time
resources. QEMU will be used as the simulation tool in this report.
3
Let's take a look at what's inside. Here's the directory structure that
we should see in pintos/src:
threads/:
Source code for the base kernel, which we will modify starting in project
1.
userprog/:
Source code for the user program loader, which we will modify starting
with project 2.
vm/:
An almost empty directory. We will implement virtual memory here in
project 3.
filesys/:
Source code for a basic file system. We will use this file system starting
with project 2, but we will not modify it until project 4.
devices/:
Source code for I/O device interfacing: keyboard, timer, disk, etc. We will
modify the timer implementation in project 1. Otherwise, we should have
no need to change this code.
lib/:
An implementation of a subset of the standard C library. The code in this
directory is compiled into both the Pintos kernel and, starting from project
2, user programs that run under it. In both kernel code and user programs,
headers in this directory can be included using the #include notation. We
should have little need to modify this code.
lib/kernel/:
Parts of the C library that are included only in the Pintos kernel. This also
includes implementations of some data types that we are free to use in our
kernel code: bitmaps, doubly linked lists, and hash tables. In the kernel,
headers in this directory can be included using the #include notation.
lib/user/:
Parts of the C library that are included only in Pintos user programs. In
user programs, headers in this directory can be included using the
#include notation.
tests/:
Tests for each project. We can modify this code if it helps us test our
submission, but Stanford will replace it with the originals before they run
the tests.
examples/:
Example user programs for use starting with project 2.
4
misc/ and utils/:
These files may come in handy if we decide to try working with Pintos on
our own machine. Otherwise, we can ignore them.
Makefile.build:
The file describes how to build the Pintos kernel. This file can only be
edited if you want to add new source code.
5
2. Algorithm:
1. process_execute function: Initiates the creation of a new thread to
execute a user program. It involves copying the file name(‘fn_copy’)
Allocates memory for ‘fn_copy’ using ‘palloc_get_page’., creating a new thread
using thread_create, and passing the copied file name to the new thread.
6
3. load function: Loads an ELF executable from a file into the current
thread. It involves opening the executable file, reading and verifying the
ELF header, reading program headers, and loading segments into
memory. It uses various helper functions such as validate_segment,
load_segment, and setup_stack.
4. validate_segment and load_segment functions: Validate and load ELF
segments into memory. These functions ensure that the segments are valid
and that memory is properly initialized.
7
8
5. setup_stack function: Creates a minimal stack for a new process by
mapping a zeroed page at the top of user virtual memory.
9
3. Results
III. Conclusion
Through this sub-project, I have gained valuable insights and skills related to the
design and implementation of operating system components. More importantly,
this has not only expand my knowledge but it hasd significantly improved my
researching skill, taught me how to be patient and resilient throughout the whole
project.
Git_Hub_ChuQuangTung_20213594
10