Home

Part 6 - School of Computer Science Student WWW Server

image

Contents

1. CS452 652 Real Time Programming Course Notes Daniel M Berry Cheriton School of Computer Science University of Waterloo 2007 Daniel M Berry Real Time Programming Trains Pg 1 Documentation Requirements For the Kernel Assignment e Description of all major components of the system e g memory management task management context switching Context switching should be described in detail e Description of kernel data structures and algorithms e g task descriptors scheduler etc e Description of syscall implementation including parameter passing 2007 Daniel M Berry Real Time Programming Trains Pg 2 Doc Regs Cont d e Explain why your implementation meets real time requirements by giving the complexity of each kernel operation e Description of test cases including that they cover what should be tested e User s manual e Tour of source code 2007 Daniel M Berry Real Time Programming Trains Pg 3 Hardware Interrupts USART1 7 6 USARTO 5 4 ICUO 3 8259 _ 2 INT 1 a 2 CPU 8259 0 PIT RTC BUS 2007 Daniel M Berry Real Time Programming Trains Pg 4 Acronyms USART Universal Synchronous Asynchronous Receiver Transmitter ICU Interrupt Control Unit RTC Real Time Clock PIT Programmable Interval Timer It bothers me that RTC and
2. PIT are different because of the chances for drift 2007 Daniel M Berry Real Time Programming Trains Pg 5 How A Device Speaks to CPU 1 External event occurs 2 Device asserting interrupt asserts its interrupt line 3 Interrupts are priority ranked by the ICU which interrupts the CPU 4 CPU reads IRQ interrupt request level from ICU data bus 5 CPU begins interrupt processing 2007 Daniel M Berry Real Time Programming Trains Pg 6 Interrupt Numbers 0 31 Processor Internal GPF division by zero etc 31 39 First ICU IRQO IRQ7 40 47 Second ICU IRQ8 IRQI5 48 255 Software Interrupts for int n be sure that n248 2007 Daniel M Berry Real Time Programming Trains Pg 7 To Make Interrupts Happen e Enable Interrupts by setting IF Interrupt Enable Flag which is stored in EFLAGS register e Instructions are STI set IF enable CLI clear IF disable 2007 Daniel M Berry Real Time Programming Trains Pg 8 Happening Cont d e Interrupts are o enabled in non kernel tasks o disabled in the kernel and o enabled at boot up e Unmask interrupts of interest in ICUs e Configure each device to generate interrupts 2007 Daniel M Berry Real Time Programming Trains Pg 9 CPU s response to an Interrupt 1 Push EFLAGS including current IF 2 Clear IF and TF trap flag to enable single stepping in single step mode each instruction is
3. only request is Delay enqueueWaiting Task pid time timeRequest 2007 Daniel M Berry Real Time Programming Trains Pg 28 Loop Body Cont d This body assumes that there is only one kind of request i e Delay If there are others the else part will have to have a case to separate out which request it is 2007 Daniel M Berry Real Time Programming Trains Pg 29 Clock Notifier ClockNotifier while 1 AwaitEvent PIT_EVENT Send MyParentPid NULL NULL 2007 Daniel M Berry Real Time Programming Trains Pg 30 Programmable Interval Timer The programmable interval timer PIT the Intel 8253 e Interrupt number 32 e Counter 0 e Mode 2 For interrupt number and counter see Diagram on Page 4 2007 Daniel M Berry Real Time Programming Trains Pg 31 Mode Mode 1 HW Interrupt or Exception in Virtual 8086 Mode Mode 2 Maskable HW Interrupt in Virtual 8086 Mode Mode 3 SW Interrupt in Virtual 8086 Mode 2007 Daniel M Berry Real Time Programming Trains Pg 32 More Clock Primitives int getTime returns the current tick count DelayUntil int t delay until a specified time t the executing process is blocked to be awakened when tick count 2 t These are optional in your kernel 2007 Daniel M Berry Real Time Programming Trains Pg 33 Delay vs DelayUntil while 1 Delay x doSomething should have the same
4. sending a message to clock server e Clock server replies after at least t ticks 2007 Daniel M Berry Real Time Programming Trains Pg 21 Delay Delay int t int clock Whols clockServer Send clock char amp t sizeof t NULL O 2007 Daniel M Berry Real Time Programming Trains Pg 22 Clock Server 2007 Daniel M Berry Real Time Programming Trains Pg 23 A Problem What if ALL tasks other than the clock server and notifier call Delay What happens between now and the next clock tick 2007 Daniel M Berry Real Time Programming Trains Pg 24 What Happens if All Delay e Kernel has no tasks to run e Kernel cannot wait for a hardware event to wake up a notifier because interrupts are disabled There needs to be a running task 2007 Daniel M Berry Real Time Programming Trains Pg 25 Always Running Task Create an idle task that never blocks and runs at the lowest priority IdleTask while 1 2007 Daniel M Berry Real Time Programming Trains Pg 26 Clock Server ClockServer time 0 InitializePIT notifier CreateClockNotifier while 1 Loop Body 2007 Daniel M Berry Real Time Programming Trains Pg 27 Loop Body pid request Receive if pid NOTIFIER time Reply pid NULL while nextWaiting Time lt time pid dequeueWaiting Task Reply pid NULL else assuming that
5. 2007 Daniel M Berry Real Time Programming Trains Pg 45 Serial Server Cont d Like the producer consumer problem but with multiple producers and multiple consumers 2007 Daniel M Berry Real Time Programming Trains Pg 46 What If ey eg a Server Serial events 2007 Daniel M Berry Real Time Programming Trains Pg 47 Too Many Readers Too many readers or writers or both could starve the notifier and the notifier could miss interrupts How can we ensure that the notifier does not miss interrupts and answers them on time 2007 Daniel M Berry Real Time Programming Trains Pg 48 Guard Process fead ar a E me ee ay a Writer T ko A 2007 Daniel M Berry D A Serial 1 Server Serial events Real Time Programming Trains Pg 49 Guard Guard serialServer MyParentPid while 1 tidsmsg lt Receive replyMsg lt Send serialServer msg Reply tid replyMsg Should there be a delay guard for the clock server
6. an interrupt 3 Push CS 4 Push EIP 5 Load CS EIP from IDT 2007 Daniel M Berry Real Time Programming Trains Pg 10 Interrupt Service Routine 1 Record interrupt number 2 Switch into kernel 3 Send non specific EOI to ICUs otherwise they won t generate any more interrupts outb IO_ICU1 0x20 outb IO_ICU2 0x20 2007 Daniel M Berry Real Time Programming Trains Pg 11 Event Abstraction An event abstraction is the representation of an external event at the task level e More than one event can be associated with a physical device e g as for serial input and output e int AwaitEvent int EventNumber block and wait for an instance of the specified event to occur e Event may occur before int AwaitEvent is issued therefore buffer at least one instance of each kind of event 2007 Daniel M Berry Real Time Programming Trains Pg 12 Event Abstraction Cont d e Associate an event number with each hardware event e Can have also software events e int SignalEvent int EventNumber signals an instance of the specified event unblocking a task that is awaiting that event number 2007 Daniel M Berry Real Time Programming Trains Pg 13 A Possible Application of Events Block a task until the fulfillment of a condition but allow more than one task to fulfill the condition and then unblock the the waiting task 2007 Daniel M Berry Real Time Programmin
7. ding Register for reading from the serial port Receiver Buffer Register for writing to the serial port 2007 Daniel M Berry Real Time Programming Trains Pg 40 Registers Cont d Interrupt Enable Register for enabling and disabling interrupts Interrupt Types e Received Data Available e Transmit Holding Register Empty e Receiver Line Status for error conditions e Modem Status not needed Interrupt Identification Register to determine what kind of interrupt fired 2007 Daniel M Berry Real Time Programming Trains Pg 41 Registers Cont d Line Control Register to initialize the chip with parity stop bits etc Line Status Register diagnostics e g ready error conditions etc 2007 Daniel M Berry Real Time Programming Trains Pg 42 Primitives for Kernel Part III ClockServer required Delay int t optional int GetTime Delay Unitil int t 2007 Daniel M Berry Real Time Programming Trains Pg 43 Kernel Part III Cont d SerialServer required byte GetPort port Put byte port optional write port buffer length atomically read port buffer length readLine port buffer length See Complete I O Port List 2007 Daniel M Berry Real Time Programming Trains Pg 44 Serial Server fead Sar PAP a r Serial Server __ UART writer ae G D ae os One notifier per port writer ae
8. effect as t getTime while 1 t x DelayUntil t doSomething Delay vs DelayUntil Cont d but they don t What s the REAL Difference 2007 Daniel M Berry Real Time Programming Trains Pg 35 One Real Difference The doSomething takes time the period in the first case is X time doSomething and the period in the second case is X 2007 Daniel M Berry Real Time Programming Trains Pg 36 Another Real Difference Amount of delay 2 x say X These s accumulate under successive Delays but These s do not accumulate under successive DelayUntils lt DelayUntil enforces stricter periodicity 2007 Daniel M Berry Real Time Programming Trains Pg 37 Scheduling Options time slicing vs run to completion fair efficient 2007 Daniel M Berry Real Time Programming Trains Pg 38 When to Reschedule Rescheduling when a task calls the kernel Pass must reschedule Should interrupt currently executing task periodically e g every k ticks to force rescheduling for round robin purposes Preemption required when a task of a priority higher than that of the running task becomes READY due to an external event 2007 Daniel M Berry Real Time Programming Trains Pg 39 Serial Chip Serial Chip PC16550D Universal Asynchronous Receiver Transmitter UART See Documentation from byterunner Registers Transmit Hol
9. g Trains Pg 14 Server Implementation HW AwaitEvent 2007 Daniel M Berry Real Time Programming Trains Pg 15 Server Implementation Cont d e On Receive server is RECEIVE_ BLOCKED e On AwaitEvent server is EVENT BLOCKED Cannot service clients while EVENT_BLOCKED Cannot respond to events while RECEIVE BLOCKED lt one type of event starves the other How can we prevent this starvation 2007 Daniel M Berry Real Time Programming Trains Pg 16 Event Notifier Task External Event N otifier Notifier while 1 AwaitEvent eventNumber transform event to Send Server eventNumber NULL a message Then server needs to call only Receive and not AwaitEvent Notifier and clients are then serviced in the order in which they send Server mplementation Server Initialize CreateNotifier RegisterAs NeW ste PNT BEOURED while 1 tid msg lt Receive if tid Notifier Reply Notifier NULL serviceDevice else serviceRequest 2007 Daniel M Berry Real Time Programming Trains Pg 19 Event table e indexed by event numbers e buffers event information e records waiting tasks if any 2007 Daniel M Berry Real Time Programming Trains Pg 20 Clock Server Delay int t e Blocks caller for at least t ticks e A tick is 1 20 of a second e Implemented by

Download Pdf Manuals

image

Related Search

Related Contents

  SRM-SUS-UM-Buyer  Sunfire Theater Grand III  Manuale Uso e Manutenzione Serie  U3700 Series User's Guide  Radio Shack PT-668C User's Manual  Maytag 6919559A Dishwasher User Manual  Samsung SCX-5935NX multifunctional  Inventaire 22 Avenue Pasteur appartement N°3  Hors série n°7 Artension  

Copyright © All rights reserved.
Failed to retrieve file