/* 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; }
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; } }
struct vm_address_space *create_address_space(void) { struct vm_address_space *space; space = slab_alloc(&address_space_slab); init_area_map(&space->area_map, PAGE_SIZE, KERNEL_BASE - 1); space->translation_map = create_translation_map(); init_rwlock(&space->mut); return space; }
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; } }
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); }
void vm_address_space_init(struct vm_translation_map *translation_map) { int i; struct vm_area_map *amap = &kernel_address_space.area_map; kernel_address_space.translation_map = translation_map; init_rwlock(&kernel_address_space.mut); init_area_map(amap, KERNEL_BASE, 0xffffffff); create_vm_area(amap, KERNEL_BASE, KERNEL_END - KERNEL_BASE, PLACE_EXACT, "kernel", AREA_WIRED | AREA_WRITABLE | AREA_EXECUTABLE); create_vm_area(amap, PHYS_MEM_ALIAS, memory_size, PLACE_EXACT, "memory alias", AREA_WIRED | AREA_WRITABLE); create_vm_area(amap, KERNEL_HEAP_BASE, KERNEL_HEAP_SIZE, PLACE_EXACT, "kernel_heap", AREA_WIRED | AREA_WRITABLE); create_vm_area(amap, DEVICE_REG_BASE, 0x10000, PLACE_EXACT, "device registers", AREA_WIRED | AREA_WRITABLE); for (i = 0; i < 4; i++) { create_vm_area(amap, INITIAL_KERNEL_STACKS + i * KERNEL_STACK_SIZE, KERNEL_STACK_SIZE, PLACE_EXACT, "kernel stack", AREA_WIRED | AREA_WRITABLE); } }