OpenImageIO/oiio — pull request #382 by lgritz (2012-06-22 21:24:07+00:00)
Title: Review: improved threading unit tests and time trials, alignment

Refactor spinlock_test and atomic_test, primarily to add command-line arguments that allow for multiple time trials and "wedges" over many thread counts. For example,

$ build/macosx/libOpenImageIO/spinlock_test --trials 3 --threads 32 --wedge

results in this output:

threads	time (best of 3)
-------	----------
1	1.2s	1.2s, range 0.0	(160000000 iters/thread)
2	1.8s	1.8s, range 0.1	(80000000 iters/thread)
4	2.5s	2.5s, range 0.1	(40000000 iters/thread)
8	2.4s	2.4s, range 0.0	(20000000 iters/thread)
12	2.4s	2.4s, range 0.1	(13333333 iters/thread)
16	2.4s	2.4s, range 0.1	(10000000 iters/thread)
20	2.1s	2.1s, range 0.3	(8000000 iters/thread)
24	2.4s	2.4s, range 0.0	(6666666 iters/thread)
28	2.2s	2.2s, range 0.3	(5714285 iters/thread)
32	2.4s	2.4s, range 0.1	(5000000 iters/thread)

Of couse, with no command-line arguments, it just tries one test with 16 threads, as it always did, for the sake of the unit tests (it has various assertions to verify that the spinlocks are working correctly). Same kind of thing for atomic_test.

Added a time_trial template to timer.h to help with such things.

New test: spin_rw_test, is like spinlock_test, but it tests the spin_rw_mutex class (reader/writer class), because I was worried about its correctness and speed. (Worked fine, BTW.)

Finally, I add some macros to sysutil.h that make it easy to align things to cache lines. (Currently works for all x86 and x86_64, may require more cases if porting to other hardware architectures.) I don't use these anywhere quite yet (in reviewed or checked in code), but intend to use them in the future for some additional threading improvements I'm working on.