9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] the Thread War
@ 2004-07-12 15:55 ron minnich
  2004-07-12 16:49 ` andrey mirtchovski
  0 siblings, 1 reply; 8+ messages in thread
From: ron minnich @ 2004-07-12 15:55 UTC (permalink / raw)
  To: 9fans


I hate to revive this but what the heck.

http://pl.atyp.us/misc/threads.tar.bz2

describes some thread microbenchmarks.

These two programs test context switch rates for threads. Usual
disclaimers apply about stupidity of microbenchmarks. But I'm curious to
see what those of you with 2.4 Ghz P4 boxes get.

No need to cc: Linus on this discussion.

ron



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

* Re: [9fans] the Thread War
  2004-07-12 15:55 [9fans] the Thread War ron minnich
@ 2004-07-12 16:49 ` andrey mirtchovski
  2004-07-12 19:31   ` andrey mirtchovski
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: andrey mirtchovski @ 2004-07-12 16:49 UTC (permalink / raw)
  To: 9fans

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

> http://pl.atyp.us/misc/threads.tar.bz2

attached is the pthread.c program as it'll look (approximately) if
written in Plan 9.  it uses two channels to send between parent and
child.

	8c -Fvw 9thread.c; 8l -o 9thread 9thread.8

the results below were obtained on a 2.6ghz P4 (note the big
difference when compared to the 2.0Ghz linux below.  do i have a bug
in my code?):

plan9% for (i in `{seq 1 10}) { 9thread }
did 1000000 iterations in 1.998280 seconds
500430 iterations/second
0 misses
did 1000000 iterations in 1.998884 seconds
500279 iterations/second
0 misses
did 1000000 iterations in 1.997603 seconds
500600 iterations/second
0 misses
did 1000000 iterations in 1.997107 seconds
500724 iterations/second
0 misses
did 1000000 iterations in 2.002966 seconds
499260 iterations/second
0 misses
did 1000000 iterations in 2.000637 seconds
499841 iterations/second
0 misses
did 1000000 iterations in 1.997824 seconds
500545 iterations/second
0 misses
did 1000000 iterations in 2.016934 seconds
495802 iterations/second
0 misses
did 1000000 iterations in 2.003826 seconds
499045 iterations/second
0 misses
did 1000000 iterations in 2.017029 seconds
495779 iterations/second
0 misses
plan9%

i don't have identical hardware running linux/bsd unfortunately.  on
my 2.0ghz P4 I get:

mirtchov@fbsd$ for i in `seq 1 10`; do ./pthread; done
did 1000000 iterations in 5.1 seconds
195115 iterations/second
0 misses
did 1000000 iterations in 5.2 seconds
193529 iterations/second
0 misses
did 1000000 iterations in 5.2 seconds
192888 iterations/second
0 misses
did 1000000 iterations in 5.1 seconds
195341 iterations/second
0 misses
did 1000000 iterations in 5.2 seconds
193341 iterations/second
0 misses
did 1000000 iterations in 5.2 seconds
194050 iterations/second
0 misses
did 1000000 iterations in 5.1 seconds
195621 iterations/second
0 misses
did 1000000 iterations in 5.1 seconds
196538 iterations/second
0 misses
did 1000000 iterations in 5.1 seconds
194644 iterations/second
0 misses
did 1000000 iterations in 5.1 seconds
194906 iterations/second
0 misses
mirtchov@fbsd$


andrey

[-- Attachment #2: 9thread.c --]
[-- Type: text/plain, Size: 1127 bytes --]

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

Channel 		*cchan, *pchan;
ulong		iterations	= 0;
ulong		misses	= 0;
enum { Parent, Child, };
int 			state		= Parent;

void
child(void *unused)
{
	char data = '1';

	USED(unused);
	for (;;) {
		recv(cchan, &data);
		if (state == Parent) {
			++iterations;
			state = Child;
		}
		else {
			++misses;
		}
		send(pchan, &data);
	}
}

void
threadmain(int argc, char **argv)
{
	vlong 	tbegin, tend;
	double 	diff;
	char 		data = '1';

	USED(argc, argv);

	cchan = chancreate(sizeof(char), 1);
	pchan = chancreate(sizeof(char), 1);

	threadcreate(child, nil, 1024);	/* could be even smaller? */

	tbegin = nsec();
	while (iterations < 1000000) {
		send(cchan, &data);
		recv(pchan, &data);
		if (state == Child) {
			++iterations;
			state = Parent;
		}
		else {
			++misses;
		}
	}
	tend = nsec();

	diff = (tend - tbegin)/1000000000.0;

	print("did %ld iterations in %f seconds\n",iterations,diff);
	print("%.0f iterations/second\n",(float)iterations/diff);
	print("%ld misses\n",misses);

	threadexitsall(nil);
}

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

* Re: [9fans] the Thread War
  2004-07-12 16:49 ` andrey mirtchovski
@ 2004-07-12 19:31   ` andrey mirtchovski
  2004-07-12 19:39   ` boyd, rounin
  2004-07-12 19:50   ` Micah Stetson
  2 siblings, 0 replies; 8+ messages in thread
From: andrey mirtchovski @ 2004-07-12 19:31 UTC (permalink / raw)
  To: 9fans

> did 1000000 iterations in 1.998280 seconds
> 500430 iterations/second
> 0 misses

with a simple change one can measure the same ping-pong between two
processes, thus involving context switches and a few syscalls (btw, using
unbuffered channels makes no difference):

plan9% diff 9thread.c 9threadproc.c
42c42
<       threadcreate(child, nil, 1024); /* could be even smaller? */
---
>       proccreate(child, nil, 1024);   /* could be even smaller? */
plan9%
plan9% for (i in `{seq 1 10}) 9threadproc
did 1000000 iterations in 7.200755 seconds
138874 iterations/second
0 misses
did 1000000 iterations in 7.235651 seconds
138205 iterations/second
0 misses
did 1000000 iterations in 7.181722 seconds
139242 iterations/second
0 misses
did 1000000 iterations in 7.272081 seconds
137512 iterations/second
0 misses
did 1000000 iterations in 7.249308 seconds
137944 iterations/second
0 misses
did 1000000 iterations in 7.202701 seconds
138837 iterations/second
0 misses
did 1000000 iterations in 7.173075 seconds
139410 iterations/second
0 misses
did 1000000 iterations in 7.256470 seconds
137808 iterations/second
0 misses
did 1000000 iterations in 7.523487 seconds
132917 iterations/second
0 misses
did 1000000 iterations in 7.225779 seconds
138393 iterations/second
0 misses
plan9%



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

* Re: [9fans] the Thread War
  2004-07-12 16:49 ` andrey mirtchovski
  2004-07-12 19:31   ` andrey mirtchovski
@ 2004-07-12 19:39   ` boyd, rounin
  2004-07-12 19:50   ` Micah Stetson
  2 siblings, 0 replies; 8+ messages in thread
From: boyd, rounin @ 2004-07-12 19:39 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

crapHat (sic) implements a thread as a proc;  all procs are threads.

this should mean that, unless context switches are blindingly
fast (which i doubt), they should be slower than user mode
threads.



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

* Re: [9fans] the Thread War
  2004-07-12 16:49 ` andrey mirtchovski
  2004-07-12 19:31   ` andrey mirtchovski
  2004-07-12 19:39   ` boyd, rounin
@ 2004-07-12 19:50   ` Micah Stetson
  2004-07-12 20:07     ` andrey mirtchovski
  2004-07-12 20:50     ` ron minnich
  2 siblings, 2 replies; 8+ messages in thread
From: Micah Stetson @ 2004-07-12 19:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> mirtchov@fbsd$ for i in `seq 1 10`; do ./pthread; done
> did 1000000 iterations in 5.1 seconds
> 195115 iterations/second
> 0 misses

Something's weird about those Linux results, maybe it's
the hostname.  Still, Linux on my 900MHz Thinkpad T22
manages about 270000 iterations/second.  I wonder what's
making it go so slow for you.  Could it be a laptop in
power-saving mode?

My Plan 9 results on the same hardware are comparable to
yours, a bit over 318000.

Micah



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

* Re: [9fans] the Thread War
  2004-07-12 19:50   ` Micah Stetson
@ 2004-07-12 20:07     ` andrey mirtchovski
  2004-07-12 20:50     ` ron minnich
  1 sibling, 0 replies; 8+ messages in thread
From: andrey mirtchovski @ 2004-07-12 20:07 UTC (permalink / raw)
  To: 9fans

> Something's weird about those Linux results, maybe it's
> the hostname.  Still, Linux on my 900MHz Thinkpad T22
> manages about 270000 iterations/second.  I wonder what's
> making it go so slow for you.  Could it be a laptop in
> power-saving mode?

the host name is a leftover from happier times, when universities
weren't linux-only :)

no, it's not a laptop but it is running the 2.6 kernel (the only
machine i have with this):

	model name      : Intel(R) Pentium(R) 4 CPU 2.00GHz
	stepping        : 4
	cpu MHz         : 1994.092
	cache size      : 512 KB

you're right though -- i get much better results on everything else i
try this on.

andrey



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

* Re: [9fans] the Thread War
  2004-07-12 19:50   ` Micah Stetson
  2004-07-12 20:07     ` andrey mirtchovski
@ 2004-07-12 20:50     ` ron minnich
  2004-07-12 21:45       ` andrey mirtchovski
  1 sibling, 1 reply; 8+ messages in thread
From: ron minnich @ 2004-07-12 20:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, 12 Jul 2004, Micah Stetson wrote:

> Something's weird about those Linux results, maybe it's
> the hostname.  Still, Linux on my 900MHz Thinkpad T22
> manages about 270000 iterations/second.  I wonder what's
> making it go so slow for you.  Could it be a laptop in
> power-saving mode?
>
> My Plan 9 results on the same hardware are comparable to
> yours, a bit over 318000.

well, does this constitute the measurement presotto said we could do, back
during the 'my TLB flushes are smaller than yours' flame war, and if so,
what's it tell us? Anything?

ron



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

* Re: [9fans] the Thread War
  2004-07-12 20:50     ` ron minnich
@ 2004-07-12 21:45       ` andrey mirtchovski
  0 siblings, 0 replies; 8+ messages in thread
From: andrey mirtchovski @ 2004-07-12 21:45 UTC (permalink / raw)
  To: 9fans


> well, does this constitute the measurement presotto said we could do, back
> during the 'my TLB flushes are smaller than yours' flame war, and if so,
> what's it tell us? Anything?

it gets even more interesting if you compile the 9thread.c code using
plan9port (you'll need to change the USED(argc, argv); into two
separate, single-argument USED's).

this is on the same 2.6.6 linux machine as previously (with the
confused prompt):

	mirtchov@fbsd$ for i in 1 2 3 4; do 9thread; done
	did 1000000 iterations in 1.976096 seconds
	506048 iterations/second
	0 misses
	did 1000000 iterations in 2.006277 seconds
	498436 iterations/second
	0 misses
	did 1000000 iterations in 1.968269 seconds
	508061 iterations/second
	0 misses
	did 1000000 iterations in 2.070409 seconds
	482996 iterations/second
	0 misses

so try it on the same box you run the original pthread program and see
what you get :)

andrey



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

end of thread, other threads:[~2004-07-12 21:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-12 15:55 [9fans] the Thread War ron minnich
2004-07-12 16:49 ` andrey mirtchovski
2004-07-12 19:31   ` andrey mirtchovski
2004-07-12 19:39   ` boyd, rounin
2004-07-12 19:50   ` Micah Stetson
2004-07-12 20:07     ` andrey mirtchovski
2004-07-12 20:50     ` ron minnich
2004-07-12 21:45       ` andrey mirtchovski

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