CPU offlining
The CPU offlining feature allows a privileged application to stop procnto from using a CPU for scheduling threads.
This feature is useful for the following:
- Powering down a CPU (e.g., for lower workloads).
- Temporarily running software outside of the QNX OS (e.g., CPU diagnostics).
- Putting the system to sleep.
The privileged application runs a high priority thread (that can't be preempted) and tells procnto to stop using the CPU. This allows the thread to do its work outside of the QNX OS. Note that when procnto isn't using the CPU, OS functionalities aren't available because any action that may cause the thread to context switch can make the system unstable.
Setting the clock IST priority
To take a CPU offline, you must use procnto's -C option to lower the clock Interrupt Service Thread (IST) to a maximum of 253. You need to leave a gap between the priorities of the clock IST and the interprocessor interrupt (IPI) IST (i.e., 255).
Taking a CPU offline
- Set its processor affinity (affinity runmask) to one that represents the CPU to take offline (it should be the only CPU in the runmask.) (For more information, go to the ThreadCtl() entry in the QNX OS C Library Reference.)
- Using a call to pthread_setschedparam() or SchedSet(), set:
- the thread's scheduling policy to SCHED_OFFLINING, and
- its scheduling priority to a value greater than that of any thread that can run on the processor, with the exception of the IPI IST.
Note:- The application must have the runstate ability enabled to set the scheduling policy.
(For more information, go to
Abilities Reference
in the QNX OS System Security guide.) - An application needs a thread with the SCHED_OFFLINING policy set for every CPU being taken offline.
- While the priority of a thread that takes a CPU offline is
higher than the clock IST priority, only some QNX C library
functions are allowed (go to
Thread priority and QNX C library functions
).
- Offload the software timers queued on the CPU being taken offline to another
CPU via a TimerDelegate()
call with the _NTO_TIMER_DELEGATE action set. The CPU that
the application delegates its timers to must be online.Delegating timers is optional:
- In cases where the CPU is taken offline for a duration that is less than the application's timer tolerance. For example, running CPU diagnostics that take tens of microseconds.
- If all CPUs are being taken offline.
- Instruct the scheduler to stop scheduling other threads on the CPU being taken offline via a SchedCtl() call with the SCHED_PROCESSOR_OFFLINE command set.
Bringing a CPU back online
- Reclaim the CPU's timers via a TimerDelegate() call with the _NTO_TIMER_RECLAIM action set.
- Mark the CPU as online via a SchedCtl() call with the SCHED_PROCESSOR_ONLINE command set.
- Set its scheduling policy to SCHED_FIFO and return its priority to a value that's lower than the clock IST’s priority.
Thread priority and QNX C library functions
- TimerDelegate() with NTO_TIMER_DELEGATE or NTO_TIMER_RECLAIM
- SchedCtl() with SCHED_PROCESSOR_OFFLINE or SCHED_PROCESSOR_ONLINE
- InterruptDisable()
- InterruptEnable()
- ClockCycles()
- clock_gettime*() with CLOCK_MONOTONIC or CLOCK_REALTIME
- atomic_*()
The thread must set its scheduling policy to SCHED_FIFO and its priority below that of the clock IST's priority prior to calling any other QNX C library functions, changing its runmask, or exiting.
