c11 atomics: Incorrect handling of boundary condition
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- testing-qa
Research direction
Start by reviewing the C11 atomics boundary-condition discussion and pull request #2485, since the issue names no source file or test. Trace the existing stale-read validation around the 499999/500000 limit; done means the legal boundary sequence no longer reports a stale read while genuine stale reads remain detected.
Written by the indexing model from the issue text.
Description
At the end of loop, there is a possible sequence
which can result myValue equal to hisRealValue
but it is still a legal sequence.
// myId is current thread Id and hisId is it's partner thread Id
// myValue starts with zero
do{
myValue++;
atomic_store_explicit(&destMemory[myId], myValue); // scope and memory order doesn't matter
fence; // type of fence doesn't matter
hisValue = atomic_load_explicit(&destMemory[hisId]);
} while(myValue == hisValue && myValue < 500000);
oldValues[myId] = hisValue;
The issue actually shows up when the two threads reading each other's values reach 499999, and now at the last iteration, one thread completes its operations and exits the loop. Now the next thread starts its operations, completes the do-while block, and will exit the loop. Below is dry run of the sequence for the both threads
//thread 1: thread 2: both have myValue as 499999
myValue++; thread 1: 500000
atomic_store_explicit(myValue) // thread 1: stores value of 500000
fence // thread 1: let others know you had new changes
hisValue = atomic_load_explicit(...) // thread 1: reads other thread value 499999
// thread 1: exit the loop since both conditions failed
myValue++; thread 2: 500000
atomic_store_explicit(myValue) // thread 2: stores value of 500000
fence // thread 2: let others know you had new changes
hisValue = atomic_load_explicit(...) // thread 2: reads other thread value 500000
// thread 2: exit the loop because myValue !< 500000
// if this is not at boundary we would have looped one more time in case of thread2
After the above execution sequence, below are the values we see while verifying the thread 1 buffers
myValue=500000
hisValue=499999
hisReadValue=500000
myValReadByHim=500000
Since myValue is equal to myValReadByHim, we are resulting in an error that says the fence is not working and both threads read a stale value. That is correct, but not at the boundary condition; here we haven't read any stale value, and the fence is working correctly. The only problem is thread 2 forced out of the loop because myValue is not less than 500000; if it's not at the boundary, it would have taken one more iteration, and the values after this iteration would not have hit this condition.
This fix makes the condition more robust while checking if two threads have read stale value. If both threads read stale values, they would read the same old values, so checking whether hisValue == myValReadByHim will make sure both threads read the stale value even at the boundaries. Now with both conditions we can be sure that both threads have read stale values.
Raised the pull request for the same: https://github.com/KhronosGroup/OpenCL-CTS/pull/2485
- Dominant language
- C++
- Stars
- 234
- Forks
- 240
- Avg merge
- 6d 12h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from KhronosGroup/OpenCL-CTS
-
cognizant-backlog
Difficulty 2/5 1-3 hours Newbie friendliness 61/100
KhronosGroup/OpenCL-CTS#2882 · 1 comment ·
Maintainers usually reply within 1 day
-
cl_khr_command_buffer: negative_enqueue_inconsistent_device expects CL_INCOMPATIBLE_COMMAND_QUEUE_KHR instead of CL_INVALID_DEVICEPossibly taken @kpet claimed this 11 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
KhronosGroup/OpenCL-CTS#2872 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
test_compiler: feature macros for cl_ext_float_atomics are not testedPossibly taken @shajder claimed this 10 days ago. Opencognizant-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/OpenCL-CTS#2818 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
KhronosGroup/OpenCL-CTS#2699 · 1 comment ·
Maintainers usually reply within 1 day
-
cleanup/refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
KhronosGroup/OpenCL-CTS#2057 ·
Maintainers usually reply within 1 day
All issues in KhronosGroup/OpenCL-CTS
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
useless statementOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
grizzlypeak3d/DJV#962 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day