ARM-software / synchronization-benchmarks

Collection of synchronization micro-benchmarks and traces from infrastructure applications
Other
38 stars 36 forks source link

Lockhammer: Introduce TB spin_rw_mutex test #15

Closed lucasclucasdo closed 6 years ago

lucasclucasdo commented 6 years ago

Add the tbb_spin_rw_mutex test extracted from intel TBB library (https://www.threadingbuildingblocks.org). This test is unique in that it includes the ability to specify different numbers of readers and writers during test execution. Reader/writer ratio and pure reader mask can be set via the test-specific arguments '-r' and '-m', respectively, after '--' on the command line.

Change-Id: Ie6b4e589c3728c6f308cf73a4734136ba6baf463 Signed-off-by: Lucas Crowthers lucasc.qdt@qualcommdatacenter.com

zoybai commented 6 years ago

Minor issue:

src/lockhammer.c:98:83: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
                 fprintf(stderr, "WARNING: limiting thread count to online cores (%d).\n", num_cores);
                                                                                  ~^
                                                                                  %ld
lucasclucasdo commented 6 years ago

Thanks Zoy, I temporarily added -Wall to see and many of the algorithms have issues as well. I have fixed the issues in the generic code here and will file a new issue to go over all the algorithms and fix compiler warnings.

zoybai commented 6 years ago

Found a bug for tbb_parse_args() optind and add additional check for strtoul.

Please review the reference patch attached. lh_tbb_getopt_patch.txt

lucasclucasdo commented 6 years ago

Zoy,

This should work correctly automatically when passing the test-specific args after a plain "--" on the command line to indicate that we are finished providing generic args. Not allowing test-specific args prior to "--" allows us to only need to specify the test specific args inside the per-test parser which is both simpler to maintain and more usable. For instance with this change on all non-tbb tests -r and -m will silently be accepted as non-functional arguments instead of printing the usage message and exiting as all other unrecognized args do.

zoybai commented 6 years ago

Lucas, Thanks for explanation. We have retested lh_tbb_spin_rw_mutex with many corner cases, and they all worked as intended. We will merge this pull request today.

# ./lh_tbb_spin_rw_mutex -- -r 0xa
tbb>tbb_init_locks:215 On each thread, for every 0 readers there will be 1 writer
tbb>tbb_init_locks:216 CPU mask 0x0 will be readers
tbb>tbb_init_locks:220   CPU[0], a pure reader? 0
tbb>tbb_init_locks:220   CPU[1], a pure reader? 0
tbb>tbb_init_locks:220   CPU[2], a pure reader? 0
tbb>tbb_init_locks:220   CPU[3], a pure reader? 0
tbb>tbb_init_locks:220   CPU[4], a pure reader? 0
tbb>tbb_init_locks:220   CPU[5], a pure reader? 0
tbb>tbb_init_locks:220   CPU[6], a pure reader? 0
tbb>tbb_init_locks:220   CPU[7], a pure reader? 0
400000 lock loops
813808 ns scheduled
208993 ns elapsed (~3.893949 cores)
2.034520 ns per access
0.522482 ns access rate
1.000000 average depth
8, 3.893949, 2.034520, 0.522482, 1.000000

# ./lh_tbb_spin_rw_mutex -- -m 0xzzz
tbb>tbb_init_locks:215 On each thread, for every 63 readers there will be 1 writer
tbb>tbb_init_locks:216 CPU mask 0x0 will be readers
tbb>tbb_init_locks:220   CPU[0], a pure reader? 0
tbb>tbb_init_locks:220   CPU[1], a pure reader? 0
tbb>tbb_init_locks:220   CPU[2], a pure reader? 0
tbb>tbb_init_locks:220   CPU[3], a pure reader? 0
tbb>tbb_init_locks:220   CPU[4], a pure reader? 0
tbb>tbb_init_locks:220   CPU[5], a pure reader? 0
tbb>tbb_init_locks:220   CPU[6], a pure reader? 0
tbb>tbb_init_locks:220   CPU[7], a pure reader? 0
400000 lock loops
813576 ns scheduled
200936 ns elapsed (~4.048931 cores)
2.033940 ns per access
0.502340 ns access rate
1.000000 average depth
8, 4.048931, 2.033940, 0.502340, 1.000000