在 2026-9-22 13:12, Kirill Makurin 写道:
Hello,

GitHub CI run: https://github.com/maiddaisuki/mingw-w64/actions/runs/35682236764

These patches look good to me. So I have pushed them now.


(the rest is some testing I did while worked on these changes)

While working in these changes, I was considering adding the spin loop which 
used a compile-time constant for the spin count (value of zero would complete 
remove this path during compilation) before entering wait state.

Back in May, when `pthread_spin_*` functions were updated, I mentioned that 
duration of tests pthread_rwlock/rwlock{7,8} increased from (all measurements 
are approximate) 1,100ms to 138,142ms and from 200ms to 13,810ms respectively.

I tried using these tests for measurements:

- With the attached changes, these tests take about 1,500ms and 250ms 
respectively.

- With the "spin loop", pthread_rwlock/rwlock8 would take about 300ms, while 
duration of pthread_rwlock/rwlock7 would range from 1,800ms to 2,200ms depending on spin 
count.

So, using "spin loop" was making code noticeable slower so I ditched that idea 
completely.

There is another thing I tried to measure: time spent in `pthread_spin_lock` 
before obtaining the lock when fast lock path failed. I called 
`QueryPerformanceCounter ` at three points:

1. Before entering the "spin loop`
2. Before entering wait state (if failed to obtain lock while spinning)
3. Once the lock was obtained

If lock was obtained while spinning, it wound print time spent spinning and 
total spin count. Otherwise, it would print time spent both spinning and 
waiting.

While time spent waiting looked pretty consistent, spinning time had absolutely 
insane spikes; for example, for some spin count, total wait time would not 
exceed 2 nanoseconds, while spinning time would sometimes spike to astronomical 
25 nanoseconds (which contributes to total time spent in `pthread_spin_lock` if 
it has to enter wait state).

Spinning can increase pressure on shared cache and cause turbulence; it's more obvious if a datum is shared between different CCDs of an AMD CPU. The issue is addressed by the K42 lock algorithm (said to be patented by IBM): https://locklessinc.com/articles/locks/




--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to