[PATCH v3] Add single-threaded fast path to rand()
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Feb 25 19:29:59 GMT 2025
On 24/02/25 11:01, Wilco Dijkstra wrote:
> Hi Adhemerval,
>
>> On 29/07/24 11:23, Wilco Dijkstra wrote:
>>> Improve performance of rand() and __random() by adding a single-threaded fast
>>> path. Bench-random-lock shows about 5x speedup on Neoverse V1.
>>
>> LGTM, although I am not sure which kind of workload does really
>> benefit from this optimization.
>
> It's a very common pitfall when one creates benchmarks and wants some randomized
> inputs. Then they find out 90+% of the time is spent in rand() and not in the code they
> try to benchmark... We've been asked plenty of times to improve rand() performance
> by various customers, so this is just a quick fix for that common issue.
Right, I guess users still rely on such bad interface for RNG with a seed.
>
> However using a simpler and faster LFSR without lots of global state would be even
> better since that could just use an atomic for the state update and avoid locks.
> Rand() is not required to be perfectly random, let alone cryptographically safe...
Yeah, although I think we most likely need a symbol version for such change.
>
> Cheers,
> Wilco
In any case,
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
More information about the Libc-alpha
mailing list