#include <u.h>
#include <libc.h>
#include <thread.h>
enum {
Ndflt = 1<<21,
Rdflt = 1,
Tdflt = 1,
Odflt = 10,
};
int N = Ndflt;
int R = Rdflt;
int T = Tdflt;
int O = Odflt;
Channel *c, *endc;
void
txthread(void*)
{
uint i;
for(i = 0; i < N; i++)
sendul(c, i);
threadexits("");
}
void
rxthread(void*)
{
uint i, n;
n = N*T/R;
for(i = 0; i < n; i++)
recvul(c);
sendul(endc, 1);
threadexits("");
}
void
usage(void)
{
fprint(2, "usage: chantest [-O nbuf] [-R nrxproc] [-T ntxproc]\n");
exits("usage");
}
void
threadmain(int argc, char **argv)
{
int i;
uvlong t;
ARGBEGIN{
default:
usage();
case 'R':
R = atoi(EARGF(usage()));
break;
case 'T':
T = atoi(EARGF(usage()));
break;
case 'O':
O = atoi(EARGF(usage()));
break;
}ARGEND
if(argc > 0)
usage();
t = -nsec();
c = chancreate(sizeof(ulong), O);
endc = chancreate(sizeof(ulong), 0);
for(i = 0; i < R; i++)
proccreate(rxthread, nil, 4*1024);
for(i = 0; i < T; i++)
proccreate(txthread, (void*)(uintptr)i, 4*1024);
for(i = 0; i < R; i++)
recvul(endc);
t += nsec();
print("%lld\n", t);
threadexits("");
}
|