Time Measurement October 25, 2001 Topics Time scales Interval counting Cycle counters K-best measurement scheme 15-213 class18.ppt.

Slides:



Advertisements
Similar presentations
Time Measurement Topics Time scales Interval counting Cycle counters K-best measurement scheme time.ppt CS 105 Tour of Black Holes of Computing.
Advertisements

Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
Virtual Memory Introduction to Operating Systems: Module 9.
CSCE 3121 Computer Organization Lecture 1. CSCE 3122 Course Overview Topics: –Theme –Five great realities of computer systems –Computer System Overview.
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
© 2004, D. J. Foreman 1 O/S Organization. © 2004, D. J. Foreman 2 Topics  Basic functions of an OS ■ Dev mgmt ■ Process & resource mgmt ■ Memory mgmt.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
1 Lecture 6 Performance Measurement and Improvement.
Introduction to Operating Systems What is an operating system? Examples How do many programs run at the same time, with one processor?
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Processes 1 CS502 Spring 2006 Processes Week 2 – CS 502.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Time Measurement CS 201 Gerson Robboy Portland State University Topics Time scales Interval counting Cycle counters K-best measurement scheme.
Copyright © 1998 Wanda Kunkle Computer Organization 1 Chapter 2.1 Introduction.
Introduction to Computer Systems Topics: Theme Five great realities of computer systems How this fits within CS curriculum CS 213 F ’03 class01a.ppt
Lecture 3: Computer Performance
Time Measurement Topics Time scales Interval counting Cycle counters K-best measurement scheme class18.ppt.
Time Measurement December 9, 2004 Topics Time scales Interval counting Cycle counters K-best measurement scheme Related tools & ideas class29.ppt
Introduction to Computer Systems Topics: Theme Five great realities of computer systems How this fits within CS curriculum F ’04 class01a.ppt
1 Physical Clocks need for time in distributed systems physical clocks and their problems synchronizing physical clocks u coordinated universal time (UTC)
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Operating system Structure and Operation by Dr. Amin Danial Asham.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems Process Management.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 4 Computer Systems Review.
Lecture 2a: Performance Measurement. Goals of Performance Analysis The goal of performance analysis is to provide quantitative information about the performance.
Computer Organization Instruction Set Architecture (ISA) Instruction Set Architecture (ISA), or simply Architecture, of a computer is the.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Time Sources and Timing David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Performance Evaluation May 2, 2000 Topics Getting accurate measurements Amdahl’s Law class29.ppt.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Real-World Pipelines Idea –Divide process into independent stages –Move objects through stages in sequence –At any given times, multiple objects being.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Measuring Time Alan L. Cox Some slides adapted from CMU slides.
Chapter Overview General Concepts IA-32 Processor Architecture
Real-World Pipelines Idea Divide process into independent stages
Chapter 2: Computer-System Structures
Processes and threads.
CS501 Advanced Computer Architecture
Homework Reading Machine Projects Labs
Time Sources and Timing
Computer Organization & Assembly Language Chapter 3
Time Sources and Timing
CS2100 Computer Organisation
Chapter 8: Main Memory.
Pipelining: Advanced ILP
Introduction to Computer Systems
Computer-System Architecture
Introduction to Computer Systems
Time Sources and Timing
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
CS2100 Computer Organisation
Presentation transcript:

Time Measurement October 25, 2001 Topics Time scales Interval counting Cycle counters K-best measurement scheme class18.ppt

CS 213 F’01– 2 – class18.ppt Computer Time Scales Two Fundamental Time Scales Processor: ~10 –9 seconds External events: ~10 –2 seconds –Keyboard input –Disk seek –Screen refresh Implication Can execute many instructions while waiting for external event to occur Can alternate among processes without anyone noticing Time Scale (1 Ghz Machine) 1.E-091.E-061.E-031.E+00 Time (seconds) 1 ns 1  s 1 ms1 s Integer Add FP Multiply FP Divide Keystroke Interrupt Handler Disk Access Screen Refresh Keystroke Microscopic Macroscopic

CS 213 F’01– 3 – class18.ppt Measurement Challenge How Much Time Does Program X Require? CPU time –How many total seconds are used when executing X? –Measure used for most applications –Small dependence on other system activities Actual (“Wall”) Time –How many seconds elapse between the start and the completion of X? –Depends on system load, I/O times, etc. Confounding Factors How does time get measured? Many processes share computing resources –Transient effects when switching from one process to another –Suddenly, the effects of alternating among processes become noticeable

