From 89b1916f96830b6b0135a98dd8739836cfc92c28 Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Fri, 16 Apr 2021 15:21:14 +0530 Subject: [PATCH 1/2] ANDROID: cgroup: Add android_rvh_cgroup_force_kthread_migration In Android GKI, CONFIG_FAIR_GROUP_SCHED is enabled [1] to help prioritize important work. Given that CPU shares of root cgroup can't be changed, leaving the tasks inside root cgroup will give them higher share compared to the other tasks inside important cgroups. This is mitigated by moving all tasks inside root cgroup to a different cgroup after Android is booted. However, there are many kernel tasks stuck in the root cgroup after the boot. It is possible to relax kernel threads and kworkers migrations under certain scenarios. However the patch [2] posted at upstream is not accepted. Hence add a restricted vendor hook to notify modules when a kernel thread is requested for cgroup migration. The modules can relax the restrictions forced by the kernel and allow the cgroup migration. [1] https://android.googlesource.com/kernel/common/+/f08f049de11c15a4251cb1db08cf0bee20bd9b59 [2] https://lore.kernel.org/lkml/1617714261-18111-1-git-send-email-pkondeti@codeaurora.org Bug: 184594949 Bug: 301261126 Change-Id: I445a170ba797c8bece3b4b59b7a42cdd85438f1f Signed-off-by: Pavankumar Kondeti [quic_dickey@quicinc.com: port to android-mainline kernel] Signed-off-by: Stephen Dickey (cherry picked from commit 7551a1a2a11f307f74ee5a1654843ef990b69d02) --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/cgroup.h | 4 ++++ kernel/cgroup/cgroup-internal.h | 3 ++- kernel/cgroup/cgroup-v1.c | 2 +- kernel/cgroup/cgroup.c | 11 ++++++++--- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 3852fc7543dff..a17eabcb75947 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -136,6 +136,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_update_sysfs); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_compl_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_set_task); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cgroup_force_kthread_migration); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_syscall_prctl_finished); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_uic_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_tm_command); diff --git a/include/trace/hooks/cgroup.h b/include/trace/hooks/cgroup.h index a50e6abc55ee7..b824197118f9a 100644 --- a/include/trace/hooks/cgroup.h +++ b/include/trace/hooks/cgroup.h @@ -23,6 +23,10 @@ DECLARE_HOOK(android_vh_cgroup_attach, TP_PROTO(struct cgroup_subsys *ss, struct cgroup_taskset *tset), TP_ARGS(ss, tset)); +DECLARE_RESTRICTED_HOOK(android_rvh_cgroup_force_kthread_migration, + TP_PROTO(struct task_struct *tsk, struct cgroup *dst_cgrp, bool *force_migration), + TP_ARGS(tsk, dst_cgrp, force_migration), 1); + DECLARE_RESTRICTED_HOOK(android_rvh_cpuset_fork, TP_PROTO(struct task_struct *p, bool *inherit_cpus), TP_ARGS(p, inherit_cpus), 1); diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h index 367b0a42ada90..892b770067b5b 100644 --- a/kernel/cgroup/cgroup-internal.h +++ b/kernel/cgroup/cgroup-internal.h @@ -251,7 +251,8 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader, void cgroup_attach_lock(bool lock_threadgroup); void cgroup_attach_unlock(bool lock_threadgroup); struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup, - bool *locked) + bool *locked, + struct cgroup *dst_cgrp); __acquires(&cgroup_threadgroup_rwsem); void cgroup_procs_write_finish(struct task_struct *task, bool locked) __releases(&cgroup_threadgroup_rwsem); diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index c6822bf6c918d..fed5bf717ce19 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -501,7 +501,7 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of, if (!cgrp) return -ENODEV; - task = cgroup_procs_write_start(buf, threadgroup, &locked); + task = cgroup_procs_write_start(buf, threadgroup, &locked, cgrp); ret = PTR_ERR_OR_ZERO(task); if (ret) goto out_unlock; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 52352aabef109..4f5074da14481 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -2921,10 +2921,12 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader, } struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup, - bool *threadgroup_locked) + bool *threadgroup_locked, + struct cgroup *dst_cgrp) { struct task_struct *tsk; pid_t pid; + bool force_migration = false; if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0) return ERR_PTR(-EINVAL); @@ -2955,13 +2957,16 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup, if (threadgroup) tsk = tsk->group_leader; + if (tsk->flags & PF_KTHREAD) + trace_android_rvh_cgroup_force_kthread_migration(tsk, dst_cgrp, &force_migration); + /* * kthreads may acquire PF_NO_SETAFFINITY during initialization. * If userland migrates such a kthread to a non-root cgroup, it can * become trapped in a cpuset, or RT kthread may be born in a * cgroup with no rt_runtime allocated. Just say no. */ - if (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY)) { + if (!force_migration && (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY))) { tsk = ERR_PTR(-EINVAL); goto out_unlock_threadgroup; } @@ -5148,7 +5153,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf, if (!dst_cgrp) return -ENODEV; - task = cgroup_procs_write_start(buf, threadgroup, &threadgroup_locked); + task = cgroup_procs_write_start(buf, threadgroup, &threadgroup_locked, dst_cgrp); ret = PTR_ERR_OR_ZERO(task); if (ret) goto out_unlock; From d96859ba8012783ffcc0a1e60c04d073a9c4ed3a Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Thu, 24 Aug 2023 11:30:19 -0700 Subject: [PATCH 2/2] ANDROID: abi_gki_aarch64_qcom: update abi symbols Add android_rvh_cgroup_force_migration and other symbols. Symbols added: __traceiter_android_rvh_cgroup_force_kthread_migration __tracepoint_android_rvh_cgroup_force_kthread_migration Bug: 184594949 Bug: 301261126 Change-Id: I8ffed8f422a33f141edc95d1b65a07b8fe30b424 Signed-off-by: Stephen Dickey (cherry picked from commit 5b0878fc616a66f63c0a84821591ff37ae133d7f) --- android/abi_gki_aarch64.stg | 28 ++++++++++++++++++++++++++++ android/abi_gki_aarch64_qcom | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 4b4e4a11b4b71..23edac82100ca 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -313129,6 +313129,14 @@ function { parameter_id: 0x18bd6530 parameter_id: 0x141e84b4 } +function { + id: 0x9bddb3a2 + return_type_id: 0x6720d32f + parameter_id: 0x18bd6530 + parameter_id: 0x1d19a9d5 + parameter_id: 0x18a16691 + parameter_id: 0x11cfee5a +} function { id: 0x9bddb929 return_type_id: 0x6720d32f @@ -327128,6 +327136,15 @@ elf_symbol { type_id: 0x9bc25990 full_name: "__traceiter_android_rvh_can_migrate_task" } +elf_symbol { + id: 0xbbd04d50 + name: "__traceiter_android_rvh_cgroup_force_kthread_migration" + is_defined: true + symbol_type: FUNCTION + crc: 0x94b3e68f + type_id: 0x9bddb3a2 + full_name: "__traceiter_android_rvh_cgroup_force_kthread_migration" +} elf_symbol { id: 0xc93c7d6d name: "__traceiter_android_rvh_check_preempt_tick" @@ -330395,6 +330412,15 @@ elf_symbol { type_id: 0x18ccbd2c full_name: "__tracepoint_android_rvh_can_migrate_task" } +elf_symbol { + id: 0xb208306e + name: "__tracepoint_android_rvh_cgroup_force_kthread_migration" + is_defined: true + symbol_type: OBJECT + crc: 0x0c180285 + type_id: 0x18ccbd2c + full_name: "__tracepoint_android_rvh_cgroup_force_kthread_migration" +} elf_symbol { id: 0x60b5a917 name: "__tracepoint_android_rvh_check_preempt_tick" @@ -385666,6 +385692,7 @@ interface { symbol_id: 0x144db0a1 symbol_id: 0x192bbbd5 symbol_id: 0xadc13d20 + symbol_id: 0xbbd04d50 symbol_id: 0xc93c7d6d symbol_id: 0x9d00b8f0 symbol_id: 0x5e9397c4 @@ -386029,6 +386056,7 @@ interface { symbol_id: 0xd7757253 symbol_id: 0x1e8a7e23 symbol_id: 0xfe3875f6 + symbol_id: 0xb208306e symbol_id: 0x60b5a917 symbol_id: 0x1dd402e6 symbol_id: 0x070d1e2a diff --git a/android/abi_gki_aarch64_qcom b/android/abi_gki_aarch64_qcom index fcebe5582b85a..dfbadd7041767 100644 --- a/android/abi_gki_aarch64_qcom +++ b/android/abi_gki_aarch64_qcom @@ -342,6 +342,7 @@ copy_from_kernel_nofault copy_page __copy_overflow + copy_page _copy_to_iter __cpu_active_mask cpu_bit_bitmap @@ -667,6 +668,7 @@ devm_rtc_allocate_device __devm_rtc_register_device devm_snd_soc_register_card + devm_snd_soc_register_component devm_thermal_of_cooling_device_register devm_thermal_of_zone_register devm_usb_get_phy_by_node @@ -854,8 +856,11 @@ drm_atomic_helper_commit_modeset_enables drm_atomic_helper_commit_planes __drm_atomic_helper_connector_destroy_state + drm_atomic_helper_connector_destroy_state __drm_atomic_helper_connector_duplicate_state + drm_atomic_helper_connector_duplicate_state __drm_atomic_helper_connector_reset + drm_atomic_helper_connector_reset __drm_atomic_helper_crtc_destroy_state __drm_atomic_helper_crtc_duplicate_state drm_atomic_helper_dirtyfb @@ -929,6 +934,7 @@ drm_dev_register drm_dev_unregister drm_display_mode_from_cea_vic + drm_do_get_edid drm_edid_duplicate drm_edid_get_monitor_name drm_edid_is_valid @@ -1331,6 +1337,7 @@ hci_uart_unregister_device hci_unregister_cb hci_unregister_dev + hdmi_audio_infoframe_init hex2bin hex_asc_upper hex_dump_to_buffer @@ -1900,9 +1907,13 @@ migrate_pages migrate_swap __migrate_task + mipi_dsi_attach mipi_dsi_create_packet mipi_dsi_dcs_set_display_brightness mipi_dsi_dcs_set_tear_off + mipi_dsi_detach + mipi_dsi_device_register_full + mipi_dsi_device_unregister mipi_dsi_host_register mipi_dsi_host_unregister misc_deregister @@ -2980,6 +2991,8 @@ smp_call_function_single smp_call_function_single_async snapshot_get_image_size + snd_ctl_add + snd_ctl_new1 snd_ctl_remove snd_hwdep_new snd_info_create_card_entry @@ -2988,7 +3001,12 @@ snd_info_register snd_interval_refine snd_jack_set_key + snd_pcm_add_chmap_ctls + snd_pcm_create_iec958_consumer_default + snd_pcm_fill_iec958_consumer + snd_pcm_fill_iec958_consumer_hw_params snd_pcm_format_width + snd_pcm_hw_constraint_eld _snd_pcm_hw_params_any snd_pcm_set_managed_buffer snd_pcm_std_chmaps @@ -3269,6 +3287,7 @@ __traceiter_android_rvh_before_do_sched_yield __traceiter_android_rvh_build_perf_domains __traceiter_android_rvh_can_migrate_task + __traceiter_android_rvh_cgroup_force_kthread_migration __traceiter_android_rvh_check_preempt_tick __traceiter_android_rvh_check_preempt_wakeup __traceiter_android_rvh_check_preempt_wakeup_ignore @@ -3413,6 +3432,7 @@ __tracepoint_android_rvh_before_do_sched_yield __tracepoint_android_rvh_build_perf_domains __tracepoint_android_rvh_can_migrate_task + __tracepoint_android_rvh_cgroup_force_kthread_migration __tracepoint_android_rvh_check_preempt_tick __tracepoint_android_rvh_check_preempt_wakeup __tracepoint_android_rvh_check_preempt_wakeup_ignore