Ejemplo n.º 1
0
/* Packs a small span with overlapping nodes, then removes all nodes from a subspan
 * and adds that many new random nodes back.
 */
static void
unit_test_churn_narrow_span(bb_node_t **node_list, uint list_length)
{
    uint i, j, k, node_count, random_span = list_length * 8;
    app_pc random_base = (app_pc) get_random_offset(0xf0000000);

    ASSERT(fragment_tree->root == fragment_tree->nil);

    for (i = 0; i < list_length; i++) { /* pack a small span */
        if (unit_test_insert_random_node(node_list, (app_pc) random_base,
                                         10 + random_span, i)) {
            if ((i+1) % 20 == 0)
                unit_test_lookup_all_nodes(node_list, i+1);
        } else {
            i--; /* found exact match, so rewind and try another */
        }
    }

    for (i = 0; i < 10; i++) {
        node_count = unit_test_remove_occupied_span(node_list, list_length);
        for (j = 0; j < node_count; j++) {
            for (k = 0; k < list_length; k++) { /* find an empty slot */
                if (node_list[k] == NULL)
                    break;
            }
            if (unit_test_insert_random_node(node_list, (app_pc) random_base,
                                             10 + random_span, k)) {
                if ((i+1) % 20 == 0)
                    unit_test_lookup_all_nodes(node_list, list_length);
            } else {
                j--; /* found exact match, so rewind and try another */
            }
        }
    }
}
Ejemplo n.º 2
0
/* Allocate and free blocks in a random order.  */
static size_t
malloc_benchmark_loop (void **ptr_arr)
{
  unsigned int offset_state = 0, block_state = 0;
  size_t iters = 0;

  while (!timeout)
    {
      unsigned int next_idx = get_random_offset (&offset_state);
      unsigned int next_block = get_random_block_size (&block_state);

      free (ptr_arr[next_idx]);

      ptr_arr[next_idx] = malloc (next_block);

      iters++;
    }

  return iters;
}
Ejemplo n.º 3
0
void ffsb_readfile(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum)
{
	struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum);
	struct ffsb_file *curfile = NULL;

	int fd;
	uint64_t filesize;

	char *buf = ft_getbuf(ft);
	int read_random = ft_get_read_random(ft);
	uint64_t read_size = ft_get_read_size(ft);
	uint32_t read_blocksize = ft_get_read_blocksize(ft);
	uint32_t read_skipsize = ft_get_read_skipsize(ft);
	int skip_reads = ft_get_read_skip(ft);
	struct randdata *rd = ft_get_randdata(ft);

	uint64_t iterations = 0;

	curfile = choose_file_reader(bf, rd);
	fd = fhopenread(curfile->name, ft, fs);

	filesize = ffsb_get_filesize(curfile->name);

	assert(filesize >= read_size);

	/* Sequential read, starting at a random point */
	if (!read_random) {
		uint64_t range = filesize - read_size;
		uint64_t offset = 0;
		/* Skip or "stride" reads option */
		if (skip_reads) {
			unsigned i, last;
			uint64_t minfilesize;
			iterations = read_size / read_blocksize;
			last = read_size % read_blocksize;

			/* Double check that the user hasn't specified
			 * a read_size that is too large when combined
			 * with the seeks
			 */
			if (last)
				minfilesize = last + iterations *
					(read_blocksize + read_skipsize);
			else
				minfilesize = read_blocksize + iterations - 1 *
					(read_blocksize + read_skipsize);

			if (minfilesize > filesize) {
				  printf("Error: read size %llu bytes too big "
					 "w/ skipsize %u and blocksize %u,"
					 " for file of size %llu bytes\n"
					 " aborting\n\n", read_size,
					 read_skipsize, read_blocksize,
					 filesize);
				  printf("minimum file size must be at least "
					 " %llu bytes\n", minfilesize);
					 exit(1);
			}

			for (i = 0; i < iterations; i++) {
				fhread(fd, buf, read_blocksize, ft, fs);
				fhseek(fd, (uint64_t)read_skipsize, SEEK_CUR,
				       ft, fs);
			}
			if (last) {
				fhread(fd, buf, (uint64_t)last, ft, fs);
				iterations++;
			}
		} else {
			/* Regular sequential reads */
			if (range) {
				offset = get_random_offset(rd, range,
							   fs_get_alignio(fs));
				fhseek(fd, offset, SEEK_SET, ft, fs);
			}
			iterations = readfile_helper(fd, read_size,
						     read_blocksize, buf,
						     ft, fs);
		}
	} else {
		/* Randomized read */
		uint64_t range = filesize - read_blocksize;
		int i;

		iterations = read_size / read_blocksize;

		for (i = 0; i < iterations; i++) {
			uint64_t offset = get_random_offset(rd, range,
							    fs_get_alignio(fs));
			fhseek(fd, offset, SEEK_SET, ft, fs);
			fhread(fd, buf, read_blocksize, ft, fs);
		}
	}

	unlock_file_reader(curfile);
	fhclose(fd, ft, fs);

	ft_incr_op(ft, opnum, iterations, read_size);
	ft_add_readbytes(ft, read_size);
}
Ejemplo n.º 4
0
static unsigned ffsb_writefile_core(ffsb_thread_t *ft, ffsb_fs_t *fs,
				    unsigned opnum, uint64_t *filesize_ret,
				    int fsync_file)
{
	struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum);
	struct ffsb_file *curfile = NULL;

	int fd;
	uint64_t filesize;

	char *buf = ft_getbuf(ft);
	int write_random = ft_get_write_random(ft);
	uint32_t write_size = ft_get_write_size(ft);
	uint32_t write_blocksize = ft_get_write_blocksize(ft);
	struct randdata *rd = ft_get_randdata(ft);
	unsigned iterations = 0;

	curfile = choose_file_reader(bf, rd);
	fd = fhopenwrite(curfile->name, ft, fs);

	filesize = ffsb_get_filesize(curfile->name);

	assert(filesize >= write_size);

	/* Sequential write, starting at a random point  */
	if (!write_random) {
		uint64_t range = filesize - write_size;
		uint64_t offset = 0;
		if (range) {
			offset = get_random_offset(rd, range,
						   fs_get_alignio(fs));
			fhseek(fd, offset, SEEK_SET, ft, fs);
		}
		iterations = writefile_helper(fd, write_size, write_blocksize,
					      buf, ft, fs);
	} else {
		/* Randomized write */
		uint64_t range = filesize - write_blocksize;
		int i;
		iterations = write_size / write_blocksize;

		for (i = 0; i < iterations; i++) {
			uint64_t offset = get_random_offset(rd, range,
							    fs_get_alignio(fs));
			fhseek(fd, offset, SEEK_SET, ft, fs);
			fhwrite(fd, buf, write_blocksize, ft, fs);
		}
	}

	if (fsync_file) {
		if (fsync(fd)) {
			perror("fsync");
			printf("aborting\n");
			exit(1);
		}
	}
	unlock_file_reader(curfile);
	fhclose(fd, ft, fs);
	*filesize_ret = filesize;
	return iterations;
}
Ejemplo n.º 5
0
static app_pc
unit_test_get_random_pc(app_pc range_start, uint max_range_size)
{
    return range_start + get_random_offset(max_range_size);
}
Ejemplo n.º 6
0
void
kernel32_redir_init_mem(void)
{
    magic_val = (ptr_uint_t) get_random_offset(POINTER_MAX);
}