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

tuesday 1 september
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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.)

slide-2
SLIDE 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
slide-3
SLIDE 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?

slide-4
SLIDE 4

A Bit More C

It has to convert from character codes (ASCII) to integers.

ASCII value Character ASCII value Character 48 ‘0’ 67 ‘C’ 49 ‘1’ ... ... 50 ‘2’ 90 ‘Z’ ... ... ... ... 57 ‘9’ 97 ‘a’ ... ... 98 ‘b’ 65 ‘A’ ... ... 66 ‘B’ 122 ‘z’

slide-5
SLIDE 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); }

slide-6
SLIDE 6

A Bit More C

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

slide-7
SLIDE 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

slide-8
SLIDE 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.)

slide-9
SLIDE 9

Defining Performance

■ Which airplane has the best performance?

§1.6 Performance

slide-10
SLIDE 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…

slide-11
SLIDE 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 TimeB / Execution TimeA

= 15s / 10s = 1.5

■ So A is 1.5 times faster than B

slide-12
SLIDE 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

slide-13
SLIDE 13

CPU Clocking

■ Operation of digital hardware governed by a

constant-rate clock

Clock (cycles) Data transfer and computation Update state Clock period

■ Clock period: duration of a clock cycle

■ e.g., 250ps = 0.25ns = 250×10–12s

■ Clock frequency (rate): cycles per second

■ e.g., 4.0GHz = 4000MHz = 4.0×109Hz

Hz = “Hertz” = “cycles per second”

slide-14
SLIDE 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

slide-15
SLIDE 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?

slide-16
SLIDE 16

Instruction Count and CPI

■ Instruction Count for a program

■ Determined by program, ISA and compiler

■ Average cycles per instruction

■ Determined by CPU hardware ■ If different instructions have different CPI

■ Average CPI affected by instruction mix

ISA = “Instruction Set Architecture” CPI = “Cycles Per Instruction”

slide-17
SLIDE 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

slide-18
SLIDE 18

CPI in More Detail

■ If different instruction classes take different

numbers of cycles

■ Weighted average CPI

Relative frequency

slide-19
SLIDE 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

■ Clock Cycles

= 2×1 + 1×2 + 2×3 = 10

■ Avg. CPI = 10/5 = 2.0

■ Sequence 2: IC = 6

■ Clock Cycles

= 4×1 + 1×2 + 1×3 = 9

■ Avg. CPI = 9/6 = 1.5

slide-20
SLIDE 20

Performance Summary

■ Performance depends on

■ Algorithm: affects IC, possibly CPI ■ Programming language: affects IC, CPI ■ Compiler: affects IC, CPI ■ Instruction set architecture: affects IC, CPI, Tc

The BIG Picture

Cycle time?

slide-21
SLIDE 21

In-Class Exercise

Exercise 1.5, page 55:

slide-22
SLIDE 22

Supplement to 1 September slides

Solution to in-class exercise:

PI: P2: P3:

slide-23
SLIDE 23

Supplement to 1 September slides

Solution to in-class exercise:

PI: P2: P3:

slide-24
SLIDE 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:

slide-25
SLIDE 25

Supplement to 1 September slides

Solution to in-class exercise:

P1: P2: P3: