Introducing Computer Systems from a Programmer’s Perspective Randal E. Bryant, David R. O’Hallaron Randal E. Bryant, David R. O’Hallaron Computer Science and Electrical Engineering Computer Science and Electrical Engineering Carnegie Mellon University Carnegie Mellon University s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 16m 8m 4m 2m 1024k 512k 256k 128k 64k 32k 16k 8k 4k 2k 1k .5k 0 200 400 600 800 1000 1200 M B/s Stride Size
29
Embed
Introducing Computer Systems from a Programmer’s Perspective Randal E. Bryant, David R. O’Hallaron Computer Science and Electrical Engineering Carnegie.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Introducing Computer Systemsfrom a
Programmer’s Perspective
Introducing Computer Systemsfrom a
Programmer’s Perspective
Randal E. Bryant, David R. O’HallaronRandal E. Bryant, David R. O’Hallaron
Computer Science and Electrical EngineeringComputer Science and Electrical Engineering
architecture course at CMU.architecture course at CMU. Good material, dedicated teachers, but students hate it Don’t see how it will affect there lives as programmers
Background (Cont.)Background (Cont.)1997: OS instructors complain about lack of 1997: OS instructors complain about lack of
preparationpreparation Students don’t know machine-level programming well
enoughWhat does it mean to store the processor state on the run-
time stack?
Our architecture course was not part of prerequisite stream
– 10 – ICS
Birth of ICSBirth of ICS1997: REB/DROH pursue new idea:1997: REB/DROH pursue new idea:
Introduce them to computer systems from a programmer's perspective rather than a system designer's perspective.
Topic Filter: What parts of a computer system affect the correctness, performance, and utility of my C programs?
1998: Replace architecture course with new course: 1998: Replace architecture course with new course: 15-213: Introduction to Computer Systems
Curriculum ChangesCurriculum Changes Sophomore level course Eliminated digital design & architecture as required
courses for CS majors
– 11 – ICS
15-213: Intro to Computer Systems15-213: Intro to Computer SystemsGoalsGoals
Teach students to be sophisticated application programmers Prepare students for upper-level systems courses
Taught every semester to 150 studentsTaught every semester to 150 students 50% CS, 40% ECE, 10% other.
Part of the 4-course CMU CS core:Part of the 4-course CMU CS core: Data structures and algorithms (Java) Programming Languages (ML) Systems (C/IA32/Linux) Intro. to theoretical CS
– 12 – ICS
ICS FeedbackICS FeedbackStudentsStudents
FacultyFaculty Prerequisite for most upper level CS systems courses Also required for ECE embedded systems, architecture, and
network courses
Course Evaluations
2
2.5
3
3.5
4
4.5
5
1995 1996 1997 1998 1999 2000 2001 2002
REB: Intro. Comp. Systems
CS Average
REB: Computer Architecture
– 13 – ICS
Lecture CoverageLecture Coverage
Data representations [3]Data representations [3] It’s all just bits. int’s are not integers and float’s are not reals.
IA32 machine language [5]IA32 machine language [5] Analyzing and understanding compiler-generated machine
code.
Program optimization [2]Program optimization [2] Understanding compilers and modern processors.
Shell Lab (1 week) Shell Lab (1 week) Writing your own shell with job control.
Malloc Lab (2-3 weeks) Malloc Lab (2-3 weeks) Writing your own malloc package.
Proxy Lab (2 weeks) Proxy Lab (2 weeks) Writing your own concurrent Web proxy.
– 19 – ICS
Bomb LabBomb Lab Idea due to Chris Colohan, TA during inaugural offering
Bomb:Bomb: C program with six C program with six phasesphases..
Each phase expects student to type a specific string.Each phase expects student to type a specific string. Wrong string: bomb explodes by printing BOOM! (- 1/4 pt) Correct string: phase defused (+10 pts) In either case, bomb sends mail to a spool file Bomb daemon posts current scores anonymously and in real time on Web
page
Goal: Defuse the bomb by defusing all six phases.Goal: Defuse the bomb by defusing all six phases. For fun, we include an unadvertised seventh secret phase
The kicker:The kicker: Students get only the binary executable of a unique bomb To defuse their bomb, students must disassemble and reverse engineer
this binary
– 20 – ICS
Properties of Bomb PhasesProperties of Bomb Phases
Phases test understanding of different C constructs Phases test understanding of different C constructs and how they are compiled to machine codeand how they are compiled to machine code Phase 1: string comparison Phase 2: loop Phase 3: switch statement/jump table Phase 4: recursive call Phase 5: pointers Phase 6: linked list/pointers/structs Secret phase: binary search (biggest challenge is figuring
out how to reach phase)
Phases start out easy and get progressively harder Phases start out easy and get progressively harder
8048b70: mov 0xfffffffc(%esi,%ebx,4),%eax 8048b74: add $0x5,%eax 8048b77: cmp %eax,(%esi,%ebx,4) 8048b7a: je 8048b81 <phase_2+0x39> 8048b7c: call 804946c <explode_bomb> 8048b81: inc %ebx 8048b82: cmp $0x5,%ebx 8048b85: jle 8048b70 <phase_2+0x28> ... # function epilogue not shown 8048b8f: ret
# else explode!
# LOOP: eax = num[i-1]
# then goto LOOP:
# edx = &str
# eax = &num[] on stack# push function args
# rd 6 ints from str 2 num
# i = 1# esi = &num[] on stack
# eax = num[i-1] + 5# if num[i-1] + 5 == num[i]# then goto OK:
# OK: i++# if (i <= 5)
# YIPPEE!
– 22 – ICS
Source Code for Bomb PhaseSource Code for Bomb Phase/* * phase2b.c - To defeat this stage the user must enter arithmetic * sequence of length 6 and delta = 5. */void phase_2(char *input){ int ii; int numbers[6];
read_six_numbers(input, numbers);
for (ii = 1; ii < 6; ii++) { if (numbers[ii] != numbers[ii-1] + 5) explode_bomb(); }}
– 23 – ICS
The Beauty of the BombThe Beauty of the Bomb
For the StudentFor the Student Get a deep understanding of machine code in the context of
a fun game Learn about machine code in the context they will encounter
in their professional livesWorking with compiler-generated code
Learn concepts and tools of debuggingForward vs backward debuggingStudents must learn to use a debugger to defuse a bomb
For the InstructorFor the Instructor Self-grading Scales to different ability levels Easy to generate variants and to port to other machines
– 35 – ICS
ICS SummaryICS Summary
ProposalProposal Introduce students to computer systems from the
programmer's perspective rather than the system builder's perspective
ThemesThemes What parts of the system affect the correctness, efficiency,
and utility of my C programs? Makes systems fun and relevant for students Prepare students for builder-oriented courses
DesireDesire Challenge the best without blowing away everyone else
MethodMethod Web-based submission of solutions Server checks for correctness and computes performance
scoreHow many stages passed, program throughput, …
Keep updated results on web pageStudents choose own nom de guerre
Relationship to GradingRelationship to Grading Students get full credit once they reach set threshold Push beyond this just for own glory/excitement
– 37 – ICS
Shameless PlugShameless Plug
http://csapp.cs.cmu.edu Published August, 2002
– 38 – ICS
CS:APPCS:APPVital stats:Vital stats:
13 chapters 154 practice problems (solutions in book), 132 homework
problems (solutions in IM) 410 figures, 249 line drawings 368 C code example, 88 machine code examples
Turn-key course provided with book:Turn-key course provided with book: Electronic versions of all code examples. Powerpoint, EPS, and PDF versions of each line drawing Password-protected Instructors Page, with Instructor’s
Manual, Lab Infrastructure, Powerpoint lecture notes, and Exam problems.
– 39 – ICS
AdoptionsAdoptions
Research universities: Prepare students for advanced courses
Small colleges: Only systems course
AdoptionsMay, 2006
– 40 – ICS
TranslationsTranslations
– 41 – ICS
CoverageCoverage
Material Used by ICS at CMUMaterial Used by ICS at CMU Pulls together material previously covered by multiple
textbooks, system programming references, and man pages
Greater Depth on Some TopicsGreater Depth on Some Topics IA32 floating point Dynamic linking Thread programming
Additional TopicAdditional Topic Computer Architecture Added to cover all topics in “Computer Organization” course
– 45 – ICS
The Evolving CS & Engineering CurriculumThe Evolving CS & Engineering CurriculumProgramming Lies at the Heart of Most Modern SystemsProgramming Lies at the Heart of Most Modern Systems
Programmers Have to Understand Their Machines and Programmers Have to Understand Their Machines and Their LimitationsTheir Limitations Correctness: computer arithmetic, storage allocation Efficiency: memory & CPU performance
Knowing How to Build Systems Is Not the Way to Learn Knowing How to Build Systems Is Not the Way to Learn How to Program ThemHow to Program Them It’s wasteful to teach every computer scientist how to design a
microprocessor Knowledge of how to build does not transfer to knowledge of