diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2021-09-12 18:12:47 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2021-09-12 18:12:47 +0000 |
commit | 6aa4d33cce95c534665f3f8e057f13a69ab10835 (patch) | |
tree | cfb6f1e6a17b8751adf037ab86a1e50594e79fb4 /testing | |
parent | 15a477c9f6730cd98e40bbdbb0511cdf3a3c4319 (diff) | |
download | sg3_utils-6aa4d33cce95c534665f3f8e057f13a69ab10835.tar.gz |
sg_dd: srand48_r() and mrand48_r() are GNU libc specific, put conditional in so non-reentrant version used otherwise
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@913 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'testing')
-rw-r--r-- | testing/sg_mrq_dd.cpp | 17 | ||||
-rw-r--r-- | testing/sgh_dd.cpp | 13 |
2 files changed, 27 insertions, 3 deletions
diff --git a/testing/sg_mrq_dd.cpp b/testing/sg_mrq_dd.cpp index 42613256..b554614a 100644 --- a/testing/sg_mrq_dd.cpp +++ b/testing/sg_mrq_dd.cpp @@ -30,7 +30,7 @@ * */ -static const char * version_str = "1.35 20210816"; +static const char * version_str = "1.36 20210906"; #define _XOPEN_SOURCE 600 #ifndef _GNU_SOURCE @@ -348,6 +348,9 @@ typedef struct request_element int out_local_partial; int in_resid_bytes; long seed; +#ifdef HAVE_SRAND48_R /* gcc extension. N.B. non-reentrant version slower */ + struct drand48_data drand;/* opaque, used by srand48_r and mrand48_r */ +#endif } Rq_elem; /* Additional parameters for sg_start_io() and sg_finish_io() */ @@ -1656,7 +1659,11 @@ read_write_thread(struct global_collection * clp, int thr_idx, int slice_idx, #endif if (vb > 1) pr2serr_lk("[%d] %s: seed=%ld\n", thr_idx, __func__, rep->seed); +#ifdef HAVE_SRAND48_R + srand48_r(rep->seed, &rep->drand); +#else srand48(rep->seed); +#endif } if (in_is_sg && inf.size()) { @@ -1895,8 +1902,12 @@ normal_in_rd(Rq_elem * rep, int64_t lba, int blocks, int d_boff) bp = rep->buffp + d_boff; for (k = 0; k < blocks; ++k, bp += clp->bs) { for (j = 0; j < clp->bs; j += jbump) { - /* mrand48 takes uniformly from [-2^31, 2^31) */ + /* mrand48 takes uniformly from [-2^31, 2^31) */ +#ifdef HAVE_SRAND48_R + mrand48_r(&rep->drand, &rn); +#else rn = mrand48(); +#endif *((uint32_t *)(bp + j)) = (uint32_t)rn; } } @@ -3385,6 +3396,8 @@ process_flags(const char * arg, struct flags_t * fp) fp->masync = true; else if (0 == strcmp(cp, "mmap")) ++fp->mmap; /* mmap > 1 stops munmap() being called */ + else if (0 == strcmp(cp, "nocreat")) + fp->nocreat = true; else if (0 == strcmp(cp, "nodur")) fp->no_dur = true; else if (0 == strcmp(cp, "no_dur")) diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp index 483dfce2..bc98de43 100644 --- a/testing/sgh_dd.cpp +++ b/testing/sgh_dd.cpp @@ -36,7 +36,7 @@ * renamed [20181221] */ -static const char * version_str = "2.15 20210816"; +static const char * version_str = "2.16 20210906"; #define _XOPEN_SOURCE 600 #ifndef _GNU_SOURCE @@ -317,6 +317,9 @@ typedef struct request_element uint32_t in_mrq_q_blks; uint32_t out_mrq_q_blks; long seed; +#ifdef HAVE_SRAND48_R /* gcc extension. N.B. non-reentrant version slower */ + struct drand48_data drand;/* opaque, used by srand48_r and mrand48_r */ +#endif pthread_t mrq_abort_thread_id; Mrq_abort_info mai; } Rq_elem; @@ -1536,7 +1539,11 @@ read_write_thread(void * v_tip) #endif if (vb > 1) pr2serr_lk("thread=%d: seed=%ld\n", rep->id, rep->seed); +#ifdef HAVE_SRAND48_R + srand48_r(rep->seed, &rep->drand); +#else srand48(rep->seed); +#endif } if (clp->in_flags.same_fds || clp->out_flags.same_fds) ; @@ -1857,7 +1864,11 @@ normal_in_rd(Rq_elem * rep, int blocks) for (k = 0, bp = rep->buffp; k < blocks; ++k, bp += clp->bs) { for (j = 0; j < clp->bs; j += jbump) { /* mrand48 takes uniformly from [-2^31, 2^31) */ +#ifdef HAVE_SRAND48_R + mrand48_r(&rep->drand, &rn); +#else rn = mrand48(); +#endif *((uint32_t *)(bp + j)) = (uint32_t)rn; } } |