00001 /* Checks that recent_cpu and priorities are updated for blocked 00002 threads. 00003 00004 The main thread sleeps for 25 seconds, spins for 5 seconds, 00005 then releases a lock. The "block" thread spins for 20 seconds 00006 then attempts to acquire the lock, which will block for 10 00007 seconds (until the main thread releases it). If recent_cpu 00008 decays properly while the "block" thread sleeps, then the 00009 block thread should be immediately scheduled when the main 00010 thread releases the lock. */ 00011 00012 #include <stdio.h> 00013 #include "tests/threads/tests.h" 00014 #include "threads/init.h" 00015 #include "threads/malloc.h" 00016 #include "threads/synch.h" 00017 #include "threads/thread.h" 00018 #include "devices/timer.h" 00019 00020 static void block_thread (void *lock_); 00021 00022 void 00023 test_mlfqs_block (void) 00024 { 00025 int64_t start_time; 00026 struct lock lock; 00027 00028 ASSERT (thread_mlfqs); 00029 00030 msg ("Main thread acquiring lock."); 00031 lock_init (&lock); 00032 lock_acquire (&lock); 00033 00034 msg ("Main thread creating block thread, sleeping 25 seconds..."); 00035 thread_create ("block", PRI_DEFAULT, block_thread, &lock); 00036 timer_sleep (25 * TIMER_FREQ); 00037 00038 msg ("Main thread spinning for 5 seconds..."); 00039 start_time = timer_ticks (); 00040 while (timer_elapsed (start_time) < 5 * TIMER_FREQ) 00041 continue; 00042 00043 msg ("Main thread releasing lock."); 00044 lock_release (&lock); 00045 00046 msg ("Block thread should have already acquired lock."); 00047 } 00048 00049 static void 00050 block_thread (void *lock_) 00051 { 00052 struct lock *lock = lock_; 00053 int64_t start_time; 00054 00055 msg ("Block thread spinning for 20 seconds..."); 00056 start_time = timer_ticks (); 00057 while (timer_elapsed (start_time) < 20 * TIMER_FREQ) 00058 continue; 00059 00060 msg ("Block thread acquiring lock..."); 00061 lock_acquire (lock); 00062 00063 msg ("...got it."); 00064 }