Skip to content

Commit 3e60028

Browse files
committed
Remove redundant memory barrier
The memory barrier before queuing AI work was intended to ensure that changes to the global variables 'finish' and 'turn' are visible to other CPUs. However, as documented in workqueue.h, 'queue_work()' provides the required memory-ordering guarantees: all stores preceding the call to 'queue_work()' will be visible to the CPU that executes the work before the work function begins. In this project, two AI work items take turns making moves. A work item is only queued after the other has finished executing, ensuring that at any given time, at most one AI work item is on the workqueue. Under this usage pattern, 'queue_work()' always returns true, which implies that the ordering guarantees are valid and the work was not already queued. Therefore, extra memory barriers are unnecessary. Tested by executing over 1000 games to verify that the turn ordering is always correct (i.e., strictly alternating between O and X).
1 parent 04978e7 commit 3e60028

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,9 @@ static void game_tasklet_func(unsigned long __data)
292292

293293
if (finish && turn == 'O') {
294294
WRITE_ONCE(finish, 0);
295-
smp_wmb();
296295
queue_work(kxo_workqueue, &ai_one_work);
297296
} else if (finish && turn == 'X') {
298297
WRITE_ONCE(finish, 0);
299-
smp_wmb();
300298
queue_work(kxo_workqueue, &ai_two_work);
301299
}
302300
queue_work(kxo_workqueue, &drawboard_work);

0 commit comments

Comments
 (0)