CS-213 Introduction to Computer Systems Yan Chen Topics: Staff, text, and policies Lecture topics and assignments Lab rationale CS 213 F 06
Teaching staff Instructor TA Prof. Yan Chen (Thu 2-4pm, Tech L459) TBD Undergraduate assistant Responsible for grading the homework and projects Location and Time Lecture: 2-3:20pm, Tech M164 2 CS-213, F 06
Prerequests CS211 or equivalent Experience with C or C++ Required CS311 Useful Required CS213 is required CS course It is prerequisite for CS 343 (Operating Systems) It is also prerequisite for ALL systems courses»see http://nsrg.cs.northwestern.edu for a current list 3 CS-213, F 06
Textbooks Required: Randal E. Bryant and David R. O Hallaron, Computer Systems: A Programmer s Perspective, Prentice Hall 2003. csapp.cs.cmu.edu Recommended: Brian Kernighan and Dennis Ritchie, The C Programming Language, Second Edition, Prentice Hall, 1988 Richard Stevens, Advanced Programming in the Unix Environment, Addison-Wesley, 1992 4 CS-213, F 06
Homeworks, Labs, and Exams 3 labs, remove the malloc lab due to lack of TA 3 ~ 4 homeworks, 2 exams Grading 10% Homeworks 10% Class attendance and discussion 30% Programming labs (10% per lab) 25% Midterm (covers first half of the course) 25% Final (covers second half of the course) Late Policy After 1 day, maximum score is 90% After 2 days, meximum score is 80%, etc. 5 CS-213, F 06
Policies: Assignments Work groups You must work in groups of 2 for all labs Handins Assignments due at 11:59pm on specified due date. Electronic handins only. 6 CS-213, F 06
Course Components Lectures Higher level concepts Recitations Labs None due to lack of TA The heart of the course 2 ~ 3 weeks Provide in-depth understanding of an aspect of systems Programming and measurement 7 CS-213, F 06
Getting Help Web http://www.cs.northwestern.edu/~ychen/classes/cs213- f06/ Copies of lectures, assignments, exams, solutions Newsgroup cs.213 For more info on newsgroup access, https://www.cs.northwestern.edu/support/services/news.php Clarifications to assignments, general discussion Personal help Professors: office hours 2-4pm on Thu. 8 CS-213, F 06
Cheating What is cheating? Sharing code: either by copying, retyping, looking at, or supplying a copy of a file. 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: Removal from course with failing grade. 9 CS-213, F 06
Facilities TLAB (Tech F-252: F 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 root (root@eecs.northwestern.edu( root@eecs.northwestern.edu) For accessing the TLAB facilities - contact Carol Surma (carol@rhodes.ece.northwestern.edu) 10 CS-213, F 06
Programs and Data (8) Topics Bits operations, arithmetic, assembly language programs, representation of C control and data structures Includes aspects of architecture and compilers Assignments L1: Manipulating bits L2: Defusing a binary bomb L3: Hacking a buffer bomb 11 CS-213, F 06
The Memory Hierarchy (2) Topics Memory technology, memory hierarchy, caches, disks, locality Includes aspects of architecture and OS. 12 CS-213, F 06
Linking and Exceptional Control Flow (3) Topics Object files, static and dynamic linking, libraries, loading Hardware exceptions, processes, process control, Unix signals, nonlocal jumps Includes aspects of compilers, OS, and architecture 13 CS-213, F 06
Virtual Memory (2) Topics Virtual memory, address translation, dynamic storage allocation Includes aspects of architecture and OS 14 CS-213, F 06
I/O, Networking, and Concurrency (3) Topics 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. 15 CS-213, F 06
Lab Rationale Doing a lab should result in new skills and concepts Data Lab: computer arithmetic, digital logic. Bomb Lab: assembly language, using a debugger, understanding the stack. Exploit Lab: understanding the calling stack organization and buffer overflow vulnerabilities. 16 CS-213, F 06
Course Theme Abstraction is good, but don t forget reality! Courses to date emphasize abstraction Abstract data types Asymptotic analysis These abstractions have limits Especially in the presence of bugs Need to understand underlying implementations Useful 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, Computer Architecture, Embedded Systems 17 CS-213, F 06
Coarse Goal Must 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 Implementations change, but concepts don t 18 CS-213, F 06
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 19 CS-213, F 06
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 20 CS-213, F 06
Hello World What happens and why when you run hello on your system? /*hello /*hello world*/ world*/ # include include <stdio.h> <stdio.h> int int main() main() { printf( hello, printf( hello, world\n ); world\n ); } Goal: introduce key concepts, terminology, and components 21 CS-213, F 06
Information is Bits + Context Hello is a source code 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) E.g., # -> 35 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 The same sequence of bytes might represent a character string or machine instruction 22 CS-213, F 06
Programs Translated by Other Programs unix> unix> gcc gcc o o hello hello hello.c hello.c printf.o hello.c Source program (text) Preprocessor (cpp) hello.i Modified source program (text) Pre-processing Compiler (cc1) hello.s Assembly program (text) Assembler (as) hello.o Relocatable object programs (binary) E.g., #include <stdio.h> is inserted into hello.i Compilation Linker (ld) hello Executable object program (binary) hello.s: each statement is an assembly language program Assembly hello.o: a binary file whose bytes encode machine language instructions Linking E.g., hello.c uses printf(), it resides in a separate precompiled object file printf.o 23 CS-213, F 06
Why do We Care about This? Optimizing program performance To write efficient code Understanding link-time errors Why does it matter what order we list libraries? Why some link-errors do not appear before run time? Avoiding security holes Buffer overflow bugs 24 CS-213, F 06
Shell unix> unix>./hello./hello hello, hello, world world unix> 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, F 06
Buses Hardware organization Buses CPU PC Register file ALU System bus Memory bus Transfer fixedsized chunks of data (WORDS) Intel Pentium -> 4Bytes bus Bus interface I/O bridge Main memory USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display 26 CS-213, F 06 Disk hello executable stored on disk
Hardware organization CPU PC Register file ALU System bus Memory bus I/O Devices System connections to external world Mouse, keyboard (input) Display, disk device (output) Bus interface I/O bridge Main memory USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display 27 CS-213, F 06 Disk hello executable stored on disk
Hardware organization CPU PC Register file ALU System bus Memory bus Main Memory Temporary storage device Holds both a program and the data it manipulates with Bus interface I/O bridge Main memory USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display 28 CS-213, F 06 Disk hello executable stored on disk
Hardware organization CPU Register file PC ALU System bus Memory bus Bus interface I/O bridge Main memory Control Processor Unit (CPU) Executes instructions stored in main memory Program Counter (PC or Register) contains the address of some machine-language instruction from memory CPU Reads the instruction from memory Performs simple operation (load, store, update) Updates the PC to point to next instruction 29 CS-213, F 06
Running the Hello Program Reading the hello command from the keyboard Register file PC ALU System bus Memory bus Bus interface I/O bridge Main memory "hello" USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display 30 CS-213, F 06 User types "hello" Disk
Running the Hello Program Shell program loads hello.exe into main memory Register file PC ALU System bus Memory bus Bus interface I/O bridge Main memory "hello,world\n" hello code USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display Disk hello executable stored on disk 31 CS-213, F 06
Running the Hello Program The processor executes instructions and displays hello Register file PC ALU System bus Memory bus Bus interface I/O bridge Main memory "hello,world\n" hello code USB controller Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard Display "hello,world\n" 32 CS-213, F 06 Disk hello executable stored on disk
Caching A system spends a lot of time moving information from one place to another Larger storage devices are slower than smaller ones Register file ~ 100 Bytes Main memory ~ millions of Bytes It is easier and cheaper to make processors run faster than it is to make main memory run faster CPU chip L1 Register file cache (SRAM) ALU Cache bus System bus Memory bus L2 cache (SRAM) Bus interface Memory bridge Main memory (DRAM) 33 CS-213, F 06
Storage Devices Form a Hierarchy Storage at one level serves as cache at the next level Smaller, faster, and costlier (per byte) storage devices Larger, slower, and cheaper (per byte) storage devices L5: L4: L3: L2: L1: L0: Registers On-chip L1 cache (SRAM) Off-chip L2 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Remote secondary storage (distributed file systems, Web servers) CPU registers hold words retrieved from cache memory. L1 cache holds cache lines retrieved from the L2 cache. L2 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. 34 CS-213, F 06
Operating System (OS) OS a layer of software interposed between the application program and the hardware Application programs Operating system Processor Main memory I/O devices Software Hardware Two primary purposes To protect the hardware from misuse by applications To provide simple and uniform mechanisms for manipulating low-level hardware devices 35 CS-213, F 06
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 Main memory I/O devices 36 CS-213, F 06
Processes The OS provides the illusion that the program is the only one in the system Process OS s abstraction of a running program Context switching Saving the context of one process Restoring the process of the new process Time shell process hello process Application code OS code Application code OS code Context switch Context switch 37 CS-213, F 06 Application code
Virtual Memory Illusion that each process has exclusive use of main memory Example The virtual address space for Linux 0xffffffff 0xc0000000 0x40000000 0x08048000 Kernel virtual memory User stack (created at runtime) Memory mapped region for shared libraries Run-time heap (created at runtime by malloc) Read/write data Read-only code and data Unused Memory invisible to user code printf() function Loaded from the hello executable file 38 0 CS-213, F 06
Networking Computers do more than execute programs They need to get data in and out I/O system critical to program reliability and performance They communicate with each other over networks Many system-level issues arise in presence of network Coping with unreliable media Cross platform compatibility Complex performance issues 39 CS-213, F 06