Upload
hoangtram
View
215
Download
0
Embed Size (px)
Citation preview
Introduction to Computer Systems
Introduction to Computer Systems
Topics:Topics:Staff, text, and policiesLecture topics and assignmentsLab rationale
CS 213 F ’06
CS-213
Yan Chen
– 2 – CS-213, F’06
Teaching staffTeaching staffInstructor
Prof. Yan Chen (Thu 2-4pm, Tech L459)
TATBD
Undergraduate assistantResponsible for grading the homework and projects
Location and TimeLecture: 2-3:20pm, Tech M164
– 3 – CS-213, F’06
PrerequestsPrerequestsCS211 or equivalent RequiredExperience with C or C++ RequiredCS311 Useful
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
– 4 – CS-213, F’06
TextbooksTextbooksRequired:Required:
Randal E. Bryant and David R. Randal E. Bryant and David R. OO’’HallaronHallaron, , “Computer Systems: A Programmer’s Perspective”, Prentice Hall 2003.csapp.cs.cmu.edu
Recommended:Recommended:
Brian Kernighan and Dennis Ritchie, Brian Kernighan and Dennis Ritchie, “The C Programming Language, Second Edition”, Prentice Hall, 1988
Richard Stevens, Richard Stevens, “Advanced Programming in the Unix Environment”, Addison-Wesley, 1992
– 5 – CS-213, F’06
Homeworks, Labs, and ExamsHomeworks, Labs, and Exams3 labs, remove the malloc lab due to lack of TA3 ~ 4 homeworks, 2 exams
GradingGrading10% Homeworks10% 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 PolicyLate PolicyAfter 1 day, maximum score is 90%After 2 days, meximum score is 80%, etc.
– 6 – CS-213, F’06
Policies: AssignmentsPolicies: Assignments
Work groupsWork groupsYou must work in groups of 2 for all labs
HandinsHandinsAssignments due at 11:59pm on specified due date.Electronic handins only.
– 7 – CS-213, F’06
Course ComponentsCourse ComponentsLecturesLectures
Higher level concepts
RecitationsRecitationsNone due to lack of TA
LabsLabsThe heart of the course2 ~ 3 weeksProvide in-depth understanding of an aspect of systemsProgramming and measurement
– 8 – CS-213, F’06
Getting HelpGetting HelpWebWeb
http://www.cs.northwestern.edu/~ychen/classes/cs213-f06/Copies of lectures, assignments, exams, solutions
NewsgroupNewsgroupcs.213For more info on newsgroup access, https://www.cs.northwestern.edu/support/services/news.php
Clarifications to assignments, general discussion
Personal helpPersonal helpProfessors: office hours 2-4pm on Thu.
– 9 – CS-213, F’06
CheatingCheatingWhat is cheating?What is cheating?
Sharing code: either by copying, retyping, looking at, or supplying a copy of a file.
What is NOT cheating?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:Penalty for cheating:Removal from course with failing grade.
– 10 – CS-213, F’06
Facilities Facilities TLAB (Tech FTLAB (Tech F--252: the Tech end of the bridge that 252: the Tech end of the bridge that
connects Tech and Ford) connects Tech and Ford) -- a cluster of Linux machines a cluster of Linux machines -- (e.g., TLAB(e.g., TLAB--11.cs.northwestern.edu) 11.cs.northwestern.edu)
You should all have TLAB accounts by now; You should all have TLAB accounts by now; --if not, contact root (if not, contact root ([email protected]@eecs.northwestern.edu))
For accessing the TLAB facilities For accessing the TLAB facilities -- contact Carol contact Carol SurmaSurma(([email protected]@rhodes.ece.northwestern.edu))
– 11 – CS-213, F’06
Programs and Data (8) Programs and Data (8)
TopicsTopicsBits operations, arithmetic, assembly language programs, representation of C control and data structuresIncludes aspects of architecture and compilers
AssignmentsAssignmentsL1: Manipulating bitsL2: Defusing a binary bombL3: Hacking a buffer bomb
– 12 – CS-213, F’06
The Memory Hierarchy (2)The Memory Hierarchy (2)
TopicsTopicsMemory technology, memory hierarchy, caches, disks, localityIncludes aspects of architecture and OS.
– 13 – CS-213, F’06
Linking and Exceptional Control Flow (3)Linking and Exceptional Control Flow (3)
TopicsTopicsObject files, static and dynamic linking, libraries, loadingHardware exceptions, processes, process control, Unix signals, nonlocal jumpsIncludes aspects of compilers, OS, and architecture
– 14 – CS-213, F’06
Virtual Memory (2)Virtual Memory (2)
TopicsTopicsVirtual memory, address translation, dynamic storage allocationIncludes aspects of architecture and OS
– 15 – CS-213, F’06
I/O, Networking, and Concurrency (3)I/O, Networking, and Concurrency (3)
TopicsTopicsHigh level and low-level I/O, network programming, Internet services, Web serversconcurrency, concurrent server design, threads, I/O multiplexing with select.Includes aspects of networking, OS, and architecture.
– 16 – CS-213, F’06
Lab Rationale Lab Rationale
Doing a lab should result in new skills and Doing a lab should result in new skills and conceptsconcepts
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.
– 17 – CS-213, F’06
Course ThemeCourse ThemeAbstraction is good, but don’t forget reality!
Courses to date emphasize abstractionCourses to date emphasize abstractionAbstract data typesAsymptotic analysis
These abstractions have limitsThese abstractions have limitsEspecially in the presence of bugsNeed to understand underlying implementations
Useful outcomesUseful outcomesBecome more effective programmers
Able to find and eliminate bugs efficientlyAble to tune program performance
Prepare for later “systems” classes in CS & ECECompilers, Operating Systems, Networks, Computer Architecture, Embedded Systems
– 18 – CS-213, F’06
Coarse GoalCoarse Goal
Must understand system to optimize Must understand system to optimize performanceperformance
How programs compiled and executedHow to measure program performance and identify bottlenecksHow to improve performance without destroying code modularity and generality
Implementations change, but concepts donImplementations change, but concepts don’’tt
– 19 – CS-213, F’06
Course PerspectiveCourse PerspectiveMost Systems Courses are BuilderMost Systems Courses are Builder--CentricCentric
Computer ArchitectureDesign pipelined processor in Verilog
Operating SystemsImplement large portions of operating system
CompilersWrite compiler for simple language
NetworkingImplement and simulate network protocols
– 20 – CS-213, F’06
Course Perspective (Cont.)Course Perspective (Cont.)Our Course is ProgrammerOur Course is Programmer--CentricCentric
Purpose is to show how by knowing more about the underlying system, one can be more effective as a programmerEnable you to
Write programs that are more reliable and efficientIncorporate features that require hooks into OS
» E.g., concurrency, signal handlers
Not just a course for dedicated hackersWe bring out the hidden hacker in everyone
Cover material in this course that you won’t see elsewhere
– 21 – CS-213, F’06
Hello WorldHello WorldWhat happens and why when you run What happens and why when you run ““hellohello””
on your system?on your system?
Goal: introduce key concepts, terminology, and Goal: introduce key concepts, terminology, and componentscomponents
/*hello world*/# include <stdio.h>
int main(){
printf(“hello, world\n”);}
/*hello world*/# include <stdio.h>
int main(){
printf(“hello, world\n”);}
– 22 – CS-213, F’06
Information is Bits + ContextInformation is Bits + Context““HelloHello”” is a source codeis a source code
Sequence of bits (0 or 1)8-bit data chunks are called BytesEach Byte has an integer value that corresponds to some character (ASCII standard)
E.g., ‘#’ -> 35
Files that consist of ASCII characters -> text filesAll other files -> binary files (e.g., 35 is a part of a machine command)
Context is importantContext is importantThe same sequence of bytes might represent a character string or machine instruction
– 23 – CS-213, F’06
Programs Translated by Other ProgramsPrograms Translated by Other Programs
Pre-processor
(cpp)
hello.i Compiler(cc1)
hello.s Assembler(as)
hello.o Linker(ld)
hellohello.c
Sourceprogram
(text)
Modifiedsource
program(text)
Assemblyprogram
(text)
Relocatableobject
programs(binary)
Executableobject
program(binary)
printf.o
Pre-processingE.g., #include <stdio.h> is inserted into hello.i
Compilationhello.s: each statement is an assembly language program
Assemblyhello.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
unix> gcc –o hello hello.cunix> gcc –o hello hello.c
– 24 – CS-213, F’06
Why do We Care about This?Why do We Care about This?Optimizing program performanceOptimizing program performance
To write efficient code
Understanding linkUnderstanding link--time errorstime errorsWhy does it matter what order we list libraries?Why some link-errors do not appear before run time?
Avoiding security holesAvoiding security holesBuffer overflow bugs
– 25 – CS-213, F’06
ShellShell
ShellShell
a commanda command--line interpreter thatline interpreter that
prints a promptprints a prompt
waits for you to type command linewaits for you to type command line
loads and runs hello programloads and runs hello program
prints a promptprints a prompt
unix> ./hellohello, worldunix>
unix> ./hellohello, worldunix>
– 26 – CS-213, F’06
Hardware organizationHardware organization BusesBusesTransfer fixed-sized chunks of data (WORDS)Intel Pentium -> 4Bytes bus
Mainmemory
I/O bridgeBus interface
ALU
Register file
CPU
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
hello executable stored on disk
PC
– 27 – CS-213, F’06
Hardware organizationHardware organization I/O DevicesI/O DevicesSystem connections to external worldMouse, keyboard (input)Display, disk device (output)
Mainmemory
I/O bridgeBus interface
ALU
Register file
CPU
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
hello executable stored on disk
PC
– 28 – CS-213, F’06
Hardware organizationHardware organizationMain MemoryMain Memory
Temporary storage deviceHolds both a program and the data it manipulates with
Mainmemory
I/O bridgeBus interface
ALU
Register file
CPU
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
hello executable stored on disk
PC
– 29 – CS-213, F’06
Hardware organizationHardware organization
Control Processor Unit Control Processor Unit (CPU)(CPU)
Executes instructions stored in main memoryProgram Counter (PC or Register) contains the address of some machine-language instruction from memory
Mainmemory
I/O bridgeBus interface
ALU
Register file
CPU
System bus Memory bus
PC
CPUCPUReads the instruction from memoryPerforms simple operation (load, store, update)Updates the PC to point to next instruction
– 30 – CS-213, F’06
Running the Hello ProgramRunning the Hello ProgramReading the hello command from the keyboardReading the hello command from the keyboard
Mainmemory
I/O bridgeBus interface
ALU
Register file
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
PC
"hello"
User types "hello"
– 31 – CS-213, F’06
Running the Hello ProgramRunning the Hello ProgramShell program loads Shell program loads hello.exehello.exe into main memoryinto main memory
Mainmemory
I/O bridgeBus interface
ALU
Register file
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
hello executable stored on disk
PC
hello code
"hello,world\n"
– 32 – CS-213, F’06
Running the Hello ProgramRunning the Hello ProgramThe processor executes instructions and displays The processor executes instructions and displays ““hellohello…”…”
Mainmemory
I/O bridgeBus interface
ALU
Register file
System bus Memory bus
Disk controller
Graphicsadapter
USBcontroller
Mouse Keyboard DisplayDisk
I/O bus Expansion slots forother devices suchas network adapters
hello executable stored on disk
PC
hello code
"hello,world\n"
"hello,world\n"
– 33 – CS-213, F’06
CachingCachingA system spends a lot of time moving information from one place to anotherLarger storage devices are slower than smaller ones
Register file ~ 100 BytesMain memory ~ millions of Bytes
It is easier and cheaper to make processors run faster than it is to make main memory run faster
Mainmemory(DRAM)
MemorybridgeBus interfaceL2 cache
(SRAM)
ALU
Register fileCPU chip
Cache bus System bus Memory bus
L1 cache
(SRAM)
– 34 – CS-213, F’06
Storage Devices Form a HierarchyStorage Devices Form a HierarchyStorage at one level serves as cache at the next Storage at one level serves as cache at the next
levellevelRegisters
On-chip L1cache (SRAM)
Main memory(DRAM)
Local secondary storage(local disks)
Larger, slower,
and cheaper (per byte)storagedevices
Remote secondary storage(distributed file systems, Web servers)
Local disks hold files retrieved from disks on remote network servers.
Main memory holds disk blocks retrieved from local disks.
Off-chip L2cache (SRAM)
L1 cache holds cache lines retrieved from the L2 cache.
CPU registers hold words retrieved from cache memory.
L2 cache holds cache lines retrieved from memory.
L0:
L1:
L2:
L3:
L4:
L5:
Smaller,faster,and
costlier(per byte)storage devices
– 35 – CS-213, F’06
Operating System (OS)Operating System (OS)OS OS –– a layer of software interposed between the a layer of software interposed between the
application program and the hardwareapplication program and the hardware
Two primary purposesTwo primary purposesTo protect the hardware from misuse by applicationsTo provide simple and uniform mechanisms for manipulating low-level hardware devices
Application programs
Processor Main memory I/O devices
Operating systemSoftware
Hardware
– 36 – CS-213, F’06
OS AbstractionsOS AbstractionsFiles are abstractions of I/O devicesFiles are abstractions of I/O devices
Virtual Memory is an abstraction for the main Virtual Memory is an abstraction for the main memory and I/O devicesmemory and I/O devices
Processes are abstractions for the processor, Processes are abstractions for the processor, main memory, and I/O devicesmain memory, and I/O devices
Processor Main memory I/O devices
Processes
Files
Virtual memory
– 37 – CS-213, F’06
ProcessesProcessesThe OS provides the illusion that the program is The OS provides the illusion that the program is
the only one in the systemthe only one in the system
Process Process OS’s abstraction of a running program
Context switchingContext switchingSaving the context of one processRestoring the process of the new process
shell process
helloprocess
Application code
Time
Context switch
Context switch
OS code
Application code
OS code
Application code
– 38 – CS-213, F’06
Virtual MemoryVirtual MemoryIllusion that Illusion that each each process has process has exclusive exclusive use of main use of main memorymemory
ExampleExampleThe virtual address space for Linux
Kernel virtual memory
Memory mapped region forshared libraries
Run-time heap(created at runtime by malloc)
User stack(created at runtime)
Unused0
Memoryinvisible touser code0xc0000000
0x08048000
0x40000000
Read/write data
Read-only code and data
Loaded from the hello executable file
printf() function
0xffffffff
– 39 – CS-213, F’06
NetworkingNetworkingComputers do more than execute programsComputers do more than execute programs
They need to get data in and outThey need to get data in and outI/O system critical to program reliability and performance
They communicate with each other over They communicate with each other over networksnetworks
Many system-level issues arise in presence of network
Coping with unreliable mediaCross platform compatibilityComplex performance issues