android_kernel_msm-6.1_noth.../kernel/sched
Qais Yousef 4ed706c20a FROMLIST: sched/pi: Reweight fair_policy() tasks when inheriting prio
For fair tasks inheriting the priority (nice) without reweighting is
a NOP as the task's share won't change.

This is visible when running with PTHREAD_PRIO_INHERIT where fair tasks
with low priority values are susceptible to starvation leading to PI
like impact on lock contention.

The logic in rt_mutex will reset these low priority fair tasks into nice
0, but without the additional reweight operation to actually update the
weights, it doesn't have the desired impact of boosting them to allow
them to run sooner/longer to release the lock.

Apply the reweight for fair_policy() tasks to achieve the desired boost
for those low nice values tasks. Note that boost here means resetting
their nice to 0; as this is what the current logic does for fair tasks.

We need to re-instate ordering fair tasks by their priority order on the
waiter tree to ensure we inherit the top_waiter properly.

Handling of idle_policy() requires more code refactoring and is not
handled yet. idle_policy() are treated specially and only run when the
CPU is idle and get a hardcoded low weight value. Changing weights won't
be enough without a promotion first to SCHED_OTHER.

Tested with a test program that creates three threads.

	1. main thread that spawns high prio and low prio task and busy
	   loops

	2. low priority thread that holds a pthread_mutex() with
	   PTHREAD_PRIO_INHERIT protocol. Runs at nice +10. Busy loops
	   after holding the lock.

	3. high priority thread that holds a pthread_mutex() with
	   PTHREADPTHREAD_PRIO_INHERIT, but made to start after the low
	   priority thread. Runs at nice 0. Should remain blocked by the
	   low priority thread.

All tasks are pinned to CPU0.

Without the patch I can see the low priority thread running only for
~10% of the time which is what expected without it being boosted.

With the patch the low priority thread runs for ~50% which is what
expected if it gets boosted to nice 0.

I modified the test program logic afterwards to ensure that after
releasing the lock the low priority thread goes back to running for 10%
of the time, and it does.

Bug: 263876335
Link: https://lore.kernel.org/lkml/20240514160711.hpdg64grdwc43ux7@airbuntu/
Reported-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Qais Yousef <qyousef@layalina.io>
[Fix trivial conflict with vendor hook]
Signed-off-by: Qais Yousef <qyousef@google.com>
Change-Id: Ia954ee528495b5cf5c3a2157c68b4a757cef1f83
(cherry picked from commit 23ac35ed8fc6220e4e498a21d22a9dbe67e7da9b)
Signed-off-by: Qais Yousef <qyousef@google.com>
2024-05-18 19:08:51 +00:00
..
autogroup.c sched/all: Change all BUG_ON() instances in the scheduler to WARN_ON_ONCE() 2022-08-12 11:25:10 +02:00
autogroup.h sched/headers: Add header guard to kernel/sched/stats.h and kernel/sched/autogroup.h 2022-02-23 08:22:00 +01:00
build_policy.c sched: Fix missing prototype warnings 2022-05-01 10:03:43 +02:00
build_utility.c sched: Fix missing prototype warnings 2022-05-01 10:03:43 +02:00
clock.c sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote} 2022-05-19 23:46:09 +02:00
completion.c sched/completion: Add wait_for_completion_state() 2022-09-07 21:53:49 +02:00
core.c FROMLIST: sched/pi: Reweight fair_policy() tasks when inheriting prio 2024-05-18 19:08:51 +00:00
core_sched.c sched: Rename task_running() to task_on_cpu() 2022-09-07 21:53:47 +02:00
cpuacct.c Merge branch 'sched/fast-headers' into sched/core 2022-03-15 09:05:05 +01:00
cpudeadline.c sched/core: Introduce sched_asym_cpucap_active() 2022-08-02 12:32:45 +02:00
cpudeadline.h
cpufreq.c ANDROID: android: Export symbols for invoking cpufreq_update_util() 2023-05-18 20:39:10 +00:00
cpufreq_schedutil.c Merge 6.1.60 into android14-6.1-lts 2023-11-03 16:23:47 +00:00
cpupri.c Merge 6.1.56 into android14-6.1-lts 2023-10-27 09:17:04 +00:00
cpupri.h
cputime.c ANDROID: vendor_hooks: Add hooks for account irqtime process tick 2023-05-19 19:41:20 +00:00
deadline.c sched: Fix stop_one_cpu_nowait() vs hotplug 2023-11-20 11:51:50 +01:00
debug.c Merge 0192445cb2 ("arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER") into android-mainline 2022-10-20 11:55:38 +02:00
fair.c ANDROID: Export sysctl_sched_wakeup_granularity to enable modifying it 2024-05-14 23:31:22 +00:00
features.h sched/fair: Introduce SIS_UTIL to search idle CPU based on sum of util_avg 2022-06-28 09:08:30 +02:00
idle.c kernel/sched: Modify initial boot task idle setup 2023-10-06 14:57:02 +02:00
isolation.c sched/headers: Introduce kernel/sched/build_utility.c and build multiple .c files there 2022-02-23 10:58:33 +01:00
loadavg.c sched/headers: Introduce kernel/sched/build_utility.c and build multiple .c files there 2022-02-23 10:58:33 +01:00
Makefile ANDROID: subsystem-specific vendor_hooks.c for sched 2022-09-07 20:00:36 +00:00
membarrier.c sched/headers: Introduce kernel/sched/build_utility.c and build multiple .c files there 2022-02-23 10:58:33 +01:00
pelt.c ANDROID: sched: Add vendor hook for update_load_sum 2023-11-29 21:33:45 +00:00
pelt.h FROMLIST: sched/pelt: Introduce PELT multiplier 2023-01-05 18:15:33 +08:00
psi.c ANDROID: Roll back some code to fix system_server registers psi trigger failed. 2024-01-22 23:38:15 +00:00
rt.c ANDROID: Move cpu_busy_with_softirqs() into sched.h 2024-04-04 02:42:42 +00:00
sched-pelt.h
sched.h ANDROID: Zap kernel/sched/android.h stubs 2024-05-16 14:00:33 +00:00
smp.h smp: Rename flush_smp_call_function_from_idle() 2022-05-01 10:03:43 +02:00
stats.c sched/headers: Introduce kernel/sched/build_utility.c and build multiple .c files there 2022-02-23 10:58:33 +01:00
stats.h sched/psi: Add PSI_IRQ to track IRQ/SOFTIRQ pressure 2022-09-09 11:08:32 +02:00
stop_task.c sched: Add update_current_exec_runtime helper 2022-08-27 00:05:35 +02:00
swait.c sched/headers: Introduce kernel/sched/build_utility.c and build multiple .c files there 2022-02-23 10:58:33 +01:00
topology.c ANDROID: sched: Export sched_domains_mutex for lockdep 2023-07-15 01:15:00 +00:00
vendor_hooks.c ANDROID: sched/cpuset: Add vendor hook to change tasks affinity 2024-02-28 18:04:33 +00:00
wait.c UPSTREAM: sched/wait: Fix a kthread_park race with wait_woken() 2024-03-28 00:24:19 +00:00
wait_bit.c wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00