sched: implement POSIX real-time scheduling

This patch is a quick experiment in adding real-time threads to OSv,
which can be used to implement Linux's SCHED_FIFO/SCHED_RR scheduling
policies.

The patch adds to each thread a _realtime._priority, an unsigned integer.
Normal (non-real-time) threads have _realtime._priority of 0, and are
time-shared fairly as before, while realtime threads have
_realtime._priority > 0, and preempt any thread with a lower realtime
priority, including all normal threads.

The patch adds a new API, t->set_realtime(priority, timeslice), to make
a thread real-time scheduled. The "priority" is an unsigned int as
explained above (0 means normal thread). The optional timeslice parameter
is the length of the time slice to let this thread run before switching
to the next thread with an equal priority (see Linux's SCHED_RR).
Timeslice defaults to 0 which means use the system default, and timeslice
-1 means no time slice (like Linux's SCHED_FIFO).

This patch is incomplete, for several reasons:

1. FIFO scheduling of same-realtime-priority threads not yet tested.
We need woken up threads to be in the runqueue *last* among the threads
which compare equal according to thread_runtime_compare. I didn't
check if this actually happens - probably will require small tweaks
to the insertion code.

2. Time slices not yet implemented. We need to keep in _realtime
the total time this thread ran since starting this slice (and
rescheduling deciding to keep the same thread, and when starting
to run a realtime thread with timeslice>=0, set a timer for when the
time slice will be expired.

3. Performance needs to be evaluated - we don't want this new feature
to slow down scheduling of normal threads.

4. Testing, testing, testing. Besides the included trivial test, I
didn't do any testing on this patch.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>

[claudio: changed some comments to mention POSIX instead of Linux
          when sensible; added a get_realtime method to query the
          realtime state]

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
libc: add RT sched API

implement the sched_ API using the OSv realtime scheduler
implementation.

This includes:

sched_setscheduler, sched_getscheduler,
sched_setparam, sched_getparam,
sched_get_priority_min, sched_get_priority_max,
and a stub for Linux-only sched_rr_get_interval.

They are implemented together as they are tightly
integrated, and one calls the other.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
sched: add explicit realtime policy state

trying to guess the exact policy as set with sched_setscheduler
from the current realtime state is not possible, and makes the
code unoptimal.
This change moves the setting of the non-RT priority inside
the set_realtime, which now deals with setting the right one
according to the passed POSIX policy.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>