Bug 197922

Summary: [patch] [sched] Remove random() from sched_ule, add short circuit for non-SMP, non-balancing
Product: Base System Reporter: Harrison Grundy <harrison.grundy>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, fidaj, imp, jmg, koobs
Priority: --- Keywords: needs-qa, patch
Version: CURRENT   
Hardware: Any   
OS: Any   
URL: https://github.com/AstrodogInc/freebsd_schedulers/blob/master/ule_patches/remove_random_in_balance.diff
Attachments:
Description Flags
Replace random with get_cyclecount as a suitable source of entropy for the balancer. Short circuit for non-SMP/Balance
none
Remove randomness entirely.
none
Creates sched_random, using the system used in cpu_search.
none
Updated patch to create sched_random() to provide entropy in the scheduler.
none
No randomness in scheduler at all
none
Removes all scheduler randomness none

Description Harrison Grundy 2015-02-22 15:16:32 UTC
Created attachment 153317 [details]
Replace random with get_cyclecount as a suitable source of entropy for the balancer. Short circuit for non-SMP/Balance

As discovered by John-Mark Gurney, ULE uses random() which is not SMP/preemption safe. 

Move the check for SMP and Balancer being enabled above the generation of the balancing interval.
Comment 1 Harrison Grundy 2015-02-24 04:25:31 UTC
Created attachment 153415 [details]
Remove randomness entirely.

Some testing indicates that balancing here may not require any randomness at all.
Comment 2 Harrison Grundy 2015-02-25 09:40:20 UTC
Created attachment 153513 [details]
Creates sched_random, using the system used in cpu_search.

Another option.

If this doesn't work, I suppose we could put an actual PRNG in here, or bitshift get_cyclecount.
Comment 3 Ivan Klymenko 2015-02-25 10:01:15 UTC
Do I understand correctly that now patch " Remove randomness entirely." is no longer needed?
Comment 4 Harrison Grundy 2015-02-25 10:04:49 UTC
(In reply to Ivan Klymenko from comment #3)

Each of the 3 patches solves the problem in a slightly different way. There's some discussion on -arch about which approach makes the most sense here, so I was planning to just leave them up until a decision is made.
Comment 5 Harrison Grundy 2015-02-25 10:34:11 UTC
Created attachment 153514 [details]
Updated patch to create sched_random() to provide entropy in the scheduler.

Whoops. Forgot to have it "reseed". Thanks Konstantin Belousov.
Comment 6 Harrison Grundy 2015-02-25 10:40:50 UTC
Created attachment 153515 [details]
No randomness in scheduler at all
Comment 7 Harrison Grundy 2015-02-25 10:54:54 UTC
Created attachment 153516 [details]
Removes all scheduler randomness

Forgot the high group. One of those days...
Comment 8 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-07-06 22:21:59 UTC
sched_random() was committed in r279349 (by imp) and further refined afterwards.