Pintos : Series : Part3 : Project 1 : Alarm Clock


The PintOS project has 27 test cases that we need to pass. In the first project we are just going for the five test cases related to alarm clock that are as under:
  • alarm_multiple
  • alarm_single
  • alarm_simultaneous
  • alarm_negative
  • alarm_zero
But before jumping into the code, let's first understand the basic structure of PintOS and how it runs. Consider the following diagram:

Here QEMU is an emulator on which pintOS runs. Test cases are the processes that we run on the PintOS (Operating System). So we only need to modify the PintOS code, we are not allowed to make any change to the test cases code as this would be a cheating.
When you open up the PintOS directory, in tests/threads/tests.c all the test cases are declared. And in the tests/threads/ directory you can observe files with the extension ".ck" and ".c". So the "test_Name.c" files are the files in which test cases are defined, while "test_Name.ck" files contain the reference output for the test case. When the test runs it checks if it is producing the same output as the reference output provided in ".ck" file. If yes, then the test passes else it fails.
So that is how pintOS test cases work.
Now what we need to do is to modify "timer.c" in "devices" directory, in a way that the timer_sleep() function avoid busy waiting; to do something useful and to pass the 5 test cases mentioned above.
If you have installed the pintOS correctly then it will PASS these test cases. But our task is to remove busy waiting along with the test cases still passing the tests. Now what's busy waiting? We can find its definition by looking into the timer_sleep() function in devices/timer.c, given below:

/* Sleeps for approximately TICKS timer ticks.  Interrupts must
   be turned on. */

void
timer_sleep (int64_t ticks)
{
  int64_t start = timer_ticks ();

  ASSERT (intr_get_level () == INTR_ON);
  while (timer_elapsed (start) < ticks)
    thread_yield ();
}


The timer_sleep() function is taking the ticks (unit of time), and after these many ticks we want the thread or process to run. Then timer_ticks() starts the timer, then the function makes sure that interrupts are enabled. After that it starts the loop, it checks if the ticks reached what we have provided in the function as "int64_t ticks", if no then it will yield the thread, the thread_yield() functions puts the thread in the start of the queue, this creates busy waiting as in each iteration the yielded thread is placed in a queue, while it has no function at that time, it's just waiting. So we need to replace this "thread_yield()" with "thread_block()" along with some other functionality, to get rid of this busy waiting.
I hope you have understood the basic concept of what we need to do.

To be continued... :) 

Special thanks to Operating Systems' honorable Professor and Ramlah !


Comments

Popular posts from this blog

1-Machine Learning : Start...

An Interview with Pakistani Data Scientist : Dr. Zeeshan Ul Hassan Usmani

Relational Data Model

Data Modeling

How to play Chess ?

Programming android applications

How to take notes in Freshman Year ?

Habits to adopt in the freshman year

E-Commerce : Platforms