
On 03/30/2014 04:13 PM, Niall Douglas wrote:
Just to clarify, my ~9000 cycles/op is for maximum contention i.e. fully loaded with eight threads all fighting it out. Is your 1000 cycles/op for two threads only?
Yes.
It locks/unlocks four times per operation, which accounts for a total of 20% of the CPU time.
I'm actually surprised it's as much as that. I would have thought twice per operation is the minimum possible, but you have to make some hard design choices to get it that low. AFIO "looks funny"
It uses one lock to protect its epoll data, and three to protect the io_service members. Don't ask me why it needs three in the latter case. Talking about surprise, I was surprised that system::system_category() accounted for 10% of the CPU time, but it looks like Asio wraps all system calls in system::error_code() before using them (e.g. for checking for would_block in non-blocking I/O.)