sched: calibrate setpriority() to match Linux's behavior

In our setpriority() implementation, we arbitrarily decided to map the
maximal nice value 20 to OSv priority 5, resulting in a maximally-nice
thread getting 1/5th of the runtime of a competing default thread.

However, it turns out (see test/misc-setpriority.cc) that on Linux,
a maximally-nice thread actually gets just 1/86th of the runtime that a
competing thread gets, not 1/5th. So to be more aligned to Linux's
behavior, this patch changes our setpriority()'s constant from 5 to 86.

After this patch, the test/misc-setpriority.cc benchmark now shows near
perfect agreement between the runtime ratio in OSv and Linux up to
about nice value -16 (where the runtime ratio to a competing default
thread is 35). There the two begin to slightly diverge, until at -20,
in Linux we get a ratio of 86 (as expected) but in OSv we get a ratio of
only 62.

Why do we get 62 and not 86 here? I.e., why does setting OSv priority=1/86
results in a thread that runs only 62 times more than a priority=1 thread,
and not 86 times more? The reason is the runtime decay mechanism and its
interaction with the hysteresis (minimum time slice) mechanism: While the
priority=1 thread runs normal time slices determined by the hysteresis
mechanism (about 4ms), the thread with priority 1/86 basically runs much
longer time slices (ideally, 86 times longer). During this very long time
slice, the other thread's runtime decays, so when we get back to it, we
run it longer than might be expected. We should probably fix this in the
future by adjusting the minimum time-slice to the load (in a machine with
load 87, like we have here, we probably need to use shorter time slices),
or adjusting the decay constant to the load.

This patch also makes the Java benchmark described in issue #438 behave
on OSv more like Linux. In Linux, the ratio between priority-10 and
priority-1 threads in that benchmark was 7.5. Before this patch, the
result in OSv is a ratio of only 2.0. After this patch, it is 7.0.

Fixes #438.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
apps: update

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>