course overview -...

21
1 Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O’Hallaron’s slides Course Overview CSE 238/2038/2138: Systems Programming

Upload: others

Post on 17-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

1

Instructor:Fatma CORUT ERGİN

Slides adapted from Bryant & O’Hallaron’s slides

CourseOverview

CSE238/2038/2138:SystemsProgramming

Page 2: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

2

Overview

¢ Coursetheme¢ Fiverealities¢ Logistics

Page 3: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

3

CourseTheme:SystemsKnowledgeisPower!¢ Systemsknowledge§ Howhardwareandsoftwarecombinetosupporttheexecutionofapplicationprograms

§ Howyou(asaprogrammer)canbestusetheseresources

¢ Usefuloutcomesofthecourse§ Becomemoreeffectiveprogrammers

§ Abletofindandeliminatebugsefficiently§ Abletounderstandandtuneforprogramperformance

§ Prepareforlater“systems”classesinCSE§ OperatingSystems,DigitalLogicDesign,ComputerOrganization,etc.

Page 4: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

4

UnderstandHowThingsWork

¢ WhydoIneedtoknowthisstuff?§ Abstractionisgood,butdon’tforgetreality

¢ MostCSEcoursesemphasizeabstraction§ Abstractdatatypes§ Asymptoticanalysis

¢ Theseabstractionshavelimits§ Especiallyinthepresenceofbugs§ Needtounderstanddetailsofunderlyingimplementations§ Sometimestheabstractinterfacesdon’tprovidethelevelofcontrolorperformanceyouneed

Page 5: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

5

GreatReality#1:IntsarenotIntegers,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

Page 6: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

6

ComputerArithmetic

¢ Doesnotgeneraterandomvalues§ Arithmeticoperationshaveimportantmathematicalproperties

¢ Cannotassumeall“usual”mathematicalproperties§ Duetofinitenessofrepresentations§ Integeroperationssatisfy“ring”properties

§ Commutativity,associativity,distributivity§ Floatingpointoperationssatisfy“ordering”properties

§ Monotonicity,valuesofsigns

¢ Observation§ Needtounderstandwhichabstractionsapplyinwhichcontexts§ Importantissuesforcompilerwritersandseriousapplicationprogrammers

Page 7: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

7

GreatReality#2:You’veGottoKnowAssembly¢ Chancesare,you’llneverwriteprogramsinassembly§ Compilersaremuchbetter&morepatientthanyouare

¢ But:Understandingassemblyiskeytomachine-levelexecutionmodel§ Behaviorofprogramsinpresenceofbugs

§ High-levellanguagemodelsbreakdown§ Tuningprogramperformance

§ Understandoptimizationsdone/notdonebythecompiler§ Understandingsourcesofprograminefficiency

§ Implementingsystemsoftware§ Compilerhasmachinecodeastarget§ Operatingsystemsmustmanageprocessstate

§ Creating/fightingmalware§ x86assemblyisthelanguageofchoice!

Page 8: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

8

GreatReality#3:MemoryMattersRandomAccessMemoryIsanUnphysicalAbstraction

¢ Memoryisnotunbounded§ Itmustbeallocatedandmanaged§ Manyapplicationsarememorydominated

¢ Memoryreferencingbugsespeciallypernicious§ Effectsaredistantinbothtimeandspace

¢ Memoryperformanceisnotuniform§ Cacheandvirtualmemoryeffectscangreatlyaffectprogramperformance§ Adaptingprogramtocharacteristicsofmemorysystemcanleadtomajorspeedimprovements

Page 9: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

9

MemoryReferencingBugExample

§ Resultissystemspecific

fun(0) à 3.14fun(1) à 3.14fun(2) à 3.1399998664856fun(3) à 2.00000061035156fun(4) à 3.14fun(6) à Segmentationfault

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;

}

Page 10: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

10

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) à Segmentationfault

Locationaccessedbyfun(i)

Explanation:

CriticalState 6

? 5

? 4

d7 ... d4 3

d3 ... d0 2

a[1] 1

a[0] 0

struct_t

Page 11: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

11

WhatAboutThis?typedef struct {

double d;int a[2];

} struct_t;

