Moving background threads to efficient cores
For next MBS Xojo Util Plugin, we add new functions to get and set the quality of service level for a thread:
GetQOSClassMBS as Integer
SetQOSClassMBS(QOS as Integer) as Integer
If your thread is marked with the highest level, usually named user interactive, the threads gets more attention and a better CPU core if available. On the other side the lower levels like background moves the thread to a lower priority and if possible a more efficient CPU core. All the levels between are scheduled on depending on the work load and what is available.
Inside the example file we can run a thread on a different cores. In our example we just count up a property. And we can measure the background thread counting to 42 while the faster cores count up to 178 in the same time.
For the QOS level, we have the following table with values from 1 (background) to 5 (interactive):
| Name | Value | Description |
|---|---|---|
| QOS_CLASS_USER_INTERACTIVE | 5 | The thread handles user input. |
| QOS_CLASS_USER_INITIATED | 4 | The user requested this action. |
| QOS_CLASS_DEFAULT | 3 | Default |
| QOS_CLASS_UTILITY | 2 | Utility thread running with reduced priority, e.g. menubar utility app. |
| QOS_CLASS_BACKGROUND | 1 | Background thread with reduced priority, e.g. backup. |
| QOS_CLASS_UNSPECIFIED | 0 | Unknown level. |
You may want to call SetQOSClassMBS(1) in your threads doing background tasks to inform the OS about your desired quality of service level. This way your application doing background things may use less battery on a portable computer.
For Linux and Windows we sets the priority for the thread to simulate similar QOS classes, so the function works cross platform. On macOS and iOS we pass the quality level directly to the thread scheduler.
Please try.