Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/devintrts.c

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


## diffname port/devintrts.c 1999/0701
## diff -e /dev/null /n/emeliedump/1999/0701/sys/src/brazil/port/devintrts.c
0a
/*
 */
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"

enum {
	Qdir,
	Qintrts,
};

static Dirtab intrtsdir[] = {
	"intrts",	{ Qintrts, 0 },		0,	0666,
};

void (*saveintrts)(void) = nil;

/* interrupt timestamps, trap() fills intrts each interrupt */
uvlong	intrts;
static	struct {
	Lock;
	int	vno;		/* vector to save timestamps for */
	int	n;		/* number of valid timestamps in ts[] */
	uvlong	ts[128];	/* time stamps */
} tsalloc;

/* called with interrupts off by interrupt routine */
void
_saveintrts(void)
{
	lock(&tsalloc);
	if(tsalloc.n < nelem(tsalloc.ts))
		tsalloc.ts[tsalloc.n++] = m->intrts;
	unlock(&tsalloc);
}

/* read interrupt timestamps */
static long
readintrts(void *buf, int n)
{
	n /= sizeof(uvlong);
	if(n <= 0)
		return 0;
	ilock(&tsalloc);
	if(n > tsalloc.n)
		n = tsalloc.n;
	memmove(buf, tsalloc.ts, n*sizeof(uvlong));
	tsalloc.n = 0;
	iunlock(&tsalloc);
	return n*sizeof(uvlong);
}


static void
intrtsreset(void)
{
	saveintrts = _saveintrts;
}

static Chan*
intrtsattach(char* spec)
{
	return devattach('Z', spec);	/* everything good was taken */
}

int
intrtswalk(Chan* c, char* name)
{
	return devwalk(c, name, intrtsdir, nelem(intrtsdir), devgen);
}

static void
intrtsstat(Chan* c, char* dp)
{
	devstat(c, dp, intrtsdir, nelem(intrtsdir), devgen);
}

static Chan*
intrtsopen(Chan* c, int omode)
{
	return devopen(c, omode, intrtsdir, nelem(intrtsdir), devgen);
}

static void
intrtsclose(Chan*)
{
}

static long
intrtsread(Chan* c, void* a, long n, vlong)
{
	switch(c->qid.path & ~CHDIR){

	case Qdir:
		return devdirread(c, a, n, intrtsdir, nelem(intrtsdir), devgen);

	case Qintrts:
		return readintrts(a, n);
	}

	error(Eperm);
	return 0;
}

static long
intrtswrite(Chan*, void*, long, vlong)
{
	error(Eperm);
	return 0;
}

Dev intrtsdevtab = {
	'Z',
	"intrts",

	intrtsreset,
	devinit,
	intrtsattach,
	devclone,
	intrtswalk,
	intrtsstat,
	intrtsopen,
	devcreate,
	intrtsclose,
	intrtsread,
	devbread,
	intrtswrite,
	devbwrite,
	devremove,
	devwstat,
};
.
## diffname port/devintrts.c 1999/0711
## diff -e /n/emeliedump/1999/0701/sys/src/brazil/port/devintrts.c /n/emeliedump/1999/0711/sys/src/brazil/port/devintrts.c
37c
	iunlock(&tsalloc);
.
34c
	ilock(&tsalloc);
.
## diffname port/devintrts.c 2001/0527 # deleted
## diff -e /n/emeliedump/1999/0711/sys/src/brazil/port/devintrts.c /n/emeliedump/2001/0527/sys/src/9/port/devintrts.c
1,134d

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