示例#1
0
文件: mtree.c 项目: taysom/tau
struct iterator_mtree *iterator_mtree(struct mtree *mt)
{
	struct iterator_mtree *imt;
	
	imt = ezalloc(sizeof(*imt));
	imt->mt = mt;
	imt->val.d = imt->data;
	return imt;
}
示例#2
0
文件: main.c 项目: taysom/tau
static struct lump randlump(void)
{
    struct lump a;

    a.size = twister_urand(13) + 3;
    a.d = ezalloc(a.size);
    gen_name(a.d, a.size);
    return a;
}
示例#3
0
文件: radix.c 项目: taysom/tau
void init_tree (tree_s *t)
{
	node_s	*node;

	++Nodes;
	node = ezalloc(sizeof(node_s)); //this isn't needed
	t->t_root.b_type = NODE;
	t->t_root.b_node = node;
}
示例#4
0
文件: mtree.c 项目: taysom/tau
struct mtree *open_mtree(const char *path)
{
	struct mtree *mt;

	mt = ezalloc(sizeof(*mt));
	mt->dev = open_dev(path, NUM_MTREE_BLOCKS);
	mt->seqnum = 1;
	mt->next_block = 1;
	return mt;
}
示例#5
0
文件: kbicho.c 项目: taysom/tau
void kbicho (void *msg)
{
	bicho_msg_s	*m = msg;
	kbicho_s	*b;

	b = ezalloc(sizeof(*b));
	b->kb_key = m->q.q_passed_key;
	who_am_i(b);
	enq_dq( &Kbicho, b, kb_link);
}
示例#6
0
文件: hints.c 项目: aahud/harvey
void
statsinit(void)
{
	static Biobuf *b = nil;
	static int64_t filelen = 0;
	int64_t newlen;
	int iq, n, i, nstats = 0;
	uint8_t *s, buf[3+HINTmax*3];  /* iq, n, (url,prob)... */
	Hint *arena, *h;
	char *file;
	static void *oldarena = nil;

	file = "/sys/log/httpd/pathstat";
	if(b == nil){
		if(filelen == -1)
			return; /* if failed first time */
		b = Bopen(file, OREAD); /* first time */
		if(b == nil){
			syslog(0, HTTPLOG, "no %s, abandon prefetch hints", file);
			filelen = -1;
			return;
		}
	}
	newlen = Bfilelen(b); /* side effect: rewinds b */
	if(newlen == filelen || Bage(b)<300)
		return;
	filelen = newlen;
	if(oldarena){
		free(oldarena);
		memset(nhint,0,sizeof nhint);
	}
	arena = (Hint*)ezalloc((filelen/3)*sizeof(Hint));
	oldarena = arena;
	for(;;){
		i = Bread(b,buf,3);
		if(i<3)
			break;
		nstats++;
		iq = buf[0];
		iq = (iq<<8) | buf[1];
		n = buf[2];
		h = arena;
		arena += n;
		hints[iq] = h;
		nhint[iq] = n;
		if(Bread(b,buf,3*n)!=3*n)
			sysfatal("stats read error");
		for(i=0; i<n; i++){
			s = &buf[3*i];
			h[i].url = (s[0]<<8) | s[1];
			h[i].prob = s[2];
		}
	}
	syslog(0, HTTPLOG, "prefetch-hints stats=%d (%.1fMB)", nstats, 1.e-6*((filelen/3)*sizeof(Hint)));
}
示例#7
0
void add_action (Action_s *a)
{
	State_s	*s;

	s = find_state(a->address);
	if (!s) {
		s = ezalloc(sizeof(*s));
		s->address = a->address;
		add_state(s);
		init_cir( &s->actions);
	}
	enq_cir( &s->actions, a, link);
	do_transition(s, a);
}
示例#8
0
文件: events.c 项目: taysom/tau
void start_threads (unsigned threads)
{
	pthread_t	*thread;
	unsigned	i;
	int		rc;
	struct arg_s	*arg;
	struct arg_s	*a;

	thread = ezalloc(threads * sizeof(pthread_t));
	arg    = ezalloc(threads * sizeof(struct arg_s));
	for (i = 0, a = arg; i < threads; i++, a++) {
		sprintf(a->name, "thead%d", i);
		a->event = i + 1;
		rc = pthread_create( &thread[i], NULL, history_test, a);
		if (rc) {
			eprintf("pthread_create %d\n", rc);
			break;
		}
	}
	while (i--) {
		pthread_join(thread[i], NULL);
	}
}
示例#9
0
int main (int argc, char *argv[])
{
	Action_s	*a;
	int	rc;

	for (;;) {
		a = ezalloc(sizeof(*a));
		rc = scanf("%lg%s%llx\n", &a->time, a->action, &a->address);
		if (rc != 3) break;
//		printf("%10.10lg %s %llx\n", a->time, a->action, a->address);
		add_action(a);
	}
	return 0;
}
示例#10
0
void start_collector(void)
{
	pthread_t collector_thread;
	int num_cpus;
	Collector_args_s *args;
	int i;
	int rc;

	Syscall_count = ezalloc(Num_syscalls * sizeof(*Syscall_count));
	init_tracing();
	enable_sys_enter();
	if (Trace_exit) {
		enable_sys_exit();
	}
	num_cpus = sysconf(_SC_NPROCESSORS_CONF);
	if (Dump) num_cpus = 1; // for now while playing with it
	args = ezalloc(num_cpus * sizeof(Collector_args_s));
	for (i = 0; i < num_cpus; i++, args++) {
		args->cpu_id = i;
		rc = pthread_create(&collector_thread, NULL,
			Dump ? dump_collector : collector, args);
		if (rc) fatal("Couldn't create collector %d:", rc);
	}
}
示例#11
0
文件: redirect.c 项目: 99years/plan9
static void
insert(Redir **tab, char *pat, char *repl)
{
	Redir **l;
	Redir *srch;
	ulong hash;

	hash = hashasu(pat, HASHSIZE);
	for(l = &tab[hash]; *l; l = &(*l)->next)
		;
	*l = srch = ezalloc(sizeof(Redir));
	srch->pat = pat;
	srch->flags = decor2flags(repl);
	srch->repl = undecorated(repl);
	srch->next = 0;
}
示例#12
0
文件: radix.c 项目: taysom/tau
void insert_leaf (bucket_s *bucket, u32 x, u32 shift)
{
	node_s	*node;
	u32	y = bucket->b_num;

	if (y == x) {
		//printf("Duplicate = %u\n", x);
		return;
	}
	++Nodes;
	node = ezalloc(sizeof(node_s));
	bucket->b_type = NODE;
	bucket->b_node = node;

	insert_node(bucket, y, shift);
	insert_node(bucket, x, shift);
}
示例#13
0
文件: symlink.c 项目: taysom/tau
char *gen_name (int len)
{
	static char file_name_char[] =  "abcdefghijklmnopqrstuvwxyz"
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
					"_0123456789";
	unsigned	i;
	char		*c;

	c = ezalloc(len);

	for (i = 0; i < len - 1; i++) {
		c[i] = file_name_char[urand(sizeof(file_name_char)-1)];
	}
	c[i] = '\0';

	return c;
}
示例#14
0
文件: blk.c 项目: taysom/tau
void binit (int num_bufs)
{
	unint	i;

	if (Buf) {
		fprintf(stderr, "block cache already initialized\n");
		return;
	}
	if (num_bufs == 0) num_bufs = DEFAULT_NUM_BUFS;
	num_bufs |= 1; /* make sure it is at least odd */

	Clock = Buf = ezalloc(sizeof(buf_s) * num_bufs);
	Data = emalloc((num_bufs + 1) * BLK_SIZE);

	Base = (u8 *)(((addr)Data + BLK_MASK) & ~BLK_MASK);
	for (i = 0; i < num_bufs; i++) {
		Buf[i].b_data = &Base[i * BLK_SIZE];
	}
	Num_bufs = num_bufs;
}
示例#15
0
文件: dir.c 项目: taysom/tau
static DirEntry_s *CreateDirEntry (int type)
{
	int fd;
	DirEntry_s *direntry;
	direntry = ezalloc(sizeof(*direntry));
	direntry->name = RndName();
	direntry->type = type;
	switch (type) {
		case T_FILE:
			fd = creat(direntry->name, 0700);
			close(fd);
			break;
		case T_DIR:
			mkdir(direntry->name, 0700);
			break;
		default:
			PrError("bad type %d", type);
			break;
	}
	return direntry;
}
示例#16
0
文件: cache.c 项目: taysom/tau
void binit (int num_bufs)
{
	buf_s	*buf;
	u8	*b;

	if (Buf) {
		fprintf(stderr, "block cache already initialized\n");
		return;
	}
	if (num_bufs == 0) num_bufs = DEFAULT_NUM_BUFS;
	num_bufs |= 1; /* make sure it is at least odd */

	Clock = Buf = ezalloc(sizeof(buf_s) * num_bufs);
	Data = emalloc((num_bufs + 1) * BLK_SIZE);

	b = Base = (u8 *)(((addr)Data + BLK_MASK) & ~BLK_MASK);
	for (buf = Buf; buf < &Buf[num_bufs]; buf++) {
		init_ant( &buf->b_ant, NULL);
		buf->b_data = b;
		b += BLK_SIZE;
	}
	Num_bufs = num_bufs;
}
示例#17
0
文件: dir_peer.c 项目: taysom/tau
/* Welcome */
static void welcome (void *m)
{
	msg_s	*msg = m;
	ki_t	hello_key = msg->q.q_passed_key;
	ki_t	share_key;
	share_s	*share;
	int	rc;
FN;
	share = ezalloc(sizeof(*share));
	share->sh_type = &Share_type.ts_tag;

	share_key = make_gate(share, RESOURCE | PASS_ANY);
	if (!share_key) {
		free(share);
		return;
	}
	msg->q.q_passed_key = share_key;
	msg->m_method = HELLO;
	rc = send_key_tau(hello_key, msg);
	if (rc) {
		destroy_key_tau(share_key);
	}
	destroy_key_tau(hello_key);
}
示例#18
0
文件: memcpy.c 项目: taysom/tau
void StartThreads (void)
{
	pthread_t *thread;
	unsigned i;
	int rc;

	Wait = Option.numthreads;
	pthread_mutex_lock(&StartLock);
	thread = ezalloc(Option.numthreads * sizeof(pthread_t));
	for (i = 0; i < Option.numthreads; i++) {
		rc = pthread_create( &thread[i], NULL, RunTest, NULL);
		if (rc) {
			eprintf("pthread_create %d\n", rc);
			break;
		}
	}
	for (i = 0; Wait; i++) {
		sleep(1);
	}
	pthread_mutex_unlock(&StartLock);
	for (i = 0; i <  Option.numthreads; i++) {
		pthread_join(thread[i], NULL);
	}
}
示例#19
0
文件: man2html.c 项目: aahud/harvey
void
searchfor(char *search)
{
	int i, j, n, fd;
	char *p, *sp;
	Biobufhdr *b;
	char *arg[32];

	hprint(hout, "<head><title>plan 9 search for %H</title></head>\n", search);
	hprint(hout, "<body>\n");

	hprint(hout, "<p>This is a keyword search through Plan 9 man pages.\n");
	hprint(hout, "The search is case insensitive; blanks denote \"boolean and\".\n");
	hprint(hout, "<FORM METHOD=\"GET\" ACTION=\"/magic/man2html\">\n");
	hprint(hout, "<INPUT NAME=\"pat\" TYPE=\"text\" SIZE=\"60\">\n");
	hprint(hout, "<INPUT TYPE=\"submit\" VALUE=\"Submit\">\n");
	hprint(hout, "</FORM>\n");

	hprint(hout, "<hr><H6>Search for %H</H6>\n", search);
	n = getfields(search, arg, 32, 1, "+");
	for(i = 0; i < n; i++){
		for(j = i+1; j < n; j++){
			if(strcmp(arg[i], arg[j]) > 0){
				sp = arg[j];
				arg[j] = arg[i];
				arg[i] = sp;
			}
		}
		sp = malloc(strlen(arg[i]) + 2);
		if(sp != nil){
			strcpy(sp+1, arg[i]);
			sp[0] = ' ';
			arg[i] = sp;
		}
	}

	/*
	 *  search index till line starts alphabetically < first token
	 */
	fd = open("/sys/man/searchindex", OREAD);
	if(fd < 0){
		hprint(hout, "<body>error: No Plan 9 search index\n");
		hprint(hout, "</body>");
		return;
	}
	p = malloc(32*1024);
	if(p == nil){
		close(fd);
		return;
	}
	b = ezalloc(sizeof *b);
	Binits(b, fd, OREAD, (uint8_t*)p, 32*1024);
	for(;;){
		p = Brdline(b, '\n');
		if(p == nil)
			break;
		p[Blinelen(b)-1] = 0;
		for(i = 0; i < n; i++){
			sp = strstr(p, arg[i]);
			if(sp == nil)
				break;
			p = sp;
		}
		if(i < n)
			continue;
		sp = strrchr(p, '\t');
		if(sp == nil)
			continue;
		sp++;
		hprint(hout, "<p><a href=\"/magic/man2html/%U\">/magic/man2html/%H</a>\n",
			sp, sp);
	}
	hprint(hout, "</body>");

	Bterm(b);
	free(b);
	free(p);
	close(fd);
}
示例#20
0
文件: bitree.c 项目: taysom/tau
static BiNode_s *bi_new (Rec_s r)
{
	BiNode_s *node = ezalloc(sizeof(*node));
	node->rec = r;
	return node;
}
示例#21
0
文件: hints.c 项目: aahud/harvey
void
urlinit(void)
{
	static Biobuf *b = nil;
	static int64_t filelen = 0;
	int64_t newlen;
	char *s, *arena;
	int i, j, n;
	uint url;
	char *file;

	if(filelen < 0)
		return;
	file = "/sys/log/httpd/url";
	if(b == nil){
		b = Bopen(file, OREAD); /* first time */
		if(b == nil){
			syslog(0, HTTPLOG, "no %s, abandon prefetch hints", file);
			filelen = -1;
			return;
		}
	}
	newlen = Bfilelen(b); /* side effect: rewinds b */
	if(newlen == filelen || Bage(b)<300)
		return;
	filelen = newlen;
	if(filelen < 0)
		return;
	if(nurl){ /* free existing tables */
		free(urlname[0]); /* arena */
		memset(urlhash,0,sizeof urlhash);
		memset(urlnext,0,sizeof urlnext);
		nurl = 0;
	}
	if(urlname==nil)
		urlname = (char**)ezalloc(URLmax*sizeof(*urlname));
	arena = (char*)ezalloc(filelen);  /* enough for all the strcpy below */
	i = 1;
	while((s=Brdline(b,'\n'))!=0){
		/* read lines of the form:  999 /url/path */
		n = Blinelen(b) - 1;
		if(n>2 && s[n]=='\n'){
			s[n] = '\0';
		}else{
			sysfatal("missing fields or newline in url-db");
		}
		j = strtoul(s,&s,10);
		while(*s==' ')
			s++;
		if(i++!=j)
			sysfatal("url-db synchronization error");
		url = hashstr(s);
		j = urllookup(url);
		if(j>=0)
			sysfatal("duplicate url");
		j = -j;
		nurl++;
		if(nurl>=URLmax){
			syslog(0, HTTPLOG, "urlinit overflow at %s",s);
			free(urlname[0]); /* arena */
			memset(urlhash,0,sizeof urlhash);
			memset(urlnext,0,sizeof urlnext);
			nurl = 0;
			return;
		}
		urltab[nurl] = url;
		urlnext[nurl] = urlhash[j];
		urlhash[j] = nurl;
		strcpy(arena,s);
		urlname[nurl] = arena;
		arena += strlen(s)+1;
	}
	syslog(0, HTTPLOG, "prefetch-hints url=%d (%.1fMB)", nurl, 1.e-6*(URLmax*sizeof(*urlname)+filelen));
	/* b is held open, because namespace will be chopped */
}
示例#22
0
文件: json.c 项目: taysom/tau
Tree_s *new_tree (void)
{
FN;
	Tree_s	*tree = ezalloc(sizeof(*tree));
	return tree;
}
示例#23
0
文件: bitmap.c 项目: taysom/tau
#include <eprintf.h>
#include <style.h>

void pr_bitmap(bitmap_t b)
{
	unint i;

	for (i = 0; i < b.n; i++) {
		if (is_set(b, i))  putchar('1');
		else putchar('0');
		if (i % 64 == 63) putchar('\n');
	}
	if (i % 64) putchar('\n');
}

bitmap_t new_bitmap(u64 nbits)
{
	u64 n = (nbits + BIT_MASK) >> BIT_SHIFT;
	bitmap_t b;

	b.map = ezalloc(n);
	b.n = nbits;
	b.start = 0;
	return b;
}

void free_bitmap(bitmap_t b)
{
	free(b.map);
}