From: Martin Pieuchot Subject: Re: improve spinning in mtx_enter To: Mateusz Guzik Cc: Alexander Bluhm , tech@openbsd.org Date: Sun, 24 Mar 2024 11:14:52 +0100 On 21/03/24(Thu) 13:36, Mateusz Guzik wrote: > On Thu, Mar 21, 2024 at 1:22 PM Alexander Bluhm wrote: > [..] > I also got about 5% in terms of system time. > > I'm not going to argue about the style, but I'm going to note some > extra stuff. :) Thanks for the notes. It's always interesting to have suggestions. > 2 speed ups on top of this would come from: > 1. reducing lock access in mtx_enter_try to begin with. most notably > IPL level could be read off only once, not every single time > execuction lands there > 2. backoff could be added, even something as simple as exponentially > going to up to 8 spins would be an improvement with more cpus > > however, vast majority of the win is already there with the initial patch > > That aside I think there is an avoidable overcounting of spinning -- > even the initial attempt at taking the lock is enclosed by > spc_spinning. I would suggest prefixing the code with a mere > mtx_enter_try. Should that fail, drop down to a do { } while loop > which spins first and tries to lock later. Please submit a tested diff. Without offence, talk is cheap and we are all already busy with others priorities. However diffs are more than welcome. Thanks.