This patchset takes advantage of the new per-task load tracking that isavailable in the kernel for packing the tasks in as few as possibleCPU/Cluster/Core. It has got 2 packing modes:-The 1st mode packs the small tasks when the system is not too busy. The maingoal is to reduce the power consumption in the low system load use cases byminimizing the number of power domain that are enabled but it also keeps thedefault behavior which is performance oriented.-The 2nd mode packs all tasks in as few as possible power domains in order toimprove the power consumption of the system but at the cost of possibleperformance decrease because of the increase of the rate of ressources sharingcompared to the default mode.

The packing is done in 3 steps (the last step is only applicable for theagressive packing mode):

The 1st step looks for the best place to pack tasks in a system according toits topology and it defines a 1st pack buddy CPU for each CPU if there is oneavailable. The policy for defining a buddy CPU is that we want to pack atlevels where a group of CPU can be power gated independently from others. Todescribe this capability, a new flag SD_SHARE_POWERDOMAIN has been introduced,that is used to indicate whether the groups of CPUs of a scheduling domainshare their power state. By default, this flag is set in all sched_domain inorder to keep unchanged the current behavior of the scheduler and only ARMplatform clears the SD_SHARE_POWERDOMAIN flag for MC and CPU level.

In a 2nd step, the scheduler checks the load average of a task which wakes upas well as the load average of the buddy CPU and it can decide to migrate thelight tasks on a not busy buddy. This check is done during the wake up becausesmall tasks tend to wake up between periodic load balance and asynchronouslyto each other which prevents the default mechanism to catch and migrate themefficiently. A light task is defined by a runnable_avg_sum that is less than20% of the runnable_avg_period. In fact, the former condition encloses 2 ones:The average CPU load of the task must be less than 20% and the task must havebeen runnable less than 10ms when it woke up last time in order to beelectable for the packing migration. So, a task than runs 1 ms each 5ms willbe considered as a small task but a task that runs 50 ms with a period of500ms, will not.Then, the business of the buddy CPU depends of the load average for the rq andthe number of running tasks. A CPU with a load average greater than 50% willbe considered as busy CPU whatever the number of running tasks is and thisthreshold will be reduced by the number of running tasks in order to notincrease too much the wake up latency of a task. When the buddy CPU is busy,the scheduler falls back to default CFS policy.

The 3rd step is only used when the agressive packing mode is enable. In thiscase, the CPUs pack their tasks in their buddy until they becomes full. Unlikethe previous step, we can't keep the same buddy so we update it during loadbalance. During the periodic load balance, the scheduler computes the activityof the system thanks the runnable_avg_sum and the cpu_power of all CPUs andthen it defines the CPUs that will be used to handle the current activity. Theselected CPUs will be their own buddy and will participate to the defaultload balancing mecanism in order to share the tasks in a fair way, whereas thenot selected CPUs will not, and their buddy will be the last selected CPU.The behavior can be summarized as: The scheduler defines how many CPUs arerequired to handle the current activity, keeps the tasks on these CPUS andperform normal load balancing (or any evolution of the current load balancerlike the use of runnable load avg from Alex https://lkml.org/lkml/2013/4/1/580)on this limited number of CPUs . Like the other steps, the CPUs are selected tominimize the number of power domain that must stay on.

Change since V3:

- Take into account comments on previous version. - Add an agressive packing mode and a knob to select between the various mode

Change since V2:

- Migrate only a task that wakes up - Change the light tasks threshold to 20% - Change the loaded CPU threshold to not pull tasks if the current number of running tasks is null but the load average is already greater than 50% - Fix the algorithm for selecting the buddy CPU.

Change since V1:

Patch 2/6 - Change the flag name which was not clear. The new name is SD_SHARE_POWERDOMAIN. - Create an architecture dependent function to tune the sched_domain flagsPatch 3/6 - Fix issues in the algorithm that looks for the best buddy CPU - Use pr_debug instead of pr_info - Fix for uniprocessorPatch 4/6 - Remove the use of usage_avg_sum which has not been mergedPatch 5/6 - Change the way the coherency of runnable_avg_sum and runnable_avg_period is ensuredPatch 6/6 - Use the arch dependent function to set/clear SD_SHARE_POWERDOMAIN for ARM platform

Previous results for v3:

This series has been tested with hackbench on ARM platform and the resultsdon't show any performance regression

The patch-set has been tested on ARM platforms: quad CA-9 SMP and TC2 HMP(dual CA-15 and 3xCA-7 cluster). For ARM platform, the results havedemonstrated that it's worth packing small tasks at all topology levels.

The performance tests have been done on both platforms with sysbench. Theresults don't show any performance regressions. These results are aligned withthe policy which uses the normal behavior with heavy use cases.

test: sysbench --test=cpu --num-threads=N --max-requests=R run

Results below is the average duration of 3 tests on the quad CA-9.default is the current scheduler behavior (pack buddy CPU is -1)pack is the scheduler with the pack mechanism

The power consumption tests have been done only on TC2 platform which has gotaccessible power lines and I have used cyclictest to simulate small tasks. Thetests show some power consumption improvements.

The A15 cluster is less power efficient than the A7 cluster but if we assumethat the tasks is well spread on both clusters, we can guest estimate that thepower consumption on a dual cluster of CA7 would have been for a defaultkernel: