tuesday 1 september
play

Tuesday, 1 September If you are still using the default password - PowerPoint PPT Presentation

Tuesday, 1 September If you are still using the default password that was assigned when your account was created, CHANGE IT NOW! (It can be the same as your email password.) Tuesday, 1 September REMINDER: Department coffee/tea this


  1. Tuesday, 1 September If you are still using the “default” password that was assigned when your account was created, CHANGE IT NOW! (It can be the same as your email password.)

  2. Tuesday, 1 September ● REMINDER: Department coffee/tea this afternoon at 2 p.m. (Alden 102). BE THERE! ● TODAY: Internship lunch ● THUR: Pizza lunch with Acutec recruiters (sign-up sheet will be passed around) ● Questions about Monday’s lab? ● Thursday: “Mock quiz” on K&R 1.6 (“arrays”) ● For Thursday, read K&R 1.6, 1.7 ● Today: A bit more C; performance

  3. A Bit More C Why are we spending time on things like “getchar()” and “putchar()” when there are much more powerful functions for doing input and output? Because when we start looking at how the computer does things at the machine level, we are going to need to think about this kind of primitive “character-at-a-time” processing. For instance, How does the computer convert the characters “3821” (in, say, an assignment statement such as “ i=3821; ”) into the actual numeric value 3821?

  4. A Bit More C It has to convert from character codes (ASCII) to integers. ASCII value Character ASCII value Character 48 67 ‘0’ ‘C’ 49 ... ‘1’ ... 50 90 ‘2’ ‘Z’ ... ... ... ... 57 97 ‘9’ ‘a’ ... 98 ... ‘b’ 65 ... ‘A’ ... 66 122 ‘B’ ‘z’

  5. A Bit More C #include <stdio.h> main() { int c; /* input character--assumed to be a digit */ int digit; /* the decimal digit corresponding to c */ int value = 0; /* value of the input string as an int */ while ((c = getchar()) != '\n') { if (c < '0' || c > '9') { /* Check for error in input */ printf("Error--non-digit in input\n"); break; } digit = c - '0'; /* Convert ASCII to digit */ value = 10 * value + digit; /* Combine with previous digits */ } printf("Value of string: %d\n",value); }

  6. A Bit More C c = '5' (ASCII value 53) digit = 5 value = 5 c = '0' (ASCII value 48) digit = 0 value = 50 c = '8' (ASCII value 56) rroos$./asciitoint digit = 8 value = 508 5082 Value of string: 5082 c = '2' (ASCII value 50) digit = 2 value = 5082

  7. A Bit More C In C, characters are treating like integers. All of the following are perfectly legal (and even make sense): int c, position; c = getchar(); /* read in a character, e.g, ‘A’ */ printf(“char = ‘%c’, ASCII value = %d\n”,c,c); position = c - ‘A’; printf(“position in alphabet: %d\n”,position); OUTPUT (assuming input of ‘A’): char = ‘A’, ASCII value = 65 position in alphabet: 0

  8. Performance (P&H, 1.6--1.7) For the next few slides we borrow from the publisher’s resources! (I have edited these slightly from the originals.)

  9. Defining Performance Performance §1.6 ■ Which airplane has the best performance?

  10. Response Time and Throughput ■ Response time ■ How long it takes to do a task ■ Throughput ■ Total work done per unit time ■ e.g., tasks/transactions/… per hour ■ How are response time and throughput affected by ■ Replacing the processor with a faster version? ■ Adding more processors? ■ We’ll focus on response time for now…

  11. Relative Performance ■ Define Performance = 1/Execution Time ■ “X is n time faster than Y” ■ Example: time taken to run a program ■ 10s on A, 15s on B ■ Execution Time B / Execution Time A = 15s / 10s = 1.5 ■ So A is 1.5 times faster than B

  12. Measuring Execution Time ■ Elapsed time ■ Total response time, including all aspects ■ Processing, I/O, OS overhead, idle time ■ Determines system performance ■ CPU time ■ Time spent processing a given job ■ Discounts I/O time, other jobs’ shares ■ Comprises user CPU time and system CPU time ■ Different programs are affected differently by CPU and system performance

  13. CPU Clocking ■ Operation of digital hardware governed by a constant-rate clock Clock period Clock (cycles) Data transfer and computation Update state Hz = ■ Clock period: duration of a clock cycle “Hertz” = “cycles per ■ e.g., 250ps = 0.25ns = 250×10 –12 s second” ■ Clock frequency (rate): cycles per second ■ e.g., 4.0GHz = 4000MHz = 4.0×10 9 Hz

  14. CPU Time ■ Performance improved by ■ Reducing number of clock cycles ■ Increasing clock rate ■ Hardware designer must often trade off clock rate against cycle count

  15. CPU Time Example Computer A: 2GHz clock, 10s CPU time ■ Designing Computer B ■ Aim for 6s CPU time ■ Can do faster clock, but causes 1.2 × clock cycles ■ How fast must Computer B clock be? ■

  16. Instruction Count and CPI ISA = “Instruction Set Architecture” ■ Instruction Count for a program ■ Determined by program, ISA and compiler ■ Average cycles per instruction CPI = “Cycles Per ■ Determined by CPU hardware Instruction” ■ If different instructions have different CPI ■ Average CPI affected by instruction mix

  17. CPI Example ■ Computer A: Cycle Time = 250ps, CPI = 2.0 ■ Computer B: Cycle Time = 500ps, CPI = 1.2 ■ Same ISA ■ Which is faster, and by how much? A is faster… …by this much

  18. CPI in More Detail ■ If different instruction classes take different numbers of cycles ■ Weighted average CPI Relative frequency

  19. CPI Example ■ Alternative compiled code sequences using instructions in classes A, B, C Class A B C CPI for class 1 2 3 IC in sequence 1 2 1 2 IC in sequence 2 4 1 1 ■ Sequence 1: IC = 5 ■ Sequence 2: IC = 6 ■ Clock Cycles ■ Clock Cycles = 2×1 + 1×2 + 2×3 = 4×1 + 1×2 + 1×3 = 10 = 9 ■ Avg. CPI = 10/5 = 2.0 ■ Avg. CPI = 9/6 = 1.5

  20. Performance Summary The BIG Picture ■ Performance depends on ■ Algorithm: affects IC, possibly CPI ■ Programming language: affects IC, CPI Cycle time? ■ Compiler: affects IC, CPI ■ Instruction set architecture: affects IC, CPI, T c

  21. In-Class Exercise Exercise 1.5, page 55:

  22. Supplement to 1 September slides Solution to in-class exercise: PI: P2: P3:

  23. Supplement to 1 September slides Solution to in-class exercise: PI: P2: P3:

  24. Supplement to 1 September slides Solution to in-class exercise: We want: (new execution time) = .7(old execution time) Let’s consider time to execute a single instruction. If C = cycles per instruction in old machine, then 1.2xC = cycles per instruction in new machine. Let R = clock rate in old machine, let x = clock rate in new machine. Then:

  25. Supplement to 1 September slides Solution to in-class exercise: P1: P2: P3:

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend