Index: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c =================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c +++ head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c @@ -124,6 +124,7 @@ #include #include #include +#include #include #include #include @@ -136,6 +137,8 @@ #include "dtrace_debug.c" #endif +#include "dtrace_xoroshiro128_plus.h" + /* * DTrace Tunable Variables * @@ -298,7 +301,6 @@ #define vuprintf vprintf #define ttoproc(_a) ((_a)->td_proc) #define crgetzoneid(_a) 0 -#define NCPU MAXCPU #define SNOCD 0 #define CPU_ON_INTR(_a) 0 @@ -4236,7 +4238,8 @@ switch (subr) { case DIF_SUBR_RAND: - regs[rd] = (dtrace_gethrtime() * 2416 + 374441) % 1771875; + regs[rd] = dtrace_xoroshiro128_plus_next( + state->dts_rstate[curcpu]); break; #ifdef illumos @@ -14495,6 +14498,7 @@ dtrace_state_t *state; dtrace_optval_t *opt; int bufsize = NCPU * sizeof (dtrace_buffer_t), i; + int cpu_it; ASSERT(MUTEX_HELD(&dtrace_lock)); ASSERT(MUTEX_HELD(&cpu_lock)); @@ -14550,6 +14554,21 @@ state->dts_buffer = kmem_zalloc(bufsize, KM_SLEEP); state->dts_aggbuffer = kmem_zalloc(bufsize, KM_SLEEP); + /* + * Allocate and initialise the per-process per-CPU random state. + * SI_SUB_RANDOM < SI_SUB_DTRACE_ANON therefore entropy device is + * assumed to be seeded at this point (if from Fortuna seed file). + */ + (void) read_random(&state->dts_rstate[0], 2 * sizeof(uint64_t)); + for (cpu_it = 1; cpu_it < NCPU; cpu_it++) { + /* + * Each CPU is assigned a 2^64 period, non-overlapping + * subsequence. + */ + dtrace_xoroshiro128_plus_jump(state->dts_rstate[cpu_it-1], + state->dts_rstate[cpu_it]); + } + #ifdef illumos state->dts_cleaner = CYCLIC_NONE; state->dts_deadman = CYCLIC_NONE; Index: head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h =================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h +++ head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h @@ -50,6 +50,7 @@ */ #include + #ifndef illumos #ifdef __sparcv9 typedef uint32_t pc_t; @@ -65,6 +66,10 @@ #define DTRACE_MAXPROPLEN 128 #define DTRACE_DYNVAR_CHUNKSIZE 256 +#ifdef __FreeBSD__ +#define NCPU MAXCPU +#endif /* __FreeBSD__ */ + struct dtrace_probe; struct dtrace_ecb; struct dtrace_predicate; @@ -1169,6 +1174,7 @@ dtrace_cred_t dts_cred; /* credentials */ size_t dts_nretained; /* number of retained enabs */ int dts_getf; /* number of getf() calls */ + uint64_t dts_rstate[NCPU][2]; /* per-CPU random state */ }; struct dtrace_provider { Index: head/sys/modules/dtrace/dtrace/Makefile =================================================================== --- head/sys/modules/dtrace/dtrace/Makefile +++ head/sys/modules/dtrace/dtrace/Makefile @@ -12,6 +12,7 @@ KMOD= dtrace SRCS= dtrace.c \ + dtrace_xoroshiro128_plus.c \ dtrace_asm.S \ dtrace_subr.c @@ -42,6 +43,7 @@ -I${SYSDIR}/cddl/dev/dtrace \ -I${SYSDIR}/cddl/dev/dtrace/${ARCHDIR} \ -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ + -I${SYSDIR}/cddl/contrib/opensolaris/uts/common/dtrace \ -I${SYSDIR}/cddl/contrib/opensolaris/common/util \ -I${SYSDIR} -DDIS_MEM Index: head/sys/modules/dtrace/fasttrap/Makefile =================================================================== --- head/sys/modules/dtrace/fasttrap/Makefile +++ head/sys/modules/dtrace/fasttrap/Makefile @@ -10,6 +10,7 @@ CFLAGS+= -I${SYSDIR}/cddl/compat/opensolaris \ -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ + -I${SYSDIR}/cddl/contrib/opensolaris/uts/common/dtrace \ -I${SYSDIR} .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" Index: head/sys/modules/dtrace/systrace/Makefile =================================================================== --- head/sys/modules/dtrace/systrace/Makefile +++ head/sys/modules/dtrace/systrace/Makefile @@ -10,6 +10,7 @@ CFLAGS+= -I${SYSDIR}/cddl/compat/opensolaris \ -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ + -I${SYSDIR}/cddl/contrib/opensolaris/uts/common/dtrace \ -I${SYSDIR} .include