CS213 Introduction to Computer Systems Aleksandar Kuzmanovic 3272006

  • Slides: 39
Download presentation
CS-213 Introduction to Computer Systems Aleksandar Kuzmanovic 3/27/2006 Topics: n Staff, text, and policies

CS-213 Introduction to Computer Systems Aleksandar Kuzmanovic 3/27/2006 Topics: n Staff, text, and policies n Lecture topics and assignments Class overview n CS 213 S ’ 06

Teaching staff n Instructor l Prof. Aleksandar Kuzmanovic (Wed 10: 00 -12: 00, Tech

Teaching staff n Instructor l Prof. Aleksandar Kuzmanovic (Wed 10: 00 -12: 00, Tech L 457) n TA l David Choffnes (Tu, Th 1 -2: 30, Ford 2 -217) l Recitation (Tu, 5 -6: 30, Tech MG 28) n Undergraduate assistant l TBA (TBA) n Location and Time l Lecture: MW 2 -3: 20, Tech LR 3 l Recitation: Tu, 5 -6: 30, Tech MG 28 – 2– CS-213, S’ 06

Prerequests n CS 211 (Fund. of comp. program. ) or eq. Experience with C

Prerequests n CS 211 (Fund. of comp. program. ) or eq. Experience with C or C++ Required n CS 311 (Data structures and mgmt) Useful n CS 213 is required CS course n l It is prerequisite for CS 343 (Operating Systems) l It is also prerequisite for ALL systems courses » See http: //nsrg. cs. northwestern. edu for a current list – 3– CS-213, S’ 06

Textbooks Required: Randal E. Bryant and David R. O’Hallaron, n n “Computer Systems: A

Textbooks Required: Randal E. Bryant and David R. O’Hallaron, n n “Computer Systems: A Programmer’s Perspective”, Prentice Hall 2003. csapp. cs. cmu. edu Recommended: Brian Kernighan and Dennis Ritchie, n “The C Programming Language, Second Edition”, Prentice Hall, 1988 Richard Stevens, n – 4– “Advanced Programming in the Unix Environment”, Addison -Wesley, 1992 CS-213, S’ 06

Homeworks, Labs, and Exams n 4 labs, 4 homeworks, 2 exams l Grading n

Homeworks, Labs, and Exams n 4 labs, 4 homeworks, 2 exams l Grading n n 10% Homeworks (2. 5% per homework) 50% Programming labs (12. 5% per lab) 20% Midterm (covers first half of the course) 20% Final (covers second half of the course) l Final grades: >90 (or 90 th percentile): A l l >80 (or 80 th percentile): B, >70 (or 70 th percentile): C, etc. l Late Policy n n – 5– After 1 day, maximum score is 90% After 2 days, maximum score is 80%, etc. CS-213, S’ 06

Policies: Assignments Work groups n You must work in groups of 2 for all

Policies: Assignments Work groups n You must work in groups of 2 for all labs l Let me and the TA know the groups by the end of the week Handins n n – 6– Assignments due at 11: 59 pm on specified due date. Electronic handins only. CS-213, S’ 06

Course Components Lectures n Higher level concepts Recitations n Applied concepts, important tools and

Course Components Lectures n Higher level concepts Recitations n Applied concepts, important tools and skills for labs, clarification of lectures, exam coverage Labs n n – 7– The heart of the course 1 or 2 weeks Provide in-depth understanding of an aspect of systems Programming and measurement CS-213, S’ 06

Getting Help Web n http: //cs. northwestern. edu/~akuzma/classes/CS 213 -s 06/ n Copies of

Getting Help Web n http: //cs. northwestern. edu/~akuzma/classes/CS 213 -s 06/ n Copies of lectures, assignments, handouts Clarifications to assignments n Newsgroups n n cs. 213. announce and cs. 213. discuss Clarifications to assignments, general discussion Can’t reply immediately! Personal help n n – 8– Professor, Wednesdays 10 -noon TA: Tu, Th 1 -2: 30 CS-213, S’ 06

Cheating What is cheating? n Sharing code: either by copying, retyping, looking at, or

Cheating What is cheating? n Sharing code: either by copying, retyping, looking at, or supplying a copy of a file. What is NOT cheating? n n n Helping others use systems or tools. Helping others with high-level design issues. Helping others debug their code. Penalty for cheating: n – 9– Removal from course with failing grade. CS-213, S’ 06

Facilities TLAB (Tech F-252: the Tech end of the bridge that connects Tech and

Facilities TLAB (Tech F-252: the Tech end of the bridge that connects Tech and Ford) - a cluster of Linux machines - (e. g. , TLAB-11. cs. northwestern. edu) You should all have TLAB accounts by now; -if not, contact Scott Hoover (scott@cs. northwestern. edu) For accessing the TLAB facilities - contact Carol Surma (carol@rhodes. ece. northwestern. edu) Should you have other problems - contact the TA directly – 10 – CS-213, S’ 06

Programs and Data (8) Topics n n Bits operations, arithmetic, assembly language programs, representation

Programs and Data (8) Topics n n Bits operations, arithmetic, assembly language programs, representation of C control and data structures Includes aspects of architecture and compilers Assignments n n n – 11 – L 1: Manipulating bits L 2: Defusing a binary bomb L 3: Hacking a buffer bomb CS-213, S’ 06

The Memory Hierarchy (2) Topics n n – 12 – Memory technology, memory hierarchy,

The Memory Hierarchy (2) Topics n n – 12 – Memory technology, memory hierarchy, caches, disks, locality Includes aspects of architecture and OS. CS-213, S’ 06

Linking and Exceptional Control Flow (3) Topics n n n – 13 – Object

Linking and Exceptional Control Flow (3) Topics n n n – 13 – Object files, static and dynamic linking, libraries, loading Hardware exceptions, processes, process control, Unix signals, nonlocal jumps Includes aspects of compilers, OS, and architecture CS-213, S’ 06

Virtual memory (2) Topics n n Virtual memory, address translation, dynamic storage allocation Includes

Virtual memory (2) Topics n n Virtual memory, address translation, dynamic storage allocation Includes aspects of architecture and OS Assignments n – 14 – L 4: Writing your own malloc package CS-213, S’ 06

I/O, Networking, and Concurrency (3) Topics n n n – 15 – High level

I/O, Networking, and Concurrency (3) Topics n n n – 15 – High level and low-level I/O, network programming, Internet services, Web servers concurrency, concurrent server design, threads, I/O multiplexing with select. Includes aspects of networking, OS, and architecture. CS-213, S’ 06

Lab Rationale Doing a lab should result in new skills and concepts n n

Lab Rationale Doing a lab should result in new skills and concepts n n n – 16 – Data Lab: computer arithmetic, digital logic. Bomb Labs: assembly language, using a debugger, understanding the stack Malloc Lab: understanding pointers and nasty memory bugs. CS-213, S’ 06

Course Theme n Abstraction is good, but don’t forget reality! Courses to date emphasize

Course Theme n Abstraction is good, but don’t forget reality! Courses to date emphasize abstraction n n Abstract data types Asymptotic analysis These abstractions have limits n n Especially in the presence of bugs Need to understand underlying implementations Useful outcomes n Become more effective programmers l Able to find and eliminate bugs efficiently l Able to tune program performance n Prepare for later “systems” classes in CS & ECE l Compilers, Operating Systems, Networks, Computer Architecture, Embedded Systems – 17 – CS-213, S’ 06

Coarse Goal Must understand system to optimize performance n n n How programs compiled

Coarse Goal Must understand system to optimize performance n n n How programs compiled and executed How to measure program performance and identify bottlenecks How to improve performance without destroying code modularity and generality Implementations change, but concepts don’t – 18 – CS-213, S’ 06

Course Perspective Most Systems Courses are Builder-Centric n Computer Architecture l Design a processor

Course Perspective Most Systems Courses are Builder-Centric n Computer Architecture l Design a processor n Operating Systems l Implement large portions of operating system n Compilers l Write compiler for simple language n Networking l Implement and simulate network protocols – 19 – CS-213, S’ 06

Course Perspective (Cont. ) This Course is Programmer-Centric n Purpose is to show by

Course Perspective (Cont. ) This Course is Programmer-Centric n Purpose is to show by knowing more about the underlying system, one can be more effective as a programmer n Enable you to l Write programs that are more reliable and efficient l Incorporate features that require hooks into OS » E. g. , concurrency, signal handlers n – 20 – Cover material in this course that you won’t see elsewhere CS-213, S’ 06

Hello World In a sense, the goal of the course is to help you

Hello World In a sense, the goal of the course is to help you understand what happens and why when you run “hello” on your system? /*hello world*/ # include <stdio. h> int main() { printf(“hello, worldn”); } Goal: introduce key concepts, terminology, and components – 21 – CS-213, S’ 06

Information is Bits + Context “Hello” is a source code n n n Sequence

Information is Bits + Context “Hello” is a source code n n n Sequence of bits (0 or 1) 8 -bit data chunks are called Bytes Each Byte has an integer value that corresponds to some character (ASCII standard) l E. g. , ‘#’ -> 35 n n Files that consist of ASCII characters -> text files All other files -> binary files (e. g. , 35 is a part of a machine command) Context is important n n n – 22 – The same sequence of bytes might represent a character string or machine instruction Machines put everything in bits! Chapter 2 -> machine representations of numbers CS-213, S’ 06

Programs Translated by Other Programs unix> gcc –o hello. c printf. o hello. c

Programs Translated by Other Programs unix> gcc –o hello. c printf. o hello. c Source program (text) Prehello. i processor (cpp) Phases: n Compiler hello. s (cc 1) Modified source program (text) Assembly program (text) Assembler hello. o (as) Relocatable object programs (binary) Linker (ld) hello Executable object program (binary) Pre-processing l E. g. , #include <stdio. h> is inserted into hello. i n Compilation l hello. s -> each statement is an assembly language program n Assembly l hello. o -> is a binary file whose bytes encode machine language instructions n – 23 – Linking l E. g. , hello. c uses printf(), it resides in a separate precompiled object file printf. o CS-213, S’ 06

Why do We Care about This? l Optimizing program performance n n To write

Why do We Care about This? l Optimizing program performance n n To write efficient code -> we do need a basic understanding of how a compiler translates different C statements into assembly language How to tune C programs to help compiler l Understanding link-time errors n n Why does it matter what order we list libraries? Why some link-errors do not appear before run time? l Avoiding security holes n – 24 – Buffer overflow bugs CS-213, S’ 06

Shell unix>. /hello, world unix> Shell a command-line interpreter that - prints a prompt

Shell unix>. /hello, world unix> Shell a command-line interpreter that - prints a prompt - waits for you to type command line - loads and runs hello program - prints a prompt – 25 – CS-213, S’ 06

Hardware organization Buses n CPU Register file n PC ALU System bus Memory bus

Hardware organization Buses n CPU Register file n PC ALU System bus Memory bus Main memory I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 26 – Graphics adapter Transfer fixed-sized chunks of data (WORDS) Intel Pentium -> 4 Bytes bus Disk controller Display Disk Expansion slots for other devices such as network adapters hello executable stored on disk CS-213, S’ 06

Hardware organization I/O Devices n CPU n Register file PC ALU n System bus

Hardware organization I/O Devices n CPU n Register file PC ALU n System bus Memory bus Main memory I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 27 – Graphics adapter System connections to external world Mouse, keyboard (input) Display, disk device (output) Disk controller Display Disk Expansion slots for other devices such as network adapters hello executable stored on disk CS-213, S’ 06

Hardware organization Main Memory n CPU n Register file PC ALU System bus Memory

Hardware organization Main Memory n CPU n Register file PC ALU System bus Memory bus Main memory I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 28 – Graphics adapter Temporary storage device Holds both a program and the data it manipulates with Disk controller Display Disk Expansion slots for other devices such as network adapters hello executable stored on disk CS-213, S’ 06

Hardware organization CPU Register file ALU PC System bus Bus interface Main memory I/O

Hardware organization CPU Register file ALU PC System bus Bus interface Main memory I/O bridge Control Processor Unit (CPU) – 29 – Memory bus n Executes instructions stored in main memory n Program Counter (PC or Register) contains the address of some machinelanguage instruction from memory CPU n n n Reads the instruction from memory Performs simple operation (load, store, update) Updates the PC to point to next instruction CS-213, S’ 06

Running the Hello Program Reading the hello command from the keyboard Register file PC

Running the Hello Program Reading the hello command from the keyboard Register file PC ALU System bus Memory bus Main "hello" memory I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 30 – Graphics adapter Disk controller Expansion slots for other devices such as network adapters Display User types "hello" Disk CS-213, S’ 06

Running the Hello Program Shell program loads hello. exe into main memory Register file

Running the Hello Program Shell program loads hello. exe into main memory Register file PC ALU System bus Memory bus "hello, worldn" Main memory hello code I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 31 – Graphics adapter Disk controller Display Disk Expansion slots for other devices such as network adapters hello executable CS-213, S’ 06 stored on disk

Running the Hello Program The processor executes instructions and displays “hello…” Register file PC

Running the Hello Program The processor executes instructions and displays “hello…” Register file PC ALU System bus Memory bus Main "hello, worldn" memory hello code I/O bridge Bus interface I/O bus USB controller Mouse Keyboard – 32 – Graphics adapter Disk controller Display "hello, worldn" Disk Expansion slots for other devices such as network adapters hello executable stored on disk CS-213, S’ 06

Caching n A system spends a lot of time moving information from one place

Caching n A system spends a lot of time moving information from one place to another n Larger storage devices are slower than smaller ones l Register file ~ 100 Bytes l Main memory ~ millions of Bytes n It is easier and cheaper to make processors run faster than it is to make main memory run faster (SRAM – Static RAM) CPU chip Register file L 1 cache ALU (SRAM) Cache bus L 2 cache (SRAM) – 33 – System bus Bus interface Memory bridge Memory bus Main memory (DRAM) CS-213, S’ 06

Storage Devices Form a Hierarchy Storage at one level serves as cache at the

Storage Devices Form a Hierarchy Storage at one level serves as cache at the next level L 0: Registers Smaller, faster, and costlier (per byte) storage devices L 1: L 2: L 3: Larger, slower, and cheaper (per byte) storage devices L 4: L 5: – 34 – CPU registers hold words retrieved from cache memory. On-chip L 1 cache (SRAM) Off-chip L 2 cache (SRAM) L 1 cache holds cache lines retrieved from the L 2 cache. Main memory (DRAM) Local secondary storage (local disks) L 2 cache holds cache lines retrieved from memory. Main memory holds disk blocks retrieved from local disks. Local disks hold files retrieved from disks on remote network servers. Remote secondary storage (distributed file systems, Web servers) CS-213, S’ 06

Operating System (OS) OS – a layer of software interposed between the application program

Operating System (OS) OS – a layer of software interposed between the application program and the hardware Application programs Software Operating system Processor Main memory I/O devices Hardware Two primary purposes n n – 35 – To protect the hardware from misuse by applications To provide simple and uniform mechanisms for manipulating low-level hardware devices CS-213, S’ 06

OS Abstractions Files are abstractions of I/O devices Virtual Memory is an abstraction for

OS Abstractions Files are abstractions of I/O devices Virtual Memory is an abstraction for the main memory and I/O devices Processes are abstractions for the processor, main memory, and I/O devices Processes Virtual memory Files Processor – 36 – Main memory I/O devices CS-213, S’ 06

Processes The OS provides the illusion that the program is the only one in

Processes The OS provides the illusion that the program is the only one in the system Process n OS’s abstraction of a running program Context switching n n Saving the context of one process Restoring the process of the new process Time shell process hello process Application code OS code Context switch Application code OS code – 37 – Application code Context switch CS-213, S’ 06

Virtual Memory l Illusion that each process has exclusive use of main memory l

Virtual Memory l Illusion that each process has exclusive use of main memory l Example n The virtual address space for Linux 0 xffff 0 xc 0000000 Kernel virtual memory Memory invisible to user code User stack (created at runtime) 0 x 40000000 Memory mapped region for shared libraries printf() function Run-time heap (created at runtime by malloc) Read/write data Read-only code and data Loaded from the hello executable file 0 x 08048000 – 38 – 0 Unused CS-213, S’ 06

Networking Computers do more than execute programs They need to get data in and

Networking Computers do more than execute programs They need to get data in and out n I/O system critical to program reliability and performance They communicate with each other over networks Because of the Internet, copying info from 1 machine to another has become important – 39 – CS-213, S’ 06