Esempio n. 1
0
void init_ffsb_config(ffsb_config_t *fc, unsigned num_fs, unsigned num_tg)
{
	memset(fc, 0, sizeof(ffsb_config_t));

	fc->num_totalthreads = -1;
	fc->num_threadgroups = num_tg;
	fc->num_filesys = num_fs;

	fc->groups = ffsb_malloc(sizeof(ffsb_tg_t) * num_tg);
	fc->filesystems = ffsb_malloc(sizeof(ffsb_fs_t) * num_fs);
}
Esempio n. 2
0
void ft_alter_bufsize(ffsb_thread_t *ft, unsigned bufsize)
{
	if (ft->mallocbuf != NULL)
		free(ft->mallocbuf);
	ft->mallocbuf = ffsb_malloc(bufsize + 4096);
	ft->alignedbuf = ffsb_align_4k(ft->mallocbuf + (4096 - 1));
}
Esempio n. 3
0
/* Private version of above function used only for reusing a
 * fileset.
 */
static struct ffsb_file *add_file_named(struct benchfiles *b, uint64_t size,
					 char *name)
{
	struct ffsb_file *newfile = NULL;

	newfile = ffsb_malloc(sizeof(struct ffsb_file));
	memset(newfile, 0, sizeof(struct ffsb_file));
	newfile->name = ffsb_strdup(name);
	newfile->size = size;
	init_rwlock(&newfile->lock);

	/* Write lock the filelist, begin critical section */
	rw_lock_write(&b->fileslock);

	newfile->num = b->listsize;
	b->listsize++;

	/* Add a new file to the rbtree */
	rbtree_insert(b->files, newfile);

	rw_lock_write(&newfile->lock);

	/* Unlock filelist */
	rw_unlock_write(&b->fileslock);

	return newfile;
}
Esempio n. 4
0
struct ffsb_file *add_file(struct benchfiles *b, uint64_t size, randdata_t *rd)
{
	struct ffsb_file *newfile, *oldfile = NULL;
	int filenum = 0;

	/* We pre-allocate here, because I don't want to spend time
	 * malloc'ing while the list is locked we free it later if
	 * necessary
	 */
	newfile = ffsb_malloc(sizeof(struct ffsb_file));

	newfile->size = size;
	init_rwlock(&(newfile->lock));

	/* Write lock the filelist, begin critical section */
	rw_lock_write(&b->fileslock);

	/* First check "holes" for a file  */
	if (!cl_empty(b->holes)) {
		oldfile = cl_remove_head(b->holes);
		rbtree_insert(b->files, oldfile);
		rw_lock_write(&oldfile->lock);
	} else {
		filenum = b->listsize;
		b->listsize++;

		newfile->num = filenum;
		rbtree_insert(b->files, newfile);

		rw_lock_write(&newfile->lock);
	}

	/* unlock filelist */
	rw_unlock_write(&b->fileslock);

