Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Real-Time Library: RTX
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
Kernighan/Ritchie: Kelley/Pohl:
The Process Control Block From: A Process Control Block (PCB, also called Task Control Block or Task Struct) is.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Timers Timer – Keeps track of the passage of time Simple Timer – Measures elapsed time, reporting it when queried Interval Timer – –Generates an interrupt.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
CS4514 Assignment 2 Help Session – Data Link Layer Client and Server Processes Speaker: Hao Shang Date: Nov. 11th, 2004.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Signal Signal : - is a notification sent to a process to notify it of some event - interrupts whatever the process is doing and force it to handle a signal.
1 CS4514 – B03 Project 2 Help Session Choong-Soo Lee November 24, 2003.
Dr. Hugh Melvin, Dept. of IT, NUI,G1 POSIX POSIX: Portable OS Interface –IEEE standard –Mandatory + Optional parts Mostly based on and adopted by Unix.
Timers Timer – Keeps track of the passage of time Simple Timer – Measures elapsed time, reporting it when queried Interval Timer – –Generates an interrupt.
1 CS4514 Project 2 Help Session (B05) Mingzhe Li Nov 10, 2005.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
CS4516: Medical Examiner Client/Server Evan Frenn 1.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Signals & Timers CS241 Discussion Section Spring 2009 Week 6.
Introduction to Embedded Systems A/D & D/A Conversion Lecture 20.
4061 Session 17 (3/19). Today Time in UNIX Today’s Objectives Define what is meant when a system is called “interrupt-driven” Describe some trade-offs.
8254 Programmable Interval Timer
ASQF Fachgruppe Automation/ Automation Day 1 Realtime capable Linux: Requirements (Standard)LinuxRealtime LinuxRealtime kernel One (physical) address space.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Real-Time Systems Design1 Priority Inversion When a low-priority task blocks a higher-priority one, a priority inversion is said to occur Assume that priorities:
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Timers and Clocks.
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
LAB 12: Timer and Interrupt Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Scheduling II: priority scheduling.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.
NCHU System & Network Lab Lab #8 Signals Operating System Lab.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Files and file allocation.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 C Basics Tarek Abdelzaher and Vikram Adve.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Operating System Overview Tarek Abdelzaher Lawrence Angrave Vikram Adve.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
Time Sources and Timing David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Signals.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 University of Illinois at Urbana-Champaign Welcome to CS 241 Systems Programming University of Illinois.
Scheduling.
Start the Quiz Show the answer Check the answer Time’s up! Timer
Timers and Time Management Ok-Kyun Ha
Event Sources and Realtime Actions
MQX GPIO.
Operating System Overview
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo
Copyright ©: Nahrstedt, Angrave, Abdelzaher
CS 6560: Operating Systems Design
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Time Sources and Timing
Protection of System Resources
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Tarek Abdelzaher Vikram Adve Marco Caccamo
CS4514 Project 2 Help Session (B07)
Processor Fundamentals
Time Sources and Timing
Signals.
Presentation transcript:

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II

Copyright ©: Nahrstedt, Angrave, Abdelzaher 2 Interval Timers Set an alarm: on its expiration send a signal Set a signal handler to do something with the signal POSIX:TMR has at least 1 real-time clock, but a process can create many independent timers Most systems require the program be linked with the librt library to use these functions.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 3 Real Time Clock & timers Timers can be used to send a signal to a process after a specified period of time has elapsed. Timers may be used in one of two modes: one-shot or periodic: when a one-shot timer is set up, a value time is specified. When that time has elapsed, the operating system sends the process a signal and deletes the timer. when a periodic timer is set up, both a value and an interval time are specified. When the value time has elapsed, the operating system sends the process a signal and reschedules the timer for interval time in the future. When the interval time has elapsed, the OS sends another signal and again reschedules the timer for interval time in the future. This will continue until the process manually deletes the timer. By default a timer will send the SIGALRM signal. If multiple timers are used in one process, however, there is no way to determine which timer sent a particular SIGALRM. Therefore, an alternate signal, like SIGUSR1, may be specified when the timer is created.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 4 POSIX.4 Real Time Clock & timers Resolution of timers: Timers are maintained by the operating system, and they are only checked periodically. A timer that expires between checks will be signaled (and rescheduled if periodic) at the next check. As a result, a process may not receive signals at the exact time(s) that it requested. The period at which the timers are checked, called the clock resolution, is operating system and hardware dependent (~1 msec in PC without add-on high resolution real time clock cards). The actual value can be determined at runtime by calling clock_getres() on the system-wide real-time clock (CLOCK_REALTIME). According to POSIX, there is at least 1 real-time clock (CLOCK_REALTIME)

Copyright ©: Nahrstedt, Angrave, Abdelzaher 5 Real Time Clock & timers Resolution of timers: For example, suppose the OS checks the timers every 10 milliseconds and a process schedules a periodic timer with value = 5 milliseconds and interval = 21 milliseconds. Quiz: what is the period of alarm signals?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 6 Real Time Clock & timers Resolution of timers: For example, suppose the OS checks the timers every 10 milliseconds and a process schedules a periodic timer with value = 5 milliseconds and interval = 21 milliseconds. Quiz: what is the period of alarm signals? Answer: after the first signal, the process will receive a signal every 30 milliseconds.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 7 Real Time Clock & timers Operations: Create_timer() is used to create a new timer. As with clock_getres(), the system-wide real-time clock (CLOCK_REALTIME) should be used. The following code shows how to create a timer that sends the default SIGALRM signal. timer_t timer1; // create a new timer that sends the default SIGALARM signal if (timer_create (CLOCK_REALTIME, NULL, &timer1) != 0) { perror(“timer create”); exit(1); } NULL specifies that default SIGALARM will be delivered!

Copyright ©: Nahrstedt, Angrave, Abdelzaher 8 Timers: struct sigevent If a different signal needs to be sent on timer expiration, then the second argument of timer_create takes a pointer to struct sigevent to specify a different signal to be sent. struct sigevent { int sigev_notify; /* notification type */ int sigev_signo; /* signal number */ union sigval sigev_value; /* Extra data to be delivered with a real-time signal! */ } sigev_notify SIGEV_NONE- No notification from timer SIGEV_SIGNAL- Send a signal

Copyright ©: Nahrstedt, Angrave, Abdelzaher 9 Real Time Clock & timers Operations: The following code shows how to create a timer that sends the SIGUSR1 signal: timer_t timerid; struct sigevent se; // Zero out the data structure and configure it for using SIGUSR1 signal memset(&se, 0, sizeof(se)); se.sigev_signo = SIGUSR1; se.sigev_notify = SIGEV_SIGNAL; // Create a new timer that will send the SIGUSR1 signal if (timer_create(CLOCK_REALTIME, &se, &timerid) != 0) { perror("Failed to create timer”); exit(1); }

Copyright ©: Nahrstedt, Angrave, Abdelzaher 10 Real Time Clock & timers The timer_settime() function is used to schedule a timer. The struct itimerspec definition taken from /usr/include/linux/time.h is seen here. The it_value member sets the time until the timer first expires. If it is set to 0, the timer will never go off. The it_interval member sets the period of the timer after it first expires. If it is set to 0, the timer will be one-shot. struct itimerspec { struct timespec it_interval; /* Timer period */ struct timespec it_value; /* Timer initial expiration */ }; struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ };

Copyright ©: Nahrstedt, Angrave, Abdelzaher 11 Real Time Clock & timers Example of scheduling timer1 (created in a preceding example) to go off in 2.5 seconds, and then every 100 milliseconds thereafter. struct itimerspec timervals; // The it_value member sets the time until the timer first goes off (2.5 seconds). // The it_interval member sets the period of the timer after it first goes off (100 ms). timervals.it_value.tv_sec = 2;// 2 seconds timervals.it_value.tv_nsec = ;// 0.5 seconds (5e8 nanoseconds) timervals.it_interval.tv_sec = 0;// 0 seconds timervals.it_interval.tv_nsec = ;// 100 milliseconds (1e8 nanoseconds) // Schedule the timer if (timer_settime(timerid, 0, &timervals, NULL) != 0) { perror("Failed to start timer"); exit(1); } Pointer to old timer spec! It specifies a “relative timer”: it does not use absolute time!

Copyright ©: Nahrstedt, Angrave, Abdelzaher 12 POSIX Real Time Clocks POSIX defines the structure of time representation. There is at least 1 real time clock. We can check the current time with clock_gettime and check the clock resolution with clock_getres. See the following example: #include struct timespec current_time, clock_resolution; return_code = clock_gettime( CLOCK_REALTIME, &current_time); //check return_code... Printf(“current time in CLOCK_REALTIME is %d, %d \n”, current_time.tv_sec,// the second portion current_time.tv_nsec); // the fractional portion in nsec representation return_code = clock_getres( CLOCK_REALTIME, &clock_resolution) //check return_code... printf(“ CLOCK_REALTIME’s resolution is %d, %d \n”, clock_resolution.tv_sec, clock_resolution.tv_nsec);