CS 213 F’01– 4 – class18.ppt “Time” on a Computer System real (wall clock) time = user time (time executing instructing instructions in the user process) += real (wall clock) time We will use the word “time” to refer to user time. = system time (time executing instructing instructions in kernel on behalf of user process) + = some other user’s time (time executing instructing instructions in different user’s process) cummulative user time

CS 213 F’01– 5 – class18.ppt Activity Periods: Light Load Most of the time spent executing one process Periodic interrupts every 10ms –Interval timer –Keep system from executing one process to exclusion of others Other interrupts –Due to I/O activity Inactivity periods –System time spent processing interrupts –~250,000 clock cycles

CS 213 F’01– 6 – class18.ppt Activity Periods: Heavy Load Sharing processor with one other active process Periodic interrupts every 10ms –Interval timer –Keep system from executing one process to exclusion of others Other interrupts –Due to I/O activity Inactivity periods –System time spent processing interrupts –Periods when other process executes

CS 213 F’01– 7 – class18.ppt Interval Counting OS Measures Runtimes Using Interval Timer Each time get timer interrupt, increment timer for executing process –User time if running in user mode –System time if running in kernel mode

CS 213 F’01– 8 – class18.ppt Unix time Command 0.82 seconds user time –82 timer intervals 0.30 seconds system time –30 timer intervals 1.32 seconds wall time 84.8% of total was used running these processes –( )/1.32 =.848 time make osevent gcc -O2 -Wall -g -march=i486 -c clock.c gcc -O2 -Wall -g -march=i486 -c options.c gcc -O2 -Wall -g -march=i486 -c load.c gcc -O2 -Wall -g -march=i486 -o osevent osevent.c u 0.300s 0: % 0+0k 0+0io 4049pf+0w

CS 213 F’01– 9 – class18.ppt Accuracy of Interval Counting Worst Case Analysis Timer Interval =  Single process segment measurement can be off by  No bound on error for multiple segments –Could consistently underestimate, or consistently overestimate Average Case Analysis Over/underestimates tend to balance out As long as total run time is sufficiently large > 1 second Consistently miss 4% overhead due to timer interrupts Computed time = 70ms Min Actual = 60 +  Max Actual = 80 – 

CS 213 F’01– 10 – class18.ppt Cycle Counters Most modern systems have built in registers that are incremented every clock cycle –Very fine grained –Maintained as part of process state »In Linux, counts elapsed global time Special assembly code instruction to access On (recent model) Intel machines: –64 bit counter. –RDTSC instruction sets %edx to high order 32-bits, %eax to low order 32-bits Wrap Around Times for 1 GHz machine –Low order 32-bits wrap around every 2 32 / 10 9 = 4.3 seconds –High order 64-bits wrap around every 2 64 / 10 9 = 18.5* 10 6 seconds = 586 years

CS 213 F’01– 11 – class18.ppt Measuring with Cycle Counter Idea Get current value of cycle counter –store as pair of unsigned’s cyc_hi and cyc_lo Compute something Get new value of cycle counter Perform double precision subtraction to get elapsed cycles /* Keep track of most recent reading of cycle counter */ static unsigned cyc_hi = 0; static unsigned cyc_lo = 0; void start_counter() { /* Get current value of cycle counter */ access_counter(&cyc_hi, &cyc_lo); }

CS 213 F’01– 12 – class18.ppt Accessing the Cycle Counter (cont.) GCC allows inline assembly code with mechanism for matching registers with program variables Code only works on x86 machine compiling with GCC Emit assembly with rdtsc and two movl instructions Code generates two outputs: –Symbolic register %0 should be used for *hi –Symbolic register %1 should be used for *lo Code has no inputs Registers %eax and %edx will be overwritten void access_counter(unsigned *hi, unsigned *lo) { /* Get cycle counter */ asm("rdtsc; movl %edx,%0; movl %eax,%1" : "=r" (*hi), "=r" (*lo) : /* No input */ : "%edx", "%eax"); }

CS 213 F’01– 13 – class18.ppt Accessing the Cycle Counter (cont.) Emitted Assembly Code movl 8(%ebp),%esi# hi movl 12(%ebp),%edi# lo #APP rdtsc; movl %edx,%ecx; movl %eax,%ebx #NO_APP movl %ecx,(%esi)# Store high bits at *hi movl %ebx,(%edi)# Store low bits at *lo

CS 213 F’01– 14 – class18.ppt Completing Measurement Get new value of cycle counter Perform double precision subtraction to get elapsed cycles Express as double to avoid overflow problems double get_counter() { unsigned ncyc_hi, ncyc_lo unsigned hi, lo, borrow; /* Get cycle counter */ access_counter(&ncyc_hi, &ncyc_lo); /* Do double precision subtraction */ lo = ncyc_lo - cyc_lo; borrow = lo > ncyc_lo; hi = ncyc_hi - cyc_hi - borrow; return (double) hi * (1 << 30) * 4 + lo; }

