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:
+-------- 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.
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.
For more information, see Scheduling policies in the entry for SchedCtl() in the QNX Neutrino C Library Reference.