Search code examples
iosswiftcpubackground-processdispatch

Which one is the performance cores in instruments?


When I'm running profile in instrument on iPhone X with A11 CPU. This CPU has two performance cores and four efficiency cores.

May I ask if there is a way to tell which one is the performance core? And as for the main thread, will GCD put main thread tasks more on the performance cores rather than the efficiency ones?

I'm very interested to understand how this actually works.

enter image description here


Solution

  • GCD doesn't know anything about different kind of cores and GCD also doesn't decide which code runs on which core.

    GCD decides which queue gets a thread of which thread pool and which code is scheduled to run next on the thread of the queue.

    Deciding when a thread will run and on which core it will run is done by the thread schedular of the kernel. And the kernel also decides how many threads are available in which GCD thread pool.

    The main thread is just a thread like any other thread. How much CPU time a thread gets depends on its own priority level, the amount of other threads, their priority levels, and the amount of workload scheduled for each of them.

    As the A11 allows all 6 cores to be active at the same time, the kernel will decide which thread gets a high performance core and which one just a low performance one. High priority threads and threads with high computation workload (those that want to run very often and usually use up their full runtime quantum when running) are preferred for high performance cores. Low priority threads and threads with little computation workload (those that want to run infrequently and very often yield/block although their runtime quantum hasn't been used up yet) are preferred for low performance cores. Though, in theory every thread can run on any core as it would be stupid to leave cores unused if threads are waiting to run, yet low power cores are generally preferred as that reduces power consumption and increases battery runtime.