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: GangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15108
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
GangCao 2022-10-21 09:24:55 -04:00 committed by Tomasz Zawadzki
parent 7ba33f49f0
commit 03b1b86078
2 changed files with 11 additions and 5 deletions

View File

@ -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,8 +1256,11 @@ 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) {
entry->zipf = spdk_zipf_create(entry->size_in_ios, 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);
@ -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;

View File

@ -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;