Académique Documents
Professionnel Documents
Culture Documents
kernel threads
user-level processes
Simulates MIPS instruction execution.
07/10/15
System Layers
User process
Thread 1
User process
Thread N
Nachos OS modules
(Threads mgm, File System, Code execution/memory mapping,
System calls/Interrupt)
Simulated MIPS Machine
(CPU, Memory, Disk, Console)
Base Operating System
(Linux for our class)
http://www.cs.ucsb.edu/~cs270t/HW/warm
up.html
07/10/15
07/10/15
Complete HW1
07/10/15
Single-threaded vs
multithreaded Process
07/10/15
main ()
{
Thread *t1 = new Thread("forked thread1");
Thread *t2 = new Thread("forked thread2");
t1->Fork(SimpleThread, 1);
t2->Fork(SimpleThread, 2);
SimpleThread(3);
}
SimpleThread(int i)
{
printf(Hello %d\n, i);
currentThread->Yield();
}
Function executed
by threads
Nachos Threads
Nachos threads execute and share the same code, share same global
variables.
Nachos scheduler maintains a ready list, containing all threads that are
ready to execute.
Each thread is in one of four states: READY, RUNNING, BLOCKED,
JUST_CREATED.
Each thread object maintains a context block.
Thread object supports the following operations:
Yield(). Suspend the calling thread and select a new one for
execution.
Finish()
07/10/15
In HW 1 we are only
concerned with the
states in this box.
Thread::Yield
running
(kernel)
Thread::Sleep
blocked
Scheduler::Run
Scheduler::ReadyToRun
ready
Thread Switching
07/10/15
11
07/10/15
12
07/10/15
13
07/10/15
14
Thread:Fork ()
in thread.cc
Initialize()
in system.cc
main() in
main.cc
ThreadTest ()
in threadtest.cc
FindNextToRun ()
in scheduler.cc
Thread:Yield ()
in thread.cc
ReadyToRun ()
in scheduler.cc
currentThread->Finish ()
in threadtest.cc
07/10/15
StackAllocate()
in thread.cc
Run ()
in scheduler.cc
SWITCH ()
in switch.s
ThreadRoot ()
in switch.s
func() such as
SimpleThread()
in ThreadTest.cc
15
ThreadRoot()
jal
StartupPC
# call startup procedure. For a
new thread, it is InterruptEnable().
07/10/15
16
QA
07/10/15
17
QA
07/10/15
18
07/10/15
19
HW 1: Files involved
Key files
07/10/15
20
HW Sample solution
~cs240t/sampleSolutionCode.tar.gz
Has an old solution for HW1, HW2, HW3
HW1 threads subdirectory. ~400 lines of new code. ~50%
are for Tasks 1/2/3. Code for task 4 is not useful.
HW2 -> userprog subdirectory. ~1300 lines of new code.
HW3 -> vm and filesys. ~1200 lines of new code. 800 may be
enough.
Caveat:
Mixed benefits/problems in using other students code.
e.g. Not well documented, not fully tested. Possibly awkward
design.
Still your responsibility to produce good solutions (correctness,
performance, style).
07/10/15
21