Commit 03b1b860 authored by GangCao's avatar GangCao Committed by Tomasz Zawadzki
Browse files

test/bdevperf: set a random seed for rand rw testing



To fix issue: #2726

And also fix the examples/nvme/perf tool.

The srand() only needs to be called once to set the seed of
futher more calls of rand().

Change-Id: I41ab3a46593513516ad11ea7a5b8960b449e9867
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15108


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 7ba33f49
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -745,7 +745,6 @@ register_file(const char *path)
	entry->io_size_blocks = g_io_size_bytes / blklen;

	if (g_is_random) {
		srand(getpid());
		entry->seed = rand();
		if (g_zipf_theta > 0) {
			entry->zipf = spdk_zipf_create(entry->size_in_ios, g_zipf_theta, 0);
@@ -1257,9 +1256,12 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
	entry->size_in_ios = ns_size / g_io_size_bytes;
	entry->io_size_blocks = g_io_size_bytes / sector_size;

	if (g_is_random && g_zipf_theta > 0) {
	if (g_is_random) {
		entry->seed = rand();
		if (g_zipf_theta > 0) {
			entry->zipf = spdk_zipf_create(entry->size_in_ios, g_zipf_theta, 0);
		}
	}

	entry->block_size = spdk_nvme_ns_get_extended_sector_size(ns);
	entry->md_size = spdk_nvme_ns_get_md_size(ns);
@@ -3000,6 +3002,9 @@ main(int argc, char **argv)
	struct spdk_env_opts opts;
	pthread_t thread_id = 0;

	/* Use the runtime PID to set the random seed */
	srand(getpid());

	spdk_env_opts_init(&opts);
	opts.name = "perf";
	opts.pci_allowed = g_allowed_pci_addr;
+3 −2
Original line number Diff line number Diff line
@@ -1215,8 +1215,6 @@ end:
static void
job_init_rw(struct bdevperf_job *job, enum job_config_rw rw)
{
	srand(getpid());

	switch (rw) {
	case JOB_CONFIG_RW_READ:
		job->rw_percentage = 100;
@@ -2158,6 +2156,9 @@ main(int argc, char **argv)
	struct spdk_app_opts opts = {};
	int rc;

	/* Use the runtime PID to set the random seed */
	srand(getpid());

	spdk_app_opts_init(&opts, sizeof(opts));
	opts.name = "bdevperf";
	opts.rpc_addr = NULL;