	if (oldfile == NULL) {
		char buf[FILENAME_MAX];
		int randdir = getrandom(rd, b->numsubdirs+1);
		int namesize = 0;
		if (randdir == 0)
			namesize = snprintf(buf, FILENAME_MAX, "%s/%s%s%d",
					    b->basedir, b->basename,
					    FILENAME_BASE, filenum);
		else
			namesize = snprintf(buf, FILENAME_MAX,
					    "%s/%s%s%d/%s%s%d", b->basedir,
					    b->basename, SUBDIRNAME_BASE,
					    randdir - 1, b->basename,
					    FILENAME_BASE, filenum);
		if (namesize >= FILENAME_MAX)
			/* !!! do something about this ? */
			printf("warning: filename \"%s\" too long\n", buf);
		newfile->name = ffsb_strdup(buf);
		return newfile;
	} else {
		free(newfile);
		return oldfile;
	}
}
Esempio n. 5
0
char *ffsb_strdup(const char *str)
{
	int len = strlen(str);
	char *dup = ffsb_malloc(len + 1);
	/* !!! am I off by one here ?? */
	strncpy(dup, str, len+1);
	return dup;
}
Esempio n. 6
0
void init_filelist(struct benchfiles *b, char *basedir, char *basename,
		   uint32_t numsubdirs, int builddirs)
{
	memset(b, 0, sizeof(struct benchfiles));
	b->basedir = ffsb_strdup(basedir);
	b->basename = ffsb_strdup(basename);
	b->numsubdirs = numsubdirs;
	init_rwlock(&b->fileslock);
	b->files = rbtree_construct();
	b->dirs = rbtree_construct();
	b->holes = ffsb_malloc(sizeof(struct cirlist));
	b->dholes = ffsb_malloc(sizeof(struct cirlist));
	init_cirlist(b->holes);
	init_cirlist(b->dholes);

	if (builddirs)
		build_dirs(b);
}
Esempio n. 7
0
void *ffsb_realloc(void *ptr, size_t size)
{
	void *tmp ;
	/* printf("ffsb_realloc: ptr = %p  size = %ld\n",ptr,size); */

	if (ptr == NULL)
		return ffsb_malloc(size);

	tmp = realloc(ptr, size);
	assert(ptr != NULL);
	ptr = tmp;
	return ptr;
}
Esempio n. 8
0
void init_ffsb_tg(ffsb_tg_t *tg, unsigned num_threads, unsigned tg_num)
{
	int i;
	memset(tg, 0, sizeof(ffsb_tg_t));

	tg->threads = ffsb_malloc(sizeof(ffsb_thread_t) * num_threads);
	tg->tg_num = tg_num;
	tg->num_threads = num_threads;

	tg->bindfs = -1; /* default is not bound */

	tg->thread_bufsize = 0;
	for (i = 0 ; i < num_threads ; i++)
		init_ffsb_thread(tg->threads + i, tg, 0, tg_num, i);
}
Esempio n. 9
0
struct ffsb_file *add_dir(struct benchfiles *b, uint64_t size, randdata_t *rd)
{
	struct ffsb_file *newdir, *olddir = NULL;
	int dirnum = 0;

	newdir = ffsb_malloc(sizeof(struct ffsb_file));

	init_rwlock(&newdir->lock);

	/* write lock the filelist, beging critical section */
	rw_lock_write(&b->fileslock);

	/* First check "holes" for a file  */
	if (!cl_empty(b->dholes)) {
		olddir = cl_remove_head(b->dholes);
		rbtree_insert(b->files, olddir);
		rw_lock_write(&olddir->lock);
	} else {
		dirnum = b->numsubdirs;
		b->numsubdirs++;
		printf("dirnum: %d\n", dirnum);
		newdir->num = dirnum;
		rbtree_insert(b->dirs, newdir);

		rw_lock_write(&newdir->lock);
	}

	/* unlock filelist */
	rw_unlock_write(&b->fileslock);

	if (olddir == NULL) {
		char buf[FILENAME_MAX];
		int namesize = 0;
		namesize = snprintf(buf, FILENAME_MAX, "%s/%s%s%d",
				    b->basedir, b->basename,
				    SUBDIRNAME_BASE, dirnum);
		if (namesize >= FILENAME_MAX)
			printf("warning: filename \"%s\" too long\n", buf);
			/* TODO: take action here... */
		newdir->name = ffsb_strdup(buf);
		return newdir;
	} else {
		free(newdir);
		return olddir;
	}
}
Esempio n. 10
0
void ffsb_statsd_init(ffsb_statsd_t *fsd, ffsb_statsc_t *fsc)
{
	int i;
	memset(fsd, 0, sizeof(*fsd));

	for (i = 0; i < FFSB_NUM_SYSCALLS; i++) {
		fsd->totals[i] = 0;
		fsd->mins[i] = UINT_MAX;
		fsd->maxs[i] = 0;
		fsd->buckets[i] = ffsb_malloc(sizeof(uint32_t) *
					      fsc->num_buckets);
		assert(fsd->buckets[i] != NULL);

		memset(fsd->buckets[i], 0, sizeof(uint32_t) *
		       fsc->num_buckets);
	}
	fsd->config = fsc;
}