Free time

Free time occurs when one partition isn't running. The thread scheduler then gives that partition's time to other running partitions. If the other running partitions demand enough time, they're allowed to run over budget.

If a partition opportunistically goes over budget, it must pay back the borrowed time, but only as much as the scheduler remembers (i.e. only the borrowing that occurred in the last window).

For example, suppose we have these partitions:

Because the System partition demands no time, its budgeted time becomes free time. If you're using the default scheduling policy (SCHED_APS_SCHEDPOL_DEFAULT), the thread scheduler distributes the remaining time to the highest-priority thread in the system. In this case, that's the infinite-loop thread in partition Pb. So the output of the aps show command may be:

                    +-------- CPU Time -------+-- Critical Time --
Partition name   id | Budget |  Max |    Used | Budget |      Used
--------------------+-------------------------+-------------------
System            0 |    70% | 100% |   0.11% |  200ms |   0.000ms
Pa                1 |    20% | 100% |  20.02% |    0ms |   0.000ms
Pb                2 |    10% | 100% |  79.83% |    0ms |   0.000ms
--------------------+-------------------------+-------------------
Total               |   100% |      |  99.95% |

In this example, partition Pa receives its guaranteed minimum of 20%, but all of the free time is given to partition Pb. This is because the thread scheduler chooses between partitions strictly by priority, as long as no partition is being limited to its budget. This strategy ensures the most realtime behavior.

But, there may be circumstances when you don't want partition Pb to receive all of the free time just because it has the highest-priority thread. For example, you might be using Pb to encapsulate an untrusted or third-party application. In such cases, you might want to use SchedCtl() or the aps modify -S command to specify a different scheduling policy:

SCHED_APS_SCHEDPOL_FREETIME_BY_RATIO
aps modify -S freetime_by_ratio
Divide free time based on the ratios of the budgets of the busy partitions. In our example, freetime-by-ratio mode might cause the aps show command to display:
                    +-------- CPU Time -------+-- Critical Time --
Partition name   id | Budget |  Max |    Used | Budget |      Used
--------------------+-------------------------+-------------------
System            0 |    70% | 100% |   0.04% |  200ms |   0.000ms
Pa                1 |    20% | 100% |  65.96% |    0ms |   0.000ms
Pb                2 |    10% | 100% |  33.96% |    0ms |   0.000ms
--------------------+-------------------------+-------------------
Total               |   100% |      |  99.96% |

which indicates that in freetime-by-ratio mode, the thread scheduler divides free time between partitions Pa and Pb in roughly a 2:1 ratio, which is the ratio of their budgets.

SCHED_APS_SCHEDPOL_PARTITION_LOCAL_PRIORITIES
aps modify -S partition_local_priorities
Schedule purely by budget ratio; the scheduler tries to balance budgets on as short a timescale as possible, regardless of the window size. That means high-priority partitions with large budgets don't run to completion (while they have budget); they're timesliced with other partitions, even low-priority ones. This policy can reduce the latencies seen by small budget partitions in a loaded system, but you won't get the strict priority preemptive behavior that happens when all partitions have budget (i.e., the default policy).

This option includes the behavior of SCHED_APS_SCHEDPOL_FREETIME_BY_RATIO.

When a critical thread consumes critical time, it temporarily forces a return to the default scheduling policy. Critical threads are allowed to run to completion and aren't timesliced by SCHED_APS_SCHEDPOL_PARTITION_LOCAL_PRIORITIES's attempts to balance budgets. In other words, critical threads aren't affected by this policy.

Note: Don't use this scheduling policy if you have running threads in a zero-budget partition. Since this policy divides time by the ratio of budgets, a zero-budget partition may never be scheduled.
SCHED_APS_SCHEDPOL_LIMIT_CPU_USAGE
aps modify -S limit_cpu_usage
Enforce the max_budget_percent parameters, which limit the amount a partition can overrun its normal budget when the system is underloaded. If this option isn't set, max_budget_percent is ignored when you're setting parameters, and is reported as 100% (meaning no limit on freetime usage).
Note: Threads in a partition with a normal budget of 0 and a max_budget_percent of 0 will never run.

For more information, see Scheduling policies in the entry for SchedCtl() in the QNX Neutrino C Library Reference.