svn commit: r313040 - head/sys/mips/include

David Chisnall theraven at FreeBSD.org
Wed Feb 1 16:44:14 UTC 2017


On 1 Feb 2017, at 08:13, Konstantin Belousov <kostikbel at gmail.com> wrote:
> 
> On Wed, Feb 01, 2017 at 10:38:42AM -0500, Alexander Kabaev wrote:
>> On Wed, 1 Feb 2017 16:17:21 +0200
>> Konstantin Belousov <kostikbel at gmail.com> wrote:
>> 
>>> Please do not retry on sc failure, return the error to upper layer.
>>> See also r313007 and preceeding discussion after r312973.
>> 
>> There was not much a discussion there, do you mind expanding a bit on
>> why one behavior is more desired than other? I am not against the
>> change, but I need to understand the reasoning behind it better. Since
>> atomic_cmpset retries too, it will have to be adjusted as well.
> 
> atomic_cmpset() cannot avoid retry on the ll/sc architectures, because
> sc might fail even if the old and the new values are same. One of the
> points of the fcmpset API design is to avoid nested loops: this is a
> microoptimization to put less pressure on the CPUs frontend. The caller
> of (f)cmpset must check for failure anyway, so not doing this inside the
> function reduces number of branches. Less branches makes code shorter,
> and reduces utilization of some CPU resources, like branch predictor
> state.

C[++]11 addresses this by having a weak and a strong variant of compare and exchange.  The strong version may only fail if the comparison fails, we weak version is permitted to fail spuriously.  Given that most uses of compare and exchange use a loop, and most ll/sc architectures guarantee forward process after a few attempts, you almost always want to use the weak version.

The weak version also has the advantage that the compiler is free to fold the initial load into the load linked, as long as the target architecture would permit it, so you end up with more idiomatic ll, op, sc, branch sequences, rather than l, op, ll, branch, sc, branch sequences.

David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3698 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20170201/f09194e3/attachment.bin>


More information about the svn-src-head mailing list