]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Significantly speed up libthr/mutex_test and make more reliable
authorarichardson <arichardson@FreeBSD.org>
Thu, 26 Nov 2020 13:31:57 +0000 (13:31 +0000)
committerarichardson <arichardson@FreeBSD.org>
Thu, 26 Nov 2020 13:31:57 +0000 (13:31 +0000)
commit504b88bb8ddd0d70d32030ca17ef9daa9c990371
treea25e7c5c6de3f25ba33d3c7dc8af371970971852
parent09e24ed8a6fe98930a30cffb7cf66dc9fe6dd270
Significantly speed up libthr/mutex_test and make more reliable

Instead of using a simple global++ as the data race, with this change we
perform the increment by loading the global, delaying for a bit and then
storing back the incremented value. If I move the increment outside of the
mutex protected range, I can now see the data race with only 100 iterations
on amd64 in almost all cases. Before this change such a racy test almost
always passed with < 100,000 iterations and only reliably failed with the
current limit of 10 million.

I noticed this poorly written test because the mutex:mutex{2,3} and
timedmutex:mutex{2,3} tests were always timing out on our CheriBSD Jenkins.
Writing good concurrency tests is hard so I won't attempt to do so, but this
change should make the test more likely to fail if pthread_mutex_lock is not
implemented correctly while also significantly reducing the time it takes to
run these four tests. It will also reduce the time it takes for QEMU RISC-V
testsuite runs by almost 40 minutes (out of currently 7 hours).

Reviewed By: brooks, ngie
Differential Revision: https://reviews.freebsd.org/D26473
contrib/netbsd-tests/lib/libpthread/t_mutex.c