9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Bakul Shah <bakul@bitblocks.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] _xinc vs ainc
Date: Sat,  7 May 2011 12:33:50 -0700	[thread overview]
Message-ID: <30A0D4B5-1AAB-4D95-9B9F-FD09CB796E6D@bitblocks.com> (raw)
In-Reply-To: <f7a852a029ef39ffa039b8ff51293722@brasstown.quanstro.net>

On May 7, 2011, at 6:05 AM, erik quanstrom <quanstro@quanstro.net>
wrote:

> i'm confused by the recent change to the thread library.
> the old code was simply to do a locked incl.  the new code
> does a locked exchange /within a loop/ until it's seen that
> nobody else has updated the value at the same time, thus
> insuring that the value has indeed been updated.
>
> since the expensive operation is the MESI(F) negotiation
> behind the scenes to get exclusive access to the cacheline,
> i don't understand the motiviation is for replacing _xinc
> with ainc.  since ainc can loop on an expensive lock instruction.
>
> that is, i think the old version was wait free, and the new version
> is not.
>
> can someone explain what i'm missing here?

> thanks!
>
> - erik
>
> ----
>
> TEXT    _xinc(SB),$0    /* void _xinc(long *); */
>
>    MOVL    l+0(FP),AX
>    LOCK
>    INCL    0(AX)
>    RET
>
> ----
>
> TEXT ainc(SB), $0    /* long ainc(long *); */
>    MOVL    addr+0(FP), BX
> ainclp:
>    MOVL    (BX), AX
>    MOVL    AX, CX
>    INCL    CX
>    LOCK
>    BYTE    $0x0F; BYTE $0xB1; BYTE $0x0B    /* CMPXCHGL CX, (BX) */
>    JNZ    ainclp
>    MOVL    CX, AX
>    RET
>

Just guessing. May be the new code allows more concurrency? If the
value is not in the processor cache, will the old code block other
processors for much longer? The new code forces caching with the first
read so may be high likelyhood cmpxchg will finish faster. I haven't
studied x86 cache behavior so this guess could be completely wrong.
Suggest asking on comp.arch where people like Andy Glew can give you a
definitive answer.



  reply	other threads:[~2011-05-07 19:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-07 13:05 erik quanstrom
2011-05-07 19:33 ` Bakul Shah [this message]
2011-05-07 22:47   ` erik quanstrom
2011-05-07 23:10     ` Bakul Shah
2011-05-08  0:25       ` erik quanstrom
2011-05-08  1:24         ` Bakul Shah
2011-05-08  2:44           ` Venkatesh Srinivas
2011-05-08  6:00 ` ron minnich
2011-05-08 13:14   ` erik quanstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30A0D4B5-1AAB-4D95-9B9F-FD09CB796E6D@bitblocks.com \
    --to=bakul@bitblocks.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).