Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to Computer Systems Today: Welcome to EECS 213 Lecture topics and assignments Lab rationale Next time: Bits & bytes and some Boolean algebra Fabián E. Bustamante, Spring 2007 Welcome to Intro. to Computer Systems Everything you need to know http://www.cs.northwestern.edu/~fabianb/classes/eecs-213.html Your instructor: Fabián E. Bustamante Your TA: we’ll see about that Your undergraduate assistant – Helping with grading homework and projects Communication channels: – Course webpage – News – eecs-213@cs EECS 213 Introduction to Computer Systems Northwestern University 2 Course theme Abstraction is good, but don’t forget reality! Courses to date emphasize abstraction – Abstract data types, asymptotic analysis, … Abstractions have limits – Especially in the presence of bugs – Need to understand underlying implementations Useful outcomes – Become more effective programmers • Better at debugging, performance tuning, … – Prepare for later “systems” classes in CS & ECE • Compilers, Operating Systems, Networks, ... – What do you need? • Required: EECS 211 or equivalent & Experience with C or C++ • Useful: EECS 311 EECS 213 Introduction to Computer Systems Northwestern University 3 Course perspective Most systems courses are builder-centric – Operating Systems: Implement portions of an OS – Compilers: Write compiler for simple language – Networking: Implement and simulate network protocols This 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 – 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 EECS 213 Introduction to Computer Systems Northwestern University 4 Textbooks Required: – Bryant & O’Hallaron, “Computer Systems: A Programmer’s Perspective”, PH 2003. (csapp.cs.cmu.edu) Recommended: – Kernighan & Ritchie (K&R), “The C Programming Language, Second Edition”, PH 1988 – R. Stevens, “Advanced Programming in the Unix Environment”, AW 1992; there’s a new edition by R. Stevens and S. Rago, AW 2005 EECS 213 Introduction to Computer Systems Northwestern University 5 Course components Lectures – Higher level concepts – 10% of grade from class participation Labs – The heart of the course – in-depth understanding – 3 labs, remove the malloc lab due to lack of TA • 2 ~ 3 weeks – 10% of grade each – Working on teams of 2 Homework assignments (3-4) – 10% of grade Exams – midterm & final – 25% of grade each EECS 213 Introduction to Computer Systems Northwestern University 6 Policies Late policy – 10% off per day 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. EECS 213 Introduction to Computer Systems Northwestern University 7 Facilities TLAB (Tech F-252, on the bridge to Ford) – A cluster of Linux machines (e.g., TLAB11.cs.northwestern.edu) You should all have TLAB accounts by now; problems? contact root ([email protected]) Need physical access to TLAB? Contact Carol Surma ([email protected]) EECS 213 Introduction to Computer Systems Northwestern University 8 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. EECS 213 Introduction to Computer Systems Northwestern University 9 Some topics covered Programs and data – Bits arithmetic, assembly, representation of C control … – Includes aspects of architecture and compilers Memory hierarch – Memory technology, memory hierarchy, caches, disks, locality – Includes aspects of architecture and OS. Linking & exceptional control flow – Object files, dynamic linking, libraries, process control, … – Includes aspects of compilers, OS, and architecture Virtual memory – Virtual memory, address translation, dynamic storage allocation – Includes aspects of architecture and OS I/O, networking & concurrency – High level & low-level I/O, net programming, threads, … – Includes aspects of networking, OS, and architecture EECS 213 Introduction to Computer Systems Northwestern University 10 Hello World What happens and why when you run “hello” on your system? /*hello world*/ # include <stdio.h> int main() { printf(“hello, world\n”); } Goal: introduce key concepts, terminology, and components EECS 213 Introduction to Computer Systems Northwestern University 11 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 EECS 213 Introduction to Computer Systems Northwestern University 12 Programs translated by other programs unix> gcc –o hello hello.c printf.o hello.c Source program (text) Prehello.i processor (cpp) Modified source program (text) Compiler hello.s (cc1) Assembly program (text) Assembler hello.o (as) Linker (ld) Relocatable object programs (binary) hello Executable object program (binary) Pre-processing – E.g., #include <stdio.h> is inserted into hello.i Compilation (.s) – Each statement is an assembly language program Assembly (.o) – A binary file whose bytes encode mach. language instructions Linking – Get printf() which resides in a separate precompiled object file EECS 213 Introduction to Computer Systems Northwestern University 13 Hardware organization CPU Buses: transfer fixed-sized chunks of data (WORDS) Pentium: 4B bus Register file PC ALU Bus interface I/O Devices: System connections to external world. Mouse, keyboard (input); Display, disk device (output) System bus Memory bus Control Processor Unit Executes instructions stored inI/O MM. PC - holds addressMain memory bridge of machine-language instruction from memory I/O bus USB controller Mouse Keyboard Graphics adapter Main Memory: Temporary storage Expansion device. Holds both slots for a programother and the data such it devices manipulates. as network adapters Disk controller Display Disk EECS 213 Introduction to Computer Systems Northwestern University hello executable stored on disk 14 Running Hello Running hello unix> ./hello hello, world unix> What’s the shell? What does it do? – prints a prompt – waits for you to type command line – loads and runs hello program … EECS 213 Introduction to Computer Systems Northwestern University 15 Running Hello 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 Graphics adapter Disk controller Expansion slots for other devices such as network adapters Display Disk User types "hello" EECS 213 Introduction to Computer Systems Northwestern University 16 Running Hello Shell program loads hello.exe into main memory Register file PC ALU "hello,world\n" System bus Memory bus Main memory I/O bridge Bus interface hello code I/O bus USB controller Mouse Keyboard Graphics adapter Disk controller Display Disk EECS 213 Introduction to Computer Systems Northwestern University Expansion slots for other devices such as network adapters hello executable stored on disk 17 Running Hello The processor executes instructions and displays “hello…” Register file PC ALU "hello,world\n" System bus Memory bus Main memory I/O bridge Bus interface hello code I/O bus USB controller Mouse Keyboard Graphics adapter Disk controller Display "hello,world\n" Disk EECS 213 Introduction to Computer Systems Northwestern University Expansion slots for other devices such as network adapters hello executable stored on disk 18 Caches matter System spends a lot of time moving info. around Larger storage devices are slower than smaller ones – Register file ~ 100 Bytes & Main memory ~ millions of Bytes Easier and cheaper to make processors run faster than to make main memory run faster – Standard answer – cache CPU chip Register file L1 cache ALU (SRAM) Cache bus L2 cache (SRAM) System bus Bus interface Memory bridge EECS 213 Introduction to Computer Systems Northwestern University Memory bus Main memory (DRAM) 19 Storage devices form a hierarchy L0: Registers Storage at one level serves as cache at the next level L1: L2: Smaller, faster, and costlier (per byte) storage devices L3: L4: L5: CPU registers hold words retrieved from cache memory. On-chip L1 cache (SRAM) L1 cache holds cache lines retrieved from the L2 cache. Off-chip L2 cache (SRAM) L2 cache holds cache lines retrieved from memory. Main memory (DRAM) Local secondary storage (local disks) 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) EECS 213 Introduction to Computer Systems Northwestern University 20 Operating System 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 goal – Protect resources from misuse by applications – Provide simple and uniform mechanisms for manipulating low-level hardware devices EECS 213 Introduction to Computer Systems Northwestern University 21 OS Abstractions Files – abstractions of I/O devices Virtual Memory – abstraction for main memory and I/O devices Processes – abstractions for processor, main memory, and I/O devices Processes Virtual memory Files Processor Main memory I/O devices EECS 213 Introduction to Computer Systems Northwestern University 22 Processes OS provides the illusion that a process is the only one there Process – OS’s abstraction of a running program Context switch – Saving context of one process, restoring that of another one – Distorted notion of time Time shell process hello process Application code OS code Context switch Application code OS code Context switch Application code EECS 213 Introduction to Computer Systems Northwestern University 23 Virtual Memory Illusion that each process has exclusive use of a large main memory Example – Virtual address space for Linux 0xffffffff 0xc0000000 Kernel virtual memory Memory invisible to user code User stack (created at runtime) 0x40000000 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 0x08048000 0 Unused EECS 213 Introduction to Computer Systems Northwestern University 24 Networking Talking to other systems Network – seen as another I/O device Many system-level issues arise in presence of network – Coping with unreliable media – Cross platform compatibility – Complex performance issues Expansion slots I/O bus USB controller Mouse Keyboard Graphics adapter Disk controller Display Disk EECS 213 Introduction to Computer Systems Northwestern University Network adapter Network 25 Conclusions Any computer system is more than just hardware – A collection of intertwined hardware & software that must cooperate to achieve the end goal – running applications The rest of our course will expand on this EECS 213 Introduction to Computer Systems Northwestern University 26