P2 - Preemptive Scheduling
Drew Zagieboylo 2/23/18
P2 - Preemptive Scheduling Drew Zagieboylo 2/23/18 P1 Postmortem - - PowerPoint PPT Presentation
P2 - Preemptive Scheduling Drew Zagieboylo 2/23/18 P1 Postmortem P1 - Nonpreemptive int thread2(int* arg) { yield() minithread_fork(thread3, NULL); allow another printf("Thread 2.\n"); thread to run minithread_yield();
Drew Zagieboylo 2/23/18
thread to run
threaded behavior
int thread2(int* arg) { minithread_fork(thread3, NULL); printf("Thread 2.\n"); minithread_yield(); return 0; }
specific interrupt type
Interrupts
since OS start
… x … … proc_1
//proc_1
0xbee0 0xbee4 0xbee8 0xbeec while (1){ x = x + 1; mt_yield(); }
pc
… x … … proc_1
//proc_1
0xbee0 0xbee4 0xbee8 0xbeec while (1){ x = x + 1; }
pc
… x … … proc_1
//proc_1
0xbee0 0xbee4 0xbee8 0xbeec while (1){ x = x + 1; }
pc clock_handler
… x … … proc_1
clock_handler { ... //pick next thread //mt_switch to next thread| //re-enable interrupts }
clock_handler
semaphore_P(sema) { sema->count--; if (count < 0) { queue_append(sema->q, minithread_self()); minithread_stop(); } }
These lines must happen atomically -> in Port OS this requires interrupt safety
future time
func)
Quick Tasks -> need low latency
Need more CPU time -> needs more throughput
…. …. …. ….
Level 1 2 3
…. …. …. ….
Level 1 2 3
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3 Start a new Thread
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3 After 1 tick, thread still executing
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3 Demote thread to LVL 1
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3 Pick another thread from LVL 0 to run
…. …. …. ….
Level 1 2 3 Time Allocated Per Queue 5t 2.5t 1.5t t Time Allocated Per Thread 2^0 2^1 2^2 2^3 Eventually… Pick a thread from LVL 1 Instead