View
19
Download
0
Category
Preview:
Citation preview
Introduction toComputer Architecture
Topics:Topics: Course policies and overview Theme Five great realities of computer systems
Powerpoint Lecture Notes for Computer Systems: A Programmer'sPerspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003
CISC 360-010
Michela TauferSeptember 4, 2008
– 2 – CISC 360-010, Fa08
Meet your Colleagues…Ask your classmate: His/Her name? What are his/her favorite topics in computer
science? List up to three topics. What is he/she planning to do after his/her
graduation?
– 3 – CISC 360-010, Fa08
Course Theme Abstraction is good, but donʼt forget reality!
Courses to date emphasize abstractionCourses to date emphasize abstraction Abstract data types Asymptotic analysis (big oh)
These abstractions have limitsThese abstractions have limits Especially in the presence of bugs Need to understand underlying implementations
Useful outcomesUseful outcomes Become more effective programmers
Able to find and eliminate bugs efficiently Able to tune program performance
Prepare for later “systems” classes in CS & ECE Compilers, Operating Systems, Networks, Embedded Systems
– 4 – CISC 360-010, Fa08
Teaching Staff Instructors
Prof. Michela Taufer (2:30PM to 3:30PM or by appointment)
TAʼs Yang Gang
– 5 – CISC 360-010, Fa08
Textbooks (Mandatory)Randal E. Bryant andRandal E. Bryant and
David R. David R. OO ʼ̓HallaronHallaron,, “Computer Systems: A
ProgrammerʼsPerspective”, PrenticeHall 2003.
csapp.cs.cmu.edu
– 6 – CISC 360-010, Fa08
Textbooks (Recommended)Brian Kernighan and DennisBrian Kernighan and Dennis
Ritchie,Ritchie, “The C Programming
Language, SecondEdition”, Prentice Hall,1988
– 7 – CISC 360-010, Fa08
Course ComponentsLecturesLectures
Higher level concepts
QuizzesQuizzes Applied concepts, important tools and skills for labs
ProjectsProjects Four lab assignments The heart of the course ~2 weeks Provide in-depth understanding of an aspect of systems Programming and measurement
– 8 – CISC 360-010, Fa08
Getting HelpCourse webpage at Course webpage at http:http://cis//cis..udeludel..edu/~taufer/coursesedu/~taufer/courses
Copies of lectures and project assignments Clarifications to assignments, deadlines Syllabus and class schedule
User:User: cisc360studentcisc360studentPassword: Password: Learn4Fun!Learn4Fun!
DiscussionsDiscussions through mailing listthrough mailing list Clarifications to assignments, general discussion Send e-mail to all with: cisc360010_fa08@gcl.cis.udel.edu
Personal helpPersonal help Professor: lecture, exams, quizzes, grades TA: lab assignments
– 9 – CISC 360-010, Fa08
Policies: Quizzes Quizzes test your understanding of the text
You are expected to do the reading assignmentYou are expected to do the reading assignmentBEFOREBEFORE the quizthe quiz
There are There are NONO make-up quizzes make-up quizzes
– 10 – CISC 360-010, Fa08
Policies: Lab AssignmentsSubmissionsSubmissions
Assignments due at 11:59PM on specified duedate
Electronic submissions ONLY - procedure isexplained in assignment
Makeup exams and assignmentsMakeup exams and assignments OK, but must make PRIOR arrangements with
Prof. Taufer.Appealing gradesAppealing grades
Within 7 days of due date or exam date
– 11 – CISC 360-010, Fa08
CheatingWhat is cheating?What is cheating?
Sharing code: either by copying, retyping, looking at, orsupplying a copy of a file.
What is NOT cheating?What is NOT cheating? Helping others use systems or tools. Helping others with high-level design issues. Helping others debug their code.
Penalty for cheating:Penalty for cheating: Removal from course with failing grade.
– 12 – CISC 360-010, Fa08
Policies: GradingExams (38%)Exams (38%)
Two in class exams (10% each) Final (28%) All exams are open book
Projects (40%)Projects (40%) 4 project (10% each)
Quizzes (12%)Quizzes (12%)
Grading CharacteristicsGrading Characteristics Lab scores tend to be high
Serious handicap if you donʼt hand a lab in Tests typically have a wider range of scores
– 13 – CISC 360-010, Fa08
FacilitiesAssignments will use Linux OS machinesAssignments will use Linux OS machines
McKinly Lab Lab 051 - 22 Linux systems for CIS labs Remote SSH Alias: hplab.acad.cis.udel.edu
– 14 – CISC 360-010, Fa08
Schedule of the Next Two WeeksClass 01 - Introduction (Sep 4)
o Course Overviewo Course Organizationo Reading chap 1 assigned
Class 02 - Bits and Bytes (Sep 9)o Reading chap 2 assignedo Quiz chap 1
Class 03 - Integers (Sep 11)
– 15 – CISC 360-010, Fa08
Course PerspectiveMost Systems Courses are Builder-CentricMost Systems Courses are Builder-Centric
Computer Architecture Design pipelined processor in Verilog
Operating Systems Implement large portions of operating system
Compilers Write compiler for simple language
Networking Implement and simulate network protocols
– 16 – CISC 360-010, Fa08
Course Perspective (Cont.)This Course is Programmer-CentricThis Course is Programmer-Centric
Purpose is to show how by knowing more about theunderlying system, one can be more effective as aprogrammer
Enable you to Write programs that are more reliable and efficient Incorporate features that require hooks into OS
» E.g., concurrency, signal handlers Not just a course for dedicated hackers
We bring out the hidden hacker in everyone Cover material in this course that you wonʼt see elsewhere
– 17 – CISC 360-010, Fa08
Programs and Data (9)
TopicsTopics Bits operations, arithmetic, assembly language programs,
representation of C control and data structures Includes aspects of architecture and compilers
Lab AssignmentsLab Assignments L1: Manipulating bits L2: Defusing a binary bomb
– 18 – CISC 360-010, Fa08
Computer Architecture (6)TopicsTopics
Computer architecture and logic design,pipelinedarchitecture
Develop understanding of processor design and the closerelationship between software and hardware
Lab AssignmentsLab Assignments L3: Design and implementation of a pipelined Y86 processor
– 19 – CISC 360-010, Fa08
Performance (2)
TopicsTopics High level processor models, code optimization (control and
data) Includes aspects of architecture, compilers, and OS
Lab AssignmentsLab Assignments L4: Optimizing Code Performance
– 20 – CISC 360-010, Fa08
The Memory Hierarchy (2)
TopicsTopics Memory technology, memory hierarchy, caches, disks,
locality Includes aspects of architecture and OS.
AssignmentsAssignments L4: Optimizing Code Performance
– 21 – CISC 360-010, Fa08
Virtual memory (4)
TopicsTopics Virtual memory, address translation, dynamic storage
allocation Includes aspects of architecture and OS
– 22 – CISC 360-010, Fa08
Project RationaleEachEach project should have a well-defined goal such as solving aproject should have a well-defined goal such as solving a
puzzle or winning a contest.puzzle or winning a contest. Defusing a binary bomb.
Doing aDoing a project should result in new skills and conceptsproject should result in new skills and concepts Data Lab: computer arithmetic, digital logic. Bomb Lab: assembly language, using a debugger,
understanding the stack Arch Lab: learn about the design and implementation of a
pipelined Y86 processor, optimizing its performance on abenchmark Y86 array copy program called ncopy.ys
Perf Lab: profiling, measurement, performance debugging.
– 23 – CISC 360-010, Fa08
Great Reality #1IntIntʼ̓s s are not Integers, Floatare not Integers, Floatʼ̓s are not s are not RealsReals
ExamplesExamples Is x2 ≥ 0?
Floatʼs: Yes! Intʼs:
» 40000 * 40000 --> 1600000000» 200 * 300 * 400 * 500 --> ??
Is (x + y) + z = x + (y + z)? Unsigned & Signed Intʼs: Yes! Floatʼs:
» (1e20 + -1e20) + 3.14 --> 3.14» 1e20 + (-1e20 + 3.14) --> ??
– 24 – CISC 360-010, Fa08
Computer ArithmeticDoes not generate random valuesDoes not generate random values
Arithmetic operations have important mathematicalproperties
Cannot assume Cannot assume ““usualusual”” properties properties Due to finiteness of representations Integer operations satisfy “ring” properties
Commutativity, associativity, distributivity Floating point operations satisfy “ordering” properties
Monotonicity, values of signs
ObservationObservation Need to understand which abstractions apply in which
contexts Important issues for compiler writers and serious application
programmers
– 25 – CISC 360-010, Fa08
Great Reality #2YouYouʼ̓ve got to know assemblyve got to know assembly
Chances are, youChances are, youʼ̓ll never write program in assemblyll never write program in assembly Compilers are much better & more patient than you are
Understanding assembly key to machine-levelUnderstanding assembly key to machine-levelexecution modelexecution model Tuning program performance
Understanding sources of program inefficiency Behavior of programs in presence of bugs
High-level language model breaks down Implementing system software
Compiler has machine code as target Operating systems must manage process state
– 26 – CISC 360-010, Fa08
Assembly Code ExampleTime Stamp CounterTime Stamp Counter
Special 64-bit register in Intel-compatible machines Incremented every clock cycle Read with rdtsc instruction
ApplicationApplication Measure time required by procedure
In units of clock cycles
double t;start_counter();P();t = get_counter();printf("P required %f clock cycles\n", t);
– 27 – CISC 360-010, Fa08
Code to Read Counter Write small amount of assembly code using GCCʼs asm
facility Inserts assembly code into machine code generated by
compilerstatic unsigned cyc_hi = 0;static unsigned cyc_lo = 0;
/* Set *hi and *lo to the high and low order bits of the cycle counter.*/void access_counter(unsigned *hi, unsigned *lo){ asm("rdtsc; movl %%edx,%0; movl %%eax,%1"
: "=r" (*hi), "=r" (*lo):: "%edx", "%eax");
}
– 28 – CISC 360-010, Fa08
Code to Read Counter/* Record the current value of the cycle counter. */void start_counter(){ access_counter(&cyc_hi, &cyc_lo);}
/* Number of cycles since the last call to start_counter. */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;}
– 29 – CISC 360-010, Fa08
Measuring TimeTrickier than it Might LookTrickier than it Might Look
Many sources of variation
ExampleExample Sum integers from 1 to n
n Cycles Cycles/n100 961 9.61
1,000 8,407 8.411,000 8,426 8.43
10,000 82,861 8.2910,000 82,876 8.29
1,000,000 8,419,907 8.421,000,000 8,425,181 8.43
1,000,000,000 8,371,2305,591 8.37
– 30 – CISC 360-010, Fa08
Great Reality #3Memory MattersMemory Matters
Memory is not unboundedMemory is not unbounded It must be allocated and managed Many applications are memory dominated
Memory referencing bugs especially perniciousMemory referencing bugs especially pernicious Effects are distant in both time and space
Memory performance is not uniformMemory performance is not uniform Cache and virtual memory effects can greatly affect program
performance Adapting program to characteristics of memory system can
lead to major speed improvements
– 31 – CISC 360-010, Fa08
Memory Referencing Bug Example
main (){ long int a[2]; double d = 3.14; a[2] = 1073741824; /* Out of bounds reference */ printf("d = %.15g\n", d); exit(0);}
Alpha MIPS Linux-g 5.30498947741318e-315 3.1399998664856 3.14
-O 3.14 3.14 3.14
(Linux version gives correct result, butimplementing as separate function givessegmentation fault.)
– 32 – CISC 360-010, Fa08
Memory Referencing ErrorsC and C++ do not provide any memory protectionC and C++ do not provide any memory protection
Out of bounds array references Invalid pointer values Abuses of malloc/free
Can lead to nasty bugsCan lead to nasty bugs Whether or not bug has any effect depends on system and
compiler Action at a distance
Corrupted object logically unrelated to one being accessed Effect of bug may be first observed long after it is generated
How can I deal with this?How can I deal with this? Program in Java, Lisp, or ML Understand what possible interactions may occur Use or develop tools to detect referencing errors
– 33 – CISC 360-010, Fa08
Memory Performance ExampleImplementations of Matrix MultiplicationImplementations of Matrix Multiplication
Multiple ways to nest loops
/* ijk */for (i=0; i<n; i++) { for (j=0; j<n; j++) { sum = 0.0; for (k=0; k<n; k++) sum += a[i][k] * b[k][j]; c[i][j] = sum; }}
/* jik */for (j=0; j<n; j++) { for (i=0; i<n; i++) { sum = 0.0; for (k=0; k<n; k++) sum += a[i][k] * b[k][j]; c[i][j] = sum }}
– 34 – CISC 360-010, Fa08
0
20
40
60
80
100
120
140
160
matrix size (n)
ijkikjjikjkikijkji
Matmult Performance (Alpha 21164)Too big for L1 Cache Too big for L2 Cache
– 35 – CISC 360-010, Fa08
Blocked matmult perf (Alpha 21164)
0
20
40
60
80
100
120
140
160
50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500matrix size (n)
bijkbikjijkikj
– 36 – CISC 360-010, Fa08
Great Reality #4ThereThereʼ̓s more to performance than asymptotics more to performance than asymptotic
complexitycomplexityConstant factors matter too!Constant factors matter too!
Easily see 10:1 performance range depending on how codewritten
Must optimize at multiple levels: algorithm, datarepresentations, procedures, and loops
Must understand system to optimize performanceMust understand system to optimize performance How programs compiled and executed How to measure program performance and identify
bottlenecks How to improve performance without destroying code
modularity and generality
– 37 – CISC 360-010, Fa08
Great Reality #5Computers do more than execute programsComputers do more than execute programs
They need to get data in and outThey need to get data in and out I/O system critical to program reliability and performance
They communicate with each other over networksThey communicate with each other over networks Many system-level issues arise in presence of network
Concurrent operations by autonomous processes Coping with unreliable media Cross platform compatibility Complex performance issues
– 38 – CISC 360-010, Fa08
Good Luck!
Recommended