CS 213 F’01– 15 – class18.ppt Timing With Cycle Counter Determine Clock Rate of Processor Count number of cycles required for some fixed number of seconds Time Function P First attempt: Simply count cycles for one execution of P double tsecs; start_counter(); P(); tsecs = get_counter() / (MHZ * 1e6); double MHZ; int sleep_time = 10; start_counter(); sleep(sleep_time); MHZ = get_counter()/(sleep_time * 1e6);

CS 213 F’01– 16 – class18.ppt Timing with Cycle Counter double tsecs; start_counter(); P(); tsecs = get_counter() / (MHZ * 1e6); double MHZ; int sleep_time = 10; start_counter(); sleep(sleep_time); MHZ = get_counter()/(sleep_time * 1e6);

CS 213 F’01– 17 – class18.ppt Measurement Pitfalls Overhead Calling get_counter() incurs small amount of overhead Want to measure long enough code sequence to compensate Unexpected Cache Effects artificial hits or misses e.g., these measurements were taken with the Alpha cycle counter: foo1(array1, array2, array3); /* 68,829 cycles */ foo2(array1, array2, array3); /* 23,337 cycles */ vs. foo2(array1, array2, array3); /* 70,513 cycles */ foo1(array1, array2, array3); /* 23,203 cycles */

CS 213 F’01– 18 – class18.ppt Dealing with Overhead & Cache Effects Always execute function once to “warm up” cache Keep doubling number of times execute P() until reach some threshold –Used CMIN = int cnt = 1; double cmeas = 0; double cycles; do { int c = cnt; P();/* Warm up cache */ get_counter(); while (c-- > 0) P(); cmeas = get_counter(); cycles = cmeas / cnt; cnt += cnt; } while (cmeas < CMIN); /* Make sure have enough */ return cycles / (1e6 * MHZ);

CS 213 F’01– 19 – class18.ppt Multitasking Effects Cycle Counter Measures Elapsed Time Keeps accumulating during periods of inactivity –System activity –Running other processes Key Observation Cycle counter never underestimates program run time Possibly overestimates by large amount K-Best Measurement Scheme Perform up to N (e.g., 20) measurements of function See if fastest K (e.g., 3) within some relative factor  (e.g., 0.001) K

CS 213 F’01– 20 – class18.ppt K-Best Validation Very good accuracy for < 8ms Within one timer interval Even when heavily loaded Less accurate of > 10ms Light load: ~4% error –Interval clock interrupt handling Heavy load: Very high error K = 3,  = 0.001

CS 213 F’01– 21 – class18.ppt Compensate For Timer Overhead Subtract Timer Overhead Estimate overhead of single interrupt by measuring periods of inactivity Call interval timer to determine number of interrupts that have occurred Better Accuracy for > 10ms Light load: 0.2% error Heavy load: Still very high error K = 3,  = 0.001

CS 213 F’01– 22 – class18.ppt K-Best on NT Acceptable accuracy for < 50ms Scheduler allows process to run multiple intervals Less accurate of > 10ms Light load: 2% error Heavy load: Generally very high error K = 3,  = 0.001

CS 213 F’01– 23 – class18.ppt Time of Day Clock Unix gettimeofday() function Return elapsed time since reference time (Jan 1, 1970) Implementation –Uses interval counting on some machines »Coarse grained –Uses cycle counter on others »Fine grained, but significant overhead and only 1 microsecond resolution #include struct timeval tstart, tfinish; double tsecs; gettimeofday(&tstart, NULL); P(); gettimeofday(&tfinish, NULL); tsecs = (tfinish.tv_sec - tstart.tv_sec) + 1e6 * (tfinish.tv_usec - tstart.tv_usec);

CS 213 F’01– 24 – class18.ppt K-Best Using gettimeofday Linux As good as using cycle counter For times > 10 microseconds Windows Implemented by interval counting Too coarse-grained

CS 213 F’01– 25 – class18.ppt Measurement Summary Timing is highly case and system dependent What is overall duration being measured? –> 1 second: interval counting is OK –<< 1 second: must use cycle counters On what hardware / OS / OS version? –Accessing counters »How gettimeofday is implemented –Timer interrupt overhead –Scheduling policy Devising a Measurement Method Long durations: use Unix timing functions Short durations –If possible, use gettimeofday –Otherwise must work with cycle counters –K-best scheme most successful