Title: Introduction to Computer Systems
1Introduction to Computer Systems
CS-213
Aleksandar Kuzmanovic 3/31/2008
- Topics
- Staff, text, and policies
- Lecture topics and assignments
- Class overview
CS 213 S 08
2Teaching staff
- Instructor
- Prof. Aleksandar Kuzmanovic (Wed 1000-1200,
Tech L457) - TA
- Ionut Trestian (Tu, Th 2-330, Ford 2-221)
- Recitation (Tu, 5-630, Tech M120)
- Location and Time
- Lecture MW 2-320, Tech L158
- Recitation Tu, 5-630, Tech M120
-
3Prerequests
- CS211 (Fund. of comp. program.) or eq. Required
- Experience with C or C Required
- CS311 (Data structures and mgmt) 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
4Textbooks
- Required
- Randal E. Bryant and David R. OHallaron,
- Computer Systems A Programmers 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
5Homeworks, Labs, and Exams
- 4 labs, 4 homeworks, 2 exams
- Grading
- 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)
- Final grades gt90 (or 90th percentile) A
- gt80 (or 80th percentile)
B, - gt70 (or 70th percentile)
C, etc. - Late Policy
- After 1 day, maximum score is 90
- After 2 days, maximum score is 80, etc.
6Policies Assignments
- Work groups
- You must work in groups of 2 for all labs
- Let me and the TA know the groups by the end of
the week - Handins
- Assignments due at 1159pm on specified due date.
- Electronic handins only.
7Course Components
- Lectures
- Higher level concepts
- Recitations
- Applied concepts, important tools and skills for
labs, clarification of lectures, exam coverage - Labs
- The heart of the course
- 1 or 2 weeks
- Provide in-depth understanding of an aspect of
systems - Programming and measurement
8Getting Help
- Web
- http//cs.northwestern.edu/akuzma/classes/CS213-s
08/ - Copies of lectures, assignments, handouts
- Clarifications to assignments
- Newsgroups
- cs.213.announce and
- cs.213.discuss
- Clarifications to assignments, general discussion
- Cant reply immediately!
- Personal help
- Professor, Wednesdays 10-noon
- TA Tu, Th 2-330
9Cheating
- 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.
-
10Facilities
- 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 root_at_eecs.northwestern.edu
- For accessing the TLAB facilities
- - contact Carol Surma (carol_at_eecs.northwestern.ed
u) - Should you have other problems
- - contact the TA directly
11Topics
- Programs and Data (8)
- Bits operations, arithmetic, assembly language
programs, representation of C control and data
structures - The Memory Hierarchy (2)
- Memory technology, memory hierarchy, caches,
disks, locality - Linking and Exceptional Control Flow (3)
- Object files, static and dynamic linking,
libraries, loading, hardware exceptions,
processes, process control, Unix signals - Virtual Memory (2)
- Virtual memory, address translation, dynamic
storage allocation - I/O, Networking, and Concurrency (3)
- Network programming, Internet services, Web
servers
12Course Theme
- Abstraction is good, but dont 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
13Coarse 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 dont
14Hello 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? - Goal introduce key concepts, terminology, and
components
/hello world/ include ltstdio.hgt int
main() printf(hello, world\n)
15Information 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., -gt 35
- Files that consist of ASCII characters -gt text
files - All other files -gt 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 - Machines put everything in bits!
- Chapter 2 -gt machine representations of numbers
16Programs Translated by Other Programs
unixgt gcc o hello hello.c
- Phases
- Pre-processing
- E.g., include ltstdio.hgt is inserted into hello.i
- Compilation
- hello.s -gt each statement is an assembly language
program - Assembly
- hello.o -gt is 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
printf.o
Pre- processor (cpp)
Compiler (cc1)
Assembler (as)
Linker (ld)
hello.i
hello.s
hello.o
hello
hello.c
Source program (text)
Assembly program (text)
Modified source program (text)
Relocatable object programs (binary)
Executable object program (binary)
17Why do We Care about This?
- Optimizing program performance
- To write efficient code -gt 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
- 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
18Shell
- Shell
- a command-line interpreter that
- - prints a prompt
- - waits for you to type command line
- - loads and runs hello program
- - prints a prompt
unixgt ./hello hello, world unixgt
19Hardware organization
- Buses
- Transfer fixed-sized chunks of data (WORDS)
- Intel Pentium -gt 4Bytes bus
CPU
Register file
ALU
PC
System bus
Memory bus
Main memory
I/O bridge
Bus interface
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
hello executable stored on disk
20Hardware organization
- I/O Devices
- System connections to external world
- Mouse, keyboard (input)
- Display, disk device (output)
CPU
Register file
ALU
PC
System bus
Memory bus
Main memory
I/O bridge
Bus interface
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
hello executable stored on disk
21Hardware organization
- Main Memory
- Temporary storage device
- Holds both a program and the data it manipulates
with
CPU
Register file
ALU
PC
System bus
Memory bus
Main memory
I/O bridge
Bus interface
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
hello executable stored on disk
22Hardware organization
CPU
Register file
ALU
PC
System bus
Memory bus
Main memory
I/O bridge
Bus interface
- CPU
- Reads the instruction from memory
- Performs simple operation (load, store, update)
- Updates the PC to point to next instruction
- 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
23Running the Hello Program
- Reading the hello command from the keyboard
Register file
ALU
PC
System bus
Memory bus
Main memory
"hello"
I/O bridge
Bus interface
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
User types "hello"
24Running the Hello Program
- Shell program loads hello.exe into main memory
Register file
ALU
PC
System bus
Memory bus
Main memory
"hello,world\n"
I/O bridge
Bus interface
hello code
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
hello executable stored on disk
25Running the Hello Program
- The processor executes instructions and displays
hello
Register file
ALU
PC
System bus
Memory bus
Main memory
"hello,world\n"
I/O bridge
Bus interface
hello code
I/O bus
Expansion slots for other devices such as network
adapters
USB controller
Disk controller
Graphics adapter
Mouse
Keyboard
Display
Disk
hello executable stored on disk
"hello,world\n"
26Caching
- 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
(SRAM Static RAM)
CPU chip
Register file
L1 cache (SRAM)
ALU
Cache bus
System bus
Memory bus
Main memory (DRAM)
Memory bridge
Bus interface
L2 cache (SRAM)
27Storage Devices Form a Hierarchy
- Storage at one level serves as cache at the next
level
L0
Smaller, faster, and costlier (per byte) storage
devices
Registers
CPU registers hold words retrieved from cache
memory.
On-chip L1 cache (SRAM)
L1
Off-chip L2 cache (SRAM)
L2
Main memory (DRAM)
L3
Larger, slower, and cheaper (per
byte) storage devices
Local secondary storage (local disks)
L4
Remote secondary storage (distributed file
systems, Web servers)
L5
28Operating System (OS)
- OS a layer of software interposed between the
application program and the hardware - Two primary purposes
- To protect the hardware from misuse by
applications - To provide simple and uniform mechanisms for
manipulating low-level hardware devices
Application programs
Software
Operating system
Processor
Main memory
I/O devices
Hardware
29OS 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
30Processes
- The OS provides the illusion that the program is
the only one in the system - Process
- OSs abstraction of a running program
- Context switching
- Saving the context of one process
- Restoring the process of the new process
shell process
hello process
Time
Application code
Context switch
OS code
Application code
Context switch
OS code
Application code
31Virtual Memory
Memory invisible to user code
0xffffffff
- Illusion that each process has exclusive use of
main memory - Example
- The virtual address space for Linux
Kernel virtual memory
0xc0000000
User stack (created at runtime)
Memory mapped region for shared libraries
printf() function
0x40000000
Run-time heap (created at runtime by malloc)
Read/write data
Loaded from the hello executable file
Read-only code and data
0x08048000
Unused
0
32Networking
- 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
- Because of the Internet, copying info from 1
machine to another has become important