45K - views

intg_1=1;intg_2=0;Thread1Thread2intfunc_1(void){intl;for(l=0;(l!=4);l+

GCC4.7.0-O2:theabovecodesometimesprints0! 2/28 CcodeAssemblygeneratedintfunc_1(void){intl;for(l=0;(l!=4);l++){if(g_1)returnl;for(g_2=0;(g_2=26);++g_2);}}func_1:movlg_1(%rip),%edxmovlg_2(%rip),%eaxtes

Embed :
Pdf Download Link

Download Pdf - The PPT/PDF document "intg_1=1;intg_2=0;Thread1Thread2intfunc_..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

intg_1=1;intg_2=0;Thread1Thread2intfunc_1(void){intl;for(l=0;(l!=4);l+






Presentation on theme: "intg_1=1;intg_2=0;Thread1Thread2intfunc_1(void){intl;for(l=0;(l!=4);l+"— Presentation transcript:

intg_1=1;intg_2=0;Thread1Thread2intfunc_1(void){intl;for(l=0;(l!=4);l++){if(g_1)returnl;�for(g_2=0;(g_2=26);++g_2);}}voidfunc_2(void){g_2=42;printf("%d",&g_2);}Shouldalwaysprint42asfunc_1doesnota ectg_2. GCC4.7.0-O2:theabovecodesometimesprints0! 2/28 CcodeAssemblygeneratedintfunc_1(void){intl;for(l=0;(l!=4);l++){if(g_1)returnl;�for(g_2=0;(g_2=26);++g_2);}}func_1:movlg_1(%rip),%edxmovlg_2(%rip),%eaxtestl%edx,%edxjne.L2movl$0,g_2(%rip)ret.L2:movl%eax,g_2(%rip)xorl%eax,%eaxret GCCsavesandrestoresg_2,sometimesrestoringitwronglyto0 3/28 Thread1Thread2func_1:movlg_1(%rip),%edxmovlg_2(%rip),%eaxtestl%edx,%edxjne.L2movl$0,g_2(%rip)ret.L2:movl%eax,g_2(%rip)xorl%eax,%eaxretvoidfunc_2(void)g_2=42;printf("%d",&g_2); I1:savesg_2=0in%eax I2:g_2=42; I1:restores%eaxtog_2 I2:printsg_2 4/28 Thread1Thread2func_1:movlg_1(%rip),%edxmovlg_2(%rip),%eaxtestl%edx,%edxjne.L2movl$0,g_2(%rip)ret.L2:movl%eax,g_2(%rip)xorl%eax,%eaxretvoidfunc_2(void)g_2=42;printf("%d",&g_2); I1:savesg_2=0in%eax I2:g_2=42; I1:restores%eaxtog_2 I2:printsg_2 4/28 Thread1Thread2func_1:movlg_1(%rip),%edxmovlg_2(%rip),%eaxtestl%edx,%edxjne.L2movl$0,g_2(%rip)ret.L2:movl%eax,g_2(%rip)xorl%eax,%eaxretvoidfunc_2(void)g_2=42;printf("%d",&g_2); I1:savesg_2=0in%eax I2:g_2=42; I1:restores%eaxtog_2 I2:printsg_2 4/28 CompilertestingStateoftheartofdi erentialcompilertesting(Regehretal.):randomwell-de nedprogramGCCvv CLang(( executableexecute executableexecute nalstate? nalstate Hardonconcurrentprograms:IRandomnon-racyinterestingprogramsIGettingallbehaviors:non-determinismIFinalstateequivalenceisnotenoughanymore 6/28 KeyremarksGCCuseseparatecompilation,soitmusttreateverysequentialfunctionasifitmaybeusedinaconcurrentprogram.Itispossibletodescribewhichoptimisationsarecorrectinanynon-racyconcurrentcontext.7/28 ContributionsAsoundnessproofforseveraltransformationsofC11executions(alongthelinesofSevcik'sworkonanidealisedDRFmodel)cmmtest:atoolforrandomdi erentialtestingofcompilersforconcurrencybugs.9/28 Whatisanoptimisation?y=42inthisexample.for(inti=0;i2;i++){z=i;;x[i]+=y+1;}=)tmp=y+1;for(inti=0;i2;i++){z=i;x[i]+=tmp;}Wz0sb Ry42sb Wx[0]43sb Wz1sb Ry42sb Wx[1]43=)Ry42sb Wz0sb Wx[0]43sb Wz1sb Wx[1]4311/28 AtomicaccessesC11isDRF:IRacesareforbiddenIRace-freecode:traceisaninterleavingoftracesofthreadsEscapemechanism:\atomiclocations"IRacesareallowedontheseIAttributesonaccessesgivetheirsemantics13/28 Release-acquiremessagepassingInitiallyx=y=f=0inthisexample:Thread1 Thread2 x=1;f.store(1,release); while(0==f.load(acquire));y=x+1;Synchronisationbetweenareleasestoreandanacquireload.Soy=2attheend.15/28 Release/acquirepairs:de nitionAnactionisareleaseifitisapossiblesourceofasynchronisation(unlock,releaseatomicwrite,scatomicwrite)Anactionisanacquireifitisapossibletargetofasynchronisation(lock,acquireatomicread,scatomicread)Asame-threadrelease-acquirepairisareleasefollowedbyanacquireinprogramorder(sb).16/28 Eliminations:criterionAnactionaisanOverwritten-Writeif:IaisawritetolIwisawritetolIaandwinthesamethread,withasbw(sbisinstructionorderinathread)I@(rel;acq):asbrelsbacqsbwwithrelareleaseandacqanacquire Similarde nitions(andsamecriterion)forRead-after-Read,Read-after-Write,Write-after-ReadandWrite-after-Write.WealsoprovedthesoundnessofeliminatingIrrelevant-Reads 17/28 Eliminations:Whythiscriterion? Thread1Thread2x=1;sb while(0==f 1.load(acquire));sb f 1.store(1,release); sb rf�!;sw;hb11 printf("%i",&x);sb while(0==f 2.load(acquire)); sb f 2.store(1,release);rf�!;sw;hboo x=2; Twosynchronisationsarerequiredforanon-racydiscriminatingcontext.18/28 ReorderingsLoop-invariantcodemotionforexamplerequirereorderingsinadditiontoeliminations.Criterion:IUnrelatednon-atomicactionscanbefreelyreorderedIActionscanbepushedincriticalsections,notout.I.e.theycangobelowanacquire,orabovearelease,butneverthecontrary(notproven).19/28 SoundoptimisationsCmmtestConclusionandfuturework 21/28 ResultsFourconcurrencybugsfoundinthecurrentversionofGCC.Writeintroductions,asinthe rstexample.InteractionwithGCCdevellopers:ITheywereusingcriteriauselesslyconservativeITheythoughtGCCwasnotdoinganyreorderingwithatomics...23/28 SummaryIWefoundcriteriaofsoundnessforcodetransformationsintheC++11memorymodelIWehaveacompleteproofoftheirsoundnessIAndbuiltatoolforautomatically ndingwhencompilersdoothertransformations26/28 Release-sequenceAWx1&#xREL0;sb;mo sw;hb!! AWx2&#xRLX0;sb;mo AWx3&#xRLX0; rf�!** ARx3¬Q0;28/28