9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@coraid.com>
To: 9fans@9fans.net
Subject: Re: [9fans] etherigbe.c using _xinc?
Date: Tue,  8 Dec 2009 15:00:46 -0500	[thread overview]
Message-ID: <7a13edea51b085e17fc02c0e8d0b6a62@coraid.com> (raw)
In-Reply-To: <dd6fe68a0912081135g5f051f33u25af76c81e87dc66@mail.gmail.com>

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

> do you have numbers to back up this claim?
>
> you are claiming that the locked XCHGL
> in tas (pc/l.s) called from lock (port/taslock.c)
> called from incref (port/chan.c) is "much faster"
> than the locked INCL in _xinc (pc/l.s).
> it seems to me that a locked memory bus
> is a locked memory bus.

yes, i do.  xinc on most modern intel is a real
loss.  and a moderate loss on amd.  my atom 330
is an exception.

intel core i7 2.4ghz
loop	0 nsec/call
loopxinc	20 nsec/call
looplock	11 nsec/call

intel 5000 1.6ghz
loop	0 nsec/call
loopxinc	44 nsec/call
looplock	25 nsec/call

intel atom 330 1.6ghz (exception!)
loop	2 nsec/call
loopxinc	14 nsec/call
looplock	22 nsec/call

amd k10 2.0ghz
loop	2 nsec/call
loopxinc	30 nsec/call
looplock	20 nsec/call

intel p4 xeon 3.0ghz

loop	1 nsec/call
loopxinc	76 nsec/call
looplock	42 nsec/call

- erik

[-- Attachment #2: xinc.s --]
[-- Type: text/plain, Size: 286 bytes --]

TEXT _xinc(SB), 1, $0				/* void _xinc(long*); */
	MOVL	l+0(FP), AX
	LOCK;	INCL 0(AX)
	RET

TEXT _xdec(SB), 1, $0				/* long _xdec(long*); */
	MOVL	l+0(FP), BX
	XORL	AX, AX
	LOCK;	DECL 0(BX)
	JLT	_xdeclt
	JGT	_xdecgt
	RET
_xdecgt:
	INCL	AX
	RET
_xdeclt:
	DECL	AX
	RET

[-- Attachment #3: timing.c --]
[-- Type: text/plain, Size: 699 bytes --]

#include <u.h>
#include <libc.h>

void	_xinc(uint*);
void	_xdec(uint*);

enum {
	N	= 1<<30,
};

void
loop(void)
{
	uint i;

	for(i = 0; i < N; i++)
		;
}

void
loopxinc(void)
{
	uint i, x;

	for(i = 0; i < N; i++){
		_xinc(&x);
		_xdec(&x);
	}
}

void
looplock(void)
{
	uint i;
	static Lock l;

	for(i = 0; i < N; i++){
		lock(&l);
		unlock(&l);
	}
}

void
timing(char *s, void (*f)(void))
{
	uvlong t[2];

	t[0] = nsec();
	f();
	t[1] = nsec();
	fprint(2, "%s\t%llud nsec/call\n", s, (t[1] - t[0])/(uvlong)N);
}

void
main(void)
{
	nsec();
	timing("loop", loop);
	timing("loopxinc", loopxinc);
	timing("looplock", looplock);
	exits("");
}

  parent reply	other threads:[~2009-12-08 20:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08 16:25 Venkatesh Srinivas
2009-12-08 16:36 ` erik quanstrom
2009-12-08 19:35   ` Russ Cox
2009-12-08 19:52     ` John Floren
2009-12-08 20:00     ` erik quanstrom [this message]
2009-12-08 23:52       ` Russ Cox
     [not found] <<dd6fe68a0912081552s30851f04n109e56479bb423cb@mail.gmail.com>
2009-12-09  0:32 ` erik quanstrom
2009-12-09  1:05   ` Russ Cox
     [not found] <<dd6fe68a0912081705q6fad8a6cl20ca648397070dae@mail.gmail.com>
2009-12-09  2:04 ` 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=7a13edea51b085e17fc02c0e8d0b6a62@coraid.com \
    --to=quanstro@coraid.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).