MINOR: debug: add a trivial PRNG for scheduler stress-tests
Commit a5a447984 ("MINOR: debug: add "debug dev sched" to stress the scheduler.") doesn't scale with threads because ha_random64() takes care of being totally thread-safe for use with UUIDs. We don't need this for the stress-testing functions, let's just implement a xorshift PRNG instead. On 8 threads the performance jumped from 230k ctx/s with 96% spent in ha_random64() to 14M ctx/s.
This commit is contained in:
parent
a5a4479849
commit
8a069eb9a4
15
src/debug.c
15
src/debug.c
@ -42,6 +42,17 @@
|
||||
volatile unsigned long threads_to_dump = 0;
|
||||
unsigned int debug_commands_issued = 0;
|
||||
|
||||
/* Xorshift RNGs from http://www.jstatsoft.org/v08/i14/paper */
|
||||
static THREAD_LOCAL unsigned int y = 2463534242;
|
||||
static unsigned int debug_prng()
|
||||
{
|
||||
|
||||
y ^= y << 13;
|
||||
y ^= y >> 17;
|
||||
y ^= y << 5;
|
||||
return y;
|
||||
}
|
||||
|
||||
/* Dumps to the buffer some known information for the desired thread, and
|
||||
* optionally extra info for the current thread. The dump will be appended to
|
||||
* the buffer, so the caller is responsible for preliminary initializing it.
|
||||
@ -684,7 +695,7 @@ static struct task *debug_task_handler(struct task *t, void *ctx, unsigned short
|
||||
t->expire = tick_add(now_ms, inter);
|
||||
|
||||
/* half of the calls will wake up another entry */
|
||||
rnd = ha_random64();
|
||||
rnd = debug_prng();
|
||||
if (rnd & 1) {
|
||||
rnd >>= 1;
|
||||
rnd %= tctx[0];
|
||||
@ -706,7 +717,7 @@ static struct task *debug_tasklet_handler(struct task *t, void *ctx, unsigned sh
|
||||
|
||||
/* wake up two random entries */
|
||||
for (i = 0; i < 2; i++) {
|
||||
rnd = ha_random64() % tctx[0];
|
||||
rnd = debug_prng() % tctx[0];
|
||||
rnd = tctx[rnd + 2];
|
||||
|
||||
if (rnd & 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user