1 / 25

Software Engineering

Software Engineering. Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004. Overview. Concurrent processes - Java Threads Mutual exclusion Semaphore s Monitors - Java synchronized, wait, notify Ada rendezvous. A kernel specification. /* kernel.h

neila
Download Presentation

Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software Engineering Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004

  2. Overview • Concurrent processes - Java Threads • Mutual exclusion • Semaphores • Monitors - Java synchronized, wait, notify • Ada rendezvous

  3. A kernel specification /* kernel.h Interface to a lightweight kernel that implements concurrent processes and a release primitive `pause'. Anders P. Ravn, DTU, Denmark 24 April 1998 apr@it.dtu.dk*/ typedef void (*Program)(void); /* A program text is a function without parameters*/ typedef void * Thread; /* identifier for a process */ extern Thread create(Program p,unsigned int stacksize); /* creates a process with a stackof the specified size and starts it executing theprogram. If there is insufficientmemory, the result is NULL */ extern void pause(void); /* release the processor */

  4. Multiprogramming #include ”kernel.h” void process() { /* do something */ pause(); /* do something */ } void main() { Thread p1, p2; p1 = create(&process,2000); /* p1 is started */ p2 = create(&process,1000); /* p2 is started */ /* the kernel will see to it that main is left when both p1 and p2 has exited */ }

  5. A kernel implementation I typedef unsigned long Register; typedef struct x {struct x* next; Register esp;} Threaddescriptor; static Threaddesriptor* ready; /* queue of threads linked cyclically; ready points to last, the first is current */ #define current ready->next ready: current esp1 esp2 esp3

  6. A kernel implementation II void pause() { Register sp; __asm__(”pushal movl %%esp,%sp"); /* sp -> |saved registers ... | eip return from call */ DISABLE; /* scheduling */ current->esp = sp; ready = current; sp = current->esp; __asm__(" movl %sp,%%esp popal" ); ENABLE; } stack1 stack2 ready: current esp1 esp2 esp3

  7. A kernel implementation III pause: pushl %ebp movl %esp,%ebp pushal movl %esp,%ecx sp = esp movl ready,%eax movl (%eax),%edx current->esp movl %ecx,4(%edx) = sp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%ecx sp = current->esp movl %ecx,%esp popal leave ret

  8. A kernel implementation IV pause: pushal movl ready,%eax movl (%eax),%edx current->esp movl %esp,4(%edx) = esp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%esp esp = current->esp popal ret

  9. Java Threads import java.awt.*; class ProcessextendsThread { public Customer(...){ ...} public void run(){... // do something } ... Process p1 = new Process(); p1.start(); ...

  10. Shared Variables class Banking { /* shared variable balance and private withdrawals */ public int balance; public int[] wd; public Banking() { balance = 2000; wd = new int[2]; } // Invariant: // balance+wd[0]+wd[1] == 2000 }

  11. Critical Section class Customer extends Thread { int id; Lock critical; Banking bank; public void run() { do { sleep(800-400*id); critical.enter(id); int local = bank.balance; sleep(shortdelay); bank.balance = local-1; critical.leave(id); bank.wd[id]++; } while (true); }}

  12. Semaphore public class Semaphore { int count; public Semaphore(int initial_value){ count= initial_value; } public synchronized void Wait(){ while(count == 0) wait(); --count; } public synchronized void signal(){ if (count++ == 0) notify(); } }

  13. Rendezvous

  14. Scheduling • Periodic processes – cyclic executive • Fixed Priority Scheduling – Rate Monotonic • Response Time Analysis • Sporadic Processes • Blocking and priority inversion • Priority Ceiling protocols • Real-Time Java

  15. Cyclic executive loop wait 25msinterrupt; a(); b(); c(); wait 25ms interrupt; a(); b(); d(); e(); wait 25ms interrupt; a(); b(); c(); wait 25ms interrupt; a(); b(); d(); end loop;

  16. Utilization tests Utilization U = C/T Priority is rate (1/T) monotonic U1 + ... + UN  N( N2 – 1)  0.693 (FPS) U1 + ... + UN  1 (Earliest Deadline First !?) Liu & Layland JACM, 1973

  17. Response Time Analysis Response time R= C + I -- Interference Ii = Ri /TN CN + ... + Ri /Ti+1Ci+1(FPS) Joseph & Pandya Computer Journal 1986

  18. Sporadic Processes Deadline D < T Priority is deadline (1/D) monotonic

  19. Blocking Critical Regions V and Q locked by eg a semaphore. d(Q,V): EEEEBQ-----------BQQVVEE c(V) : EEVV----VVEE b() : ------------EEEE a(Q) : EEQQ----------------QQQQQQ------EE Priority Inversion

  20. Response Time Analysis Response time R= C + B + I K = (k1,..., km): resources used by a process of lower priority and by a process with a higher or equal prority Bi = Ck1 + ... + Ckm

  21. Immediate Ceiling Protocol A resource uses the maximual priority of any process using it. K = (k1,..., km): resources used by a process of lower priority and by a process with a higher or equal prority Bi = max C(k), k  K

  22. Blocking ICPP d(Q,V): EEEEBQ-----------BQQVVEE c(V) : EEVV----VVEE b() : ------------EEEE a(Q) : EEQQ----------------QQQQQQ------EE ------------------- d(Q,V): BBEEEEQQVVEE c(V) : BBBBBB----------EEVVVVEE b() : BBBBBB------------------EEEE a(Q) : EEQQQQQQQQ----------------------EE

  23. Real-Time Java public classPeriodic extendsRealTimeThread{ public Periodic(PriorityParameters pp, PeriodicParameters p) { ... } publicvoid run(){ for (;;){ ... waitForNextPeriod(); } } }

  24. PeriodicParameters public classPeriodicparameters ... { public PeriodicParameters( HighResolutionTime start, RelativeTime period, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunhandler, AsyncEventHandler misshandler){ ... } }

  25. And more http://www.rtj.org

More Related