CKRM CPU Scheduling 
===================

Overview
--------

In CKRM, cpu scheduling is based on a two level scheduling decision.
Every time a new task is to be selected, the scheduler first determines
which class to run next and then schedules the next task in selected
task.

Limit provided by the CKRM CPU scheduler is soft limit. i.e at any point
of time a class can get more than its limit, as long as guarantees of all
classes are satisfied.

The scheduling within a class is performed using the default Linux
O(1) scheduler.

The class scheduler also follows the O(1) principle and works as
follows: 

Each class maintains a local runqueue per cpu aka <struct
ckrm_runqueue> or short lrq. The existing O(1) scheduler is used to
schedule within an <lrq>.

Weights are assigned to each lrq that mirror the effectives shares of
that class. Every time a task executes, its weighted cycles are
charged against its class. Thus classes progress in time called
cummulative virtual time (CVT). In essence the class with the smallest
CVT is selected next. Provisions are made to keep interactivity and
to avoid starvation of the longer sleeping classes.

Load balancing across an SMP is performed by balancing the load of
the system across CPUs while maintaining each class's guarantee.

Due to the fact that CKRM uses a class hierarchy, cycles that are unused
by a class are redistributed to the class's busy children and then to the
class's busy siblings. Excess CPU cycles are allocated proportional to the
hungry class's limit.

Enabling the CKRM CPU scheduler
-------------------------------

The scheduler is integrated into the linux scheduler and therefore
can not be loaded dynamically like other CKRM schedulers.

However it can be selected at boot time or dynamically at run time.

The boot options "ckrmcpu" OR "nockrmcpu" enable / disable the CKRM
cpu scheduler at boot time. Currently by default the scheduler is
disabled.

# grep 'res=cpu' /rcfs/taskclass/config 

"res=cpu,mode=enabled" indicates that the CKRM cpu scheduler is
enabled

"res=cpu,mode=disabled" indicates that the CKRM cpu scheduler is
disabled

The strings can also be used to dynamically change the scheduling modus
at runtime. For example, to dynamically activate the scheduler.

# echo "res=cpu,mode=enabled" > /rcfs/taskclass/config

# cat /rcfs/taskclass/*/stats

The cpu portion of the scheduler is shown

    "cpu-usage(2,10,60)= 290 340 510"

The 3 numbers represent the load for the 2 second, 10 second 
and 60 seconds. The base = 1000.
Hence the system has 29.0%, 33.5% and 49.8% respectively

For debugging purposes additional information can be printed out but
that format should not be relied upon. 

Use `echo "res=cpu,usage_detail=3" for the highest detail on usage.
Please consult the source code for the specifics.

Assigning shares
----------------

Follows the general approach described under ckrm_basics.

# echo "res=cpu,guarantee=val" > /rcfs/taskclass/<classname>/shares

sets the minimum guarantee of the class.

# echo "res=cpu,limit=val" > /rcfs/taskclass/<classname>/shares

sets the soft limit of the class.
