[cores/sched] Refactor scheduling class assignment

The assignment of a task scheduling class depends on its priority as well
as the user-defined policy. So far, if a task has not RT priority it always
gets the CFS scheduling class assigned.

This patch makes the scheduling class assignment more modular by checking
RT priority as well as (eventually) the user-defined scheduling policy.
Thus it prepares the ground to add different scheduling policies in
between the RT and CFS ones.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>

BP2 ad3ee00 - [cores/sched] Refactor scheduling class assignment

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Add CBS load weight computations

The load weight assigned to tasks managed by the CBS policy are computed
similar to CFS class.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Add SCHED_CBS policy to core scheduler

Tasks with a SCHED_CBS policy are allowed to fork and the CBS scheduling
class is assigned to them.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix SE references

SE data related to CBS managed tasks are hosted by the task_struct.cbs
structure. This patch fixes some typos or incorrect references.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix HEAD enqueue enforcing

New (ready to run) SE _must_ be enqueued at the list head according to the
current round scheduling implementation.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix SE put/pick on sched_class changes

Once the RQ of a running task is changed we should consider the case of
such a task entering the CBS scheduler.
In that case, the task has not been scheduler for execution by the CBS
thus it is safer to request a new rescheduling to properly trigger the
CBS policy.

These changes are triggered so far by
- core::rt_mutex_setptio
- core::__sched_setscheduler
- core::sched_move_task
with all of them using this pattern:
1. put_prev_task
2. // updated scheduler and/or RQ
3. set_curr_task
4. enqueue_task

This patch provides this support:
A. trigger a rescheduling once a _running_ SE enter a CBS RQ
   => this allows the CBS policy to get control on the execution of this
      task and other RQ siblings
B. put just previously CBS scheduled entities
   indeed, if a running task is moved into CBS there is not need to stop
   and put the CBS entity

Thus, each time we enter the run_cbs_entity_stop and put_prev_cbs_entity
we are granted to being putting a previously CBS scheduled entity.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Use a more safe consistency check

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Add a set of consistency checks

These checks adds a run-time overhead and some of them could be removed
once the CBS scheduler has been proved to be reasonably stable.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Add some RQ accounting metadata

The number of rounds and re-initializations is tracked by this patch.
These counters could provides some interesting figures about the scheduler
behaviors.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Controller: Bugfix some constants initialization

This patch properly initialized some u32 constants.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Remove unused RQ parameter

The idle thread in Linux, differently than in Miosix, is managed by the
core scheduler. Thus, we don't need to setup a burst for the idle thread.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Debugging: add initial support

This patch integrates the /proc/sched_debug interface with a dump of
some of the most interesting data of each CBS RQ.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix fork callback

Once a new task is forked we reset all the CBS data apart from the load,
which is keept equal to the one of its parent.

TODO: check forking flags if the load should be reset to the default value.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Check for round being over

This adds a utility function to verify if the current round has completed.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Conditional compile BUG_ON conditions

Adds the possibility to remove BUG_ON conditions checking to eventually
remove all the non-functional overhead once the scheduler is considered
stable.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Move CBS statistics into dedicated structure

All the CBS related statistics are collected into a dedicated sub-structure
to easy code readability and eventuality conditionally compile them.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix entity dequeue

Instead of tracking prev and curr entities we track now prev and next entities
which is safer in case of current task being dequeued, e.g. because of it's
going to sleep.

Right now:
- curr always point to the current running entity, and it is reset on CPU
release
- next always point to the next entity to schedule in the current round, while
it is NULL once the current is also the last entity in this round.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Bugfix round time set-point

The set-point for the round time should be assigned as computed.

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Better rename cbs statistics collection method

Signed-off-by: Patrick Bellasi <derkling@gmail.com>
[core/sched/cbs] Add some more CBS statistics

Signed-off-by: Patrick Bellasi <derkling@gmail.com>