1 / 17

Timing

Timing. Tutorial #5 CPSC 261. Clocks. Most computer systems have a number of clocks Give time signals to the pipeline and memory Tick at 2.67 GHz (or whatever) Interrupt generating clocks Interrupt every X ms Real time clocks Keep track of time in the “real world”. Linux notion of time.

livana
Download Presentation

Timing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Timing Tutorial #5 CPSC 261

  2. Clocks • Most computer systems have a number of clocks • Give time signals to the pipeline and memory • Tick at 2.67 GHz (or whatever) • Interrupt generating clocks • Interrupt every X ms • Real time clocks • Keep track of time in the “real world”

  3. Linux notion of time • time() • return the number of seconds since Jan 1, 1970 UTC • gettimeofday() • More fine-grained notion of time • Seconds and milliseconds • Stored in a structure called a timeval

  4. How to measure elapsed time? int before = time(0) // do the work int after = time(0) int elapsed = after – before

  5. Problems with using time • Coarse granularity • Often get an answer of 0 • Sometimes get 1 second even for short operations

  6. Try #2 measuring elapsed time structtimeval before, after; gettimeofday(&before) // do the work gettimeofday(&after) elapsed= after - before

  7. Problems with using gettimeofday • Overhead of measurement may dwarf small elapsed times • structtimevals don’t support subtraction (so you have to write it)

  8. General problems with timing • Timing short-lived events • Repeat them a lot of times • External factors can affect measurement • Other processes • Hardware interrupts • Repeat measurements a few times

  9. Look at timenothing.c • Explain all the interesting bits

  10. Special files • Linux has a number of special files in /dev • null • Reads return EOF • Writes disappear into the bit-bucket • zero • Reads return 0 bytes • Writes disappear into the bit-bucket • random • Reads return random bytes • Writes affect later reads in a non-obvious way

  11. Throwing stuff away • From the command line: • chatty-program > /dev/null

  12. System calls and library calls • The lowest level of interaction with the Linux system is via system calls • read, write, open, close • Documented in section 2 of the manual • More “user-friendly” interfaces can often be found in the “standard library” • fread, fwrite, fopen, fclose • Documents in section 3 of the manual

  13. issawtooth • issawtooth is a function that detects sawtooth patterns • Each value is alternatively bigger or smaller than the one before it • Starting with bigger issawtooth(1) == 1 issawtooth(1, 4, 3, 10, 3, 5) == 1 issawtooth(1, 4, 4, 10,3, 5) == 0 issawtooth(1, 4, 5, 10, 3, 5) == 0

  14. Look at issawtooth.c long issawtooth(long *p, long n) { long i; long up = 1; for (i = 1; i < n; i++) { if (up && p[i] <= p[i-1]) return 0; if (!up && p[i] >= p[i-1]) return 0; up = !up; } return 1; }

  15. Look at issawtooth.s • Explain what it is doing

  16. Make it faster • Less memory accesses • Less branches • Less dependencies

  17. The online scoreboard • Each time you check in your lab, the scoreboard will be updated • Your checkin will be a bit slower • https://www.ugrad.cs.ubc.ca/~cs261/2013w2/scoreboard/index.php

More Related