Presentation is loading. Please wait.

Presentation is loading. Please wait.

Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.

Similar presentations


Presentation on theme: "Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of."— Presentation transcript:

1 Time Management

2  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of the time of day, and current date  Measuring elapsed time  Measuring the time used by various activities and processes  Starting and stopping activities at specific times

3  A hardware clock is:  Is a physical device which measures time.  Causes periodic interrupts either at specific intervals, or upon the expiration of a preset time interval, and may need to be reset.  Control of clocks is provided via software using a clock driver, interrupt handlers, and timer management routines.  Typically, multiple software/virtual clocks can be based on the same physical clock.  Time of day clocks  Clocks to time processes  Each virtual clock is represented by a data item in main memory, which is updated appropriately when a signal is received from the hardware clock.

4 Physical clocks  Physical clocks generate precisely timed electronic pulses that synchronize the other components of the computer system, by periodically generating interrupts at a KNOWN frequency.  Master Clock: Every processor has a master clock that drives every cycle of the hardware operation. Today these clocks produce control signals, “ticks” at a rate of billions of times a second. This is too fast to be used directly by software.  Programmable clocks: These are implemented as a fixed-rate clock, and a counter register. These clocks have a “counter register” whose contents are decremented at a fixed interval, based on the master clock. When the value contained in this register reaches 0 then an interrupt is generated. Some clocks automatically refresh the counter register after an interrupt using a “holding register”, thus avoiding software overhead. The frequency of the interrupts for this type of clock can be set by the CPU. Typical frequencies are between 20 and 100 ticks per second.  The resolution of programmable clocks is relatively course. Time of day clocks based on programmable clocks can drift. Most modern processors provide a cycle counter that provides a running count of the number of master clock cycles since the system was started. This may be read directly when accurate timing information is required.

5 Clock Drivers  Drivers are software modules that provide control over external devices.  Clock drivers control clocks. These drivers provide service routines to:  Read and modify the value or behavior of both hardware and logical clocks.  Main responsibility is to deal with interrupts that represent clock ticks, which occur when a programmable clock’s counter has reached zero. These “ticks” are used to update software clocks.  Interrupt handlers for clocks are simple:

6 Clock_Interrupt:save registers increment Time_Of_Day_Clock IF Time_Of_Day_Clock > 24 hours THEN IF Time_Of_Day_Clock > 24 hours THEN set Time_of_Day_Clock to 0 advance date ENDIF restore registers restore registers RETURN from interrupt RETURN from interrupt

7 Time of Day services  One of the primary responsibilities of time management is to provide date and time of day services!  To do this the system must record the current date and time and provide this information (in a variety of ways) upon request. In its simplest form a clock interrupt handler might maintain a counter of the # of clock ticks in 24 hours

8 Clock_Interrupt:save registers increment #_of_ticks_Counter IF #_of_ticks_Counter > 1 second THEN IF #_of_ticks_Counter > 1 second THEN Set #_of_ticks_counter to 0 Advance second_counter If second_counter > 24 hours then Set second_counter to 0 Advance date Endifendif restore registers restore registers RETURN from interrupt RETURN from interrupt

9  Frequently clock interrupt handlers, are written to determine the cause of the interrupt, reset the physical clock, resume interrupts, then call a second level interrupt handler, to start events associated with the interrupt.

10 Date Services  A separate counter is maintained for the current date.  Can be stored separately as “day, month, and Year”  Most store the # of days since some base date  # of seconds since midnight on the selected base date

11 Timing services :  providing "watchdog" or monitoring timers for systems processes and expected events:  The scheduler uses this mechanism to generate an interrupt that will preempt a process at the end of its time slice  Disk I/O subsystem uses it to invoke the flushing of dirty cache buffers to disk.  Interruption of operations that are proceeding too slowly, or have encountered an error and may have stopped.  providing suspension of a process for a specified interval  providing suspension of a process until a specific time of day  providing for the startup of a process at a specific time of day  providing for cancellation of previous timer requests

12 Timer Queues  The OS can support more timer requests than the number of physical hardware timers, by simulating virtual clocks.  To do this a list of interrupts wanted, with a FIFO ordering, is maintained in a timer queue.  Like a process queue, a timer queue is implemented to keep track of timing requests generated either by individual processes or the OS itself  The “time” associated with the first request in the list is associated with a programmable timer. This can be implemented in multiple ways:

13 8430 Current time * 8437 A * 8442 B * 8450 C * 8453 D * 8457 E * 8467 F PCB Front of queue Each element contains the time in clock ticks, when an event is to be triggered. When the current time matches the “time” stored in the first timer element, the event associated with that element is performed, a timer element will also contain a link to a PCB associated with the event, and an address of a routine that is to be executed to perform the event.

14 TIMER SEARCH: SET P TO THE TOP_TQE DO WHILE TIME_OF_DAY_CLOCK > P->TQE_TOD SCHEDULE ACTION OF P->TQE SET P TO NEXT TQE ENDWHILE SET TOP_TQE POINTER TO TQE POINTED TO BY P RETURN The overhead required for processing the timer queue is potentially high

15 Storing Intervals in elements 8430 Current time * 7 A * 5 B * 8 C * 3 D * 4 E * 10 F Front of queue Request for 8437, 8430+7 Request for 8442, 8437+5 Request for 8450 Time in the top element is reduced with each tick

16 * 7 A * 0 B * 0 C * 3 D * 4 E * 10 F Front of queue 8430 Current time Request for 8437, 8430+7 Request for 8440, 8437+3

17 Programmable clock 730 # of clock ticks until the event is to be triggered Timer Queue Head * 730 A * 405 B Programmable clock 685 Timer Queue Head * 730 A * 405 B Alternately measure elapsed time, by placing the time associated with the front element in a programmable timer, when the timer ticks down the event associated with that element is performed.

18 Programmable clock 685 Timer Queue Head * 730 A * 405 B A new request arrives for a time interval of 457 Programmable clock 457 Timer Queue Head * 405 B * 228 A * 457 C Timer interval in A reset to the time remaining in the programmable clock, minus the time interval of the new event. 685 – 457 = 228

19 Adding new timing requests  Determining the time interval for the new element  Searching the queue until an element is found whose event should occur after the time interval for the new element.  Inserting the new element into the queue  Adjusting the time interval of the element, in front of which the new element has been inserted.

20 Current time= 8430 Timerq_head 18 G 7 A 5 B 8 C 3 D 4 E 10 F

21 Current time= 8430 Timerq_ head 7 A 5 B 6 G 2 C 3 D 4 E 10 F

22 Deleting element C Current time= 8430 Timerq_ head 7 A 5 B 6 G 2 C 3 D 4 E 10 F 5 D 4 E F

23 Timing issues:  The time spent processing a clock interrupt is critical to the accuracy of the timing facility within an OS.  We must update the hardware clock as quickly as possible  The accuracy of triggers is limited by the resolution of the timer together with the overhead of maintaining virtual clocks.  Must be the highest priority interrupt if clock ticks are to be counted accurately.  Ability to block all but clock interrupts will allow critical work to be done, but still maintaining the accuracy of the clock

24 Contents of the timer queue element:  Pointers to the next (and previous element)  Time quantum  Link to the PCB of requesting process  Address of a procedure to call (representing the action to perform)  Type of request (user or OS) Next Element Time Quantum PCB Address Action Routine Address Type of Request


Download ppt "Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of."

Similar presentations


Ads by Google