Answered step by step
Verified Expert Solution
Link Copied!

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
timer_alarm(int ticks)
System call that wakes up a process in ticks amount
of time
PintOS uses busy waiting for the alarm
Modify PintOS to use sleep/wakeup for alarm
Files to modify Threads/thread Devices/timer
Sometimes, a thread may want to wait for some time to pass, a.k.a. sleep
Problem: Pintos implementation of sleep is very wasteful
Devices/timer.c
void timer_sleep (int64_t ticks)
{
int64_t start = timer_ticks (); while (timer_elapsed (start)< ticks) thread_yield ();
}
Modifying timer_sleep()
void timer_sleep (int64_t ticks)
{
//int64_t start = timer_ticks ();
// while (timer_elapsed (start)< ticks)//
thread_yield ();
thread_sleep(ticks); // New function!
}
Modifying struct thread
threads/thread.h
enum thread_status
{
THREAD_RUNNING, /* Running thread. */
THREAD_READY, /* Not running but ready to run. */
THREAD_SLEEPING, /* New state for sleeping threads */
THREAD_BLOCKED, /* Waiting for an event to trigger. */
THREAD_DYING /* About to be destroyed. */
};
struct thread {...
int64_t wake_time;
thread_sleep()
threads/thread.c
static struct list sleeping_list;
void thread_sleep (int64_t ticks){
struct thread *cur = thread_current();
enum intr_level old_level;
old_level = intr_disable ();
if (cur != idle_thread){
list_push_back (&sleeping_list, &cur->elem);
cur->status = THREAD_SLEEPING;
cur->wake_time = timer_ticks()+ ticks;
schedule ();
}
intr_set_level (old_level);
}
Modifying schedule()
Threads/thread.c
struct list_elem *temp,*e = list_begin (&sleeping_list);
int64_t cur_ticks = timer_ticks();
while (e != list_end (&sleeping_list)){
struct thread *t = list_entry (e, struct thread, allelem);
if (cur_ticks >= t->wake_time){
list_push_back (&ready_list, &t->elem); /* Wake this thread up!*/
t->status = THREAD_READY;
temp = e;
e = list_next (e);
list_remove(temp); /* Remove this thread from sleeping_list */
}
else e = list_next (e);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Create a Fishbone diagram with the problem being coal "mine safety

Answered: 1 week ago