[PATCH 2/2] Add single-threaded fast path to rand()
Xi Ruoyao
xry111@xry111.site
Wed Mar 20 14:40:09 GMT 2024
On Wed, 2024-03-20 at 14:28 +0000, Wilco Dijkstra wrote:
> Hi Cristian,
>
> > Yeah, it should be no surprise this interfaces are bad,
> > I thought this was common knowledge.
>
> It's bad but we also made it thread-safe via locks rather than add its state to TLS.
>
> > we need something like https://github.com/C2SP/C2SP/blob/main/chacha8rand.md
> > which prety much outperforms even non-CS algorithms in at least 64 bit x86.
> > but the question of the state remains.global? TLS? how to discard it
> > in all the appropriate occasions?
>
> I believe the current implementation is already way overkill. All you need is a simple
> LFSR random generator with 64 bits of state and a decently large cycle. It's not
> meant to be a serious random number generator - it's invariably used to generate
> randomized inputs for testing and benchmarking. That's all. The complaints are
> due to it being too slow due to all the locking.
Yes, we don't need a *CS*PRNG, just a PRNG. Thus no "oops, the user
space cannot know whether to reseed" stuff.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
More information about the Libc-alpha
mailing list