Efficient Alarm Clock
In PintOS, threads may call this function to put themselves to sleep:
/**
* This function suspends execution of the calling thread until time has
* advanced by at least x timer ticks. Unless the system is otherwise idle, the
* thread need not wake up after exactly x ticks. Just put it on the ready queue
* after they have waited for the right number of ticks. The argument to
* timer_sleep() is expressed in timer ticks, not in milliseconds or any another
* unit. There are TIMER_FREQ timer ticks per second, where TIMER_FREQ is a
* constant defined in devices/timer.h (spoiler: it's 100 ticks per second).
*/
void timer_sleep (int64_t ticks);
timer_sleep is useful for threads that operate in real-time (e.g. for blinking the cursor once per second). The current implementation of timer_sleep is inefficient, because it calls thread_yield in a loop until enough time has passed. This consumes CPU cycles while the thread is waiting. Your task is to reimplement timer_sleep so that it executes efficiently without any busy waiting.
The underlying idea for solving this task lies in the thread API functions thread_block and thread_unblock (see the comments on those functions in src/threads/thread.c for more information) combined with the fact, that PintOS creates and handles a regular timer interrupt that fires usually once every 10ms (see the function timer_interrupt in src/devices/timer.c, also see the TIMER_FREQ constant defined in src/devices/timer.h).
So one way would be to iterate over all existing threads (see the API function thread_foreach defined in src/threads/thread.c) on each timer interrupt to check if an thread that is blocked during timer_sleep needs to be unblocked as its wait time has run out.
Next task: Strict Priority Scheduler.