Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/locktest/tastest.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


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

extern int xadd(int*, int);

enum {
	Ndflt	= 1<<21,
	Rdflt	= 1,
	Odflt	= 10,
};

int	N = Ndflt;
int	R = Rdflt;
int	O = Odflt;

Channel *endc;
uchar pad[64];
int valtas;
uchar pad[64];
int val;
uchar pad[64];
long aincval;
uchar pad[64];
int xaddval;

void
tasthread(void*)
{
	uint i;

	for(i = 0; i < N; i++){
		_tas(&valtas);
		val++;
		valtas = 0;
	}
	sendul(endc, 1);
	threadexits("");
}

void
aincthread(void*)
{
	uint i;

	for(i = 0; i < N; i++){
		ainc(&aincval);
	}
	sendul(endc, 1);
	threadexits("");
}

void
xaddthread(void*)
{
	uint i;

	for(i = 0; i < N; i++){
		xadd(&xaddval, 1);
	}
	sendul(endc, 1);
	threadexits("");
}

void
usage(void)
{
	fprint(2, "usage: tastest [-R tasproc]\n");
	exits("usage");
}

void
threadmain(int argc, char **argv)
{
	int i;
	uvlong t;

	ARGBEGIN{
	default:
		usage();
	case 'R':
		R = atoi(EARGF(usage()));
		break;
	}ARGEND
	if(argc > 0)
		usage();

	endc = chancreate(sizeof(ulong), 0);

	t = -nsec();
	for(i = 0; i < R; i++)
		proccreate(tasthread, nil, 4*1024);
	for(i = 0; i < R; i++)
		recvul(endc);
	t += nsec();
	print("%lld tas\n", t);

	t = -nsec();
	for(i = 0; i < R; i++)
		proccreate(aincthread, nil, 4*1024);
	for(i = 0; i < R; i++)
		recvul(endc);
	t += nsec();
	print("%lld ainc\n", t);

	t = -nsec();
	for(i = 0; i < R; i++)
		proccreate(xaddthread, nil, 4*1024);
	for(i = 0; i < R; i++)
		recvul(endc);
	t += nsec();
	print("%lld xadd\n", t);

	threadexits("");
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].