X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=runtime%2Fruntime.c;fp=runtime%2Fruntime.c;h=415a1617816f18133728538b7059bf1b89ee9980;hp=ceb67729f79ba7e7518736cf9d6812607630520f;hb=7d658a03f83e64690d0c71b4733dd3f9a2c60208;hpb=6b4f3ea4891b6c0e65dfd6d41f49aee2daa9e23d diff --git a/runtime/runtime.c b/runtime/runtime.c index ceb6772..415a161 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -34,7 +34,11 @@ static void *worker (void *arg) { thread_info_t *ti = (thread_info_t *)arg; SET_THREAD_LOCAL(tid_, ti->thread_id); LOCALIZE_THREAD_LOCAL(tid_, int); +#ifndef NDEBUG SET_THREAD_LOCAL(rand_seed_, tid_+1); +#else + SET_THREAD_LOCAL(rand_seed_, nbd_rand_seed(tid_+1)); +#endif lwt_thread_init(ti->thread_id); rcu_thread_init(ti->thread_id); void *ret = ti->start_routine(ti->arg); @@ -56,3 +60,13 @@ int nbd_rand (void) { SET_THREAD_LOCAL(rand_seed_, r); return r; } + +uint64_t nbd_rand_seed (int i) { + return rdtsc() + -715159705 + i * 129; +} + +// Fairly fast random numbers +int nbd_next_rand (uint64_t *r) { + *r = (*r * 0x5DEECE66DLL + 0xBLL) & MASK(48); + return (*r >> 17) & 0x7FFFFFFF; +}