runq: API tidy up: 'pri' => 'idx', 'idx' as int, remove runq_remove_idx()
Make sure that external and internal users are aware that the runqueue
API always expects queue indices, and not priority levels. Name
arithmetic arguments in 'runq.h' for better immediate reference.
Use plain integers to pass indices instead of 'u_char' (using the latter
probably doesn't bring any gain, and an 'int' makes the API agnostic to
a number of queues greater than 256). Add a static assertion that
RQ_NQS can't be strictly greater than 256 as long as the 'td_rqindex'
thread field is of type 'u_char'.
Add a new macro CHECK_IDX() that checks that an index is non-negative
and below RQ_NQS, and use it in all low-level functions (and "public"
ones when they don't need to call the former).
While here, remove runq_remove_idx(), as it knows a bit too much of
ULE's internals, in particular by treating the whole runqueue as
round-robin, which we are going to change. Instead, have runq_remove()
return whether the queue from which the thread was removed is now empty,
and leverage this information in tdq_runq_rem() (sched_ule(4)).
While here, re-implement runq_add() on top of runq_add_idx() to remove
its duplicated code (all lines except one). Introduce the new
RQ_PRI_TO_IDX() macro to convert a priority to a queue index, and use it
in runq_add() (many more uses will be introduced in later commits).
While here, rename runq_check() to runq_not_empty() and have it return
a boolean instead of an 'int', and same for sched_runnable() as an
impact (and while here, fix a small style violation in sched_4bsd(4)'s
version).
While here, simplify sched_runnable().
While here, make <sys/sched.h> standalone include-wise.
No functional change intended.
Reviewed by: kib
MFC after: 1 month
Event: Kitchener-Waterloo Hackathon 202506
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45387