Time Measurement October 25, 2001Computer Time ScalesMeasurement Challenge“Time” on a Computer SystemActivity Periods: Light LoadActivity Periods: Heavy LoadInterval CountingUnix time CommandAccuracy of Interval CountingCycle CountersMeasuring with Cycle CounterAccessing the Cycle Counter (cont.)Completing MeasurementTiming With Cycle CounterTiming with Cycle CounterMeasurement PitfallsDealing with Overhead & Cache EffectsMultitasking EffectsK-Best ValidationCompensate For Timer OverheadK-Best on NTTime of Day ClockK-Best Using gettimeofdayMeasurement SummaryTime MeasurementOctober 25, 2001Topics•Time scales•Interval counting•Cycle counters•K-best measurement scheme15-213class18.pptCS 213 F’01– 2 –class18.pptComputer Time ScalesTwo Fundamental Time Scales•Processor: ~10–9 seconds•External events: ~10–2 seconds–Keyboard input–Disk seek–Screen refreshImplication•Can execute many instructions while waiting for external event to occur•Can alternate among processes without anyone noticingTime Scale (1 Ghz Machine)1.E-09 1.E-06 1.E-03 1.E+00Time (seconds)1 ns1 s1 ms 1 sInteger AddFP MultiplyFP DivideKeystrokeInterruptHandlerDisk AccessScreen RefreshKeystrokeMicroscopicMacroscopicCS 213 F’01– 3 –class18.pptMeasurement ChallengeHow 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 noticeableCS 213 F’01– 4 –class18.ppt“Time” on a Computer Systemreal (wall clock) time= user time (time executing instructing instructions in the user process)+ = real (wall clock) timeWe 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 timeCS 213 F’01– 5 –class18.pptActivity 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 Activity Periods, Load = 10 10 20 30 40 50 60 70 801Time (ms)ActiveInactiveCS 213 F’01– 6 –class18.pptActivity 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 executesActivity Periods, Load = 20 10 20 30 40 50 60 70 801Time (ms)ActiveInactiveCS 213 F’01– 7 –class18.pptInterval CountingOS 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 modeAu Au Au As Bu Bs Bu Bu Bu Bu As Au Au Au Au Au Bs Bu Bu Bs Au Au Au As AsA 110u + 40sB 70u + 30s(a) Interval TimingsB BAA A(b) Actual TimesBAABA 120.0u + 33.3sB 73.3u + 23.3s0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160AAu Au Au As Bu Bs Bu Bu Bu Bu As Au Au Au Au Au Bs Bu Bu Bs Au Au Au As AsA 110u + 40sB 70u + 30s(a) Interval TimingsB BAA AAu Au Au As Bu Bs Bu Bu Bu Bu As Au Au Au Au Au Bs Bu Bu Bs Au Au Au As AsA 110u + 40sB 70u + 30s(a) Interval TimingsB BAA A(b) Actual TimesBAABA 120.0u + 33.3sB 73.3u + 23.3s0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160A(b) Actual TimesBAABA 120.0u + 33.3sB 73.3u + 23.3s0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160ACS 213 F’01– 8 –class18.pptUnix 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 –(.82+0.3)/1.32 = .848time make oseventgcc -O2 -Wall -g -march=i486 -c clock.cgcc -O2 -Wall -g -march=i486 -c options.cgcc -O2 -Wall -g -march=i486 -c load.cgcc -O2 -Wall -g -march=i486 -o osevent osevent.c . . .0.820u 0.300s 0:01.32 84.8% 0+0k 0+0io 4049pf+0wCS 213 F’01– 9 –class18.pptAccuracy of Interval CountingWorst Case Analysis•Timer Interval = •Single process segment measurement can be off by •No bound on error for multiple segments–Could consistently underestimate, or consistently overestimateAverage 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 interrupts0 10 20 30 40 50 60 70 80AAMinimumMaximum0 10 20 30 40 50 60 70 80AAMinimumMaximum•Computed time = 70ms•Min Actual = 60 + •Max Actual = 80 – CS 213 F’01– 10 –class18.pptCycle 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-bitsWrap Around Times for 550 MHz machine•Low order 32-bits wrap around every 232 / (550 * 106) = 7.8 seconds•High order 64-bits wrap around every 264 / (550 * 106) = 33539534679 seconds–1065.3 yearsCS 213 F’01– 11 –class18.pptMeasuring with Cycle CounterIdea•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.pptAccessing 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
View Full Document