Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Main Goal timer _ alarm ( int ticks ) System call that wakes up a process in ticks amount of time PintOS uses busy waiting
Main Goal
timeralarmint ticks
System call that wakes up a process in ticks amount
of time
PintOS uses busy waiting for the alarm
Modify PintOS to use sleepwakeup for alarm
Files to modify Threadsthread Devicestimer
Sometimes, a thread may want to wait for some time to pass, aka sleep
Problem: Pintos implementation of sleep is very wasteful
Devicestimerc
void timersleep intt ticks
intt start timerticks ;
while timerelapsed start ticks
threadyield ;
Modifying timersleep
void timersleep intt ticks
intt start timerticks ;
while timerelapsed start ticks
threadyield ;
threadsleepticks; New function!
Modifying struct thread
threadsthreadh
enum threadstatus
THREADRUNNING, Running thread.
THREADREADY, Not running but ready to run.
THREADSLEEPING, New state for sleeping threads
THREADBLOCKED, Waiting for an event to trigger.
THREADDYING About to be destroyed.
;
struct thread
intt waketime;
threadsleep
threadsthreadc
static struct list sleepinglist;
void threadsleep intt ticks
struct thread cur threadcurrent;
enum intrlevel oldlevel;
oldlevel intrdisable ;
if cur idlethread
listpushback &sleepinglist, &curelem;
curstatus THREADSLEEPING;
curwaketime timerticks ticks;
schedule ;
intrsetlevel oldlevel;
Modifying schedule
Threadsthreadc
struct listelem tempe listbegin &sleepinglist;
intt curticks timerticks;
while e listend &sleepinglist
struct thread t listentry e struct thread, allelem;
if curticks twaketime
listpushback &readylist, &telem; Wake this thread up
tstatus THREADREADY;
temp e;
e listnext e;
listremovetemp; Remove this thread from sleepinglist
else e listnext e;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started