Page MenuHomeFreeBSD

Make sched_random() return an unsigned number.
ClosedPublic

Authored by imp on Feb 27 2015, 5:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 9 2024, 1:57 AM
Unknown Object (File)
Feb 11 2024, 6:37 PM
Unknown Object (File)
Dec 22 2023, 9:36 PM
Unknown Object (File)
Sep 10 2023, 4:54 AM
Unknown Object (File)
Aug 14 2023, 12:19 PM
Unknown Object (File)
Jul 2 2023, 1:31 AM
Unknown Object (File)
Jun 27 2023, 10:14 AM
Unknown Object (File)
Jun 27 2023, 9:28 AM

Details

Summary

Make sched_random() return an unsigned number, and use uint32_t
consistently. This also matches the per-cpu pointer declaration
anyway.

This changes the tweak we give to the load from -32..31 to be 0..63
which seems more inline with the rest of the code (- rnd and the -=
64). It should also provide the randomness we need, and may fix a
signedness bug in the old code (it isn't clear that the effect was
intentional as opposed to sloppy, and the right shift of a signed
value is undefined).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

imp retitled this revision from to Make sched_random() return an unsigned number..
imp updated this object.
imp edited the test plan for this revision. (Show Details)

Only return upper 16 bits from sched_random() and just mask out what
we need.

avg added inline comments.
sys/kern/sched_ule.c
367 ↗(On Diff #4018)

I think that the function name should be on a new line.

(inline)

sys/kern/sched_ule.c
722 ↗(On Diff #4018)

It is rather unusual to specify a bitmask as a decimal constant; 0x1f might be more clear.
I think this only returns a value in [0, 31], too, whereas the comment in the previous code says negative values are also possible.

In D1981#9, @bjk wrote:

(inline)

It's not clear that was intentional. It relied on undefined behavior to make it happen if it did. It could also
make some of the invariants wrong if it subtracted a negative number. I think it was just sloppiness in the
original implementation rather than something intentional.

I've change it to % 32, since that's what we really want and there's no constant for the 64 that's
based on.

sys/kern/sched_ule.c
367 ↗(On Diff #4018)

Yup. Had to make other changes, so this goes in too.

imp edited edge metadata.

Nits

bjk edited edge metadata.
This revision is now accepted and ready to land.Feb 27 2015, 7:39 PM
imp updated this revision to Diff 4022.

Closed by commit rS279373 (authored by @imp).