cs452 652
play

CS452/652 For the Kernel Assignment: Description of all major - PowerPoint PPT Presentation

Documentation Requirements CS452/652 For the Kernel Assignment: Description of all major components of the system, g Real-Time e.g. memory management, task management, context switching. Context switching should be Programming described in


  1. Documentation Requirements CS452/652 For the Kernel Assignment: Description of all major components of the system, g Real-Time e.g. memory management, task management, context switching. Context switching should be Programming described in detail . Description of kernel data structures and g Course Notes algorithms, e.g., task descriptors, scheduler, etc. Description of syscall implementation, including g parameter passing. Daniel M. Berry, Cheriton School of Computer Science University of Waterloo  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 1  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 2 Doc. Reqs., Cont’d Hardware Interrupts Explain why your implementation meets real-time g USART1 7 requirements, by giving the complexity of each 6 5 kernel operation. USART0 4 ICU0 3 8259 Description of test cases, including that they cover g INT 2 what should be tested. 1 0 CPU ICU1 User’s manual g 8259 Tour of source code. g 0 PIT RTC BUS  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 3  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 4

  2. Acronyms How A Device Speaks to CPU USART = Universal Synchronous Asynchronous 1. External event occurs. Receiver/Transmitter 2. Device asserting interrupt asserts its interrupt line. ICU = Interrupt Control Unit 3. Interrupts are priority ranked by the ICU, which interrupts the CPU. RTC = Real Time Clock 4. CPU reads IRQ (interrupt request) level from ICU data bus. PIT = Programmable Interval Timer 5. CPU begins interrupt processing. It bothers me that RTC and PIT are different, because of the chances for drift.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 5  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 6 Interrupt Numbers To Make Interrupts Happen 0–31 Processor Internal (GPF, division by zero, Enable Interrupts by setting IF (Interrupt Enable g etc.) Flag), which is stored in EFLAGS register. 31–39 First ICU (IRQ0–IRQ7) Instructions are: g STI — set IF (enable) 40–47 Second ICU (IRQ8–IRQ15) CLI — clear IF (disable) 48–255 Software Interrupts; ∴ , for int n , be sure that n ≥ 48!  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 7  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 8

  3. Happening, Cont’d CPU’s response to an Interrupt Interrupts are: 1. Push EFLAGS, including current IF. g enabled in non-kernel tasks, f disabled in the kernel, and 2. Clear IF and TF (trap flag, to enable single- f enabled at boot up. stepping; in single-step mode, each instruction is an f interrupt). Unmask interrupts of interest in ICUs. g 3. Push CS Configure each device to generate interrupts. g 4. Push EIP 5. Load CS, EIP from IDT.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 9  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 10 Interrupt Service Routine Event Abstraction 1. Record interrupt number. An event abstraction is the representation of an external event at the task level. 2. Switch into kernel. More than one event can be associated with a g 3. Send non-specific EOI to ICUs, otherwise they physical device, e.g., as for serial input and output. won’t generate any more interrupts: int AwaitEvent(int EventNumber) — block and g outb(IO_ICU1,0x20) wait for an instance of the specified event to occur. outb(IO_ICU2,0x20) Event may occur before int AwaitEvent is issued; g therefore buffer at least one instance of each kind of event.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 11  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 12

  4. Event Abstraction, Cont’d A Possible Application of Events Associate an event number with each hardware Block a task until the fulfillment of a condition, but g event. allow more than one task to fulfill the condition and then unblock the the waiting task. Can have also software events. g int SignalEvent(int EventNumber) — signals an g instance of the specified event, unblocking a task that is awaiting that event number.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 13  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 14 Server Implementation Server Implementation, Cont’d On Receive() , server is RECEIVE_BLOCKED g Client On AwaitEvent() , server is EVENT_BLOCKED g 1 Cannot service clients while EVENT_BLOCKED . . Cannot respond to events while AwaitEvent() Receive() . RECEIVE_BLOCKED . HW Server . ∴ , one type of event starves the other. How can we prevent this starvation? Client N  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 15  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 16

  5. Event Notifier Task Notifier Notifier(){ Client while(1){ 1 AwaitEvent(eventNumber); /* transform event to */ Send(Server,eventNumber,NULL); /* a message */ } . } . Notifier Server Then server needs to call only Receive() , and not AwaitEvent() . . Notifier and clients are then serviced in the order in which they send. External Client Event N  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 17  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 18 Server Implementation Server(){ New state: EVENT_BLOCKED Initialize(); CreateNotifier(); RegisterAs(…); while(1){ Event table: (tid,msg) ← Receive(); if (tid==Notifier){ indexed by event numbers g Reply(Notifier,NULL); serviceDevice(); buffers event information g } else { records waiting tasks if any g serviceRequest(); } } }  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 19  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 20

  6. Clock Server Delay Delay(int t) : Delay(int t){ int clock = WhoIs("clockServer"); Blocks caller for at least t ticks. Send(clock,(char *)&t,sizeof(t),NULL,0); g } A tick is 1/20 of a second. g Implemented by sending a message to clock server. g Clock server replies after at least t ticks. g  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 21  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 22 Clock Server A Problem What if ALL tasks, other than the clock server and Client notifier, call Delay() ? 1 What happens between now and the next clock tick? . Clock . Notifier Server . Clock Client Event N  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 23  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 24

  7. What Happens if All Delay? Always Running Task Kernel has no tasks to run. Create an idle task that never blocks, and runs at the g lowest priority! Kernel cannot wait for a hardware event to wake up g IdleTask(){ a notifier, while(1); because interrupts are disabled! } ∴ There needs to be a running task.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 25  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 26 Clock Server Loop Body ClockServer(){ (pid,request) ← Receive(); time = 0; if(pid == NOTIFIER){ InitializePIT(); time++; notifier = CreateClockNotifier(); Reply(pid,NULL); while(1){ while(nextWaitingTime() <= time){ Loop Body pid = dequeueWaitingTask(); } Reply(pid,NULL); } } } else { /* assuming that only request is Delay */ enqueueWaitingTask(pid,time + timeRequest); }  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 27  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 28

  8. Loop Body, Cont’d Clock Notifier This body assumes that there is only one kind of ClockNotifier(){ request, i.e., Delay . while(1){ AwaitEvent(PIT_EVENT); If there are others, the else part will have to have a Send(MyParentPid(),NULL,NULL); case to separate out which request it is. } }  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 29  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 30 Programmable Interval Timer Mode ? The programmable interval timer (PIT), the Intel 8253: Mode 1 = HW Interrupt or Exception in Virtual 8086 Mode Interrupt number 32 g Mode 2 = Maskable HW Interrupt in Virtual 8086 Counter 0 Mode g Mode 2 Mode 3 = SW Interrupt in Virtual 8086 Mode g For interrupt number and counter, see Diagram on Page 4.  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 31  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 32

  9. More Clock Primitives Delay vs DelayUntil int getTime() — returns the current tick count while (1){ Delay(x); DelayUntil(int t) — delay until a specified time t ; the doSomething(); } executing process is blocked to be awakened when tick count ≥ t . should have the same effect as These are optional in your kernel. t = getTime(); while (1){ t+=x; DelayUntil(t); doSomething(); }  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 33  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 34 Delay vs DelayUntil, Cont’d One Real Difference but they don’t. The doSomething takes time. ∴ , the period in the first case is x + time What’s the REAL Difference? ( doSomething ), and the period in the second case is x .  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 35  2007 Daniel M. Berry Real-Time Programming: Trains Pg. 36

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend