9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* more microbenchmarks, threads
@ 1995-12-09  5:22 Scott
  0 siblings, 0 replies; only message in thread
From: Scott @ 1995-12-09  5:22 UTC (permalink / raw)


Over on comp.programming.threads there's been some discussion of thread
performance under solaris based on some small programs that exercise
thread creation.  (See Steve Rogers' <steve@ct.picker.com>
Message-ID:  <1995Dec6.125003.2562@picker.com>, and subsequent.)

Inspired to comparare, I ran one of those programs on a Sparcstation 2
with Solaris.  Then I translated it---accurately I hope, although
rendezvous() isn't quite the same as a semaphore---for Plan 9, and ran
it on another SS2.  The results were about the same, except that under
Plan 9 real time was much greater than user+system.  Is the time
getting lost during scheduling, or something like that?

term% time k.out
COUNTER: 10000
0.20u 9.78s 43.26r 	 k.out

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

#define ITERATIONS 1000
#define MAX_THREAD 10

static Lock mutex;
static int counter = 0;

void thread_func(void)
{
    lock(&mutex);
    counter++;
    if ((counter % MAX_THREAD) == 0) {
        rendezvous(0, 1); 
    }
    unlock(&mutex);
}

int thr_create (void (*func)(void))
{
	int pid = rfork(RFPROC|RFMEM|RFNOWAIT);
	switch (pid) {
	case -1:
		fprint(2, "rfork failed: %r\n");
		exits("rfork");
	case 0:
		(*func)();
		exits(0);
	default:		
		return pid;
	}
}

void main(int argc, char *argv[])
{
	int ii, jj;
	int pid;

	counter = 0;
	lockinit();
	for ( ii = 0; ii < ITERATIONS; ii++ ) {
		for ( jj = 0; jj < MAX_THREAD; jj++ ) {
			pid = thr_create(thread_func);
		}
		rendezvous(0, 0);
	}
	fprint(2, "COUNTER: %d\n", counter);
	exits(0);
}







^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-12-09  5:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-12-09  5:22 more microbenchmarks, threads Scott

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