CSCI 3240 CSCI 3240 Overview' ! Course'theme' CSCI$3240$ ! Five'reali;es' Introduc0on$to$Computer$Systems$ ! How'the'course'fits'into'the'curriculum' ! Academic'integrity' MTSU$ Spring$2016 ' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 1 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 2 CSCI 3240 CSCI 3240 Course$Theme:$ Great$Reality$#1:$$ Abstrac0on$Is$Good$But$Don’t$Forget$Reality$ Ints$are$not$Integers,$Floats$are$not$Reals$ ! Most$CS$and$CE$courses$emphasize$abstrac0on$ ! Example$1:$Is$x 2 $≥$0?$ ! Abstract'data'types' ! Float’s:'Yes!' ! Asympto;c'analysis' ! These$abstrac0ons$have$limits$ ! Especially'in'the'presence'of'bugs' ! Need'to'understand'details'of'underlying'implementa;ons' ! Int’s:' ! Useful$outcomes$from$taking$3240$ ! '40000'*'40000'' ➙ '1600000000' ! Become'more'effec;ve'programmers' ! '50000'*'50000'' ➙ '??' ! Able'to'find'and'eliminate'bugs'efficiently' ! Example$2:$Is$(x$+$y)$+$z$$=$$x$+$(y$+$z)?$ ! Able'to'understand'and'tune'for'program'performance' ! Unsigned'&'Signed'Int’s:'Yes!' ! Prepare'for'later'“systems”'classes'in'CS'&'ECE' ! Float’s: '' ! Compilers,'Opera;ng'Systems,'Networks,'Computer'Architecture,' ! '(1e20'+'\1e20)'+'3.14'\\>'3.14' Embedded'Systems,'Storage'Systems,'etc.' ! '1e20'+'(\1e20'+'3.14)'\\>'??' Source:'xkcd.com/571' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 3 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 4 CSCI 3240 CSCI 3240 Great$Reality$#2:$$ Computer$Arithme0c$ You’ve$Got$to$Know$Assembly$ ! Does$not$generate$random$values$ ! Chances$are,$you’ll$never$write$programs$in$assembly$ ! Arithme;c'opera;ons'have'important'mathema;cal'proper;es' ! Compilers'are'much'beeer'&'more'pa;ent'than'you'are' ! Cannot$assume$all$“usual”$mathema0cal$proper0es$ ! But:$Understanding$assembly$is$key$to$machine]level$execu0on$ model$ ! Due'to'finiteness'of'representa;ons' ! Integer'opera;ons'sa;sfy'“ring”'proper;es' ! Behavior'of'programs'in'presence'of'bugs' ! Commuta;vity,'associa;vity,'distribu;vity' ! High\level'language'models'break'down' ! Floa;ng'point'opera;ons'sa;sfy'“ordering”'proper;es' ! Tuning'program'performance' ! Monotonicity,'values'of'signs' ! Understand'op;miza;ons'done'/'not'done'by'the'compiler' ! Observa0on$ ! Understanding'sources'of'program'inefficiency' ! Implemen;ng'system'sogware' ! Need'to'understand'which'abstrac;ons'apply'in'which'contexts' ! Compiler'has'machine'code'as'target' ! Important'issues'for'compiler'writers'and'serious'applica;on'programmers' ! Opera;ng'systems'must'manage'process'state' ! Crea;ng'/'figh;ng'malware' ! x86'assembly'is'the'language'of'choice!' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 5 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 6
CSCI 3240 CSCI 3240 Great$Reality$#3:$Memory$Ma^ers$ Memory$Referencing$Bug$Example$ Random$Access$Memory$Is$an$Unphysical$Abstrac0on$ typedef struct { int a[2]; ! Memory$is$not$unbounded$ double d; } struct_t; ! It'must'be'allocated'and'managed' ! Many'applica;ons'are'memory'dominated' double fun(int i) { volatile struct_t s; ! Memory$referencing$bugs$especially$pernicious$ s.d = 3.14; s.a[i] = 1073741824; /* Possibly out of bounds */ ! Effects'are'distant'in'both';me'and'space' return s.d; ! Memory$performance$is$not$uniform$ } ! Cache'and'virtual'memory'effects'can'greatly'affect'program'performance' 3.14 fun(0) ➙ 3.14 ! Adap;ng'program'to'characteris;cs'of'memory'system'can'lead'to'major' fun(1) ➙ 3.1399998664856 fun(2) ➙ speed'improvements' 2.00000061035156 fun(3) ➙ fun(4) ➙ 3.14 Segmenta;on'fault fun(6) ➙ ! Result'is'system'specific' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 7 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 8 CSCI 3240 CSCI 3240 Memory$Referencing$Errors$ Memory$Referencing$Bug$Example$ 3.14 typedef struct { fun(0) ➙ ! C$and$C++$do$not$provide$any$memory$protec0on$ 3.14 int a[2]; fun(1) ➙ double d; 3.1399998664856 ! Out'of'bounds'array'references' fun(2) ➙ } struct_t; 2.00000061035156 fun(3) ➙ ! Invalid'pointer'values' fun(4) ➙ 3.14 ! Abuses'of'malloc/free' Segmenta;on'fault fun(6) ➙ ! Can$lead$to$nasty$bugs$ Explana;on:' ! Whether'or'not'bug'has'any'effect'depends'on'system'and'compiler' ! Ac;on'at'a'distance' Cri;cal'State' 6' ! Corrupted'object'logically'unrelated'to'one'being'accessed' ?' 5' ! Effect'of'bug'may'be'first'observed'long'ager'it'is'generated' ?' 4' Loca;on'accessed'by' ! How$can$I$deal$with$this?$ fun(i) ! Program'in'Java,'Ruby,'Python,'ML,'…' 3' d7 ... d4 struct_t ! Understand'what'possible'interac;ons'may'occur' 2' d3 ... d0 ! Use'or'develop'tools'to'detect'referencing'errors'(e.g.'Valgrind)' 1' a[1] Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 9 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 10 CSCI 3240 CSCI 3240 Great$Reality$#4:$There’s$more$to$ Memory$System$Performance$Example$ performance$than$asympto0c$complexity ' ' ! Constant$factors$ma^er$too!$ void copyij(int src[2048][2048], void copyji(int src[2048][2048], int dst[2048][2048]) int dst[2048][2048]) ! And$even$exact$op$count$does$not$predict$performance$ { { int i,j; int i,j; ! Easily'see'10:1'performance'range'depending'on'how'code'wrieen' for (i = 0; i < 2048; i++) for (j = 0; j < 2048; j++) ! Must'op;mize'at'mul;ple'levels:'algorithm,'data'representa;ons,' for (j = 0; j < 2048; j++) for (i = 0; i < 2048; i++) dst[i][j] = src[i][j]; dst[i][j] = src[i][j]; procedures,'and'loops' } } ! Must$understand$system$to$op0mize$performance$ 4.3ms' 2.0'GHz'Intel'Core'i7'Haswell' 81.8ms' ! How'programs'compiled'and'executed' ! How'to'measure'program'performance'and'iden;fy'boelenecks' ! Hierarchical'memory'organiza;on' ! How'to'improve'performance'without'destroying'code'modularity'and' generality' ! Performance'depends'on'access'paeerns' ! Including'how'step'through'mul;\dimensional'array' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 11 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 12
CSCI 3240 Great$Reality$#5:$ Why'The'Performance'Differs' Computers$do$more$than$execute$programs$ copyij ! They$need$to$get$data$in$and$out$ ! I/O'system'cri;cal'to'program'reliability'and'performance' 16000 14000 Read throughput (MB/s) 12000 ! They$communicate$with$each$other$over$networks$ 10000 ! Many'system\level'issues'arise'in'presence'of'network' 8000 ! Concurrent'opera;ons'by'autonomous'processes' 6000 ! Coping'with'unreliable'media' ! Cross'plaqorm'compa;bility' 4000 2000 ! Complex'performance'issues' copyji 0 32k s1 128k s3 512k s5 2m s7 8m Stride (x8 bytes) s9 Size (bytes) 32m s11 128m Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 13 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 14 CSCI 3240 CSCI 3240 Role'within'CS/ECE'Curriculum' Course'Perspec;ve' ! Most'Systems'Courses'are'Builder\Centric' ! Computer'Architecture' Opera;ng ! Design'pipelined'processor'in'Verilog' Databases' Networks' Compilers' Architecture' Systems' ! Opera;ng'Systems' Network' Processes' Machine' ! Implement'sample'por;ons'of'opera;ng'system' Data'Reps.' Execu;on'Model' Protocols' Mem.'Mgmt' Code' Memory'Model' Memory'System' ! Compilers' ! Write'compiler'for'simple'language' ! Networking' 3240' Founda;on'of'Computer'Systems' ! Implement'and'simulate'network'protocols' Underlying'principles'for'hardware,'' sogware,'and'networking' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 15 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 16 CSCI 3240 CSCI 3240 Chea;ng:'Descrip;on' Chea;ng:'Consequences' ! What'is'chea;ng?' ! Penalty'for'chea;ng:' ! Sharing'code:'by'copying,'retyping,' looking$at ,'or'supplying'a'file' ! Removal'from'course'with'failing'grade'(no'excep;ons!)' ! Describing:'verbal'descrip;on'of'code'from'one'person'to'another.' ! Permanent'mark'on'your'record' ! Coaching:'helping'your'friend'to'write'a'lab,'line'by'line' ! Your'instructors’'personal'contempt' ! Searching'the'Web'for'solu;ons' ! Copying'code'from'a'previous'course'or'online'solu;on' ! Detec;on'of'chea;ng:' ! You'are'only'allowed'to'use'code'we'supply,'or'from'the'CS:APP'website' ! I'have'sophis;cated'tools'for'detec;ng'code'plagiarism' ! What'is'NOT'chea;ng?' ! Last'Fall'at'CMU,'20'students'were'caught'chea;ng'and'failed'the'course.'' ! Explaining'how'to'use'systems'or'tools' ! Some'were'expelled'from'the'University' ! Helping'others'with'high\level'design'issues' ! Don’t'do'it!' ! See'the'course'syllabus'for'details.' ! Start'early' ! Ignorance'is'not'an'excuse' ! Ask'the'tutors'for'help'when'you'get'stuck' ' Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 17 Bryant'and'O’Hallaron,'Computer'Systems:'A'Programmer’s'Perspec;ve,'Third'Edi;on' 18
Recommend
More recommend