fun(0) à 3.14fun(1) à 3.14fun(2) à 3.14fun(3) à 3.14fun(4) à 3.14fun(6) à Segmentationfault

Locationaccessedbyfun(i)

Explanation:

CriticalState 6

? 5

? 4

a[1] 3

a[0] 2

d7 ... d4 1

d3 ... d0 0

struct_t

Page 12: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

12

MemoryReferencingErrors

¢ CandC++donotprovideanymemoryprotection§ Outofboundsarrayreferences§ Invalidpointervalues§ Abusesofmalloc/free

¢ Canleadtonastybugs§ Whetherornotbughasanyeffectdependsonsystemandcompiler§ Actionatadistance

§ Corruptedobjectlogicallyunrelatedtoonebeingaccessed§ Effectofbugmaybefirstobservedlongafteritisgenerated

¢ HowcanIdealwiththis?§ PrograminJava,Ruby,Python,ML,…§ Understandwhatpossibleinteractionsmayoccur§ Useordeveloptoolstodetectreferencingerrors(e.g.Valgrind)

Page 13: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

13

GreatReality#4:There’smoretoperformancethanasymptoticcomplexity

¢ Constantfactorsmattertoo!¢ Andevenexactopcountdoesnotpredictperformance

§ Easilysee10:1performancerangedependingonhowcodewritten§ Mustoptimizeatmultiplelevels:algorithm,datarepresentations,procedures,andloops

¢ Mustunderstandsystemtooptimizeperformance§ Howprogramscompiledandexecuted§ Howtomeasureprogramperformanceandidentifybottlenecks§ Howtoimproveperformancewithoutdestroyingcodemodularityandgenerality

Page 14: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

14

MemorySystemPerformanceExample

¢ Hierarchicalmemoryorganization¢ Performancedependsonaccesspatterns

§ Includinghowstepthroughmulti-dimensionalarray

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.3ms2.0GHzIntelCorei7Haswell

Page 15: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

15

CoursePerspective

¢ OurCourseisProgrammer-Centric§ Purposeistoshowthatbyknowingmoreabouttheunderlyingsystem,onecanbemoreeffectiveasaprogrammer

§ Enableyouto§ Writeprogramsthataremorereliableandefficient§ IncorporatefeaturesthatrequirehooksintoOS

– E.g.,concurrency,signalhandlers

Page 16: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

16

Cheating:Description

¢ Whatischeating?§ Sharingcode:bycopying,retyping,lookingat,orsupplyingafile§ Describing:verbaldescriptionofcodefromonepersontoanother.§ Coaching:helpingyourfriendtowritealab,linebyline§ SearchingtheWebforsolutions§ Copyingcodefromanykindofsource

§ Youareonlyallowedtousecodewesupply

¢ WhatisNOTcheating?§ Explaininghowtousesystemsortools§ Helpingotherswithhigh-leveldesignissues

Page 17: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

17

Cheating:Consequences¢ Penaltyforcheating:§ “0”gradeforbothparties§ Permanentmarkonyourrecordinthedepartment“black-list”

¢ Detectionofcheating:§ Wehavesophisticatedtoolsfordetectingcodeplagiarism

¢ Don’tdoit!§ Startearly§ Askthestaffforhelpwhenyougetstuck

Page 18: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

18

TeachingAssistants¢ Birol GENÇYILMAZ§ [email protected]§ Office:MB453

¢ Lokman ALTIN§ [email protected]§ Office:MB342

Page 19: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

19

Textbook

¢ RandalE.BryantandDavidR.O’Hallaron,§ ComputerSystems:AProgrammer’sPerspective,ThirdEdition(CS:APP3e),Pearson,2016

§ http://csapp.cs.cmu.edu§ Thisbookreallymattersforthecourse!

§ Howtosolvelabs§ Practiceproblemstypicalofexamproblems

Page 20: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

20

Grading

¢ Midterm (20%)¢ Final (40%)¢ Projects+Lab (40%)

Page 21: Course Overview - mimoza.marmara.edu.trmimoza.marmara.edu.tr/~fatma.ergin/courses/cse2138/slides/lecture/0… · 3 Course Theme: Systems Knowledge is Power! ¢Systems knowledge §How

21

WelcomeandEnjoy!