Plan 9 from Bell Labs’s /usr/web/sources/contrib/rminnich/9.fastpath/test/testwrite.c

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


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

int mysyscall(int which);

#define	TEMP	"/n/temp"

struct info {
	uvlong now;
	int bytes;
};

struct info info [1048576];

char data[1048576];

void reader(int fd)
{
	int i = 0, j;
	int amt;
	int pid = fork();
	if (pid < 0)
		sysfatal("fork: %r");
	if (pid)
		return;
	while((amt = read(fd, data, sizeof data)) > 1) {
		cycles(&info[i].now);
		info[i].bytes = amt;	
		i++;
	}
//	for(j = 0; j < i; j++)
//		print("%d %lld %d\n", j, info[j].now, info[j].bytes);
}

void usage(void)
{
	sysfatal("usage: testwrite [-f]");
}
static char area[512];
void
main(int argc, char *argv[])
{
	char *cmd, *f;
	int fd0, fd1, ctl;
	int res;
	int i = 0, j;
	int usefast = 0;

	ARGBEGIN{
	case 'f':
		f = ARGF();
		usefast = f ? atoi(f) : 512;
		break;
	default:
		usage();
	}ARGEND
print("argc %d\n", argc);
	if(argc)
		usage();
	if(bind("#|", TEMP, MREPL) < 0)
		sysfatal("bind pipe %s: %r", TEMP);

	ctl = open(TEMP "/ctl", ORDWR);
	if(ctl < 0)
		sysfatal("open %s: %r", TEMP "/ctl");

	fd0 = open(TEMP "/data", ORDWR);
	if(fd0 < 0)
		sysfatal("open %s: %r", TEMP "/data0");

	fd1 = open(TEMP "/data1", ORDWR);
	if(fd1 < 0)
		sysfatal("open %s: %r", TEMP "/data1");

	/* fork the kid, and let it sit there counting data */
	reader(fd1);
	cmd = smprint("fastwrite 256 %d 0x%p %d", fd0, area, sizeof(area));
	print("%s\n", cmd);
	res = write(ctl, cmd, strlen(cmd));
	if (res < 0)
		sysfatal("cmd %s: %r", cmd);
	print("OK\n");

	for(i = 0; i < 512; i++) {
		write(fd0, data, 512);
		cycles(&info[i].now);
		info[i].bytes = 512;	
	}

	for(; (i < 2*512) && usefast; i++) {
		res = mysyscall(256);
		if (res < 512)
			sysfatal("cmd %s: %r", cmd);
		cycles(&info[i].now);
		info[i].bytes = 512;	
	}
	write(fd0, data, 1);
	print("Res is %d\n", res);
	unmount(nil, TEMP);
	for(j = 1; j < i; j++)
		print("%d %lld %d\n", j, info[j].now -  info[j-1].now, info[j].bytes);
	exits(nil);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.