Download presentation
Presentation is loading. Please wait.
Published bySuzanna Fox Modified over 8 years ago
1
Er a s e r A D y n a m i c D a t a - R a c e D e t e c t o r f o r M u l t i - T h r e a d e d P r o g r a m s M u l t i R a c e A n E f f i c i e n t O n - t h e - F l y D a t a - R a c e D e t e c t i o n T o o l f o r M u l t i - T h r e a d e d C + + P r o g r a m s Jo h n C. L i n f o r d Detect ing Data Races in Multi- Threa ded Progr ams Slide 1 / 31
2
Key Points 1.Dat a rac es are ea sy to ca us e an d har d to de bu g. 2.We ca n't det ect all dat a rac es. 3.Det ecti on of fea sibl e rac es reli es on det ecti on of ap par ent dat a rac es. 4.Dat a rac e det ecti on too ls are eit her sta tic or dy na mic (on - the -fly an d po st mo rte m). Slide 2 / 31
3
Key Points Cont. 5.Dat a rac es ca n be pre ve nte d by foll owi ng a loc kin g dis cipl ine. 6.Co m mo nly us ed det ecti on alg orit hm s are Lo cks et an d DJI T (H ap pe ns- Bef ore ). 7.Lo cks et ma int ain s a set of ca ndi dat e loc ks for ea ch sh are d me mo ry loc ati on. If a sh are d loc ati on is acc ess ed wh en this set is em pty, the re ha s be en a viol ati on of the loc kin g dis cipl ine. Slide 3 / 31
4
Key Points Cont. 8.Lo cks et is vul ner abl e to fals e ala rm s. 9.DJI T us es a log gin g me ch ani sm. Ev ery sh are d me mo ry acc ess is log ge d to se e tha t it “ha pp en s bef ore ” pri or acc ess es to the sa me loc ati on. 10.DJ IT is de pe nd ent on the sch ed ule r an d thr ea d int erl ea vin g. 11.C om bini ng ha pp en s- bef ore wit h Lo cks et ca n im pro ve det ecti on acc ura cy. Slide 4 / 31
5
Data Race Revie w ●At lea st on e acc ess is a writ e, ●Si mu lta ne ou s acc ess is not pre ve nte d. ●Ex am ple (va ria ble X is glo bal an d sh are d) Thr ea d 1 Thr ea d 2 X = 2.7 X = 3.1 Z = 2 T = X Two thread s acces s a share d variabl e Execution Slide 5 / 31
6
Data Race Demo nstrati on ●Dat a rac es oft en lea d to un ex pe cte d an d ev en no nd ete rmi nist ic be ha vio r ●Th e out co me ma y be de pe nd ent on sp ecif ic ex ec uti on ord er (thr ea ds' int erl ea vin g) ●Cli ck im ag e to sta rt Slide 6 / 31
7
Data Race Demo nstrati on Cont. t1 = new Thread() { public void run() { while(t1 != null) {... shared[0] = shared[0] + 1;... }...t1 = new Thread() { public void run() { while(t1 != null) {... shared[0] = shared[0] + 1;... }... t1 = new Thread() { public void run() { while(t1 != null) {... shared[0] = shared[0] + 1;... }...t1 = new Thread() { public void run() { while(t1 != null) {... shared[0] = shared[0] + 1;... }... t2 = new Thread() { public void run() { while(t2 != null) {... shared[0] = shared[0] + 1;... }...t2 = new Thread() { public void run() { while(t2 != null) {... shared[0] = shared[0] + 1;... }... t2 = new Thread() { public void run() { while(t2 != null) {... shared[0] = shared[0] + 1;... }...t2 = new Thread() { public void run() { while(t2 != null) {... shared[0] = shared[0] + 1;... }... int[] share d = new int[1]; Threa d t1, t2; public DataR ace() { // Initiali ze and start thread s (show n below) } int[] share d = new int[1]; Threa d t1, t2; public DataR ace() { // Initiali ze and start thread s (show n below) } Slide 7 / 31
8
We Can't Detect All Data Races ●For t thr ea ds of n inst ruc tio ns ea ch, the nu mb er of po ssi ble ord ers is ab out t n*t. ●All po ssi ble inp uts wo uld ha ve to be tes ted. ●Ad din g det ecti on co de or de bu ggi ng inf or ma tio n ca n ch an ge the ex ec uti on sch ed ule. [Pozni ansky & Schus ter, 2003] Slide 8 / 31
9
Feasi ble Data Races ●Ra ces ba se d on po ssi ble be ha vio r of the pro gra m. ●Act ual dat a rac es whi ch co uld ma nif est in an y ex ec uti on. ●Lo cati ng fea sibl e rac es req uir es a full an aly sis of the pro gra m's se ma ntic s. ●Ex actl y loc ati ng fea sibl e rac es is NP - har d [Po zni an sky & Sc hu ste r, 20 03]. Slide 9 / 31
10
Appar ent Data Races ●Ap pro xim ati on s of fea sibl e dat a rac es ba se d on syn chr oni zati on be ha vio r in an ex ec uti on. ●Ea sie r to det ect, but les s acc ura te. ●Ap par ent rac es exi st if an d onl y if at lea st on e fea sibl e rac e exi sts. ●Lo cati ng all ap par ent rac es is NP - har d [Po zni an sky & Sc hu ste r, 20 03]. Slide 10 / 31
11
Eraser [Sava ge, Burro ws, et al., 1997] ●On - the -fly too l. ●Lo cks et alg orit hm. ●Co de an not ati on s to fla g sp eci al cas es. ●Ca n be ext en de d to ha ndl e oth er loc kin g me ch ani sm s (IR Qs ). ●Us ed in ind ust ry. ●Slo ws ap plic ati on s by a fac tor of 10 – 30. Slide 11 / 31
12
The Locks et Algorit hm (Simpl e Form) L et loc ks _h eld (t) be the set of loc ks hel d by thr ea d t F or ea ch sh are d me mo ry loc ati on v, init iali ze C( v) to the set of all loc ks O n ea ch ac ce ss to v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ l o c k s _ h e l d ( t ) I f C ( v ) : = { }, t h e n i s s u e a w a r n i n g L et loc ks _h eld (t) be the set of loc ks hel d by thr ea d t F or ea ch sh are d me mo ry loc ati on v, init iali ze C( v) to the set of all loc ks O n ea ch ac ce ss to v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ l o c k s _ h e l d ( t ) I f C ( v ) : = { }, t h e n i s s u e a w a r n i n g ●Det ect s rac es not ma nif est ed in on e ex ec uti on. ●Ge ner ate s fals e ala rm s. Lock set Refin eme nt Slide 12 / 31
13
Locks et Refine ment Exam ple Progr am locks_ held C(v) int v; v := 1024; lock(m u1); v := v + 1; unlock (mu1); lock(m u2); v := v + 1; unlock (mu2); {} {mu1} {} {mu2} {} {mu1, mu2} {mu1} {} War ning ! Slide 13 / 31
14
Simpl e Locks et is too Strict ●Var iabl es initi aliz ed wit ho ut loc ks hel d. ●Re ad- sh are d dat a rea d wit ho ut loc ks hel d. ●Re ad- writ e loc kin g me ch ani sm s (pr od uc er / co ns um er). Locks et will produ ce false- positiv es for: Slide 14 / 31
15
Locks et State Diagra m Virgi n Excl usiv e Shar ed Shar ed- Mod ified Warni ngs are issued only in the Share d- Modifi ed state Slide 15 / 31
16
Locks et State Exam ple Progr am locks_ held C(v)State( v) int v; v := 1024; lock(m u1); v := v + 1; unlock (mu1); lock(m u2); v := v + 1; unlock (mu2); {} {mu1} {} {mu2} {} {mu1, mu2} {mu1} {} Virgin Exclus ive Share d Share d- Modifi ed T1T2T1Rac e dete cted corr ectl y Slide 16 / 31
17
The Locks et Algorit hm (Exten ded) L et loc ks _h eld (t) be the set of loc ks hel d in an y mo de by thr ea d t L et wri te_ loc ks _h eld (t) be the set of loc ks hel d in wri te mo de by thr ea d t F or ea ch sh are d me mo ry loc ati on v, init iali ze C( v) to the set of all loc ks O n ea ch rea d of v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ l o c k s _ h e l d ( t ) I f C ( v ) = { }, t h e n i s s u e a w a r n i n g O n ea ch wri te of v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ w r i t e _ l o c k s _ h e l d ( t ) I f C ( v ) = { }, t h e n i s s u e a w a r n i n g L et loc ks _h eld (t) be the set of loc ks hel d in an y mo de by thr ea d t L et wri te_ loc ks _h eld (t) be the set of loc ks hel d in wri te mo de by thr ea d t F or ea ch sh are d me mo ry loc ati on v, init iali ze C( v) to the set of all loc ks O n ea ch rea d of v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ l o c k s _ h e l d ( t ) I f C ( v ) = { }, t h e n i s s u e a w a r n i n g O n ea ch wri te of v by thr ea d t, S e t C ( v ) : = C ( v ) ∩ w r i t e _ l o c k s _ h e l d ( t ) I f C ( v ) = { }, t h e n i s s u e a w a r n i n g Slide 17 / 31
18
Unhan dled Cases in Eraser ●Me mo ry reu se ●Un rec og niz ed thr ea d AP I ●Initi aliz ati on in diff ere nt thr ea d ●Be nig n rac es if(fptr == NULL) {lock(fptr_mu);if(fptr == NULL) {fptr = open(filename);}unlock(fptr_mu);}if(fptr == NULL) {lock(fptr_mu);if(fptr == NULL) {fptr = open(filename);}unlock(fptr_mu);} if(fptr == NULL) {lock(fptr_mu);if(fptr == NULL) {fptr = open(filename);}unlock(fptr_mu);}if(fptr == NULL) {lock(fptr_mu);if(fptr == NULL) {fptr = open(filename);}unlock(fptr_mu);} Slide 18 / 31
19
Unhan dled Cases in Eraser Cont. ●Ra ce on an d will be mis se d if ex ec ute s firs t int[] shared = new int[1];Thread t = new Thread() { public void run() { shared = shared + 1;...};...shared = 512;t.start();shared = shared + 256;...int[] shared = new int[1];Thread t = new Thread() { public void run() { shared = shared + 1;...};...shared = 512;t.start();shared = shared + 256;... int[] shared = new int[1];Thread t = new Thread() { public void run() { shared = shared + 1;...};...shared = 512;t.start();shared = shared + 256;...int[] shared = new int[1];Thread t = new Thread() { public void run() { shared = shared + 1;...};...shared = 512;t.start();shared = shared + 256;... [Serag iotto, 2005] Slide 19 / 31
20
Unhan dled Cases in Eraser Cont. Progra m State(s hared) Data race is not detect ed! int[] shared = new int[1];shared = 512;t.start();shared = shared + 256;Thread t = new Thread() { public void run() { shared = shared + 1;...};...int[] shared = new int[1];shared = 512;t.start();shared = shared + 256;Thread t = new Thread() { public void run() { shared = shared + 1;...};... Virgin Exclus ive Share d Share d- Modifi ed locks_h eld C(v) {}{mu1} {} Slide 20 / 31
21
Unhan dled Cases in Eraser Cont. Data race is detect ed! Progra m State(s hared) int[] shared = new int[1];shared = 512;t.start();Thread t = new Thread() { public void run() { shared = shared + 1;...};shared = shared + 256;int[] shared = new int[1];shared = 512;t.start();Thread t = new Thread() { public void run() { shared = shared + 1;...};shared = shared + 256; Virgin Exclus ive Share d Share d- Modifi ed locks_h eld C(v) {}{mu1} {} Slide 21 / 31
22
Impro ved Locks et State Diagra m [Serag iotto, 2005] Initia lized (Exc lusiv e) Initia lized and Rea d Shar ed Shar ed- Mod ified Initia lized and Writt en Virgi n Slide 22 / 31
23
Imple menta tions: Eraser ●Ma int ain s ha sh tab le of set s of loc ks. ●Re pre se nts ea ch set of loc ks wit h an ind ex. ●Ev ery sh are d me mo ry loc ati on ha s sh ad ow me mo ry co nta inin g loc kse t ind ex an d sta te. ●Sh ad ow me mo ry is loc ate d by ad din g off set to sh are d me mo ry loc ati on ad dre ss. Slide 23 / 31
24
Imple menta tions: Eraser vProgr am Memo ry Shado w Memo ry &v + Shado w Offset Locks et Index Table mu1mu2 Lock Vector Sh are d me mo ry loc ati on v is as so cia ted wit h loc ks mu 1 an d mu 2 Sh are d me mo ry loc ati on v is as so cia ted wit h loc ks mu 1 an d mu 2 [Sava ge, Burro ws, et al., 2005] Slide 24 / 31
25
Imple menta tions: Ladyb ug [Serag iotto, 2005] ●GC Era ser : –M a i n t a i n s l o c k l i s t f o r t h r e a d s a n d v a r i a b l e s. –U s e s w e a k r e f e r e n c e s ( l e s s m e m o r y u s a g e ). ●Fa st Era ser : –M a i n t a i n s l o c k l i s t f o r t h r e a d s a n d v a r i a b l e s. –U s e s s t r o n g r e f e r e n c e s ( f a s t e r ). ●Va nill a Era ser : –S a m e a s e r a s e r, b u t k e e p s h a s h t a b l e o f l o c k s e t s a l r e a d y c r e a t e d. Slide 25 / 31
26
Ladyb ug Demo nstrati on ●Re writ e cla ss file –j a v a - c p L a d y b u g. j a r b r. i m e. u s p. l a d y b u g. L a d y b u g C l a s s R e w r i t e r D a t a R a c e. c l a s s ●Ru n mo difi ed cla ss –j a v a - c p L a d y b u g. j a r :. D a t a R a c e ●Ra ces rep ort ed as exc ept ion s br.i me.us p.l ad yb ug. RC Ex ce pti on: [lin e 9] Ra ce co ndi tio n det ect ed: t2 of Dat aR ac e (ha sh co de = 1b 67f 74) wit h Thr ea d-0 at br.i me.us p.l ad yb ug. Sta ticL ad yb ug. wa rn( Sta ticL ad yb ug. jav a:1 01 4) at br.i me.us p.l ad yb ug. era ser.Er as er GC.wri teF ield (Er as er GC.jav a:4 7)... at Dat aR ac e.a cce ss$ 20 2( Dat aR ac e.j av a:9 ) at Dat aR ac e$ 1.r un( Dat aR ac e.j av a:3 7) ●Ca n als o us e GU I Slide 26 / 31
27
MultiR ace [Pozni ansky & Schus ter, 2003] ●On - the -fly too l. ●Im pro ve d Lo cks et an d DJI T+. ●Sig nifi ca ntly few er fals e ala rm s tha n Era ser. ●Mi ni ma l im pa ct on pro gra m sp ee d. Slide 27 / 31
28
DJIT ●Ba se d on La mp ort' s Ha pp en s- Bef ore rel ati on shi p. ●Det ect s the firs t ap par ent dat a rac e wh en it act uall y occ urs. ●Ca n be ext en de d to det ect rac es aft er the firs t (DJ IT+ ). ●De pe nd ent on sch ed ulin g ord er. Slide 28 / 31
29
Benefi ts of Combi ning Locks et and DJIT ●Ra ces are in the int ers ecti on of wa rni ng s. ●Lo cks et's ins en siti vity co mp en sat es for DJI T's se nsit ivit y to thr ea d int erl ea vin g. ●Lo cks et red uc es DJI T ex ec uti on ov erh ea d. ●Lo cks et wa rni ng s are “ra nk ed” by DJI T. ●Im ple me nta tio n ov erh ea d is mi ni miz ed. Slide 29 / 31
30
Concl usion 1.Dat a rac es are ea sy to ca us e an d har d to de bu g. 2.Dat a rac e det ecti on too ls are eit her sta tic or dy na mic (on - the -fly an d po st mo rte m). 3.Co m mo nly us ed det ecti on alg orit hm s are Lo cks et an d DJI T (H ap pe ns- Bef ore ). 4.Lo cks et is vul ner abl e to fals e ala rm s. 5.DJI T is de pe nd ent on the sch ed ule r an d thr ea d int erl ea vin g. 6.Co mb inin g ha pp en s- bef ore wit h Lo cks et ca n im pro ve det ecti on acc ura cy. Slide 30 / 31
31
Refer ences ●S. Sa va ge, M. Bur ro ws, G. Nel so n, P. So bal var ro, an d T.E. An der so n. Era ser : A Dy na mic Dat a Ra ce Det ect or for Mu ltith rea de d Pro gra ms. In AC M Tra ns acti on s on Co mp ute r Sy ste ms, 15( 4): pp. 39 1- 41 1, 19 97. ●E. Po zni an sky an d A. Sc hu ste r. Dy na mic Dat a- Ra ce Det ecti on in Lo ck- Ba se d Mu lti- Thr ea de d Pro gra ms. In Pri nci ple s an d Pra ctic e of Par alle l Pro gra m mi ng, pp. 17 0- 19 0, 20 03. ●E. Po zni an sky an d A. Sc hu ste r. Mu ltiR ac e: Effi cie nt Dat a Ra ce Det ecti on To ol for Mu ltith rea de d C+ + Pro gra ms. 20 05. htt p:// dsl. cs.t ec hni on. ac.i l/pr oje cts/ mu ltir ac e/ Mu ltiR ac e.h tm. htt p:// dsl. cs.t ec hni on. ac.i l/pr oje cts/ mu ltir ac e/ Mu ltiR ac e.h tm ●C. Ser agi ott o. La dy bu g: Ra ce Co ndi tio n Det ecti on in Jav a. 20 05. htt p:// ww w.p ar. uni vie. ac. at/ ~cl ovi s/la dy bu g/ htt p:// ww w.p ar. uni vie. ac. at/ ~cl ovi s/la dy bu g/ Slide 31 / 31
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.