Skip to content

Commit 5f06575

Browse files
committed
formatting, add new critical-section check for mutual-exclusion violation
1 parent 277bada commit 5f06575

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1059
-868
lines changed

AndersonKim.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void * Worker( void * arg ) {
182182
Atomic ly;
183183

184184
for ( int r = 0; r < RUNS; r += 1 ) {
185-
uint32_t randomThreadChecksum = 0;
185+
RTYPE randomThreadChecksum = 0;
186186

187187
for ( entry = 0; stop == 0; entry += 1 ) {
188188
x = id;
@@ -284,7 +284,7 @@ void __attribute__((noinline)) ctor2() {
284284
states = Allocator( sizeof(typeof(states[0])) * N );
285285
levels = Allocator( sizeof(typeof(levels[0])) * N );
286286
levels[0] = -1; // default for N=1
287-
for ( TYPE id = 0; id < N; id += 1 ) {
287+
for ( typeof(N) id = 0; id < N; id += 1 ) {
288288
t[id].Q[0] = t[id].Q[1] = t[id].R = 0;
289289
unsigned int start = N + id, level = Log2( start );
290290
states[id] = Allocator( sizeof(typeof(states[0][0])) * level );

AravindF3.c

+7-16
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,32 @@
22
// Distrib. Comput. 73 (2013), Fig. 3, p. 1033.
33
// Moved turn[id] = 0; after the critical section for performance reasons.
44

5-
#include "FCFS.h"
6-
75
static TYPE PAD1 CALIGN __attribute__(( unused )); // protect further false sharing
86
static VTYPE * D CALIGN, * T CALIGN;
9-
FCFSTestGlobal();
107
static TYPE PAD2 CALIGN __attribute__(( unused )); // protect further false sharing
118

129
static void * Worker( void * arg ) {
1310
TYPE id = (size_t)arg;
1411
uint64_t entry;
1512

16-
#ifdef FAST
13+
#ifdef FAST
1714
unsigned int cnt = 0, oid = id;
18-
#endif // FAST
15+
#endif // FAST
1916

2017
TYPE S[N];
2118
typeof(N) j, t;
2219

2320
for ( int r = 0; r < RUNS; r += 1 ) {
24-
uint32_t randomThreadChecksum = 0;
21+
RTYPE randomThreadChecksum = 0;
2522
t = 1;
2623

2724
for ( entry = 0; stop == 0; entry += 1 ) {
28-
FCFSTestIntroTop();
2925
D[id] = 1; // phase 1, FCFS
3026
Fence(); // force store before more loads
3127
for ( j = 0; j < N; j += 1 ) // copy turn values
3228
S[j] = T[j];
3329
T[id] = t; // advance turn
3430
D[id] = 0;
35-
FCFSTestIntroMid();
3631
Fence(); // force store before more loads
3732
for ( j = 0; j < N; j += 1 )
3833
if ( S[j] != 0 ) // want in ?
@@ -49,26 +44,24 @@ static void * Worker( void * arg ) {
4944
for ( j = id + 1; j < N; j += 1 ) // B-L entry protocol, stage 2
5045
while ( D[j] != 0 ) Pause();
5146
// T[id] = 0; // original position
52-
FCFSTestIntroBot();
5347

5448
randomThreadChecksum += CriticalSection( id );
5549

56-
FCFSTestExit();
5750
D[id] = 0; // B-L exit protocol
5851
T[id] = 0; // new position
5952
t = t < 3 ? t + 1 : 1; // [1..3]
6053

61-
#ifdef FAST
54+
#ifdef FAST
6255
id = startpoint( cnt ); // different starting point each experiment
6356
cnt = cycleUp( cnt, NoStartPoints );
64-
#endif // FAST
57+
#endif // FAST
6558
} // for
6659

6760
__sync_fetch_and_add( &sumOfThreadChecksums, randomThreadChecksum );
6861

69-
#ifdef FAST
62+
#ifdef FAST
7063
id = oid;
71-
#endif // FAST
64+
#endif // FAST
7265
entries[r][id] = entry;
7366
__sync_fetch_and_add( &Arrived, 1 );
7467
while ( stop != 0 ) Pause();
@@ -86,11 +79,9 @@ void __attribute__((noinline)) ctor() {
8679
for ( typeof(N) i = 0; i < N; i += 1 ) {
8780
T[i] = 0;
8881
} // for
89-
FCFSTestCtor();
9082
} // ctor
9183

9284
void __attribute__((noinline)) dtor() {
93-
FCFSTestDtor();
9485
free( (void *)T );
9586
free( (void *)D );
9687
} // dtor

AravindF4.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ static void * Worker( void * arg ) {
99
TYPE id = (size_t)arg;
1010
uint64_t entry;
1111

12-
#ifdef FAST
12+
#ifdef FAST
1313
unsigned int cnt = 0, oid = id;
14-
#endif // FAST
14+
#endif // FAST
1515

1616
TYPE S[N][2];
1717
typeof(N) j, bit;
1818

1919
for ( int r = 0; r < RUNS; r += 1 ) {
20-
uint32_t randomThreadChecksum = 0;
20+
RTYPE randomThreadChecksum = 0;
2121
bit = 0;
2222

2323
for ( entry = 0; stop == 0; entry += 1 ) {
@@ -56,17 +56,17 @@ static void * Worker( void * arg ) {
5656
X[id] = 0;
5757
bit = ! bit;
5858

59-
#ifdef FAST
59+
#ifdef FAST
6060
id = startpoint( cnt ); // different starting point each experiment
6161
cnt = cycleUp( cnt, NoStartPoints );
62-
#endif // FAST
62+
#endif // FAST
6363
} // for
6464

6565
__sync_fetch_and_add( &sumOfThreadChecksums, randomThreadChecksum );
6666

67-
#ifdef FAST
67+
#ifdef FAST
6868
id = oid;
69-
#endif // FAST
69+
#endif // FAST
7070
entries[r][id] = entry;
7171
__sync_fetch_and_add( &Arrived, 1 );
7272
while ( stop != 0 ) Pause();

Arbiter.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ static pthread_t arbiter;
1111
static void * Worker( void * arg ) {
1212
TYPE id = (size_t)arg;
1313
uint64_t entry;
14-
#ifdef FAST
14+
#ifdef FAST
1515
unsigned int cnt = 0, oid = id;
16-
#endif // FAST
16+
#endif // FAST
1717

1818
for ( int r = 0; r < RUNS; r += 1 ) {
19-
uint32_t randomThreadChecksum = 0;
19+
RTYPE randomThreadChecksum = 0;
2020

2121
for ( entry = 0; stop == 0; entry += 1 ) {
2222
intents[id] = 1; // entry protocol
@@ -26,17 +26,17 @@ static void * Worker( void * arg ) {
2626

2727
serving[id] = 0; // exit protocol
2828

29-
#ifdef FAST
29+
#ifdef FAST
3030
id = startpoint( cnt ); // different starting point each experiment
3131
cnt = cycleUp( cnt, NoStartPoints );
32-
#endif // FAST
32+
#endif // FAST
3333
} // for
3434

3535
__sync_fetch_and_add( &sumOfThreadChecksums, randomThreadChecksum );
3636

37-
#ifdef FAST
37+
#ifdef FAST
3838
id = oid;
39-
#endif // FAST
39+
#endif // FAST
4040
entries[r][id] = entry;
4141
__sync_fetch_and_add( &Arrived, 1 );
4242
while ( stop != 0 ) Pause();

Burns2.c

+28-20
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33

44
#include <stdbool.h>
55

6-
static volatile TYPE turn CALIGN, *flag CALIGN;
7-
static TYPE PAD CALIGN __attribute__(( unused )); // protect further false sharing
6+
static TYPE PAD1 CALIGN __attribute__(( unused )); // protect further false sharing
7+
static VTYPE turn CALIGN, * flag CALIGN;
8+
static TYPE PAD2 CALIGN __attribute__(( unused )); // protect further false sharing
89

9-
static void *Worker( void *arg ) {
10+
static void * Worker( void * arg ) {
1011
TYPE id = (size_t)arg;
1112
uint64_t entry;
12-
#ifdef FAST
13+
14+
#ifdef FAST
1315
unsigned int cnt = 0, oid = id;
14-
#endif // FAST
16+
#endif // FAST
1517

16-
int j;
18+
typeof(N) j;
1719

1820
for ( int r = 0; r < RUNS; r += 1 ) {
19-
entry = 0;
20-
while ( stop == 0 ) {
21+
RTYPE randomThreadChecksum = 0;
22+
23+
for ( entry = 0; stop == 0; entry += 1 ) {
2124
L0: flag[id] = true; // entry protocol
2225
turn = id; // RACE
2326
Fence(); // force store before more loads
@@ -34,17 +37,22 @@ static void *Worker( void *arg ) {
3437
for ( j = 0; j < N; j += 1 )
3538
if ( FASTPATH( j != id && flag[j] ) ) goto L2;
3639
} // if
37-
CriticalSection( id );
40+
41+
randomThreadChecksum += CriticalSection( id );
42+
3843
flag[id] = false; // exit protocol
39-
#ifdef FAST
44+
45+
#ifdef FAST
4046
id = startpoint( cnt ); // different starting point each experiment
4147
cnt = cycleUp( cnt, NoStartPoints );
42-
#endif // FAST
43-
entry += 1;
44-
} // while
45-
#ifdef FAST
48+
#endif // FAST
49+
} // for
50+
51+
__sync_fetch_and_add( &sumOfThreadChecksums, randomThreadChecksum );
52+
53+
#ifdef FAST
4654
id = oid;
47-
#endif // FAST
55+
#endif // FAST
4856
entries[r][id] = entry;
4957
__sync_fetch_and_add( &Arrived, 1 );
5058
while ( stop != 0 ) Pause();
@@ -53,19 +61,19 @@ static void *Worker( void *arg ) {
5361
return NULL;
5462
} // Worker
5563

56-
void ctor() {
57-
flag = Allocator( N * sizeof(typeof(flag[0])) );
58-
for ( int i = 0; i < N; i += 1 ) { // initialize shared data
64+
void __attribute__((noinline)) ctor() {
65+
flag = Allocator( sizeof(typeof(flag[0])) * N );
66+
for ( typeof(N) i = 0; i < N; i += 1 ) { // initialize shared data
5967
flag[i] = false;
6068
} // for
6169
//turn = 0;
6270
} // ctor
6371

64-
void dtor() {
72+
void __attribute__((noinline)) dtor() {
6573
free( (void *)flag );
6674
} // dtor
6775

6876
// Local Variables: //
6977
// tab-width: 4 //
70-
// compile-command: "gcc -Wall -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=Burns2 Harness.c -lpthread -lm" //
78+
// compile-command: "gcc -Wall -Wextra -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=Burns2 Harness.c -lpthread -lm -D`hostname` -DCFMT -DCNT=0" //
7179
// End: //

BurnsLynchRetract.c

+32-21
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,50 @@
33

44
enum Intent { DontWantIn, WantIn };
55

6-
static volatile TYPE *intents CALIGN; // shared
6+
static TYPE PAD1 CALIGN __attribute__(( unused )); // protect further false sharing
7+
static VTYPE * intents CALIGN; // shared
8+
static TYPE PAD2 CALIGN __attribute__(( unused )); // protect further false sharing
79

8-
static void *Worker( void *arg ) {
9-
const TYPE id = (size_t)arg;
10+
static void * Worker( void * arg ) {
11+
TYPE id = (size_t)arg;
1012
uint64_t entry;
11-
#ifdef FAST
13+
14+
#ifdef FAST
1215
unsigned int cnt = 0, oid = id;
13-
#endif // FAST
16+
#endif // FAST
17+
18+
typeof(N) j;
1419

1520
for ( int r = 0; r < RUNS; r += 1 ) {
16-
entry = 0;
17-
while ( stop == 0 ) {
21+
RTYPE randomThreadChecksum = 0;
22+
23+
for ( entry = 0; stop == 0; entry += 1 ) {
1824
L0: intents[id] = DontWantIn; // entry protocol
1925
Fence(); // force store before more loads
20-
for ( int j = 0; j < id; j += 1 )
26+
for ( j = 0; j < id; j += 1 )
2127
if ( intents[j] == WantIn ) { Pause(); goto L0; }
2228
intents[id] = WantIn;
2329
Fence(); // force store before more loads
24-
for ( int j = 0; j < id; j += 1 )
30+
for ( j = 0; j < id; j += 1 )
2531
if ( intents[j] == WantIn ) goto L0;
26-
L1: for ( int j = id + 1; j < N; j += 1 )
32+
L1: for ( j = id + 1; j < N; j += 1 )
2733
if ( intents[j] == WantIn ) { Pause(); goto L1; }
28-
CriticalSection( id ); // critical section
34+
35+
randomThreadChecksum += CriticalSection( id );
36+
2937
intents[id] = DontWantIn; // exit protocol
30-
#ifdef FAST
38+
39+
#ifdef FAST
3140
id = startpoint( cnt ); // different starting point each experiment
3241
cnt = cycleUp( cnt, NoStartPoints );
33-
#endif // FAST
34-
entry += 1;
35-
} // while
36-
#ifdef FAST
42+
#endif // FAST
43+
} // for
44+
45+
__sync_fetch_and_add( &sumOfThreadChecksums, randomThreadChecksum );
46+
47+
#ifdef FAST
3748
id = oid;
38-
#endif // FAST
49+
#endif // FAST
3950
entries[r][id] = entry;
4051
__sync_fetch_and_add( &Arrived, 1 );
4152
while ( stop != 0 ) Pause();
@@ -44,18 +55,18 @@ static void *Worker( void *arg ) {
4455
return NULL;
4556
} // Worker
4657

47-
void ctor() {
58+
void __attribute__((noinline)) ctor() {
4859
intents = Allocator( sizeof(typeof(intents[0])) * N );
49-
for ( int i = 0; i < N; i += 1 ) { // initialize shared data
60+
for ( typeof(N) i = 0; i < N; i += 1 ) { // initialize shared data
5061
intents[i] = DontWantIn;
5162
} // for
5263
} // ctor
5364

54-
void dtor() {
65+
void __attribute__((noinline)) dtor() {
5566
free( (void *)intents );
5667
} // dtor
5768

5869
// Local Variables: //
5970
// tab-width: 4 //
60-
// compile-command: "gcc -Wall -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=BurnsLynchRetract Harness.c -lpthread -lm" //
71+
// compile-command: "gcc -Wall -Wextra -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=BurnsLynchRetract Harness.c -lpthread -lm -D`hostname` -DCFMT -DCNT=0" //
6172
// End: //

0 commit comments

Comments
 (0)