1 / 53

Course Introduction Introduction to Computer Systems Adapted from CMU course 15-213

Course Introduction Introduction to Computer Systems Adapted from CMU course 15-213. Instructor: Yuan Tang. Instructor. 唐 渊 yuantang@fudan.edu.cn Phone # : 13917047105 Make an appointment. Teaching Assistant. 王天豪 11302010005@fudan.edu.cn , 15026687118 邬志罡

nerita
Télécharger la présentation

Course Introduction Introduction to Computer Systems Adapted from CMU course 15-213

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. Course IntroductionIntroduction to Computer Systems Adapted from CMU course 15-213 Instructor: Yuan Tang

  2. Instructor • 唐渊 • yuantang@fudan.edu.cn • Phone # : 13917047105 • Make an appointment

  3. Teaching Assistant • 王天豪 • 11302010005@fudan.edu.cn,15026687118 • 邬志罡 • 12302010008@fudan.edu.cn, 13585862607 • 李孟桐 • 12302010057@fudan.edu.cn, GoldenKnight@126.com,18818263415 • 曾虹驰 • 12302010055@fudan.edu.cn, 18818263645 • 郭悦 • 12302010083@fudan.edu.cn, 18818265520

  4. Textbook and website • Randy Bryant and David O’Hallaron, • Computer Systems: A Programmer’s Perspective • 2nd Edition • Prentice Hall, 2011. • Brian Kernighan and Dennis Ritchie, • The C Programming Language, Second Edition • Prentice Hall, 1988 • http://ics.fudan.edu.cn

  5. Grading • Exams(60%) • Mid term (20%) • Final (40%) • All exams are open books/open notes. • Labs (20%) • 4 labs(20%), (3-8% each) • On line exam for lab 2&3 (10%) • Home work(5%) • Scribing (15%)

  6. Cheating • What is cheating? • Sharing code: by copying, retyping, looking at, or supplying a file • Coaching: helping your friend to write a lab, line by line • Copying code from previous course or from elsewhere on WWW • Only allowed to use code we supply, or from CS:APP website • What is NOT cheating? • Explaining how to use systems or tools • Helping others with high-level design issues • Penalty for cheating: • 0 credit for the lab • 0 chance to get A • Detection of cheating: • We do check • Our tools for doing this are much better than most cheaters think!

  7. Theory Systems Curricular Structures • Three roles of science: • Observation • Conjecture • Test • Theory • How to model real world • Abstract concepts • How to reduce asymptotic bounds • System • How to run the real world • Concrete implementations • How to reduce constants

  8. Carnegie Mellon Course Perspective • Most 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

  9. Carnegie Mellon Course Perspective (Cont.) • Our Course is Programmer-Centric • Purpose is to show how by knowing more about the underlying system, one can be more effective as a programmer • 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

  10. What’s covered by this course? • Assembly language • Programming in C • Compiler • Operating System • Computer Architecture • Performance Optimization • Networking • Concurrent programming

  11. Carnegie Mellon Assembly 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 procedure double t; start_counter(); P(); t = get_counter(); printf("P required %f clock cycles\n", t);

  12. Carnegie Mellon Code to Read Counter • Write small amount of assembly code using GCC’s asm facility • Inserts assembly code into machine code generated by compiler static 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"); } GCC extended assembly syntax asm( assembler syntax : output operands /*optional */ : input operands /* optional */ : list of clobbered registers /* optional */ );

  13. Operating Systems • 1960’s • IBM OS/360, Honeywell Multics, • Fernado Jose Corbató • IEEE Computer Pioneer Award, 1982 • ACM Turing Award, 1990

  14. Operating Systems • Unix • Bell Lab, DEC PDP-7, 1969 • Ken Thompson, Dennis Ritchie, Doug Mcllroy, Joe Ossana • 1970 Brian Kernighandubbed the system “Unix” • Rewritten in C in 1973, announced in 1974 • BSD (UC, Berkeley), System V(Bell lab) • Solaris (Sun Microsystem) • Posix standard • Ken Thompson, Dennis Ritchie • ACM Turing Award, 1983

  15. Linux • 1991, Linus Torvalds • Unix-like operating systems • 386(486)AT, bash(1.08), gcc(1.40) • Posix complaint version of Unix operating system • Available on a wide array of computers • From handheld devices to mainframe computers • wristwatch

  16. GNU • Free software • Richard Stallman, 1984 • A complete Unix-like system with source code • An environment • All major components of a Unix operating system • Except for kernel

  17. We have seen a bunch of Operating Systems

  18. We have seen a bunch of Operating Systems

  19. The C Programming Language • C was developed • in 1969 to 1973 • by Dennis Ritchie of Bell Laboratories. • The American National Standards Institute (ANSI) • ratified the ANSI C standard in 1989. • The standard defines • the C language • and a set of library functions known as the C standard library.

  20. The C Programming Language • Kernighan and Ritchie describe ANSI C in their classic book • which is known affectionately as “K&R” . • describes the complete language and standard library, with numerous examples and exercises, in only 261 pages. • In Ritchie’s words, C is • quirky, • flawed, • and an enormous success. • Why the success?

  21. The C Programming Language • C was closely tied with the Unix operating system • C was born for system programming • Small, simple, super-performance • Most of the Unix kernel, and all of its supporting tools and libraries, were written in C. • Widely taught and popular in in universities in the late 1970s and early 1980s • Portability • Lots of libraries

  22. The C Programming Language • However, it is not perfect for all programmers and all situations • C pointer is dangerous • C is Not type-safe. • C is imperative

  23. A tour of computer system • Information = bits + context • Text files • Binary files • The only thing that distinguish different data objects is the context in which we view them.

  24. hello.c • hello.c: • 1 #include <stdio.h> • 2 • 3 int main() • 4 { • 5 printf(“hello, world\n”); • 6 }

  25. The ASCII text representation of hello.c

  26. The compilation system

  27. Preprocessor Macro Substitution # 1 "a.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "a.c" # 1 "b.h" 1 int j; # 2 "a.c" 2 main() { return 100 +j ; } • Obtain with command • gcc -E a.c • Source file a.i

  28. Source Code and Assembly Code

  29. Machine Code

  30. Standardization of C • The original Bell Labs version of C • the 1st edition of the book K&R • The ANSI C standard in 1989 • The American National Standards Institute • Modify the way functions are declared • the 2nd edition of the book K&R • ISO C90 (The International Standards Organization)

  31. Standardization of C • ISO C99 • Introduced some new data types • Provided support for text strings requiring characters not found in the English language • Gcc supporting • Unix> gcc -std=c99 prog.c • -ansiand -std=c89 have the same effect

  32. Standardization of C

  33. Why shall we understand how compilation system works? • Optimizing program performance void copyij(int src[2048][2048], int dst[2048][2048]) { int i,j; for (i = 0; i < 2048; i++) for (j = 0; j < 2048; j++) dst[i][j] = src[i][j]; } void copyji(int src[2048][2048], int dst[2048][2048]) { int i,j; for (j = 0; j < 2048; j++) for (i = 0; i < 2048; i++) dst[i][j] = src[i][j]; } 21 times slower(Pentium 4) • Hierarchical memory organization • Performance depends on access patterns • Including how step through multi-dimensional array

  34. Why shall we understand how compilation system works? • Optimizing program performance • Understanding link-time errors • Linker cannot resolve a reference? • Static versus global variable? • Two global variables in different C files with the same name? • Order of listed library on the command line?

  35. Why shall we understand how compilation system works? • Optimizing program performance • Understanding link-time errors • Avoiding security holes double fun(int i) { volatile double d[1] = {3.14}; volatile long int a[2]; a[i] = 1073741824; /* Possibly out of bounds */ return d[0]; }

  36. Why shall we understand how compilation system works? • Avoiding security holes double 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.14 fun(1) => 3.14 fun(2) =>3.14 fun(3) =>3.14 fun(4) =>segmentation fault • Result is architecture specific

  37. Why shall we understand how compilation system works? • Avoiding security holes double fun(int i) { volatile double d[1] = {3.14}; volatile long int a[2]; a[i] = 1073741824; /* Possibly out of bounds */ return d[0]; } Explanation: Location accessed by fun(i)

  38. Hardware organization of a system

  39. Running the hello program

  40. Running the hello program

  41. Running the hello program

  42. Storage hierarchy

  43. The Operating System manages HW

  44. Abstraction provided by OS • Files: • A sequence of bytes. • Unified API: UNIX I/O • Virtual memory: • Illusion of exclusive use of memory • Virtual address space • Process: • The OS’s abstraction for a running program • Concurrency, context switching, uni-processor system, multi-processor system

  45. Process context switching • Process: • The OS’s abstraction for a running program • Concurrency, context switching, uni-processor system, multi-processor system

  46. Virtual memory

  47. Systems communicate with other systems using networks

  48. Networking • Computers are connected by networks

  49. Cloud • Computer Systems support the cloud computing Wireless Ethernet

More Related