We were cleaning up the scheduler when we found this in kernel/sched/fair.c:
#if !defined(CONFIG_MTK_LOAD_BALANCE_ENHANCEMENT) && defined(CONFIG_HMP)
/* for more than two clusters,
* we still need wakeup nohz CPUs and force balancing
*/
if (sched_feat(SCHED_HMP) && cpumask_first_and(nohz.idle_cpus_mask,
&(hmp_cpu_domain(cpu))->cpus) >= nr_cpu_ids)
return false;
#endif
That CONFIG_HMP symbol (not CONFIG_SCHED_HMP, what this tree actually defines) is not a real Kconfig option anywhere in this tree. The #ifdef is permanently false. These 14 lines have been compiled out, unreachable, since the day they were written.
We deleted them. Then we kept going.
What a CPU scheduler actually does
Before any of this makes sense, you need to know what a scheduler is.
Your phone has eight CPU cores. At any given moment it runs hundreds of processes: the launcher, the camera daemon, the audio stack, the kernel's own work threads, your app, the Android framework. There are far more tasks that want CPU time than there are CPUs to give it.
The scheduler is the kernel subsystem that decides which task runs on which CPU, and for how long, before being preempted and replaced. It runs thousands of times per second. Get it wrong and the phone is sluggish (something that needed a fast CPU is stuck on a slow one), or it runs hot and kills battery (background tasks sitting on power-hungry cores they don't need).
Linux's main scheduler is CFS (Completely Fair Scheduler). It was designed around one assumption: all CPUs are roughly equivalent. Give every task a fair share of available compute, weighted by priority.
On a phone, that assumption breaks immediately.
The hardware: mt6785 is not symmetric
The mt6785 (Helio G90T, inside begonia/Redmi Note 8 Pro) has two clusters of CPU cores that are completely different from each other.
The A75 (big) and A55 (LITTLE) have different maximum clocks and wildly different IPC (instructions per clock cycle). At the same frequency an A75 does roughly 2-3x the useful work of an A55, and draws significantly more power.
This creates a real scheduling problem. Run a background sync job on an A75 and you burn 3x the power you need to. Run your main UI thread on an A55 while the user scrolls and the animation stutters. The scheduler needs to route tasks to the right cluster, and stock CFS has no idea the asymmetry exists.
HMP: the first attempt (circa 2014)
ARM shipped the first big.LITTLE chip in 2013. The kernel had no cluster awareness. Vendors bolted on out-of-tree patches. The most widespread was HMP (Heterogeneous Multi-Processing).
HMP tracked each task's CPU load as a rolling average and defined "up" and "down" migration thresholds. Tasks above the threshold moved to big cores. Tasks below moved to LITTLE. It also had a boost mode: a global lever that overrides all thresholds and forces tasks to big cores immediately, used when the user touches the screen and you want maximum responsiveness.
The begonia tree had CONFIG_SCHED_HMP enabled, plus MediaTek's own layers on top: MTK_SCHED_BOOST, task_turbo, and set_sched_boost() which drivers could call to engage the boost.
It was better than treating all cores as equal. The problems were structural.
Thresholds were tuned by hand at build time. Conservative thresholds (protecting battery) meant interactive tasks ended up on LITTLE cores. Aggressive thresholds (maximizing responsiveness) meant background tasks sat on big cores burning power. No feedback loop, no way for the scheduler to verify its choices were actually efficient.
Boost was all-or-nothing. set_sched_boost(SCHED_ALL_BOOST) moved everything to big cores simultaneously: background sync, garbage collector, render thread. No proportionality.
And it was never upstream. Every security update, every scheduler fix from mainline meant rebasing against a patch series upstream had no interest in maintaining.
EAS: what replaced HMP
Energy Aware Scheduling landed in mainline Linux 5.0 (2019). Instead of static thresholds, EAS uses power models.
When a task wakes up, EAS estimates what frequency each candidate CPU would need to run at to handle existing load plus this new task, using PELT (Per-Entity Load Tracking). It looks up the OPP table from Device Tree to get the power cost at that frequency, computes the energy cost of each placement, and picks the cheapest one that still meets the task's performance requirement.
EAS is strictly better than HMP when its load tracking inputs are accurate. "What frequency will this CPU need" depends entirely on PELT numbers being correct, properly scaled for CPU capacity differences, accounting for thermal throttling, tracking runnable tasks at the right utilization level. Getting PELT right was a separate piece of this work, covered in the next post.
The dead code
Back to what we opened with. The dead code lived in nohz_kick_needed(), the function that decides whether to wake up idle CPUs to rebalance load.
#if !defined(CONFIG_MTK_LOAD_BALANCE_ENHANCEMENT) && defined(CONFIG_HMP)
if (sched_feat(SCHED_HMP) && cpumask_first_and(...) >= nr_cpu_ids)
return false;
#endif
This tree defines CONFIG_SCHED_HMP in defconfig. The block checks CONFIG_HMP. Two different symbols. CONFIG_HMP is referenced nowhere in this tree's Kconfig files; it was copied verbatim from a different vendor patch series that used a different symbol name. The preprocessor strips the block at compile time. Always has.
Commit acca769bc253:
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -11957,20 +11957,6 @@ static inline bool nohz_kick_needed(struct rq *rq, bool only_update)
if (time_before(now, nohz.next_balance))
return false;
-#if !defined(CONFIG_MTK_LOAD_BALANCE_ENHANCEMENT) && defined(CONFIG_HMP)
- /* for more than two clusters,
- * we still need wakeup nohz CPUs and force balancing
- *
- * Bail out if there are no nohz CPUs in our
- * HMP domain, since we will move tasks between
- * domains through wakeup and force balancing
- * as necessary based upon task load.
- */
- if (sched_feat(SCHED_HMP) && cpumask_first_and(nohz.idle_cpus_mask,
- &(hmp_cpu_domain(cpu))->cpus) >= nr_cpu_ids)
- return false;
-#endif
-
if (rq->nr_running >= 2 &&
(!energy_aware() || cpu_overutilized(cpu)))
return true;
Fourteen lines gone. No behavior change.
Replacing HMP boost with EAS uclamp
The real work was in cpufreq_mtk.c. When the cpufreq driver applied a minimum frequency limit for a cluster (say, a game requesting "keep big cores above 1.4 GHz"), the old code called:
#ifdef CONFIG_MTK_SCHED_BOOST
int sched_boost_type = (current_cpu_freq[cluster].min > 0 ...)
? SCHED_ALL_BOOST : SCHED_NO_BOOST;
set_sched_boost(sched_boost_type);
#endif
With HMP gone and EAS running, set_sched_boost() was a no-op. EAS does not know what HMP boost is.
To tell EAS about frequency requirements, you use uclamp (utilization clamping).
Each task in the kernel has a utilization value, a number from 0 to 1024 representing how much CPU capacity it needs (1024 = 100% of the fastest CPU). EAS uses this to estimate what frequency a CPU needs to serve the task. uclamp_min is a floor on this value: set it to 512 and the scheduler treats the task as needing at least 50% capacity even if it's currently idle. EAS then picks a placement that can deliver that.
Setting a system-wide uclamp_min floor (via sysctl_sched_uclamp_util_min) applies the floor to all tasks globally. That is the EAS equivalent of HMP all-boost: push the minimum utilization estimate up system-wide, EAS naturally routes tasks to placements that can meet it, which at high floor values means the big cluster.
The new code we added to kernel/sched/core.c and the cpufreq driver in commit 616786f12352:
static unsigned int cluster_uclamp_floor(int cluster)
{
unsigned int cpu, cap, max_freq;
if (current_cpu_freq[cluster].min <= 0)
return 0;
cpu = (cluster == BIG) ? topology.big_cpu_start : topology.ltl_cpu_start;
cap = topology_get_cpu_scale(NULL, cpu);
max_freq = topology_get_max_cpu_freq(NULL, cpu);
if (!cap || !max_freq)
return 0;
return mult_frac(cap, current_cpu_freq[cluster].min, max_freq);
}
The function converts a minimum frequency request into a utilization floor. mult_frac(cap, min_freq, max_freq) is linear scaling: if the driver requests min_freq = max_freq / 2, the floor is cap * 0.5. EAS uses that number directly in its placement math.
This commit also fixed a pre-existing bug in is_freq_valid(), the function that checks whether a given frequency exists in the cluster's OPP table. The original code had the logic completely backwards: valid inputs returned uninitialized stack garbage, and an invalid frequency (not in the table) was the only case where ret was set, and it was set to 1 (valid).
The fix:
-int is_freq_valid(int cluster, int freq) {
- int ret;
- if (freq == -1)
- goto out; /* ret never set, returns garbage */
- cpufreq_for_each_valid_entry(pos, cpuftbl[cluster]) {
- if (pos->frequency == freq)
- goto out; /* ret never set, returns garbage */
- }
- ret = 1; /* only reached when NOT found, backwards */
-out:
- return ret;
-}
+int is_freq_valid(int cluster, int freq) {
+ if (freq == -1)
+ return 1; /* no limit, always valid */
+ cpufreq_for_each_valid_entry(pos, cpuftbl[cluster]) {
+ if (pos->frequency == freq)
+ return 1;
+ }
+ return 0; /* not in table, invalid */
+}
The follow-up: baseline restore
sched_set_uclamp_min_floor(0) means "remove the floor." The first version zeroed sysctl_sched_uclamp_util_min on release.
Userspace can configure its own sched_uclamp_util_min via /proc/sys/kernel/sched_util_clamp_min. The driver setting and releasing a floor should leave that baseline alone; zeroing it on release silently wipes whatever userspace configured.
Fixed same day, commit 599b9db71cb4:
int sched_set_uclamp_min_floor(unsigned int value)
{
+ static unsigned int saved_min;
+ static bool floor_active;
+
if (value > SCHED_CAPACITY_SCALE)
return -EINVAL;
mutex_lock(&uclamp_mutex);
value = find_fit_capacity(value);
+ if (value) {
+ if (!floor_active) {
+ saved_min = sysctl_sched_uclamp_util_min;
+ floor_active = true;
+ }
+ if (value < saved_min)
+ value = saved_min; /* floor can't undercut baseline */
+ } else if (floor_active) {
+ value = saved_min; /* restore, not zero */
+ floor_active = false;
+ }
if (value != sysctl_sched_uclamp_util_min) {
On first activation: save the current baseline in saved_min. On release: restore it. The driver's floor layers over the userspace baseline rather than replacing it.
What changed
No dead HMP code in the idle-balance path. No call to a defunct set_sched_boost() from the cpufreq driver. A proper EAS-native frequency floor that feeds directly into EAS's placement math rather than working around it.
The frequency boost that previously worked by forcing tasks to big cores through HMP now works by telling EAS "here is a minimum utilization requirement" and letting it find the cheapest placement that satisfies it. Same outcome for heavy load. The difference is in the middle: HMP boost was binary, this is continuous and energy-aware.