UT CS 429H - COMPUTER ARCHITECTURE AND ORGANIZATION

Unformatted text preview:

Slide 1OverviewCourse Theme: Abstraction Is Good But Don’t Forget RealityGreat Reality #1: Ints are not Integers, Floats are not RealsCode Security ExampleTypical UsageMalicious UsageComputer ArithmeticGreat Reality #2: You’ve Got to Know AssemblyAssembly Code ExampleCode to Read CounterSlide 12Memory Referencing Bug ExampleMemory Referencing Bug ExampleMemory Referencing ErrorsMemory System Performance ExampleThe Memory MountainSlide 18Example Matrix MultiplicationMMM Plot: AnalysisCourse PerspectiveCourse Perspective (Cont.)TextbooksCourse ComponentsCourse LearningGetting HelpPolicies: Assignments (Labs) And ExamsFacilitiesTimelinessCheatingOther Rules of the Lecture HallPolicies: Grading (approximate)Programs and DataArchitecture: Datapath & PipeliningThe Memory HierarchyPerformance AnalysisLab RationaleWelcome and Enjoy!COURSE OVERVIEWCOMPUTER ARCHITECTURE AND ORGANIZATIONInstructor: Professor Emmett Witchel2University of Texas at AustinOverview•Course theme•Five realities•Logistics3University of Texas at AustinCourse Theme:Abstraction Is Good But Don’t Forget Reality•Most CS and CE courses emphasize abstraction•Abstract data types•Asymptotic analysis•These abstractions have limits•Especially in the presence of bugs•Need to understand details of underlying implementations•Useful outcomes•Become more effective programmers•Able to find and eliminate bugs efficiently•Able to understand and tune for program performance•Prepare for later “systems” classes in CS & ECE•Compilers, Operating Systems, Networks, Computer Architecture, Embedded Systems4University of Texas at AustinGreat Reality #1: Ints are not Integers, Floats are not Reals•Example 1: Is x2 ≥ 0?•Floats: Yes!•Ints:• 40000 * 40000 →1600000000• 50000 * 50000 → ??•Example 2: Is (x + y) + z = x + (y + z)?•Unsigned & Signed Ints: Yes!•Floats:• (1e20 + -1e20) + 3.14 --> 3.14• 1e20 + (-1e20 + 3.14) --> ??Source: xkcd.com/5715University of Texas at AustinCode Security Example•Similar to code found in FreeBSD’s implementation of getpeername•There are legions of smart people trying to find vulnerabilities in programs/* Kernel memory region holding user-accessible data */#define KSIZE 1024char kbuf[KSIZE];/* Copy at most maxlen bytes from kernel region to user buffer */int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen ? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len;}6University of Texas at AustinTypical Usage/* Kernel memory region holding user-accessible data */#define KSIZE 1024char kbuf[KSIZE];/* Copy at most maxlen bytes from kernel region to user buffer */int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen ? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len;}#define MSIZE 528void getstuff() { char mybuf[MSIZE]; copy_from_kernel(mybuf, MSIZE); printf(“%s\n”, mybuf);}7University of Texas at AustinMalicious Usage#define MSIZE 528void getstuff() { char mybuf[MSIZE]; copy_from_kernel(mybuf, -MSIZE); . . .}/* Kernel memory region holding user-accessible data */#define KSIZE 1024char kbuf[KSIZE];/* Copy at most maxlen bytes from kernel region to user buffer */int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen ? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len;}8University of Texas at AustinComputer Arithmetic•Does not generate random values•Arithmetic operations have important mathematical properties•Cannot assume all “usual” mathematical properties•Due to finiteness of representations•Integer operations satisfy “ring” properties•Commutativity, associativity, distributivity•Floating point operations satisfy “ordering” properties•Monotonicity, values of signs•Observation•Need to understand which abstractions apply in which contexts•Important issues for compiler writers and serious application programmers9University of Texas at AustinGreat Reality #2: You’ve Got to Know Assembly•Chances are, you’ll never write programs in assembly•Compilers are much better & more patient than you are•But: Understanding assembly is key to machine-level execution model•Behavior of programs in presence of bugs•High-level language models break down•Tuning program performance•Understand optimizations done / not done by the compiler•Understanding sources of program inefficiency•Implementing system software•Compiler has machine code as target•Operating systems must manage process state•Creating / fighting malware•x86 assembly is the language of choice!10University of Texas at AustinAssembly Code Example•Time Stamp Counter•Special 64-bit register in Intel-compatible machines•Incremented every clock cycle•Read with rdtsc instruction•Application•Measure time (in clock cycles) required by proceduredouble t;start_counter();P();t = get_counter();printf("P required %f clock cycles\n", t);11University of Texas at AustinCode 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");}12University of Texas at AustinGreat Reality #3: Memory MattersRandom Access Memory Is an Unphysical Abstraction•Memory is not unbounded•It must be allocated and managed•Many applications are memory dominated•Memory referencing bugs especially pernicious•Effects are distant in both time and space•Memory 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 improvements13University of Texas at AustinMemory Referencing Bug Example• Result is architecture specificdouble fun(int i){ volatile double d[1] = {3.14}; volatile long int a[2]; a[i] = 1073741824; /* Possibly out of bounds */ return d[0];}fun(0) → 3.14fun(1) → 3.14fun(2) → 3.1399998664856fun(3) → 2.00000061035156fun(4) → 3.14, then segmentation


View Full Document

UT CS 429H - COMPUTER ARCHITECTURE AND ORGANIZATION

Download COMPUTER ARCHITECTURE AND ORGANIZATION
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view COMPUTER ARCHITECTURE AND ORGANIZATION and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view COMPUTER ARCHITECTURE AND ORGANIZATION 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?