9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] ainc() 386/amd64 differences
@ 2014-05-14 20:34 erik quanstrom
  2014-05-14 20:57 ` Charles Forsyth
  0 siblings, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2014-05-14 20:34 UTC (permalink / raw)
  To: 9fans

for 386, libc has this definition for ainc

TEXT ainc(SB), $0	/* int ainc(int *); */
	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

the amd64 kernel has had this definition (the pc kernel doesn't define ainc)

TEXT ainc(SB), 1, $-4
	MOVL	$1, AX
	LOCK; XADDL AX, (RARG)
	ADDL	$1, AX				/* overflow if -ve or 0 */
	JGT	_return
_trap:
	XORQ	BX, BX
	MOVQ	(BX), BX			/* over under sideways down */
_return:
	RET

these are substantially different in two ways.
- the first is not wait free.  the second may be wait free.
- the second is geared toward reference counting, and will
trap instead of wrapping.  it can't be used for generating
a unique sequence.

i'd like to see the amd64 kernel version replace incref, and
this version of ainc

TEXT ainc(SB), 1, $-4
TEXT ainc32(SB), 1, $-4
	MOVL	$1, AX
	LOCK; XADDL AX, (RARG)
	INCL	AX
	RET

what does the list think?

- erik



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] ainc() 386/amd64 differences
  2014-05-14 20:34 [9fans] ainc() 386/amd64 differences erik quanstrom
@ 2014-05-14 20:57 ` Charles Forsyth
  2014-05-14 21:26   ` erik quanstrom
  0 siblings, 1 reply; 4+ messages in thread
From: Charles Forsyth @ 2014-05-14 20:57 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

% cat ../port/ref.c
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"

int
incref(Ref *r)
{
int x;

x = ainc(&r->ref);
if(x <= 0)
panic("incref pc=%#p", getcallerpc(&r));
return x;
}

int
decref(Ref *r)
{
int x;

x = adec(&r->ref);
if(x < 0)
panic("decref pc=%#p", getcallerpc(&r));
return x;
}

[-- Attachment #2: Type: text/html, Size: 2116 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] ainc() 386/amd64 differences
  2014-05-14 20:57 ` Charles Forsyth
@ 2014-05-14 21:26   ` erik quanstrom
  2014-05-14 21:46     ` erik quanstrom
  0 siblings, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2014-05-14 21:26 UTC (permalink / raw)
  To: 9fans

> int
> incref(Ref *r)
> {
> int x;
>
> x = ainc(&r->ref);
> if(x <= 0)
> panic("incref pc=%#p", getcallerpc(&r));
> return x;
> }

ah, yes.  i'd not remembered this nice implementation.

then your ainc is guard-free?  and your Ref is struct Ref {int ref;}?
also, did you decide that any reuse of the ref lock is already buggy and needs
no further review?  that's the bit i got bogged down on.

- erik



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] ainc() 386/amd64 differences
  2014-05-14 21:26   ` erik quanstrom
@ 2014-05-14 21:46     ` erik quanstrom
  0 siblings, 0 replies; 4+ messages in thread
From: erik quanstrom @ 2014-05-14 21:46 UTC (permalink / raw)
  To: 9fans

On Wed May 14 17:27:58 EDT 2014, quanstro@quanstro.net wrote:
> > int
> > incref(Ref *r)
> > {
> > int x;
> >
> > x = ainc(&r->ref);
> > if(x <= 0)
> > panic("incref pc=%#p", getcallerpc(&r));
> > return x;
> > }
>
> ah, yes.  i'd not remembered this nice implementation.
>
> then your ainc is guard-free?  and your Ref is struct Ref {int ref;}?
> also, did you decide that any reuse of the ref lock is already buggy and needs
> no further review?  that's the bit i got bogged down on.

i've rebooted my kernel with this change, and it appears to be solid.
still a bit concerned about additional consistency forced by the prior
incref.

- erik



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-14 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-14 20:34 [9fans] ainc() 386/amd64 differences erik quanstrom
2014-05-14 20:57 ` Charles Forsyth
2014-05-14 21:26   ` erik quanstrom
2014-05-14 21:46     ` erik quanstrom

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).