9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: [9fans] io patterns
Date: Fri,  7 Oct 2011 03:47:07 -0400	[thread overview]
Message-ID: <238f1d9f84af5026a757c92fef32f717@brasstown.quanstro.net> (raw)
In-Reply-To: <df007707aa25b94092ccd79c06d75e79@hamnavoe.com>

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

to beat a dead horse to death, i spent a few minutes writing a little
test program inspired by the little programming language in igbe for
bit-banging the atmel part.  a minimal primer
o	set offset (in bytes)
{}	set up timing
: n ;	loop
r/w	read/write
s	seek {n sectors, or 'r' random}
z	set sector size

so this little program times 1000 sectors of sequential read io
	{:1000 rs1 ;}
and this one skips sectors

so this little program times 1000 sectors of sequential read io
	{:1000 rs1 ;}
and this one would read every other sector
	{:1000 rs2 ;}

new# iop -p '{:1000 rs2 ;}' data
0.061
16220.14 iops
new# iop -p '{:1000 rs2 ;}' data
0.299
3340.96 iops

i think the 4k sector test would then be

	for(i in 1 2 3 4) iop -p z4096o$i^'{:1000 rs1 ;}' data

- erik

[-- Attachment #2: iop.c --]
[-- Type: text/plain, Size: 2749 bytes --]

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

enum {
	Nanoi	= 1000000000,	/* 1/nano */
	Microi	= 1000000,
};

void
ioloop(int fd, uvlong bytes, char *prog)
{
	char *buf, *p, *loop;
	int l;
	uint ss, iops;
	uvlong byte0, maxlba, lba, t, x;

	/* silence compiler */
	iops = 0;
	l = 0;
	t = 0;

	loop = nil;
	byte0 = 0;
	lba = 0;
	ss = 512;
	maxlba = (bytes - byte0) / ss;
	buf = malloc(ss);
	if(buf == nil)
		sysfatal("malloc");
	srand(nsec());
	for(p = prog;; ){
		switch(*p){
		default:
			sysfatal("bad char %c in prog %s\n", *p, prog);
		case 0:
			goto end;
		case ' ':
			break;
		case ':':							/* loop */
			l = strtol(p+1, &loop, 0);
			p = loop;
			continue;
		case ';':							/* end */
			if(loop == nil)
				sysfatal("malformd loop: extra ';'");
			if(--l > 0){
				p = loop;
				continue;
			}
			loop = nil;
			break;
		case '{':
			iops = 0;
			t = - nsec();
			break;
		case '}':
			t += nsec();
			print("%lld.%03lld\n", t/Nanoi, (t%Nanoi)/Microi);
			x = (uvlong)iops*(uvlong)Nanoi*100;
			x /= t;
			print("%lld.%02lld iops\n", x/100, (x%100));
			break;
		case 'o':
			byte0 = strtoull(p, &p, 0);
			maxlba = (bytes - byte0) / ss;
			continue;
		case 'z':
			ss = strtoul(p, &p, 0);
			if(ss == 0)
				sysfatal("sector size zero");
			maxlba = (bytes - byte0) / ss;
			buf = realloc(buf, ss);
			if(buf == nil)
				sysfatal("realloc: %r");
			break;
		case 'r':							/* read */
			pread(fd, buf, ss, byte0 + lba*ss);
			iops++;
			break;
		case 'w':							/* write */
			pwrite(fd, buf, ss, byte0 + lba*ss);
			iops++;
			break;
		case 's':							/* seek */
			switch(p[1]){
			default:
				sysfatal("seek requires argument\n");
			case 'r':
				lba = frand()*maxlba;	/* awful.  no vlnrand() */
				p++;
				break;
			case 's':
				p++;
			case '0': case '1': case '2': case '3': case '4':
			case '5': case '6': case '7': case '8': case '9':
				p++;
				lba += strtol(p, &p, 0);
				break;
			}
			continue;
		}
		p++;
	}
end:
	free(buf);
}

void
usage(void)
{
	fprint(2, "usage: iop [-p prog] ... [file ...]\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	char *prog[25];
	int i, j, nprog, fd;
	uvlong bytes;
	Dir *d;

	nprog = 0;

	ARGBEGIN{
	case 'p':
		if(nprog == nelem(prog))
			sysfatal("too many programs");
		prog[nprog++] = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND;

	for(i = 0; i < argc; i++){
		d = dirstat(argv[i]);
		if(d == nil)
			sysfatal("dirstat: %r");
		bytes = d->length;
		free(d);

		fd = open(argv[i], ORDWR);
		if(fd == -1)
			sysfatal("open: %r");
		for(j = 0; j < nprog; j++)
			ioloop(fd, bytes, prog[i]);
		close(fd);
	}
	exits("");
}

  parent reply	other threads:[~2011-10-07  7:47 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-24  0:20 [9fans] copying fossil filesystem to a bigger disk slash
2011-09-24  8:07 ` David du Colombier
2011-09-24  8:34   ` Steve Simon
2011-09-29 23:54   ` slash
2011-09-30  8:31     ` Richard Miller
2011-09-30  8:54       ` Richard Miller
2011-09-30  9:44         ` Charles Forsyth
2011-09-30 14:06           ` erik quanstrom
2011-09-30 14:16           ` Ethan Grammatikidis
2011-09-30 14:00         ` erik quanstrom
2011-10-01 10:36           ` slash
     [not found]           ` <CAEaiYYzXCfB2KbnDzBHTXytrfQqGUCepRg5Aj-c14ZoEz5hHaw@mail.gmail.c>
2011-10-01 13:51             ` erik quanstrom
2011-10-01 15:27               ` slash
2011-10-01 16:14             ` erik quanstrom
2011-10-01 16:23               ` erik quanstrom
2011-10-04 11:28                 ` Richard Miller
2011-10-04 11:52                   ` Charles Forsyth
2011-10-04 12:01                     ` Richard Miller
2011-10-04 12:05                       ` erik quanstrom
2011-10-04 12:09                       ` Charles Forsyth
2011-10-04 12:13                         ` Charles Forsyth
2011-10-04 12:19                           ` dexen deVries
2011-10-04 12:27                           ` Richard Miller
     [not found]                       ` <CAOw7k5i3i+w_=pUuFjUCnxH1Tp5U0vh3v7wFUoBddfML9xG+ag@mail.gmail.c>
2011-10-04 12:17                         ` erik quanstrom
2011-10-04 12:30                           ` Charles Forsyth
     [not found]                           ` <CAOw7k5hGWG16a5fTjtXBEBd2-gt=XnhjEJKFNjdPrB46_6=dBg@mail.gmail.c>
2011-10-04 12:34                             ` erik quanstrom
2011-10-04 12:05                   ` erik quanstrom
2011-10-04 12:15                     ` Richard Miller
2011-10-04 12:17                       ` erik quanstrom
2011-10-04 12:17                   ` erik quanstrom
2011-10-04 12:33                     ` Richard Miller
2011-10-04 12:52                       ` dexen deVries
2011-10-04 13:05                         ` dexen deVries
2011-10-04 14:13                       ` erik quanstrom
2011-10-04 15:56                         ` Richard Miller
2011-10-04 16:00                           ` erik quanstrom
2011-10-04 16:42                             ` Richard Miller
2011-10-04 16:45                               ` erik quanstrom
2011-10-04 17:52                                 ` Charles Forsyth
2011-10-04 18:05                                   ` dexen deVries
2011-10-04 18:24                                 ` Bakul Shah
2011-10-04 18:29                                   ` erik quanstrom
2011-10-03 23:07               ` slash
2011-10-06  7:35                 ` Peter A. Cejchan
2011-10-07 10:49                   ` slash
2011-10-07 11:15                     ` Peter A. Cejchan
2011-10-07 13:03                       ` Steve Simon
2011-10-10 10:32                         ` Peter A. Cejchan
     [not found]                   ` <CAEaiYYya5eq3CoVbbZGqPf91_kMEcbkCQ_8WEL4yakFdenek5g@mail.gmail.c>
2011-10-07 13:17                     ` erik quanstrom
2011-10-10  2:32                       ` slash
     [not found]                       ` <CAEaiYYy36ydHfw=Tg2YC9x9gEW7=MAHF2C6-UVbgr36G-qv=rA@mail.gmail.c>
2011-10-10  3:11                         ` erik quanstrom
2011-10-10 10:15                           ` slash
     [not found]                         ` <d0c02b8a1e36c9329902a1183192d732@chula.quanstro.>
     [not found]                           ` <CAEaiYYxoHLgMZddGZ4gCPvW-GuqwRYzytXgfezoi+vjUgxx9tg@mail.gmail.c>
2011-10-10 13:17                             ` erik quanstrom
2011-10-11  8:51                               ` slash
2011-10-11  8:55                                 ` slash
2011-10-11 15:01                                 ` slash
2011-10-11 15:36                                   ` David du Colombier
2011-10-12 19:24                                     ` slash
2011-10-13  7:07                   ` Peter A. Cejchan
     [not found]               ` <CAEaiYYxsUzf70Ffhd3hzsBZcMb5=2yhfSCv5-nJ+_27wYbJKig@mail.gmail.c>
2011-10-03 23:10                 ` erik quanstrom
2011-10-04  0:02                 ` erik quanstrom
2011-10-04  7:58                   ` dexen deVries
2011-10-04  9:52               ` Richard Miller
2011-10-04  9:34           ` Richard Miller
2011-10-07  7:47       ` erik quanstrom [this message]
2011-09-24  8:30 ` Steve Simon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=238f1d9f84af5026a757c92fef32f717@brasstown.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).