Course Overview - TAMU Computer Science People...
Transcript of Course Overview - TAMU Computer Science People...
1BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
CourseOverview
CSCE312
Instructor:DanielA.Jiménez
2BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
Overview
¢ Coursetheme¢ Fiverealities¢ HowthecoursefitsintotheCS/ECEcurriculum¢ Academicintegrity
3BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
CourseTheme:AbstractionIsGoodButDon’tForgetReality¢ MostCSandCEcoursesemphasizeabstraction§ Abstractdatatypes§ Asymptoticanalysis
¢ Theseabstractionshavelimits§ Especiallyinthepresence ofbugs§ Needtounderstand detailsofunderlyingimplementations
¢ Usefuloutcomesfromtaking312§ Becomemoreeffective programmers
§ Abletofindandeliminatebugsefficiently§ Abletounderstand andtuneforprogramperformance
§ Prepare forlater“systems”classes inCS&ECE§ Compilers, OperatingSystems,Networks,Computer Architecture,Embedded Systems,StorageSystems,etc.
4BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GreatReality#1:Ints arenotIntegers,FloatsarenotReals
¢ Example1:Isx2 ≥0?
§ Float’s:Yes!
§ Int’s:§ 40000*40000➙ 1600000000§ 50000*50000➙ ??
¢ Example2:Is(x +y)+z =x +(y +z)?§ Unsigned&SignedInt’s:Yes!§ Float’s:
§ (1e20+-1e20)+3.14-->3.14§ 1e20+(-1e20+3.14)-->??
Source:xkcd.com/571
5BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
ComputerArithmetic
¢ Doesnotgeneraterandomvalues§ Arithmeticoperations have importantmathematical properties
¢ Cannotassumeall“usual”mathematicalproperties§ Duetofiniteness ofrepresentations§ Integer operationssatisfy“ring”properties
§ Commutativity,associativity, distributivity§ Floatingpointoperations satisfy“ordering”properties
§ Monotonicity,valuesofsigns
¢ Observation§ Needtounderstand whichabstractions applyinwhichcontexts§ Important issues forcompilerwritersandseriousapplicationprogrammers
6BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GreatReality#2:You’veGottoKnowAssembly¢ Chancesare,you’llneverwriteprogramsinassembly§ Compilersaremuchbetter&morepatient thanyouare
¢ But:Understandingassemblyiskeytomachine-levelexecutionmodel§ Behavior ofprograms inpresence ofbugs
§ High-level languagemodelsbreakdown§ Tuningprogramperformance
§ Understand optimizationsdone/notdonebythecompiler§ Understanding sourcesofprograminefficiency
§ Implementing systemsoftware§ Compilerhasmachinecodeastarget§ Operatingsystemsmustmanageprocess state
§ Creating/fightingmalware§ x86assemblyisthelanguageofchoice!
7BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GreatReality#3:MemoryMattersRandomAccessMemoryIsanUnphysicalAbstraction
¢ Memoryisnotunbounded§ Itmustbeallocatedandmanaged§ Manyapplicationsarememorydominated
¢ Memoryreferencingbugsespeciallypernicious§ Effects aredistantinbothtimeandspace
¢ Memoryperformanceisnotuniform§ Cacheandvirtualmemoryeffects cangreatlyaffectprogramperformance§ Adaptingprogramtocharacteristics ofmemorysystemcanleadtomajorspeed improvements
8BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
MemoryReferencingBugExample
§ Result issystemspecific
fun(0) ➙ 3.14fun(1) ➙ 3.14fun(2) ➙ 3.1399998664856fun(3) ➙ 2.00000061035156fun(4) ➙ 3.14fun(6) ➙ Segmentation fault
typedef struct {int a[2];double d;
} struct_t;
double fun(int i) {volatile struct_t s;s.d = 3.14;s.a[i] = 1073741824; /* Possibly out of bounds */return s.d;
}
9BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
MemoryReferencingBugExampletypedef struct {
int a[2];double d;
} struct_t;
fun(0) ➙ 3.14fun(1) ➙ 3.14fun(2) ➙ 3.1399998664856fun(3) ➙ 2.00000061035156fun(4) ➙ 3.14fun(6) ➙ Segmentation fault
Locationaccessed byfun(i)
Explanation:
CriticalState 6
? 5
? 4
d7 ... d4 3
d3 ... d0 2
a[1] 1
a[0] 0
struct_t
10BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
MemoryReferencingErrors
¢ CandC++donotprovideanymemoryprotection§ Outofboundsarrayreferences§ Invalidpointervalues§ Abusesofmalloc/free
¢ Canleadtonastybugs§ Whetherornotbughasanyeffect depends onsystemandcompiler§ Actionatadistance
§ Corrupted objectlogicallyunrelated toonebeingaccessed§ Effectofbugmaybefirstobserved longafter itisgenerated
¢ HowcanIdealwiththis?§ Program inJava,Ruby,Python,ML,…§ Understand whatpossible interactionsmayoccur§ Useordevelop toolstodetect referencing errors (e.g.Valgrind)
11BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GreatReality#4:There’smoretoperformancethanasymptoticcomplexity
¢ Constantfactorsmattertoo!¢ Andevenexactopcountdoesnotpredictperformance
§ Easilysee10:1performance rangedependingonhowcodewritten§ Mustoptimizeatmultiplelevels:algorithm,datarepresentations,procedures, andloops
¢ Mustunderstandsystemtooptimizeperformance§ Howprogramscompiledandexecuted§ Howtomeasure programperformance andidentifybottlenecks§ Howtoimproveperformance withoutdestroyingcodemodularityandgenerality
12BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
MemorySystemPerformanceExample
¢ Hierarchicalmemoryorganization¢ Performancedependsonaccesspatterns
§ Includinghowstepthroughmulti-dimensional array
void copyji(int src[2048][2048],int dst[2048][2048])
{int i,j;for (j = 0; j < 2048; j++)for (i = 0; i < 2048; i++)
dst[i][j] = src[i][j];}
void copyij(int src[2048][2048],int dst[2048][2048])
{int i,j;for (i = 0; i < 2048; i++)for (j = 0; j < 2048; j++)
dst[i][j] = src[i][j];}
81.8ms4.3ms 2.0GHzIntelCorei7Haswell
13BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
WhyThePerformanceDiffers
128m32m
8m2m
512k128k
32k0
2000
4000
6000
8000
10000
12000
14000
16000
s1s3
s5s7
s9s11
Size (bytes)
Read
thro
ughp
ut (M
B/s)
Stride (x8 bytes)
copyij
copyji
14BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GreatReality#5:Computersdomorethanexecuteprograms
¢ Theyneedtogetdatainandout§ I/Osystemcriticaltoprogramreliabilityandperformance
¢ Theycommunicatewitheachotherovernetworks§ Manysystem-level issuesarise inpresence ofnetwork
§ Concurrent operations byautonomousprocesses§ Copingwithunreliablemedia§ Crossplatformcompatibility§ Complexperformance issues
15BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
CoursePerspective
¢ MostSystemsCoursesareBuilder-Centric§ ComputerArchitecture
§ Designpipelinedprocessor inVerilog§ OperatingSystems
§ Implementsampleportionsofoperatingsystem§ Compilers
§ Writecompiler forsimplelanguage§ Networking
§ Implementandsimulatenetworkprotocols
16BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
CoursePerspective(Cont.)
¢ OurCourseisProgrammer-Centric§ Purpose istoshowthatbyknowingmoreabouttheunderlyingsystem,onecanbemoreeffective asaprogrammer
§ Enableyouto§ Writeprograms thataremore reliableandefficient§ Incorporate features thatrequirehooksintoOS
– E.g.,concurrency, signalhandlers§ Covermaterial inthiscourse thatyouwon’tseeelsewhere§ Notjustacourse fordedicatedhackers
§ Webringoutthehiddenhacker ineveryone!
17BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
Textbook
¢ RandalE.BryantandDavidR.O’Hallaron,§ ComputerSystems:AProgrammer’sPerspective,ThirdEdition (CS:APP3e),Pearson, 2016
§ http://csapp.cs.cmu.edu§ Thisbookreallymatters forthecourse!
§ Howtosolve labs§ Practiceproblems typicalofexamproblems
18BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
CourseComponents
¢ Lectures§ Higher levelconcepts
¢ Recitations§ Appliedconcepts, important toolsandskillsforlabs,clarification oflectures, examcoverage
¢ Homeworks (Labs)§ Theheartofthecourse§ 1-2weekseach§ Provide in-depthunderstanding ofanaspectofsystems§ Programmingandmeasurement
¢ Exams(midterm+final)§ Testyourunderstanding ofconcepts&mathematicalprinciples
19BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
GettingHelp
¢ ClassWeb page:http://faculty.cse.tamu.edu/djimenez/312§ “Complete”schedule oflectures, exams,andassignments§ Copiesoflectures, assignments, exams, solutions§ Clarifications toassignments
¢ TeachingAssistants¢ PeerTeachers¢ OfficeHours¢ AskQuestionsinClass!
20BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
RulesoftheLectureHall
¢ Laptops:permitted
¢ Electroniccommunications:forbidden§ Noemail,instantmessaging, cellphonecalls,etc
¢ Presenceinlectures,recitations:voluntary,recommended
21BryantandO’Hallaron,ComputerSystems:AProgrammer’sPerspective,ThirdEdition
WelcomeandEnjoy!