From bbec2c993ef030f656f2945f708c29e40fcdc19d Mon Sep 17 00:00:00 2001 From: bengris32 Date: Fri, 5 May 2023 22:57:31 +0100 Subject: [PATCH] [SQUASH] treewide: Remove useless oplus bloat * Drop a BUNCH of useless oplus drivers, "features", loggers and other useless mods. Signed-off-by: bengris32 Change-Id: I5133459af68c9cabbbfe729c417e5d903375413a --- Kconfig | 6 - Makefile | 5 - OplusKernelEnvConfig.mk | 58 +- arch/arm64/mm/fault.c | 6 - block/Kconfig | 5 - block/Makefile | 4 - block/blk-core.c | 56 - block/blk-flush.c | 16 - block/blk-sysfs.c | 46 - block/blk.h | 24 - block/elevator.c | 31 - block/foreground_io_opt/Kconfig | 9 - block/foreground_io_opt/Makefile | 4 - block/foreground_io_opt/foreground_io_opt.c | 165 -- block/foreground_io_opt/foreground_io_opt.h | 28 - block/foreground_io_opt/high_prio_task.c | 92 - .../trace/foreground_io_opt_trace.h | 43 - block/scsi_ioctl.c | 21 - drivers/android/binder.c | 892 +----- drivers/android/binder_alloc.c | 42 - drivers/android/binder_alloc.h | 10 - drivers/block/zram/Kconfig | 48 - drivers/block/zram/Makefile | 5 - drivers/block/zram/hybridswap/hybridswap.h | 98 - .../zram/hybridswap/hybridswap_akcompress.c | 575 ---- .../block/zram/hybridswap/hybridswap_area.c | 699 ----- .../block/zram/hybridswap/hybridswap_area.h | 50 - .../block/zram/hybridswap/hybridswap_core.c | 1008 ------- .../block/zram/hybridswap/hybridswap_ctrl.c | 678 ----- .../zram/hybridswap/hybridswap_internal.h | 561 ---- .../block/zram/hybridswap/hybridswap_list.c | 323 --- .../block/zram/hybridswap/hybridswap_list.h | 67 - .../zram/hybridswap/hybridswap_lru_rmap.c | 293 -- .../zram/hybridswap/hybridswap_lru_rmap.h | 22 - .../block/zram/hybridswap/hybridswap_main.c | 1035 ------- .../zram/hybridswap/hybridswap_manager.c | 1069 ------- .../block/zram/hybridswap/hybridswap_perf.c | 351 --- .../zram/hybridswap/hybridswap_schedule.c | 724 ----- .../block/zram/hybridswap/hybridswap_stats.c | 482 --- .../block/zram/hybridswap/hybridswap_swapd.c | 1975 ------------- drivers/block/zram/zram_drv.c | 221 -- drivers/block/zram/zram_drv.h | 18 +- drivers/block/zram/zram_drv_internal.h | 4 - drivers/cpufreq/cpufreq.c | 9 - drivers/cpufreq/cpufreq_times.c | 6 - drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 6 - drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 8 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 6 - drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 6 - drivers/gpu/drm/mediatek/mtk_drm_fb.c | 6 - drivers/gpu/drm/mediatek/mtk_dsi.c | 19 - ...us21851_samsung_ams643ag01_1080p_dsi_cmd.c | 6 - drivers/input/keyboard/mediatek/kpd.c | 13 - .../input/keyboard/mediatek/mt6893/hal_kpd.c | 8 - drivers/mfd/mt6358-misc.c | 17 - drivers/misc/Kconfig | 1 - drivers/misc/Makefile | 2 - .../misc/mediatek/adsp/mt6853/adsp_excep.c | 7 - .../misc/mediatek/adsp/mt6885/adsp_excep.c | 11 - .../misc/mediatek/aee/mrdump/mrdump_panic.c | 40 - .../power/cpufreq_v1/src/mtk_cpufreq_hybrid.c | 6 - .../power/cpufreq_v1/src/mtk_cpufreq_main.c | 7 - .../power/cpufreq_v2/src/mtk_cpufreq_main.c | 4 - .../mediatek/cmdq/mailbox/cmdq-sec-mailbox.c | 7 - .../connectivity/wlan/core/gen4m/Makefile | 18 - .../core/gen4m/oplus_wfd/wlan_oplus_wfd.c | 336 --- .../wlan/core/gen4m/os/linux/gl_init.c | 25 - .../misc/mediatek/eccci/fsm/mdee_dumper_v3.c | 58 - .../misc/mediatek/eccci/fsm/mdee_dumper_v3.h | 6 - .../misc/mediatek/eccci/fsm/mdee_dumper_v5.c | 65 - .../misc/mediatek/eccci/fsm/mdee_dumper_v5.h | 6 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 19 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 19 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 18 - .../mtk_platform_common/mtk_platform_common.c | 36 - .../misc/mediatek/gud/500/MobiCoreDriver/nq.c | 19 +- .../misc/mediatek/include/mt-plat/mtk_rtc.h | 6 - .../include/mt-plat/mtk_rtc_hal_common.h | 3 - drivers/misc/mediatek/mlog/mlog_logger.c | 22 - .../fpsgo_v3/fbt/include/fbt_usedext.h | 6 - .../performance/fpsgo_v3/fbt/src/fbt_cpu.c | 20 - .../misc/mediatek/rtc/mt6358/mtk_rtc_hal.c | 3 - drivers/misc/mediatek/rtc/mtk_rtc_common.c | 11 - drivers/misc/mediatek/sched/sched_ctl.c | 36 +- .../sensor/2.0/oplus_sensor_devinfo/Kconfig | 5 - .../sensor/2.0/oplus_sensor_devinfo/Makefile | 1 - .../oplus_sensor_feedback/Makefile | 2 - .../oplus_sensor_feedback/sensor_feedback.c | 607 ---- .../oplus_sensor_feedback/sensor_feedback.h | 159 - .../sensors-1.0/oplus_sensor_devinfo/Makefile | 1 - .../oplus_sensor_feedback/Makefile | 2 - .../oplus_sensor_feedback/sensor_feedback.c | 607 ---- .../oplus_sensor_feedback/sensor_feedback.h | 159 - .../oplus/oplus_display_alwaysondisplay.c | 1 - .../misc/oplus/oplus_display_private_api.c | 997 ++++--- drivers/misc/oplus_misc_healthinfo/Kconfig | 8 - drivers/misc/oplus_misc_healthinfo/Makefile | 1 - .../oplus_misc_healthinfo.c | 368 --- .../oplus_misc_healthinfo.h | 44 - drivers/mmc/core/bus.c | 12 - drivers/mmc/core/core.c | 27 - drivers/mmc/core/sd.c | 7 - drivers/mmc/host/mediatek/ComboA/sd.c | 26 - drivers/mmc/host/sdInfo/sdinfo.c | 108 - drivers/of/of_reserved_mem.c | 12 - drivers/power/oplus/oplus_charger.c | 6 - drivers/power/oplus/oplus_debug_info.c | 131 - drivers/power/oplus/oplus_debug_info.h | 8 - drivers/scsi/ufs/ufs-mtk.c | 3 - drivers/soc/Kconfig | 25 - drivers/soc/Makefile | 28 - drivers/soc/mediatek/mtk-cmdq-helper.c | 8 - drivers/soc/oplus/healthinfo/Kconfig | 16 - drivers/soc/oplus/healthinfo/Makefile | 3 - drivers/soc/oplus/healthinfo/healthinfo.c | 1195 -------- drivers/soc/oplus/healthinfo/healthinfo.h | 138 - drivers/soc/oplus/iomonitor/Kconfig | 15 - drivers/soc/oplus/iomonitor/Makefile | 9 - drivers/soc/oplus/iomonitor/console.c | 158 - .../soc/oplus/iomonitor/include/iomonitor.h | 263 -- drivers/soc/oplus/iomonitor/include/iotrace.h | 23 - drivers/soc/oplus/iomonitor/iomonitor.c | 1683 ----------- drivers/soc/oplus/iomonitor/iotrace.c | 1109 ------- drivers/soc/oplus/iomonitor/uid_status.c | 501 ---- drivers/soc/oplus/lowmem_dbg/Kconfig | 8 - drivers/soc/oplus/lowmem_dbg/Makefile | 37 - drivers/soc/oplus/lowmem_dbg/lowmem_dbg.c | 912 ------ drivers/soc/oplus/lowmem_dbg/lowmem_dbg.h | 20 - drivers/soc/oplus/lowmem_dbg/lowmem_dbg_5.4.c | 784 ----- drivers/soc/oplus/midas/Kconfig | 22 - drivers/soc/oplus/midas/Makefile | 6 - drivers/soc/oplus/midas/v1/Makefile | 15 - drivers/soc/oplus/midas/v1/binder_stats_dev.c | 1160 -------- drivers/soc/oplus/midas/v1/dispcap_dev.c | 465 --- drivers/soc/oplus/midas/v1/midas_dev.c | 336 --- drivers/soc/oplus/midas/v1/midas_dev.h | 73 - drivers/soc/oplus/midas/v1/midas_ioctl.c | 287 -- .../oplus/midas/v1/vpu_pw_off_latency_proc.c | 95 - drivers/soc/oplus/midas/v1_gki/Makefile | 10 - .../soc/oplus/midas/v1_gki/binder_stats_dev.c | 1451 --------- drivers/soc/oplus/midas/v1_gki/dispcap_dev.c | 465 --- drivers/soc/oplus/midas/v1_gki/midas_dev.c | 332 --- drivers/soc/oplus/midas/v1_gki/midas_dev.h | 76 - drivers/soc/oplus/midas/v1_gki/midas_ioctl.c | 331 --- drivers/soc/oplus/midas/v1_gki/midas_module.c | 32 - .../midas/v1_gki/vpu_pw_off_latency_proc.c | 95 - drivers/soc/oplus/midas/v2/Makefile | 12 - drivers/soc/oplus/midas/v2/binder_stats_dev.c | 1466 ---------- drivers/soc/oplus/midas/v2/dispcap_dev.c | 465 --- drivers/soc/oplus/midas/v2/midas_cpu.c | 165 -- drivers/soc/oplus/midas/v2/midas_cpu.h | 54 - drivers/soc/oplus/midas/v2/midas_dev.c | 385 --- drivers/soc/oplus/midas/v2/midas_dev.h | 61 - drivers/soc/oplus/midas/v2/midas_ioctl.c | 127 - drivers/soc/oplus/midas/v2/midas_mem.c | 107 - drivers/soc/oplus/midas/v2/midas_mem.h | 41 - drivers/soc/oplus/midas/v2/midas_module.c | 32 - .../oplus/midas/v2/vpu_pw_off_latency_proc.c | 95 - .../soc/oplus/oplus_als_cali_value/Makefile | 2 +- drivers/soc/oplus/oplus_criticallog/Kconfig | 4 - drivers/soc/oplus/oplus_criticallog/Makefile | 4 - .../oplus_criticallog/criticallog_class.c | 167 -- .../oplus_criticallog/criticallog_class.h | 51 - .../oplus_criticallog/oplus_criticallog.c | 103 - drivers/soc/oplus/oplus_nandswap/Kconfig | 12 - drivers/soc/oplus/oplus_nandswap/Makefile | 1 - drivers/soc/oplus/oplus_nandswap/nandswap.h | 39 - .../soc/oplus/oplus_nandswap/nandswap_core.c | 1591 ---------- drivers/soc/oplus/system/Kconfig | 50 - drivers/soc/oplus/system/Makefile | 47 - drivers/soc/oplus/system/acm/Kconfig | 18 - drivers/soc/oplus/system/acm/Makefile | 1 - drivers/soc/oplus/system/acm/acm.c | 1863 ------------ drivers/soc/oplus/system/acm/acm.h | 190 -- .../soc/oplus/system/dump_device_info/Kconfig | 7 - .../oplus/system/dump_device_info/Makefile | 3 - .../dump_device_info/dump_device_info.c | 263 -- drivers/soc/oplus/system/dump_reason/Kconfig | 7 - drivers/soc/oplus/system/dump_reason/Makefile | 3 - .../oplus/system/dump_reason/dump_reason.c | 101 - drivers/soc/oplus/system/feedback/Kconfig | 8 - drivers/soc/oplus/system/feedback/Makefile | 13 - drivers/soc/oplus/system/feedback/gki/Kconfig | 10 - .../soc/oplus/system/feedback/gki/kernel_fb.c | 697 ----- drivers/soc/oplus/system/feedback/kernel_fb.c | 687 ----- .../system/feedback/oplus_fb_guard_netlink.h | 64 - drivers/soc/oplus/system/full_aging/Kconfig | 7 - .../oplus/system/hung_task_enhance/Kconfig | 17 - .../oplus/system/hung_task_enhance/Makefile | 12 - .../system/hung_task_enhance/gki/Kconfig | 17 - .../hung_task_enhance/gki/hung_task_enhance.c | 284 -- .../hung_task_enhance/hung_task_enhance.c | 295 -- drivers/soc/oplus/system/include/boot_mode.h | 39 - .../soc/oplus/system/include/device_info.h | 15 - .../soc/oplus/system/include/dump_reason.h | 27 - .../oplus/system/include/hung_task_enhance.h | 33 - drivers/soc/oplus/system/include/kernel_fb.h | 39 - .../system/include/oplus_brightscreen_check.h | 11 - .../soc/oplus/system/include/oplus_bscheck.h | 11 - .../oplus/system/include/oplus_mm_kevent_fb.h | 93 - .../soc/oplus/system/include/oplus_signal.h | 30 - .../oplus/system/include/oplus_sync_time.h | 74 - .../soc/oplus/system/include/oppo_process.h | 103 - drivers/soc/oplus/system/include/proc.h | 21 - .../system/include/qcom_minidump_enhance.h | 18 - .../soc/oplus/system/include/qcom_pmicwd.h | 25 - .../soc/oplus/system/include/uboot_utils.h | 163 -- drivers/soc/oplus/system/mdmrst/Kconfig | 6 - drivers/soc/oplus/system/mdmrst/Makefile | 3 - .../soc/oplus/system/mdmrst/oplus_mdmrst.c | 174 -- .../soc/oplus/system/mm_osvelte/CHANGELOG.md | 45 - drivers/soc/oplus/system/mm_osvelte/Kconfig | 5 - drivers/soc/oplus/system/mm_osvelte/Makefile | 11 - drivers/soc/oplus/system/mm_osvelte/VERSION | 1 - drivers/soc/oplus/system/mm_osvelte/common.h | 31 - drivers/soc/oplus/system/mm_osvelte/logger.c | 885 ------ drivers/soc/oplus/system/mm_osvelte/logger.h | 106 - .../soc/oplus/system/mm_osvelte/lowmem-dbg.c | 613 ---- .../soc/oplus/system/mm_osvelte/lowmem-dbg.h | 10 - drivers/soc/oplus/system/mm_osvelte/memstat.h | 29 - .../oplus/system/mm_osvelte/proc-memstat.c | 279 -- .../oplus/system/mm_osvelte/proc-memstat.h | 153 - .../soc/oplus/system/mm_osvelte/sys-memstat.c | 382 --- .../soc/oplus/system/mm_osvelte/sys-memstat.h | 120 - .../oplus/system/mm_osvelte/vsprintf-dup.c | 278 -- .../oplus/system/mtk_shutdown_reboot/Kconfig | 7 - .../oplus/system/mtk_shutdown_reboot/Makefile | 3 - .../mtk_force_shutdown/mtk_force_shutdown.c | 158 - drivers/soc/oplus/system/oplus_hans/Kconfig | 9 - drivers/soc/oplus/system/oplus_hans/Makefile | 4 - drivers/soc/oplus/system/oplus_hans/hans.c | 318 -- drivers/soc/oplus/system/oplus_hans/hans.h | 185 -- .../soc/oplus/system/oplus_hans/hans_help.c | 381 --- .../oplus/system/oplus_hans/hans_netfilter.c | 283 -- drivers/soc/oplus/system/oplus_midas/Kconfig | 9 - drivers/soc/oplus/system/oplus_midas/Makefile | 8 - .../oplus/system/oplus_midas/dispcap_dev.c | 487 ---- .../soc/oplus/system/oplus_midas/midas_proc.c | 341 --- .../oplus_midas/vpu_pw_off_latency_proc.c | 125 - drivers/soc/oplus/system/oplus_mm_fb/Kconfig | 5 - drivers/soc/oplus/system/oplus_mm_fb/Makefile | 2 - .../system/oplus_mm_fb/oplus_mm_fb_netlink.h | 52 - .../system/oplus_mm_fb/oplus_mm_kevent.c | 343 --- .../system/oplus_mm_fb/oplus_mm_kevent.h | 72 - .../system/oplus_mm_fb/oplus_mm_kevent_fb.c | 573 ---- .../soc/oplus/system/oplus_phoenix/Kconfig | 9 - .../soc/oplus/system/oplus_phoenix/Makefile | 21 - .../oplus/system/oplus_phoenix/gki/Kconfig | 9 - .../system/oplus_phoenix/gki/op_bootprof.c | 249 -- .../system/oplus_phoenix/gki/op_bootprof.h | 24 - .../system/oplus_phoenix/gki/oplus_phoenix.h | 137 - .../system/oplus_phoenix/gki/phoenix_base.c | 321 -- .../system/oplus_phoenix/gki/phoenix_dump.c | 318 -- .../oplus_phoenix/gki/phoenix_watchdog.c | 288 -- .../oplus/system/oplus_phoenix/op_bootprof.c | 280 -- .../oplus/system/oplus_phoenix/op_bootprof.h | 24 - .../system/oplus_phoenix/oplus_phoenix.h | 129 - .../oplus/system/oplus_phoenix/phoenix_base.c | 309 -- .../oplus/system/oplus_phoenix/phoenix_dump.c | 407 --- .../system/oplus_phoenix/phoenix_watchdog.c | 300 -- .../oplus/system/oplus_pmic_monitor/Kconfig | 8 - .../oplus/system/oplus_pmic_monitor/Makefile | 6 - .../oplus/system/oplus_pmic_monitor/main.c | 1126 ------- .../oplus_pmic_monitor/oplus_pmic_info.h | 189 -- .../oplus_pmic_monitor/oplus_pmic_info_smem.c | 46 - drivers/soc/oplus/system/oplus_saupwk/Kconfig | 9 - .../soc/oplus/system/oplus_saupwk/Makefile | 16 - .../soc/oplus/system/oplus_saupwk/gki/Kconfig | 9 - .../system/oplus_saupwk/gki/oplus_saupwk.c | 110 - .../oplus/system/oplus_saupwk/oplus_saupwk.c | 108 - .../soc/oplus/system/qcom_minidump/Kconfig | 8 - .../soc/oplus/system/qcom_minidump/Makefile | 4 - .../soc/oplus/system/qcom_minidump/get_regs.S | 38 - .../qcom_minidump/qcom_minidump_enhance.c | 316 -- drivers/soc/oplus/system/qcom_pmicwd/Kconfig | 9 - drivers/soc/oplus/system/qcom_pmicwd/Makefile | 5 - .../oplus/system/qcom_pmicwd/qcom_pmicwd.c | 737 ----- .../oplus/system/qcom_pmicwd/qcom_pwkpwr.c | 246 -- .../soc/oplus/system/qcom_watchdog/Kconfig | 8 - .../soc/oplus/system/qcom_watchdog/Makefile | 4 - .../qcom_watchdog/qcom_enhance_watchdog.c | 298 -- drivers/soc/oplus/system/rt_info/Kconfig | 5 - drivers/soc/oplus/system/rt_info/Makefile | 3 - drivers/soc/oplus/system/rt_info/rt_info.c | 334 --- drivers/soc/oplus/system/rt_info/rt_info.h | 30 - .../soc/oplus/system/shutdown_detect/Kconfig | 8 - .../soc/oplus/system/shutdown_detect/Makefile | 13 - .../oplus/system/shutdown_detect/gki/Kconfig | 8 - .../shutdown_detect/gki/shutdown_detect.c | 629 ---- .../system/shutdown_detect/shutdown_detect.c | 619 ---- drivers/soc/oplus/system/slabtrace/Kconfig | 11 - drivers/soc/oplus/system/slabtrace/Makefile | 3 - .../soc/oplus/system/slabtrace/slabtrace.c | 581 ---- .../soc/oplus/system/slabtrace/slabtrace.h | 135 - drivers/soc/oplus/system/theia/Kconfig | 9 - drivers/soc/oplus/system/theia/Makefile | 6 - .../oplus/system/theia/black_screen_check.c | 379 --- .../oplus/system/theia/bright_screen_check.c | 448 --- .../soc/oplus/system/theia/oplus_BScheck.c | 938 ------ .../system/theia/oplus_brightscreen_check.c | 792 ----- .../soc/oplus/system/theia/powerkey_monitor.c | 509 ---- .../soc/oplus/system/theia/powerkey_monitor.h | 113 - .../oplus/system/theia/theia_kevent_kernel.c | 216 -- .../oplus/system/theia/theia_kevent_kernel.h | 42 - drivers/soc/oplus/system/uboot_log/Kconfig | 9 - drivers/soc/oplus/system/uboot_log/Makefile | 4 - .../soc/oplus/system/uboot_log/uboot_log.c | 265 -- drivers/staging/android/Kconfig | 9 - drivers/staging/android/Makefile | 5 - drivers/staging/android/hans.c | 196 -- drivers/staging/android/hans_netfilter.c | 223 -- drivers/staging/android/ion/Makefile | 2 - drivers/staging/android/ion/ion.c | 174 -- drivers/staging/android/ion/ion_heap.c | 11 - drivers/staging/android/ion/ion_page_pool.c | 8 - drivers/staging/android/ion/ion_priv.h | 14 - .../staging/android/ion/ion_track/ion_track.c | 264 -- .../staging/android/ion/ion_track/ion_track.h | 12 - drivers/staging/android/ion/mtk/Kconfig | 6 - drivers/staging/android/ion/mtk/Makefile | 1 - drivers/staging/android/ion/mtk/ion_drv.c | 22 - drivers/staging/android/ion/mtk/ion_drv.h | 3 - drivers/staging/android/ion/mtk/ion_history.c | 8 - drivers/staging/android/ion/mtk/ion_mm_heap.c | 330 --- .../staging/android/ion/mtk/ion_sec_heap.c | 16 - .../android/ion/mtk/oplus_ion_boost_pool.c | 777 ----- .../android/ion/mtk/oplus_ion_boost_pool.h | 44 - .../staging/android/ion/oplus_ion/Makefile | 5 - drivers/staging/android/ion/oplus_ion/ion.c | 12 - drivers/tty/sysrq.c | 17 - drivers/watchdog/mediatek/wdk/wd_api.c | 4 - fs/block_dev.c | 9 - fs/direct-io.c | 6 - fs/eventpoll.c | 6 - fs/exec.c | 3 - fs/f2fs/f2fs.h | 9 - fs/f2fs/file.c | 5 - fs/fs-writeback.c | 6 - fs/iomap.c | 6 - fs/pipe.c | 66 - fs/proc/Kconfig | 8 - fs/proc/Makefile | 8 - fs/proc/array.c | 18 - fs/proc/base.c | 95 - fs/proc/healthinfo/Kconfig | 15 - fs/proc/healthinfo/Makefile | 7 - fs/proc/healthinfo/cpuload.c | 82 - fs/proc/healthinfo/fg_uid/Makefile | 2 - fs/proc/healthinfo/fg_uid/fg_uid.c | 120 - fs/proc/healthinfo/fg_uid/fg_uid.h | 21 - fs/proc/healthinfo/jank_monitor.c | 171 -- fs/proc/internal.h | 4 - fs/proc/meminfo.c | 15 - fs/proc/task_cpustats/Kconfig | 17 - fs/proc/task_cpustats/Makefile | 15 - fs/proc/task_cpustats/task_cpustats.c | 258 -- fs/proc/task_cpustats/task_cpustats.h | 36 - .../task_cpustats/task_cpustats_mtk_v414.c | 331 --- fs/proc/task_cpustats/task_load.c | 372 --- fs/proc/task_cpustats/task_load.h | 18 - fs/proc/task_cpustats/task_sched_info.c | 765 ----- fs/proc/task_cpustats/task_sched_info.h | 47 - fs/proc/task_mmu.c | 27 - fs/read_write.c | 85 - fs/sync.c | 20 - include/linux/alarmtimer.h | 3 - include/linux/backing-dev-defs.h | 5 - include/linux/blk_types.h | 6 - include/linux/blkdev.h | 43 - include/linux/cpufreq.h | 3 - include/linux/hans.h | 112 - include/linux/healthinfo/fg.h | 41 - include/linux/healthinfo/ion.h | 14 - include/linux/healthinfo/jank_monitor.h | 43 - include/linux/healthinfo/memory_monitor.h | 14 - include/linux/healthinfo/slub_debug.h | 37 - include/linux/iomonitor/iomonitor.h | 263 -- include/linux/iomonitor/iotrace.h | 23 - include/linux/mmzone.h | 26 - include/linux/mutex.h | 16 - include/linux/of_reserved_mem.h | 9 - include/linux/oplus_midas.h | 20 - include/linux/oppo_mm_kevent_fb.h | 43 - include/linux/prefer_silver.h | 26 - include/linux/process_mm_reclaim.h | 56 - include/linux/rmap.h | 5 - include/linux/rwsem.h | 18 - include/linux/sched.h | 96 - include/linux/sched/cpufreq.h | 5 - include/linux/sched/sysctl.h | 9 - include/linux/sched_assist/Kconfig | 27 - include/linux/sched_assist/Makefile | 16 - .../linux/sched_assist/sched_assist_binder.h | 43 - .../linux/sched_assist/sched_assist_common.c | 2583 ----------------- .../linux/sched_assist/sched_assist_common.h | 310 -- .../linux/sched_assist/sched_assist_fork.h | 37 - .../linux/sched_assist/sched_assist_futex.c | 134 - .../linux/sched_assist/sched_assist_futex.h | 18 - .../linux/sched_assist/sched_assist_mutex.c | 93 - .../linux/sched_assist/sched_assist_mutex.h | 14 - include/linux/sched_assist/sched_assist_rt.c | 116 - .../linux/sched_assist/sched_assist_rwsem.c | 120 - .../linux/sched_assist/sched_assist_rwsem.h | 20 - .../linux/sched_assist/sched_assist_slide.c | 237 -- .../linux/sched_assist/sched_assist_slide.h | 81 - .../sched_assist/sched_assist_slide_v1.c | 239 -- .../linux/sched_assist/sched_assist_status.h | 23 - .../linux/sched_assist/sched_assist_trace.h | 45 - .../sched_assist/sched_assist_workqueue.c | 46 - .../sched_assist/sched_assist_workqueue.h | 25 - include/linux/slab.h | 18 - include/linux/swap.h | 23 - include/linux/task_io_accounting_ops.h | 9 - include/linux/task_sched_info.h | 47 - include/linux/vmalloc.h | 4 - include/linux/workqueue.h | 4 - include/net/oplus/oplus_wfd_wlan.h | 35 - include/net/oplus_nwpower.h | 50 - include/net/sock.h | 16 - include/soc/oplus/boot_mode.h | 39 - include/soc/oplus/healthinfo.h | 138 - include/soc/oplus/lowmem_dbg.h | 20 - include/soc/oplus/system/boot_mode.h | 39 - include/soc/oplus/system/device_info.h | 15 - include/soc/oplus/system/dump_reason.h | 27 - include/soc/oplus/system/hung_task_enhance.h | 33 - include/soc/oplus/system/kernel_fb.h | 39 - .../oplus/system/oplus_brightscreen_check.h | 11 - include/soc/oplus/system/oplus_bscheck.h | 11 - include/soc/oplus/system/oplus_mm_kevent_fb.h | 93 - include/soc/oplus/system/oplus_signal.h | 30 - include/soc/oplus/system/oplus_sync_time.h | 74 - include/soc/oplus/system/oppo_process.h | 103 - include/soc/oplus/system/proc.h | 21 - .../soc/oplus/system/qcom_minidump_enhance.h | 18 - include/soc/oplus/system/qcom_pmicwd.h | 25 - include/soc/oplus/system/uboot_utils.h | 163 -- include/soc/oppo/boot_mode.h | 23 - include/soc/oppo/boot_mode_types.h | 30 - include/soc/oppo/healthinfo.h | 138 - include/soc/oppo/mmkey_log.h | 51 - include/trace/events/power.h | 50 - include/trace/events/sched.h | 33 - include/uapi/linux/netlink.h | 20 - init/Kconfig | 3 - init/main.c | 42 - kernel/Makefile | 12 - kernel/cgroup/cgroup-v1.c | 7 - kernel/exit.c | 25 - kernel/fork.c | 28 - kernel/futex.c | 6 - kernel/hung_task.c | 29 - kernel/locking/mutex.c | 39 - kernel/locking/rwsem-xadd.c | 99 - kernel/locking/rwsem.c | 59 - kernel/locking/semaphore.c | 7 - kernel/panic.c | 54 +- kernel/panic_flush.c | 133 - kernel/prefer_silver/Kconfig | 5 - kernel/prefer_silver/Makefile | 1 - kernel/prefer_silver/prefer_silver.c | 101 - kernel/prefer_silver/prefer_silver.h | 26 - kernel/sched/completion.c | 7 - kernel/sched/core.c | 95 +- kernel/sched/cpufreq_schedutil.c | 415 --- kernel/sched/cpufreq_schedutil_plus.c | 29 - kernel/sched/cpupri.c | 14 - kernel/sched/cputime.c | 46 - kernel/sched/eas_plus.c | 16 - kernel/sched/fair.c | 231 -- kernel/sched/hmp.c | 7 - kernel/sched/sched.h | 7 - kernel/sched/sched_plus.h | 6 - kernel/sched/topology.c | 6 - kernel/sched/tune.c | 25 - kernel/sched/walt.c | 7 - kernel/sched_assist/Kconfig | 27 - kernel/sched_assist/Makefile | 16 - kernel/sched_assist/sched_assist_binder.h | 43 - kernel/sched_assist/sched_assist_common.c | 2583 ----------------- kernel/sched_assist/sched_assist_common.h | 310 -- kernel/sched_assist/sched_assist_fork.h | 37 - kernel/sched_assist/sched_assist_futex.c | 134 - kernel/sched_assist/sched_assist_futex.h | 18 - kernel/sched_assist/sched_assist_mutex.c | 93 - kernel/sched_assist/sched_assist_mutex.h | 14 - kernel/sched_assist/sched_assist_rt.c | 116 - kernel/sched_assist/sched_assist_rwsem.c | 120 - kernel/sched_assist/sched_assist_rwsem.h | 20 - kernel/sched_assist/sched_assist_slide.c | 237 -- kernel/sched_assist/sched_assist_slide.h | 81 - kernel/sched_assist/sched_assist_slide_v1.c | 239 -- kernel/sched_assist/sched_assist_status.h | 23 - kernel/sched_assist/sched_assist_trace.h | 45 - kernel/sched_assist/sched_assist_workqueue.c | 46 - kernel/sched_assist/sched_assist_workqueue.h | 25 - kernel/signal.c | 38 - kernel/sysctl.c | 251 -- kernel/time/alarmtimer.c | 10 - kernel/trace/ring_buffer.c | 28 - kernel/trace/trace.c | 16 +- kernel/workqueue.c | 39 - lib/Makefile | 4 - lib/memleak_debug_stackdepot.c | 334 --- lib/show_mem.c | 6 - mm/Kconfig | 41 - mm/Makefile | 29 - mm/async_shrink_slabd.c | 3 - mm/compaction.c | 16 - mm/healthinfo/Kconfig | 7 - mm/healthinfo/Makefile | 4 - mm/healthinfo/memory_monitor.c | 191 -- mm/madvise.c | 9 - mm/malloc_track/Kconfig | 17 - mm/malloc_track/Kconfig.compat | 17 - mm/malloc_track/Kconfig.in | 16 - mm/malloc_track/slub_track.c | 1207 -------- mm/malloc_track/vmalloc_track.c | 605 ---- mm/memory.c | 15 - mm/memory_hotplug.c | 12 - mm/multi_freearea.c | 246 -- mm/multi_freearea.h | 18 - mm/multi_kswapd/Kconfig | 15 - mm/multi_kswapd/Makefile | 4 - mm/multi_kswapd/multi_kswapd.c | 203 -- mm/page_alloc.c | 212 -- mm/page_io.c | 10 - mm/process_mm_reclaim.c | 604 ---- mm/process_mm_reclaim_weak.c | 11 - mm/rmap.c | 83 - mm/slab.h | 6 +- mm/slab_common.c | 22 - mm/slub.c | 123 +- mm/swap.c | 4 - mm/swap_slots.c | 5 - mm/swap_state.c | 4 - mm/swapfile.c | 51 - mm/util.c | 7 +- mm/vmalloc.c | 35 +- mm/vmscan.c | 257 -- mm/vmstat.c | 51 - mm/zsmalloc.c | 8 - nativefeatures.mk | 14 - net/Kconfig | 14 - net/Makefile | 23 - net/ipv4/inet_connection_sock.c | 10 - net/ipv4/tcp_input.c | 8 - net/ipv4/tcp_ipv4.c | 15 - net/ipv4/tcp_output.c | 15 - net/ipv6/route.c | 7 - net/ipv6/tcp_ipv6.c | 15 - net/oplus_connectivity_sla/Kconfig | 7 - net/oplus_connectivity_sla/Makefile | 23 - .../oplus_connectivity_sla.c | 1613 ---------- net/oplus_modules/Kconfig | 11 - net/oplus_modules/Makefile | 17 - net/oplus_modules/oplus_dns_hook/Kconfig | 7 - net/oplus_modules/oplus_dns_hook/Makefile | 4 - .../oplus_dns_hook/oplus_dns_hook.c | 834 ------ net/oplus_modules/oplus_qr_scan/Kconfig | 7 - net/oplus_modules/oplus_qr_scan/Makefile | 5 - .../oplus_qr_scan/oplus_qr_scan.c | 657 ----- net/oplus_modules/oplus_stats_calc/Kconfig | 7 - net/oplus_modules/oplus_stats_calc/Makefile | 4 - .../oplus_stats_calc/oplus_stats_calc.c | 442 --- net/oplus_nwpower/Makefile | 4 - net/oplus_nwpower/oplus_nwpower.c | 960 ------ net/oplus_score/Kconfig | 7 - net/oplus_score/Makefile | 5 - net/oplus_score/oplus_score.c | 1437 --------- net/oplus_wificapcenter/Kconfig | 14 - net/oplus_wificapcenter/Makefile | 6 - net/oplus_wificapcenter/oplus_wificapcenter.c | 548 ---- net/socket.c | 10 - .../codecs/audio/aw882xx_v1.10.0/aw882xx.c | 468 +-- .../codecs/audio/aw882xx_v1.10.0/aw882xx.h | 12 +- sound/soc/codecs/audio/driver/Makefile | 1 - sound/soc/codecs/audio/driver/hal_feedback.c | 59 - sound/soc/codecs/audio/fsa44xx/fsa4480-i2c.c | 8 - sound/soc/mediatek/audio_dsp/mtk-base-dsp.h | 3 - sound/soc/mediatek/audio_dsp/mtk-dsp-common.c | 11 - sound/soc/mediatek/audio_dsp/mtk-dsp-common.h | 30 - .../audio_dsp/mtk-dsp-platform-driver.c | 31 - sound/soc/mediatek/common/mtk-afe-fe-dai.c | 5 - sound/soc/mediatek/common/mtk-sp-common.h | 24 - .../mediatek/feedback/oplus_audio_kernel_fb.h | 40 - sound/soc/mediatek/mt6833/mt6833-mt6359.c | 14 - sound/soc/mediatek/mt6853/mt6853-mt6359.c | 14 - sound/soc/mediatek/mt6877/mt6877-mt6359.c | 14 - sound/soc/mediatek/mt6885/mt6885-mt6359.c | 14 - .../mediatek/scp_ultra/mtk-scp-ultra-common.h | 28 - 601 files changed, 610 insertions(+), 86617 deletions(-) delete mode 100755 block/foreground_io_opt/Kconfig delete mode 100755 block/foreground_io_opt/Makefile delete mode 100755 block/foreground_io_opt/foreground_io_opt.c delete mode 100755 block/foreground_io_opt/foreground_io_opt.h delete mode 100755 block/foreground_io_opt/high_prio_task.c delete mode 100755 block/foreground_io_opt/trace/foreground_io_opt_trace.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap_akcompress.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_area.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_area.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap_core.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_ctrl.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_internal.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap_list.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_list.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap_lru_rmap.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_lru_rmap.h delete mode 100755 drivers/block/zram/hybridswap/hybridswap_main.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_manager.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_perf.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_schedule.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_stats.c delete mode 100755 drivers/block/zram/hybridswap/hybridswap_swapd.c delete mode 100755 drivers/misc/mediatek/connectivity/wlan/core/gen4m/oplus_wfd/wlan_oplus_wfd.c delete mode 100755 drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile delete mode 100755 drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c delete mode 100755 drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h delete mode 100755 drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile delete mode 100755 drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c delete mode 100755 drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h delete mode 100755 drivers/misc/oplus_misc_healthinfo/Kconfig delete mode 100755 drivers/misc/oplus_misc_healthinfo/Makefile delete mode 100755 drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.c delete mode 100755 drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.h delete mode 100755 drivers/soc/oplus/healthinfo/Kconfig delete mode 100644 drivers/soc/oplus/healthinfo/Makefile delete mode 100755 drivers/soc/oplus/healthinfo/healthinfo.c delete mode 100644 drivers/soc/oplus/healthinfo/healthinfo.h delete mode 100755 drivers/soc/oplus/iomonitor/Kconfig delete mode 100755 drivers/soc/oplus/iomonitor/Makefile delete mode 100755 drivers/soc/oplus/iomonitor/console.c delete mode 100755 drivers/soc/oplus/iomonitor/include/iomonitor.h delete mode 100755 drivers/soc/oplus/iomonitor/include/iotrace.h delete mode 100755 drivers/soc/oplus/iomonitor/iomonitor.c delete mode 100755 drivers/soc/oplus/iomonitor/iotrace.c delete mode 100755 drivers/soc/oplus/iomonitor/uid_status.c delete mode 100644 drivers/soc/oplus/lowmem_dbg/Kconfig delete mode 100644 drivers/soc/oplus/lowmem_dbg/Makefile delete mode 100755 drivers/soc/oplus/lowmem_dbg/lowmem_dbg.c delete mode 100644 drivers/soc/oplus/lowmem_dbg/lowmem_dbg.h delete mode 100755 drivers/soc/oplus/lowmem_dbg/lowmem_dbg_5.4.c delete mode 100755 drivers/soc/oplus/midas/Kconfig delete mode 100755 drivers/soc/oplus/midas/Makefile delete mode 100644 drivers/soc/oplus/midas/v1/Makefile delete mode 100644 drivers/soc/oplus/midas/v1/binder_stats_dev.c delete mode 100755 drivers/soc/oplus/midas/v1/dispcap_dev.c delete mode 100755 drivers/soc/oplus/midas/v1/midas_dev.c delete mode 100755 drivers/soc/oplus/midas/v1/midas_dev.h delete mode 100755 drivers/soc/oplus/midas/v1/midas_ioctl.c delete mode 100755 drivers/soc/oplus/midas/v1/vpu_pw_off_latency_proc.c delete mode 100755 drivers/soc/oplus/midas/v1_gki/Makefile delete mode 100755 drivers/soc/oplus/midas/v1_gki/binder_stats_dev.c delete mode 100755 drivers/soc/oplus/midas/v1_gki/dispcap_dev.c delete mode 100755 drivers/soc/oplus/midas/v1_gki/midas_dev.c delete mode 100755 drivers/soc/oplus/midas/v1_gki/midas_dev.h delete mode 100755 drivers/soc/oplus/midas/v1_gki/midas_ioctl.c delete mode 100644 drivers/soc/oplus/midas/v1_gki/midas_module.c delete mode 100755 drivers/soc/oplus/midas/v1_gki/vpu_pw_off_latency_proc.c delete mode 100755 drivers/soc/oplus/midas/v2/Makefile delete mode 100755 drivers/soc/oplus/midas/v2/binder_stats_dev.c delete mode 100755 drivers/soc/oplus/midas/v2/dispcap_dev.c delete mode 100755 drivers/soc/oplus/midas/v2/midas_cpu.c delete mode 100644 drivers/soc/oplus/midas/v2/midas_cpu.h delete mode 100755 drivers/soc/oplus/midas/v2/midas_dev.c delete mode 100755 drivers/soc/oplus/midas/v2/midas_dev.h delete mode 100755 drivers/soc/oplus/midas/v2/midas_ioctl.c delete mode 100755 drivers/soc/oplus/midas/v2/midas_mem.c delete mode 100644 drivers/soc/oplus/midas/v2/midas_mem.h delete mode 100644 drivers/soc/oplus/midas/v2/midas_module.c delete mode 100755 drivers/soc/oplus/midas/v2/vpu_pw_off_latency_proc.c delete mode 100755 drivers/soc/oplus/oplus_criticallog/Kconfig delete mode 100755 drivers/soc/oplus/oplus_criticallog/Makefile delete mode 100755 drivers/soc/oplus/oplus_criticallog/criticallog_class.c delete mode 100755 drivers/soc/oplus/oplus_criticallog/criticallog_class.h delete mode 100755 drivers/soc/oplus/oplus_criticallog/oplus_criticallog.c delete mode 100644 drivers/soc/oplus/oplus_nandswap/Kconfig delete mode 100644 drivers/soc/oplus/oplus_nandswap/Makefile delete mode 100644 drivers/soc/oplus/oplus_nandswap/nandswap.h delete mode 100755 drivers/soc/oplus/oplus_nandswap/nandswap_core.c delete mode 100755 drivers/soc/oplus/system/acm/Kconfig delete mode 100755 drivers/soc/oplus/system/acm/Makefile delete mode 100755 drivers/soc/oplus/system/acm/acm.c delete mode 100755 drivers/soc/oplus/system/acm/acm.h delete mode 100755 drivers/soc/oplus/system/dump_device_info/Kconfig delete mode 100755 drivers/soc/oplus/system/dump_device_info/Makefile delete mode 100755 drivers/soc/oplus/system/dump_device_info/dump_device_info.c delete mode 100755 drivers/soc/oplus/system/dump_reason/Kconfig delete mode 100755 drivers/soc/oplus/system/dump_reason/Makefile delete mode 100755 drivers/soc/oplus/system/dump_reason/dump_reason.c delete mode 100755 drivers/soc/oplus/system/feedback/Kconfig delete mode 100755 drivers/soc/oplus/system/feedback/Makefile delete mode 100755 drivers/soc/oplus/system/feedback/gki/Kconfig delete mode 100755 drivers/soc/oplus/system/feedback/gki/kernel_fb.c delete mode 100755 drivers/soc/oplus/system/feedback/kernel_fb.c delete mode 100755 drivers/soc/oplus/system/feedback/oplus_fb_guard_netlink.h delete mode 100755 drivers/soc/oplus/system/full_aging/Kconfig delete mode 100755 drivers/soc/oplus/system/hung_task_enhance/Kconfig delete mode 100755 drivers/soc/oplus/system/hung_task_enhance/Makefile delete mode 100755 drivers/soc/oplus/system/hung_task_enhance/gki/Kconfig delete mode 100755 drivers/soc/oplus/system/hung_task_enhance/gki/hung_task_enhance.c delete mode 100755 drivers/soc/oplus/system/hung_task_enhance/hung_task_enhance.c delete mode 100755 drivers/soc/oplus/system/include/boot_mode.h delete mode 100755 drivers/soc/oplus/system/include/device_info.h delete mode 100755 drivers/soc/oplus/system/include/dump_reason.h delete mode 100755 drivers/soc/oplus/system/include/hung_task_enhance.h delete mode 100755 drivers/soc/oplus/system/include/kernel_fb.h delete mode 100755 drivers/soc/oplus/system/include/oplus_brightscreen_check.h delete mode 100755 drivers/soc/oplus/system/include/oplus_bscheck.h delete mode 100755 drivers/soc/oplus/system/include/oplus_mm_kevent_fb.h delete mode 100755 drivers/soc/oplus/system/include/oplus_signal.h delete mode 100755 drivers/soc/oplus/system/include/oplus_sync_time.h delete mode 100755 drivers/soc/oplus/system/include/oppo_process.h delete mode 100755 drivers/soc/oplus/system/include/proc.h delete mode 100755 drivers/soc/oplus/system/include/qcom_minidump_enhance.h delete mode 100755 drivers/soc/oplus/system/include/qcom_pmicwd.h delete mode 100755 drivers/soc/oplus/system/include/uboot_utils.h delete mode 100755 drivers/soc/oplus/system/mdmrst/Kconfig delete mode 100755 drivers/soc/oplus/system/mdmrst/Makefile delete mode 100755 drivers/soc/oplus/system/mdmrst/oplus_mdmrst.c delete mode 100644 drivers/soc/oplus/system/mm_osvelte/CHANGELOG.md delete mode 100644 drivers/soc/oplus/system/mm_osvelte/Kconfig delete mode 100644 drivers/soc/oplus/system/mm_osvelte/Makefile delete mode 100755 drivers/soc/oplus/system/mm_osvelte/VERSION delete mode 100755 drivers/soc/oplus/system/mm_osvelte/common.h delete mode 100755 drivers/soc/oplus/system/mm_osvelte/logger.c delete mode 100644 drivers/soc/oplus/system/mm_osvelte/logger.h delete mode 100755 drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.c delete mode 100644 drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.h delete mode 100755 drivers/soc/oplus/system/mm_osvelte/memstat.h delete mode 100755 drivers/soc/oplus/system/mm_osvelte/proc-memstat.c delete mode 100644 drivers/soc/oplus/system/mm_osvelte/proc-memstat.h delete mode 100644 drivers/soc/oplus/system/mm_osvelte/sys-memstat.c delete mode 100644 drivers/soc/oplus/system/mm_osvelte/sys-memstat.h delete mode 100644 drivers/soc/oplus/system/mm_osvelte/vsprintf-dup.c delete mode 100755 drivers/soc/oplus/system/mtk_shutdown_reboot/Kconfig delete mode 100755 drivers/soc/oplus/system/mtk_shutdown_reboot/Makefile delete mode 100755 drivers/soc/oplus/system/mtk_shutdown_reboot/mtk_force_shutdown/mtk_force_shutdown.c delete mode 100755 drivers/soc/oplus/system/oplus_hans/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_hans/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_hans/hans.c delete mode 100755 drivers/soc/oplus/system/oplus_hans/hans.h delete mode 100755 drivers/soc/oplus/system/oplus_hans/hans_help.c delete mode 100755 drivers/soc/oplus/system/oplus_hans/hans_netfilter.c delete mode 100644 drivers/soc/oplus/system/oplus_midas/Kconfig delete mode 100644 drivers/soc/oplus/system/oplus_midas/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_midas/dispcap_dev.c delete mode 100755 drivers/soc/oplus/system/oplus_midas/midas_proc.c delete mode 100755 drivers/soc/oplus/system/oplus_midas/vpu_pw_off_latency_proc.c delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_fb_netlink.h delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.c delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.h delete mode 100755 drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent_fb.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.h delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/oplus_phoenix.h delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_base.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_dump.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_watchdog.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/op_bootprof.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/op_bootprof.h delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/phoenix_base.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/phoenix_dump.c delete mode 100755 drivers/soc/oplus/system/oplus_phoenix/phoenix_watchdog.c delete mode 100755 drivers/soc/oplus/system/oplus_pmic_monitor/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_pmic_monitor/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_pmic_monitor/main.c delete mode 100755 drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info.h delete mode 100755 drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info_smem.c delete mode 100755 drivers/soc/oplus/system/oplus_saupwk/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_saupwk/Makefile delete mode 100755 drivers/soc/oplus/system/oplus_saupwk/gki/Kconfig delete mode 100755 drivers/soc/oplus/system/oplus_saupwk/gki/oplus_saupwk.c delete mode 100755 drivers/soc/oplus/system/oplus_saupwk/oplus_saupwk.c delete mode 100755 drivers/soc/oplus/system/qcom_minidump/Kconfig delete mode 100755 drivers/soc/oplus/system/qcom_minidump/Makefile delete mode 100755 drivers/soc/oplus/system/qcom_minidump/get_regs.S delete mode 100755 drivers/soc/oplus/system/qcom_minidump/qcom_minidump_enhance.c delete mode 100755 drivers/soc/oplus/system/qcom_pmicwd/Kconfig delete mode 100755 drivers/soc/oplus/system/qcom_pmicwd/Makefile delete mode 100755 drivers/soc/oplus/system/qcom_pmicwd/qcom_pmicwd.c delete mode 100755 drivers/soc/oplus/system/qcom_pmicwd/qcom_pwkpwr.c delete mode 100755 drivers/soc/oplus/system/qcom_watchdog/Kconfig delete mode 100755 drivers/soc/oplus/system/qcom_watchdog/Makefile delete mode 100755 drivers/soc/oplus/system/qcom_watchdog/qcom_enhance_watchdog.c delete mode 100755 drivers/soc/oplus/system/rt_info/Kconfig delete mode 100755 drivers/soc/oplus/system/rt_info/Makefile delete mode 100755 drivers/soc/oplus/system/rt_info/rt_info.c delete mode 100755 drivers/soc/oplus/system/rt_info/rt_info.h delete mode 100755 drivers/soc/oplus/system/shutdown_detect/Kconfig delete mode 100755 drivers/soc/oplus/system/shutdown_detect/Makefile delete mode 100755 drivers/soc/oplus/system/shutdown_detect/gki/Kconfig delete mode 100755 drivers/soc/oplus/system/shutdown_detect/gki/shutdown_detect.c delete mode 100755 drivers/soc/oplus/system/shutdown_detect/shutdown_detect.c delete mode 100755 drivers/soc/oplus/system/slabtrace/Kconfig delete mode 100755 drivers/soc/oplus/system/slabtrace/Makefile delete mode 100755 drivers/soc/oplus/system/slabtrace/slabtrace.c delete mode 100755 drivers/soc/oplus/system/slabtrace/slabtrace.h delete mode 100755 drivers/soc/oplus/system/theia/Kconfig delete mode 100755 drivers/soc/oplus/system/theia/Makefile delete mode 100755 drivers/soc/oplus/system/theia/black_screen_check.c delete mode 100755 drivers/soc/oplus/system/theia/bright_screen_check.c delete mode 100755 drivers/soc/oplus/system/theia/oplus_BScheck.c delete mode 100755 drivers/soc/oplus/system/theia/oplus_brightscreen_check.c delete mode 100755 drivers/soc/oplus/system/theia/powerkey_monitor.c delete mode 100755 drivers/soc/oplus/system/theia/powerkey_monitor.h delete mode 100755 drivers/soc/oplus/system/theia/theia_kevent_kernel.c delete mode 100755 drivers/soc/oplus/system/theia/theia_kevent_kernel.h delete mode 100755 drivers/soc/oplus/system/uboot_log/Kconfig delete mode 100755 drivers/soc/oplus/system/uboot_log/Makefile delete mode 100755 drivers/soc/oplus/system/uboot_log/uboot_log.c delete mode 100755 drivers/staging/android/hans.c delete mode 100755 drivers/staging/android/hans_netfilter.c delete mode 100755 drivers/staging/android/ion/ion_track/ion_track.c delete mode 100644 drivers/staging/android/ion/ion_track/ion_track.h delete mode 100755 drivers/staging/android/ion/mtk/oplus_ion_boost_pool.c delete mode 100644 drivers/staging/android/ion/mtk/oplus_ion_boost_pool.h delete mode 100644 drivers/staging/android/ion/oplus_ion/Makefile delete mode 100644 drivers/staging/android/ion/oplus_ion/ion.c delete mode 100644 fs/proc/healthinfo/Kconfig delete mode 100644 fs/proc/healthinfo/Makefile delete mode 100755 fs/proc/healthinfo/cpuload.c delete mode 100644 fs/proc/healthinfo/fg_uid/Makefile delete mode 100755 fs/proc/healthinfo/fg_uid/fg_uid.c delete mode 100644 fs/proc/healthinfo/fg_uid/fg_uid.h delete mode 100755 fs/proc/healthinfo/jank_monitor.c delete mode 100644 fs/proc/task_cpustats/Kconfig delete mode 100644 fs/proc/task_cpustats/Makefile delete mode 100755 fs/proc/task_cpustats/task_cpustats.c delete mode 100755 fs/proc/task_cpustats/task_cpustats.h delete mode 100755 fs/proc/task_cpustats/task_cpustats_mtk_v414.c delete mode 100755 fs/proc/task_cpustats/task_load.c delete mode 100755 fs/proc/task_cpustats/task_load.h delete mode 100755 fs/proc/task_cpustats/task_sched_info.c delete mode 100755 fs/proc/task_cpustats/task_sched_info.h delete mode 100755 include/linux/hans.h delete mode 100644 include/linux/healthinfo/fg.h delete mode 100644 include/linux/healthinfo/ion.h delete mode 100755 include/linux/healthinfo/jank_monitor.h delete mode 100755 include/linux/healthinfo/memory_monitor.h delete mode 100644 include/linux/healthinfo/slub_debug.h delete mode 100755 include/linux/iomonitor/iomonitor.h delete mode 100755 include/linux/iomonitor/iotrace.h delete mode 100644 include/linux/oplus_midas.h delete mode 100755 include/linux/oppo_mm_kevent_fb.h delete mode 100644 include/linux/prefer_silver.h delete mode 100755 include/linux/process_mm_reclaim.h delete mode 100755 include/linux/sched_assist/Kconfig delete mode 100755 include/linux/sched_assist/Makefile delete mode 100755 include/linux/sched_assist/sched_assist_binder.h delete mode 100755 include/linux/sched_assist/sched_assist_common.c delete mode 100755 include/linux/sched_assist/sched_assist_common.h delete mode 100755 include/linux/sched_assist/sched_assist_fork.h delete mode 100755 include/linux/sched_assist/sched_assist_futex.c delete mode 100755 include/linux/sched_assist/sched_assist_futex.h delete mode 100755 include/linux/sched_assist/sched_assist_mutex.c delete mode 100755 include/linux/sched_assist/sched_assist_mutex.h delete mode 100755 include/linux/sched_assist/sched_assist_rt.c delete mode 100755 include/linux/sched_assist/sched_assist_rwsem.c delete mode 100755 include/linux/sched_assist/sched_assist_rwsem.h delete mode 100755 include/linux/sched_assist/sched_assist_slide.c delete mode 100755 include/linux/sched_assist/sched_assist_slide.h delete mode 100755 include/linux/sched_assist/sched_assist_slide_v1.c delete mode 100755 include/linux/sched_assist/sched_assist_status.h delete mode 100755 include/linux/sched_assist/sched_assist_trace.h delete mode 100755 include/linux/sched_assist/sched_assist_workqueue.c delete mode 100755 include/linux/sched_assist/sched_assist_workqueue.h delete mode 100755 include/linux/task_sched_info.h delete mode 100755 include/net/oplus/oplus_wfd_wlan.h delete mode 100755 include/net/oplus_nwpower.h delete mode 100755 include/soc/oplus/boot_mode.h delete mode 100644 include/soc/oplus/healthinfo.h delete mode 100644 include/soc/oplus/lowmem_dbg.h delete mode 100755 include/soc/oplus/system/boot_mode.h delete mode 100755 include/soc/oplus/system/device_info.h delete mode 100755 include/soc/oplus/system/dump_reason.h delete mode 100755 include/soc/oplus/system/hung_task_enhance.h delete mode 100755 include/soc/oplus/system/kernel_fb.h delete mode 100755 include/soc/oplus/system/oplus_brightscreen_check.h delete mode 100755 include/soc/oplus/system/oplus_bscheck.h delete mode 100755 include/soc/oplus/system/oplus_mm_kevent_fb.h delete mode 100755 include/soc/oplus/system/oplus_signal.h delete mode 100755 include/soc/oplus/system/oplus_sync_time.h delete mode 100755 include/soc/oplus/system/oppo_process.h delete mode 100755 include/soc/oplus/system/proc.h delete mode 100755 include/soc/oplus/system/qcom_minidump_enhance.h delete mode 100755 include/soc/oplus/system/qcom_pmicwd.h delete mode 100755 include/soc/oplus/system/uboot_utils.h delete mode 100755 include/soc/oppo/boot_mode.h delete mode 100755 include/soc/oppo/boot_mode_types.h delete mode 100644 include/soc/oppo/healthinfo.h delete mode 100755 include/soc/oppo/mmkey_log.h delete mode 100755 kernel/panic_flush.c delete mode 100644 kernel/prefer_silver/Kconfig delete mode 100644 kernel/prefer_silver/Makefile delete mode 100644 kernel/prefer_silver/prefer_silver.c delete mode 100644 kernel/prefer_silver/prefer_silver.h delete mode 100755 kernel/sched_assist/Kconfig delete mode 100755 kernel/sched_assist/Makefile delete mode 100755 kernel/sched_assist/sched_assist_binder.h delete mode 100755 kernel/sched_assist/sched_assist_common.c delete mode 100755 kernel/sched_assist/sched_assist_common.h delete mode 100755 kernel/sched_assist/sched_assist_fork.h delete mode 100755 kernel/sched_assist/sched_assist_futex.c delete mode 100755 kernel/sched_assist/sched_assist_futex.h delete mode 100755 kernel/sched_assist/sched_assist_mutex.c delete mode 100755 kernel/sched_assist/sched_assist_mutex.h delete mode 100755 kernel/sched_assist/sched_assist_rt.c delete mode 100755 kernel/sched_assist/sched_assist_rwsem.c delete mode 100755 kernel/sched_assist/sched_assist_rwsem.h delete mode 100755 kernel/sched_assist/sched_assist_slide.c delete mode 100755 kernel/sched_assist/sched_assist_slide.h delete mode 100755 kernel/sched_assist/sched_assist_slide_v1.c delete mode 100755 kernel/sched_assist/sched_assist_status.h delete mode 100755 kernel/sched_assist/sched_assist_trace.h delete mode 100755 kernel/sched_assist/sched_assist_workqueue.c delete mode 100755 kernel/sched_assist/sched_assist_workqueue.h delete mode 100755 lib/memleak_debug_stackdepot.c delete mode 100644 mm/healthinfo/Kconfig delete mode 100644 mm/healthinfo/Makefile delete mode 100755 mm/healthinfo/memory_monitor.c delete mode 100644 mm/malloc_track/Kconfig delete mode 100644 mm/malloc_track/Kconfig.compat delete mode 100644 mm/malloc_track/Kconfig.in delete mode 100755 mm/malloc_track/slub_track.c delete mode 100755 mm/malloc_track/vmalloc_track.c delete mode 100644 mm/multi_freearea.c delete mode 100644 mm/multi_freearea.h delete mode 100755 mm/multi_kswapd/Kconfig delete mode 100755 mm/multi_kswapd/Makefile delete mode 100755 mm/multi_kswapd/multi_kswapd.c delete mode 100755 mm/process_mm_reclaim.c delete mode 100644 mm/process_mm_reclaim_weak.c delete mode 100755 net/oplus_connectivity_sla/Kconfig delete mode 100755 net/oplus_connectivity_sla/Makefile delete mode 100755 net/oplus_connectivity_sla/oplus_connectivity_sla.c delete mode 100755 net/oplus_modules/Kconfig delete mode 100755 net/oplus_modules/Makefile delete mode 100644 net/oplus_modules/oplus_dns_hook/Kconfig delete mode 100644 net/oplus_modules/oplus_dns_hook/Makefile delete mode 100755 net/oplus_modules/oplus_dns_hook/oplus_dns_hook.c delete mode 100755 net/oplus_modules/oplus_qr_scan/Kconfig delete mode 100755 net/oplus_modules/oplus_qr_scan/Makefile delete mode 100755 net/oplus_modules/oplus_qr_scan/oplus_qr_scan.c delete mode 100644 net/oplus_modules/oplus_stats_calc/Kconfig delete mode 100644 net/oplus_modules/oplus_stats_calc/Makefile delete mode 100755 net/oplus_modules/oplus_stats_calc/oplus_stats_calc.c delete mode 100755 net/oplus_nwpower/Makefile delete mode 100755 net/oplus_nwpower/oplus_nwpower.c delete mode 100755 net/oplus_score/Kconfig delete mode 100755 net/oplus_score/Makefile delete mode 100755 net/oplus_score/oplus_score.c delete mode 100755 net/oplus_wificapcenter/Kconfig delete mode 100755 net/oplus_wificapcenter/Makefile delete mode 100755 net/oplus_wificapcenter/oplus_wificapcenter.c delete mode 100755 sound/soc/codecs/audio/driver/hal_feedback.c delete mode 100755 sound/soc/mediatek/feedback/oplus_audio_kernel_fb.h diff --git a/Kconfig b/Kconfig index 9d733cf04986..8c4c1cb0f9cd 100644 --- a/Kconfig +++ b/Kconfig @@ -5,12 +5,6 @@ # mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration" -config OPLUS_FEATURE_PANIC_FLUSH - bool "fsync optimization " - default y - help - define this config to fsync optimization - config SRCARCH string option env="SRCARCH" diff --git a/Makefile b/Makefile index 17f2e030c215..cf7bf81829e1 100755 --- a/Makefile +++ b/Makefile @@ -459,11 +459,6 @@ KBUILD_CFLAGS += -DCONFIG_HIGH_TEMP_VERSION endif #endif /* OPLUS_FEATURE_CHG_BASIC */ -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -ifeq ($(AGING_DEBUG_MASK),1) -# enable memleak detect daemon -OPLUS_MEMLEAK_DETECT := true -endif ifeq ($(TARGET_MEMLEAK_DETECT_TEST),0) # disable memleak detect daemon diff --git a/OplusKernelEnvConfig.mk b/OplusKernelEnvConfig.mk index cbdd7424e462..01b0c0774615 100755 --- a/OplusKernelEnvConfig.mk +++ b/OplusKernelEnvConfig.mk @@ -18,68 +18,21 @@ -include nativefeatures.mk -OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET := - -ifeq ($(OPLUS_FEATURE_WIFI_MTUDETECT), yes) -OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET += OPLUS_FEATURE_WIFI_MTUDETECT -endif - - -$(foreach myfeature,$(OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET),\ - $( \ - $(eval KBUILD_CFLAGS += -D$(myfeature)) \ - $(eval KBUILD_CPPFLAGS += -D$(myfeature)) \ - $(eval CFLAGS_KERNEL += -D$(myfeature)) \ - $(eval CFLAGS_MODULE += -D$(myfeature)) \ - ) \ -) - ALLOWED_MCROS := \ -OPLUS_FEATURE_HANS_FREEZE \ OPLUS_FEATURE_AOD \ -OPLUS_FEATURE_HEALTHINFO \ -OPLUS_FEATURE_TASK_CPUSTATS \ -OPLUS_FEATURE_FG_IO_OPT \ -OPLUS_FEATURE_SCHED_ASSIST \ -OPLUS_FEATURE_SDCARD_INFO \ OPLUS_FEATURE_FINGERPRINT \ -OPLUS_FEATURE_STORAGE_TOOL \ -OPLUS_FEATURE_MULTI_FREEAREA \ -OPLUS_FEATURE_MULTI_KSWAPD \ -OPLUS_FEATURE_NFC_CONSOFT \ OPLUS_FEATURE_ONSCREENFINGERPRINT \ -OPLUS_FEATURE_PHOENIX \ -OPLUS_FEATURE_AGINGTEST \ -OPLUS_FEATURE_PROCESS_RECLAIM \ OPLUS_FEATURE_SENSOR \ OPLUS_FEATURE_SENSOR_ALGORITHM \ OPLUS_FEATURE_SENSOR_SMEM \ OPLUS_FEATURE_SENSOR_WISELIGHT \ -OPLUS_FEATURE_IOMONITOR \ OPLUS_FEATURE_SPEAKER_MUTE \ -OPLUS_FEATURE_MM_FEEDBACK \ OPLUS_FEATURE_CHG_BASIC \ -OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY \ -OPLUS_FEATURE_MEMLEAK_DETECT \ -OPLUS_FEATURE_WIFI_MTUDETECT \ -OPLUS_FEATURE_WIFI_RUSUPGRADE \ -OPLUS_FEATURE_WIFI_SLA \ -OPLUS_FEATURE_DATA_EVAL \ -OPLUS_FEATURE_ZRAM_OPT \ OPLUS_BUG_COMPATIBILITY \ -OPLUS_FEATURE_MIDAS \ OPLUS_BUG_STABILITY \ OPLUS_ARCH_INJECT \ OPLUS_ARCH_EXTENDS \ -OPLUS_FEATURE_LOWMEM_DBG \ -OPLUS_FEATURE_PERFORMANCE \ -OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK \ -OPLUS_FEATURE_ALARMINFO_STANDBY \ -OPLUS_FEATURE_POWERINFO_FTM \ -OPLUS_FEATURE_SCHEDUTIL_USE_TL \ -OPLUS_FEATURE_CORE_CTL \ -OPLUS_FEATURE_CAMERA_COMMON \ -OPLUS_FEATURE_WIFI_OPLUSWFD +OPLUS_FEATURE_CAMERA_COMMON $(foreach myfeature,$(ALLOWED_MCROS),\ $(eval KBUILD_CFLAGS += -D$(myfeature)) \ @@ -88,15 +41,6 @@ $(foreach myfeature,$(ALLOWED_MCROS),\ $(eval CFLAGS_MODULE += -D$(myfeature)) \ ) -# BSP team can do customzation by referring the feature variables -ifeq ($(OPLUS_FEATURE_PREFER_SILVER),yes) -export CONFIG_OPLUS_PREFER_SILVER=y -KBUILD_CFLAGS += -DCONFIG_OPLUS_PREFER_SILVER -KBUILD_CPPFLAGS += -DCONFIG_OPLUS_PREFER_SILVER -CFLAGS_KERNEL += -DCONFIG_OPLUS_PREFER_SILVER -CFLAGS_MODULE += -DCONFIG_OPLUS_PREFER_SILVER -endif - #Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for multibits backlight ifeq ($(OPLUS_FEATURE_MULTIBITS_BL),yes) KBUILD_CFLAGS += -DOPLUS_FEATURE_MULTIBITS_BL diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 82249c1c48aa..b69a826c9c33 100755 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -46,9 +46,6 @@ #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, @@ -529,9 +526,6 @@ done: */ if (major) { tsk->maj_flt++; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_fs_stats(FS_MAJOR_FAULT, 1); -#endif /*OPLUS_FEATURE_IOMONITOR*/ perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr); } else { diff --git a/block/Kconfig b/block/Kconfig index 620d761e169c..4d9bcb951d83 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -230,8 +230,3 @@ config BLK_MQ_RDMA default y source block/Kconfig.iosched - -#ifdef OPLUS_FEATURE_FG_IO_OPT -#/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -source block/foreground_io_opt/Kconfig -#endif \ No newline at end of file diff --git a/block/Makefile b/block/Makefile index 7e732f7c6bf1..3316cadbd36f 100644 --- a/block/Makefile +++ b/block/Makefile @@ -39,7 +39,3 @@ obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += keyslot-manager.o bio-crypt-ctx.o \ blk-crypto.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o -#ifdef OPLUS_FEATURE_FG_IO_OPT -#/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -obj-$(CONFIG_OPLUS_FG_IO_OPT) += foreground_io_opt/ -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ \ No newline at end of file diff --git a/block/blk-core.c b/block/blk-core.c index 4b79ef733a97..daa722b2e91c 100755 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -45,18 +45,11 @@ #include "blk-mq-sched.h" #include "blk-wbt.h" -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -#include "foreground_io_opt/foreground_io_opt.h" -#endif #ifdef CONFIG_DEBUG_FS struct dentry *blk_debugfs_root; #endif -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap); EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap); @@ -126,10 +119,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq) memset(rq, 0, sizeof(*rq)); INIT_LIST_HEAD(&rq->queuelist); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - INIT_LIST_HEAD(&rq->fg_list); -#endif INIT_LIST_HEAD(&rq->timeout_list); rq->cpu = -1; rq->q = q; @@ -848,10 +837,6 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) gfp_mask | __GFP_ZERO, node_id); if (!q) return NULL; -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - INIT_LIST_HEAD(&q->fg_head); -#endif q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask); if (q->id < 0) goto fail_q; @@ -873,10 +858,6 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) q->backing_dev_info->capabilities = BDI_CAP_CGROUP_WRITEBACK; q->backing_dev_info->name = "block"; q->node = node_id; -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - fg_bg_max_count_init(q); -#endif setup_timer(&q->backing_dev_info->laptop_mode_wb_timer, laptop_mode_timer_fn, (unsigned long) q); setup_timer(&q->timeout, blk_rq_timed_out_timer, (unsigned long) q); @@ -1320,9 +1301,6 @@ out: */ if (ioc_batching(q, ioc)) ioc->nr_batch_requests--; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_init_reqstats(rq); -#endif /*OPLUS_FEATURE_IOMONITOR*/ trace_block_getrq(q, bio, op); return rq; @@ -1814,11 +1792,6 @@ void blk_init_request_from_bio(struct request *req, struct bio *bio) if (bio->bi_opf & REQ_RAHEAD) req->cmd_flags |= REQ_FAILFAST_MASK; -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - if (bio->bi_opf & REQ_FG) - req->cmd_flags |= REQ_FG; -#endif req->__sector = bio->bi_iter.bi_sector; if (ioprio_valid(bio_prio(bio))) req->ioprio = bio_prio(bio); @@ -2315,17 +2288,11 @@ blk_qc_t submit_bio(struct bio *bio) if (op_is_write(bio_op(bio))) { count_vm_events(PGPGOUT, count); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_vm_stats(PGPGOUT, count); -#endif/*OPLUS_FEATURE_IOMONITOR*/ } else { if (bio_flagged(bio, BIO_WORKINGSET)) workingset_read = true; task_io_account_read(bio->bi_iter.bi_size); count_vm_events(PGPGIN, count); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_vm_stats(PGPGIN, count); -#endif/*OPLUS_FEATURE_IOMONITOR*/ } if (unlikely(block_dump)) { @@ -2337,11 +2304,6 @@ blk_qc_t submit_bio(struct bio *bio) bio_devname(bio, b), count); } } -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - if (high_prio_for_task(current)) - bio->bi_opf |= REQ_FG; -#endif /* * If we're reading data that is part of the userspace * workingset, count submission time as memory stall. When the @@ -2634,9 +2596,6 @@ struct request *blk_peek_request(struct request_queue *q) * not be passed by new incoming requests */ rq->rq_flags |= RQF_STARTED; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - rq->req_td = ktime_get(); -#endif /*OPLUS_FEATURE_IOMONITOR*/ trace_block_rq_issue(q, rq); } @@ -2696,9 +2655,6 @@ struct request *blk_peek_request(struct request_queue *q) break; } } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_record_io_history(rq); -#endif /*OPLUS_FEATURE_IOMONITOR*/ return rq; } EXPORT_SYMBOL(blk_peek_request); @@ -2711,11 +2667,6 @@ static void blk_dequeue_request(struct request *rq) BUG_ON(ELV_ON_HASH(rq)); list_del_init(&rq->queuelist); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - if (sysctl_fg_io_opt && (rq->cmd_flags & REQ_FG)) - list_del_init(&rq->fg_list); -#endif /* * the time frame between a request being removed from the lists * and to it is freed is accounted as io that is in progress at @@ -2725,10 +2676,6 @@ static void blk_dequeue_request(struct request *rq) q->in_flight[rq_is_sync(rq)]++; set_io_start_time_ns(rq); } -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue - ohm_ioqueue_add_inflight(q, rq); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ } /** @@ -2811,9 +2758,6 @@ bool blk_update_request(struct request *req, blk_status_t error, int total_bytes; trace_block_rq_complete(req, blk_status_to_errno(error), nr_bytes); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_record_reqstats(req, nr_bytes); -#endif /*OPLUS_FEATURE_IOMONITOR*/ if (!req->bio) return false; diff --git a/block/blk-flush.c b/block/blk-flush.c index b5eed90ca0c3..23ba36f34e1a 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -76,10 +76,6 @@ #include "blk-mq-tag.h" #include "blk-mq-sched.h" -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -#include "foreground_io_opt/foreground_io_opt.h" -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ /* PREFLUSH/FUA sequences */ enum { @@ -147,10 +143,6 @@ static bool blk_flush_queue_rq(struct request *rq, bool add_front) list_add(&rq->queuelist, &rq->q->queue_head); else list_add_tail(&rq->queuelist, &rq->q->queue_head); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - queue_throtl_add_request(rq->q, rq, add_front); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ return true; } } @@ -474,15 +466,7 @@ void blk_insert_flush(struct request *rq) if (q->mq_ops) blk_mq_sched_insert_request(rq, false, true, false, false); else -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - { list_add_tail(&rq->queuelist, &q->queue_head); - queue_throtl_add_request(q, rq, false); - } -#else - list_add_tail(&rq->queuelist, &q->queue_head); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ return; } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index c82cadba24fc..5d5710bb1d48 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -16,10 +16,6 @@ #include "blk-mq.h" #include "blk-mq-debugfs.h" #include "blk-wbt.h" -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -#include "foreground_io_opt/foreground_io_opt.h" -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ struct queue_sysfs_entry { struct attribute attr; @@ -400,19 +396,6 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, return count; } -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue -static ssize_t queue_show_ohm_inflight(struct request_queue *q, char *page) -{ - ssize_t ret; - - ret = sprintf(page, "async:%d\n", q->in_flight[0]); - ret += sprintf(page + ret, "sync:%d\n", q->in_flight[1]); - ret += sprintf(page + ret, "bg:%d\n", q->in_flight[2]); - ret += sprintf(page + ret, "fg:%d\n", q->in_flight[3]); - return ret; -} -#endif /*OPLUS_FEATURE_HEALTHINFO*/ static ssize_t queue_poll_show(struct request_queue *q, char *page) { @@ -667,13 +650,6 @@ static struct queue_sysfs_entry queue_iostats_entry = { .store = queue_store_iostats, }; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue -static struct queue_sysfs_entry queue_ohm_inflight_entry = { - .attr = {.name = "ohm_inflight", .mode = S_IRUGO }, - .show = queue_show_ohm_inflight, -}; -#endif /*OPLUS_FEATURE_HEALTHINFO*/ static struct queue_sysfs_entry queue_random_entry = { .attr = {.name = "add_random", .mode = S_IRUGO | S_IWUSR }, @@ -722,27 +698,9 @@ static struct queue_sysfs_entry throtl_sample_time_entry = { .store = blk_throtl_sample_time_store, }; #endif -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -static struct queue_sysfs_entry queue_fgio_entry = { - .attr = {.name = "fg_io_cnt_max", .mode = S_IRUGO | S_IWUSR }, - .show = queue_fg_count_max_show, - .store = queue_fg_count_max_store, -}; -static struct queue_sysfs_entry queue_bothio_entry = { - .attr = {.name = "both_io_cnt_max", .mode = S_IRUGO | S_IWUSR }, - .show = queue_both_count_max_show, - .store = queue_both_count_max_store, -}; -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ static struct attribute *default_attrs[] = { &queue_requests_entry.attr, &queue_ra_entry.attr, -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - &queue_fgio_entry.attr, - &queue_bothio_entry.attr, -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ &queue_max_hw_sectors_entry.attr, &queue_max_sectors_entry.attr, &queue_max_segments_entry.attr, @@ -767,10 +725,6 @@ static struct attribute *default_attrs[] = { &queue_nomerges_entry.attr, &queue_rq_affinity_entry.attr, &queue_iostats_entry.attr, -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue - &queue_ohm_inflight_entry.attr, -#endif /*OPLUS_FEATURE_HEALTHINFO*/ &queue_random_entry.attr, &queue_poll_entry.attr, &queue_wc_entry.attr, diff --git a/block/blk.h b/block/blk.h index 1d1e733ddec8..4f8173640f3a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -5,9 +5,6 @@ #include #include #include "blk-mq.h" -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -#include -#endif /* Amount of time in which a process may batch requests */ #define BLK_BATCH_TIME (HZ/50UL) @@ -20,10 +17,6 @@ #ifdef CONFIG_DEBUG_FS extern struct dentry *blk_debugfs_root; #endif -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -extern unsigned int sysctl_fg_io_opt; -extern struct request * smart_peek_request(struct request_queue *q); -#endif struct blk_flush_queue { unsigned int flush_queue_delayed:1; unsigned int flush_pending_idx:1; @@ -162,27 +155,10 @@ static inline struct request *__elv_next_request(struct request_queue *q) WARN_ON_ONCE(q->mq_ops); while (1) { -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - if (likely(sysctl_fg_io_opt) -#ifdef CONFIG_PM - &&(q->rpm_status == RPM_ACTIVE) -#endif - ) { - rq = smart_peek_request(q); - if(rq) - return rq; - } - else { -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ if (!list_empty(&q->queue_head)) { rq = list_entry_rq(q->queue_head.next); return rq; } -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - } -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ /* * Flush request is running and flush request isn't queueable * in the drive, we can hold the queue till flush request is diff --git a/block/elevator.c b/block/elevator.c index 9a1b356b8b49..8f7a0eeedfe2 100755 --- a/block/elevator.c +++ b/block/elevator.c @@ -42,10 +42,6 @@ #include "blk.h" #include "blk-mq-sched.h" #include "blk-wbt.h" -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -#include "foreground_io_opt/foreground_io_opt.h" -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ static DEFINE_SPINLOCK(elv_list_lock); static LIST_HEAD(elv_list); @@ -418,10 +414,6 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq) } list_add(&rq->queuelist, entry); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - queue_throtl_add_request(q, rq, false); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ } EXPORT_SYMBOL(elv_dispatch_sort); @@ -442,10 +434,6 @@ void elv_dispatch_add_tail(struct request_queue *q, struct request *rq) q->end_sector = rq_end_sector(rq); q->boundary_rq = rq; list_add_tail(&rq->queuelist, &q->queue_head); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - queue_throtl_add_request(q, rq, false); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ } EXPORT_SYMBOL(elv_dispatch_add_tail); @@ -618,10 +606,6 @@ void elv_requeue_request(struct request_queue *q, struct request *rq) */ if (blk_account_rq(rq)) { q->in_flight[rq_is_sync(rq)]--; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue - ohm_ioqueue_dec_inflight(q, rq); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ if (rq->rq_flags & RQF_SORTED) elv_deactivate_rq(q, rq); } @@ -654,9 +638,6 @@ void elv_drain_elevator(struct request_queue *q) void __elv_add_request(struct request_queue *q, struct request *rq, int where) { -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - rq->req_ti = ktime_get(); -#endif /*OPLUS_FEATURE_IOMONITOR*/ trace_block_rq_insert(q, rq); @@ -680,20 +661,12 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) case ELEVATOR_INSERT_FRONT: rq->rq_flags |= RQF_SOFTBARRIER; list_add(&rq->queuelist, &q->queue_head); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - queue_throtl_add_request(q, rq, true); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ break; case ELEVATOR_INSERT_BACK: rq->rq_flags |= RQF_SOFTBARRIER; elv_drain_elevator(q); list_add_tail(&rq->queuelist, &q->queue_head); -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - queue_throtl_add_request(q, rq, false); -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ /* * We kick the queue here for the following reasons. * - The elevator might have returned NULL previously @@ -828,10 +801,6 @@ void elv_completed_request(struct request_queue *q, struct request *rq) */ if (blk_account_rq(rq)) { q->in_flight[rq_is_sync(rq)]--; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue - ohm_ioqueue_dec_inflight(q, rq); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ if ((rq->rq_flags & RQF_SORTED) && e->type->ops.sq.elevator_completed_req_fn) e->type->ops.sq.elevator_completed_req_fn(q, rq); diff --git a/block/foreground_io_opt/Kconfig b/block/foreground_io_opt/Kconfig deleted file mode 100755 index d9186c455523..000000000000 --- a/block/foreground_io_opt/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config OPLUS_FG_IO_OPT - bool "Enable foreground io optimization" - depends on FG_TASK_UID - default y - help - foreground io optimization diff --git a/block/foreground_io_opt/Makefile b/block/foreground_io_opt/Makefile deleted file mode 100755 index ac77170aa4af..000000000000 --- a/block/foreground_io_opt/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -obj-y += high_prio_task.o foreground_io_opt.o diff --git a/block/foreground_io_opt/foreground_io_opt.c b/block/foreground_io_opt/foreground_io_opt.c deleted file mode 100755 index d9acdac04f0f..000000000000 --- a/block/foreground_io_opt/foreground_io_opt.c +++ /dev/null @@ -1,165 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "foreground_io_opt.h" - -#define CREATE_TRACE_POINTS -#include - -#define FG_CNT_DEF 20 -#define BOTH_CNT_DEF 10 - -void fg_bg_max_count_init(struct request_queue *q) -{ - q->fg_count_max = FG_CNT_DEF; - q->both_count_max = BOTH_CNT_DEF; - - q->fg_count = FG_CNT_DEF; - q->both_count = BOTH_CNT_DEF; -} - -static inline bool should_get_fg_req(struct request_queue *q) -{ - if (!list_empty(&q->fg_head) - && (q->fg_count > 0)) - return true; - - return false; -} - -static inline bool should_get_bg_req(struct request_queue *q) -{ - if (q->both_count > 0) - return true; - - return false; -} - -static struct request *get_fg_bg_req(struct request_queue *q) -{ - - struct request *rq = NULL; - - if (!list_empty(&q->queue_head)) { - if (should_get_fg_req(q)) { - rq = list_entry(q->fg_head.next, struct request, fg_list); - q->fg_count--; - trace_block_fg_io_peek_req(current, (long)rq,"FG\0",q->fg_count); - } - else if (should_get_bg_req(q)) { - rq = list_entry_rq(q->queue_head.next); - q->both_count--; - trace_block_fg_io_peek_req(current, (long)rq,"BG\0",q->both_count); - } - else { - q->fg_count = q->fg_count_max; - q->both_count = q->both_count_max; - rq = list_entry_rq(q->queue_head.next); - } - } - return rq; -} - -struct request * smart_peek_request(struct request_queue *q) -{ - return get_fg_bg_req(q); -} - -void queue_throtl_add_request(struct request_queue *q, - struct request *rq, bool front) -{ - struct list_head *head; - - if (unlikely(!sysctl_fg_io_opt)) - return; - - if (rq->cmd_flags & REQ_FG) { - head = &q->fg_head; - if (front) - list_add(&rq->fg_list, head); - else - list_add_tail(&rq->fg_list, head); - } -} - -/*blk-sys*/ -static ssize_t -queue_var_show(unsigned long var, char *page) -{ - if (unlikely(!sysctl_fg_io_opt)) - return 0; - - return sprintf(page, "%lu\n", var); -} - -static ssize_t -queue_var_store(unsigned long *var, const char *page, size_t count) -{ - int err; - unsigned long v; - - if (unlikely(!sysctl_fg_io_opt)) - return 0; - - err = kstrtoul(page, 10, &v); - if (err || v > UINT_MAX) - return -EINVAL; - - *var = v; - - return count; -} - -ssize_t queue_fg_count_max_show(struct request_queue *q, - char *page) -{ - int cnt = q->fg_count_max; - - return queue_var_show(cnt, (page)); -} - -ssize_t queue_fg_count_max_store(struct request_queue *q, - const char *page, size_t count) -{ - unsigned long cnt; - ssize_t ret = queue_var_store(&cnt, page, count); - - if (ret < 0) - return ret; - - q->fg_count_max= cnt; - - return ret; -} - -ssize_t queue_both_count_max_show(struct request_queue *q, - char *page) -{ - int cnt = q->both_count_max; - - return queue_var_show(cnt, (page)); -} - -ssize_t queue_both_count_max_store(struct request_queue *q, - const char *page, size_t count) -{ - unsigned long cnt; - ssize_t ret = queue_var_store(&cnt, page, count); - - if (ret < 0) - return ret; - - q->both_count_max= cnt; - - return ret; -} diff --git a/block/foreground_io_opt/foreground_io_opt.h b/block/foreground_io_opt/foreground_io_opt.h deleted file mode 100755 index 306b9fe4cfdb..000000000000 --- a/block/foreground_io_opt/foreground_io_opt.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef __OPLUS_FOREGROUND_IO_OPT__ -#define __OPLUS_FOREGROUND_IO_OPT__ - -#ifdef CONFIG_FG_TASK_UID -#include -#endif /*CONFIG_FG_TASK_UID*/ - -extern unsigned int sysctl_fg_io_opt; - -extern void fg_bg_max_count_init(struct request_queue *q); -extern void queue_throtl_add_request(struct request_queue *q, - struct request *rq, bool front); -extern ssize_t queue_fg_count_max_show(struct request_queue *q, - char *page); -extern ssize_t queue_fg_count_max_store(struct request_queue *q, - const char *page, size_t count); -extern ssize_t queue_both_count_max_show(struct request_queue *q, - char *page); -extern ssize_t queue_both_count_max_store(struct request_queue *q, - const char *page, size_t count); -extern bool high_prio_for_task(struct task_struct *t); -extern struct request * smart_peek_request(struct request_queue *q); -#endif /*__OPLUS_FOREGROUND_IO_OPT__*/ diff --git a/block/foreground_io_opt/high_prio_task.c b/block/foreground_io_opt/high_prio_task.c deleted file mode 100755 index 4ec9be741bc9..000000000000 --- a/block/foreground_io_opt/high_prio_task.c +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "foreground_io_opt.h" - -#define SYSTEM_APP_UID 1000 - -static bool is_system_uid(struct task_struct *t) -{ - int cur_uid; - cur_uid = task_uid(t).val; - if (cur_uid == SYSTEM_APP_UID) - return true; - - return false; -} - -static bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - - struct task_struct * first_child = NULL; - if(t->children.next && t->children.next != (struct list_head*)&t->children.next) - first_child = container_of(t->children.next, struct task_struct, sibling); - if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 && !strcmp(t->parent->comm,"init")) ) - return true; - else - return false; - return false; -} - -static bool is_system_process(struct task_struct *t) -{ - if (is_system_uid(t)) { - if (t->group_leader && (!strncmp(t->group_leader->comm,"system_server", 13) || - !strncmp(t->group_leader->comm, "surfaceflinger", 14) || - !strncmp(t->group_leader->comm, "servicemanager", 14) || - !strncmp(t->group_leader->comm, "ndroid.systemui", 15))) - return true; - } - return false; -} - -bool is_critial_process(struct task_struct *t) -{ - if( is_zygote_process(t) || is_system_process(t)) - return true; - - return false; -} - -bool is_filter_process(struct task_struct *t) -{ - if(!strncmp(t->comm,"logcat", TASK_COMM_LEN) ) - return true; - - return false; -} -static inline bool is_fg_task_without_sysuid(struct task_struct *t) -{ - if(!is_system_uid(t) -#ifdef CONFIG_FG_TASK_UID - &&is_fg(task_uid(t).val) -#endif /*CONFIG_FG_TASK_UID*/ - ) - return true; - - return false; - -} - -bool high_prio_for_task(struct task_struct *t) -{ - if (!sysctl_fg_io_opt) - return false; - - if ((is_fg_task_without_sysuid(t) && !is_filter_process(t)) - || is_critial_process(t)) - return true; - - return false; -} diff --git a/block/foreground_io_opt/trace/foreground_io_opt_trace.h b/block/foreground_io_opt/trace/foreground_io_opt_trace.h deleted file mode 100755 index c3ce10e9444b..000000000000 --- a/block/foreground_io_opt/trace/foreground_io_opt_trace.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#undef TRACE_SYSTEM -#define TRACE_INCLUDE_PATH ../../block/foreground_io_opt/trace -#define TRACE_SYSTEM foreground_io_opt_trace - -#if !defined(_OPLUS_FOREGROUND_IO_OPT_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) -#define _OPLUS_FOREGROUND_IO_OPT_TRACE_H - -#include - -/*trace*/ -TRACE_EVENT(block_fg_io_peek_req, - TP_PROTO(struct task_struct *task, long req_addr, \ - char * fg, int count), - - TP_ARGS(task, req_addr, fg, count), - - TP_STRUCT__entry( - __array(char, comm, TASK_COMM_LEN) - __field(pid_t, pid) - __field(long, req_addr) - __array(char, fg, 3) - __field(int, count) - ), - - TP_fast_assign( - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); - __entry->pid = task->pid; - __entry->req_addr = req_addr; - memcpy(__entry->fg, fg, 3); - __entry->count = count; - ), - - TP_printk("%s (%d), req_addr %x task_group:%s, count %d", - __entry->comm, __entry->pid, __entry->req_addr, - __entry->fg, __entry->count) -); -#endif /*_OPLUS_FOREGROUND_IO_OPT_TRACE_H*/ -#include diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 5070624cd0f3..82eddff6a2b2 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -212,12 +212,6 @@ static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter) __set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok); __set_bit(GPCMD_SET_STREAMING, filter->write_ok); __set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok); -#ifdef OPLUS_FEATURE_STORAGE_TOOL -// add write buffer command for common user -// add vendor command for common user - __set_bit(WRITE_BUFFER, filter->write_ok); - __set_bit(VENDOR_SPECIFIC_CDB, filter->write_ok); -#endif } int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm) @@ -444,11 +438,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, unsigned int in_len, out_len, bytes, opcode, cmdlen; char *buffer = NULL; -#ifdef OPLUS_FEATURE_STORAGE_TOOL -// vendor cmd len is 16 and not 10 in spec. -// in current application ,only samsung health will use this cmd. - struct scsi_device *sdev = NULL; -#endif if (!sic) return -EINVAL; @@ -482,16 +471,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, cmdlen = COMMAND_SIZE(opcode); -#ifdef OPLUS_FEATURE_STORAGE_TOOL -// vendor cmd len is 16 and not 10 in spec. -// in current application ,only samsung health will use this cmd. - sdev = (struct scsi_device*)(q->queuedata); - if ((VENDOR_SPECIFIC_CDB == opcode) - &&(0 == strncmp(sdev->vendor, "SAMSUNG ", 8)) - ){ - cmdlen = 16; - } -#endif /* * get command and data to send to device, if any */ diff --git a/drivers/android/binder.c b/drivers/android/binder.c index a38c8c23a866..f77e8d0cc064 100755 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -78,14 +78,7 @@ #include "binder_internal.h" #include "binder_trace.h" -#ifdef OPLUS_FEATURE_HANS_FREEZE -// Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -#include -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_MTK_TASK_TURBO #include @@ -165,38 +158,6 @@ module_param_named(devices, binder_devices_param, charp, 0444); static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait); static int binder_stop_on_user_error; -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - -#include - -#define OPLUS_MAX_SERVICE_NAME_LEN 32 -#define OPLUS_MAGIC_SERVICE_NAME_OFFSET 76 - -struct binder_notify { - struct task_struct *caller_task; - struct task_struct *binder_task; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool pending_async; -}; - -static ATOMIC_NOTIFIER_HEAD(binderevent_notif_chain); - -int register_binderevent_notifier(struct notifier_block *nb) { - return atomic_notifier_chain_register(&binderevent_notif_chain, nb); -} -EXPORT_SYMBOL_GPL(register_binderevent_notifier); - -int unregister_binderevent_notifier(struct notifier_block *nb) { - return atomic_notifier_chain_unregister(&binderevent_notif_chain, nb); -} -EXPORT_SYMBOL_GPL(unregister_binderevent_notifier); - -int call_binderevent_notifiers(unsigned long val, void *v) { - return atomic_notifier_call_chain(&binderevent_notif_chain, val, v); -} -EXPORT_SYMBOL_GPL(call_binderevent_notifiers); - -#endif // #if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) static int binder_set_stop_on_user_error(const char *val, const struct kernel_param *kp) @@ -330,9 +291,6 @@ struct binder_work { BINDER_WORK_DEAD_BINDER_AND_CLEAR, BINDER_WORK_CLEAR_DEATH_NOTIFICATION, } type; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - u64 ob_begin; -#endif }; struct binder_error { @@ -444,9 +402,6 @@ struct binder_node { #ifdef BINDER_WATCHDOG char name[MAX_SERVICE_NAME_LEN]; #endif -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; -#endif }; struct binder_ref_death { @@ -607,15 +562,8 @@ struct binder_proc { int deferred_work; bool is_dead; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - int proc_type; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ struct list_head todo; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - struct list_head ux_todo; - uint32_t ux_count; -#endif struct binder_stats stats; struct list_head delivered_death; int max_threads; @@ -638,9 +586,6 @@ enum { BINDER_LOOPER_STATE_INVALID = 0x08, BINDER_LOOPER_STATE_WAITING = 0x10, BINDER_LOOPER_STATE_POLL = 0x20, -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - BINDER_LOOPER_STATE_BACKGROUND = 0x40, -#endif }; /** @@ -1328,57 +1273,6 @@ struct binder_object { }; }; -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - -static void oplus_parse_service_name(struct binder_transaction_data *tr, - struct binder_proc *proc, - char *name) { - unsigned int i, len = 0; - char *tmp; - char c; - char sname[OPLUS_MAX_SERVICE_NAME_LEN]; - - if (NULL != tr && tr->target.handle == 0 && NULL != proc && NULL != proc->context) { - if (!strcmp(proc->context->name, "hwbinder")) { - strcpy(sname, "hwbinderService"); - } else { - for (i = 0; (2 * i) < tr->data_size; i++) { - if ((2 * i) < OPLUS_MAGIC_SERVICE_NAME_OFFSET) { - continue; - } - if (len >= (OPLUS_MAX_SERVICE_NAME_LEN - 1)) - break; - tmp = (char *)(uintptr_t)(tr->data.ptr.buffer + (2*i)); - get_user(c, tmp); - if (c >= 32 && c <= 126) { // visible character range [32, 126] - if (len < OPLUS_MAX_SERVICE_NAME_LEN - 1) - len += sprintf(sname + len, "%c", c); - else - break; - } - if ('\0' == c) { - break; - } - } - sname[len] = '\0'; - } - pr_info("context.name[%s] tr.size:%lu service:%s\n", - proc->context->name, (unsigned long)tr->data_size, sname); - } else { - if (NULL != tr && 0 != tr->target.handle) { - sprintf(sname, "AnonymousCallback"); - } else { - sprintf(sname, "unknown"); - } - } - - if (NULL != name){ - strncpy(name, sname, OPLUS_MAX_SERVICE_NAME_LEN); - name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - } -} - -#endif // #if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) /** * binder_proc_lock() - Acquire outer lock for given binder_proc @@ -1678,452 +1572,6 @@ static void task_fd_install( mutex_unlock(&proc->files_lock); } -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -#include - - -#define BINDER_LOOPER_STATE_BACKGROUND 0x40 -#define OBPROC_CHECK_CYCLE_NS 100000000 -#define OBWORK_TIMEOUT_NS 800000000 -#define BG_THREAD (2) -#define SA_CGROUP_BACKGROUND (3) -#define MAX_UX_WORK_CONTINUOUS (10) - -struct ob_struct ob_target; -pid_t ob_pid; -int ob_err; -int sysctl_ob_control_enable = 1; -int sysctl_binder_status_record = 1; - -static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer) -{ - return list_entry(buffer->entry.next, struct binder_buffer, entry); -} - -static size_t binder_alloc_buffer_size(struct binder_alloc *alloc, - struct binder_buffer *buffer) -{ - if (list_is_last(&buffer->entry, &alloc->buffers)) - return alloc->buffer + alloc->buffer_size - buffer->user_data; - return binder_buffer_next(buffer)->user_data - buffer->user_data; -} - -/* - * Check amount and size of buffers allocated for - * async and sync binder transactions. - * Warn if free_async_space low has been used lower than 1/5 * (alloc->buffer_size * 1/2). - * Warn if total_alloc_size_unoneway has been larger than 9 / 10 * alloc->buffer_size. - */ -#ifdef CONFIG_OPLUS_HEALTHINFO -void obinder_low_mem_check(struct binder_alloc *alloc) -{ - struct rb_node *n = alloc->free_buffers.rb_node; - struct binder_buffer *buffer; - size_t total_alloc_size_oneway = 0; - size_t total_alloc_size_unoneway = 0; - size_t oneway_buffers = 0; - size_t unoneway_buffers = 0; - - if (alloc->pid != ob_target.pid) - return; - if (!sysctl_binder_status_record) - return; - mutex_lock(&alloc->mutex); - for (n = rb_first(&alloc->allocated_buffers); n != NULL; - n = rb_next(n)) { - buffer = rb_entry(n, struct binder_buffer, rb_node); - if (buffer->async_transaction) { - total_alloc_size_oneway += binder_alloc_buffer_size(alloc, buffer) - + sizeof(struct binder_buffer); - oneway_buffers++; - } else { - total_alloc_size_unoneway += binder_alloc_buffer_size(alloc, buffer) - + sizeof(struct binder_buffer); - unoneway_buffers++; - } - } - if (alloc->free_async_space < alloc->buffer_size / 10) { - system_server_proc_status.async_mem_over_low++; - if (alloc->free_async_space < alloc->buffer_size / 20) - system_server_proc_status.async_mem_over_high++; - } - - if (total_alloc_size_unoneway > alloc->buffer_size * 70 / 100) { - system_server_proc_status.sync_mem_over_low++; - if (total_alloc_size_unoneway > alloc->buffer_size * 90 / 100) - system_server_proc_status.sync_mem_over_high++; - } - mutex_unlock(&alloc->mutex); - return; -} -#endif -/* - * Try to boost async which need large allocated buffer by list_add. -*/ -void obset_async_boost_work(struct binder_buffer *buffer, struct binder_transaction *t, - struct binder_proc *proc, struct binder_alloc *alloc, bool is_async) -{ - size_t size, data_offsets_size; - - data_offsets_size = ALIGN(buffer->data_size, sizeof(void *)) - +ALIGN(buffer->offsets_size, sizeof(void *)); - size = data_offsets_size + ALIGN(buffer->extra_buffers_size, sizeof(void *)); - if (ob_target.ob_proc != proc) - return; -#ifdef CONFIG_OPLUS_HEALTHINFO - obinder_low_mem_check(alloc); -#endif - if (!sysctl_ob_control_enable) - return; - if (!is_async) - return; - mutex_lock(&alloc->mutex); - if (size + sizeof(struct binder_buffer) > alloc->free_async_space / 100) { - if (!(t->flags & TF_ASYNC_BOOST)) { - t->flags |= TF_ASYNC_BOOST; - } - } - mutex_unlock(&alloc->mutex); - return; -} - -noinline void ob_tracing_mark_write(const char *buf) -{ - trace_printk(buf); -} - -void ob_sysctrace_c(struct binder_proc *proc, struct binder_thread *thread) -{ - char buf[256]; - - snprintf(buf, sizeof(buf), "C|%d|oplus_bt%s|%d", proc->pid, thread->task->comm, 1); - ob_tracing_mark_write(buf); -} - -int get_task_cgroup_id(struct task_struct *task) -{ - struct cgroup_subsys_state *css = task_css(task, schedtune_cgrp_id); - return css ? css->id : -1; -} - -bool test_task_bg(struct task_struct *task) -{ - return (SA_CGROUP_BACKGROUND == get_task_cgroup_id(task)) ? 1 : 0; -} - -bool obtrans_is_from_background(struct binder_transaction *t) -{ - return test_task_bg(t->from->task); -} - -bool obtrans_is_from_third_party(struct binder_transaction *t) -{ - return (from_kuid(current_user_ns(), t->sender_euid) % 100000) >= 10000; -} - -bool obtrans_is_from_main(struct binder_transaction *t) -{ - return t->from->proc->pid == t->from->pid; -} - -bool obwork_is_ux_boost(struct binder_transaction *t) -{ - if ((!t->from) || (!t->from->proc)) - return false; - if (!test_task_ux(t->from->task)) - return false; - else - return true; -} - -bool obwork_is_async_boost(struct binder_transaction *t) -{ - if (!sysctl_ob_control_enable) - return false; - if (t->flags & TF_ASYNC_BOOST) - return true; - return false; -} - -bool obwork_is_restrict(struct binder_transaction *t) -{ - if ((!t->from) || (!t->from->proc)) - return false; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_SCHED_ASSIST) - return obtrans_is_from_background(t) && obtrans_is_from_third_party(t) && - !obtrans_is_from_main(t) && !test_task_ux(t->from->task); -#else - return obtrans_is_from_background(t) && obtrans_is_from_third_party(t) && - !obtrans_is_from_main(t); -#endif -} - -void obwork_check_restrict_off(struct binder_proc *proc) -{ - struct binder_work *w = NULL; - struct binder_work *tmp = NULL; - struct binder_transaction *t = NULL; - u64 now = sched_clock(); - if (proc != ob_target.ob_proc || binder_worklist_empty_ilocked(&ob_target.ob_list) || (now - ob_target.ob_check_ts) < OBPROC_CHECK_CYCLE_NS) - return; - list_for_each_entry_safe(w, tmp, &ob_target.ob_list, entry) { - if (!w) - continue; - t = container_of(w, struct binder_transaction, work); - if ((now - w->ob_begin < OBWORK_TIMEOUT_NS)) - break; - list_del_init(&w->entry); - binder_enqueue_work_ilocked(w, &proc->todo); - } - ob_target.ob_check_ts = sched_clock(); -} - -void obtrans_restrict_start(struct binder_proc *proc, struct binder_transaction *t) -{ - if (!sysctl_ob_control_enable) - return; - if (obwork_is_restrict(t)) - t->work.ob_begin = sched_clock(); - obwork_check_restrict_off(proc); -} - -void oblist_dequeue_all(void) -{ - struct binder_work *w; - struct binder_work *w_tmp; - - if (ob_target.ob_proc == NULL) - return; - binder_inner_proc_lock(ob_target.ob_proc); - if (binder_worklist_empty_ilocked(&ob_target.ob_list)) { - binder_inner_proc_unlock(ob_target.ob_proc); - return; - } - list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) { - if (!w) - continue; - list_del_init(&w->entry); - binder_enqueue_work_ilocked(w, &ob_target.ob_proc->todo); - } - binder_inner_proc_unlock(ob_target.ob_proc); - return; -} - - -/* - * When top app changed, we need to check if it's binder had been pushed to ob list before - */ -void oblist_dequeue_topapp_change(uid_t topuid) -{ - struct binder_work *w; - struct binder_work *w_tmp; - struct binder_transaction *t; - if (ob_target.ob_proc == NULL) - return; - binder_inner_proc_lock(ob_target.ob_proc); - if (!binder_worklist_empty_ilocked(&ob_target.ob_list)) { - list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) { - if (!w) - continue; - t = container_of(w, struct binder_transaction, work); - if (from_kuid(current_user_ns(), t->sender_euid) != topuid) - continue; - list_del_init(&w->entry); - binder_enqueue_work_ilocked(w, &ob_target.ob_proc->todo); - } - } - binder_inner_proc_unlock(ob_target.ob_proc); - return; -} - -static inline int list_is_first(const struct list_head *list, - const struct list_head *head) -{ - return list->prev == head; -} - -void obinder_enqueue_work_head_ilocked(struct binder_work *work, struct list_head *target_list) -{ - BUG_ON(target_list == NULL); - BUG_ON(work->entry.next && !list_empty(&work->entry)); - list_add(&work->entry, target_list); -} - -void obbinder_thread_check_status(struct binder_proc *proc) -{ - - struct binder_thread *thread; - struct rb_node *n; - struct binder_transaction *tmp; - int doing_bg = 0; - int doing_fg = 0; - - if (!sysctl_binder_status_record) - return; - if (!proc) - return; - if (&proc->threads == NULL) - return; - if (!(proc == ob_target.ob_proc)) - return; - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) { - thread = rb_entry(n, struct binder_thread, rb_node); - if (thread && thread->looper & BINDER_LOOPER_STATE_REGISTERED) { - tmp = thread->transaction_stack; - if (tmp && !(tmp->flags & TF_ONE_WAY)) { - spin_lock(&tmp->lock); - if (!obwork_is_restrict(tmp)) - doing_fg++; - else { - doing_bg++; - } - spin_unlock(&tmp->lock); - } - } - } -#ifdef CONFIG_OPLUS_HEALTHINFO - system_server_proc_status.warning++; - if (doing_bg > doing_fg) { - system_server_proc_status.warning_cg_bg++; - } -#endif -} - -void obwork_restrict(struct binder_proc *proc, struct binder_transaction *t, bool pending_async) -{ - struct binder_node *node = t->buffer->target_node; - - if (!pending_async) { - obbinder_thread_check_status(proc); - if (sysctl_ob_control_enable && obwork_is_ux_boost(t)) { - binder_enqueue_work_ilocked(&t->work, &proc->ux_todo); - return; - } - if (!sysctl_ob_control_enable || (proc != ob_target.ob_proc) || !obwork_is_restrict(t)) - binder_enqueue_work_ilocked(&t->work, &proc->todo); - else - binder_enqueue_work_ilocked(&t->work, &ob_target.ob_list); - } else { - if (!sysctl_ob_control_enable || (proc != ob_target.ob_proc)) - binder_enqueue_work_ilocked(&t->work, &node->async_todo); - else if (obwork_is_async_boost(t)) - obinder_enqueue_work_head_ilocked(&t->work, &node->async_todo); - else - binder_enqueue_work_ilocked(&t->work, &node->async_todo); - } -} - - -void obtarget_init(struct binder_proc *proc) -{ - if (!proc->tsk || !proc->context || !proc->context->name) - return; - if (ob_target.init) - return; - if ((!strncmp(proc->tsk->comm, "system_server", TASK_COMM_LEN)) && !strcmp(proc->context->name, "binder")) { - ob_target.ob_proc = proc; - ob_target.ob_check_ts = sched_clock(); - INIT_LIST_HEAD(&ob_target.ob_list); - ob_target.pid = proc->pid; - ob_target.init = true; - } -} - -void obthread_init(struct binder_proc *proc, struct binder_thread *thread) -{ - if (proc != ob_target.ob_proc) - return; - if (proc->requested_threads_started == BG_THREAD) { - thread->looper |= BINDER_LOOPER_STATE_BACKGROUND; - ob_pid = thread->task->pid; - } -} - -bool ob_ux_todo_has_work(struct binder_thread *thread) -{ - return !binder_worklist_empty_ilocked(&thread->proc->ux_todo); -} - -bool check_ob_ux_todo_has_work(struct binder_thread *thread) -{ - if (!ob_ux_todo_has_work(thread)) { - thread->proc->ux_count = 0; - return false; - } else - return true; -} - -bool obthread_has_work(struct binder_thread *thread) -{ - if (!sysctl_ob_control_enable || !(thread->looper & BINDER_LOOPER_STATE_BACKGROUND) || (thread->proc != ob_target.ob_proc)) - return false; - return !binder_worklist_empty_ilocked(&ob_target.ob_list); -} - -static void binder_wakeup_proc_ilocked(struct binder_proc *proc); -void obproc_has_work(struct binder_proc *proc) -{ - struct binder_thread *thread = NULL; - - if (!binder_worklist_empty_ilocked(&ob_target.ob_list)) { - list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node) { - if (thread && (thread->looper & BINDER_LOOPER_STATE_BACKGROUND)) { - list_del_init(&thread->waiting_thread_node); - wake_up_interruptible(&thread->wait); - } - } - } - if (!binder_worklist_empty_ilocked(&proc->ux_todo)) { - binder_wakeup_proc_ilocked(proc); - } - return; -} - -void obproc_free(struct binder_proc *proc) -{ - if (proc == ob_target.ob_proc) { - BUG_ON(!list_empty(&ob_target.ob_list)); - ob_target.ob_check_ts = 0; - ob_target.ob_proc = NULL; - } -} - -void obprint_oblist(void) -{ - struct binder_work *w; - struct binder_work *w_tmp; - struct binder_transaction *t; - if (!sysctl_ob_control_enable) - return; - if (ob_target.ob_proc == NULL) - return; - if (binder_worklist_empty_ilocked(&ob_target.ob_list)) - return; - list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) { - if (!w) - continue; - t = container_of(w, struct binder_transaction, work); - if (!obwork_is_restrict(t)) - ob_err++; - } -} - -int sysctl_ob_control_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - if (write && *ppos) - *ppos = 0; - ret = proc_dointvec(table, write, buffer, lenp, ppos); - if (!write) - goto out; - if (!sysctl_ob_control_enable) { - pr_info("_%s dequeue all bg work", __func__); - oblist_dequeue_all(); - } -out: - return ret; -} -#endif /* * copied from sys_close @@ -2152,17 +1600,10 @@ err: static bool binder_has_work_ilocked(struct binder_thread *thread, bool do_proc_work) { -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - return thread->process_todo || - thread->looper_need_return || (do_proc_work && obthread_has_work(thread)) || (do_proc_work && ob_ux_todo_has_work(thread)) || - (do_proc_work && - !binder_worklist_empty_ilocked(&thread->proc->todo)); -#else return thread->process_todo || thread->looper_need_return || (do_proc_work && !binder_worklist_empty_ilocked(&thread->proc->todo)); -#endif } static bool binder_has_work(struct binder_thread *thread, bool do_proc_work) @@ -2230,22 +1671,6 @@ binder_select_thread_ilocked(struct binder_proc *proc) return thread; } -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -struct binder_thread *obthread_get(struct binder_proc *proc, struct binder_transaction *t, bool oneway) -{ - struct binder_thread *thread = NULL; - - if (sysctl_ob_control_enable && (proc == ob_target.ob_proc) && obwork_is_restrict(t)) { - list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node) - if (thread && (thread->looper & BINDER_LOOPER_STATE_BACKGROUND)) { - list_del_init(&thread->waiting_thread_node); - return thread; - } - return NULL; - } - return binder_select_thread_ilocked(proc); -} -#endif /** * binder_wakeup_thread_ilocked() - wakes up a thread for doing proc work. @@ -2406,17 +1831,10 @@ static void binder_restore_priority(struct task_struct *task, binder_do_set_priority(task, desired, /* verify = */ false); } -#ifdef OPLUS_FEATURE_SCHED_ASSIST -static void binder_transaction_priority(struct binder_thread *thread, struct task_struct *task, - struct binder_transaction *t, - struct binder_priority node_prio, - bool inherit_rt) -#else static void binder_transaction_priority(struct task_struct *task, struct binder_transaction *t, struct binder_priority node_prio, bool inherit_rt) -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ { struct binder_priority desired_prio = t->priority; @@ -2427,13 +1845,6 @@ static void binder_transaction_priority(struct task_struct *task, t->saved_priority.sched_policy = task->policy; t->saved_priority.prio = task->normal_prio; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - //NOTE: if task is main thread, and doesn't join pool as a binder thread, - //DON'T actually change priority in binder transaction. - if ((task->tgid == task->pid) && !(thread->looper & BINDER_LOOPER_STATE_ENTERED)) { - return; - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ if (!inherit_rt && is_rt_policy(desired_prio.sched_policy)) { desired_prio.prio = NICE_TO_PRIO(0); @@ -3737,7 +3148,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc, } } } -#if defined(BINDER_WATCHDOG) || defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) +#if defined(BINDER_WATCHDOG) static int binder_translate_binder(struct binder_transaction_data *tr, struct flat_binder_object *fp, struct binder_transaction *t, @@ -3761,9 +3172,6 @@ static int binder_translate_binder(struct flat_binder_object *fp, return -ENOMEM; #ifdef BINDER_WATCHDOG parse_service_name(tr, proc, node->name); -#endif -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - oplus_parse_service_name(tr, proc, node->service_name); #endif } if (fp->cookie != node->cookie) { @@ -4055,13 +3463,6 @@ static int binder_fixup_parent(struct binder_transaction *t, return 0; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST -static inline bool is_binder_proc_sf(struct binder_proc *proc) -{ - return proc && proc->tsk && strstr(proc->tsk->comm, "surfaceflinger") - && (task_uid(proc->tsk).val == 1000); -} -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /** * binder_proc_transaction() - sends a transaction to a process and wakes it up @@ -4088,9 +3489,6 @@ static bool binder_proc_transaction(struct binder_transaction *t, struct binder_priority node_prio; bool oneway = !!(t->flags & TF_ONE_WAY); bool pending_async = false; -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - struct binder_notify binder_notify_obj; -#endif BUG_ON(!node); binder_node_lock(node); @@ -4113,79 +3511,22 @@ static bool binder_proc_transaction(struct binder_transaction *t, binder_node_unlock(node); return false; } -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obtrans_restrict_start(proc, t); - if (!thread && !pending_async) { - thread = obthread_get(proc, t, oneway); - } -#else if (!thread && !pending_async) thread = binder_select_thread_ilocked(proc); -#endif -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - if (NULL != node && NULL != proc->tsk) { - binder_notify_obj.caller_task = current; - strncpy(binder_notify_obj.service_name, node->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - binder_notify_obj.service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - binder_notify_obj.pending_async = pending_async; - } -#endif if (thread) { -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - binder_notify_obj.binder_task = thread->task; - call_binderevent_notifiers(0, (void *)&binder_notify_obj); -#endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - binder_transaction_priority(thread, thread->task, t, node_prio, - node->inherit_rt); -#else binder_transaction_priority(thread->task, t, node_prio, node->inherit_rt); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ binder_enqueue_thread_work_ilocked(thread, &t->work); #ifdef CONFIG_MTK_TASK_TURBO if (binder_start_turbo_inherit(t->from ? t->from->task : NULL, thread->task)) t->inherit_task = thread->task; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - if (!oneway || proc->proc_type) - binder_set_inherit_ux(thread->task, current); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } else if (!pending_async) { -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - if (NULL != proc && NULL != proc->tsk) { - binder_notify_obj.binder_task = proc->tsk; - call_binderevent_notifiers(0, (void *)&binder_notify_obj); - } -#endif -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obwork_restrict(proc, t, pending_async); -#else binder_enqueue_work_ilocked(&t->work, &proc->todo); -#endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - if ((!oneway || proc->proc_type) && proc->max_threads == 0) { - binder_set_inherit_ux(proc->tsk, current); - } - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } else { -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - if (NULL != proc && NULL != proc->tsk) { - binder_notify_obj.binder_task = proc->tsk; - call_binderevent_notifiers(0, (void *)&binder_notify_obj); - } -#endif -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obwork_restrict(proc, t, pending_async); -#else binder_enqueue_work_ilocked(&t->work, &node->async_todo); -#endif } if (!pending_async) @@ -4265,14 +3606,6 @@ static void binder_transaction(struct binder_proc *proc, int t_debug_id = atomic_inc_return(&binder_last_id); char *secctx = NULL; u32 secctx_sz = 0; -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - char buf_data[INTERFACETOKEN_BUFF_SIZE]; - size_t buf_data_size; - char buf[INTERFACETOKEN_BUFF_SIZE] = {0}; - int i = 0; - int j = 0; -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ #ifdef BINDER_WATCHDOG struct binder_transaction_log_entry log_entry; unsigned int log_idx = -1; @@ -4421,16 +3754,6 @@ static void binder_transaction(struct binder_proc *proc, goto err_dead_binder; } -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - if (!(tr->flags & TF_ONE_WAY) //report sync binder call - && target_proc - && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) - && (proc->pid != target_proc->pid) - && is_frozen_tg(target_proc->tsk)) { - hans_report(SYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER", -1); - } -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ #if defined(CONFIG_CFS_BANDWIDTH) if (!(tr->flags & TF_ONE_WAY) /*report sync binder call*/ && target_proc @@ -4632,24 +3955,6 @@ static void binder_transaction(struct binder_proc *proc, t->buffer->transaction = t; t->buffer->target_node = target_node; trace_binder_transaction_alloc_buf(t->buffer); -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obset_async_boost_work(t->buffer, t, target_proc, &target_proc->alloc, !reply && t->flags & TF_ONE_WAY); -#endif - - //ifdef OPLUS_BUG_STABILITY - if (!(t->flags & TF_ONE_WAY)) { - size_t buffer_size = binder_alloc_buffer_size_locked(&target_proc->alloc,t->buffer); - if(buffer_size > 100 * SZ_1K) { - if (reply) - binder_debug(BINDER_DEBUG_USER_ERROR,"%d:%d BC_REPLY -> %d:%d alloc buffer %zd \n", - proc->pid, thread->pid,target_proc->pid, target_thread->pid,buffer_size); - else - binder_debug(BINDER_DEBUG_USER_ERROR,"%d:%d BC_TRANSACTION -> %d:%d alloc buffer %zd \n", - proc->pid, thread->pid,target_proc->pid, target_thread ? target_thread->pid : 0,buffer_size); - } - } - //endif /*OPLUS_BUG_STABILITY*/ - if (binder_alloc_copy_user_to_buffer( &target_proc->alloc, @@ -4695,32 +4000,6 @@ static void binder_transaction(struct binder_proc *proc, return_error_line = __LINE__; goto err_bad_offset; } -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - if ((tr->flags & TF_ONE_WAY) //report async binder call - && target_proc - && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) - && (proc->pid != target_proc->pid) - && is_frozen_tg(target_proc->tsk)) { - buf_data_size = tr->data_size>INTERFACETOKEN_BUFF_SIZE ?INTERFACETOKEN_BUFF_SIZE:tr->data_size; - if (!copy_from_user(buf_data, (char*)tr->data.ptr.buffer, buf_data_size)) { - //1.skip first PARCEL_OFFSET bytes (useless data) - //2.make sure the invalid address issue is not occuring(j =PARCEL_OFFSET+1, j+=2) - //3.java layer uses 2 bytes char. And only the first bytes has the data.(p+=2) - if (buf_data_size > PARCEL_OFFSET) { - char *p = (char *)(buf_data) + PARCEL_OFFSET; - j = PARCEL_OFFSET + 1; - while (i < INTERFACETOKEN_BUFF_SIZE && j < buf_data_size && *p != '\0') { - buf[i++] = *p; - j += 2; - p += 2; - } - if (i == INTERFACETOKEN_BUFF_SIZE) buf[i-1] = '\0'; - } - hans_report(ASYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, buf, tr->code); - } - } -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ off_start_offset = ALIGN(tr->data_size, sizeof(void *)); buffer_offset = off_start_offset; off_end_offset = off_start_offset + tr->offsets_size; @@ -4762,7 +4041,7 @@ static void binder_transaction(struct binder_proc *proc, struct flat_binder_object *fp; fp = to_flat_binder_object(hdr); -#if defined(BINDER_WATCHDOG) || defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) +#if defined(BINDER_WATCHDOG) ret = binder_translate_binder(tr, fp, t, thread); #else ret = binder_translate_binder(fp, t, thread); @@ -4946,16 +4225,6 @@ static void binder_transaction(struct binder_proc *proc, binder_stop_turbo_inherit(thread->task); in_reply_to->inherit_task = NULL; } -#endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled && !proc->proc_type) { - binder_unset_inherit_ux(thread->task); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - binder_inner_proc_lock(proc); - obwork_check_restrict_off(proc); - binder_inner_proc_unlock(proc); #endif binder_restore_priority(current, in_reply_to->saved_priority); binder_free_transaction(in_reply_to); @@ -5279,16 +4548,6 @@ static int binder_thread_write(struct binder_proc *proc, break; } - //ifdef OPLUS_BUG_STABILITY - if(buffer != NULL) { - size_t buffer_size = binder_alloc_buffer_size_locked(&proc->alloc,buffer); - if(buffer_size > 100 * SZ_1K){ - binder_debug(BINDER_DEBUG_USER_ERROR, - "%d:%d BC_FREE_BUFFER free size %zd \n", - proc->pid, thread->pid, buffer_size); - } - } - //endif /*OPLUS_BUG_STABILITY*/ binder_debug(BINDER_DEBUG_FREE_BUFFER, "%d:%d BC_FREE_BUFFER u%016llx found buffer %d for %s transaction\n", proc->pid, thread->pid, (u64)data_ptr, @@ -5367,10 +4626,6 @@ static int binder_thread_write(struct binder_proc *proc, proc->requested_threads_started++; } thread->looper |= BINDER_LOOPER_STATE_REGISTERED; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - /* when thread calls BC_REGISTER_LOOPER, it become binder thread authentic*/ - obthread_init(proc, thread); -#endif binder_inner_proc_unlock(proc); break; case BC_ENTER_LOOPER: @@ -5630,29 +4885,11 @@ static int binder_wait_for_work(struct binder_thread *thread, prepare_to_wait(&thread->wait, &wait, TASK_INTERRUPTIBLE); if (binder_has_work_ilocked(thread, do_proc_work)) break; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (do_proc_work) { - list_add(&thread->waiting_thread_node, - &proc->waiting_threads); - - if (sysctl_sched_assist_enabled) { - binder_unset_inherit_ux(thread->task); - } - } -#else /* OPLUS_FEATURE_SCHED_ASSIST */ if (do_proc_work) list_add(&thread->waiting_thread_node, &proc->waiting_threads); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ binder_inner_proc_unlock(proc); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - if (!do_proc_work) - current->in_binder = 1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ schedule(); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_binder = 0; -#endif /* OPLUS_FEATURE_HEALTHINFO */ binder_inner_proc_lock(proc); list_del_init(&thread->waiting_thread_node); if (signal_pending(current)) { @@ -5734,26 +4971,6 @@ retry: binder_inner_proc_lock(proc); if (!binder_worklist_empty_ilocked(&thread->todo)) list = &thread->todo; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - else if (obthread_has_work(thread) && wait_for_proc_work) { - list = &ob_target.ob_list; - obprint_oblist(); - } - /* prevent normal work to be starved */ - else if (check_ob_ux_todo_has_work(thread) && wait_for_proc_work) { - if (proc->ux_count >= MAX_UX_WORK_CONTINUOUS) { - if (!binder_worklist_empty_ilocked(&proc->todo)) { - list = &proc->todo; - proc->ux_count = 0; - } - else - list = &proc->ux_todo; - } else { - proc->ux_count++; - list = &proc->ux_todo; - } - } -#endif else if (!binder_worklist_empty_ilocked(&proc->todo) && wait_for_proc_work) list = &proc->todo; @@ -5952,13 +5169,8 @@ retry: trd->cookie = target_node->cookie; node_prio.sched_policy = target_node->sched_policy; node_prio.prio = target_node->min_priority; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - binder_transaction_priority(thread, current, t, node_prio, - target_node->inherit_rt); -#else /* OPLUS_FEATURE_SCHED_ASSIST */ binder_transaction_priority(current, t, node_prio, target_node->inherit_rt); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ cmd = BR_TRANSACTION; } else { trd->target.ptr = 0; @@ -5982,11 +5194,6 @@ retry: thread->task)) t->inherit_task = thread->task; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - binder_set_inherit_ux(thread->task, t_from->task); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } else { trd->sender_pid = 0; } @@ -6225,9 +5432,6 @@ static void binder_free_proc(struct binder_proc *proc) BUG_ON(!list_empty(&proc->todo)); BUG_ON(!list_empty(&proc->delivered_death)); -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obproc_free(proc); -#endif device = container_of(proc->context, struct binder_device, context); if (refcount_dec_and_test(&device->ref)) { kfree(proc->context->name); @@ -6404,9 +5608,6 @@ static int binder_ioctl_write_read(struct file *filp, filp->f_flags & O_NONBLOCK); trace_binder_read_done(ret); binder_inner_proc_lock(proc); -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obproc_has_work(proc); -#endif if (!binder_worklist_empty_ilocked(&proc->todo)) binder_wakeup_proc_ilocked(proc); binder_inner_proc_unlock(proc); @@ -6470,15 +5671,6 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp, new_node->has_strong_ref = 1; new_node->has_weak_ref = 1; context->binder_context_mgr_node = new_node; -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - if (NULL != context->binder_context_mgr_node && - NULL != context->binder_context_mgr_node->proc && - NULL != context->binder_context_mgr_node->proc->tsk) { - snprintf(context->binder_context_mgr_node->service_name, OPLUS_MAX_SERVICE_NAME_LEN, - "%s", context->binder_context_mgr_node->proc->tsk->comm); - context->binder_context_mgr_node->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - } -#endif binder_node_unlock(new_node); binder_put_node(new_node); out: @@ -6776,16 +5968,9 @@ static int binder_open(struct inode *nodp, struct file *filp) spin_lock_init(&proc->outer_lock); get_task_struct(current->group_leader); proc->tsk = current->group_leader; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - proc->proc_type = is_binder_proc_sf(proc) ? 1 : 0; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ mutex_init(&proc->files_lock); proc->cred = get_cred(filp->f_cred); INIT_LIST_HEAD(&proc->todo); -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - INIT_LIST_HEAD(&proc->ux_todo); - proc->ux_count = 0; -#endif if (binder_supported_policy(current->policy)) { proc->default_priority.sched_policy = current->policy; proc->default_priority.prio = current->normal_prio; @@ -6812,9 +5997,6 @@ static int binder_open(struct inode *nodp, struct file *filp) INIT_LIST_HEAD(&proc->delivered_death); INIT_LIST_HEAD(&proc->waiting_threads); filp->private_data = proc; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - obtarget_init(proc); -#endif mutex_lock(&binder_procs_lock); hlist_add_head(&proc->proc_node, &binder_procs); @@ -7058,11 +6240,6 @@ static void binder_deferred_release(struct binder_proc *proc) binder_release_work(proc, &proc->todo); binder_release_work(proc, &proc->delivered_death); -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - binder_release_work(proc, &proc->ux_todo); - if (proc == ob_target.ob_proc) - binder_release_work(proc, &ob_target.ob_list); -#endif binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d threads %d, nodes %d (ref %d), refs %d, active transactions %d\n", @@ -7575,71 +6752,6 @@ int binder_state_show(struct seq_file *m, void *unused) return 0; } -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -static void hans_check_uid_proc_status(struct binder_proc *proc, enum message_type type) -{ - struct rb_node *n = NULL; - struct binder_thread *thread = NULL; - int uid = -1; - struct binder_transaction *btrans = NULL; - bool empty = true; - - //check binder_thread/transaction_stack/binder_proc ongoing transaction - binder_inner_proc_lock(proc); - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) { - thread = rb_entry(n, struct binder_thread, rb_node); - empty = binder_worklist_empty_ilocked(&thread->todo); - - if (thread->task != NULL) { - // has "todo" binder thread in worklist? - uid = task_uid(thread->task).val; - if (!empty) { - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_THREAD", -1); - return; - } - - // has transcation in transaction_stack? - btrans = thread->transaction_stack; - if (btrans) { - spin_lock(&btrans->lock); - if (btrans->to_thread == thread) { - // only report incoming binder call - spin_unlock(&btrans->lock); - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_STACK", -1); - return; - } - spin_unlock(&btrans->lock); - } - } - } - - // has "todo" binder proc in worklist - empty = binder_worklist_empty_ilocked(&proc->todo); - if (proc->tsk != NULL && !empty) { - uid = task_uid(proc->tsk).val; - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_PROC", -1); - return; - } - binder_inner_proc_unlock(proc); -} - -void hans_check_frozen_transcation(uid_t uid, enum message_type type) -{ - struct binder_proc *proc; - - mutex_lock(&binder_procs_lock); - hlist_for_each_entry(proc, &binder_procs, proc_node) { - if (proc != NULL && (task_uid(proc->tsk).val == uid)) { - hans_check_uid_proc_status(proc, type); - } - } - mutex_unlock(&binder_procs_lock); -} -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ int binder_stats_show(struct seq_file *m, void *unused) { diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 53be6733946d..d07e88a94e1b 100755 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -37,10 +37,6 @@ #endif #include "binder_alloc.h" #include "binder_trace.h" -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -#include -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ struct list_lru binder_alloc_lru; @@ -72,20 +68,6 @@ static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer) { return list_entry(buffer->entry.prev, struct binder_buffer, entry); } -//ifdef OPLUS_BUG_STABILITY -size_t binder_alloc_buffer_size_locked(struct binder_alloc *alloc, - struct binder_buffer *buffer) -{ - size_t buffer_size; - mutex_lock(&alloc->mutex); - if (list_is_last(&buffer->entry, &alloc->buffers)) - buffer_size = alloc->buffer + alloc->buffer_size - buffer->user_data; - else - buffer_size = binder_buffer_next(buffer)->user_data - buffer->user_data; - mutex_unlock(&alloc->mutex); - return buffer_size; -} -//endif /*OPLUS_BUG_STABILITY*/ static size_t binder_alloc_buffer_size(struct binder_alloc *alloc, struct binder_buffer *buffer) @@ -452,10 +434,6 @@ static struct binder_buffer *binder_alloc_new_buf_locked( void __user *end_page_addr; size_t size, data_offsets_size; int ret; -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - struct task_struct *p = NULL; -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ if (!binder_alloc_get_vma(alloc)) { pr_err("%d: binder_alloc_buf, no vma\n", @@ -479,19 +457,6 @@ static struct binder_buffer *binder_alloc_new_buf_locked( alloc->pid, extra_buffers_size); return ERR_PTR(-EINVAL); } -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - if (is_async - && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer)) - || (alloc->free_async_space < ((alloc->buffer_size / 2) * 9 / 10)))) { - rcu_read_lock(); - p = find_task_by_vpid(alloc->pid); - rcu_read_unlock(); - if (p != NULL && is_frozen_tg(p)) { - hans_report(ASYNC_BINDER, task_tgid_nr(current), task_uid(current).val, task_tgid_nr(p), task_uid(p).val, "free_buffer_full", -1); - } - } -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ if (is_async && alloc->free_async_space < size + sizeof(struct binder_buffer)) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, @@ -534,13 +499,6 @@ static struct binder_buffer *binder_alloc_new_buf_locked( total_alloc_size += buffer_size; if (buffer_size > largest_alloc_size) largest_alloc_size = buffer_size; - //ifdef OPLUS_BUG_STABILITY - if(buffer_size > 100 * SZ_1K) { - binder_alloc_debug(BINDER_DEBUG_USER_ERROR, - "%d: binder_alloc_buf size %zd \n", - buffer->pid, buffer_size); - } - //endif /*OPLUS_BUG_STABILITY*/ } for (n = rb_first(&alloc->free_buffers); n != NULL; n = rb_next(n)) { diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h index 1aeb67961a7b..3daa3e211267 100755 --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -24,12 +24,6 @@ #include #include - -//ifdef OPLUS_BUG_STABILITY -#ifndef SZ_1K -#define SZ_1K 0x400 -#endif -//endif /*OPLUS_BUG_STABILITY*/ extern struct list_lru binder_alloc_lru; struct binder_transaction; @@ -153,10 +147,6 @@ extern void binder_alloc_print_allocated(struct seq_file *m, void binder_alloc_print_pages(struct seq_file *m, struct binder_alloc *alloc); -//ifdef OPLUS_BUG_STABILITY -size_t binder_alloc_buffer_size_locked(struct binder_alloc *alloc, - struct binder_buffer *buffer); -//endif /*OPLUS_BUG_STABILITY*/ /** * binder_alloc_get_free_async_space() - get free space available for async * @alloc: binder_alloc for this proc diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 9b798cd8a299..67a8823899b6 100755 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -31,16 +31,6 @@ config ZRAM_WRITEBACK See Documentation/blockdev/zram.txt for more information. -#ifdef OPLUS_FEATURE_ZRAM_OPT -#/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-21, add zram opt support*/ -config OPLUS_ZRAM_OPT - bool "oplus zram optimization" - depends on ZRAM - default y - help - oplus zram optimization -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ - config ZRAM_MEMORY_TRACKING bool "Track zRam block status" depends on ZRAM && DEBUG_FS @@ -50,41 +40,3 @@ config ZRAM_MEMORY_TRACKING /sys/kernel/debug/zram/zramX/block_state. See Documentation/blockdev/zram.txt for more information. -config HYBRIDSWAP - bool "Enable Hybridswap" - depends on MEMCG && ZRAM && !ZRAM_DEDUP && !ZRAM_WRITEBACK && !ZWB_HANDLE - default n - help - Hybridswap is a intelligent memory management solution. - -config HYBRIDSWAP_SWAPD - bool "Enable hybridswap swapd thread to reclaim anon pages in background" - default n - depends on HYBRIDSWAP - help - swapd is a kernel thread that reclaim anonymous pages in the - background. When the use of swap pages reaches the watermark - and the refault of anonymous pages is high, the content of - zram will exchanged to eswap by a certain percentage. - -# Selected when system need hybridswap container -config HYBRIDSWAP_CORE - bool "Hybridswap container device support" - depends on ZRAM && HYBRIDSWAP - default n - help - Say Y here if you want to use the hybridswap - as the backend device in ZRAM. - If unsure, say N here. - This module can't be compiled as a module, - the module is as one part of the ZRAM driver. - -config HYBRIDSWAP_ASYNC_COMPRESS - bool "hypbridswap support asynchronous compress anon pages" - depends on ZRAM && HYBRIDSWAP - default n - help - Say Y here if you want to create asynchronous thread - for compress anon pages. - If unsure, say N here. - This feature will reduce the kswapd cpu load. diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile index f10b114bd2ba..de9e457907b1 100755 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile @@ -2,8 +2,3 @@ zram-y := zcomp.o zram_drv.o obj-$(CONFIG_ZRAM) += zram.o - -zram-$(CONFIG_HYBRIDSWAP) += hybridswap/hybridswap_main.o -zram-$(CONFIG_HYBRIDSWAP_SWAPD) += hybridswap/hybridswap_swapd.o -zram-$(CONFIG_HYBRIDSWAP_ASYNC_COMPRESS) += hybridswap/hybridswap_akcompress.o -zram-$(CONFIG_HYBRIDSWAP_CORE) += hybridswap/hybridswap_area.o hybridswap/hybridswap_core.o hybridswap/hybridswap_ctrl.o hybridswap/hybridswap_list.o hybridswap/hybridswap_lru_rmap.o hybridswap/hybridswap_manager.o hybridswap/hybridswap_perf.o hybridswap/hybridswap_schedule.o hybridswap/hybridswap_stats.o diff --git a/drivers/block/zram/hybridswap/hybridswap.h b/drivers/block/zram/hybridswap/hybridswap.h deleted file mode 100755 index 2deefc30ce7a..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap.h +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#ifndef HYBRIDSWAP_H -#define HYBRIDSWAP_H -extern int __init hybridswap_pre_init(void); -extern ssize_t hybridswap_vmstat_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_loglevel_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_loglevel_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_enable_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_enable_show(struct device *dev, - struct device_attribute *attr, char *buf); -#ifdef CONFIG_HYBRIDSWAP_CORE -extern void hybridswap_track(struct zram *zram, u32 index, struct mem_cgroup *memcg); -extern void hybridswap_untrack(struct zram *zram, u32 index); -extern int hybridswap_fault_out(struct zram *zram, u32 index); -extern bool hybridswap_delete(struct zram *zram, u32 index); - -extern ssize_t hybridswap_report_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_stat_snap_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_meminfo_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_core_enable_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_core_enable_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_loop_device_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_loop_device_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_dev_life_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_dev_life_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_quota_day_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_quota_day_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern ssize_t hybridswap_zram_increase_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_zram_increase_show(struct device *dev, - struct device_attribute *attr, char *buf); -#endif - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -/* 63---48,47--32,31-0 : cgroup id, thread_idx, index*/ -#define ZRAM_INDEX_SHIFT 32 -#define CACHE_INDEX_SHIFT 32 -#define CACHE_INDEX_MASK ((1llu << CACHE_INDEX_SHIFT) - 1) -#define ZRAM_INDEX_MASK ((1llu << ZRAM_INDEX_SHIFT) - 1) - -#define cache_idx_val(idx) (((unsigned long)idx & CACHE_INDEX_MASK) << ZRAM_INDEX_SHIFT) -#define zram_idx_val(id) ((unsigned long)id & ZRAM_INDEX_MASK) -#define mk_page_val(cache_idx, index) (cache_idx_val(cache_idx) | zram_idx_val(index)) - -#define get_cache_id(page) ((page->private >> 32) & CACHE_INDEX_MASK) -#define get_zram_index(page) (page->private & ZRAM_INDEX_MASK) - -#define zram_set_page(zram, index, page) (zram->table[index].page = page) -#define zram_get_page(zram, index) (zram->table[index].page) - -extern void del_page_from_cache(struct page *page); -extern int add_anon_page2cache(struct zram * zram, u32 index, - struct page *page); -extern ssize_t hybridswap_akcompress_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_akcompress_show(struct device *dev, - struct device_attribute *attr, char *buf); -extern void put_free_page(struct page *page); -extern void put_anon_pages(struct page *page); -extern int akcompress_cache_fault_out(struct zram *zram, - struct page *page, u32 index); -extern void destroy_akcompressd_task(struct zram *zram); -#endif - -#ifdef CONFIG_HYBRIDSWAP_SWAPD -extern ssize_t hybridswap_swapd_pause_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len); -extern ssize_t hybridswap_swapd_pause_show(struct device *dev, - struct device_attribute *attr, char *buf); -#endif -static inline bool current_is_swapd(void) -{ -#ifdef CONFIG_HYBRIDSWAP_SWAPD - return (strncmp(current->comm, "hybridswapd:", sizeof("hybridswapd:") - 1) == 0); -#else - return false; -#endif -} -#endif /* HYBRIDSWAP_H */ diff --git a/drivers/block/zram/hybridswap/hybridswap_akcompress.c b/drivers/block/zram/hybridswap/hybridswap_akcompress.c deleted file mode 100755 index 11cfc8877407..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_akcompress.c +++ /dev/null @@ -1,575 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_internal.h" -#include "hybridswap.h" - -struct compress_info_s { - struct list_head free_page_head; - spinlock_t free_lock; - unsigned int free_cnt; - - unsigned int max_cnt; -} compress_info; - -#define MAX_AKCOMPRESSD_THREADS 4 -#define DEFAULT_CACHE_SIZE_MB 64 -#define DEFAULT_COMPRESS_BATCH_MB 1 -#define DEFAULT_CACHE_COUNT ((DEFAULT_CACHE_SIZE_MB << 20) >> PAGE_SHIFT) -#define WAKEUP_AKCOMPRESSD_WATERMARK ((DEFAULT_COMPRESS_BATCH_MB << 20) >> PAGE_SHIFT) - -static wait_queue_head_t akcompressd_wait; -static struct task_struct *akc_task[MAX_AKCOMPRESSD_THREADS]; -static atomic64_t akc_cnt[MAX_AKCOMPRESSD_THREADS]; -static int akcompressd_threads = 0; -static atomic64_t cached_cnt; -static struct zram *zram_info; -static DEFINE_MUTEX(akcompress_init_lock); - -struct idr cached_idr = IDR_INIT(cached_idr); -DEFINE_SPINLOCK(cached_idr_lock); - -static void wake_all_akcompressd(void); - -void clear_page_memcg(struct cgroup_cache_page *cache) -{ - struct list_head *pos; - struct page *page; - - spin_lock(&cache->lock); - if (list_empty(&cache->head)) - goto out; - - list_for_each(pos, &cache->head) { - page = list_entry(pos, struct page, lru); - if (!page->mem_cgroup) - BUG(); - page->mem_cgroup = NULL; - } - -out: - cache->dead = 1; - spin_unlock(&cache->lock); -} - -static inline struct page * get_free_page(void) -{ - struct page *page = NULL; - - spin_lock(&compress_info.free_lock); - if (compress_info.free_cnt > 0) { - if (list_empty(&compress_info.free_page_head)) - BUG(); - page = lru_to_page(&compress_info.free_page_head); - list_del(&page->lru); - compress_info.free_cnt--; - } - spin_unlock(&compress_info.free_lock); - - return page; -} - -void put_free_page(struct page *page) -{ - set_page_private(page, 0); - spin_lock(&compress_info.free_lock); - list_add_tail(&page->lru, &compress_info.free_page_head); - compress_info.free_cnt++; - spin_unlock(&compress_info.free_lock); -} - -static inline struct cgroup_cache_page *find_and_get_memcg_cache(int cache_id) -{ - struct cgroup_cache_page *cache; - - spin_lock(&cached_idr_lock); - cache = (struct cgroup_cache_page *)idr_find(&cached_idr, cache_id); - if (unlikely(!cache)) { - spin_unlock(&cached_idr_lock); - pr_err("cache_id %d cache not find.\n", cache_id); - - return NULL; - } - get_memcg_cache(container_of(cache, memcg_hybs_t, cache)); - spin_unlock(&cached_idr_lock); - - return cache; -} - -void del_page_from_cache(struct page *page) -{ - int cache_id; - struct cgroup_cache_page *cache; - - if (!page) - return; - - cache_id = get_cache_id(page); - if (unlikely(cache_id < 0 || cache_id > MEM_CGROUP_ID_MAX)) { - hybp(HYB_ERR, "page %p cache_id %d index %u is invalid.\n", - page, cache_id, get_zram_index(page)); - return; - } - - cache = find_and_get_memcg_cache(cache_id); - if (!cache) - return; - - spin_lock(&cache->lock); - list_del(&page->lru); - cache->cnt--; - spin_unlock(&cache->lock); - put_memcg_cache(container_of(cache, memcg_hybs_t, cache)); - atomic64_dec(&cached_cnt); -} - -void del_page_from_cache_with_cache(struct page *page, - struct cgroup_cache_page *cache) -{ - spin_lock(&cache->lock); - list_del(&page->lru); - cache->cnt--; - spin_unlock(&cache->lock); - atomic64_dec(&cached_cnt); -} - -void put_anon_pages(struct page *page) -{ - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(page->mem_cgroup); - - spin_lock(&hybs->cache.lock); - list_add(&page->lru, &hybs->cache.head); - hybs->cache.cnt++; - spin_unlock(&hybs->cache.lock); -} - -static inline bool can_stop_working(struct cgroup_cache_page *cache, int idx) -{ - spin_lock(&cache->lock); - if (unlikely(!list_empty(&cache->head))) { - spin_unlock(&cache->lock); - return false; - } - spin_unlock(&cache->lock); - return 1; -} - -static int check_cache_state(struct cgroup_cache_page *cache) -{ - if (cache->cnt == 0 || cache->compressing == 1) - return 0; - - spin_lock(&cache->lock); - if (cache->cnt == 0 || cache->compressing) { - spin_unlock(&cache->lock); - return 0; - } - cache->compressing = 1; - spin_unlock(&cache->lock); - get_memcg_cache(container_of(cache, memcg_hybs_t, cache)); - return 1; -} - -struct cgroup_cache_page *fetch_one_cache(void) -{ - struct cgroup_cache_page *cache = NULL; - int id; - - spin_lock(&cached_idr_lock); - idr_for_each_entry(&cached_idr, cache, id) { - if (check_cache_state(cache)) - break; - } - spin_unlock(&cached_idr_lock); - - return cache; -} - -void mark_compressing_stop(struct cgroup_cache_page *cache) -{ - spin_lock(&cache->lock); - if (cache->dead) - hybp(HYB_WARN, "stop compressing, may be cgroup is delelted\n"); - cache->compressing = 0; - spin_unlock(&cache->lock); - put_memcg_cache(container_of(cache, memcg_hybs_t, cache)); -} - -static inline struct page *get_anon_page(struct zram *zram, - struct cgroup_cache_page *cache) -{ - struct page *page, *prev_page; - int index; - - if (compress_info.free_cnt == 0) - return NULL; - - prev_page = NULL; -try_again: - page = NULL; - - spin_lock(&cache->lock); - if (!list_empty(&cache->head)) { - page = lru_to_page(&cache->head); - index = get_zram_index(page); - } - spin_unlock(&cache->lock); - - if (page) { - if (prev_page && (page == prev_page)) { - hybp(HYB_ERR, "zram %p index %d page %p\n", - zram, index, page); - BUG(); - } - - zram_slot_lock(zram, index); - if (!zram_test_flag(zram, index, ZRAM_CACHED)) { - zram_slot_unlock(zram, index); - prev_page = page; - goto try_again; - } - - prev_page = NULL; - zram_clear_flag(zram, index, ZRAM_CACHED); - del_page_from_cache_with_cache(page, cache); - zram_set_flag(zram, index, ZRAM_CACHED_COMPRESS); - zram_slot_unlock(zram, index); - } - - return page; -} - -int add_anon_page2cache(struct zram * zram, u32 index, struct page *page) -{ - struct page *dst_page; - void *src, *dst; - struct mem_cgroup *memcg; - struct cgroup_cache_page *cache; - memcg_hybs_t *hybs; - - if (akcompressd_threads == 0) - return 0; - - memcg = page->mem_cgroup; - if (!memcg || !MEMCGRP_ITEM_DATA(memcg)) - return 0; - - hybs = MEMCGRP_ITEM_DATA(memcg); - cache = &hybs->cache; - if (find_and_get_memcg_cache(cache->id) != cache) - return 0; - - spin_lock(&cache->lock); - if (cache->dead == 1) { - spin_unlock(&cache->lock); - return 0; - } - spin_unlock(&cache->lock); - - dst_page = get_free_page(); - if (!dst_page) - return 0; - - src = kmap_atomic(page); - dst = kmap_atomic(dst_page); - memcpy(dst, src, PAGE_SIZE); - kunmap_atomic(src); - kunmap_atomic(dst); - - dst_page->mem_cgroup = memcg; - set_page_private(dst_page, mk_page_val(cache->id, index)); - update_zram_index(zram, index, (unsigned long)dst_page); - atomic64_inc(&cached_cnt); - wake_all_akcompressd(); - hybp(HYB_DEBUG, "add_anon_page2cache index %u page %p passed\n", - index, dst_page); - return 1; -} - -static inline void akcompressd_try_to_sleep(wait_queue_head_t *waitq) -{ - DEFINE_WAIT(wait); - - prepare_to_wait(waitq, &wait, TASK_INTERRUPTIBLE); - freezable_schedule(); - finish_wait(waitq, &wait); -} - -static int akcompressd_func(void *data) -{ - struct page *page; - int ret, thread_idx; - struct list_head compress_fail_list; - struct cgroup_cache_page *cache = NULL; - - thread_idx = (int)data; - if (thread_idx < 0 || thread_idx >= MAX_AKCOMPRESSD_THREADS) { - hybp(HYB_ERR, "akcompress task idx %d is invalid.\n", thread_idx); - return -EINVAL; - } - - set_freezable(); - while (!kthread_should_stop()) { - akcompressd_try_to_sleep(&akcompressd_wait); - count_swapd_event(AKCOMPRESSD_WAKEUP); - - cache = fetch_one_cache(); - if (!cache) - continue; - -finish_last_jobs: - INIT_LIST_HEAD(&compress_fail_list); - page = get_anon_page(zram_info, cache); - while (page) { - ret = async_compress_page(zram_info, page); - put_memcg_cache(container_of(cache, memcg_hybs_t, cache)); - - if (ret) - list_add(&page->lru, &compress_fail_list); - else { - atomic64_inc(&akc_cnt[thread_idx]); - page->mem_cgroup = NULL; - put_free_page(page); - } - page = get_anon_page(zram_info, cache); - } - - if (!list_empty(&compress_fail_list)) - hybp(HYB_ERR, "have some compress failed pages.\n"); - - if (kthread_should_stop()) { - if (!can_stop_working(cache, thread_idx)) - goto finish_last_jobs; - } - mark_compressing_stop(cache); - } - - return 0; -} - -static int update_akcompressd_threads(int thread_count, struct zram *zram) -{ - int drop, increase; - int last_idx, start_idx, hid; - static DEFINE_MUTEX(update_lock); - - if (thread_count < 0 || thread_count > MAX_AKCOMPRESSD_THREADS) { - hybp(HYB_ERR, "thread_count %d is invalid\n", thread_count); - return -EINVAL; - } - - mutex_lock(&update_lock); - if (!zram_info || zram_info != zram) - zram_info = zram; - - if (thread_count == akcompressd_threads) { - mutex_unlock(&update_lock); - return thread_count; - } - - last_idx = akcompressd_threads - 1; - if (thread_count < akcompressd_threads) { - drop = akcompressd_threads - thread_count; - for (hid = last_idx; hid > (last_idx - drop); hid--) { - if (akc_task[hid]) { - kthread_stop(akc_task[hid]); - akc_task[hid] = NULL; - } - } - } else { - increase = thread_count - akcompressd_threads; - start_idx = last_idx + 1; - for (hid = start_idx; hid < (start_idx + increase); hid++) { - if (unlikely(akc_task[hid])) - BUG(); - akc_task[hid]= kthread_run(akcompressd_func, - (void*)(unsigned long)hid, "akcompressd:%d", hid); - if (IS_ERR(akc_task[hid])) { - pr_err("Failed to start akcompressd%d\n", hid); - akc_task[hid] = NULL; - break; - } - } - } - - hybp(HYB_INFO, "akcompressd_threads count changed, old:%d new:%d\n", - akcompressd_threads, thread_count); - akcompressd_threads = thread_count; - mutex_unlock(&update_lock); - - return thread_count; -} - -static void wake_all_akcompressd(void) -{ - if (atomic64_read(&cached_cnt) < WAKEUP_AKCOMPRESSD_WATERMARK) - return; - - if (!waitqueue_active(&akcompressd_wait)) - return; - - wake_up_interruptible(&akcompressd_wait); -} - -int create_akcompressd_task(struct zram *zram) -{ - return update_akcompressd_threads(1, zram) != 1; -} - -void destroy_akcompressd_task(struct zram *zram) -{ - (void)update_akcompressd_threads(0, zram); -} - -ssize_t hybridswap_akcompress_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - int ret; - unsigned long val; - struct zram *zram = dev_to_zram(dev); - - ret = kstrtoul(buf, 0, &val); - if (unlikely(ret)) { - hybp(HYB_ERR, "val is error!\n"); - return -EINVAL; - } - - ret = update_akcompressd_threads(val, zram); - if (ret < 0) { - hybp(HYB_ERR, "create task failed, val %d\n", val); - return ret; - } - - return len; -} - -ssize_t hybridswap_akcompress_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = 0, id, i; - struct cgroup_cache_page *cache = NULL; - unsigned long cnt = atomic64_read(&cached_cnt); - memcg_hybs_t *hybs; - - len += sprintf(buf + len, "akcompressd_threads: %d\n", akcompressd_threads); - len += sprintf(buf + len, "cached page cnt: %lu\n", cnt); - len += sprintf(buf + len, "free page cnt: %u\n", compress_info.free_cnt); - - for (i = 0; i < MAX_AKCOMPRESSD_THREADS; i++) - len += sprintf(buf + len, "%-d %-d\n", i, atomic64_read(&akc_cnt[i])); - - if (cnt == 0) - return len; - - spin_lock(&cached_idr_lock); - idr_for_each_entry(&cached_idr, cache, id) { - hybs = container_of(cache, memcg_hybs_t, cache); - if (cache->cnt == 0) - continue; - - len += scnprintf(buf + len, PAGE_SIZE - len, "%s %d\n", - hybs->name, cache->cnt); - - if (len >= PAGE_SIZE) - break; - } - spin_unlock(&cached_idr_lock); - - return len; -} - -void __init akcompressd_pre_init(void) -{ - int i; - struct page *page; - - mutex_lock(&akcompress_init_lock); - INIT_LIST_HEAD(&compress_info.free_page_head); - spin_lock_init(&compress_info.free_lock); - compress_info.free_cnt = 0; - - init_waitqueue_head(&akcompressd_wait); - - atomic64_set(&cached_cnt, 0); - for (i = 0; i < MAX_AKCOMPRESSD_THREADS; i++) - atomic64_set(&akc_cnt[i], 0); - - for (i = 0; i < DEFAULT_CACHE_COUNT; i ++) { - page = alloc_page(GFP_KERNEL); - - if (page) { - list_add_tail(&page->lru, &compress_info.free_page_head); - } else - break; - } - compress_info.free_cnt = i; - mutex_unlock(&akcompress_init_lock); -} - -void __exit akcompressd_pre_deinit(void) -{ - int i; - struct page *page, *tmp; - - mutex_lock(&akcompress_init_lock); - if (list_empty(&compress_info.free_page_head)) - goto out; - list_for_each_entry_safe(page, tmp, &compress_info.free_page_head , lru) { - list_del(&page->lru); - free_page(page); - } - -out: - compress_info.free_cnt = 0; - mutex_unlock(&akcompress_init_lock); -} - -int akcompress_cache_fault_out(struct zram *zram, - struct page *page, u32 index) -{ - void *src, *dst; - - if (zram_test_flag(zram, index, ZRAM_CACHED)) { - struct page *src_page = (struct page *)zram_get_page(zram, index); - - src = kmap_atomic(src_page); - dst = kmap_atomic(page); - memcpy(dst, src, PAGE_SIZE); - kunmap_atomic(src); - kunmap_atomic(dst); - zram_slot_unlock(zram, index); - - hybp(HYB_DEBUG, "read_anon_page_from_cache index %u page %p passed, ZRAM_CACHED\n", - index, src_page); - return 1; - } - - if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - struct page *src_page = (struct page *)zram_get_page(zram, index); - - src = kmap_atomic(src_page); - dst = kmap_atomic(page); - memcpy(dst, src, PAGE_SIZE); - kunmap_atomic(src); - kunmap_atomic(dst); - zram_slot_unlock(zram, index); - - hybp(HYB_DEBUG, "read_anon_page_from_cache index %u page %p passed, ZRAM_CACHED_COMPRESS\n", - index, src_page); - return 1; - } - - return 0; -} diff --git a/drivers/block/zram/hybridswap/hybridswap_area.c b/drivers/block/zram/hybridswap/hybridswap_area.c deleted file mode 100755 index e28248ef1938..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_area.c +++ /dev/null @@ -1,699 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include - -#include "hybridswap_area.h" -#include "hybridswap_list.h" -#include "hybridswap_internal.h" - -struct mem_cgroup *get_mem_cgroup(unsigned short mcg_id) -{ - struct mem_cgroup *mcg = NULL; - - rcu_read_lock(); - mcg = mem_cgroup_from_id(mcg_id); - rcu_read_unlock(); - - return mcg; -} - -static bool fragment_dec(bool prev_flag, bool next_flag, - struct hybridswap_stat *stat) -{ - if (prev_flag && next_flag) { - atomic64_inc(&stat->frag_cnt); - return false; - } - - if (prev_flag || next_flag) - return false; - - return true; -} - -static bool fragment_inc(bool prev_flag, bool next_flag, - struct hybridswap_stat *stat) -{ - if (prev_flag && next_flag) { - atomic64_dec(&stat->frag_cnt); - return false; - } - - if (prev_flag || next_flag) - return false; - - return true; -} - -static bool prev_is_cont(struct hybridswap_area *area, int ext_id, int mcg_id) -{ - int prev; - - if (is_first_idx(ext_idx(area, ext_id), mcg_idx(area, mcg_id), - area->ext_table)) - return false; - prev = prev_idx(ext_idx(area, ext_id), area->ext_table); - - return (prev >= 0) && (ext_idx(area, ext_id) == prev + 1); -} - -static bool next_is_cont(struct hybridswap_area *area, int ext_id, int mcg_id) -{ - int next; - - if (is_last_idx(ext_idx(area, ext_id), mcg_idx(area, mcg_id), - area->ext_table)) - return false; - next = next_idx(ext_idx(area, ext_id), area->ext_table); - - return (next >= 0) && (ext_idx(area, ext_id) + 1 == next); -} - -static void ext_fragment_sub(struct hybridswap_area *area, int ext_id) -{ - bool prev_flag = false; - bool next_flag = false; - int mcg_id; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - - if (!area->ext_table) { - hybp(HYB_ERR, "NULL table\n"); - return; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return; - } - - mcg_id = hyb_list_get_mcgid(ext_idx(area, ext_id), area->ext_table); - if (mcg_id <= 0 || mcg_id >= area->nr_mcgs) { - hybp(HYB_ERR, "mcg_id = %d invalid\n", mcg_id); - return; - } - - atomic64_dec(&stat->ext_cnt); - area->mcg_id_cnt[mcg_id]--; - if (area->mcg_id_cnt[mcg_id] == 0) { - atomic64_dec(&stat->mcg_cnt); - atomic64_dec(&stat->frag_cnt); - return; - } - - prev_flag = prev_is_cont(area, ext_id, mcg_id); - next_flag = next_is_cont(area, ext_id, mcg_id); - - if (fragment_dec(prev_flag, next_flag, stat)) - atomic64_dec(&stat->frag_cnt); -} - -static void ext_fragment_add(struct hybridswap_area *area, int ext_id) -{ - bool prev_flag = false; - bool next_flag = false; - int mcg_id; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - - if (!area->ext_table) { - hybp(HYB_ERR, "NULL table\n"); - return; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return; - } - - mcg_id = hyb_list_get_mcgid(ext_idx(area, ext_id), area->ext_table); - if (mcg_id <= 0 || mcg_id >= area->nr_mcgs) { - hybp(HYB_ERR, "mcg_id = %d invalid\n", mcg_id); - return; - } - - atomic64_inc(&stat->ext_cnt); - if (area->mcg_id_cnt[mcg_id] == 0) { - area->mcg_id_cnt[mcg_id]++; - atomic64_inc(&stat->frag_cnt); - atomic64_inc(&stat->mcg_cnt); - return; - } - area->mcg_id_cnt[mcg_id]++; - - prev_flag = prev_is_cont(area, ext_id, mcg_id); - next_flag = next_is_cont(area, ext_id, mcg_id); - - if (fragment_inc(prev_flag, next_flag, stat)) - atomic64_inc(&stat->frag_cnt); -} - -static int extent_bit2id(struct hybridswap_area *area, int bit) -{ - if (bit < 0 || bit >= area->nr_exts) { - hybp(HYB_ERR, "bit = %d invalid\n", bit); - return -EINVAL; - } - - return area->nr_exts - bit - 1; -} - -static int extent_id2bit(struct hybridswap_area *area, int id) -{ - if (id < 0 || id >= area->nr_exts) { - hybp(HYB_ERR, "id = %d invalid\n", id); - return -EINVAL; - } - - return area->nr_exts - id - 1; -} - -int obj_idx(struct hybridswap_area *area, int idx) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (idx < 0 || idx >= area->nr_objs) { - hybp(HYB_ERR, "idx = %d invalid\n", idx); - return -EINVAL; - } - - return idx; -} - -int ext_idx(struct hybridswap_area *area, int idx) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (idx < 0 || idx >= area->nr_exts) { - hybp(HYB_ERR, "idx = %d invalid\n", idx); - return -EINVAL; - } - - return idx + area->nr_objs; -} - -int mcg_idx(struct hybridswap_area *area, int idx) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (idx <= 0 || idx >= area->nr_mcgs) { - hybp(HYB_ERR, "idx = %d invalid, nr_mcgs %d\n", idx, - area->nr_mcgs); - return -EINVAL; - } - - return idx + area->nr_objs + area->nr_exts; -} - -static struct hyb_list_head *get_obj_table_node(int idx, void *private) -{ - struct hybridswap_area *area = private; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return NULL; - } - if (idx < 0) { - hybp(HYB_ERR, "idx = %d invalid\n", idx); - return NULL; - } - if (idx < area->nr_objs) - return &area->lru[idx]; - idx -= area->nr_objs; - if (idx < area->nr_exts) - return &area->rmap[idx]; - idx -= area->nr_exts; - if (idx > 0 && idx < area->nr_mcgs) { - struct mem_cgroup *mcg = get_mem_cgroup(idx); - - if (!mcg) - goto err_out; - return (struct hyb_list_head *)(&MEMCGRP_ITEM(mcg, zram_lru)); - } -err_out: - hybp(HYB_ERR, "idx = %d invalid, mcg is NULL\n", idx); - - return NULL; -} - -static void free_obj_list_table(struct hybridswap_area *area) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return; - } - - if (area->lru) { - vfree(area->lru); - area->lru = NULL; - } - if (area->rmap) { - vfree(area->rmap); - area->rmap = NULL; - } - - kfree(area->obj_table); - area->obj_table = NULL; -} - -static int init_obj_list_table(struct hybridswap_area *area) -{ - int i; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - - area->lru = vzalloc(sizeof(struct hyb_list_head) * area->nr_objs); - if (!area->lru) { - hybp(HYB_ERR, "area->lru alloc failed\n"); - goto err_out; - } - area->rmap = vzalloc(sizeof(struct hyb_list_head) * area->nr_exts); - if (!area->rmap) { - hybp(HYB_ERR, "area->rmap alloc failed\n"); - goto err_out; - } - area->obj_table = alloc_table(get_obj_table_node, area, GFP_KERNEL); - if (!area->obj_table) { - hybp(HYB_ERR, "area->obj_table alloc failed\n"); - goto err_out; - } - for (i = 0; i < area->nr_objs; i++) - hyb_list_init(obj_idx(area, i), area->obj_table); - for (i = 0; i < area->nr_exts; i++) - hyb_list_init(ext_idx(area, i), area->obj_table); - - hybp(HYB_INFO, "hybridswap obj list table init OK.\n"); - return 0; -err_out: - free_obj_list_table(area); - hybp(HYB_ERR, "hybridswap obj list table init failed.\n"); - - return -ENOMEM; -} - -static struct hyb_list_head *get_ext_table_node(int idx, void *private) -{ - struct hybridswap_area *area = private; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return NULL; - } - - if (idx < area->nr_objs) - goto err_out; - idx -= area->nr_objs; - if (idx < area->nr_exts) - return &area->ext[idx]; - idx -= area->nr_exts; - if (idx > 0 && idx < area->nr_mcgs) { - struct mem_cgroup *mcg = get_mem_cgroup(idx); - - if (!mcg) - return NULL; - return (struct hyb_list_head *)(&MEMCGRP_ITEM(mcg, ext_lru)); - } -err_out: - hybp(HYB_ERR, "idx = %d invalid\n", idx); - - return NULL; -} - -static void free_ext_list_table(struct hybridswap_area *area) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return; - } - - if (area->ext) - vfree(area->ext); - - kfree(area->ext_table); -} - -static int init_ext_list_table(struct hybridswap_area *area) -{ - int i; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - area->ext = vzalloc(sizeof(struct hyb_list_head) * area->nr_exts); - if (!area->ext) - goto err_out; - area->ext_table = alloc_table(get_ext_table_node, area, GFP_KERNEL); - if (!area->ext_table) - goto err_out; - for (i = 0; i < area->nr_exts; i++) - hyb_list_init(ext_idx(area, i), area->ext_table); - hybp(HYB_INFO, "hybridswap ext list table init OK.\n"); - return 0; -err_out: - free_ext_list_table(area); - hybp(HYB_ERR, "hybridswap ext list table init failed.\n"); - - return -ENOMEM; -} - -void free_hybridswap_area(struct hybridswap_area *area) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return; - } - - vfree(area->bitmap); - vfree(area->ext_stored_pages); - free_obj_list_table(area); - free_ext_list_table(area); - vfree(area); -} - -struct hybridswap_area *alloc_hybridswap_area(unsigned long ori_size, - unsigned long comp_size) -{ - struct hybridswap_area *area = vzalloc(sizeof(struct hybridswap_area)); - - if (!area) { - hybp(HYB_ERR, "area alloc failed\n"); - goto err_out; - } - if (comp_size & (EXTENT_SIZE - 1)) { - hybp(HYB_ERR, "disksize = %ld align invalid (32K align needed)\n", - comp_size); - goto err_out; - } - area->size = comp_size; - area->nr_exts = comp_size >> EXTENT_SHIFT; - area->nr_mcgs = MEM_CGROUP_ID_MAX; - area->nr_objs = ori_size >> PAGE_SHIFT; - area->bitmap = vzalloc(BITS_TO_LONGS(area->nr_exts) * sizeof(long)); - if (!area->bitmap) { - hybp(HYB_ERR, "area->bitmap alloc failed, %lu\n", - BITS_TO_LONGS(area->nr_exts) * sizeof(long)); - goto err_out; - } - area->ext_stored_pages = vzalloc(sizeof(atomic_t) * area->nr_exts); - if (!area->ext_stored_pages) { - hybp(HYB_ERR, "area->ext_stored_pages alloc failed\n"); - goto err_out; - } - if (init_obj_list_table(area)) { - hybp(HYB_ERR, "init obj list table failed\n"); - goto err_out; - } - if (init_ext_list_table(area)) { - hybp(HYB_ERR, "init ext list table failed\n"); - goto err_out; - } - hybp(HYB_INFO, "area %p size %lu nr_exts %lu nr_mcgs %lu nr_objs %lu\n", - area, area->size, area->nr_exts, area->nr_mcgs, - area->nr_objs); - hybp(HYB_INFO, "hybridswap_area init OK.\n"); - return area; -err_out: - free_hybridswap_area(area); - hybp(HYB_ERR, "hybridswap_area init failed.\n"); - - return NULL; -} - -void hybridswap_check_area_extent(struct hybridswap_area *area) -{ - int i; - - if (!area) - return; - - for (i = 0; i < area->nr_exts; i++) { - int cnt = atomic_read(&area->ext_stored_pages[i]); - int ext_id = ext_idx(area, i); - bool priv = hyb_list_test_priv(ext_id, area->ext_table); - int mcg_id = hyb_list_get_mcgid(ext_id, area->ext_table); - - if (cnt < 0 || (cnt > 0 && mcg_id == 0)) - hybp(HYB_ERR, "%8d %8d %8d %8d %4d\n", i, cnt, ext_id, - mcg_id, priv); - } -} - -void hybridswap_free_extent(struct hybridswap_area *area, int ext_id) -{ - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "INVALID ext %d\n", ext_id); - return; - } - hybp(HYB_DEBUG, "free ext id = %d.\n", ext_id); - - hyb_list_set_mcgid(ext_idx(area, ext_id), area->ext_table, 0); - if (!test_and_clear_bit(extent_id2bit(area, ext_id), area->bitmap)) { - hybp(HYB_ERR, "bit not set, ext = %d\n", ext_id); - WARN_ON_ONCE(1); - } - atomic_dec(&area->stored_exts); -} - -static int alloc_bitmap(unsigned long *bitmap, int max, int last_bit) -{ - int bit; - - if (!bitmap) { - hybp(HYB_ERR, "NULL bitmap.\n"); - return -EINVAL; - } -retry: - bit = find_next_zero_bit(bitmap, max, last_bit); - if (bit == max) { - if (last_bit == 0) { - hybp(HYB_ERR, "alloc bitmap failed.\n"); - return -ENOSPC; - } - last_bit = 0; - goto retry; - } - if (test_and_set_bit(bit, bitmap)) - goto retry; - - return bit; -} - -int hybridswap_alloc_extent(struct hybridswap_area *area, struct mem_cgroup *mcg) -{ - int last_bit; - int bit; - int ext_id; - int mcg_id; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return -EINVAL; - } - - last_bit = atomic_read(&area->last_alloc_bit); - hybp(HYB_DEBUG, "last_bit = %d.\n", last_bit); - bit = alloc_bitmap(area->bitmap, area->nr_exts, last_bit); - if (bit < 0) { - hybp(HYB_ERR, "alloc bitmap failed.\n"); - return bit; - } - ext_id = extent_bit2id(area, bit); - mcg_id = hyb_list_get_mcgid(ext_idx(area, ext_id), area->ext_table); - if (mcg_id) { - hybp(HYB_ERR, "already has mcg %d, ext %d\n", - mcg_id, ext_id); - goto err_out; - } - hyb_list_set_mcgid(ext_idx(area, ext_id), area->ext_table, mcg->id.id); - - atomic_set(&area->last_alloc_bit, bit); - atomic_inc(&area->stored_exts); - hybp(HYB_DEBUG, "extent %d init OK.\n", ext_id); - hybp(HYB_DEBUG, "mcg_id = %d, ext id = %d\n", mcg->id.id, ext_id); - - return ext_id; -err_out: - clear_bit(bit, area->bitmap); - WARN_ON_ONCE(1); - return -EBUSY; -} - -int get_extent(struct hybridswap_area *area, int ext_id) -{ - int mcg_id; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return -EINVAL; - } - - if (!hyb_list_clear_priv(ext_idx(area, ext_id), area->ext_table)) - return -EBUSY; - mcg_id = hyb_list_get_mcgid(ext_idx(area, ext_id), area->ext_table); - if (mcg_id) { - ext_fragment_sub(area, ext_id); - hyb_list_del(ext_idx(area, ext_id), mcg_idx(area, mcg_id), - area->ext_table); - } - hybp(HYB_DEBUG, "ext id = %d\n", ext_id); - - return ext_id; -} - -void put_extent(struct hybridswap_area *area, int ext_id) -{ - int mcg_id; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return; - } - - mcg_id = hyb_list_get_mcgid(ext_idx(area, ext_id), area->ext_table); - if (mcg_id) { - hh_lock_list(mcg_idx(area, mcg_id), area->ext_table); - hyb_list_add_nolock(ext_idx(area, ext_id), mcg_idx(area, mcg_id), - area->ext_table); - ext_fragment_add(area, ext_id); - hh_unlock_list(mcg_idx(area, mcg_id), area->ext_table); - } - if (!hyb_list_set_priv(ext_idx(area, ext_id), area->ext_table)) { - hybp(HYB_ERR, "private not set, ext = %d\n", ext_id); - WARN_ON_ONCE(1); - return; - } - hybp(HYB_DEBUG, "put extent %d.\n", ext_id); -} - -int get_memcg_extent(struct hybridswap_area *area, struct mem_cgroup *mcg) -{ - int mcg_id; - int ext_id = -ENOENT; - int idx; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (!area->ext_table) { - hybp(HYB_ERR, "NULL table\n"); - return -EINVAL; - } - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return -EINVAL; - } - - mcg_id = mcg->id.id; - hh_lock_list(mcg_idx(area, mcg_id), area->ext_table); - hyb_list_for_each_entry(idx, mcg_idx(area, mcg_id), area->ext_table) - if (hyb_list_clear_priv(idx, area->ext_table)) { - ext_id = idx - area->nr_objs; - break; - } - if (ext_id >= 0 && ext_id < area->nr_exts) { - ext_fragment_sub(area, ext_id); - hyb_list_del_nolock(idx, mcg_idx(area, mcg_id), area->ext_table); - hybp(HYB_DEBUG, "ext id = %d\n", ext_id); - } - hh_unlock_list(mcg_idx(area, mcg_id), area->ext_table); - - return ext_id; -} - -int get_memcg_zram_entry(struct hybridswap_area *area, struct mem_cgroup *mcg) -{ - int mcg_id, idx; - int index = -ENOENT; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (!area->obj_table) { - hybp(HYB_ERR, "NULL table\n"); - return -EINVAL; - } - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return -EINVAL; - } - - mcg_id = mcg->id.id; - hh_lock_list(mcg_idx(area, mcg_id), area->obj_table); - hyb_list_for_each_entry(idx, mcg_idx(area, mcg_id), area->obj_table) { - index = idx; - break; - } - hh_unlock_list(mcg_idx(area, mcg_id), area->obj_table); - - return index; -} - -int get_extent_zram_entry(struct hybridswap_area *area, int ext_id) -{ - int index = -ENOENT; - int idx; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return -EINVAL; - } - if (!area->obj_table) { - hybp(HYB_ERR, "NULL table\n"); - return -EINVAL; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return -EINVAL; - } - - hh_lock_list(ext_idx(area, ext_id), area->obj_table); - hyb_list_for_each_entry(idx, ext_idx(area, ext_id), area->obj_table) { - index = idx; - break; - } - hh_unlock_list(ext_idx(area, ext_id), area->obj_table); - - return index; -} diff --git a/drivers/block/zram/hybridswap/hybridswap_area.h b/drivers/block/zram/hybridswap/hybridswap_area.h deleted file mode 100755 index a1d8a9c91c9b..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_area.h +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#ifndef _HYBRIDSWAP_AREA_H -#define _HYBRIDSWAP_AREA_H - -#include - -struct hybridswap_area { - unsigned long size; - int nr_objs; - int nr_exts; - int nr_mcgs; - - unsigned long *bitmap; - atomic_t last_alloc_bit; - - struct hyb_list_table *ext_table; - struct hyb_list_head *ext; - - struct hyb_list_table *obj_table; - struct hyb_list_head *rmap; - struct hyb_list_head *lru; - - atomic_t stored_exts; - atomic_t *ext_stored_pages; - - unsigned int mcg_id_cnt[MEM_CGROUP_ID_MAX + 1]; -}; - -struct mem_cgroup *get_mem_cgroup(unsigned short mcg_id); - -int obj_idx(struct hybridswap_area *area, int idx); -int ext_idx(struct hybridswap_area *area, int idx); -int mcg_idx(struct hybridswap_area *area, int idx); - -void free_hybridswap_area(struct hybridswap_area *area); -struct hybridswap_area *alloc_hybridswap_area(unsigned long ori_size, - unsigned long comp_size); -void hybridswap_check_area_extent(struct hybridswap_area *area); -void hybridswap_free_extent(struct hybridswap_area *area, int ext_id); -int hybridswap_alloc_extent(struct hybridswap_area *area, struct mem_cgroup *mcg); -int get_extent(struct hybridswap_area *area, int ext_id); -void put_extent(struct hybridswap_area *area, int ext_id); -int get_memcg_extent(struct hybridswap_area *area, struct mem_cgroup *mcg); -int get_memcg_zram_entry(struct hybridswap_area *area, struct mem_cgroup *mcg); -int get_extent_zram_entry(struct hybridswap_area *area, int ext_id); -#endif /* _HYBRIDSWAP_AREA_H */ diff --git a/drivers/block/zram/hybridswap/hybridswap_core.c b/drivers/block/zram/hybridswap/hybridswap_core.c deleted file mode 100755 index 6f79247fd289..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_core.c +++ /dev/null @@ -1,1008 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_area.h" -#include "hybridswap_list.h" -#include "hybridswap_internal.h" -#include "hybridswap.h" - -struct async_req { - struct mem_cgroup *mcg; - unsigned long size; - unsigned long out_size; - unsigned long reclaimined_sz; - struct work_struct work; - int nice; - bool preload; -}; - -struct io_priv { - struct zram *zram; - enum hybridswap_scenario scenario; - struct hybridswap_page_pool page_pool; -}; - -struct schedule_para { - void *io_handler; - struct hybridswap_entry *io_entry; - struct hybridswap_buffer io_buf; - struct io_priv priv; - struct hybridswap_key_point_record record; -}; - -#define MIN_RECLAIM_ZRAM_SZ (1024 * 1024) - -static void hybridswap_memcg_iter( - int (*iter)(struct mem_cgroup *, void *), void *data) -{ - struct mem_cgroup *mcg = get_next_memcg(NULL); - int ret; - - while (mcg) { - ret = iter(mcg, data); - hybp(HYB_DEBUG, "%pS mcg %d %s %s, ret %d\n", - iter, mcg->id.id, - MEMCGRP_ITEM(mcg, name), - ret ? "failed" : "pass", - ret); - if (ret) { - get_next_memcg_break(mcg); - return; - } - mcg = get_next_memcg(mcg); - } -} - -/* - * This interface will be called when anon page is added to ZRAM. - * Hybridswap should trace this ZRAM in memcg LRU list. - */ -void hybridswap_track(struct zram *zram, u32 index, - struct mem_cgroup *memcg) -{ - memcg_hybs_t *hybs; - struct hybridswap_stat *stat; - - if (!hybridswap_core_enabled()) - return; - - if (!memcg || !memcg->id.id) { - stat = hybridswap_get_stat_obj(); - if (stat) - atomic64_inc(&stat->null_memcg_skip_track_cnt); - return; - } - - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs) { - hybs = hybridswap_cache_alloc(memcg, false); - if (!hybs) { - stat = hybridswap_get_stat_obj(); - if (stat) - atomic64_inc(&stat->skip_track_cnt); - return; - } - } - - if (unlikely(!hybs->zram)) { - spin_lock(&hybs->zram_init_lock); - if (!hybs->zram) - hybridswap_manager_memcg_init(zram, memcg); - spin_unlock(&hybs->zram_init_lock); - } - - hybridswap_zram_lru_add(zram, index, memcg); - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - zram_slot_unlock(zram, index); - if (!zram_watermark_ok()) - wake_all_swapd(); - zram_slot_lock(zram, index); -#endif -} - -void hybridswap_untrack(struct zram *zram, u32 index) -{ - /* - * 1. When the ZS object in the writeback or swapin, - * it can't be untrack. - * 2. Updata the stored size in memcg and ZRAM. - * 3. Remove ZRAM obj from LRU. - * - */ - if (!hybridswap_core_enabled()) - return; - - while (zram_test_flag(zram, index, ZRAM_UNDER_WB) || - zram_test_flag(zram, index, ZRAM_BATCHING_OUT)) { - zram_slot_unlock(zram, index); - udelay(50); - zram_slot_lock(zram, index); - } - - hybridswap_zram_lru_del(zram, index); -} - -static unsigned long memcg_reclaim_size(struct mem_cgroup *memcg) -{ - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - unsigned long zram_size, cur_size, new_size; - - if (!hybs) - return 0; - - zram_size = atomic64_read(&hybs->zram_stored_size); - if (hybs->force_swapout) { - hybs->can_eswaped = zram_size; - return zram_size; - } - - cur_size = atomic64_read(&hybs->hybridswap_stored_size); - new_size = (zram_size + cur_size) * - atomic_read(&hybs->ub_zram2ufs_ratio) / 100; - - hybs->can_eswaped = (new_size > cur_size) ? (new_size - cur_size) : 0; - return hybs->can_eswaped; -} - -static int hybridswap_permcg_sz(struct mem_cgroup *memcg, void *data) -{ - unsigned long *out_size = (unsigned long *)data; - - *out_size += memcg_reclaim_size(memcg); - return 0; -} - -static void hybridswap_flush_cb(enum hybridswap_scenario scenario, - void *pri, struct hybridswap_io_req *req) -{ - switch (scenario) { - case HYBRIDSWAP_FAULT_OUT: - case HYBRIDSWAP_PRE_OUT: - case HYBRIDSWAP_BATCH_OUT: - hybridswap_extent_destroy(pri, scenario); - break; - case HYBRIDSWAP_RECLAIM_IN: - hybridswap_extent_register(pri, req); - break; - default: - break; - } -} - -static void hybridswap_flush_done(struct hybridswap_entry *io_entry, - int err, struct hybridswap_io_req *req) -{ - struct io_priv *priv; - - if (unlikely(!io_entry)) - return; - - priv = (struct io_priv *)(io_entry->private); - if (likely(!err)) { - hybridswap_flush_cb(priv->scenario, - io_entry->manager_private, req); -#ifdef CONFIG_HYBRIDSWAP_SWAPD - if (!zram_watermark_ok()) - wake_all_swapd(); -#endif - } else { - hybridswap_extent_exception(priv->scenario, - io_entry->manager_private); - } - hybridswap_free(io_entry); -} - -static void hybridswap_free_pagepool(struct schedule_para *sched) -{ - struct page *free_page = NULL; - - spin_lock(&sched->priv.page_pool.page_pool_lock); - while (!list_empty(&sched->priv.page_pool.page_pool_list)) { - free_page = list_first_entry( - &sched->priv.page_pool.page_pool_list, - struct page, lru); - list_del_init(&free_page->lru); - __free_page(free_page); - } - spin_unlock(&sched->priv.page_pool.page_pool_lock); -} - -static void hybridswap_plug_complete(void *data) -{ - struct schedule_para *sched = (struct schedule_para *)data; - - hybridswap_free_pagepool(sched); - - hybridswap_perf_end(&sched->record); - - hybridswap_free(sched); -} - -static void *hybridswap_init_plug(struct zram *zram, - enum hybridswap_scenario scenario, - struct schedule_para *sched) -{ - struct hybridswap_io io_para; - - io_para.bdev = zram->bdev; - io_para.scenario = scenario; - io_para.private = (void *)sched; - io_para.record = &sched->record; - INIT_LIST_HEAD(&sched->priv.page_pool.page_pool_list); - spin_lock_init(&sched->priv.page_pool.page_pool_lock); - io_para.done_callback = hybridswap_flush_done; - switch (io_para.scenario) { - case HYBRIDSWAP_RECLAIM_IN: - io_para.complete_notify = hybridswap_plug_complete; - sched->io_buf.pool = NULL; - break; - case HYBRIDSWAP_BATCH_OUT: - case HYBRIDSWAP_PRE_OUT: - io_para.complete_notify = hybridswap_plug_complete; - sched->io_buf.pool = &sched->priv.page_pool; - break; - case HYBRIDSWAP_FAULT_OUT: - io_para.complete_notify = NULL; - sched->io_buf.pool = NULL; - break; - default: - break; - } - sched->io_buf.zram = zram; - sched->priv.zram = zram; - sched->priv.scenario = io_para.scenario; - return hybridswap_plug_start(&io_para); -} - -static void hybridswap_fill_entry(struct hybridswap_entry *io_entry, - struct hybridswap_buffer *io_buf, - void *private) -{ - io_entry->addr = io_entry->ext_id * EXTENT_SECTOR_SIZE; - io_entry->dest_pages = io_buf->dest_pages; - io_entry->pages_sz = EXTENT_PG_CNT; - io_entry->private = private; -} - -static int hybridswap_reclaim_check(struct mem_cgroup *memcg, - unsigned long *require_size) -{ - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - - if (unlikely(!hybs) || unlikely(!hybs->zram)) - return -EAGAIN; - if (unlikely(hybs->in_swapin)) - return -EAGAIN; - if (!hybs->force_swapout && *require_size < MIN_RECLAIM_ZRAM_SZ) - return -EAGAIN; - - return 0; -} - -static int hybridswap_update_reclaim_sz(unsigned long *require_size, - unsigned long *mcg_reclaimed_sz, - unsigned long reclaim_size) -{ - *mcg_reclaimed_sz += reclaim_size; - - if (*require_size > reclaim_size) - *require_size -= reclaim_size; - else - *require_size = 0; - - return 0; -} - -static void hybridswap_stat_alloc_fail(enum hybridswap_scenario scenario, - int err) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat || (err != -ENOMEM) || (scenario >= HYBRIDSWAP_SCENARIO_BUTT)) - return; - - atomic64_inc(&stat->alloc_fail_cnt[scenario]); -} - -static int hybridswap_reclaim_extent(struct mem_cgroup *memcg, - struct schedule_para *sched, - unsigned long *require_size, - unsigned long *mcg_reclaimed_sz, - int *io_err) -{ - int ret; - unsigned long reclaim_size; - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - sched->io_entry = hybridswap_malloc( - sizeof(struct hybridswap_entry), false, true); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - if (unlikely(!sched->io_entry)) { - hybp(HYB_ERR, "alloc io entry failed!\n"); - *require_size = 0; - *io_err = -ENOMEM; - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, -ENOMEM); - - return *io_err; - } - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_FIND_EXTENT); - reclaim_size = hybridswap_extent_create( - memcg, &sched->io_entry->ext_id, - &sched->io_buf, &sched->io_entry->manager_private); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_FIND_EXTENT); - if (unlikely(!reclaim_size)) { - if (sched->io_entry->ext_id != -ENOENT) - *require_size = 0; - hybridswap_free(sched->io_entry); - return -EAGAIN; - } - - hybridswap_fill_entry(sched->io_entry, &sched->io_buf, - (void *)(&sched->priv)); - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IO_EXTENT); - ret = hybridswap_write_extent(sched->io_handler, sched->io_entry); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IO_EXTENT); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap write failed! %d\n", ret); - *require_size = 0; - *io_err = ret; - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, ret); - - return *io_err; - } - - ret = hybridswap_update_reclaim_sz(require_size, mcg_reclaimed_sz, - reclaim_size); - if (MEMCGRP_ITEM(memcg, force_swapout)) - return 0; - return ret; -} - -static int hybridswap_permcg_reclaim(struct mem_cgroup *memcg, - unsigned long require_size, unsigned long *mcg_reclaimed_sz) -{ - int ret, extcnt; - int io_err = 0; - unsigned long require_size_before = 0; - struct schedule_para *sched = NULL; - ktime_t start = ktime_get(); - unsigned long long start_ravg_sum = hybridswap_get_ravg_sum(); - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - - ret = hybridswap_reclaim_check(memcg, &require_size); - if (ret) - return ret == -EAGAIN ? 0 : ret; - - sched = hybridswap_malloc(sizeof(struct schedule_para), false, true); - if (unlikely(!sched)) { - hybp(HYB_ERR, "alloc sched failed!\n"); - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, -ENOMEM); - - return -ENOMEM; - } - - hybridswap_perf_start(&sched->record, start, start_ravg_sum, - HYBRIDSWAP_RECLAIM_IN); - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_INIT); - sched->io_handler = hybridswap_init_plug(hybs->zram, - HYBRIDSWAP_RECLAIM_IN, sched); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_INIT); - if (unlikely(!sched->io_handler)) { - hybp(HYB_ERR, "plug start failed!\n"); - hybridswap_perf_end(&sched->record); - hybridswap_free(sched); - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, -ENOMEM); - ret = -EIO; - goto out; - } - - require_size_before = require_size; - while (require_size) { - if (hybridswap_reclaim_extent(memcg, sched, - &require_size, mcg_reclaimed_sz, &io_err)) - break; - - atomic64_inc(&hybs->hybridswap_outextcnt); - extcnt = atomic_inc_return(&hybs->hybridswap_extcnt); - if (extcnt > atomic_read(&hybs->hybridswap_peakextcnt)) - atomic_set(&hybs->hybridswap_peakextcnt, extcnt); - } - - ret = hybridswap_plug_finish(sched->io_handler); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap write flush failed! %d\n", ret); - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, ret); - require_size = 0; - } else { - ret = io_err; - } - atomic64_inc(&hybs->hybridswap_outcnt); - -out: - hybp(HYB_INFO, "memcg %s %lu %lu reclaim_in %lu KB eswap %lu zram %lu %d\n", - hybs->name, require_size_before, require_size, - (require_size_before - require_size) >> 10, - atomic64_read(&hybs->hybridswap_stored_size), - atomic64_read(&hybs->zram_stored_size), ret); - return ret; -} - -static void hybridswap_reclaimin_inc(void) -{ - struct hybridswap_stat *stat; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) - return; - atomic64_inc(&stat->reclaimin_infight); -} - -static void hybridswap_reclaimin_dec(void) -{ - struct hybridswap_stat *stat; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) - return; - atomic64_dec(&stat->reclaimin_infight); -} - -static int hybridswap_permcg_reclaimin(struct mem_cgroup *memcg, - void *data) -{ - struct async_req *rq = (struct async_req *)data; - unsigned long mcg_reclaimed_size = 0, require_size; - int ret; - memcg_hybs_t *hybs; - - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs) - return 0; - - require_size = hybs->can_eswaped * rq->size / rq->out_size; - if (require_size < MIN_RECLAIM_ZRAM_SZ) - return 0; - - if (!mutex_trylock(&hybs->swap_lock)) - return 0; - - ret = hybridswap_permcg_reclaim(memcg, require_size, - &mcg_reclaimed_size); - rq->reclaimined_sz += mcg_reclaimed_size; - mutex_unlock(&hybs->swap_lock); - - hybp(HYB_INFO, "memcg %s mcg_reclaimed_size %lu rq->reclaimined_sz %lu rq->size %lu rq->out_size %lu ret %d\n", - hybs->name, mcg_reclaimed_size, rq->reclaimined_sz, - rq->size, rq->out_size, ret); - - if (!ret && rq->reclaimined_sz >= rq->size) - return -EINVAL; - - return ret; -} - -static void hybridswap_reclaim_work(struct work_struct *work) -{ - struct async_req *rq = container_of(work, struct async_req, work); - int old_nice = task_nice(current); - - set_user_nice(current, rq->nice); - hybridswap_reclaimin_inc(); - hybridswap_memcg_iter(hybridswap_permcg_reclaimin, rq); - hybridswap_reclaimin_dec(); - set_user_nice(current, old_nice); - hybp(HYB_INFO, "SWAPOUT want %lu MB real %lu Mb\n", rq->size >> 20, - rq->reclaimined_sz >> 20); - hybridswap_free(rq); -} - -unsigned long hybridswap_reclaim_in(unsigned long size) -{ - struct async_req *rq = NULL; - unsigned long out_size = 0; - - if (!hybridswap_core_enabled() || !hybridswap_reclaim_in_enable() - || hybridswap_reach_life_protect() || !size) - return 0; - - hybridswap_memcg_iter(hybridswap_permcg_sz, &out_size); - if (!out_size) - return 0; - - rq = hybridswap_malloc(sizeof(struct async_req), false, true); - if (unlikely(!rq)) { - hybp(HYB_ERR, "alloc async req fail!\n"); - hybridswap_stat_alloc_fail(HYBRIDSWAP_RECLAIM_IN, -ENOMEM); - return 0; - } - - if (out_size < size) - size = out_size; - rq->size = size; - rq->out_size = out_size; - rq->reclaimined_sz = 0; - rq->nice = task_nice(current); - INIT_WORK(&rq->work, hybridswap_reclaim_work); - queue_work(hybridswap_get_reclaim_workqueue(), &rq->work); - - return out_size > size ? size : out_size; -} - -static int hybridswap_batch_out_extent(struct schedule_para *sched, - struct mem_cgroup *mcg, - bool preload, - int *io_err) -{ - int ret; - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - sched->io_entry = hybridswap_malloc( - sizeof(struct hybridswap_entry), !preload, preload); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - if (unlikely(!sched->io_entry)) { - hybp(HYB_ERR, "alloc io entry failed!\n"); - *io_err = -ENOMEM; - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, -ENOMEM); - - return *io_err; - } - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_FIND_EXTENT); - sched->io_entry->ext_id = hybridswap_find_extent_by_memcg( - mcg, &sched->io_buf, - &sched->io_entry->manager_private); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_FIND_EXTENT); - if (sched->io_entry->ext_id < 0) { - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, - sched->io_entry->ext_id); - hybridswap_free(sched->io_entry); - return -EAGAIN; - } - - hybridswap_fill_entry(sched->io_entry, &sched->io_buf, - (void *)(&sched->priv)); - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IO_EXTENT); - ret = hybridswap_read_extent(sched->io_handler, sched->io_entry); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IO_EXTENT); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap read failed! %d\n", ret); - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, ret); - *io_err = ret; - - return *io_err; - } - - return 0; -} - -static int hybridswap_do_batch_out_init(struct schedule_para **out_sched, - struct mem_cgroup *mcg, bool preload) -{ - struct schedule_para *sched = NULL; - ktime_t start = ktime_get(); - unsigned long long start_ravg_sum = hybridswap_get_ravg_sum(); - - sched = hybridswap_malloc(sizeof(struct schedule_para), - !preload, preload); - if (unlikely(!sched)) { - hybp(HYB_ERR, "alloc sched failed!\n"); - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, -ENOMEM); - - return -ENOMEM; - } - - hybridswap_perf_start(&sched->record, start, start_ravg_sum, - preload ? HYBRIDSWAP_PRE_OUT : HYBRIDSWAP_BATCH_OUT); - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_INIT); - sched->io_handler = hybridswap_init_plug(MEMCGRP_ITEM(mcg, zram), - preload ? HYBRIDSWAP_PRE_OUT : HYBRIDSWAP_BATCH_OUT, - sched); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_INIT); - if (unlikely(!sched->io_handler)) { - hybp(HYB_ERR, "plug start failed!\n"); - hybridswap_perf_end(&sched->record); - hybridswap_free(sched); - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, -ENOMEM); - - return -EIO; - } - - *out_sched = sched; - - return 0; -} - -static int hybridswap_do_batch_out(struct mem_cgroup *mcg, - unsigned long size, bool preload) -{ - int ret = 0; - int io_err = 0; - struct schedule_para *sched = NULL; - - if (unlikely(!mcg || !MEMCGRP_ITEM(mcg, zram))) { - hybp(HYB_WARN, "no zram in mcg!\n"); - ret = -EINVAL; - goto out; - } - - ret = hybridswap_do_batch_out_init(&sched, mcg, preload); - if (unlikely(ret)) - goto out; - - MEMCGRP_ITEM(mcg, in_swapin) = true; - while (size) { - if (hybridswap_batch_out_extent(sched, mcg, preload, &io_err)) - break; - size -= EXTENT_SIZE; - } - - ret = hybridswap_plug_finish(sched->io_handler); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap read flush failed! %d\n", ret); - hybridswap_stat_alloc_fail(HYBRIDSWAP_BATCH_OUT, ret); - } else { - ret = io_err; - } - - if (atomic64_read(&MEMCGRP_ITEM(mcg, hybridswap_stored_size)) && - hybridswap_loglevel() >= HYB_INFO) - hybridswap_check_area_extent((MEMCGRP_ITEM(mcg, zram)->area)); - - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_incnt)); - MEMCGRP_ITEM(mcg, in_swapin) = false; -out: - return ret; -} - -static void hybridswap_batchout_inc(void) -{ - struct hybridswap_stat *stat; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) - return; - atomic64_inc(&stat->batchout_inflight); -} - -static void hybridswap_batchout_dec(void) -{ - struct hybridswap_stat *stat; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) - return; - atomic64_dec(&stat->batchout_inflight); -} - -int hybridswap_batch_out(struct mem_cgroup *mcg, - unsigned long size, bool preload) -{ - int ret; - - if (!hybridswap_core_enabled()) - return 0; - - hybridswap_batchout_inc(); - ret = hybridswap_do_batch_out(mcg, size, preload); - hybridswap_batchout_dec(); - - return ret; -} - -static void hybridswap_fault_stat(struct zram *zram, u32 index) -{ - struct mem_cgroup *mcg = NULL; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (unlikely(!stat)) - return; - - atomic64_inc(&stat->fault_cnt); - - mcg = hybridswap_zram_get_memcg(zram, index); - if (mcg) - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_allfaultcnt)); -} - -static void hybridswap_fault2_stat(struct zram *zram, u32 index) -{ - struct mem_cgroup *mcg = NULL; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (unlikely(!stat)) - return; - - atomic64_inc(&stat->hybridswap_fault_cnt); - - mcg = hybridswap_zram_get_memcg(zram, index); - if (mcg) - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_faultcnt)); -} - -static bool hybridswap_fault_out_check(struct zram *zram, - u32 index, unsigned long *zentry) -{ - if (!hybridswap_core_enabled()) - return false; - - hybridswap_fault_stat(zram, index); - - if (!zram_test_flag(zram, index, ZRAM_WB)) - return false; - - zram_set_flag(zram, index, ZRAM_BATCHING_OUT); - *zentry = zram_get_handle(zram, index); - zram_slot_unlock(zram, index); - return true; -} - -static int hybridswap_fault_out_get_extent(struct zram *zram, - struct schedule_para *sched, - unsigned long zentry, - u32 index) -{ - int wait_cycle = 0; - - sched->io_buf.zram = zram; - sched->priv.zram = zram; - sched->io_buf.pool = NULL; - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_FIND_EXTENT); - sched->io_entry->ext_id = hybridswap_find_extent_by_idx(zentry, - &sched->io_buf, &sched->io_entry->manager_private); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_FIND_EXTENT); - if (unlikely(sched->io_entry->ext_id == -EBUSY)) { - /* The extent maybe in unexpected case, wait here */ - while (1) { - /* The extent doesn't exist in hybridswap */ - zram_slot_lock(zram, index); - if (!zram_test_flag(zram, index, ZRAM_WB)) { - zram_slot_unlock(zram, index); - hybridswap_free(sched->io_entry); -#ifdef CONFIG_HYBRIDSWAP_SWAPD - if (wait_cycle >= 1000) - atomic_long_dec(&fault_out_pause); -#endif - return -EAGAIN; - } - zram_slot_unlock(zram, index); - - /* Get extent again */ - hybridswap_perf_lat_start(&sched->record, - HYBRIDSWAP_FIND_EXTENT); - sched->io_entry->ext_id = - hybridswap_find_extent_by_idx(zentry, - &sched->io_buf, - &sched->io_entry->manager_private); - hybridswap_perf_lat_end(&sched->record, - HYBRIDSWAP_FIND_EXTENT); - if (likely(sched->io_entry->ext_id != -EBUSY)) - break; - - if (wait_cycle < 100) - udelay(50); - else - usleep_range(50, 100); - wait_cycle++; -#ifdef CONFIG_HYBRIDSWAP_SWAPD - if (wait_cycle == 1000) { - atomic_long_inc(&fault_out_pause); - atomic_long_inc(&fault_out_pause_cnt); - } -#endif - } - } -#ifdef CONFIG_HYBRIDSWAP_SWAPD - if (wait_cycle >= 1000) - atomic_long_dec(&fault_out_pause); -#endif - if (sched->io_entry->ext_id < 0) { - hybridswap_stat_alloc_fail(HYBRIDSWAP_FAULT_OUT, - sched->io_entry->ext_id); - - return sched->io_entry->ext_id; - } - hybridswap_fault2_stat(zram, index); - hybridswap_fill_entry(sched->io_entry, &sched->io_buf, - (void *)(&sched->priv)); - return 0; -} - -static int hybridswap_fault_out_exit_check(struct zram *zram, - u32 index, int ret) -{ - zram_slot_lock(zram, index); - if (likely(!ret)) { - if (unlikely(zram_test_flag(zram, index, ZRAM_WB))) { - hybp(HYB_ERR, "still in WB status!\n"); - ret = -EIO; - } - } - zram_clear_flag(zram, index, ZRAM_BATCHING_OUT); - - return ret; -} - -static int hybridswap_fault_out_extent(struct zram *zram, u32 index, - struct schedule_para *sched, unsigned long zentry) -{ - int ret; - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - sched->io_entry = hybridswap_malloc(sizeof(struct hybridswap_entry), - true, true); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IOENTRY_ALLOC); - if (unlikely(!sched->io_entry)) { - hybp(HYB_ERR, "alloc io entry failed!\n"); - hybridswap_stat_alloc_fail(HYBRIDSWAP_FAULT_OUT, -ENOMEM); - hybridswap_fail_record(HYBRIDSWAP_FAULT_OUT_ENTRY_ALLOC_FAIL, - index, 0, sched->record.task_comm); - return -ENOMEM; - } - - ret = hybridswap_fault_out_get_extent(zram, sched, zentry, index); - if (ret) - return ret; - - hybridswap_perf_lat_start(&sched->record, HYBRIDSWAP_IO_EXTENT); - ret = hybridswap_read_extent(sched->io_handler, sched->io_entry); - hybridswap_perf_lat_end(&sched->record, HYBRIDSWAP_IO_EXTENT); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap read failed! %d\n", ret); - hybridswap_stat_alloc_fail(HYBRIDSWAP_FAULT_OUT, ret); - } - - return ret; -} - -/* - * This interface will be called when ZRAM is read. - * Hybridswap should be searched before ZRAM is read. - * This function require ZRAM slot lock being held. - * - */ -int hybridswap_fault_out(struct zram *zram, u32 index) -{ - /* - * 1. Find the extent in ZRAM by the index. - * 2. if extent exist, dispatch it to UFS. - * - */ - int ret = 0; - int io_err; - struct schedule_para sched; - unsigned long zentry; - ktime_t start = ktime_get(); - unsigned long long start_ravg_sum = hybridswap_get_ravg_sum(); - - if (!hybridswap_fault_out_check(zram, index, &zentry)) - return ret; - - memset(&sched.record, 0, sizeof(struct hybridswap_key_point_record)); - hybridswap_perf_start(&sched.record, start, start_ravg_sum, - HYBRIDSWAP_FAULT_OUT); - - hybridswap_perf_lat_start(&sched.record, HYBRIDSWAP_INIT); - sched.io_handler = hybridswap_init_plug(zram, - HYBRIDSWAP_FAULT_OUT, &sched); - hybridswap_perf_lat_end(&sched.record, HYBRIDSWAP_INIT); - if (unlikely(!sched.io_handler)) { - hybp(HYB_ERR, "plug start failed!\n"); - hybridswap_stat_alloc_fail(HYBRIDSWAP_FAULT_OUT, -ENOMEM); - ret = -EIO; - hybridswap_fail_record(HYBRIDSWAP_FAULT_OUT_INIT_FAIL, - index, 0, sched.record.task_comm); - - goto out; - } - - io_err = hybridswap_fault_out_extent(zram, index, &sched, zentry); - ret = hybridswap_plug_finish(sched.io_handler); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap flush failed! %d\n", ret); - hybridswap_stat_alloc_fail(HYBRIDSWAP_FAULT_OUT, ret); - } else { - ret = (io_err != -EAGAIN) ? io_err : 0; - } -out: - hybridswap_perf_lat_start(&sched.record, HYBRIDSWAP_ZRAM_LOCK); - ret = hybridswap_fault_out_exit_check(zram, index, ret); - hybridswap_perf_lat_end(&sched.record, HYBRIDSWAP_ZRAM_LOCK); - hybridswap_perf_end(&sched.record); - - return ret; -} - -/* - * This interface will be called when ZRAM is freed. - * Hybridswap should be deleted before ZRAM is freed. - * If obj can be deleted from ZRAM, - * return true, otherwise return false. - * - */ -bool hybridswap_delete(struct zram *zram, u32 index) -{ - /* - * 1. Find the extent in ZRAM by the index. - * 2. Delete the zs Object in the extent. - * 3. If extent is empty, free the extent. - * - */ - - if (!hybridswap_core_enabled()) - return true; - - if (zram_test_flag(zram, index, ZRAM_UNDER_WB) - || zram_test_flag(zram, index, ZRAM_BATCHING_OUT)) { - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (stat) - atomic64_inc(&stat->miss_free); - return false; - } - - if (!zram_test_flag(zram, index, ZRAM_WB)) - return true; - - hybridswap_extent_objs_del(zram, index); - - return true; -} - -void hybridswap_mem_cgroup_deinit(struct mem_cgroup *memcg) -{ - if (!hybridswap_core_enabled()) - return; - - hybridswap_manager_memcg_deinit(memcg); -} - -void hybridswap_force_reclaim(struct mem_cgroup *mcg) -{ - unsigned long mcg_reclaimed_size = 0, require_size; - memcg_hybs_t *hybs; - - if (!hybridswap_core_enabled() || !hybridswap_reclaim_in_enable() - || hybridswap_reach_life_protect()) - return; - - if (!mcg) - return; - - hybs = MEMCGRP_ITEM_DATA(mcg); - if (!hybs || !hybs->zram) - return; - - mutex_lock(&hybs->swap_lock); - require_size = atomic64_read(&hybs->zram_stored_size); - hybs->force_swapout = true; - hybridswap_permcg_reclaim(mcg, require_size, &mcg_reclaimed_size); - hybs->force_swapout = false; - mutex_unlock(&hybs->swap_lock); -} - -void mem_cgroup_id_remove_hook(void *data, struct mem_cgroup *memcg) -{ - if (!memcg->android_oem_data1) - return; - - hybridswap_mem_cgroup_deinit(memcg); - hybp(HYB_DEBUG, "hybridswap remove mcg id = %d\n", memcg->id.id); -} diff --git a/drivers/block/zram/hybridswap/hybridswap_ctrl.c b/drivers/block/zram/hybridswap/hybridswap_ctrl.c deleted file mode 100755 index bc3d8323b35c..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_ctrl.c +++ /dev/null @@ -1,678 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_internal.h" -#include "hybridswap.h" - -#define PRE_EOL_INFO_OVER_VAL 2 -#define LIFE_TIME_EST_OVER_VAL 8 -#define DEFAULT_STORED_WM_RATIO 90 - -struct zs_ext_para { - struct hybridswap_page_pool *pool; - size_t alloc_size; - bool fast; - bool nofail; -}; - -struct hybridswap_cfg { - atomic_t enable; - atomic_t reclaim_in_enable; - struct hybridswap_stat *stat; - struct workqueue_struct *reclaim_wq; - struct zram *zram; - - atomic_t dev_life; - unsigned long quota_day; - struct timer_list lpc_timer; - struct work_struct lpc_work; -}; - -struct hybridswap_cfg global_settings; - -#define DEVICE_NAME_LEN 64 -static char loop_device[DEVICE_NAME_LEN]; - -void *hybridswap_malloc(size_t size, bool fast, bool nofail) -{ - void *mem = NULL; - - if (likely(fast)) { - mem = kzalloc(size, GFP_ATOMIC); - if (likely(mem || !nofail)) - return mem; - } - - mem = kzalloc(size, GFP_NOIO); - - return mem; -} - -void hybridswap_free(const void *mem) -{ - kfree(mem); -} - -struct page *hybridswap_alloc_page_common(void *data, gfp_t gfp) -{ - struct page *page = NULL; - struct zs_ext_para *ext_para = (struct zs_ext_para *)data; - - if (ext_para->pool) { - spin_lock(&ext_para->pool->page_pool_lock); - if (!list_empty(&ext_para->pool->page_pool_list)) { - page = list_first_entry( - &ext_para->pool->page_pool_list, - struct page, lru); - list_del(&page->lru); - } - spin_unlock(&ext_para->pool->page_pool_lock); - } - - if (!page) { - if (ext_para->fast) { - page = alloc_page(GFP_ATOMIC); - if (likely(page)) - goto out; - } - if (ext_para->nofail) - page = alloc_page(GFP_NOIO); - else - page = alloc_page(gfp); - } -out: - return page; -} - -unsigned long hybridswap_zsmalloc(struct zs_pool *zs_pool, - size_t size, struct hybridswap_page_pool *pool) -{ - gfp_t gfp = __GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM | - __GFP_NOWARN | __GFP_HIGHMEM | __GFP_MOVABLE; - return zs_malloc(zs_pool, size, gfp); -} - -unsigned long zram_zsmalloc(struct zs_pool *zs_pool, size_t size, gfp_t gfp) -{ - return zs_malloc(zs_pool, size, gfp); -} - -struct page *hybridswap_alloc_page(struct hybridswap_page_pool *pool, - gfp_t gfp, bool fast, bool nofail) -{ - struct zs_ext_para ext_para; - - ext_para.pool = pool; - ext_para.fast = fast; - ext_para.nofail = nofail; - - return hybridswap_alloc_page_common((void *)&ext_para, gfp); -} - -void hybridswap_page_recycle(struct page *page, struct hybridswap_page_pool *pool) -{ - if (pool) { - spin_lock(&pool->page_pool_lock); - list_add(&page->lru, &pool->page_pool_list); - spin_unlock(&pool->page_pool_lock); - } else { - __free_page(page); - } -} - -bool hybridswap_reclaim_in_enable(void) -{ - return !!atomic_read(&global_settings.reclaim_in_enable); -} - -void hybridswap_set_reclaim_in_disable(void) -{ - atomic_set(&global_settings.reclaim_in_enable, false); -} - -void hybridswap_set_reclaim_in_enable(bool en) -{ - atomic_set(&global_settings.reclaim_in_enable, en ? 1 : 0); -} - -bool hybridswap_core_enabled(void) -{ - return !!atomic_read(&global_settings.enable); -} - -void hybridswap_set_enable(bool en) -{ - hybridswap_set_reclaim_in_enable(en); - - if (!hybridswap_core_enabled()) - atomic_set(&global_settings.enable, en ? 1 : 0); -} - -struct hybridswap_stat *hybridswap_get_stat_obj(void) -{ - return global_settings.stat; -} - -bool hybridswap_dev_life(void) -{ - return !!atomic_read(&global_settings.dev_life); -} - -void hybridswap_set_dev_life(bool en) -{ - atomic_set(&global_settings.dev_life, en ? 1 : 0); -} - -unsigned long hybridswap_quota_day(void) -{ - return global_settings.quota_day; -} - -void hybridswap_set_quota_day(unsigned long val) -{ - global_settings.quota_day = val; -} - -bool hybridswap_reach_life_protect(void) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - unsigned long quota = hybridswap_quota_day(); - - if (hybridswap_dev_life()) - quota /= 10; - return atomic64_read(&stat->reclaimin_bytes_daily) > quota; -} - -static void hybridswap_life_protect_ctrl_work(struct work_struct *work) -{ - struct tm tm; - struct timespec64 ts; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - ktime_get_real_ts64(&ts); - time64_to_tm(ts.tv_sec - sys_tz.tz_minuteswest * 60, 0, &tm); - - if (tm.tm_hour > 2) - atomic64_set(&stat->reclaimin_bytes_daily, 0); -} - -static void hybridswap_life_protect_ctrl_timer(struct timer_list *t) -{ - schedule_work(&global_settings.lpc_work); - mod_timer(&global_settings.lpc_timer, - jiffies + HYBRIDSWAP_CHECK_INTERVAL * HZ); -} - -void hybridswap_close_bdev(struct block_device *bdev, struct file *backing_dev) -{ - if (bdev) - blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); - - if (backing_dev) - filp_close(backing_dev, NULL); -} - -struct file *hybridswap_open_bdev(const char *file_name) -{ - struct file *backing_dev = NULL; - - backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0); - if (unlikely(IS_ERR(backing_dev))) { - hybp(HYB_ERR, "open the %s failed! eno = %lld\n", - file_name, PTR_ERR(backing_dev)); - backing_dev = NULL; - return NULL; - } - - if (unlikely(!S_ISBLK(backing_dev->f_mapping->host->i_mode))) { - hybp(HYB_ERR, "%s isn't a blk device\n", file_name); - hybridswap_close_bdev(NULL, backing_dev); - return NULL; - } - - return backing_dev; -} - -int hybridswap_bind(struct zram *zram, const char *file_name) -{ - struct file *backing_dev = NULL; - struct inode *inode = NULL; - unsigned long nr_pages; - struct block_device *bdev = NULL; - int err; - - backing_dev = hybridswap_open_bdev(file_name); - if (unlikely(!backing_dev)) - return -EINVAL; - - inode = backing_dev->f_mapping->host; - bdev = blkdev_get_by_dev(inode->i_rdev, - FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram); - if (IS_ERR(bdev)) { - hybp(HYB_ERR, "%s blkdev_get failed!\n", file_name); - err = PTR_ERR(bdev); - bdev = NULL; - goto out; - } - - nr_pages = (unsigned long)i_size_read(inode) >> PAGE_SHIFT; - err = set_blocksize(bdev, PAGE_SIZE); - if (unlikely(err)) { - hybp(HYB_ERR, - "%s set blocksize failed! eno = %d\n", file_name, err); - goto out; - } - - zram->bdev = bdev; - zram->backing_dev = backing_dev; - zram->nr_pages = nr_pages; - return 0; - -out: - hybridswap_close_bdev(bdev, backing_dev); - - return err; -} - -static inline unsigned long get_original_used_swap(void) -{ - struct sysinfo val; - - si_swapinfo(&val); - - return val.totalswap - val.freeswap; -} - -void hybridswap_stat_init(struct hybridswap_stat *stat) -{ - int i; - - atomic64_set(&stat->reclaimin_cnt, 0); - atomic64_set(&stat->reclaimin_bytes, 0); - atomic64_set(&stat->reclaimin_real_load, 0); - atomic64_set(&stat->dropped_ext_size, 0); - atomic64_set(&stat->reclaimin_bytes_daily, 0); - atomic64_set(&stat->reclaimin_pages, 0); - atomic64_set(&stat->reclaimin_infight, 0); - atomic64_set(&stat->batchout_cnt, 0); - atomic64_set(&stat->batchout_bytes, 0); - atomic64_set(&stat->batchout_real_load, 0); - atomic64_set(&stat->batchout_pages, 0); - atomic64_set(&stat->batchout_inflight, 0); - atomic64_set(&stat->fault_cnt, 0); - atomic64_set(&stat->hybridswap_fault_cnt, 0); - atomic64_set(&stat->reout_pages, 0); - atomic64_set(&stat->reout_bytes, 0); - atomic64_set(&stat->zram_stored_pages, 0); - atomic64_set(&stat->zram_stored_size, 0); - atomic64_set(&stat->stored_pages, 0); - atomic64_set(&stat->stored_size, 0); - atomic64_set(&stat->notify_free, 0); - atomic64_set(&stat->frag_cnt, 0); - atomic64_set(&stat->mcg_cnt, 0); - atomic64_set(&stat->ext_cnt, 0); - atomic64_set(&stat->miss_free, 0); - atomic64_set(&stat->mcgid_clear, 0); - atomic64_set(&stat->skip_track_cnt, 0); - atomic64_set(&stat->null_memcg_skip_track_cnt, 0); - atomic64_set(&stat->used_swap_pages, get_original_used_swap()); - atomic64_set(&stat->stored_wm_ratio, DEFAULT_STORED_WM_RATIO); - - for (i = 0; i < HYBRIDSWAP_SCENARIO_BUTT; ++i) { - atomic64_set(&stat->io_fail_cnt[i], 0); - atomic64_set(&stat->alloc_fail_cnt[i], 0); - atomic64_set(&stat->lat[i].total_lat, 0); - atomic64_set(&stat->lat[i].max_lat, 0); - } - - stat->record.num = 0; - spin_lock_init(&stat->record.lock); -} - -static bool hybridswap_global_setting_init(struct zram *zram) -{ - if (unlikely(global_settings.stat)) - return false; - - global_settings.zram = zram; - hybridswap_set_enable(false); - global_settings.stat = hybridswap_malloc( - sizeof(struct hybridswap_stat), false, true); - if (unlikely(!global_settings.stat)) { - hybp(HYB_ERR, "global stat allocation failed!\n"); - return false; - } - - hybridswap_stat_init(global_settings.stat); - global_settings.reclaim_wq = alloc_workqueue("hybridswap_reclaim", - WQ_CPU_INTENSIVE, 0); - if (unlikely(!global_settings.reclaim_wq)) { - hybp(HYB_ERR, "reclaim workqueue allocation failed!\n"); - hybridswap_free(global_settings.stat); - global_settings.stat = NULL; - - return false; - } - - global_settings.quota_day = HYBRIDSWAP_QUOTA_DAY; - INIT_WORK(&global_settings.lpc_work, hybridswap_life_protect_ctrl_work); - global_settings.lpc_timer.expires = jiffies + HYBRIDSWAP_CHECK_INTERVAL * HZ; - timer_setup(&global_settings.lpc_timer, hybridswap_life_protect_ctrl_timer, 0); - add_timer(&global_settings.lpc_timer); - - hybp(HYB_DEBUG, "global settings init success\n"); - return true; -} - -void hybridswap_global_setting_deinit(void) -{ - destroy_workqueue(global_settings.reclaim_wq); - hybridswap_free(global_settings.stat); - global_settings.stat = NULL; - global_settings.zram = NULL; - global_settings.reclaim_wq = NULL; -} - -struct workqueue_struct *hybridswap_get_reclaim_workqueue(void) -{ - return global_settings.reclaim_wq; -} - -static int hybridswap_core_init(struct zram *zram) -{ - int ret; - - if (loop_device[0] == '\0') { - hybp(HYB_ERR, "please setting loop_device first\n"); - return -EINVAL; - } - - if (!hybridswap_global_setting_init(zram)) - return -EINVAL; - - ret = hybridswap_bind(zram, loop_device); - if (unlikely(ret)) { - hybp(HYB_ERR, "bind storage device failed! %d\n", ret); - hybridswap_global_setting_deinit(); - } - - return 0; -} - -int hybridswap_set_enable_init(bool en) -{ - int ret; - - if (hybridswap_core_enabled() || !en) - return 0; - - if (!global_settings.stat) { - hybp(HYB_ERR, "global_settings.stat is null!\n"); - - return -EINVAL; - } - - ret = hybridswap_manager_init(global_settings.zram); - if (unlikely(ret)) { - hybp(HYB_ERR, "init manager failed! %d\n", ret); - - return -EINVAL; - } - - ret = hybridswap_schedule_init(); - if (unlikely(ret)) { - hybp(HYB_ERR, "init schedule failed! %d\n", ret); - hybridswap_manager_deinit(global_settings.zram); - - return -EINVAL; - } - - return 0; -} - -ssize_t hybridswap_core_enable_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - int ret; - unsigned long val; - - ret = kstrtoul(buf, 0, &val); - if (unlikely(ret)) { - hybp(HYB_ERR, "val is error!\n"); - - return -EINVAL; - } - - if (hybridswap_set_enable_init(!!val)) - return -EINVAL; - - hybridswap_set_enable(!!val); - - return len; -} - -ssize_t hybridswap_core_enable_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = snprintf(buf, PAGE_SIZE, "hybridswap %s reclaim_in %s\n", - hybridswap_core_enabled() ? "enable" : "disable", - hybridswap_reclaim_in_enable() ? "enable" : "disable"); - - return len; -} - -ssize_t hybridswap_loop_device_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - struct zram *zram; - int ret = 0; - - if (len > (DEVICE_NAME_LEN - 1)) { - hybp(HYB_ERR, "buf %s len %d is too long\n", buf, len); - return -EINVAL; - } - - memcpy(loop_device, buf, len); - loop_device[len] = '\0'; - strstrip(loop_device); - - zram = dev_to_zram(dev); - down_write(&zram->init_lock); - if (zram->disksize == 0) { - hybp(HYB_ERR, "disksize is 0\n"); - goto out; - } - - ret = hybridswap_core_init(zram); - if (ret) - hybp(HYB_ERR, "hybridswap_core_init init failed\n"); - -out: - up_write(&zram->init_lock); - return len; -} - -ssize_t hybridswap_loop_device_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = 0; - - len = sprintf(buf, "%s\n", loop_device); - - return len; -} - -ssize_t hybridswap_dev_life_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - int ret; - unsigned long val; - - ret = kstrtoul(buf, 0, &val); - if (unlikely(ret)) { - hybp(HYB_ERR, "val is error!\n"); - - return -EINVAL; - } - - hybridswap_set_dev_life(!!val); - - return len; -} - -ssize_t hybridswap_dev_life_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = 0; - - len = sprintf(buf, "%s\n", - hybridswap_dev_life() ? "enable" : "disable"); - - return len; -} - -ssize_t hybridswap_quota_day_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - int ret; - unsigned long val; - - ret = kstrtoul(buf, 0, &val); - if (unlikely(ret)) { - hybp(HYB_ERR, "val is error!\n"); - - return -EINVAL; - } - - hybridswap_set_quota_day(val); - - return len; -} - -ssize_t hybridswap_quota_day_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = 0; - - len = sprintf(buf, "%llu\n", hybridswap_quota_day()); - - return len; -} - -ssize_t hybridswap_zram_increase_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - char *type_buf = NULL; - unsigned long val; - struct zram *zram = dev_to_zram(dev); - - type_buf = strstrip((char *)buf); - if (kstrtoul(type_buf, 0, &val)) - return -EINVAL; - - zram->increase_nr_pages = (val << 8); - return len; -} - -ssize_t hybridswap_zram_increase_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - ssize_t size = 0; - struct zram *zram = dev_to_zram(dev); - - size += scnprintf(buf + size, PAGE_SIZE - size, - "%lu\n", zram->increase_nr_pages >> 8); - - return size; -} - -int mem_cgroup_stored_wm_ratio_write( - struct cgroup_subsys_state *css, struct cftype *cft, s64 val) -{ - if (val > MAX_RATIO || val < MIN_RATIO) - return -EINVAL; - - if (!global_settings.stat) - return -EINVAL; - - atomic64_set(&global_settings.stat->stored_wm_ratio, val); - - return 0; -} - -s64 mem_cgroup_stored_wm_ratio_read( - struct cgroup_subsys_state *css, struct cftype *cft) -{ - if (!global_settings.stat) - return -EINVAL; - - return atomic64_read(&global_settings.stat->stored_wm_ratio); -} - -int hybridswap_stored_info(unsigned long *total, unsigned long *used) -{ - if (!total || !used) - return -EINVAL; - - if (!global_settings.stat || !global_settings.zram) { - *total = 0; - *used = 0; - return 0; - } - - *used = atomic64_read(&global_settings.stat->ext_cnt) * EXTENT_PG_CNT; - *total = global_settings.zram->nr_pages; - - return 0; -} - -bool hybridswap_stored_wm_ok(void) -{ - unsigned long ratio, stored_pages, total_pages, wm_ratio; - int ret; - - if (!hybridswap_core_enabled()) - return false; - - ret = hybridswap_stored_info(&total_pages, &stored_pages); - if (ret) - return false; - - ratio = (stored_pages * 100) / (total_pages + 1); - wm_ratio = atomic64_read(&global_settings.stat->stored_wm_ratio); - - return ratio <= wm_ratio; -} - -int hybridswap_core_enable(void) -{ - int ret; - - ret = hybridswap_set_enable_init(true); - if (ret) { - hybp(HYB_ERR, "set true failed, ret=%d\n", ret); - return ret; - } - - hybridswap_set_enable(true); - return 0; -} - -void hybridswap_core_disable(void) -{ - (void)hybridswap_set_enable_init(false); - hybridswap_set_enable(false); -} diff --git a/drivers/block/zram/hybridswap/hybridswap_internal.h b/drivers/block/zram/hybridswap/hybridswap_internal.h deleted file mode 100755 index 0da33c89efb9..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_internal.h +++ /dev/null @@ -1,561 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#ifndef HYBRIDSWAP_INTERNAL_H -#define HYBRIDSWAP_INTERNAL_H - -#include -#include -#include -#include -#include - -#define EXTENT_SHIFT 15 -#define EXTENT_SIZE (1UL << EXTENT_SHIFT) -#define EXTENT_PG_CNT (EXTENT_SIZE >> PAGE_SHIFT) -#define EXTENT_SECTOR_SIZE (EXTENT_PG_CNT << 3) -#define EXTENT_MAX_OBJ_CNT (30 * EXTENT_PG_CNT) -#define EXTENT_MASK (~(EXTENT_SIZE - 1)) -#define EXTENT_ALIGN_UP(size) ((size + EXTENT_SIZE - 1) & EXTENT_MASK) - -#define MAX_FAIL_RECORD_NUM 10 -#define MEM_CGROUP_NAME_MAX_LEN 32 -#define MAX_APP_SCORE 1000 - -#define HYBRIDSWAP_QUOTA_DAY 0x280000000 /* 10G bytes */ -#define HYBRIDSWAP_CHECK_INTERVAL 86400 /* 24 hour */ - -#define MAX_RATIO 100 -#define MIN_RATIO 0 - -enum { - HYB_ERR = 0, - HYB_WARN, - HYB_INFO, - HYB_DEBUG, - HYB_MAX -}; - -void hybridswap_loglevel_set(int level); -int hybridswap_loglevel(void); - -#define DUMP_STACK_ON_ERR 0 -#define pt(l, f, ...) pr_err("[%s]<%d:%s>:"f, #l, __LINE__, __func__, ##__VA_ARGS__) -static inline void pr_none(void) {} -#define hybp(l, f, ...) do {\ - (l <= hybridswap_loglevel()) ? pt(l, f, ##__VA_ARGS__) : pr_none();\ - if (DUMP_STACK_ON_ERR && l == HYB_ERR) dump_stack();\ -} while (0) - -enum hybridswap_scenario { - HYBRIDSWAP_RECLAIM_IN = 0, - HYBRIDSWAP_FAULT_OUT, - HYBRIDSWAP_BATCH_OUT, - HYBRIDSWAP_PRE_OUT, - HYBRIDSWAP_SCENARIO_BUTT -}; - -enum hybridswap_key_point { - HYBRIDSWAP_START = 0, - HYBRIDSWAP_INIT, - HYBRIDSWAP_IOENTRY_ALLOC, - HYBRIDSWAP_FIND_EXTENT, - HYBRIDSWAP_IO_EXTENT, - HYBRIDSWAP_SEGMENT_ALLOC, - HYBRIDSWAP_BIO_ALLOC, - HYBRIDSWAP_SUBMIT_BIO, - HYBRIDSWAP_END_IO, - HYBRIDSWAP_SCHED_WORK, - HYBRIDSWAP_END_WORK, - HYBRIDSWAP_CALL_BACK, - HYBRIDSWAP_WAKE_UP, - HYBRIDSWAP_ZRAM_LOCK, - HYBRIDSWAP_DONE, - HYBRIDSWAP_KYE_POINT_BUTT -}; - -enum hybridswap_mcg_member { - MCG_ZRAM_STORED_SZ = 0, - MCG_ZRAM_STORED_PG_SZ, - MCG_DISK_STORED_SZ, - MCG_DISK_STORED_PG_SZ, - MCG_ANON_FAULT_CNT, - MCG_DISK_FAULT_CNT, - MCG_ESWAPOUT_CNT, - MCG_ESWAPOUT_SZ, - MCG_ESWAPIN_CNT, - MCG_ESWAPIN_SZ, - MCG_DISK_SPACE, - MCG_DISK_SPACE_PEAK, -}; - -enum hybridswap_fail_point { - HYBRIDSWAP_FAULT_OUT_INIT_FAIL = 0, - HYBRIDSWAP_FAULT_OUT_ENTRY_ALLOC_FAIL, - HYBRIDSWAP_FAULT_OUT_IO_ENTRY_PARA_FAIL, - HYBRIDSWAP_FAULT_OUT_SEGMENT_ALLOC_FAIL, - HYBRIDSWAP_FAULT_OUT_BIO_ALLOC_FAIL, - HYBRIDSWAP_FAULT_OUT_BIO_ADD_FAIL, - HYBRIDSWAP_FAULT_OUT_IO_FAIL, - HYBRIDSWAP_FAIL_POINT_BUTT -}; - -struct hybridswap_fail_record { - unsigned char task_comm[TASK_COMM_LEN]; - enum hybridswap_fail_point point; - ktime_t time; - u32 index; - int ext_id; -}; - -struct hybridswap_fail_record_info { - int num; - spinlock_t lock; - struct hybridswap_fail_record record[MAX_FAIL_RECORD_NUM]; -}; - -struct hybridswap_key_point_info { - unsigned int record_cnt; - unsigned int end_cnt; - ktime_t first_time; - ktime_t last_time; - s64 proc_total_time; - s64 proc_max_time; - unsigned long long last_ravg_sum; - unsigned long long proc_ravg_sum; - spinlock_t time_lock; -}; - -struct hybridswap_key_point_record { - struct timer_list lat_monitor; - unsigned long warning_threshold; - int page_cnt; - int segment_cnt; - int nice; - bool timeout_flag; - unsigned char task_comm[TASK_COMM_LEN]; - struct task_struct *task; - enum hybridswap_scenario scenario; - struct hybridswap_key_point_info key_point[HYBRIDSWAP_KYE_POINT_BUTT]; -}; - -struct hybridswap_lat_stat { - atomic64_t total_lat; - atomic64_t max_lat; - atomic64_t timeout_cnt; -}; - -struct hybridswap_fault_timeout_cnt{ - atomic64_t timeout_100ms_cnt; - atomic64_t timeout_500ms_cnt; -}; - -struct hybridswap_stat { - atomic64_t reclaimin_cnt; - atomic64_t reclaimin_bytes; - atomic64_t reclaimin_real_load; - atomic64_t reclaimin_bytes_daily; - atomic64_t reclaimin_pages; - atomic64_t reclaimin_infight; - atomic64_t batchout_cnt; - atomic64_t batchout_bytes; - atomic64_t batchout_real_load; - atomic64_t batchout_pages; - atomic64_t batchout_inflight; - atomic64_t fault_cnt; - atomic64_t hybridswap_fault_cnt; - atomic64_t reout_pages; - atomic64_t reout_bytes; - atomic64_t zram_stored_pages; - atomic64_t zram_stored_size; - atomic64_t stored_pages; - atomic64_t stored_size; - atomic64_t notify_free; - atomic64_t frag_cnt; - atomic64_t mcg_cnt; - atomic64_t ext_cnt; - atomic64_t miss_free; - atomic64_t mcgid_clear; - atomic64_t skip_track_cnt; - atomic64_t used_swap_pages; - atomic64_t null_memcg_skip_track_cnt; - atomic64_t stored_wm_ratio; - atomic64_t dropped_ext_size; - atomic64_t io_fail_cnt[HYBRIDSWAP_SCENARIO_BUTT]; - atomic64_t alloc_fail_cnt[HYBRIDSWAP_SCENARIO_BUTT]; - struct hybridswap_lat_stat lat[HYBRIDSWAP_SCENARIO_BUTT]; - struct hybridswap_fault_timeout_cnt fault_stat[2]; /* 0:bg 1:fg */ - struct hybridswap_fail_record_info record; -}; - -struct hybridswap_page_pool { - struct list_head page_pool_list; - spinlock_t page_pool_lock; -}; - -struct io_extent { - int ext_id; - struct zram *zram; - struct mem_cgroup *mcg; - struct page *pages[EXTENT_PG_CNT]; - u32 index[EXTENT_MAX_OBJ_CNT]; - int cnt; - int real_load; - - struct hybridswap_page_pool *pool; -}; - -struct hybridswap_buffer { - struct zram *zram; - struct hybridswap_page_pool *pool; - struct page **dest_pages; -}; - -struct hybridswap_entry { - int ext_id; - sector_t addr; - struct page **dest_pages; - int pages_sz; - struct list_head list; - void *private; - void *manager_private; -}; - -struct hybridswap_io_req; -struct hybridswap_io { - struct block_device *bdev; - enum hybridswap_scenario scenario; - void (*done_callback)(struct hybridswap_entry *, int, struct hybridswap_io_req *); - void (*complete_notify)(void *); - void *private; - struct hybridswap_key_point_record *record; -}; - -struct hybridswap_io_req { - struct hybridswap_io io_para; - struct kref refcount; - struct mutex refmutex; - struct wait_queue_head io_wait; - atomic_t extent_inflight; - struct completion io_end_flag; - struct hybridswap_segment *segment; - bool limit_inflight_flag; - bool wait_io_finish_flag; - int page_cnt; - int segment_cnt; - int nice; - atomic64_t real_load; -}; - -/* Change hybridswap_event_item, you should change swapd_text togather*/ -enum hybridswap_event_item { -#ifdef CONFIG_HYBRIDSWAP_SWAPD - SWAPD_WAKEUP, - SWAPD_REFAULT, - SWAPD_MEDIUM_PRESS, - SWAPD_CRITICAL_PRESS, - SWAPD_MEMCG_RATIO_SKIP, - SWAPD_MEMCG_REFAULT_SKIP, - SWAPD_SHRINK_ANON, - SWAPD_SWAPOUT, - SWAPD_SKIP_SWAPOUT, - SWAPD_EMPTY_ROUND, - SWAPD_OVER_MIN_BUFFER_SKIP_TIMES, - SWAPD_EMPTY_ROUND_SKIP_TIMES, - SWAPD_SNAPSHOT_TIMES, - SWAPD_SKIP_SHRINK_OF_WINDOW, - SWAPD_MANUAL_PAUSE, -#ifdef CONFIG_OPLUS_JANK - SWAPD_CPU_BUSY_SKIP_TIMES, - SWAPD_CPU_BUSY_BREAK_TIMES, -#endif -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - AKCOMPRESSD_WAKEUP, -#endif - NR_EVENT_ITEMS -}; - -struct swapd_event_state { - unsigned long event[NR_EVENT_ITEMS]; -}; - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -struct cgroup_cache_page { - spinlock_t lock; - struct list_head head; - unsigned int cnt; - int id; - char compressing; - char dead; -}; -#endif - -typedef struct mem_cgroup_hybridswap { -#ifdef CONFIG_HYBRIDSWAP - atomic64_t ub_ufs2zram_ratio; - atomic_t ub_zram2ufs_ratio; - atomic64_t app_score; - atomic64_t app_uid; - struct list_head score_node; - char name[MEM_CGROUP_NAME_MAX_LEN]; - struct zram *zram; - struct mem_cgroup *memcg; - refcount_t usage; -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD - atomic_t ub_mem2zram_ratio; - atomic_t refault_threshold; - unsigned long long reclaimed_pagefault; - long long can_reclaimed; -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE - unsigned long zram_lru; - unsigned long ext_lru; - struct list_head link_list; - spinlock_t zram_init_lock; - long long can_eswaped; - - atomic64_t zram_stored_size; - atomic64_t zram_page_size; - unsigned long zram_watermark; - - atomic_t hybridswap_extcnt; - atomic_t hybridswap_peakextcnt; - - atomic64_t hybridswap_stored_pages; - atomic64_t hybridswap_stored_size; - atomic64_t hybridswap_ext_notify_free; - - atomic64_t hybridswap_outcnt; - atomic64_t hybridswap_incnt; - atomic64_t hybridswap_allfaultcnt; - atomic64_t hybridswap_faultcnt; - - atomic64_t hybridswap_outextcnt; - atomic64_t hybridswap_inextcnt; - - struct mutex swap_lock; - bool in_swapin; - bool force_swapout; -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - struct cgroup_cache_page cache; -#endif -}memcg_hybs_t; - -#define MEMCGRP_ITEM_DATA(memcg) ((memcg_hybs_t *)(memcg)->android_oem_data1) -#define MEMCGRP_ITEM(memcg, item) (MEMCGRP_ITEM_DATA(memcg)->item) - -extern void __put_memcg_cache(memcg_hybs_t *hybs); - -static inline memcg_hybs_t *get_memcg_cache(memcg_hybs_t *hybs) -{ - refcount_inc(&hybs->usage); - return hybs; -} - -static inline void put_memcg_cache(memcg_hybs_t *hybs) -{ - if (refcount_dec_and_test(&hybs->usage)) - __put_memcg_cache(hybs); -} - -DECLARE_PER_CPU(struct swapd_event_state, swapd_event_states); -extern struct mutex reclaim_para_lock; - -static inline void __count_swapd_event(enum hybridswap_event_item item) -{ - raw_cpu_inc(swapd_event_states.event[item]); -} - -static inline void count_swapd_event(enum hybridswap_event_item item) -{ - this_cpu_inc(swapd_event_states.event[item]); -} - -static inline void __count_swapd_events(enum hybridswap_event_item item, long delta) -{ - raw_cpu_add(swapd_event_states.event[item], delta); -} - -static inline void count_swapd_events(enum hybridswap_event_item item, long delta) -{ - this_cpu_add(swapd_event_states.event[item], delta); -} - -void *hybridswap_malloc(size_t size, bool fast, bool nofail); -void hybridswap_free(const void *mem); -unsigned long hybridswap_zsmalloc(struct zs_pool *zs_pool, - size_t size, struct hybridswap_page_pool *pool); -struct page *hybridswap_alloc_page( - struct hybridswap_page_pool *pool, gfp_t gfp, - bool fast, bool nofail); -void hybridswap_page_recycle(struct page *page, - struct hybridswap_page_pool *pool); -struct hybridswap_stat *hybridswap_get_stat_obj(void); -int hybridswap_manager_init(struct zram *zram); -void hybridswap_manager_memcg_init(struct zram *zram, - struct mem_cgroup *memcg); -void hybridswap_manager_memcg_deinit(struct mem_cgroup *mcg); -void hybridswap_zram_lru_add(struct zram *zram, u32 index, - struct mem_cgroup *memcg); -void hybridswap_zram_lru_del(struct zram *zram, u32 index); -unsigned long hybridswap_extent_create(struct mem_cgroup *memcg, - int *ext_id, - struct hybridswap_buffer *dest_buf, - void **private); -void hybridswap_extent_register(void *private, struct hybridswap_io_req *req); -void hybridswap_extent_objs_del(struct zram *zram, u32 index); -int hybridswap_find_extent_by_idx( - unsigned long eswpentry, struct hybridswap_buffer *buf, void **private); -int hybridswap_find_extent_by_memcg( - struct mem_cgroup *mcg, - struct hybridswap_buffer *dest_buf, void **private); -void hybridswap_extent_destroy(void *private, enum hybridswap_scenario scenario); -void hybridswap_extent_exception(enum hybridswap_scenario scenario, - void *private); -void hybridswap_manager_deinit(struct zram *zram); -struct mem_cgroup *hybridswap_zram_get_memcg(struct zram *zram, u32 index); -int hybridswap_schedule_init(void); -void *hybridswap_plug_start(struct hybridswap_io *io_para); -int hybridswap_read_extent(void *io_handler, - struct hybridswap_entry *io_entry); -int hybridswap_write_extent(void *io_handler, - struct hybridswap_entry *io_entry); - -int hybridswap_plug_finish(void *io_handler); - -void hybridswap_perf_start( - struct hybridswap_key_point_record *record, - ktime_t stsrt, unsigned long long start_ravg_sum, - enum hybridswap_scenario scenario); - -void hybridswap_perf_end(struct hybridswap_key_point_record *record); - -void hybridswap_perf_lat_start( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type); - -void hybridswap_perf_lat_end( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type); - -void hybridswap_perf_lat_point( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type); - -void hybridswap_perf_async_perf( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type, ktime_t start, - unsigned long long start_ravg_sum); - -void hybridswap_perf_io_stat( - struct hybridswap_key_point_record *record, int page_cnt, - int segment_cnt); - -static inline unsigned long long hybridswap_get_ravg_sum(void) -{ - return 0; -} - -void hybridswap_fail_record(enum hybridswap_fail_point point, - u32 index, int ext_id, unsigned char *task_comm); -bool hybridswap_reach_life_protect(void); -struct workqueue_struct *hybridswap_get_reclaim_workqueue(void); -extern struct mem_cgroup *get_next_memcg(struct mem_cgroup *prev); -extern void get_next_memcg_break(struct mem_cgroup *prev); -extern memcg_hybs_t *hybridswap_cache_alloc(struct mem_cgroup *memcg, bool atomic); -extern void memcg_app_score_resort(void); -extern unsigned long memcg_anon_pages(struct mem_cgroup *memcg); - -#ifdef CONFIG_HYBRIDSWAP_CORE -extern bool hybridswap_core_enabled(void); -extern bool hybridswap_reclaim_in_enable(void); -extern void hybridswap_mem_cgroup_deinit(struct mem_cgroup *memcg); -extern unsigned long hybridswap_reclaim_in(unsigned long size); -extern int hybridswap_batch_out(struct mem_cgroup *mcg, - unsigned long size, bool preload); -extern unsigned long zram_zsmalloc(struct zs_pool *zs_pool, - size_t size, gfp_t gfp); -extern struct task_struct *get_task_from_proc(struct inode *inode); -extern unsigned long hybridswap_get_zram_used_pages(void); -extern unsigned long long hybridswap_get_zram_pagefault(void); -extern bool hybridswap_reclaim_work_running(void); -extern void hybridswap_force_reclaim(struct mem_cgroup *mcg); -extern bool hybridswap_stored_wm_ok(void); -extern void mem_cgroup_id_remove_hook(void *data, struct mem_cgroup *memcg); -extern int mem_cgroup_stored_wm_ratio_write( - struct cgroup_subsys_state *css, struct cftype *cft, s64 val); -extern s64 mem_cgroup_stored_wm_ratio_read( - struct cgroup_subsys_state *css, struct cftype *cft); -extern bool hybridswap_delete(struct zram *zram, u32 index); -extern int hybridswap_stored_info(unsigned long *total, unsigned long *used); - -extern unsigned long long hybridswap_read_mcg_stats( - struct mem_cgroup *mcg, enum hybridswap_mcg_member mcg_member); -extern int hybridswap_core_enable(void); -extern void hybridswap_core_disable(void); -extern int hybridswap_psi_show(struct seq_file *m, void *v); -#else -static inline unsigned long long hybridswap_read_mcg_stats( - struct mem_cgroup *mcg, enum hybridswap_mcg_member mcg_member) -{ - return 0; -} - -static inline unsigned long long hybridswap_get_zram_pagefault(void) -{ - return 0; -} - -static inline unsigned long hybridswap_get_zram_used_pages(void) -{ - return 0; -} - -static inline bool hybridswap_reclaim_work_running(void) -{ - return false; -} - -static inline bool hybridswap_core_enabled(void) { return false; } -static inline bool hybridswap_reclaim_in_enable(void) { return false; } -#endif - -#ifdef CONFIG_HYBRIDSWAP_SWAPD -extern atomic_long_t fault_out_pause; -extern atomic_long_t fault_out_pause_cnt; -extern struct cftype mem_cgroup_swapd_legacy_files[]; -extern bool zram_watermark_ok(void); -extern void wake_all_swapd(void); -extern void alloc_pages_slowpath_hook(void *data, gfp_t gfp_mask, - unsigned int order, unsigned long delta); -extern void rmqueue_hook(void *data, struct zone *preferred_zone, - struct zone *zone, unsigned int order, gfp_t gfp_flags, - unsigned int alloc_flags, int migratetype); -extern void __init swapd_pre_init(void); -extern void swapd_pre_deinit(void); -extern void update_swapd_memcg_param(struct mem_cgroup *memcg); -extern bool free_zram_is_ok(void); -extern unsigned long get_nr_zram_total(void); -extern int swapd_init(struct zram *zram); -extern void swapd_exit(void); -extern bool hybridswap_swapd_enabled(void); -#else -static inline bool hybridswap_swapd_enabled(void) { return false; } -#endif - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -extern spinlock_t cached_idr_lock; -extern struct idr cached_idr; - -extern void __init akcompressd_pre_init(void); -extern void __exit akcompressd_pre_deinit(void); -extern int create_akcompressd_task(struct zram *zram); -extern void clear_page_memcg(struct cgroup_cache_page *cache); -#endif - -#endif /* end of HYBRIDSWAP_INTERNAL_H */ diff --git a/drivers/block/zram/hybridswap/hybridswap_list.c b/drivers/block/zram/hybridswap/hybridswap_list.c deleted file mode 100755 index 2dfdf4a25de6..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_list.c +++ /dev/null @@ -1,323 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include - -#include "hybridswap_list.h" -#include "hybridswap_internal.h" - -static struct hyb_list_head *get_node_default(int idx, void *private) -{ - struct hyb_list_head *table = private; - - return &table[idx]; -} - -struct hyb_list_table *alloc_table(struct hyb_list_head *(*get_node)(int, void *), - void *private, gfp_t gfp) -{ - struct hyb_list_table *table = - kmalloc(sizeof(struct hyb_list_table), gfp); - - if (!table) - return NULL; - table->get_node = get_node ? get_node : get_node_default; - table->private = private; - - return table; -} - -void hh_lock_list(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return; - } - bit_spin_lock(HH_LIST_LOCK_BIT, (unsigned long *)node); -} - -void hh_unlock_list(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return; - } - bit_spin_unlock(HH_LIST_LOCK_BIT, (unsigned long *)node); -} - -bool hyb_list_empty(int hidx, struct hyb_list_table *table) -{ - bool ret = false; - - hh_lock_list(hidx, table); - ret = (prev_idx(hidx, table) == hidx) && (next_idx(hidx, table) == hidx); - hh_unlock_list(hidx, table); - - return ret; -} - -void hyb_list_init(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pS func %pS\n", - idx, table, table->get_node); - return; - } - memset(node, 0, sizeof(struct hyb_list_head)); - node->prev = idx; - node->next = idx; -} - -void hyb_list_add_nolock(int idx, int hidx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = NULL; - struct hyb_list_head *head = NULL; - struct hyb_list_head *next = NULL; - int nidx; - - node = idx_node(idx, table); - if (!node) { - hybp(HYB_ERR, - "NULL node, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - head = idx_node(hidx, table); - if (!head) { - hybp(HYB_ERR, - "NULL head, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - next = idx_node(head->next, table); - if (!next) { - hybp(HYB_ERR, - "NULL next, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - - nidx = head->next; - if (idx != hidx) - hh_lock_list(idx, table); - node->prev = hidx; - node->next = nidx; - if (idx != hidx) - hh_unlock_list(idx, table); - head->next = idx; - if (nidx != hidx) - hh_lock_list(nidx, table); - next->prev = idx; - if (nidx != hidx) - hh_unlock_list(nidx, table); -} - -void hyb_list_add_tail_nolock(int idx, int hidx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = NULL; - struct hyb_list_head *head = NULL; - struct hyb_list_head *tail = NULL; - int tidx; - - node = idx_node(idx, table); - if (!node) { - hybp(HYB_ERR, - "NULL node, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - head = idx_node(hidx, table); - if (!head) { - hybp(HYB_ERR, - "NULL head, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - tail = idx_node(head->prev, table); - if (!tail) { - hybp(HYB_ERR, - "NULL tail, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - - tidx = head->prev; - if (idx != hidx) - hh_lock_list(idx, table); - node->prev = tidx; - node->next = hidx; - if (idx != hidx) - hh_unlock_list(idx, table); - head->prev = idx; - if (tidx != hidx) - hh_lock_list(tidx, table); - tail->next = idx; - if (tidx != hidx) - hh_unlock_list(tidx, table); -} - -void hyb_list_del_nolock(int idx, int hidx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = NULL; - struct hyb_list_head *prev = NULL; - struct hyb_list_head *next = NULL; - int pidx, nidx; - - node = idx_node(idx, table); - if (!node) { - hybp(HYB_ERR, - "NULL node, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - prev = idx_node(node->prev, table); - if (!prev) { - hybp(HYB_ERR, - "NULL prev, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - next = idx_node(node->next, table); - if (!next) { - hybp(HYB_ERR, - "NULL next, idx = %d, hidx = %d, table = %pK\n", - idx, hidx, table); - return; - } - - if (idx != hidx) - hh_lock_list(idx, table); - pidx = node->prev; - nidx = node->next; - node->prev = idx; - node->next = idx; - if (idx != hidx) - hh_unlock_list(idx, table); - if (pidx != hidx) - hh_lock_list(pidx, table); - prev->next = nidx; - if (pidx != hidx) - hh_unlock_list(pidx, table); - if (nidx != hidx) - hh_lock_list(nidx, table); - next->prev = pidx; - if (nidx != hidx) - hh_unlock_list(nidx, table); -} - -void hyb_list_add(int idx, int hidx, struct hyb_list_table *table) -{ - hh_lock_list(hidx, table); - hyb_list_add_nolock(idx, hidx, table); - hh_unlock_list(hidx, table); -} - -void hyb_list_add_tail(int idx, int hidx, struct hyb_list_table *table) -{ - hh_lock_list(hidx, table); - hyb_list_add_tail_nolock(idx, hidx, table); - hh_unlock_list(hidx, table); -} - -void hyb_list_del(int idx, int hidx, struct hyb_list_table *table) -{ - hh_lock_list(hidx, table); - hyb_list_del_nolock(idx, hidx, table); - hh_unlock_list(hidx, table); -} - -unsigned short hyb_list_get_mcgid(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - int mcg_id; - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return 0; - } - - hh_lock_list(idx, table); - mcg_id = (node->mcg_hi << HH_LIST_MCG_SHIFT_HALF) | node->mcg_lo; - hh_unlock_list(idx, table); - - return mcg_id; -} - -void hyb_list_set_mcgid(int idx, struct hyb_list_table *table, int mcg_id) -{ - struct hyb_list_head *node = idx_node(idx, table); - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK, mcg = %d\n", - idx, table, mcg_id); - return; - } - - hh_lock_list(idx, table); - node->mcg_hi = (u32)mcg_id >> HH_LIST_MCG_SHIFT_HALF; - node->mcg_lo = (u32)mcg_id & ((1 << HH_LIST_MCG_SHIFT_HALF) - 1); - hh_unlock_list(idx, table); -} - -bool hyb_list_set_priv(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - bool ret = false; - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return false; - } - hh_lock_list(idx, table); - ret = !test_and_set_bit(HH_LIST_PRIV_BIT, (unsigned long *)node); - hh_unlock_list(idx, table); - - return ret; -} - -bool hyb_list_test_priv(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - bool ret = false; - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return false; - } - hh_lock_list(idx, table); - ret = test_bit(HH_LIST_PRIV_BIT, (unsigned long *)node); - hh_unlock_list(idx, table); - - return ret; -} - -bool hyb_list_clear_priv(int idx, struct hyb_list_table *table) -{ - struct hyb_list_head *node = idx_node(idx, table); - bool ret = false; - - if (!node) { - hybp(HYB_ERR, "idx = %d, table = %pK\n", idx, table); - return false; - } - - hh_lock_list(idx, table); - ret = test_and_clear_bit(HH_LIST_PRIV_BIT, (unsigned long *)node); - hh_unlock_list(idx, table); - - return ret; -} diff --git a/drivers/block/zram/hybridswap/hybridswap_list.h b/drivers/block/zram/hybridswap/hybridswap_list.h deleted file mode 100755 index 5acaf33be47e..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_list.h +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#ifndef _HYBRIDSWAP_LIST_H_ -#define _HYBRIDSWAP_LIST_H_ - -#define HH_LIST_PTR_SHIFT 23 -#define HH_LIST_MCG_SHIFT_HALF 8 -#define HH_LIST_LOCK_BIT HH_LIST_MCG_SHIFT_HALF -#define HH_LIST_PRIV_BIT (HH_LIST_PTR_SHIFT + HH_LIST_MCG_SHIFT_HALF + \ - HH_LIST_MCG_SHIFT_HALF + 1) -struct hyb_list_head { - unsigned int mcg_hi : HH_LIST_MCG_SHIFT_HALF; - unsigned int lock : 1; - unsigned int prev : HH_LIST_PTR_SHIFT; - unsigned int mcg_lo : HH_LIST_MCG_SHIFT_HALF; - unsigned int priv : 1; - unsigned int next : HH_LIST_PTR_SHIFT; -}; -struct hyb_list_table { - struct hyb_list_head *(*get_node)(int, void *); - void *private; -}; -#define idx_node(idx, tab) ((tab)->get_node((idx), (tab)->private)) -#define next_idx(idx, tab) (idx_node((idx), (tab))->next) -#define prev_idx(idx, tab) (idx_node((idx), (tab))->prev) - -#define is_last_idx(idx, hidx, tab) (next_idx(idx, tab) == (hidx)) -#define is_first_idx(idx, hidx, tab) (prev_idx(idx, tab) == (hidx)) - -struct hyb_list_table *alloc_table(struct hyb_list_head *(*get_node)(int, void *), - void *private, gfp_t gfp); -void hh_lock_list(int idx, struct hyb_list_table *table); -void hh_unlock_list(int idx, struct hyb_list_table *table); - -void hyb_list_init(int idx, struct hyb_list_table *table); -void hyb_list_add_nolock(int idx, int hidx, struct hyb_list_table *table); -void hyb_list_add_tail_nolock(int idx, int hidx, struct hyb_list_table *table); -void hyb_list_del_nolock(int idx, int hidx, struct hyb_list_table *table); -void hyb_list_add(int idx, int hidx, struct hyb_list_table *table); -void hyb_list_add_tail(int idx, int hidx, struct hyb_list_table *table); -void hyb_list_del(int idx, int hidx, struct hyb_list_table *table); - -unsigned short hyb_list_get_mcgid(int idx, struct hyb_list_table *table); -void hyb_list_set_mcgid(int idx, struct hyb_list_table *table, int mcg_id); -bool hyb_list_set_priv(int idx, struct hyb_list_table *table); -bool hyb_list_clear_priv(int idx, struct hyb_list_table *table); -bool hyb_list_test_priv(int idx, struct hyb_list_table *table); - -bool hyb_list_empty(int hidx, struct hyb_list_table *table); - -#define hyb_list_for_each_entry(idx, hidx, tab) \ - for ((idx) = next_idx((hidx), (tab)); \ - (idx) != (hidx); (idx) = next_idx((idx), (tab))) -#define hyb_list_for_each_entry_safe(idx, tmp, hidx, tab) \ - for ((idx) = next_idx((hidx), (tab)), (tmp) = next_idx((idx), (tab)); \ - (idx) != (hidx); (idx) = (tmp), (tmp) = next_idx((idx), (tab))) -#define hyb_list_for_each_entry_reverse(idx, hidx, tab) \ - for ((idx) = prev_idx((hidx), (tab)); \ - (idx) != (hidx); (idx) = prev_idx((idx), (tab))) -#define hyb_list_for_each_entry_reverse_safe(idx, tmp, hidx, tab) \ - for ((idx) = prev_idx((hidx), (tab)), (tmp) = prev_idx((idx), (tab)); \ - (idx) != (hidx); (idx) = (tmp), (tmp) = prev_idx((idx), (tab))) - -#endif /* _HYBRIDSWAP_LIST_H_ */ diff --git a/drivers/block/zram/hybridswap/hybridswap_lru_rmap.c b/drivers/block/zram/hybridswap/hybridswap_lru_rmap.c deleted file mode 100755 index 25ce701ef762..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_lru_rmap.c +++ /dev/null @@ -1,293 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap.h" -#include "hybridswap_internal.h" - -#include "hybridswap_list.h" -#include "hybridswap_area.h" -#include "hybridswap_lru_rmap.h" - -#define esentry_extid(e) ((e) >> EXTENT_SHIFT) - -void zram_set_memcg(struct zram *zram, u32 index, int mcg_id) -{ - hyb_list_set_mcgid(obj_idx(zram->area, index), - zram->area->obj_table, mcg_id); -} - -struct mem_cgroup *zram_get_memcg(struct zram *zram, u32 index) -{ - unsigned short mcg_id; - - mcg_id = hyb_list_get_mcgid(obj_idx(zram->area, index), - zram->area->obj_table); - - return get_mem_cgroup(mcg_id); -} - -int zram_get_memcg_coldest_index(struct hybridswap_area *area, - struct mem_cgroup *mcg, - int *index, int max_cnt) -{ - int cnt = 0; - u32 i, tmp; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return 0; - } - if (!area->obj_table) { - hybp(HYB_ERR, "NULL table\n"); - return 0; - } - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return 0; - } - if (!index) { - hybp(HYB_ERR, "NULL index\n"); - return 0; - } - - hh_lock_list(mcg_idx(area, mcg->id.id), area->obj_table); - hyb_list_for_each_entry_reverse_safe(i, tmp, - mcg_idx(area, mcg->id.id), area->obj_table) { - if (i >= (u32)area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", i); - continue; - } - index[cnt++] = i; - if (cnt >= max_cnt) - break; - } - hh_unlock_list(mcg_idx(area, mcg->id.id), area->obj_table); - - return cnt; -} - -int zram_rmap_get_extent_index(struct hybridswap_area *area, - int ext_id, int *index) -{ - int cnt = 0; - u32 i; - - if (!area) { - hybp(HYB_ERR, "NULL area\n"); - return 0; - } - if (!area->obj_table) { - hybp(HYB_ERR, "NULL table\n"); - return 0; - } - if (!index) { - hybp(HYB_ERR, "NULL index\n"); - return 0; - } - if (ext_id < 0 || ext_id >= area->nr_exts) { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - return 0; - } - - hh_lock_list(ext_idx(area, ext_id), area->obj_table); - hyb_list_for_each_entry(i, ext_idx(area, ext_id), area->obj_table) { - if (cnt >= (int)EXTENT_MAX_OBJ_CNT) { - WARN_ON_ONCE(1); - break; - } - index[cnt++] = i; - } - hh_unlock_list(ext_idx(area, ext_id), area->obj_table); - - return cnt; -} - -void zram_lru_add(struct zram *zram, u32 index, struct mem_cgroup *memcg) -{ - unsigned long size; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - if (zram_test_flag(zram, index, ZRAM_WB)) { - hybp(HYB_ERR, "WB object, index = %d\n", index); - return; - } -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if (zram_test_flag(zram, index, ZRAM_CACHED)) { - hybp(HYB_ERR, "CACHED object, index = %d\n", index); - return; - } - if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - hybp(HYB_ERR, "CACHED_COMPRESS object, index = %d\n", index); - return; - } -#endif - if (zram_test_flag(zram, index, ZRAM_SAME)) - return; - - zram_set_memcg(zram, index, memcg->id.id); - hyb_list_add(obj_idx(zram->area, index), - mcg_idx(zram->area, memcg->id.id), - zram->area->obj_table); - - size = zram_get_obj_size(zram, index); - - atomic64_add(size, &MEMCGRP_ITEM(memcg, zram_stored_size)); - atomic64_inc(&MEMCGRP_ITEM(memcg, zram_page_size)); - atomic64_add(size, &stat->zram_stored_size); - atomic64_inc(&stat->zram_stored_pages); -} - -void zram_lru_add_tail(struct zram *zram, u32 index, struct mem_cgroup *mcg) -{ - unsigned long size; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (!mcg || !MEMCGRP_ITEM(mcg, zram) || !MEMCGRP_ITEM(mcg, zram)->area) { - hybp(HYB_ERR, "invalid mcg\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - if (zram_test_flag(zram, index, ZRAM_WB)) { - hybp(HYB_ERR, "WB object, index = %d\n", index); - return; - } -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if (zram_test_flag(zram, index, ZRAM_CACHED)) { - hybp(HYB_ERR, "CACHED object, index = %d\n", index); - return; - } - if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - hybp(HYB_ERR, "CACHED_COMPRESS object, index = %d\n", index); - return; - } -#endif - if (zram_test_flag(zram, index, ZRAM_SAME)) - return; - - zram_set_memcg(zram, index, mcg->id.id); - hyb_list_add_tail(obj_idx(zram->area, index), - mcg_idx(zram->area, mcg->id.id), - zram->area->obj_table); - - size = zram_get_obj_size(zram, index); - - atomic64_add(size, &MEMCGRP_ITEM(mcg, zram_stored_size)); - atomic64_inc(&MEMCGRP_ITEM(mcg, zram_page_size)); - atomic64_add(size, &stat->zram_stored_size); - atomic64_inc(&stat->zram_stored_pages); -} - -void zram_lru_del(struct zram *zram, u32 index) -{ - struct mem_cgroup *mcg = NULL; - unsigned long size; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram || !zram->area) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - if (zram_test_flag(zram, index, ZRAM_WB)) { - hybp(HYB_ERR, "WB object, index = %d\n", index); - return; - } - - mcg = zram_get_memcg(zram, index); - if (!mcg || !MEMCGRP_ITEM(mcg, zram) || !MEMCGRP_ITEM(mcg, zram)->area) - return; - if (zram_test_flag(zram, index, ZRAM_SAME)) - return; - - size = zram_get_obj_size(zram, index); - hyb_list_del(obj_idx(zram->area, index), - mcg_idx(zram->area, mcg->id.id), - zram->area->obj_table); - zram_set_memcg(zram, index, 0); - - atomic64_sub(size, &MEMCGRP_ITEM(mcg, zram_stored_size)); - atomic64_dec(&MEMCGRP_ITEM(mcg, zram_page_size)); - atomic64_sub(size, &stat->zram_stored_size); - atomic64_dec(&stat->zram_stored_pages); -} - -void zram_rmap_insert(struct zram *zram, u32 index) -{ - unsigned long eswpentry; - u32 ext_id; - - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - - eswpentry = zram_get_handle(zram, index); - ext_id = esentry_extid(eswpentry); - hyb_list_add_tail(obj_idx(zram->area, index), - ext_idx(zram->area, ext_id), - zram->area->obj_table); -} - -void zram_rmap_erase(struct zram *zram, u32 index) -{ - unsigned long eswpentry; - u32 ext_id; - - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - - eswpentry = zram_get_handle(zram, index); - ext_id = esentry_extid(eswpentry); - hyb_list_del(obj_idx(zram->area, index), - ext_idx(zram->area, ext_id), - zram->area->obj_table); -} diff --git a/drivers/block/zram/hybridswap/hybridswap_lru_rmap.h b/drivers/block/zram/hybridswap/hybridswap_lru_rmap.h deleted file mode 100755 index 764230bb1ef3..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_lru_rmap.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#ifndef _HYBRIDSWAP_LRU_MAP_ -#define _HYBRIDSWAP_LRU_MAP_ - -void zram_set_memcg(struct zram *zram, u32 index, int mcg_id); -struct mem_cgroup *zram_get_memcg(struct zram *zram, u32 index); -int zram_get_memcg_coldest_index(struct hybridswap_area *area, - struct mem_cgroup *mcg, - int *index, int max_cnt); -int zram_rmap_get_extent_index(struct hybridswap_area *area, - int ext_id, int *index); -void zram_lru_add(struct zram *zram, u32 index, struct mem_cgroup *memcg); -void zram_lru_add_tail(struct zram *zram, u32 index, struct mem_cgroup *mcg); -void zram_lru_del(struct zram *zram, u32 index); -void zram_rmap_insert(struct zram *zram, u32 index); -void zram_rmap_erase(struct zram *zram, u32 index); - -#endif /* _HYBRIDSWAP_LRU_MAP_ */ diff --git a/drivers/block/zram/hybridswap/hybridswap_main.c b/drivers/block/zram/hybridswap/hybridswap_main.c deleted file mode 100755 index c022099706fd..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_main.c +++ /dev/null @@ -1,1035 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_internal.h" -#include "hybridswap.h" - -static const char *swapd_text[NR_EVENT_ITEMS] = { -#ifdef CONFIG_HYBRIDSWAP_SWAPD - "swapd_wakeup", - "swapd_hit_refaults", - "swapd_medium_press", - "swapd_critical_press", - "swapd_memcg_ratio_skip", - "swapd_memcg_refault_skip", - "swapd_shrink_anon", - "swapd_swapout", - "swapd_skip_swapout", - "swapd_empty_round", - "swapd_over_min_buffer_skip_times", - "swapd_empty_round_skip_times", - "swapd_snapshot_times", - "swapd_skip_shrink_of_window", - "swapd_manual_pause", -#ifdef CONFIG_OPLUS_JANK - "swapd_cpu_busy_skip_times", - "swapd_cpu_busy_break_times", -#endif -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - "akcompressd_running", -#endif -}; - -enum scan_balance { - SCAN_EQUAL, - SCAN_FRACT, - SCAN_ANON, - SCAN_FILE, -}; - -static int log_level = HYB_MAX; -static struct kmem_cache *hybridswap_cache; -static struct list_head score_head; -static DEFINE_SPINLOCK(score_list_lock); -static DEFINE_MUTEX(hybridswap_enable_lock); -static bool hybridswap_enabled = false; - -DEFINE_MUTEX(reclaim_para_lock); -DEFINE_PER_CPU(struct swapd_event_state, swapd_event_states); - -extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, - unsigned long nr_pages, - gfp_t gfp_mask, - bool may_swap); - - -void hybridswap_loglevel_set(int level) -{ - log_level = level; -} - -int hybridswap_loglevel(void) -{ - return log_level; -} - -void __put_memcg_cache(memcg_hybs_t *hybs) -{ -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if (hybs->cache.id > 0) { - spin_lock(&cached_idr_lock); - idr_replace(&cached_idr, NULL, hybs->cache.id); - idr_remove(&cached_idr, hybs->cache.id); - spin_unlock(&cached_idr_lock); - } - - spin_lock(&hybs->cache.lock); - if (hybs->cache.dead != 1) - BUG(); - spin_unlock(&hybs->cache.lock); -#endif - kmem_cache_free(hybridswap_cache, (void *)hybs); -} - -static inline void sum_hybridswap_vm_events(unsigned long *ret) -{ - int cpu; - int i; - - memset(ret, 0, NR_EVENT_ITEMS * sizeof(unsigned long)); - - for_each_online_cpu(cpu) { - struct swapd_event_state *this = - &per_cpu(swapd_event_states, cpu); - - for (i = 0; i < NR_EVENT_ITEMS; i++) - ret[i] += this->event[i]; - } -} - -static inline void all_hybridswap_vm_events(unsigned long *ret) -{ - get_online_cpus(); - sum_hybridswap_vm_events(ret); - put_online_cpus(); -} - -ssize_t hybridswap_vmstat_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - unsigned long *vm_buf = NULL; - int len = 0; - int i = 0; - - vm_buf = kzalloc(sizeof(struct swapd_event_state), GFP_KERNEL); - if (!vm_buf) - return -ENOMEM; - all_hybridswap_vm_events(vm_buf); - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n", - "fault_out_pause", atomic_long_read(&fault_out_pause)); - len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n", - "fault_out_pause_cnt", atomic_long_read(&fault_out_pause_cnt)); -#endif - - for (;i < NR_EVENT_ITEMS; i++) { - len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n", - swapd_text[i], vm_buf[i]); - if (len == PAGE_SIZE) - break; - } - kfree(vm_buf); - - return len; -} - -ssize_t hybridswap_loglevel_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - char *type_buf = NULL; - unsigned long val; - - type_buf = strstrip((char *)buf); - if (kstrtoul(type_buf, 0, &val)) - return -EINVAL; - - if (val >= HYB_MAX) { - hybp(HYB_ERR, "val %lu is not valid\n", val); - return -EINVAL; - } - hybridswap_loglevel_set((int)val); - - return len; -} - -ssize_t hybridswap_loglevel_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - ssize_t size = 0; - - size += scnprintf(buf + size, PAGE_SIZE - size, - "Hybridswap log level: %d\n", hybridswap_loglevel()); - - return size; -} - -/* Make sure the memcg is not NULL in caller */ -memcg_hybs_t *hybridswap_cache_alloc(struct mem_cgroup *memcg, bool atomic) -{ - memcg_hybs_t *hybs; - u64 ret; - gfp_t flags = GFP_KERNEL; - - if (memcg->android_oem_data1) - BUG(); - - if (atomic) - flags &= ~__GFP_DIRECT_RECLAIM; - - hybs = (memcg_hybs_t *)kmem_cache_zalloc(hybridswap_cache, flags); - if (!hybs) - return NULL; - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - spin_lock_init(&hybs->cache.lock); - INIT_LIST_HEAD(&hybs->cache.head); - hybs->cache.cnt = 0; - hybs->cache.compressing = 0; - hybs->cache.dead = 0; - spin_lock(&cached_idr_lock); - hybs->cache.id = idr_alloc(&cached_idr, NULL, 1, MEM_CGROUP_ID_MAX, - GFP_KERNEL); - if (hybs->cache.id < 0) { - spin_unlock(&cached_idr_lock); - kmem_cache_free(hybridswap_cache, (void*)hybs); - return NULL; - } - idr_replace(&cached_idr, &hybs->cache, hybs->cache.id); - spin_unlock(&cached_idr_lock); -#endif - INIT_LIST_HEAD(&hybs->score_node); -#ifdef CONFIG_HYBRIDSWAP_CORE - spin_lock_init(&hybs->zram_init_lock); -#endif - atomic64_set(&hybs->app_score, 300); - atomic64_set(&hybs->ub_ufs2zram_ratio, 100); -#ifdef CONFIG_HYBRIDSWAP_SWAPD - atomic_set(&hybs->ub_mem2zram_ratio, 80); - atomic_set(&hybs->ub_zram2ufs_ratio, 50); - atomic_set(&hybs->refault_threshold, 50); -#endif - hybs->memcg = memcg; - refcount_set(&hybs->usage, 1); - - ret = atomic64_cmpxchg((atomic64_t *)&memcg->android_oem_data1, 0, (u64)hybs); - if (ret != 0) { -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - hybs->cache.dead = 1; -#endif - put_memcg_cache(hybs); - return (memcg_hybs_t *)ret; - } - - return hybs; -} - -#ifdef CONFIG_HYBRIDSWAP_SWAPD -static void tune_scan_type_hook(void *data, char *scan_balance) -{ - /*hybrid swapd,scan anon only*/ - if (current_is_swapd()) { - *scan_balance = SCAN_ANON; - return; - } - -#ifdef CONFIG_HYBRIDSWAP_CORE - if (unlikely(!hybridswap_core_enabled())) - return; - - /*real zram full, scan file only*/ - if (!free_zram_is_ok()) { - *scan_balance = SCAN_FILE; - return; - } -#endif -} -#endif - -static void mem_cgroup_alloc_hook(void *data, struct mem_cgroup *memcg) -{ - if (memcg->android_oem_data1) - BUG(); - - hybridswap_cache_alloc(memcg, true); -} - -static void mem_cgroup_free_hook(void *data, struct mem_cgroup *memcg) -{ - memcg_hybs_t *hybs; - - if (!memcg->android_oem_data1) - return; - - hybs = (memcg_hybs_t *)memcg->android_oem_data1; - memcg->android_oem_data1 = 0; -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - clear_page_memcg(&hybs->cache); -#endif - put_memcg_cache(hybs); -} - -void memcg_app_score_update(struct mem_cgroup *target) -{ - struct list_head *pos = NULL; - unsigned long flags; - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - update_swapd_memcg_param(target); -#endif - spin_lock_irqsave(&score_list_lock, flags); - list_for_each(pos, &score_head) { - memcg_hybs_t *hybs = list_entry(pos, memcg_hybs_t, score_node); - if (atomic64_read(&hybs->app_score) < - atomic64_read(&MEMCGRP_ITEM(target, app_score))) - break; - } - list_move_tail(&MEMCGRP_ITEM(target, score_node), pos); - spin_unlock_irqrestore(&score_list_lock, flags); -} - -static void mem_cgroup_css_online_hook(void *data, - struct cgroup_subsys_state *css, struct mem_cgroup *memcg) -{ - if (memcg->android_oem_data1) - memcg_app_score_update(memcg); - - css_get(css); -} - -static void mem_cgroup_css_offline_hook(void *data, - struct cgroup_subsys_state *css, struct mem_cgroup *memcg) -{ - unsigned long flags; - - if (memcg->android_oem_data1) { - spin_lock_irqsave(&score_list_lock, flags); - list_del_init(&MEMCGRP_ITEM(memcg, score_node)); - spin_unlock_irqrestore(&score_list_lock, flags); - } - - css_put(css); -} - -#define REGISTER_HOOK(name) do {\ - rc = register_trace_android_vh_##name(name##_hook, NULL);\ - if (rc) {\ - hybp(HYB_ERR, "%s:%d register hook %s failed", __FILE__, __LINE__, #name);\ - goto err_out_##name;\ - }\ -} while (0) - -#define UNREGISTER_HOOK(name) do {\ - unregister_trace_android_vh_##name(name##_hook, NULL);\ -} while (0) - -#define ERROR_OUT(name) err_out_##name - -static int register_all_hooks(void) -{ - int rc; - - /* mem_cgroup_alloc_hook */ - REGISTER_HOOK(mem_cgroup_alloc); - /* mem_cgroup_free_hook */ - REGISTER_HOOK(mem_cgroup_free); - /* mem_cgroup_css_online_hook */ - REGISTER_HOOK(mem_cgroup_css_online); - /* mem_cgroup_css_offline_hook */ - REGISTER_HOOK(mem_cgroup_css_offline); -#ifdef CONFIG_HYBRIDSWAP_SWAPD - /* rmqueue_hook */ - REGISTER_HOOK(rmqueue); - /* tune_scan_type_hook */ - REGISTER_HOOK(tune_scan_type); -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE - /* mem_cgroup_id_remove_hook */ - REGISTER_HOOK(mem_cgroup_id_remove); -#endif - return 0; - -#ifdef CONFIG_HYBRIDSWAP_CORE - UNREGISTER_HOOK(mem_cgroup_id_remove); -ERROR_OUT(mem_cgroup_id_remove): -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD - UNREGISTER_HOOK(tune_scan_type); -ERROR_OUT(tune_scan_type): - UNREGISTER_HOOK(rmqueue); -ERROR_OUT(rmqueue): -#endif - UNREGISTER_HOOK(mem_cgroup_css_offline); -ERROR_OUT(mem_cgroup_css_offline): - UNREGISTER_HOOK(mem_cgroup_css_online); -ERROR_OUT(mem_cgroup_css_online): - UNREGISTER_HOOK(mem_cgroup_free); -ERROR_OUT(mem_cgroup_free): - UNREGISTER_HOOK(mem_cgroup_alloc); -ERROR_OUT(mem_cgroup_alloc): - return rc; -} - -static void unregister_all_hook(void) -{ - UNREGISTER_HOOK(mem_cgroup_alloc); - UNREGISTER_HOOK(mem_cgroup_free); - UNREGISTER_HOOK(mem_cgroup_css_offline); - UNREGISTER_HOOK(mem_cgroup_css_online); -#ifdef CONFIG_HYBRIDSWAP_CORE - UNREGISTER_HOOK(mem_cgroup_id_remove); -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD - UNREGISTER_HOOK(rmqueue); - UNREGISTER_HOOK(tune_scan_type); -#endif -} - -unsigned long memcg_anon_pages(struct mem_cgroup *memcg) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) - struct lruvec *lruvec = NULL; - struct mem_cgroup_per_node *mz = NULL; -#endif - if (!memcg) - return 0; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) - mz = mem_cgroup_nodeinfo(memcg, 0); - if (!mz) { - get_next_memcg_break(memcg); - return 0; - } - - lruvec = &mz->lruvec; - if (!lruvec) { - get_next_memcg_break(memcg); - return 0; - } - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - return (mem_cgroup_get_lru_size(lruvec, LRU_ACTIVE_ANON) + - mem_cgroup_get_lru_size(lruvec, LRU_INACTIVE_ANON)); -#else - return (lruvec_page_state(lruvec, NR_ACTIVE_ANON) + - lruvec_page_state(lruvec, NR_INACTIVE_ANON)); -#endif -#else - return (memcg_page_state_local(memcg, NR_ACTIVE_ANON) + - memcg_page_state_local(memcg, NR_INACTIVE_ANON)); -#endif -} - -static unsigned long memcg_inactive_anon_pages(struct mem_cgroup *memcg) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) - struct lruvec *lruvec = NULL; - struct mem_cgroup_per_node *mz = NULL; -#endif - - if (!memcg) - return 0; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) - mz = mem_cgroup_nodeinfo(memcg, 0); - if (!mz) { - get_next_memcg_break(memcg); - return 0; - } - - lruvec = &mz->lruvec; - if (!lruvec) { - get_next_memcg_break(memcg); - return 0; - } - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - return mem_cgroup_get_lru_size(lruvec, LRU_INACTIVE_ANON); -#else - return lruvec_page_state(lruvec, NR_INACTIVE_ANON); -#endif -#else - return memcg_page_state_local(memcg, NR_INACTIVE_ANON); -#endif -} - -static ssize_t mem_cgroup_force_shrink_anon(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - struct mem_cgroup *memcg; - unsigned long nr_need_reclaim, reclaim_total, nr_reclaimed; - int ret; - - buf = strstrip(buf); - ret = kstrtoul(buf, 0, &reclaim_total); - if (unlikely(ret)) { - hybp(HYB_ERR, "reclaim_total %s value is error!\n", buf); - return -EINVAL; - } - - memcg = mem_cgroup_from_css(of_css(of)); - - if (reclaim_total) - nr_need_reclaim = memcg_anon_pages(memcg); - else - nr_need_reclaim = memcg_inactive_anon_pages(memcg); - - nr_reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_need_reclaim, - GFP_KERNEL, true); - - return nbytes; -} - -static int memcg_total_info_per_app_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = NULL; - unsigned long anon_size; - unsigned long zram_compress_size; - unsigned long eswap_compress_size; - unsigned long zram_page_size; - unsigned long eswap_page_size; - - seq_printf(m, "%-8s %-8s %-8s %-8s %-8s %s \n", - "anon", "zram_c", "zram_p", "eswap_c", "eswap_p", - "memcg_n"); - while ((memcg = get_next_memcg(memcg))) { - if (!MEMCGRP_ITEM_DATA(memcg)) - continue; - - anon_size = memcg_anon_pages(memcg); - zram_compress_size = hybridswap_read_mcg_stats(memcg, - MCG_ZRAM_STORED_SZ); - eswap_compress_size = hybridswap_read_mcg_stats(memcg, - MCG_DISK_STORED_SZ); - zram_page_size = hybridswap_read_mcg_stats(memcg, - MCG_ZRAM_STORED_PG_SZ); - eswap_page_size = hybridswap_read_mcg_stats(memcg, - MCG_DISK_STORED_PG_SZ); - - anon_size *= PAGE_SIZE / SZ_1K; - zram_compress_size /= SZ_1K; - eswap_compress_size /= SZ_1K; - zram_page_size *= PAGE_SIZE / SZ_1K; - eswap_page_size *= PAGE_SIZE / SZ_1K; - - seq_printf(m, "%-8lu %-8lu %-8lu %-8lu %-8lu %s \n", - anon_size, zram_compress_size, zram_page_size, - eswap_compress_size, eswap_page_size, - MEMCGRP_ITEM(memcg, name)); - } - - return 0; -} - -static int memcg_swap_stat_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = NULL; - unsigned long eswap_out_cnt; - unsigned long eswap_out_size; - unsigned long eswap_in_size; - unsigned long eswap_in_cnt; - unsigned long page_fault_cnt; - unsigned long cur_eswap_size; - unsigned long max_eswap_size; - unsigned long zram_compress_size, zram_page_size; - unsigned long eswap_compress_size, eswap_page_size; - - memcg = mem_cgroup_from_css(seq_css(m)); - - zram_compress_size = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_SZ); - zram_page_size = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ); - eswap_compress_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_SZ); - eswap_page_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ); - - eswap_out_cnt = hybridswap_read_mcg_stats(memcg, MCG_ESWAPOUT_CNT); - eswap_out_size = hybridswap_read_mcg_stats(memcg, MCG_ESWAPOUT_SZ); - eswap_in_size = hybridswap_read_mcg_stats(memcg, MCG_ESWAPIN_SZ); - eswap_in_cnt = hybridswap_read_mcg_stats(memcg, MCG_ESWAPIN_CNT); - page_fault_cnt = hybridswap_read_mcg_stats(memcg, MCG_DISK_FAULT_CNT); - cur_eswap_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_SPACE); - max_eswap_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_SPACE_PEAK); - - seq_printf(m, "%-32s %12lu KB\n", "zramCompressedSize:", - zram_compress_size / SZ_1K); - seq_printf(m, "%-32s %12lu KB\n", "zramOrignalSize:", - zram_page_size << (PAGE_SHIFT - 10)); - seq_printf(m, "%-32s %12lu KB\n", "eswapCompressedSize:", - eswap_compress_size / SZ_1K); - seq_printf(m, "%-32s %12lu KB\n", "eswapOrignalSize:", - eswap_page_size << (PAGE_SHIFT - 10)); - seq_printf(m, "%-32s %12lu \n", "eswapOutTotal:", eswap_out_cnt); - seq_printf(m, "%-32s %12lu KB\n", "eswapOutSize:", eswap_out_size / SZ_1K); - seq_printf(m, "%-32s %12lu\n", "eswapInTotal:", eswap_in_cnt); - seq_printf(m, "%-32s %12lu KB\n", "eswapInSize:", eswap_in_size / SZ_1K); - seq_printf(m, "%-32s %12lu\n", "pageInTotal:", page_fault_cnt); - seq_printf(m, "%-32s %12lu KB\n", "eswapSizeCur:", cur_eswap_size / SZ_1K); - seq_printf(m, "%-32s %12lu KB\n", "eswapSizeMax:", max_eswap_size / SZ_1K); - - return 0; -} - -static ssize_t mem_cgroup_name_write(struct kernfs_open_file *of, char *buf, - size_t nbytes, loff_t off) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); - memcg_hybs_t *hybp = MEMCGRP_ITEM_DATA(memcg); - int len, w_len; - - if (!hybp) - return -EINVAL; - - buf = strstrip(buf); - len = strlen(buf) + 1; - if (len > MEM_CGROUP_NAME_MAX_LEN) - len = MEM_CGROUP_NAME_MAX_LEN; - - w_len = snprintf(hybp->name, len, "%s", buf); - if (w_len > len) - hybp->name[len - 1] = '\0'; - - return nbytes; -} - -static int mem_cgroup_name_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); - - if (!MEMCGRP_ITEM_DATA(memcg)) - return -EPERM; - - seq_printf(m, "%s\n", MEMCGRP_ITEM(memcg, name)); - - return 0; -} - -static int mem_cgroup_app_score_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - struct mem_cgroup *memcg; - memcg_hybs_t *hybs; - - if (val > MAX_APP_SCORE || val < 0) - return -EINVAL; - - memcg = mem_cgroup_from_css(css); - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs) { - hybs = hybridswap_cache_alloc(memcg, false); - if (!hybs) - return -EINVAL; - } - - if (atomic64_read(&MEMCGRP_ITEM(memcg, app_score)) != val) - atomic64_set(&MEMCGRP_ITEM(memcg, app_score), val); - memcg_app_score_update(memcg); - - return 0; -} - -static s64 mem_cgroup_app_score_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(css); - - if (!MEMCGRP_ITEM_DATA(memcg)) - return -EPERM; - - return atomic64_read(&MEMCGRP_ITEM(memcg, app_score)); -} - -int mem_cgroup_app_uid_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - struct mem_cgroup *memcg; - memcg_hybs_t *hybs; - - if (val < 0) - return -EINVAL; - - memcg = mem_cgroup_from_css(css); - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs) { - return -EINVAL; - } - - if (atomic64_read(&MEMCGRP_ITEM(memcg, app_uid)) != val) - atomic64_set(&MEMCGRP_ITEM(memcg, app_uid), val); - - return 0; -} - -static s64 mem_cgroup_app_uid_read(struct cgroup_subsys_state *css, struct cftype *cft) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(css); - - if (!MEMCGRP_ITEM_DATA(memcg)) - return -EPERM; - - return atomic64_read(&MEMCGRP_ITEM(memcg, app_uid)); -} - -static int mem_cgroup_ub_ufs2zram_ratio_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(css); - - if (!MEMCGRP_ITEM_DATA(memcg)) - return -EPERM; - - if (val > MAX_RATIO || val < MIN_RATIO) - return -EINVAL; - - atomic64_set(&MEMCGRP_ITEM(memcg, ub_ufs2zram_ratio), val); - - return 0; -} - -static s64 mem_cgroup_ub_ufs2zram_ratio_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(css); - - if (!MEMCGRP_ITEM_DATA(memcg)) - return -EPERM; - - return atomic64_read(&MEMCGRP_ITEM(memcg, ub_ufs2zram_ratio)); -} - -static int mem_cgroup_force_swapin_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(css); - memcg_hybs_t *hybs; - unsigned long size = 0; - const unsigned int ratio = 100; - - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs) - return -EPERM; - -#ifdef CONFIG_HYBRIDSWAP_CORE - size = atomic64_read(&hybs->hybridswap_stored_size); -#endif - size = atomic64_read(&hybs->ub_ufs2zram_ratio) * size / ratio; - size = EXTENT_ALIGN_UP(size); - -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_batch_out(memcg, size, val ? true : false); -#endif - - return 0; -} - -static int mem_cgroup_force_swapout_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_force_reclaim(mem_cgroup_from_css(css)); -#endif - return 0; -} - -struct mem_cgroup *get_next_memcg(struct mem_cgroup *prev) -{ - memcg_hybs_t *hybs = NULL; - struct mem_cgroup *memcg = NULL; - struct list_head *pos = NULL; - unsigned long flags; - bool prev_got = true; - - spin_lock_irqsave(&score_list_lock, flags); -find_again: - if (unlikely(!prev)) - pos = &score_head; - else - pos = &MEMCGRP_ITEM(prev, score_node); - - if (list_empty(pos)) /* deleted node */ - goto unlock; - - if (pos->next == &score_head) - goto unlock; - - hybs = list_entry(pos->next, struct mem_cgroup_hybridswap, score_node); - memcg = hybs->memcg; - if (unlikely(!memcg)) - goto unlock; - - if (!css_tryget(&memcg->css)) { - if (prev && prev_got) - css_put(&prev->css); - prev = memcg; - prev_got = false; - goto find_again; - } - -unlock: - spin_unlock_irqrestore(&score_list_lock, flags); - if (prev && prev_got) - css_put(&prev->css); - - return memcg; -} - -void get_next_memcg_break(struct mem_cgroup *memcg) -{ - if (memcg) - css_put(&memcg->css); -} - -static struct cftype mem_cgroup_hybridswap_legacy_files[] = { - { - .name = "force_shrink_anon", - .write = mem_cgroup_force_shrink_anon, - }, - { - .name = "total_info_per_app", - .flags = CFTYPE_ONLY_ON_ROOT, - .seq_show = memcg_total_info_per_app_show, - }, - { - .name = "swap_stat", - .seq_show = memcg_swap_stat_show, - }, - { - .name = "name", - .write = mem_cgroup_name_write, - .seq_show = mem_cgroup_name_show, - }, - { - .name = "app_score", - .flags = CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_app_score_write, - .read_s64 = mem_cgroup_app_score_read, - }, - { - .name = "app_uid", - .flags = CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_app_uid_write, - .read_s64 = mem_cgroup_app_uid_read, - }, - { - .name = "ub_ufs2zram_ratio", - .flags = CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_ub_ufs2zram_ratio_write, - .read_s64 = mem_cgroup_ub_ufs2zram_ratio_read, - }, - { - .name = "force_swapin", - .write_s64 = mem_cgroup_force_swapin_write, - }, - { - .name = "force_swapout", - .write_s64 = mem_cgroup_force_swapout_write, - }, -#ifdef CONFIG_HYBRIDSWAP_CORE - { - .name = "psi", - .flags = CFTYPE_ONLY_ON_ROOT, - .seq_show = hybridswap_psi_show, - }, - { - .name = "stored_wm_ratio", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_stored_wm_ratio_write, - .read_s64 = mem_cgroup_stored_wm_ratio_read, - }, -#endif - { }, /* terminate */ -}; - -static int hybridswap_enable(struct zram *zram) -{ - int ret = 0; - - if (hybridswap_enabled) { - hybp(HYB_WARN, "hybridswap_enabled is true\n"); - return ret; - } - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - ret = swapd_init(zram); - if (ret) - return ret; -#endif - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - ret = create_akcompressd_task(zram); - if (ret) - goto create_akcompressd_task_fail; -#endif - -#ifdef CONFIG_HYBRIDSWAP_CORE - ret = hybridswap_core_enable(); - if (ret) - goto hybridswap_core_enable_fail; -#endif - hybridswap_enabled = true; - - return 0; - -#ifdef CONFIG_HYBRIDSWAP_CORE -hybridswap_core_enable_fail: -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - destroy_akcompressd_task(zram); -create_akcompressd_task_fail: -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD - swapd_exit(); -#endif - return ret; -} - -static void hybridswap_disable(struct zram * zram) -{ - if (!hybridswap_enabled) { - hybp(HYB_WARN, "hybridswap_enabled is false\n"); - return; - } - -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_core_disable(); -#endif - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - destroy_akcompressd_task(zram); -#endif - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - swapd_exit(); -#endif - hybridswap_enabled = false; -} - -ssize_t hybridswap_enable_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len = snprintf(buf, PAGE_SIZE, "hybridswap %s reclaim_in %s swapd %s\n", - hybridswap_core_enabled() ? "enable" : "disable", - hybridswap_reclaim_in_enable() ? "enable" : "disable", - hybridswap_swapd_enabled() ? "enable" : "disable"); - - return len; -} - -ssize_t hybridswap_enable_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - int ret; - unsigned long val; - char *kbuf; - struct zram *zram; - - kbuf = strstrip((char *)buf); - ret = kstrtoul(kbuf, 0, &val); - if (unlikely(ret)) { - hybp(HYB_ERR, "val %s is invalid!\n", kbuf); - - return -EINVAL; - } - - mutex_lock(&hybridswap_enable_lock); - zram = dev_to_zram(dev); - if (val == 0) - hybridswap_disable(zram); - else - ret = hybridswap_enable(zram); - mutex_unlock(&hybridswap_enable_lock); - - if (ret == 0) - ret = len; - return ret; -} - -int __init hybridswap_pre_init(void) -{ - int ret; - - INIT_LIST_HEAD(&score_head); - log_level = HYB_INFO; - - hybridswap_cache = kmem_cache_create("mem_cgroup_hybridswap", - sizeof(struct mem_cgroup_hybridswap), - 0, SLAB_PANIC, NULL); - if (!hybridswap_cache) { - hybp(HYB_ERR, "create hybridswap_cache failed\n"); - ret = -ENOMEM; - return ret; - } - - ret = cgroup_add_legacy_cftypes(&memory_cgrp_subsys, - mem_cgroup_hybridswap_legacy_files); - if (ret) { - hybp(HYB_INFO, "add mem_cgroup_hybridswap_legacy_files failed\n"); - goto error_out; - } - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - ret = cgroup_add_legacy_cftypes(&memory_cgrp_subsys, - mem_cgroup_swapd_legacy_files); - if (ret) { - hybp(HYB_INFO, "add mem_cgroup_swapd_legacy_files failed!\n"); - goto error_out; - } -#endif - -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - akcompressd_pre_init(); -#endif - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - swapd_pre_init(); -#endif - ret = register_all_hooks(); - if (ret) - goto fail_out; - - hybp(HYB_INFO, "hybridswap inited success!\n"); - return 0; - -fail_out: -#ifdef CONFIG_HYBRIDSWAP_SWAPD - swapd_pre_deinit(); -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - akcompressd_pre_deinit(); -#endif -error_out: - if (hybridswap_cache) { - kmem_cache_destroy(hybridswap_cache); - hybridswap_cache = NULL; - } - return ret; -} - -void __exit hybridswap_exit(void) -{ - unregister_all_hook(); - -#ifdef CONFIG_HYBRIDSWAP_SWAPD - swapd_pre_deinit(); -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - akcompressd_pre_deinit(); -#endif - - if (hybridswap_cache) { - kmem_cache_destroy(hybridswap_cache); - hybridswap_cache = NULL; - } -} diff --git a/drivers/block/zram/hybridswap/hybridswap_manager.c b/drivers/block/zram/hybridswap/hybridswap_manager.c deleted file mode 100755 index 7c5147d6883a..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_manager.c +++ /dev/null @@ -1,1069 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap.h" - -#include "hybridswap_list.h" -#include "hybridswap_area.h" -#include "hybridswap_internal.h" -#include "hybridswap_lru_rmap.h" - -#define esentry_extid(e) ((e) >> EXTENT_SHIFT) -#define esentry_pgid(e) (((e) & ((1 << EXTENT_SHIFT) - 1)) >> PAGE_SHIFT) -#define esentry_pgoff(e) ((e) & (PAGE_SIZE - 1)) - -static struct io_extent *alloc_io_extent(struct hybridswap_page_pool *pool, - bool fast, bool nofail) -{ - int i; - struct io_extent *io_ext = hybridswap_malloc(sizeof(struct io_extent), - fast, nofail); - - if (!io_ext) { - hybp(HYB_ERR, "alloc io_ext failed\n"); - return NULL; - } - - io_ext->ext_id = -EINVAL; - io_ext->pool = pool; - for (i = 0; i < (int)EXTENT_PG_CNT; i++) { - io_ext->pages[i] = hybridswap_alloc_page(pool, GFP_ATOMIC, - fast, nofail); - if (!io_ext->pages[i]) { - hybp(HYB_ERR, "alloc page[%d] failed\n", i); - goto page_free; - } - } - return io_ext; -page_free: - for (i = 0; i < (int)EXTENT_PG_CNT; i++) - if (io_ext->pages[i]) - hybridswap_page_recycle(io_ext->pages[i], pool); - hybridswap_free(io_ext); - - return NULL; -} - -static void discard_io_extent(struct io_extent *io_ext, unsigned int op) -{ - struct zram *zram = NULL; - int i; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return; - } - if (!io_ext->mcg) - zram = io_ext->zram; - else - zram = MEMCGRP_ITEM(io_ext->mcg, zram); - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - goto out; - } - for (i = 0; i < (int)EXTENT_PG_CNT; i++) - if (io_ext->pages[i]) - hybridswap_page_recycle(io_ext->pages[i], io_ext->pool); - if (io_ext->ext_id < 0) - goto out; - hybp(HYB_DEBUG, "ext = %d, op = %d\n", io_ext->ext_id, op); - if (op == REQ_OP_READ) { - put_extent(zram->area, io_ext->ext_id); - goto out; - } - for (i = 0; i < io_ext->cnt; i++) { - u32 index = io_ext->index[i]; - - zram_slot_lock(zram, index); - if (io_ext->mcg) - zram_lru_add_tail(zram, index, io_ext->mcg); - zram_clear_flag(zram, index, ZRAM_UNDER_WB); - zram_slot_unlock(zram, index); - } - hybridswap_free_extent(zram->area, io_ext->ext_id); -out: - hybridswap_free(io_ext); -} - -static void copy_to_pages(u8 *src, struct page *pages[], - unsigned long eswpentry, int size) -{ - u8 *dst = NULL; - int pg_id = esentry_pgid(eswpentry); - int offset = esentry_pgoff(eswpentry); - - if (!src) { - hybp(HYB_ERR, "NULL src\n"); - return; - } - if (!pages) { - hybp(HYB_ERR, "NULL pages\n"); - return; - } - if (size < 0 || size > (int)PAGE_SIZE) { - hybp(HYB_ERR, "size = %d invalid\n", size); - return; - } - dst = page_to_virt(pages[pg_id]); - if (offset + size <= (int)PAGE_SIZE) { - memcpy(dst + offset, src, size); - return; - } - if (pg_id == EXTENT_PG_CNT - 1) { - hybp(HYB_ERR, "ext overflow, addr = %lx, size = %d\n", - eswpentry, size); - return; - } - memcpy(dst + offset, src, PAGE_SIZE - offset); - dst = page_to_virt(pages[pg_id + 1]); - memcpy(dst, src + PAGE_SIZE - offset, offset + size - PAGE_SIZE); -} - -static void copy_from_pages(u8 *dst, struct page *pages[], - unsigned long eswpentry, int size) -{ - u8 *src = NULL; - int pg_id = esentry_pgid(eswpentry); - int offset = esentry_pgoff(eswpentry); - - if (!dst) { - hybp(HYB_ERR, "NULL dst\n"); - return; - } - if (!pages) { - hybp(HYB_ERR, "NULL pages\n"); - return; - } - if (size < 0 || size > (int)PAGE_SIZE) { - hybp(HYB_ERR, "size = %d invalid\n", size); - return; - } - - src = page_to_virt(pages[pg_id]); - if (offset + size <= (int)PAGE_SIZE) { - memcpy(dst, src + offset, size); - return; - } - if (pg_id == EXTENT_PG_CNT - 1) { - hybp(HYB_ERR, "ext overflow, addr = %lx, size = %d\n", - eswpentry, size); - return; - } - memcpy(dst, src + offset, PAGE_SIZE - offset); - src = page_to_virt(pages[pg_id + 1]); - memcpy(dst + PAGE_SIZE - offset, src, offset + size - PAGE_SIZE); -} - -static bool zram_test_skip(struct zram *zram, u32 index, struct mem_cgroup *mcg) -{ - if (zram_test_flag(zram, index, ZRAM_WB)) - return true; - if (zram_test_flag(zram, index, ZRAM_UNDER_WB)) - return true; - if (zram_test_flag(zram, index, ZRAM_BATCHING_OUT)) - return true; - if (zram_test_flag(zram, index, ZRAM_SAME)) - return true; - if (mcg != zram_get_memcg(zram, index)) - return true; - if (!zram_get_obj_size(zram, index)) - return true; - - return false; -} - -static bool zram_test_overwrite(struct zram *zram, u32 index, int ext_id) -{ - if (!zram_test_flag(zram, index, ZRAM_WB)) - return true; - if (ext_id != esentry_extid(zram_get_handle(zram, index))) - return true; - - return false; -} - -static void update_size_info(struct zram *zram, u32 index) -{ - struct hybridswap_stat *stat; - int size = zram_get_obj_size(zram, index); - struct mem_cgroup *mcg; - memcg_hybs_t *hybs; - int ext_id; - - if (!zram_test_flag(zram, index, ZRAM_IN_BD)) - return; - - ext_id = esentry_extid(zram_get_handle(zram, index)); - hybp(HYB_INFO, "ext_id %d index %d\n", ext_id, index); - - if (ext_id >= 0 && ext_id < zram->area->nr_exts) - atomic_dec(&zram->area->ext_stored_pages[ext_id]); - else { - hybp(HYB_ERR, "ext = %d invalid\n", ext_id); - ext_id = -1; - } - - stat = hybridswap_get_stat_obj(); - if (stat) { - atomic64_add(size, &stat->dropped_ext_size); - atomic64_sub(size, &stat->stored_size); - atomic64_dec(&stat->stored_pages); - } else - hybp(HYB_ERR, "NULL stat\n"); - - mcg = zram_get_memcg(zram, index); - if (mcg) { - hybs = MEMCGRP_ITEM_DATA(mcg); - - if (hybs) { - atomic64_sub(size, &hybs->hybridswap_stored_size); - atomic64_dec(&hybs->hybridswap_stored_pages); - } else - hybp(HYB_ERR, "NULL hybs\n"); - } else - hybp(HYB_ERR, "NULL mcg\n"); - zram_clear_flag(zram, index, ZRAM_IN_BD); -} - -static void move_to_hybridswap(struct zram *zram, u32 index, - unsigned long eswpentry, struct mem_cgroup *mcg) -{ - int size; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return; - } - - size = zram_get_obj_size(zram, index); - - zram_clear_flag(zram, index, ZRAM_UNDER_WB); - - zs_free(zram->mem_pool, zram_get_handle(zram, index)); - atomic64_sub(size, &zram->stats.compr_data_size); - atomic64_dec(&zram->stats.pages_stored); - - zram_set_memcg(zram, index, mcg->id.id); - zram_set_flag(zram, index, ZRAM_IN_BD); - zram_set_flag(zram, index, ZRAM_WB); - zram_set_obj_size(zram, index, size); - if (size == PAGE_SIZE) - zram_set_flag(zram, index, ZRAM_HUGE); - zram_set_handle(zram, index, eswpentry); - zram_rmap_insert(zram, index); - - atomic64_add(size, &stat->stored_size); - atomic64_add(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size)); - atomic64_inc(&stat->stored_pages); - atomic_inc(&zram->area->ext_stored_pages[esentry_extid(eswpentry)]); - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages)); -} - -static void __move_to_zram(struct zram *zram, u32 index, unsigned long handle, - struct io_extent *io_ext) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - struct mem_cgroup *mcg = io_ext->mcg; - int size = zram_get_obj_size(zram, index); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - - zram_slot_lock(zram, index); - if (zram_test_overwrite(zram, index, io_ext->ext_id)) { - zram_slot_unlock(zram, index); - zs_free(zram->mem_pool, handle); - return; - } - zram_rmap_erase(zram, index); - zram_set_handle(zram, index, handle); - zram_clear_flag(zram, index, ZRAM_WB); - if (mcg) - zram_lru_add_tail(zram, index, mcg); - zram_set_flag(zram, index, ZRAM_FROM_HYBRIDSWAP); - atomic64_add(size, &zram->stats.compr_data_size); - atomic64_inc(&zram->stats.pages_stored); - zram_clear_flag(zram, index, ZRAM_IN_BD); - zram_slot_unlock(zram, index); - - atomic64_inc(&stat->batchout_pages); - atomic64_sub(size, &stat->stored_size); - atomic64_dec(&stat->stored_pages); - atomic64_add(size, &stat->batchout_real_load); - atomic_dec(&zram->area->ext_stored_pages[io_ext->ext_id]); - if (mcg) { - atomic64_sub(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size)); - atomic64_dec(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages)); - } -} - -static int move_to_zram(struct zram *zram, u32 index, struct io_extent *io_ext) -{ - unsigned long handle, eswpentry; - struct mem_cgroup *mcg = NULL; - int size, i; - u8 *dst = NULL; - - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return -EINVAL; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return -EINVAL; - } - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return -EINVAL; - } - - mcg = io_ext->mcg; - zram_slot_lock(zram, index); - eswpentry = zram_get_handle(zram, index); - if (zram_test_overwrite(zram, index, io_ext->ext_id)) { - zram_slot_unlock(zram, index); - return 0; - } - size = zram_get_obj_size(zram, index); - zram_slot_unlock(zram, index); - - for (i = esentry_pgid(eswpentry) - 1; i >= 0 && io_ext->pages[i]; i--) { - hybridswap_page_recycle(io_ext->pages[i], io_ext->pool); - io_ext->pages[i] = NULL; - } - handle = hybridswap_zsmalloc(zram->mem_pool, size, io_ext->pool); - if (!handle) { - hybp(HYB_ERR, "alloc handle failed, size = %d\n", size); - return -ENOMEM; - } - dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); - copy_from_pages(dst, io_ext->pages, eswpentry, size); - zs_unmap_object(zram->mem_pool, handle); - __move_to_zram(zram, index, handle, io_ext); - - return 0; -} - -static int extent_unlock(struct io_extent *io_ext) -{ - int ext_id; - struct mem_cgroup *mcg = NULL; - struct zram *zram = NULL; - int k; - unsigned long eswpentry; - int real_load = 0, size; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - goto out; - } - - mcg = io_ext->mcg; - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - goto out; - } - zram = MEMCGRP_ITEM(mcg, zram); - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - goto out; - } - ext_id = io_ext->ext_id; - if (ext_id < 0) - goto out; - - ext_id = io_ext->ext_id; - if (MEMCGRP_ITEM(mcg, in_swapin)) - goto out; - hybp(HYB_DEBUG, "add ext_id = %d, cnt = %d.\n", - ext_id, io_ext->cnt); - eswpentry = ((unsigned long)ext_id) << EXTENT_SHIFT; - for (k = 0; k < io_ext->cnt; k++) - zram_slot_lock(zram, io_ext->index[k]); - for (k = 0; k < io_ext->cnt; k++) { - move_to_hybridswap(zram, io_ext->index[k], eswpentry, mcg); - size = zram_get_obj_size(zram, io_ext->index[k]); - eswpentry += size; - real_load += size; - } - put_extent(zram->area, ext_id); - io_ext->ext_id = -EINVAL; - for (k = 0; k < io_ext->cnt; k++) - zram_slot_unlock(zram, io_ext->index[k]); - hybp(HYB_DEBUG, "add extent OK.\n"); -out: - discard_io_extent(io_ext, REQ_OP_WRITE); - if (mcg) - css_put(&mcg->css); - - return real_load; -} - -static void extent_add(struct io_extent *io_ext, - enum hybridswap_scenario scenario) -{ - struct mem_cgroup *mcg = NULL; - struct zram *zram = NULL; - int ext_id; - int k; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return; - } - - mcg = io_ext->mcg; - if (!mcg) - zram = io_ext->zram; - else - zram = MEMCGRP_ITEM(mcg, zram); - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - goto out; - } - - ext_id = io_ext->ext_id; - if (ext_id < 0) - goto out; - - io_ext->cnt = zram_rmap_get_extent_index(zram->area, - ext_id, - io_ext->index); - hybp(HYB_DEBUG, "ext_id = %d, cnt = %d.\n", ext_id, io_ext->cnt); - for (k = 0; k < io_ext->cnt; k++) { - int ret = move_to_zram(zram, io_ext->index[k], io_ext); - - if (ret < 0) - goto out; - } - hybp(HYB_DEBUG, "extent add OK, free ext_id = %d.\n", ext_id); - hybridswap_free_extent(zram->area, io_ext->ext_id); - io_ext->ext_id = -EINVAL; - if (mcg) { - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_inextcnt)); - atomic_dec(&MEMCGRP_ITEM(mcg, hybridswap_extcnt)); - } -out: - discard_io_extent(io_ext, REQ_OP_READ); - if (mcg) - css_put(&mcg->css); -} - -static void extent_clear(struct zram *zram, int ext_id) -{ - int *index = NULL; - int cnt; - int k; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - - index = kzalloc(sizeof(int) * EXTENT_MAX_OBJ_CNT, GFP_NOIO); - if (!index) - index = kzalloc(sizeof(int) * EXTENT_MAX_OBJ_CNT, - GFP_NOIO | __GFP_NOFAIL); - - cnt = zram_rmap_get_extent_index(zram->area, ext_id, index); - - for (k = 0; k < cnt; k++) { - zram_slot_lock(zram, index[k]); - if (zram_test_overwrite(zram, index[k], ext_id)) { - zram_slot_unlock(zram, index[k]); - continue; - } - zram_set_memcg(zram, index[k], 0); - zram_set_flag(zram, index[k], ZRAM_MCGID_CLEAR); - atomic64_inc(&stat->mcgid_clear); - zram_slot_unlock(zram, index[k]); - } - - kfree(index); -} - -static int shrink_entry(struct zram *zram, u32 index, struct io_extent *io_ext, - unsigned long ext_off) -{ - unsigned long handle; - int size; - u8 *src = NULL; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return -EINVAL; - } - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return -EINVAL; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return -EINVAL; - } - - zram_slot_lock(zram, index); - handle = zram_get_handle(zram, index); - if (!handle || zram_test_skip(zram, index, io_ext->mcg)) { - zram_slot_unlock(zram, index); - return 0; - } - size = zram_get_obj_size(zram, index); - if (ext_off + size > EXTENT_SIZE) { - zram_slot_unlock(zram, index); - return -ENOSPC; - } - - src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); - copy_to_pages(src, io_ext->pages, ext_off, size); - zs_unmap_object(zram->mem_pool, handle); - io_ext->index[io_ext->cnt++] = index; - - zram_lru_del(zram, index); - zram_set_flag(zram, index, ZRAM_UNDER_WB); - if (zram_test_flag(zram, index, ZRAM_FROM_HYBRIDSWAP)) { - atomic64_inc(&stat->reout_pages); - atomic64_add(size, &stat->reout_bytes); - } - zram_slot_unlock(zram, index); - atomic64_inc(&stat->reclaimin_pages); - - return size; -} - -static int shrink_entry_list(struct io_extent *io_ext) -{ - struct mem_cgroup *mcg = NULL; - struct zram *zram = NULL; - unsigned long stored_size; - int *swap_index = NULL; - int swap_cnt, k; - int swap_size = 0; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return -EINVAL; - } - - mcg = io_ext->mcg; - zram = MEMCGRP_ITEM(mcg, zram); - hybp(HYB_DEBUG, "mcg = %d\n", mcg->id.id); - stored_size = atomic64_read(&MEMCGRP_ITEM(mcg, zram_stored_size)); - hybp(HYB_DEBUG, "zram_stored_size = %ld\n", stored_size); - if (stored_size < EXTENT_SIZE) { - hybp(HYB_INFO, "%lu is smaller than EXTENT_SIZE\n", stored_size); - return -ENOENT; - } - - swap_index = kzalloc(sizeof(int) * EXTENT_MAX_OBJ_CNT, GFP_NOIO); - if (!swap_index) - return -ENOMEM; - io_ext->ext_id = hybridswap_alloc_extent(zram->area, mcg); - if (io_ext->ext_id < 0) { - kfree(swap_index); - return io_ext->ext_id; - } - swap_cnt = zram_get_memcg_coldest_index(zram->area, mcg, swap_index, - EXTENT_MAX_OBJ_CNT); - io_ext->cnt = 0; - for (k = 0; k < swap_cnt && swap_size < (int)EXTENT_SIZE; k++) { - int size = shrink_entry(zram, swap_index[k], io_ext, swap_size); - - if (size < 0) - break; - swap_size += size; - } - kfree(swap_index); - hybp(HYB_DEBUG, "fill extent = %d, cnt = %d, overhead = %ld.\n", - io_ext->ext_id, io_ext->cnt, EXTENT_SIZE - swap_size); - if (swap_size == 0) { - hybp(HYB_ERR, "swap_size = 0, free ext_id = %d.\n", - io_ext->ext_id); - hybridswap_free_extent(zram->area, io_ext->ext_id); - io_ext->ext_id = -EINVAL; - return -ENOENT; - } - - return swap_size; -} - -/* - * The function is used to initialize global settings - */ -void hybridswap_manager_deinit(struct zram *zram) -{ - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - - free_hybridswap_area(zram->area); - zram->area = NULL; -} - -int hybridswap_manager_init(struct zram *zram) -{ - int ret; - - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - ret = -EINVAL; - goto out; - } - - zram->area = alloc_hybridswap_area(zram->disksize, - zram->nr_pages << PAGE_SHIFT); - if (!zram->area) { - ret = -ENOMEM; - goto out; - } - return 0; -out: - hybridswap_manager_deinit(zram); - - return ret; -} - -/* - * The function is used to initialize private member in memcg - */ -void hybridswap_manager_memcg_init(struct zram *zram, - struct mem_cgroup *memcg) -{ - memcg_hybs_t *hybs; - - if (!memcg || !zram || !zram->area) { - hybp(HYB_ERR, "invalid zram or mcg_hyb\n"); - return; - } - - hyb_list_init(mcg_idx(zram->area, memcg->id.id), zram->area->obj_table); - hyb_list_init(mcg_idx(zram->area, memcg->id.id), zram->area->ext_table); - - hybs = MEMCGRP_ITEM_DATA(memcg); - hybs->in_swapin = false; - atomic64_set(&hybs->zram_stored_size, 0); - atomic64_set(&hybs->zram_page_size, 0); - atomic64_set(&hybs->hybridswap_stored_pages, 0); - atomic64_set(&hybs->hybridswap_stored_size, 0); - atomic64_set(&hybs->hybridswap_allfaultcnt, 0); - atomic64_set(&hybs->hybridswap_outcnt, 0); - atomic64_set(&hybs->hybridswap_incnt, 0); - atomic64_set(&hybs->hybridswap_faultcnt, 0); - atomic64_set(&hybs->hybridswap_outextcnt, 0); - atomic64_set(&hybs->hybridswap_inextcnt, 0); - atomic_set(&hybs->hybridswap_extcnt, 0); - atomic_set(&hybs->hybridswap_peakextcnt, 0); - mutex_init(&hybs->swap_lock); - - smp_wmb(); - hybs->zram = zram; - hybp(HYB_DEBUG, "new memcg in zram, id = %d.\n", memcg->id.id); -} - -void hybridswap_manager_memcg_deinit(struct mem_cgroup *mcg) -{ - struct zram *zram = NULL; - struct hybridswap_area *area = NULL; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - int last_index = -1; - memcg_hybs_t *hybs; - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - - hybs = MEMCGRP_ITEM_DATA(mcg); - if (!hybs->zram) - return; - - zram = hybs->zram; - if (!zram->area) { - hybp(HYB_WARN, "mcg %p name %s id %d zram %p area is NULL\n", - mcg, hybs->name, mcg->id.id, zram); - return; - } - - hybp(HYB_DEBUG, "deinit mcg %d %s\n", mcg->id.id, hybs->name); - if (mcg->id.id == 0) - return; - - area = zram->area; - while (1) { - int index = get_memcg_zram_entry(area, mcg); - - if (index == -ENOENT) - break; - - if (index < 0) { - hybp(HYB_ERR, "invalid index\n"); - return; - } - - if (last_index == index) { - hybp(HYB_ERR, "dup index %d\n", index); - dump_stack(); - } - - zram_slot_lock(zram, index); - if (index == last_index || mcg == zram_get_memcg(zram, index)) { - hyb_list_del(obj_idx(zram->area, index), - mcg_idx(zram->area, mcg->id.id), - zram->area->obj_table); - zram_set_memcg(zram, index, 0); - zram_set_flag(zram, index, ZRAM_MCGID_CLEAR); - atomic64_inc(&stat->mcgid_clear); - } - zram_slot_unlock(zram, index); - last_index = index; - } - - hybp(HYB_DEBUG, "deinit mcg %d %s, entry done\n", mcg->id.id, hybs->name); - while (1) { - int ext_id = get_memcg_extent(area, mcg); - - if (ext_id == -ENOENT) - break; - - extent_clear(zram, ext_id); - hyb_list_set_mcgid(ext_idx(area, ext_id), area->ext_table, 0); - put_extent(area, ext_id); - } - hybp(HYB_DEBUG, "deinit mcg %d %s, extent done\n", mcg->id.id, hybs->name); - hybs->zram = NULL; -} -/* - * The function is used to add ZS object to ZRAM LRU list - */ -void hybridswap_zram_lru_add(struct zram *zram, - u32 index, struct mem_cgroup *memcg) -{ - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - - zram_lru_add(zram, index, memcg); -} - -/* - * The function is used to del ZS object from ZRAM LRU list - */ -void hybridswap_zram_lru_del(struct zram *zram, u32 index) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - - zram_clear_flag(zram, index, ZRAM_FROM_HYBRIDSWAP); - if (zram_test_flag(zram, index, ZRAM_MCGID_CLEAR)) { - zram_clear_flag(zram, index, ZRAM_MCGID_CLEAR); - atomic64_dec(&stat->mcgid_clear); - } - - if (zram_test_flag(zram, index, ZRAM_WB)) { - update_size_info(zram, index); - zram_rmap_erase(zram, index); - zram_clear_flag(zram, index, ZRAM_WB); - zram_set_memcg(zram, index, 0); - zram_set_handle(zram, index, 0); - } else { - zram_lru_del(zram, index); - } -} - -/* - * The function is used to alloc a new extent, - * then reclaim ZRAM by LRU list to the new extent. - */ -unsigned long hybridswap_extent_create(struct mem_cgroup *mcg, - int *ext_id, - struct hybridswap_buffer *buf, - void **private) -{ - struct io_extent *io_ext = NULL; - int reclaim_size; - - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return 0; - } - if (!ext_id) { - hybp(HYB_ERR, "NULL ext_id\n"); - return 0; - } - (*ext_id) = -EINVAL; - if (!buf) { - hybp(HYB_ERR, "NULL buf\n"); - return 0; - } - if (!private) { - hybp(HYB_ERR, "NULL private\n"); - return 0; - } - - io_ext = alloc_io_extent(buf->pool, false, true); - if (!io_ext) - return 0; - io_ext->mcg = mcg; - reclaim_size = shrink_entry_list(io_ext); - if (reclaim_size < 0) { - discard_io_extent(io_ext, REQ_OP_WRITE); - (*ext_id) = reclaim_size; - return 0; - } - io_ext->real_load = reclaim_size; - css_get(&mcg->css); - (*ext_id) = io_ext->ext_id; - buf->dest_pages = io_ext->pages; - (*private) = io_ext; - hybp(HYB_DEBUG, "mcg = %d, ext_id = %d\n", mcg->id.id, io_ext->ext_id); - - return reclaim_size; -} - -/* - * The function will be called when hybridswap write done. - * The function should register extent to hybridswap manager. - */ -void hybridswap_extent_register(void *private, struct hybridswap_io_req *req) -{ - struct io_extent *io_ext = private; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return; - } - hybp(HYB_DEBUG, "ext_id = %d\n", io_ext->ext_id); - atomic64_add(extent_unlock(io_ext), &req->real_load); -} - -/* - * If extent empty, return false, otherise return true. - */ -void hybridswap_extent_objs_del(struct zram *zram, u32 index) -{ - int ext_id; - struct mem_cgroup *mcg = NULL; - unsigned long eswpentry; - int size; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat) { - hybp(HYB_ERR, "NULL stat\n"); - return; - } - if (!zram || !zram->area) { - hybp(HYB_ERR, "NULL zram\n"); - return; - } - if (index >= (u32)zram->area->nr_objs) { - hybp(HYB_ERR, "index = %d invalid\n", index); - return; - } - if (!zram_test_flag(zram, index, ZRAM_WB)) { - hybp(HYB_ERR, "not WB object\n"); - return; - } - - eswpentry = zram_get_handle(zram, index); - size = zram_get_obj_size(zram, index); - atomic64_sub(size, &stat->stored_size); - atomic64_dec(&stat->stored_pages); - atomic64_add(size, &stat->dropped_ext_size); - mcg = zram_get_memcg(zram, index); - if (mcg) { - atomic64_sub(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size)); - atomic64_dec(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages)); - } - - zram_clear_flag(zram, index, ZRAM_IN_BD); - if (!atomic_dec_and_test( - &zram->area->ext_stored_pages[esentry_extid(eswpentry)])) - return; - ext_id = get_extent(zram->area, esentry_extid(eswpentry)); - if (ext_id < 0) - return; - - atomic64_inc(&stat->notify_free); - if (mcg) - atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_ext_notify_free)); - hybp(HYB_DEBUG, "free ext_id = %d\n", ext_id); - hybridswap_free_extent(zram->area, ext_id); -} - -/* - * The function will be called when hybridswap execute fault out. - */ -int hybridswap_find_extent_by_idx(unsigned long eswpentry, - struct hybridswap_buffer *buf, - void **private) -{ - int ext_id; - struct io_extent *io_ext = NULL; - struct zram *zram = NULL; - - if (!buf) { - hybp(HYB_ERR, "NULL buf\n"); - return -EINVAL; - } - if (!private) { - hybp(HYB_ERR, "NULL private\n"); - return -EINVAL; - } - - zram = buf->zram; - ext_id = get_extent(zram->area, esentry_extid(eswpentry)); - if (ext_id < 0) - return ext_id; - io_ext = alloc_io_extent(buf->pool, true, true); - if (!io_ext) { - hybp(HYB_ERR, "io_ext alloc failed\n"); - put_extent(zram->area, ext_id); - return -ENOMEM; - } - - io_ext->ext_id = ext_id; - io_ext->zram = zram; - io_ext->mcg = get_mem_cgroup( - hyb_list_get_mcgid(ext_idx(zram->area, ext_id), - zram->area->ext_table)); - if (io_ext->mcg) - css_get(&io_ext->mcg->css); - buf->dest_pages = io_ext->pages; - (*private) = io_ext; - hybp(HYB_DEBUG, "get entry = %lx ext = %d\n", eswpentry, ext_id); - - return ext_id; -} - -/* - * The function will be called when hybridswap executes batch out. - */ -int hybridswap_find_extent_by_memcg(struct mem_cgroup *mcg, - struct hybridswap_buffer *buf, - void **private) -{ - int ext_id; - struct io_extent *io_ext = NULL; - - if (!mcg) { - hybp(HYB_ERR, "NULL mcg\n"); - return -EINVAL; - } - if (!buf) { - hybp(HYB_ERR, "NULL buf\n"); - return -EINVAL; - } - if (!private) { - hybp(HYB_ERR, "NULL private\n"); - return -EINVAL; - } - - ext_id = get_memcg_extent(MEMCGRP_ITEM(mcg, zram)->area, mcg); - if (ext_id < 0) - return ext_id; - io_ext = alloc_io_extent(buf->pool, true, false); - if (!io_ext) { - hybp(HYB_ERR, "io_ext alloc failed\n"); - put_extent(MEMCGRP_ITEM(mcg, zram)->area, ext_id); - return -ENOMEM; - } - io_ext->ext_id = ext_id; - io_ext->mcg = mcg; - css_get(&mcg->css); - buf->dest_pages = io_ext->pages; - (*private) = io_ext; - hybp(HYB_DEBUG, "get mcg = %d, ext = %d\n", mcg->id.id, ext_id); - - return ext_id; -} - -/* - * The function will be called when hybridswap read done. - * The function should extra the extent to ZRAM, then destroy - */ -void hybridswap_extent_destroy(void *private, enum hybridswap_scenario scenario) -{ - struct io_extent *io_ext = private; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return; - } - - hybp(HYB_DEBUG, "ext_id = %d\n", io_ext->ext_id); - extent_add(io_ext, scenario); -} - -/* - * The function will be called - * when schedule meets exception proceeding extent - */ -void hybridswap_extent_exception(enum hybridswap_scenario scenario, - void *private) -{ - struct io_extent *io_ext = private; - struct mem_cgroup *mcg = NULL; - unsigned int op = (scenario == HYBRIDSWAP_RECLAIM_IN) ? - REQ_OP_WRITE : REQ_OP_READ; - - if (!io_ext) { - hybp(HYB_ERR, "NULL io_ext\n"); - return; - } - - hybp(HYB_DEBUG, "ext_id = %d, op = %d\n", io_ext->ext_id, op); - mcg = io_ext->mcg; - discard_io_extent(io_ext, op); - if (mcg) - css_put(&mcg->css); -} - -struct mem_cgroup *hybridswap_zram_get_memcg(struct zram *zram, u32 index) -{ - return zram_get_memcg(zram, index); -} diff --git a/drivers/block/zram/hybridswap/hybridswap_perf.c b/drivers/block/zram/hybridswap/hybridswap_perf.c deleted file mode 100755 index 47aec0425974..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_perf.c +++ /dev/null @@ -1,351 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_FG_TASK_UID -#include -#endif -#include "hybridswap_internal.h" - -#define DUMP_BUF_LEN 512 - -static unsigned long warning_threshold[HYBRIDSWAP_SCENARIO_BUTT] = { - 0, 200, 500, 0 -}; - -const char *key_point_name[HYBRIDSWAP_KYE_POINT_BUTT] = { - "START", - "INIT", - "IOENTRY_ALLOC", - "FIND_EXTENT", - "IO_EXTENT", - "SEGMENT_ALLOC", - "BIO_ALLOC", - "SUBMIT_BIO", - "END_IO", - "SCHED_WORK", - "END_WORK", - "CALL_BACK", - "WAKE_UP", - "ZRAM_LOCK", - "DONE" -}; - -static void hybridswap_dump_point_lat( - struct hybridswap_key_point_record *record, ktime_t start) -{ - int i; - - for (i = 0; i < HYBRIDSWAP_KYE_POINT_BUTT; ++i) { - if (!record->key_point[i].record_cnt) - continue; - - hybp(HYB_ERR, - "%s diff %lld cnt %u end %u lat %lld ravg_sum %llu\n", - key_point_name[i], - ktime_us_delta(record->key_point[i].first_time, start), - record->key_point[i].record_cnt, - record->key_point[i].end_cnt, - record->key_point[i].proc_total_time, - record->key_point[i].proc_ravg_sum); - } -} - -static void hybridswap_dump_no_record_point( - struct hybridswap_key_point_record *record, char *log, - unsigned int *count) -{ - int i; - unsigned int point = 0; - - for (i = 0; i < HYBRIDSWAP_KYE_POINT_BUTT; ++i) - if (record->key_point[i].record_cnt) - point = i; - - point++; - if (point < HYBRIDSWAP_KYE_POINT_BUTT) - *count += snprintf(log + *count, - (size_t)(DUMP_BUF_LEN - *count), - " no_record_point %s", key_point_name[point]); - else - *count += snprintf(log + *count, - (size_t)(DUMP_BUF_LEN - *count), " all_point_record"); -} - -static long long hybridswap_calc_speed(s64 page_cnt, s64 time) -{ - s64 size; - - if (!page_cnt) - return 0; - - size = page_cnt * PAGE_SIZE * BITS_PER_BYTE; - if (time) - return size * USEC_PER_SEC / time; - else - return S64_MAX; -} - -static void hybridswap_dump_lat( - struct hybridswap_key_point_record *record, ktime_t curr_time, - bool perf_end_flag) -{ - char log[DUMP_BUF_LEN] = { 0 }; - unsigned int count = 0; - ktime_t start; - s64 total_time; - - start = record->key_point[HYBRIDSWAP_START].first_time; - total_time = ktime_us_delta(curr_time, start); - count += snprintf(log + count, - (size_t)(DUMP_BUF_LEN - count), - "totaltime(us) %lld scenario %u task %s nice %d", - total_time, record->scenario, record->task_comm, record->nice); - - if (perf_end_flag) - count += snprintf(log + count, (size_t)(DUMP_BUF_LEN - count), - " page %d segment %d speed(bps) %lld threshold %llu", - record->page_cnt, record->segment_cnt, - hybridswap_calc_speed(record->page_cnt, total_time), - record->warning_threshold); - else - count += snprintf(log + count, (size_t)(DUMP_BUF_LEN - count), - " state %c", task_state_to_char(record->task)); - - hybridswap_dump_no_record_point(record, log, &count); - - hybp(HYB_ERR, "perf end flag %u %s\n", perf_end_flag, log); - hybridswap_dump_point_lat(record, start); - dump_stack(); -} - -static unsigned long hybridswap_perf_warning_threshold( - enum hybridswap_scenario scenario) -{ - if (unlikely(scenario >= HYBRIDSWAP_SCENARIO_BUTT)) - return 0; - - return warning_threshold[scenario]; -} - -void hybridswap_perf_warning(struct timer_list *t) -{ - struct hybridswap_key_point_record *record = - from_timer(record, t, lat_monitor); - static unsigned long last_dump_lat_jiffies = 0; - - if (!record->warning_threshold) - return; - - if (jiffies_to_msecs(jiffies - last_dump_lat_jiffies) <= 60000) - return; - - hybridswap_dump_lat(record, ktime_get(), false); - - if (likely(record->task)) - sched_show_task(record->task); - last_dump_lat_jiffies = jiffies; - record->warning_threshold <<= 2; - record->timeout_flag = true; - mod_timer(&record->lat_monitor, - jiffies + msecs_to_jiffies(record->warning_threshold)); -} - -static void hybridswap_perf_init_monitor( - struct hybridswap_key_point_record *record, - enum hybridswap_scenario scenario) -{ - record->warning_threshold = hybridswap_perf_warning_threshold(scenario); - - if (!record->warning_threshold) - return; - - record->task = current; - get_task_struct(record->task); - timer_setup(&record->lat_monitor, hybridswap_perf_warning, 0); - mod_timer(&record->lat_monitor, - jiffies + msecs_to_jiffies(record->warning_threshold)); -} - -static void hybridswap_perf_stop_monitor( - struct hybridswap_key_point_record *record) -{ - if (!record->warning_threshold) - return; - - del_timer_sync(&record->lat_monitor); - put_task_struct(record->task); -} - -static void hybridswap_perf_init(struct hybridswap_key_point_record *record, - enum hybridswap_scenario scenario) -{ - int i; - - for (i = 0; i < HYBRIDSWAP_KYE_POINT_BUTT; ++i) - spin_lock_init(&record->key_point[i].time_lock); - - record->nice = task_nice(current); - record->scenario = scenario; - get_task_comm(record->task_comm, current); - hybridswap_perf_init_monitor(record, scenario); -} - -void hybridswap_perf_start_proc( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type, ktime_t curr_time, - unsigned long long current_ravg_sum) -{ - struct hybridswap_key_point_info *key_point = - &record->key_point[type]; - - if (!key_point->record_cnt) - key_point->first_time = curr_time; - - key_point->record_cnt++; - key_point->last_time = curr_time; - key_point->last_ravg_sum = current_ravg_sum; -} - -void hybridswap_perf_end_proc( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type, ktime_t curr_time, - unsigned long long current_ravg_sum) -{ - struct hybridswap_key_point_info *key_point = - &record->key_point[type]; - s64 diff_time = ktime_us_delta(curr_time, key_point->last_time); - - key_point->proc_total_time += diff_time; - if (diff_time > key_point->proc_max_time) - key_point->proc_max_time = diff_time; - - key_point->proc_ravg_sum += current_ravg_sum - - key_point->last_ravg_sum; - key_point->end_cnt++; - key_point->last_time = curr_time; - key_point->last_ravg_sum = current_ravg_sum; -} - -void hybridswap_perf_async_perf( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type, ktime_t start, - unsigned long long start_ravg_sum) -{ - unsigned long long current_ravg_sum = ((type == HYBRIDSWAP_CALL_BACK) || - (type == HYBRIDSWAP_END_WORK)) ? hybridswap_get_ravg_sum() : 0; - unsigned long flags; - - spin_lock_irqsave(&record->key_point[type].time_lock, flags); - hybridswap_perf_start_proc(record, type, start, start_ravg_sum); - hybridswap_perf_end_proc(record, type, ktime_get(), - current_ravg_sum); - spin_unlock_irqrestore(&record->key_point[type].time_lock, flags); -} - -void hybridswap_perf_lat_point( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type) -{ - hybridswap_perf_start_proc(record, type, ktime_get(), - hybridswap_get_ravg_sum()); - record->key_point[type].end_cnt++; -} - -void hybridswap_perf_start( - struct hybridswap_key_point_record *record, - ktime_t stsrt, unsigned long long start_ravg_sum, - enum hybridswap_scenario scenario) -{ - hybridswap_perf_init(record, scenario); - hybridswap_perf_start_proc(record, HYBRIDSWAP_START, stsrt, - start_ravg_sum); - record->key_point[HYBRIDSWAP_START].end_cnt++; -} - -void hybridswap_perf_lat_stat( - struct hybridswap_key_point_record *record) -{ - int task_is_fg = 0; - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - s64 curr_lat; - /* reclaim_in: 2s, fault_out: 100ms, batch_out: 500ms, pre_out: 2s */ - s64 timeout_value[HYBRIDSWAP_SCENARIO_BUTT] = { - 2000000, 100000, 500000, 2000000 - }; - - if (!stat || (record->scenario >= HYBRIDSWAP_SCENARIO_BUTT)) - return; - - curr_lat = ktime_us_delta(record->key_point[HYBRIDSWAP_DONE].first_time, - record->key_point[HYBRIDSWAP_START].first_time); - atomic64_add(curr_lat, &stat->lat[record->scenario].total_lat); - if (curr_lat > atomic64_read(&stat->lat[record->scenario].max_lat)) - atomic64_set(&stat->lat[record->scenario].max_lat, curr_lat); - if (curr_lat > timeout_value[record->scenario]) - atomic64_inc(&stat->lat[record->scenario].timeout_cnt); - if (record->scenario == HYBRIDSWAP_FAULT_OUT) { - if (curr_lat <= timeout_value[HYBRIDSWAP_FAULT_OUT]) - return; -#ifdef CONFIG_FG_TASK_UID - task_is_fg = current_is_fg() ? 1 : 0; -#endif - if (curr_lat > 500000) - atomic64_inc(&stat->fault_stat[task_is_fg].timeout_500ms_cnt); - else if (curr_lat > 100000) - atomic64_inc(&stat->fault_stat[task_is_fg].timeout_100ms_cnt); - hybp(HYB_INFO, "task %s:%d fault out timeout us %llu fg %d\n", - current->comm, current->pid, curr_lat, task_is_fg); - } -} - -void hybridswap_perf_end(struct hybridswap_key_point_record *record) -{ - int loglevel; - - hybridswap_perf_stop_monitor(record); - hybridswap_perf_lat_point(record, HYBRIDSWAP_DONE); - hybridswap_perf_lat_stat(record); - - loglevel = record->timeout_flag ? HYB_ERR : HYB_DEBUG; - if (loglevel > hybridswap_loglevel()) - return; - - hybridswap_dump_lat(record, - record->key_point[HYBRIDSWAP_DONE].first_time, true); -} - -void hybridswap_perf_lat_start( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type) -{ - hybridswap_perf_start_proc(record, type, ktime_get(), - hybridswap_get_ravg_sum()); -} - -void hybridswap_perf_lat_end( - struct hybridswap_key_point_record *record, - enum hybridswap_key_point type) -{ - hybridswap_perf_end_proc(record, type, ktime_get(), - hybridswap_get_ravg_sum()); -} - -void hybridswap_perf_io_stat( - struct hybridswap_key_point_record *record, int page_cnt, - int segment_cnt) -{ - record->page_cnt = page_cnt; - record->segment_cnt = segment_cnt; -} - diff --git a/drivers/block/zram/hybridswap/hybridswap_schedule.c b/drivers/block/zram/hybridswap/hybridswap_schedule.c deleted file mode 100755 index 0ed0f2ab1131..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_schedule.c +++ /dev/null @@ -1,724 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hybridswap_internal.h" - -/* default key index is zero */ -#define HYBRIDSWAP_KEY_INDEX 0 -#define HYBRIDSWAP_KEY_SIZE 64 -#define HYBRIDSWAP_KEY_INDEX_SHIFT 3 - -#define HYBRIDSWAP_MAX_INFILGHT_NUM 256 - -#define HYBRIDSWAP_SECTOR_SHIFT 9 -#define HYBRIDSWAP_PAGE_SIZE_SECTOR (PAGE_SIZE >> HYBRIDSWAP_SECTOR_SHIFT) - -#define HYBRIDSWAP_READ_TIME 10 -#define HYBRIDSWAP_WRITE_TIME 100 -#define HYBRIDSWAP_FAULT_OUT_TIME 10 - -struct hybridswap_segment_time { - ktime_t submit_bio; - ktime_t end_io; -}; - -struct hybridswap_segment { - sector_t segment_sector; - int extent_cnt; - int page_cnt; - struct list_head io_entries; - struct hybridswap_entry *io_entries_fifo[BIO_MAX_PAGES]; - struct work_struct endio_work; - struct hybridswap_io_req *req; - struct hybridswap_segment_time time; - u32 bio_result; -}; - -static u8 hybridswap_io_key[HYBRIDSWAP_KEY_SIZE]; -#ifdef CONFIG_SCSI_UFS_ENHANCED_INLINE_CRYPTO_V3 -static u8 hybridswap_io_metadata[METADATA_BYTE_IN_KDF]; -#endif -static struct workqueue_struct *hybridswap_proc_read_workqueue; -static struct workqueue_struct *hybridswap_proc_write_workqueue; -bool hybridswap_schedule_init_flag; - -static void hybridswap_stat_io_bytes(struct hybridswap_io_req *req) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat || !req->page_cnt) - return; - - if (req->io_para.scenario == HYBRIDSWAP_RECLAIM_IN) { - atomic64_add(req->page_cnt * PAGE_SIZE, &stat->reclaimin_bytes); - atomic64_add(req->page_cnt * PAGE_SIZE, &stat->reclaimin_bytes_daily); - atomic64_add(atomic64_read(&req->real_load), &stat->reclaimin_real_load); - atomic64_inc(&stat->reclaimin_cnt); - } else { - atomic64_add(req->page_cnt * PAGE_SIZE, &stat->batchout_bytes); - atomic64_inc(&stat->batchout_cnt); - } -} - -static void hybridswap_key_init(void) -{ - get_random_bytes(hybridswap_io_key, HYBRIDSWAP_KEY_SIZE); -#ifdef CONFIG_SCSI_UFS_ENHANCED_INLINE_CRYPTO_V3 - get_random_bytes(hybridswap_io_metadata, METADATA_BYTE_IN_KDF); -#endif -} - -static void hybridswap_io_req_release(struct kref *ref) -{ - struct hybridswap_io_req *req = - container_of(ref, struct hybridswap_io_req, refcount); - - if (req->io_para.complete_notify && req->io_para.private) - req->io_para.complete_notify(req->io_para.private); - - kfree(req); -} - -static void hybridswap_segment_free(struct hybridswap_io_req *req, - struct hybridswap_segment *segment) -{ - int i; - - for (i = 0; i < segment->extent_cnt; ++i) { - INIT_LIST_HEAD(&segment->io_entries_fifo[i]->list); - req->io_para.done_callback(segment->io_entries_fifo[i], -EIO, req); - } - kfree(segment); -} - -static void hybridswap_limit_inflight(struct hybridswap_io_req *req) -{ - int ret; - - if (!req->limit_inflight_flag) - return; - - if (atomic_read(&req->extent_inflight) >= HYBRIDSWAP_MAX_INFILGHT_NUM) { - do { - hybp(HYB_DEBUG, "wait inflight start\n"); - ret = wait_event_timeout(req->io_wait, - atomic_read(&req->extent_inflight) < - HYBRIDSWAP_MAX_INFILGHT_NUM, - msecs_to_jiffies(100)); - } while (!ret); - } -} - -static void hybridswap_wait_io_finish(struct hybridswap_io_req *req) -{ - int ret; - unsigned int wait_time; - - if (!req->wait_io_finish_flag || !req->page_cnt) - return; - - if (req->io_para.scenario == HYBRIDSWAP_FAULT_OUT) { - hybp(HYB_DEBUG, "fault out wait finish start\n"); - wait_for_completion_io_timeout(&req->io_end_flag, - MAX_SCHEDULE_TIMEOUT); - - return; - } - - wait_time = (req->io_para.scenario == HYBRIDSWAP_RECLAIM_IN) ? - HYBRIDSWAP_WRITE_TIME : HYBRIDSWAP_READ_TIME; - - do { - hybp(HYB_DEBUG, "wait finish start\n"); - ret = wait_event_timeout(req->io_wait, - (!atomic_read(&req->extent_inflight)), - msecs_to_jiffies(wait_time)); - } while (!ret); -} - -static void hybridswap_inflight_inc(struct hybridswap_segment *segment) -{ - mutex_lock(&segment->req->refmutex); - kref_get(&segment->req->refcount); - mutex_unlock(&segment->req->refmutex); - atomic_add(segment->page_cnt, &segment->req->extent_inflight); -} - -static void hybridswap_inflight_dec(struct hybridswap_io_req *req, - int num) -{ - if ((atomic_sub_return(num, &req->extent_inflight) < - HYBRIDSWAP_MAX_INFILGHT_NUM) && req->limit_inflight_flag && - wq_has_sleeper(&req->io_wait)) - wake_up(&req->io_wait); -} - -static void hybridswap_io_end_wake_up(struct hybridswap_io_req *req) -{ - if (req->io_para.scenario == HYBRIDSWAP_FAULT_OUT) { - complete(&req->io_end_flag); - return; - } - - if (wq_has_sleeper(&req->io_wait)) - wake_up(&req->io_wait); -} - -static void hybridswap_io_entry_proc(struct hybridswap_segment *segment) -{ - int i; - struct hybridswap_io_req *req = segment->req; - struct hybridswap_key_point_record *record = req->io_para.record; - int page_num; - ktime_t callback_start; - unsigned long long callback_start_ravg_sum; - - for (i = 0; i < segment->extent_cnt; ++i) { - INIT_LIST_HEAD(&segment->io_entries_fifo[i]->list); - page_num = segment->io_entries_fifo[i]->pages_sz; - hybp(HYB_DEBUG, "extent_id[%d] %d page_num %d\n", - i, segment->io_entries_fifo[i]->ext_id, page_num); - callback_start = ktime_get(); - callback_start_ravg_sum = hybridswap_get_ravg_sum(); - if (req->io_para.done_callback) - req->io_para.done_callback(segment->io_entries_fifo[i], - 0, req); - hybridswap_perf_async_perf(record, HYBRIDSWAP_CALL_BACK, - callback_start, callback_start_ravg_sum); - hybridswap_inflight_dec(req, page_num); - } -} - -static void hybridswap_io_err_record(enum hybridswap_fail_point point, - struct hybridswap_io_req *req, int ext_id) -{ - if (req->io_para.scenario == HYBRIDSWAP_FAULT_OUT) - hybridswap_fail_record(point, 0, ext_id, - req->io_para.record->task_comm); -} - -static void hybridswap_stat_io_fail(enum hybridswap_scenario scenario) -{ - struct hybridswap_stat *stat = hybridswap_get_stat_obj(); - - if (!stat || (scenario >= HYBRIDSWAP_SCENARIO_BUTT)) - return; - - atomic64_inc(&stat->io_fail_cnt[scenario]); -} - -static void hybridswap_io_err_proc(struct hybridswap_io_req *req, - struct hybridswap_segment *segment) -{ - hybp(HYB_ERR, "segment sector 0x%llx, extent_cnt %d\n", - segment->segment_sector, segment->extent_cnt); - hybp(HYB_ERR, "scenario %u, bio_result %u\n", - req->io_para.scenario, segment->bio_result); - hybridswap_stat_io_fail(req->io_para.scenario); - hybridswap_io_err_record(HYBRIDSWAP_FAULT_OUT_IO_FAIL, req, - segment->io_entries_fifo[0]->ext_id); - hybridswap_inflight_dec(req, segment->page_cnt); - hybridswap_io_end_wake_up(req); - hybridswap_segment_free(req, segment); - kref_put_mutex(&req->refcount, hybridswap_io_req_release, - &req->refmutex); -} - -static void hybridswap_io_end_work(struct work_struct *work) -{ - struct hybridswap_segment *segment = - container_of(work, struct hybridswap_segment, endio_work); - struct hybridswap_io_req *req = segment->req; - struct hybridswap_key_point_record *record = req->io_para.record; - int old_nice = task_nice(current); - ktime_t work_start; - unsigned long long work_start_ravg_sum; - - if (unlikely(segment->bio_result)) { - hybridswap_io_err_proc(req, segment); - return; - } - - hybp(HYB_DEBUG, "segment sector 0x%llx, extent_cnt %d passed\n", - segment->segment_sector, segment->extent_cnt); - hybp(HYB_DEBUG, "scenario %u, bio_result %u passed\n", - req->io_para.scenario, segment->bio_result); - - set_user_nice(current, req->nice); - - hybridswap_perf_async_perf(record, HYBRIDSWAP_SCHED_WORK, - segment->time.end_io, 0); - work_start = ktime_get(); - work_start_ravg_sum = hybridswap_get_ravg_sum(); - - hybridswap_io_entry_proc(segment); - - hybridswap_perf_async_perf(record, HYBRIDSWAP_END_WORK, work_start, - work_start_ravg_sum); - - hybridswap_io_end_wake_up(req); - - kref_put_mutex(&req->refcount, hybridswap_io_req_release, - &req->refmutex); - kfree(segment); - - set_user_nice(current, old_nice); -} - -static void hybridswap_end_io(struct bio *bio) -{ - struct hybridswap_segment *segment = bio->bi_private; - struct hybridswap_io_req *req = NULL; - struct workqueue_struct *workqueue = NULL; - struct hybridswap_key_point_record *record = NULL; - - if (unlikely(!segment || !(segment->req))) { - hybp(HYB_ERR, "segment or req null\n"); - bio_put(bio); - - return; - } - - req = segment->req; - record = req->io_para.record; - - hybridswap_perf_async_perf(record, HYBRIDSWAP_END_IO, - segment->time.submit_bio, 0); - - workqueue = (req->io_para.scenario == HYBRIDSWAP_RECLAIM_IN) ? - hybridswap_proc_write_workqueue : hybridswap_proc_read_workqueue; - segment->time.end_io = ktime_get(); - segment->bio_result = bio->bi_status; - - queue_work(workqueue, &segment->endio_work); - bio_put(bio); -} - -static bool hybridswap_ext_merge_back( - struct hybridswap_segment *segment, - struct hybridswap_entry *io_entry) -{ - struct hybridswap_entry *tail_io_entry = - list_last_entry(&segment->io_entries, - struct hybridswap_entry, list); - - return ((tail_io_entry->addr + - tail_io_entry->pages_sz * HYBRIDSWAP_PAGE_SIZE_SECTOR) == - io_entry->addr); -} - -static bool hybridswap_ext_merge_front( - struct hybridswap_segment *segment, - struct hybridswap_entry *io_entry) -{ - struct hybridswap_entry *head_io_entry = - list_first_entry(&segment->io_entries, - struct hybridswap_entry, list); - - return (head_io_entry->addr == - (io_entry->addr + - io_entry->pages_sz * HYBRIDSWAP_PAGE_SIZE_SECTOR)); -} - -static bool hybridswap_ext_merge(struct hybridswap_io_req *req, - struct hybridswap_entry *io_entry) -{ - struct hybridswap_segment *segment = req->segment; - - if (segment == NULL) - return false; - - if ((segment->page_cnt + io_entry->pages_sz) > BIO_MAX_PAGES) - return false; - - if (hybridswap_ext_merge_front(segment, io_entry)) { - list_add(&io_entry->list, &segment->io_entries); - segment->io_entries_fifo[segment->extent_cnt++] = io_entry; - segment->segment_sector = io_entry->addr; - segment->page_cnt += io_entry->pages_sz; - return true; - } - - if (hybridswap_ext_merge_back(segment, io_entry)) { - list_add_tail(&io_entry->list, &segment->io_entries); - segment->io_entries_fifo[segment->extent_cnt++] = io_entry; - segment->page_cnt += io_entry->pages_sz; - return true; - } - - return false; -} - -static struct bio *hybridswap_bio_alloc(enum hybridswap_scenario scenario) -{ - gfp_t gfp = (scenario != HYBRIDSWAP_RECLAIM_IN) ? GFP_ATOMIC : GFP_NOIO; - struct bio *bio = bio_alloc(gfp, BIO_MAX_PAGES); - - if (!bio && (scenario == HYBRIDSWAP_FAULT_OUT)) - bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES); - - return bio; -} - -static int hybridswap_bio_add_page(struct bio *bio, - struct hybridswap_segment *segment) -{ - int i; - int k = 0; - struct hybridswap_entry *io_entry = NULL; - struct hybridswap_entry *tmp = NULL; - - list_for_each_entry_safe(io_entry, tmp, &segment->io_entries, list) { - for (i = 0; i < io_entry->pages_sz; i++) { - io_entry->dest_pages[i]->index = - bio->bi_iter.bi_sector + k; - if (unlikely(!bio_add_page(bio, - io_entry->dest_pages[i], PAGE_SIZE, 0))) { - return -EIO; - } - k += HYBRIDSWAP_PAGE_SIZE_SECTOR; - } - } - - return 0; -} - -static void hybridswap_set_bio_opf(struct bio *bio, - struct hybridswap_segment *segment) -{ - if (segment->req->io_para.scenario == HYBRIDSWAP_RECLAIM_IN) { - bio->bi_opf |= REQ_BACKGROUND; - return; - } - - bio->bi_opf |= REQ_SYNC; -} - -int hybridswap_submit_bio(struct hybridswap_segment *segment) -{ - unsigned int op = - (segment->req->io_para.scenario == HYBRIDSWAP_RECLAIM_IN) ? - REQ_OP_WRITE : REQ_OP_READ; - struct hybridswap_entry *head_io_entry = - list_first_entry(&segment->io_entries, - struct hybridswap_entry, list); - struct hybridswap_key_point_record *record = - segment->req->io_para.record; - struct bio *bio = NULL; - - hybridswap_perf_lat_start(record, HYBRIDSWAP_BIO_ALLOC); - bio = hybridswap_bio_alloc(segment->req->io_para.scenario); - hybridswap_perf_lat_end(record, HYBRIDSWAP_BIO_ALLOC); - if (unlikely(!bio)) { - hybp(HYB_ERR, "bio is null.\n"); - hybridswap_io_err_record(HYBRIDSWAP_FAULT_OUT_BIO_ALLOC_FAIL, - segment->req, segment->io_entries_fifo[0]->ext_id); - - return -ENOMEM; - } - - bio->bi_iter.bi_sector = segment->segment_sector; - bio_set_dev(bio, segment->req->io_para.bdev); - bio->bi_private = segment; - bio_set_op_attrs(bio, op, 0); - bio->bi_end_io = hybridswap_end_io; - hybridswap_set_bio_opf(bio, segment); - - if (unlikely(hybridswap_bio_add_page(bio, segment))) { - bio_put(bio); - hybp(HYB_ERR, "bio_add_page fail\n"); - hybridswap_io_err_record(HYBRIDSWAP_FAULT_OUT_BIO_ADD_FAIL, - segment->req, segment->io_entries_fifo[0]->ext_id); - - return -EIO; - } - - hybridswap_inflight_inc(segment); - hybp(HYB_DEBUG, "submit bio sector %llu ext_id %d\n", - segment->segment_sector, head_io_entry->ext_id); - hybp(HYB_DEBUG, "extent_cnt %d scenario %u\n", - segment->extent_cnt, segment->req->io_para.scenario); - - segment->req->page_cnt += segment->page_cnt; - segment->req->segment_cnt++; - segment->time.submit_bio = ktime_get(); - - hybridswap_perf_lat_start(record, HYBRIDSWAP_SUBMIT_BIO); - submit_bio(bio); - hybridswap_perf_lat_end(record, HYBRIDSWAP_SUBMIT_BIO); - - return 0; -} - -static int hybridswap_new_segment_init(struct hybridswap_io_req *req, - struct hybridswap_entry *io_entry) -{ - gfp_t gfp = (req->io_para.scenario != HYBRIDSWAP_RECLAIM_IN) ? - GFP_ATOMIC : GFP_NOIO; - struct hybridswap_segment *segment = NULL; - struct hybridswap_key_point_record *record = req->io_para.record; - - hybridswap_perf_lat_start(record, HYBRIDSWAP_SEGMENT_ALLOC); - segment = kzalloc(sizeof(struct hybridswap_segment), gfp); - if (!segment && (req->io_para.scenario == HYBRIDSWAP_FAULT_OUT)) - segment = kzalloc(sizeof(struct hybridswap_segment), GFP_NOIO); - hybridswap_perf_lat_end(record, HYBRIDSWAP_SEGMENT_ALLOC); - if (unlikely(!segment)) { - hybridswap_io_err_record(HYBRIDSWAP_FAULT_OUT_SEGMENT_ALLOC_FAIL, - req, io_entry->ext_id); - - return -ENOMEM; - } - - segment->req = req; - INIT_LIST_HEAD(&segment->io_entries); - list_add_tail(&io_entry->list, &segment->io_entries); - segment->io_entries_fifo[segment->extent_cnt++] = io_entry; - segment->page_cnt = io_entry->pages_sz; - INIT_WORK(&segment->endio_work, hybridswap_io_end_work); - segment->segment_sector = io_entry->addr; - req->segment = segment; - - return 0; -} - -static int hybridswap_io_submit(struct hybridswap_io_req *req, - bool merge_flag) -{ - int ret; - struct hybridswap_segment *segment = req->segment; - - if (!segment || ((merge_flag) && (segment->page_cnt < BIO_MAX_PAGES))) - return 0; - - hybridswap_limit_inflight(req); - - ret = hybridswap_submit_bio(segment); - if (unlikely(ret)) { - hybp(HYB_WARN, "submit bio failed, ret %d\n", ret); - hybridswap_segment_free(req, segment); - } - req->segment = NULL; - - return ret; -} - -static bool hybridswap_check_io_para_err(struct hybridswap_io *io_para) -{ - if (unlikely(!io_para)) { - hybp(HYB_ERR, "io_para null\n"); - - return true; - } - - if (unlikely(!io_para->bdev || - (io_para->scenario >= HYBRIDSWAP_SCENARIO_BUTT))) { - hybp(HYB_ERR, "io_para err, scenario %u\n", - io_para->scenario); - - return true; - } - - if (unlikely(!io_para->done_callback)) { - hybp(HYB_ERR, "done_callback err\n"); - - return true; - } - - return false; -} - -static bool hybridswap_check_entry_err( - struct hybridswap_entry *io_entry) -{ - int i; - - if (unlikely(!io_entry)) { - hybp(HYB_ERR, "io_entry null\n"); - - return true; - } - - if (unlikely((!io_entry->dest_pages) || - (io_entry->ext_id < 0) || - (io_entry->pages_sz > BIO_MAX_PAGES) || - (io_entry->pages_sz <= 0))) { - hybp(HYB_ERR, "ext_id %d, page_sz %d\n", io_entry->ext_id, - io_entry->pages_sz); - - return true; - } - - for (i = 0; i < io_entry->pages_sz; ++i) { - if (!io_entry->dest_pages[i]) { - hybp(HYB_ERR, "dest_pages[%d] is null\n", i); - return true; - } - } - - return false; -} - -static int hybridswap_io_extent(void *io_handler, - struct hybridswap_entry *io_entry) -{ - int ret; - struct hybridswap_io_req *req = (struct hybridswap_io_req *)io_handler; - - if (unlikely(hybridswap_check_entry_err(io_entry))) { - hybridswap_io_err_record(HYBRIDSWAP_FAULT_OUT_IO_ENTRY_PARA_FAIL, - req, io_entry ? io_entry->ext_id : -EINVAL); - req->io_para.done_callback(io_entry, -EIO, req); - - return -EFAULT; - } - - hybp(HYB_DEBUG, "ext id %d, pages_sz %d, addr %llx\n", - io_entry->ext_id, io_entry->pages_sz, - io_entry->addr); - - if (hybridswap_ext_merge(req, io_entry)) - return hybridswap_io_submit(req, true); - - ret = hybridswap_io_submit(req, false); - if (unlikely(ret)) { - hybp(HYB_ERR, "submit fail %d\n", ret); - req->io_para.done_callback(io_entry, -EIO, req); - - return ret; - } - - ret = hybridswap_new_segment_init(req, io_entry); - if (unlikely(ret)) { - hybp(HYB_ERR, "hybridswap_new_segment_init fail %d\n", ret); - req->io_para.done_callback(io_entry, -EIO, req); - - return ret; - } - - return 0; -} - -int hybridswap_schedule_init(void) -{ - if (hybridswap_schedule_init_flag) - return 0; - - hybridswap_proc_read_workqueue = alloc_workqueue("proc_hybridswap_read", - WQ_HIGHPRI | WQ_UNBOUND, 0); - if (unlikely(!hybridswap_proc_read_workqueue)) - return -EFAULT; - - hybridswap_proc_write_workqueue = alloc_workqueue("proc_hybridswap_write", - WQ_CPU_INTENSIVE, 0); - if (unlikely(!hybridswap_proc_write_workqueue)) { - destroy_workqueue(hybridswap_proc_read_workqueue); - - return -EFAULT; - } - - hybridswap_key_init(); - - hybridswap_schedule_init_flag = true; - - return 0; -} - -void *hybridswap_plug_start(struct hybridswap_io *io_para) -{ - gfp_t gfp; - struct hybridswap_io_req *req = NULL; - - if (unlikely(hybridswap_check_io_para_err(io_para))) - return NULL; - - gfp = (io_para->scenario != HYBRIDSWAP_RECLAIM_IN) ? - GFP_ATOMIC : GFP_NOIO; - req = kzalloc(sizeof(struct hybridswap_io_req), gfp); - if (!req && (io_para->scenario == HYBRIDSWAP_FAULT_OUT)) - req = kzalloc(sizeof(struct hybridswap_io_req), GFP_NOIO); - - if (unlikely(!req)) { - hybp(HYB_ERR, "io_req null\n"); - - return NULL; - } - - kref_init(&req->refcount); - mutex_init(&req->refmutex); - atomic_set(&req->extent_inflight, 0); - init_waitqueue_head(&req->io_wait); - req->io_para.bdev = io_para->bdev; - req->io_para.scenario = io_para->scenario; - req->io_para.done_callback = io_para->done_callback; - req->io_para.complete_notify = io_para->complete_notify; - req->io_para.private = io_para->private; - req->io_para.record = io_para->record; - req->limit_inflight_flag = - (io_para->scenario == HYBRIDSWAP_RECLAIM_IN) || - (io_para->scenario == HYBRIDSWAP_PRE_OUT); - req->wait_io_finish_flag = - (io_para->scenario == HYBRIDSWAP_RECLAIM_IN) || - (io_para->scenario == HYBRIDSWAP_FAULT_OUT); - req->nice = task_nice(current); - init_completion(&req->io_end_flag); - - return (void *)req; -} - -/* io_handler validity guaranteed by the caller */ -int hybridswap_read_extent(void *io_handler, - struct hybridswap_entry *io_entry) -{ - return hybridswap_io_extent(io_handler, io_entry); -} - -/* io_handler validity guaranteed by the caller */ -int hybridswap_write_extent(void *io_handler, - struct hybridswap_entry *io_entry) -{ - return hybridswap_io_extent(io_handler, io_entry); -} - -/* io_handler validity guaranteed by the caller */ -int hybridswap_plug_finish(void *io_handler) -{ - int ret; - struct hybridswap_io_req *req = (struct hybridswap_io_req *)io_handler; - - hybridswap_perf_lat_start(req->io_para.record, HYBRIDSWAP_IO_EXTENT); - ret = hybridswap_io_submit(req, false); - if (unlikely(ret)) - hybp(HYB_ERR, "submit fail %d\n", ret); - - hybridswap_perf_lat_end(req->io_para.record, HYBRIDSWAP_IO_EXTENT); - hybridswap_wait_io_finish(req); - hybridswap_perf_lat_point(req->io_para.record, HYBRIDSWAP_WAKE_UP); - - hybridswap_stat_io_bytes(req); - hybridswap_perf_io_stat(req->io_para.record, req->page_cnt, - req->segment_cnt); - - kref_put_mutex(&req->refcount, hybridswap_io_req_release, - &req->refmutex); - - hybp(HYB_DEBUG, "io schedule finish succ\n"); - - return ret; -} - diff --git a/drivers/block/zram/hybridswap/hybridswap_stats.c b/drivers/block/zram/hybridswap/hybridswap_stats.c deleted file mode 100755 index 0feee4264881..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_stats.c +++ /dev/null @@ -1,482 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_internal.h" -#include "hybridswap.h" - -#define SCENARIO_NAME_LEN 32 -#define MBYTE_SHIFT 20 - -static char scenario_name[HYBRIDSWAP_SCENARIO_BUTT][SCENARIO_NAME_LEN] = { - "reclaim_in", - "fault_out", - "batch_out", - "pre_out" -}; - -static char *fg_bg[2] = {"BG", "FG"}; - -static void hybridswap_lat_show(struct seq_file *m, - struct hybridswap_stat *stat) -{ - int i; - - for (i = 0; i < HYBRIDSWAP_SCENARIO_BUTT; ++i) { - seq_printf(m, "hybridswap_%s_total_lat: %lld\n", - scenario_name[i], - atomic64_read(&stat->lat[i].total_lat)); - seq_printf(m, "hybridswap_%s_max_lat: %lld\n", - scenario_name[i], - atomic64_read(&stat->lat[i].max_lat)); - seq_printf(m, "hybridswap_%s_timeout_cnt: %lld\n", - scenario_name[i], - atomic64_read(&stat->lat[i].timeout_cnt)); - } - - for (i = 0; i < 2; i++) { - seq_printf(m, "fault_out_timeout_100ms_cnt(%s): %lld\n", - fg_bg[i], - atomic64_read(&stat->fault_stat[i].timeout_100ms_cnt)); - seq_printf(m, "fault_out_timeout_500ms_cnt(%s): %lld\n", - fg_bg[i], - atomic64_read(&stat->fault_stat[i].timeout_500ms_cnt)); - } -} - -static void hybridswap_stats_show(struct seq_file *m, - struct hybridswap_stat *stat) -{ - seq_printf(m, "hybridswap_out_times: %lld\n", - atomic64_read(&stat->reclaimin_cnt)); - seq_printf(m, "hybridswap_out_comp_size: %lld MB\n", - atomic64_read(&stat->reclaimin_bytes) >> MBYTE_SHIFT); - if (PAGE_SHIFT < MBYTE_SHIFT) - seq_printf(m, "hybridswap_out_ori_size: %lld MB\n", - atomic64_read(&stat->reclaimin_pages) >> - (MBYTE_SHIFT - PAGE_SHIFT)); - seq_printf(m, "hybridswap_in_times: %lld\n", - atomic64_read(&stat->batchout_cnt)); - seq_printf(m, "hybridswap_in_comp_size: %lld MB\n", - atomic64_read(&stat->batchout_bytes) >> MBYTE_SHIFT); - if (PAGE_SHIFT < MBYTE_SHIFT) - seq_printf(m, "hybridswap_in_ori_size: %lld MB\n", - atomic64_read(&stat->batchout_pages) >> - (MBYTE_SHIFT - PAGE_SHIFT)); - seq_printf(m, "hybridswap_all_fault: %lld\n", - atomic64_read(&stat->fault_cnt)); - seq_printf(m, "hybridswap_fault: %lld\n", - atomic64_read(&stat->hybridswap_fault_cnt)); -} - -static void hybridswap_area_info_show(struct seq_file *m, - struct hybridswap_stat *stat) -{ - seq_printf(m, "hybridswap_reout_ori_size: %lld MB\n", - atomic64_read(&stat->reout_pages) >> - (MBYTE_SHIFT - PAGE_SHIFT)); - seq_printf(m, "hybridswap_reout_comp_size: %lld MB\n", - atomic64_read(&stat->reout_bytes) >> MBYTE_SHIFT); - seq_printf(m, "hybridswap_store_comp_size: %lld MB\n", - atomic64_read(&stat->stored_size) >> MBYTE_SHIFT); - seq_printf(m, "hybridswap_store_ori_size: %lld MB\n", - atomic64_read(&stat->stored_pages) >> - (MBYTE_SHIFT - PAGE_SHIFT)); - seq_printf(m, "hybridswap_notify_free_size: %lld MB\n", - atomic64_read(&stat->notify_free) >> - (MBYTE_SHIFT - EXTENT_SHIFT)); - seq_printf(m, "hybridswap_store_memcg_cnt: %lld\n", - atomic64_read(&stat->mcg_cnt)); - seq_printf(m, "hybridswap_store_extent_cnt: %lld\n", - atomic64_read(&stat->ext_cnt)); - seq_printf(m, "hybridswap_store_fragment_cnt: %lld\n", - atomic64_read(&stat->frag_cnt)); -} - -static void hybridswap_fail_show(struct seq_file *m, - struct hybridswap_stat *stat) -{ - int i; - - for (i = 0; i < HYBRIDSWAP_SCENARIO_BUTT; ++i) { - seq_printf(m, "hybridswap_%s_io_fail_cnt: %lld\n", - scenario_name[i], - atomic64_read(&stat->io_fail_cnt[i])); - seq_printf(m, "hybridswap_%s_alloc_fail_cnt: %lld\n", - scenario_name[i], - atomic64_read(&stat->alloc_fail_cnt[i])); - } -} - -int hybridswap_psi_show(struct seq_file *m, void *v) -{ - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return -EINVAL; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - return -EINVAL; - } - - hybridswap_stats_show(m, stat); - hybridswap_area_info_show(m, stat); - hybridswap_lat_show(m, stat); - hybridswap_fail_show(m, stat); - - return 0; -} - -unsigned long hybridswap_get_zram_used_pages(void) -{ - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return 0; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - - return 0; - } - - return atomic64_read(&stat->zram_stored_pages); -} - -unsigned long long hybridswap_get_zram_pagefault(void) -{ - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return 0; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - - return 0; - } - - return atomic64_read(&stat->fault_cnt); -} - -bool hybridswap_reclaim_work_running(void) -{ - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return false; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - - return 0; - } - - return atomic64_read(&stat->reclaimin_infight) ? true : false; -} - -unsigned long long hybridswap_read_mcg_stats(struct mem_cgroup *mcg, - enum hybridswap_mcg_member mcg_member) -{ - struct mem_cgroup_hybridswap *mcg_hybs; - - unsigned long long val = 0; - int extcnt; - - if (!hybridswap_core_enabled()) - return 0; - - mcg_hybs = MEMCGRP_ITEM_DATA(mcg); - if (!mcg_hybs) { - hybp(HYB_DEBUG, "NULL mcg_hybs\n"); - return 0; - } - - switch (mcg_member) { - case MCG_ZRAM_STORED_SZ: - val = atomic64_read(&mcg_hybs->zram_stored_size); - break; - case MCG_ZRAM_STORED_PG_SZ: - val = atomic64_read(&mcg_hybs->zram_page_size); - break; - case MCG_DISK_STORED_SZ: - val = atomic64_read(&mcg_hybs->hybridswap_stored_size); - break; - case MCG_DISK_STORED_PG_SZ: - val = atomic64_read(&mcg_hybs->hybridswap_stored_pages); - break; - case MCG_ANON_FAULT_CNT: - val = atomic64_read(&mcg_hybs->hybridswap_allfaultcnt); - break; - case MCG_DISK_FAULT_CNT: - val = atomic64_read(&mcg_hybs->hybridswap_faultcnt); - break; - case MCG_ESWAPOUT_CNT: - val = atomic64_read(&mcg_hybs->hybridswap_outcnt); - break; - case MCG_ESWAPOUT_SZ: - val = atomic64_read(&mcg_hybs->hybridswap_outextcnt) << EXTENT_SHIFT; - break; - case MCG_ESWAPIN_CNT: - val = atomic64_read(&mcg_hybs->hybridswap_incnt); - break; - case MCG_ESWAPIN_SZ: - val = atomic64_read(&mcg_hybs->hybridswap_inextcnt) << EXTENT_SHIFT; - break; - case MCG_DISK_SPACE: - extcnt = atomic_read(&mcg_hybs->hybridswap_extcnt); - if (extcnt < 0) - extcnt = 0; - val = ((unsigned long long) extcnt) << EXTENT_SHIFT; - break; - case MCG_DISK_SPACE_PEAK: - extcnt = atomic_read(&mcg_hybs->hybridswap_peakextcnt); - if (extcnt < 0) - extcnt = 0; - val = ((unsigned long long) extcnt) << EXTENT_SHIFT; - break; - default: - break; - } - - return val; -} - -void hybridswap_fail_record(enum hybridswap_fail_point point, - u32 index, int ext_id, unsigned char *task_comm) -{ - struct hybridswap_stat *stat = NULL; - unsigned long flags; - unsigned int copylen = strlen(task_comm) + 1; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - return; - } - - if (copylen > TASK_COMM_LEN) { - hybp(HYB_ERR, "task_comm len %d is err\n", copylen); - return; - } - - spin_lock_irqsave(&stat->record.lock, flags); - if (stat->record.num < MAX_FAIL_RECORD_NUM) { - stat->record.record[stat->record.num].point = point; - stat->record.record[stat->record.num].index = index; - stat->record.record[stat->record.num].ext_id = ext_id; - stat->record.record[stat->record.num].time = ktime_get(); - memcpy(stat->record.record[stat->record.num].task_comm, - task_comm, copylen); - stat->record.num++; - } - spin_unlock_irqrestore(&stat->record.lock, flags); -} - -static void hybridswap_fail_record_get( - struct hybridswap_fail_record_info *record_info) -{ - struct hybridswap_stat *stat = NULL; - unsigned long flags; - - if (!hybridswap_core_enabled()) - return; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - return; - } - - spin_lock_irqsave(&stat->record.lock, flags); - memcpy(record_info, &stat->record, - sizeof(struct hybridswap_fail_record_info)); - stat->record.num = 0; - spin_unlock_irqrestore(&stat->record.lock, flags); -} - -static ssize_t hybridswap_fail_record_show(char *buf) -{ - int i; - ssize_t size = 0; - struct hybridswap_fail_record_info record_info = { 0 }; - - hybridswap_fail_record_get(&record_info); - - size += scnprintf(buf + size, PAGE_SIZE, - "hybridswap_fail_record_num: %d\n", record_info.num); - for (i = 0; i < record_info.num; ++i) - size += scnprintf(buf + size, PAGE_SIZE - size, - "point[%u]time[%lld]taskname[%s]index[%u]ext_id[%d]\n", - record_info.record[i].point, - ktime_us_delta(ktime_get(), - record_info.record[i].time), - record_info.record[i].task_comm, - record_info.record[i].index, - record_info.record[i].ext_id); - - return size; -} - -ssize_t hybridswap_report_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return hybridswap_fail_record_show(buf); -} - -static inline meminfo_show(struct hybridswap_stat *stat, char *buf, ssize_t len) -{ - unsigned long eswap_total_pages = 0, eswap_compressed_pages = 0; - unsigned long eswap_used_pages = 0; - unsigned long zram_total_pags, zram_used_pages, zram_compressed; - ssize_t size = 0; - - if (!stat || !buf || !len) - return 0; - - (void)hybridswap_stored_info(&eswap_total_pages, &eswap_compressed_pages); - eswap_used_pages = atomic64_read(&stat->stored_pages); -#ifdef CONFIG_HYBRIDSWAP_SWAPD - zram_total_pags = get_nr_zram_total(); -#else - zram_total_pags = 0; -#endif - zram_compressed = atomic64_read(&stat->zram_stored_size); - zram_used_pages = atomic64_read(&stat->zram_stored_pages); - - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "EST:", eswap_total_pages << (PAGE_SHIFT - 10)); - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "ESU_C:", eswap_compressed_pages << (PAGE_SHIFT - 10)); - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "ESU_O:", eswap_used_pages << (PAGE_SHIFT - 10)); - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "ZST:", zram_total_pags << (PAGE_SHIFT - 10)); - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "ZSU_C:", zram_compressed >> 10); - size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n", - "ZSU_O:", zram_used_pages << (PAGE_SHIFT - 10)); - - return size; -} - -ssize_t hybridswap_stat_snap_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - ssize_t size = 0; - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return 0; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_INFO, "can't get stat obj!\n"); - return 0; - } - - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "reclaimin_cnt:", atomic64_read(&stat->reclaimin_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reclaimin_bytes:", atomic64_read(&stat->reclaimin_bytes) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reclaimin_real_load:", atomic64_read(&stat->reclaimin_real_load) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reclaimin_bytes_daily:", atomic64_read(&stat->reclaimin_bytes_daily) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reclaimin_pages:", atomic64_read(&stat->reclaimin_pages) * PAGE_SIZE / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "reclaimin_infight:", atomic64_read(&stat->reclaimin_infight)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "batchout_cnt:", atomic64_read(&stat->batchout_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "batchout_bytes:", atomic64_read(&stat->batchout_bytes) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "batchout_real_load:", atomic64_read(&stat->batchout_real_load) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "batchout_pages:", atomic64_read(&stat->batchout_pages) * PAGE_SIZE / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "batchout_inflight:", atomic64_read(&stat->batchout_inflight)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "fault_cnt:", atomic64_read(&stat->fault_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "hybridswap_fault_cnt:", atomic64_read(&stat->hybridswap_fault_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reout_pages:", atomic64_read(&stat->reout_pages) * PAGE_SIZE / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reout_bytes:", atomic64_read(&stat->reout_bytes) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "zram_stored_pages:", atomic64_read(&stat->zram_stored_pages) * PAGE_SIZE / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "zram_stored_size:", atomic64_read(&stat->zram_stored_size) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "stored_pages:", atomic64_read(&stat->stored_pages) * PAGE_SIZE / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "stored_size:", atomic64_read(&stat->stored_size) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n", - "reclain-batchout:", (atomic64_read(&stat->reclaimin_real_load) - - atomic64_read(&stat->batchout_real_load)) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12lld KB\n", - "reclain-batchout-stored:", - (atomic64_read(&stat->reclaimin_real_load) - - atomic64_read(&stat->batchout_real_load) - - atomic64_read(&stat->stored_size)) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12lld KB\n", - "dropped_ext_size:", atomic64_read(&stat->dropped_ext_size) / SZ_1K); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "notify_free:", atomic64_read(&stat->notify_free)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "frag_cnt:", atomic64_read(&stat->frag_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "mcg_cnt:", atomic64_read(&stat->mcg_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "ext_cnt:", atomic64_read(&stat->ext_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "miss_free:", atomic64_read(&stat->miss_free)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "mcgid_clear:", atomic64_read(&stat->mcgid_clear)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "skip_track_cnt:", atomic64_read(&stat->skip_track_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "null_memcg_skip_track_cnt:", - atomic64_read(&stat->null_memcg_skip_track_cnt)); - size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n", - "used_swap_pages:", atomic64_read(&stat->used_swap_pages) * PAGE_SIZE / SZ_1K); - size += meminfo_show(stat, buf + size, PAGE_SIZE - size); - - return size; -} - -ssize_t hybridswap_meminfo_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct hybridswap_stat *stat = NULL; - - if (!hybridswap_core_enabled()) - return 0; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_INFO, "can't get stat obj!\n"); - return 0; - } - - return meminfo_show(stat, buf, PAGE_SIZE); -} diff --git a/drivers/block/zram/hybridswap/hybridswap_swapd.c b/drivers/block/zram/hybridswap/hybridswap_swapd.c deleted file mode 100755 index 34bcbddae215..000000000000 --- a/drivers/block/zram/hybridswap/hybridswap_swapd.c +++ /dev/null @@ -1,1975 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2022 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -#include -#endif - -#include "../zram_drv.h" -#include "../zram_drv_internal.h" -#include "hybridswap_internal.h" - -enum swapd_pressure_level { - LEVEL_LOW = 0, - LEVEL_MEDIUM, - LEVEL_CRITICAL, - LEVEL_COUNT -}; - -struct swapd_param { - unsigned int min_score; - unsigned int max_score; - unsigned int ub_mem2zram_ratio; - unsigned int ub_zram2ufs_ratio; - unsigned int refault_threshold; -}; - -struct hybridswapd_task { - wait_queue_head_t swapd_wait; - atomic_t swapd_wait_flag; - struct task_struct *swapd; - struct cpumask swapd_bind_cpumask; -}; -#define PGDAT_ITEM_DATA(pgdat) ((struct hybridswapd_task*)(pgdat)->android_oem_data1) -#define PGDAT_ITEM(pgdat, item) (PGDAT_ITEM_DATA(pgdat)->item) - -#define AREA_ANON_REFAULT_THRESHOLD 22000 -#define ANON_REFAULT_SNAPSHOT_MIN_INTERVAL 200 -#define EMPTY_ROUND_SKIP_INTERNVAL 20 -#define MAX_SKIP_INTERVAL 1000 -#define EMPTY_ROUND_CHECK_THRESHOLD 10 -#define ZRAM_WM_RATIO 75 -#define COMPRESS_RATIO 30 -#define SWAPD_MAX_LEVEL_NUM 10 -#define SWAPD_DEFAULT_BIND_CPUS "0-3" -#define MAX_RECLAIMIN_SZ (200llu << 20) -#define page_to_kb(nr) (nr << (PAGE_SHIFT - 10)) -#define SWAPD_SHRINK_WINDOW (HZ * 10) -#define SWAPD_SHRINK_SIZE_PER_WINDOW 1024 -#define PAGES_TO_MB(pages) ((pages) >> 8) -#define PAGES_PER_1MB (1 << 8) - -unsigned long long global_anon_refault_ratio; -unsigned long long swapd_skip_interval; -bool last_round_is_empty; -unsigned long last_swapd_time; -struct eventfd_ctx *swapd_press_efd[LEVEL_COUNT]; -atomic64_t zram_wm_ratio = ATOMIC_LONG_INIT(ZRAM_WM_RATIO); -atomic64_t compress_ratio = ATOMIC_LONG_INIT(COMPRESS_RATIO); -atomic_t avail_buffers = ATOMIC_INIT(0); -atomic_t min_avail_buffers = ATOMIC_INIT(0); -atomic_t high_avail_buffers = ATOMIC_INIT(0); -atomic_t max_reclaim_size = ATOMIC_INIT(100); -atomic64_t free_swap_threshold = ATOMIC64_INIT(0); -atomic64_t zram_crit_thres = ATOMIC_LONG_INIT(0); -atomic64_t cpuload_threshold = ATOMIC_LONG_INIT(0); -atomic64_t area_anon_refault_threshold = ATOMIC_LONG_INIT(AREA_ANON_REFAULT_THRESHOLD); -atomic64_t anon_refault_snapshot_min_interval = ATOMIC_LONG_INIT(ANON_REFAULT_SNAPSHOT_MIN_INTERVAL); -atomic64_t empty_round_skip_interval = ATOMIC_LONG_INIT(EMPTY_ROUND_SKIP_INTERNVAL); -atomic64_t max_skip_interval = ATOMIC_LONG_INIT(MAX_SKIP_INTERVAL); -atomic64_t empty_round_check_threshold = ATOMIC_LONG_INIT(EMPTY_ROUND_CHECK_THRESHOLD); -static unsigned long reclaim_exceed_sleep_ms = 50; -static unsigned long all_totalreserve_pages; - -static wait_queue_head_t snapshotd_wait; -static atomic_t snapshotd_wait_flag; -static atomic_t snapshotd_init_flag = ATOMIC_LONG_INIT(0); -static struct task_struct *snapshotd_task; -static DEFINE_MUTEX(pressure_event_lock); -static pid_t swapd_pid = -1; -static unsigned long long area_last_anon_pagefault; -static unsigned long last_anon_snapshot_time; -static struct swapd_param zswap_param[SWAPD_MAX_LEVEL_NUM]; -static enum cpuhp_state swapd_online; -static struct zram *swapd_zram = NULL; -static u64 max_reclaimin_size = MAX_RECLAIMIN_SZ; -atomic_long_t fault_out_pause = ATOMIC_LONG_INIT(0); -atomic_long_t fault_out_pause_cnt = ATOMIC_LONG_INIT(0); -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -static struct notifier_block fb_notif; -static atomic_t display_off = ATOMIC_LONG_INIT(0); -#endif -static unsigned long swapd_shrink_window = SWAPD_SHRINK_WINDOW; -static unsigned long swapd_shrink_limit_per_window = SWAPD_SHRINK_SIZE_PER_WINDOW; -static unsigned long swapd_last_window_start; -static unsigned long swapd_last_window_shrink; -static atomic_t swapd_pause = ATOMIC_INIT(0); -static atomic_t swapd_enabled = ATOMIC_INIT(0); -static unsigned long swapd_nap_jiffies = 1; - -extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, - unsigned long nr_pages, - gfp_t gfp_mask, - bool may_swap); -#ifdef CONFIG_OPLUS_JANK -extern u32 get_cpu_load(u32 win_cnt, struct cpumask *mask); -#endif - -inline u64 get_zram_wm_ratio_value(void) -{ - return atomic64_read(&zram_wm_ratio); -} - -inline u64 get_compress_ratio_value(void) -{ - return atomic64_read(&compress_ratio); -} - -inline unsigned int get_avail_buffers_value(void) -{ - return atomic_read(&avail_buffers); -} - -inline unsigned int get_min_avail_buffers_value(void) -{ - return atomic_read(&min_avail_buffers); -} - -inline unsigned int get_high_avail_buffers_value(void) -{ - return atomic_read(&high_avail_buffers); -} - -inline u64 get_swapd_max_reclaim_size(void) -{ - return atomic_read(&max_reclaim_size); -} - -inline u64 get_free_swap_threshold_value(void) -{ - return atomic64_read(&free_swap_threshold); -} - -inline unsigned long long get_area_anon_refault_threshold_value(void) -{ - return atomic64_read(&area_anon_refault_threshold); -} - -inline unsigned long get_anon_refault_snapshot_min_interval_value(void) -{ - return atomic64_read(&anon_refault_snapshot_min_interval); -} - -inline unsigned long long get_empty_round_skip_interval_value(void) -{ - return atomic64_read(&empty_round_skip_interval); -} - -inline unsigned long long get_max_skip_interval_value(void) -{ - return atomic64_read(&max_skip_interval); -} - -inline unsigned long long get_empty_round_check_threshold_value(void) -{ - return atomic64_read(&empty_round_check_threshold); -} - -inline u64 get_zram_critical_threshold_value(void) -{ - return atomic64_read(&zram_crit_thres); -} - -inline u64 get_cpuload_threshold_value(void) -{ - return atomic64_read(&cpuload_threshold); -} - -static ssize_t avail_buffers_params_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - unsigned int avail_buffers_value; - unsigned int min_avail_buffers_value; - unsigned int high_avail_buffers_value; - u64 free_swap_threshold_value; - - buf = strstrip(buf); - - if (sscanf(buf, "%u %u %u %llu", - &avail_buffers_value, - &min_avail_buffers_value, - &high_avail_buffers_value, - &free_swap_threshold_value) != 4) - return -EINVAL; - - atomic_set(&avail_buffers, avail_buffers_value); - atomic_set(&min_avail_buffers, min_avail_buffers_value); - atomic_set(&high_avail_buffers, high_avail_buffers_value); - atomic64_set(&free_swap_threshold, - (free_swap_threshold_value * (SZ_1M / PAGE_SIZE))); - - if (atomic_read(&min_avail_buffers) == 0) - atomic_set(&snapshotd_init_flag, 0); - else - atomic_set(&snapshotd_init_flag, 1); - - wake_all_swapd(); - - return nbytes; -} - -static int avail_buffers_params_show(struct seq_file *m, void *v) -{ - seq_printf(m, "avail_buffers: %u\n", - atomic_read(&avail_buffers)); - seq_printf(m, "min_avail_buffers: %u\n", - atomic_read(&min_avail_buffers)); - seq_printf(m, "high_avail_buffers: %u\n", - atomic_read(&high_avail_buffers)); - seq_printf(m, "free_swap_threshold: %llu\n", - (atomic64_read(&free_swap_threshold) * PAGE_SIZE / SZ_1M)); - - return 0; -} - -static ssize_t swapd_max_reclaim_size_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - const unsigned int base = 10; - u32 max_reclaim_size_value; - int ret; - - buf = strstrip(buf); - ret = kstrtouint(buf, base, &max_reclaim_size_value); - if (ret) - return -EINVAL; - - atomic_set(&max_reclaim_size, max_reclaim_size_value); - - return nbytes; -} - -static int swapd_max_reclaim_size_show(struct seq_file *m, void *v) -{ - seq_printf(m, "swapd_max_reclaim_size: %u\n", - atomic_read(&max_reclaim_size)); - - return 0; -} - -static int area_anon_refault_threshold_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&area_anon_refault_threshold, val); - - return 0; -} - -static s64 area_anon_refault_threshold_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&area_anon_refault_threshold); -} - -static int empty_round_skip_interval_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&empty_round_skip_interval, val); - - return 0; -} - -static s64 empty_round_skip_interval_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&empty_round_skip_interval); -} - -static int max_skip_interval_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&max_skip_interval, val); - - return 0; -} - -static s64 max_skip_interval_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&max_skip_interval); -} - -static int empty_round_check_threshold_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&empty_round_check_threshold, val); - - return 0; -} - -static s64 empty_round_check_threshold_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&empty_round_check_threshold); -} - - -static int anon_refault_snapshot_min_interval_write( - struct cgroup_subsys_state *css, struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&anon_refault_snapshot_min_interval, val); - - return 0; -} - -static s64 anon_refault_snapshot_min_interval_read( - struct cgroup_subsys_state *css, struct cftype *cft) -{ - return atomic64_read(&anon_refault_snapshot_min_interval); -} - -static int zram_critical_thres_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&zram_crit_thres, val << (20 - PAGE_SHIFT)); - - return 0; -} - -static s64 zram_critical_thres_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&zram_crit_thres) >> (20 - PAGE_SHIFT); -} - -static s64 cpuload_threshold_read(struct cgroup_subsys_state *css, - struct cftype *cft) - -{ - return atomic64_read(&cpuload_threshold); -} - -static int cpuload_threshold_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - atomic64_set(&cpuload_threshold, val); - - return 0; -} - -static ssize_t swapd_pressure_event_control(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - int efd; - unsigned int level; - struct fd efile; - int ret; - - buf = strstrip(buf); - if (sscanf(buf, "%d %u", &efd, &level) != 2) - return -EINVAL; - - if (level >= LEVEL_COUNT) - return -EINVAL; - - if (efd < 0) - return -EBADF; - - mutex_lock(&pressure_event_lock); - efile = fdget(efd); - if (!efile.file) { - ret = -EBADF; - goto out; - } - swapd_press_efd[level] = eventfd_ctx_fileget(efile.file); - if (IS_ERR(swapd_press_efd[level])) { - ret = PTR_ERR(swapd_press_efd[level]); - goto out_put_efile; - } - fdput(efile); - mutex_unlock(&pressure_event_lock); - return nbytes; - -out_put_efile: - fdput(efile); -out: - mutex_unlock(&pressure_event_lock); - - return ret; -} - -void swapd_pressure_report(enum swapd_pressure_level level) -{ - int ret; - - if (swapd_press_efd[level] == NULL) - return; - - ret = eventfd_signal(swapd_press_efd[level], 1); - hybp(HYB_INFO, "SWAP-MM: level:%u, ret:%d ", level, ret); -} - -static s64 swapd_pid_read(struct cgroup_subsys_state *css, struct cftype *cft) -{ - return swapd_pid; -} - -static void swapd_memcgs_param_parse(int level_num) -{ - struct mem_cgroup *memcg = NULL; - memcg_hybs_t *hybs = NULL; - int i; - - while ((memcg = get_next_memcg(memcg))) { - hybs = MEMCGRP_ITEM_DATA(memcg); - - for (i = 0; i < level_num; ++i) { - if (atomic64_read(&hybs->app_score) >= zswap_param[i].min_score && - atomic64_read(&hybs->app_score) <= zswap_param[i].max_score) - break; - } - atomic_set(&hybs->ub_mem2zram_ratio, zswap_param[i].ub_mem2zram_ratio); - atomic_set(&hybs->ub_zram2ufs_ratio, zswap_param[i].ub_zram2ufs_ratio); - atomic_set(&hybs->refault_threshold, zswap_param[i].refault_threshold); - } -} - -static void update_swapd_memcg_hybs(memcg_hybs_t *hybs) -{ - int i; - - for (i = 0; i < SWAPD_MAX_LEVEL_NUM; ++i) { - if (!zswap_param[i].min_score && !zswap_param[i].max_score) - return; - - if (atomic64_read(&hybs->app_score) >= zswap_param[i].min_score && - atomic64_read(&hybs->app_score) <= zswap_param[i].max_score) - break; - } - - if (i == SWAPD_MAX_LEVEL_NUM) - return; - - atomic_set(&hybs->ub_mem2zram_ratio, zswap_param[i].ub_mem2zram_ratio); - atomic_set(&hybs->ub_zram2ufs_ratio, zswap_param[i].ub_zram2ufs_ratio); - atomic_set(&hybs->refault_threshold, zswap_param[i].refault_threshold); -} - -void update_swapd_memcg_param(struct mem_cgroup *memcg) -{ - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - - if (!hybs) - return; - - update_swapd_memcg_hybs(hybs); -} - -static int update_swapd_memcgs_param(char *buf) -{ - const char delim[] = " "; - char *token = NULL; - int level_num; - int i; - - buf = strstrip(buf); - token = strsep(&buf, delim); - - if (!token) - return -EINVAL; - - if (kstrtoint(token, 0, &level_num)) - return -EINVAL; - - if (level_num > SWAPD_MAX_LEVEL_NUM || level_num < 0) - return -EINVAL; - - mutex_lock(&reclaim_para_lock); - for (i = 0; i < level_num; ++i) { - token = strsep(&buf, delim); - if (!token) - goto out; - - if (kstrtoint(token, 0, &zswap_param[i].min_score) || - zswap_param[i].min_score > MAX_APP_SCORE) - goto out; - - token = strsep(&buf, delim); - if (!token) - goto out; - - if (kstrtoint(token, 0, &zswap_param[i].max_score) || - zswap_param[i].max_score > MAX_APP_SCORE) - goto out; - - token = strsep(&buf, delim); - if (!token) - goto out; - - if (kstrtoint(token, 0, &zswap_param[i].ub_mem2zram_ratio) || - zswap_param[i].ub_mem2zram_ratio > MAX_RATIO) - goto out; - - token = strsep(&buf, delim); - if (!token) - goto out; - - if (kstrtoint(token, 0, &zswap_param[i].ub_zram2ufs_ratio) || - zswap_param[i].ub_zram2ufs_ratio > MAX_RATIO) - goto out; - - token = strsep(&buf, delim); - if (!token) - goto out; - - if (kstrtoint(token, 0, &zswap_param[i].refault_threshold)) - goto out; - } - - swapd_memcgs_param_parse(level_num); - mutex_unlock(&reclaim_para_lock); - return 0; - -out: - mutex_unlock(&reclaim_para_lock); - return -EINVAL; -} - -static ssize_t swapd_memcgs_param_write(struct kernfs_open_file *of, char *buf, - size_t nbytes, loff_t off) -{ - int ret = update_swapd_memcgs_param(buf); - - if (ret) - return ret; - - return nbytes; -} - -static int swapd_memcgs_param_show(struct seq_file *m, void *v) -{ - int i; - - for (i = 0; i < SWAPD_MAX_LEVEL_NUM; ++i) { - seq_printf(m, "level %d min score: %u\n", - i, zswap_param[i].min_score); - seq_printf(m, "level %d max score: %u\n", - i, zswap_param[i].max_score); - seq_printf(m, "level %d ub_mem2zram_ratio: %u\n", - i, zswap_param[i].ub_mem2zram_ratio); - seq_printf(m, "level %d ub_zram2ufs_ratio: %u\n", - i, zswap_param[i].ub_zram2ufs_ratio); - seq_printf(m, "memcg %d refault_threshold: %u\n", - i, zswap_param[i].refault_threshold); - } - - return 0; -} - -static ssize_t swapd_nap_jiffies_write(struct kernfs_open_file *of, char *buf, - size_t nbytes, loff_t off) -{ - unsigned long nap; - - buf = strstrip(buf); - if (!buf) - return -EINVAL; - - if (kstrtoul(buf, 0, &nap)) - return -EINVAL; - - swapd_nap_jiffies = nap; - return nbytes; -} - -static int swapd_nap_jiffies_show(struct seq_file *m, void *v) -{ - seq_printf(m, "%lu\n", swapd_nap_jiffies); - - return 0; -} - -static ssize_t swapd_single_memcg_param_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); - unsigned int ub_mem2zram_ratio; - unsigned int ub_zram2ufs_ratio; - unsigned int refault_threshold; - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - - if (!hybs) - return -EINVAL; - - buf = strstrip(buf); - - if (sscanf(buf, "%u %u %u", &ub_mem2zram_ratio, &ub_zram2ufs_ratio, - &refault_threshold) != 3) - return -EINVAL; - - if (ub_mem2zram_ratio > MAX_RATIO || ub_zram2ufs_ratio > MAX_RATIO) - return -EINVAL; - - atomic_set(&MEMCGRP_ITEM(memcg, ub_mem2zram_ratio), ub_mem2zram_ratio); - atomic_set(&MEMCGRP_ITEM(memcg, ub_zram2ufs_ratio), ub_zram2ufs_ratio); - atomic_set(&MEMCGRP_ITEM(memcg, refault_threshold), refault_threshold); - - return nbytes; -} - - -static int swapd_single_memcg_param_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); - memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg); - - if (!hybs) - return -EINVAL; - - seq_printf(m, "memcg score: %lu\n", - atomic64_read(&hybs->app_score)); - seq_printf(m, "memcg ub_mem2zram_ratio: %u\n", - atomic_read(&hybs->ub_mem2zram_ratio)); - seq_printf(m, "memcg ub_zram2ufs_ratio: %u\n", - atomic_read(&hybs->ub_zram2ufs_ratio)); - seq_printf(m, "memcg refault_threshold: %u\n", - atomic_read(&hybs->refault_threshold)); - - return 0; -} - -static int mem_cgroup_zram_wm_ratio_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val > MAX_RATIO || val < MIN_RATIO) - return -EINVAL; - - atomic64_set(&zram_wm_ratio, val); - - return 0; -} - -static s64 mem_cgroup_zram_wm_ratio_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&zram_wm_ratio); -} - -static int mem_cgroup_compress_ratio_write(struct cgroup_subsys_state *css, - struct cftype *cft, s64 val) -{ - if (val > MAX_RATIO || val < MIN_RATIO) - return -EINVAL; - - atomic64_set(&compress_ratio, val); - - return 0; -} - -static s64 mem_cgroup_compress_ratio_read(struct cgroup_subsys_state *css, - struct cftype *cft) -{ - return atomic64_read(&compress_ratio); -} - -static int memcg_active_app_info_list_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = NULL; - unsigned long anon_size; - unsigned long zram_size; - unsigned long eswap_size; - - while ((memcg = get_next_memcg(memcg))) { - u64 score; - - if (!MEMCGRP_ITEM_DATA(memcg)) - continue; - - score = atomic64_read(&MEMCGRP_ITEM(memcg, app_score)); - anon_size = memcg_anon_pages(memcg); - eswap_size = hybridswap_read_mcg_stats(memcg, - MCG_DISK_STORED_PG_SZ); - zram_size = hybridswap_read_mcg_stats(memcg, - MCG_ZRAM_STORED_PG_SZ); - - if (anon_size + zram_size + eswap_size == 0) - continue; - - if (!strlen(MEMCGRP_ITEM(memcg, name))) - continue; - - anon_size *= PAGE_SIZE / SZ_1K; - zram_size *= PAGE_SIZE / SZ_1K; - eswap_size *= PAGE_SIZE / SZ_1K; - - seq_printf(m, "%s %llu %lu %lu %lu %llu\n", - MEMCGRP_ITEM(memcg, name), score, - anon_size, zram_size, eswap_size, - MEMCGRP_ITEM(memcg, reclaimed_pagefault)); - } - return 0; -} - -static unsigned long get_totalreserve_pages(void) -{ - int nid; - unsigned long val = 0; - - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat = NODE_DATA(nid); - - if (pgdat) - val += pgdat->totalreserve_pages; - } - - return val; -} - -unsigned int system_cur_avail_buffers(void) -{ - unsigned long reclaimable; - long buffers; - unsigned long pagecache; - unsigned long wmark_low = 0; - struct zone *zone; - - buffers = global_zone_page_state(NR_FREE_PAGES) - all_totalreserve_pages; - - for_each_zone(zone) - wmark_low += low_wmark_pages(zone); - pagecache = global_node_page_state(NR_ACTIVE_FILE) + - global_node_page_state(NR_INACTIVE_FILE); - pagecache -= min(pagecache / 2, wmark_low); - buffers += pagecache; - - reclaimable = global_node_page_state(NR_SLAB_RECLAIMABLE) + - global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE); - buffers += reclaimable - min(reclaimable / 2, wmark_low); - - if (buffers < 0) - buffers = 0; - - return buffers >> 8; /* pages to MB */ -} - -static bool min_buffer_is_suitable(void) -{ - u32 curr_buffers = system_cur_avail_buffers(); - - if (curr_buffers >= get_min_avail_buffers_value()) - return true; - - return false; -} - -static bool buffer_is_suitable(void) -{ - u32 curr_buffers = system_cur_avail_buffers(); - - if (curr_buffers >= get_avail_buffers_value()) - return true; - - return false; -} - -bool high_buffer_is_suitable(void) -{ - u32 curr_buffers = system_cur_avail_buffers(); - - if (curr_buffers >= get_high_avail_buffers_value()) - return true; - - return false; -} - -static void snapshot_anon_refaults(void) -{ - struct mem_cgroup *memcg = NULL; - - while ((memcg = get_next_memcg(memcg))) { - MEMCGRP_ITEM(memcg, reclaimed_pagefault) = - hybridswap_read_mcg_stats(memcg, MCG_ANON_FAULT_CNT); - } - - area_last_anon_pagefault = hybridswap_get_zram_pagefault(); - last_anon_snapshot_time = jiffies; -} - -/* - * Return true means skip reclaim. - */ -bool get_memcg_anon_refault_status(struct mem_cgroup *memcg, - pg_data_t *pgdat) -{ - const unsigned int percent_constant = 100; - unsigned long long cur_anon_pagefault; - unsigned long anon_total; - unsigned long long ratio, thresh; - memcg_hybs_t *hybs; - - if (!memcg || !MEMCGRP_ITEM_DATA(memcg)) - return false; - - hybs = MEMCGRP_ITEM_DATA(memcg); - thresh = atomic_read(&hybs->refault_threshold); - if (thresh == 0) - return false; - - cur_anon_pagefault = hybridswap_read_mcg_stats(memcg, MCG_ANON_FAULT_CNT); - if (cur_anon_pagefault == hybs->reclaimed_pagefault) - return false; - - anon_total = memcg_anon_pages(memcg) + - hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ) + - hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ); - ratio = (cur_anon_pagefault - hybs->reclaimed_pagefault) * - percent_constant / (anon_total + 1); - hybp(HYB_INFO, "memcg %16s ratio %8llu threshold %8llu\n", hybs->name, - ratio, thresh); - - if (ratio >= thresh) - return true; - - return false; -} - -static bool hybridswap_ratio_ok(void) -{ - struct hybridswap_stat *stat = NULL; - - stat = hybridswap_get_stat_obj(); - if (unlikely(!stat)) { - hybp(HYB_ERR, "can't get stat obj!\n"); - - return false; - } - - return (atomic64_read(&stat->zram_stored_pages) > - atomic64_read(&stat->stored_pages)); -} - -static bool get_area_anon_refault_status(void) -{ - const unsigned int percent_constant = 1000; - unsigned long long cur_anon_pagefault; - unsigned long long cur_time; - unsigned long long ratio = 0; - - cur_anon_pagefault = hybridswap_get_zram_pagefault(); - cur_time = jiffies; - - if (cur_anon_pagefault == area_last_anon_pagefault - || cur_time == last_anon_snapshot_time) - goto false_out; - - ratio = (cur_anon_pagefault - area_last_anon_pagefault) * - percent_constant / (jiffies_to_msecs(cur_time - - last_anon_snapshot_time) + 1); - - global_anon_refault_ratio = ratio; - - if (ratio > get_area_anon_refault_threshold_value()) - return true; - - hybp(HYB_INFO, "current %llu t %llu last %llu t %llu ratio %llu refault_ratio %llu\n", - cur_anon_pagefault, cur_time, - area_last_anon_pagefault, last_anon_snapshot_time, - ratio, area_anon_refault_threshold); -false_out: - return false; -} - -static int reclaim_exceed_sleep_ms_write( - struct cgroup_subsys_state *css, struct cftype *cft, s64 val) -{ - if (val < 0) - return -EINVAL; - - reclaim_exceed_sleep_ms = val; - - return 0; -} - -static s64 reclaim_exceed_sleep_ms_read( - struct cgroup_subsys_state *css, struct cftype *cft) -{ - return reclaim_exceed_sleep_ms; -} - -static int max_reclaimin_size_mb_write( - struct cgroup_subsys_state *css, struct cftype *cft, u64 val) -{ - max_reclaimin_size = (val << 20); - - return 0; -} - -static u64 max_reclaimin_size_mb_read( - struct cgroup_subsys_state *css, struct cftype *cft) -{ - return max_reclaimin_size >> 20; -} - -static ssize_t swapd_shrink_parameter_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - unsigned long window, limit; - - buf = strstrip(buf); - if (sscanf(buf, "%lu %lu", &window, &limit) != 2) - return -EINVAL; - - swapd_shrink_window = msecs_to_jiffies(window); - swapd_shrink_limit_per_window = limit; - - return nbytes; -} - -static int swapd_shrink_parameter_show(struct seq_file *m, void *v) -{ - seq_printf(m, "%-32s %lu(jiffies) %u(msec)\n", "swapd_shrink_window", - swapd_shrink_window, jiffies_to_msecs(swapd_shrink_window)); - seq_printf(m, "%-32s %lu MB\n", "swapd_shrink_limit_per_window", - swapd_shrink_limit_per_window); - seq_printf(m, "%-32s %u msec\n", "swapd_last_window", - jiffies_to_msecs(jiffies - swapd_last_window_start)); - seq_printf(m, "%-32s %lu MB\n", "swapd_last_window_shrink", - swapd_last_window_shrink); - - return 0; -} - -static int swapd_update_cpumask(struct task_struct *tsk, char *buf, - struct pglist_data *pgdat) -{ - int retval; - struct cpumask temp_mask; - const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id); - struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat); - - if (unlikely(!hyb_task)) { - hybp(HYB_ERR, "set task %s cpumask %s node %d failed, " - "hyb_task is NULL\n", tsk->comm, buf, pgdat->node_id); - return -EINVAL; - } - - cpumask_clear(&temp_mask); - retval = cpulist_parse(buf, &temp_mask); - if (retval < 0 || cpumask_empty(&temp_mask)) { - hybp(HYB_ERR, "%s are invalid, use default\n", buf); - goto use_default; - } - - if (!cpumask_subset(&temp_mask, cpu_present_mask)) { - hybp(HYB_ERR, "%s is not subset of cpu_present_mask, use default\n", - buf); - goto use_default; - } - - if (!cpumask_subset(&temp_mask, cpumask)) { - hybp(HYB_ERR, "%s is not subset of cpumask, use default\n", buf); - goto use_default; - } - - set_cpus_allowed_ptr(tsk, &temp_mask); - cpumask_copy(&hyb_task->swapd_bind_cpumask, &temp_mask); - return 0; - -use_default: - if (cpumask_empty(&hyb_task->swapd_bind_cpumask)) - set_cpus_allowed_ptr(tsk, cpumask); - return -EINVAL; -} - -static ssize_t swapd_bind_write(struct kernfs_open_file *of, char *buf, - size_t nbytes, loff_t off) -{ - int ret = 0, nid; - struct pglist_data *pgdat; - - buf = strstrip(buf); - for_each_node_state(nid, N_MEMORY) { - pgdat = NODE_DATA(nid); - if (!PGDAT_ITEM_DATA(pgdat)) - continue; - - if (PGDAT_ITEM(pgdat, swapd)) { - ret = swapd_update_cpumask(PGDAT_ITEM(pgdat, swapd), - buf, pgdat); - if (ret) - break; - } - } - - if (ret) - return ret; - - return nbytes; -} - -static int swapd_bind_read(struct seq_file *m, void *v) -{ - int nid; - struct pglist_data *pgdat; - struct hybridswapd_task* hyb_task; - - seq_printf(m, "%4s %s\n", "Node", "mask"); - for_each_node_state(nid, N_MEMORY) { - pgdat = NODE_DATA(nid); - hyb_task = PGDAT_ITEM_DATA(pgdat); - if (!hyb_task) - continue; - - if (!hyb_task->swapd) - continue; - seq_printf(m, "%4d %*pbl\n", nid, - cpumask_pr_args(&hyb_task->swapd_bind_cpumask)); - } - - return 0; -} - -struct cftype mem_cgroup_swapd_legacy_files[] = { - { - .name = "active_app_info_list", - .flags = CFTYPE_ONLY_ON_ROOT, - .seq_show = memcg_active_app_info_list_show, - }, - { - .name = "zram_wm_ratio", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_zram_wm_ratio_write, - .read_s64 = mem_cgroup_zram_wm_ratio_read, - }, - { - .name = "compress_ratio", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = mem_cgroup_compress_ratio_write, - .read_s64 = mem_cgroup_compress_ratio_read, - }, - { - .name = "swapd_pressure", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_pressure_event_control, - }, - { - .name = "swapd_pid", - .flags = CFTYPE_ONLY_ON_ROOT, - .read_s64 = swapd_pid_read, - }, - { - .name = "avail_buffers", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = avail_buffers_params_write, - .seq_show = avail_buffers_params_show, - }, - { - .name = "swapd_max_reclaim_size", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_max_reclaim_size_write, - .seq_show = swapd_max_reclaim_size_show, - }, - { - .name = "area_anon_refault_threshold", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = area_anon_refault_threshold_write, - .read_s64 = area_anon_refault_threshold_read, - }, - { - .name = "empty_round_skip_interval", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = empty_round_skip_interval_write, - .read_s64 = empty_round_skip_interval_read, - }, - { - .name = "max_skip_interval", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = max_skip_interval_write, - .read_s64 = max_skip_interval_read, - }, - { - .name = "empty_round_check_threshold", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = empty_round_check_threshold_write, - .read_s64 = empty_round_check_threshold_read, - }, - { - .name = "anon_refault_snapshot_min_interval", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = anon_refault_snapshot_min_interval_write, - .read_s64 = anon_refault_snapshot_min_interval_read, - }, - { - .name = "swapd_memcgs_param", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_memcgs_param_write, - .seq_show = swapd_memcgs_param_show, - }, - { - .name = "swapd_single_memcg_param", - .flags = CFTYPE_WORLD_WRITABLE, - .write = swapd_single_memcg_param_write, - .seq_show = swapd_single_memcg_param_show, - }, - { - .name = "zram_critical_threshold", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = zram_critical_thres_write, - .read_s64 = zram_critical_thres_read, - }, - { - .name = "cpuload_threshold", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = cpuload_threshold_write, - .read_s64 = cpuload_threshold_read, - }, - { - .name = "reclaim_exceed_sleep_ms", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_s64 = reclaim_exceed_sleep_ms_write, - .read_s64 = reclaim_exceed_sleep_ms_read, - }, - { - .name = "swapd_bind", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_bind_write, - .seq_show = swapd_bind_read, - }, - { - .name = "max_reclaimin_size_mb", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write_u64 = max_reclaimin_size_mb_write, - .read_u64 = max_reclaimin_size_mb_read, - }, - { - .name = "swapd_shrink_parameter", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_shrink_parameter_write, - .seq_show = swapd_shrink_parameter_show, - }, - { - .name = "swapd_nap_jiffies", - .flags = CFTYPE_ONLY_ON_ROOT | CFTYPE_WORLD_WRITABLE, - .write = swapd_nap_jiffies_write, - .seq_show = swapd_nap_jiffies_show, - }, - { }, /* terminate */ -}; - -void wakeup_snapshotd(void) -{ - unsigned long curr_snapshot_interval = - jiffies_to_msecs(jiffies - last_anon_snapshot_time); - - if (curr_snapshot_interval >= - get_anon_refault_snapshot_min_interval_value()) { - atomic_set(&snapshotd_wait_flag, 1); - wake_up_interruptible(&snapshotd_wait); - } -} - -static int snapshotd(void *p) -{ - int ret; - - while (!kthread_should_stop()) { - ret = wait_event_interruptible(snapshotd_wait, - atomic_read(&snapshotd_wait_flag)); - if (ret) - continue; - - if (unlikely(kthread_should_stop())) - break; - - atomic_set(&snapshotd_wait_flag, 0); - - snapshot_anon_refaults(); - count_swapd_event(SWAPD_SNAPSHOT_TIMES); - } - - return 0; -} - -static int snapshotd_run(void) -{ - atomic_set(&snapshotd_wait_flag, 0); - init_waitqueue_head(&snapshotd_wait); - snapshotd_task = kthread_run(snapshotd, NULL, "snapshotd"); - - if (IS_ERR(snapshotd_task)) { - hybp(HYB_ERR, "Failed to start snapshotd\n"); - return PTR_ERR(snapshotd_task); - } - - return 0; -} - -static void snapshotd_exit(void) -{ - if (snapshotd_task) { - atomic_set(&snapshotd_wait_flag, 1); - kthread_stop(snapshotd_task); - } - snapshotd_task = NULL; -} - -unsigned long get_nr_zram_total(void) -{ - unsigned long nr_zram = 1; - - if (!swapd_zram) - return nr_zram; - - nr_zram = swapd_zram->disksize >> PAGE_SHIFT; -#if (defined CONFIG_ZRAM_WRITEBACK) || (defined CONFIG_HYBRIDSWAP_CORE) - nr_zram -= swapd_zram->increase_nr_pages; -#endif - return nr_zram; -} - -bool zram_watermark_ok(void) -{ - long long diff_buffers; - long long wm = 0; - long long cur_ratio = 0; - unsigned long zram_used = hybridswap_get_zram_used_pages(); - const unsigned int percent_constant = 100; - - diff_buffers = get_high_avail_buffers_value() - - system_cur_avail_buffers(); - diff_buffers *= SZ_1M / PAGE_SIZE; - diff_buffers *= get_compress_ratio_value() / 10; - diff_buffers = diff_buffers * percent_constant / get_nr_zram_total(); - - cur_ratio = zram_used * percent_constant / get_nr_zram_total(); - wm = min(get_zram_wm_ratio_value(), get_zram_wm_ratio_value()- diff_buffers); - - return cur_ratio > wm; -} - -bool free_zram_is_ok(void) -{ - unsigned long nr_used = hybridswap_get_zram_used_pages(); - unsigned long nr_total = get_nr_zram_total(); - unsigned long reserve = nr_total >> 6; - - return (nr_used < (nr_total - reserve)); -} - -static bool zram_need_swapout(void) -{ - bool zram_wm_ok = zram_watermark_ok(); - bool avail_buffer_wm_ok = !high_buffer_is_suitable(); - bool ufs_wm_ok = true; - -#ifdef CONFIG_HYBRIDSWAP_CORE - ufs_wm_ok = hybridswap_stored_wm_ok(); -#endif - - if (zram_wm_ok && avail_buffer_wm_ok && ufs_wm_ok) - return true; - - hybp(HYB_INFO, "zram_wm_ok %d avail_buffer_wm_ok %d ufs_wm_ok %d\n", - zram_wm_ok, avail_buffer_wm_ok, ufs_wm_ok); - - return false; -} - -bool zram_watermark_exceed(void) -{ - u64 nr_zram_used; - u64 nr_wm = get_zram_critical_threshold_value(); - - if (!nr_wm) - return false; - - nr_zram_used = hybridswap_get_zram_used_pages(); - - if (nr_zram_used > nr_wm) - return true; - - return false; -} - - -#ifdef CONFIG_OPLUS_JANK -static bool is_cpu_busy(void) -{ - unsigned int cpuload = 0; - int i; - struct cpumask mask; - - cpumask_clear(&mask); - - for (i = 0; i < 6; i++) - cpumask_set_cpu(i, &mask); - - cpuload = get_cpu_load(1, &mask); - if (cpuload > get_cpuload_threshold_value()) { - hybp(HYB_INFO, "cpuload %d\n", cpuload); - return true; - } - - return false; -} -#endif - -static void wakeup_swapd(pg_data_t *pgdat) -{ - unsigned long curr_interval; - struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat); - - if (!hyb_task || !hyb_task->swapd) - return; - - if (atomic_read(&swapd_pause)) { - count_swapd_event(SWAPD_MANUAL_PAUSE); - return; - } - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if (atomic_read(&display_off)) - return; -#endif - - if (!waitqueue_active(&hyb_task->swapd_wait)) - return; - - /* make anon pagefault snapshots */ - if (atomic_read(&snapshotd_init_flag) == 1) - wakeup_snapshotd(); - - /* wake up when the buffer is lower than min_avail_buffer */ - if (min_buffer_is_suitable()) { - count_swapd_event(SWAPD_OVER_MIN_BUFFER_SKIP_TIMES); - return; - } - - curr_interval = jiffies_to_msecs(jiffies - last_swapd_time); - if (curr_interval < swapd_skip_interval) { - count_swapd_event(SWAPD_EMPTY_ROUND_SKIP_TIMES); - return; - } - - atomic_set(&hyb_task->swapd_wait_flag, 1); - wake_up_interruptible(&hyb_task->swapd_wait); -} - -void wake_all_swapd(void) -{ - pg_data_t *pgdat = NULL; - int nid; - - for_each_online_node(nid) { - pgdat = NODE_DATA(nid); - wakeup_swapd(pgdat); - } -} - -bool free_swap_is_low(void) -{ - struct sysinfo info; - - si_swapinfo(&info); - - return (info.freeswap < get_free_swap_threshold_value()); -} -EXPORT_SYMBOL(free_swap_is_low); - -static inline u64 __calc_nr_to_reclaim(void) -{ - u32 curr_buffers; - u64 high_buffers; - u64 max_reclaim_size_value; - u64 reclaim_size = 0; - - high_buffers = get_high_avail_buffers_value(); - curr_buffers = system_cur_avail_buffers(); - max_reclaim_size_value = get_swapd_max_reclaim_size(); - if (curr_buffers < high_buffers) - reclaim_size = high_buffers - curr_buffers; - - reclaim_size = min(reclaim_size, max_reclaim_size_value); - - return reclaim_size * SZ_1M / PAGE_SIZE; -} - -static inline u64 calc_shrink_ratio(pg_data_t *pgdat) -{ - struct mem_cgroup *memcg = NULL; - const u32 percent_constant = 100; - u64 total_can_reclaimed = 0; - - while ((memcg = get_next_memcg(memcg))) { - s64 nr_anon, nr_zram, nr_eswap, total, can_reclaimed, thresh; - memcg_hybs_t *hybs; - - hybs = MEMCGRP_ITEM_DATA(memcg); - thresh = atomic_read(&hybs->ub_mem2zram_ratio); - if (!thresh || get_memcg_anon_refault_status(memcg, pgdat)) { - hybs->can_reclaimed = 0; - continue; - } - - nr_anon = memcg_anon_pages(memcg); - nr_zram = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ); - nr_eswap = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ); - total = nr_anon + nr_zram + nr_eswap; - - can_reclaimed = total * thresh / percent_constant; - if (can_reclaimed <= (nr_zram + nr_eswap)) - hybs->can_reclaimed = 0; - else - hybs->can_reclaimed = can_reclaimed - (nr_zram + nr_eswap); - hybp(HYB_INFO, "memcg %s can_reclaimed %lu nr_anon %lu zram %lu eswap %lu total %lu ratio %lu thresh %lu\n", - hybs->name, page_to_kb(hybs->can_reclaimed), - page_to_kb(nr_anon), page_to_kb(nr_zram), - page_to_kb(nr_eswap), page_to_kb(total), - (nr_zram + nr_eswap) * 100 / (total + 1), - thresh); - total_can_reclaimed += hybs->can_reclaimed; - } - - return total_can_reclaimed; -} - -static unsigned long swapd_shrink_anon(pg_data_t *pgdat, - unsigned long nr_to_reclaim) -{ - struct mem_cgroup *memcg = NULL; - unsigned long nr_reclaimed = 0; - unsigned long reclaim_memcg_cnt = 0; - u64 total_can_reclaimed = calc_shrink_ratio(pgdat); - unsigned long start_js = jiffies; - unsigned long reclaim_cycles; - bool exit = false; - unsigned long reclaim_size_per_cycle = PAGES_PER_1MB >> 1; - - if (unlikely(total_can_reclaimed == 0)) - goto out; - - if (total_can_reclaimed < nr_to_reclaim) - nr_to_reclaim = total_can_reclaimed; - - reclaim_cycles = nr_to_reclaim / reclaim_size_per_cycle; - while (reclaim_cycles) { - while ((memcg = get_next_memcg(memcg))) { - unsigned long memcg_nr_reclaimed, memcg_to_reclaim; - memcg_hybs_t *hybs; - - if (high_buffer_is_suitable()) { - get_next_memcg_break(memcg); - exit = true; - break; - } - - hybs = MEMCGRP_ITEM_DATA(memcg); - if (!hybs->can_reclaimed) - continue; - - memcg_to_reclaim = reclaim_size_per_cycle * hybs->can_reclaimed / total_can_reclaimed; - memcg_nr_reclaimed = try_to_free_mem_cgroup_pages(memcg, - memcg_to_reclaim, GFP_KERNEL, true); - reclaim_memcg_cnt++; - hybs->can_reclaimed -= memcg_nr_reclaimed; - hybp(HYB_INFO, "memcg %s reclaim %lu want %lu\n", hybs->name, - memcg_nr_reclaimed, memcg_to_reclaim); - nr_reclaimed += memcg_nr_reclaimed; - if (nr_reclaimed >= nr_to_reclaim) { - get_next_memcg_break(memcg); - exit = true; - break; - } - - if (hybs->can_reclaimed < 0) - hybs->can_reclaimed = 0; - - if (swapd_nap_jiffies && time_after_eq(jiffies, start_js + swapd_nap_jiffies)) { - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout((jiffies - start_js) * 2); - start_js = jiffies; - } - } - if (exit) - break; - reclaim_cycles--; - } - -out: - hybp(HYB_INFO, "total_reclaim %lu nr_to_reclaim %lu from memcg %lu total_can_reclaimed %lu\n", - page_to_kb(nr_reclaimed), page_to_kb(nr_to_reclaim), - reclaim_memcg_cnt, page_to_kb(total_can_reclaimed)); - return nr_reclaimed; -} - -static void swapd_shrink_node(pg_data_t *pgdat) -{ - const unsigned int increase_rate = 2; - unsigned long nr_reclaimed = 0; - unsigned long nr_to_reclaim; - unsigned int before_avail = system_cur_avail_buffers(); - unsigned int after_avail; - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if (atomic_read(&display_off)) - return; -#endif - - if (high_buffer_is_suitable()) - return; - -#ifdef CONFIG_OPLUS_JANK - if (is_cpu_busy()) { - count_swapd_event(SWAPD_CPU_BUSY_BREAK_TIMES); - return; - } -#endif - - if ((jiffies - swapd_last_window_start) < swapd_shrink_window) { - if (swapd_last_window_shrink >= swapd_shrink_limit_per_window) { - count_swapd_event(SWAPD_SKIP_SHRINK_OF_WINDOW); - hybp(HYB_INFO, "swapd_last_window_shrink %lu, skip shrink\n", - swapd_last_window_shrink); - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(msecs_to_jiffies(reclaim_exceed_sleep_ms)); - return; - } - } else { - swapd_last_window_start = jiffies; - swapd_last_window_shrink = 0lu; - } - - nr_to_reclaim = __calc_nr_to_reclaim(); - if (!nr_to_reclaim) - return; - - count_swapd_event(SWAPD_SHRINK_ANON); - nr_reclaimed = swapd_shrink_anon(pgdat, nr_to_reclaim); - swapd_last_window_shrink += PAGES_TO_MB(nr_reclaimed); - - if (nr_reclaimed < get_empty_round_check_threshold_value()) { - count_swapd_event(SWAPD_EMPTY_ROUND); - if (last_round_is_empty) - swapd_skip_interval = min(swapd_skip_interval * - increase_rate, - get_max_skip_interval_value()); - else - swapd_skip_interval = - get_empty_round_skip_interval_value(); - last_round_is_empty = true; - } else { - swapd_skip_interval = 0; - last_round_is_empty = false; - } - - after_avail = system_cur_avail_buffers(); - hybp(HYB_INFO, "total_reclaimed %lu KB, avail buffer %lu %lu MB, swapd_skip_interval %llu\n", - nr_reclaimed * 4, before_avail, after_avail, swapd_skip_interval); -} - -static int swapd(void *p) -{ - pg_data_t *pgdat = (pg_data_t *)p; - struct task_struct *tsk = current; - struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat); - static unsigned long last_reclaimin_jiffies = 0; - long fault_out_pause_value; - int display_un_blank = 1; - - /* save swapd pid for schedule strategy */ - swapd_pid = tsk->pid; - - /* swapd do not runnint on super core */ - cpumask_clear(&hyb_task->swapd_bind_cpumask); - (void)swapd_update_cpumask(tsk, SWAPD_DEFAULT_BIND_CPUS, pgdat); - set_freezable(); - - swapd_last_window_start = jiffies - swapd_shrink_window; - while (!kthread_should_stop()) { - bool refault = false; - u64 curr_buffers, avail; - u64 size, swapout_size = 0; - - wait_event_freezable(hyb_task->swapd_wait, - atomic_read(&hyb_task->swapd_wait_flag)); - atomic_set(&hyb_task->swapd_wait_flag, 0); - if (unlikely(kthread_should_stop())) - break; - count_swapd_event(SWAPD_WAKEUP); - /*swapd_pressure_report(LEVEL_LOW);*/ - - if (get_area_anon_refault_status() && hybridswap_ratio_ok()) { - refault = true; - count_swapd_event(SWAPD_REFAULT); - goto do_eswap; - } - - swapd_shrink_node(pgdat); - last_swapd_time = jiffies; -do_eswap: - fault_out_pause_value = atomic_long_read(&fault_out_pause); -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - display_un_blank = !atomic_read(&display_off); -#endif - if (!hybridswap_reclaim_work_running() && display_un_blank && - (zram_need_swapout() || refault) && !fault_out_pause_value && - jiffies_to_msecs(jiffies - last_reclaimin_jiffies) >= 50) { - avail = get_high_avail_buffers_value(); - curr_buffers = system_cur_avail_buffers(); - - if (curr_buffers < avail) { - size = (avail - curr_buffers) * SZ_1M; - size = min_t(u64, size, max_reclaimin_size); -#ifdef CONFIG_HYBRIDSWAP_CORE - swapout_size = hybridswap_reclaim_in(size); - count_swapd_event(SWAPD_SWAPOUT); - last_reclaimin_jiffies = jiffies; -#endif - hybp(HYB_DEBUG, "SWAPD_SWAPOUT curr %u avail %lu size %lu maybe swapout %lu\n", - curr_buffers, avail, - size / SZ_1M, swapout_size / SZ_1M); - } else { - hybp(HYB_INFO, "SWAPD_SKIP_SWAPOUT curr %u avail %lu\n", - curr_buffers, avail); - count_swapd_event(SWAPD_SKIP_SWAPOUT); - } - } - - if (!buffer_is_suitable()) { - if (free_swap_is_low() || zram_watermark_exceed()) { - swapd_pressure_report(LEVEL_CRITICAL); - count_swapd_event(SWAPD_CRITICAL_PRESS); - } - } - } - - return 0; -} - -/* - * This swapd start function will be called by init and node-hot-add. - */ -int swapd_run(int nid) -{ - pg_data_t *pgdat = NODE_DATA(nid); - struct sched_param param = { - .sched_priority = DEFAULT_PRIO, - }; - struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat); - int ret; - - if (!hyb_task || hyb_task->swapd) - return 0; - - atomic_set(&hyb_task->swapd_wait_flag, 0); - hyb_task->swapd = kthread_create(swapd, pgdat, "hybridswapd:%d", nid); - if (IS_ERR(hyb_task->swapd)) { - hybp(HYB_ERR, "Failed to start swapd on node %d\n", nid); - ret = PTR_ERR(hyb_task->swapd); - hyb_task->swapd = NULL; - return ret; - } - - sched_setscheduler_nocheck(hyb_task->swapd, SCHED_NORMAL, ¶m); - set_user_nice(hyb_task->swapd, PRIO_TO_NICE(param.sched_priority)); - wake_up_process(hyb_task->swapd); - - return 0; -} - -/* - * Called by memory hotplug when all memory in a node is offlined. Caller must - * hold mem_hotplug_begin/end(). - */ -void swapd_stop(int nid) -{ - struct pglist_data *pgdata = NODE_DATA(nid); - struct task_struct *swapd; - struct hybridswapd_task* hyb_task; - - if (unlikely(!PGDAT_ITEM_DATA(pgdata))) { - hybp(HYB_ERR, "nid %d pgdata %p PGDAT_ITEM_DATA is NULL\n", - nid, pgdata); - return; - } - - hyb_task = PGDAT_ITEM_DATA(pgdata); - swapd = hyb_task->swapd; - if (swapd) { - atomic_set(&hyb_task->swapd_wait_flag, 1); - kthread_stop(swapd); - hyb_task->swapd = NULL; - } - - swapd_pid = -1; -} - -static int mem_hotplug_swapd_notifier(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct memory_notify *arg = (struct memory_notify*)data; - int nid = arg->status_change_nid; - - if (action == MEM_ONLINE) - swapd_run(nid); - else if (action == MEM_OFFLINE) - swapd_stop(nid); - - return NOTIFY_OK; -} - -static struct notifier_block swapd_notifier_nb = { - .notifier_call = mem_hotplug_swapd_notifier, -}; - -static int swapd_cpu_online(unsigned int cpu) -{ - int nid; - - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat = NODE_DATA(nid); - struct hybridswapd_task* hyb_task; - struct cpumask *mask; - - hyb_task = PGDAT_ITEM_DATA(pgdat); - mask = &hyb_task->swapd_bind_cpumask; - - if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) - /* One of our CPUs online: restore mask */ - set_cpus_allowed_ptr(PGDAT_ITEM(pgdat, swapd), mask); - } - return 0; -} - -void alloc_pages_slowpath_hook(void *data, gfp_t gfp_flags, - unsigned int order, unsigned long delta) -{ - if (gfp_flags & __GFP_KSWAPD_RECLAIM) - wake_all_swapd(); -} - -void rmqueue_hook(void *data, struct zone *preferred_zone, - struct zone *zone, unsigned int order, gfp_t gfp_flags, - unsigned int alloc_flags, int migratetype) -{ - if (gfp_flags & __GFP_KSWAPD_RECLAIM) - wake_all_swapd(); -} - -static int create_swapd_thread(struct zram *zram) -{ - int nid; - int ret; - struct pglist_data *pgdat; - struct hybridswapd_task *tsk_info; - - for_each_node(nid) { - pgdat = NODE_DATA(nid); - if (!PGDAT_ITEM_DATA(pgdat)) { - tsk_info = kzalloc(sizeof(struct hybridswapd_task), - GFP_KERNEL); - if (!tsk_info) { - hybp(HYB_ERR, "kmalloc tsk_info failed node %d\n", nid); - goto error_out; - } - - pgdat->android_oem_data1 = (u64)tsk_info; - } - - init_waitqueue_head(&PGDAT_ITEM(pgdat, swapd_wait)); - } - - for_each_node_state(nid, N_MEMORY) { - if (swapd_run(nid)) - goto error_out; - } - - ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, - "mm/swapd:online", swapd_cpu_online, NULL); - if (ret < 0) { - hybp(HYB_ERR, "swapd: failed to register hotplug callbacks.\n"); - goto error_out; - } - swapd_online = ret; - - return 0; - -error_out: - for_each_node(nid) { - pgdat = NODE_DATA(node); - - if (!PGDAT_ITEM_DATA(pgdat)) - continue; - - if (PGDAT_ITEM(pgdat, swapd)) { - kthread_stop(PGDAT_ITEM(pgdat, swapd)); - PGDAT_ITEM(pgdat, swapd) = NULL; - } - - kfree((void*)PGDAT_ITEM_DATA(pgdat)); - pgdat->android_oem_data1 = 0; - } - - return -ENOMEM; -} - -static void destroy_swapd_thread(void) -{ - int nid; - struct pglist_data *pgdat; - - cpuhp_remove_state_nocalls(swapd_online); - for_each_node(nid) { - pgdat = NODE_DATA(node); - if (!PGDAT_ITEM_DATA(pgdat)) - continue; - - swapd_stop(nid); - kfree((void*)PGDAT_ITEM_DATA(pgdat)); - pgdat->android_oem_data1 = 0; - } -} - -ssize_t hybridswap_swapd_pause_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - char *type_buf = NULL; - bool val; - - type_buf = strstrip((char *)buf); - if (kstrtobool(type_buf, &val)) - return -EINVAL; - atomic_set(&swapd_pause, val); - - return len; -} - -ssize_t hybridswap_swapd_pause_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - ssize_t size = 0; - - size += scnprintf(buf + size, PAGE_SIZE - size, - "%d\n", atomic_read(&swapd_pause)); - - return size; -} - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct msm_drm_notifier *evdata = data; - int *blank; - - if (evdata && evdata->data) { - blank = evdata->data; - - if (*blank == MSM_DRM_BLANK_POWERDOWN) - atomic_set(&display_off, 1); - else if (*blank == MSM_DRM_BLANK_UNBLANK) - atomic_set(&display_off, 0); - } - - return NOTIFY_OK; -} -#endif - -void __init swapd_pre_init(void) -{ - all_totalreserve_pages = get_totalreserve_pages(); -} - -void swapd_pre_deinit(void) -{ - all_totalreserve_pages = 0; -} - -int swapd_init(struct zram *zram) -{ - int ret; - - ret = register_memory_notifier(&swapd_notifier_nb); - if (ret) { - hybp(HYB_ERR, "register_memory_notifier failed, ret = %d\n", ret); - return ret; - } - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - fb_notif.notifier_call = bright_fb_notifier_callback; - ret = msm_drm_register_client(&fb_notif); - if (ret) { - hybp(HYB_ERR, "msm_drm_register_client failed, ret=%d\n", ret); - goto msm_drm_register_fail; - } -#endif - - ret = snapshotd_run(); - if (ret) { - hybp(HYB_ERR, "snapshotd_run failed, ret=%d\n", ret); - goto snapshotd_fail; - } - - ret = create_swapd_thread(zram); - if (ret) { - hybp(HYB_ERR, "create_swapd_thread failed, ret=%d\n", ret); - goto create_swapd_fail; - } - - swapd_zram = zram; - atomic_set(&swapd_enabled, 1); - return 0; - -create_swapd_fail: - snapshotd_exit(); -snapshotd_fail: -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - msm_drm_unregister_client(&fb_notif); -msm_drm_register_fail: -#endif - unregister_memory_notifier(&swapd_notifier_nb); - return ret; -} - -void swapd_exit(void) -{ - destroy_swapd_thread(); - snapshotd_exit(); -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - msm_drm_unregister_client(&fb_notif); -#endif - unregister_memory_notifier(&swapd_notifier_nb); - atomic_set(&swapd_enabled, 0); -} - -bool hybridswap_swapd_enabled(void) -{ - return !!atomic_read(&swapd_enabled); -} diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9090b7a681c2..447751f78402 100755 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -37,9 +37,6 @@ #include "zram_drv.h" #include "zram_drv_internal.h" -#ifdef CONFIG_HYBRIDSWAP -#include "hybridswap/hybridswap.h" -#endif static DEFINE_IDR(zram_index_idr); /* idr index must be protected */ @@ -1123,26 +1120,7 @@ static void zram_free_page(struct zram *zram, size_t index) atomic64_dec(&zram->stats.huge_pages); } -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if (zram_test_flag(zram, index, ZRAM_CACHED)) { - struct page *page = (struct page *)zram_get_page(zram, index); - del_page_from_cache(page); - page->mem_cgroup = NULL; - put_free_page(page); - zram_clear_flag(zram, index, ZRAM_CACHED); - goto out; - } - - if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - zram_clear_flag(zram, index, ZRAM_CACHED_COMPRESS); - goto out; - } -#endif - -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_untrack(zram, index); -#endif if (zram_test_flag(zram, index, ZRAM_WB)) { zram_clear_flag(zram, index, ZRAM_WB); @@ -1179,124 +1157,6 @@ out: ~(1UL << ZRAM_LOCK | 1UL << ZRAM_UNDER_WB)); } -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -void update_zram_index(struct zram *zram, u32 index, unsigned long page) -{ - zram_slot_lock(zram, index); - put_anon_pages((struct page*)page); - - zram_free_page(zram, index); - zram_set_flag(zram, index, ZRAM_CACHED); - zram_set_page(zram, index, page); - zram_set_obj_size(zram, index, PAGE_SIZE); - zram_slot_unlock(zram, index); -} - -int async_compress_page(struct zram *zram, struct page* page) -{ - int ret = 0; - unsigned long alloced_pages; - unsigned long handle = 0; - unsigned int comp_len = 0; - void *src, *dst; - struct zcomp_strm *zstrm; - int index = get_zram_index(page); - -compress_again: - zram_slot_lock(zram, index); - if (!zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - zram_slot_unlock(zram, index); - return 0; - } - zram_slot_unlock(zram, index); - - zstrm = zcomp_stream_get(zram->comp); - src = kmap_atomic(page); - ret = zcomp_compress(zstrm, src, &comp_len); - kunmap_atomic(src); - - if (unlikely(ret)) { - zcomp_stream_put(zram->comp); - pr_err("Compression failed! err=%d\n", ret); - zs_free(zram->mem_pool, handle); - return ret; - } - - if (comp_len >= huge_class_size) - comp_len = PAGE_SIZE; - - if (!handle) - handle = zs_malloc(zram->mem_pool, comp_len, - __GFP_KSWAPD_RECLAIM | - __GFP_NOWARN | - __GFP_HIGHMEM | - __GFP_MOVABLE | - __GFP_CMA); - if (!handle) { - zcomp_stream_put(zram->comp); - atomic64_inc(&zram->stats.writestall); - handle = zs_malloc(zram->mem_pool, comp_len, - GFP_NOIO | __GFP_HIGHMEM | - __GFP_MOVABLE | __GFP_CMA | - GFP_ATOMIC | ___GFP_HIGH_ATOMIC_ZRAM); - if (handle) - goto compress_again; - return -ENOMEM; - } - - alloced_pages = zs_get_total_pages(zram->mem_pool); - update_used_max(zram, alloced_pages); - - if (zram->limit_pages && alloced_pages > zram->limit_pages) { - zcomp_stream_put(zram->comp); - zs_free(zram->mem_pool, handle); - return -ENOMEM; - } - - dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); - - src = zstrm->buffer; - if (comp_len == PAGE_SIZE) - src = kmap_atomic(page); - memcpy(dst, src, comp_len); - if (comp_len == PAGE_SIZE) - kunmap_atomic(src); - - zcomp_stream_put(zram->comp); - zs_unmap_object(zram->mem_pool, handle); - atomic64_add(comp_len, &zram->stats.compr_data_size); - - /* - * Free memory associated with this sector - * before overwriting unused sectors. - */ - zram_slot_lock(zram, index); - if (!zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) { - atomic64_sub(comp_len, &zram->stats.compr_data_size); - zs_free(zram->mem_pool, handle); - zram_slot_unlock(zram, index); - return 0; - } - zram_free_page(zram, index); - - if (comp_len == PAGE_SIZE) { - zram_set_flag(zram, index, ZRAM_HUGE); - atomic64_inc(&zram->stats.huge_pages); - } - - zram_set_handle(zram, index, handle); - zram_set_obj_size(zram, index, comp_len); -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_track(zram, index, page->mem_cgroup); -#endif - zram_slot_unlock(zram, index); - - /* Update stats */ - atomic64_inc(&zram->stats.pages_stored); - - return ret; -} -#endif static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, struct bio *bio, bool partial_io) @@ -1307,22 +1167,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, void *src, *dst; zram_slot_lock(zram, index); -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if (akcompress_cache_fault_out(zram, page, index)) - return 0; -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE - if (likely(!bio)) { - ret = hybridswap_fault_out(zram, index); - if (unlikely(ret)) { - pr_err("search in hybridswap failed! err=%d, page=%u\n", - ret, index); - zram_slot_unlock(zram, index); - return ret; - } - } -#endif if (zram_test_flag(zram, index, ZRAM_WB)) { struct bio_vec bvec; @@ -1431,12 +1276,6 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, } kunmap_atomic(mem); -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - if ((current_is_kswapd() || current_is_swapd(current)) && - add_anon_page2cache(zram, index, page)) { - return 0; - } -#endif compress_again: zstrm = zcomp_stream_get(zram->comp); src = kmap_atomic(page); @@ -1524,9 +1363,6 @@ out: zram_set_obj_size(zram, index, comp_len); } -#ifdef CONFIG_HYBRIDSWAP_CORE - hybridswap_track(zram, index, page->mem_cgroup); -#endif zram_slot_unlock(zram, index); /* Update stats */ @@ -1734,13 +1570,6 @@ static void zram_slot_free_notify(struct block_device *bdev, return; } -#ifdef CONFIG_HYBRIDSWAP_CORE - if (!hybridswap_delete(zram, index)) { - zram_slot_unlock(zram, index); - atomic64_inc(&zram->stats.miss_free); - return; - } -#endif zram_free_page(zram, index); zram_slot_unlock(zram, index); } @@ -1957,27 +1786,6 @@ static DEVICE_ATTR_WO(writeback); static DEVICE_ATTR_RW(writeback_limit); static DEVICE_ATTR_RW(writeback_limit_enable); #endif -#ifdef CONFIG_HYBRIDSWAP -static DEVICE_ATTR_RO(hybridswap_vmstat); -static DEVICE_ATTR_RW(hybridswap_loglevel); -static DEVICE_ATTR_RW(hybridswap_enable); -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD -static DEVICE_ATTR_RW(hybridswap_swapd_pause); -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE -static DEVICE_ATTR_RW(hybridswap_core_enable); -static DEVICE_ATTR_RW(hybridswap_loop_device); -static DEVICE_ATTR_RW(hybridswap_dev_life); -static DEVICE_ATTR_RW(hybridswap_quota_day); -static DEVICE_ATTR_RO(hybridswap_report); -static DEVICE_ATTR_RO(hybridswap_stat_snap); -static DEVICE_ATTR_RO(hybridswap_meminfo); -static DEVICE_ATTR_RW(hybridswap_zram_increase); -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -static DEVICE_ATTR_RW(hybridswap_akcompress); -#endif static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -2001,27 +1809,6 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_bd_stat.attr, #endif &dev_attr_debug_stat.attr, -#ifdef CONFIG_HYBRIDSWAP - &dev_attr_hybridswap_vmstat.attr, - &dev_attr_hybridswap_loglevel.attr, - &dev_attr_hybridswap_enable.attr, -#endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD - &dev_attr_hybridswap_swapd_pause.attr, -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE - &dev_attr_hybridswap_core_enable.attr, - &dev_attr_hybridswap_report.attr, - &dev_attr_hybridswap_meminfo.attr, - &dev_attr_hybridswap_stat_snap.attr, - &dev_attr_hybridswap_loop_device.attr, - &dev_attr_hybridswap_dev_life.attr, - &dev_attr_hybridswap_quota_day.attr, - &dev_attr_hybridswap_zram_increase.attr, -#endif -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - &dev_attr_hybridswap_akcompress.attr, -#endif NULL, }; @@ -2169,9 +1956,6 @@ static int zram_remove(struct zram *zram) del_gendisk(zram->disk); blk_cleanup_queue(zram->disk->queue); put_disk(zram->disk); -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - destroy_akcompressd_task(zram); -#endif if (zram_devices == zram) zram_devices = NULL; kfree(zram); @@ -2374,11 +2158,6 @@ static int __init zram_init(void) proc_create("zraminfo", 0644, NULL, &zraminfo_proc_fops); #endif -#ifdef CONFIG_HYBRIDSWAP - ret = hybridswap_pre_init(); - if (ret) - goto out_error; -#endif return 0; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index c5c0e7c53047..e317e1ce9cb1 100755 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -51,16 +51,6 @@ enum zram_pageflags { ZRAM_UNDER_WB, /* page is under writeback */ ZRAM_HUGE, /* Incompressible page */ ZRAM_IDLE, /* not accessed page since last idle marking */ -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - ZRAM_CACHED, /* page is cached in async compress cache buffer */ - ZRAM_CACHED_COMPRESS, /* page is under async compress */ -#endif -#ifdef CONFIG_HYBRIDSWAP_CORE - ZRAM_BATCHING_OUT, - ZRAM_FROM_HYBRIDSWAP, - ZRAM_MCGID_CLEAR, - ZRAM_IN_BD, /* zram stored in back device */ -#endif __NR_ZRAM_PAGEFLAGS, }; @@ -71,9 +61,6 @@ struct zram_table_entry { union { unsigned long handle; unsigned long element; -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS - unsigned long page; -#endif }; unsigned long flags; #ifdef CONFIG_ZRAM_MEMORY_TRACKING @@ -138,15 +125,12 @@ struct zram { #ifdef CONFIG_ZRAM_MEMORY_TRACKING struct dentry *debugfs_dir; #endif -#if (defined CONFIG_ZRAM_WRITEBACK) || (defined CONFIG_HYBRIDSWAP_CORE) +#if (defined CONFIG_ZRAM_WRITEBACK) struct block_device *bdev; unsigned int old_block_size; unsigned long nr_pages; unsigned long increase_nr_pages; #endif -#ifdef CONFIG_HYBRIDSWAP_CORE - struct hybridswap_area *area; -#endif }; /* mlog */ diff --git a/drivers/block/zram/zram_drv_internal.h b/drivers/block/zram/zram_drv_internal.h index 8b1021593739..d5e4ebae0dc2 100755 --- a/drivers/block/zram/zram_drv_internal.h +++ b/drivers/block/zram/zram_drv_internal.h @@ -35,8 +35,4 @@ zram->table[index].flags = (flags << ZRAM_FLAG_SHIFT) | size; \ } while(0) -#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS -extern int async_compress_page(struct zram *zram, struct page* page); -extern void update_zram_index(struct zram *zram, u32 index, unsigned long page); -#endif #endif /* _ZRAM_DRV_INTERNAL_H_ */ diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index dbb17b123b74..6af35dfe9034 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -32,9 +32,6 @@ #include #include -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ static LIST_HEAD(cpufreq_policy_list); @@ -349,9 +346,6 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy, CPUFREQ_POSTCHANGE, freqs); if (likely(policy) && likely(policy->cpu == freqs->cpu)) { policy->cur = freqs->new; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_freq_info(policy); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ } break; } @@ -2264,9 +2258,6 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, policy->min = new_policy->min; policy->max = new_policy->max; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_freq_limit_info(policy); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ arch_set_max_freq_scale(policy->cpus, policy->max); arch_set_min_freq_scale(policy->cpus, policy->min); diff --git a/drivers/cpufreq/cpufreq_times.c b/drivers/cpufreq/cpufreq_times.c index 406f6e0e1a16..9b3044a20631 100644 --- a/drivers/cpufreq/cpufreq_times.c +++ b/drivers/cpufreq/cpufreq_times.c @@ -25,9 +25,6 @@ #include #include -#ifdef CONFIG_OPLUS_FEATURE_MIDAS -#include -#endif #define UID_HASH_BITS 10 @@ -428,9 +425,6 @@ void cpufreq_acct_update_power(struct task_struct *p, u64 cputime) uid_entry->time_in_state[state] += cputime; spin_unlock_irqrestore(&uid_lock, flags); -#ifdef CONFIG_OPLUS_FEATURE_MIDAS - midas_record_task_times(uid, cputime, p, state); -#endif rcu_read_lock(); uid_entry = find_uid_entry_rcu(uid); diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c index fafc7af19b2c..c6a5d7c8e5ce 100755 --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c @@ -19,9 +19,6 @@ #include #include #include -#ifdef OPLUS_BUG_STABILITY -#include -#endif #include "mtk_drm_drv.h" #include "mtk_drm_crtc.h" @@ -3777,9 +3774,6 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev) DDPAEE("%s:%d, failed to request irq:%d ret:%d comp_id:%d\n", __func__, __LINE__, irq, ret, comp_id); - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@501$$", MM_FB_KEY_RATELIMIT_1H, "ovl_probe error irq:%d ret:%d comp_id:%d", irq, ret, comp_id); - #endif return ret; } diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c index 3e788b176dc4..8588ee397a6c 100755 --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c @@ -33,9 +33,6 @@ #include "mtk_layering_rule.h" #include "mtk_drm_trace.h" #include "swpm_me.h" -#ifdef OPLUS_BUG_STABILITY -#include -#endif #define DISP_REG_RDMA_INT_ENABLE 0x0000 #define DISP_REG_RDMA_INT_STATUS 0x0004 @@ -404,11 +401,6 @@ static irqreturn_t mtk_disp_rdma_irq_handler(int irq, void *dev_id) DDPAEE("%s: underflow! cnt=%d\n", mtk_dump_comp_str(rdma), priv->underflow_cnt); - #ifdef OPLUS_BUG_STABILITY - if ((priv->underflow_cnt) < 5) { - mm_fb_display_kevent("DisplayDriverID@@502$$", MM_FB_KEY_RATELIMIT_1H, "underflow cnt=%d", priv->underflow_cnt); - } - #endif } } diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index 86db7f2b60ee..dbbdc5119765 100755 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -28,9 +28,6 @@ #include #include #include -#ifdef OPLUS_BUG_STABILITY -#include -#endif #include "mtk_drm_arr.h" #include "mtk_drm_drv.h" @@ -6148,9 +6145,6 @@ static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc, DDPAEE("%s:%d, invalid vblank:%d, crtc:%p\n", __func__, __LINE__, drm_crtc_vblank_get(crtc), crtc); - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@503$$", MM_FB_KEY_RATELIMIT_1H, "invalid vblank:%d", drm_crtc_vblank_get(crtc)); - #endif } mtk_crtc->event = state->base.event; state->base.event = NULL; diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c index f6773a818580..7fb55941a8a7 100755 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c @@ -20,9 +20,6 @@ #include #include #include -#ifdef OPLUS_BUG_STABILITY -#include -#endif #include "mtk_drm_ddp.h" #include "mtk_drm_crtc.h" @@ -8317,9 +8314,6 @@ static int mtk_ddp_probe(struct platform_device *pdev) DDPAEE("%s:%d, failed to request irq:%d ret:%d\n", __func__, __LINE__, irq, ret); - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@504$$", MM_FB_KEY_RATELIMIT_1H, "mtk_ddp_probe failed to request irq:%d ret:%d", irq, ret); - #endif return ret; } diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index 89df95445c2b..73dd37c31f5c 100755 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -21,9 +21,6 @@ #include "mtk_drm_drv.h" #include "mtk_drm_fb.h" #include "mtk_drm_gem.h" -#ifdef OPLUS_BUG_STABILITY -#include -#endif /* * mtk specific framebuffer structure. @@ -197,9 +194,6 @@ int mtk_fb_wait(struct drm_framebuffer *fb) DDPAEE("%s:%d, invalid ret:%ld\n", __func__, __LINE__, ret); - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@505$$", MM_FB_KEY_RATELIMIT_1H, "mtk_fb_wait invalid ret:%ld", ret); - #endif return ret; } diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c index be6a6907940c..79489960c6ac 100755 --- a/drivers/gpu/drm/mediatek/mtk_dsi.c +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c @@ -53,9 +53,6 @@ #include "mtk_drm_fbdev.h" #include "mtk_fbconfig_kdebug.h" /* ********* end Panel Master *********** */ -#ifdef OPLUS_BUG_STABILITY -#include -#endif #include /* ********** bridge ic ***************** */ @@ -1895,9 +1892,6 @@ static irqreturn_t mtk_dsi_irq_status(int irq, void *dev_id) dsi->encoder.crtc); } dsi_underrun_trigger = 0; - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@506$$", MM_FB_KEY_RATELIMIT_1H, "underrun"); - #endif } } @@ -4148,19 +4142,6 @@ int mtk_dsi_esd_cmp(struct mtk_ddp_comp *comp, void *handle, void *slot) DDPPR_ERR("[DSI]cmp fail:read(0x%x)!=expect(0x%x)\n", chk_val, lcm_esd_tb->para_list[0]); ret = -1; - #ifdef OPLUS_BUG_STABILITY - if (ret < 0) { - char payload[200] = ""; - int cnt = 0; - - cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, "DisplayDriverID@@507$$"); - cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, "ESD:"); - cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, "%02x = %02x", - lcm_esd_tb->cmd,lcm_esd_tb->para_list[0]); - DDPPR_ERR("ESD check failed: %s\n", payload); - mm_fb_display_kevent(payload, MM_FB_KEY_RATELIMIT_1H, "ESD check failed"); - } - #endif break; } #ifdef OPLUS_BUG_STABILITY diff --git a/drivers/gpu/drm/panel/oplus21851_samsung_ams643ag01_1080p_dsi_cmd.c b/drivers/gpu/drm/panel/oplus21851_samsung_ams643ag01_1080p_dsi_cmd.c index c09f9285aca8..b7ab1f5a9bee 100755 --- a/drivers/gpu/drm/panel/oplus21851_samsung_ams643ag01_1080p_dsi_cmd.c +++ b/drivers/gpu/drm/panel/oplus21851_samsung_ams643ag01_1080p_dsi_cmd.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #define CONFIG_MTK_PANEL_EXT @@ -1302,11 +1301,6 @@ static int lcm_panel_poweroff(struct drm_panel *panel) msleep(70); - /*if (fan53870_fail_flag == 1) { - mm_fb_display_kevent("DisplayDriverID@@509$$", MM_FB_KEY_RATELIMIT_1H, "fan53870 no ok"); - fan53870_fail_flag = 0; - }*/ - return 0; } diff --git a/drivers/input/keyboard/mediatek/kpd.c b/drivers/input/keyboard/mediatek/kpd.c index e59091de034b..91d667f9edaa 100755 --- a/drivers/input/keyboard/mediatek/kpd.c +++ b/drivers/input/keyboard/mediatek/kpd.c @@ -38,11 +38,6 @@ #endif /*CONFIG_MACH_MT6768*/ //#endif /*OPLUS_FEATURE_TP_BASIC*/ -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_THEIA) -#include -#include -#endif - #define KPD_NAME "mtk-kpd" #ifdef CONFIG_LONG_PRESS_MODE_EN @@ -515,14 +510,6 @@ void kpd_pwrkey_pmic_handler(unsigned long pressed) return; } kpd_pmic_pwrkey_hal(pressed); - - #if IS_ENABLED(CONFIG_OPLUS_FEATURE_THEIA) - if(pressed){ - //we should canel per work - black_screen_timer_restart(); - bright_screen_timer_restart(); - } - #endif } #endif diff --git a/drivers/input/keyboard/mediatek/mt6893/hal_kpd.c b/drivers/input/keyboard/mediatek/mt6893/hal_kpd.c index ad2120b98466..446227b1e1e3 100644 --- a/drivers/input/keyboard/mediatek/mt6893/hal_kpd.c +++ b/drivers/input/keyboard/mediatek/mt6893/hal_kpd.c @@ -191,14 +191,6 @@ void kpd_pmic_pwrkey_hal(unsigned long pressed) input_sync(kpd_input_dev); kpd_print(KPD_SAY "(%s) HW keycode =%d using PMIC\n", pressed ? "pressed" : "released", kpd_dts_data.kpd_sw_pwrkey); - - #if IS_ENABLED(CONFIG_OPLUS_FEATURE_THEIA) - if(pressed){ - //we should canel per work - black_screen_timer_restart(); - bright_screen_timer_restart(); - } - #endif } static int mrdump_eint_state; diff --git a/drivers/mfd/mt6358-misc.c b/drivers/mfd/mt6358-misc.c index 082d1c6dbba6..5b62db9bcbd3 100755 --- a/drivers/mfd/mt6358-misc.c +++ b/drivers/mfd/mt6358-misc.c @@ -181,9 +181,6 @@ enum rtc_spare_enum { RTC_SENSOR_CAUSE_PANIC, #endif /* OPLUS_BUG_STABILITY */ RTC_SAFE_BOOT, -#ifdef OPLUS_FEATURE_AGINGTEST - RTC_AGINGTEST_BOOT, -#endif /*OPLUS_FEATURE_AGINGTEST */ #ifdef OPLUS_BUG_STABILITY RTC_EDL_BOOT, #endif /* OPLUS_BUG_STABILITY */ @@ -231,9 +228,6 @@ u16 rtc_spare_reg[RTC_SPAR_NUM][3] = { #endif /* OPLUS_BUG_STABILITY */ #ifdef OPLUS_BUG_STABILITY {RTC_SPAR0, 0x1, 15}, -#ifdef OPLUS_FEATURE_AGINGTEST - {RTC_SPAR0, 0x01, 14}, -#endif /*OPLUS_FEATURE_AGINGTEST */ {RTC_AL_DOW, 0x1, 15}, #endif /* OPLUS_BUG_STABILITY */ }; @@ -785,17 +779,6 @@ void oppo_rtc_mark_sau(void) spin_unlock_irqrestore(&rtc_misc->lock, flags); } -#ifdef OPLUS_FEATURE_AGINGTEST -void oppo_rtc_mark_agingtest(void) -{ - unsigned long flags; - - pr_notice("rtc_mark_agingtest\n"); - spin_lock_irqsave(&rtc_misc->lock, flags); - mtk_rtc_set_spare_register(RTC_AGINGTEST_BOOT, 0x01); - spin_unlock_irqrestore(&rtc_misc->lock, flags); -} -#endif /*OPLUS_FEATURE_AGINGTEST */ void oppo_rtc_mark_factory(void) { diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 982821b1011e..16849f17f1a4 100755 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -575,5 +575,4 @@ source "drivers/misc/tri_state_key/Kconfig" #ifdef OPLUS_FEATURE_CHG_BASIC//Fanhong.Kong@ProDrv.CHG,add 2018/10/25 for vib aw8697 source "drivers/misc/aw8697_haptic/Kconfig" #endif -source "drivers/misc/oplus_misc_healthinfo/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index bfc5b42c02f5..fe053013adf7 100755 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -68,8 +68,6 @@ obj-$(CONFIG_AW8697_HAPTIC) += aw8697_haptic/ obj-$(CONFIG_MTK_FB) += oplus/ #endif -obj-$(CONFIG_OPLUS_MISC_HEALTHONFO) += oplus_misc_healthinfo/ - lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o lkdtm-$(CONFIG_LKDTM) += lkdtm_heap.o diff --git a/drivers/misc/mediatek/adsp/mt6853/adsp_excep.c b/drivers/misc/mediatek/adsp/mt6853/adsp_excep.c index 93dc3c820fdc..48705fe8edbf 100755 --- a/drivers/misc/mediatek/adsp/mt6853/adsp_excep.c +++ b/drivers/misc/mediatek/adsp/mt6853/adsp_excep.c @@ -19,9 +19,6 @@ #include "adsp_platform_driver.h" #include "adsp_excep.h" #include "adsp_logger.h" -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#include -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #define ADSP_MISC_EXTRA_SIZE 0x400 //1KB #define ADSP_MISC_BUF_SIZE 0x10000 //64KB @@ -216,10 +213,6 @@ static void adsp_exception_dump(struct adsp_exception_control *ctrl) coredump->assert_log); } pr_info("%s", detail); -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_ADSP_CRASH, \ - MM_FB_KEY_RATELIMIT_5MIN, "FieldData@@%s$$detailData@@audio$$module@@adsp", coredump->assert_log); -#endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK /* adsp aed api, only detail information available*/ aed_common_exception_api("adsp", (const int *)coredump, coredump_size, diff --git a/drivers/misc/mediatek/adsp/mt6885/adsp_excep.c b/drivers/misc/mediatek/adsp/mt6885/adsp_excep.c index d82f38a0f9b8..48381962bcae 100755 --- a/drivers/misc/mediatek/adsp/mt6885/adsp_excep.c +++ b/drivers/misc/mediatek/adsp/mt6885/adsp_excep.c @@ -19,9 +19,6 @@ #include "adsp_platform_driver.h" #include "adsp_excep.h" #include "adsp_logger.h" -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#include -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #define ADSP_MISC_EXTRA_SIZE 0x400 //1KB #define ADSP_MISC_BUF_SIZE 0x10000 //64KB @@ -220,10 +217,6 @@ static void adsp_exception_dump(struct adsp_exception_control *ctrl) coredump->assert_log); } pr_info("%s", detail); -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_ADSP_CRASH, \ - MM_FB_KEY_RATELIMIT_5MIN, "FieldData@@%s$$detailData@@audio$$module@@adsp", coredump->assert_log); -#endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK /* adsp aed api, only detail information available*/ aed_common_exception_api("adsp", (const int *)coredump, coredump_size, NULL, 0, detail, db_opt); @@ -279,10 +272,6 @@ void adsp_aed_worker(struct work_struct *ws) "[ADSP]", "ASSERT: ADSP DEAD! Recovery Fail"); -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_ADSP_RECOVERY_FAIL, \ - MM_FB_KEY_RATELIMIT_5MIN, "payload@@ADSP DEAD! Recovery Fail,ret=%d", ret); -#endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK /* BUG_ON(1); */ } diff --git a/drivers/misc/mediatek/aee/mrdump/mrdump_panic.c b/drivers/misc/mediatek/aee/mrdump/mrdump_panic.c index 075cf00a5dd8..3f88719d0a0a 100644 --- a/drivers/misc/mediatek/aee/mrdump/mrdump_panic.c +++ b/drivers/misc/mediatek/aee/mrdump/mrdump_panic.c @@ -38,11 +38,6 @@ #include #include -#ifdef OPLUS_FEATURE_PERFORMANCE -//ZuoTong@ANDROID.PERFORMANCE, 2020/06/28,Add for flushing device cache before goto dump mode! -extern bool is_triggering_panic; -extern void flush_cache_on_panic(void); -#endif /*OPLUS_FEATURE_PERFORMANCE*/ static char mrdump_lk[12]; bool mrdump_ddr_reserve_ready; @@ -151,47 +146,12 @@ __weak void aee_wdt_zap_locks(void) pr_notice("%s:weak function\n", __func__); } -#ifdef OPLUS_FEATURE_PHOENIX -extern void deal_fatal_err(void); -extern int kernel_panic_happened; -extern int hwt_happened; -#endif /* OPLUS_FEATURE_PHOENIX */ - -#ifdef CONFIG_OPLUS_FEATURE_PANIC_FLUSH -extern int panic_flush_device_cache(int timeout); -#endif - int mrdump_common_die(int fiq_step, int reboot_reason, const char *msg, struct pt_regs *regs) { -#ifdef OPLUS_FEATURE_PHOENIX - if((AEE_REBOOT_MODE_KERNEL_OOPS == reboot_reason || AEE_REBOOT_MODE_KERNEL_PANIC == reboot_reason) - && !kernel_panic_happened) - { - kernel_panic_happened = 1; - deal_fatal_err(); - } - else if (AEE_REBOOT_MODE_WDT == reboot_reason && !hwt_happened) - { - hwt_happened = 1; - deal_fatal_err(); - } -#endif /* OPLUS_FEATURE_PHOENIX */ -#ifdef CONFIG_OPLUS_FEATURE_PANIC_FLUSH - panic_flush_device_cache(2000); -#endif -#ifdef OPLUS_FEATURE_PERFORMANCE -//ZuoTong@ANDROID.PERFORMANCE, 2020/06/28,Add for flushing device cache before go to dump mode! - if(!is_triggering_panic) - { - is_triggering_panic = true; - pr_notice("is_triggering_panic : true\n"); - flush_cache_on_panic(); - } -#endif // OPLUS_FEATURE_PERFORMANCE bust_spinlocks(1); aee_disable_api(); diff --git a/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_hybrid.c b/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_hybrid.c index 91e10103cc92..f1431e7e004c 100644 --- a/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_hybrid.c +++ b/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_hybrid.c @@ -81,9 +81,6 @@ #include "swpm_v1/mtk_swpm_interface.h" #endif -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ #ifdef CONFIG_MTK_CPU_MSSV extern unsigned int cpumssv_get_state(void); @@ -423,9 +420,6 @@ int Ripi_cpu_dvfs_thread(void *data) freqs.new, 0); } #endif -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_freq_limit_info(p->mt_policy); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_cpu_frequency_limits(p->mt_policy->max, p->mt_policy->min, p->mt_policy->cpu); diff --git a/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_main.c b/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_main.c index 25d0e154832b..b3243cf2a8cb 100755 --- a/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_main.c +++ b/drivers/misc/mediatek/base/power/cpufreq_v1/src/mtk_cpufreq_main.c @@ -1383,14 +1383,7 @@ static struct freq_attr *_mt_cpufreq_attr[] = { }; static struct cpufreq_driver _mt_cpufreq_driver = { - -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) \ - || (defined(CONFIG_MTK_PLAT_MT6885_EMULATION) || defined(CONFIG_MACH_MT6893) \ - || defined(CONFIG_MACH_MT6833)) - .flags = CPUFREQ_ASYNC_NOTIFICATION | CPUFREQ_HAVE_GOVERNOR_PER_POLICY, -#else .flags = CPUFREQ_ASYNC_NOTIFICATION, -#endif .verify = _mt_cpufreq_verify, .target = _mt_cpufreq_target, .init = _mt_cpufreq_init, diff --git a/drivers/misc/mediatek/base/power/cpufreq_v2/src/mtk_cpufreq_main.c b/drivers/misc/mediatek/base/power/cpufreq_v2/src/mtk_cpufreq_main.c index 7cd39fee9632..1c07a8e4bce9 100755 --- a/drivers/misc/mediatek/base/power/cpufreq_v2/src/mtk_cpufreq_main.c +++ b/drivers/misc/mediatek/base/power/cpufreq_v2/src/mtk_cpufreq_main.c @@ -1193,11 +1193,7 @@ static struct freq_attr *_mt_cpufreq_attr[] = { }; static struct cpufreq_driver _mt_cpufreq_driver = { -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - .flags = CPUFREQ_ASYNC_NOTIFICATION | CPUFREQ_HAVE_GOVERNOR_PER_POLICY, -#else .flags = CPUFREQ_ASYNC_NOTIFICATION, -#endif .verify = _mt_cpufreq_ver_dbgify, .target = _mt_cpufreq_target, .init = _mt_cpufreq_init, diff --git a/drivers/misc/mediatek/cmdq/mailbox/cmdq-sec-mailbox.c b/drivers/misc/mediatek/cmdq/mailbox/cmdq-sec-mailbox.c index d2c49d4d8108..93e2f1e2ecb0 100755 --- a/drivers/misc/mediatek/cmdq/mailbox/cmdq-sec-mailbox.c +++ b/drivers/misc/mediatek/cmdq/mailbox/cmdq-sec-mailbox.c @@ -16,10 +16,6 @@ #include "cmdq-sec-tl-api.h" #include "cmdq-util.h" -#ifdef OPLUS_BUG_STABILITY -#include -#endif - #ifdef CMDQ_SECURE_MTEE_SUPPORT #include "cmdq_sec_mtee.h" #endif @@ -1804,9 +1800,6 @@ static s32 cmdq_sec_late_init_wsm(void *data) err = cmdq_sec_session_init(cmdq->context); mutex_unlock(&cmdq->exec_lock); if (err) { - #ifdef OPLUS_BUG_STABILITY - mm_fb_display_kevent("DisplayDriverID@@509$$", MM_FB_KEY_RATELIMIT_1H, "cmdq sec session init failed:%d", err); - #endif err = -CMDQ_ERR_SEC_CTX_SETUP; cmdq_err("session init failed:%d", err); continue; diff --git a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/Makefile b/drivers/misc/mediatek/connectivity/wlan/core/gen4m/Makefile index ebe70370b9ff..90895cfe4f8f 100755 --- a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/Makefile +++ b/drivers/misc/mediatek/connectivity/wlan/core/gen4m/Makefile @@ -913,19 +913,6 @@ SYSDVT_OBJS += $(SYSDVT_DIR)dvt_dmashdl.o endif endif -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD -#//XiaZijian@CONNECTIVITY.WIFI.BASIC.26106 2021/03/18 , add for oplus wfd -ifeq ($(CONFIG_OPLUS_FEATURE_WIFI_OPLUSWFD), m) -ccflags-y += -DOPLUS_FEATURE_WIFI_OPLUSWFD=1 -else ifeq ($(CONFIG_OPLUS_FEATURE_WIFI_OPLUSWFD), y) -ccflags-y += -DOPLUS_FEATURE_WIFI_OPLUSWFD=1 -else ifeq ($(CONFIG_OPLUS_FEATURE_WIFI_OPLUSWFD), n) -ccflags-y += -UOPLUS_FEATURE_WIFI_OPLUSWFD -endif - -OPLUS_WFD_OBJS += oplus_wfd/wlan_oplus_wfd.o -#endif /* OPLUS_FEATURE_WIFI_OPLUSWFD */ - # --------------------------------------------------- # Service git List # --------------------------------------------------- @@ -964,11 +951,6 @@ $(MODULE_NAME)-objs += $(SYSDVT_OBJS) $(MODULE_NAME)-objs += $(NAN_OBJS) $(MODULE_NAME)-objs += $(NAN_SEC_OBJS) -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD -#//XiaZijian@CONNECTIVITY.WIFI.BASIC.26106 2021/03/18 , add for oplus wfd -$(MODULE_NAME)-objs += $(OPLUS_WFD_OBJS) -#endif /* OPLUS_FEATURE_WIFI_OPLUSWFD */ - ifneq ($(findstring UT_TEST_MODE,$(MTK_COMBO_CHIP)),) include $(src)/test/ut.make endif diff --git a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/oplus_wfd/wlan_oplus_wfd.c b/drivers/misc/mediatek/connectivity/wlan/core/gen4m/oplus_wfd/wlan_oplus_wfd.c deleted file mode 100755 index aaa669d85b47..000000000000 --- a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/oplus_wfd/wlan_oplus_wfd.c +++ /dev/null @@ -1,336 +0,0 @@ -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "gl_os.h" -#include "debug.h" -#include "wlan_lib.h" -#include "gl_wext.h" -#include "gl_cfg80211.h" -#include "gl_kal.h" -#include "precomp.h" -#include "nic_cmd_event.h" -#include "wsys_cmd_handler_fw.h" -#include -#include - -#define BIT_SUPPORTED_PHY_NO_HT 1 -#define BIT_SUPPORTED_PHY_HT 2 -#define BIT_SUPPORTED_PHY_VHT 4 -#define BIT_SUPPORTED_PHY_HE 8 - -#define MTK_SUPPORT_AVOID_CHANNEL 1 - -static int is_remove_He_ie_from_prebe_request = 0; -static struct wireless_dev *s_hdd_ctx = NULL; -static DEFINE_MUTEX(ctx_mutex); - -static DECLARE_COMPLETION(s_avoid_channel_query_comp); -static char s_avoid_channel_query_comp_inited = 0; -static struct EVENT_LTE_SAFE_CHN s_event_lte_safe_chn; - -extern uint8_t wlanGetChannelIndex(enum ENUM_BAND eBand, uint8_t channel); -#if CFG_SUPPORT_IDC_CH_SWITCH -extern struct EVENT_LTE_SAFE_CHN g_rLteSafeChInfo; -#endif - -int oplus_wfd_get_remove_He_ie_flag(void); -void oplus_wfd_set_hdd_ctx(struct wireless_dev *hdd_ctx); -void oplus_register_oplus_wfd_wlan_ops_qcom(void); - -static void remove_he_ie_from_probe_request(int remove); -static int get_dbs_capacity(void); -static int get_phy_capacity(int band); -static void get_avoid_channels(int *len, int* freqs, int max_num); - -static struct oplus_wfd_wlan_ops_t oplus_wfd_wlan_ops_mtk = { - .remove_he_ie_from_probe_request = remove_he_ie_from_probe_request, - .get_dbs_capacity = get_dbs_capacity, - .get_phy_capacity = get_phy_capacity, - .get_supported_channels = NULL, -#if MTK_SUPPORT_AVOID_CHANNEL - .get_avoid_channels = get_avoid_channels, -#else - .get_avoid_channels = NULL, -#endif -}; - -static void remove_he_ie_from_probe_request(int remove) { - is_remove_He_ie_from_prebe_request = remove; -} - -static struct wireless_dev * get_wdev_sta() -{ - return s_hdd_ctx; -} - -static struct ADAPTER * get_adapter() { - struct wireless_dev *wdev_sta = NULL; - struct GLUE_INFO *prGlueInfo = NULL; - struct ADAPTER *prAdapter = NULL; - struct wiphy *wiphy; - - wdev_sta = get_wdev_sta(); - - if (wdev_sta == NULL) { - goto EXIT; - } - - if (kalIsHalted()) { - goto EXIT; - } - - wiphy = wdev_sta->wiphy; - if (wiphy == NULL) { - goto EXIT; - } - - WIPHY_PRIV(wiphy, prGlueInfo); - if (prGlueInfo == NULL) { - goto EXIT; - } - if (!prGlueInfo->fgIsRegistered) { - goto EXIT; - } - - prAdapter = prGlueInfo->prAdapter; - if (prAdapter == NULL) { - goto EXIT; - } - -EXIT: - return prAdapter; -} -static int get_dbs_capacity(void) -{ - #define DBS_UNKNOWN 0 - #define DBS_NULL 1 - #define DBS_SISO 2 - #define DBS_MIMO 3 - int cap = DBS_UNKNOWN; - struct ADAPTER *prAdapter = NULL; - mutex_lock(&ctx_mutex); - - prAdapter = get_adapter(); - if (prAdapter == NULL) { - goto EXIT; - } - - cap = DBS_NULL; - -EXIT: - mutex_unlock(&ctx_mutex); - return cap; -} - -static int get_phy_capacity(int band) -{ - int phy_bit = 0; - struct ADAPTER *prAdapter = NULL; - - mutex_lock(&ctx_mutex); - prAdapter = get_adapter(); - if (prAdapter == NULL) { - goto EXIT; - } - - if (prAdapter->rWifiVar.ucStaHt) { - phy_bit |= BIT_SUPPORTED_PHY_HT; - } - if (prAdapter->rWifiVar.ucStaVht) { - phy_bit |= BIT_SUPPORTED_PHY_VHT | BIT_SUPPORTED_PHY_HT; - } -#if (CFG_SUPPORT_802_11AX == 1) - if (prAdapter->rWifiVar.ucStaHe) { - phy_bit |= BIT_SUPPORTED_PHY_HE | BIT_SUPPORTED_PHY_VHT | BIT_SUPPORTED_PHY_HT; - } -#endif - -EXIT: - mutex_unlock(&ctx_mutex); - return phy_bit; -} - -static int convertChannelToFrequency(int channel) { - if ((channel >= 0) && (channel < 14)) { - return 2412 + 5 * (channel - 1); - } else if (channel == 14) { - return 2484; - } else if ((channel >= 36) && (channel <= 181)) { - return 5180 + (channel - 36) * 5; - } - return -1; -} - -#if MTK_SUPPORT_AVOID_CHANNEL - -void oplus_nicOidCmdTimeoutCommon(IN struct ADAPTER *prAdapter, - IN struct CMD_INFO *prCmdInfo) { -} - -void oplus_WfdCmdEventQueryLteSafeChn(IN struct ADAPTER *prAdapter, - IN struct CMD_INFO *prCmdInfo, - IN uint8_t *pucEventBuf) -{ - struct EVENT_LTE_SAFE_CHN *prEvent; - int index; - do { - if ((prAdapter == NULL) || (prCmdInfo == NULL) || (pucEventBuf == NULL) - || (prCmdInfo->pvInformationBuffer == NULL)) { - break; - } - - prEvent = (struct EVENT_LTE_SAFE_CHN *) pucEventBuf; - - if (prEvent->u4Flags & BIT(0)) { - memcpy(&s_event_lte_safe_chn, prEvent, sizeof(s_event_lte_safe_chn)); - for (index = 0 ; index < ENUM_SAFE_CH_MASK_MAX_NUM; index++) { - } - } else { - } - } while (false); - - complete(&s_avoid_channel_query_comp); -} - -static uint32_t oplus_wlanQueryLteSafeChannel(IN struct ADAPTER *prAdapter, - IN uint8_t ucRoleIndex) -{ - uint32_t rResult = WLAN_STATUS_FAILURE; - struct CMD_GET_LTE_SAFE_CHN rQuery_LTE_SAFE_CHN; - - kalMemZero(&rQuery_LTE_SAFE_CHN, sizeof(rQuery_LTE_SAFE_CHN)); - - do { - if (!prAdapter) - break; - - kalMemZero(&s_event_lte_safe_chn, sizeof(s_event_lte_safe_chn)); - - /* Get LTE safe channel list */ - wlanSendSetQueryCmd(prAdapter, - CMD_ID_GET_LTE_CHN, - FALSE, - TRUE, - FALSE, /* Query ID */ - oplus_WfdCmdEventQueryLteSafeChn, /* The handler to receive*/ - oplus_nicOidCmdTimeoutCommon, - sizeof(struct CMD_GET_LTE_SAFE_CHN), - (uint8_t *)&rQuery_LTE_SAFE_CHN, - &s_event_lte_safe_chn, - 0); - rResult = WLAN_STATUS_SUCCESS; - } while (0); - - return rResult; -} - - -static void get_avoid_channels(int* out_len, int* out_freqs, int max_num) -{ - struct ADAPTER *prAdapter = NULL; - uint32_t u4LteSafeChnBitMask_2G = 0, u4LteSafeChnBitMask_5G_1 = 0, - u4LteSafeChnBitMask_5G_2 = 0; - struct RF_CHANNEL_INFO aucChannelList[MAX_CHN_NUM]; - uint8_t ucNumOfChannel; - int freq; - int len = 0; - int index = 0; - enum ENUM_BAND eBand; - - *out_len = 0; - mutex_lock(&ctx_mutex); - - prAdapter = get_adapter(); - if (prAdapter == NULL) { - goto EXIT; - } - - reinit_completion(&s_avoid_channel_query_comp); - if (WLAN_STATUS_SUCCESS == oplus_wlanQueryLteSafeChannel(prAdapter, 0)) { - pr_debug("get_avoid_channels begine to wait for fw"); - if (!wait_for_completion_timeout(&s_avoid_channel_query_comp, msecs_to_jiffies(1000))) { - } else { - if (s_event_lte_safe_chn.u4Flags & BIT(0)) { - u4LteSafeChnBitMask_2G = s_event_lte_safe_chn - .rLteSafeChn.au4SafeChannelBitmask[0]; - u4LteSafeChnBitMask_5G_1 = s_event_lte_safe_chn - .rLteSafeChn.au4SafeChannelBitmask[1]; - u4LteSafeChnBitMask_5G_2 = s_event_lte_safe_chn - .rLteSafeChn.au4SafeChannelBitmask[2]; - } else { - goto EXIT; - } - - for (eBand = BAND_2G4; eBand <= BAND_5G; eBand++) { - kalMemZero(aucChannelList, sizeof(struct RF_CHANNEL_INFO) * MAX_CHN_NUM); - - rlmDomainGetChnlList(prAdapter, eBand, TRUE, MAX_CHN_NUM, - &ucNumOfChannel, aucChannelList); - - //goto safe channel loop - for (index = 0; index < ucNumOfChannel && len < max_num; index++) { - uint8_t ucIdx; - freq = -1; - ucIdx = wlanGetChannelIndex(eBand, aucChannelList[index].ucChannelNum); - if (ucIdx >= MAX_CHN_NUM) { - continue; - } - - if (aucChannelList[index].ucChannelNum <= 14) { - if (!(u4LteSafeChnBitMask_2G & BIT(aucChannelList[index].ucChannelNum))) { - freq = convertChannelToFrequency(aucChannelList[index].ucChannelNum); - } - } else if ((aucChannelList[index].ucChannelNum >= 36) && (aucChannelList[index].ucChannelNum <= 144)) { - if (!(u4LteSafeChnBitMask_5G_1 & BIT((aucChannelList[index].ucChannelNum - 36) / 4))) { - freq = convertChannelToFrequency(aucChannelList[index].ucChannelNum); - } - } else if ((aucChannelList[index].ucChannelNum >= 149) && (aucChannelList[index].ucChannelNum <= 181)) { - if (!(u4LteSafeChnBitMask_5G_2 & BIT((aucChannelList[index].ucChannelNum - 149) / 4))) { - freq = convertChannelToFrequency(aucChannelList[index].ucChannelNum); - } - } - if (freq > 0 && len < max_num) { - out_freqs[len++] = freq; - } - } - } - } - } else { - } - -EXIT: - *out_len = len; - mutex_unlock(&ctx_mutex); -} -#endif -/*************public begin********************/ -int oplus_wfd_get_remove_He_ie_flag(void) -{ - return is_remove_He_ie_from_prebe_request; -} - -void oplus_wfd_set_hdd_ctx(struct wireless_dev *hdd_ctx) -{ - mutex_lock(&ctx_mutex); - s_hdd_ctx = hdd_ctx; - mutex_unlock(&ctx_mutex); -} - -void oplus_register_oplus_wfd_wlan_ops_mtk(void) -{ - if (s_avoid_channel_query_comp_inited == 0) { - init_completion(&s_avoid_channel_query_comp); - s_avoid_channel_query_comp_inited = 1; - } - register_oplus_wfd_wlan_ops(&oplus_wfd_wlan_ops_mtk); -} -#endif diff --git a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/os/linux/gl_init.c b/drivers/misc/mediatek/connectivity/wlan/core/gen4m/os/linux/gl_init.c index 2daa6db77720..ec8becc6e685 100755 --- a/drivers/misc/mediatek/connectivity/wlan/core/gen4m/os/linux/gl_init.c +++ b/drivers/misc/mediatek/connectivity/wlan/core/gen4m/os/linux/gl_init.c @@ -96,11 +96,6 @@ #include "fw_log_wifi.h" #endif -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD -//XiaZijian@CONNECTIVITY.WIFI.BASIC.26106,20200703 -void oplus_wfd_set_hdd_ctx(struct wireless_dev *hdd_ctx); -void oplus_register_oplus_wfd_wlan_ops_mtk(void); -#endif /******************************************************************************* * C O N S T A N T S ******************************************************************************* @@ -3105,11 +3100,6 @@ static void wlanDestroyAllWdev(void) #if CFG_ENABLE_WIFI_DIRECT int i = 0; #endif -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD - //XiaZijian@CONNECTIVITY.WIFI.BASIC.26106,20200703 - DBGLOG(INIT, INFO, "wlanDestroyAllWdev"); - oplus_wfd_set_hdd_ctx(NULL); -#endif WIPHY_PRIV(wlanGetWiphy(), prGlueInfo); kalMemFree(prGlueInfo, VIR_MEM_TYPE, sizeof(struct GLUE_INFO)); @@ -3508,10 +3498,6 @@ void wlanNetDestroy(struct wireless_dev *prWdev) struct GLUE_INFO *prGlueInfo = NULL; ASSERT(prWdev); -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD - //XiaZijian@CONNECTIVITY.WIFI.BASIC.26106,20200703 - oplus_wfd_set_hdd_ctx(NULL); -#endif if (!prWdev) { DBGLOG(INIT, ERROR, "The device context is NULL\n"); return; @@ -5942,13 +5928,6 @@ static int32_t wlanProbe(void *pvData, void *pvDriverData) break; } } -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD -//XiaZijian@CONNECTIVITY.WIFI.BASIC.26106,20200703 - if (i4Status == 0) { - oplus_wfd_set_hdd_ctx(gprWdev[0]); - oplus_register_oplus_wfd_wlan_ops_mtk(); - } -#endif return i4Status; } /* end of wlanProbe() */ @@ -6003,10 +5982,6 @@ static void wlanRemove(void) uint8_t i; #endif DBGLOG(INIT, INFO, "Remove wlan!\n"); -#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD - //XiaZijian@CONNECTIVITY.WIFI.BASIC.26106,20200703 - oplus_wfd_set_hdd_ctx(NULL); -#endif kalSetHalted(TRUE); /*reset NVRAM State to ready for the next wifi-no*/ diff --git a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.c b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.c index c644a60af6d3..08d5deaaa182 100755 --- a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.c +++ b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.c @@ -26,10 +26,6 @@ #include "modem_sys.h" #include "md_sys1_platform.h" -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -//MaiWentian@NETWORK.RF.1448074, 2018/06/26,Add for monitor modem crash -#include -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ #ifndef DB_OPT_DEFAULT #define DB_OPT_DEFAULT (0) /* Dummy macro define to avoid build error */ @@ -65,14 +61,6 @@ static void ccci_aed_v3(struct ccci_fsm_ee *mdee, unsigned int dump_flag, int md_dbg_dump_flag = per_md_data->md_dbg_dump_flag; #endif -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -//MaiWentian@NETWORK.RF.1448074, 2018/06/26,Add for monitor modem crash - int temp_i; - int checkID = 0; - unsigned int hashId = 0; - char *logBuf; - char *aed_str_for_hash = NULL; -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ int ret = 0; @@ -101,52 +89,6 @@ static void ccci_aed_v3(struct ccci_fsm_ee *mdee, unsigned int dump_flag, CCCI_ERROR_LOG(md_id, FSM, "%s-%d:snprintf fail,ret = %d\n", __func__, __LINE__, ret); memset(mdee->ex_start_time, 0x0, sizeof(mdee->ex_start_time)); -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -//MaiWentian@NETWORK.RF.1448074, 2018/06/26,Add for monitor modem crash - #define MCU_CORE_MSG "(MCU_core" - aed_str_for_hash = aed_str; - if( aed_str_for_hash != NULL ) { - if( (strncmp(aed_str_for_hash, MCU_CORE_MSG, strlen(MCU_CORE_MSG)) == 0) ) { - while(aed_str_for_hash[0] != '\n') { - ++aed_str_for_hash; - } - ++aed_str_for_hash; //skip '\n' - } - hashId = BKDRHash(aed_str_for_hash, strlen(aed_str_for_hash)); - } - else { - CCCI_ERROR_LOG(md_id, FSM, "aed_str_for_hash is null!!"); - } - logBuf = vmalloc(BUF_LOG_LENGTH); - if ((logBuf != NULL)&&(aed_str_for_hash != NULL)) { - for (temp_i = 0 ; (temp_i < BUF_LOG_LENGTH) && (temp_i < strlen(aed_str_for_hash)) ; temp_i++) { - //chenyihuai@NETWORK.EM, 2019/12/12, Modify for some othe type dump,start - /* - if(aed_str_for_hash[temp_i] == '\n') { - logBuf[temp_i] = '\0'; - break; - } - logBuf[temp_i] = aed_str_for_hash[temp_i]; - */ - if(aed_str_for_hash[temp_i] == '\n') { - checkID++; - CCCI_ERROR_LOG(md_id, FSM, "checkID = %d",checkID); - if(2 == checkID) { - logBuf[temp_i] = '\0'; - break; - } - logBuf[temp_i] = ' '; - }else { - logBuf[temp_i] = aed_str_for_hash[temp_i]; - } - //end - } - logBuf[BUF_LOG_LENGTH - 1] = '\0'; - CCCI_NORMAL_LOG(md_id, FSM, "modem crash wirte to critical log. hashid = %u, cause = %s.", hashId, logBuf); - mm_keylog_write_modemdump(hashId, logBuf, MODEM_MONITOR_ID, "modem"); - vfree(logBuf); - } -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ /* MD ID must sync with aee_dump_ccci_debug_info() */ err_exit1: if (dump_flag & CCCI_AED_DUMP_CCIF_REG) { diff --git a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.h b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.h index fe75610ac2ea..d3ed5e575725 100755 --- a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.h +++ b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v3.h @@ -230,11 +230,5 @@ struct mdee_dumper_v3 { /* request by modem, change to 2k: include struct ex_PL_log*/ unsigned char ex_pl_info[MD_HS1_FAIL_DUMP_SIZE]; }; -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -//MaiWentian@NETWORK.RF.1448074, 2018/06/26,Add for monitor modem crash -#define MODEM_MONITOR_ID 509 //modem crash -#define BUF_LOG_LENGTH 2148 -unsigned int BKDRHash(const char* str, unsigned int len); -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ #endif /* __MDEE_DUMPER_V3_H__ */ diff --git a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.c b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.c index 0f3b08d356ce..2f86622a96cb 100755 --- a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.c +++ b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.c @@ -22,9 +22,6 @@ #include "ccci_config.h" #include "ccci_fsm_sys.h" -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -#include -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ #ifndef DB_OPT_DEFAULT #define DB_OPT_DEFAULT (0) /* Dummy macro define to avoid build error */ @@ -60,13 +57,6 @@ static void ccci_aed_v5(struct ccci_fsm_ee *mdee, unsigned int dump_flag, int md_dbg_dump_flag = per_md_data->md_dbg_dump_flag; #endif -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP - int temp_i; - int checkID = 0; - unsigned int hashId = 0; - char *logBuf; - char *aed_str_for_hash = NULL; -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ int ret = 0; @@ -97,43 +87,6 @@ static void ccci_aed_v5(struct ccci_fsm_ee *mdee, unsigned int dump_flag, goto err_exit1; } memset(mdee->ex_start_time, 0x0, sizeof(mdee->ex_start_time)); -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP - #define MCU_CORE_MSG "(MCU_core" - aed_str_for_hash = aed_str; - if( aed_str_for_hash != NULL ) { - if( (strncmp(aed_str_for_hash, MCU_CORE_MSG, strlen(MCU_CORE_MSG)) == 0) ) { - while(aed_str_for_hash[0] != '\n') { - ++aed_str_for_hash; - } - ++aed_str_for_hash; //skip '\n' - } - hashId = BKDRHash(aed_str_for_hash, strlen(aed_str_for_hash)); - } - else { - CCCI_ERROR_LOG(md_id, FSM, "aed_str_for_hash is null!!"); - } - logBuf = vmalloc(BUF_LOG_LENGTH); - if ((logBuf != NULL)&&(aed_str_for_hash != NULL)) { - for (temp_i = 0 ; (temp_i < BUF_LOG_LENGTH) && (temp_i < strlen(aed_str_for_hash)) ; temp_i++) { - if(aed_str_for_hash[temp_i] == '\n') { - checkID++; - CCCI_ERROR_LOG(md_id, FSM, "checkID = %d",checkID); - if(2 == checkID) { - logBuf[temp_i] = '\0'; - break; - } - logBuf[temp_i] = ' '; - }else { - logBuf[temp_i] = aed_str_for_hash[temp_i]; - } - //end - } - logBuf[BUF_LOG_LENGTH - 1] = '\0'; - CCCI_NORMAL_LOG(md_id, FSM, "modem crash wirte to critical log. hashid = %u, cause = %s.", hashId, logBuf); - mm_keylog_write_modemdump(hashId, logBuf, MODEM_MONITOR_ID, "modem"); - vfree(logBuf); - } -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ /* MD ID must sync with aee_dump_ccci_debug_info() */ err_exit1: if (dump_flag & CCCI_AED_DUMP_CCIF_REG) { @@ -1003,21 +956,3 @@ int mdee_dumper_v5_alloc(struct ccci_fsm_ee *mdee) return 0; } -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -unsigned int BKDRHash(const char* str, unsigned int len) -{ - unsigned int seed = 131; /* 31 131 1313 13131 131313 etc.. */ - unsigned int hash = 0; - int i = 0; - - if (str == NULL) { - return 0; - } - - for(i = 0; i < len; str++, i++) { - hash = (hash * seed) + (*str); - } - - return hash; -} -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ diff --git a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.h b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.h index 751983e2991f..b5178d848374 100755 --- a/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.h +++ b/drivers/misc/mediatek/eccci/fsm/mdee_dumper_v5.h @@ -239,10 +239,4 @@ struct mdee_dumper_v5 { /* request by modem, change to 2k: include struct ex_PL_log*/ unsigned char ex_pl_info[MD_HS1_FAIL_DUMP_SIZE]; }; -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -#define MODEM_MONITOR_ID 509 //modem crash -#define BUF_LOG_LENGTH 2148 -unsigned int BKDRHash(const char* str, unsigned int len); -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ #endif /* __MDEE_DUMPER_V5_H__ */ - diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r14p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r14p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index a22e0197bc19..b6cb3b91df06 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r14p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r14p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,24 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r15p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r15p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index a22e0197bc19..b6cb3b91df06 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r15p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r15p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,24 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r16p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r16p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 6921d2bb3391..079f2dabcedc 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r16p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r16p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,25 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -f;kf -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r18p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r18p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index a47fb352c738..3524a2c7e084 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r18p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r18p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,24 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r19p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r19p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index c78aef01f271..3524a2c7e084 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r19p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r19p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,25 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r20p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r20p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index a47fb352c738..3524a2c7e084 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r20p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r20p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,24 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r24p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r24p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index a47fb352c738..3524a2c7e084 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r24p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r24p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -166,24 +166,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 59d00f9412ba..cd535a5f8c73 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_bifrost/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -193,24 +193,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return 0; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 8142bf174802..ccb7c2e5e2a7 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r25p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -195,24 +195,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return 0; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r27p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r27p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 4bf43baeecb0..41a123047a84 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r27p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r27p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -170,24 +170,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r28p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r28p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 4bf43baeecb0..41a123047a84 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r28p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r28p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -170,24 +170,6 @@ static int proc_gpu_memoryusage_show(struct seq_file *m, void *v) return ret; } -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - static int kbasep_gpu_memoryusage_debugfs_open(struct inode *in, struct file *file) { return single_open(file, proc_gpu_memoryusage_show, NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r30p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r30p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index eabe819decec..b523bf62858a 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r30p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r30p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -142,24 +142,6 @@ static int mtk_common_gpu_memory_show(struct seq_file *m, void *v) DEFINE_SHOW_ATTRIBUTE(mtk_common_gpu_utilization); DEFINE_SHOW_ATTRIBUTE(mtk_common_gpu_memory); -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - void mtk_common_procfs_init(void) { mtk_mali_root = proc_mkdir("mtk_mali", NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index e56c7a3be69f..93de32fa55d4 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p0/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -141,24 +141,6 @@ static int mtk_common_gpu_memory_show(struct seq_file *m, void *v) } DEFINE_SHOW_ATTRIBUTE(mtk_common_gpu_memory); -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - void mtk_common_procfs_init(void) { mtk_mali_root = proc_mkdir("mtk_mali", NULL); diff --git a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p1/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p1/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c index 73414d2a638d..93de32fa55d4 100644 --- a/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p1/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c +++ b/drivers/misc/mediatek/gpu/gpu_mali/mali_valhall/mali-r32p1/drivers/gpu/arm/midgard/platform/mtk_platform_common/mtk_platform_common.c @@ -141,42 +141,6 @@ static int mtk_common_gpu_memory_show(struct seq_file *m, void *v) } DEFINE_SHOW_ATTRIBUTE(mtk_common_gpu_memory); -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -int get_gl_mem_by_pid(pid_t pid) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gl_mem_by_pid); -#endif - -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ -unsigned long get_gpumem_by_pid(pid_t pid, int mem_type) -{ - ssize_t ret = 0; -#ifdef ENABLE_MTK_MEMINFO - int i = 0; - for (i = 0; (i < MTK_MEMINFO_SIZE) && (g_mtk_gpu_meminfo[i].pid != 0); i++) { - if(g_mtk_gpu_meminfo[i].pid == pid) { //no lock protecte? - return P2K(g_mtk_gpu_meminfo[i].used_pages); - } - } -#endif /* ENABLE_MTK_MEMINFO */ - return ret; -} -EXPORT_SYMBOL(get_gpumem_by_pid); -#endif - void mtk_common_procfs_init(void) { mtk_mali_root = proc_mkdir("mtk_mali", NULL); diff --git a/drivers/misc/mediatek/gud/500/MobiCoreDriver/nq.c b/drivers/misc/mediatek/gud/500/MobiCoreDriver/nq.c index e8e53be28e83..cd80bb813a24 100755 --- a/drivers/misc/mediatek/gud/500/MobiCoreDriver/nq.c +++ b/drivers/misc/mediatek/gud/500/MobiCoreDriver/nq.c @@ -54,10 +54,6 @@ #define NQ_TEE_WORKER_THREADS 1 #endif -//#ifdef OPLUS_FEATURE_SECURITY_COMMON -extern int phx_is_system_boot_completed(void); -//#endif /* OPLUS_FEATURE_SECURITY_COMMON */ - static struct { struct mutex buffer_mutex; /* Lock on SWd communication buffer */ struct mcp_buffer *mcp_buffer; @@ -517,10 +513,6 @@ static void nq_dump_status(void) size_t i; cpumask_t old_affinity; -//#ifdef OPLUS_FEATURE_SECURITY_COMMON - int boot_completed_tee = 0; -//#endif /* OPLUS_FEATURE_SECURITY_COMMON */ - if (l_ctx.dump.off) ret = -EBUSY; @@ -566,16 +558,7 @@ static void nq_dump_status(void) tee_restore_affinity(old_affinity); mc_dev_info(" %-22s= 0x%s", "mcExcep.uuid", uuid_str); - //#ifdef OPLUS_FEATURE_SECURITY_COMMON - if(0 == strcmp(uuid_str, "07170000000000000000000000000000")) { - boot_completed_tee = phx_is_system_boot_completed(); - if(boot_completed_tee == 1) { - mc_dev_info("tee boot complete\n"); - } else { - BUG(); - } - } - //#endif /* OPLUS_FEATURE_SECURITY_COMMON */ + if (ret >= 0) ret = kasnprintf(&l_ctx.dump, "%-22s= 0x%s\n", "mcExcep.uuid", uuid_str); diff --git a/drivers/misc/mediatek/include/mt-plat/mtk_rtc.h b/drivers/misc/mediatek/include/mt-plat/mtk_rtc.h index c98fd44c7129..c32505cf2a8c 100755 --- a/drivers/misc/mediatek/include/mt-plat/mtk_rtc.h +++ b/drivers/misc/mediatek/include/mt-plat/mtk_rtc.h @@ -60,9 +60,6 @@ extern void oppo_rtc_mark_edl(void); extern void oppo_rtc_mark_sensor_cause_panic(void); extern int oppo_get_rtc_sensor_cause_panic_value(void); extern void oppo_clear_rtc_sensor_cause_panic(void); -#ifdef OPLUS_FEATURE_AGINGTEST -extern void oppo_rtc_mark_agingtest(void); -#endif /*OPLUS_FEATURE_AGINGTEST */ #endif /* OPLUS_BUG_STABILITY */ extern u16 rtc_rdwr_uart_bits(u16 *val); extern void rtc_bbpu_power_down(void); @@ -105,9 +102,6 @@ extern bool crystal_exist_status(void); #define oppo_rtc_mark_sensor_cause_panic() do {} while (0) #define oppo_get_rtc_sensor_cause_panic_value() do {} while (0) #define oppo_clear_rtc_sensor_cause_panic() do {} while (0) -#ifdef OPLUS_FEATURE_AGINGTEST -#define oppo_rtc_mark_agingtest() do {} while (0) -#endif /*OPLUS_FEATURE_AGINGTEST */ #endif /* OPLUS_BUG_STABILITY */ #define rtc_read_pwron_alarm(alm) ({ 0; }) #define get_rtc_spare_fg_value() ({ 0; }) diff --git a/drivers/misc/mediatek/include/mt-plat/mtk_rtc_hal_common.h b/drivers/misc/mediatek/include/mt-plat/mtk_rtc_hal_common.h index b2782f569b0f..5b73601c5626 100644 --- a/drivers/misc/mediatek/include/mt-plat/mtk_rtc_hal_common.h +++ b/drivers/misc/mediatek/include/mt-plat/mtk_rtc_hal_common.h @@ -52,9 +52,6 @@ enum rtc_spare_enum { RTC_SENSOR_CAUSE_PANIC, #endif /* OPLUS_BUG_STABILITY */ RTC_SAFE_BOOT, -#ifdef OPLUS_FEATURE_AGINGTEST - RTC_AGINGTEST_BOOT, -#endif /*OPLUS_FEATURE_AGINGTEST */ RTC_SPAR_NUM }; diff --git a/drivers/misc/mediatek/mlog/mlog_logger.c b/drivers/misc/mediatek/mlog/mlog_logger.c index 172bd06bce01..e4eb7f50fa9e 100644 --- a/drivers/misc/mediatek/mlog/mlog_logger.c +++ b/drivers/misc/mediatek/mlog/mlog_logger.c @@ -35,9 +35,6 @@ #include #include -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#include -#endif #ifdef CONFIG_MTK_GPU_SUPPORT #include @@ -408,35 +405,16 @@ static void mlog_buddyinfo(void) for_each_populated_zone(zone) { unsigned long flags; unsigned int order; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned long nr[FREE_AREA_COUNTS][MAX_ORDER] = {0}; - unsigned int flc; -#else unsigned long nr[MAX_ORDER] = {0}; -#endif spin_lock_irqsave(&zone->lock, flags); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; ++flc) { - for (order = 0; order < MAX_ORDER; ++order) - nr[flc][order] = zone->free_area[flc][order].nr_free; - } -#else for (order = 0; order < MAX_ORDER; ++order) nr[order] = zone->free_area[order].nr_free; -#endif spin_unlock_irqrestore(&zone->lock, flags); /* emit logs */ spin_lock_bh(&mlogbuf_lock); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; ++flc) { - for (order = 0; order < MAX_ORDER; ++order) - mlog_emit(nr[flc][order]); - } -#else for (order = 0; order < MAX_ORDER; ++order) mlog_emit(nr[order]); -#endif spin_unlock_bh(&mlogbuf_lock); } } diff --git a/drivers/misc/mediatek/performance/fpsgo_v3/fbt/include/fbt_usedext.h b/drivers/misc/mediatek/performance/fpsgo_v3/fbt/include/fbt_usedext.h index 2bbf93e8dbc3..4cb23180f959 100755 --- a/drivers/misc/mediatek/performance/fpsgo_v3/fbt/include/fbt_usedext.h +++ b/drivers/misc/mediatek/performance/fpsgo_v3/fbt/include/fbt_usedext.h @@ -23,14 +23,8 @@ extern unsigned int mt_ppm_userlimit_freq_limit_by_others( unsigned int cluster); extern unsigned long get_cpu_orig_capacity(unsigned int cpu); extern int upower_get_turn_point(void); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -extern void set_capacity_margin_dvfs(unsigned int margin); -extern void set_capacity_margin_dvfs_changed(bool changed); -extern unsigned int get_capacity_margin_dvfs(void); -#else extern void set_capacity_margin(unsigned int margin); extern unsigned int get_capacity_margin(void); -#endif extern void set_user_nice(struct task_struct *p, long nice); extern int fpsgo_fbt2minitop_start(int count, struct fpsgo_loading *fl); diff --git a/drivers/misc/mediatek/performance/fpsgo_v3/fbt/src/fbt_cpu.c b/drivers/misc/mediatek/performance/fpsgo_v3/fbt/src/fbt_cpu.c index a88ef0fca041..a1180259a64c 100755 --- a/drivers/misc/mediatek/performance/fpsgo_v3/fbt/src/fbt_cpu.c +++ b/drivers/misc/mediatek/performance/fpsgo_v3/fbt/src/fbt_cpu.c @@ -687,20 +687,10 @@ static void fbt_set_cap_margin_locked(int set) fpsgo_systrace_c_fbt_gm(-100, 0, set?1024:def_capacity_margin, "cap_margin"); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - if (set) - set_capacity_margin_dvfs(1024); - else - set_capacity_margin_dvfs(def_capacity_margin); -#if defined(CONFIG_SCHEDUTIL_USE_TL) - set_capacity_margin_dvfs_changed(!!set); -#endif /* CONFIG_SCHEDUTIL_USE_TL */ -#else if (set) set_capacity_margin(1024); else set_capacity_margin(def_capacity_margin); -#endif /* OPLUS_FEATURE_SCHEDUTIL_USE_TL */ set_cap_margin = set; } @@ -4629,15 +4619,9 @@ static ssize_t enable_switch_cap_margin_show(struct kobject *kobj, FPSGO_SYSFS_MAX_BUFF_SIZE - posi, "set_cap_margin %d\n", set_cap_margin); posi += length; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - length = scnprintf(temp + posi, - FPSGO_SYSFS_MAX_BUFF_SIZE - posi, - "get_cap_margin %d\n", get_capacity_margin_dvfs()); -#else length = scnprintf(temp + posi, FPSGO_SYSFS_MAX_BUFF_SIZE - posi, "get_cap_margin %d\n", get_capacity_margin()); -#endif posi += length; mutex_unlock(&fbt_mlock); @@ -5180,11 +5164,7 @@ int __init fbt_cpu_init(void) fbt_down_throttle_enable = 1; sync_flag = -1; fbt_sync_flag_enable = 1; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - def_capacity_margin = get_capacity_margin_dvfs(); -#else def_capacity_margin = get_capacity_margin(); -#endif fbt_cap_margin_enable = 1; boost_ta = fbt_get_default_boost_ta(); adjust_loading = fbt_get_default_adj_loading(); diff --git a/drivers/misc/mediatek/rtc/mt6358/mtk_rtc_hal.c b/drivers/misc/mediatek/rtc/mt6358/mtk_rtc_hal.c index 840add7ef282..c8556fc88bd7 100644 --- a/drivers/misc/mediatek/rtc/mt6358/mtk_rtc_hal.c +++ b/drivers/misc/mediatek/rtc/mt6358/mtk_rtc_hal.c @@ -121,9 +121,6 @@ u16 rtc_spare_reg[RTC_SPAR_NUM][3] = { {RTC_SPAR0, 0x1, 12}, {RTC_SPAR0, 0x1, 13}, #endif -#ifdef OPLUS_FEATURE_AGINGTEST - {RTC_SPAR0, 0x01, 14}, -#endif /*OPLUS_FEATURE_AGINGTEST */ #ifdef CONFIG_OPLUS_CHARGER_MTK6771 {RTC_SPAR0, 0x01, 15}, #endif /* OPLUS_BUG_STABILITY */ diff --git a/drivers/misc/mediatek/rtc/mtk_rtc_common.c b/drivers/misc/mediatek/rtc/mtk_rtc_common.c index c36d1430db60..749a83f96e25 100644 --- a/drivers/misc/mediatek/rtc/mtk_rtc_common.c +++ b/drivers/misc/mediatek/rtc/mtk_rtc_common.c @@ -468,17 +468,6 @@ void oppo_rtc_mark_factory(void) spin_unlock_irqrestore(&rtc_lock, flags); } -#ifdef OPLUS_FEATURE_AGINGTEST -void oppo_rtc_mark_agingtest(void) -{ - unsigned long flags; - - rtc_xinfo("rtc_mark_agingtest\n"); - spin_lock_irqsave(&rtc_lock, flags); - hal_rtc_set_spare_register(RTC_AGINGTEST_BOOT, 0x01); - spin_unlock_irqrestore(&rtc_lock, flags); -} -#endif /*OPLUS_FEATURE_AGINGTEST */ void oppo_rtc_mark_safe(void) { diff --git a/drivers/misc/mediatek/sched/sched_ctl.c b/drivers/misc/mediatek/sched/sched_ctl.c index e73f074b0145..3013d4a7e8bd 100755 --- a/drivers/misc/mediatek/sched/sched_ctl.c +++ b/drivers/misc/mediatek/sched/sched_ctl.c @@ -34,9 +34,6 @@ #include "mtk_devinfo.h" #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #define SCHED_HINT_THROTTLE_NSEC 10000000 /* 10ms for throttle */ @@ -408,8 +405,7 @@ err: late_initcall(sched_hint_init); #ifdef CONFIG_MTK_SCHED_BOOST -//OPLUS_FEATURE_SCHED_ASSIST remove static -/*static*/ int sched_boost_type = SCHED_NO_BOOST; +static int sched_boost_type = SCHED_NO_BOOST; inline int valid_cpu_prefer(int task_prefer) { @@ -616,9 +612,6 @@ void __init init_efuse_info(void) efuse_aware_big_thermal = (get_devinfo_with_index(7) & 0xFF) == 0x30; } #endif -#ifdef CONFIG_MTK_SCHED_BOOST -extern oplus_task_sched_boost(struct task_struct *p, int *task_prefer); -#endif int select_task_prefer_cpu(struct task_struct *p, int new_cpu) { int task_prefer; @@ -633,15 +626,6 @@ int select_task_prefer_cpu(struct task_struct *p, int new_cpu) #endif task_prefer = cpu_prefer(p); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if(task_prefer == SCHED_PREFER_LITTLE && (test_task_ux(p) || is_sf(p)) && sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE)|| sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM))){ - task_prefer = SCHED_PREFER_NONE; - p->cpu_prefer = SCHED_PREFER_NONE; - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef CONFIG_MTK_SCHED_BOOST //OPLUS_FEATURE_SCHED_ASSIST - oplus_task_sched_boost(p, &task_prefer); -#endif if (!hinted_cpu_prefer(task_prefer)) goto out; @@ -651,17 +635,8 @@ int select_task_prefer_cpu(struct task_struct *p, int new_cpu) } for (i = 0; i < domain_cnt; i++) { -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (task_prefer == SCHED_PREFER_BIG) - iter_domain = domain_cnt - i - 1; - else if (task_prefer == SCHED_PREFER_MEDIUM) - iter_domain = (i < domain_cnt -1) ? i + 1 : 0; - else - iter_domain = i; -#else iter_domain = (task_prefer == SCHED_PREFER_BIG) ? domain_cnt-i-1 : i; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ domain = tmp_domain[iter_domain]; @@ -789,9 +764,7 @@ int set_sched_boost(unsigned int val) if (val == SCHED_ALL_BOOST) sched_scheduler_switch(SCHED_HMP_LB); else if (val == SCHED_FG_BOOST) { - //OPLUS_FEATURE_SCHED_ASSIST - //In MTK platform,we use oplus_task_sched_boost - //sched_set_boost_fg(); + sched_set_boost_fg(); } } printk_deferred("[name:sched_boost&] sched boost: set %d\n", @@ -949,13 +922,8 @@ int sched_walt_enable(int user, int en) } #ifdef CONFIG_SCHED_WALT -#ifdef OPLUS_FEATURE_SCHED_ASSIST - sysctl_sched_use_walt_cpu_util = 0; - sysctl_sched_use_walt_task_util = 0; -#else /* OPLUS_FEATURE_SCHED_ASSIST */ sysctl_sched_use_walt_cpu_util = walted; sysctl_sched_use_walt_task_util = walted; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ trace_sched_ctl_walt(user_mask, walted); #endif diff --git a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Kconfig b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Kconfig index 6a23b32a8a43..5a7d90766e27 100755 --- a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Kconfig +++ b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Kconfig @@ -3,8 +3,3 @@ config OPLUS_SENSOR_MTK68XX default n help It support 68xx. -config OPLUS_SENSOR_FB_MTK - tristate "sensor feedback config for qcom" - help - To compile this driver as a module, set M in kernel build config - module will be called sensor_feedback. diff --git a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Makefile b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Makefile index d3ccba0ad410..52c88702541a 100755 --- a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Makefile +++ b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/Makefile @@ -15,4 +15,3 @@ subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/scp/$(CONFIG_MTK_PLATFORM subdir-ccflags-y += -D CONFIG_OPLUS_SENSOR_MTK68XX endif obj-$(CONFIG_NANOHUB) += sensor_devinfo.o -obj-$(CONFIG_OPLUS_SENSOR_FB_MTK) += oplus_sensor_feedback/ diff --git a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile deleted file mode 100755 index f14ee11a5ee8..000000000000 --- a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -oplus_bsp_sensor_feedback-y := sensor_feedback.o -obj-$(CONFIG_OPLUS_SENSOR_FB_MTK) += oplus_bsp_sensor_feedback.o diff --git a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c deleted file mode 100755 index 21c7cf709e3a..000000000000 --- a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c +++ /dev/null @@ -1,607 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - - -#define pr_fmt(fmt) "" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "scp_helper.h" -#include "sensor_feedback.h" -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK -#include -#endif - -#define SENSOR_DEVICE_TYPE "10002" -#define SENSOR_POWER_TYPE "10003" -#define SENSOR_STABILITY_TYPE "10004" -#define SENSOR_PFMC_TYPE "10005" -#define SENSOR_MEMORY_TYPE "10006" - -#define SENSOR_DEBUG_DEVICE_TYPE "20002" -#define SENSOR_DEBUG_POWER_TYPE "20003" -#define SENSOR_DEBUG_STABILITY_TYPE "20004" -#define SENSOR_DEBUG_PFMC_TYPE "20005" -#define SENSOR_DEBUG_MEMORY_TYPE "20006" - - -static struct sensor_fb_cxt *g_sensor_fb_cxt = NULL; - -/*fb_field :maxlen 19*/ -struct sensor_fb_conf g_fb_conf[] = { - {PS_INIT_FAIL_ID, "device_ps_init_fail", SENSOR_DEVICE_TYPE}, - {PS_I2C_ERR_ID, "device_ps_i2c_err", SENSOR_DEVICE_TYPE}, - {PS_ALLOC_FAIL_ID, "device_ps_alloc_fail", SENSOR_DEVICE_TYPE}, - {PS_ESD_REST_ID, "device_ps_esd_reset", SENSOR_DEVICE_TYPE}, - {PS_NO_INTERRUPT_ID, "device_ps_no_irq", SENSOR_DEVICE_TYPE}, - {PS_FIRST_REPORT_DELAY_COUNT_ID, "device_ps_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {PS_ORIGIN_DATA_TO_ZERO_ID, "device_ps_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {PS_CALI_DATA_ID, "device_ps_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {ALS_INIT_FAIL_ID, "device_als_init_fail", SENSOR_DEVICE_TYPE}, - {ALS_I2C_ERR_ID, "device_als_i2c_err", SENSOR_DEVICE_TYPE}, - {ALS_ALLOC_FAIL_ID, "device_als_alloc_fail", SENSOR_DEVICE_TYPE}, - {ALS_ESD_REST_ID, "device_als_esd_reset", SENSOR_DEVICE_TYPE}, - {ALS_NO_INTERRUPT_ID, "device_als_no_irq", SENSOR_DEVICE_TYPE}, - {ALS_FIRST_REPORT_DELAY_COUNT_ID, "device_als_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {ALS_ORIGIN_DATA_TO_ZERO_ID, "device_als_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {ALS_CALI_DATA_ID, "device_als_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {ACCEL_INIT_FAIL_ID, "device_acc_init_fail", SENSOR_DEVICE_TYPE}, - {ACCEL_I2C_ERR_ID, "device_acc_i2c_err", SENSOR_DEVICE_TYPE}, - {ACCEL_ALLOC_FAIL_ID, "device_acc_alloc_fail", SENSOR_DEVICE_TYPE}, - {ACCEL_ESD_REST_ID, "device_acc_esd_reset", SENSOR_DEVICE_TYPE}, - {ACCEL_NO_INTERRUPT_ID, "device_acc_no_irq", SENSOR_DEVICE_TYPE}, - {ACCEL_FIRST_REPORT_DELAY_COUNT_ID, "device_acc_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {ACCEL_ORIGIN_DATA_TO_ZERO_ID, "device_acc_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {ACCEL_CALI_DATA_ID, "device_acc_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {GYRO_INIT_FAIL_ID, "device_gyro_init_fail", SENSOR_DEVICE_TYPE}, - {GYRO_I2C_ERR_ID, "device_gyro_i2c_err", SENSOR_DEVICE_TYPE}, - {GYRO_ALLOC_FAIL_ID, "device_gyro_alloc_fail", SENSOR_DEVICE_TYPE}, - {GYRO_ESD_REST_ID, "device_gyro_esd_reset", SENSOR_DEVICE_TYPE}, - {GYRO_NO_INTERRUPT_ID, "device_gyro_no_irq", SENSOR_DEVICE_TYPE}, - {GYRO_FIRST_REPORT_DELAY_COUNT_ID, "device_gyro_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {GYRO_ORIGIN_DATA_TO_ZERO_ID, "device_gyro_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {GYRO_CALI_DATA_ID, "device_gyro_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {MAG_INIT_FAIL_ID, "device_mag_init_fail", SENSOR_DEVICE_TYPE}, - {MAG_I2C_ERR_ID, "device_mag_i2c_err", SENSOR_DEVICE_TYPE}, - {MAG_ALLOC_FAIL_ID, "device_mag_alloc_fail", SENSOR_DEVICE_TYPE}, - {MAG_ESD_REST_ID, "device_mag_esd_reset", SENSOR_DEVICE_TYPE}, - {MAG_NO_INTERRUPT_ID, "device_mag_no_irq", SENSOR_DEVICE_TYPE}, - {MAG_FIRST_REPORT_DELAY_COUNT_ID, "device_mag_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {MAG_ORIGIN_DATA_TO_ZERO_ID, "device_mag_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {MAG_CALI_DATA_ID, "device_mag_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {SAR_INIT_FAIL_ID, "device_sar_init_fail", SENSOR_DEVICE_TYPE}, - {SAR_I2C_ERR_ID, "device_sar_i2c_err", SENSOR_DEVICE_TYPE}, - {SAR_ALLOC_FAIL_ID, "device_sar_alloc_fail", SENSOR_DEVICE_TYPE}, - {SAR_ESD_REST_ID, "device_sar_esd_reset", SENSOR_DEVICE_TYPE}, - {SAR_NO_INTERRUPT_ID, "device_sar_no_irq", SENSOR_DEVICE_TYPE}, - {SAR_FIRST_REPORT_DELAY_COUNT_ID, "device_sar_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {SAR_ORIGIN_DATA_TO_ZERO_ID, "device_sar_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {SAR_CALI_DATA_ID, "device_sar_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {POWER_SENSOR_INFO_ID, "debug_power_sns_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_ACCEL_INFO_ID, "debug_power_acc_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_GYRO_INFO_ID, "debug_power_gyro_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_MAG_INFO_ID, "debug_power_mag_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_PROXIMITY_INFO_ID, "debug_power_prox_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_LIGHT_INFO_ID, "debug_power_light_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_WISE_LIGHT_INFO_ID, "debug_power_wiseligt_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_WAKE_UP_RATE_ID, "debug_power_wakeup_rate", SENSOR_DEBUG_POWER_TYPE}, - {POWER_ADSP_SLEEP_RATIO_ID, "power_adsp_sleep_ratio", SENSOR_POWER_TYPE}, - - {DOUBLE_TAP_REPORTED_ID, "device_double_tap_reported", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_NEAR_ID, "device_double_tap_prevented_by_near", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_ATTITUDE_ID, "device_double_prevented_by_attitude", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_FREEFALL_Z_ID, "device_double_prevented_by_freefall_z", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_FREEFALL_SLOPE_ID, "device_double_prevented_by_freefall_slope", SENSOR_DEBUG_DEVICE_TYPE}, - - {ALAILABLE_SENSOR_LIST_ID, "available_sensor_list", SENSOR_DEBUG_DEVICE_TYPE}, - - {HAL_SENSOR_NOT_FOUND, "device_hal_not_found", SENSOR_DEVICE_TYPE}, - {HAL_QMI_ERROR, "device_hal_qmi_error", SENSOR_DEVICE_TYPE}, - {HAL_SENSOR_TIMESTAMP_ERROR, "device_hal_ts_error", SENSOR_DEBUG_DEVICE_TYPE} - -}; - -static int find_event_id(int16_t event_id) -{ - int len = sizeof(g_fb_conf) / sizeof(g_fb_conf[0]); - int ret = -1; - int index = 0; - - for (index = 0; index < len; index++) { - if (g_fb_conf[index].event_id == event_id) { - ret = index; - } - } - - return ret; -} - -static ssize_t adsp_notify_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - - spin_lock(&sensor_fb_cxt->rw_lock); - adsp_event_counts = sensor_fb_cxt->adsp_event_counts; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d\n", adsp_event_counts); - return snprintf(buf, PAGE_SIZE, "%d\n", adsp_event_counts); -} - -static ssize_t adsp_notify_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - uint16_t node_type = 0; - int err = 0; - - err = sscanf(buf, "%hu %hu", &node_type, &adsp_event_counts); - - if (err < 0) { - pr_err("adsp_notify_store error: err = %d\n", err); - return err; - } - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d, node_type=%d\n", adsp_event_counts, - node_type); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - return count; -} - -int scp_notify_store(uint16_t node_type, uint16_t adsp_event_counts) -{ - if (g_sensor_fb_cxt != NULL) { - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d, node_type=%d\n", adsp_event_counts, - node_type); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - } else { - pr_err("error: g_sensor_fb_cxt is NULL\n"); - } - return 0; -} - -static ssize_t hal_info_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - uint16_t event_ct = 0; - uint16_t event_id = 0; - char strbuf[32] = {0x00}; - int err = 0; - int index = 0; - unsigned char payload[1024] = {0x00}; - - pr_info("hal_info_store\n"); - memset(strbuf, 0, 32); - memset(payload, 0, 1024); - - err = sscanf(buf, "%u %u %31s", &event_id, &event_ct, strbuf); - - if (err < 0) { - pr_err("hal_info_store error: err = %d\n", err); - return count; - } - - strbuf[31] = '\0'; - - index = find_event_id(event_id); - - if (index == -1) { - pr_info("nout find event_id =%d\n", event_id); - return count; - } - - scnprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%d$$detailData@@%s", - g_fb_conf[index].fb_field, - event_ct, - strbuf); - pr_info("payload =%s\n", payload); - -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK - oplus_kevent_fb(FB_SENSOR, g_fb_conf[index].fb_event_id, payload); -#endif - return count; -} - - -static ssize_t test_id_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - uint16_t node_type = 0; - uint16_t event_id = 0; - uint16_t event_data = 0; - int err = 0; - - err = sscanf(buf, "%hu %hu %hu %hu", &node_type, &adsp_event_counts, &event_id, - &event_data); - - if (err < 0) { - pr_err("test_id_store error: err = %d\n", err); - return count; - } - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - - sensor_fb_cxt->fb_smem.event[0].event_id = event_id; - sensor_fb_cxt->fb_smem.event[0].count = event_data; - - pr_info("test_id_store adsp_value = %d, node_type=%d \n", adsp_event_counts, - node_type); - pr_info("test_id_store event_id = %d, event_data=%d \n", event_id, event_data); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - return count; -} - -static ssize_t sensor_list_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t sensor_list[2] = {0x00}; - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_list[0] = sensor_fb_cxt->sensor_list[0]; - sensor_list[1] = sensor_fb_cxt->sensor_list[1]; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("phy = 0x%x, virt = 0x%x\n", sensor_list[0], sensor_list[1]); - - return snprintf(buf, PAGE_SIZE, "phy = 0x%x, virt = 0x%x\n", sensor_list[0], - sensor_list[1]); -} - -DEVICE_ATTR(adsp_notify, 0644, adsp_notify_show, adsp_notify_store); -DEVICE_ATTR(hal_info, 0644, NULL, hal_info_store); -DEVICE_ATTR(test_id, 0644, NULL, test_id_store); -DEVICE_ATTR(sensor_list, 0644, sensor_list_show, NULL); - -static struct attribute *sensor_feedback_attributes[] = { - &dev_attr_adsp_notify.attr, - &dev_attr_hal_info.attr, - &dev_attr_test_id.attr, - &dev_attr_sensor_list.attr, - NULL -}; - -static struct attribute_group sensor_feedback_attribute_group = { - .attrs = sensor_feedback_attributes -}; - -#define SMEM_SENSOR_FEEDBACK (128) -static int read_data_from_share_mem(struct sensor_fb_cxt *sensor_fb_cxt) -{ - void *smem_addr = NULL; - struct fb_event_smem *fb_event = NULL; - - smem_addr = (void *)(long)scp_get_reserve_mem_virt(SENS_FB_MEM_ID); - fb_event = (struct fb_event_smem *)smem_addr; - - if (fb_event == NULL) { - return -2; - } - - memcpy((void *)&sensor_fb_cxt->fb_smem, (void *)fb_event, - sizeof(sensor_fb_cxt->fb_smem)); - return 0; -} - -int procce_special_event_id(unsigned short event_id, int count, - struct sensor_fb_cxt *sensor_fb_cxt) -{ - int ret = 0; - - if (event_id == ALAILABLE_SENSOR_LIST_ID) { - sensor_fb_cxt->sensor_list[0] = (uint32_t) - sensor_fb_cxt->fb_smem.event[count].buff[0]; - sensor_fb_cxt->sensor_list[1] = (uint32_t) - sensor_fb_cxt->fb_smem.event[count].buff[1]; - pr_info("sensor_list virt_sns = 0x%x, phy_sns = 0x%x\n", - sensor_fb_cxt->sensor_list[0], sensor_fb_cxt->sensor_list[1]); - ret = 1; - } - - return ret; -} - -static int parse_shr_info(struct sensor_fb_cxt *sensor_fb_cxt) -{ - int ret = 0; - int count = 0; - uint16_t event_id = 0; - int index = 0; - unsigned char payload[1024] = {0x00}; - int fb_len = 0; - unsigned char detail_buff[128] = {0x00}; - - for (count = 0; count < sensor_fb_cxt->adsp_event_counts; count ++) { - event_id = sensor_fb_cxt->fb_smem.event[count].event_id; - pr_info("event_id =%d, count =%d\n", event_id, count); - - index = find_event_id(event_id); - - if (index == -1) { - pr_info("not find event_id =%d, count =%d\n", event_id, count); - continue; - } - - ret = procce_special_event_id(event_id, count, sensor_fb_cxt); - - if (ret == 1) { - continue; - } - - memset(payload, 0, sizeof(payload)); - memset(detail_buff, 0, sizeof(detail_buff)); - snprintf(detail_buff, sizeof(detail_buff), "%d %d %d", - sensor_fb_cxt->fb_smem.event[count].buff[0], - sensor_fb_cxt->fb_smem.event[count].buff[1], - sensor_fb_cxt->fb_smem.event[count].buff[2]); - fb_len += scnprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%d$$detailData@@%s", - g_fb_conf[index].fb_field, - sensor_fb_cxt->fb_smem.event[count].count, - detail_buff); - pr_info("payload =%s\n", payload); -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK - oplus_kevent_fb(FB_SENSOR, g_fb_conf[index].fb_event_id, payload); -#endif - } - - return ret; -} - -static int sensor_report_thread(void *arg) -{ - int ret = 0; - struct sensor_fb_cxt *sensor_fb_cxt = (struct sensor_fb_cxt *)arg; - uint16_t node_type = 0; - pr_info("sensor_report_thread step1!\n"); - - while (!kthread_should_stop()) { - wait_event_interruptible(sensor_fb_cxt->wq, test_bit(THREAD_WAKEUP, - (unsigned long *)&sensor_fb_cxt->wakeup_flag)); - - clear_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - set_bit(THREAD_SLEEP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - spin_lock(&sensor_fb_cxt->rw_lock); - node_type = sensor_fb_cxt->node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - - if (node_type == 0) { - ret = read_data_from_share_mem(sensor_fb_cxt); - - } else if (node_type == 2) { - - } else if (node_type == 3) { //power done - - } else { - pr_info("test from node\n"); - } - - ret = parse_shr_info(sensor_fb_cxt); - spin_lock(&sensor_fb_cxt->rw_lock); - memset((void *)&sensor_fb_cxt->fb_smem, 0, sizeof(struct fb_event_smem)); - sensor_fb_cxt->adsp_event_counts = 0; - spin_unlock(&sensor_fb_cxt->rw_lock); - } - - pr_info("step2 ret =%s\n", ret); - return ret; -} - -static ssize_t sensor_list_read_proc(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - char page[128] = {0}; - int len = 0; - struct sensor_fb_cxt *sensor_fb_cxt = (struct sensor_fb_cxt *)PDE_DATA( - file_inode(file)); - - len = snprintf(page, sizeof(page), "phy = 0x%x, virt = 0x%x\n", - sensor_fb_cxt->sensor_list[0], sensor_fb_cxt->sensor_list[1]); - len = simple_read_from_buffer(buf, count, off, page, strlen(page)); - pr_info("phy = 0x%x, virt = 0x%x, len=%d \n", sensor_fb_cxt->sensor_list[0], - sensor_fb_cxt->sensor_list[1], - len); - return len; -} - -static struct file_operations sensor_list_fops = { - .owner = THIS_MODULE, - .read = sensor_list_read_proc, -}; - -static int create_sensor_node(struct sensor_fb_cxt *sensor_fb_cxt) -{ - int err = 0; - struct proc_dir_entry *pentry = NULL; - - err = sysfs_create_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - - if (err < 0) { - pr_err("unable to create sensor_feedback_attribute_group file err=%d\n", err); - goto sysfs_create_failed; - } - - kobject_uevent(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, KOBJ_ADD); - - sensor_fb_cxt->proc_sns = proc_mkdir("sns_debug", NULL); - - if (!sensor_fb_cxt->proc_sns) { - pr_err("can't create sns_debug proc\n"); - err = -EFAULT; - goto sysfs_create_failed; - } - - pentry = proc_create_data("sensor_list", 0666, sensor_fb_cxt->proc_sns, - &sensor_list_fops, sensor_fb_cxt); - - if (!pentry) { - pr_err("create sensor_list proc failed.\n"); - err = -EFAULT; - goto sysfs_create_failed; - } - - return 0; -sysfs_create_failed: - sysfs_remove_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - return err; -} - -static int sensor_feedback_probe(struct platform_device *pdev) -{ - int err = 0; - struct sensor_fb_cxt *sensor_fb_cxt = NULL; - - sensor_fb_cxt = kzalloc(sizeof(struct sensor_fb_cxt), GFP_KERNEL); - - if (sensor_fb_cxt == NULL) { - pr_err("kzalloc g_sensor_fb_cxt failed\n"); - err = -ENOMEM; - goto alloc_sensor_fb_failed; - } - - /*sensor_fb_cxt init*/ - sensor_fb_cxt->sensor_fb_dev = pdev; - g_sensor_fb_cxt = sensor_fb_cxt; - spin_lock_init(&sensor_fb_cxt->rw_lock); - init_waitqueue_head(&sensor_fb_cxt->wq); - set_bit(THREAD_SLEEP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - platform_set_drvdata(pdev, sensor_fb_cxt); - - err = create_sensor_node(sensor_fb_cxt); - - if (err != 0) { - pr_info("create_sensor_node failed\n"); - goto create_sensor_node_failed; - - } - - /*create sensor_feedback_task thread*/ - sensor_fb_cxt->report_task = kthread_create(sensor_report_thread, - (void *)sensor_fb_cxt, - "sensor_feedback_task"); - - if (IS_ERR(sensor_fb_cxt->report_task)) { - pr_info("kthread_create failed\n"); - err = PTR_ERR(sensor_fb_cxt->report_task); - goto create_task_failed; - } - - /*wake up thread of report_task*/ - wake_up_process(sensor_fb_cxt->report_task); - pr_info("sensor_feedback_init success\n"); - return 0; - -create_task_failed: -create_sensor_node_failed: - kfree(sensor_fb_cxt); - g_sensor_fb_cxt = NULL; -alloc_sensor_fb_failed: - return err; -} - - -static int sensor_feedback_remove(struct platform_device *pdev) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - sysfs_remove_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - kfree(sensor_fb_cxt); - g_sensor_fb_cxt = NULL; - return 0; -} - -static const struct of_device_id of_drv_match[] = { - { .compatible = "oplus,sensor-feedback"}, - {}, -}; -MODULE_DEVICE_TABLE(of, of_drv_match); - -static struct platform_driver _driver = { - .probe = sensor_feedback_probe, - .remove = sensor_feedback_remove, - .driver = { - .name = "sensor_feedback", - .of_match_table = of_drv_match, - }, -}; - -static int __init sensor_feedback_init(void) -{ - pr_info("sensor_feedback_init call\n"); - - platform_driver_register(&_driver); - return 0; -} - -/* -static int __exit sensor_feedback_exit(void) -{ - pr_info("sensor_feedback_exit call\n"); - - platform_driver_unregister(&_driver); - return 0; -}*/ - - -core_initcall(sensor_feedback_init); - -//module_init(sensor_feedback_init); -//module_exit(sensor_feedback_exit); - - -MODULE_AUTHOR("JangHua.Tang"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h b/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h deleted file mode 100755 index a4c25dd1660e..000000000000 --- a/drivers/misc/mediatek/sensor/2.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h +++ /dev/null @@ -1,159 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __SENSOR_FEEDBACK_H__ -#define __SENSOR_FEEDBACK_H__ - -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include - -#define THREAD_WAKEUP 0 -#define THREAD_SLEEP 1 - -#undef SUBSYS_COUNTS -#define SUBSYS_COUNTS (3) - -struct sensor_fb_conf { - uint16_t event_id; - char *fb_field; - char *fb_event_id; -}; - - -enum sensor_fb_event_id { - FD_HEAD_EVENT_ID = 0, - //1~100 - PS_INIT_FAIL_ID = 1, - PS_I2C_ERR_ID = 2, - PS_ALLOC_FAIL_ID = 3, - PS_ESD_REST_ID = 4, - PS_NO_INTERRUPT_ID = 5, - PS_FIRST_REPORT_DELAY_COUNT_ID = 6, - PS_ORIGIN_DATA_TO_ZERO_ID = 7, - PS_CALI_DATA_ID = 8, - - //100~200 - ALS_INIT_FAIL_ID = 100, - ALS_I2C_ERR_ID = 101, - ALS_ALLOC_FAIL_ID = 102, - ALS_ESD_REST_ID = 103, - ALS_NO_INTERRUPT_ID = 104, - ALS_FIRST_REPORT_DELAY_COUNT_ID = 105, - ALS_ORIGIN_DATA_TO_ZERO_ID = 106, - ALS_CALI_DATA_ID = 107, - - //200~300 - ACCEL_INIT_FAIL_ID = 200, - ACCEL_I2C_ERR_ID = 201, - ACCEL_ALLOC_FAIL_ID = 202, - ACCEL_ESD_REST_ID = 203, - ACCEL_NO_INTERRUPT_ID = 204, - ACCEL_FIRST_REPORT_DELAY_COUNT_ID = 205, - ACCEL_ORIGIN_DATA_TO_ZERO_ID = 206, - ACCEL_CALI_DATA_ID = 207, - - //300~400 - GYRO_INIT_FAIL_ID = 300, - GYRO_I2C_ERR_ID = 301, - GYRO_ALLOC_FAIL_ID = 302, - GYRO_ESD_REST_ID = 303, - GYRO_NO_INTERRUPT_ID = 304, - GYRO_FIRST_REPORT_DELAY_COUNT_ID = 305, - GYRO_ORIGIN_DATA_TO_ZERO_ID = 306, - GYRO_CALI_DATA_ID = 307, - - //400~500 - MAG_INIT_FAIL_ID = 400, - MAG_I2C_ERR_ID = 401, - MAG_ALLOC_FAIL_ID = 402, - MAG_ESD_REST_ID = 403, - MAG_NO_INTERRUPT_ID = 404, - MAG_FIRST_REPORT_DELAY_COUNT_ID = 405, - MAG_ORIGIN_DATA_TO_ZERO_ID = 406, - MAG_CALI_DATA_ID = 407, - - //500~600 - SAR_INIT_FAIL_ID = 500, - SAR_I2C_ERR_ID = 501, - SAR_ALLOC_FAIL_ID = 502, - SAR_ESD_REST_ID = 503, - SAR_NO_INTERRUPT_ID = 504, - SAR_FIRST_REPORT_DELAY_COUNT_ID = 505, - SAR_ORIGIN_DATA_TO_ZERO_ID = 506, - SAR_CALI_DATA_ID = 507, - - //600~700 - POWER_SENSOR_INFO_ID = 600, - POWER_ACCEL_INFO_ID = 601, - POWER_GYRO_INFO_ID = 602, - POWER_MAG_INFO_ID = 603, - POWER_PROXIMITY_INFO_ID = 604, - POWER_LIGHT_INFO_ID = 605, - POWER_WISE_LIGHT_INFO_ID = 606, - POWER_WAKE_UP_RATE_ID = 607, - POWER_ADSP_SLEEP_RATIO_ID = 608, - - //700~800 - DOUBLE_TAP_REPORTED_ID = 701, - DOUBLE_TAP_PREVENTED_BY_NEAR_ID = 702, - DOUBLE_TAP_PREVENTED_BY_ATTITUDE_ID = 703, - DOUBLE_TAP_PREVENTED_BY_FREEFALL_Z_ID = 704, - DOUBLE_TAP_PREVENTED_BY_FREEFALL_SLOPE_ID = 705, - - //1000 - ALAILABLE_SENSOR_LIST_ID = 1000, - - // 10000 , sensor-hal - HAL_SENSOR_NOT_FOUND = 10000, - HAL_QMI_ERROR = 10001, - HAL_SENSOR_TIMESTAMP_ERROR = 10002, -}; - -struct fd_data { - int data_x; - int data_y; - int data_z; -}; - -#define EVNET_DATA_LEN 3 -struct sns_fb_event { - unsigned short event_id; - unsigned int count; - union { - int buff[EVNET_DATA_LEN]; - struct fd_data data; - }; -}; - -#define EVNET_NUM_MAX 109 -struct fb_event_smem { - struct sns_fb_event event[EVNET_NUM_MAX]; -}; - -struct sensor_fb_cxt { - /*struct miscdevice sensor_fb_dev;*/ - struct platform_device *sensor_fb_dev; - spinlock_t rw_lock; - wait_queue_head_t wq; - struct task_struct *report_task; /*kernel thread*/ - uint16_t adsp_event_counts; - struct fb_event_smem fb_smem; - uint16_t node_type; - unsigned long wakeup_flag; - uint32_t sensor_list[2]; - struct proc_dir_entry *proc_sns; -}; -#endif /*__SENSOR_FEEDBACK_H__*/ diff --git a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/Makefile b/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/Makefile index d3ccba0ad410..52c88702541a 100755 --- a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/Makefile +++ b/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/Makefile @@ -15,4 +15,3 @@ subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/scp/$(CONFIG_MTK_PLATFORM subdir-ccflags-y += -D CONFIG_OPLUS_SENSOR_MTK68XX endif obj-$(CONFIG_NANOHUB) += sensor_devinfo.o -obj-$(CONFIG_OPLUS_SENSOR_FB_MTK) += oplus_sensor_feedback/ diff --git a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile b/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile deleted file mode 100755 index f14ee11a5ee8..000000000000 --- a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -oplus_bsp_sensor_feedback-y := sensor_feedback.o -obj-$(CONFIG_OPLUS_SENSOR_FB_MTK) += oplus_bsp_sensor_feedback.o diff --git a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c b/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c deleted file mode 100755 index 21c7cf709e3a..000000000000 --- a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.c +++ /dev/null @@ -1,607 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - - -#define pr_fmt(fmt) "" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "scp_helper.h" -#include "sensor_feedback.h" -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK -#include -#endif - -#define SENSOR_DEVICE_TYPE "10002" -#define SENSOR_POWER_TYPE "10003" -#define SENSOR_STABILITY_TYPE "10004" -#define SENSOR_PFMC_TYPE "10005" -#define SENSOR_MEMORY_TYPE "10006" - -#define SENSOR_DEBUG_DEVICE_TYPE "20002" -#define SENSOR_DEBUG_POWER_TYPE "20003" -#define SENSOR_DEBUG_STABILITY_TYPE "20004" -#define SENSOR_DEBUG_PFMC_TYPE "20005" -#define SENSOR_DEBUG_MEMORY_TYPE "20006" - - -static struct sensor_fb_cxt *g_sensor_fb_cxt = NULL; - -/*fb_field :maxlen 19*/ -struct sensor_fb_conf g_fb_conf[] = { - {PS_INIT_FAIL_ID, "device_ps_init_fail", SENSOR_DEVICE_TYPE}, - {PS_I2C_ERR_ID, "device_ps_i2c_err", SENSOR_DEVICE_TYPE}, - {PS_ALLOC_FAIL_ID, "device_ps_alloc_fail", SENSOR_DEVICE_TYPE}, - {PS_ESD_REST_ID, "device_ps_esd_reset", SENSOR_DEVICE_TYPE}, - {PS_NO_INTERRUPT_ID, "device_ps_no_irq", SENSOR_DEVICE_TYPE}, - {PS_FIRST_REPORT_DELAY_COUNT_ID, "device_ps_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {PS_ORIGIN_DATA_TO_ZERO_ID, "device_ps_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {PS_CALI_DATA_ID, "device_ps_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {ALS_INIT_FAIL_ID, "device_als_init_fail", SENSOR_DEVICE_TYPE}, - {ALS_I2C_ERR_ID, "device_als_i2c_err", SENSOR_DEVICE_TYPE}, - {ALS_ALLOC_FAIL_ID, "device_als_alloc_fail", SENSOR_DEVICE_TYPE}, - {ALS_ESD_REST_ID, "device_als_esd_reset", SENSOR_DEVICE_TYPE}, - {ALS_NO_INTERRUPT_ID, "device_als_no_irq", SENSOR_DEVICE_TYPE}, - {ALS_FIRST_REPORT_DELAY_COUNT_ID, "device_als_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {ALS_ORIGIN_DATA_TO_ZERO_ID, "device_als_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {ALS_CALI_DATA_ID, "device_als_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {ACCEL_INIT_FAIL_ID, "device_acc_init_fail", SENSOR_DEVICE_TYPE}, - {ACCEL_I2C_ERR_ID, "device_acc_i2c_err", SENSOR_DEVICE_TYPE}, - {ACCEL_ALLOC_FAIL_ID, "device_acc_alloc_fail", SENSOR_DEVICE_TYPE}, - {ACCEL_ESD_REST_ID, "device_acc_esd_reset", SENSOR_DEVICE_TYPE}, - {ACCEL_NO_INTERRUPT_ID, "device_acc_no_irq", SENSOR_DEVICE_TYPE}, - {ACCEL_FIRST_REPORT_DELAY_COUNT_ID, "device_acc_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {ACCEL_ORIGIN_DATA_TO_ZERO_ID, "device_acc_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {ACCEL_CALI_DATA_ID, "device_acc_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {GYRO_INIT_FAIL_ID, "device_gyro_init_fail", SENSOR_DEVICE_TYPE}, - {GYRO_I2C_ERR_ID, "device_gyro_i2c_err", SENSOR_DEVICE_TYPE}, - {GYRO_ALLOC_FAIL_ID, "device_gyro_alloc_fail", SENSOR_DEVICE_TYPE}, - {GYRO_ESD_REST_ID, "device_gyro_esd_reset", SENSOR_DEVICE_TYPE}, - {GYRO_NO_INTERRUPT_ID, "device_gyro_no_irq", SENSOR_DEVICE_TYPE}, - {GYRO_FIRST_REPORT_DELAY_COUNT_ID, "device_gyro_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {GYRO_ORIGIN_DATA_TO_ZERO_ID, "device_gyro_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {GYRO_CALI_DATA_ID, "device_gyro_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {MAG_INIT_FAIL_ID, "device_mag_init_fail", SENSOR_DEVICE_TYPE}, - {MAG_I2C_ERR_ID, "device_mag_i2c_err", SENSOR_DEVICE_TYPE}, - {MAG_ALLOC_FAIL_ID, "device_mag_alloc_fail", SENSOR_DEVICE_TYPE}, - {MAG_ESD_REST_ID, "device_mag_esd_reset", SENSOR_DEVICE_TYPE}, - {MAG_NO_INTERRUPT_ID, "device_mag_no_irq", SENSOR_DEVICE_TYPE}, - {MAG_FIRST_REPORT_DELAY_COUNT_ID, "device_mag_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {MAG_ORIGIN_DATA_TO_ZERO_ID, "device_mag_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {MAG_CALI_DATA_ID, "device_mag_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {SAR_INIT_FAIL_ID, "device_sar_init_fail", SENSOR_DEVICE_TYPE}, - {SAR_I2C_ERR_ID, "device_sar_i2c_err", SENSOR_DEVICE_TYPE}, - {SAR_ALLOC_FAIL_ID, "device_sar_alloc_fail", SENSOR_DEVICE_TYPE}, - {SAR_ESD_REST_ID, "device_sar_esd_reset", SENSOR_DEVICE_TYPE}, - {SAR_NO_INTERRUPT_ID, "device_sar_no_irq", SENSOR_DEVICE_TYPE}, - {SAR_FIRST_REPORT_DELAY_COUNT_ID, "device_sar_rpt_delay", SENSOR_DEBUG_DEVICE_TYPE}, - {SAR_ORIGIN_DATA_TO_ZERO_ID, "device_sar_to_zero", SENSOR_DEBUG_DEVICE_TYPE}, - {SAR_CALI_DATA_ID, "device_sar_cali_data", SENSOR_DEBUG_DEVICE_TYPE}, - - - {POWER_SENSOR_INFO_ID, "debug_power_sns_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_ACCEL_INFO_ID, "debug_power_acc_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_GYRO_INFO_ID, "debug_power_gyro_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_MAG_INFO_ID, "debug_power_mag_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_PROXIMITY_INFO_ID, "debug_power_prox_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_LIGHT_INFO_ID, "debug_power_light_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_WISE_LIGHT_INFO_ID, "debug_power_wiseligt_info", SENSOR_DEBUG_POWER_TYPE}, - {POWER_WAKE_UP_RATE_ID, "debug_power_wakeup_rate", SENSOR_DEBUG_POWER_TYPE}, - {POWER_ADSP_SLEEP_RATIO_ID, "power_adsp_sleep_ratio", SENSOR_POWER_TYPE}, - - {DOUBLE_TAP_REPORTED_ID, "device_double_tap_reported", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_NEAR_ID, "device_double_tap_prevented_by_near", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_ATTITUDE_ID, "device_double_prevented_by_attitude", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_FREEFALL_Z_ID, "device_double_prevented_by_freefall_z", SENSOR_DEBUG_DEVICE_TYPE}, - {DOUBLE_TAP_PREVENTED_BY_FREEFALL_SLOPE_ID, "device_double_prevented_by_freefall_slope", SENSOR_DEBUG_DEVICE_TYPE}, - - {ALAILABLE_SENSOR_LIST_ID, "available_sensor_list", SENSOR_DEBUG_DEVICE_TYPE}, - - {HAL_SENSOR_NOT_FOUND, "device_hal_not_found", SENSOR_DEVICE_TYPE}, - {HAL_QMI_ERROR, "device_hal_qmi_error", SENSOR_DEVICE_TYPE}, - {HAL_SENSOR_TIMESTAMP_ERROR, "device_hal_ts_error", SENSOR_DEBUG_DEVICE_TYPE} - -}; - -static int find_event_id(int16_t event_id) -{ - int len = sizeof(g_fb_conf) / sizeof(g_fb_conf[0]); - int ret = -1; - int index = 0; - - for (index = 0; index < len; index++) { - if (g_fb_conf[index].event_id == event_id) { - ret = index; - } - } - - return ret; -} - -static ssize_t adsp_notify_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - - spin_lock(&sensor_fb_cxt->rw_lock); - adsp_event_counts = sensor_fb_cxt->adsp_event_counts; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d\n", adsp_event_counts); - return snprintf(buf, PAGE_SIZE, "%d\n", adsp_event_counts); -} - -static ssize_t adsp_notify_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - uint16_t node_type = 0; - int err = 0; - - err = sscanf(buf, "%hu %hu", &node_type, &adsp_event_counts); - - if (err < 0) { - pr_err("adsp_notify_store error: err = %d\n", err); - return err; - } - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d, node_type=%d\n", adsp_event_counts, - node_type); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - return count; -} - -int scp_notify_store(uint16_t node_type, uint16_t adsp_event_counts) -{ - if (g_sensor_fb_cxt != NULL) { - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("adsp_value = %d, node_type=%d\n", adsp_event_counts, - node_type); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - } else { - pr_err("error: g_sensor_fb_cxt is NULL\n"); - } - return 0; -} - -static ssize_t hal_info_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - uint16_t event_ct = 0; - uint16_t event_id = 0; - char strbuf[32] = {0x00}; - int err = 0; - int index = 0; - unsigned char payload[1024] = {0x00}; - - pr_info("hal_info_store\n"); - memset(strbuf, 0, 32); - memset(payload, 0, 1024); - - err = sscanf(buf, "%u %u %31s", &event_id, &event_ct, strbuf); - - if (err < 0) { - pr_err("hal_info_store error: err = %d\n", err); - return count; - } - - strbuf[31] = '\0'; - - index = find_event_id(event_id); - - if (index == -1) { - pr_info("nout find event_id =%d\n", event_id); - return count; - } - - scnprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%d$$detailData@@%s", - g_fb_conf[index].fb_field, - event_ct, - strbuf); - pr_info("payload =%s\n", payload); - -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK - oplus_kevent_fb(FB_SENSOR, g_fb_conf[index].fb_event_id, payload); -#endif - return count; -} - - -static ssize_t test_id_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t adsp_event_counts = 0; - uint16_t node_type = 0; - uint16_t event_id = 0; - uint16_t event_data = 0; - int err = 0; - - err = sscanf(buf, "%hu %hu %hu %hu", &node_type, &adsp_event_counts, &event_id, - &event_data); - - if (err < 0) { - pr_err("test_id_store error: err = %d\n", err); - return count; - } - - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_fb_cxt->adsp_event_counts = adsp_event_counts; - sensor_fb_cxt->node_type = node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - - sensor_fb_cxt->fb_smem.event[0].event_id = event_id; - sensor_fb_cxt->fb_smem.event[0].count = event_data; - - pr_info("test_id_store adsp_value = %d, node_type=%d \n", adsp_event_counts, - node_type); - pr_info("test_id_store event_id = %d, event_data=%d \n", event_id, event_data); - - set_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - /*wake_up_interruptible(&sensor_fb_cxt->wq);*/ - wake_up(&sensor_fb_cxt->wq); - return count; -} - -static ssize_t sensor_list_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - uint16_t sensor_list[2] = {0x00}; - spin_lock(&sensor_fb_cxt->rw_lock); - sensor_list[0] = sensor_fb_cxt->sensor_list[0]; - sensor_list[1] = sensor_fb_cxt->sensor_list[1]; - spin_unlock(&sensor_fb_cxt->rw_lock); - pr_info("phy = 0x%x, virt = 0x%x\n", sensor_list[0], sensor_list[1]); - - return snprintf(buf, PAGE_SIZE, "phy = 0x%x, virt = 0x%x\n", sensor_list[0], - sensor_list[1]); -} - -DEVICE_ATTR(adsp_notify, 0644, adsp_notify_show, adsp_notify_store); -DEVICE_ATTR(hal_info, 0644, NULL, hal_info_store); -DEVICE_ATTR(test_id, 0644, NULL, test_id_store); -DEVICE_ATTR(sensor_list, 0644, sensor_list_show, NULL); - -static struct attribute *sensor_feedback_attributes[] = { - &dev_attr_adsp_notify.attr, - &dev_attr_hal_info.attr, - &dev_attr_test_id.attr, - &dev_attr_sensor_list.attr, - NULL -}; - -static struct attribute_group sensor_feedback_attribute_group = { - .attrs = sensor_feedback_attributes -}; - -#define SMEM_SENSOR_FEEDBACK (128) -static int read_data_from_share_mem(struct sensor_fb_cxt *sensor_fb_cxt) -{ - void *smem_addr = NULL; - struct fb_event_smem *fb_event = NULL; - - smem_addr = (void *)(long)scp_get_reserve_mem_virt(SENS_FB_MEM_ID); - fb_event = (struct fb_event_smem *)smem_addr; - - if (fb_event == NULL) { - return -2; - } - - memcpy((void *)&sensor_fb_cxt->fb_smem, (void *)fb_event, - sizeof(sensor_fb_cxt->fb_smem)); - return 0; -} - -int procce_special_event_id(unsigned short event_id, int count, - struct sensor_fb_cxt *sensor_fb_cxt) -{ - int ret = 0; - - if (event_id == ALAILABLE_SENSOR_LIST_ID) { - sensor_fb_cxt->sensor_list[0] = (uint32_t) - sensor_fb_cxt->fb_smem.event[count].buff[0]; - sensor_fb_cxt->sensor_list[1] = (uint32_t) - sensor_fb_cxt->fb_smem.event[count].buff[1]; - pr_info("sensor_list virt_sns = 0x%x, phy_sns = 0x%x\n", - sensor_fb_cxt->sensor_list[0], sensor_fb_cxt->sensor_list[1]); - ret = 1; - } - - return ret; -} - -static int parse_shr_info(struct sensor_fb_cxt *sensor_fb_cxt) -{ - int ret = 0; - int count = 0; - uint16_t event_id = 0; - int index = 0; - unsigned char payload[1024] = {0x00}; - int fb_len = 0; - unsigned char detail_buff[128] = {0x00}; - - for (count = 0; count < sensor_fb_cxt->adsp_event_counts; count ++) { - event_id = sensor_fb_cxt->fb_smem.event[count].event_id; - pr_info("event_id =%d, count =%d\n", event_id, count); - - index = find_event_id(event_id); - - if (index == -1) { - pr_info("not find event_id =%d, count =%d\n", event_id, count); - continue; - } - - ret = procce_special_event_id(event_id, count, sensor_fb_cxt); - - if (ret == 1) { - continue; - } - - memset(payload, 0, sizeof(payload)); - memset(detail_buff, 0, sizeof(detail_buff)); - snprintf(detail_buff, sizeof(detail_buff), "%d %d %d", - sensor_fb_cxt->fb_smem.event[count].buff[0], - sensor_fb_cxt->fb_smem.event[count].buff[1], - sensor_fb_cxt->fb_smem.event[count].buff[2]); - fb_len += scnprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%d$$detailData@@%s", - g_fb_conf[index].fb_field, - sensor_fb_cxt->fb_smem.event[count].count, - detail_buff); - pr_info("payload =%s\n", payload); -#ifdef CONFIG_OPLUS_FEATURE_FEEDBACK - oplus_kevent_fb(FB_SENSOR, g_fb_conf[index].fb_event_id, payload); -#endif - } - - return ret; -} - -static int sensor_report_thread(void *arg) -{ - int ret = 0; - struct sensor_fb_cxt *sensor_fb_cxt = (struct sensor_fb_cxt *)arg; - uint16_t node_type = 0; - pr_info("sensor_report_thread step1!\n"); - - while (!kthread_should_stop()) { - wait_event_interruptible(sensor_fb_cxt->wq, test_bit(THREAD_WAKEUP, - (unsigned long *)&sensor_fb_cxt->wakeup_flag)); - - clear_bit(THREAD_WAKEUP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - set_bit(THREAD_SLEEP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - spin_lock(&sensor_fb_cxt->rw_lock); - node_type = sensor_fb_cxt->node_type; - spin_unlock(&sensor_fb_cxt->rw_lock); - - if (node_type == 0) { - ret = read_data_from_share_mem(sensor_fb_cxt); - - } else if (node_type == 2) { - - } else if (node_type == 3) { //power done - - } else { - pr_info("test from node\n"); - } - - ret = parse_shr_info(sensor_fb_cxt); - spin_lock(&sensor_fb_cxt->rw_lock); - memset((void *)&sensor_fb_cxt->fb_smem, 0, sizeof(struct fb_event_smem)); - sensor_fb_cxt->adsp_event_counts = 0; - spin_unlock(&sensor_fb_cxt->rw_lock); - } - - pr_info("step2 ret =%s\n", ret); - return ret; -} - -static ssize_t sensor_list_read_proc(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - char page[128] = {0}; - int len = 0; - struct sensor_fb_cxt *sensor_fb_cxt = (struct sensor_fb_cxt *)PDE_DATA( - file_inode(file)); - - len = snprintf(page, sizeof(page), "phy = 0x%x, virt = 0x%x\n", - sensor_fb_cxt->sensor_list[0], sensor_fb_cxt->sensor_list[1]); - len = simple_read_from_buffer(buf, count, off, page, strlen(page)); - pr_info("phy = 0x%x, virt = 0x%x, len=%d \n", sensor_fb_cxt->sensor_list[0], - sensor_fb_cxt->sensor_list[1], - len); - return len; -} - -static struct file_operations sensor_list_fops = { - .owner = THIS_MODULE, - .read = sensor_list_read_proc, -}; - -static int create_sensor_node(struct sensor_fb_cxt *sensor_fb_cxt) -{ - int err = 0; - struct proc_dir_entry *pentry = NULL; - - err = sysfs_create_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - - if (err < 0) { - pr_err("unable to create sensor_feedback_attribute_group file err=%d\n", err); - goto sysfs_create_failed; - } - - kobject_uevent(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, KOBJ_ADD); - - sensor_fb_cxt->proc_sns = proc_mkdir("sns_debug", NULL); - - if (!sensor_fb_cxt->proc_sns) { - pr_err("can't create sns_debug proc\n"); - err = -EFAULT; - goto sysfs_create_failed; - } - - pentry = proc_create_data("sensor_list", 0666, sensor_fb_cxt->proc_sns, - &sensor_list_fops, sensor_fb_cxt); - - if (!pentry) { - pr_err("create sensor_list proc failed.\n"); - err = -EFAULT; - goto sysfs_create_failed; - } - - return 0; -sysfs_create_failed: - sysfs_remove_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - return err; -} - -static int sensor_feedback_probe(struct platform_device *pdev) -{ - int err = 0; - struct sensor_fb_cxt *sensor_fb_cxt = NULL; - - sensor_fb_cxt = kzalloc(sizeof(struct sensor_fb_cxt), GFP_KERNEL); - - if (sensor_fb_cxt == NULL) { - pr_err("kzalloc g_sensor_fb_cxt failed\n"); - err = -ENOMEM; - goto alloc_sensor_fb_failed; - } - - /*sensor_fb_cxt init*/ - sensor_fb_cxt->sensor_fb_dev = pdev; - g_sensor_fb_cxt = sensor_fb_cxt; - spin_lock_init(&sensor_fb_cxt->rw_lock); - init_waitqueue_head(&sensor_fb_cxt->wq); - set_bit(THREAD_SLEEP, (unsigned long *)&sensor_fb_cxt->wakeup_flag); - platform_set_drvdata(pdev, sensor_fb_cxt); - - err = create_sensor_node(sensor_fb_cxt); - - if (err != 0) { - pr_info("create_sensor_node failed\n"); - goto create_sensor_node_failed; - - } - - /*create sensor_feedback_task thread*/ - sensor_fb_cxt->report_task = kthread_create(sensor_report_thread, - (void *)sensor_fb_cxt, - "sensor_feedback_task"); - - if (IS_ERR(sensor_fb_cxt->report_task)) { - pr_info("kthread_create failed\n"); - err = PTR_ERR(sensor_fb_cxt->report_task); - goto create_task_failed; - } - - /*wake up thread of report_task*/ - wake_up_process(sensor_fb_cxt->report_task); - pr_info("sensor_feedback_init success\n"); - return 0; - -create_task_failed: -create_sensor_node_failed: - kfree(sensor_fb_cxt); - g_sensor_fb_cxt = NULL; -alloc_sensor_fb_failed: - return err; -} - - -static int sensor_feedback_remove(struct platform_device *pdev) -{ - struct sensor_fb_cxt *sensor_fb_cxt = g_sensor_fb_cxt; - sysfs_remove_group(&sensor_fb_cxt->sensor_fb_dev->dev.kobj, - &sensor_feedback_attribute_group); - kfree(sensor_fb_cxt); - g_sensor_fb_cxt = NULL; - return 0; -} - -static const struct of_device_id of_drv_match[] = { - { .compatible = "oplus,sensor-feedback"}, - {}, -}; -MODULE_DEVICE_TABLE(of, of_drv_match); - -static struct platform_driver _driver = { - .probe = sensor_feedback_probe, - .remove = sensor_feedback_remove, - .driver = { - .name = "sensor_feedback", - .of_match_table = of_drv_match, - }, -}; - -static int __init sensor_feedback_init(void) -{ - pr_info("sensor_feedback_init call\n"); - - platform_driver_register(&_driver); - return 0; -} - -/* -static int __exit sensor_feedback_exit(void) -{ - pr_info("sensor_feedback_exit call\n"); - - platform_driver_unregister(&_driver); - return 0; -}*/ - - -core_initcall(sensor_feedback_init); - -//module_init(sensor_feedback_init); -//module_exit(sensor_feedback_exit); - - -MODULE_AUTHOR("JangHua.Tang"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h b/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h deleted file mode 100755 index a4c25dd1660e..000000000000 --- a/drivers/misc/mediatek/sensors-1.0/oplus_sensor_devinfo/oplus_sensor_feedback/sensor_feedback.h +++ /dev/null @@ -1,159 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __SENSOR_FEEDBACK_H__ -#define __SENSOR_FEEDBACK_H__ - -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include - -#define THREAD_WAKEUP 0 -#define THREAD_SLEEP 1 - -#undef SUBSYS_COUNTS -#define SUBSYS_COUNTS (3) - -struct sensor_fb_conf { - uint16_t event_id; - char *fb_field; - char *fb_event_id; -}; - - -enum sensor_fb_event_id { - FD_HEAD_EVENT_ID = 0, - //1~100 - PS_INIT_FAIL_ID = 1, - PS_I2C_ERR_ID = 2, - PS_ALLOC_FAIL_ID = 3, - PS_ESD_REST_ID = 4, - PS_NO_INTERRUPT_ID = 5, - PS_FIRST_REPORT_DELAY_COUNT_ID = 6, - PS_ORIGIN_DATA_TO_ZERO_ID = 7, - PS_CALI_DATA_ID = 8, - - //100~200 - ALS_INIT_FAIL_ID = 100, - ALS_I2C_ERR_ID = 101, - ALS_ALLOC_FAIL_ID = 102, - ALS_ESD_REST_ID = 103, - ALS_NO_INTERRUPT_ID = 104, - ALS_FIRST_REPORT_DELAY_COUNT_ID = 105, - ALS_ORIGIN_DATA_TO_ZERO_ID = 106, - ALS_CALI_DATA_ID = 107, - - //200~300 - ACCEL_INIT_FAIL_ID = 200, - ACCEL_I2C_ERR_ID = 201, - ACCEL_ALLOC_FAIL_ID = 202, - ACCEL_ESD_REST_ID = 203, - ACCEL_NO_INTERRUPT_ID = 204, - ACCEL_FIRST_REPORT_DELAY_COUNT_ID = 205, - ACCEL_ORIGIN_DATA_TO_ZERO_ID = 206, - ACCEL_CALI_DATA_ID = 207, - - //300~400 - GYRO_INIT_FAIL_ID = 300, - GYRO_I2C_ERR_ID = 301, - GYRO_ALLOC_FAIL_ID = 302, - GYRO_ESD_REST_ID = 303, - GYRO_NO_INTERRUPT_ID = 304, - GYRO_FIRST_REPORT_DELAY_COUNT_ID = 305, - GYRO_ORIGIN_DATA_TO_ZERO_ID = 306, - GYRO_CALI_DATA_ID = 307, - - //400~500 - MAG_INIT_FAIL_ID = 400, - MAG_I2C_ERR_ID = 401, - MAG_ALLOC_FAIL_ID = 402, - MAG_ESD_REST_ID = 403, - MAG_NO_INTERRUPT_ID = 404, - MAG_FIRST_REPORT_DELAY_COUNT_ID = 405, - MAG_ORIGIN_DATA_TO_ZERO_ID = 406, - MAG_CALI_DATA_ID = 407, - - //500~600 - SAR_INIT_FAIL_ID = 500, - SAR_I2C_ERR_ID = 501, - SAR_ALLOC_FAIL_ID = 502, - SAR_ESD_REST_ID = 503, - SAR_NO_INTERRUPT_ID = 504, - SAR_FIRST_REPORT_DELAY_COUNT_ID = 505, - SAR_ORIGIN_DATA_TO_ZERO_ID = 506, - SAR_CALI_DATA_ID = 507, - - //600~700 - POWER_SENSOR_INFO_ID = 600, - POWER_ACCEL_INFO_ID = 601, - POWER_GYRO_INFO_ID = 602, - POWER_MAG_INFO_ID = 603, - POWER_PROXIMITY_INFO_ID = 604, - POWER_LIGHT_INFO_ID = 605, - POWER_WISE_LIGHT_INFO_ID = 606, - POWER_WAKE_UP_RATE_ID = 607, - POWER_ADSP_SLEEP_RATIO_ID = 608, - - //700~800 - DOUBLE_TAP_REPORTED_ID = 701, - DOUBLE_TAP_PREVENTED_BY_NEAR_ID = 702, - DOUBLE_TAP_PREVENTED_BY_ATTITUDE_ID = 703, - DOUBLE_TAP_PREVENTED_BY_FREEFALL_Z_ID = 704, - DOUBLE_TAP_PREVENTED_BY_FREEFALL_SLOPE_ID = 705, - - //1000 - ALAILABLE_SENSOR_LIST_ID = 1000, - - // 10000 , sensor-hal - HAL_SENSOR_NOT_FOUND = 10000, - HAL_QMI_ERROR = 10001, - HAL_SENSOR_TIMESTAMP_ERROR = 10002, -}; - -struct fd_data { - int data_x; - int data_y; - int data_z; -}; - -#define EVNET_DATA_LEN 3 -struct sns_fb_event { - unsigned short event_id; - unsigned int count; - union { - int buff[EVNET_DATA_LEN]; - struct fd_data data; - }; -}; - -#define EVNET_NUM_MAX 109 -struct fb_event_smem { - struct sns_fb_event event[EVNET_NUM_MAX]; -}; - -struct sensor_fb_cxt { - /*struct miscdevice sensor_fb_dev;*/ - struct platform_device *sensor_fb_dev; - spinlock_t rw_lock; - wait_queue_head_t wq; - struct task_struct *report_task; /*kernel thread*/ - uint16_t adsp_event_counts; - struct fb_event_smem fb_smem; - uint16_t node_type; - unsigned long wakeup_flag; - uint32_t sensor_list[2]; - struct proc_dir_entry *proc_sns; -}; -#endif /*__SENSOR_FEEDBACK_H__*/ diff --git a/drivers/misc/oplus/oplus_display_alwaysondisplay.c b/drivers/misc/oplus/oplus_display_alwaysondisplay.c index c427b0019331..32670fec2865 100755 --- a/drivers/misc/oplus/oplus_display_alwaysondisplay.c +++ b/drivers/misc/oplus/oplus_display_alwaysondisplay.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include "ddp_dsi.h" diff --git a/drivers/misc/oplus/oplus_display_private_api.c b/drivers/misc/oplus/oplus_display_private_api.c index 34ab9b46cd13..f658b9ee2132 100755 --- a/drivers/misc/oplus/oplus_display_private_api.c +++ b/drivers/misc/oplus/oplus_display_private_api.c @@ -12,21 +12,20 @@ ** Guo.Ling 2018/11/27 1.2 Modify for mt6779 ** Lin.Hao 2019/11/01 1.3 Modify for MT6779_Q ******************************************************************/ -#define pr_fmt(fmt) "oplus_api: %s: " fmt, __func__ +#define pr_fmt(fmt) "oplus_api: %s: " fmt, __func__ #include "oplus_display_private_api.h" #include "disp_drv_log.h" -#include #include #include #include -#include +#include #include #include -#include -#include +#include +#include #include "primary_display.h" -#include "display_panel/oplus_display_panel.h" - +#include "display_panel/oplus_display_panel.h" + /* * we will create a sysfs which called /sys/kernel/oppo_display, * In that directory, oppo display private api can be called @@ -47,52 +46,52 @@ bool oppo_display_sau_support; unsigned long oplus_display_brightness = 0; unsigned int oplus_set_brightness = 0; unsigned int aod_light_mode = 0; -bool oplus_flag_lcd_off = false; +bool oplus_flag_lcd_off = false; unsigned long oplus_silence_mode = 0; unsigned int oplus_fp_silence_mode = 0; int esd_status = 0; unsigned long seed_mode = 0; -bool oplus_display_cabc_support; /* if cabc is supported(cmd sent without cmdq handle) */ +bool oplus_display_cabc_support; /* if cabc is supported(cmd sent without cmdq handle) */ bool oplus_display_cabc_cmdq_support; /* if cabc is supported(cmd sent with cmdq handle) */ bool oplus_display_mipi_before_init; /* if frame data must be sent before lcd init(ic:TM TD4330) */ bool oplus_display_lcm_id_check_support; /* whether lcm id is needed to be checked or not(only himax ic of 18311&18011 for now) */ -bool oplus_display_aod_support; /* if aod feature is supported */ +bool oplus_display_aod_support; /* if aod feature is supported */ bool oplus_display_hbm_support; bool oplus_display_fppress_support; /* #ifdef OPLUS_FEATURE_RAMLESS_AOD */ bool oplus_display_aod_ramless_support; /* if ramless aod feature is supported */ bool oplus_display_aodlight_support; /* if aod light mode( high-light or low-light) option is supported */ /* #endif */ /* OPLUS_FEATURE_RAMLESS_AOD */ -#if 0 -bool oppo_display_aod_legacy_support; /* if aod feature is supported(for old project like 17197 which aodlight mode and fppress is not supported on) */ -#endif -#ifdef OPLUS_FEATURE_MULTIBITS_BL -/* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for multibits backlight */ -bool oplus_display_tenbits_support; -bool oplus_display_elevenbits_support; -bool oplus_display_twelvebits_support; -#endif /* OPLUS_FEATURE_MULTIBITS_BL */ -bool oplus_display_backlight_ic_support; /* if backlight ic like lm3697 or ktd3136 is supported */ -bool oplus_display_bl_set_on_lcd_esd_recovery; -/* recover backlight after esd recovery (cmd sent without a cmdq handle) */ -bool oplus_display_bl_set_cmdq_on_lcd_esd_recovery; -/* recover backlight after esd recovery (cmd sent with a cmdq handle) */ -u32 oplus_display_esd_try_count = 0; /* customize esd consecutive recover max time until success (only 18531&18561&18161 for now)*/ -#if 0 -bool oppo_display_esd_check_dsi_rx_data1; /* if need to read DSI_RX_DATA1 reg on esd checking(only himax ic of 18311&18011 for now)*/ -/* tp fw must be reloaded after lcd esd recovery if value is 1(18311&18011&18611) */ -u32 oppo_display_tp_fw_reload_on_lcd_esd_recovery = 0; -/* need recover backlight after esd recovery if value is 1(cmd sent withous cmdq handle) */ -u32 oppo_display_dyn_data_rate = 0; -u32 oppo_display_dyn_dsi_hbp = 0; -u32 oppo_display_lcd_height = 0; /* for projects which share the same lcd driver file but have different resolution height */ +#if 0 +bool oppo_display_aod_legacy_support; /* if aod feature is supported(for old project like 17197 which aodlight mode and fppress is not supported on) */ +#endif +#ifdef OPLUS_FEATURE_MULTIBITS_BL +/* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for multibits backlight */ +bool oplus_display_tenbits_support; +bool oplus_display_elevenbits_support; +bool oplus_display_twelvebits_support; +#endif /* OPLUS_FEATURE_MULTIBITS_BL */ +bool oplus_display_backlight_ic_support; /* if backlight ic like lm3697 or ktd3136 is supported */ +bool oplus_display_bl_set_on_lcd_esd_recovery; +/* recover backlight after esd recovery (cmd sent without a cmdq handle) */ +bool oplus_display_bl_set_cmdq_on_lcd_esd_recovery; +/* recover backlight after esd recovery (cmd sent with a cmdq handle) */ +u32 oplus_display_esd_try_count = 0; /* customize esd consecutive recover max time until success (only 18531&18561&18161 for now)*/ +#if 0 +bool oppo_display_esd_check_dsi_rx_data1; /* if need to read DSI_RX_DATA1 reg on esd checking(only himax ic of 18311&18011 for now)*/ +/* tp fw must be reloaded after lcd esd recovery if value is 1(18311&18011&18611) */ +u32 oppo_display_tp_fw_reload_on_lcd_esd_recovery = 0; +/* need recover backlight after esd recovery if value is 1(cmd sent withous cmdq handle) */ +u32 oppo_display_dyn_data_rate = 0; +u32 oppo_display_dyn_dsi_hbp = 0; +u32 oppo_display_lcd_height = 0; /* for projects which share the same lcd driver file but have different resolution height */ extern void ffl_set_enable(unsigned int enable); #endif extern int __attribute((weak)) primary_display_read_lcm_id(char cmd, uint32_t *buf, int num) { return 0;}; extern int __attribute((weak)) primary_display_read_serial(char addr, uint64_t *buf, int lenth) { return 1;}; extern int __attribute((weak)) panel_serial_number_read(char cmd, uint64_t *buf, int num) { return 0;}; -extern int __attribute((weak)) primary_display_set_cabc_mode(unsigned int level) { return 0;}; +extern int __attribute((weak)) primary_display_set_cabc_mode(unsigned int level) { return 0;}; extern int __attribute((weak)) primary_display_set_hbm_mode(unsigned int level) {return 0;}; extern int __attribute((weak)) primary_display_setbacklight(unsigned int level) {return 0;}; extern void __attribute((weak)) _primary_path_switch_dst_lock(void) {return;}; @@ -102,7 +101,7 @@ extern void __attribute((weak)) _primary_path_unlock(const char *caller) {return extern int __attribute((weak)) primary_display_aod_backlight(int level) {return 0;}; extern bool __attribute((weak)) primary_display_get_fp_hbm_state(void) {return 0;}; extern unsigned int __attribute((weak)) delay_uiready = 0; -#if defined(CONFIG_MACH_MT6785) +#if defined(CONFIG_MACH_MT6785) extern enum DISP_HELPER_STAGE disp_helper_get_stage(void); extern const char *disp_helper_stage_spy(void); extern void oplus_delayed_trigger_kick_set(int params); @@ -125,7 +124,7 @@ static int disp_lcm_set_safe_mode(struct disp_lcm_handle *plcm, void *handle, un DISP_PR_ERR("lcm_drv is null\n"); return -1; } - + /* #ifdef OPLUS_FEATURE_RAMLESS_AOD */ struct aod_area { bool enable; @@ -255,8 +254,8 @@ static ssize_t oplus_display_set_aod_area(struct device *dev, */ return count; } -int oplus_display_panel_set_aod_area(void *buf) -{ +int oplus_display_panel_set_aod_area(void *buf) +{ struct panel_aod_area_para *para = (struct panel_aod_area_para *)buf; int i, cnt = 0; @@ -368,10 +367,10 @@ int oplus_display_panel_set_aod_area(void *buf) _primary_path_switch_dst_unlock(); print_hex_dump(KERN_INFO, "aod area setting raw data: ", DUMP_PREFIX_ADDRESS, 16, 1, aod_area_cmd, sizeof(aod_area_cmd), true); */ - return 0; -} + return 0; +} /* #endif */ /* OPLUS_FEATURE_RAMLESS_AOD */ - + static int _set_safe_mode_by_cmdq(unsigned int level) { int ret = 0; @@ -468,25 +467,25 @@ int primary_display_set_safe_mode(unsigned int level) MMPROFILE_FLAG_END, 0, 0); return ret; } -#endif +#endif -unsigned int oplus_display_normal_max_brightness = 0; -/* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for lcd */ -int oplus_mtkfb_custom_data_init(struct platform_device *pdev) -{ - int of_ret = 0; - - if (!pdev) { - pr_err("%s, pdev is null\n", __func__); - return -1; - } - - #ifdef OPLUS_FEATURE_MULTIBITS_BL - /* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for multibits backlight */ - oplus_display_tenbits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_tenbits_support"); - oplus_display_elevenbits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_elevenbits_support"); - oplus_display_twelvebits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_twelvebits_support"); - #endif /* OPLUS_FEATURE_MULTIBITS_BL */ +unsigned int oplus_display_normal_max_brightness = 0; +/* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for lcd */ +int oplus_mtkfb_custom_data_init(struct platform_device *pdev) +{ + int of_ret = 0; + + if (!pdev) { + pr_err("%s, pdev is null\n", __func__); + return -1; + } + + #ifdef OPLUS_FEATURE_MULTIBITS_BL + /* Zhijun.Ye@MM.Display.LCD.Machine, 2020/09/23, add for multibits backlight */ + oplus_display_tenbits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_tenbits_support"); + oplus_display_elevenbits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_elevenbits_support"); + oplus_display_twelvebits_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_twelvebits_support"); + #endif /* OPLUS_FEATURE_MULTIBITS_BL */ oplus_display_backlight_ic_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_backlight_ic_support"); oplus_display_cabc_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_cabc_support"); oplus_display_cabc_cmdq_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_cabc_cmdq_support"); @@ -502,22 +501,22 @@ int oplus_mtkfb_custom_data_init(struct platform_device *pdev) oplus_display_panelid_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_panelid_support"); oplus_display_panelnum_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_panelnum_support"); oplus_display_panelnum_continue_support = of_property_read_bool(pdev->dev.of_node, "oplus_display_panelnum_continue_support"); - - of_ret = of_property_read_u32(pdev->dev.of_node, "oplus_display_esd_try_count", &oplus_display_esd_try_count); - if (!of_ret) - dev_err(&pdev->dev, "read property oplus_display_esd_try_count failed."); - else - DISPMSG("%s:oplus_display_esd_try_count=%u\n", __func__, oplus_display_esd_try_count); - - of_ret = of_property_read_u32(pdev->dev.of_node, "oplus_display_normal_max_brightness", &oplus_display_normal_max_brightness); - if (!of_ret) - dev_err(&pdev->dev, "read property oplus_display_normal_max_brightness failed."); - else - DISPMSG("%s:oplus_display_normal_max_brightness=%u\n", __func__, oplus_display_normal_max_brightness); - - return of_ret; -} - + + of_ret = of_property_read_u32(pdev->dev.of_node, "oplus_display_esd_try_count", &oplus_display_esd_try_count); + if (!of_ret) + dev_err(&pdev->dev, "read property oplus_display_esd_try_count failed."); + else + DISPMSG("%s:oplus_display_esd_try_count=%u\n", __func__, oplus_display_esd_try_count); + + of_ret = of_property_read_u32(pdev->dev.of_node, "oplus_display_normal_max_brightness", &oplus_display_normal_max_brightness); + if (!of_ret) + dev_err(&pdev->dev, "read property oplus_display_normal_max_brightness failed."); + else + DISPMSG("%s:oplus_display_normal_max_brightness=%u\n", __func__, oplus_display_normal_max_brightness); + + return of_ret; +} + static ssize_t oplus_display_get_brightness(struct device *dev, struct device_attribute *attr, char *buf) { @@ -528,12 +527,12 @@ static ssize_t oplus_display_get_brightness(struct device *dev, return sprintf(buf, "%ld\n", oplus_display_brightness); } -int oplus_display_panel_set_brightness(void *buf) -{ - unsigned int *oplus_brightness = buf; - - oplus_set_brightness = (*oplus_brightness); - +int oplus_display_panel_set_brightness(void *buf) +{ + unsigned int *oplus_brightness = buf; + + oplus_set_brightness = (*oplus_brightness); + pr_info("brightness = %d\n", oplus_set_brightness); if (oplus_set_brightness > LED_FULL || oplus_set_brightness < LED_OFF) { @@ -546,29 +545,29 @@ int oplus_display_panel_set_brightness(void *buf) _primary_path_unlock(__func__); _primary_path_switch_dst_unlock(); - return 0; + return 0; } - -int oplus_display_panel_get_brightness(void *buf) + +int oplus_display_panel_get_brightness(void *buf) { - unsigned int *oplus_brightness = buf; - + unsigned int *oplus_brightness = buf; + if (oplus_display_brightness > LED_FULL || oplus_display_brightness < LED_OFF) { oplus_display_brightness = LED_OFF; } - - *oplus_brightness = oplus_display_brightness; - - return 0; + + *oplus_brightness = oplus_display_brightness; + + return 0; } static ssize_t oplus_display_set_brightness(struct device *dev, - struct device_attribute *attr, const char *buf, size_t num) -{ + struct device_attribute *attr, const char *buf, size_t num) +{ int ret; - + ret = kstrtouint(buf, 10, &oplus_set_brightness); - + printk("%s %d\n", __func__, oplus_set_brightness); if (oplus_set_brightness > LED_FULL || oplus_set_brightness < LED_OFF) { @@ -581,40 +580,40 @@ static ssize_t oplus_display_set_brightness(struct device *dev, _primary_path_unlock(__func__); _primary_path_switch_dst_unlock(); - return num; + return num; } static ssize_t oplus_display_get_max_brightness(struct device *dev, struct device_attribute *attr, char *buf) { - unsigned int max_brightness = 0; - - if (!oplus_display_normal_max_brightness) - max_brightness = LED_FULL; - else - max_brightness = oplus_display_normal_max_brightness; - + unsigned int max_brightness = 0; + + if (!oplus_display_normal_max_brightness) + max_brightness = LED_FULL; + else + max_brightness = oplus_display_normal_max_brightness; + //printk(KERN_INFO "oplus_display_get_max_brightness = %d\n",LED_FULL); return sprintf(buf, "%u\n", max_brightness); } - -int oplus_display_panel_get_max_brightness(void *buf) -{ - uint32_t *max_brightness = buf; - - if (!max_brightness) { - pr_info("invalid argument:NULL\n"); - return -1; - } - - if (!oplus_display_normal_max_brightness) - (*max_brightness) = LED_FULL; - else - (*max_brightness) = oplus_display_normal_max_brightness; - - pr_info("value is %d", *max_brightness); - return 0; -} + +int oplus_display_panel_get_max_brightness(void *buf) +{ + uint32_t *max_brightness = buf; + + if (!max_brightness) { + pr_info("invalid argument:NULL\n"); + return -1; + } + + if (!oplus_display_normal_max_brightness) + (*max_brightness) = LED_FULL; + else + (*max_brightness) = oplus_display_normal_max_brightness; + + pr_info("value is %d", *max_brightness); + return 0; +} static ssize_t oplus_get_aod_light_mode(struct device *dev, struct device_attribute *attr, char *buf) { @@ -634,7 +633,7 @@ static ssize_t oplus_set_aod_light_mode(struct device *dev, if (oplus_display_aodlight_support) { ret = kstrtouint(buf, 10, &temp_save); - + if (primary_display_get_fp_hbm_state()) { printk(KERN_INFO "oplus_set_aod_light_mode = %d return on hbm\n",temp_save); return count; @@ -646,14 +645,14 @@ static ssize_t oplus_set_aod_light_mode(struct device *dev, return count; } - + int oplus_panel_set_aod_light_mode(void *buf) { unsigned int *temp_save = buf; int ret = 0; pr_info("aodlight_support = %d\n", oplus_display_aodlight_support); - + if (oplus_display_aodlight_support) { if (primary_display_get_fp_hbm_state()) { pr_info("oplus_set_aod_light_mode = %d return on hbm\n", (*temp_save)); @@ -666,7 +665,7 @@ int oplus_panel_set_aod_light_mode(void *buf) return 0; } - + int oplus_panel_get_aod_light_mode(void *buf) { unsigned int *aod_mode = buf; @@ -674,7 +673,7 @@ int oplus_panel_get_aod_light_mode(void *buf) pr_info("oplus_panel_get_aod_light_mode = %d\n", aod_light_mode); return 0; } - + int oplus_panel_alpha = 0; int oplus_underbrightness_alpha = 0; @@ -785,33 +784,33 @@ static ssize_t oplus_display_set_dim_alpha(struct device *dev, sscanf(buf, "%x", &oplus_panel_alpha); return count; } - -int oplus_display_panel_get_dim_alpha(void *buf) -{ - unsigned int *dim_alpha = buf; - - if (!primary_display_get_fp_hbm_state()) { - (*dim_alpha) = 0; - } - - oplus_underbrightness_alpha = oplus_get_panel_brightness_to_alpha(); - (*dim_alpha) = oplus_underbrightness_alpha; - - return 0; -} - -int oplus_display_panel_set_dim_alpha(void *buf) -{ - unsigned int *dim_alpha = buf; - - oplus_panel_alpha = (*dim_alpha); - - return 0; -} - -int oplus_dc_alpha = 0; -int oplus_dc_enable = 0; - + +int oplus_display_panel_get_dim_alpha(void *buf) +{ + unsigned int *dim_alpha = buf; + + if (!primary_display_get_fp_hbm_state()) { + (*dim_alpha) = 0; + } + + oplus_underbrightness_alpha = oplus_get_panel_brightness_to_alpha(); + (*dim_alpha) = oplus_underbrightness_alpha; + + return 0; +} + +int oplus_display_panel_set_dim_alpha(void *buf) +{ + unsigned int *dim_alpha = buf; + + oplus_panel_alpha = (*dim_alpha); + + return 0; +} + +int oplus_dc_alpha = 0; +int oplus_dc_enable = 0; + static ssize_t oplus_display_get_dc_enable(struct device *dev, struct device_attribute *attr, char *buf) { @@ -825,23 +824,23 @@ static ssize_t oplus_display_set_dc_enable(struct device *dev, sscanf(buf, "%x", &oplus_dc_enable); return count; } - -int oplus_display_panel_get_dimlayer_enable(void *buf) -{ - unsigned int *dc_enable = buf; - (*dc_enable) = oplus_dc_enable; - pr_info("value is %d", oplus_dc_enable); - return 0; -} - -int oplus_display_panel_set_dimlayer_enable(void *buf) -{ - unsigned int *dc_enable = buf; - oplus_dc_enable = (*dc_enable); - pr_info("value is %d", (*dc_enable)); - return 0; -} - + +int oplus_display_panel_get_dimlayer_enable(void *buf) +{ + unsigned int *dc_enable = buf; + (*dc_enable) = oplus_dc_enable; + pr_info("value is %d", oplus_dc_enable); + return 0; +} + +int oplus_display_panel_set_dimlayer_enable(void *buf) +{ + unsigned int *dc_enable = buf; + oplus_dc_enable = (*dc_enable); + pr_info("value is %d", (*dc_enable)); + return 0; +} + static ssize_t oplus_display_get_dim_dc_alpha(struct device *dev, struct device_attribute *attr, char *buf) { @@ -855,24 +854,24 @@ static ssize_t oplus_display_set_dim_dc_alpha(struct device *dev, sscanf(buf, "%x", &oplus_dc_alpha); return count; } - -int oplus_display_panel_get_dim_dc_alpha(void *buf) -{ - unsigned int *dim_dc_alpha = buf; - - (*dim_dc_alpha) = oplus_dc_alpha; - - return 0; -} - -int oplus_display_panel_set_dim_dc_alpha(void *buf) -{ - unsigned int *dim_dc_alpha = buf; - - oplus_dc_alpha = (*dim_dc_alpha); - - return 0; -} + +int oplus_display_panel_get_dim_dc_alpha(void *buf) +{ + unsigned int *dim_dc_alpha = buf; + + (*dim_dc_alpha) = oplus_dc_alpha; + + return 0; +} + +int oplus_display_panel_set_dim_dc_alpha(void *buf) +{ + unsigned int *dim_dc_alpha = buf; + + oplus_dc_alpha = (*dim_dc_alpha); + + return 0; +} unsigned long HBM_mode = 0; unsigned long HBM_pre_mode = 0; @@ -910,41 +909,41 @@ static ssize_t LCM_HBM_store(struct device *dev, } return num; } - -int oplus_display_panel_set_hbm(void *buf) -{ - int ret = -1; - unsigned int *HBM = buf; - + +int oplus_display_panel_set_hbm(void *buf) +{ + int ret = -1; + unsigned int *HBM = buf; + if (oplus_display_hbm_support) { - HBM_pre_mode = HBM_mode; - HBM_mode = (*HBM); - pr_info("HBM_mode=%ld\n", (*HBM)); - ret = primary_display_set_hbm_mode((unsigned int)HBM_mode); -/* - if (HBM_mode == 1) { - mdelay(80); - printk("%s delay done\n", __func__); - } - if (HBM_mode == 8) { - get_monotonic_boottime(&hbm_time_on); - hbm_on_start = hbm_time_on.tv_sec; - } -*/ - } else { - pr_info("not to support set hbm\n"); - } - return ret; -} - -int oplus_display_panel_get_hbm(void *buf) -{ - unsigned int *HBM = buf; - pr_info("HBM_mode=%ld\n", HBM_mode); - (*HBM) = HBM_mode; - return 0; -} - + HBM_pre_mode = HBM_mode; + HBM_mode = (*HBM); + pr_info("HBM_mode=%ld\n", (*HBM)); + ret = primary_display_set_hbm_mode((unsigned int)HBM_mode); +/* + if (HBM_mode == 1) { + mdelay(80); + printk("%s delay done\n", __func__); + } + if (HBM_mode == 8) { + get_monotonic_boottime(&hbm_time_on); + hbm_on_start = hbm_time_on.tv_sec; + } +*/ + } else { + pr_info("not to support set hbm\n"); + } + return ret; +} + +int oplus_display_panel_get_hbm(void *buf) +{ + unsigned int *HBM = buf; + pr_info("HBM_mode=%ld\n", HBM_mode); + (*HBM) = HBM_mode; + return 0; +} + #if 0 unsigned int ffl_set_mode = 0; @@ -1003,34 +1002,34 @@ static ssize_t lcm_id_info_store(struct device *dev, printk("%s lcm_id_addr = 0x%x\n", __func__, lcm_id_addr); return num; } - -int oplus_display_panel_get_id(void *buf) -{ - int ret = 0; - unsigned char id_addr; - struct panel_id *p_id = buf; - - id_addr = (unsigned char)p_id->DA; /*for mtk DA represent the id_addr to read*/ - p_id->DB = 0; - p_id->DC = 0; - - pr_info("\n"); - - if ((oplus_display_panelid_support) && (id_addr != 0)) { - if (oplus_display_aod_ramless_support) { - ret = primary_display_read_lcm_id(id_addr, &p_id->DA, LCM_REG_READ_LEN); - } else { - ret = primary_display_read_lcm_id(id_addr, &p_id->DA, LCM_ID_READ_LEN); - } - ret = 0; - } else { - pr_err("read id not support\n"); - ret = -1; - } - - return ret; -} - + +int oplus_display_panel_get_id(void *buf) +{ + int ret = 0; + unsigned char id_addr; + struct panel_id *p_id = buf; + + id_addr = (unsigned char)p_id->DA; /*for mtk DA represent the id_addr to read*/ + p_id->DB = 0; + p_id->DC = 0; + + pr_info("\n"); + + if ((oplus_display_panelid_support) && (id_addr != 0)) { + if (oplus_display_aod_ramless_support) { + ret = primary_display_read_lcm_id(id_addr, &p_id->DA, LCM_REG_READ_LEN); + } else { + ret = primary_display_read_lcm_id(id_addr, &p_id->DA, LCM_ID_READ_LEN); + } + ret = 0; + } else { + pr_err("read id not support\n"); + ret = -1; + } + + return ret; +} + static uint64_t serial_number = 0x0; @@ -1046,15 +1045,15 @@ int lcm_first_get_serial(void) return ret; } -int lcm_first_get_serial_change(void) -{ - int ret = 0; - - pr_err("lcm_first_get_serial\n"); - ret = panel_serial_number_read(PANEL_SERIAL_NUM_REG, &serial_number, - PANEL_REG_READ_LEN); - - return ret; +int lcm_first_get_serial_change(void) +{ + int ret = 0; + + pr_err("lcm_first_get_serial\n"); + ret = panel_serial_number_read(PANEL_SERIAL_NUM_REG, &serial_number, + PANEL_REG_READ_LEN); + + return ret; } static ssize_t mdss_get_panel_serial_number(struct device *dev, @@ -1111,26 +1110,26 @@ static ssize_t silence_store(struct device *dev, pr_info("oplus_silence_mode=%ld\n", oplus_silence_mode); return num; } - -int oplus_display_panel_get_closebl_flag(void *buf) -{ - unsigned int *s_mode = buf; - + +int oplus_display_panel_get_closebl_flag(void *buf) +{ + unsigned int *s_mode = buf; + pr_info("oplus_silence_mode=%ld\n", oplus_silence_mode); - (*s_mode) = (unsigned int)oplus_silence_mode; - - return 0; -} - -int oplus_display_panel_set_closebl_flag(void *buf) -{ - unsigned int *s_mode = buf; - - oplus_silence_mode = (*s_mode); + (*s_mode) = (unsigned int)oplus_silence_mode; + + return 0; +} + +int oplus_display_panel_set_closebl_flag(void *buf) +{ + unsigned int *s_mode = buf; + + oplus_silence_mode = (*s_mode); pr_info("oplus_silence_mode=%ld\n", (*s_mode)); - - return 0; -} + + return 0; +} bool oplus_fp_notify_down_delay = false; bool oplus_fp_notify_up_delay = false; @@ -1150,30 +1149,30 @@ void fingerprint_send_notify(struct fb_info *fbi, uint8_t fingerprint_op_mode) pr_info("%s send uiready : %d\n", __func__, fingerprint_op_mode); } -int oplus_display_panel_set_finger_print(void *buf) -{ - uint8_t fingerprint_op_mode = 0x0; - uint32_t *finger_print = buf; - if (oplus_display_fppress_support) { - /* will ignoring event during panel off situation. */ - if (oplus_flag_lcd_off) - { - pr_err("%s panel in off state, ignoring event.\n", __func__); - return 0; - } - fingerprint_op_mode = (uint8_t)(*finger_print); - if (fingerprint_op_mode == 1) { - oplus_fp_notify_down_delay = true; - } else { - oplus_fp_notify_up_delay = true; - ds_rec_fpd = false; - doze_rec_fpd = false; - } - pr_info("%s receive uiready %d\n", __func__,fingerprint_op_mode); - } - return 0; -} - +int oplus_display_panel_set_finger_print(void *buf) +{ + uint8_t fingerprint_op_mode = 0x0; + uint32_t *finger_print = buf; + if (oplus_display_fppress_support) { + /* will ignoring event during panel off situation. */ + if (oplus_flag_lcd_off) + { + pr_err("%s panel in off state, ignoring event.\n", __func__); + return 0; + } + fingerprint_op_mode = (uint8_t)(*finger_print); + if (fingerprint_op_mode == 1) { + oplus_fp_notify_down_delay = true; + } else { + oplus_fp_notify_up_delay = true; + ds_rec_fpd = false; + doze_rec_fpd = false; + } + pr_info("%s receive uiready %d\n", __func__,fingerprint_op_mode); + } + return 0; +} + static ssize_t fingerprint_notify_trigger(struct device *dev, struct device_attribute *attr, const char *buf, size_t num) @@ -1203,195 +1202,195 @@ static ssize_t fingerprint_notify_trigger(struct device *dev, } return num; } - -unsigned long CABC_mode = 2; - -unsigned long cabc_old_mode = 1; -unsigned long cabc_true_mode = 1; -unsigned long cabc_sun_flag = 0; -unsigned long cabc_back_flag = 1; - -enum{ - CABC_LEVEL_0, - CABC_LEVEL_1, - CABC_LEVEL_3 = 3, - CABC_EXIT_SPECIAL = 8, - CABC_ENTER_SPECIAL = 9, -}; - -#if defined(CONFIG_MACH_MT6768) || defined(CONFIG_MACH_MT6785) -bool backlight_high_light_dre_cabc = true; -#else -bool backlight_high_light_dre_cabc = false; -#endif -/* -* add dre only use for camera -*/ -extern void disp_aal_set_dre_en(int enable); - -static ssize_t LCM_CABC_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - if (backlight_high_light_dre_cabc) { - pr_err("%s CABC_mode=%ld\n", __func__, cabc_true_mode); - return sprintf(buf, "%ld\n", cabc_true_mode); - } else { - printk("%s CABC_mode=%ld\n", __func__, CABC_mode); - return sprintf(buf, "%ld\n", CABC_mode); - } -} - -static ssize_t LCM_CABC_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t num) -{ - int ret = 0; - if (backlight_high_light_dre_cabc) { - ret = kstrtoul(buf, 10, &cabc_old_mode); - cabc_true_mode = cabc_old_mode; - if(cabc_old_mode < 4) { - cabc_back_flag = cabc_old_mode; - } - pr_err("%s CABC_mode=%ld cabc_back_flag = %d\n", __func__, cabc_old_mode, cabc_back_flag); - if(CABC_ENTER_SPECIAL == cabc_old_mode) { - cabc_sun_flag = 1; - cabc_true_mode = 0; - } else if (CABC_EXIT_SPECIAL == cabc_old_mode) { - cabc_sun_flag = 0; - cabc_true_mode = cabc_back_flag; - } else if (1 == cabc_sun_flag) { - if(CABC_LEVEL_0 == cabc_back_flag) { - disp_aal_set_dre_en(1); - pr_err("%s enable dre1\n", __func__); - } else { - disp_aal_set_dre_en(1); - pr_err("%s disable dre1\n", __func__); - } - return num; - } - - if(cabc_true_mode == CABC_LEVEL_0 && cabc_back_flag == CABC_LEVEL_0) { - disp_aal_set_dre_en(1); - pr_err("%s enable dre2\n", __func__); - } else { - disp_aal_set_dre_en(1); - pr_err("%s enable dre 2\n", __func__); - } - - pr_err("%s cabc_true_mode = %d\n", __func__, cabc_true_mode); - ret = primary_display_set_cabc_mode((unsigned int)cabc_true_mode); - - if(cabc_true_mode != cabc_back_flag) { - cabc_true_mode = cabc_back_flag; - } - } else { - ret = kstrtoul(buf, 10, &CABC_mode); - if( CABC_mode > 3 ){ - CABC_mode = 3; - } - printk("%s CABC_mode=%ld\n", __func__, CABC_mode); - - if (CABC_mode == 0) { - disp_aal_set_dre_en(1); - printk("%s enable dre\n", __func__); - } else { - disp_aal_set_dre_en(0); - printk("%s disable dre\n", __func__); - } - - /* - * modify for oled not need set cabc - */ - if (oplus_display_cabc_support || oplus_display_cabc_cmdq_support) { - ret = primary_display_set_cabc_mode((unsigned int)CABC_mode); - } - } - - return num; + +unsigned long CABC_mode = 2; + +unsigned long cabc_old_mode = 1; +unsigned long cabc_true_mode = 1; +unsigned long cabc_sun_flag = 0; +unsigned long cabc_back_flag = 1; + +enum{ + CABC_LEVEL_0, + CABC_LEVEL_1, + CABC_LEVEL_3 = 3, + CABC_EXIT_SPECIAL = 8, + CABC_ENTER_SPECIAL = 9, +}; + +#if defined(CONFIG_MACH_MT6768) || defined(CONFIG_MACH_MT6785) +bool backlight_high_light_dre_cabc = true; +#else +bool backlight_high_light_dre_cabc = false; +#endif +/* +* add dre only use for camera +*/ +extern void disp_aal_set_dre_en(int enable); + +static ssize_t LCM_CABC_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + if (backlight_high_light_dre_cabc) { + pr_err("%s CABC_mode=%ld\n", __func__, cabc_true_mode); + return sprintf(buf, "%ld\n", cabc_true_mode); + } else { + printk("%s CABC_mode=%ld\n", __func__, CABC_mode); + return sprintf(buf, "%ld\n", CABC_mode); + } } - -int oplus_display_panel_get_cabc(void *buf) -{ - unsigned int *cabc_status = buf; - - if (backlight_high_light_dre_cabc) { - pr_info("CABC_mode=%ld\n", cabc_true_mode); - (*cabc_status) = cabc_true_mode; - } else { - pr_info("CABC_mode=%ld\n", CABC_mode); - (*cabc_status) = CABC_mode; - } - - return 0; -} - -int oplus_display_panel_set_cabc(void *buf) -{ - int ret = -1; - unsigned int *cabc_status = buf; - - if (backlight_high_light_dre_cabc) { - cabc_old_mode = (*cabc_status); - cabc_true_mode = cabc_old_mode; - if(cabc_old_mode < 4) { - cabc_back_flag = cabc_old_mode; - } - pr_err("CABC_mode=%ld cabc_back_flag = %d\n", cabc_old_mode, cabc_back_flag); - if(CABC_ENTER_SPECIAL == cabc_old_mode) { - cabc_sun_flag = 1; - cabc_true_mode = 0; - } else if (CABC_EXIT_SPECIAL == cabc_old_mode) { - cabc_sun_flag = 0; - cabc_true_mode = cabc_back_flag; - } else if (1 == cabc_sun_flag) { - if(CABC_LEVEL_0 == cabc_back_flag) { - disp_aal_set_dre_en(1); - pr_err("enable dre1\n"); - } else { - disp_aal_set_dre_en(1); - pr_err("disable dre1\n"); - } - return 0; - } - - if(cabc_true_mode == CABC_LEVEL_0 && cabc_back_flag == CABC_LEVEL_0) { - disp_aal_set_dre_en(1); - pr_err("enable dre2\n"); - } else { - disp_aal_set_dre_en(1); - pr_err("enable dre 2\n"); - } - - pr_err("cabc_true_mode = %d\n", cabc_true_mode); - ret = primary_display_set_cabc_mode((unsigned int)cabc_true_mode); - - if(cabc_true_mode != cabc_back_flag) { - cabc_true_mode = cabc_back_flag; - } - } else { - CABC_mode = (*cabc_status); - if(CABC_mode > 3) { - CABC_mode = 3; - } - pr_info("CABC_mode=%ld\n", CABC_mode); - - if (CABC_mode == 0) { - disp_aal_set_dre_en(1); - pr_info("enable dre\n"); - } else { - disp_aal_set_dre_en(0); - pr_info("disable dre\n"); - } - - /* - * modify for oled not need set cabc - */ - if (oplus_display_cabc_support || oplus_display_cabc_cmdq_support) { - ret = primary_display_set_cabc_mode((unsigned int)CABC_mode); - } - } - pr_info("ret = %d\n", ret); - - return 0; + +static ssize_t LCM_CABC_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t num) +{ + int ret = 0; + if (backlight_high_light_dre_cabc) { + ret = kstrtoul(buf, 10, &cabc_old_mode); + cabc_true_mode = cabc_old_mode; + if(cabc_old_mode < 4) { + cabc_back_flag = cabc_old_mode; + } + pr_err("%s CABC_mode=%ld cabc_back_flag = %d\n", __func__, cabc_old_mode, cabc_back_flag); + if(CABC_ENTER_SPECIAL == cabc_old_mode) { + cabc_sun_flag = 1; + cabc_true_mode = 0; + } else if (CABC_EXIT_SPECIAL == cabc_old_mode) { + cabc_sun_flag = 0; + cabc_true_mode = cabc_back_flag; + } else if (1 == cabc_sun_flag) { + if(CABC_LEVEL_0 == cabc_back_flag) { + disp_aal_set_dre_en(1); + pr_err("%s enable dre1\n", __func__); + } else { + disp_aal_set_dre_en(1); + pr_err("%s disable dre1\n", __func__); + } + return num; + } + + if(cabc_true_mode == CABC_LEVEL_0 && cabc_back_flag == CABC_LEVEL_0) { + disp_aal_set_dre_en(1); + pr_err("%s enable dre2\n", __func__); + } else { + disp_aal_set_dre_en(1); + pr_err("%s enable dre 2\n", __func__); + } + + pr_err("%s cabc_true_mode = %d\n", __func__, cabc_true_mode); + ret = primary_display_set_cabc_mode((unsigned int)cabc_true_mode); + + if(cabc_true_mode != cabc_back_flag) { + cabc_true_mode = cabc_back_flag; + } + } else { + ret = kstrtoul(buf, 10, &CABC_mode); + if( CABC_mode > 3 ){ + CABC_mode = 3; + } + printk("%s CABC_mode=%ld\n", __func__, CABC_mode); + + if (CABC_mode == 0) { + disp_aal_set_dre_en(1); + printk("%s enable dre\n", __func__); + } else { + disp_aal_set_dre_en(0); + printk("%s disable dre\n", __func__); + } + + /* + * modify for oled not need set cabc + */ + if (oplus_display_cabc_support || oplus_display_cabc_cmdq_support) { + ret = primary_display_set_cabc_mode((unsigned int)CABC_mode); + } + } + + return num; +} + +int oplus_display_panel_get_cabc(void *buf) +{ + unsigned int *cabc_status = buf; + + if (backlight_high_light_dre_cabc) { + pr_info("CABC_mode=%ld\n", cabc_true_mode); + (*cabc_status) = cabc_true_mode; + } else { + pr_info("CABC_mode=%ld\n", CABC_mode); + (*cabc_status) = CABC_mode; + } + + return 0; +} + +int oplus_display_panel_set_cabc(void *buf) +{ + int ret = -1; + unsigned int *cabc_status = buf; + + if (backlight_high_light_dre_cabc) { + cabc_old_mode = (*cabc_status); + cabc_true_mode = cabc_old_mode; + if(cabc_old_mode < 4) { + cabc_back_flag = cabc_old_mode; + } + pr_err("CABC_mode=%ld cabc_back_flag = %d\n", cabc_old_mode, cabc_back_flag); + if(CABC_ENTER_SPECIAL == cabc_old_mode) { + cabc_sun_flag = 1; + cabc_true_mode = 0; + } else if (CABC_EXIT_SPECIAL == cabc_old_mode) { + cabc_sun_flag = 0; + cabc_true_mode = cabc_back_flag; + } else if (1 == cabc_sun_flag) { + if(CABC_LEVEL_0 == cabc_back_flag) { + disp_aal_set_dre_en(1); + pr_err("enable dre1\n"); + } else { + disp_aal_set_dre_en(1); + pr_err("disable dre1\n"); + } + return 0; + } + + if(cabc_true_mode == CABC_LEVEL_0 && cabc_back_flag == CABC_LEVEL_0) { + disp_aal_set_dre_en(1); + pr_err("enable dre2\n"); + } else { + disp_aal_set_dre_en(1); + pr_err("enable dre 2\n"); + } + + pr_err("cabc_true_mode = %d\n", cabc_true_mode); + ret = primary_display_set_cabc_mode((unsigned int)cabc_true_mode); + + if(cabc_true_mode != cabc_back_flag) { + cabc_true_mode = cabc_back_flag; + } + } else { + CABC_mode = (*cabc_status); + if(CABC_mode > 3) { + CABC_mode = 3; + } + pr_info("CABC_mode=%ld\n", CABC_mode); + + if (CABC_mode == 0) { + disp_aal_set_dre_en(1); + pr_info("enable dre\n"); + } else { + disp_aal_set_dre_en(0); + pr_info("disable dre\n"); + } + + /* + * modify for oled not need set cabc + */ + if (oplus_display_cabc_support || oplus_display_cabc_cmdq_support) { + ret = primary_display_set_cabc_mode((unsigned int)CABC_mode); + } + } + pr_info("ret = %d\n", ret); + + return 0; } static ssize_t oplus_display_get_seed(struct device *dev, @@ -1409,7 +1408,7 @@ static ssize_t oplus_display_set_seed(struct device *dev, ret = kstrtoul(buf, 10, &seed_mode); printk("%s,esd mode is %d\n", __func__, seed_mode); return count; -} +} static struct kobject *oplus_display_kobj; @@ -1429,11 +1428,11 @@ static DEVICE_ATTR(notify_fppress, S_IRUGO|S_IWUSR, NULL, fingerprint_notify_tri static DEVICE_ATTR(sau_closebl_node, S_IRUGO|S_IWUSR, silence_show, silence_store); static DEVICE_ATTR(LCM_CABC, S_IRUGO|S_IWUSR, LCM_CABC_show, LCM_CABC_store); static DEVICE_ATTR(seed, S_IRUGO|S_IWUSR, oplus_display_get_seed, oplus_display_set_seed); -#if defined(CONFIG_MACH_MT6785) +#if defined(CONFIG_MACH_MT6785) /* #ifdef OPLUS_FEATURE_RAMLESS_AOD */ static DEVICE_ATTR(aod_area, S_IRUGO|S_IWUSR, NULL, oplus_display_set_aod_area); /* #endif */ /* OPLUS_FEATURE_RAMLESS_AOD */ -#endif +#endif /* * Create a group of attributes so that we can create and destroy them all @@ -1454,25 +1453,25 @@ static struct attribute *oplus_display_attrs[] = { &dev_attr_sau_closebl_node.attr, &dev_attr_LCM_CABC.attr, &dev_attr_seed.attr, -#if defined(CONFIG_MACH_MT6785) +#if defined(CONFIG_MACH_MT6785) /* #ifdef OPLUS_FEATURE_RAMLESS_AOD */ &dev_attr_aod_area.attr, /* #endif */ /* OPLUS_FEATURE_RAMLESS_AOD */ -#endif +#endif NULL, /* need to NULL terminate the list of attributes */ }; static struct attribute_group oplus_display_attr_group = { .attrs = oplus_display_attrs, -}; - +}; + static int __init oplus_display_private_api_init(void) { int retval; - if (get_eng_version() == 1) - oplus_dc_enable = 1; - + if (get_eng_version() == 1) + oplus_dc_enable = 1; + oplus_display_kobj = kobject_create_and_add("oplus_display", kernel_kobj); if (!oplus_display_kobj) return -ENOMEM; @@ -1493,4 +1492,4 @@ static void __exit oplus_display_private_api_exit(void) module_init(oplus_display_private_api_init); module_exit(oplus_display_private_api_exit); MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Hujie "); +MODULE_AUTHOR("Hujie "); diff --git a/drivers/misc/oplus_misc_healthinfo/Kconfig b/drivers/misc/oplus_misc_healthinfo/Kconfig deleted file mode 100755 index 46fd02ad3e8b..000000000000 --- a/drivers/misc/oplus_misc_healthinfo/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -config OPLUS_MISC_HEALTHONFO - bool "oplus misc healthinfo device" - default n - help - Say Y here if you oplus misc healthinfo connected - to your system. - - If unsure, say N. diff --git a/drivers/misc/oplus_misc_healthinfo/Makefile b/drivers/misc/oplus_misc_healthinfo/Makefile deleted file mode 100755 index 32290abaa6c7..000000000000 --- a/drivers/misc/oplus_misc_healthinfo/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-$(CONFIG_OPLUS_MISC_HEALTHONFO) += oplus_misc_healthinfo.o diff --git a/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.c b/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.c deleted file mode 100755 index 37b5752251e7..000000000000 --- a/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.c +++ /dev/null @@ -1,368 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "oplus_misc_healthinfo.h" - -#define DRIVER_NAME "oplus_misc_healthinfo" -#define MAX_CNT 2592000 -#define CHG_TIME 1000 -#define PAGESIZE 512 -#define MAX_SECOND 60 -#define MAX_MINUTE 60 -#define MAX_HOUR 60 -#define MAX_LIGHTS 3 -#define ON 1 -#define OFF 0 -#define CNT_CLEAR 0 - -unsigned int omh_debug; - -static unsigned long long time_cnr[TIME_COUNT] = {0}; -static unsigned int my_para[TIME_COUNT] = {0}; -static unsigned int my_status[TIME_COUNT] = {0}; - -static unsigned long long lights_health_para[TIME_COUNT][TIME_COUNT] = {{0}}; - -struct work_struct my_work; -struct workqueue_struct *my_wq; - -static void lights_time_record_work(struct work_struct *work) -{ - unsigned long long time_cnt = 0; - unsigned long long power_cnt = 0; - int i = 0; - - for (i = 0;i < MAX_LIGHTS;i++) { - if (lights_health_para[i][1] == LIGHTS_ON && lights_health_para[i][2] == OFF) { - lights_health_para[i][2] = ON; - lights_health_para[i][3] = ktime_to_ms(ktime_get()); - lights_health_para[i][7] = lights_health_para[i][6]; - - OMH_DEBUG("%s ON", - lights_health_para[i][0] > LIGHTS_GREEN ? "LIGHTS_BLUE" : \ - lights_health_para[i][0] == LIGHTS_GREEN ? "LIGHTS_GREEN" : "LIGHTS_RED"); - } else if (lights_health_para[i][1] == LIGHTS_OFF && lights_health_para[i][2] == ON) { - lights_health_para[i][2] = OFF; - lights_health_para[i][4] = ktime_to_ms(ktime_get()); - - OMH_DEBUG("%s OFF", - lights_health_para[i][0] > LIGHTS_GREEN ? "LIGHTS_BLUE" : \ - lights_health_para[i][0] == LIGHTS_GREEN ? "LIGHTS_GREEN" : "LIGHTS_RED"); - - if (lights_health_para[i][5] < MAX_CNT) { - time_cnt = lights_health_para[i][4] - lights_health_para[i][3]; - lights_health_para[i][5] += time_cnt; - } else { - lights_health_para[i][5] = CNT_CLEAR; - } - - if (lights_health_para[i][5] > MAX_SECOND) { - lights_health_para[i][9] = lights_health_para[i][5] / MAX_SECOND; - if (lights_health_para[i][9] > MAX_MINUTE) - lights_health_para[i][10] = lights_health_para[i][9] / MAX_MINUTE; - } - - power_cnt = lights_health_para[i][7] * 4 * (time_cnt / CHG_TIME); - lights_health_para[i][8] = power_cnt; - - OMH_DEBUG("debug : [%d][%d][%d]", - lights_health_para[i][5], time_cnt, lights_health_para[i][7]); - } - } - - return; -} - -int oplus_misc_healthinfo(int type, int para, int bright) -{ - int ret = 0; - - switch (type) { - case LIGHTS_RED: - lights_health_para[0][0] = LIGHTS_RED; - lights_health_para[0][1] = para; - lights_health_para[0][6] = bright; - break; - case LIGHTS_GREEN: - lights_health_para[1][0] = LIGHTS_GREEN; - lights_health_para[1][1] = para; - lights_health_para[1][6] = bright; - break; - case LIGHTS_BLUE: - lights_health_para[2][0] = LIGHTS_BLUE; - lights_health_para[2][1] = para; - lights_health_para[2][6] = bright; - break; - default: - OMH_INFO("nothing get\n"); - break; - } - - my_para[0] = type; - my_para[1] = para; - queue_work(my_wq, &my_work); - - return ret; -} -EXPORT_SYMBOL(oplus_misc_healthinfo); - -static int proc_misc_healthinfo_read(struct seq_file *s, void *v) { - struct oplus_misc_healthinfo_para *omhp = s->private; - ssize_t ret = 0; - int i = 0; - unsigned long long cnt_time; - unsigned long long lcd_para[TIME_COUNT][TIME_COUNT] = {{0}}; - - mutex_lock(&omhp->my_lock); - - cnt_time = lights_health_para[0][5] + lights_health_para[1][5] + lights_health_para[2][5]; - - cnt_time = cnt_time / CHG_TIME; - - - OMH_DEBUG("0 lights_health_para[%d]", lights_health_para[0][5]); - - for (i = 0; i < MAX_LIGHTS; i++) { - if ((lights_health_para[i][5] / CHG_TIME) > MAX_SECOND) { - lcd_para[i][1] = lights_health_para[i][8]; - lcd_para[i][2] = CNT_CLEAR; - lcd_para[i][3] = lights_health_para[i][9] / CHG_TIME; - lcd_para[i][4] = lights_health_para[i][10] / CHG_TIME; - } else { - lcd_para[i][1] = lights_health_para[i][8]; - lcd_para[i][2] = lights_health_para[i][5] / CHG_TIME; - lcd_para[i][3] = CNT_CLEAR; - lcd_para[i][4] = CNT_CLEAR; - } - } - - seq_printf(s, "name:lights_all:%d\n", cnt_time); - - for (i = 0; i < MAX_LIGHTS; i++) { - seq_printf(s, "name:light_%s, power:%d, times_sec:%d, times_min:%d, times_hour:%d\n", - lights_health_para[i][0] > LIGHTS_GREEN ? "blue" : \ - lights_health_para[i][0] == LIGHTS_GREEN ? "green" : "red", \ - lcd_para[i][1], - lcd_para[i][2], - lcd_para[i][3], - lcd_para[i][4]); - OMH_DEBUG("read lcd_para[%d][2][3][4] = %d, %d, %d", i, - lcd_para[i][2], - lcd_para[i][3], - lcd_para[i][4]); - } - - mutex_unlock(&omhp->my_lock); - - return ret; -} - -static ssize_t proc_misc_healthinfo_write(struct file *file, const char __user *buffer, - size_t count, loff_t *ppos) -{ - struct oplus_misc_healthinfo_para *omhp = PDE_DATA(file_inode(file)); - char buf[PAGESIZE] = {0}; - int tmp = 0; - int i = 0, j = 0; - - mutex_lock(&omhp->my_lock); - - if (!omhp || count >= sizeof(buf)) { - OMH_INFO("! cd or count over size"); - goto OUT; - } - - if (copy_from_user(buf, buffer, count)) { - OMH_INFO("write proc input error."); - goto OUT; - } - - if(!sscanf(buf, "%d", &tmp)) { - OMH_INFO("write proc input error."); - goto OUT; - } - - OMH_INFO(" tmp is %d \n", tmp); - - if (tmp == 1) { - OMH_INFO("clear all\n"); - for (i = 0; i < TIME_COUNT; i++) - for (j = 0; j < TIME_COUNT; j++) - lights_health_para[i][j] = 0; - } - mutex_unlock(&omhp->my_lock); - return count; -OUT: - mutex_unlock(&omhp->my_lock); - OMH_INFO(" write ec_debug_level failed \n"); - return -1; -} - -static int proc_misc_healthinfo_open(struct inode *inode, struct file *file) { - return single_open(file, proc_misc_healthinfo_read, PDE_DATA(inode)); -} - -static const struct file_operations proc_misc_healthinfo_ops = { - .owner = THIS_MODULE, - .open = proc_misc_healthinfo_open, - .read = seq_read, - .write = proc_misc_healthinfo_write, - .release = single_release, -}; - -static int oplus_misc_healthinfo_init_proc(struct oplus_misc_healthinfo_para *omhp) -{ - int ret = 0; - struct proc_dir_entry *prEntry_cr = NULL; - struct proc_dir_entry *prEntry_tmp = NULL; - - OMH_INFO("entry"); - /*proc files-step1:/proc/oplus_misc*/ - - prEntry_cr = proc_mkdir("oplus_misc", NULL); - - if (prEntry_cr == NULL) { - ret = -ENOMEM; - OMH_INFO("Couldn't create oplus_misc_healthinfo_init_proc entry"); - } - - /*proc files-step2:/proc/oplus_misc/healthinfo (misc_healthinfo interface)*/ - prEntry_tmp = proc_create_data("misc_feedback", 0666, prEntry_cr, &proc_misc_healthinfo_ops, omhp); - if (prEntry_tmp == NULL) { - ret = -ENOMEM; - OMH_INFO("Couldn't create proc_misc_healthinfo_ops entry"); - } - - return ret; -} - -static oplus_misc_healthinfo_parse_dt(struct device *dev, struct oplus_misc_healthinfo_para *omhp) -{ - struct device_node *dn = dev->of_node; - if (!dn) { - OMH_INFO("Don't has device of_node."); - return -1; - } - - omhp->omhp_support = of_property_read_bool(dn, "oplus_misc_healthinfo_support"); - - return 0; -} - -static int oplus_misc_healthinfo_probe(struct platform_device *pdev) -{ - int ret = 0, i = 0, j = 0; - - struct oplus_misc_healthinfo_para *omhp = NULL; - pr_err("start to probe oplus_misc_healthinfo driver."); - - omhp = devm_kzalloc(&pdev->dev, sizeof(struct oplus_misc_healthinfo_para), GFP_KERNEL); - if (!omhp) { - OMH_INFO("Malloc memory for oplus_misc_healthinfo fail."); - ret = -ENOMEM; - goto PROBE_ERR; - } - - ret = oplus_misc_healthinfo_parse_dt(&pdev->dev, omhp); - - omhp->my_pdev = pdev; - omhp->my_dev = &pdev->dev; - mutex_init(&omhp->my_lock); - platform_set_drvdata(pdev, omhp); - - OMH_INFO("probe clear all\n"); - - for (i = 0; i < TIME_COUNT; i++) - for (j = 0; j < TIME_COUNT; j++) - lights_health_para[i][j] = 0; - - my_wq = create_singlethread_workqueue("oplus_misc_healthinfo_wq"); - if (!my_wq) { - ret = -ENOMEM; - OMH_INFO("Malloc memory for oplus_misc_healthinfo fail."); - goto PROBE_ERR; - } - INIT_WORK(&my_work, lights_time_record_work); - - - ret = oplus_misc_healthinfo_init_proc(omhp); - - if (ret) { - OMH_INFO("creat oplus_misc_healthinfo_init_proc proc error."); - goto PROBE_ERR; - } - -PROBE_ERR: - return 0; -} - - -static int oplus_misc_healthinfo_remove(struct platform_device *dev) { - struct oplus_misc_healthinfo_para *omhp = platform_get_drvdata(dev); - OMH_INFO("start remove the oplus_misc_healthinfo platform dev."); - - if (omhp) { - proc_remove(omhp->my_prEntry_cr); - omhp->my_prEntry_cr = NULL; - } - - return 0; -} - -static const struct of_device_id oplus_misc_healthinfo_match_table[] = { - {.compatible = "oplus,misc_healthinfo"}, - {} -}; - -static struct platform_driver oplus_misc_healthinfo_driver = { - .probe = oplus_misc_healthinfo_probe, - .remove = oplus_misc_healthinfo_remove, - .driver = { - .owner = THIS_MODULE, - .name = DRIVER_NAME, - .of_match_table = oplus_misc_healthinfo_match_table, - }, -}; - -static int __init oplus_misc_healthinfo_init(void) { - return platform_driver_register(&oplus_misc_healthinfo_driver); -} - -static void __exit oplus_misc_healthinfo_exit(void) { - return platform_driver_unregister(&oplus_misc_healthinfo_driver); -} - - -late_initcall(oplus_misc_healthinfo_init); -module_exit(oplus_misc_healthinfo_exit); - -MODULE_DESCRIPTION("oplus_misc_healthinfo Driver Module"); -MODULE_AUTHOR("Xuhang.Li"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.h b/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.h deleted file mode 100755 index fb89204d58e1..000000000000 --- a/drivers/misc/oplus_misc_healthinfo/oplus_misc_healthinfo.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _OPLUS_MISC_HEALTHONFO_ -#define _OPLUS_MISC_HEALTHONFO_ -#include -#include - -extern unsigned int omh_debug; - -#define TIME_COUNT 12 - -#define OMH_INFO(fmt, args...) \ - pr_info("OPLUS_MISC: healthinfo :%s:" fmt "\n", __func__, ##args) - -#define LEVEL_DEBUG 1 - -#define OMH_DEBUG(fmt, args...) \ - do { \ - if (LEVEL_DEBUG == omh_debug) \ - pr_info("OPLUS_MISC: healthinfo :%s:" fmt "\n", __func__, ##args);\ - }while(0) - -enum lights_status { - LIGHTS_RED = 0, - LIGHTS_GREEN, - LIGHTS_BLUE, - LIGHTS_ON, - LIGHTS_OFF, - DEFAULT, -}; - -struct oplus_misc_healthinfo_para { - struct platform_device *my_pdev; - struct proc_dir_entry *my_prEntry_cr; - struct device *my_dev; - struct mutex my_lock; - unsigned int omhp_support; -}; - -#endif /* _OPLUS_MISC_HEALTHONFO_ */ - diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index f46b4475524f..298d0be6a8e8 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -28,9 +28,6 @@ #include "sdio_cis.h" #include "bus.h" -#ifdef OPLUS_FEATURE_SDCARD_INFO -#include "../host/sdInfo/sdinfo.h" -#endif #define to_mmc_driver(d) container_of(d, struct mmc_driver, drv) @@ -285,9 +282,6 @@ struct mmc_card *mmc_alloc_card(struct mmc_host *host, struct device_type *type) return card; } -#ifdef OPLUS_FEATURE_SDCARD_INFO -extern void set_sdinfo(struct mmc_card *card); -#endif /* * Register a new MMC card with the driver model. */ @@ -370,12 +364,6 @@ int mmc_add_card(struct mmc_card *card) mmc_card_set_present(card); -#ifdef OPLUS_FEATURE_SDCARD_INFO - if (card->type == MMC_TYPE_SD) { - reset_sdinfo(); - set_sdinfo(card); - } -#endif return 0; } diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index b6deeb7cfec5..7f8f7a942eff 100755 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -55,9 +55,6 @@ #include "mtk_mmc_block.h" #include "queue.h" -#ifdef OPLUS_FEATURE_SDCARD_INFO -#include "../host/sdInfo/sdinfo.h" -#endif /* If the device is not responding */ #define MMC_CORE_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ @@ -1283,18 +1280,6 @@ static void mmc_wait_data_done(struct mmc_request *mrq) context_info->is_done_rcv = true; wake_up_interruptible(&context_info->wait); -#ifdef OPLUS_FEATURE_SDCARD_INFO - if (mrq->host && mrq->host->card && mmc_card_sd(mrq->host->card)) { - if ((mrq->cmd && (mrq->cmd->error == -ETIMEDOUT)) || (mrq->stop && (mrq->stop->error == -ETIMEDOUT)) || (mrq->sbc && (mrq->sbc->error == -ETIMEDOUT))) - sdinfo.cmd_timeout_count += 1; - else if ((mrq->cmd && (mrq->cmd->error == -EILSEQ)) || (mrq->stop && (mrq->stop->error == -EILSEQ)) || (mrq->sbc && (mrq->sbc->error == -EILSEQ))) - sdinfo.cmd_crc_err_count += 1; - else if (mrq->data && (mrq->data->error == -ETIMEDOUT)) - sdinfo.data_timeout_int_count +=1; - else if (mrq->data && (mrq->data->error == -EILSEQ)) - sdinfo.data_crc_err_count += 1; - } -#endif } static void mmc_wait_done(struct mmc_request *mrq) @@ -1398,18 +1383,6 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) } } -#ifdef OPLUS_FEATURE_SDCARD_INFO - if (host && host->card && mmc_card_sd(host->card)) { - if ((mrq->cmd && (mrq->cmd->error == -ETIMEDOUT)) || (mrq->stop && (mrq->stop->error == -ETIMEDOUT)) || (mrq->sbc && (mrq->sbc->error == -ETIMEDOUT))) - sdinfo.cmd_timeout_count += 1; - else if ((mrq->cmd && (mrq->cmd->error == -EILSEQ)) || (mrq->stop && (mrq->stop->error == -EILSEQ)) || (mrq->sbc && (mrq->sbc->error == -EILSEQ))) - sdinfo.cmd_crc_err_count += 1; - else if (mrq->data && (mrq->data->error == -ETIMEDOUT)) - sdinfo.data_timeout_int_count +=1; - else if (mrq->data && (mrq->data->error == -EILSEQ)) - sdinfo.data_crc_err_count += 1; - } -#endif if (!cmd->error || !cmd->retries || mmc_card_removed(host->card)) break; diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 0d900211604b..6b5f75c8c486 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -29,9 +29,6 @@ #include "sd.h" #include "sd_ops.h" -#ifdef OPLUS_FEATURE_SDCARD_INFO -#include "../host/sdInfo/sdinfo.h" -#endif static const unsigned int tran_exp[] = { 10000, 100000, 1000000, 10000000, @@ -1218,10 +1215,6 @@ static int _mmc_sd_resume(struct mmc_host *host) out: mmc_release_host(host); -#ifdef OPLUS_FEATURE_SDCARD_INFO - if (err) - sdinfo.runtime_resume_error_count += 1; -#endif return err; } diff --git a/drivers/mmc/host/mediatek/ComboA/sd.c b/drivers/mmc/host/mediatek/ComboA/sd.c index 0392027f3931..eee8da76a46a 100644 --- a/drivers/mmc/host/mediatek/ComboA/sd.c +++ b/drivers/mmc/host/mediatek/ComboA/sd.c @@ -69,9 +69,6 @@ #include "dbg.h" -#ifdef OPLUS_FEATURE_SDCARD_INFO -#include "../../sdInfo/sdinfo.h" -#endif #define CAPACITY_2G (2 * 1024 * 1024 * 1024ULL) @@ -2599,12 +2596,6 @@ static void msdc_dma_start(struct msdc_host *host) /* Schedule delayed work to check if data0 keeps busy */ if (host->data) { host->data_timeout_ms = DATA_TIMEOUT_MS; -#ifdef OPLUS_FEATURE_SDCARD_INFO - if (get_dma_data_timeout() && host->mmc && host->mmc->card && mmc_card_sd(host->mmc->card)) { - host->data_timeout_ms = 1000 * 10; /* 10s */ - pr_err("mmc set dma timeout to 10s\n"); - } -#endif schedule_delayed_work(&host->data_timeout_work, msecs_to_jiffies(host->data_timeout_ms)); N_MSG(DMA, "DMA Data Busy Timeout:%u ms, schedule_delayed_work", @@ -4260,17 +4251,6 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq) bool cq_host_en = false; #endif -#ifdef OPLUS_FEATURE_SDCARD_INFO - if ((SET_SDCARD_QUICK_RETURN == get_sdcard_remove()) && mmc->card && mmc_card_sd(mmc->card)) { - if (mrq && mrq->cmd && ((mrq->cmd->opcode == MMC_READ_SINGLE_BLOCK) || (mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) || (mrq->cmd->opcode == MMC_WRITE_BLOCK) || (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK))) { - pr_err("mmc card(sd) error, cmd: %u arg: %u\n", mrq->cmd->opcode, mrq->cmd->arg); - mrq->cmd->error = (unsigned int)-EIO; - if (mrq->done) - mrq->done(mrq); - goto end; - } - } -#endif if ((host->hw->host_function == MSDC_SDIO) && !(host->trans_lock.active)) @@ -4735,9 +4715,6 @@ static void msdc_check_data_timeout(struct work_struct *work) spin_unlock(&host->lock); data->error = (unsigned int)-ETIMEDOUT; -#ifdef OPLUS_FEATURE_SDCARD_INFO - sdinfo.data_timeout_count += 1; -#endif host->sw_timeout++; if (mrq->done) @@ -5293,9 +5270,6 @@ static int msdc_drv_probe(struct platform_device *pdev) if (!mmc) return -ENOMEM; -#ifdef OPLUS_FEATURE_SDCARD_INFO - sdcard_remove_attr_init_sysfs(&pdev->dev); -#endif host = mmc_priv(mmc); /* Initialize vcore opp to leave vcore unchanged by default */ diff --git a/drivers/mmc/host/sdInfo/sdinfo.c b/drivers/mmc/host/sdInfo/sdinfo.c index 1f8698df8d79..95991e4d7e44 100644 --- a/drivers/mmc/host/sdInfo/sdinfo.c +++ b/drivers/mmc/host/sdInfo/sdinfo.c @@ -11,111 +11,3 @@ ** 2021-07-13 1.0 sdcard info ****************************************************************/ -#ifdef OPLUS_FEATURE_SDCARD_INFO - -#include -#include -#include -#include "sdinfo.h" - -#define UNSTUFF_BITS(resp, start, size) \ - ({ \ - const int __size = size; \ - const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ - const int __off = 3 - ((start) / 32); \ - const int __shft = (start) & 31; \ - u32 __res; \ - \ - __res = resp[__off] >> __shft; \ - if (__size + __shft > 32) \ - __res |= resp[__off-1] << ((32 - __shft) % 32); \ - __res & __mask; \ - }) - -struct sd_info sdinfo; -static int remove_sdcard = 0; -static struct delayed_work remove_sdcard_reset_work; -static int set_dma_data_timeout = 0; - -static void sdcard_remove_reset(struct work_struct *work) -{ - remove_sdcard = 0; - pr_err("mmc reset sdcard_remove\n"); -} - -ssize_t sdcard_remove_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return snprintf(buf, PAGE_SIZE, "echo 1 > /sys/devices/platform/soc/externdevice/sdcard_remove\nremove_sdcard=%d\n", remove_sdcard); -} - -ssize_t sdcard_remove_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - u32 value; - - value = (u32)buf[0] - 48; - - pr_err("mmc sdcard_remove value: %u\n", value); - if (value) { - switch(value) { - case SET_SDCARD_QUICK_RETURN : remove_sdcard = value; sdinfo.vold_timeout_count += 1; break; - case RESET_SDCARD_QUICK_RETURN : schedule_delayed_work(&remove_sdcard_reset_work, msecs_to_jiffies(2000)); break; - case SET_DMA_DATA_TIMEOUT : set_dma_data_timeout = 1; break; - case RESET_DMA_DATA_TIMEOUT : set_dma_data_timeout = 0; break; - default : pr_err("mmc sdinfo: value(%d) error\n", value); - } - } else - remove_sdcard = 0; - - return count; -} - -static struct device_attribute sdcard_remove_attr; -void sdcard_remove_attr_init_sysfs(struct device *dev) -{ - sdcard_remove_attr.show = sdcard_remove_show; - sdcard_remove_attr.store = sdcard_remove_store; - sysfs_attr_init(&sdcard_remove_attr.attr); - sdcard_remove_attr.attr.name = "sdcard_remove"; - sdcard_remove_attr.attr.mode = 0644; - if (device_create_file(dev, &sdcard_remove_attr)) - dev_err(dev, "Failed to create sysfs for sdcard_remove_attr\n"); - - INIT_DELAYED_WORK(&remove_sdcard_reset_work, sdcard_remove_reset); -} - -void reset_sdinfo(void) -{ - char *tmp = (char*)&sdinfo; - int len = sizeof(sdinfo); - - while (len--) - *(tmp+len) = 0; - remove_sdcard = 0; - set_dma_data_timeout = 0; -} - -void set_sdinfo(struct mmc_card *card) -{ - sdinfo.manfid = card->cid.manfid; - sdinfo.csd_version = UNSTUFF_BITS(card->raw_csd, 126, 2); - sdinfo.capacity = card->csd.capacity; - sdinfo.supported_bus_mode = card->sw_caps.sd3_bus_mode & (SD_MODE_UHS_SDR104 | SD_MODE_UHS_SDR50 | SD_MODE_UHS_DDR50 | SD_MODE_UHS_SDR25 | SD_MODE_UHS_SDR12); - sdinfo.sd_bus_speed = card->sd_bus_speed; - sdinfo.taac_ns = card->csd.taac_ns; - sdinfo.taac_clks = card->csd.taac_clks; - sdinfo.r2w_factor = card->csd.r2w_factor; -} - -int get_sdcard_remove(void) -{ - return remove_sdcard; -} - -int get_dma_data_timeout(void) -{ - return set_dma_data_timeout; -} - -#endif diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 0de7fe6d8b23..134a88447f36 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -43,9 +43,6 @@ struct reserved_mem *get_reserved_mem(int num) return &reserved_mem[num]; } -#ifdef OPLUS_FEATURE_LOWMEM_DBG -static unsigned long reserved_mem_size; -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ #if defined(CONFIG_HAVE_MEMBLOCK) #include @@ -293,9 +290,6 @@ void __init fdt_init_reserved_mem(void) &rmem->base, &rmem->size); if (err == 0) __reserved_mem_init_node(rmem); -#ifdef OPLUS_FEATURE_LOWMEM_DBG - reserved_mem_size += rmem->size; -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ } } @@ -383,12 +377,6 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, } EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_idx); -#ifdef OPLUS_FEATURE_LOWMEM_DBG -unsigned long dt_memory_reserved_pages(void) -{ - return reserved_mem_size >> PAGE_SHIFT; -} -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ /** * of_reserved_mem_device_release() - release reserved memory device structures diff --git a/drivers/power/oplus/oplus_charger.c b/drivers/power/oplus/oplus_charger.c index de26e4ef9101..1ee17b669f7f 100755 --- a/drivers/power/oplus/oplus_charger.c +++ b/drivers/power/oplus/oplus_charger.c @@ -526,13 +526,7 @@ int oplus_battery_set_property(struct power_supply *psy, } EXPORT_SYMBOL(oplus_battery_set_property); -#define OPLUS_MIDAS_CHG_DEBUG 1 -#ifdef OPLUS_MIDAS_CHG_DEBUG -#define midas_debug(fmt, args...) \ - pr_notice("[OPLUS_MIDAS_CHG_DEBUG]" fmt, ##args) -#else #define midas_debug(fmt, args...) -#endif /* OPLUS_MIDAS_CHG_DEBUG */ static struct oplus_midas_chg { int cali_passed_chg; diff --git a/drivers/power/oplus/oplus_debug_info.c b/drivers/power/oplus/oplus_debug_info.c index 7c7725ce00d2..add00d576137 100755 --- a/drivers/power/oplus/oplus_debug_info.c +++ b/drivers/power/oplus/oplus_debug_info.c @@ -17,9 +17,6 @@ #include -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) -#include -#endif #include "oplus_vooc.h" #include "oplus_charger.h" @@ -49,10 +46,6 @@ static int break_flag = -1; static int mcu_update_flag = -1; static int gauge_seal_flag = -1; -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) -#define OPLUS_CHG_DEBUG_LOG_TAG "OplusCharger" -#define OPLUS_CHG_DEBUG_EVENT_ID "charge_monitor" -#endif struct oplus_chg_debug_info oplus_chg_debug_info; struct oplus_chg_chip *g_debug_oplus_chip = NULL; @@ -369,99 +362,6 @@ static int oplus_chg_reset_chg_notify_type(void); static int oplus_chg_chg_batt_capacity_jump_check(struct oplus_chg_chip *chip); static int oplus_chg_mcu_update_check(struct oplus_chg_chip *chip); -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) -static int oplus_chg_pack_debug_info(struct oplus_chg_chip *chip) -{ - char log_tag[] = OPLUS_CHG_DEBUG_LOG_TAG; - char event_id[] = OPLUS_CHG_DEBUG_EVENT_ID; - int len; - - len = strlen(&oplus_chg_debug_msg[sizeof(struct kernel_packet_info)]); - - if (len) { - mutex_lock(&oplus_chg_debug_info.dcs_info_lock); - memset(oplus_chg_debug_info.dcs_info, 0x0, sizeof(struct kernel_packet_info)); - - oplus_chg_debug_info.dcs_info->type = 1; - memcpy(oplus_chg_debug_info.dcs_info->log_tag, log_tag, strlen(log_tag)); - memcpy(oplus_chg_debug_info.dcs_info->event_id, event_id, strlen(event_id)); - oplus_chg_debug_info.dcs_info->payload_length = len + 1; - - if (chg_check_point_debug&OPEN_LOG_BIT) { - chg_err("%s\n", oplus_chg_debug_info.dcs_info->payload); - } - - mutex_unlock(&oplus_chg_debug_info.dcs_info_lock); - - return 0; - } - return -1; -} - -static int oplus_chg_debug_mask_notify_flag(int low, int high) -{ - unsigned long long mask = -1; - int bits = sizeof(mask) * 8 - 1; - - mask = (mask >> low) << low; - mask = (mask << (bits - high)) >> (bits - high); - mutex_lock(&oplus_chg_debug_info.nflag_lock); - oplus_chg_debug_info.notify_flag &= ~mask; - mutex_unlock(&oplus_chg_debug_info.nflag_lock); - - return 0; -} - -static void oplus_chg_send_info_dwork(struct work_struct *work) -{ - int ret; - - mutex_lock(&oplus_chg_debug_info.dcs_info_lock); - ret = fb_kevent_send_to_user(oplus_chg_debug_info.dcs_info); - mutex_unlock(&oplus_chg_debug_info.dcs_info_lock); - if ((ret > 0) && (oplus_chg_debug_info.retry_cnt > 0)) { - queue_delayed_work(oplus_chg_debug_info.oplus_chg_debug_wq, - &oplus_chg_debug_info.send_info_dwork, msecs_to_jiffies(SEND_INFO_DELAY)); - } - else { - //soc jump - oplus_chg_debug_mask_notify_flag(0, OPLUS_NOTIFY_CHG_BATT_FULL_NON_100_CAP); - - //slow check - if(send_info_flag != SEND_INFO_FLAG_IRQ) {//plug out with mcu error 0x54 do not clear charger slow flag - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_CHG_SLOW_BATT_WARM_TEMP, - OPLUS_NOTIFY_CHG_SLOW_LED_ON_LONG_TIME); - } - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_CHG_SLOW_BATT_NON_AUTH, - OPLUS_NOTIFY_SC8547_ERROR);/*ic error*/ - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_CHG_BATT_RECHG, OPLUS_NOTIFY_CHG_BATT_RECHG);/*add for rechg counts*/ - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_WIRELESS_BOOTUP, OPLUS_NOTIFY_WIRELESS_STOP_TX);/*add for wireless chg*/ - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_WIRELESS_BOOTUP, OPLUS_NOTIFY_WIRELESS_WIRELESS_CHG_END);/*add for wireless chg*/ - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_BCC_ANODE_POTENTIAL_OVER_TIME, OPLUS_NOTIFY_BCC_ANODE_POTENTIAL_OVER_TIME); - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_BCC_CURR_ADJUST_ERR, OPLUS_NOTIFY_BCC_CURR_ADJUST_ERR); - if (oplus_switching_support_parallel_chg() == 1) { - oplus_chg_debug_mask_notify_flag(OPLUS_NOTIFY_PARALLEL_LIMITIC_ERROR, OPLUS_NOTIFY_PARALLEL_FULL_NON_100_ERROR);/*add for parallel chg*/ - } - oplus_chg_reset_chg_notify_type(); - memset(oplus_chg_debug_info.flag_reason,0,sizeof(oplus_chg_debug_info.flag_reason)); - memset(oplus_chg_debug_info.type_reason,0,sizeof(oplus_chg_debug_info.type_reason)); - memset(oplus_chg_debug_info.bcc_buf, 0, sizeof(oplus_chg_debug_info.bcc_buf)); - memset(oplus_chg_debug_info.sc8547_error_reason, 0, - sizeof(oplus_chg_debug_info.sc8547_error_reason)); - oplus_chg_debug_info.vooc_mcu_error = 0; - if(send_info_flag == SEND_INFO_FLAG_IRQ) { - send_info_flag = 0; - } - break_flag = -1; - mcu_update_flag = -1; - gauge_seal_flag = -1; - } - - chg_err("retry_cnt: %d\n", oplus_chg_debug_info.retry_cnt); - - oplus_chg_debug_info.retry_cnt--; -} -#endif static int oplus_chg_read_filedata(struct timespec *ts) { @@ -591,22 +491,11 @@ static void oplus_chg_print_debug_info(struct oplus_chg_chip *chip) if (oplus_chg_debug_info.notify_type || oplus_chg_debug_notify_flag_is_set(OPLUS_NOTIFY_CHARGER_INFO)) { -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) - if (delayed_work_pending(&oplus_chg_debug_info.send_info_dwork)) - cancel_delayed_work_sync(&oplus_chg_debug_info.send_info_dwork); - mutex_lock(&oplus_chg_debug_info.dcs_info_lock); -#endif memset(oplus_chg_debug_msg, 0x0, sizeof(oplus_chg_debug_msg)); getnstimeofday(&ts); rtc_time_to_tm(ts.tv_sec, &tm); -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) - ret += sizeof(struct kernel_packet_info); - - ret += snprintf(&oplus_chg_debug_msg[ret], OPLUS_CHG_DEBUG_MSG_LEN - ret, - OPLUS_CHG_DEBUG_EVENT_ID"$$"); -#endif //add for common ret += snprintf(&oplus_chg_debug_msg[ret], OPLUS_CHG_DEBUG_MSG_LEN - ret, "type@@0x%x", oplus_chg_debug_info.notify_type); @@ -884,27 +773,12 @@ static void oplus_chg_print_debug_info(struct oplus_chg_chip *chip) ret += snprintf(&oplus_chg_debug_msg[ret], OPLUS_CHG_DEBUG_MSG_LEN - ret, "%s", oplus_chg_debug_info.bcc_buf); } -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) - mutex_unlock(&oplus_chg_debug_info.dcs_info_lock); - - chg_err("[feedback] %s\n", &oplus_chg_debug_msg[sizeof(struct kernel_packet_info)]); - - if (oplus_chg_debug_info.notify_type || - oplus_chg_debug_notify_flag_is_set(OPLUS_NOTIFY_CHARGER_INFO)) { - ret = oplus_chg_pack_debug_info(chip); - if (!ret) { - oplus_chg_debug_info.retry_cnt = SEND_INFO_MAX_CNT; - queue_delayed_work(oplus_chg_debug_info.oplus_chg_debug_wq, &oplus_chg_debug_info.send_info_dwork, 0); - } - } -#else printk(KERN_ERR "%s\n", oplus_chg_debug_msg); if (ret > OPLUS_ERROR_LENGTH) printk(KERN_ERR "debug msg:%s\n", &oplus_chg_debug_msg[ret-OPLUS_ERROR_LENGTH]); if (chg_check_point_debug&OPEN_LOG_BIT) { chg_err("[debug test]%s\n", oplus_chg_debug_msg); } -#endif oplus_chg_debug_info.real_charger_type = oplus_chg_get_real_charger_type(chip); } } @@ -2725,11 +2599,6 @@ int oplus_chg_debug_info_init(struct oplus_chg_chip *chip) oplus_chg_debug_info.batt_psy = power_supply_get_by_name("battery"); oplus_chg_debug_info.oplus_chg_debug_wq = create_workqueue("oplus_chg_debug_wq"); -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) - oplus_chg_debug_info.dcs_info = (struct kernel_packet_info *)&oplus_chg_debug_msg[0]; - INIT_DELAYED_WORK(&oplus_chg_debug_info.send_info_dwork, oplus_chg_send_info_dwork); - mutex_init(&oplus_chg_debug_info.dcs_info_lock); -#endif INIT_DELAYED_WORK(&oplus_chg_debug_info.soc_load_dwork, oplus_chg_soc_load_dwork); oplus_chg_debug_info_parse_dt(chip); diff --git a/drivers/power/oplus/oplus_debug_info.h b/drivers/power/oplus/oplus_debug_info.h index 61994ad727f0..c1389a46cf4d 100755 --- a/drivers/power/oplus/oplus_debug_info.h +++ b/drivers/power/oplus/oplus_debug_info.h @@ -160,14 +160,6 @@ struct oplus_chg_debug_info { int rechg_counts;/*add for rechg counts*/ struct workqueue_struct *oplus_chg_debug_wq; -#if defined(CONFIG_OPLUS_FEATURE_FEEDBACK) || defined(CONFIG_OPLUS_FEATURE_FEEDBACK_MODULE) - struct kernel_packet_info *dcs_info; - struct mutex dcs_info_lock; -#define SEND_INFO_DELAY 3000 - struct delayed_work send_info_dwork; -#define SEND_INFO_MAX_CNT 5 - int retry_cnt; -#endif char flag_reason[32]; char type_reason[32]; char sc8547_error_reason[32]; diff --git a/drivers/scsi/ufs/ufs-mtk.c b/drivers/scsi/ufs/ufs-mtk.c index d142c7535889..edd1e96164ea 100755 --- a/drivers/scsi/ufs/ufs-mtk.c +++ b/drivers/scsi/ufs/ufs-mtk.c @@ -1951,9 +1951,6 @@ int ufs_mtk_ioctl_query(struct ufs_hba *hba, u8 lun, void __user *buf_user) switch (read_desc) { case QUERY_DESC_IDN_DEVICE: case QUERY_DESC_IDN_STRING: -#ifdef OPLUS_FEATURE_STORAGE_TOOL - case QUERY_DESC_IDN_HEALTH: -#endif break; default: goto out_einval; diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index 35d71fc1417d..e2e7be30f8e0 100755 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -18,19 +18,6 @@ source "drivers/soc/ux500/Kconfig" source "drivers/soc/versatile/Kconfig" source "drivers/soc/zte/Kconfig" -#ifdef OPLUS_FEATURE_LOWMEM_DBG -source "drivers/soc/oplus/lowmem_dbg/Kconfig" -##endif /* OPLUS_FEATURE_LOWMEM_DBG */ - -#ifdef OPLUS_FEATURE_IOMONITOR -source "drivers/soc/oplus/iomonitor/Kconfig" -#endif /*OPLUS_FEATURE_IOMONITOR*/ - -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -#Add for svelte -source "drivers/soc/oplus/svelte/Kconfig" -#endif /* OPLUS_FEATURE_MEMLEAK_DETECT */ - #ifdef OPLUS_BUG_STABILITY source "drivers/soc/oplus/system/Kconfig" #endif /* OPLUS_BUG_STABILITY */ @@ -40,18 +27,6 @@ source "drivers/soc/oplus/system/Kconfig" source "drivers/soc/oplus/device_info/Kconfig" ##endif /* OPLUS_FEATURE_TP_BASIC */ -#ifdef OPLUS_FEATURE_HEALTHINFO -source "drivers/soc/oplus/healthinfo/Kconfig" -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#ifdef OPLUS_FEATURE_MIDAS -source "drivers/soc/oplus/midas/Kconfig" -#endif - -#Add for NandSwap -source "drivers/soc/oplus/oplus_nandswap/Kconfig" -#ifdef OPLUS_FEATURE_MIDAS source "drivers/soc/oplus/oplus_als_cali_value/Kconfig" -#endif endmenu diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 5b22cc87fbc5..126022819523 100755 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -25,19 +25,6 @@ obj-$(CONFIG_ARCH_U8500) += ux500/ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ obj-$(CONFIG_ARCH_ZX) += zte/ -#ifdef OPLUS_FEATURE_LOWMEM_DBG -obj-$(CONFIG_OPLUS_FEATURE_LOWMEM_DBG) += oplus/lowmem_dbg/ -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ - -#ifdef OPLUS_FEATURE_IOMONITOR -obj-$(CONFIG_IOMONITOR) += oplus/iomonitor/ -#endif /*OPLUS_FEATURE_IOMONITOR*/ - -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -#Add for svelte -obj-$(CONFIG_SVELTE) += oplus/svelte/ -#endif /* OPLUS_FEATURE_MEMLEAK_DETECT */ - #ifdef OPLUS_BUG_STABILITY obj-y += oplus/system/ #endif /* OPLUS_BUG_STABILITY */ @@ -47,25 +34,10 @@ obj-y += oplus/system/ obj-y += oplus/device_info/ ##endif /* OPLUS_FEATURE_TP_BASIC */ -#ifdef OPLUS_FEATURE_HEALTHINFO -obj-y += oplus/healthinfo/ -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#ifdef OPLUS_FEATURE_MIDAS -obj-$(CONFIG_OPLUS_FEATURE_MIDAS) += oplus/midas/ -#endif - #ifdef OPLUS_BUG_STABILITY obj-y += oplus/oplus_custom/ #endif /* OPLUS_BUG_STABILITY */ -#Add for NandSwap -obj-$(CONFIG_NANDSWAP) += oplus/oplus_nandswap/ - -#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -obj-y += oplus/oplus_criticallog/ -#endif OPLUS_FEATURE_MODEM_MINIDUMP - # ifdef OPLUS_FEATURE_SENSOR obj-$(CONFIG_OPLUS_ALS_CALI) += oplus/oplus_als_cali_value/ # endif /* OPLUS_FEATURE_SENSOR */ diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c index 465598a828c7..71d9e67c2dea 100755 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -11,9 +11,6 @@ #include #include #include -#ifdef OPLUS_BUG_STABILITY -#include -#endif #if IS_ENABLED(CONFIG_MTK_CMDQ_MBOX_EXT) #include "cmdq-util.h" @@ -1693,11 +1690,6 @@ void cmdq_pkt_err_dump_cb(struct cmdq_cb_data data) cmdq_util_error_enable(); cmdq_util_user_err(client->chan, "Begin of Error %u", err_num); - #ifdef OPLUS_BUG_STABILITY - if (err_num < 5) { - mm_fb_display_kevent("DisplayDriverID@@508$$", MM_FB_KEY_RATELIMIT_1H, "cmdq timeout Begin of Error %u", err_num); - } - #endif cmdq_dump_core(client->chan); diff --git a/drivers/soc/oplus/healthinfo/Kconfig b/drivers/soc/oplus/healthinfo/Kconfig deleted file mode 100755 index 1bde94e8cc81..000000000000 --- a/drivers/soc/oplus/healthinfo/Kconfig +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -config OPLUS_HEALTHINFO -bool "config healthinfo" -help - define this config to init healthinfo. - -config OPLUS_HEALTHINFO_CPUFREQ_MAX -bool "config cpufreq max" -help - define this config for cpufreq max. -#endif /* OPLUS_FEATURE_HEALTHINFO */ -config OPLUS_FEATURE_AUDIO_OPT - bool "config audio opt" - default n - help - audio task schedule opt diff --git a/drivers/soc/oplus/healthinfo/Makefile b/drivers/soc/oplus/healthinfo/Makefile deleted file mode 100644 index 775e136100b6..000000000000 --- a/drivers/soc/oplus/healthinfo/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -obj-$(CONFIG_OPLUS_HEALTHINFO) += healthinfo.o -#endif /* OPLUS_FEATURE_HEALTHINFO */ diff --git a/drivers/soc/oplus/healthinfo/healthinfo.c b/drivers/soc/oplus/healthinfo/healthinfo.c deleted file mode 100755 index b6a45fcb9b55..000000000000 --- a/drivers/soc/oplus/healthinfo/healthinfo.c +++ /dev/null @@ -1,1195 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_OPLUS_MEM_MONITOR -#include -#endif -#ifdef OPLUS_FEATURE_SDCARD_INFO -#include "../../../drivers/mmc/host/sdInfo/sdinfo.h" -#endif -#include -#include -#ifdef CONFIG_PROCESS_RECLAIM_ENHANCE -#include -#endif -#include -#ifdef CONFIG_OPLUS_HEALTHINFO_CPUFREQ_MAX -#include -#endif - -#define BUFFER_SIZE_S 256 -#define BUFFER_SIZE_M 512 -#define BUFFER_SIZE_L 1024 - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern bool test_task_ux(struct task_struct *task); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -extern int sysctl_uxchain_v2; -extern u64 sysctl_mmapsem_uninterruptable_time; -#endif -#endif - -struct sched_stat_para sched_para[OHM_SCHED_TOTAL]; -static char *sched_list[OHM_TYPE_TOTAL] = { - "iowait", - "sched_latency", - "fsync", - "emmcio", - "dstate", - "sched_default_05", - "sched_default_06", - "sched_default_07", - "sched_default_08", - "sched_default_09", - "sched_default_10", - "sched_default_11", - "cur_cpu_load", - "memory_monitor", - "io_panic", - "svm_monitor", - "rlimit_monitor", - "ionwait_monitor" -}; - -/****** Action ******/ -#define MAX_OHMEVENT_PARAM 4 -#define OH_MSG_LEN 256 -static struct kobject *ohm_kobj = NULL; -static struct work_struct ohm_detect_ws; -static char *ohm_detect_env[MAX_OHMEVENT_PARAM] = { "OHMACTION=uevent", NULL }; - -static bool ohm_action_ctrl = false; -static char msg_buf[OH_MSG_LEN] = { 0 }; - -void ohm_action_trig(int type) -{ - if (!ohm_action_ctrl) { - ohm_err_deferred("ctrl off\n"); - return; - } - ohm_debug_deferred("%s trig action\n", sched_list[type]); - if (OHM_MEM_MON == type || OHM_SCHED_FSYNC == type) { - if (!ohm_kobj) { - ohm_err_deferred("kobj NULL\n"); - return; - } - sprintf(ohm_detect_env[1], "OHMTYPE=%s", sched_list[type]); - ohm_detect_env[MAX_OHMEVENT_PARAM - 2] = NULL; - ohm_detect_env[MAX_OHMEVENT_PARAM - 1] = NULL; - schedule_work(&ohm_detect_ws); - } -} - -void ohm_action_trig_with_msg(int type, char *msg) -{ - int len; - - if (!ohm_action_ctrl) { - ohm_err("ctrl off\n"); - return; - } - - if (!ohm_kobj) { - ohm_err("kobj NULL\n"); - return; - } - if (OHM_SVM_MON == type || OHM_RLIMIT_MON == type - || OHM_MEM_VMA_ALLOC_ERR == type) { - sprintf(ohm_detect_env[1], "OHMTYPE=%s", sched_list[type]); - len = snprintf(msg_buf, OH_MSG_LEN - 1, "OHMMSG=%s", msg); - msg_buf[len] = '\0'; - ohm_detect_env[MAX_OHMEVENT_PARAM - 2] = msg_buf; - ohm_detect_env[MAX_OHMEVENT_PARAM - 1] = NULL; - schedule_work(&ohm_detect_ws); - } -} - -void ohm_detect_work(struct work_struct *work) -{ - ohm_debug("Uevent Para: %s, %s\n", ohm_detect_env[0], - ohm_detect_env[1]); - kobject_uevent_env(ohm_kobj, KOBJ_CHANGE, ohm_detect_env); - ohm_debug("Uevent Done!\n"); -} - -void ohm_action_init(void) -{ - int i = 0; - - for (i = 1; i < MAX_OHMEVENT_PARAM - 2; i++) { - ohm_detect_env[i] = kzalloc(50, GFP_KERNEL); - if (!ohm_detect_env[i]) { - ohm_err("kzalloc ohm uevent param failed\n"); - goto ohm_action_init_free_memory; - } - } - - ohm_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); - if (!ohm_kobj) { - goto ohm_action_init_kobj_failed; - } - INIT_WORK(&ohm_detect_ws, ohm_detect_work); - ohm_debug("Success !\n"); - return; - -ohm_action_init_kobj_failed: - ohm_err("Ohm kobj init err\n"); -ohm_action_init_free_memory: - for (i--; i > 0; i--) { - kfree(ohm_detect_env[i]); - } - ohm_err("Failed !\n"); -} - -/****** Sched record ******/ -static inline void ohm_sched_stat_record_common(struct sched_stat_para *sched_stat, - struct sched_stat_common *stat_common, u64 delta_ms) -{ - stat_common->total_ms += delta_ms; - stat_common->total_cnt++; - - if (delta_ms > stat_common->max_ms) { - stat_common->max_ms = delta_ms; - } - if (delta_ms >= sched_stat->high_thresh_ms) { - stat_common->high_cnt++; - } else if (delta_ms >= sched_stat->low_thresh_ms) { - stat_common->low_cnt++; - } -} - -void ohm_schedstats_record(int sched_type, struct task_struct *task, - u64 delta_ms) -{ - struct sched_stat_para *sched_stat = &sched_para[sched_type]; - static DEFINE_RATELIMIT_STATE(ratelimit, 60 * HZ, 1); - - if (unlikely(!sched_stat->ctrl)) { - return; - } - - sched_stat->delta_ms = delta_ms; - ohm_sched_stat_record_common(sched_stat, &sched_stat->all, delta_ms); - - if (task_is_fg(task)) { - ohm_sched_stat_record_common(sched_stat, &sched_stat->fg, - delta_ms); - if (unlikely(delta_ms >= sched_stat->high_thresh_ms)) { - if (sched_para[sched_type].logon - && __ratelimit(&ratelimit)) { - ohm_debug_deferred - ("[%s / %s] high_cnt, delay = %llu ms\n", - sched_list[sched_type], "fg", delta_ms); - } - if (sched_para[sched_type].trig) - ohm_action_trig(sched_type); - } - } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (test_task_ux(task)) { - ohm_sched_stat_record_common(sched_stat, &sched_stat->ux, - delta_ms); - } -#endif - return; -} - -#define OHM_LIST_MAGIC 0x5a000000 -#define OHM_CTRL_MAX 32 -#define OHM_INT_MAX 20 -#define OHM_CTRL_IOWAIT BIT(OHM_SCHED_IOWAIT) -#define OHM_CTRL_SCHEDLATENCY BIT(OHM_SCHED_SCHEDLATENCY) -#define OHM_CTRL_FSYNC BIT(OHM_SCHED_FSYNC) -#define OHM_CTRL_EMMCIO BIT(OHM_SCHED_EMMCIO) -#define OHM_CTRL_DSTATE BIT(OHM_SCHED_DSTATE) -#define OHM_CTRL_SCHEDTOTAL OHM_CTRL_EMMCIO | OHM_CTRL_FSYNC | OHM_CTRL_SCHEDLATENCY | OHM_CTRL_IOWAIT | OHM_CTRL_DSTATE -#define OHM_CTRL_CPU_CUR BIT(OHM_CPU_LOAD_CUR) -#define OHM_CTRL_MEMMON BIT(OHM_MEM_MON) -#define OHM_CTRL_IOPANIC_MON BIT(OHM_IOPANIC_MON) -#define OHM_CTRL_SVM BIT(OHM_SVM_MON) -#define OHM_CTRL_RLIMIT BIT(OHM_RLIMIT_MON) -#define OHM_CTRL_IONMON BIT(OHM_ION_MON) - -/* -ohm_ctrl_list = 0x5a0fffff -ohm_logon_list = 0x5a002005 -ohm_trig_list = 0x5a002000 -*/ - -/*Default*/ -static int ohm_ctrl_list = OHM_LIST_MAGIC | OHM_CTRL_CPU_CUR | OHM_CTRL_MEMMON | OHM_CTRL_IONMON | OHM_CTRL_SCHEDTOTAL; -static int ohm_logon_list = OHM_LIST_MAGIC; -static int ohm_trig_list = OHM_LIST_MAGIC; - -bool ohm_cpu_ctrl = true; -bool ohm_cpu_logon = false; -bool ohm_cpu_trig = false; - -bool ohm_memmon_ctrl = true; -bool ohm_memmon_logon = false; -bool ohm_memmon_trig = false; - -bool ohm_iopanic_mon_ctrl = true; -bool ohm_iopanic_mon_logon = false; -bool ohm_iopanic_mon_trig = false; - -bool ohm_ionmon_ctrl = true; -bool ohm_ionmon_logon = false; -bool ohm_ionmon_trig = false; - -/****** Para Update *****/ -#define LOW_THRESH_MS_DEFAULT 100 -#define HIGH_THRESH_MS_DEFAULT 500 -/* low thresh 10~1000ms*/ -#define LOW_THRESH_MS_LOW 10 -#define LOW_THRESH_MS_HIGH 1000 -/* high thresh 100~5000ms*/ -#define HIGH_THRESH_MS_LOW 50 -#define HIGH_THRESH_MS_HIGH 5000 - -struct thresh_para { - int l_ms; - int h_ms; -}; - -struct thresh_para ohm_thresh_para[OHM_SCHED_TOTAL] = { - {LOW_THRESH_MS_DEFAULT, HIGH_THRESH_MS_DEFAULT}, - {LOW_THRESH_MS_DEFAULT, HIGH_THRESH_MS_DEFAULT}, - {LOW_THRESH_MS_DEFAULT, HIGH_THRESH_MS_DEFAULT}, - {100, 200}, - {LOW_THRESH_MS_DEFAULT, HIGH_THRESH_MS_DEFAULT}, -}; - -void ohm_para_update(void) -{ - int i; - for (i = 0; i < OHM_SCHED_TOTAL; i++) { - if (ohm_thresh_para[i].l_ms < LOW_THRESH_MS_LOW - || ohm_thresh_para[i].l_ms > LOW_THRESH_MS_HIGH - || ohm_thresh_para[i].h_ms < HIGH_THRESH_MS_LOW - || ohm_thresh_para[i].h_ms > HIGH_THRESH_MS_HIGH) { - /********** Legal Check **********/ - ohm_err - ("Para illegal: sched_type %s, l_ms %d, h_ms %d\n", - sched_list[i], ohm_thresh_para[i].l_ms, - ohm_thresh_para[i].h_ms); - ohm_thresh_para[i].l_ms = LOW_THRESH_MS_DEFAULT; - ohm_thresh_para[i].h_ms = HIGH_THRESH_MS_DEFAULT; - return; - } - sched_para[i].low_thresh_ms = ohm_thresh_para[i].l_ms; - sched_para[i].high_thresh_ms = ohm_thresh_para[i].h_ms; - } - ohm_debug("Success update ohm_para!\n"); -} - -/**** Init ****/ -void ohm_trig_init(void) -{ - int i; - ohm_memmon_trig = (ohm_trig_list & OHM_CTRL_MEMMON) ? true : false; - ohm_cpu_trig = (ohm_trig_list & OHM_CTRL_CPU_CUR) ? true : false; - ohm_iopanic_mon_trig = - (ohm_trig_list & OHM_CTRL_IOPANIC_MON) ? true : false; - ohm_ionmon_trig = (ohm_trig_list & OHM_CTRL_IONMON) ? true : false; - for (i = 0; i < OHM_SCHED_TOTAL; i++) { - sched_para[i].trig = (ohm_trig_list & BIT(i)) ? true : false; - } - return; -} - -void ohm_logon_init(void) -{ - int i; - ohm_cpu_logon = (ohm_logon_list & OHM_CTRL_CPU_CUR) ? true : false; - ohm_memmon_logon = (ohm_logon_list & OHM_CTRL_MEMMON) ? true : false; - ohm_iopanic_mon_logon = - (ohm_logon_list & OHM_CTRL_IOPANIC_MON) ? true : false; - ohm_ionmon_logon = (ohm_logon_list & OHM_CTRL_IONMON) ? true : false; - for (i = 0; i < OHM_SCHED_TOTAL; i++) { - sched_para[i].logon = (ohm_logon_list & BIT(i)) ? true : false; - } - return; -} - -void ohm_ctrl_init(void) -{ - int i; - ohm_cpu_ctrl = (ohm_ctrl_list & OHM_CTRL_CPU_CUR) ? true : false; - ohm_memmon_ctrl = (ohm_ctrl_list & OHM_CTRL_MEMMON) ? true : false; - ohm_iopanic_mon_ctrl = - (ohm_ctrl_list & OHM_CTRL_IOPANIC_MON) ? true : false; - ohm_ionmon_ctrl = (ohm_ctrl_list & OHM_CTRL_IONMON) ? true : false; - for (i = 0; i < OHM_SCHED_TOTAL; i++) { - sched_para[i].ctrl = (ohm_ctrl_list & BIT(i)) ? true : false; - } - return; -} - -static inline void _ohm_para_init(struct sched_stat_para *sched_para) -{ - sched_para->delta_ms = 0; - memset(&sched_para->all, 0, sizeof(struct sched_stat_common)); - memset(&sched_para->ux, 0, sizeof(struct sched_stat_common)); - memset(&sched_para->fg, 0, sizeof(struct sched_stat_common)); - - return; -} - -void ohm_para_init(void) -{ - int i; - for (i = 0; i < OHM_SCHED_TOTAL; i++) { - _ohm_para_init(&sched_para[i]); - sched_para[i].low_thresh_ms = 100; - sched_para[i].high_thresh_ms = 500; - } - sched_para[OHM_SCHED_EMMCIO].low_thresh_ms = 100; - sched_para[OHM_SCHED_EMMCIO].high_thresh_ms = 200; - ohm_ctrl_init(); - ohm_logon_init(); - ohm_trig_init(); - ohm_debug("origin list: ctrl 0x%08x, logon 0x%08x, trig 0x%08x\n", - (u32) ohm_ctrl_list, (u32) ohm_logon_list, - (u32) ohm_trig_list); - return; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -#define LATENCY_STRING_FORMAT(BUF, MODULE, SCHED_STAT) sprintf(BUF, \ - #MODULE"_ctrl: %s\n"#MODULE"_logon: %s\n"#MODULE"_trig: %s\n" \ - #MODULE"_delta_ms: %llu\n"#MODULE"_low_thresh_ms: %d\n"#MODULE"_high_thresh_ms: %d\n" \ - #MODULE"_max_ms: %llu\n"#MODULE"_high_cnt: %llu\n"#MODULE"_low_cnt: %llu\n" \ - #MODULE"_total_ms: %llu\n"#MODULE"_total_cnt: %llu\n" \ - #MODULE"_fg_max_ms: %llu\n"#MODULE"_fg_high_cnt: %llu\n"#MODULE"_fg_low_cnt: %llu\n" \ - #MODULE"_fg_total_ms: %llu\n"#MODULE"_fg_total_cnt: %llu\n" \ - #MODULE"_ux_max_ms: %llu\n"#MODULE"_ux_high_cnt: %llu\n"#MODULE"_ux_low_cnt: %llu\n" \ - #MODULE"_ux_total_ms: %llu\n"#MODULE"_ux_total_cnt: %llu\n" \ - #MODULE"_sysctl_uxchain_v2: %d\n"#MODULE"_sysctl_mmapsem_uninterruptable_time: %llu\n", \ - SCHED_STAT->ctrl ? "true":"false", \ - SCHED_STAT->logon ? "true":"false", \ - SCHED_STAT->trig ? "true":"false", \ - SCHED_STAT->delta_ms, \ - SCHED_STAT->low_thresh_ms, \ - SCHED_STAT->high_thresh_ms, \ - SCHED_STAT->all.max_ms, \ - SCHED_STAT->all.high_cnt, \ - SCHED_STAT->all.low_cnt, \ - SCHED_STAT->all.total_ms, \ - SCHED_STAT->all.total_cnt, \ - SCHED_STAT->fg.max_ms, \ - SCHED_STAT->fg.high_cnt, \ - SCHED_STAT->fg.low_cnt, \ - SCHED_STAT->fg.total_ms, \ - SCHED_STAT->fg.total_cnt, \ - SCHED_STAT->ux.max_ms, \ - SCHED_STAT->ux.high_cnt, \ - SCHED_STAT->ux.low_cnt, \ - SCHED_STAT->ux.total_ms, \ - SCHED_STAT->ux.total_cnt, \ - sysctl_uxchain_v2, \ - sysctl_mmapsem_uninterruptable_time) -#else -#define LATENCY_STRING_FORMAT(BUF, MODULE, SCHED_STAT) sprintf(BUF, \ - #MODULE"_ctrl: %s\n"#MODULE"_logon: %s\n"#MODULE"_trig: %s\n" \ - #MODULE"_delta_ms: %llu\n"#MODULE"_low_thresh_ms: %d\n"#MODULE"_high_thresh_ms: %d\n" \ - #MODULE"_max_ms: %llu\n"#MODULE"_high_cnt: %llu\n"#MODULE"_low_cnt: %llu\n" \ - #MODULE"_total_ms: %llu\n"#MODULE"_total_cnt: %llu\n" \ - #MODULE"_fg_max_ms: %llu\n"#MODULE"_fg_high_cnt: %llu\n"#MODULE"_fg_low_cnt: %llu\n" \ - #MODULE"_fg_total_ms: %llu\n"#MODULE"_fg_total_cnt: %llu\n" \ - #MODULE"_ux_max_ms: %llu\n"#MODULE"_ux_high_cnt: %llu\n"#MODULE"_ux_low_cnt: %llu\n" \ - #MODULE"_ux_total_ms: %llu\n"#MODULE"_ux_total_cnt: %llu\n", \ - SCHED_STAT->ctrl ? "true":"false", \ - SCHED_STAT->logon ? "true":"false", \ - SCHED_STAT->trig ? "true":"false", \ - SCHED_STAT->delta_ms, \ - SCHED_STAT->low_thresh_ms, \ - SCHED_STAT->high_thresh_ms, \ - SCHED_STAT->all.max_ms, \ - SCHED_STAT->all.high_cnt, \ - SCHED_STAT->all.low_cnt, \ - SCHED_STAT->all.total_ms, \ - SCHED_STAT->all.total_cnt, \ - SCHED_STAT->fg.max_ms, \ - SCHED_STAT->fg.high_cnt, \ - SCHED_STAT->fg.low_cnt, \ - SCHED_STAT->fg.total_ms, \ - SCHED_STAT->fg.total_cnt, \ - SCHED_STAT->ux.max_ms, \ - SCHED_STAT->ux.high_cnt, \ - SCHED_STAT->ux.low_cnt, \ - SCHED_STAT->ux.total_ms, \ - SCHED_STAT->ux.total_cnt) -#endif - -static inline ssize_t sched_data_to_user(char __user *buff, size_t count, - loff_t *off, char *format_str, int len) -{ - if (len > *off) - len -= *off; - else - len = 0; - if (copy_to_user(buff, format_str, (len < count ? len : count))) - return -EFAULT; - *off += len < count ? len : count; - - return (len < count ? len : count); -} - -static ssize_t cpu_load_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_S] = { 0 }; - int len = 0; - int load = ohm_get_cur_cpuload(ohm_cpu_ctrl); - - if (load < 0) - load = 0; - len = sprintf(page, - "cur_cpuloading: %d\n" "cur_cpu_ctrl: %s\n" - "cur_cpu_logon: %s\n" "cur_cpu_trig: %s\n", load, - (ohm_cpu_ctrl ? "true" : "false"), - (ohm_cpu_logon ? "true" : "false"), - (ohm_cpu_trig ? "true" : "false")); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_cpu_load_fops = { - .read = cpu_load_read, -}; - -static ssize_t sched_latency_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - struct sched_stat_para *sched_stat = - &sched_para[OHM_SCHED_SCHEDLATENCY]; - - len = LATENCY_STRING_FORMAT(page, sched_latency, sched_stat); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_sched_latency_fops = { - .read = sched_latency_read, -}; - -static ssize_t iowait_read(struct file *filp, char __user *buff, size_t count, - loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - struct sched_stat_para *sched_stat = &sched_para[OHM_SCHED_IOWAIT]; - - len = LATENCY_STRING_FORMAT(page, iowait, sched_stat); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_iowait_fops = { - .read = iowait_read, -}; - -static ssize_t fsync_wait_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - struct sched_stat_para *sched_stat = &sched_para[OHM_SCHED_FSYNC]; - - len = LATENCY_STRING_FORMAT(page, fsync, sched_stat); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_fsync_wait_fops = { - .read = fsync_wait_read, -}; - -int ohm_flash_type = OHM_FLASH_TYPE_UFS; -static ssize_t emmcio_read(struct file *filp, char __user *buff, size_t count, - loff_t *off) -{ - int len = 0; - char page[1024] = { 0 }; - struct sched_stat_para *sched_stat = &sched_para[OHM_SCHED_EMMCIO]; - - len = LATENCY_STRING_FORMAT(page, emmcio, sched_stat); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_emmcio_fops = { - .read = emmcio_read, -}; - -static ssize_t dstate_read(struct file *filp, char __user *buff, size_t count, - loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - struct sched_stat_para *sched_stat = &sched_para[OHM_SCHED_DSTATE]; - - len = LATENCY_STRING_FORMAT(page, dstate, sched_stat); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_dstate_fops = { - .read = dstate_read, -}; - -#ifdef CONFIG_OPLUS_MEM_MONITOR -static ssize_t alloc_wait_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[1024] = { 0 }; - int len = 0; - - len = sprintf(page, - "total_alloc_wait_h_cnt: %llu\n" - "total_alloc_wait_l_cnt: %llu\n" - "ux_alloc_wait_h_cnt: %llu\n" "ux_alloc_wait_l_cnt: %llu\n" - "ux_alloc_wait_max_ms: %llu\n" - "ux_alloc_wait_max_order: %llu\n" - "fg_alloc_wait_h_cnt: %llu\n" "fg_alloc_wait_l_cnt: %llu\n" - "total_alloc_wait_max_ms: %llu\n" - "total_alloc_wait_max_order: %llu\n" - "fg_alloc_wait_max_ms: %llu\n" - "fg_alloc_wait_max_order: %llu\n" "alloc_wait_ctrl: %s\n" - "alloc_wait_logon: %s\n" "alloc_wait_trig: %s\n", - allocwait_para.total_alloc_wait.high_cnt, - allocwait_para.total_alloc_wait.low_cnt, - allocwait_para.ux_alloc_wait.high_cnt, - allocwait_para.ux_alloc_wait.low_cnt, - allocwait_para.ux_alloc_wait.max_ms, - allocwait_para.ux_alloc_wait_max_order, - allocwait_para.fg_alloc_wait.high_cnt, - allocwait_para.fg_alloc_wait.low_cnt, - allocwait_para.total_alloc_wait.max_ms, - allocwait_para.total_alloc_wait_max_order, - allocwait_para.fg_alloc_wait.max_ms, - allocwait_para.fg_alloc_wait_max_order, - ohm_memmon_ctrl ? "true" : "false", - ohm_memmon_logon ? "true" : "false", - ohm_memmon_trig ? "true" : "false"); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_alloc_wait_fops = { - .read = alloc_wait_read, -}; - -static ssize_t ion_wait_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - - len = sprintf(page, - "total_ion_wait_h_cnt: %llu\n" - "total_ion_wait_l_cnt: %llu\n" "fg_ion_wait_h_cnt: %llu\n" - "fg_ion_wait_l_cnt: %llu\n" "ux_ion_wait_h_cnt: %llu\n" - "ux_ion_wait_l_cnt: %llu\n" "total_ion_wait_max_ms: %llu\n" - "ion_wait_ctrl: %s\n" "ion_wait_logon: %s\n" - "ion_wait_trig: %s\n", ionwait_para.total_ion_wait.high_cnt, - ionwait_para.total_ion_wait.low_cnt, - ionwait_para.fg_ion_wait.high_cnt, - ionwait_para.fg_ion_wait.low_cnt, - ionwait_para.ux_ion_wait.high_cnt, - ionwait_para.ux_ion_wait.low_cnt, - ionwait_para.total_ion_wait.max_ms, - ohm_ionmon_ctrl ? "true" : "false", - ohm_ionmon_logon ? "true" : "false", - ohm_ionmon_trig ? "true" : "false"); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_ion_wait_fops = { - .read = ion_wait_read, -}; -#endif /*CONFIG_OPLUS_MEM_MONITOR */ - -static ssize_t ohm_para_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_S] = { 0 }; - int len = 0; - - len = sprintf(page, - "action: %s\n" "ctrl: 0x%08x\n" "logon: 0x%08x\n" - "trig: 0x%08x\n", (ohm_action_ctrl ? "true" : "false"), - (u32) ohm_ctrl_list, (u32) ohm_logon_list, - (u32) ohm_trig_list); - - return sched_data_to_user(buff, count, off, page, len); -} - -static ssize_t ohm_para_write(struct file *file, const char __user *buff, - size_t len, loff_t *ppos) -{ - char write_data[32] = { 0 }; - char ctrl_list[32] = { 0 }; - int action_ctrl; - - if (len > 31) - return -EFAULT; - - if (copy_from_user(&write_data, buff, len)) { - ohm_err("write error.\n"); - return -EFAULT; - } - write_data[len] = '\0'; - if (write_data[len - 1] == '\n') { - write_data[len - 1] = '\0'; - } - - if (0 == strncmp(write_data, "ohmctrl", 7)) { - strncpy(ctrl_list, &write_data[7], OHM_INT_MAX); - ctrl_list[OHM_INT_MAX] = '\0'; - ohm_ctrl_list = (int)simple_strtol(ctrl_list, NULL, 10); - ohm_ctrl_init(); - } else if (0 == strncmp(write_data, "ohmlogon", 8)) { - strncpy(ctrl_list, &write_data[8], OHM_INT_MAX); - ctrl_list[OHM_INT_MAX] = '\0'; - ohm_logon_list = (int)simple_strtol(ctrl_list, NULL, 10); - ohm_logon_init(); - } else if (0 == strncmp(write_data, "ohmtrig", 7)) { - strncpy(ctrl_list, &write_data[7], OHM_INT_MAX); - ctrl_list[OHM_INT_MAX] = '\0'; - ohm_trig_list = (int)simple_strtol(ctrl_list, NULL, 10); - ohm_trig_init(); - } else if (0 == strncmp(write_data, "ohmparaupdate", 13)) { - ohm_para_update(); - return len; - } else if (0 == strncmp(write_data, "ohmacitonctrl", 13)) { - strncpy(ctrl_list, &write_data[13], OHM_INT_MAX); - ctrl_list[OHM_INT_MAX] = '\0'; - action_ctrl = (int)simple_strtol(ctrl_list, NULL, 10); - ohm_action_ctrl = action_ctrl != 0 ? 1 : 0; - } else { - ohm_err("input illegal\n"); - return -EFAULT; - } - ohm_debug - ("write: %s, set: %s, ctrl: 0x%08x, logon: 0x%08x, trig: 0x%08x\n", - write_data, ctrl_list, (u32) ohm_ctrl_list, (u32) ohm_logon_list, - (u32) ohm_trig_list); - return len; -} - -static const struct file_operations proc_para_fops = { - .read = ohm_para_read, - .write = ohm_para_write, -}; - -unsigned int iowait_hung_cnt; -unsigned int iowait_panic_cnt; -static ssize_t iowait_hung_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_M] = { 0 }; - int len = 0; - - len = sprintf(page, "iowait_hung_cnt: %u\n" "iowait_panic_cnt: %u\n" - "ohm_iopanic_mon_ctrl: %s\n" "ohm_iopanic_mon_logon: %s\n" - "ohm_iopanic_mon_trig: %s\n", iowait_hung_cnt, - iowait_panic_cnt, - (ohm_iopanic_mon_ctrl ? "true" : "false"), - (ohm_iopanic_mon_logon ? "true" : "false"), - (ohm_iopanic_mon_trig ? "true" : "false")); - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_iowait_hung_fops = { - .read = iowait_hung_read, -}; - -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -struct binder_proc_status system_server_proc_status; -static ssize_t ss_binder_proc_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[1024] = { 0 }; - int len = 0; - - len = sprintf(page, - "async_mem_over_high: %llu\nasync_mem_over_low: %llu\nsync_mem_over_high: %llu\nsync_mem_over_low: %llu\nwarning_cg_bg: %llu\nwarning: %llu\n", - system_server_proc_status.async_mem_over_high, - system_server_proc_status.async_mem_over_low, - system_server_proc_status.sync_mem_over_high, - system_server_proc_status.sync_mem_over_low, - system_server_proc_status.warning_cg_bg, - system_server_proc_status.warning); - - if (len > *off) { - len -= *off; - } else { - len = 0; - } - if (copy_to_user(buff, page, (len < count ? len : count))) { - return -EFAULT; - } - *off += len < count ? len : count; - - return (len < count ? len : count); -} - -static const struct file_operations proc_ss_fops = { - .read = ss_binder_proc_read, -}; -#endif - -/****** cpu info show ******/ -extern unsigned int cpufreq_quick_get_max(unsigned int cpu); -static ssize_t cpu_info_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[BUFFER_SIZE_L] = { 0 }; - int len = 0; - unsigned int cpu; - unsigned long scale_capacity = 0, last_capacity = 0; - - for_each_possible_cpu(cpu) { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) - scale_capacity = arch_scale_cpu_capacity(NULL, cpu); -#else - scale_capacity = arch_scale_cpu_capacity(cpu); -#endif - if (scale_capacity == last_capacity) { - continue; - } - last_capacity = scale_capacity; - len += - snprintf(page + len, sizeof(page) - len, "%u ", - cpufreq_quick_get_max(cpu)); - } - - return sched_data_to_user(buff, count, off, page, len); -} - -static const struct file_operations proc_cpu_info_fops = { - .read = cpu_info_read, -}; -struct oplus_binder_proc_status system_server_proc; -static ssize_t sched_assist_ss_binder_proc_read(struct file *filp, - char __user *buff, - size_t count, loff_t *off) -{ - char page[1024] = { 0 }; - int len = 0; - - len = sprintf(page, - "in_all: %d\nin_tt: %d\nin_pt: %d\nfg_in_all: %d\nfg_in_tt: %d\nfg_in_pt: %d\nbg_in_all: %d\nbg_in_tt: %d\nbg_in_pt: %d\nwarning: %d\n", - system_server_proc.trans2proc[TYPE_ALL][IN_ALL], - system_server_proc. - trans2proc[TYPE_ALL][IN_THREAD_TODO_LIST], - system_server_proc.trans2proc[TYPE_ALL][IN_PROC_TODO_LIST], - system_server_proc.trans2proc[TYPE_TOPAPP][IN_ALL], - system_server_proc. - trans2proc[TYPE_TOPAPP][IN_THREAD_TODO_LIST], - system_server_proc. - trans2proc[TYPE_TOPAPP][IN_PROC_TODO_LIST], - system_server_proc.trans2proc[TYPE_UNTOPAPP][IN_ALL], - system_server_proc.warning_cg_bg, - system_server_proc.warning_cg_fg, - system_server_proc.warning); - - if (len > *off) { - len -= *off; - } else { - len = 0; - } - if (copy_to_user(buff, page, (len < count ? len : count))) { - return -EFAULT; - } - *off += len < count ? len : count; - - return (len < count ? len : count); -} - -static const struct file_operations proc_ssproc_fops = { - .read = sched_assist_ss_binder_proc_read, -}; - -#ifdef CONFIG_OPLUS_HEALTHINFO_CPUFREQ_MAX -static ssize_t cpufreq_max_read(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - char page[1024] = { 0 }; - int len = 0; - struct cpufreq_policy *policy; - struct list_head *head = get_cpufreq_policy_list(); - - if (!head) - return -EINVAL; - - list_for_each_entry(policy, head, policy_list) - len += - sprintf(page + len, "policy%u: %u\n", policy->cpu, - policy->cpuinfo.max_freq); - - if (len > *off) { - len -= *off; - } else { - len = 0; - } - if (copy_to_user(buff, page, (len < count ? len : count))) { - return -EFAULT; - } - *off += len < count ? len : count; - return (len < count ? len : count); -} - -static const struct file_operations proc_cpufreq_max_fops = { - .read = cpufreq_max_read, -}; -#endif - -static ssize_t ohm_thresh_read_common(struct file *filp, char __user *buff, - size_t count, loff_t *off, int type) -{ - char page[BUFFER_SIZE_S] = { 0 }; - int len = 0; - - len = sprintf(page, " %s_thresh:\n h_ms = %dms,l_ms = %dms\n", - sched_list[type], ohm_thresh_para[type].h_ms, - ohm_thresh_para[type].l_ms); - - return sched_data_to_user(buff, count, off, page, len); -} - -static ssize_t ohm_thresh_read_iowait(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - return ohm_thresh_read_common(filp, buff, count, off, OHM_SCHED_IOWAIT); -} - -static ssize_t ohm_thresh_read_sched_latency(struct file *filp, - char __user *buff, size_t count, - loff_t *off) -{ - return ohm_thresh_read_common(filp, buff, count, off, - OHM_SCHED_SCHEDLATENCY); -} - -static ssize_t ohm_thresh_read_fsync(struct file *filp, char __user *buff, - size_t count, loff_t *off) -{ - return ohm_thresh_read_common(filp, buff, count, off, OHM_SCHED_FSYNC); -} - -static ssize_t ohm_thresh_write_common(struct file *file, - const char __user *buff, size_t len, - loff_t *ppos, int type) -{ - char write_data[32] = { 0 }; - char thresh_list[32] = { 0 }; - int thresh = 0; - - if (len > 31) - return -EFAULT; - - if (copy_from_user(&write_data, buff, len)) { - ohm_err("write error.\n"); - return -EFAULT; - } - write_data[len] = '\0'; - if (write_data[len - 1] == '\n') - write_data[len - 1] = '\0'; - if (strncmp(write_data, "highthresh", 10) == 0) { - strncpy(thresh_list, &write_data[9], OHM_INT_MAX); - thresh_list[OHM_INT_MAX] = '\0'; - thresh = (int)simple_strtol(thresh_list, NULL, 10); - if (thresh < 0 || thresh < ohm_thresh_para[type].l_ms) - goto input_err; - ohm_thresh_para[type].h_ms = thresh; - } else if (strncmp(write_data, "lowthresh", 9) == 0) { - strncpy(thresh_list, &write_data[9], OHM_INT_MAX); - thresh_list[OHM_INT_MAX] = '\0'; - thresh = (int)simple_strtol(thresh_list, NULL, 10); - if (thresh < 0 || thresh > ohm_thresh_para[type].h_ms) - goto input_err; - ohm_thresh_para[type].l_ms = thresh; - } else { - goto input_err; - } - - ohm_debug("thresh update success!Now %s h_ms= %dms,l_ms= %dms\n", - sched_list[type], ohm_thresh_para[type].h_ms, - ohm_thresh_para[type].l_ms); - return len; - -input_err: - ohm_err("input illegal\n"); - return -EFAULT; -} - -static ssize_t ohm_thresh_write_iowait(struct file *file, - const char __user *buff, size_t len, - loff_t *ppos) -{ - return ohm_thresh_write_common(file, buff, len, ppos, OHM_SCHED_IOWAIT); -} - -static ssize_t ohm_thresh_write_sched_latency(struct file *file, - const char __user *buff, - size_t len, loff_t *ppos) -{ - return ohm_thresh_write_common(file, buff, len, ppos, - OHM_SCHED_SCHEDLATENCY); -} - -static ssize_t ohm_thresh_write_fsync(struct file *file, - const char __user *buff, size_t len, - loff_t *ppos) -{ - return ohm_thresh_write_common(file, buff, len, ppos, OHM_SCHED_FSYNC); -} - -static const struct file_operations proc_iowait_thresh_fops = { - .read = ohm_thresh_read_iowait, - .write = ohm_thresh_write_iowait, -}; - -static const struct file_operations proc_sched_latency_thresh_fops = { - .read = ohm_thresh_read_sched_latency, - .write = ohm_thresh_write_sched_latency, -}; - -static const struct file_operations proc_fsync_thresh_fops = { - .read = ohm_thresh_read_fsync, - .write = ohm_thresh_write_fsync, -}; - -#ifdef OPLUS_FEATURE_SDCARD_INFO -static ssize_t sdinfo_read(struct file *filp, char __user *buff, size_t count, - loff_t *off) -{ - char page[1024] = { 0 }; - int len = 0; - - len += sprintf(&page[len], "manfid: %d\ncsd_version: %d\ncapacity: %d\n" - "supported_bus_mode: %d\nsd_bus_speed: %d\ntaac_ns: %d\n" - "taac_clks: %d\nr2w_factor: %d\nruntime_resume_error_count: %d\n" - "cmd_timeout_count: %d\ncmd_crc_err_count: %d\ndata_timeout_int_count: %d\n" - "data_crc_err_count: %d\ndata_timeout_count: %d\nvold_timeout_count: %d\n", - sdinfo.manfid, sdinfo.csd_version, sdinfo.capacity, - sdinfo.supported_bus_mode, sdinfo.sd_bus_speed, - sdinfo.taac_ns, sdinfo.taac_clks, sdinfo.r2w_factor, - sdinfo.runtime_resume_error_count, - sdinfo.cmd_timeout_count, sdinfo.cmd_crc_err_count, - sdinfo.data_timeout_int_count, sdinfo.data_crc_err_count, - sdinfo.data_timeout_count, sdinfo.vold_timeout_count); - - if (len > *off) { - len -= *off; - } else { - len = 0; - } - if (copy_to_user(buff, page, (len < count ? len : count))) { - return -EFAULT; - } - *off += len < count ? len : count; - return (len < count ? len : count); -} - -static const struct file_operations proc_sdinfo_fops = { - .read = sdinfo_read, -}; -#endif - -#define HEALTHINFO_PROC_NODE "oplus_healthinfo" -static struct proc_dir_entry *healthinfo = NULL; -static struct proc_dir_entry *sched_thresh = NULL; - -#ifdef CONFIG_KMALLOC_DEBUG -/* operations of vmalloc_debug and kmalloc_debug */ -extern int __weak create_kmalloc_debug(struct proc_dir_entry *parent); -#endif -#ifdef CONFIG_VMALLOC_DEBUG -extern int __weak create_vmalloc_debug(struct proc_dir_entry *parent); -#endif -#ifdef CONFIG_VIRTUAL_RESERVE_MEMORY -int create_reserved_area_enable_proc(struct proc_dir_entry *parent); -#endif -#if IS_BUILTIN(CONFIG_HYBRIDSWAP_SWAPD) -extern int create_swappiness_para_proc(void); -#endif -static int __init healthinfo_init(void) -{ - int ret = 0; - struct proc_dir_entry *pentry; - - ohm_para_init(); - ohm_action_init(); - healthinfo = proc_mkdir(HEALTHINFO_PROC_NODE, NULL); - if (!healthinfo) { - ohm_err("can't create healthinfo proc\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("para_update", S_IRUGO | S_IWUGO, healthinfo, - &proc_para_fops); - if (!pentry) { - ohm_err("create para_update proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("fsync_wait", S_IRUGO, healthinfo, - &proc_fsync_wait_fops); - if (!pentry) { - ohm_err("create fsync_wait proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - pentry = proc_create("systemserver", S_IRUGO, healthinfo, &proc_ss_fops); - if (!pentry) { - ohm_err("create ss_status proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#endif - pentry = proc_create("cpu_loading", S_IRUGO, healthinfo, - &proc_cpu_load_fops); - if (!pentry) { - ohm_err("create cpu_loading proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("iowait", S_IRUGO, healthinfo, &proc_iowait_fops); - if (!pentry) { - ohm_err("create iowait proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("sched_latency", S_IRUGO, healthinfo, - &proc_sched_latency_fops); - if (!pentry) { - ohm_err("create sched_latency proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("emcdrv_iowait", S_IRUGO, healthinfo, - &proc_emmcio_fops); - if (!pentry) { - ohm_err("create emmc_driver_io_wait proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("dstate", S_IRUGO, healthinfo, &proc_dstate_fops); - if (!pentry) { - ohm_err("create dstate proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("iowait_hung", S_IRUGO, healthinfo, - &proc_iowait_hung_fops); - if (!pentry) { - ohm_err("create iowait_hung proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("ss_status", S_IRUGO, healthinfo, &proc_ssproc_fops); - if (!pentry) { - ohm_err("create ss_status proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#ifdef CONFIG_OPLUS_MEM_MONITOR - pentry = proc_create("alloc_wait", S_IRUGO, healthinfo, - &proc_alloc_wait_fops); - if (!pentry) { - ohm_err("create alloc_wait proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("ion_wait", S_IRUGO, healthinfo, &proc_ion_wait_fops); - if (!pentry) { - ohm_err("create ion_wait proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#endif /*CONFIG_OPLUS_MEM_MONITOR */ - pentry = proc_create("cpu_info", S_IRUGO, healthinfo, &proc_cpu_info_fops); - if (!pentry) { - ohm_err("create cpu info proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#ifdef CONFIG_OPLUS_HEALTHINFO_CPUFREQ_MAX - pentry = proc_create("cpufreq_max", S_IRUGO, healthinfo, &proc_cpufreq_max_fops); - if (!pentry) { - ohm_err("create cpufreq_max proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#endif -#ifdef OPLUS_FEATURE_SDCARD_INFO - pentry = proc_create("sd_info", S_IRUGO, healthinfo, &proc_sdinfo_fops); - if (!pentry) { - ohm_err("create sd_info proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#endif -#ifdef CONFIG_VIRTUAL_RESERVE_MEMORY - ret = create_reserved_area_enable_proc(healthinfo); - if (ret) - goto ERROR_INIT_VERSION; -#endif -#ifdef CONFIG_PROCESS_RECLAIM_ENHANCE - ret = create_process_reclaim_enable_proc(healthinfo); - if (ret) - goto ERROR_INIT_VERSION; -#endif - sched_thresh = proc_mkdir("sched_thresh", healthinfo); - if (!healthinfo) { - ohm_err("can't create healthinfo proc\n"); - goto ERROR_INIT_VERSION; - } - pentry = - proc_create("iowait_thresh", S_IRUGO | S_IWUGO, sched_thresh, - &proc_iowait_thresh_fops); - if (!pentry) { - ohm_err("create iowait_thresh proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("sched_latency_thresh", S_IRUGO | S_IWUGO, sched_thresh, - &proc_sched_latency_thresh_fops); - if (!pentry) { - ohm_err("create sched_latency_thresh proc failed.\n"); - goto ERROR_INIT_VERSION; - } - pentry = proc_create("fsync_thresh", S_IRUGO | S_IWUGO, sched_thresh, - &proc_fsync_thresh_fops); - if (!pentry) { - ohm_err("create fsync_thresh proc failed.\n"); - goto ERROR_INIT_VERSION; - } -#ifdef CONFIG_VMALLOC_DEBUG - ret = create_vmalloc_debug(healthinfo); - if (ret) - goto ERROR_INIT_VERSION; -#endif -#ifdef CONFIG_KMALLOC_DEBUG - ret = create_kmalloc_debug(healthinfo); - if (ret) - goto ERROR_INIT_VERSION; -#endif -#if IS_BUILTIN(CONFIG_HYBRIDSWAP_SWAPD) - ret = create_swappiness_para_proc(); - if (ret) - goto ERROR_INIT_VERSION; -#endif - ohm_debug("Success \n"); - return ret; - -ERROR_INIT_VERSION: - remove_proc_entry(HEALTHINFO_PROC_NODE, NULL); - return -ENOENT; -} - -module_init(healthinfo_init); - -module_param_named(ohm_action_ctrl, ohm_action_ctrl, bool, S_IRUGO | S_IWUSR); - -MODULE_DESCRIPTION("healthinfo monitor"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/healthinfo/healthinfo.h b/drivers/soc/oplus/healthinfo/healthinfo.h deleted file mode 100644 index 2740faa49216..000000000000 --- a/drivers/soc/oplus/healthinfo/healthinfo.h +++ /dev/null @@ -1,138 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _HEALTHINFO_H_ -#define _HEALTHINFO_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ohm_err(fmt, ...) \ - printk(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug(fmt, ...) \ - printk(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug_deferred(fmt, ...) \ - printk_deferred(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_err_deferred(fmt, ...) \ - printk_deferred(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -#define OHM_FLASH_TYPE_EMC 1 -#define OHM_FLASH_TYPE_UFS 2 -#define SA_CGROUP_FOREGROUND (2) -#define SA_CGROUP_BACKGROUND (3) -#define OHM_SCHED_TYPE_MAX 12 - -enum { - TYPE_TOPAPP, - TYPE_UNTOPAPP, - TYPE_ALL, - TYPE_DEFAULT, -}; -enum { - IN_THREAD_TODO_LIST, - IN_PROC_TODO_LIST, - IN_ALL, - IN_DEFAULT, -}; - -struct oplus_binder_proc_status{ - bool ctrl; - int warning; - int warning_cg_bg; - int warning_cg_fg; - int trans2proc[TYPE_DEFAULT][IN_DEFAULT]; - char comm[TASK_COMM_LEN]; -}; - -enum { - /* SCHED_STATS 0 -11 */ - OHM_SCHED_IOWAIT = 0, - OHM_SCHED_SCHEDLATENCY, - OHM_SCHED_FSYNC, - OHM_SCHED_EMMCIO, - OHM_SCHED_DSTATE, - OHM_SCHED_TOTAL, - /* OTHER_TYPE 12 - */ - OHM_CPU_LOAD_CUR = OHM_SCHED_TYPE_MAX, - OHM_MEM_MON, - OHM_IOPANIC_MON, - OHM_SVM_MON, - OHM_RLIMIT_MON, - OHM_ION_MON, - OHM_MEM_VMA_ALLOC_ERR, - OHM_TYPE_TOTAL -}; - -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -struct ob_struct{ - struct binder_proc *ob_proc; - struct list_head ob_list; - pid_t pid; - u64 ob_check_ts; - bool init; -}; - -struct binder_proc_status{ - u64 warning; - u64 warning_cg_bg; - u64 async_mem_over_high; - u64 async_mem_over_low; - u64 sync_mem_over_high; - u64 sync_mem_over_low; -}; -#endif - -struct sched_stat_common { - u64 max_ms; - u64 high_cnt; - u64 low_cnt; - u64 total_ms; - u64 total_cnt; -}; - -struct sched_stat_para { - bool ctrl; - bool logon; - bool trig; - int low_thresh_ms; - int high_thresh_ms; - u64 delta_ms; - struct sched_stat_common all; - struct sched_stat_common fg; - struct sched_stat_common ux; -}; - -struct alloc_wait_para { - u64 total_alloc_wait_max_order; - u64 fg_alloc_wait_max_order; - u64 ux_alloc_wait_max_order; - struct sched_stat_common total_alloc_wait; - struct sched_stat_common fg_alloc_wait; - struct sched_stat_common ux_alloc_wait; -}; - -struct ion_wait_para { - struct sched_stat_common ux_ion_wait; - struct sched_stat_common fg_ion_wait; - struct sched_stat_common total_ion_wait; -}; - -extern void ohm_schedstats_record(int sched_type, struct task_struct *task, u64 delta_ms); -extern int ohm_get_cur_cpuload(bool ctrl); -extern void ohm_action_trig_with_msg(int type, char *msg); -extern struct oplus_binder_proc_status system_server_proc; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -extern struct binder_proc_status system_server_proc_status; -#endif -#endif /* _HEALTHINFO_H_*/ - diff --git a/drivers/soc/oplus/iomonitor/Kconfig b/drivers/soc/oplus/iomonitor/Kconfig deleted file mode 100755 index 6217d217864b..000000000000 --- a/drivers/soc/oplus/iomonitor/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ifdef OPLUS_FEATURE_IOMONITOR -config IOMONITOR - bool "Iomonitor module" - help - define this config to init iomonitor. - -config IOMONITOR_WITH_F2FS - bool "Filesystem is f2fs" - depends on IOMONITOR - help - define this config to support both f2fs and ext4 -#endif /*OPLUS_FEATURE_IOMONITOR*/ diff --git a/drivers/soc/oplus/iomonitor/Makefile b/drivers/soc/oplus/iomonitor/Makefile deleted file mode 100755 index 6b861c1a3117..000000000000 --- a/drivers/soc/oplus/iomonitor/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ifdef OPLUS_FEATURE_IOMONITOR -obj-$(CONFIG_IOMONITOR) += console.o -obj-$(CONFIG_IOMONITOR) += iomonitor.o -obj-$(CONFIG_IOMONITOR) += iotrace.o -obj-$(CONFIG_IOMONITOR) += uid_status.o -#endif /*OPLUS_FEATURE_IOMONITOR*/ diff --git a/drivers/soc/oplus/iomonitor/console.c b/drivers/soc/oplus/iomonitor/console.c deleted file mode 100755 index de4aaffda556..000000000000 --- a/drivers/soc/oplus/iomonitor/console.c +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include -#include -#include -#include -#include -#include -#include -#include - -struct console_data { - unsigned int len; - unsigned int size:31; - unsigned int overflow:1; - char buf[0]; -}; - -#define MEMFP (sizeof(struct console_data)) - -static unsigned int size = PAGE_SIZE * 2 - MEMFP; -module_param(size, uint, 0400); -MODULE_PARM_DESC(size, "size of log buffer to dump recent kernel log"); -static struct console_data *ocd; -static void console_write(struct console *con, const char *s, unsigned n) -{ - unsigned len, pos; - - pos = ocd->len % ocd->size; - ocd->len += n; - if (!ocd->overflow && ocd->len > ocd->size) - ocd->overflow = 1; - if (unlikely(n > ocd->size)) { - s += n - ocd->size; - pos = (pos + n) % ocd->size; - n = ocd->size; - } - len = ocd->size - pos; - if (n > len) { - memcpy(ocd->buf + pos, s, len); - n -= len; - memcpy(ocd->buf, s + len, n); - } else { - memcpy(ocd->buf + pos, s, n); - } -} - -static struct console console_dev = { - .name = "con", - .write = console_write, - .flags = CON_PRINTBUFFER | CON_ENABLED, - .index = -1, -}; - -/** - * dump_log() -- dump the recent log to buffer - * @buf - buffer to save the kernel log - * @len - size of the buffer - * return the size of log dumped - */ -unsigned dump_log(char *buf, unsigned len) -{ - unsigned n, i; - - if (!ocd) - return 0; - n = ocd->overflow ? ocd->size : ocd->len; - if (unlikely(len > n)) - len = n; - i = (ocd->len - len) % ocd->size; - n = ocd->size - i; - if (n > len) { - memcpy(buf, ocd->buf + i, len); - } else { - memcpy(buf, ocd->buf + i, n); - memcpy(buf, ocd->buf, len - n); - } - return len; -} -EXPORT_SYMBOL(dump_log); - -/* #define DEBUG */ -#ifdef DEBUG -/* /proc/con_dump */ -#define CON_DUMP "con_dump" -static void *con_dump_start(struct seq_file *seq, loff_t *pos) -{ - if (*pos < 0 || *pos >= ocd->len) - return NULL; - if (*pos == 0 && ocd->overflow) - *pos = ocd->len - ocd->size; - return pos; -} - -static void *con_dump_next(struct seq_file *seq, void *v, loff_t *pos) -{ - ++*pos; - if (*pos < 0 || *pos >= ocd->len) - return NULL; - - return pos; -} - -static int con_dump_show(struct seq_file *seq, void *v) -{ - unsigned idx = (*(loff_t *) v) % ocd->size; - - seq_putc(seq, ocd->buf[idx]); - return 0; -} - -static void con_dump_stop(struct seq_file *seq, void *v) -{ -} - -const struct seq_operations con_dump_ops = { - .start = con_dump_start, - .next = con_dump_next, - .stop = con_dump_stop, - .show = con_dump_show, -}; -#endif - -static int __init oplus_console_init(void) -{ - ocd = kvmalloc(MEMFP + size, GFP_KERNEL); - if (!ocd) { - pr_err("fail to allocate memory\n"); - return -ENOMEM; - } - ocd->size = size; - ocd->overflow = 0; - ocd->len = 0; - register_console(&console_dev); -#ifdef DEBUG - proc_create_seq(CON_DUMP, S_IRUGO, NULL, &con_dump_ops); -#endif - return 0; -} - -void oplus_console_exit(void) -{ -#ifdef DEBUG - remove_proc_entry(CON_DUMP, NULL); -#endif - unregister_console(&console_dev); - kvfree(ocd); -} - -module_init(oplus_console_init); -module_exit(oplus_console_exit); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Console driver"); diff --git a/drivers/soc/oplus/iomonitor/include/iomonitor.h b/drivers/soc/oplus/iomonitor/include/iomonitor.h deleted file mode 100755 index 11557dd8cd4d..000000000000 --- a/drivers/soc/oplus/iomonitor/include/iomonitor.h +++ /dev/null @@ -1,263 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _IOMONITOR_H_ -#define _IOMONITOR_H_ - -/* Add for calculate free memory. */ -#include -#include - -/* Add for calculate free disk with f2fs. */ -#include -#include - -/* Add for statistical IO time-consuming distribution. */ -#include -#include -#include - -/* - * io monitor entry type - * NUM_ENTRY_TYPE: int value - * STR_ENTRY_TYPE: str value - * STR_FREE_ENTRY_TYPE: str value, need free string mem - */ -#define NUM_ENTRY_TYPE 0 -#define STR_ENTRY_TYPE 1 -#define STR_FREE_ENTRY_TYPE 2 -#define PRIVATE_ENTRY_TYPE 3 -#define IO_WAIT_TIMEOUT 500 -#define UX_IO_WAIT_TIMEOUT 300 -#define IO_WAIT_LOW 200 -#define IO_WAIT_HIGH 500 -enum { - IO_MONITOR_DELAY_SYNC = 0, - IO_MONITOR_DELAY_NSYNC, - IO_MONITOR_DELAY_BLOCK_NUM, -}; - -struct block_delay_data { - /* sync = 0, nsync = 1 */ - u64 stage_one[2]; - u64 stage_two[2]; - u64 stage_thr[2]; - u64 stage_fou[2]; - u64 stage_fiv[2]; - u64 stage_six[2]; - u64 stage_sev[2]; - u64 stage_eig[2]; - u64 stage_nin[2]; - u64 stage_ten[2]; - u64 max_delay[2]; - u64 cnt[2]; - u64 total_delay[2]; -}; - -enum { - IO_MONITOR_DELAY_READ = 0, - IO_MONITOR_DELAY_WRITE, - IO_MONITOR_DELAY_OPTION_NUM, -}; - -enum { - IO_MONITOR_DELAY_4K = 0, - IO_MONITOR_DELAY_512K, - IO_MONITOR_DELAY_DEVICE_NUM, -}; - -struct device_delay_data { - /* read = 0, write = 1 */ - u64 stage_one[2]; - u64 stage_two[2]; - u64 stage_thr[2]; - u64 stage_fou[2]; - u64 stage_fiv[2]; - u64 max_delay[2]; - u64 cnt[2]; - u64 total_delay[2]; -}; - -struct block_delay_data_ux { - u64 stage_one; - u64 stage_two; - u64 stage_thr; - u64 stage_fou; - u64 stage_fiv; - u64 stage_six; - u64 stage_sev; - u64 stage_eig; - u64 stage_nin; - u64 stage_ten; - u64 max_delay; - u64 cnt; - u64 total_delay; -}; - -struct req_delay_data { - struct block_delay_data_ux uxreq_block_para; - struct block_delay_data req_block_para; - /* 4K = 0, 512K = 1 */ - struct device_delay_data req_device_para[2]; -}; - -struct cal_data_info { - u64 user_read_data; - u64 user_write_data; - u64 kernel_read_data; - u64 kernel_write_data; - u64 dio_write_data; -}; - -struct cal_page_info { - u64 page_in; - u64 page_out; -}; - -struct fs_status_info { - atomic64_t major_fpage; - atomic64_t nfsync; - u64 discard; - u64 gc; - u64 task_rw_data; - u64 low_iowait; - u64 high_iowait; - atomic64_t dirty_page; -}; - -struct iowait_info { - u64 iowait_total_ms; - u64 iowait_total_count; - u64 iowait_1ms; - u64 iowait_10ms; - u64 iowait_20ms; - u64 iowait_60ms; - u64 iowait_100ms; - u64 iowait_200ms; - u64 iowait_300ms; - u64 iowait_400ms; - u64 iowait_500ms; - u64 iowait_600ms; - u64 iowait_800ms; - u64 iowait_1000ms; - u64 iowait_1500ms; - u64 iowait_2000ms; - u64 iowait_above2000ms; -}; - -struct abnormal_info { - int reason; - pid_t pid; - int delay; -}; - -enum iomointor_io_type { - IO_WAIT, - UX_IO_WAIT, - FRAME_DROP, - USER_TRIGGER -}; - -enum daily_data_type { - USER_READ, - USER_WRITE, - KERNEL_READ, - KERNEL_WRITE, - DIO_WRITE -}; - -enum rt_record_type { - RECORD_INIT, - RECORD_STOP, - RECORD_START, - RECORD_SIZE -}; - -/* monitor fs event like gc, discard, fsync*/ -enum fs_event_type { - FS_GC_OPT, - FS_DISCARD_OPT, - FS_FSYNC, - FS_MAJOR_FAULT, - FS_DIRTY_PAGES, -}; - -extern void iomonitor_update_rw_stats(enum daily_data_type type, - struct file *file, ssize_t ret); -extern void iomonitor_update_vm_stats(enum vm_event_item type, u64 delta); -extern void iomonitor_update_fs_stats(enum fs_event_type type, long delta); -extern void iomonitor_record_iowait(struct task_struct *tsk, u64 delta_ms); -#define PID_LENGTH 32 -#define PID_HASH_LEGNTH 199 -#define TASK_STATUS_LENGTH 4096 -#define UID_SHOW_DAILY_LIMIT (300*1024*1024) /* 300M */ -#define TASK_SHOW_DAILY_LIMIT (100*1024*1024) /* 100M */ -struct task_io_info { - pid_t pid; - pid_t tgid; - uid_t uid; - u64 read_bytes; - u64 write_bytes; - bool used; - char comm[TASK_COMM_LEN]; - unsigned long time; -}; - -struct disk_info { - unsigned int score; - unsigned int free; /* blocks */ - /* - * 4..8K |8..16K | 16..32K |32..64K | 64..128K | - * 128..256K | 256..512K | 512K..1M | 1M+ - */ - unsigned blocks[9]; -}; - -struct inter_disk_data { - unsigned int len; - char *buf; -}; - -#define IO_HISTORY_DEPTH 32 -struct io_history { - unsigned int cmd_flags; - unsigned long jiffies; -}; - -extern void iomonitor_record_io_history(const struct request *req); -extern int exit_uid_find_or_register(struct task_struct *task); -extern void free_all_uid_entry(void); - -int abnormal_handle(enum iomointor_io_type reason, pid_t pid, u64 delta_ms); - -struct proc_dir_entry *create_uid_proc(struct proc_dir_entry *parent); -struct proc_dir_entry *create_iotrace_proc(struct proc_dir_entry *parent); -/* extern void iomonitor_get_disk_info(struct super_block *sb, void *arg); */ - -void add_pid_to_list(struct task_struct *task, size_t bytes, bool opt); -static inline void iomonitor_record_task_io(struct task_struct *task, - size_t bytes, bool rw) -{ - add_pid_to_list(task, bytes, rw); -} - -static inline void iomonitor_init_reqstats(struct request *rq) -{ - rq->req_tg = ktime_get(); - rq->req_ti = ktime_set(0, 0); - rq->req_td = ktime_set(0, 0); - rq->req_tc = ktime_set(0, 0); -} - -void reqstats_record(struct request *req, unsigned nr_bytes); -static inline void iomonitor_record_reqstats(struct request *req, - unsigned int nr_bytes) -{ - req->req_tc = ktime_get(); - if (nr_bytes && req->req_tg && req->req_td && req->req_tc) - reqstats_record(req, nr_bytes); -} - -#endif /* _IOMONITOR_H_ */ diff --git a/drivers/soc/oplus/iomonitor/include/iotrace.h b/drivers/soc/oplus/iomonitor/include/iotrace.h deleted file mode 100755 index 4441b5883926..000000000000 --- a/drivers/soc/oplus/iomonitor/include/iotrace.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _IO_TRACE_H -#define _IO_TRACE_H - -#include - -DECLARE_TRACE(syscall_read_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -DECLARE_TRACE(syscall_write_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -DECLARE_TRACE(syscall_sync_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -#endif diff --git a/drivers/soc/oplus/iomonitor/iomonitor.c b/drivers/soc/oplus/iomonitor/iomonitor.c deleted file mode 100755 index e6880c2923d1..000000000000 --- a/drivers/soc/oplus/iomonitor/iomonitor.c +++ /dev/null @@ -1,1683 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../../../fs/mount.h" -#ifdef CONFIG_IOMONITOR_WITH_F2FS -#include "../../../../fs/f2fs/f2fs.h" -#endif - -#define TMP_BUF_LEN 64 -#define ABNORMAL_LOG_NAME "/data/debugging/io_abnormal.log" -#define ENTRY_END_TAG "-------STR end-----\n" - -#define DATE_STR_LEN 128 -#define IOM_REASON_LENGTH 32 - -#ifdef CONFIG_IOMONITOR_WITH_F2FS -extern block_t of2fs_seg_freefrag(struct f2fs_sb_info *sbi, - unsigned int segno, block_t *blocks, - unsigned int n); -#endif - -extern unsigned dump_log(char *buf, unsigned len); - -static LIST_HEAD(daily_list); -static LIST_HEAD(abnormal_list); -static LIST_HEAD(flow_list); - -#define MAX_IOMEVENT_PARAM 5 -#define MAX_RTEVENT_PARAM 2 -static struct kobject *iomonitor_kobj; -static char *io_monitor_env[MAX_IOMEVENT_PARAM] = { NULL }; -static char *rt_record_env[MAX_RTEVENT_PARAM] = { NULL }; -char iom_reason[IOM_REASON_LENGTH]; -char iom_pid[IOM_REASON_LENGTH]; -char iom_delay[IOM_REASON_LENGTH]; -char rt_reason[IOM_REASON_LENGTH]; - -unsigned int io_abl_interval_s = 10 * 60 * 1000; /* secs */ -unsigned int rt_record_interval_s = 30 * 1000; /* secs */ -unsigned int log_file_size = 10 * 1024 * 1024; /* LOG_FILE_SIZE */ - -static unsigned long last_abnormal_jiffies; -static unsigned long last_rt_record_jiffies; -static atomic_t abnormal_handle_ref; -static int rt_record_status; -struct proc_dir_entry *IoMonitor_dir; -struct fs_status_info fs_status; -struct iowait_info iowait_status; -struct abnormal_info io_abnormal_info = { 0, 0, 0 }; - -static void io_abnormal(struct work_struct *work); -static void realtime_record(struct work_struct *work); -void rt_record_handle(void); -static DECLARE_WAIT_QUEUE_HEAD(io_abnormal_wait); -static struct workqueue_struct *io_abnormal_queue; -static struct workqueue_struct *rt_record_queue; -static DECLARE_DELAYED_WORK(io_abnormal_work, io_abnormal); -static DECLARE_DELAYED_WORK(rt_record_work, realtime_record); - -static DEFINE_PER_CPU(struct cal_data_info, rw_data_info) = { -0, 0, 0, 0, 0}; - -static DEFINE_PER_CPU(struct cal_page_info, pgpg_info) = { -0, 0}; - -#ifdef CONFIG_IOMONITOR_WITH_F2FS -static struct disk_info disk_status; -#endif -static int task_status_init(void); - -static struct task_io_info taskio[PID_HASH_LEGNTH]; -char *task_buffer; -static int block_delay_range[][10] = { - /* unit of measurement is 'ms' */ - [IO_MONITOR_DELAY_SYNC] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256}, - [IO_MONITOR_DELAY_NSYNC] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256}, -}; - -static int device_delay_range[][5] = { - /* unit of measurement is 'ms' */ - [IO_MONITOR_DELAY_4K] = {0, 1, 10, 50, 100}, - [IO_MONITOR_DELAY_512K] = {1, 10, 50, 100, 500}, -}; - -struct req_delay_data req_para; - -/* - * descripte one item - * @name: string for this entry - * @type: see above - * @get_value: call back used to get this entry's value - * @list: list to abnormal_list or daily_list - * - * get_value in case of type == NUM_ENTRY_TYPE - * return entry's value; -1 means failed, - * @data is ignored - * - * get_value in case of type == STR_ENTRY_TYPE - * return value represent length of @data ; -1 means get_value failed - * @data point to entry buf - * - * get_value in case of type == STR_FREE_ENTRY_TYPE - * return value represent length of @data ; -1 means get_value failed - * @data point to entry buf - * need free @data after exec get_value - */ -struct io_info_entry { - char *name; - int type; - int (*get_value) (char **data); - struct list_head list; -}; - -static int abnormal_interval_seq_show(struct seq_file *seq, void *p) -{ - seq_printf(seq, "%d\n", (io_abl_interval_s / 1000)); - return 0; -} - -static ssize_t abnormal_interval_write(struct file *filp, - const char __user *ubuf, size_t cnt, - loff_t *ppos) -{ - char buf[8] = { 0 }; - ssize_t buf_size; - unsigned int v; - int ret; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t) (sizeof(buf) - 1)); - if (copy_from_user(buf, ubuf, buf_size)) - return -EFAULT; - buf[buf_size - 1] = '\0'; - - ret = kstrtouint(buf, 10, &v); - if (ret) - return ret; - - io_abl_interval_s = v * 1000; - - printk("my debug %s %d:int buf=%d\n", __func__, __LINE__, - io_abl_interval_s); - - return cnt; -} - -static int abnormal_interval_open(struct inode *inode, struct file *file) -{ - return single_open(file, abnormal_interval_seq_show, PDE_DATA(inode)); -} - -static const struct file_operations seq_abnormal_interval_fops = { - .open = abnormal_interval_open, - .read = seq_read, - .write = abnormal_interval_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static int abnormal_size_seq_show(struct seq_file *seq, void *p) -{ - seq_printf(seq, "%d\n", (log_file_size/(1024*1024))); - return 0; -} - -static ssize_t abnormal_size_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char buf[8] = { 0 }; - ssize_t buf_size; - unsigned int v; - int ret; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(buf)-1)); - if (copy_from_user(buf, ubuf, buf_size)) - return -EFAULT; - buf[buf_size-1] = '\0'; - - ret = kstrtouint(buf, 10, &v); - if (ret) - return ret; - - log_file_size = v*1024*1024; - - printk("my debug %s %d:size buf=%d\n", __func__, __LINE__, - log_file_size); - - return cnt; -} - -static int abnormal_size_open(struct inode *inode, struct file *file) -{ - return single_open(file, abnormal_size_seq_show, PDE_DATA(inode)); -} - -static const struct file_operations seq_abnormal_size_fops = { - .open = abnormal_size_open, - .read = seq_read, - .write = abnormal_size_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static inline bool is_data_fs(struct file *file) -{ - struct super_block *sb; - - sb = file->f_inode->i_sb; - if (!sb) - return false; - if ((!strncmp(sb->s_type->name, "f2fs", 4)) - || (!strncmp(sb->s_type->name, "ext4", 4))) - return true; - return false; -} - -static int rt_record_count; -static unsigned long rt_record_last_time; -#define RT_RECORD_COUNT 3 -bool iomonitor_rt_need_record(void) -{ - /*some iowait trigger during 1 sec,than record count add 1*/ - if (time_before(jiffies, rt_record_last_time + msecs_to_jiffies(1000))) - rt_record_count++; - else - rt_record_count = 0; - rt_record_last_time = jiffies; - if (rt_record_count == RT_RECORD_COUNT) - return true; - return false; -} - -void iomonitor_iowait_segment_statistics(u64 delta_ms) -{ - iowait_status.iowait_total_ms += delta_ms; - iowait_status.iowait_total_count++; - if (delta_ms <= 1) - iowait_status.iowait_1ms++; - else if (delta_ms <= 10) - iowait_status.iowait_10ms++; - else if (delta_ms <= 20) - iowait_status.iowait_20ms++; - else if (delta_ms <= 60) - iowait_status.iowait_60ms++; - else if (delta_ms <= 100) - iowait_status.iowait_100ms++; - else if (delta_ms <= 200) - iowait_status.iowait_200ms++; - else if (delta_ms <= 300) - iowait_status.iowait_300ms++; - else if (delta_ms <= 400) - iowait_status.iowait_400ms++; - else if (delta_ms <= 500) - iowait_status.iowait_500ms++; - else if (delta_ms <= 600) - iowait_status.iowait_600ms++; - else if (delta_ms <= 800) - iowait_status.iowait_800ms++; - else if (delta_ms <= 1000) - iowait_status.iowait_1000ms++; - else if (delta_ms <= 1500) - iowait_status.iowait_1500ms++; - else if (delta_ms <= 2000) - iowait_status.iowait_2000ms++; - else - iowait_status.iowait_above2000ms++; -} - -void iomonitor_update_rw_stats(enum daily_data_type type, struct file *file, - ssize_t ret) -{ - switch (type) { - case USER_READ: - if (is_data_fs(file)) - this_cpu_add(rw_data_info.user_read_data, ret); - break; - case USER_WRITE: - if (is_data_fs(file)) - this_cpu_add(rw_data_info.user_write_data, ret); - break; - case KERNEL_READ: - if (is_data_fs(file)) - this_cpu_add(rw_data_info.kernel_read_data, ret); - break; - case KERNEL_WRITE: - if (is_data_fs(file)) - this_cpu_add(rw_data_info.kernel_write_data, ret); - break; - case DIO_WRITE: - this_cpu_add(rw_data_info.dio_write_data, ret); - break; - } -} -EXPORT_SYMBOL(iomonitor_update_rw_stats); - -void iomonitor_update_vm_stats(enum vm_event_item type, u64 delta) -{ - switch (type) { - case PGPGIN: - this_cpu_add(pgpg_info.page_in, delta); - break; - case PGPGOUT: - this_cpu_add(pgpg_info.page_out, delta); - break; - default: - break; - } -} -EXPORT_SYMBOL(iomonitor_update_vm_stats); - -void iomonitor_update_fs_stats(enum fs_event_type type, long delta) -{ - switch (type) { - case FS_GC_OPT: - fs_status.gc += delta; - break; - case FS_DISCARD_OPT: - fs_status.discard += delta; - break; - case FS_FSYNC: - atomic64_add(delta, &fs_status.nfsync); - break; - case FS_MAJOR_FAULT: - atomic64_add(delta, &fs_status.major_fpage); - break; - case FS_DIRTY_PAGES: - atomic64_add(delta, &fs_status.dirty_page); - break; - default: - break; - } -} -EXPORT_SYMBOL(iomonitor_update_fs_stats); - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern bool test_task_ux(struct task_struct *task); -#endif -void iomonitor_record_iowait(struct task_struct *tsk, u64 delta_ms) -{ - if (delta_ms > IO_WAIT_HIGH) - fs_status.high_iowait++; - else if (delta_ms > IO_WAIT_LOW) { - fs_status.low_iowait++; - if (iomonitor_rt_need_record()) - rt_record_handle(); - } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - /* first decide ux iowait */ - if (test_task_ux(tsk) && delta_ms > UX_IO_WAIT_TIMEOUT) - abnormal_handle(UX_IO_WAIT, tsk->pid, delta_ms); - else if (delta_ms > IO_WAIT_TIMEOUT) - abnormal_handle(IO_WAIT, tsk->pid, delta_ms); -#else - if (delta_ms > IO_WAIT_TIMEOUT) - abnormal_handle(IO_WAIT, tsk->pid, delta_ms); -#endif - - iomonitor_iowait_segment_statistics(delta_ms); -} - -static void get_rw_bytes(u64 *uread, u64 *uwrite, u64 *kread, u64 *kwrite, - u64 *dwrite) -{ - int i; - - for_each_possible_cpu(i) { - struct cal_data_info *s_data_info = - per_cpu_ptr(&rw_data_info, i); - *uread += s_data_info->user_read_data; - *uwrite += s_data_info->user_write_data; - *kread += s_data_info->kernel_read_data; - *kwrite += s_data_info->kernel_write_data; - *dwrite += s_data_info->dio_write_data; - - s_data_info->user_read_data = 0; - s_data_info->user_write_data = 0; - s_data_info->kernel_read_data = 0; - s_data_info->kernel_write_data = 0; - s_data_info->dio_write_data = 0; - } -} - -static int fs_status_get_value(char **data) -{ - char *tmp = kzalloc(128, GFP_KERNEL); - ssize_t len; - u64 major_fpage = atomic64_read(&fs_status.major_fpage); - u64 nfsync = atomic64_read(&fs_status.nfsync); - u64 dirty_page = atomic64_read(&fs_status.dirty_page); - - len = snprintf(tmp, 128, "%llu %llu %llu %llu %llu %llu %llu %llu\n", - major_fpage, nfsync, fs_status.discard, fs_status.gc, - fs_status.task_rw_data, fs_status.high_iowait, - fs_status.low_iowait, dirty_page); - *data = tmp; - return len; -} - -struct io_info_entry fs_status_entry = { - .name = "fs_status", - .type = STR_FREE_ENTRY_TYPE, - .get_value = fs_status_get_value, - .list = LIST_HEAD_INIT(fs_status_entry.list), -}; - -extern int write_log_kernel(char **data); -struct io_info_entry io_trace_entry = { - .name = "io_trace", - .type = PRIVATE_ENTRY_TYPE, - .get_value = write_log_kernel, -}; - -static int pgpg_status_get_value(char **data) -{ - char *tmp = kzalloc(128, GFP_KERNEL); - ssize_t len; - int i; - unsigned long pgpgin = 0, pgpgout = 0; - u64 uread = 0, uwrite = 0, kread = 0, kwrite = 0, dwrite = 0; - - for_each_possible_cpu(i) { - struct cal_page_info *s_page_info = per_cpu_ptr(&pgpg_info, i); - pgpgin += s_page_info->page_in; - pgpgout += s_page_info->page_out; - s_page_info->page_in = 0; - s_page_info->page_out = 0; - } - - pgpgin /= 2; - pgpgout /= 2; - get_rw_bytes(&uread, &uwrite, &kread, &kwrite, &dwrite); - len = - snprintf(tmp, 128, "%llu %llu %llu %llu %llu %lu %lu\n", uread, - uwrite, kread, kwrite, dwrite, pgpgin, pgpgout); - *data = tmp; - return len; -} - -struct io_info_entry pgpg_status_entry = { - .name = "pgpg_status", - .type = STR_FREE_ENTRY_TYPE, - .get_value = pgpg_status_get_value, - .list = LIST_HEAD_INIT(pgpg_status_entry.list), -}; - -static int get_free_mem(char **data) -{ - char *tmp = kzalloc(64, GFP_KERNEL); - ssize_t len = -1; - unsigned long freeram, bufferram; - long cached, availableram; - /* Free memory = xxx MB. */ - freeram = global_zone_page_state(NR_FREE_PAGES); - bufferram = nr_blockdev_pages(); - cached = global_node_page_state(NR_FILE_PAGES) - - total_swapcache_pages() - bufferram; - availableram = si_mem_available(); - len = snprintf(tmp, 64, "%lu %lu %ld %ld\n", - freeram, bufferram, cached, availableram); - *data = tmp; - return len; -} - - -struct io_info_entry free_mem_entry = { - .name = "free_mem", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_free_mem -}; - -#ifdef CONFIG_IOMONITOR_WITH_F2FS -static int f2fs_get_free_disk(struct f2fs_sb_info *sbi) -{ - u64 free_size = 0; - - if (!sbi->ckpt || !sbi->sm_info) - return 0; - if (!sbi->sm_info->dcc_info) - return 0; - - free_size = (sbi->user_block_count - sbi->total_valid_block_count); - /* Free disk = xxx GB. */ - free_size >>= (20 - (int)sbi->log_blocksize); - return ((int)free_size < 0 ? 0 : (int)free_size); -} - -static void __dump_disk_info(struct inter_disk_data *disk_data) -{ - int ret = 0; - char *disk_buf; - int i; - char *p; - - disk_data->len = -1; - - disk_buf = kzalloc(512, GFP_KERNEL); - if (!disk_buf) - return; - - p = disk_buf; - ret = sprintf(p, "%d ", disk_status.score); - p = p + ret; - disk_data->len += ret; - - ret = sprintf(p, "%d ", disk_status.free); - p = p + ret; - disk_data->len += ret; - - for (i = 0; i < ARRAY_SIZE(disk_status.blocks); i++) { - if (!disk_status.blocks[i]) - continue; - if (i == ARRAY_SIZE(disk_status.blocks) - 1) { - ret = sprintf(p, "%d\n", disk_status.blocks[i]); - p = p + ret; - disk_data->len += ret; - } else { - ret = sprintf(p, "%d ", disk_status.blocks[i]); - p = p + ret; - disk_data->len += ret; - } - } - - disk_data->buf = disk_buf; - - return; -} - -static void __get_disk_info(struct super_block *sb, void *arg) -{ - unsigned int i; - bool valid_patition = false; - struct mount *mnt; - struct f2fs_sb_info *sbi; - unsigned int total_segs; - block_t total_blocks = 0; - struct inter_disk_data *disk_data = (struct inter_disk_data *)arg; - - if (disk_data->len != -1) - return; - - lock_mount_hash(); - list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { - if (strstr(mnt->mnt_devname, "userdata") - && strstr(mnt->mnt_mp->m_dentry->d_name.name, "data")) { - if (sb->s_magic == F2FS_SUPER_MAGIC) { - valid_patition = true; - break; - } - } - } - unlock_mount_hash(); - - if (valid_patition) { - sbi = F2FS_SB(sb); - total_segs = le32_to_cpu(sbi->raw_super->segment_count_main); - memset(&disk_status, 0, sizeof(struct disk_info)); - for (i = 0; i < total_segs; i++) { - total_blocks += of2fs_seg_freefrag(sbi, i, - disk_status.blocks, - ARRAY_SIZE(disk_status.blocks)); - - cond_resched(); - } - disk_status.score = - total_blocks ? (disk_status.blocks[0] + - disk_status.blocks[1]) * 100ULL / total_blocks : 0; - disk_status.free = f2fs_get_free_disk(sbi); - - __dump_disk_info(disk_data); - - } - - return; -} - -static int get_disk_info(char **data) -{ - struct inter_disk_data disk_data; - - disk_data.len = -1; - disk_data.buf = NULL; - - iterate_supers(__get_disk_info, &disk_data); - - *data = disk_data.buf; - return disk_data.len; -} - -struct io_info_entry disk_info_entry = { - .name = "disk", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_disk_info, -}; -#endif - -static int get_iowait_info(char **data) -{ - ssize_t len = -1; - char *tmp = kzalloc(512, GFP_KERNEL); - - if (!tmp) - return -1; - - len = snprintf(tmp, 512, - "%lld %lld %lld %lld %lld %lld %lld %lld " - "%lld %lld %lld %lld %lld %lld %lld %lld %lld\n", - iowait_status.iowait_total_ms, - iowait_status.iowait_total_count, - iowait_status.iowait_1ms, - iowait_status.iowait_10ms, - iowait_status.iowait_20ms, - iowait_status.iowait_60ms, - iowait_status.iowait_100ms, - iowait_status.iowait_200ms, - iowait_status.iowait_300ms, - iowait_status.iowait_400ms, - iowait_status.iowait_500ms, - iowait_status.iowait_600ms, - iowait_status.iowait_800ms, - iowait_status.iowait_1000ms, - iowait_status.iowait_1500ms, - iowait_status.iowait_2000ms, - iowait_status.iowait_above2000ms - ); - - *data = tmp; - return len; - -} - -struct io_info_entry iowait_info_entry = { - .name = "iowait", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_iowait_info, -}; - -static struct io_history io_queue_history[IO_HISTORY_DEPTH]; -static unsigned char io_queue_index; -void iomonitor_record_io_history(const struct request *rq) -{ - if (rq && rq->rq_disk && !strcmp(rq->rq_disk->disk_name, "sda")) { - io_queue_history[io_queue_index].cmd_flags = rq->cmd_flags; - io_queue_history[io_queue_index].jiffies = jiffies; - - io_queue_index++; - if (io_queue_index == 32) - io_queue_index = 0; - } -} - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -static inline bool rq_is_ux(struct request *rq) -{ - return (rq->cmd_flags & REQ_UX); -} -#endif - -void reqstats_init(void) -{ - memset(&req_para, 0, sizeof(struct req_delay_data)); - return; -} - -void reqstats_record(struct request *req, unsigned int nr_bytes) -{ - u64 tg2d = 0, td2c = 0; - int index, rw, sync; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - int isux; -#endif - if (!req) - return; - - /* BLOCK */ - tg2d = ktime_us_delta(req->req_td, req->req_tg) / 1000; - sync = rq_is_sync(req) ? 0 : 1; - index = sync; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - isux = rq_is_ux(req); - /* UX req */ - if (!sync && isux) { - req_para.uxreq_block_para.cnt++; - req_para.uxreq_block_para.total_delay += tg2d; - if (tg2d >= block_delay_range[index][9]) - req_para.uxreq_block_para.stage_ten++; - else if (tg2d >= block_delay_range[index][8]) - req_para.uxreq_block_para.stage_nin++; - else if (tg2d >= block_delay_range[index][7]) - req_para.uxreq_block_para.stage_eig++; - else if (tg2d >= block_delay_range[index][6]) - req_para.uxreq_block_para.stage_sev++; - else if (tg2d >= block_delay_range[index][5]) - req_para.uxreq_block_para.stage_six++; - else if (tg2d >= block_delay_range[index][4]) - req_para.uxreq_block_para.stage_fiv++; - else if (tg2d >= block_delay_range[index][3]) - req_para.uxreq_block_para.stage_fou++; - else if (tg2d >= block_delay_range[index][2]) - req_para.uxreq_block_para.stage_thr++; - else if (tg2d >= block_delay_range[index][1]) - req_para.uxreq_block_para.stage_two++; - else if (tg2d >= block_delay_range[index][0]) - req_para.uxreq_block_para.stage_one++; - req_para.uxreq_block_para.max_delay = - (req_para.uxreq_block_para.max_delay >= - tg2d) ? req_para.uxreq_block_para.max_delay : tg2d; - } -#endif - /* ALL req */ - req_para.req_block_para.cnt[sync]++; - req_para.req_block_para.total_delay[sync] += tg2d; - if (tg2d >= block_delay_range[index][9]) - req_para.req_block_para.stage_ten[sync]++; - else if (tg2d >= block_delay_range[index][8]) - req_para.req_block_para.stage_nin[sync]++; - else if (tg2d >= block_delay_range[index][7]) - req_para.req_block_para.stage_eig[sync]++; - else if (tg2d >= block_delay_range[index][6]) - req_para.req_block_para.stage_sev[sync]++; - else if (tg2d >= block_delay_range[index][5]) - req_para.req_block_para.stage_six[sync]++; - else if (tg2d >= block_delay_range[index][4]) - req_para.req_block_para.stage_fiv[sync]++; - else if (tg2d >= block_delay_range[index][3]) - req_para.req_block_para.stage_fou[sync]++; - else if (tg2d >= block_delay_range[index][2]) - req_para.req_block_para.stage_thr[sync]++; - else if (tg2d >= block_delay_range[index][1]) - req_para.req_block_para.stage_two[sync]++; - else if (tg2d >= block_delay_range[index][0]) - req_para.req_block_para.stage_one[sync]++; - req_para.req_block_para.max_delay[sync] = - (req_para.req_block_para.max_delay[sync] >= - tg2d) ? req_para.req_block_para.max_delay[sync] : tg2d; - - /* DEVICE */ - td2c = ktime_us_delta(req->req_tc, req->req_td) / 1000; - if (nr_bytes == 4 * 1024) - index = IO_MONITOR_DELAY_4K; - else if (nr_bytes == 512 * 1024) - index = IO_MONITOR_DELAY_512K; - else { - index = IO_MONITOR_DELAY_DEVICE_NUM; - return; - } - /* size = 512K && time < 1ms, do not record */ - if (td2c < 1 && index == IO_MONITOR_DELAY_512K) - return; - rw = rq_data_dir(req); - req_para.req_device_para[index].cnt[rw]++; - req_para.req_device_para[index].total_delay[rw] += td2c; - if (td2c >= device_delay_range[index][4]) - req_para.req_device_para[index].stage_fiv[rw]++; - else if (td2c >= device_delay_range[index][3]) - req_para.req_device_para[index].stage_fou[rw]++; - else if (td2c >= device_delay_range[index][2]) - req_para.req_device_para[index].stage_thr[rw]++; - else if (td2c >= device_delay_range[index][1]) - req_para.req_device_para[index].stage_two[rw]++; - else if (td2c >= device_delay_range[index][0]) - req_para.req_device_para[index].stage_one[rw]++; - req_para.req_device_para[index].max_delay[rw] = - (req_para.req_device_para[index].max_delay[rw] >= - td2c) ? req_para.req_device_para[index].max_delay[rw] : td2c; - - return; -} - -static int get_blk_ux_io_distribution(char **data) -{ - int ret = 0; - char *uxio_buff; - - uxio_buff = kzalloc(1024, GFP_KERNEL); - if (!uxio_buff) - return ret; - ret = snprintf(uxio_buff, 1024, - "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", - req_para.uxreq_block_para.cnt, - req_para.uxreq_block_para.total_delay, - req_para.uxreq_block_para.max_delay, - req_para.uxreq_block_para.stage_one, - req_para.uxreq_block_para.stage_two, - req_para.uxreq_block_para.stage_thr, - req_para.uxreq_block_para.stage_fou, - req_para.uxreq_block_para.stage_fiv, - req_para.uxreq_block_para.stage_six, - req_para.uxreq_block_para.stage_sev, - req_para.uxreq_block_para.stage_eig, - req_para.uxreq_block_para.stage_nin, - req_para.uxreq_block_para.stage_ten); - - *data = uxio_buff; - return ret; -} - -struct io_info_entry block_ux_io_entry = { - .name = "block_ux_io", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_blk_ux_io_distribution -}; - -static int get_blk_sync_io_distribution(char **data) -{ - int ret = 0; - char *syncio_buff; - - syncio_buff = kzalloc(1024, GFP_KERNEL); - if (!syncio_buff) - return ret; - ret = snprintf(syncio_buff, 1024, - "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", - req_para.req_block_para.cnt[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.total_delay[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.max_delay[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_one[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_two[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_thr[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_fou[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_fiv[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_six[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_sev[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_eig[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_nin[IO_MONITOR_DELAY_SYNC], - req_para.req_block_para.stage_ten[IO_MONITOR_DELAY_SYNC]); - - *data = syncio_buff; - return ret; -} - -struct io_info_entry block_sync_io_entry = { - .name = "block_sync_io", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_blk_sync_io_distribution -}; - -static int get_blk_nsync_io_distribution(char **data) -{ - int ret = 0; - char *nsyncio_buff; - - nsyncio_buff = kzalloc(1024, GFP_KERNEL); - if (!nsyncio_buff) - return ret; - ret = snprintf(nsyncio_buff, 1024, - "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", - req_para.req_block_para.cnt[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.total_delay[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.max_delay[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_one[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_two[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_thr[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_fou[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_fiv[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_six[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_sev[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_eig[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_nin[IO_MONITOR_DELAY_NSYNC], - req_para.req_block_para.stage_ten[IO_MONITOR_DELAY_NSYNC]); - - *data = nsyncio_buff; - return ret; -} - -struct io_info_entry block_nsync_io_entry = { - .name = "block_nsync_io", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_blk_nsync_io_distribution -}; - -static int get_dev_4k_rw_distribution(char **data) -{ - int ret = 0; - char *rw4k_buff; - - rw4k_buff = kzalloc(1024, GFP_KERNEL); - if (!rw4k_buff) - return ret; - ret = snprintf(rw4k_buff, 1024, - "%lld %lld %lld %lld %lld %lld %lld %lld " - "%lld %lld %lld %lld %lld %lld %lld %lld\n", - req_para.req_device_para[IO_MONITOR_DELAY_4K].cnt[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].total_delay[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].max_delay[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_one[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_two[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_thr[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_fou[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_fiv[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_4K].cnt[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].total_delay[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].max_delay[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_one[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_two[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_thr[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_fou[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_4K].stage_fiv[IO_MONITOR_DELAY_WRITE]); - - *data = rw4k_buff; - return ret; -} - -struct io_info_entry device_4k_rw_entry = { - .name = "device_4k_rw", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_dev_4k_rw_distribution -}; - -static int get_dev_512k_rw_distribution(char **data) -{ - int ret = 0; - char *rw512k_buff; - - rw512k_buff = kzalloc(1024, GFP_KERNEL); - if (!rw512k_buff) - return ret; - ret = snprintf(rw512k_buff, 1024, - "%lld %lld %lld %lld %lld %lld %lld %lld " - "%lld %lld %lld %lld %lld %lld %lld %lld\n", - req_para.req_device_para[IO_MONITOR_DELAY_512K].cnt[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].total_delay[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].max_delay[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_one[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_two[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_thr[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_fou[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_fiv[IO_MONITOR_DELAY_READ], - req_para.req_device_para[IO_MONITOR_DELAY_512K].cnt[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].total_delay[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].max_delay[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_one[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_two[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_thr[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_fou[IO_MONITOR_DELAY_WRITE], - req_para.req_device_para[IO_MONITOR_DELAY_512K].stage_fiv[IO_MONITOR_DELAY_WRITE]); - - *data = rw512k_buff; - return ret; -} - -struct io_info_entry device_512k_rw_entry = { - .name = "device_512k_rw", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_dev_512k_rw_distribution -}; - -static int get_dump_log(char **data) -{ - int ret = 0; - char *dmesg_buff; - - dmesg_buff = kzalloc(4096, GFP_KERNEL); - if (!dmesg_buff) - return ret; - ret = dump_log(dmesg_buff, 4096); - *data = dmesg_buff; - return ret; -} - -struct io_info_entry ligntweight_dmesg_entry = { - .name = "dmesg", - .type = STR_FREE_ENTRY_TYPE, - .get_value = get_dump_log -}; - -static int exit_task_notifier(struct notifier_block *self, - unsigned long cmd, void *v) -{ - struct task_struct *task = v; - - if (!task->ioac.read_bytes && !task->ioac.write_bytes) - return NOTIFY_OK; - - exit_uid_find_or_register(task); - return NOTIFY_OK; -} - -static struct notifier_block exit_task_notifier_block = { - .notifier_call = exit_task_notifier, -}; - -void add_pid_to_list(struct task_struct *task, size_t bytes, bool opt) -{ - int i = 0; - int slot = task->pid%PID_HASH_LEGNTH; - struct task_io_info *ti = NULL; - struct task_io_info *old_ti = NULL; - unsigned long min_time = jiffies; - - for (i = 0; i < PID_HASH_LEGNTH; i++) { - ti = &taskio[(slot + i) % PID_HASH_LEGNTH]; - if (ti->used) { - if (ti->pid == task->pid) { - ti->time = jiffies; - if (opt) - ti->write_bytes += bytes; - else - ti->read_bytes += bytes; - return; - } else if (time_before(ti->time, min_time)) { - min_time = ti->time; - old_ti = ti; - } - } else { - ti->pid = task->pid; - ti->tgid = task->tgid; - ti->uid = from_kuid_munged(current_user_ns(), task_uid(task)); - ti->time = jiffies; - memcpy(ti->comm, task->comm, TASK_COMM_LEN); - ti->used = true; - if (opt) - ti->write_bytes = bytes; - else - ti->read_bytes = bytes; - return; - } - } - if (!old_ti) - return; - old_ti->pid = task->pid; - old_ti->tgid = task->tgid; - old_ti->uid = from_kuid_munged(current_user_ns(), task_uid(task)); - old_ti->time = jiffies; - memcpy(old_ti->comm, task->comm, TASK_COMM_LEN); - old_ti->used = true; - if (opt) - old_ti->write_bytes = bytes; - else - old_ti->read_bytes = bytes; -} - -static int task_status_get_value(struct seq_file *m, void *v) -{ - int i; - struct task_io_info *ti = NULL; - - for (i = 0; i < PID_HASH_LEGNTH; i++) { - ti = taskio + i; - if (ti->pid) - seq_printf(m, "%d %d %d %llu %llu %s\n", - ti->pid, ti->tgid, ti->uid, ti->read_bytes, - ti->write_bytes, ti->comm); - } - return 0; -} - -static int get_task_status(char **data) -{ - int len = 0, i; - struct task_io_info *ti = NULL; - - memset(task_buffer, 0, sizeof(struct task_io_info)*PID_HASH_LEGNTH); - for (i = 0; i < PID_HASH_LEGNTH; i++) { - ti = taskio + i; - if (ti->pid) - len += snprintf(task_buffer + len, - sizeof(struct task_io_info) * PID_HASH_LEGNTH - len, - "%d %d %d %llu %llu %s\n", ti->pid, ti->tgid, - ti->uid, ti->read_bytes, ti->write_bytes, ti->comm); - } - *data = task_buffer; - return len; -} - -static inline void add_daily_entry(struct io_info_entry *entry) -{ - list_add_tail(&entry->list, &daily_list); -} - -static inline void add_monitor_entry(struct io_info_entry *entry) -{ - list_add_tail(&entry->list, &abnormal_list); -} - -static inline void add_flow_entry(struct io_info_entry *entry) -{ - list_add_tail(&entry->list, &flow_list); -} - -static int io_monitor_show(struct seq_file *m, void *v) -{ - struct list_head *p; - struct io_info_entry *entry; - int ret; - char *pbuf; - - p = daily_list.next; - while (p != &daily_list) { - entry = list_entry(p, struct io_info_entry, list); - p = p->next; - - if (entry->type == NUM_ENTRY_TYPE) { - ret = entry->get_value(NULL); - if (-1 != ret) - seq_printf(m, "%s %d\n", entry->name, ret); - } else if (entry->type == STR_ENTRY_TYPE - || entry->type == STR_FREE_ENTRY_TYPE) { - ret = entry->get_value(&pbuf); - if (-1 != ret) { - seq_printf(m, "%s %s", entry->name, pbuf); - if (entry->type == STR_FREE_ENTRY_TYPE) - kfree(pbuf); - } - } - - } - memset(&fs_status, 0, sizeof(struct fs_status_info)); - /* memset(&disk_status, 0, sizeof(struct disk_info)); */ - memset(&req_para, 0, sizeof(struct req_delay_data)); - memset(&iowait_status, 0, sizeof(struct iowait_info)); - return 0; -} - -static int iomonitor_open(struct inode *inode, struct file *file) -{ - return single_open(file, io_monitor_show, inode->i_private); -} - -static const struct file_operations proc_dailyio_operations = { - .open = iomonitor_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int iomonitor_dataflow_show(struct seq_file *m, void *v) -{ - task_status_get_value(m, v); - return 0; -} - -static int iomonitor_dataflow_open(struct inode *inode, struct file *file) -{ - return single_open(file, iomonitor_dataflow_show, inode->i_private); -} - -static ssize_t iomonitor_dataflow_write(struct file *filp, - const char __user *ubuf, size_t cnt, loff_t *ppos) -{ - char buf[8] = { 0 }; - ssize_t buf_size; - unsigned int v; - int ret; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(buf)-1)); - if (copy_from_user(buf, ubuf, buf_size)) - return -EFAULT; - buf[buf_size-1] = '\0'; - - ret = kstrtouint(buf, 10, &v); - if (ret) - return ret; - - if (v > RECORD_SIZE) - return -EINVAL; - - rt_record_status = v; - - printk("my debug %s %d:int dataflow=%d\n", __func__, __LINE__, rt_record_status); - - return cnt; -} - -static int iomonitor_dataflow_release(struct inode *inode, struct file *file) -{ - memset(taskio, 0, sizeof(struct task_io_info)*PID_HASH_LEGNTH); - return single_release(inode, file); -} - -static ssize_t trigger_abnormal_event(struct file *filp, - const char __user *ubuf, size_t cnt, - loff_t *ppos) -{ - char buf[8] = { 0 }; - ssize_t buf_size; - unsigned int v; - int ret; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(buf)-1)); - if (copy_from_user(buf, ubuf, buf_size)) - return -EFAULT; - buf[buf_size-1] = '\0'; - - ret = kstrtouint(buf, 10, &v); - if (ret) - return ret; - - switch (v) { - case 1: - abnormal_handle(USER_TRIGGER, current->pid, 0); - break; - case 2: - rt_record_handle(); - break; - default: - abnormal_handle(USER_TRIGGER, current->pid, 0); - break; - } - - return cnt; -} - -static const struct file_operations proc_dataflow_operations = { - .open = iomonitor_dataflow_open, - .read = seq_read, - .write = iomonitor_dataflow_write, - .llseek = seq_lseek, - .release = iomonitor_dataflow_release, -}; - -static int trigger_abnormal_open(struct inode *inode, struct file *file) -{ - return single_open(file, abnormal_interval_seq_show, inode->i_private); -} - -static const struct file_operations trigger_abnormal_open_operations = { - .open = trigger_abnormal_open, - .read = seq_read, - .write = trigger_abnormal_event, - .llseek = seq_lseek, - .release = single_release, -}; - -static int get_date(char *date) -{ - struct timespec64 ts; - struct rtc_time tm; - int len = 0; - - getnstimeofday64(&ts); - ts.tv_sec -= sys_tz.tz_minuteswest * 60; - rtc_time_to_tm(ts.tv_sec, &tm); - - len += snprintf(date + len, DATE_STR_LEN - len, - "%04d-%02d-%02d %02d:%02d:%02d %d %d %d\n", tm.tm_year + 1900, - tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, - tm.tm_sec, io_abnormal_info.reason, io_abnormal_info.pid, - io_abnormal_info.delay); - - return len; -} - -int write_abnormal_file(struct file *filp, struct io_info_entry *entry) -{ - char name_buf[TMP_BUF_LEN]; - int ret; - loff_t file_pos = 0; - char *pbuf = NULL; - - switch (entry->type) { - case NUM_ENTRY_TYPE: - ret = entry->get_value(NULL); - if (-1 != ret) { - memset(name_buf, 0, TMP_BUF_LEN); - snprintf(name_buf, TMP_BUF_LEN, "%d\n", ret); - kernel_write(filp, name_buf, strlen(name_buf), &file_pos); - } - break; - case STR_ENTRY_TYPE: - case STR_FREE_ENTRY_TYPE: - ret = entry->get_value(&pbuf); - if (-1 != ret) { - memset(name_buf, 0, TMP_BUF_LEN); - snprintf(name_buf, TMP_BUF_LEN, "%s %d\n", entry->name, ret); - kernel_write(filp, name_buf, strlen(name_buf), &file_pos); - kernel_write(filp, pbuf, ret, &file_pos); - kernel_write(filp, ENTRY_END_TAG, strlen(ENTRY_END_TAG), &file_pos); - - if (entry->type == STR_FREE_ENTRY_TYPE) { - if (pbuf) - kfree(pbuf); - } - } - break; - case PRIVATE_ENTRY_TYPE: - entry->get_value((char **)filp); - break; - } - return 0; -} - -static void realtime_record(struct work_struct *work) -{ - printk("[iomonitor] RT record status %d\n", rt_record_status); - if (time_before(jiffies, last_rt_record_jiffies + - msecs_to_jiffies(rt_record_interval_s))) - return; - memset(rt_record_env[0], 0, IOM_REASON_LENGTH); - snprintf(rt_record_env[0], IOM_REASON_LENGTH, - "RT_TRIGGER=%d", rt_record_status); - if (iomonitor_kobj) { - printk("[iomonitor] send RT_TRIGGER uevent\n"); - kobject_uevent_env(iomonitor_kobj, KOBJ_CHANGE, rt_record_env); - } - last_rt_record_jiffies = jiffies; -} - -static void io_abnormal(struct work_struct *work) -{ - struct list_head *p; - struct file *filp_log; - loff_t file_pos = 0; - struct io_info_entry *io_entry; - char *buffer = NULL; - char date[DATE_STR_LEN]; - int flags = O_RDWR | O_CREAT | O_APPEND; - - if (time_before(jiffies, last_abnormal_jiffies + - msecs_to_jiffies(io_abl_interval_s))) { - atomic_dec(&abnormal_handle_ref); - return; - } - - memset(date, 0, DATE_STR_LEN); - get_date(date); - memset(io_monitor_env[0], 0, IOM_REASON_LENGTH); - memset(io_monitor_env[1], 0, IOM_REASON_LENGTH); - memset(io_monitor_env[2], 0, IOM_REASON_LENGTH); - memset(io_monitor_env[3], 0, DATE_STR_LEN); - snprintf(io_monitor_env[0], IOM_REASON_LENGTH, - "REASON=%d", io_abnormal_info.reason); - snprintf(io_monitor_env[1], IOM_REASON_LENGTH, - "PID=%d", io_abnormal_info.pid); - snprintf(io_monitor_env[2], IOM_REASON_LENGTH, - "DELAY=%d", io_abnormal_info.delay); - snprintf(io_monitor_env[3], DATE_STR_LEN, "DATE=%s", date); - if (iomonitor_kobj) - kobject_uevent_env(iomonitor_kobj, KOBJ_CHANGE, io_monitor_env); - memset(&io_abnormal_info, 0, sizeof(struct abnormal_info)); - filp_log = filp_open(ABNORMAL_LOG_NAME, flags, 0666); - if (IS_ERR(filp_log)) { - atomic_dec(&abnormal_handle_ref); - last_abnormal_jiffies = jiffies; - return; - } - - if (filp_log->f_inode->i_size > log_file_size) { - atomic_dec(&abnormal_handle_ref); - filp_close(filp_log, NULL); - last_abnormal_jiffies = jiffies; - return; - } - - /* write log file header */ - kernel_write(filp_log, date, strlen(date), &file_pos); - - get_task_status(&buffer); - kernel_write(filp_log, buffer, strlen(buffer), &file_pos); - - /* write log file data */ - p = abnormal_list.next; - while (p != &abnormal_list) { - io_entry = list_entry(p, struct io_info_entry, list); - p = p->next; - - write_abnormal_file(filp_log, io_entry); - } - - filp_close(filp_log, NULL); - last_abnormal_jiffies = jiffies; - - atomic_dec(&abnormal_handle_ref); - - return; -} - -/* - * should be called at io abnormal point - * might sleep,can't used in atomic-context - */ -int abnormal_handle(enum iomointor_io_type reason, pid_t pid, u64 delta_ms) -{ - if (atomic_inc_return(&abnormal_handle_ref) > 1) { - atomic_dec(&abnormal_handle_ref); - return 0; - } - - io_abnormal_info.reason = reason; - io_abnormal_info.pid = pid; - io_abnormal_info.delay = (int)delta_ms; - queue_delayed_work(io_abnormal_queue, &io_abnormal_work, msecs_to_jiffies(1)); - - return 0; -} - -/* - * should be called at realtime record point - * might sleep,can't used in atomic-context - */ -void rt_record_handle(void) -{ - queue_delayed_work(rt_record_queue, &rt_record_work, msecs_to_jiffies(1)); -} - -static void fs_status_init(void) -{ - memset(&fs_status, 0, sizeof(struct fs_status_info)); -} - -static int task_status_init(void) -{ - task_buffer = kzalloc(sizeof(struct task_io_info) * PID_HASH_LEGNTH, GFP_KERNEL); - if (!task_buffer) - return -1; - profile_event_register(PROFILE_TASK_EXIT, &exit_task_notifier_block); - return 0; -} - -static int task_status_exit(void) -{ - if (task_buffer) - kfree(task_buffer); - profile_event_unregister(PROFILE_TASK_EXIT, &exit_task_notifier_block); - return 0; -} - -/* - * alloc meme for IoMonitor - * return 0 success,otherwith fail - */ -static int io_monitor_resource_init(void) -{ - fs_status_init(); - task_status_init(); - return 0; -} - -static inline void remove_uevent_resourse(void) -{ - int i; - - for (i = 3; i < MAX_IOMEVENT_PARAM - 1; i++) { - if (io_monitor_env[i]) - kfree(io_monitor_env[i]); - } - - return; -} - -/* - * free meme for IoMonitor - * return 0 success,otherwith fail - */ -static int io_monitor_resource_exit(void) -{ - task_status_exit(); - free_all_uid_entry(); - return 0; -} - -static void add_monitor_items(void) -{ - add_monitor_entry(&free_mem_entry); - /* add_monitor_entry(&io_queue_history_entry); */ - add_monitor_entry(&io_trace_entry); - add_monitor_entry(&ligntweight_dmesg_entry); -} - -static void add_daily_items(void) -{ - add_daily_entry(&fs_status_entry); - add_daily_entry(&block_ux_io_entry); - add_daily_entry(&block_sync_io_entry); - add_daily_entry(&block_nsync_io_entry); - add_daily_entry(&device_4k_rw_entry); - add_daily_entry(&device_512k_rw_entry); - add_daily_entry(&pgpg_status_entry); -#ifdef CONFIG_IOMONITOR_WITH_F2FS - add_daily_entry(&disk_info_entry); -#endif - add_daily_entry(&iowait_info_entry); -} - -static int iomonitor_uevent_init(void) -{ - int i; - - io_monitor_env[0] = &iom_reason[0]; - io_monitor_env[1] = &iom_pid[0]; - io_monitor_env[2] = &iom_delay[0]; - io_monitor_env[3] = kzalloc(DATE_STR_LEN, GFP_KERNEL); - if (!io_monitor_env[3]) { - printk("io_monitor:kzalloc io monitor uevent param failed\n"); - goto err; - } - - rt_record_env[0] = &rt_reason[0]; - iomonitor_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); - if (!iomonitor_kobj) { - printk("io_monitor:find kobj %s failed.\n", KBUILD_MODNAME); - goto err; - } - - printk("io_monitor:find kobj %s success.\n", KBUILD_MODNAME); - - return 0; -err: - for (i = 3; i < MAX_IOMEVENT_PARAM - 1; i++) { - if (io_monitor_env[i]) - kfree(io_monitor_env[i]); - } - - return -1; -} - -static int __init io_monitor_init(void) -{ - int ret = -1; - struct proc_dir_entry *daily_info_entry = NULL; - struct proc_dir_entry *data_flow_entry = NULL; - struct proc_dir_entry *uid_status_entry = NULL; - struct proc_dir_entry *trigger_event_entry = NULL; - struct proc_dir_entry *interval_entry = NULL; - struct proc_dir_entry *size_entry = NULL; - struct proc_dir_entry *iotrace_debug = NULL; - - ret = io_monitor_resource_init(); - if (ret != 0) { - printk("io_monitor:resource init failed.\n"); - return -1; - } - - ret = iomonitor_uevent_init(); - if (ret) - goto err; - - IoMonitor_dir = proc_mkdir("IoMonitor", NULL); - if (IoMonitor_dir) { - daily_info_entry = - proc_create("daily", S_IRUGO | S_IWUGO, IoMonitor_dir, - &proc_dailyio_operations); - if (!daily_info_entry) { - printk("io_monitor:create daily_info failed.\n"); - ret = -1; - goto err; - } - data_flow_entry = - proc_create("flow", S_IRUGO | S_IWUGO, IoMonitor_dir, - &proc_dataflow_operations); - if (!data_flow_entry) { - printk("io_monitor:create data_flow failed.\n"); - ret = -1; - goto err; - } - - trigger_event_entry = - proc_create("event", S_IRUGO | S_IWUGO, IoMonitor_dir, - &trigger_abnormal_open_operations); - if (!trigger_event_entry) { - printk("io_monitor:create trigger_event failed.\n"); - ret = -1; - goto err; - } - - uid_status_entry = create_uid_proc(IoMonitor_dir); - if (!uid_status_entry) { - printk("io_monitor:create uid_proc failed.\n"); - ret = -1; - goto err; - } - - interval_entry = - proc_create("interval", S_IRUGO | S_IWUGO, IoMonitor_dir, - &seq_abnormal_interval_fops); - if (!interval_entry) { - printk("io_monitor:create interval failed.\n"); - ret = -1; - goto err; - } - - size_entry = proc_create("log_size", S_IRUGO | S_IWUGO, IoMonitor_dir, - &seq_abnormal_size_fops); - if (!size_entry) { - printk("io_monitor:create log_size failed.\n"); - ret = -1; - goto err; - } - - iotrace_debug = create_iotrace_proc(IoMonitor_dir); - if (!iotrace_debug) { - ret = -1; - goto err; - } - } - - reqstats_init(); - add_monitor_items(); - add_daily_items(); - - io_abnormal_queue = create_singlethread_workqueue("iomonitor-queue"); - if (io_abnormal_queue == NULL) { - printk("%s: failed to create work queue iomonitor-queue\n", __func__); - goto err; - } - - rt_record_queue = create_singlethread_workqueue("iomonitor-rt-queue"); - if (rt_record_queue == NULL) { - printk("%s: failed to create work queue iomonitor-rt-queue\n", __func__); - goto err; - } - - printk("io_monitor:init module success\n"); - - return 0; - - err: - if (IoMonitor_dir) { - remove_proc_subtree("IoMonitor", NULL); - IoMonitor_dir = NULL; - } - io_monitor_resource_exit(); - return ret; -} - -static void __exit io_monitor_exit(void) -{ - if (io_abnormal_queue) { - destroy_workqueue(io_abnormal_queue); - io_abnormal_queue = NULL; - } - if (rt_record_queue) { - destroy_workqueue(rt_record_queue); - rt_record_queue = NULL; - } - remove_proc_subtree("IoMonitor", NULL); - IoMonitor_dir = NULL; - - remove_uevent_resourse(); - - io_monitor_resource_exit(); - - printk("io_monitor: module exit\n"); -} - -module_init(io_monitor_init); -module_exit(io_monitor_exit); - -MODULE_DESCRIPTION("iomonitor"); -MODULE_VERSION("1.0"); -MODULE_LICENSE("GPL"); diff --git a/drivers/soc/oplus/iomonitor/iotrace.c b/drivers/soc/oplus/iomonitor/iotrace.c deleted file mode 100755 index cc1e0663c70d..000000000000 --- a/drivers/soc/oplus/iomonitor/iotrace.c +++ /dev/null @@ -1,1109 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* data type for block offset of block group */ -typedef int ext4_grpblk_t; -/* data type for filesystem-wide blocks number */ -typedef unsigned long long ext4_fsblk_t; -/* data type for file logical block number */ -typedef __u32 ext4_lblk_t; -/* data type for block group number */ -typedef unsigned int ext4_group_t; -#include -#include -#include -#include -#include -#include - -/********************************************************************/ -#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) -#define io_trace_print(fmt, arg...) \ - printk("[[IO_TRACE] %s:%d]"fmt, __func__, __LINE__, ##arg) -#define io_trace_assert(cond) \ -{ \ - if (!(cond)) \ - io_trace_print("[IO_TRACE] %s\n", #cond); \ -} -#define IO_TRACE_PARENT_END (10) - -enum IO_TRACE_ACTION { - SYS_READ_TIMEOUT_TAG = 0x1, - TRACE_BEGIN_TAG = SYS_READ_TIMEOUT_TAG, - SYS_WRITE_TIMEOUT_TAG, - SYS_SYNC_TIMEOUT_TAG, - - BLOCK_BEGIN_TAG = SYS_SYNC_TIMEOUT_TAG, - - BLOCK_GETRQ_TAG, - BLOCK_RQ_INSERT_TAG, - BLOCK_RQ_ISSUE_TAG, - BLOCK_RQ_COMPLETE_TAG, - BLOCK_RQ_REQUEUE_TAG, - BLOCK_RQ_SLEEP_TAG, - BLOCK_END_TAG = BLOCK_RQ_SLEEP_TAG, - - SCSI_BLK_CMD_RW_ERROR_TAG, - SCSI_BLK_CMD_RW_TIMEOUT_TAG, - - TRACE_END_TAG = SCSI_BLK_CMD_RW_TIMEOUT_TAG, - - SCHED_STAT_IOWAIT_TAG, - -}; - -struct io_trace_action { - unsigned int action; - unsigned char *name; -}; - -/*lint -save -e64*/ -enum IO_TRACE_TYPE { - __IO_TRACE_WRITE, - - __IO_TRACE_SYNC = 4, - __IO_TRACE_META, /* metadata io request */ - __IO_TRACE_PRIO, /* boost priority in cfq */ - __IO_TRACE_DISCARD, /* request to discard sectors */ - __IO_TRACE_SECURE_ERASE, - __IO_TRACE_WRITE_SAME, - __IO_TRACE_FLUSH, - __IO_TRACE_FUA, - __IO_TRACE_FG, -}; - -enum TRACE_TYPE { - TRACE_SYSCALL, - TRACE_BLK, - TRACE_DEV, - TRACE_IOWAIT, - TRACE_END, -}; - -#define IO_TRACE_READ (0) -#define IO_TRACE_WRITE (1 << __IO_TRACE_WRITE) -#define IO_TRACE_SYNC (1 << __IO_TRACE_SYNC) -#define IO_TRACE_META (1 << __IO_TRACE_META) -#define IO_TRACE_DISCARD (1 << __IO_TRACE_DISCARD) -#define IO_TRACE_SECURE_ERASE (1 << __IO_TRACE_SECURE_ERASE) -#define IO_TRACE_WRITE_SAME (1 << __IO_TRACE_WRITE_SAME) -#define IO_TRACE_FLUSH (1 << __IO_TRACE_FLUSH) -#define IO_TRACE_FUA (1 << __IO_TRACE_FUA) -#define IO_TRACE_FG (1 << __IO_TRACE_FG) - -#define io_ns_to_ms(ns) ((ns) / 1000000) -#define IO_MAX_GLOBAL_ENTRY (1024 * 1024) - -#define IO_MAX_LOG_PER_GLOBAL \ - (((IO_MAX_GLOBAL_ENTRY) / sizeof(struct io_trace_log_entry)) - 1) -#define IO_F_NAME_LEN (32) -#define IO_P_NAME_LEN (16) -#define IO_TRACE_SYSCALL_TIMEOUT (1000) - -struct io_trace_entry_head { - char type; - char len; - char val[0]; -}; - -struct io_trace_syscall_entry { - unsigned char action; - u64 delay; - unsigned char f_name[IO_F_NAME_LEN]; - unsigned char comm[IO_P_NAME_LEN]; - pid_t pid; - unsigned long time; -}; - -struct io_trace_blk_entry { - unsigned char action; - unsigned int rw; - unsigned long sector; - unsigned int nr_bytes; - unsigned char dev_major; - unsigned char dev_minor; - - union { - unsigned short nr_rqs_sync; - unsigned short in_flight_sync; - }; - union { - unsigned short nr_rqs_async; - unsigned short in_flight_async; - }; - unsigned long time; -}; - -struct io_trace_dev_entry { - unsigned char action; - unsigned int rw; - unsigned long sector; - int result; - unsigned long time; -}; -struct io_trace_iowait_entry { - unsigned char action; - unsigned char comm[IO_P_NAME_LEN]; - unsigned char wchan[IO_P_NAME_LEN]; - pid_t pid; - u64 delay; - unsigned char ux_flag; - unsigned long time; -}; - -struct io_trace_ctrl { - struct platform_device *pdev; - unsigned int enable; - - unsigned int size; /* size of buffer */ - unsigned int first; /* start pos of first record */ - unsigned int last; /* end pos of last record */ - - unsigned char *all_trace_buff; -}; - -struct iotrace_debug_info { - unsigned int pos_err_cnt; - int before_loop_pos; - unsigned int before_loop_last; - ktime_t enter_loop_time; - int in_loop_pos; - unsigned int in_loop_first; - unsigned int in_loop_last; - ktime_t err_time; -}; - -static struct iotrace_debug_info *otrace_dbg_info; -static struct io_trace_ctrl *io_trace_this; -static struct io_trace_iowait_entry iowait_entry; -static struct io_trace_syscall_entry syscall_entry; -static struct io_trace_blk_entry blk_entry; -static struct io_trace_dev_entry dev_entry; - -static struct ufs_hba *fsr_hba; -static spinlock_t global_spinlock; -static struct mutex output_mutex; -static DEFINE_SPINLOCK(global_spinlock); -static DEFINE_MUTEX(output_mutex); - -static int trace_mm_init(struct io_trace_ctrl *trace_ctrl); -static void io_trace_setup(struct io_trace_ctrl *trace_ctrl); - -static ssize_t sysfs_io_trace_attr_show(struct device *dev, - struct device_attribute *attr, - char *buf); -static ssize_t sysfs_io_trace_attr_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count); - -#define IO_TRACE_DEVICE_ATTR(_name) \ - DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \ - sysfs_io_trace_attr_show, \ - sysfs_io_trace_attr_store) - -static IO_TRACE_DEVICE_ATTR(enable); - -static struct attribute *io_trace_attrs[] = { - &dev_attr_enable.attr, - - /*&io_log_data_attr.attr, */ - NULL, -}; - -struct attribute_group io_trace_attr_group = { - .name = "iotrace", - .attrs = io_trace_attrs, -}; - -static ssize_t sysfs_io_trace_attr_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - ssize_t ret = 0; - - if (attr == &dev_attr_enable) - ret = sprintf(buf, "%d\n", io_trace_this->enable); - - return ret; -} - -static ssize_t sysfs_io_trace_attr_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - unsigned int value; - - if (attr == &dev_attr_enable) { - mutex_lock(&output_mutex); - sscanf(buf, "%u", &value); - if (value == 1) - io_trace_this->enable = value; - if (value == 0) - io_trace_this->enable = value; - mutex_unlock(&output_mutex); - } - - return count; -} - -static struct kobject *kobject_ts; -static int io_trace_probe(struct platform_device *pdev) -{ - int ret; - - kobject_ts = kobject_create_and_add("io_log_data", NULL); - if (!kobject_ts) { - io_trace_print("create object failed!\n"); - return -1; - } - - ret = sysfs_create_group(kobject_ts, &io_trace_attr_group); - if (ret) { - kobject_put(kobject_ts); - io_trace_print("create group failed!\n"); - return -1; - } - return ret; -} - -static struct platform_driver io_trace_driver = { - .probe = io_trace_probe, - .driver = { - .owner = THIS_MODULE, - .name = "io_trace", - }, -}; - -static inline int is_syscall_action(unsigned int action) -{ - /*only the syscall log */ - if (action >= TRACE_BEGIN_TAG && action <= BLOCK_BEGIN_TAG) - return 1; - - return 0; -} - -static inline int is_block_action(unsigned int action) -{ - /*only the block log */ - if (action > BLOCK_BEGIN_TAG && action <= BLOCK_END_TAG) - return 1; - - return 0; -} - -static inline int is_dev_action(unsigned int action) -{ - /*only the device log */ - if (action > BLOCK_END_TAG && action <= TRACE_END_TAG) - return 1; - - return 0; -} - -static inline struct io_trace_entry_head *get_entry_head(int pos) -{ - - if (unlikely(pos >= io_trace_this->size)) - pos %= io_trace_this->size; - - return (struct io_trace_entry_head *)(io_trace_this->all_trace_buff + - pos); -} - -static inline void io_trace_record_log(char type, char entry_size, void *entry) -{ - struct io_trace_entry_head *entry_head; - int len, first, remain, pos; - unsigned long flags; - - len = sizeof(struct io_trace_entry_head) + entry_size; - spin_lock_irqsave(&global_spinlock, flags); - - pos = io_trace_this->last % io_trace_this->size; - remain = io_trace_this->size - pos; - - /* mark the end of the record */ - if (unlikely(remain < len)) { - entry_head = get_entry_head(pos); - entry_head->type = TRACE_END; - io_trace_this->last = io_trace_this->size + len; - first = 1; - pos = 0; - } else { - if (io_trace_this->first == 0 - && io_trace_this->last == io_trace_this->size) { - first = 1; - - } else { - first = io_trace_this->first; - - } - io_trace_this->last += len; - } - /* mark the start of record */ - if (first && (first < pos + len)) { - if (unlikely(first == 1)) - first = 0; - while (first < pos + len) { - - entry_head = get_entry_head(first); - if (entry_head->type == TRACE_END) { - first = 0; - break; - } else { - first += entry_head->len; - } - } - if (!first && io_trace_this->last >= io_trace_this->size) - io_trace_this->last -= io_trace_this->size; - if (first == io_trace_this->size && - io_trace_this->last >= io_trace_this->size) { - first -= io_trace_this->size; - io_trace_this->last -= io_trace_this->size; - } - io_trace_this->first = first; - } - - spin_unlock_irqrestore(&global_spinlock, flags); - entry_head = get_entry_head(pos); - entry_head->type = type; - entry_head->len = len; - - memcpy(entry_head->val, entry, entry_size); - - return; -} - -static void io_trace_global_log(unsigned int action, unsigned long sector, - unsigned int nr_bytes, struct file *filp, - unsigned int rw_flags, struct request_queue *rq, - unsigned int dev_major, unsigned int dev_minor, - int result, struct task_struct *tsk, u64 delay) -{ - struct timespec realts; - unsigned long log_time; - - do_posix_clock_monotonic_gettime(&realts); - log_time = (unsigned long)realts.tv_sec * 1000000000 + realts.tv_nsec; - - if (sector == ((unsigned long)-1)) - sector = (unsigned long)0; - - if (is_block_action(action)) { - blk_entry.action = action; - blk_entry.rw = rw_flags; - blk_entry.sector = sector; - blk_entry.nr_bytes = nr_bytes; - blk_entry.dev_major = (unsigned char)dev_major; - blk_entry.dev_minor = (unsigned char)dev_minor; - - if (action == BLOCK_GETRQ_TAG) { - blk_entry.nr_rqs_sync = (unsigned short)rq->nr_rqs[1]; - blk_entry.nr_rqs_async = (unsigned short)rq->nr_rqs[0]; - } else if (action == BLOCK_RQ_ISSUE_TAG) { - blk_entry.in_flight_sync = - (unsigned short)rq->in_flight[1]; - blk_entry.in_flight_async = - (unsigned short)rq->in_flight[0]; - - } - blk_entry.time = log_time; - - io_trace_record_log(TRACE_BLK, - sizeof(struct io_trace_blk_entry), - &blk_entry); - } else if (is_dev_action(action)) { - dev_entry.action = action; - dev_entry.rw = rw_flags; - dev_entry.sector = sector; - dev_entry.result = result; - dev_entry.time = log_time; - - io_trace_record_log(TRACE_DEV, - sizeof(struct io_trace_dev_entry), - &dev_entry); - } else if (action == SCHED_STAT_IOWAIT_TAG) { - iowait_entry.action = action; - iowait_entry.pid = tsk->pid; - iowait_entry.delay = io_ns_to_ms(delay); - iowait_entry.time = log_time; - iowait_entry.ux_flag = (unsigned char)result; - memcpy(iowait_entry.comm, tsk->comm, IO_P_NAME_LEN); - snprintf(iowait_entry.wchan, sizeof(iowait_entry.wchan), "%ps", - (void *)get_wchan(tsk)); - - io_trace_record_log(TRACE_IOWAIT, - sizeof(struct io_trace_iowait_entry), - &iowait_entry); - } else if (is_syscall_action(action)) { - syscall_entry.action = action; - syscall_entry.delay = delay; - syscall_entry.pid = current->pid; - memcpy(syscall_entry.comm, current->comm, IO_P_NAME_LEN); - - memset(syscall_entry.f_name, '\0', IO_F_NAME_LEN); - memcpy(syscall_entry.f_name, filp->f_path.dentry->d_iname, - IO_F_NAME_LEN); - - syscall_entry.time = log_time; - - io_trace_record_log(TRACE_SYSCALL, - sizeof(struct io_trace_syscall_entry), - &syscall_entry); - } - return; -} - -int write_log_kernel(char **data) -{ - - int ret = -1, pos, before_loop_pos; - loff_t file_pos = 0; - unsigned char buf[512]; - unsigned len; - unsigned int before_loop_last; - ktime_t enter_loop_time; - - struct io_trace_iowait_entry *iowait_entry = NULL; - struct io_trace_blk_entry *blk_entry = NULL; - struct io_trace_dev_entry *dev_entry = NULL; - struct io_trace_entry_head *entry_head = NULL; - struct io_trace_syscall_entry *syscall_entry = NULL; - - struct file *filp = (struct file *)data; - - if (io_trace_this == NULL) { - io_trace_print("io_trace_this is NULL!\n"); - return ret; - } - mutex_lock(&output_mutex); - if (!io_trace_this->enable) { - io_trace_print("io trace enable failed!\n"); - mutex_unlock(&output_mutex); - return ret; - } - - io_trace_this->enable = 0; - - if (filp == NULL) { - io_trace_print("filp is null\n"); - goto end; - } - if (IS_ERR(filp)) { - io_trace_print("file descriptor to is invalid: %ld\n", - PTR_ERR(filp)); - goto end; - } - - pos = io_trace_this->first; - before_loop_pos = pos; - before_loop_last = io_trace_this->last; - enter_loop_time = ktime_get(); - while (pos >= io_trace_this->first && pos < io_trace_this->last) { - - entry_head = get_entry_head(pos); - - /* Check end flag first, avoid illegal memory access */ - if (entry_head->type == TRACE_END) { - pos = io_trace_this->size; - continue; - } - - /* Avoid while dead loop problem, but can cause invalid log */ - if ((int)entry_head->len <= 0) { - if (otrace_dbg_info) { - otrace_dbg_info->pos_err_cnt += 1; - otrace_dbg_info->before_loop_pos = before_loop_pos; - otrace_dbg_info->before_loop_last = before_loop_last; - otrace_dbg_info->enter_loop_time = enter_loop_time; - otrace_dbg_info->in_loop_pos = pos; - otrace_dbg_info->in_loop_first = io_trace_this->first; - otrace_dbg_info->in_loop_last = io_trace_this->last; - otrace_dbg_info->err_time = ktime_get(); - } - pr_err("IOMonitor: dead loop will happen, but it is circumvented. " - "first=%d, last=%d, pos=%d.\n", io_trace_this->first, - io_trace_this->last, pos); - break; - } - - pos += entry_head->len; - - switch (entry_head->type) { - case TRACE_SYSCALL: - syscall_entry = - (struct io_trace_syscall_entry *)entry_head->val; - len = - snprintf(buf, sizeof(buf), "%lu %d %d %s %s %llu\n", - syscall_entry->time, syscall_entry->action, - syscall_entry->pid, syscall_entry->comm, - syscall_entry->f_name, - syscall_entry->delay); - ret = kernel_write(filp, buf, len, &file_pos); - break; - case TRACE_IOWAIT: - iowait_entry = - (struct io_trace_iowait_entry *)entry_head->val; - len = - snprintf(buf, sizeof(buf), - "%lu %d %d %s %s %llu %d\n", - iowait_entry->time, iowait_entry->action, - iowait_entry->pid, iowait_entry->comm, - iowait_entry->wchan, iowait_entry->delay, - iowait_entry->ux_flag); - ret = kernel_write(filp, buf, len, &file_pos); - break; - case TRACE_BLK: - blk_entry = - (struct io_trace_blk_entry *)entry_head->val; - if (blk_entry->action == BLOCK_GETRQ_TAG) - len = - snprintf(buf, sizeof(buf), - "%lu %d %d %d %d %lu %d %u %u\n", - blk_entry->time, blk_entry->action, - blk_entry->dev_major, - blk_entry->dev_minor, - (unsigned int)(blk_entry->rw), - blk_entry->sector, - blk_entry->nr_bytes, - blk_entry->nr_rqs_sync, - blk_entry->nr_rqs_async); - else if (blk_entry->action == BLOCK_RQ_ISSUE_TAG) - len = - snprintf(buf, sizeof(buf), - "%lu %d %d %d %d %lu %d %u %u\n", - blk_entry->time, blk_entry->action, - blk_entry->dev_major, - blk_entry->dev_minor, - (unsigned int)(blk_entry->rw), - blk_entry->sector, - blk_entry->nr_bytes, - blk_entry->in_flight_sync, - blk_entry->in_flight_async); - else - len = - snprintf(buf, sizeof(buf), - "%lu %d %d %d %d %lu %d\n", - blk_entry->time, blk_entry->action, - blk_entry->dev_major, - blk_entry->dev_minor, - (unsigned int)(blk_entry->rw), - blk_entry->sector, - blk_entry->nr_bytes); - ret = kernel_write(filp, buf, len, &file_pos); - break; - case TRACE_DEV: - dev_entry = - (struct io_trace_dev_entry *)entry_head->val; - len = - snprintf(buf, sizeof(buf), "%lu %d %d %lu %d\n", - dev_entry->time, dev_entry->action, - (unsigned int)(dev_entry->rw), - dev_entry->sector, dev_entry->result); - ret = kernel_write(filp, buf, len, &file_pos); - break; - case TRACE_END: - break; - } - - } - - end: - io_trace_this->enable = 1; - mutex_unlock(&output_mutex); - - return ret; - -} -EXPORT_SYMBOL(write_log_kernel); - -static void io_syscall_read_timeout(void *ignore, struct file *file, u64 delay) -{ - if (delay < IO_TRACE_SYSCALL_TIMEOUT || file == NULL) - return; - - if (io_trace_this->enable) { - io_trace_global_log(SYS_READ_TIMEOUT_TAG, 0, 0, file, 0, NULL, - 0, 0, -1000, NULL, delay); - } -} - -static void io_syscall_write_timeout(void *ignore, struct file *file, u64 delay) -{ - if (delay < IO_TRACE_SYSCALL_TIMEOUT || file == NULL) - return; - - if (io_trace_this->enable) { - io_trace_global_log(SYS_WRITE_TIMEOUT_TAG, 0, 0, file, 0, NULL, - 0, 0, -1000, NULL, delay); - } -} - -static void io_syscall_sync_timeout(void *ignore, struct file *file, u64 delay) -{ - if (delay < IO_TRACE_SYSCALL_TIMEOUT || file == NULL) - return; - - if (io_trace_this->enable) { - io_trace_global_log(SYS_SYNC_TIMEOUT_TAG, 0, 0, file, 0, NULL, - 0, 0, -1000, NULL, delay); - } -} - -static void blk_add_trace_rq_get(void *ignore, struct request_queue *q, - struct bio *bio, int rw) -{ - if (io_trace_this->enable && bio) { - unsigned int rw_type = bio->bi_opf; - unsigned int dev = bio_dev(bio); - - io_trace_global_log(BLOCK_GETRQ_TAG, bio->bi_iter.bi_sector, - bio->bi_iter.bi_size, 0, rw_type, q, - MAJOR(dev), MINOR(dev), -1000, NULL, 0); - } - - return; -} - -static void blk_add_trace_rq_insert(void *ignore, struct request_queue *q, - struct request *rq) -{ - if (io_trace_this->enable) { - unsigned int rw_type = rq->cmd_flags; - unsigned int dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; - - io_trace_global_log(BLOCK_RQ_INSERT_TAG, - blk_rq_trace_sector(rq), blk_rq_bytes(rq), - 0, rw_type, q, MAJOR(dev), MINOR(dev), - -1000, NULL, 0); - } - - return; -} - -static void blk_add_trace_rq_issue(void *ignore, struct request_queue *q, - struct request *rq) -{ - - if (io_trace_this->enable) { - unsigned int rw_type = rq->cmd_flags; - unsigned int dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; - - io_trace_global_log(BLOCK_RQ_ISSUE_TAG, blk_rq_trace_sector(rq), - blk_rq_bytes(rq), 0, rw_type, q, MAJOR(dev), - MINOR(dev), -1000, NULL, 0); - } - - return; -} - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) -static void blk_add_trace_rq_complete(void *ignore, struct request *rq, - int error, unsigned int nr_bytes) -{ - if (io_trace_this->enable) { - unsigned int rw_type = rq->cmd_flags; - unsigned int dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; - - io_trace_global_log(BLOCK_RQ_COMPLETE_TAG, - blk_rq_trace_sector(rq), blk_rq_bytes(rq), - 0, rw_type, NULL, MAJOR(dev), MINOR(dev), - -1000, NULL, 0); - } - return; -} - -#else -static void blk_add_trace_rq_complete(void *ignore, struct request_queue *q, - struct request *rq, unsigned int nr_bytes) -{ - if (io_trace_this->enable) { - unsigned int rw_type = rq->cmd_flags; - unsigned int dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; - - io_trace_global_log(BLOCK_RQ_COMPLETE_TAG, - blk_rq_trace_sector(rq), blk_rq_bytes(rq), - 0, rw_type, NULL, MAJOR(dev), MINOR(dev), - -1000, NULL, 0); - - } - return; -} -#endif - -static void blk_add_trace_rq_requeue(void *ignore, struct request_queue *q, - struct request *rq) -{ - - if (io_trace_this->enable) { - unsigned int rw_type = rq->cmd_flags; - unsigned int dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; - - io_trace_global_log(BLOCK_RQ_REQUEUE_TAG, - blk_rq_trace_sector(rq), blk_rq_bytes(rq), - 0, rw_type, q, MAJOR(dev), MINOR(dev), - -1000, NULL, 0); - } - - return; -} - -static void blk_add_trace_sleeprq(void *ignore, struct request_queue *q, - struct bio *bio, int rw) -{ - - if (io_trace_this->enable && bio) { - unsigned int rw_type = bio->bi_opf; - unsigned int dev = bio_dev(bio); - - io_trace_global_log(BLOCK_RQ_SLEEP_TAG, bio->bi_iter.bi_sector, - bio->bi_iter.bi_size, 0, rw_type, q, - MAJOR(dev), MINOR(dev), -1000, NULL, 0); - } - - return; -} - -static void scsi_dispatch_cmd_timeout(void *ignore, struct scsi_cmnd *cmd) -{ - unsigned int rw_flags = 0; - unsigned char c[4]; - unsigned char len[2]; - unsigned int *addr; - unsigned short *size; - int result; - struct scsi_cmnd *fsr_scsi = NULL; - struct Scsi_Host *host = NULL; - - fsr_scsi = (struct scsi_cmnd *)cmd; - - if (fsr_scsi->device->host == NULL) - return; - - host = fsr_scsi->device->host; - fsr_hba = shost_priv(host); - - if (!fsr_hba) { - io_trace_print("%s shost_priv host failed\n", __func__); - return; - } - - c[0] = cmd->cmnd[5]; - c[1] = cmd->cmnd[4]; - c[2] = cmd->cmnd[3]; - c[3] = cmd->cmnd[2]; - - len[0] = cmd->cmnd[7]; - len[1] = cmd->cmnd[8]; - - addr = (int *)c; - size = (short *)len; - result = cmd->result; - - if (0x2A == cmd->cmnd[0]) - rw_flags |= IO_TRACE_WRITE; - else if (0x35 == cmd->cmnd[0]) - rw_flags |= (IO_TRACE_SYNC | IO_TRACE_WRITE); - else if (0x28 == cmd->cmnd[0]) - rw_flags |= IO_TRACE_READ; - if (io_trace_this->enable) { - io_trace_global_log(SCSI_BLK_CMD_RW_TIMEOUT_TAG, (*addr) * 8, - (*size) * 16, 0, rw_flags, NULL, 0, 0, - result, NULL, 0); - } - return; -} - -static void scsi_dispatch_cmd_error(void *ignore, struct scsi_cmnd *cmd, - int rtn) -{ - unsigned int rw_flags = 0; - unsigned char c[4]; - unsigned char len[2]; - unsigned int *addr; - unsigned short *size; - int result; - struct scsi_cmnd *fsr_scsi = NULL; - struct Scsi_Host *host = NULL; - - fsr_scsi = (struct scsi_cmnd *)cmd; - - if (fsr_scsi->device->host == NULL) - return; - - host = fsr_scsi->device->host; - fsr_hba = shost_priv(host); - - if (!fsr_hba) { - io_trace_print("%s shost_priv host failed\n", __func__); - return; - } - - c[0] = cmd->cmnd[5]; - c[1] = cmd->cmnd[4]; - c[2] = cmd->cmnd[3]; - c[3] = cmd->cmnd[2]; - - len[0] = cmd->cmnd[7]; - len[1] = cmd->cmnd[8]; - - addr = (int *)c; - size = (short *)len; - result = rtn; - - if (0x2A == cmd->cmnd[0]) - rw_flags |= IO_TRACE_WRITE; - else if (0x35 == cmd->cmnd[0]) - rw_flags |= (IO_TRACE_SYNC | IO_TRACE_WRITE); - else if (0x28 == cmd->cmnd[0]) - rw_flags |= IO_TRACE_READ; - if (io_trace_this->enable) { - io_trace_global_log(SCSI_BLK_CMD_RW_ERROR_TAG, (*addr) * 8, - (*size) * 16, 0, rw_flags, NULL, 0, 0, - result, NULL, 0); - } - return; -} - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern bool test_task_ux(struct task_struct *task); -#endif -static void sched_stat_iowait(void *ignore, struct task_struct *tsk, u64 delay) -{ - if (tsk == NULL) - return; - - if (io_trace_this->enable) { -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (test_task_ux(tsk) - && io_ns_to_ms(delay) >= UX_IO_WAIT_TIMEOUT) - io_trace_global_log(SCHED_STAT_IOWAIT_TAG, 0, 0, 0, 0, - NULL, 0, 0, 1, tsk, delay); - else if (io_ns_to_ms(delay) >= IO_WAIT_TIMEOUT) - io_trace_global_log(SCHED_STAT_IOWAIT_TAG, 0, 0, 0, 0, - NULL, 0, 0, 0, tsk, delay); -#else - if (io_ns_to_ms(delay) >= IO_WAIT_TIMEOUT) - io_trace_global_log(SCHED_STAT_IOWAIT_TAG, 0, 0, 0, 0, - NULL, 0, 0, 0, tsk, delay); -#endif - } - - return; -} - -static int iotrace_debug_seq_show(struct seq_file *seq, void *offset) -{ - seq_printf(seq, "pos_err_cnt: %u\n" - "before_loop_pos: %d\n" - "before_loop_last: %u\n" - "enter_loop_time: %lld\n" - "in_loop_pos: %d\n" - "in_loop_first: %u\n" - "in_loop_last: %u\n" - "err_time: %lld\n", - otrace_dbg_info->pos_err_cnt, - otrace_dbg_info->before_loop_pos, - otrace_dbg_info->before_loop_last, - otrace_dbg_info->enter_loop_time, - otrace_dbg_info->in_loop_pos, - otrace_dbg_info->in_loop_first, - otrace_dbg_info->in_loop_last, - otrace_dbg_info->err_time); - return 0; -} - -static int iotrace_debug_open(struct inode *inode, struct file *file) -{ - return single_open(file, iotrace_debug_seq_show, NULL); -} - -static const struct file_operations proc_iotrace_debug_operations = { - .open = iotrace_debug_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -struct proc_dir_entry *create_iotrace_proc(struct proc_dir_entry *parent) -{ - struct proc_dir_entry *child = NULL; - child = proc_create("iotrace_debug", S_IRUGO | S_IWUGO, parent, - &proc_iotrace_debug_operations); - return child; -} - -static void iotrace_register_tracepoints(void) -{ - int ret; - - /* syscall */ - ret = - register_trace_syscall_read_timeout(io_syscall_read_timeout, NULL); - WARN_ON(ret); - ret = - register_trace_syscall_write_timeout(io_syscall_write_timeout, - NULL); - WARN_ON(ret); - ret = - register_trace_syscall_sync_timeout(io_syscall_sync_timeout, NULL); - WARN_ON(ret); - - /* block layer */ - ret = register_trace_block_getrq(blk_add_trace_rq_get, NULL); - WARN_ON(ret); - ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); - WARN_ON(ret); - ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); - WARN_ON(ret); - ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); - WARN_ON(ret); - ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); - WARN_ON(ret); - ret = register_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); - WARN_ON(ret); - - ret = - register_trace_scsi_dispatch_cmd_error(scsi_dispatch_cmd_error, - NULL); - WARN_ON(ret); - ret = - register_trace_scsi_dispatch_cmd_timeout(scsi_dispatch_cmd_timeout, - NULL); - WARN_ON(ret); - ret = register_trace_sched_stat_iowait(sched_stat_iowait, NULL); - WARN_ON(ret); - - return; -} - -static void io_trace_setup(struct io_trace_ctrl *trace_ctrl) -{ - io_trace_print("io trace setup!\n"); - iotrace_register_tracepoints(); - - return; -} - -static int trace_mm_init(struct io_trace_ctrl *trace_ctrl) -{ - io_trace_print("trace mm init start!\n"); - - trace_ctrl->all_trace_buff = kvmalloc(IO_MAX_GLOBAL_ENTRY, GFP_KERNEL); - if (trace_ctrl->all_trace_buff == NULL) { - io_trace_print("mem mngt kvmalloc failed!\n"); - goto failed; - } - - return 0; - - failed: - return -1; -} - -static int trace_ctrl_init(struct io_trace_ctrl *trace_ctrl, - unsigned int *total_mem) -{ - trace_ctrl->enable = 0; - trace_ctrl->pdev = NULL; - trace_ctrl->size = IO_MAX_GLOBAL_ENTRY; - trace_ctrl->first = 0; - trace_ctrl->last = 0; - return 0; -} - -static int __init io_trace_init(void) -{ - int ret = -1; - int total_mem = 0; - - if (otrace_dbg_info == NULL) - otrace_dbg_info = (struct iotrace_debug_info *) - kzalloc(sizeof(struct iotrace_debug_info), GFP_KERNEL); - if (otrace_dbg_info == NULL) - return -1; - - io_trace_print("Enter %s\n", __func__); - if (io_trace_this == NULL) { - io_trace_this = - (struct io_trace_ctrl *) - kzalloc(sizeof(struct io_trace_ctrl), GFP_KERNEL); - total_mem += sizeof(struct io_trace_ctrl); - if (NULL == io_trace_this) { - io_trace_print("(%s)kmalloc failed!", __func__); - return -1; - } - io_trace_print("io_trace_this is init!\n"); - if (trace_ctrl_init(io_trace_this, &total_mem) < 0) - return -1; - - ret = trace_mm_init(io_trace_this); - if (ret < 0) { - io_trace_print("trace mm init failed!\n"); - return ret; - } - io_trace_setup(io_trace_this); - io_trace_this->enable = 1; - } - - io_trace_print("total mem : %d\n", total_mem); - io_trace_print("Enter %s:%d\n", __func__, __LINE__); - - io_trace_this->pdev = - platform_device_register_simple("io_trace", -1, NULL, 0); - if (!io_trace_this->pdev) { - io_trace_print - ("(%s)register platform_device_register_simple null!", - __func__); - return -1; - } - - ret = platform_driver_register(&io_trace_driver); - if (ret < 0) { - io_trace_print("(%s)register platform_driver_register failed!", - __func__); - return ret; - } - - return 0; -} - -static void __exit io_trace_exit(void) -{ - if (io_trace_this->pdev) - platform_device_unregister(io_trace_this->pdev); - - platform_driver_unregister(&io_trace_driver); - - if (otrace_dbg_info) - kfree(otrace_dbg_info); -} - -late_initcall(io_trace_init); -module_exit(io_trace_exit); diff --git a/drivers/soc/oplus/iomonitor/uid_status.c b/drivers/soc/oplus/iomonitor/uid_status.c deleted file mode 100755 index 6cc6d70dcd0f..000000000000 --- a/drivers/soc/oplus/iomonitor/uid_status.c +++ /dev/null @@ -1,501 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define UID_HASH_BITS 8 -DECLARE_HASHTABLE(uid_hash_table, UID_HASH_BITS); -static DEFINE_RT_MUTEX(uid_lock); - -#define UID_STATE_DELTA 0 -#define UID_STATE_TOTAL_CURR 1 -#define UID_STATE_TOTAL_LAST 2 -#define UID_STATE_DEAD_TASKS 3 -#define UID_STATE_SIZE 4 -#define TASK_LIMIT_COUNT 40000 -#define TASK_LIMIT_DATA (2*1024*1024) -#define TGID_TASK_LIMTI_DATA (100*1024*1024) -#define UID_LIMIT_COUNT 2000 -static int task_limit_count; -static int uid_limit_count; -struct io_stats { - u64 read_bytes; - u64 write_bytes; - u64 rchar; - u64 wchar; - u64 fsync; -}; -#define MAX_TASK_COMM_LEN 16 -#define task_all_bytes(tsk) \ - (tsk->ioac.read_bytes + compute_write_bytes(tsk)) - -struct task_entry { - char comm[MAX_TASK_COMM_LEN]; - char tgid_comm[MAX_TASK_COMM_LEN]; - pid_t pid; - bool is_kthread; - int state; - struct io_stats io[UID_STATE_SIZE]; - struct hlist_node hash; -}; - -struct uid_entry { - uid_t uid; - int task_count; - struct io_stats io[UID_STATE_SIZE]; - struct hlist_node hash; - DECLARE_HASHTABLE(task_entries, UID_HASH_BITS); -}; - -static void trim_space(char *trim) -{ - char *s = trim; - int cnt = 0; - int i; - - for (i = 0; s[i]; i++) { - if (!isspace(s[i])) - s[cnt++] = s[i]; - } - s[cnt] = '\0'; -} - -static u64 compute_write_bytes(struct task_struct *task) -{ - if (task->ioac.write_bytes <= task->ioac.cancelled_write_bytes) - return 0; - - return task->ioac.write_bytes - task->ioac.cancelled_write_bytes; -} - -static void compute_io_bucket_stats(struct io_stats *io_bucket, - struct io_stats *io_curr, - struct io_stats *io_last, - struct io_stats *io_dead) -{ - /* tasks could switch to another uid group, but its io_last in the - * previous uid group could still be positive. - * therefore before each update, do an overflow check first - */ - int64_t delta; - - delta = io_curr->read_bytes + io_dead->read_bytes - io_last->read_bytes; - io_bucket->read_bytes = delta > 0 ? delta : 0; - delta = io_curr->write_bytes + io_dead->write_bytes - - io_last->write_bytes; - io_bucket->write_bytes = delta > 0 ? delta : 0; - delta = io_curr->rchar + io_dead->rchar - io_last->rchar; - io_bucket->rchar = delta > 0 ? delta : 0; - delta = io_curr->wchar + io_dead->wchar - io_last->wchar; - io_bucket->wchar = delta > 0 ? delta : 0; - delta = io_curr->fsync + io_dead->fsync - io_last->fsync; - io_bucket->fsync = delta > 0 ? delta : 0; - - io_last->read_bytes = io_curr->read_bytes; - io_last->write_bytes = io_curr->write_bytes; - io_last->rchar = io_curr->rchar; - io_last->wchar = io_curr->wchar; - io_last->fsync = io_curr->fsync; - - memset(io_dead, 0, sizeof(struct io_stats)); -} - -static inline bool task_is_kthread(struct task_struct *task) -{ - if (task->mm == NULL) - return true; - return false; -} - -static struct uid_entry *find_uid_entry(uid_t uid) -{ - struct uid_entry *uid_entry; - - hash_for_each_possible(uid_hash_table, uid_entry, hash, uid) { - if (uid_entry->uid == uid) - return uid_entry; - } - return NULL; -} - -static struct uid_entry *find_or_register_uid(uid_t uid) -{ - struct uid_entry *uid_entry = NULL; - - uid_entry = find_uid_entry(uid); - if (uid_entry) - return uid_entry; - - if (uid_limit_count > UID_LIMIT_COUNT) - return NULL; - uid_entry = kzalloc(sizeof(struct uid_entry), GFP_ATOMIC); - if (!uid_entry) - return NULL; - uid_entry->uid = uid; - hash_init(uid_entry->task_entries); - hash_add(uid_hash_table, &uid_entry->hash, uid); - uid_limit_count++; - - return uid_entry; -} - -static struct task_entry *find_task_entry(struct uid_entry *uid_entry, - struct task_struct *task) -{ - struct task_entry *task_entry; - - hash_for_each_possible(uid_entry->task_entries, task_entry, hash, - task->pid) { - if (task->pid == task_entry->pid) { - /* if thread name changed, update the entire command */ - int len = strlen(task->comm); - - if (strncmp(task_entry->comm, task->comm, len)) - __get_task_comm(task_entry->comm, TASK_COMM_LEN, task); - trim_space(task_entry->comm); - return task_entry; - } - } - return NULL; -} - -static struct task_entry *find_or_register_task(struct uid_entry *uid_entry, - struct task_struct *task, - int state) -{ - struct task_entry *task_entry = NULL; - struct task_struct *tgid_task = NULL; - pid_t pid = task->pid; - - task_entry = find_task_entry(uid_entry, task); - if (task_entry) - return task_entry; - if (task_limit_count > TASK_LIMIT_COUNT) - return NULL; - if (state == TASK_DEAD && (task_all_bytes(task) < TASK_LIMIT_DATA)) - return NULL; - task_entry = kzalloc(sizeof(struct task_entry), GFP_ATOMIC); - if (!task_entry) - return NULL; - __get_task_comm(task_entry->comm, TASK_COMM_LEN, task); - trim_space(task_entry->comm); - - if (task_all_bytes(task) > TGID_TASK_LIMTI_DATA) { - tgid_task = find_task_by_pid_ns(task->tgid, &init_pid_ns); - if (tgid_task) { - __get_task_comm(task_entry->tgid_comm, TASK_COMM_LEN, - tgid_task); - trim_space(task_entry->tgid_comm); - } - } - task_entry->pid = pid; - task_entry->is_kthread = task_is_kthread(task); - hash_add(uid_entry->task_entries, &task_entry->hash, (unsigned int)pid); - task_limit_count++; - - return task_entry; -} - -static void add_uid_tasks_io_stats(struct uid_entry *uid_entry, - struct task_struct *task, int slot, - int state) -{ - struct io_stats *task_io_slot; - struct task_entry *task_entry = - find_or_register_task(uid_entry, task, state); - if (!task_entry) - return; - - task_entry->state = state; - task_io_slot = &task_entry->io[slot]; - - task_io_slot->read_bytes += task->ioac.read_bytes; - task_io_slot->write_bytes += compute_write_bytes(task); - task_io_slot->rchar += task->ioac.rchar; - task_io_slot->wchar += task->ioac.wchar; - task_io_slot->fsync += task->ioac.syscfs; -} - -static void add_uid_io_stats(struct uid_entry *uid_entry, - struct task_struct *task, int slot, int state) -{ - struct io_stats *io_slot = &uid_entry->io[slot]; - - io_slot->read_bytes += task->ioac.read_bytes; - io_slot->write_bytes += compute_write_bytes(task); - io_slot->rchar += task->ioac.rchar; - io_slot->wchar += task->ioac.wchar; - io_slot->fsync += task->ioac.syscfs; - - add_uid_tasks_io_stats(uid_entry, task, slot, state); -} - -static void set_io_uid_tasks_zero(struct uid_entry *uid_entry) -{ - struct task_entry *task_entry; - unsigned long bkt_task; - - hash_for_each(uid_entry->task_entries, bkt_task, task_entry, hash) { - memset(&task_entry->io[UID_STATE_TOTAL_CURR], 0, - sizeof(struct io_stats)); - } -} - -static void compute_io_uid_tasks(struct uid_entry *uid_entry) -{ - struct task_entry *task_entry; - unsigned long bkt_task; - - uid_entry->task_count = 0; - hash_for_each(uid_entry->task_entries, bkt_task, task_entry, hash) { - uid_entry->task_count++; - compute_io_bucket_stats(&task_entry->io[UID_STATE_DELTA], - &task_entry->io[UID_STATE_TOTAL_CURR], - &task_entry->io[UID_STATE_TOTAL_LAST], - &task_entry->io[UID_STATE_DEAD_TASKS]); - } -} - -static void show_io_uid_tasks(struct seq_file *m, struct uid_entry *uid_entry) -{ - struct task_entry *task_entry; - unsigned long bkt_task; - u64 task_all_bytes; - - hash_for_each(uid_entry->task_entries, bkt_task, task_entry, hash) { - /* Separated by comma because space exists in task comm */ - task_all_bytes = - task_entry->io[UID_STATE_DELTA].read_bytes + - task_entry->io[UID_STATE_DELTA].write_bytes; - if (task_all_bytes >= TASK_SHOW_DAILY_LIMIT) - seq_printf(m, - "task:%s %lu %llu %llu %llu %llu %llu %d %s\n", - task_entry->comm, - (unsigned long)task_entry->pid, - task_entry->io[UID_STATE_DELTA].rchar, - task_entry->io[UID_STATE_DELTA].wchar, - task_entry->io[UID_STATE_DELTA].read_bytes, - task_entry->io[UID_STATE_DELTA].write_bytes, - task_entry->io[UID_STATE_DELTA].fsync, - task_entry->is_kthread, - task_entry->tgid_comm); - - } -} - -static void remove_dead_uid_tasks(struct uid_entry *uid_entry) -{ - struct task_entry *task_entry; - unsigned long bkt_task; - struct hlist_node *tmp_task; - - hash_for_each_safe(uid_entry->task_entries, bkt_task, - tmp_task, task_entry, hash) { - if (task_entry->state == TASK_DEAD) { - hash_del(&task_entry->hash); - kfree(task_entry); - uid_entry->task_count--; - task_limit_count--; - } - } -} - -static void remove_all_uid_tasks(struct uid_entry *uid_entry) -{ - struct task_entry *task_entry; - unsigned long bkt_task; - struct hlist_node *tmp_task; - - hash_for_each_safe(uid_entry->task_entries, bkt_task, - tmp_task, task_entry, hash) { - if (task_entry) { - hash_del(&task_entry->hash); - kfree(task_entry); - task_limit_count--; - } - } -} - -static void remove_no_task_uid_entry(void) -{ - struct uid_entry *uid_entry = NULL; - unsigned long bkt; - struct hlist_node *tmp_task; - - hash_for_each_safe(uid_hash_table, bkt, tmp_task, uid_entry, hash) { - if (uid_entry->task_count == 0) { - hash_del(&uid_entry->hash); - kfree(uid_entry); - uid_limit_count--; - } - } -} - -static int uid_io_show(struct seq_file *m, void *v) -{ - struct uid_entry *uid_entry = NULL; - unsigned long bkt; - u64 all_bytes; - - rt_mutex_lock(&uid_lock); - hash_for_each(uid_hash_table, bkt, uid_entry, hash) { - seq_printf(m, "%d %llu %llu %llu %llu %llu %d\n", - uid_entry->uid, - uid_entry->io[UID_STATE_DELTA].rchar, - uid_entry->io[UID_STATE_DELTA].wchar, - uid_entry->io[UID_STATE_DELTA].read_bytes, - uid_entry->io[UID_STATE_DELTA].write_bytes, - uid_entry->io[UID_STATE_DELTA].fsync, - uid_entry->task_count); - - all_bytes = - uid_entry->io[UID_STATE_DELTA].read_bytes + - uid_entry->io[UID_STATE_DELTA].write_bytes; - if (all_bytes >= UID_SHOW_DAILY_LIMIT) - show_io_uid_tasks(m, uid_entry); - } - rt_mutex_unlock(&uid_lock); - return 0; -} - -int exit_uid_find_or_register(struct task_struct *task) -{ - struct uid_entry *uid_entry; - uid_t uid; - - if (!task) - return NOTIFY_OK; - - rt_mutex_lock(&uid_lock); - uid = from_kuid_munged(current_user_ns(), task_uid(task)); - uid_entry = find_or_register_uid(uid); - if (!uid_entry) { - pr_err("%s: failed to find uid %d\n", __func__, uid); - goto exit; - } - add_uid_io_stats(uid_entry, task, UID_STATE_DEAD_TASKS, TASK_DEAD); - - exit: - rt_mutex_unlock(&uid_lock); - return NOTIFY_OK; -} - -void free_all_uid_entry(void) -{ - struct uid_entry *uid_entry = NULL; - unsigned long bkt; - struct hlist_node *tmp_task; - - hash_for_each_safe(uid_hash_table, bkt, tmp_task, uid_entry, hash) { - if (uid_entry) { - remove_all_uid_tasks(uid_entry); - hash_del(&uid_entry->hash); - kfree(uid_entry); - uid_limit_count--; - } - } - -} - -static int uidio_show_open(struct inode *inode, struct file *file) -{ - struct uid_entry *uid_entry = NULL; - struct task_struct *temp, *task; - unsigned long bkt; - uid_t uid; - - rt_mutex_lock(&uid_lock); - hash_for_each(uid_hash_table, bkt, uid_entry, hash) { - memset(&uid_entry->io[UID_STATE_TOTAL_CURR], 0, - sizeof(struct io_stats)); - set_io_uid_tasks_zero(uid_entry); - } - - rcu_read_lock(); - do_each_thread(temp, task) { - if (!task->ioac.read_bytes && !task->ioac.write_bytes) - continue; - uid = from_kuid_munged(current_user_ns(), task_uid(task)); - uid_entry = find_or_register_uid(uid); - if (!uid_entry) - continue; - add_uid_io_stats(uid_entry, task, UID_STATE_TOTAL_CURR, - task->state); - } while_each_thread(temp, task); - rcu_read_unlock(); - - hash_for_each(uid_hash_table, bkt, uid_entry, hash) { - compute_io_bucket_stats(&uid_entry->io[UID_STATE_DELTA], - &uid_entry->io[UID_STATE_TOTAL_CURR], - &uid_entry->io[UID_STATE_TOTAL_LAST], - &uid_entry->io[UID_STATE_DEAD_TASKS]); - compute_io_uid_tasks(uid_entry); - } - rt_mutex_unlock(&uid_lock); - return single_open(file, uid_io_show, inode->i_private); -} - -static int uidio_show_release(struct inode *inode, struct file *file) -{ - struct uid_entry *uid_entry = NULL; - unsigned long bkt; - - printk("uid debug: %d %d\n", task_limit_count, uid_limit_count); - rt_mutex_lock(&uid_lock); - hash_for_each(uid_hash_table, bkt, uid_entry, hash) { - remove_dead_uid_tasks(uid_entry); - } - remove_no_task_uid_entry(); - rt_mutex_unlock(&uid_lock); - return single_release(inode, file); -} - -static const struct file_operations proc_uidio_show_operations = { - .open = uidio_show_open, - .read = seq_read, - .llseek = seq_lseek, - .release = uidio_show_release, -}; - -struct proc_dir_entry *create_uid_proc(struct proc_dir_entry *parent) -{ - struct proc_dir_entry *dir_entry = NULL; - - dir_entry = - proc_create("uid_io_show", S_IRUGO | S_IWUGO, parent, - &proc_uidio_show_operations); - - return dir_entry; -} diff --git a/drivers/soc/oplus/lowmem_dbg/Kconfig b/drivers/soc/oplus/lowmem_dbg/Kconfig deleted file mode 100644 index 04c92334c388..000000000000 --- a/drivers/soc/oplus/lowmem_dbg/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config OPLUS_FEATURE_LOWMEM_DBG - bool "OPLUS Low Memory debug" - default n - help - print memory usage when low mem occurs. diff --git a/drivers/soc/oplus/lowmem_dbg/Makefile b/drivers/soc/oplus/lowmem_dbg/Makefile deleted file mode 100644 index ee4e584888cc..000000000000 --- a/drivers/soc/oplus/lowmem_dbg/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -# ifneq ($(OPLUS_FEATURE_LOWMEM_DBG),) disable this cause of some project not uses. -ifeq ($(PATCHLEVEL),) -$(error VERSION is not defined) -endif - -ifeq ($(PATCHLEVEL),) -$(error PATCHLEVEL is not defined) -endif - -CONFIG_KERVER_VERSION := $(VERSION).$(PATCHLEVEL) - -ifeq ($(CONFIG_KERVER_VERSION),5.4) -$(info lowmem_dbg mtk_ion use kernel $(CONFIG_KERVER_VERSION)) -obj-$(CONFIG_OPLUS_FEATURE_LOWMEM_DBG) += lowmem_dbg_5.4.o -else -$(info lowmem_dbg mtk_ion use kernel $(CONFIG_KERVER_VERSION)) -obj-$(CONFIG_OPLUS_FEATURE_LOWMEM_DBG) += lowmem_dbg.o -endif - - -# mtk -ifeq ($(CONFIG_MTK_ION), y) -$(info lowmem_dbg mtk_ion use kernel $(CONFIG_KERVER_VERSION)) -ifeq ($(CONFIG_KERVER_VERSION),4.19) -ccflags-$(CONFIG_MTK_ION) += -I$(srctree)/drivers/staging/android/mtk_ion/ -endif -ifeq ($(CONFIG_KERVER_VERSION),4.14) -ccflags-$(CONFIG_MTK_ION) += -I$(srctree)/drivers/staging/android/ion/ -endif -endif - -# qcom -ccflags-$(CONFIG_QCOM_KGSL) += -I$(srctree)/drivers/gpu/msm/ -# endif diff --git a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.c b/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.c deleted file mode 100755 index dc498eb4f804..000000000000 --- a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.c +++ /dev/null @@ -1,912 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "lowmem_dbg: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_OF_RESERVED_MEM -#include -#endif /* CONFIG_OF_RESERVED_MEM */ -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS -#include -#endif - -#include "../../../../mm/slab.h" - -#ifdef CONFIG_MTK_ION -#include "ion_priv.h" -#endif /* CONFIG_MTK_ION */ - -#ifdef CONFIG_QCOM_KGSL -#include "kgsl.h" -#endif /* CONFIG_QCOM_KGSL */ - -#define K(x) ((x) << (PAGE_SHIFT-10)) -extern unsigned long ion_total(void); - -static int lowmem_dbg_ram[] = { - 0, - 768 * 1024, /* 3GB */ - 1024 * 1024, /* 4GB */ -}; - -static int lowmem_dbg_low[] = { - 64 * 1024, /* 256MB */ - 128 * 1024, /* 512MB */ - 256 * 1024, /* 1024MB */ -}; - -static void lowmem_dbg_dump(struct work_struct *work); - -static DEFINE_MUTEX(lowmem_dump_mutex); -static DECLARE_WORK(lowmem_dbg_work, lowmem_dbg_dump); -static DECLARE_WORK(lowmem_dbg_critical_work, lowmem_dbg_dump); - -static int dump_tasks_info(bool verbose); -static int dump_ion(bool verbose); -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) -static int dump_slab(bool verbose); -#endif /* CONFIG_SLUB_DEBUG || CONFIG_SLUB_STAT_DEBUG */ -#if IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) -extern void mtk_dump_gpu_memory_usage(void) __attribute__((weak)); -extern bool mtk_get_gpu_memory_usage(unsigned int *pMemUsage); -static int dump_gpu(bool verbose) -{ - mtk_dump_gpu_memory_usage(); - return 0; -} -#endif /* CONFIG_MTK_GPU_SUPPORT */ - -enum mem_type { - MEM_ANON, - MEM_SLAB_UNRECLAIMABLE, - MEM_ION_USED, - MEM_GPU, - /* other stats start from here */ - MEM_TOTAL, - MEM_FREE, - MEM_AVAILABLE, - MEM_FILE, - MEM_ACTIVE_FILE, - MEM_INACTIVE_FILE, - MEM_ACTIVE_ANON, - MEM_INACTIVE_ANON, - MEM_PAGE_TABLES, - MEM_KERNEL_STACKS, - MEM_SLAB, - MEM_SLAB_RECLAIMABLE, - MEM_VMALLOC, - MEM_ION, - MEM_ION_CACHE, - MEM_DT_RESERVED, - MEM_ITEMS, -}; - -struct lowmem_dbg_cfg { - unsigned int dump_interval; - u64 last_jiffies; - u64 wm_low; - u64 wm_critical; - u64 wms[MEM_TOTAL]; -}; - -const char * const mem_type_text[] = { - "Anon", - "SlabUnreclaim", - "IONUsed", - "GPU", - /* other stats start from here */ - "Total", - "Free", - "Available", - "File", - "ActivFile", - "InactiveFile", - "AtiveAnon", - "InativeAnon", - "PageTable", - "KernelStack", - "Slab", - "SlabReclaim", - "Vmalloc", - "ION", - "IONCache", - "DTReserved", - "", -}; - -struct lowmem_dump_cfg { - enum mem_type type; - void (*dump)(bool); - bool (*critical)(void); -}; - -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS -#define NS_PER_MS 1000000 -#define KSWAPD_DEBUG_INFO_KBUF_LEN 4096 -static void dump_kswapd_debug_info(void) -{ - pg_data_t *pgdat; - int order; - struct kswapd_debug_entry *entry; - - for_each_online_pgdat(pgdat) { - pr_info("Node %d kswapd has run %lu ms %lu times:\n", - pgdat->node_id, - div_u64(atomic_long_read(&pgdat->kswapd_running_ns), NS_PER_MS), - atomic_long_read(&pgdat->kswapd_running_times)); - - entry = pgdat->kswapd_debug; - for (order=0; order<=MAX_ORDER; order++) - pr_info("order %4d %12lu %12lu ms\n", order, - atomic_long_read(&entry[order].cnt), - div_u64(atomic_long_read(&entry[order].runtime_ns), NS_PER_MS)); - } -} - -ssize_t kswapd_debug_info_read(struct file *file, char __user *buffer, - size_t count, loff_t *off) -{ - pg_data_t *pgdat; - int order; - struct kswapd_debug_entry *entry; - int len = 0; - int end; - char* kbuf = (char*)vmalloc(KSWAPD_DEBUG_INFO_KBUF_LEN); - - if (!kbuf) - return -ENOMEM; - - for_each_online_pgdat(pgdat) { - len += scnprintf(kbuf + len, KSWAPD_DEBUG_INFO_KBUF_LEN - len, - "Node %d kswapd has run %lu ms %lu times:\n", - pgdat->node_id, - div_u64(atomic_long_read(&pgdat->kswapd_running_ns), NS_PER_MS), - atomic_long_read(&pgdat->kswapd_running_times)); - - entry = pgdat->kswapd_debug; - for (order=0; order<=MAX_ORDER; order++) - len += scnprintf(kbuf + len, KSWAPD_DEBUG_INFO_KBUF_LEN - len, - "order %3d %10lu %10lu ms\n", order, - atomic_long_read(&entry[order].cnt), - div_u64(atomic_long_read(&entry[order].runtime_ns), NS_PER_MS)); - - } - - if (KSWAPD_DEBUG_INFO_KBUF_LEN == len) - end = KSWAPD_DEBUG_INFO_KBUF_LEN -1; - else - end = len; - if (kbuf[end] != '\n') - kbuf[end] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) { - vfree(kbuf); - return -EFAULT; - } - - vfree(kbuf); - *off += (len < count ? len : count); - return (len < count ? len : count); -} -#endif - -static long get_mem_usage_pages(enum mem_type type) -{ - int ret = 0; - switch(type) { - case MEM_TOTAL: - return totalram_pages; - case MEM_FREE: - ret = global_zone_page_state(NR_FREE_PAGES); - break; - case MEM_AVAILABLE: - ret = si_mem_available(); - break; - case MEM_FILE: - ret = global_node_page_state(NR_FILE_PAGES); - break; - case MEM_ACTIVE_FILE: - ret = global_node_page_state(NR_ACTIVE_FILE); - break; - case MEM_INACTIVE_FILE: - ret = global_node_page_state(NR_INACTIVE_FILE); - break; - case MEM_ANON: - ret = global_node_page_state(NR_ANON_MAPPED); - break; - case MEM_ACTIVE_ANON: - ret = global_node_page_state(NR_ACTIVE_ANON); - break; - case MEM_INACTIVE_ANON: - ret = global_node_page_state(NR_INACTIVE_ANON); - break; - case MEM_PAGE_TABLES: - ret = global_zone_page_state(NR_PAGETABLE); - break; - case MEM_KERNEL_STACKS: - ret = global_zone_page_state(NR_KERNEL_STACK_KB) / 4; - break; - case MEM_SLAB: - ret = global_node_page_state(NR_SLAB_RECLAIMABLE) + - global_node_page_state(NR_SLAB_UNRECLAIMABLE); - break; - case MEM_SLAB_RECLAIMABLE: - ret = global_node_page_state(NR_SLAB_RECLAIMABLE); - break; - case MEM_SLAB_UNRECLAIMABLE: - ret = global_node_page_state(NR_SLAB_UNRECLAIMABLE); - break; - case MEM_VMALLOC: - ret = vmalloc_nr_pages(); - break; - case MEM_ION: -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO - ret = (ion_total() >> PAGE_SHIFT) + - global_zone_page_state(NR_IONCACHE_PAGES); - break; -#endif -#endif - case MEM_ION_USED: -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO - ret = ion_total() >> PAGE_SHIFT; -#endif -#endif - break; - case MEM_ION_CACHE: -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO - ret = global_zone_page_state(NR_IONCACHE_PAGES); -#endif -#endif - break; - case MEM_GPU: -#ifdef CONFIG_QCOM_KGSL - ret = atomic_long_read(&kgsl_driver.stats.page_alloc) >> PAGE_SHIFT; -#elif IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) - mtk_get_gpu_memory_usage(&ret); - ret >>= PAGE_SHIFT; -#endif /* CONFIG_QCOM_KGSL */ - break; - case MEM_DT_RESERVED: -#ifdef CONFIG_OF_RESERVED_MEM - ret = dt_memory_reserved_pages(); -#endif /* CONFIG_OF_RESERVED_MEM */ - break; - case MEM_ITEMS: - break; - default: - break; - } - return ret; -} - -static inline int dump_mem_detail(enum mem_type type, bool verbose) -{ - int ret = -1; - switch(type) { - case MEM_SLAB: - case MEM_SLAB_RECLAIMABLE: - case MEM_SLAB_UNRECLAIMABLE: -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) - ret = dump_slab(verbose); -#endif /* CONFIG_SLUB_DEBUG || CONFIG_SLUB_STAT_DEBUG */ - break; - case MEM_ANON: - ret = dump_tasks_info(verbose); - break; - case MEM_ION_USED: - ret = dump_ion(verbose); - break; - case MEM_GPU: -#if IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) - ret = dump_gpu(verbose); -#endif /* CONFIG_MTK_GPU_SUPPORT */ - break; - default: - break; - } - return ret; -} - -static struct lowmem_dbg_cfg dbg_cfg; - -static void oplus_show_mem(void) -{ - pg_data_t *pgdat; - unsigned long total = 0, reserved = 0, highmem = 0; - long free, slab_rec, slab_unrec, vmalloc, anon, file, pagetbl, kernel_stack; - long ion_used, ion_cache, gpu, dt_reserved, unaccounted; - - show_free_areas(SHOW_MEM_FILTER_NODES, NULL); - - for_each_online_pgdat(pgdat) { - unsigned long flags; - int zoneid; - - pgdat_resize_lock(pgdat, &flags); - for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { - struct zone *zone = &pgdat->node_zones[zoneid]; - if (!populated_zone(zone)) - continue; - - total += zone->present_pages; - reserved += zone->present_pages - zone->managed_pages; - - if (is_highmem_idx(zoneid)) - highmem += zone->present_pages; - } - pgdat_resize_unlock(pgdat, &flags); - } - - printk("%lu pages RAM\n", total); - printk("%lu pages HighMem/MovableOnly\n", highmem); - printk("%lu pages reserved\n", reserved); -#ifdef CONFIG_CMA - printk("%lu pages cma reserved\n", totalcma_pages); -#endif -#ifdef CONFIG_QUICKLIST - printk("%lu pages in pagetable cache\n", - quicklist_total_size()); -#endif -#ifdef CONFIG_MEMORY_FAILURE - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); -#endif - total = get_mem_usage_pages(MEM_TOTAL); - free = get_mem_usage_pages(MEM_FREE); - slab_rec = get_mem_usage_pages(MEM_SLAB_RECLAIMABLE); - slab_unrec = get_mem_usage_pages(MEM_SLAB_UNRECLAIMABLE); - vmalloc = get_mem_usage_pages(MEM_VMALLOC); - anon = get_mem_usage_pages(MEM_ANON); - file = get_mem_usage_pages(MEM_FILE); - pagetbl = get_mem_usage_pages(MEM_PAGE_TABLES); - kernel_stack = get_mem_usage_pages(MEM_KERNEL_STACKS); - ion_used = get_mem_usage_pages(MEM_ION_USED); - ion_cache = get_mem_usage_pages(MEM_ION_CACHE); - gpu = get_mem_usage_pages(MEM_GPU); - dt_reserved = get_mem_usage_pages(MEM_DT_RESERVED); - - unaccounted = total - free - slab_rec - slab_unrec - vmalloc -anon - - file - pagetbl - kernel_stack - ion_used - ion_cache - gpu; - - pr_info("%s:%lukB %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "%s:%lukB %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "%s:%lukB %s:%lukB %s:%lukB Unaccounted:%lukB", - mem_type_text[MEM_TOTAL], K(total), - mem_type_text[MEM_FREE], K(free), - mem_type_text[MEM_SLAB_RECLAIMABLE], K(slab_rec), - mem_type_text[MEM_SLAB_UNRECLAIMABLE], K(slab_unrec), - mem_type_text[MEM_VMALLOC], K(vmalloc), - mem_type_text[MEM_ANON], K(anon), - mem_type_text[MEM_FILE], K(file), - mem_type_text[MEM_PAGE_TABLES], K(pagetbl), - mem_type_text[MEM_KERNEL_STACKS], K(kernel_stack), - mem_type_text[MEM_ION_USED], K(ion_used), - mem_type_text[MEM_ION_CACHE], K(ion_cache), - mem_type_text[MEM_GPU], K(gpu), - mem_type_text[MEM_DT_RESERVED], K(dt_reserved), - K(unaccounted)); -} - -static int dump_tasks_info(bool verbose) -{ - struct task_struct *p; - struct task_struct *tsk; - short tsk_oom_adj = 0; - unsigned long tsk_nr_ptes = 0; - char task_state = 0; - char frozen_mark = ' '; - short service_adj = 500; - u64 wm_task_rss = SZ_256M >> PAGE_SHIFT; - - pr_info("[ pid ] uid tgid total_vm rss nptes swap sheme adj s name\n"); - - rcu_read_lock(); - for_each_process(p) { - tsk = find_lock_task_mm(p); - if (!tsk) { - /* - * This is a kthread or all of p's threads have already - * detached their mm's. There's no need to report - * them; they can't be oom killed anyway. - */ - continue; - } - - tsk_oom_adj = tsk->signal->oom_score_adj; - - if (!verbose && tsk_oom_adj && - (tsk_oom_adj <= service_adj) && - (get_mm_rss(tsk->mm) + - get_mm_counter(tsk->mm, MM_SWAPENTS)) < wm_task_rss) { - task_unlock(tsk); - continue; - } - - /* consolidate page table accounting */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) - tsk_nr_ptes = PTRS_PER_PTE * sizeof(pte_t) * atomic_long_read(&tsk->mm->nr_ptes); -#else - tsk_nr_ptes = mm_pgtables_bytes(tsk->mm); -#endif - task_state = task_state_to_char(tsk); - /* check whether we have freezed a task. */ - frozen_mark = frozen(tsk) ? '*' : ' '; - - pr_info("[%5d] %5d %5d %8lu %8lu %8lu %8lu %8lu %5hd %c %s%c\n", - tsk->pid, - from_kuid(&init_user_ns, task_uid(tsk)), - tsk->tgid, tsk->mm->total_vm, - get_mm_rss(tsk->mm), - tsk_nr_ptes / SZ_1K, - get_mm_counter(tsk->mm, MM_SWAPENTS), - get_mm_counter(tsk->mm, MM_SHMEMPAGES), - tsk_oom_adj, - task_state, - tsk->comm, - frozen_mark); - task_unlock(tsk); - } - rcu_read_unlock(); - return 0; -} - -#ifdef CONFIG_MTK_ION -extern struct ion_device *g_ion_device; -static int dump_ion(bool verbose) -{ - struct ion_device *dev = g_ion_device; - struct rb_node *n, *m; - unsigned int buffer_size = 0; - size_t total_orphaned_size = 0; - size_t total_size = 0; - -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) { -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - if (!down_read_trylock(&dev->lock)) { -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - return -1; - } - for (n = rb_first(&dev->clients); n; n = rb_next(n)) { - struct ion_client *client = - rb_entry(n, struct ion_client, node); - char task_comm[TASK_COMM_LEN]; - - if (client->task) { - get_task_comm(task_comm, client->task); - } - - mutex_lock(&client->lock); - for (m = rb_first(&client->handles); m; m = rb_next(m)) { - struct ion_handle *handle = rb_entry(m, struct ion_handle, - node); - buffer_size += (unsigned int)(handle->buffer->size); - } - if (!buffer_size) { - mutex_unlock(&client->lock); - continue; - } - pr_info("[%-5d] %-8d %-16s %-16s\n", - client->pid, - buffer_size / SZ_1K, - client->task ? task_comm : "from_kernel", - (*client->dbg_name) ? client->dbg_name : client->name); - buffer_size = 0; - mutex_unlock(&client->lock); - } - - pr_info("orphaned allocation (info is from last known client):\n"); - mutex_lock(&dev->buffer_lock); - for (n = rb_first(&dev->buffers); n; n = rb_next(n)) { - struct ion_buffer *buffer = rb_entry(n, struct ion_buffer, - node); - total_size += buffer->size; - if (!buffer->handle_count) { - pr_info("[%-5d] %-8d %-16s 0x%p %d %d\n", - buffer->pid, - buffer->size / SZ_1K, - buffer->task_comm, - buffer, - buffer->kmap_cnt, - atomic_read(&buffer->ref.refcount.refs)); - total_orphaned_size += buffer->size; - } - } - mutex_unlock(&dev->buffer_lock); - pr_info("orphaned: %zu total: %zu\n", - total_orphaned_size, total_size); - -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - return 0; -} -#else /* CONFIG_MTK_ION */ -struct dma_info { - struct task_struct *tsk; - bool verbose; - size_t sz; -}; - -static int acct_dma_dize(const void *data, struct file *file, - unsigned int n) -{ - struct dma_info *dmainfo = (struct dma_info *)data; - struct dma_buf *dbuf; - - if (!oplus_is_dma_buf_file(file)) { - return 0; - } - - dbuf = file->private_data; - if (dbuf->size && dmainfo->verbose) { - pr_info("%s:%ldkB\n", - dbuf->buf_name, - dbuf->size / SZ_1K); - } - - dmainfo->sz += dbuf->size; - return 0; -} - -static int dump_ion(bool verbose) -{ - struct task_struct *task, *thread; - struct files_struct *files; - int ret = 0; - - rcu_read_lock(); - for_each_process(task) { - struct files_struct *group_leader_files = NULL; - struct dma_info dmainfo = { - .verbose = verbose, - .sz = 0, - }; - - for_each_thread(task, thread) { - task_lock(thread); - if (unlikely(!group_leader_files)) { - group_leader_files = task->group_leader->files; - } - - files = thread->files; - if (files && (group_leader_files != files || - thread == task->group_leader)) { - dmainfo.tsk = thread; - ret = iterate_fd(files, 0, acct_dma_dize, - &dmainfo); - } - task_unlock(thread); - } - - if (ret || !dmainfo.sz) { - continue; - } - - pr_info("%s (PID:%d) size:%lukB\n", - task->comm, task->pid, dmainfo.sz / SZ_1K); - } - rcu_read_unlock(); - return 0; -} -#endif /* CONFIG_MTK_ION */ - -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) -static int dump_slab(bool verbose) -{ - if (likely(!verbose)) { - unsigned long slab_pages = 0; - struct kmem_cache *cachep = NULL; - struct kmem_cache *max_cachep = NULL; - struct kmem_cache *prev_max_cachep = NULL; - - mutex_lock(&slab_mutex); - list_for_each_entry(cachep, &slab_caches, list) { - struct slabinfo sinfo; - unsigned long scratch; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - scratch = sinfo.num_slabs << sinfo.cache_order; - - if (slab_pages < scratch) { - slab_pages = scratch; - prev_max_cachep = max_cachep; - max_cachep = cachep; - } - } - - if (max_cachep || prev_max_cachep) { - pr_info("name : tunables : slabdata "); - } - - if (max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - /* TODO maybe we can cache slabinfo to achieve - * better performance */ - get_slabinfo(max_cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - max_cachep->name, sinfo.active_objs, - sinfo.num_objs, max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - - if (prev_max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - /* TODO maybe we can cache slabinfo to achieve - * better performance */ - get_slabinfo(prev_max_cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - prev_max_cachep->name, sinfo.active_objs, - sinfo.num_objs, prev_max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - mutex_unlock(&slab_mutex); - - } else { - struct kmem_cache *cachep = NULL; - - pr_info("# name : tunables : slabdata "); - - mutex_lock(&slab_mutex); - list_for_each_entry(cachep, &slab_caches, list) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - cachep->name, sinfo.active_objs, - sinfo.num_objs, cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - mutex_unlock(&slab_mutex); - } - return 0; -} -#endif /* CONFIG_SLUB_DEBUG && CONFIG_SLUB_STAT_DEBUG */ - - -static void lowmem_dbg_dump(struct work_struct *work) -{ - bool critical = (work == &lowmem_dbg_critical_work); - int i = 0; - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - mutex_lock(&lowmem_dump_mutex); - pr_info("dump start avail:%lukB critical:%d\n", - K(get_mem_usage_pages(MEM_AVAILABLE)), critical); - oplus_show_mem(); - for (i = MEM_ANON; i < MEM_TOTAL; i++) { - long usage = get_mem_usage_pages(i); - const char *text = mem_type_text[i]; - if (usage <= 0) { - pr_warn("not suport %s stats", text); - continue; - } - pr_info("dump [%s] usage:%lukB above_watermark:%d\n", - text, K(usage), pcfg->wms[i] < usage); - dump_mem_detail(i, critical ? true : pcfg->wms[i] < usage); - pr_info("dump [%s] end.\n", text); - } -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS - dump_kswapd_debug_info(); -#endif - pr_info("dump end\n"); - -#ifdef CONFIG_MTK_ION - if (K(get_mem_usage_pages(MEM_ION_USED)) > 3670016) - ion_mm_heap_memory_detail(); -#endif - - mutex_unlock(&lowmem_dump_mutex); -} - -void oplus_lowmem_dbg(bool critical) -{ - u64 now = get_jiffies_64(); - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - if (time_before64(now, (pcfg->last_jiffies + pcfg->dump_interval))) - return; - - pcfg->last_jiffies = now; - if (unlikely(critical)) { - schedule_work(&lowmem_dbg_critical_work); - } else { - schedule_work(&lowmem_dbg_work); - } -} - -static unsigned long lowmem_count(struct shrinker *s, - struct shrink_control *sc) -{ - return global_node_page_state(NR_ACTIVE_ANON) + - global_node_page_state(NR_ACTIVE_FILE) + - global_node_page_state(NR_INACTIVE_ANON) + - global_node_page_state(NR_INACTIVE_FILE); -} - -static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) -{ - static atomic_t atomic_lmk = ATOMIC_INIT(0); - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - long avail = get_mem_usage_pages(MEM_AVAILABLE); - - if (avail > pcfg->wm_low) - return 0; - - if (atomic_inc_return(&atomic_lmk) > 1) { - atomic_dec(&atomic_lmk); - return 0; - } - - oplus_lowmem_dbg(avail <= pcfg->wm_critical); - atomic_dec(&atomic_lmk); - return 0; -} - -static struct shrinker lowmem_shrinker = { - .scan_objects = lowmem_scan, - .count_objects = lowmem_count, - .seeks = DEFAULT_SEEKS -}; - -static __init int oplus_lowmem_dbg_init(void) -{ - int ret, i; - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - /* This is a process holding an application service */ - pcfg->dump_interval = 15 * HZ; - - /* init watermark */ - pcfg->wms[MEM_ION_USED] = SZ_2G >> PAGE_SHIFT; - pcfg->wms[MEM_ANON] = totalram_pages / 2; - pcfg->wms[MEM_SLAB_UNRECLAIMABLE] = SZ_1G >> PAGE_SHIFT; - pcfg->wms[MEM_GPU] = SZ_2G >> PAGE_SHIFT; - pcfg->wm_low = lowmem_dbg_low[0]; - for (i = ARRAY_SIZE(lowmem_dbg_ram) - 1; i >= 0; i--) { - if (totalram_pages >= lowmem_dbg_ram[i]) { - pcfg->wm_low = lowmem_dbg_low[i]; - break; - } - } - pcfg->wm_critical = pcfg->wm_low / 2; - - if (totalram_pages < lowmem_dbg_ram[1]) - pcfg->wm_critical = pcfg->wm_low; - - ret = register_shrinker(&lowmem_shrinker); - - pr_info("init watermark %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "Low %lukB Critical %lukB", - mem_type_text[MEM_ANON], K(pcfg->wms[MEM_ANON]), - mem_type_text[MEM_SLAB_UNRECLAIMABLE], - K(pcfg->wms[MEM_SLAB_UNRECLAIMABLE]), - mem_type_text[MEM_ION_USED], K(pcfg->wms[MEM_ION_USED]), - mem_type_text[MEM_GPU], K(pcfg->wms[MEM_GPU]), - K(pcfg->wm_low), K(pcfg->wm_critical)); - return 0; -} -device_initcall(oplus_lowmem_dbg_init); - -#ifdef LOWMEM_DBG_DEBUG -static ssize_t oplus_lowmem_dbg_test_write(struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[13]; - int err, critical; - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtoint(strstrip(buffer), 0, &critical); - if(err) - return err; - - oplus_lowmem_dbg(critical); - return count; -} - -static int oplus_lowmem_dbg_test_open(struct inode *inode, struct file *filp) -{ - return 0; -} - -static const struct file_operations lowmem_dbg_test_operations = { - .open = oplus_lowmem_dbg_test_open, - .write = oplus_lowmem_dbg_test_write, -}; - -static __init int oplus_lowmem_dbg_test_init(void) -{ - proc_create("lowmem_dbg_test", S_IWUGO, NULL, - &lowmem_dbg_test_operations); - return 0; -} -fs_initcall(oplus_lowmem_dbg_test_init); -#endif - -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS -static const struct file_operations kswapd_debug_operations = { - .read = kswapd_debug_info_read, -}; - -int kswapd_debug_init(struct proc_dir_entry *parent) -{ - struct proc_dir_entry *entry; - - if (!parent) { - pr_warn("%s: parent is NULL\n", __func__); - return -EINVAL; - } - - entry = proc_create("kswapd_debug", S_IRUGO, parent, &kswapd_debug_operations); - if (!entry) { - pr_warn("%s: create kswapd_debug failed.\n", __func__); - return -ENOMEM; - } - - return 0; -} -#endif diff --git a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.h b/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.h deleted file mode 100644 index fd07654302b2..000000000000 --- a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef __LOWMEM_DBG_H -#define __LOWMEM_DBG_H -#include -#include - -void oplus_lowmem_dbg(bool critical); - -#ifndef CONFIG_MTK_ION -inline int oplus_is_dma_buf_file(struct file *file); -#endif /* CONFIG_MTK_ION */ -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS -int kswapd_debug_init(struct proc_dir_entry *parent); -#endif - -#endif /* __LOWMEM_DBG_H */ diff --git a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg_5.4.c b/drivers/soc/oplus/lowmem_dbg/lowmem_dbg_5.4.c deleted file mode 100755 index 80c1a227b526..000000000000 --- a/drivers/soc/oplus/lowmem_dbg/lowmem_dbg_5.4.c +++ /dev/null @@ -1,784 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) "lowmem_dbg: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_QUICKLIST -#include -#endif -#ifdef CONFIG_OF_RESERVED_MEM -#include -#endif /* CONFIG_OF_RESERVED_MEM */ - -#include "../../../../mm/slab.h" -#include - -#ifdef CONFIG_MTK_ION -#include "ion_priv.h" -#endif /* CONFIG_MTK_ION */ - -#ifdef CONFIG_QCOM_KGSL -#include "kgsl.h" -#endif /* CONFIG_QCOM_KGSL */ - -#define K(x) ((x) << (PAGE_SHIFT-10)) -extern unsigned long ion_total(void); -static int lowmem_dbg_ram[] = { - 0, - 768 * 1024, /* 3GB */ - 1024 * 1024, /* 4GB */ -}; - -static int lowmem_dbg_low[] = { - 64 * 1024, /* 256MB */ - 128 * 1024, /* 512MB */ - 256 * 1024, /* 1024MB */ -}; - -static void lowmem_dbg_dump(struct work_struct *work); - -static DEFINE_MUTEX(lowmem_dump_mutex); -static DECLARE_WORK(lowmem_dbg_work, lowmem_dbg_dump); -static DECLARE_WORK(lowmem_dbg_critical_work, lowmem_dbg_dump); - -static int dump_tasks_info(bool verbose); -static int dump_ion(bool verbose); -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) -static int dump_slab(bool verbose); -#endif /* CONFIG_SLUB_DEBUG || CONFIG_SLUB_STAT_DEBUG */ -#if IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) -extern void mtk_dump_gpu_memory_usage(void) __attribute__((weak)); -extern bool mtk_get_gpu_memory_usage(unsigned int *pMemUsage); -static int dump_gpu(bool verbose) -{ - mtk_dump_gpu_memory_usage(); - return 0; -} -#endif /* CONFIG_MTK_GPU_SUPPORT */ - -enum mem_type { - MEM_ANON, - MEM_SLAB_UNRECLAIMABLE, - MEM_ION_USED, - MEM_GPU, - /* other stats start from here */ - MEM_TOTAL, - MEM_FREE, - MEM_AVAILABLE, - MEM_FILE, - MEM_ACTIVE_FILE, - MEM_INACTIVE_FILE, - MEM_ACTIVE_ANON, - MEM_INACTIVE_ANON, - MEM_PAGE_TABLES, - MEM_KERNEL_STACKS, - MEM_SLAB, - MEM_SLAB_RECLAIMABLE, - MEM_VMALLOC, - MEM_ION, - MEM_ION_CACHE, - MEM_DT_RESERVED, - MEM_ITEMS, -}; - -struct lowmem_dbg_cfg { - unsigned int dump_interval; - u64 last_jiffies; - u64 wm_low; - u64 wm_critical; - u64 wms[MEM_TOTAL]; -}; - -const char * const mem_type_text[] = { - "Anon", - "SlabUnreclaim", - "IONUsed", - "GPU", - /* other stats start from here */ - "Total", - "Free", - "Available", - "File", - "ActivFile", - "InactiveFile", - "AtiveAnon", - "InativeAnon", - "PageTable", - "KernelStack", - "Slab", - "SlabReclaim", - "Vmalloc", - "ION", - "IONCache", - "DTReserved", - "", -}; - -struct lowmem_dump_cfg { - enum mem_type type; - void (*dump)(bool); - bool (*critical)(void); -}; - -static long get_mem_usage_pages(enum mem_type type) -{ - int ret = 0; - switch(type) { - case MEM_TOTAL: - return totalram_pages(); - case MEM_FREE: - ret = global_zone_page_state(NR_FREE_PAGES); - break; - case MEM_AVAILABLE: - ret = si_mem_available(); - break; - case MEM_FILE: - ret = global_node_page_state(NR_FILE_PAGES); - break; - case MEM_ACTIVE_FILE: - ret = global_node_page_state(NR_ACTIVE_FILE); - break; - case MEM_INACTIVE_FILE: - ret = global_node_page_state(NR_INACTIVE_FILE); - break; - case MEM_ANON: - ret = global_node_page_state(NR_ANON_MAPPED); - break; - case MEM_ACTIVE_ANON: - ret = global_node_page_state(NR_ACTIVE_ANON); - break; - case MEM_INACTIVE_ANON: - ret = global_node_page_state(NR_INACTIVE_ANON); - break; - case MEM_PAGE_TABLES: - ret = global_zone_page_state(NR_PAGETABLE); - break; - case MEM_KERNEL_STACKS: - ret = global_zone_page_state(NR_KERNEL_STACK_KB) / 4; - break; - case MEM_SLAB: - ret = global_node_page_state(NR_SLAB_RECLAIMABLE) + - global_node_page_state(NR_SLAB_UNRECLAIMABLE); - break; - case MEM_SLAB_RECLAIMABLE: - ret = global_node_page_state(NR_SLAB_RECLAIMABLE); - break; - case MEM_SLAB_UNRECLAIMABLE: - ret = global_node_page_state(NR_SLAB_UNRECLAIMABLE); - break; - case MEM_VMALLOC: - ret = vmalloc_nr_pages(); - break; - case MEM_ION: -#ifdef OPLUS_FEATURE_HEALTHINFO - ret = (ion_total() >> PAGE_SHIFT) + - global_zone_page_state(NR_IONCACHE_PAGES); - break; -#endif - case MEM_ION_USED: -#ifdef OPLUS_FEATURE_HEALTHINFO - ret = ion_total() >> PAGE_SHIFT; -#endif - break; - case MEM_ION_CACHE: -#ifdef OPLUS_FEATURE_HEALTHINFO - ret = global_zone_page_state(NR_IONCACHE_PAGES); -#endif - break; - case MEM_GPU: -#ifdef CONFIG_QCOM_KGSL - ret = atomic_long_read(&kgsl_driver.stats.page_alloc) >> PAGE_SHIFT; -#elif IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) - mtk_get_gpu_memory_usage(&ret); - ret >>= PAGE_SHIFT; -#endif /* CONFIG_QCOM_KGSL */ - break; - case MEM_DT_RESERVED: -#ifdef CONFIG_OF_RESERVED_MEM - ret = dt_memory_reserved_pages(); -#endif /* CONFIG_OF_RESERVED_MEM */ - break; - case MEM_ITEMS: - break; - default: - break; - } - return ret; -} - -static inline int dump_mem_detail(enum mem_type type, bool verbose) -{ - int ret = -1; - switch(type) { - case MEM_SLAB: - case MEM_SLAB_RECLAIMABLE: - case MEM_SLAB_UNRECLAIMABLE: -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) - ret = dump_slab(verbose); -#endif /* CONFIG_SLUB_DEBUG || CONFIG_SLUB_STAT_DEBUG */ - break; - case MEM_ANON: - ret = dump_tasks_info(1); - break; - case MEM_ION_USED: - ret = dump_ion(verbose); - break; - case MEM_GPU: -#if IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) - ret = dump_gpu(verbose); -#endif /* CONFIG_MTK_GPU_SUPPORT */ - break; - default: - break; - } - return ret; -} - -static struct lowmem_dbg_cfg dbg_cfg; - -static void oplus_show_mem(void) -{ - pg_data_t *pgdat; - unsigned long total = 0, reserved = 0, highmem = 0; - long free, slab_rec, slab_unrec, vmalloc, anon, file, pagetbl, kernel_stack; - long ion_used, ion_cache, gpu, dt_reserved, unaccounted; - - show_free_areas(SHOW_MEM_FILTER_NODES, NULL); - - for_each_online_pgdat(pgdat) { - unsigned long flags; - int zoneid; - - pgdat_resize_lock(pgdat, &flags); - for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { - struct zone *zone = &pgdat->node_zones[zoneid]; - if (!populated_zone(zone)) - continue; - - total += zone->present_pages; - reserved += zone->present_pages - zone_managed_pages(zone); - - if (is_highmem_idx(zoneid)) - highmem += zone->present_pages; - } - pgdat_resize_unlock(pgdat, &flags); - } - - printk("%lu pages RAM\n", total); - printk("%lu pages HighMem/MovableOnly\n", highmem); - printk("%lu pages reserved\n", reserved); -#ifdef CONFIG_CMA - printk("%lu pages cma reserved\n", totalcma_pages); -#endif -#ifdef CONFIG_QUICKLIST - printk("%lu pages in pagetable cache\n", - quicklist_total_size()); -#endif -#ifdef CONFIG_MEMORY_FAILURE - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); -#endif - total = get_mem_usage_pages(MEM_TOTAL); - free = get_mem_usage_pages(MEM_FREE); - slab_rec = get_mem_usage_pages(MEM_SLAB_RECLAIMABLE); - slab_unrec = get_mem_usage_pages(MEM_SLAB_UNRECLAIMABLE); - vmalloc = get_mem_usage_pages(MEM_VMALLOC); - anon = get_mem_usage_pages(MEM_ANON); - file = get_mem_usage_pages(MEM_FILE); - pagetbl = get_mem_usage_pages(MEM_PAGE_TABLES); - kernel_stack = get_mem_usage_pages(MEM_KERNEL_STACKS); - ion_used = get_mem_usage_pages(MEM_ION_USED); - ion_cache = get_mem_usage_pages(MEM_ION_CACHE); - gpu = get_mem_usage_pages(MEM_GPU); - dt_reserved = get_mem_usage_pages(MEM_DT_RESERVED); - - unaccounted = total - free - slab_rec - slab_unrec - vmalloc -anon - - file - pagetbl - kernel_stack - ion_used - ion_cache - gpu; - - pr_info("%s:%lukB %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "%s:%lukB %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "%s:%lukB %s:%lukB %s:%lukB Unaccounted:%lukB", - mem_type_text[MEM_TOTAL], K(total), - mem_type_text[MEM_FREE], K(free), - mem_type_text[MEM_SLAB_RECLAIMABLE], K(slab_rec), - mem_type_text[MEM_SLAB_UNRECLAIMABLE], K(slab_unrec), - mem_type_text[MEM_VMALLOC], K(vmalloc), - mem_type_text[MEM_ANON], K(anon), - mem_type_text[MEM_FILE], K(file), - mem_type_text[MEM_PAGE_TABLES], K(pagetbl), - mem_type_text[MEM_KERNEL_STACKS], K(kernel_stack), - mem_type_text[MEM_ION_USED], K(ion_used), - mem_type_text[MEM_ION_CACHE], K(ion_cache), - mem_type_text[MEM_GPU], K(gpu), - mem_type_text[MEM_DT_RESERVED], K(dt_reserved), - K(unaccounted)); -} - -static int dump_tasks_info(bool verbose) -{ - struct task_struct *p; - struct task_struct *tsk; - short tsk_oom_adj = 0; - unsigned long tsk_nr_ptes = 0; - char task_state = 0; - char frozen_mark = ' '; - short service_adj = 500; - u64 wm_task_rss = SZ_256M >> PAGE_SHIFT; - - pr_info("[ pid ] uid tgid total_vm rss nptes swap sheme adj s name\n"); - - rcu_read_lock(); - for_each_process(p) { - tsk = find_lock_task_mm(p); - if (!tsk) { - /* - * This is a kthread or all of p's threads have already - * detached their mm's. There's no need to report - * them; they can't be oom killed anyway. - */ - continue; - } - - tsk_oom_adj = tsk->signal->oom_score_adj; - - if (!verbose && tsk_oom_adj && - (tsk_oom_adj <= service_adj) && - (get_mm_rss(tsk->mm) + - get_mm_counter(tsk->mm, MM_SWAPENTS)) < wm_task_rss) { - task_unlock(tsk); - continue; - } - - /* consolidate page table accounting */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) - tsk_nr_ptes = PTRS_PER_PTE * sizeof(pte_t) * atomic_long_read(&tsk->mm->nr_ptes); -#else - tsk_nr_ptes = mm_pgtables_bytes(tsk->mm); -#endif - task_state = task_state_to_char(tsk); - /* check whether we have freezed a task. */ - frozen_mark = frozen(tsk) ? '*' : ' '; - - pr_info("[%5d] %5d %5d %8lu %8lu %8lu %8lu %8lu %5hd %c %s%c\n", - tsk->pid, - from_kuid(&init_user_ns, task_uid(tsk)), - tsk->tgid, tsk->mm->total_vm, - get_mm_rss(tsk->mm), - tsk_nr_ptes / SZ_1K, - get_mm_counter(tsk->mm, MM_SWAPENTS), - get_mm_counter(tsk->mm, MM_SHMEMPAGES), - tsk_oom_adj, - task_state, - tsk->comm, - frozen_mark); - task_unlock(tsk); - } - rcu_read_unlock(); - return 0; -} - -#ifdef CONFIG_MTK_ION -extern struct ion_device *g_ion_device; -static int dump_ion(bool verbose) -{ - struct ion_device *dev = g_ion_device; - struct rb_node *n, *m; - unsigned int buffer_size = 0; - size_t total_orphaned_size = 0; - size_t total_size = 0; - - if (!down_read_trylock(&dev->lock)) { - return -1; - } - for (n = rb_first(&dev->clients); n; n = rb_next(n)) { - struct ion_client *client = - rb_entry(n, struct ion_client, node); - char task_comm[TASK_COMM_LEN]; - - if (client->task) { - get_task_comm(task_comm, client->task); - } - - mutex_lock(&client->lock); - for (m = rb_first(&client->handles); m; m = rb_next(m)) { - struct ion_handle *handle = rb_entry(m, struct ion_handle, - node); - buffer_size += (unsigned int)(handle->buffer->size); - } - if (!buffer_size) { - mutex_unlock(&client->lock); - continue; - } - pr_info("[%-5d] %-8d %-16s %-16s\n", - client->pid, - buffer_size / SZ_1K, - client->task ? task_comm : "from_kernel", - (*client->dbg_name) ? client->dbg_name : client->name); - buffer_size = 0; - mutex_unlock(&client->lock); - } - - pr_info("orphaned allocation (info is from last known client):\n"); - mutex_lock(&dev->buffer_lock); - for (n = rb_first(&dev->buffers); n; n = rb_next(n)) { - struct ion_buffer *buffer = rb_entry(n, struct ion_buffer, - node); - total_size += buffer->size; - if (!buffer->handle_count) { - pr_info("[%-5d] %-8d %-16s 0x%p %d %d\n", - buffer->pid, - buffer->size / SZ_1K, - buffer->task_comm, - buffer, - buffer->kmap_cnt, - atomic_read(&buffer->ref.refcount.refs)); - total_orphaned_size += buffer->size; - } - } - mutex_unlock(&dev->buffer_lock); - pr_info("orphaned: %zu total: %zu\n", - total_orphaned_size, total_size); - - up_read(&dev->lock); - return 0; -} -#else /* CONFIG_MTK_ION */ -struct dma_info { - struct task_struct *tsk; - bool verbose; - size_t sz; -}; - -static int acct_dma_dize(const void *data, struct file *file, - unsigned int n) -{ - struct dma_info *dmainfo = (struct dma_info *)data; - struct dma_buf *dbuf; - - if (!oplus_is_dma_buf_file(file)) { - return 0; - } - - dbuf = file->private_data; - if (dbuf->size && dmainfo->verbose) { - pr_info("%ld:%ldkB\n", - file_inode(dbuf->file)->i_ino, - dbuf->size / SZ_1K); - } - - dmainfo->sz += dbuf->size; - return 0; -} - -static int dump_ion(bool verbose) -{ - struct task_struct *task, *thread; - struct files_struct *files; - int ret = 0; - - rcu_read_lock(); - for_each_process(task) { - struct files_struct *group_leader_files = NULL; - struct dma_info dmainfo = { - .verbose = verbose, - .sz = 0, - }; - - for_each_thread(task, thread) { - task_lock(thread); - if (unlikely(!group_leader_files)) { - group_leader_files = task->group_leader->files; - } - - files = thread->files; - if (files && (group_leader_files != files || - thread == task->group_leader)) { - dmainfo.tsk = thread; - ret = iterate_fd(files, 0, acct_dma_dize, - &dmainfo); - } - task_unlock(thread); - } - - if (ret || !dmainfo.sz) { - continue; - } - - pr_info("%s (PID:%d) size:%lukB\n", - task->comm, task->pid, dmainfo.sz / SZ_1K); - } - rcu_read_unlock(); - return 0; -} -#endif /* CONFIG_MTK_ION */ - -#if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SLUB_STAT_DEBUG) -static int dump_slab(bool verbose) -{ - if (likely(!verbose)) { - unsigned long slab_pages = 0; - struct kmem_cache *cachep = NULL; - struct kmem_cache *max_cachep = NULL; - struct kmem_cache *prev_max_cachep = NULL; - - mutex_lock(&slab_mutex); - list_for_each_entry(cachep, &slab_caches, list) { - struct slabinfo sinfo; - unsigned long scratch; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - scratch = sinfo.num_slabs << sinfo.cache_order; - - if (slab_pages < scratch) { - slab_pages = scratch; - prev_max_cachep = max_cachep; - max_cachep = cachep; - } - } - - if (max_cachep || prev_max_cachep) { - pr_info("name : tunables : slabdata "); - } - - if (max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - /* TODO maybe we can cache slabinfo to achieve - * better performance */ - get_slabinfo(max_cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - max_cachep->name, sinfo.active_objs, - sinfo.num_objs, max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - - if (prev_max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - /* TODO maybe we can cache slabinfo to achieve - * better performance */ - get_slabinfo(prev_max_cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - prev_max_cachep->name, sinfo.active_objs, - sinfo.num_objs, prev_max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - mutex_unlock(&slab_mutex); - - } else { - struct kmem_cache *cachep = NULL; - - pr_info("# name : tunables : slabdata "); - - mutex_lock(&slab_mutex); - list_for_each_entry(cachep, &slab_caches, list) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - - pr_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - cachep->name, sinfo.active_objs, - sinfo.num_objs, cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - mutex_unlock(&slab_mutex); - } - return 0; -} -#endif /* CONFIG_SLUB_DEBUG && CONFIG_SLUB_STAT_DEBUG */ - - -static void lowmem_dbg_dump(struct work_struct *work) -{ - bool critical = (work == &lowmem_dbg_critical_work); - int i = 0; - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - mutex_lock(&lowmem_dump_mutex); - pr_info("dump start avail:%lukB critical:%d\n", - K(get_mem_usage_pages(MEM_AVAILABLE)), critical); - oplus_show_mem(); - for (i = MEM_ANON; i < MEM_TOTAL; i++) { - long usage = get_mem_usage_pages(i); - const char *text = mem_type_text[i]; - if (usage <= 0) { - pr_warn("not suport %s stats", text); - continue; - } - pr_info("dump [%s] usage:%lukB above_watermark:%d\n", - text, K(usage), pcfg->wms[i] < usage); - dump_mem_detail(i, critical ? true : pcfg->wms[i] < usage); - pr_info("dump [%s] end.\n", text); - } - pr_info("dump end\n"); - mutex_unlock(&lowmem_dump_mutex); -} - -void oplus_lowmem_dbg(bool critical) -{ - u64 now = get_jiffies_64(); - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - if (time_before64(now, (pcfg->last_jiffies + pcfg->dump_interval))) - return; - - pcfg->last_jiffies = now; - if (unlikely(critical)) { - schedule_work(&lowmem_dbg_critical_work); - } else { - schedule_work(&lowmem_dbg_work); - } -} - -static unsigned long lowmem_count(struct shrinker *s, - struct shrink_control *sc) -{ - return global_node_page_state(NR_ACTIVE_ANON) + - global_node_page_state(NR_ACTIVE_FILE) + - global_node_page_state(NR_INACTIVE_ANON) + - global_node_page_state(NR_INACTIVE_FILE); -} - -static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) -{ - static atomic_t atomic_lmk = ATOMIC_INIT(0); - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - long avail = get_mem_usage_pages(MEM_AVAILABLE); - - if (avail > pcfg->wm_low) - return 0; - - if (atomic_inc_return(&atomic_lmk) > 1) { - atomic_dec(&atomic_lmk); - return 0; - } - - oplus_lowmem_dbg(avail <= pcfg->wm_critical); - atomic_dec(&atomic_lmk); - return 0; -} - -static struct shrinker lowmem_shrinker = { - .scan_objects = lowmem_scan, - .count_objects = lowmem_count, - .seeks = DEFAULT_SEEKS -}; - -static __init int oplus_lowmem_dbg_init(void) -{ - int ret, i; - struct lowmem_dbg_cfg *pcfg = &dbg_cfg; - - /* This is a process holding an application service */ - pcfg->dump_interval = 15 * HZ; - - /* init watermark */ - pcfg->wms[MEM_ION_USED] = SZ_2G >> PAGE_SHIFT; - pcfg->wms[MEM_ANON] = totalram_pages()/ 2; - pcfg->wms[MEM_SLAB_UNRECLAIMABLE] = SZ_1G >> PAGE_SHIFT; - pcfg->wms[MEM_GPU] = SZ_2G >> PAGE_SHIFT; - pcfg->wm_low = lowmem_dbg_low[0]; - for (i = ARRAY_SIZE(lowmem_dbg_ram) - 1; i >= 0; i--) { - if (totalram_pages() >= lowmem_dbg_ram[i]) { - pcfg->wm_low = lowmem_dbg_low[i]; - break; - } - } - pcfg->wm_critical = pcfg->wm_low / 2; - ret = register_shrinker(&lowmem_shrinker); - - pr_info("init watermark %s:%lukB %s:%lukB %s:%lukB %s:%lukB " - "Low %lukB Critical %lukB", - mem_type_text[MEM_ANON], K(pcfg->wms[MEM_ANON]), - mem_type_text[MEM_SLAB_UNRECLAIMABLE], - K(pcfg->wms[MEM_SLAB_UNRECLAIMABLE]), - mem_type_text[MEM_ION_USED], K(pcfg->wms[MEM_ION_USED]), - mem_type_text[MEM_GPU], K(pcfg->wms[MEM_GPU]), - K(pcfg->wm_low), K(pcfg->wm_critical)); - return 0; -} -device_initcall(oplus_lowmem_dbg_init); - -#ifdef LOWMEM_DBG_DEBUG -static ssize_t oplus_lowmem_dbg_test_write(struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[13]; - int err, critical; - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtoint(strstrip(buffer), 0, &critical); - if(err) - return err; - - oplus_lowmem_dbg(critical); - return count; -} - -static int oplus_lowmem_dbg_test_open(struct inode *inode, struct file *filp) -{ - return 0; -} - -static const struct file_operations lowmem_dbg_test_operations = { - .open = oplus_lowmem_dbg_test_open, - .write = oplus_lowmem_dbg_test_write, -}; - -static __init int oplus_lowmem_dbg_test_init(void) -{ - proc_create("lowmem_dbg_test", S_IWUGO, NULL, - &lowmem_dbg_test_operations); - return 0; -} -fs_initcall(oplus_lowmem_dbg_test_init); -#endif diff --git a/drivers/soc/oplus/midas/Kconfig b/drivers/soc/oplus/midas/Kconfig deleted file mode 100755 index 9db64fae5984..000000000000 --- a/drivers/soc/oplus/midas/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2021 Oplus. All rights reserved. - -config OPLUS_FEATURE_MIDAS -bool "config oplus midas device feature" -help - This selects midas device driver - -config OPLUS_FEATURE_MIDAS_GKI -tristate "config oplus midas module feature" -help - This defines midas gki module - -config OPLUS_FEATURE_BINDER_STATS_ENABLE -bool "config oplus midas binder stats feature" -help - This selects midas binder stats device driver - -config OPLUS_FEATURE_MIDAS_V2 -tristate "config oplus midas module feature" -help - This defines midas driver v2 diff --git a/drivers/soc/oplus/midas/Makefile b/drivers/soc/oplus/midas/Makefile deleted file mode 100755 index 2140ae39ac9f..000000000000 --- a/drivers/soc/oplus/midas/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2021 Oplus. All rights reserved. - -obj-$(CONFIG_OPLUS_FEATURE_MIDAS) += v1/ -obj-$(CONFIG_OPLUS_FEATURE_MIDAS_GKI) += v1_gki/ -obj-$(CONFIG_OPLUS_FEATURE_MIDAS_V2) += v2/ diff --git a/drivers/soc/oplus/midas/v1/Makefile b/drivers/soc/oplus/midas/v1/Makefile deleted file mode 100644 index 2cb601d3d714..000000000000 --- a/drivers/soc/oplus/midas/v1/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -oplus_midas_device-objs := midas_dev.o midas_ioctl.o -obj-$(CONFIG_OPLUS_FEATURE_MIDAS) += oplus_midas_device.o - -oplus_binder_stats-objs := binder_stats_dev.o -obj-$(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) += oplus_binder_stats.o - -obj-$(CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY) += vpu_pw_off_latency_proc.o - -obj-$(CONFIG_OPLUS_FEATURE_DISPCAP) += dispcap_dev.o - -ccflags-y += -I$(srctree)/drivers/staging - diff --git a/drivers/soc/oplus/midas/v1/binder_stats_dev.c b/drivers/soc/oplus/midas/v1/binder_stats_dev.c deleted file mode 100644 index fa08cca79ef3..000000000000 --- a/drivers/soc/oplus/midas/v1/binder_stats_dev.c +++ /dev/null @@ -1,1160 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - -#define BINDER_STATS_LOGI(...) -#define BINDER_STATS_LOGE pr_err - -#define BINDER_STATS_CTL_VERSION_CODE 1 - -#define BINDER_STATS_CTL_GET_VERSION 100 -#define BINDER_STATS_CTL_ENABLE 101 -#define BINDER_STATS_CTL_UPDATE 102 -#define BINDER_STATS_CTL_CFG_CLEAR 110 -#define BINDER_STATS_CTL_CFG_MAX_ITEM 111 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_NAME 112 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM 113 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_UID 114 -#define BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM 115 -#define BINDER_STATS_CTL_RET_SUCC 0 -#define BINDER_STATS_CTL_RET_INVALID -1 - -#define OPLUS_MAX_SERVICE_NAME_LEN 32 -#define BINDER_STATS_MAX_COUNT_LIMIT 32768 -#define BINDER_STATS_DEFAULT_MAX_COUNT 4096 -#define BINDER_STATS_HASH_ORDER 9 -#define BINDER_STATS_FILTER_LIMIT_MAX 128 - -/* import from binder driver */ -struct binder_notify { - struct task_struct *caller_task; - struct task_struct *binder_task; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool pending_async; -}; -extern int register_binderevent_notifier(struct notifier_block *nb); -extern int unregister_binderevent_notifier(struct notifier_block *nb); - -static int binder_notify_fn(struct notifier_block *nb, unsigned long action, void *data); -static struct notifier_block binder_nb = { - .notifier_call = binder_notify_fn, -}; - -struct binder_stats_item { - char caller_proc_comm[TASK_COMM_LEN]; - int caller_pid; - int caller_tgid; - int caller_uid; - char caller_comm[TASK_COMM_LEN]; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - char binder_proc_comm[TASK_COMM_LEN]; - int binder_pid; - int binder_tgid; - int binder_uid; - char binder_comm[TASK_COMM_LEN]; - unsigned int call_count; -}; - -/* - * binder_stats : user space mmap the buffer struct. - * this struct buffer is dynamic alloc, - * items size is max_item_cnt, it is config by user. - * items size BINDER_STATS_MAX_COUNT_LIMIT is invalid. - */ -struct binder_stats { - unsigned int max_item_cnt; - unsigned int valid_item_cnt; - struct binder_stats_item items[BINDER_STATS_MAX_COUNT_LIMIT]; -}; - -struct binder_stats_item_ref { - struct hlist_node hentry; - struct binder_stats_item *item; -}; - -struct binder_stats_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct mutex lock; - int version_code; - - struct list_head user_list_head; - bool regist_binder_stats_flag; - spinlock_t user_list_lock; -}; - -struct binder_stats_filter_srv_name { - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm { - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid { - int uid; - bool intreresting; -}; - -struct binder_stats_filter_srv_name_node { - struct hlist_node hentry; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm_node { - struct hlist_node hentry; - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid_node { - struct hlist_node hentry; - int uid; - bool intreresting; -}; - -struct binder_stats_user_context { - struct list_head list_node; - int enable; - int max_item_cnt; - struct binder_stats *binder_stats_buf_0; /* double swap buffer 0 */ - struct binder_stats *binder_stats_buf_1; /* double swap buffer 1 */ - struct binder_stats_item_ref *kernel_binder_stats_refs; - DECLARE_HASHTABLE(kernel_binder_stats_hash, BINDER_STATS_HASH_ORDER); - struct binder_stats *kernel_binder_stats; - struct binder_stats *user_binder_stats; - bool user_mmap_flag; - spinlock_t buf_lock; - - int enable_binder_comm; - DECLARE_HASHTABLE(intre_srv_name_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_srv_name; - bool has_unintr_srv_name; - DECLARE_HASHTABLE(intre_proc_comm_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_proc_comm; - bool has_unintr_proc_comm; - DECLARE_HASHTABLE(intre_uid_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_uid; - bool has_unintr_uid; -}; - -struct binder_stats_driver g_binder_stats_driver; - -/* key is from caller_comm & binder_comm && service_name */ -static inline long long hash_key(struct binder_notify *bn, int enable_binder_comm) { - long long key = 0; - int i; - long long *v1 = (long long *)bn->caller_task->comm; - long long *v2 = (long long *)bn->binder_task->comm; - long long *v3 = (long long *)bn->service_name; - for (i = 0; i < TASK_COMM_LEN/sizeof(long long); ++i) { - if (1 == enable_binder_comm) - key += (v1[i] + v2[i]); - else - key += v1[i]; - } - for (i = 0; i < OPLUS_MAX_SERVICE_NAME_LEN/sizeof(long long); ++i) { - key += v3[i]; - } - return key; -} - -static inline bool hash_match(struct binder_notify *bn, struct binder_stats_item *stats_item, int enable_binder_comm) { - struct task_struct *caller_proc_task = NULL; - struct task_struct *binder_proc_task = NULL; - if (NULL != bn->caller_task->group_leader) - caller_proc_task = bn->caller_task->group_leader; - else - caller_proc_task = bn->caller_task; - - if (NULL != bn->binder_task->group_leader) - binder_proc_task = bn->binder_task->group_leader; - else - binder_proc_task = bn->binder_task; - - if (1 == enable_binder_comm) - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_comm, bn->binder_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); - else - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); -} - -static inline long long hash_key_for_str(const char *str, unsigned int len) { - long long key = 0; - int i; - long long *v = (long long *)str; - for (i = 0; i < len/sizeof(long long); ++i) { - key += v[i]; - str += sizeof(long long); - } - for (i = 0; i < len%sizeof(long long); ++i) { - key += str[i]; - } - return key; -} - -static bool intreresting_filter(struct binder_stats_user_context *context_ptr, - struct binder_notify *bn) { - bool intreresting = false; - struct task_struct *caller_task; - struct task_struct *binder_proc_task; - int binder_uid; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - - caller_task = bn->caller_task; - binder_proc_task = NULL == bn->binder_task->group_leader? bn->binder_task: bn->binder_task->group_leader; - binder_uid = from_kuid_munged(current_user_ns(), task_uid(bn->binder_task)); - - if (!context_ptr->has_intr_srv_name && !context_ptr->has_intr_proc_comm && !context_ptr->has_intr_uid) { - intreresting = true; - } else { - intreresting = false; - } - - hash_for_each_possible(context_ptr->intre_srv_name_hash, hash_node_srv_name, hentry, - hash_key_for_str(bn->service_name, strlen(bn->service_name))) { - if (0 == strcmp(hash_node_srv_name->service_name, bn->service_name)) { - if (hash_node_srv_name->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_proc_comm_hash, hash_node_proc_comm, hentry, - hash_key_for_str(binder_proc_task->comm, strlen(binder_proc_task->comm))) { - if (0 == strcmp(hash_node_proc_comm->comm, binder_proc_task->comm)) { - if (hash_node_proc_comm->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_uid_hash, hash_node_uid, hentry, (long long)binder_uid) { - if (hash_node_uid->uid == binder_uid) { - return hash_node_uid->intreresting; - if (hash_node_uid->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - return intreresting; -} - -static void store_binder_stats_to_kernel(struct binder_notify *data) { - struct binder_stats_item *find_item = NULL; - unsigned long flags, ctx_flag; - struct binder_stats *kernel_binder_stats = NULL; - struct binder_stats_item_ref *ref_hash_node; - struct binder_stats_user_context *context_ptr = NULL; - struct task_struct *caller_task = NULL; - struct task_struct *binder_task = NULL; - - if (NULL == data || NULL == data->caller_task || NULL == data->binder_task) - return; - - caller_task = data->caller_task; - binder_task = data->binder_task; - - /* BINDER_STATS_LOGI("%d(%s) => (%s)(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - data->service_name, binder_task->comm, binder_task->pid, binder_task->comm); */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - - list_for_each_entry(context_ptr, &g_binder_stats_driver.user_list_head, list_node) { - if (NULL == context_ptr || NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) - continue; - - find_item = NULL; - - if (!intreresting_filter(context_ptr, data)) - continue; - - spin_lock_irqsave(&context_ptr->buf_lock, ctx_flag); - - kernel_binder_stats = context_ptr->kernel_binder_stats; - - /* find current item with hash */ - hash_for_each_possible(context_ptr->kernel_binder_stats_hash, ref_hash_node, hentry, hash_key(data, context_ptr->enable_binder_comm)) { - if (hash_match(data, ref_hash_node->item, context_ptr->enable_binder_comm)) { - find_item = ref_hash_node->item; - break; - } - } - - if (NULL != find_item) { - find_item->call_count++; - } else { - if (kernel_binder_stats->valid_item_cnt + 1 <= kernel_binder_stats->max_item_cnt) { - find_item = &(kernel_binder_stats->items[kernel_binder_stats->valid_item_cnt]); - - /* caller proc comm */ - if (NULL != caller_task->group_leader) - strncpy(find_item->caller_proc_comm, caller_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->caller_proc_comm, caller_task->comm, TASK_COMM_LEN); - - /* caller pid tgid uid */ - find_item->caller_pid = task_pid_nr(caller_task); - find_item->caller_tgid = task_tgid_nr(caller_task); - find_item->caller_uid = from_kuid_munged(current_user_ns(), task_uid(caller_task)); - /* caller comm */ - strncpy(find_item->caller_comm, caller_task->comm, TASK_COMM_LEN); - - /* service name */ - strncpy(find_item->service_name, data->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - - /* binder proc comm */ - if (NULL != binder_task->group_leader) - strncpy(find_item->binder_proc_comm, binder_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->binder_proc_comm, binder_task->comm, TASK_COMM_LEN); - - /* binder tgid uid */ - find_item->binder_tgid = task_tgid_nr(binder_task); - find_item->binder_uid = from_kuid_munged(current_user_ns(), task_uid(binder_task)); - - /* binder comm pid */ - if (1 == context_ptr->enable_binder_comm) { - find_item->binder_pid = task_pid_nr(binder_task); - strncpy(find_item->binder_comm, binder_task->comm, TASK_COMM_LEN); - } else { - find_item->binder_pid = find_item->binder_tgid; - strncpy(find_item->binder_comm, "binderTh", TASK_COMM_LEN); - } - - /* call count init */ - find_item->call_count = 1; - - /* add hash for improve search performance */ - ref_hash_node = &(context_ptr->kernel_binder_stats_refs[kernel_binder_stats->valid_item_cnt]); - ref_hash_node->item = find_item; - hash_add(context_ptr->kernel_binder_stats_hash, &ref_hash_node->hentry, hash_key(data, context_ptr->enable_binder_comm)); - - kernel_binder_stats->valid_item_cnt++; - } - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, ctx_flag); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); -} - -static void binder_stats_clear_user_context(struct binder_stats_user_context *context_ptr) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - BINDER_STATS_LOGI("start\n"); - - /* first remove user node from global user list - then clear the local user memory */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_del(&context_ptr->list_node); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (!IS_ERR_OR_NULL(context_ptr->user_binder_stats)) { - vfree(context_ptr->user_binder_stats); - context_ptr->user_binder_stats = NULL; - } - - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats)) { - vfree(context_ptr->kernel_binder_stats); - context_ptr->kernel_binder_stats = NULL; - } - - context_ptr->binder_stats_buf_0 = NULL; - context_ptr->binder_stats_buf_1 = NULL; - context_ptr->user_mmap_flag = false; - - context_ptr->enable = 0; -} - -static int user_enable_binder_stats(struct binder_stats_user_context *context_ptr, int enable) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - int max_item_cnt = BINDER_STATS_DEFAULT_MAX_COUNT; - int binder_stats_buffer_size = 0; - - if (0 != enable && 1 != enable) { - BINDER_STATS_LOGE("enable param error!\n"); - return -1; - } - if (context_ptr->enable == enable) { - BINDER_STATS_LOGE("enable value is same with current value!\n"); - return -1; - } - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("user mem in used!\n"); - return -1; - } - - if (1 == enable) { - if (NULL != context_ptr->binder_stats_buf_0 || - NULL != context_ptr->binder_stats_buf_1 || - NULL != context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer exist!\n"); - return -1; - } - - if (0 != context_ptr->max_item_cnt) { - max_item_cnt = context_ptr->max_item_cnt; - } - - binder_stats_buffer_size = 2*sizeof(unsigned int) + max_item_cnt*sizeof(struct binder_stats_item); - - context_ptr->binder_stats_buf_0 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_0->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_0->valid_item_cnt = 0; - context_ptr->kernel_binder_stats = context_ptr->binder_stats_buf_0; - - context_ptr->kernel_binder_stats_refs = vmalloc_user(max_item_cnt*sizeof(struct binder_stats_item_ref)); - if (IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - - hash_init(context_ptr->kernel_binder_stats_hash); - - context_ptr->binder_stats_buf_1 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_1->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_1->valid_item_cnt = 0; - context_ptr->user_binder_stats = context_ptr->binder_stats_buf_1; - - spin_lock_init(&context_ptr->buf_lock); - context_ptr->user_mmap_flag = false; - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_add(&context_ptr->list_node, &g_binder_stats_driver.user_list_head); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - context_ptr->enable = 1; - - return 0; - -enable_fail: - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - vfree(context_ptr->binder_stats_buf_1); - context_ptr->binder_stats_buf_1 = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - vfree(context_ptr->binder_stats_buf_0); - context_ptr->binder_stats_buf_0 = NULL; - } - context_ptr->user_binder_stats = NULL; - context_ptr->kernel_binder_stats = NULL; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - - return -1; - } else { - if (NULL == context_ptr->user_binder_stats || - NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer not exit!\n"); - return -1; - } - - binder_stats_clear_user_context(context_ptr); - - return 0; - } -} - -static int user_update_binder_stats(struct binder_stats_user_context *context_ptr) { - int ret = 0; - unsigned long flags; - struct binder_stats * swap_tmp; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - if (0 == context_ptr->enable) { - BINDER_STATS_LOGE("function not enabled!\n"); - return -1; - } - - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("memory is used!\n"); - return -1; - } - - spin_lock_irqsave(&context_ptr->buf_lock, flags); - - /* swap buffer & clear kernel_binder_stats & kernel_binder_stats_hash */ - if (NULL != context_ptr->kernel_binder_stats && NULL != context_ptr->user_binder_stats) { - swap_tmp = context_ptr->kernel_binder_stats; - context_ptr->kernel_binder_stats = context_ptr->user_binder_stats; - context_ptr->user_binder_stats = swap_tmp; - - /* reset cnt & clear hash */ - context_ptr->kernel_binder_stats->valid_item_cnt = 0; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - } else { - ret = -1; - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, flags); - - return ret; -} - -static int user_binder_stats_cfg_clear(struct binder_stats_user_context *context_ptr) { - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - struct hlist_node *tmp; - int i; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - hash_del(&hash_node_srv_name->hentry); - vfree(hash_node_srv_name); - } - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - hash_del(&hash_node_proc_comm->hentry); - vfree(hash_node_proc_comm); - } - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - hash_del(&hash_node_uid->hentry); - vfree(hash_node_uid); - } - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - context_ptr->enable_binder_comm = 0; - - context_ptr->max_item_cnt = 0; - - return 0; -} - -static int user_binder_stats_cfg_set_max_item_cnt(struct binder_stats_user_context *context_ptr, int max_item_cnt) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - if (max_item_cnt < 0 || max_item_cnt > BINDER_STATS_MAX_COUNT_LIMIT) { - BINDER_STATS_LOGE("invalid max_item_cnt!\n"); - return -1; - } - - context_ptr->max_item_cnt = max_item_cnt; - - return 0; -} - -static int user_binder_stats_cfg_set_enable_binder_comm(struct binder_stats_user_context *context_ptr, int enable_binder_comm) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - if (0 != enable_binder_comm && 1 != enable_binder_comm) { - BINDER_STATS_LOGE("enable_binder_comm param error!\n"); - return -1; - } - - context_ptr->enable_binder_comm = enable_binder_comm; - - return 0; -} - -static int user_binder_stats_add_intreresting_svr_name(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_srv_name *filter_srv_name) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_srv_name = vmalloc_user(sizeof(struct binder_stats_filter_srv_name_node)); - if (IS_ERR_OR_NULL(hash_node_srv_name)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_srv_name->service_name, filter_srv_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - hash_node_srv_name->intreresting = filter_srv_name->intreresting; - hash_add(context_ptr->intre_srv_name_hash, &hash_node_srv_name->hentry, - hash_key_for_str(hash_node_srv_name->service_name, strlen(hash_node_srv_name->service_name))); - - if (hash_node_srv_name->intreresting) { - context_ptr->has_intr_srv_name = true; - } else { - context_ptr->has_unintr_srv_name = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_srv_name->service_name, hash_node_srv_name->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_proc_comm(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_proc_comm *filter_proc_comm) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_proc_comm = vmalloc_user(sizeof(struct binder_stats_filter_proc_comm_node)); - if (IS_ERR_OR_NULL(hash_node_proc_comm)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_proc_comm->comm, filter_proc_comm->comm, TASK_COMM_LEN); - hash_node_proc_comm->intreresting = filter_proc_comm->intreresting; - hash_add(context_ptr->intre_proc_comm_hash, &hash_node_proc_comm->hentry, - hash_key_for_str(hash_node_proc_comm->comm, strlen(hash_node_proc_comm->comm))); - - if (hash_node_proc_comm->intreresting) { - context_ptr->has_intr_proc_comm = true; - } else { - context_ptr->has_unintr_proc_comm = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_proc_comm->comm, hash_node_proc_comm->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_uid(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_uid *filter_uid) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_uid_node *hash_node_uid; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_uid = vmalloc_user(sizeof(struct binder_stats_filter_uid_node)); - if (IS_ERR_OR_NULL(hash_node_uid)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - hash_node_uid->uid = filter_uid->uid; - hash_node_uid->intreresting = filter_uid->intreresting; - hash_add(context_ptr->intre_uid_hash, &hash_node_uid->hentry, (long long)hash_node_uid->uid); - - if (hash_node_uid->intreresting) { - context_ptr->has_intr_uid = true; - } else { - context_ptr->has_unintr_uid = true; - } - - /* BINDER_STATS_LOGI("%d %d\n", hash_node_uid->uid, hash_node_uid->intreresting); */ - - return ret; -} - -static int binder_notify_fn(struct notifier_block *nb, unsigned long action, void *data) { - struct binder_notify *bn = NULL; - if (NULL == data) { - return 0; - } - bn = (struct binder_notify *)data; - store_binder_stats_to_kernel(bn); - return 0; -} - -static int binder_stats_driver_open(struct inode *inode, struct file *filp) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - if (!g_binder_stats_driver.regist_binder_stats_flag) { - register_binderevent_notifier(&binder_nb); - g_binder_stats_driver.regist_binder_stats_flag = true; - } - - context_ptr = vmalloc(sizeof(struct binder_stats_user_context)); - if (IS_ERR_OR_NULL(context_ptr)) { - BINDER_STATS_LOGE("vmalloc failed\n"); - goto open_fail; - } - - memset(context_ptr, 0, sizeof(struct binder_stats_user_context)); - - /* init config data */ - - context_ptr->max_item_cnt = 0; - - context_ptr->enable_binder_comm = 0; - - hash_init(context_ptr->intre_srv_name_hash); - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_init(context_ptr->intre_proc_comm_hash); - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_init(context_ptr->intre_uid_hash); - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - filp->private_data = context_ptr; - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; - -open_fail: - - mutex_unlock(&g_binder_stats_driver.lock); - - return -1; -} - -static int binder_stats_driver_release(struct inode *ignored, struct file *filp) { - struct binder_stats_user_context *context_ptr; - unsigned long flags; - bool clear_notifier = false; - struct list_head *pos = NULL; - int list_size = 0; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - if (IS_ERR_OR_NULL(context_ptr)) { - mutex_unlock(&g_binder_stats_driver.lock); - return -1; - } - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_size = 0; - list_for_each(pos, &g_binder_stats_driver.user_list_head) { - ++list_size; - } - if (g_binder_stats_driver.regist_binder_stats_flag && - ((1 == list_size && list_is_last(&context_ptr->list_node, &g_binder_stats_driver.user_list_head)) || - list_empty(&g_binder_stats_driver.user_list_head))) { - clear_notifier = true; - g_binder_stats_driver.regist_binder_stats_flag = false; - } - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (clear_notifier) { - unregister_binderevent_notifier(&binder_nb); - } - - if (!IS_ERR_OR_NULL(context_ptr)) { - if (1 == context_ptr->enable) { - binder_stats_clear_user_context(context_ptr); - } - vfree(context_ptr); - filp->private_data = NULL; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static void binder_stats_mmap_close(struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - if (NULL == vma || NULL == vma->vm_file || NULL == vma->vm_file->private_data) { - BINDER_STATS_LOGE("invalid private_data\n"); - return; - } - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = vma->vm_file->private_data; - context_ptr->user_mmap_flag = false; - - mutex_unlock(&g_binder_stats_driver.lock); -} - -static const struct vm_operations_struct binder_stats_mmap_vmops = { - .close = binder_stats_mmap_close, -}; - -static int binder_stats_driver_mmap(struct file *filp, struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - - if (NULL != context_ptr && NULL != context_ptr->user_binder_stats) { - vma->vm_ops = &binder_stats_mmap_vmops; - if (remap_vmalloc_range(vma, context_ptr->user_binder_stats, vma->vm_pgoff)) { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - context_ptr->user_mmap_flag = true; - } else { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static long binder_stats_driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - long ret = -1; - int enable = 0; - int max_item_cnt = 0; - int enable_binder_comm = 0; - struct binder_stats_filter_srv_name filter_srv_name; - struct binder_stats_filter_proc_comm filter_proc_comm; - struct binder_stats_filter_uid filter_uid; - struct binder_stats_user_context *context_ptr = filp->private_data; - - BINDER_STATS_LOGI("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - BINDER_STATS_LOGE("context_ptr error!\n"); - return ret; - } - - mutex_lock(&g_binder_stats_driver.lock); - - switch (cmd) { - case BINDER_STATS_CTL_GET_VERSION: { - if (0 != arg) { - if(0 == copy_to_user((unsigned int *)arg, - &g_binder_stats_driver.version_code, sizeof(unsigned int))) { - BINDER_STATS_LOGI("BINDER_STATS_CTL_GET_VERSION %d\n", g_binder_stats_driver.version_code); - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. arg error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_ENABLE: { - if(0 != copy_from_user(&enable, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_enable_binder_stats(context_ptr, enable)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_UPDATE: { - if (0 == user_update_binder_stats(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_UPDATE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_CLEAR: { - if (0 == user_binder_stats_cfg_clear(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_CLEAR failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_MAX_ITEM: { - if(0 != copy_from_user(&max_item_cnt, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_max_item_cnt(context_ptr, max_item_cnt)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM: { - if(0 != copy_from_user(&enable_binder_comm, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_enable_binder_comm(context_ptr, enable_binder_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_NAME: { - if(0 != copy_from_user(&filter_srv_name, (char *)arg, sizeof(struct binder_stats_filter_srv_name))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_svr_name(context_ptr, &filter_srv_name)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM: { - if(0 != copy_from_user(&filter_proc_comm, (char *)arg, sizeof(struct binder_stats_filter_proc_comm))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_proc_comm(context_ptr, &filter_proc_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_UID: { - if(0 != copy_from_user(&filter_uid, (int *)arg, sizeof(struct binder_stats_filter_uid))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_uid(context_ptr, &filter_uid)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - default: { - BINDER_STATS_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = BINDER_STATS_CTL_RET_INVALID; - } - break; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = binder_stats_driver_open, - .release = binder_stats_driver_release, - .unlocked_ioctl = binder_stats_driver_ioctl, - .mmap = binder_stats_driver_mmap, -}; - -int __init binder_stats_dev_init(void) { - int err = 0; - - g_binder_stats_driver.version_code = BINDER_STATS_CTL_VERSION_CODE; - mutex_init(&g_binder_stats_driver.lock); - spin_lock_init(&g_binder_stats_driver.user_list_lock); - INIT_LIST_HEAD(&g_binder_stats_driver.user_list_head); - - err = alloc_chrdev_region(&g_binder_stats_driver.dev, 0, 1, "binder_stats"); - if (err < 0) { - BINDER_STATS_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_binder_stats_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_binder_stats_driver.cdev, g_binder_stats_driver.dev, 1); - if (err < 0) { - BINDER_STATS_LOGE("cdev_add g_binder_stats_driver.cdev failed!\n"); - goto unreg_region; - } - - g_binder_stats_driver.dev_class = class_create(THIS_MODULE, "binder_stats_class"); - if (IS_ERR(g_binder_stats_driver.dev_class)) { - BINDER_STATS_LOGE("create class g_binder_stats_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_binder_stats_driver.device = device_create(g_binder_stats_driver.dev_class, - NULL, g_binder_stats_driver.dev, NULL, "binder_stats"); - if (IS_ERR(g_binder_stats_driver.device)) { - BINDER_STATS_LOGE("device_create g_binder_stats_driver.device error\n"); - goto destroy_class; - } - - g_binder_stats_driver.regist_binder_stats_flag = false; - - return 0; - -destroy_class: - class_destroy(g_binder_stats_driver.dev_class); - -destroy_cdev: - cdev_del(&g_binder_stats_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_binder_stats_driver.dev, 1); - -fail: - return -1; -} - - -void __exit binder_stats_dev_exit(void) { - if (g_binder_stats_driver.dev_class) { - device_destroy(g_binder_stats_driver.dev_class, g_binder_stats_driver.dev); - class_destroy(g_binder_stats_driver.dev_class); - g_binder_stats_driver.dev_class = NULL; - } - - cdev_del(&g_binder_stats_driver.cdev); - - unregister_chrdev_region(g_binder_stats_driver.dev, 1); -} - -#else /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - -int __init binder_stats_dev_init(void) { - return 0; -} - -void __exit binder_stats_dev_exit(void) { -} - -#endif /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - - -module_init(binder_stats_dev_init); -module_exit(binder_stats_dev_exit); diff --git a/drivers/soc/oplus/midas/v1/dispcap_dev.c b/drivers/soc/oplus/midas/v1/dispcap_dev.c deleted file mode 100755 index 08378c79ffd2..000000000000 --- a/drivers/soc/oplus/midas/v1/dispcap_dev.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * linux/drivers/soc/oplus/oppo_midas/dispcap_dev.c - * - * Added dispcap drivers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#if defined(CONFIG_OPLUS_FEATURE_DISPCAP) - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* import from cwb driver begin */ - -enum CWB_BUFFER_TYPE { - IMAGE_ONLY, - CARRY_METADATA, - BUFFER_TYPE_NR, -}; -struct mtk_cwb_funcs { - /** - * @get_buffer: - * - * This function is optional. - * - * If user hooks this callback, driver will use this first when - * wdma irq is arrived. (capture done) - * User need fill buffer address to *buffer. - * - * If user not hooks this callback driver will confirm whether - * mtk_wdma_capture_info->user_buffer is NULL or not. - * User can use setUserBuffer() assigned this param. - */ - void (*get_buffer)(void **buffer); - - /** - * @copy_done: - * - * When Buffer copy done will be use this callback to notify user. - */ - void (*copy_done)(void *buffer, enum CWB_BUFFER_TYPE type); -}; - -struct mtk_rect { - int x; - int y; - int width; - int height; -}; - -extern bool mtk_drm_set_cwb_roi(struct mtk_rect rect); -extern bool mtk_drm_cwb_enable(int en, - const struct mtk_cwb_funcs *funcs, - enum CWB_BUFFER_TYPE type); -extern bool mtk_drm_set_cwb_user_buf(void *user_buffer, enum CWB_BUFFER_TYPE type); - -/* import from ion driver */ - -struct ion_handle; -extern struct ion_device *g_ion_device; -extern void * ion_map_kernel(struct ion_client *client, struct ion_handle *handle); -extern void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); - -/* dispcap driver */ - -#define DISPCAP_CTL_SET_CAPTURE_RECT 97 -#define DISPCAP_CTL_SET_CAPTURE_INTERVAL 98 -#define DISPCAP_CTL_ENABLE_CAPTURE 99 -#define DISPCAP_CTL_SET_BUFFER 100 -#define DISPCAP_CTL_WAIT_BUFFER_COMPLETE 101 -#define DISPCAP_CTL_RET_SUCC 0 -#define DISPCAP_CTL_RET_WAIT_TIMEOUT 1 -#define DISPCAP_CTL_RET_INVALID -1 -#define DISPCAP_CTL_RET_ERROR -2 -#define DISPCAP_LOGD(...) -#define DISPCAP_LOGE pr_err - -struct disp_capture_rect -{ - int x; - int y; - int w; - int h; -}; - -struct disp_driver_context -{ - struct ion_handle *dispcap_ion_handle; -}; - -struct disp_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct ion_client *ion_client; - struct completion dispcap_cmp; - struct mutex dispcap_lock; - bool dispcap_used; - int pid; -}; - -static struct disp_driver g_disp_driver; - -void my_user_copy_done(void *buffer, enum CWB_BUFFER_TYPE type) { - DISPCAP_LOGD("start : %p\n", buffer); - complete(&g_disp_driver.dispcap_cmp); -} - -static const struct mtk_cwb_funcs user_cwb_funcs = { - .copy_done = my_user_copy_done, -}; - -static int driver_open(struct inode *inode, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if (g_disp_driver.dispcap_used) { - DISPCAP_LOGD("dispcap is in used. pid:%d\n", g_disp_driver.pid); - mutex_unlock(&g_disp_driver.dispcap_lock); - return -1; - } - - context_ptr = kmalloc(sizeof(struct disp_driver_context), GFP_KERNEL); - if (NULL == context_ptr) { - mutex_unlock(&g_disp_driver.dispcap_lock); - return -ENOMEM; - } - - context_ptr->dispcap_ion_handle = NULL; - - filp->private_data = context_ptr; - - g_disp_driver.dispcap_used = true; - g_disp_driver.pid = current->pid; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static int driver_release(struct inode *ignored, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr = filp->private_data; - if (NULL != context_ptr) { - - // disable capture buffer and unmap - mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY); - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - kfree(context_ptr); - filp->private_data = NULL; - } - - g_disp_driver.dispcap_used = false; - g_disp_driver.pid = -1; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static long driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) -{ - long ret = -1; - struct disp_driver_context *context_ptr = filp->private_data; - - DISPCAP_LOGD("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - DISPCAP_LOGE("context_ptr error!\n"); - return ret; - } - - switch (cmd) { - case DISPCAP_CTL_SET_CAPTURE_RECT: { - struct disp_capture_rect rect; - if(0 != copy_from_user(&rect, (void __user *)arg, sizeof(struct disp_capture_rect))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_CAPTURE_RECT arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - struct mtk_rect mrect; - mrect.x = rect.x; - mrect.y = rect.y; - mrect.width = rect.w; - mrect.height = rect.h; - if(!mtk_drm_set_cwb_roi(mrect)) { - DISPCAP_LOGE("setCaptureRect error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("setCaptureRect:%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_ENABLE_CAPTURE: { - int capture; - if(0 != copy_from_user(&capture, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_ENABLE_CAPTURE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_cwb_enable(capture, &user_cwb_funcs, IMAGE_ONLY)) { - DISPCAP_LOGE("setCaptureInterval error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("enableCapture:%d mtk_crtc_capt_enable\n", capture); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_SET_BUFFER: { - int ion_share_fd; - struct dma_buf *cur_dma_buf; - void * map_ion_va; - - if(0 != copy_from_user(&ion_share_fd, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_BUFFER arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - DISPCAP_LOGD("ion_share_fd:%d\n", ion_share_fd); - - cur_dma_buf = dma_buf_get(ion_share_fd); - if (NULL == cur_dma_buf) { - DISPCAP_LOGE("dma_buf_get failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - break; - } - DISPCAP_LOGD("cur_dma_buf:%p\n", cur_dma_buf); - DISPCAP_LOGD("cur_dma_buf size:%lu\n", cur_dma_buf->size); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr->dispcap_ion_handle = ion_import_dma_buf_fd(g_disp_driver.ion_client, ion_share_fd); - if (NULL == context_ptr->dispcap_ion_handle) { - DISPCAP_LOGE("ion_import_dma_buf_fd failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_import_dma_buf_fd ion_handle:%p\n", context_ptr->dispcap_ion_handle); - - map_ion_va = ion_map_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - if (NULL == map_ion_va) { - DISPCAP_LOGE("ion_map_kernel failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_map_kernel map_ion_va:%p\n", map_ion_va); - - DISPCAP_LOGD("reinit_completion\n"); - reinit_completion(&g_disp_driver.dispcap_cmp); - - DISPCAP_LOGD("setUserBuffer: %p\n", map_ion_va); - if(!mtk_drm_set_cwb_user_buf((void *)map_ion_va, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_WAIT_BUFFER_COMPLETE: { - int wait_ms; - int wait_ret; - if(0 != copy_from_user(&wait_ms, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_WAIT_BUFFER_COMPLETE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout timeout:%dms begin ...\n", wait_ms); - wait_ret = wait_for_completion_interruptible_timeout(&g_disp_driver.dispcap_cmp, msecs_to_jiffies(wait_ms)); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout OK wait_ret:%d\n", wait_ret); - if (0 == wait_ret) { - ret = DISPCAP_CTL_RET_WAIT_TIMEOUT; - } else if (0 < wait_ret) { - ret = DISPCAP_CTL_RET_SUCC; - } else { - ret = DISPCAP_CTL_RET_INVALID; - } - } - break; - default: { - DISPCAP_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = DISPCAP_CTL_RET_INVALID; - } - break; - } - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = driver_open, - .release = driver_release, - .unlocked_ioctl = driver_ioctl, -}; - -int __init dispcap_dev_init(void) -{ - int err = 0; - - DISPCAP_LOGD("start\n"); - - g_disp_driver.dev_class = NULL; - g_disp_driver.device = NULL; - g_disp_driver.dev_class = NULL; - g_disp_driver.ion_client = NULL; - g_disp_driver.dispcap_used = false; - mutex_init(&g_disp_driver.dispcap_lock); - - err = alloc_chrdev_region(&g_disp_driver.dev, 0, 1, "midas_dispcap"); - if (err < 0) { - DISPCAP_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_disp_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_disp_driver.cdev, g_disp_driver.dev, 1); - if (err < 0) { - DISPCAP_LOGE("cdev_add g_disp_driver.cdev failed!\n"); - goto unreg_region; - } - - g_disp_driver.dev_class = class_create(THIS_MODULE, "midas_dispcap_class"); - if (IS_ERR(g_disp_driver.dev_class)) { - DISPCAP_LOGE("create class g_disp_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_disp_driver.device = device_create(g_disp_driver.dev_class, NULL, g_disp_driver.dev, NULL, "midas_dispcap"); - if (IS_ERR(g_disp_driver.device)) { - DISPCAP_LOGE("device_create g_disp_driver.device error\n"); - goto destroy_class; - } - - g_disp_driver.ion_client = ion_client_create(g_ion_device, "dispcap_ion_client"); - if (NULL == g_disp_driver.ion_client) { - DISPCAP_LOGE("ion_client_create g_disp_driver.ion_client failed\n"); - goto destroy_device; - } - - init_completion(&g_disp_driver.dispcap_cmp); - - return 0; - -destroy_device: - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - -destroy_class: - class_destroy(g_disp_driver.dev_class); - -destroy_cdev: - cdev_del(&g_disp_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_disp_driver.dev, 1); - -fail: - return -1; -} - -void __exit dispcap_dev_exit(void) -{ - DISPCAP_LOGD("start\n"); - - if (NULL != g_disp_driver.ion_client) { - ion_client_destroy(g_disp_driver.ion_client); - g_disp_driver.ion_client = NULL; - } - - if (g_disp_driver.dev_class) { - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - class_destroy(g_disp_driver.dev_class); - g_disp_driver.dev_class = NULL; - } - - cdev_del(&g_disp_driver.cdev); - - unregister_chrdev_region(g_disp_driver.dev, 1); -} - - -module_init(dispcap_dev_init); -module_exit(dispcap_dev_exit); - -#endif // #if defined(CONFIG_OPLUS_FEATURE_DISPCAP) diff --git a/drivers/soc/oplus/midas/v1/midas_dev.c b/drivers/soc/oplus/midas/v1/midas_dev.c deleted file mode 100755 index b9a1cf5b6033..000000000000 --- a/drivers/soc/oplus/midas/v1/midas_dev.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "midas_dev.h" - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -#include -#else -#include -#endif - -#define MIDAS_MAX_DEVS 1 -#define MAX_RASMEVENT_PARAM 7 - -static char *rasm_env[MAX_RASMEVENT_PARAM]; - -static void do_getboottime(struct timeval *tv) -{ - struct timespec64 now; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ktime_get_boottime_ts64(&now); -#else - get_monotonic_boottime64(&now); -#endif - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000; -} - -static int rasm_resume(struct device *dev) { - struct timeval resume_time; - struct timeval resume_boot_time; - struct rasm_data *data; - int index = 0; - int i; - struct midas_dev_info *dev_info; - - if (!dev) { - pr_err("dev is empty"); - return 0; - } - - dev_info = dev->driver_data; - if (!dev_info) { - pr_err("driver_data is empty"); - return 0; - } - - data = dev_info->rasm_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - - - do_gettimeofday(&resume_time); - data->last_resume_time = resume_time.tv_sec; - data->last_resume_millsec_time = resume_time.tv_sec * 1000 + resume_time.tv_usec / 1000; - do_getboottime(&resume_boot_time); - data->last_resume_boot_time = resume_boot_time.tv_sec * 1000 + resume_boot_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will resume.", data->last_resume_time); - - rasm_env[index++] = kasprintf(GFP_KERNEL, "NAME=rasm"); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend=%ld", data->last_suspend_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume=%ld", data->last_resume_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_boot=%ld", data->last_resume_boot_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_millsec=%ld", data->last_resume_millsec_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend_millsec=%ld", data->last_suspend_millsec_time); - rasm_env[index++] = NULL; - - if (index > ARRAY_SIZE(rasm_env)) - BUG(); - - kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, rasm_env); - for (i = 0; i < index - 1; ++i) - kfree(rasm_env[i]); - return 0; -} - -static int rasm_suspend(struct device *dev) { - struct timeval suspend_time; - struct rasm_data *data; - struct midas_dev_info *dev_info; - - if (!dev) { - pr_err("dev is empty"); - return 0; - } - - dev_info = dev->driver_data; - if (!dev_info) { - pr_err("driver_data is empty"); - return 0; - } - - data = dev_info->rasm_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - - do_gettimeofday(&suspend_time); - data->last_suspend_time = suspend_time.tv_sec; - data->last_suspend_millsec_time = suspend_time.tv_sec * 1000 + suspend_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will suspend.", data->last_suspend_time); - return 0; -} - -static const struct dev_pm_ops rasm_pm_ops = { - .suspend = rasm_suspend, - .resume = rasm_resume, -}; - -static int midas_dev_mmap(struct file *filp, struct vm_area_struct *vma) -{ - struct midas_priv_info *info = filp->private_data; - if (IS_ERR_OR_NULL(info)) - return -EINVAL; - - if (remap_vmalloc_range(vma, info->mmap_addr, - vma->vm_pgoff)) { - pr_err("remap failed\n"); - return -EAGAIN; - } - - return 0; -} - -static int midas_dev_open(struct inode *inode, struct file *filp) -{ - int ret = 0; - - struct midas_priv_info *info = kzalloc(sizeof(struct midas_priv_info), GFP_KERNEL); - if (IS_ERR_OR_NULL(info)) - return -ENOMEM; - - info->mmap_addr = vmalloc_user(sizeof(struct midas_mmap_data)); - if (IS_ERR_OR_NULL(info->mmap_addr)) { - pr_err("mmap_addr vmalloc failed!\n"); - ret = -ENOMEM; - goto err_info_alloc; - } - - filp->private_data = info; - return 0; - -err_info_alloc: - kfree(info); - return ret; -} - -static int midas_dev_release(struct inode *inode, struct file *filp) -{ - struct midas_priv_info *info = filp->private_data; - if (IS_ERR_OR_NULL(info)) - return 0; - - if (info->mmap_addr != NULL) - vfree(info->mmap_addr); - - kfree(info); - return 0; -} - -static const struct file_operations midas_dev_fops = { - .open = midas_dev_open, - .release = midas_dev_release, - .mmap = midas_dev_mmap, - .unlocked_ioctl = midas_dev_ioctl, -}; - -static int midas_pdev_probe(struct platform_device *pdev) -{ - int ret = 0; - struct device *dev; - struct midas_dev_info *dev_info; - struct rasm_data *rasm_data; - - dev_info = kzalloc(sizeof(struct midas_dev_info), GFP_KERNEL); - if (IS_ERR_OR_NULL(dev_info)) { - pr_err("Fail to alloc dev info\n"); - ret = -ENOMEM; - goto err_info_alloc; - } - - rasm_data = kzalloc(sizeof(struct rasm_data), GFP_KERNEL); - if (IS_ERR_OR_NULL(rasm_data)) { - pr_err("Fail to alloc rasm_data\n"); - ret = -ENOMEM; - goto err_rasm_alloc; - } - dev_info->rasm_data = rasm_data; - - ret = alloc_chrdev_region(&dev_info->devno, 0, MIDAS_MAX_DEVS, "midas_dev"); - if (ret) { - pr_err("Fail to alloc devno, ret=%d\n", ret); - goto err_cdev_alloc; - } - - cdev_init(&dev_info->cdev, &midas_dev_fops); - ret = cdev_add(&dev_info->cdev, dev_info->devno, MIDAS_MAX_DEVS); - if (ret) { - pr_err("Fail to add cdev, ret=%d\n", ret); - goto err_cdev_add; - } - - dev_info->class = class_create(THIS_MODULE, "midas"); - if (IS_ERR_OR_NULL(dev_info->class)) { - pr_err("Fail to create class, ret=%d\n", ret); - goto err_class_create; - } - - dev = device_create(dev_info->class, NULL, dev_info->devno, - dev_info, "midas_dev"); - - if (IS_ERR_OR_NULL(dev)) { - pr_err("Fail to create device, ret=%d\n", ret); - goto err_device_create; - } - - platform_set_drvdata(pdev, dev_info); - - return 0; - -err_device_create: - class_destroy(dev_info->class); -err_class_create: - cdev_del(&dev_info->cdev); -err_cdev_add: - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); -err_cdev_alloc: - kfree(rasm_data); -err_rasm_alloc: - kfree(dev_info); -err_info_alloc: - return ret; -} - - -static int midas_pdev_remove(struct platform_device *pdev) -{ - struct midas_dev_info *dev_info = platform_get_drvdata(pdev); - if (IS_ERR_OR_NULL(dev_info)) - return -EINVAL; - - device_destroy(dev_info->class, dev_info->devno); - class_destroy(dev_info->class); - cdev_del(&dev_info->cdev); - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); - kfree(dev_info->rasm_data); - kfree(dev_info); - - return 0; -} - -static void midas_pdev_release(struct device *dev) -{ - return; -} - -static struct platform_device midas_pdev = { - .id = -1, - .name = "midas-pdev", - .dev = { - .release = midas_pdev_release, - } -}; - -static const struct of_device_id midas_pdev_dt_ids[] = { - { .compatible = "oplus,midas-pdev", }, - { } -}; - -static struct platform_driver midas_pdev_driver = { - .driver = { - .name = "midas-pdev", - .of_match_table = midas_pdev_dt_ids, - .pm = &rasm_pm_ops, - }, - .probe = midas_pdev_probe, - .remove = midas_pdev_remove, -}; - -static int __init midas_dev_init(void) -{ - int ret; - - ret = platform_device_register(&midas_pdev); - if (ret < 0) { - pr_err("platform_device_register failed! ret=%d\n", ret); - return ret; - } - - ret = platform_driver_register(&midas_pdev_driver); - if (ret < 0) { - pr_err("platform_driver_register failed! ret=%d\n", ret); - goto err_driver_register; - } - return 0; - -err_driver_register: - platform_device_unregister(&midas_pdev); - return ret; -} - -static void __exit midas_dev_exit(void) -{ - platform_device_unregister(&midas_pdev); - platform_driver_unregister(&midas_pdev_driver); -} - -module_init(midas_dev_init); -module_exit(midas_dev_exit); diff --git a/drivers/soc/oplus/midas/v1/midas_dev.h b/drivers/soc/oplus/midas/v1/midas_dev.h deleted file mode 100755 index be212d768ad5..000000000000 --- a/drivers/soc/oplus/midas/v1/midas_dev.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#ifndef __MIDAS_DEV_H__ -#define __MIDAS_DEV_H__ - -#include -#include -#include - -#define STATE_MAX 60 -#define CNT_MAX 1024 -#define CPU_MAX 8 - -enum { - ID_PID = 0, - ID_TGID, - ID_UID, - ID_TOTAL, -}; - -struct id_entry { - unsigned int id[ID_TOTAL]; - unsigned int type; - char pid_name[TASK_COMM_LEN]; - char tgid_name[TASK_COMM_LEN]; - unsigned long long time_in_state[STATE_MAX]; -}; - -struct cpu_entry { - unsigned long long time_in_state[STATE_MAX]; -}; - -struct midas_mmap_data { - unsigned int cnt; - struct id_entry entrys[CNT_MAX]; - struct cpu_entry cpu_entrys[CPU_MAX]; -}; - -struct rasm_data { - long last_suspend_time; - long last_resume_time; - long last_resume_boot_time; - long last_suspend_millsec_time; - long last_resume_millsec_time; -}; - -struct midas_dev_info { - unsigned int version; - dev_t devno; - struct cdev cdev; - struct class *class; - struct rasm_data *rasm_data; -}; - -struct midas_priv_info { - struct midas_mmap_data *mmap_addr; -}; - -typedef int midas_ioctl_t(void *kdata, void *priv_info); - -struct midas_ioctl_desc { - unsigned int cmd; - midas_ioctl_t *func; -}; - -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg); - -#endif diff --git a/drivers/soc/oplus/midas/v1/midas_ioctl.c b/drivers/soc/oplus/midas/v1/midas_ioctl.c deleted file mode 100755 index 35f56e511e5b..000000000000 --- a/drivers/soc/oplus/midas/v1/midas_ioctl.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include - -#include "midas_dev.h" - -#define MIDAS_IOCTL_DEF(ioctl, _func) \ - [MIDAS_IOCTL_NR(ioctl)] = { \ - .cmd = ioctl, \ - .func = _func, \ - } - -#define MIDAS_IOCTL_BASE 'm' -#define MIDAS_IO(nr) _IO(MIDAS_IOCTL_BASE, nr) -#define MIDAS_IOR(nr, type) _IOR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOW(nr, type) _IOW(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOWR(nr, type) _IOWR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOCTL_NR(n) _IOC_NR(n) -#define MIDAS_CORE_IOCTL_CNT ARRAY_SIZE(midas_ioctls) - -#define MIDAS_IOCTL_GET_TIME_IN_STATE MIDAS_IOR(0x1, unsigned int) -#define MIDAS_IOCTL_SET_TRACK_UID MIDAS_IOR(0x2, unsigned int) -#define MIDAS_IOCTL_REMOVE_TRACK_UID MIDAS_IOR(0x3, unsigned int) -#define MIDAS_IOCTL_CLEAR_TRACK_UID MIDAS_IOR(0x4, unsigned int) - -#define SYS_UID 1000 -#define ROOT_UID 0 -#define WQ_NAME_LEN 24 -#define TRACK_UID_NUM 10 - -enum { - TYPE_NONE = 0, - TYPE_PROCESS, - TYPE_APP, - TYPE_TOTAL, -}; - -static struct midas_mmap_data midas_mmap_buf; -static DEFINE_SPINLOCK(midas_data_lock); -static unsigned int g_track_uid[TRACK_UID_NUM] = {0}; - -static int check_track_uid(int uid) -{ - int i; - - if (uid == ROOT_UID || uid == SYS_UID) - return 0; - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (uid == g_track_uid[i]) - return 0; - } - - return -1; -} - -static void update_cpu_entry_locked(struct task_struct *p, u64 cputime, - unsigned int state) -{ - unsigned int cpu = p->cpu; - - if (cpu >= CPU_MAX) - return; - - midas_mmap_buf.cpu_entrys[cpu].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); -} - -static void query_pid_name(struct task_struct *p, char *pid_name) -{ - char buf[WQ_NAME_LEN] = {0}; - - if (!(p->flags & PF_WQ_WORKER)) { - strncpy(pid_name, p->comm, TASK_COMM_LEN); - } else { - get_worker_info(p, buf); - if (buf[0]) { - strncpy(pid_name, buf, TASK_COMM_LEN - 1); - pid_name[TASK_COMM_LEN - 1] = '\0'; - } else { - strncpy(pid_name, p->comm, TASK_COMM_LEN); - } - } -} - -static void update_or_create_entry_locked(uid_t uid, struct task_struct *p, u64 cputime, - unsigned int state, unsigned int type) -{ - unsigned int id_cnt = midas_mmap_buf.cnt; - unsigned int index = (type == TYPE_PROCESS) ? ID_PID : ID_UID; - unsigned int id = (type == TYPE_PROCESS) ? task_pid_nr(p) : uid; - struct task_struct *task; - int i; - - for (i = 0; i < id_cnt; i++) { - if (midas_mmap_buf.entrys[i].type == type - && midas_mmap_buf.entrys[i].id[index] == id) { - /* the unit of time_in_state is ms */ - midas_mmap_buf.entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - return; - } - } - - if (i >= CNT_MAX) - return; - - /* We didn't find id_entry exsited, should create a new one */ - midas_mmap_buf.entrys[i].id[ID_UID] = uid; - midas_mmap_buf.entrys[i].type = type; - if (type == TYPE_PROCESS) { - midas_mmap_buf.entrys[i].id[ID_PID] = task_pid_nr(p); - midas_mmap_buf.entrys[i].id[ID_TGID] = task_tgid_nr(p); - query_pid_name(p, midas_mmap_buf.entrys[i].pid_name); - /* Get tgid name */ - rcu_read_lock(); - task = find_task_by_vpid(midas_mmap_buf.entrys[i].id[ID_TGID]); - rcu_read_unlock(); - - if (task != NULL) - strncpy(midas_mmap_buf.entrys[i].tgid_name, task->comm, TASK_COMM_LEN); - } - /* the unit of time_in_state is ms */ - midas_mmap_buf.entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - midas_mmap_buf.cnt = ((id_cnt + 1) > CNT_MAX) ? CNT_MAX : (id_cnt + 1); -} - -void midas_record_task_times(uid_t uid, u64 cputime, struct task_struct *p, - unsigned int state) { - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - update_or_create_entry_locked(uid, p, cputime, state, TYPE_APP); - - if (!check_track_uid(uid)) - update_or_create_entry_locked(uid, p, cputime, state, TYPE_PROCESS); - - update_cpu_entry_locked(p, cputime, state); - - spin_unlock_irqrestore(&midas_data_lock, flags); -} -EXPORT_SYMBOL(midas_record_task_times); - -static int midas_ioctl_get_time_in_state(void *kdata, void *priv_info) -{ - unsigned long flags; - struct midas_priv_info *info = priv_info; - - if (IS_ERR_OR_NULL(info->mmap_addr)) - return -EINVAL; - - spin_lock_irqsave(&midas_data_lock, flags); - - memcpy(info->mmap_addr, &midas_mmap_buf, sizeof(struct midas_mmap_data)); - memset(&midas_mmap_buf, 0, sizeof(struct midas_mmap_data)); - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_remove_track_uid(void *kdata, void *priv_info) -{ - unsigned int *uid = kdata; - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (g_track_uid[i] == *uid) { - g_track_uid[i] = 0; - break; - } - } - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_clear_track_uid(void *kdata, void *priv_info) -{ - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) - g_track_uid[i] = 0; - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_set_track_uid(void *kdata, void *priv_info) -{ - unsigned int *uid = kdata; - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (g_track_uid[i] == 0) { - g_track_uid[i] = *uid; - break; - } else if (g_track_uid[i] == *uid) { - break; - } - } - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -/* Ioctl table */ -static const struct midas_ioctl_desc midas_ioctls[] = { - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_TIME_IN_STATE, midas_ioctl_get_time_in_state), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_SET_TRACK_UID, midas_ioctl_set_track_uid), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_REMOVE_TRACK_UID, midas_ioctl_remove_track_uid), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_CLEAR_TRACK_UID, midas_ioctl_clear_track_uid), -}; - -#define KDATA_SIZE 512 -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg) -{ - struct midas_priv_info *info = filp->private_data; - const struct midas_ioctl_desc *ioctl = NULL; - midas_ioctl_t *func; - unsigned int nr = MIDAS_IOCTL_NR(cmd); - int ret = -EINVAL; - char kdata[KDATA_SIZE] = { }; - unsigned int in_size, out_size; - - if (nr >= MIDAS_CORE_IOCTL_CNT) { - pr_err("out of array\n"); - return -EINVAL; - } - - ioctl = &midas_ioctls[nr]; - - out_size = in_size = _IOC_SIZE(cmd); - if ((cmd & IOC_IN) == 0) - in_size = 0; - if ((cmd & IOC_OUT) == 0) - out_size = 0; - - if (out_size > KDATA_SIZE || in_size > KDATA_SIZE) { - pr_err("out of memory\n"); - ret = -EINVAL; - goto err_out_of_mem; - } - - func = ioctl->func; - if (unlikely(!func)) { - pr_err("no func\n"); - ret = -EINVAL; - goto err_no_func; - } - - if (copy_from_user(kdata, (void __user *)arg, in_size)) { - pr_err("copy_from_user failed\n"); - ret = -EFAULT; - goto err_fail_cp; - } - - ret = func(kdata, info); - - if (copy_to_user((void __user *)arg, kdata, out_size)) { - pr_err("copy_to_user failed\n"); - ret = -EFAULT; - } - -err_fail_cp: -err_no_func: -err_out_of_mem: - return ret; -} diff --git a/drivers/soc/oplus/midas/v1/vpu_pw_off_latency_proc.c b/drivers/soc/oplus/midas/v1/vpu_pw_off_latency_proc.c deleted file mode 100755 index d03979d94304..000000000000 --- a/drivers/soc/oplus/midas/v1/vpu_pw_off_latency_proc.c +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY - -// import from MTK vpu driver -extern int set_all_vpu_power_off_latency(uint64_t pw_off_latency); - -#define BUF_LEN 1024 - -static struct proc_dir_entry *g_vpu_pw_off_latency_pentry = NULL; - -static ssize_t vpu_pw_off_latency_proc_write(struct file *file, const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len; - uint64_t latency_ms; - char tmp[BUF_LEN + 1]; - - if (cnt == 0) - return 0; - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') - tmp[len - 1] = '\0'; - else - tmp[len] = '\0'; - - ret = sscanf(tmp, "%llu", &latency_ms); - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - pr_info("latency_ms cmd:%llu\n", latency_ms); - - set_all_vpu_power_off_latency(latency_ms); - - return cnt; -} - -static const struct file_operations vpu_pw_off_latency_proc_fops = { - .write = vpu_pw_off_latency_proc_write, -}; - -int __init vpu_pw_off_latency_proc_init(void) -{ - g_vpu_pw_off_latency_pentry = proc_create("all_vpu_pw_off_latency", - 0666, NULL, &vpu_pw_off_latency_proc_fops); - return 0; -} - - -void __exit vpu_pw_off_latency_proc_exit(void) -{ - if (NULL != g_vpu_pw_off_latency_pentry) { - proc_remove(g_vpu_pw_off_latency_pentry); - g_vpu_pw_off_latency_pentry = NULL; - } -} - -module_init(vpu_pw_off_latency_proc_init); -module_exit(vpu_pw_off_latency_proc_exit); - -#endif // #ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY diff --git a/drivers/soc/oplus/midas/v1_gki/Makefile b/drivers/soc/oplus/midas/v1_gki/Makefile deleted file mode 100755 index a4bde500f5bd..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -oplus_bsp_midas-objs := \ - binder_stats_dev.o \ - midas_dev.o \ - midas_ioctl.o \ - midas_module.o - -obj-$(CONFIG_OPLUS_FEATURE_MIDAS_GKI) += oplus_bsp_midas.o diff --git a/drivers/soc/oplus/midas/v1_gki/binder_stats_dev.c b/drivers/soc/oplus/midas/v1_gki/binder_stats_dev.c deleted file mode 100755 index 237d2ade2356..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/binder_stats_dev.c +++ /dev/null @@ -1,1451 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - -#define BINDER_STATS_LOGI(...) -#define BINDER_STATS_LOGE pr_err -/* #define BINDER_STATS_DEBUGFS */ - -#define BINDER_STATS_CTL_VERSION_CODE 1 - -#define BINDER_STATS_CTL_GET_VERSION 100 -#define BINDER_STATS_CTL_ENABLE 101 -#define BINDER_STATS_CTL_UPDATE 102 -#define BINDER_STATS_CTL_CFG_CLEAR 110 -#define BINDER_STATS_CTL_CFG_MAX_ITEM 111 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_NAME 112 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM 113 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_UID 114 -#define BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM 115 -#define BINDER_STATS_CTL_SRVMGR_INT 120 -#define BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME 121 -#define BINDER_STATS_CTL_RET_SUCC 0 -#define BINDER_STATS_CTL_RET_INVALID -1 - -#define OPLUS_MAX_SERVICE_NAME_LEN 32 -#define BINDER_STATS_MAX_COUNT_LIMIT 32768 -#define BINDER_STATS_DEFAULT_MAX_COUNT 4096 -#define BINDER_STATS_HASH_ORDER 9 -#define BINDER_STATS_FILTER_LIMIT_MAX 128 - -/* import from binder driver */ -struct binder_notify { - struct task_struct *caller_task; - struct task_struct *binder_task; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool pending_async; -}; - -struct binder_stats_item { - char caller_proc_comm[TASK_COMM_LEN]; - int caller_pid; - int caller_tgid; - int caller_uid; - char caller_comm[TASK_COMM_LEN]; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - char binder_proc_comm[TASK_COMM_LEN]; - int binder_pid; - int binder_tgid; - int binder_uid; - char binder_comm[TASK_COMM_LEN]; - unsigned int call_count; -}; - -/* - * binder_stats : user space mmap the buffer struct. - * this struct buffer is dynamic alloc, - * items size is max_item_cnt, it is config by user. - * items size BINDER_STATS_MAX_COUNT_LIMIT is invalid. - */ -struct binder_stats { - unsigned int max_item_cnt; - unsigned int valid_item_cnt; - struct binder_stats_item items[BINDER_STATS_MAX_COUNT_LIMIT]; -}; - -struct binder_stats_item_ref { - struct hlist_node hentry; - struct binder_stats_item *item; -}; - -struct binder_stats_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct mutex lock; - int version_code; - - struct list_head user_list_head; - bool regist_binder_stats_flag; - spinlock_t user_list_lock; - - DECLARE_HASHTABLE(handle_name_hash, BINDER_STATS_HASH_ORDER); - DECLARE_HASHTABLE(debug_id_name_hash, BINDER_STATS_HASH_ORDER); - int srvmgr_tgid; - spinlock_t srv_name_lock; - -#if defined(BINDER_STATS_DEBUGFS) - struct dentry *d_folder_binder_stats; - struct dentry *d_file_cmd; -#endif -}; - -struct binder_stats_filter_srv_name { - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm { - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid { - int uid; - bool intreresting; -}; - -struct binder_stats_handle_name { - int handle; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; -}; - -struct binder_stats_filter_srv_name_node { - struct hlist_node hentry; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm_node { - struct hlist_node hentry; - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid_node { - struct hlist_node hentry; - int uid; - bool intreresting; -}; - -struct binder_stats_handle_name_node { - struct hlist_node hentry_handle; - struct hlist_node hentry_debug_id; - int handle; - int node_debug_id; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; -}; - -struct binder_stats_user_context { - struct list_head list_node; - int enable; - int max_item_cnt; - struct binder_stats *binder_stats_buf_0; /* double swap buffer 0 */ - struct binder_stats *binder_stats_buf_1; /* double swap buffer 1 */ - struct binder_stats_item_ref *kernel_binder_stats_refs; - DECLARE_HASHTABLE(kernel_binder_stats_hash, BINDER_STATS_HASH_ORDER); - struct binder_stats *kernel_binder_stats; - struct binder_stats *user_binder_stats; - bool user_mmap_flag; - spinlock_t buf_lock; - - int enable_binder_comm; - DECLARE_HASHTABLE(intre_srv_name_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_srv_name; - bool has_unintr_srv_name; - DECLARE_HASHTABLE(intre_proc_comm_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_proc_comm; - bool has_unintr_proc_comm; - DECLARE_HASHTABLE(intre_uid_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_uid; - bool has_unintr_uid; -}; - -struct binder_stats_driver g_binder_stats_driver; - -/* key is from caller_comm & binder_comm && service_name */ -static inline long long hash_key(struct binder_notify *bn, int enable_binder_comm) { - long long key = 0; - int i; - long long *v1 = (long long *)bn->caller_task->comm; - long long *v2 = (long long *)bn->binder_task->comm; - long long *v3 = (long long *)bn->service_name; - for (i = 0; i < TASK_COMM_LEN/sizeof(long long); ++i) { - if (1 == enable_binder_comm) - key += (v1[i] + v2[i]); - else - key += v1[i]; - } - for (i = 0; i < OPLUS_MAX_SERVICE_NAME_LEN/sizeof(long long); ++i) { - key += v3[i]; - } - return key; -} - -static inline bool hash_match(struct binder_notify *bn, struct binder_stats_item *stats_item, int enable_binder_comm) { - struct task_struct *caller_proc_task = NULL; - struct task_struct *binder_proc_task = NULL; - if (NULL != bn->caller_task->group_leader) - caller_proc_task = bn->caller_task->group_leader; - else - caller_proc_task = bn->caller_task; - - if (NULL != bn->binder_task->group_leader) - binder_proc_task = bn->binder_task->group_leader; - else - binder_proc_task = bn->binder_task; - - if (1 == enable_binder_comm) - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_comm, bn->binder_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); - else - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); -} - -static inline long long hash_key_for_str(const char *str, unsigned int len) { - long long key = 0; - int i; - long long *v = (long long *)str; - for (i = 0; i < len/sizeof(long long); ++i) { - key += v[i]; - str += sizeof(long long); - } - for (i = 0; i < len%sizeof(long long); ++i) { - key += str[i]; - } - return key; -} - -static bool intreresting_filter(struct binder_stats_user_context *context_ptr, - struct binder_notify *bn) { - bool intreresting = false; - struct task_struct *caller_task; - struct task_struct *binder_proc_task; - int binder_uid; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - - caller_task = bn->caller_task; - binder_proc_task = NULL == bn->binder_task->group_leader? bn->binder_task: bn->binder_task->group_leader; - binder_uid = from_kuid_munged(current_user_ns(), task_uid(bn->binder_task)); - - if (!context_ptr->has_intr_srv_name && !context_ptr->has_intr_proc_comm && !context_ptr->has_intr_uid) { - intreresting = true; - } else { - intreresting = false; - } - - hash_for_each_possible(context_ptr->intre_srv_name_hash, hash_node_srv_name, hentry, - hash_key_for_str(bn->service_name, strlen(bn->service_name))) { - if (0 == strcmp(hash_node_srv_name->service_name, bn->service_name)) { - if (hash_node_srv_name->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_proc_comm_hash, hash_node_proc_comm, hentry, - hash_key_for_str(binder_proc_task->comm, strlen(binder_proc_task->comm))) { - if (0 == strcmp(hash_node_proc_comm->comm, binder_proc_task->comm)) { - if (hash_node_proc_comm->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_uid_hash, hash_node_uid, hentry, (long long)binder_uid) { - if (hash_node_uid->uid == binder_uid) { - return hash_node_uid->intreresting; - if (hash_node_uid->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - return intreresting; -} - -static void store_binder_stats_to_kernel(struct binder_notify *data) { - struct binder_stats_item *find_item = NULL; - unsigned long flags, ctx_flag; - struct binder_stats *kernel_binder_stats = NULL; - struct binder_stats_item_ref *ref_hash_node; - struct binder_stats_user_context *context_ptr = NULL; - struct task_struct *caller_task = NULL; - struct task_struct *binder_task = NULL; - - if (NULL == data || NULL == data->caller_task || NULL == data->binder_task) - return; - - caller_task = data->caller_task; - binder_task = data->binder_task; - - /* BINDER_STATS_LOGI("%d(%s) => (%s)(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - data->service_name, binder_task->comm, binder_task->pid, binder_task->comm); */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - - list_for_each_entry(context_ptr, &g_binder_stats_driver.user_list_head, list_node) { - if (NULL == context_ptr || NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) - continue; - - find_item = NULL; - - if (!intreresting_filter(context_ptr, data)) - continue; - - spin_lock_irqsave(&context_ptr->buf_lock, ctx_flag); - - kernel_binder_stats = context_ptr->kernel_binder_stats; - - /* find current item with hash */ - hash_for_each_possible(context_ptr->kernel_binder_stats_hash, ref_hash_node, hentry, hash_key(data, context_ptr->enable_binder_comm)) { - if (hash_match(data, ref_hash_node->item, context_ptr->enable_binder_comm)) { - find_item = ref_hash_node->item; - break; - } - } - - if (NULL != find_item) { - find_item->call_count++; - } else { - if (kernel_binder_stats->valid_item_cnt + 1 <= kernel_binder_stats->max_item_cnt) { - find_item = &(kernel_binder_stats->items[kernel_binder_stats->valid_item_cnt]); - - /* caller proc comm */ - if (NULL != caller_task->group_leader) - strncpy(find_item->caller_proc_comm, caller_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->caller_proc_comm, caller_task->comm, TASK_COMM_LEN); - - /* caller pid tgid uid */ - find_item->caller_pid = task_pid_nr(caller_task); - find_item->caller_tgid = task_tgid_nr(caller_task); - find_item->caller_uid = from_kuid_munged(current_user_ns(), task_uid(caller_task)); - /* caller comm */ - strncpy(find_item->caller_comm, caller_task->comm, TASK_COMM_LEN); - - /* service name */ - strncpy(find_item->service_name, data->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - - /* binder proc comm */ - if (NULL != binder_task->group_leader) - strncpy(find_item->binder_proc_comm, binder_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->binder_proc_comm, binder_task->comm, TASK_COMM_LEN); - - /* binder tgid uid */ - find_item->binder_tgid = task_tgid_nr(binder_task); - find_item->binder_uid = from_kuid_munged(current_user_ns(), task_uid(binder_task)); - - /* binder comm pid */ - if (1 == context_ptr->enable_binder_comm) { - find_item->binder_pid = task_pid_nr(binder_task); - strncpy(find_item->binder_comm, binder_task->comm, TASK_COMM_LEN); - } else { - find_item->binder_pid = find_item->binder_tgid; - strncpy(find_item->binder_comm, "binderTh", TASK_COMM_LEN); - } - - /* call count init */ - find_item->call_count = 1; - - /* add hash for improve search performance */ - ref_hash_node = &(context_ptr->kernel_binder_stats_refs[kernel_binder_stats->valid_item_cnt]); - ref_hash_node->item = find_item; - hash_add(context_ptr->kernel_binder_stats_hash, &ref_hash_node->hentry, hash_key(data, context_ptr->enable_binder_comm)); - - kernel_binder_stats->valid_item_cnt++; - } - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, ctx_flag); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); -} - -static void binder_stats_clear_user_context(struct binder_stats_user_context *context_ptr) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - BINDER_STATS_LOGI("start\n"); - - /* first remove user node from global user list - then clear the local user memory */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_del(&context_ptr->list_node); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (!IS_ERR_OR_NULL(context_ptr->user_binder_stats)) { - vfree(context_ptr->user_binder_stats); - context_ptr->user_binder_stats = NULL; - } - - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats)) { - vfree(context_ptr->kernel_binder_stats); - context_ptr->kernel_binder_stats = NULL; - } - - context_ptr->binder_stats_buf_0 = NULL; - context_ptr->binder_stats_buf_1 = NULL; - context_ptr->user_mmap_flag = false; - - context_ptr->enable = 0; -} - -static int user_enable_binder_stats(struct binder_stats_user_context *context_ptr, int enable) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - int max_item_cnt = BINDER_STATS_DEFAULT_MAX_COUNT; - int binder_stats_buffer_size = 0; - - if (0 != enable && 1 != enable) { - BINDER_STATS_LOGE("enable param error!\n"); - return -1; - } - if (context_ptr->enable == enable) { - BINDER_STATS_LOGE("enable value is same with current value!\n"); - return -1; - } - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("user mem in used!\n"); - return -1; - } - - if (1 == enable) { - if (NULL != context_ptr->binder_stats_buf_0 || - NULL != context_ptr->binder_stats_buf_1 || - NULL != context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer exist!\n"); - return -1; - } - - if (0 != context_ptr->max_item_cnt) { - max_item_cnt = context_ptr->max_item_cnt; - } - - binder_stats_buffer_size = 2*sizeof(unsigned int) + max_item_cnt*sizeof(struct binder_stats_item); - - context_ptr->binder_stats_buf_0 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_0->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_0->valid_item_cnt = 0; - context_ptr->kernel_binder_stats = context_ptr->binder_stats_buf_0; - - context_ptr->kernel_binder_stats_refs = vmalloc_user(max_item_cnt*sizeof(struct binder_stats_item_ref)); - if (IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - - hash_init(context_ptr->kernel_binder_stats_hash); - - context_ptr->binder_stats_buf_1 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_1->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_1->valid_item_cnt = 0; - context_ptr->user_binder_stats = context_ptr->binder_stats_buf_1; - - spin_lock_init(&context_ptr->buf_lock); - context_ptr->user_mmap_flag = false; - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_add(&context_ptr->list_node, &g_binder_stats_driver.user_list_head); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - context_ptr->enable = 1; - - return 0; - -enable_fail: - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - vfree(context_ptr->binder_stats_buf_1); - context_ptr->binder_stats_buf_1 = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - vfree(context_ptr->binder_stats_buf_0); - context_ptr->binder_stats_buf_0 = NULL; - } - context_ptr->user_binder_stats = NULL; - context_ptr->kernel_binder_stats = NULL; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - - return -1; - } else { - if (NULL == context_ptr->user_binder_stats || - NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer not exit!\n"); - return -1; - } - - binder_stats_clear_user_context(context_ptr); - - return 0; - } -} - -static int user_update_binder_stats(struct binder_stats_user_context *context_ptr) { - int ret = 0; - unsigned long flags; - struct binder_stats * swap_tmp; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - if (0 == context_ptr->enable) { - BINDER_STATS_LOGE("function not enabled!\n"); - return -1; - } - - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("memory is used!\n"); - return -1; - } - - spin_lock_irqsave(&context_ptr->buf_lock, flags); - - /* swap buffer & clear kernel_binder_stats & kernel_binder_stats_hash */ - if (NULL != context_ptr->kernel_binder_stats && NULL != context_ptr->user_binder_stats) { - swap_tmp = context_ptr->kernel_binder_stats; - context_ptr->kernel_binder_stats = context_ptr->user_binder_stats; - context_ptr->user_binder_stats = swap_tmp; - - /* reset cnt & clear hash */ - context_ptr->kernel_binder_stats->valid_item_cnt = 0; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - } else { - ret = -1; - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, flags); - - return ret; -} - -static int user_binder_stats_cfg_clear(struct binder_stats_user_context *context_ptr) { - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - struct hlist_node *tmp; - int i; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - hash_del(&hash_node_srv_name->hentry); - vfree(hash_node_srv_name); - } - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - hash_del(&hash_node_proc_comm->hentry); - vfree(hash_node_proc_comm); - } - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - hash_del(&hash_node_uid->hentry); - vfree(hash_node_uid); - } - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - context_ptr->enable_binder_comm = 0; - - context_ptr->max_item_cnt = 0; - - return 0; -} - -static int user_binder_stats_cfg_set_max_item_cnt(struct binder_stats_user_context *context_ptr, int max_item_cnt) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - if (max_item_cnt < 0 || max_item_cnt > BINDER_STATS_MAX_COUNT_LIMIT) { - BINDER_STATS_LOGE("invalid max_item_cnt!\n"); - return -1; - } - - context_ptr->max_item_cnt = max_item_cnt; - - return 0; -} - -static int user_binder_stats_cfg_set_enable_binder_comm(struct binder_stats_user_context *context_ptr, int enable_binder_comm) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - if (0 != enable_binder_comm && 1 != enable_binder_comm) { - BINDER_STATS_LOGE("enable_binder_comm param error!\n"); - return -1; - } - - context_ptr->enable_binder_comm = enable_binder_comm; - - return 0; -} - -static int user_binder_stats_add_intreresting_svr_name(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_srv_name *filter_srv_name) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_srv_name = vmalloc_user(sizeof(struct binder_stats_filter_srv_name_node)); - if (IS_ERR_OR_NULL(hash_node_srv_name)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_srv_name->service_name, filter_srv_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - hash_node_srv_name->intreresting = filter_srv_name->intreresting; - hash_add(context_ptr->intre_srv_name_hash, &hash_node_srv_name->hentry, - hash_key_for_str(hash_node_srv_name->service_name, strlen(hash_node_srv_name->service_name))); - - if (hash_node_srv_name->intreresting) { - context_ptr->has_intr_srv_name = true; - } else { - context_ptr->has_unintr_srv_name = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_srv_name->service_name, hash_node_srv_name->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_proc_comm(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_proc_comm *filter_proc_comm) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_proc_comm = vmalloc_user(sizeof(struct binder_stats_filter_proc_comm_node)); - if (IS_ERR_OR_NULL(hash_node_proc_comm)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_proc_comm->comm, filter_proc_comm->comm, TASK_COMM_LEN); - hash_node_proc_comm->intreresting = filter_proc_comm->intreresting; - hash_add(context_ptr->intre_proc_comm_hash, &hash_node_proc_comm->hentry, - hash_key_for_str(hash_node_proc_comm->comm, strlen(hash_node_proc_comm->comm))); - - if (hash_node_proc_comm->intreresting) { - context_ptr->has_intr_proc_comm = true; - } else { - context_ptr->has_unintr_proc_comm = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_proc_comm->comm, hash_node_proc_comm->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_uid(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_uid *filter_uid) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_uid_node *hash_node_uid; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_uid = vmalloc_user(sizeof(struct binder_stats_filter_uid_node)); - if (IS_ERR_OR_NULL(hash_node_uid)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - hash_node_uid->uid = filter_uid->uid; - hash_node_uid->intreresting = filter_uid->intreresting; - hash_add(context_ptr->intre_uid_hash, &hash_node_uid->hentry, (long long)hash_node_uid->uid); - - if (hash_node_uid->intreresting) { - context_ptr->has_intr_uid = true; - } else { - context_ptr->has_unintr_uid = true; - } - - /* BINDER_STATS_LOGI("%d %d\n", hash_node_uid->uid, hash_node_uid->intreresting); */ - - return ret; -} - -static int set_driver_binder_stats_srvmgr_init() { - BINDER_STATS_LOGI("BDS_MGR task_tgid_nr:%d\n", task_tgid_nr(current)); - g_binder_stats_driver.srvmgr_tgid = task_tgid_nr(current); - return 0; -} - -static int set_driver_binder_stats_srvmgr_handle_name(struct binder_stats_handle_name *handle_name) { - int ret = 0; - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_stats_handle_name_node *handle_name_new; - - if (NULL == handle_name) { - BINDER_STATS_LOGE("handle_name error!\n"); - return -1; - } - - handle_name_new = kmalloc(sizeof(struct binder_stats_handle_name_node), GFP_ATOMIC); - if (NULL == handle_name_new) { - BINDER_STATS_LOGE("handle_name_new error!\n"); - return -1; - } - memset(handle_name_new, 0, sizeof(struct binder_stats_handle_name_node)); - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, handle_name->handle) { - if (handle_name_tmp->handle == handle_name->handle) - handle_name_find = handle_name_tmp; - } - - if (NULL != handle_name_find) { - strncpy(handle_name_find->service_name, handle_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - handle_name_find->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - } else { - handle_name_new->handle = handle_name->handle; - strncpy(handle_name_new->service_name, handle_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - handle_name_new->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - hash_add(g_binder_stats_driver.handle_name_hash, &handle_name_new->hentry_handle, handle_name_new->handle); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find && NULL != handle_name_new) { - BINDER_STATS_LOGI("BDS_MGR BDS_SET_HANDLE_NAME %d %s\n", handle_name_find->handle, handle_name_find->service_name); - kfree(handle_name_new); - } else { - BINDER_STATS_LOGE("BDS_MGR BDS_SET_HANDLE_NAME_BUG not found ref_desc:%u service_name:%s\n", handle_name_new->handle, handle_name_new->service_name); - } - - return ret; -} - -static int binder_stats_driver_open(struct inode *inode, struct file *filp) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - if (!g_binder_stats_driver.regist_binder_stats_flag) { - g_binder_stats_driver.regist_binder_stats_flag = true; - } - - context_ptr = vmalloc(sizeof(struct binder_stats_user_context)); - if (IS_ERR_OR_NULL(context_ptr)) { - BINDER_STATS_LOGE("vmalloc failed\n"); - goto open_fail; - } - - memset(context_ptr, 0, sizeof(struct binder_stats_user_context)); - - /* init config data */ - - context_ptr->max_item_cnt = 0; - - context_ptr->enable_binder_comm = 0; - - hash_init(context_ptr->intre_srv_name_hash); - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_init(context_ptr->intre_proc_comm_hash); - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_init(context_ptr->intre_uid_hash); - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - filp->private_data = context_ptr; - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; - -open_fail: - - mutex_unlock(&g_binder_stats_driver.lock); - - return -1; -} - -static int binder_stats_driver_release(struct inode *ignored, struct file *filp) { - struct binder_stats_user_context *context_ptr; - unsigned long flags; - struct list_head *pos = NULL; - int list_size = 0; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - if (IS_ERR_OR_NULL(context_ptr)) { - mutex_unlock(&g_binder_stats_driver.lock); - return -1; - } - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_size = 0; - list_for_each(pos, &g_binder_stats_driver.user_list_head) { - ++list_size; - } - if (g_binder_stats_driver.regist_binder_stats_flag && - ((1 == list_size && list_is_last(&context_ptr->list_node, &g_binder_stats_driver.user_list_head)) || - list_empty(&g_binder_stats_driver.user_list_head))) { - g_binder_stats_driver.regist_binder_stats_flag = false; - } - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (!IS_ERR_OR_NULL(context_ptr)) { - if (1 == context_ptr->enable) { - binder_stats_clear_user_context(context_ptr); - } - vfree(context_ptr); - filp->private_data = NULL; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static void binder_stats_mmap_close(struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - if (NULL == vma || NULL == vma->vm_file || NULL == vma->vm_file->private_data) { - BINDER_STATS_LOGE("invalid private_data\n"); - return; - } - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = vma->vm_file->private_data; - context_ptr->user_mmap_flag = false; - - mutex_unlock(&g_binder_stats_driver.lock); -} - -static const struct vm_operations_struct binder_stats_mmap_vmops = { - .close = binder_stats_mmap_close, -}; - -static int binder_stats_driver_mmap(struct file *filp, struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - - if (NULL != context_ptr && NULL != context_ptr->user_binder_stats) { - vma->vm_ops = &binder_stats_mmap_vmops; - if (remap_vmalloc_range(vma, context_ptr->user_binder_stats, vma->vm_pgoff)) { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - context_ptr->user_mmap_flag = true; - } else { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static long binder_stats_driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - long ret = -1; - int enable = 0; - int max_item_cnt = 0; - int enable_binder_comm = 0; - struct binder_stats_filter_srv_name filter_srv_name; - struct binder_stats_filter_proc_comm filter_proc_comm; - struct binder_stats_filter_uid filter_uid; - struct binder_stats_user_context *context_ptr = filp->private_data; - struct binder_stats_handle_name handle_name; - - BINDER_STATS_LOGI("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - BINDER_STATS_LOGE("context_ptr error!\n"); - return ret; - } - - mutex_lock(&g_binder_stats_driver.lock); - - switch (cmd) { - case BINDER_STATS_CTL_GET_VERSION: { - if (0 != arg) { - if(0 == copy_to_user((unsigned int *)arg, - &g_binder_stats_driver.version_code, sizeof(unsigned int))) { - BINDER_STATS_LOGI("BINDER_STATS_CTL_GET_VERSION %d\n", g_binder_stats_driver.version_code); - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. arg error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_ENABLE: { - if(0 != copy_from_user(&enable, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_enable_binder_stats(context_ptr, enable)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_UPDATE: { - if (0 == user_update_binder_stats(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_UPDATE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_CLEAR: { - if (0 == user_binder_stats_cfg_clear(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_CLEAR failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_MAX_ITEM: { - if(0 != copy_from_user(&max_item_cnt, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_max_item_cnt(context_ptr, max_item_cnt)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM: { - if(0 != copy_from_user(&enable_binder_comm, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_enable_binder_comm(context_ptr, enable_binder_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_NAME: { - if(0 != copy_from_user(&filter_srv_name, (char *)arg, sizeof(struct binder_stats_filter_srv_name))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_svr_name(context_ptr, &filter_srv_name)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM: { - if(0 != copy_from_user(&filter_proc_comm, (char *)arg, sizeof(struct binder_stats_filter_proc_comm))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_proc_comm(context_ptr, &filter_proc_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_UID: { - if(0 != copy_from_user(&filter_uid, (int *)arg, sizeof(struct binder_stats_filter_uid))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_uid(context_ptr, &filter_uid)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_SRVMGR_INT: { - if (0 == set_driver_binder_stats_srvmgr_init()) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_INT failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME: { - if(0 != copy_from_user(&handle_name, (int *)arg, sizeof(struct binder_stats_handle_name))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == set_driver_binder_stats_srvmgr_handle_name(&handle_name)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - default: { - BINDER_STATS_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = BINDER_STATS_CTL_RET_INVALID; - } - break; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = binder_stats_driver_open, - .release = binder_stats_driver_release, - .unlocked_ioctl = binder_stats_driver_ioctl, - .mmap = binder_stats_driver_mmap, -}; - -void binder_proc_transaction_hook(void *data, - struct task_struct *caller_task, struct task_struct *binder_proc_task, struct task_struct *binder_th_task, - int node_debug_id, unsigned int code, bool pending_async) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_notify bn; - bool stats_flag; - - if (NULL == caller_task || NULL == binder_proc_task) - return; - - if (!g_binder_stats_driver.regist_binder_stats_flag) - return; - - memset(&bn, 0, sizeof(bn)); - stats_flag = false; - if (g_binder_stats_driver.srvmgr_tgid == task_tgid_nr(binder_proc_task)) { - strncpy(bn.service_name, binder_proc_task->comm, TASK_COMM_LEN); - bn.service_name[TASK_COMM_LEN-1] = '\0'; - stats_flag = true; - } else { - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.debug_id_name_hash, handle_name_tmp, hentry_debug_id, node_debug_id) { - if (handle_name_tmp->node_debug_id == node_debug_id) - handle_name_find = handle_name_tmp; - } - if (NULL != handle_name_find) { - strncpy(bn.service_name, handle_name_find->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - bn.service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - stats_flag = true; - } else { - strncpy(bn.service_name, "", OPLUS_MAX_SERVICE_NAME_LEN); - } - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - } - - if (stats_flag) { - bn.caller_task = caller_task; - bn.pending_async = pending_async; - if (NULL != binder_th_task) { - BINDER_STATS_LOGI("BDS_TRAN %d(%s) -> %d(%s) %d(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - node_debug_id, bn.service_name, - binder_proc_task->pid, binder_proc_task->comm, binder_th_task->pid, binder_th_task->comm); - bn.binder_task = binder_th_task; - } else { - BINDER_STATS_LOGI("BDS_TRAN %d(%s) -> %d(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - node_debug_id, bn.service_name, - binder_proc_task->pid, binder_proc_task->comm); - bn.binder_task = binder_proc_task; - } - store_binder_stats_to_kernel(&bn); - } -} - -void binder_new_ref_hool(void *data, - struct task_struct *proc, uint32_t ref_desc, int node_debug_id) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_stats_handle_name_node *handle_name_new; - int tgid; - - if (NULL == proc) - return; - - tgid = task_tgid_nr(proc); - - if (g_binder_stats_driver.srvmgr_tgid < 0 || g_binder_stats_driver.srvmgr_tgid != tgid) { - BINDER_STATS_LOGI("BDS_IGN ignored! srvmgr_tgid:%d proc_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid, tgid); - return; - } - - handle_name_new = kmalloc(sizeof(struct binder_stats_handle_name_node), GFP_ATOMIC); - if (NULL == handle_name_new) { - BINDER_STATS_LOGE("handle_name_new error!\n"); - return; - } - memset(handle_name_new, 0, sizeof(struct binder_stats_handle_name_node)); - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, ref_desc) { - if (handle_name_tmp->handle == ref_desc) - handle_name_find = handle_name_tmp; - } - - if (NULL == handle_name_find) { - handle_name_new->handle = ref_desc; - handle_name_new->node_debug_id = node_debug_id; - strncpy(handle_name_new->service_name, "", OPLUS_MAX_SERVICE_NAME_LEN); - hash_add(g_binder_stats_driver.handle_name_hash, &handle_name_new->hentry_handle, ref_desc); - hash_add(g_binder_stats_driver.debug_id_name_hash, &handle_name_new->hentry_debug_id, node_debug_id); - } else { - handle_name_find->node_debug_id = node_debug_id; - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find && NULL != handle_name_new) { - BINDER_STATS_LOGE("BDS_NEW_BUG tgid:%d ref_desc:%u node_debug_id:%d\n", task_tgid_nr(proc), ref_desc, node_debug_id); - kfree(handle_name_new); - } else { - BINDER_STATS_LOGI("BDS_NEW tgid:%d ref_desc:%u node_debug_id:%d\n", task_tgid_nr(proc), ref_desc, node_debug_id); - } -} - -void binder_del_ref_hook(void *data, - struct task_struct *proc, uint32_t ref_desc) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - int tgid; - - if (NULL == proc) - return; - - tgid = task_tgid_nr(proc); - - if (g_binder_stats_driver.srvmgr_tgid < 0 || g_binder_stats_driver.srvmgr_tgid != tgid) { - BINDER_STATS_LOGI("BDS_IGN ignored! srvmgr_tgid:%d proc_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid, tgid); - return; - } - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, ref_desc) { - if (handle_name_tmp->handle == ref_desc) - handle_name_find = handle_name_tmp; - } - if (NULL != handle_name_find) { - hash_del(&handle_name_find->hentry_handle); - hash_del(&handle_name_find->hentry_debug_id); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find) { - BINDER_STATS_LOGI("BDS_DEL tgid:%d ref_desc:%u\n", tgid, ref_desc); - kfree(handle_name_find); - } else { - BINDER_STATS_LOGE("BDS_DEL_BUG tgid:%d not found ref_desc:%u\n", tgid, ref_desc); - } -} - -#if defined(BINDER_STATS_DEBUGFS) - -static ssize_t debug_write(struct file *file, const char __user *ubuf, - size_t count, loff_t *ppos) { - const int debug_bufmax = 512 - 1; - size_t ret; - char cmd_buffer[512]; - int i; - struct hlist_node *tmp; - struct binder_stats_handle_name_node *handle_name_find; - - ret = count; - - if (count > debug_bufmax) - count = debug_bufmax; - - if (copy_from_user(&cmd_buffer, ubuf, count)) - return -EFAULT; - - cmd_buffer[count] = 0; - - if (strncmp(cmd_buffer, "srvmap", 6) == 0) { - BINDER_STATS_LOGI("BDS_DBG srvmap\n"); - BINDER_STATS_LOGI("BDS_DBG srvmgr_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid); - hash_for_each_safe(g_binder_stats_driver.handle_name_hash, i, tmp, handle_name_find, hentry_handle) { - BINDER_STATS_LOGI("BDS_DBG service_name:%s handle:%d node_debug_id:%d\n", - handle_name_find->service_name, handle_name_find->handle, handle_name_find->node_debug_id); - } - } - - return ret; -} - -static const struct file_operations binder_stats_dbg_fops = { - .write = debug_write, -}; - -#endif - -int __init binder_stats_dev_init(void) { - int err = 0; - g_binder_stats_driver.version_code = BINDER_STATS_CTL_VERSION_CODE; - mutex_init(&g_binder_stats_driver.lock); - spin_lock_init(&g_binder_stats_driver.user_list_lock); - INIT_LIST_HEAD(&g_binder_stats_driver.user_list_head); - hash_init(g_binder_stats_driver.handle_name_hash); - hash_init(g_binder_stats_driver.debug_id_name_hash); - g_binder_stats_driver.srvmgr_tgid = -1; - spin_lock_init(&g_binder_stats_driver.srv_name_lock); - - err = alloc_chrdev_region(&g_binder_stats_driver.dev, 0, 1, "binder_stats"); - if (err < 0) { - BINDER_STATS_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_binder_stats_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_binder_stats_driver.cdev, g_binder_stats_driver.dev, 1); - if (err < 0) { - BINDER_STATS_LOGE("cdev_add g_binder_stats_driver.cdev failed!\n"); - goto unreg_region; - } - - g_binder_stats_driver.dev_class = class_create(THIS_MODULE, "binder_stats_class"); - if (IS_ERR(g_binder_stats_driver.dev_class)) { - BINDER_STATS_LOGE("create class g_binder_stats_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_binder_stats_driver.device = device_create(g_binder_stats_driver.dev_class, - NULL, g_binder_stats_driver.dev, NULL, "binder_stats"); - if (IS_ERR(g_binder_stats_driver.device)) { - BINDER_STATS_LOGE("device_create g_binder_stats_driver.device error\n"); - goto destroy_class; - } - - g_binder_stats_driver.regist_binder_stats_flag = false; - - register_trace_android_vh_binder_proc_transaction(binder_proc_transaction_hook, NULL); - register_trace_android_vh_binder_new_ref(binder_new_ref_hool, NULL); - register_trace_android_vh_binder_del_ref(binder_del_ref_hook, NULL); - -#if defined(BINDER_STATS_DEBUGFS) - g_binder_stats_driver.d_folder_binder_stats = debugfs_create_dir("binder_stats", NULL); - if (g_binder_stats_driver.d_folder_binder_stats) - g_binder_stats_driver.d_file_cmd = debugfs_create_file("cmd", S_IFREG | 0644, - g_binder_stats_driver.d_folder_binder_stats, NULL, &binder_stats_dbg_fops); -#endif - - return 0; - -destroy_class: - class_destroy(g_binder_stats_driver.dev_class); - -destroy_cdev: - cdev_del(&g_binder_stats_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_binder_stats_driver.dev, 1); - -fail: - return -1; -} - - -void __exit binder_stats_dev_exit(void) { -#if defined(BINDER_STATS_DEBUGFS) - if (g_binder_stats_driver.d_file_cmd) - debugfs_remove(g_binder_stats_driver.d_file_cmd); - if (g_binder_stats_driver.d_folder_binder_stats) - debugfs_remove(g_binder_stats_driver.d_folder_binder_stats); -#endif - unregister_trace_android_vh_binder_proc_transaction(binder_proc_transaction_hook, NULL); - unregister_trace_android_vh_binder_new_ref(binder_new_ref_hool, NULL); - unregister_trace_android_vh_binder_del_ref(binder_del_ref_hook, NULL); - if (g_binder_stats_driver.dev_class) { - device_destroy(g_binder_stats_driver.dev_class, g_binder_stats_driver.dev); - class_destroy(g_binder_stats_driver.dev_class); - g_binder_stats_driver.dev_class = NULL; - } - - cdev_del(&g_binder_stats_driver.cdev); - - unregister_chrdev_region(g_binder_stats_driver.dev, 1); -} - -#else /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - -int __init binder_stats_dev_init(void) { - return 0; -} - -void __exit binder_stats_dev_exit(void) { -} - -#endif /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - diff --git a/drivers/soc/oplus/midas/v1_gki/dispcap_dev.c b/drivers/soc/oplus/midas/v1_gki/dispcap_dev.c deleted file mode 100755 index fdf9c83cd8aa..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/dispcap_dev.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * linux/drivers/soc/oplus/midas/dispcap_dev.c - * - * Added dispcap drivers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#if defined(CONFIG_OPLUS_FEATURE_DISPCAP) - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* import from cwb driver begin */ - -enum CWB_BUFFER_TYPE { - IMAGE_ONLY, - CARRY_METADATA, - BUFFER_TYPE_NR, -}; -struct mtk_cwb_funcs { - /** - * @get_buffer: - * - * This function is optional. - * - * If user hooks this callback, driver will use this first when - * wdma irq is arrived. (capture done) - * User need fill buffer address to *buffer. - * - * If user not hooks this callback driver will confirm whether - * mtk_wdma_capture_info->user_buffer is NULL or not. - * User can use setUserBuffer() assigned this param. - */ - void (*get_buffer)(void **buffer); - - /** - * @copy_done: - * - * When Buffer copy done will be use this callback to notify user. - */ - void (*copy_done)(void *buffer, enum CWB_BUFFER_TYPE type); -}; - -struct mtk_rect { - int x; - int y; - int width; - int height; -}; - -extern bool mtk_drm_set_cwb_roi(struct mtk_rect rect); -extern bool mtk_drm_cwb_enable(int en, - const struct mtk_cwb_funcs *funcs, - enum CWB_BUFFER_TYPE type); -extern bool mtk_drm_set_cwb_user_buf(void *user_buffer, enum CWB_BUFFER_TYPE type); - -/* import from ion driver */ - -struct ion_handle; -extern struct ion_device *g_ion_device; -extern void * ion_map_kernel(struct ion_client *client, struct ion_handle *handle); -extern void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); - -/* dispcap driver */ - -#define DISPCAP_CTL_SET_CAPTURE_RECT 97 -#define DISPCAP_CTL_SET_CAPTURE_INTERVAL 98 -#define DISPCAP_CTL_ENABLE_CAPTURE 99 -#define DISPCAP_CTL_SET_BUFFER 100 -#define DISPCAP_CTL_WAIT_BUFFER_COMPLETE 101 -#define DISPCAP_CTL_RET_SUCC 0 -#define DISPCAP_CTL_RET_WAIT_TIMEOUT 1 -#define DISPCAP_CTL_RET_INVALID -1 -#define DISPCAP_CTL_RET_ERROR -2 -#define DISPCAP_LOGD(...) -#define DISPCAP_LOGE pr_err - -struct disp_capture_rect -{ - int x; - int y; - int w; - int h; -}; - -struct disp_driver_context -{ - struct ion_handle *dispcap_ion_handle; -}; - -struct disp_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct ion_client *ion_client; - struct completion dispcap_cmp; - struct mutex dispcap_lock; - bool dispcap_used; - int pid; -}; - -static struct disp_driver g_disp_driver; - -void my_user_copy_done(void *buffer, enum CWB_BUFFER_TYPE type) { - DISPCAP_LOGD("start : %p\n", buffer); - complete(&g_disp_driver.dispcap_cmp); -} - -static const struct mtk_cwb_funcs user_cwb_funcs = { - .copy_done = my_user_copy_done, -}; - -static int driver_open(struct inode *inode, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if (g_disp_driver.dispcap_used) { - DISPCAP_LOGD("dispcap is in used. pid:%d\n", g_disp_driver.pid); - mutex_unlock(&g_disp_driver.dispcap_lock); - return -1; - } - - context_ptr = kmalloc(sizeof(struct disp_driver_context), GFP_KERNEL); - if (NULL == context_ptr) { - mutex_unlock(&g_disp_driver.dispcap_lock); - return -ENOMEM; - } - - context_ptr->dispcap_ion_handle = NULL; - - filp->private_data = context_ptr; - - g_disp_driver.dispcap_used = true; - g_disp_driver.pid = current->pid; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static int driver_release(struct inode *ignored, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr = filp->private_data; - if (NULL != context_ptr) { - - // disable capture buffer and unmap - mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY); - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - kfree(context_ptr); - filp->private_data = NULL; - } - - g_disp_driver.dispcap_used = false; - g_disp_driver.pid = -1; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static long driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) -{ - long ret = -1; - struct disp_driver_context *context_ptr = filp->private_data; - - DISPCAP_LOGD("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - DISPCAP_LOGE("context_ptr error!\n"); - return ret; - } - - switch (cmd) { - case DISPCAP_CTL_SET_CAPTURE_RECT: { - struct disp_capture_rect rect; - if(0 != copy_from_user(&rect, (void __user *)arg, sizeof(struct disp_capture_rect))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_CAPTURE_RECT arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - struct mtk_rect mrect; - mrect.x = rect.x; - mrect.y = rect.y; - mrect.width = rect.w; - mrect.height = rect.h; - if(!mtk_drm_set_cwb_roi(mrect)) { - DISPCAP_LOGE("setCaptureRect error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("setCaptureRect:%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_ENABLE_CAPTURE: { - int capture; - if(0 != copy_from_user(&capture, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_ENABLE_CAPTURE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_cwb_enable(capture, &user_cwb_funcs, IMAGE_ONLY)) { - DISPCAP_LOGE("setCaptureInterval error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("enableCapture:%d mtk_crtc_capt_enable\n", capture); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_SET_BUFFER: { - int ion_share_fd; - struct dma_buf *cur_dma_buf; - void * map_ion_va; - - if(0 != copy_from_user(&ion_share_fd, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_BUFFER arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - DISPCAP_LOGD("ion_share_fd:%d\n", ion_share_fd); - - cur_dma_buf = dma_buf_get(ion_share_fd); - if (NULL == cur_dma_buf) { - DISPCAP_LOGE("dma_buf_get failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - break; - } - DISPCAP_LOGD("cur_dma_buf:%p\n", cur_dma_buf); - DISPCAP_LOGD("cur_dma_buf size:%lu\n", cur_dma_buf->size); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr->dispcap_ion_handle = ion_import_dma_buf_fd(g_disp_driver.ion_client, ion_share_fd); - if (NULL == context_ptr->dispcap_ion_handle) { - DISPCAP_LOGE("ion_import_dma_buf_fd failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_import_dma_buf_fd ion_handle:%p\n", context_ptr->dispcap_ion_handle); - - map_ion_va = ion_map_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - if (NULL == map_ion_va) { - DISPCAP_LOGE("ion_map_kernel failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_map_kernel map_ion_va:%p\n", map_ion_va); - - DISPCAP_LOGD("reinit_completion\n"); - reinit_completion(&g_disp_driver.dispcap_cmp); - - DISPCAP_LOGD("setUserBuffer: %p\n", map_ion_va); - if(!mtk_drm_set_cwb_user_buf((void *)map_ion_va, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_WAIT_BUFFER_COMPLETE: { - int wait_ms; - int wait_ret; - if(0 != copy_from_user(&wait_ms, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_WAIT_BUFFER_COMPLETE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout timeout:%dms begin ...\n", wait_ms); - wait_ret = wait_for_completion_interruptible_timeout(&g_disp_driver.dispcap_cmp, msecs_to_jiffies(wait_ms)); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout OK wait_ret:%d\n", wait_ret); - if (0 == wait_ret) { - ret = DISPCAP_CTL_RET_WAIT_TIMEOUT; - } else if (0 < wait_ret) { - ret = DISPCAP_CTL_RET_SUCC; - } else { - ret = DISPCAP_CTL_RET_INVALID; - } - } - break; - default: { - DISPCAP_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = DISPCAP_CTL_RET_INVALID; - } - break; - } - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = driver_open, - .release = driver_release, - .unlocked_ioctl = driver_ioctl, -}; - -int __init dispcap_dev_init(void) -{ - int err = 0; - - DISPCAP_LOGD("start\n"); - - g_disp_driver.dev_class = NULL; - g_disp_driver.device = NULL; - g_disp_driver.dev_class = NULL; - g_disp_driver.ion_client = NULL; - g_disp_driver.dispcap_used = false; - mutex_init(&g_disp_driver.dispcap_lock); - - err = alloc_chrdev_region(&g_disp_driver.dev, 0, 1, "midas_dispcap"); - if (err < 0) { - DISPCAP_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_disp_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_disp_driver.cdev, g_disp_driver.dev, 1); - if (err < 0) { - DISPCAP_LOGE("cdev_add g_disp_driver.cdev failed!\n"); - goto unreg_region; - } - - g_disp_driver.dev_class = class_create(THIS_MODULE, "midas_dispcap_class"); - if (IS_ERR(g_disp_driver.dev_class)) { - DISPCAP_LOGE("create class g_disp_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_disp_driver.device = device_create(g_disp_driver.dev_class, NULL, g_disp_driver.dev, NULL, "midas_dispcap"); - if (IS_ERR(g_disp_driver.device)) { - DISPCAP_LOGE("device_create g_disp_driver.device error\n"); - goto destroy_class; - } - - g_disp_driver.ion_client = ion_client_create(g_ion_device, "dispcap_ion_client"); - if (NULL == g_disp_driver.ion_client) { - DISPCAP_LOGE("ion_client_create g_disp_driver.ion_client failed\n"); - goto destroy_device; - } - - init_completion(&g_disp_driver.dispcap_cmp); - - return 0; - -destroy_device: - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - -destroy_class: - class_destroy(g_disp_driver.dev_class); - -destroy_cdev: - cdev_del(&g_disp_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_disp_driver.dev, 1); - -fail: - return -1; -} - -void __exit dispcap_dev_exit(void) -{ - DISPCAP_LOGD("start\n"); - - if (NULL != g_disp_driver.ion_client) { - ion_client_destroy(g_disp_driver.ion_client); - g_disp_driver.ion_client = NULL; - } - - if (g_disp_driver.dev_class) { - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - class_destroy(g_disp_driver.dev_class); - g_disp_driver.dev_class = NULL; - } - - cdev_del(&g_disp_driver.cdev); - - unregister_chrdev_region(g_disp_driver.dev, 1); -} - - -module_init(dispcap_dev_init); -module_exit(dispcap_dev_exit); - -#endif // #if defined(CONFIG_OPLUS_FEATURE_DISPCAP) diff --git a/drivers/soc/oplus/midas/v1_gki/midas_dev.c b/drivers/soc/oplus/midas/v1_gki/midas_dev.c deleted file mode 100755 index b48ed6fc2d0c..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/midas_dev.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "midas_dev.h" - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -#include -#else -#include -#endif - -#define MIDAS_MAX_DEVS 1 -#define MAX_RASMEVENT_PARAM 7 - -static char *rasm_env[MAX_RASMEVENT_PARAM]; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -#ifndef _STRUCT_TIMESPEC -struct timeval { - long tv_sec; - long tv_usec; -}; -#endif -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -static void do_gettimeofday(struct timeval *tv) -{ - struct timespec64 now; - - ktime_get_real_ts64(&now); - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000; -} -#endif - -static void do_getboottime(struct timeval *tv) -{ - struct timespec64 now; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ktime_get_boottime_ts64(&now); -#else - get_monotonic_boottime64(&now); -#endif - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000; -} - -struct rasm_data { - long last_suspend_time; - long last_resume_time; - long last_resume_boot_time; - long last_suspend_millsec_time; - long last_resume_millsec_time; -}; - -static int rasm_resume(struct device *dev) { - struct timeval resume_time; - struct timeval resume_boot_time; - struct rasm_data *data; - int index = 0; - int i; - - data = dev->driver_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - do_gettimeofday(&resume_time); - data->last_resume_time = resume_time.tv_sec; - data->last_resume_millsec_time = resume_time.tv_sec * 1000 + resume_time.tv_usec / 1000; - do_getboottime(&resume_boot_time); - data->last_resume_boot_time = resume_boot_time.tv_sec * 1000 + resume_boot_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will resume.", data->last_resume_time); - - rasm_env[index++] = kasprintf(GFP_KERNEL, "NAME=rasm"); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend=%ld", data->last_suspend_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume=%ld", data->last_resume_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_boot=%ld", data->last_resume_boot_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_millsec=%ld", data->last_resume_millsec_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend_millsec=%ld", data->last_suspend_millsec_time); - rasm_env[index++] = NULL; - - if (index > ARRAY_SIZE(rasm_env)) - BUG(); - - kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, rasm_env); - for (i = 0; i < index - 1; ++i) - kfree(rasm_env[i]); - return 0; -} - -static int rasm_suspend(struct device *dev) { - struct timeval suspend_time; - struct rasm_data *data; - - data = dev->driver_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - do_gettimeofday(&suspend_time); - data->last_suspend_time = suspend_time.tv_sec; - data->last_suspend_millsec_time = suspend_time.tv_sec * 1000 + suspend_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will suspend.", data->last_suspend_time); - return 0; -} -static const struct dev_pm_ops rasm_pm_ops = { - .suspend = rasm_suspend, - .resume = rasm_resume, -}; -static int midas_dev_mmap(struct file *filp, struct vm_area_struct *vma) -{ - struct midas_priv_info *info = filp->private_data; - if (!info) - return -EINVAL; - - if (remap_vmalloc_range(vma, info->mmap_addr, - vma->vm_pgoff)) { - pr_err("remap failed\n"); - return -EAGAIN; - } - - return 0; -} - -static int midas_dev_open(struct inode *inode, struct file *filp) -{ - int ret = 0; - - struct midas_priv_info *info = kzalloc(sizeof(struct midas_priv_info), GFP_KERNEL); - if (!info) - return -ENOMEM; - - info->mmap_addr = vmalloc_user(sizeof(struct midas_mmap_data)); - if (!info->mmap_addr) { - pr_err("mmap_addr vmalloc failed!\n"); - ret = -ENOMEM; - goto err_info_alloc; - } - - filp->private_data = info; - return 0; - -err_info_alloc: - kfree(info); - return ret; -} - -static int midas_dev_release(struct inode *inode, struct file *filp) -{ - struct midas_priv_info *info = filp->private_data; - if (!info) - return 0; - - if (info->mmap_addr != NULL) - vfree(info->mmap_addr); - - kfree(info); - return 0; -} - -static const struct file_operations midas_dev_fops = { - .open = midas_dev_open, - .release = midas_dev_release, - .mmap = midas_dev_mmap, - .unlocked_ioctl = midas_dev_ioctl, -}; - -static int midas_pdev_probe(struct platform_device *pdev) -{ - int ret = 0; - struct device *dev; - struct midas_dev_info *dev_info; - - dev_info = kzalloc(sizeof(struct midas_dev_info), GFP_KERNEL); - if (!dev_info) { - pr_err("Fail to alloc dev info\n"); - ret = -ENOMEM; - goto err_info_alloc; - } - - ret = alloc_chrdev_region(&dev_info->devno, 0, MIDAS_MAX_DEVS, "midas_dev"); - if (ret) { - pr_err("Fail to alloc devno, ret=%d\n", ret); - goto err_cdev_alloc; - } - - cdev_init(&dev_info->cdev, &midas_dev_fops); - ret = cdev_add(&dev_info->cdev, dev_info->devno, MIDAS_MAX_DEVS); - if (ret) { - pr_err("Fail to add cdev, ret=%d\n", ret); - goto err_cdev_add; - } - - dev_info->class = class_create(THIS_MODULE, "midas"); - if (IS_ERR_OR_NULL(dev_info->class)) { - pr_err("Fail to create class, ret=%d\n", ret); - goto err_class_create; - } - - dev = device_create(dev_info->class, NULL, dev_info->devno, - dev_info, "midas_dev"); - - if (IS_ERR_OR_NULL(dev)) { - pr_err("Fail to create device, ret=%d\n", ret); - goto err_device_create; - } - - platform_set_drvdata(pdev, dev_info); - - return 0; - -err_device_create: - class_destroy(dev_info->class); -err_class_create: - cdev_del(&dev_info->cdev); -err_cdev_add: - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); -err_cdev_alloc: - kfree(dev_info); -err_info_alloc: - return ret; -} - - -static int midas_pdev_remove(struct platform_device *pdev) -{ - struct midas_dev_info *dev_info = platform_get_drvdata(pdev); - if (!dev_info) - return -EINVAL; - - device_destroy(dev_info->class, dev_info->devno); - class_destroy(dev_info->class); - cdev_del(&dev_info->cdev); - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); - kfree(dev_info); - - return 0; -} - -static void midas_pdev_release(struct device *dev) -{ - return; -} - -static struct platform_device midas_pdev = { - .id = -1, - .name = "midas-pdev", - .dev = { - .release = midas_pdev_release, - } -}; - -static const struct of_device_id midas_pdev_dt_ids[] = { - { .compatible = "oplus,midas-pdev", }, - { } -}; - -static struct platform_driver midas_pdev_driver = { - .driver = { - .name = "midas-pdev", - .of_match_table = midas_pdev_dt_ids, - .pm = &rasm_pm_ops, - }, - .probe = midas_pdev_probe, - .remove = midas_pdev_remove, -}; - -int __init midas_dev_init(void) -{ - int rc = 0; - - rc = register_trace_android_vh_cpufreq_acct_update_power(midas_record_task_times, NULL); - if (rc < 0) { - pr_err("register_trace_android_vh_midas_record_task_times failed! rc=%d\n", rc); - goto err_trace_register; - } - - rc = platform_device_register(&midas_pdev); - if (rc < 0) { - pr_err("platform_device_register failed! rc=%d\n", rc); - goto err_device_register; - } - - rc = platform_driver_register(&midas_pdev_driver); - if (rc < 0) { - pr_err("platform_driver_register failed! rc=%d\n", rc); - goto err_driver_register; - } - - return 0; - -err_driver_register: - platform_device_unregister(&midas_pdev); -err_device_register: - unregister_trace_android_vh_cpufreq_acct_update_power(midas_record_task_times, NULL); -err_trace_register: - return rc; -} - -void __exit midas_dev_exit(void) -{ - unregister_trace_android_vh_cpufreq_acct_update_power(midas_record_task_times, NULL); - platform_device_unregister(&midas_pdev); - platform_driver_unregister(&midas_pdev_driver); -} - diff --git a/drivers/soc/oplus/midas/v1_gki/midas_dev.h b/drivers/soc/oplus/midas/v1_gki/midas_dev.h deleted file mode 100755 index 86ff4ea15f5c..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/midas_dev.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#ifndef __MIDAS_DEV_H__ -#define __MIDAS_DEV_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STATE_MAX 100 -#define CNT_MAX 1024 -#define EM_CNT_MAX 100 - -enum { - ID_PID = 0, - ID_TGID, - ID_UID, - ID_TOTAL, -}; - -struct id_entry { - unsigned int id[ID_TOTAL]; - unsigned int type; - char pid_name[TASK_COMM_LEN]; - char tgid_name[TASK_COMM_LEN]; - unsigned long long time_in_state[STATE_MAX]; -}; - -struct midas_mmap_data { - unsigned int cnt; - struct id_entry entrys[CNT_MAX]; -}; - -struct midas_dev_info { - unsigned int version; - dev_t devno; - struct cdev cdev; - struct class *class; -}; - -struct midas_priv_info { - struct midas_mmap_data *mmap_addr; -}; - -typedef int midas_ioctl_t(void *kdata, void *priv_info); - -struct midas_ioctl_desc { - unsigned int cmd; - midas_ioctl_t *func; -}; - -struct em_data { - unsigned int cnt; - unsigned int power[EM_CNT_MAX]; -}; - -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg); - -void midas_record_task_times(void *data, u64 cputime, struct task_struct *p, - unsigned int state); - -int __init midas_dev_init(void); -void __exit midas_dev_exit(void); - -#endif diff --git a/drivers/soc/oplus/midas/v1_gki/midas_ioctl.c b/drivers/soc/oplus/midas/v1_gki/midas_ioctl.c deleted file mode 100755 index ac16b864e459..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/midas_ioctl.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) && defined(CONFIG_ENERGY_MODEL) -#include -#endif - -#include "midas_dev.h" - -#define MIDAS_DEV_VERSION 0x11 - -#define MIDAS_IOCTL_DEF(ioctl, _func) \ - [MIDAS_IOCTL_NR(ioctl)] = { \ - .cmd = ioctl, \ - .func = _func, \ - } - -#define MIDAS_IOCTL_BASE 'm' -#define MIDAS_IO(nr) _IO(MIDAS_IOCTL_BASE, nr) -#define MIDAS_IOR(nr, type) _IOR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOW(nr, type) _IOW(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOWR(nr, type) _IOWR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOCTL_NR(n) _IOC_NR(n) -#define MIDAS_CORE_IOCTL_CNT ARRAY_SIZE(midas_ioctls) - -#define MIDAS_IOCTL_GET_TIME_IN_STATE MIDAS_IOR(0x1, unsigned int) -#define MIDAS_IOCTL_SET_TRACK_UID MIDAS_IOR(0x2, unsigned int) -#define MIDAS_IOCTL_REMOVE_TRACK_UID MIDAS_IOR(0x3, unsigned int) -#define MIDAS_IOCTL_CLEAR_TRACK_UID MIDAS_IOR(0x4, unsigned int) -#define MIDAS_IOCTL_GET_VERSION MIDAS_IOR(0x5, int) -#define MIDAS_IOCTL_GET_EM MIDAS_IOR(0x10, struct em_data) - -#define SYS_UID 1000 -#define ROOT_UID 0 -#define WQ_NAME_LEN 24 -#define TRACK_UID_NUM 10 - -enum { - TYPE_NONE = 0, - TYPE_PROCESS, - TYPE_APP, - TYPE_TOTAL, -}; - -static struct midas_mmap_data midas_mmap_buf; -static DEFINE_SPINLOCK(midas_data_lock); -static unsigned int g_track_uid[TRACK_UID_NUM] = {0}; - -static int check_track_uid(int uid) -{ - int i; - - if (uid == ROOT_UID || uid == SYS_UID) - return 0; - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (uid == g_track_uid[i]) - return 0; - } - - return -1; -} - -static void query_pid_name(struct task_struct *p, char *pid_name) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - strncpy(pid_name, p->comm, TASK_COMM_LEN); -#else - char buf[WQ_NAME_LEN] = {0}; - - if (!(p->flags & PF_WQ_WORKER)) { - strncpy(pid_name, p->comm, TASK_COMM_LEN); - } else { - get_worker_info(p, buf); - if (buf[0]) { - strncpy(pid_name, buf, TASK_COMM_LEN - 1); - pid_name[TASK_COMM_LEN - 1] = '\0'; - } else { - strncpy(pid_name, p->comm, TASK_COMM_LEN); - } - } -#endif -} - -static void update_or_create_entry_locked(uid_t uid, struct task_struct *p, u64 cputime, - unsigned int state, unsigned int type) -{ - unsigned int id_cnt = midas_mmap_buf.cnt; - unsigned int index = (type == TYPE_PROCESS) ? ID_PID : ID_UID; - unsigned int id = (type == TYPE_PROCESS) ? task_pid_nr(p) : uid; - struct task_struct *task; - int i; - - for (i = 0; i < id_cnt; i++) { - if (midas_mmap_buf.entrys[i].type == type - && midas_mmap_buf.entrys[i].id[index] == id) { - /* the unit of time_in_state is ms */ - midas_mmap_buf.entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - return; - } - } - - if (i >= CNT_MAX) - return; - - /* We didn't find id_entry exsited, should create a new one */ - midas_mmap_buf.entrys[i].id[ID_UID] = uid; - midas_mmap_buf.entrys[i].type = type; - if (type == TYPE_PROCESS) { - midas_mmap_buf.entrys[i].id[ID_PID] = task_pid_nr(p); - midas_mmap_buf.entrys[i].id[ID_TGID] = task_tgid_nr(p); - query_pid_name(p, midas_mmap_buf.entrys[i].pid_name); - /* Get tgid name */ - rcu_read_lock(); - task = find_task_by_vpid(midas_mmap_buf.entrys[i].id[ID_TGID]); - rcu_read_unlock(); - strncpy(midas_mmap_buf.entrys[i].tgid_name, task->comm, TASK_COMM_LEN); - } - - /* the unit of time_in_state is ms */ - midas_mmap_buf.entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - midas_mmap_buf.cnt = ((id_cnt + 1) > CNT_MAX) ? CNT_MAX : (id_cnt + 1); -} - -void midas_record_task_times(void *data, u64 cputime, struct task_struct *p, - unsigned int state) { - unsigned long flags; - uid_t uid; - uid = from_kuid_munged(current_user_ns(), task_uid(p)); - - spin_lock_irqsave(&midas_data_lock, flags); - - update_or_create_entry_locked(uid, p, cputime, state, TYPE_APP); - - if (!check_track_uid(uid)) - update_or_create_entry_locked(uid, p, cputime, state, TYPE_PROCESS); - - spin_unlock_irqrestore(&midas_data_lock, flags); -} - -static int midas_ioctl_get_time_in_state(void *kdata, void *priv_info) -{ - unsigned long flags; - struct midas_priv_info *info = priv_info; - - if (!info->mmap_addr) - return -EINVAL; - - spin_lock_irqsave(&midas_data_lock, flags); - - memcpy(info->mmap_addr, &midas_mmap_buf, sizeof(struct midas_mmap_data)); - memset(&midas_mmap_buf, 0, sizeof(struct midas_mmap_data)); - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_remove_track_uid(void *kdata, void *priv_info) -{ - unsigned int *uid = kdata; - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (g_track_uid[i] == *uid) { - g_track_uid[i] = 0; - break; - } - } - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_clear_track_uid(void *kdata, void *priv_info) -{ - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) - g_track_uid[i] = 0; - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_set_track_uid(void *kdata, void *priv_info) -{ - unsigned int *uid = kdata; - int i; - unsigned long flags; - - spin_lock_irqsave(&midas_data_lock, flags); - - for (i = 0; i < TRACK_UID_NUM; i++) { - if (g_track_uid[i] == 0) { - g_track_uid[i] = *uid; - break; - } else if (g_track_uid[i] == *uid) { - break; - } - } - - spin_unlock_irqrestore(&midas_data_lock, flags); - return 0; -} - -static int midas_ioctl_get_version(void *kdata, void *priv_info) -{ - int *tmp = (int *)kdata; - - *tmp = MIDAS_DEV_VERSION; - return 0; -} - -static int midas_ioctl_get_em(void *kdata, void *priv_info) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) && defined(CONFIG_ENERGY_MODEL) - struct em_perf_domain *em_pd = NULL; - struct em_data data; - int index = 0, i, cpu; - - memset(&data, 0, sizeof(struct em_data)); - - for_each_possible_cpu(cpu) { - if ((em_pd != NULL) && cpumask_test_cpu(cpu, em_span_cpus(em_pd))) - continue; - - em_pd = em_cpu_get(cpu); - if (!em_pd) { - pr_err("find %d em_pd failed!\n", cpu); - return -EINVAL; - } - - for (i = 0; i < em_pd->nr_perf_states; i++) { - data.power[index] = em_pd->table[i].power; - index++; - } - data.cnt += em_pd->nr_perf_states; - } - - memcpy(kdata, &data, sizeof(struct em_data)); - - return 0; -#else - return -EINVAL; -#endif -} - -/* Ioctl table */ -static const struct midas_ioctl_desc midas_ioctls[] = { - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_TIME_IN_STATE, midas_ioctl_get_time_in_state), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_SET_TRACK_UID, midas_ioctl_set_track_uid), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_REMOVE_TRACK_UID, midas_ioctl_remove_track_uid), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_CLEAR_TRACK_UID, midas_ioctl_clear_track_uid), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_VERSION, midas_ioctl_get_version), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_EM, midas_ioctl_get_em), -}; - -#define KDATA_SIZE 512 -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg) -{ - struct midas_priv_info *info = filp->private_data; - const struct midas_ioctl_desc *ioctl = NULL; - midas_ioctl_t *func; - unsigned int nr = MIDAS_IOCTL_NR(cmd); - int ret = -EINVAL; - char kdata[KDATA_SIZE] = { }; - unsigned int in_size, out_size; - - if (nr >= MIDAS_CORE_IOCTL_CNT) { - pr_err("out of array\n"); - return -EINVAL; - } - - ioctl = &midas_ioctls[nr]; - - out_size = in_size = _IOC_SIZE(cmd); - if ((cmd & IOC_IN) == 0) - in_size = 0; - if ((cmd & IOC_OUT) == 0) - out_size = 0; - - if (out_size > KDATA_SIZE || in_size > KDATA_SIZE) { - pr_err("out of memory\n"); - ret = -EINVAL; - goto err_out_of_mem; - } - - func = ioctl->func; - if (unlikely(!func)) { - pr_err("no func\n"); - ret = -EINVAL; - goto err_no_func; - } - - if (copy_from_user(kdata, (void __user *)arg, in_size)) { - pr_err("copy_from_user failed\n"); - ret = -EFAULT; - goto err_fail_cp; - } - - ret = func(kdata, info); - - if (copy_to_user((void __user *)arg, kdata, out_size)) { - pr_err("copy_to_user failed\n"); - ret = -EFAULT; - } - -err_fail_cp: -err_no_func: -err_out_of_mem: - return ret; -} diff --git a/drivers/soc/oplus/midas/v1_gki/midas_module.c b/drivers/soc/oplus/midas/v1_gki/midas_module.c deleted file mode 100644 index 6e02c185d85f..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/midas_module.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include "midas_dev.h" - -extern int __init binder_stats_dev_init(void); -extern void __exit binder_stats_dev_exit(void); - -static int __init midas_module_init(void) -{ - midas_dev_init(); - binder_stats_dev_init(); - - return 0; -} - -static void __exit midas_module_exit(void) -{ - midas_dev_exit(); - binder_stats_dev_exit(); -} - -module_init(midas_module_init); -module_exit(midas_module_exit); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/midas/v1_gki/vpu_pw_off_latency_proc.c b/drivers/soc/oplus/midas/v1_gki/vpu_pw_off_latency_proc.c deleted file mode 100755 index d03979d94304..000000000000 --- a/drivers/soc/oplus/midas/v1_gki/vpu_pw_off_latency_proc.c +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY - -// import from MTK vpu driver -extern int set_all_vpu_power_off_latency(uint64_t pw_off_latency); - -#define BUF_LEN 1024 - -static struct proc_dir_entry *g_vpu_pw_off_latency_pentry = NULL; - -static ssize_t vpu_pw_off_latency_proc_write(struct file *file, const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len; - uint64_t latency_ms; - char tmp[BUF_LEN + 1]; - - if (cnt == 0) - return 0; - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') - tmp[len - 1] = '\0'; - else - tmp[len] = '\0'; - - ret = sscanf(tmp, "%llu", &latency_ms); - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - pr_info("latency_ms cmd:%llu\n", latency_ms); - - set_all_vpu_power_off_latency(latency_ms); - - return cnt; -} - -static const struct file_operations vpu_pw_off_latency_proc_fops = { - .write = vpu_pw_off_latency_proc_write, -}; - -int __init vpu_pw_off_latency_proc_init(void) -{ - g_vpu_pw_off_latency_pentry = proc_create("all_vpu_pw_off_latency", - 0666, NULL, &vpu_pw_off_latency_proc_fops); - return 0; -} - - -void __exit vpu_pw_off_latency_proc_exit(void) -{ - if (NULL != g_vpu_pw_off_latency_pentry) { - proc_remove(g_vpu_pw_off_latency_pentry); - g_vpu_pw_off_latency_pentry = NULL; - } -} - -module_init(vpu_pw_off_latency_proc_init); -module_exit(vpu_pw_off_latency_proc_exit); - -#endif // #ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY diff --git a/drivers/soc/oplus/midas/v2/Makefile b/drivers/soc/oplus/midas/v2/Makefile deleted file mode 100755 index 7f3b0d7baf13..000000000000 --- a/drivers/soc/oplus/midas/v2/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2021 Oplus. All rights reserved. - -oplus_bsp_midas-objs := \ - binder_stats_dev.o \ - midas_dev.o \ - midas_ioctl.o \ - midas_cpu.o \ - midas_mem.o \ - midas_module.o - -obj-$(CONFIG_OPLUS_FEATURE_MIDAS_V2) += oplus_bsp_midas.o diff --git a/drivers/soc/oplus/midas/v2/binder_stats_dev.c b/drivers/soc/oplus/midas/v2/binder_stats_dev.c deleted file mode 100755 index fe3af370d9c0..000000000000 --- a/drivers/soc/oplus/midas/v2/binder_stats_dev.c +++ /dev/null @@ -1,1466 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) - -#define BINDER_STATS_LOGI(...) -#define BINDER_STATS_LOGE pr_err -/* #define BINDER_STATS_DEBUGFS */ - -#define BINDER_STATS_CTL_VERSION_CODE 1 - -#define BINDER_STATS_CTL_GET_VERSION 100 -#define BINDER_STATS_CTL_ENABLE 101 -#define BINDER_STATS_CTL_UPDATE 102 -#define BINDER_STATS_CTL_CFG_CLEAR 110 -#define BINDER_STATS_CTL_CFG_MAX_ITEM 111 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_NAME 112 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM 113 -#define BINDER_STATS_CTL_CFG_SVR_FILTER_UID 114 -#define BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM 115 -#define BINDER_STATS_CTL_SRVMGR_INT 120 -#define BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME 121 -#define BINDER_STATS_CTL_RET_SUCC 0 -#define BINDER_STATS_CTL_RET_INVALID -1 - -#define OPLUS_MAX_SERVICE_NAME_LEN 32 -#define BINDER_STATS_MAX_COUNT_LIMIT 32768 -#define BINDER_STATS_DEFAULT_MAX_COUNT 4096 -#define BINDER_STATS_HASH_ORDER 9 -#define BINDER_STATS_FILTER_LIMIT_MAX 128 - -/* import from binder driver */ -struct binder_notify { - struct task_struct *caller_task; - struct task_struct *binder_task; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool pending_async; -}; - -struct binder_stats_item { - char caller_proc_comm[TASK_COMM_LEN]; - int caller_pid; - int caller_tgid; - int caller_uid; - char caller_comm[TASK_COMM_LEN]; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - char binder_proc_comm[TASK_COMM_LEN]; - int binder_pid; - int binder_tgid; - int binder_uid; - char binder_comm[TASK_COMM_LEN]; - unsigned int call_count; -}; - -/* - * binder_stats : user space mmap the buffer struct. - * this struct buffer is dynamic alloc, - * items size is max_item_cnt, it is config by user. - * items size BINDER_STATS_MAX_COUNT_LIMIT is invalid. - */ -struct binder_stats { - unsigned int max_item_cnt; - unsigned int valid_item_cnt; - struct binder_stats_item items[BINDER_STATS_MAX_COUNT_LIMIT]; -}; - -struct binder_stats_item_ref { - struct hlist_node hentry; - struct binder_stats_item *item; -}; - -struct binder_stats_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct mutex lock; - int version_code; - - struct list_head user_list_head; - bool regist_binder_stats_flag; - spinlock_t user_list_lock; - - DECLARE_HASHTABLE(handle_name_hash, BINDER_STATS_HASH_ORDER); - DECLARE_HASHTABLE(debug_id_name_hash, BINDER_STATS_HASH_ORDER); - int srvmgr_tgid; - spinlock_t srv_name_lock; - -#if defined(BINDER_STATS_DEBUGFS) - struct dentry *d_folder_binder_stats; - struct dentry *d_file_cmd; -#endif -}; - -struct binder_stats_filter_srv_name { - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm { - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid { - int uid; - bool intreresting; -}; - -struct binder_stats_handle_name { - int handle; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; -}; - -struct binder_stats_filter_srv_name_node { - struct hlist_node hentry; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_proc_comm_node { - struct hlist_node hentry; - char comm[TASK_COMM_LEN]; - bool intreresting; -}; - -struct binder_stats_filter_uid_node { - struct hlist_node hentry; - int uid; - bool intreresting; -}; - -struct binder_stats_handle_name_node { - struct hlist_node hentry_handle; - struct hlist_node hentry_debug_id; - int handle; - int node_debug_id; - char service_name[OPLUS_MAX_SERVICE_NAME_LEN]; -}; - -struct binder_stats_user_context { - struct list_head list_node; - int enable; - int max_item_cnt; - struct binder_stats *binder_stats_buf_0; /* double swap buffer 0 */ - struct binder_stats *binder_stats_buf_1; /* double swap buffer 1 */ - struct binder_stats_item_ref *kernel_binder_stats_refs; - DECLARE_HASHTABLE(kernel_binder_stats_hash, BINDER_STATS_HASH_ORDER); - struct binder_stats *kernel_binder_stats; - struct binder_stats *user_binder_stats; - bool user_mmap_flag; - spinlock_t buf_lock; - - int enable_binder_comm; - DECLARE_HASHTABLE(intre_srv_name_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_srv_name; - bool has_unintr_srv_name; - DECLARE_HASHTABLE(intre_proc_comm_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_proc_comm; - bool has_unintr_proc_comm; - DECLARE_HASHTABLE(intre_uid_hash, BINDER_STATS_HASH_ORDER); - bool has_intr_uid; - bool has_unintr_uid; -}; - -struct binder_stats_driver g_binder_stats_driver; - -/* key is from caller_comm & binder_comm && service_name */ -static inline long long hash_key(struct binder_notify *bn, int enable_binder_comm) { - long long key = 0; - int i; - long long *v1 = (long long *)bn->caller_task->comm; - long long *v2 = (long long *)bn->binder_task->comm; - long long *v3 = (long long *)bn->service_name; - for (i = 0; i < TASK_COMM_LEN/sizeof(long long); ++i) { - if (1 == enable_binder_comm) - key += (v1[i] + v2[i]); - else - key += v1[i]; - } - for (i = 0; i < OPLUS_MAX_SERVICE_NAME_LEN/sizeof(long long); ++i) { - key += v3[i]; - } - return key; -} - -static inline bool hash_match(struct binder_notify *bn, struct binder_stats_item *stats_item, int enable_binder_comm) { - struct task_struct *caller_proc_task = NULL; - struct task_struct *binder_proc_task = NULL; - if (NULL != bn->caller_task->group_leader) - caller_proc_task = bn->caller_task->group_leader; - else - caller_proc_task = bn->caller_task; - - if (NULL != bn->binder_task->group_leader) - binder_proc_task = bn->binder_task->group_leader; - else - binder_proc_task = bn->binder_task; - - if (1 == enable_binder_comm) - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_comm, bn->binder_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); - else - return (0 == strncmp(stats_item->caller_comm, bn->caller_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->caller_proc_comm, caller_proc_task->comm, TASK_COMM_LEN) - && 0 == strncmp(stats_item->service_name, bn->service_name, OPLUS_MAX_SERVICE_NAME_LEN) - && 0 == strncmp(stats_item->binder_proc_comm, binder_proc_task->comm, TASK_COMM_LEN)); -} - -static inline long long hash_key_for_str(const char *str, unsigned int len) { - long long key = 0; - int i; - long long *v = (long long *)str; - for (i = 0; i < len/sizeof(long long); ++i) { - key += v[i]; - str += sizeof(long long); - } - for (i = 0; i < len%sizeof(long long); ++i) { - key += str[i]; - } - return key; -} - -static bool intreresting_filter(struct binder_stats_user_context *context_ptr, - struct binder_notify *bn) { - bool intreresting = false; - struct task_struct *caller_task; - struct task_struct *binder_proc_task; - int binder_uid; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - - caller_task = bn->caller_task; - binder_proc_task = NULL == bn->binder_task->group_leader? bn->binder_task: bn->binder_task->group_leader; - binder_uid = from_kuid_munged(current_user_ns(), task_uid(bn->binder_task)); - - if (!context_ptr->has_intr_srv_name && !context_ptr->has_intr_proc_comm && !context_ptr->has_intr_uid) { - intreresting = true; - } else { - intreresting = false; - } - - hash_for_each_possible(context_ptr->intre_srv_name_hash, hash_node_srv_name, hentry, - hash_key_for_str(bn->service_name, strlen(bn->service_name))) { - if (0 == strcmp(hash_node_srv_name->service_name, bn->service_name)) { - if (hash_node_srv_name->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_proc_comm_hash, hash_node_proc_comm, hentry, - hash_key_for_str(binder_proc_task->comm, strlen(binder_proc_task->comm))) { - if (0 == strcmp(hash_node_proc_comm->comm, binder_proc_task->comm)) { - if (hash_node_proc_comm->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - hash_for_each_possible(context_ptr->intre_uid_hash, hash_node_uid, hentry, (long long)binder_uid) { - if (hash_node_uid->uid == binder_uid) { - return hash_node_uid->intreresting; - if (hash_node_uid->intreresting) { - intreresting = true; - } else { - return false; - } - } - } - - return intreresting; -} - -static void store_binder_stats_to_kernel(struct binder_notify *data) { - struct binder_stats_item *find_item = NULL; - unsigned long flags, ctx_flag; - struct binder_stats *kernel_binder_stats = NULL; - struct binder_stats_item_ref *ref_hash_node; - struct binder_stats_user_context *context_ptr = NULL; - struct task_struct *caller_task = NULL; - struct task_struct *binder_task = NULL; - - if (NULL == data || NULL == data->caller_task || NULL == data->binder_task) - return; - - caller_task = data->caller_task; - binder_task = data->binder_task; - - /* BINDER_STATS_LOGI("%d(%s) => (%s)(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - data->service_name, binder_task->comm, binder_task->pid, binder_task->comm); */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - - list_for_each_entry(context_ptr, &g_binder_stats_driver.user_list_head, list_node) { - if (NULL == context_ptr || NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) - continue; - - find_item = NULL; - - if (!intreresting_filter(context_ptr, data)) - continue; - - spin_lock_irqsave(&context_ptr->buf_lock, ctx_flag); - - kernel_binder_stats = context_ptr->kernel_binder_stats; - - /* find current item with hash */ - hash_for_each_possible(context_ptr->kernel_binder_stats_hash, ref_hash_node, hentry, hash_key(data, context_ptr->enable_binder_comm)) { - if (hash_match(data, ref_hash_node->item, context_ptr->enable_binder_comm)) { - find_item = ref_hash_node->item; - break; - } - } - - if (NULL != find_item) { - find_item->call_count++; - } else { - if (kernel_binder_stats->valid_item_cnt + 1 <= kernel_binder_stats->max_item_cnt) { - find_item = &(kernel_binder_stats->items[kernel_binder_stats->valid_item_cnt]); - - /* caller proc comm */ - if (NULL != caller_task->group_leader) - strncpy(find_item->caller_proc_comm, caller_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->caller_proc_comm, caller_task->comm, TASK_COMM_LEN); - - /* caller pid tgid uid */ - find_item->caller_pid = task_pid_nr(caller_task); - find_item->caller_tgid = task_tgid_nr(caller_task); - find_item->caller_uid = from_kuid_munged(current_user_ns(), task_uid(caller_task)); - /* caller comm */ - strncpy(find_item->caller_comm, caller_task->comm, TASK_COMM_LEN); - - /* service name */ - strncpy(find_item->service_name, data->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - - /* binder proc comm */ - if (NULL != binder_task->group_leader) - strncpy(find_item->binder_proc_comm, binder_task->group_leader->comm, TASK_COMM_LEN); - else - strncpy(find_item->binder_proc_comm, binder_task->comm, TASK_COMM_LEN); - - /* binder tgid uid */ - find_item->binder_tgid = task_tgid_nr(binder_task); - find_item->binder_uid = from_kuid_munged(current_user_ns(), task_uid(binder_task)); - - /* binder comm pid */ - if (1 == context_ptr->enable_binder_comm) { - find_item->binder_pid = task_pid_nr(binder_task); - strncpy(find_item->binder_comm, binder_task->comm, TASK_COMM_LEN); - } else { - find_item->binder_pid = find_item->binder_tgid; - strncpy(find_item->binder_comm, "binderTh", TASK_COMM_LEN); - } - - /* call count init */ - find_item->call_count = 1; - - /* add hash for improve search performance */ - ref_hash_node = &(context_ptr->kernel_binder_stats_refs[kernel_binder_stats->valid_item_cnt]); - ref_hash_node->item = find_item; - hash_add(context_ptr->kernel_binder_stats_hash, &ref_hash_node->hentry, hash_key(data, context_ptr->enable_binder_comm)); - - kernel_binder_stats->valid_item_cnt++; - } - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, ctx_flag); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); -} - -static void binder_stats_clear_user_context(struct binder_stats_user_context *context_ptr) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - BINDER_STATS_LOGI("start\n"); - - /* first remove user node from global user list - then clear the local user memory */ - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_del(&context_ptr->list_node); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (!IS_ERR_OR_NULL(context_ptr->user_binder_stats)) { - vfree(context_ptr->user_binder_stats); - context_ptr->user_binder_stats = NULL; - } - - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats)) { - vfree(context_ptr->kernel_binder_stats); - context_ptr->kernel_binder_stats = NULL; - } - - context_ptr->binder_stats_buf_0 = NULL; - context_ptr->binder_stats_buf_1 = NULL; - context_ptr->user_mmap_flag = false; - - context_ptr->enable = 0; -} - -static int user_enable_binder_stats(struct binder_stats_user_context *context_ptr, int enable) { - unsigned long flags; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - int max_item_cnt = BINDER_STATS_DEFAULT_MAX_COUNT; - int binder_stats_buffer_size = 0; - - if (0 != enable && 1 != enable) { - BINDER_STATS_LOGE("enable param error!\n"); - return -1; - } - if (context_ptr->enable == enable) { - BINDER_STATS_LOGE("enable value is same with current value!\n"); - return -1; - } - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("user mem in used!\n"); - return -1; - } - - if (1 == enable) { - if (NULL != context_ptr->binder_stats_buf_0 || - NULL != context_ptr->binder_stats_buf_1 || - NULL != context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer exist!\n"); - return -1; - } - - if (0 != context_ptr->max_item_cnt) { - max_item_cnt = context_ptr->max_item_cnt; - } - - binder_stats_buffer_size = 2*sizeof(unsigned int) + max_item_cnt*sizeof(struct binder_stats_item); - - context_ptr->binder_stats_buf_0 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_0->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_0->valid_item_cnt = 0; - context_ptr->kernel_binder_stats = context_ptr->binder_stats_buf_0; - - context_ptr->kernel_binder_stats_refs = vmalloc_user(max_item_cnt*sizeof(struct binder_stats_item_ref)); - if (IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - - hash_init(context_ptr->kernel_binder_stats_hash); - - context_ptr->binder_stats_buf_1 = vmalloc_user(binder_stats_buffer_size); - if (IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - BINDER_STATS_LOGE("malloc failed!\n"); - goto enable_fail; - } - context_ptr->binder_stats_buf_1->max_item_cnt = max_item_cnt; - context_ptr->binder_stats_buf_1->valid_item_cnt = 0; - context_ptr->user_binder_stats = context_ptr->binder_stats_buf_1; - - spin_lock_init(&context_ptr->buf_lock); - context_ptr->user_mmap_flag = false; - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_add(&context_ptr->list_node, &g_binder_stats_driver.user_list_head); - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - context_ptr->enable = 1; - - return 0; - -enable_fail: - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_1)) { - vfree(context_ptr->binder_stats_buf_1); - context_ptr->binder_stats_buf_1 = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->kernel_binder_stats_refs)) { - vfree(context_ptr->kernel_binder_stats_refs); - context_ptr->kernel_binder_stats_refs = NULL; - } - if (!IS_ERR_OR_NULL(context_ptr->binder_stats_buf_0)) { - vfree(context_ptr->binder_stats_buf_0); - context_ptr->binder_stats_buf_0 = NULL; - } - context_ptr->user_binder_stats = NULL; - context_ptr->kernel_binder_stats = NULL; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - - return -1; - } else { - if (NULL == context_ptr->user_binder_stats || - NULL == context_ptr->kernel_binder_stats || - NULL == context_ptr->kernel_binder_stats_refs) { - BINDER_STATS_LOGE("context_ptr buffer not exit!\n"); - return -1; - } - - binder_stats_clear_user_context(context_ptr); - - return 0; - } -} - -static int user_update_binder_stats(struct binder_stats_user_context *context_ptr) { - int ret = 0; - unsigned long flags; - struct binder_stats * swap_tmp; - struct binder_stats_item_ref *ref_hash_node; - struct hlist_node *tmp; - int i; - - if (0 == context_ptr->enable) { - BINDER_STATS_LOGE("function not enabled!\n"); - return -1; - } - - if (context_ptr->user_mmap_flag) { - BINDER_STATS_LOGE("memory is used!\n"); - return -1; - } - - spin_lock_irqsave(&context_ptr->buf_lock, flags); - - /* swap buffer & clear kernel_binder_stats & kernel_binder_stats_hash */ - if (NULL != context_ptr->kernel_binder_stats && NULL != context_ptr->user_binder_stats) { - swap_tmp = context_ptr->kernel_binder_stats; - context_ptr->kernel_binder_stats = context_ptr->user_binder_stats; - context_ptr->user_binder_stats = swap_tmp; - - /* reset cnt & clear hash */ - context_ptr->kernel_binder_stats->valid_item_cnt = 0; - hash_for_each_safe(context_ptr->kernel_binder_stats_hash, i, tmp, ref_hash_node, hentry) { - hash_del(&ref_hash_node->hentry); - } - } else { - ret = -1; - } - - spin_unlock_irqrestore(&context_ptr->buf_lock, flags); - - return ret; -} - -static int user_binder_stats_cfg_clear(struct binder_stats_user_context *context_ptr) { - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - struct binder_stats_filter_uid_node *hash_node_uid; - struct hlist_node *tmp; - int i; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - hash_del(&hash_node_srv_name->hentry); - vfree(hash_node_srv_name); - } - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - hash_del(&hash_node_proc_comm->hentry); - vfree(hash_node_proc_comm); - } - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - hash_del(&hash_node_uid->hentry); - vfree(hash_node_uid); - } - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - context_ptr->enable_binder_comm = 0; - - context_ptr->max_item_cnt = 0; - - return 0; -} - -static int user_binder_stats_cfg_set_max_item_cnt(struct binder_stats_user_context *context_ptr, int max_item_cnt) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - if (max_item_cnt < 0 || max_item_cnt > BINDER_STATS_MAX_COUNT_LIMIT) { - BINDER_STATS_LOGE("invalid max_item_cnt!\n"); - return -1; - } - - context_ptr->max_item_cnt = max_item_cnt; - - return 0; -} - -static int user_binder_stats_cfg_set_enable_binder_comm(struct binder_stats_user_context *context_ptr, int enable_binder_comm) { - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - if (0 != enable_binder_comm && 1 != enable_binder_comm) { - BINDER_STATS_LOGE("enable_binder_comm param error!\n"); - return -1; - } - - context_ptr->enable_binder_comm = enable_binder_comm; - - return 0; -} - -static int user_binder_stats_add_intreresting_svr_name(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_srv_name *filter_srv_name) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_srv_name_node *hash_node_srv_name; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_srv_name_hash, i, tmp, hash_node_srv_name, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_srv_name = vmalloc_user(sizeof(struct binder_stats_filter_srv_name_node)); - if (IS_ERR_OR_NULL(hash_node_srv_name)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_srv_name->service_name, filter_srv_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - hash_node_srv_name->intreresting = filter_srv_name->intreresting; - hash_add(context_ptr->intre_srv_name_hash, &hash_node_srv_name->hentry, - hash_key_for_str(hash_node_srv_name->service_name, strlen(hash_node_srv_name->service_name))); - - if (hash_node_srv_name->intreresting) { - context_ptr->has_intr_srv_name = true; - } else { - context_ptr->has_unintr_srv_name = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_srv_name->service_name, hash_node_srv_name->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_proc_comm(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_proc_comm *filter_proc_comm) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_proc_comm_node *hash_node_proc_comm; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_proc_comm_hash, i, tmp, hash_node_proc_comm, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_proc_comm = vmalloc_user(sizeof(struct binder_stats_filter_proc_comm_node)); - if (IS_ERR_OR_NULL(hash_node_proc_comm)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - strncpy(hash_node_proc_comm->comm, filter_proc_comm->comm, TASK_COMM_LEN); - hash_node_proc_comm->intreresting = filter_proc_comm->intreresting; - hash_add(context_ptr->intre_proc_comm_hash, &hash_node_proc_comm->hentry, - hash_key_for_str(hash_node_proc_comm->comm, strlen(hash_node_proc_comm->comm))); - - if (hash_node_proc_comm->intreresting) { - context_ptr->has_intr_proc_comm = true; - } else { - context_ptr->has_unintr_proc_comm = true; - } - - /* BINDER_STATS_LOGI("%s %d\n", hash_node_proc_comm->comm, hash_node_proc_comm->intreresting); */ - - return ret; -} - -static int user_binder_stats_add_intreresting_uid(struct binder_stats_user_context *context_ptr, - struct binder_stats_filter_uid *filter_uid) { - int ret = 0, i = 0, cur_cnt = 0; - struct hlist_node *tmp; - struct binder_stats_filter_uid_node *hash_node_uid; - - if (1 == context_ptr->enable) { - BINDER_STATS_LOGE("can not set config when function enabled already!\n"); - return -1; - } - - hash_for_each_safe(context_ptr->intre_uid_hash, i, tmp, hash_node_uid, hentry) { - cur_cnt++; - } - if (cur_cnt >= BINDER_STATS_FILTER_LIMIT_MAX) { - BINDER_STATS_LOGE("max limit!\n"); - return -1; - } - - hash_node_uid = vmalloc_user(sizeof(struct binder_stats_filter_uid_node)); - if (IS_ERR_OR_NULL(hash_node_uid)) { - BINDER_STATS_LOGE("malloc err\n"); - return -1; - } - hash_node_uid->uid = filter_uid->uid; - hash_node_uid->intreresting = filter_uid->intreresting; - hash_add(context_ptr->intre_uid_hash, &hash_node_uid->hentry, (long long)hash_node_uid->uid); - - if (hash_node_uid->intreresting) { - context_ptr->has_intr_uid = true; - } else { - context_ptr->has_unintr_uid = true; - } - - /* BINDER_STATS_LOGI("%d %d\n", hash_node_uid->uid, hash_node_uid->intreresting); */ - - return ret; -} - -static int set_driver_binder_stats_srvmgr_init() { - BINDER_STATS_LOGI("BDS_MGR task_tgid_nr:%d\n", task_tgid_nr(current)); - g_binder_stats_driver.srvmgr_tgid = task_tgid_nr(current); - return 0; -} - -static int set_driver_binder_stats_srvmgr_handle_name(struct binder_stats_handle_name *handle_name) { - int ret = 0; - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_stats_handle_name_node *handle_name_new; - - if (NULL == handle_name || NULL == g_binder_stats_driver.handle_name_hash) { - BINDER_STATS_LOGE("handle_name error!\n"); - return -1; - } - - handle_name_new = kmalloc(sizeof(struct binder_stats_handle_name_node), GFP_ATOMIC); - if (NULL == handle_name_new) { - BINDER_STATS_LOGE("handle_name_new error!\n"); - return -1; - } - memset(handle_name_new, 0, sizeof(struct binder_stats_handle_name_node)); - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, handle_name->handle) { - if (handle_name_tmp->handle == handle_name->handle) - handle_name_find = handle_name_tmp; - } - - if (NULL != handle_name_find) { - strncpy(handle_name_find->service_name, handle_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - handle_name_find->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - } else { - handle_name_new->handle = handle_name->handle; - strncpy(handle_name_new->service_name, handle_name->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - handle_name_new->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - hash_add(g_binder_stats_driver.handle_name_hash, &handle_name_new->hentry_handle, handle_name_new->handle); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find && NULL != handle_name_new) { - BINDER_STATS_LOGI("BDS_MGR BDS_SET_HANDLE_NAME %d %s\n", handle_name_find->handle, handle_name_find->service_name); - kfree(handle_name_new); - } else { - BINDER_STATS_LOGE("BDS_MGR BDS_SET_HANDLE_NAME_BUG not found ref_desc:%u service_name:%s\n", handle_name_new->handle, handle_name_new->service_name); - } - - return ret; -} - -static int binder_stats_driver_open(struct inode *inode, struct file *filp) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - if (!g_binder_stats_driver.regist_binder_stats_flag) { - g_binder_stats_driver.regist_binder_stats_flag = true; - } - - context_ptr = vmalloc(sizeof(struct binder_stats_user_context)); - if (IS_ERR_OR_NULL(context_ptr)) { - BINDER_STATS_LOGE("vmalloc failed\n"); - goto open_fail; - } - - memset(context_ptr, 0, sizeof(struct binder_stats_user_context)); - - /* init config data */ - - context_ptr->max_item_cnt = 0; - - context_ptr->enable_binder_comm = 0; - - hash_init(context_ptr->intre_srv_name_hash); - context_ptr->has_intr_srv_name = false; - context_ptr->has_unintr_srv_name = false; - - hash_init(context_ptr->intre_proc_comm_hash); - context_ptr->has_intr_proc_comm = false; - context_ptr->has_unintr_proc_comm = false; - - hash_init(context_ptr->intre_uid_hash); - context_ptr->has_intr_uid = false; - context_ptr->has_unintr_uid = false; - - filp->private_data = context_ptr; - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; - -open_fail: - - mutex_unlock(&g_binder_stats_driver.lock); - - return -1; -} - -static int binder_stats_driver_release(struct inode *ignored, struct file *filp) { - struct binder_stats_user_context *context_ptr; - unsigned long flags; - struct list_head *pos = NULL; - int list_size = 0; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - if (IS_ERR_OR_NULL(context_ptr)) { - mutex_unlock(&g_binder_stats_driver.lock); - return -1; - } - - spin_lock_irqsave(&g_binder_stats_driver.user_list_lock, flags); - list_size = 0; - list_for_each(pos, &g_binder_stats_driver.user_list_head) { - ++list_size; - } - if (g_binder_stats_driver.regist_binder_stats_flag && - ((1 == list_size && list_is_last(&context_ptr->list_node, &g_binder_stats_driver.user_list_head)) || - list_empty(&g_binder_stats_driver.user_list_head))) { - g_binder_stats_driver.regist_binder_stats_flag = false; - } - spin_unlock_irqrestore(&g_binder_stats_driver.user_list_lock, flags); - - if (!IS_ERR_OR_NULL(context_ptr)) { - if (1 == context_ptr->enable) { - binder_stats_clear_user_context(context_ptr); - } - vfree(context_ptr); - filp->private_data = NULL; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static void binder_stats_mmap_close(struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - if (NULL == vma || NULL == vma->vm_file || NULL == vma->vm_file->private_data) { - BINDER_STATS_LOGE("invalid private_data\n"); - return; - } - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = vma->vm_file->private_data; - context_ptr->user_mmap_flag = false; - - mutex_unlock(&g_binder_stats_driver.lock); -} - -static const struct vm_operations_struct binder_stats_mmap_vmops = { - .close = binder_stats_mmap_close, -}; - -static int binder_stats_driver_mmap(struct file *filp, struct vm_area_struct *vma) { - struct binder_stats_user_context *context_ptr; - - BINDER_STATS_LOGI("start\n"); - - mutex_lock(&g_binder_stats_driver.lock); - - context_ptr = filp->private_data; - - if (NULL != context_ptr && NULL != context_ptr->user_binder_stats) { - vma->vm_ops = &binder_stats_mmap_vmops; - if (remap_vmalloc_range(vma, context_ptr->user_binder_stats, vma->vm_pgoff)) { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - context_ptr->user_mmap_flag = true; - } else { - mutex_unlock(&g_binder_stats_driver.lock); - BINDER_STATS_LOGE("remap failed\n"); - return -EAGAIN; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return 0; -} - -static long binder_stats_driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - long ret = -1; - int enable = 0; - int max_item_cnt = 0; - int enable_binder_comm = 0; - struct binder_stats_filter_srv_name filter_srv_name; - struct binder_stats_filter_proc_comm filter_proc_comm; - struct binder_stats_filter_uid filter_uid; - struct binder_stats_user_context *context_ptr = filp->private_data; - struct binder_stats_handle_name handle_name; - - BINDER_STATS_LOGI("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - BINDER_STATS_LOGE("context_ptr error!\n"); - return ret; - } - - mutex_lock(&g_binder_stats_driver.lock); - - switch (cmd) { - case BINDER_STATS_CTL_GET_VERSION: { - if (0 != arg) { - if(0 == copy_to_user((unsigned int *)arg, - &g_binder_stats_driver.version_code, sizeof(unsigned int))) { - BINDER_STATS_LOGI("BINDER_STATS_CTL_GET_VERSION %d\n", g_binder_stats_driver.version_code); - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_GET_VERSION failed. arg error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_ENABLE: { - if(0 != copy_from_user(&enable, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_enable_binder_stats(context_ptr, enable)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_ENABLE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_UPDATE: { - if (0 == user_update_binder_stats(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_UPDATE failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_CLEAR: { - if (0 == user_binder_stats_cfg_clear(context_ptr)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_CLEAR failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_MAX_ITEM: { - if(0 != copy_from_user(&max_item_cnt, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_max_item_cnt(context_ptr, max_item_cnt)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_MAX_ITEM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM: { - if(0 != copy_from_user(&enable_binder_comm, (int *)arg, sizeof(int))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_cfg_set_enable_binder_comm(context_ptr, enable_binder_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_ENABLE_BINDER_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_NAME: { - if(0 != copy_from_user(&filter_srv_name, (char *)arg, sizeof(struct binder_stats_filter_srv_name))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_svr_name(context_ptr, &filter_srv_name)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_NAME failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM: { - if(0 != copy_from_user(&filter_proc_comm, (char *)arg, sizeof(struct binder_stats_filter_proc_comm))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_proc_comm(context_ptr, &filter_proc_comm)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_PROC_COMM failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_CFG_SVR_FILTER_UID: { - if(0 != copy_from_user(&filter_uid, (int *)arg, sizeof(struct binder_stats_filter_uid))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == user_binder_stats_add_intreresting_uid(context_ptr, &filter_uid)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_CFG_SVR_FILTER_UID failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_SRVMGR_INT: { - if (0 == set_driver_binder_stats_srvmgr_init()) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_INT failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - case BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME: { - if(0 != copy_from_user(&handle_name, (int *)arg, sizeof(struct binder_stats_handle_name))) { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME failed. copy_to_user error!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - break; - } - if (0 == set_driver_binder_stats_srvmgr_handle_name(&handle_name)) { - ret = BINDER_STATS_CTL_RET_SUCC; - } else { - BINDER_STATS_LOGE("BINDER_STATS_CTL_SRVMGR_SET_HANDLE_NAME failed!\n"); - ret = BINDER_STATS_CTL_RET_INVALID; - } - } - break; - default: { - BINDER_STATS_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = BINDER_STATS_CTL_RET_INVALID; - } - break; - } - - mutex_unlock(&g_binder_stats_driver.lock); - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = binder_stats_driver_open, - .release = binder_stats_driver_release, - .unlocked_ioctl = binder_stats_driver_ioctl, - .mmap = binder_stats_driver_mmap, -}; - -void binder_proc_transaction_hook(void *data, - struct task_struct *caller_task, struct task_struct *binder_proc_task, struct task_struct *binder_th_task, - int node_debug_id, unsigned int code, bool pending_async) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_notify bn; - bool stats_flag; - - if (NULL == caller_task || NULL == binder_proc_task) - return; - - if (!g_binder_stats_driver.regist_binder_stats_flag) - return; - - if (NULL == g_binder_stats_driver.handle_name_hash) { - BINDER_STATS_LOGE("handle_name_hash error!\n"); - return; - } - - memset(&bn, 0, sizeof(bn)); - stats_flag = false; - if (g_binder_stats_driver.srvmgr_tgid == task_tgid_nr(binder_proc_task)) { - strncpy(bn.service_name, binder_proc_task->comm, TASK_COMM_LEN); - bn.service_name[TASK_COMM_LEN-1] = '\0'; - stats_flag = true; - } else { - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.debug_id_name_hash, handle_name_tmp, hentry_debug_id, node_debug_id) { - if (handle_name_tmp->node_debug_id == node_debug_id) - handle_name_find = handle_name_tmp; - } - if (NULL != handle_name_find) { - strncpy(bn.service_name, handle_name_find->service_name, OPLUS_MAX_SERVICE_NAME_LEN); - bn.service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0'; - stats_flag = true; - } else { - strncpy(bn.service_name, "", OPLUS_MAX_SERVICE_NAME_LEN); - } - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - } - - if (stats_flag) { - bn.caller_task = caller_task; - bn.pending_async = pending_async; - if (NULL != binder_th_task) { - BINDER_STATS_LOGI("BDS_TRAN %d(%s) -> %d(%s) %d(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - node_debug_id, bn.service_name, - binder_proc_task->pid, binder_proc_task->comm, binder_th_task->pid, binder_th_task->comm); - bn.binder_task = binder_th_task; - } else { - BINDER_STATS_LOGI("BDS_TRAN %d(%s) -> %d(%s) %d(%s)\n", caller_task->pid, caller_task->comm, - node_debug_id, bn.service_name, - binder_proc_task->pid, binder_proc_task->comm); - bn.binder_task = binder_proc_task; - } - store_binder_stats_to_kernel(&bn); - } -} - -void binder_new_ref_hool(void *data, - struct task_struct *proc, uint32_t ref_desc, int node_debug_id) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - struct binder_stats_handle_name_node *handle_name_new; - int tgid; - - if (NULL == proc) - return; - - tgid = task_tgid_nr(proc); - - if (g_binder_stats_driver.srvmgr_tgid < 0 || g_binder_stats_driver.srvmgr_tgid != tgid) { - BINDER_STATS_LOGI("BDS_IGN ignored! srvmgr_tgid:%d proc_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid, tgid); - return; - } - - if (NULL == g_binder_stats_driver.handle_name_hash) { - BINDER_STATS_LOGE("handle_name_hash error!\n"); - return; - } - - handle_name_new = kmalloc(sizeof(struct binder_stats_handle_name_node), GFP_ATOMIC); - if (NULL == handle_name_new) { - BINDER_STATS_LOGE("handle_name_new error!\n"); - return; - } - memset(handle_name_new, 0, sizeof(struct binder_stats_handle_name_node)); - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, ref_desc) { - if (handle_name_tmp->handle == ref_desc) - handle_name_find = handle_name_tmp; - } - - if (NULL == handle_name_find) { - handle_name_new->handle = ref_desc; - handle_name_new->node_debug_id = node_debug_id; - strncpy(handle_name_new->service_name, "", OPLUS_MAX_SERVICE_NAME_LEN); - hash_add(g_binder_stats_driver.handle_name_hash, &handle_name_new->hentry_handle, ref_desc); - hash_add(g_binder_stats_driver.debug_id_name_hash, &handle_name_new->hentry_debug_id, node_debug_id); - } else { - handle_name_find->node_debug_id = node_debug_id; - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find && NULL != handle_name_new) { - BINDER_STATS_LOGE("BDS_NEW_BUG tgid:%d ref_desc:%u node_debug_id:%d\n", task_tgid_nr(proc), ref_desc, node_debug_id); - kfree(handle_name_new); - } else { - BINDER_STATS_LOGI("BDS_NEW tgid:%d ref_desc:%u node_debug_id:%d\n", task_tgid_nr(proc), ref_desc, node_debug_id); - } -} - -void binder_del_ref_hook(void *data, - struct task_struct *proc, uint32_t ref_desc) { - unsigned long flags; - struct binder_stats_handle_name_node *handle_name_tmp; - struct binder_stats_handle_name_node *handle_name_find; - int tgid; - - if (NULL == proc) - return; - - tgid = task_tgid_nr(proc); - - if (g_binder_stats_driver.srvmgr_tgid < 0 || g_binder_stats_driver.srvmgr_tgid != tgid) { - BINDER_STATS_LOGI("BDS_IGN ignored! srvmgr_tgid:%d proc_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid, tgid); - return; - } - - if (NULL == g_binder_stats_driver.handle_name_hash) { - BINDER_STATS_LOGE("handle_name error!\n"); - return; - } - - spin_lock_irqsave(&g_binder_stats_driver.srv_name_lock, flags); - - handle_name_find = NULL; - hash_for_each_possible(g_binder_stats_driver.handle_name_hash, handle_name_tmp, hentry_handle, ref_desc) { - if (handle_name_tmp->handle == ref_desc) - handle_name_find = handle_name_tmp; - } - if (NULL != handle_name_find) { - hash_del(&handle_name_find->hentry_handle); - hash_del(&handle_name_find->hentry_debug_id); - } - - spin_unlock_irqrestore(&g_binder_stats_driver.srv_name_lock, flags); - - if (NULL != handle_name_find) { - BINDER_STATS_LOGI("BDS_DEL tgid:%d ref_desc:%u\n", tgid, ref_desc); - kfree(handle_name_find); - } else { - BINDER_STATS_LOGE("BDS_DEL_BUG tgid:%d not found ref_desc:%u\n", tgid, ref_desc); - } -} - -#if defined(BINDER_STATS_DEBUGFS) - -static ssize_t debug_write(struct file *file, const char __user *ubuf, - size_t count, loff_t *ppos) { - const int debug_bufmax = 512 - 1; - size_t ret; - char cmd_buffer[512]; - int i; - struct hlist_node *tmp; - struct binder_stats_handle_name_node *handle_name_find; - - ret = count; - - if (count > debug_bufmax) - count = debug_bufmax; - - if (copy_from_user(&cmd_buffer, ubuf, count)) - return -EFAULT; - - cmd_buffer[count] = 0; - - if (strncmp(cmd_buffer, "srvmap", 6) == 0) { - BINDER_STATS_LOGI("BDS_DBG srvmap\n"); - BINDER_STATS_LOGI("BDS_DBG srvmgr_tgid:%d\n", g_binder_stats_driver.srvmgr_tgid); - hash_for_each_safe(g_binder_stats_driver.handle_name_hash, i, tmp, handle_name_find, hentry_handle) { - BINDER_STATS_LOGI("BDS_DBG service_name:%s handle:%d node_debug_id:%d\n", - handle_name_find->service_name, handle_name_find->handle, handle_name_find->node_debug_id); - } - } - - return ret; -} - -static const struct file_operations binder_stats_dbg_fops = { - .write = debug_write, -}; - -#endif - -int __init binder_stats_dev_init(void) { - int err = 0; - g_binder_stats_driver.version_code = BINDER_STATS_CTL_VERSION_CODE; - mutex_init(&g_binder_stats_driver.lock); - spin_lock_init(&g_binder_stats_driver.user_list_lock); - INIT_LIST_HEAD(&g_binder_stats_driver.user_list_head); - hash_init(g_binder_stats_driver.handle_name_hash); - hash_init(g_binder_stats_driver.debug_id_name_hash); - g_binder_stats_driver.srvmgr_tgid = -1; - spin_lock_init(&g_binder_stats_driver.srv_name_lock); - - err = alloc_chrdev_region(&g_binder_stats_driver.dev, 0, 1, "binder_stats"); - if (err < 0) { - BINDER_STATS_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_binder_stats_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_binder_stats_driver.cdev, g_binder_stats_driver.dev, 1); - if (err < 0) { - BINDER_STATS_LOGE("cdev_add g_binder_stats_driver.cdev failed!\n"); - goto unreg_region; - } - - g_binder_stats_driver.dev_class = class_create(THIS_MODULE, "binder_stats_class"); - if (IS_ERR(g_binder_stats_driver.dev_class)) { - BINDER_STATS_LOGE("create class g_binder_stats_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_binder_stats_driver.device = device_create(g_binder_stats_driver.dev_class, - NULL, g_binder_stats_driver.dev, NULL, "binder_stats"); - if (IS_ERR(g_binder_stats_driver.device)) { - BINDER_STATS_LOGE("device_create g_binder_stats_driver.device error\n"); - goto destroy_class; - } - - g_binder_stats_driver.regist_binder_stats_flag = false; - - register_trace_android_vh_binder_proc_transaction(binder_proc_transaction_hook, NULL); - register_trace_android_vh_binder_new_ref(binder_new_ref_hool, NULL); - register_trace_android_vh_binder_del_ref(binder_del_ref_hook, NULL); - -#if defined(BINDER_STATS_DEBUGFS) - g_binder_stats_driver.d_folder_binder_stats = debugfs_create_dir("binder_stats", NULL); - if (g_binder_stats_driver.d_folder_binder_stats) - g_binder_stats_driver.d_file_cmd = debugfs_create_file("cmd", S_IFREG | 0644, - g_binder_stats_driver.d_folder_binder_stats, NULL, &binder_stats_dbg_fops); -#endif - - return 0; - -destroy_class: - class_destroy(g_binder_stats_driver.dev_class); - -destroy_cdev: - cdev_del(&g_binder_stats_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_binder_stats_driver.dev, 1); - -fail: - return -1; -} - - -void __exit binder_stats_dev_exit(void) { -#if defined(BINDER_STATS_DEBUGFS) - if (g_binder_stats_driver.d_file_cmd) - debugfs_remove(g_binder_stats_driver.d_file_cmd); - if (g_binder_stats_driver.d_folder_binder_stats) - debugfs_remove(g_binder_stats_driver.d_folder_binder_stats); -#endif - unregister_trace_android_vh_binder_proc_transaction(binder_proc_transaction_hook, NULL); - unregister_trace_android_vh_binder_new_ref(binder_new_ref_hool, NULL); - unregister_trace_android_vh_binder_del_ref(binder_del_ref_hook, NULL); - if (g_binder_stats_driver.dev_class) { - device_destroy(g_binder_stats_driver.dev_class, g_binder_stats_driver.dev); - class_destroy(g_binder_stats_driver.dev_class); - g_binder_stats_driver.dev_class = NULL; - } - - cdev_del(&g_binder_stats_driver.cdev); - - unregister_chrdev_region(g_binder_stats_driver.dev, 1); -} - -#else /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - -int __init binder_stats_dev_init(void) { - return 0; -} - -void __exit binder_stats_dev_exit(void) { -} - -#endif /* defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE) */ - diff --git a/drivers/soc/oplus/midas/v2/dispcap_dev.c b/drivers/soc/oplus/midas/v2/dispcap_dev.c deleted file mode 100755 index 08378c79ffd2..000000000000 --- a/drivers/soc/oplus/midas/v2/dispcap_dev.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * linux/drivers/soc/oplus/oppo_midas/dispcap_dev.c - * - * Added dispcap drivers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#if defined(CONFIG_OPLUS_FEATURE_DISPCAP) - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* import from cwb driver begin */ - -enum CWB_BUFFER_TYPE { - IMAGE_ONLY, - CARRY_METADATA, - BUFFER_TYPE_NR, -}; -struct mtk_cwb_funcs { - /** - * @get_buffer: - * - * This function is optional. - * - * If user hooks this callback, driver will use this first when - * wdma irq is arrived. (capture done) - * User need fill buffer address to *buffer. - * - * If user not hooks this callback driver will confirm whether - * mtk_wdma_capture_info->user_buffer is NULL or not. - * User can use setUserBuffer() assigned this param. - */ - void (*get_buffer)(void **buffer); - - /** - * @copy_done: - * - * When Buffer copy done will be use this callback to notify user. - */ - void (*copy_done)(void *buffer, enum CWB_BUFFER_TYPE type); -}; - -struct mtk_rect { - int x; - int y; - int width; - int height; -}; - -extern bool mtk_drm_set_cwb_roi(struct mtk_rect rect); -extern bool mtk_drm_cwb_enable(int en, - const struct mtk_cwb_funcs *funcs, - enum CWB_BUFFER_TYPE type); -extern bool mtk_drm_set_cwb_user_buf(void *user_buffer, enum CWB_BUFFER_TYPE type); - -/* import from ion driver */ - -struct ion_handle; -extern struct ion_device *g_ion_device; -extern void * ion_map_kernel(struct ion_client *client, struct ion_handle *handle); -extern void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); - -/* dispcap driver */ - -#define DISPCAP_CTL_SET_CAPTURE_RECT 97 -#define DISPCAP_CTL_SET_CAPTURE_INTERVAL 98 -#define DISPCAP_CTL_ENABLE_CAPTURE 99 -#define DISPCAP_CTL_SET_BUFFER 100 -#define DISPCAP_CTL_WAIT_BUFFER_COMPLETE 101 -#define DISPCAP_CTL_RET_SUCC 0 -#define DISPCAP_CTL_RET_WAIT_TIMEOUT 1 -#define DISPCAP_CTL_RET_INVALID -1 -#define DISPCAP_CTL_RET_ERROR -2 -#define DISPCAP_LOGD(...) -#define DISPCAP_LOGE pr_err - -struct disp_capture_rect -{ - int x; - int y; - int w; - int h; -}; - -struct disp_driver_context -{ - struct ion_handle *dispcap_ion_handle; -}; - -struct disp_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct ion_client *ion_client; - struct completion dispcap_cmp; - struct mutex dispcap_lock; - bool dispcap_used; - int pid; -}; - -static struct disp_driver g_disp_driver; - -void my_user_copy_done(void *buffer, enum CWB_BUFFER_TYPE type) { - DISPCAP_LOGD("start : %p\n", buffer); - complete(&g_disp_driver.dispcap_cmp); -} - -static const struct mtk_cwb_funcs user_cwb_funcs = { - .copy_done = my_user_copy_done, -}; - -static int driver_open(struct inode *inode, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if (g_disp_driver.dispcap_used) { - DISPCAP_LOGD("dispcap is in used. pid:%d\n", g_disp_driver.pid); - mutex_unlock(&g_disp_driver.dispcap_lock); - return -1; - } - - context_ptr = kmalloc(sizeof(struct disp_driver_context), GFP_KERNEL); - if (NULL == context_ptr) { - mutex_unlock(&g_disp_driver.dispcap_lock); - return -ENOMEM; - } - - context_ptr->dispcap_ion_handle = NULL; - - filp->private_data = context_ptr; - - g_disp_driver.dispcap_used = true; - g_disp_driver.pid = current->pid; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static int driver_release(struct inode *ignored, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr = filp->private_data; - if (NULL != context_ptr) { - - // disable capture buffer and unmap - mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY); - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - kfree(context_ptr); - filp->private_data = NULL; - } - - g_disp_driver.dispcap_used = false; - g_disp_driver.pid = -1; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static long driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) -{ - long ret = -1; - struct disp_driver_context *context_ptr = filp->private_data; - - DISPCAP_LOGD("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - DISPCAP_LOGE("context_ptr error!\n"); - return ret; - } - - switch (cmd) { - case DISPCAP_CTL_SET_CAPTURE_RECT: { - struct disp_capture_rect rect; - if(0 != copy_from_user(&rect, (void __user *)arg, sizeof(struct disp_capture_rect))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_CAPTURE_RECT arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - struct mtk_rect mrect; - mrect.x = rect.x; - mrect.y = rect.y; - mrect.width = rect.w; - mrect.height = rect.h; - if(!mtk_drm_set_cwb_roi(mrect)) { - DISPCAP_LOGE("setCaptureRect error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("setCaptureRect:%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_ENABLE_CAPTURE: { - int capture; - if(0 != copy_from_user(&capture, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_ENABLE_CAPTURE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_cwb_enable(capture, &user_cwb_funcs, IMAGE_ONLY)) { - DISPCAP_LOGE("setCaptureInterval error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("enableCapture:%d mtk_crtc_capt_enable\n", capture); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_SET_BUFFER: { - int ion_share_fd; - struct dma_buf *cur_dma_buf; - void * map_ion_va; - - if(0 != copy_from_user(&ion_share_fd, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_BUFFER arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - DISPCAP_LOGD("ion_share_fd:%d\n", ion_share_fd); - - cur_dma_buf = dma_buf_get(ion_share_fd); - if (NULL == cur_dma_buf) { - DISPCAP_LOGE("dma_buf_get failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - break; - } - DISPCAP_LOGD("cur_dma_buf:%p\n", cur_dma_buf); - DISPCAP_LOGD("cur_dma_buf size:%lu\n", cur_dma_buf->size); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr->dispcap_ion_handle = ion_import_dma_buf_fd(g_disp_driver.ion_client, ion_share_fd); - if (NULL == context_ptr->dispcap_ion_handle) { - DISPCAP_LOGE("ion_import_dma_buf_fd failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_import_dma_buf_fd ion_handle:%p\n", context_ptr->dispcap_ion_handle); - - map_ion_va = ion_map_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - if (NULL == map_ion_va) { - DISPCAP_LOGE("ion_map_kernel failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - DISPCAP_LOGD("ion_map_kernel map_ion_va:%p\n", map_ion_va); - - DISPCAP_LOGD("reinit_completion\n"); - reinit_completion(&g_disp_driver.dispcap_cmp); - - DISPCAP_LOGD("setUserBuffer: %p\n", map_ion_va); - if(!mtk_drm_set_cwb_user_buf((void *)map_ion_va, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - case DISPCAP_CTL_WAIT_BUFFER_COMPLETE: { - int wait_ms; - int wait_ret; - if(0 != copy_from_user(&wait_ms, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_WAIT_BUFFER_COMPLETE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout timeout:%dms begin ...\n", wait_ms); - wait_ret = wait_for_completion_interruptible_timeout(&g_disp_driver.dispcap_cmp, msecs_to_jiffies(wait_ms)); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if(!mtk_drm_set_cwb_user_buf((void *)NULL, IMAGE_ONLY)) { - DISPCAP_LOGE("mtk_drm_set_cwb_user_buf failed!\n"); - ret = DISPCAP_CTL_RET_INVALID; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout OK wait_ret:%d\n", wait_ret); - if (0 == wait_ret) { - ret = DISPCAP_CTL_RET_WAIT_TIMEOUT; - } else if (0 < wait_ret) { - ret = DISPCAP_CTL_RET_SUCC; - } else { - ret = DISPCAP_CTL_RET_INVALID; - } - } - break; - default: { - DISPCAP_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = DISPCAP_CTL_RET_INVALID; - } - break; - } - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = driver_open, - .release = driver_release, - .unlocked_ioctl = driver_ioctl, -}; - -int __init dispcap_dev_init(void) -{ - int err = 0; - - DISPCAP_LOGD("start\n"); - - g_disp_driver.dev_class = NULL; - g_disp_driver.device = NULL; - g_disp_driver.dev_class = NULL; - g_disp_driver.ion_client = NULL; - g_disp_driver.dispcap_used = false; - mutex_init(&g_disp_driver.dispcap_lock); - - err = alloc_chrdev_region(&g_disp_driver.dev, 0, 1, "midas_dispcap"); - if (err < 0) { - DISPCAP_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_disp_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_disp_driver.cdev, g_disp_driver.dev, 1); - if (err < 0) { - DISPCAP_LOGE("cdev_add g_disp_driver.cdev failed!\n"); - goto unreg_region; - } - - g_disp_driver.dev_class = class_create(THIS_MODULE, "midas_dispcap_class"); - if (IS_ERR(g_disp_driver.dev_class)) { - DISPCAP_LOGE("create class g_disp_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_disp_driver.device = device_create(g_disp_driver.dev_class, NULL, g_disp_driver.dev, NULL, "midas_dispcap"); - if (IS_ERR(g_disp_driver.device)) { - DISPCAP_LOGE("device_create g_disp_driver.device error\n"); - goto destroy_class; - } - - g_disp_driver.ion_client = ion_client_create(g_ion_device, "dispcap_ion_client"); - if (NULL == g_disp_driver.ion_client) { - DISPCAP_LOGE("ion_client_create g_disp_driver.ion_client failed\n"); - goto destroy_device; - } - - init_completion(&g_disp_driver.dispcap_cmp); - - return 0; - -destroy_device: - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - -destroy_class: - class_destroy(g_disp_driver.dev_class); - -destroy_cdev: - cdev_del(&g_disp_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_disp_driver.dev, 1); - -fail: - return -1; -} - -void __exit dispcap_dev_exit(void) -{ - DISPCAP_LOGD("start\n"); - - if (NULL != g_disp_driver.ion_client) { - ion_client_destroy(g_disp_driver.ion_client); - g_disp_driver.ion_client = NULL; - } - - if (g_disp_driver.dev_class) { - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - class_destroy(g_disp_driver.dev_class); - g_disp_driver.dev_class = NULL; - } - - cdev_del(&g_disp_driver.cdev); - - unregister_chrdev_region(g_disp_driver.dev, 1); -} - - -module_init(dispcap_dev_init); -module_exit(dispcap_dev_exit); - -#endif // #if defined(CONFIG_OPLUS_FEATURE_DISPCAP) diff --git a/drivers/soc/oplus/midas/v2/midas_cpu.c b/drivers/soc/oplus/midas/v2/midas_cpu.c deleted file mode 100755 index 4e0fe388c4ae..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_cpu.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include "midas_dev.h" -#include "midas_cpu.h" - -#define WQ_NAME_LEN 24 - -enum { - TYPE_NONE = 0, - TYPE_PROCESS, - TYPE_APP, - TYPE_TOTAL, -}; - -int midas_ioctl_get_och(void *kdata, void *priv_info) -{ - unsigned long flags; - struct midas_priv_info *info = priv_info; - struct cpu_och_data *buf = NULL; - - if (IS_ERR_OR_NULL(info) || - IS_ERR_OR_NULL(info->mmap_addr)) - return -EINVAL; - - buf = info->mmap_addr; - spin_lock_irqsave(&info->lock, flags); - memset(buf, 0, sizeof(struct cpu_och_data)); - get_cpufreq_health_info(&buf->cnt, buf->info); - spin_unlock_irqrestore(&info->lock, flags); - - return 0; -} - -static void update_cpu_entry_locked(struct task_struct *p, u64 cputime, - unsigned int state, struct cpu_mmap_data *buf) -{ - unsigned int cpu = p->cpu; - - if (cpu >= CPU_MAX) - return; - - buf->cpu_entrys[cpu].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); -} - -static void query_pid_name(struct task_struct *p, char *name) -{ - char buf[WQ_NAME_LEN] = {0}; - - if (!(p->flags & PF_WQ_WORKER)) { - strncpy(name, p->comm, TASK_COMM_LEN); - } else { - get_worker_info(p, buf); - if (buf[0]) { - strncpy(name, buf, TASK_COMM_LEN - 1); - name[TASK_COMM_LEN - 1] = '\0'; - } else { - strncpy(name, p->comm, TASK_COMM_LEN); - } - } -} - -static void update_entry_locked(uid_t uid, struct task_struct *p, u64 cputime, - unsigned int state, struct cpu_mmap_data *buf, unsigned int type) -{ - unsigned int id_cnt = buf->cnt; - unsigned int index = (type == TYPE_PROCESS) ? ID_PID : ID_UID; - unsigned int id = (type == TYPE_PROCESS) ? task_pid_nr(p) : uid; - struct task_struct *task; - int i; - - for (i = 0; i < id_cnt; i++) { - if (buf->entrys[i].type == type - && buf->entrys[i].id[index] == id) { - if ((type == TYPE_PROCESS && buf->entrys[i].id[ID_UID] == uid) - || (type == TYPE_APP)) { - /* the unit of time_in_state is ms */ - buf->entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - return; - } - } - } - - if (i >= ENTRY_MAX) - return; - - /* We didn't find id_entry exsited, should create a new one */ - buf->entrys[i].id[ID_UID] = uid; - buf->entrys[i].type = type; - if (type == TYPE_PROCESS) { - buf->entrys[i].id[ID_PID] = task_pid_nr(p); - buf->entrys[i].id[ID_TGID] = task_tgid_nr(p); - query_pid_name(p, buf->entrys[i].name[ID_PID]); - /* Get tgid name */ - rcu_read_lock(); - task = find_task_by_vpid(buf->entrys[i].id[ID_TGID]); - rcu_read_unlock(); - strncpy(buf->entrys[i].name[ID_TGID], task->comm, TASK_COMM_LEN); - } - /* the unit of time_in_state is ms */ - buf->entrys[i].time_in_state[state] += DIV_ROUND_CLOSEST(cputime, NSEC_PER_MSEC); - buf->cnt = ((id_cnt + 1) > ENTRY_MAX) ? ENTRY_MAX : (id_cnt + 1); -} - -void midas_record_task_times(void *data, u64 cputime, struct task_struct *p, - unsigned int state) -{ - unsigned long flags, user_flags; - uid_t uid = from_kuid_munged(current_user_ns(), task_uid(p)); - struct midas_priv_info *info; - unsigned int avail; - struct list_head *head = get_user_list(); - struct spinlock *user_lock = get_user_lock(); - struct cpu_mmap_pool *pool; - - spin_lock_irqsave(user_lock, user_flags); - list_for_each_entry(info, head, list) { - if (!info) - continue; - - spin_lock_irqsave(&info->lock, flags); - if (info->removing || !info->mmap_addr || - info->type != MMAP_CPU) { - spin_unlock_irqrestore(&info->lock, flags); - continue; - } - avail = info->avail; - pool = info->mmap_addr; - - update_entry_locked(uid, p, cputime, state, &pool->buf[avail], TYPE_APP); - update_entry_locked(uid, p, cputime, state, &pool->buf[avail], TYPE_PROCESS); - update_cpu_entry_locked(p, cputime, state, &pool->buf[avail]); - - spin_unlock_irqrestore(&info->lock, flags); - } - spin_unlock_irqrestore(user_lock, user_flags); -} - -int midas_ioctl_get_time_in_state(void *kdata, void *priv_info) -{ - unsigned long flags; - struct midas_priv_info *info = priv_info; - unsigned int *tmp = (unsigned int *)kdata; - struct cpu_mmap_pool *pool; - - if (IS_ERR_OR_NULL(info) || - IS_ERR_OR_NULL(info->mmap_addr)) - return -EINVAL; - - spin_lock_irqsave(&info->lock, flags); - - *tmp = info->avail; - info->avail = !info->avail; - pool = info->mmap_addr; - memset(&pool->buf[info->avail], 0, sizeof(struct cpu_mmap_data)); - - spin_unlock_irqrestore(&info->lock, flags); - return 0; -} diff --git a/drivers/soc/oplus/midas/v2/midas_cpu.h b/drivers/soc/oplus/midas/v2/midas_cpu.h deleted file mode 100644 index 74e20dae45b4..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_cpu.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#ifndef __MIDAS_CPU_H__ -#define __MIDAS_CPU_H__ - -#include -#include "midas_dev.h" -#include "../../cpufreq_health/cpufreq_health.h" - -#define STATE_MAX 60 -#define CPU_MAX 8 - -enum { - ID_PID = 0, - ID_TGID, - ID_PROC_TOTAL, - ID_UID = 2, - ID_TOTAL, -}; - -struct id_entry { - unsigned int id[ID_TOTAL]; - unsigned int type; - char name[ID_PROC_TOTAL][TASK_COMM_LEN]; - unsigned long long time_in_state[STATE_MAX]; -}; - -struct cpu_entry { - unsigned long long time_in_state[STATE_MAX]; -}; - -struct cpu_mmap_data { - unsigned int cnt; - struct id_entry entrys[ENTRY_MAX]; - struct cpu_entry cpu_entrys[CPU_MAX]; -}; - -struct cpu_mmap_pool { - struct cpu_mmap_data buf[BUF_NUM]; -}; - -struct cpu_och_data { - unsigned int cnt; - struct cpufreq_health_info info[STATE_MAX]; -}; - -int midas_ioctl_get_time_in_state(void *kdata, void *priv_info); -int midas_ioctl_get_och(void *kdata, void *priv_info); -void midas_record_task_times(void *data, u64 cputime, struct task_struct *p, unsigned int state); -#endif /* __MIDAS_CPU_H__ */ diff --git a/drivers/soc/oplus/midas/v2/midas_dev.c b/drivers/soc/oplus/midas/v2/midas_dev.c deleted file mode 100755 index 637813a7ddfb..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_dev.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "midas_dev.h" -#include "midas_cpu.h" -#include "midas_mem.h" - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -#include -#else -#include -#endif - -#define MIDAS_MAX_DEVS 1 -#define MAX_USER_CNT 10 -#define MAX_RASMEVENT_PARAM 7 - -static char *rasm_env[MAX_RASMEVENT_PARAM]; -static LIST_HEAD(user_list); -static DEFINE_SPINLOCK(user_lock); -static atomic_t user_cnt = ATOMIC_INIT(0); - -unsigned long mmap_size_tbl[MMAP_TYPE_MAX] = { - sizeof(struct cpu_mmap_pool), - sizeof(struct mem_mmap_data), - sizeof(struct cpu_och_data), -}; - -struct list_head *get_user_list(void) -{ - return &user_list; -} - -struct spinlock *get_user_lock(void) -{ - return &user_lock; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -static void do_gettimeofday(struct timeval *tv) -{ - struct timespec64 now; - - ktime_get_real_ts64(&now); - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000; -} -#endif - -static void do_getboottime(struct timeval *tv) -{ - struct timespec64 now; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ktime_get_boottime_ts64(&now); -#else - get_monotonic_boottime64(&now); -#endif - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000; -} - -struct rasm_data { - long last_suspend_time; - long last_resume_time; - long last_resume_boot_time; - long last_suspend_millsec_time; - long last_resume_millsec_time; -}; - -static int rasm_resume(struct device *dev) { - struct timeval resume_time; - struct timeval resume_boot_time; - struct rasm_data *data; - int index = 0; - int i; - - data = dev->driver_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - do_gettimeofday(&resume_time); - data->last_resume_time = resume_time.tv_sec; - data->last_resume_millsec_time = resume_time.tv_sec * 1000 + resume_time.tv_usec / 1000; - do_getboottime(&resume_boot_time); - data->last_resume_boot_time = resume_boot_time.tv_sec * 1000 + resume_boot_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will resume.", data->last_resume_time); - - rasm_env[index++] = kasprintf(GFP_KERNEL, "NAME=rasm"); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend=%ld", data->last_suspend_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume=%ld", data->last_resume_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_boot=%ld", data->last_resume_boot_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "resume_millsec=%ld", data->last_resume_millsec_time); - rasm_env[index++] = kasprintf(GFP_KERNEL, "suspend_millsec=%ld", data->last_suspend_millsec_time); - rasm_env[index++] = NULL; - - if (index > ARRAY_SIZE(rasm_env)) - BUG(); - - kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, rasm_env); - for (i = 0; i < index - 1; ++i) - kfree(rasm_env[i]); - return 0; -} - -static int rasm_suspend(struct device *dev) { - struct timeval suspend_time; - struct rasm_data *data; - - data = dev->driver_data; - if (!data) { - pr_err("rasm_data is empty"); - return 0; - } - do_gettimeofday(&suspend_time); - data->last_suspend_time = suspend_time.tv_sec; - data->last_suspend_millsec_time = suspend_time.tv_sec * 1000 + suspend_time.tv_usec / 1000; - dev_dbg(dev, "Now it is %ld, system will suspend.", data->last_suspend_time); - return 0; -} - -static const struct dev_pm_ops rasm_pm_ops = { - .suspend = rasm_suspend, - .resume = rasm_resume, -}; - -static int midas_dev_mmap(struct file *filp, struct vm_area_struct *vma) -{ - int ret = 0; - - struct midas_priv_info *info = filp->private_data; - if (IS_ERR_OR_NULL(info)) - return -EINVAL; - - if (info->type < 0 || info->type >= MMAP_TYPE_MAX) { - pr_err("mmap type=%d is invalid!\n", info->type); - return -EINVAL; - } - - info->mmap_addr = vmalloc_user(mmap_size_tbl[info->type]); - if (IS_ERR_OR_NULL(info->mmap_addr)) { - pr_err("mmap_addr vmalloc failed!\n"); - return -ENOMEM; - } - - if (remap_vmalloc_range(vma, info->mmap_addr, - vma->vm_pgoff)) { - pr_err("remap failed\n"); - ret = -EAGAIN; - goto err_remap; - } - - return 0; - -err_remap: - vfree(info->mmap_addr); - info->mmap_addr = NULL; - return ret; -} - -static int midas_dev_open(struct inode *inode, struct file *filp) -{ - struct midas_priv_info *info; - unsigned long flags; - - if (atomic_read(&user_cnt) >= MAX_USER_CNT) { - pr_err("user_cnt=%d, open failed\n", atomic_read(&user_cnt)); - return -EINVAL; - } - - info = kzalloc(sizeof(struct midas_priv_info), GFP_KERNEL); - if (IS_ERR_OR_NULL(info)) - return -ENOMEM; - - info->type = -1; - info->mmap_addr = NULL; - spin_lock_init(&info->lock); - info->removing = false; - filp->private_data = info; - - spin_lock_irqsave(&user_lock, flags); - list_add(&info->list, &user_list); - spin_unlock_irqrestore(&user_lock, flags); - - atomic_inc(&user_cnt); - pr_info("user_cnt=%d\n", atomic_read(&user_cnt)); - return 0; -} - -static int midas_dev_release(struct inode *inode, struct file *filp) -{ - unsigned long flags; - struct midas_priv_info *info = filp->private_data; - if (IS_ERR_OR_NULL(info)) - return 0; - - spin_lock_irqsave(&info->lock, flags); - info->removing = true; - spin_unlock_irqrestore(&info->lock, flags); - - if (info->mmap_addr != NULL) { - vfree(info->mmap_addr); - info->mmap_addr = NULL; - } - - spin_lock_irqsave(&user_lock, flags); - list_del(&info->list); - spin_unlock_irqrestore(&user_lock, flags); - - atomic_dec(&user_cnt); - pr_info("user_cnt=%d\n", atomic_read(&user_cnt)); - kfree(info); - info = NULL; - return 0; -} - -static const struct file_operations midas_dev_fops = { - .open = midas_dev_open, - .release = midas_dev_release, - .mmap = midas_dev_mmap, - .unlocked_ioctl = midas_dev_ioctl, -}; - -static int midas_pdev_probe(struct platform_device *pdev) -{ - int ret = 0; - struct device *dev; - struct midas_dev_info *dev_info; - - dev_info = kzalloc(sizeof(struct midas_dev_info), GFP_KERNEL); - if (IS_ERR_OR_NULL(dev_info)) { - pr_err("Fail to alloc dev info\n"); - ret = -ENOMEM; - goto err_info_alloc; - } - - ret = alloc_chrdev_region(&dev_info->devno, 0, MIDAS_MAX_DEVS, "midas_dev"); - if (ret) { - pr_err("Fail to alloc devno, ret=%d\n", ret); - goto err_cdev_alloc; - } - - cdev_init(&dev_info->cdev, &midas_dev_fops); - ret = cdev_add(&dev_info->cdev, dev_info->devno, MIDAS_MAX_DEVS); - if (ret) { - pr_err("Fail to add cdev, ret=%d\n", ret); - goto err_cdev_add; - } - - dev_info->class = class_create(THIS_MODULE, "midas"); - if (IS_ERR_OR_NULL(dev_info->class)) { - pr_err("Fail to create class, ret=%d\n", ret); - goto err_class_create; - } - - dev = device_create(dev_info->class, NULL, dev_info->devno, - dev_info, "midas_dev"); - - if (IS_ERR_OR_NULL(dev)) { - pr_err("Fail to create device, ret=%d\n", ret); - goto err_device_create; - } - - platform_set_drvdata(pdev, dev_info); - - return 0; - -err_device_create: - class_destroy(dev_info->class); -err_class_create: - cdev_del(&dev_info->cdev); -err_cdev_add: - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); -err_cdev_alloc: - kfree(dev_info); -err_info_alloc: - return ret; -} - - -static int midas_pdev_remove(struct platform_device *pdev) -{ - struct midas_dev_info *dev_info = platform_get_drvdata(pdev); - if (IS_ERR_OR_NULL(dev_info)) - return -EINVAL; - - device_destroy(dev_info->class, dev_info->devno); - class_destroy(dev_info->class); - cdev_del(&dev_info->cdev); - unregister_chrdev_region(dev_info->devno, MIDAS_MAX_DEVS); - kfree(dev_info); - - return 0; -} - -static void midas_pdev_release(struct device *dev) -{ - return; -} - -static struct platform_device midas_pdev = { - .id = -1, - .name = "midas-pdev", - .dev = { - .release = midas_pdev_release, - } -}; - -static const struct of_device_id midas_pdev_dt_ids[] = { - { .compatible = "oplus,midas-pdev", }, - { } -}; - -static struct platform_driver midas_pdev_driver = { - .driver = { - .name = "midas-pdev", - .of_match_table = midas_pdev_dt_ids, - .pm = &rasm_pm_ops, - }, - .probe = midas_pdev_probe, - .remove = midas_pdev_remove, -}; - -int __init midas_dev_init(void) -{ - int rc = 0; - - rc = register_trace_android_vh_midas_record_task_times(midas_record_task_times, NULL); - if (rc < 0) { - pr_err("register_trace_android_vh_midas_record_task_times failed! rc=%d\n", rc); - goto err_trace_register; - } - - rc = platform_device_register(&midas_pdev); - if (rc < 0) { - pr_err("platform_device_register failed! rc=%d\n", rc); - goto err_device_register; - } - - rc = platform_driver_register(&midas_pdev_driver); - if (rc < 0) { - pr_err("platform_driver_register failed! rc=%d\n", rc); - goto err_driver_register; - } - - return 0; - -err_driver_register: - platform_device_unregister(&midas_pdev); -err_device_register: - unregister_trace_android_vh_midas_record_task_times(midas_record_task_times, NULL); -err_trace_register: - return rc; -} - -void __exit midas_dev_exit(void) -{ - unregister_trace_android_vh_midas_record_task_times(midas_record_task_times, NULL); - platform_device_unregister(&midas_pdev); - platform_driver_unregister(&midas_pdev_driver); -} diff --git a/drivers/soc/oplus/midas/v2/midas_dev.h b/drivers/soc/oplus/midas/v2/midas_dev.h deleted file mode 100755 index 861b8809ef1e..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_dev.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#ifndef __MIDAS_DEV_H__ -#define __MIDAS_DEV_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ENTRY_MAX 1024 -#define BUF_NUM 2 - -enum { - MMAP_CPU = 0, - MMAP_MEM, - MMAP_OCH, - MMAP_TYPE_MAX, -}; - -struct midas_dev_info { - unsigned int version; - dev_t devno; - struct cdev cdev; - struct class *class; -}; - -struct midas_priv_info { - int type; - struct list_head list; - spinlock_t lock; - unsigned int avail; - void *mmap_addr; - bool removing; -}; - -typedef int midas_ioctl_t(void *kdata, void *priv_info); - -struct midas_ioctl_desc { - unsigned int cmd; - midas_ioctl_t *func; -}; - -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg); -struct list_head *get_user_list(void); -struct spinlock *get_user_lock(void); - -int __init midas_dev_init(void); -void __exit midas_dev_exit(void); - -#endif diff --git a/drivers/soc/oplus/midas/v2/midas_ioctl.c b/drivers/soc/oplus/midas/v2/midas_ioctl.c deleted file mode 100755 index 1d1bb29cb8ec..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_ioctl.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include - -#include "midas_dev.h" -#include "midas_cpu.h" -#include "midas_mem.h" - -/* - * Version: - * 3. Add OCA ioctl. - * 2. Add MIDAS memory module. - */ -#define MIDAS_DEV_VERSION 3 - -#define MIDAS_IOCTL_DEF(ioctl, _func) \ - [MIDAS_IOCTL_NR(ioctl)] = { \ - .cmd = ioctl, \ - .func = _func, \ - } - -#define MIDAS_IOCTL_BASE 'm' -#define MIDAS_IO(nr) _IO(MIDAS_IOCTL_BASE, nr) -#define MIDAS_IOR(nr, type) _IOR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOW(nr, type) _IOW(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOWR(nr, type) _IOWR(MIDAS_IOCTL_BASE, nr, type) -#define MIDAS_IOCTL_NR(n) _IOC_NR(n) -#define MIDAS_CORE_IOCTL_CNT ARRAY_SIZE(midas_ioctls) - -#define MIDAS_IOCTL_GET_TIME_IN_STATE MIDAS_IOR(0x1, unsigned int) -#define MIDAS_IOCTL_GET_VERSION MIDAS_IOR(0x5, int) -#define MIDAS_IOCTL_SET_MMAP_TYPE MIDAS_IOW(0x6, int) -#define MIDAS_IOCTL_GET_MEMINFO MIDAS_IOR(0x7, int) -#define MIDAS_IOCTL_GET_TOTALMEM MIDAS_IOR(0x8, unsigned long) -#define MIDAS_IOCTL_GET_OCH MIDAS_IOW(0x9, int) - -static int midas_ioctl_get_version(void *kdata, void *priv_info) -{ - int *tmp = (int *)kdata; - - *tmp = MIDAS_DEV_VERSION; - return 0; -} - -static int midas_ioctl_set_mmap_type(void *kdata, void *priv_info) -{ - int *type = kdata; - struct midas_priv_info *info = priv_info; - - info->type = *type; - return 0; -} - -/* Ioctl table */ -static const struct midas_ioctl_desc midas_ioctls[] = { - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_TIME_IN_STATE, midas_ioctl_get_time_in_state), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_VERSION, midas_ioctl_get_version), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_SET_MMAP_TYPE, midas_ioctl_set_mmap_type), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_MEMINFO, midas_ioctl_get_meminfo), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_TOTALMEM, midas_ioctl_get_totalmem), - MIDAS_IOCTL_DEF(MIDAS_IOCTL_GET_OCH, midas_ioctl_get_och), -}; - -#define KDATA_SIZE 512 -long midas_dev_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg) -{ - struct midas_priv_info *info = filp->private_data; - const struct midas_ioctl_desc *ioctl = NULL; - midas_ioctl_t *func; - unsigned int nr = MIDAS_IOCTL_NR(cmd); - int ret = -EINVAL; - char kdata[KDATA_SIZE] = { }; - unsigned int in_size, out_size; - - if (nr >= MIDAS_CORE_IOCTL_CNT) { - pr_err("out of array\n"); - return -EINVAL; - } - - ioctl = &midas_ioctls[nr]; - - out_size = in_size = _IOC_SIZE(cmd); - if ((cmd & IOC_IN) == 0) - in_size = 0; - if ((cmd & IOC_OUT) == 0) - out_size = 0; - - if (out_size > KDATA_SIZE || in_size > KDATA_SIZE) { - pr_err("out of memory\n"); - ret = -EINVAL; - goto err_out_of_mem; - } - - func = ioctl->func; - if (unlikely(!func)) { - pr_err("no func\n"); - ret = -EINVAL; - goto err_no_func; - } - - if (copy_from_user(kdata, (void __user *)arg, in_size)) { - pr_err("copy_from_user failed\n"); - ret = -EFAULT; - goto err_fail_cp; - } - - ret = func(kdata, info); - - if (copy_to_user((void __user *)arg, kdata, out_size)) { - pr_err("copy_to_user failed\n"); - ret = -EFAULT; - } - -err_fail_cp: -err_no_func: -err_out_of_mem: - return ret; -} diff --git a/drivers/soc/oplus/midas/v2/midas_mem.c b/drivers/soc/oplus/midas/v2/midas_mem.c deleted file mode 100755 index b64b3b023d90..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_mem.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include "midas_mem.h" -#include "midas_cpu.h" -#include "midas_dev.h" - -static void update_procmem_entry_locked(int index, struct process_mem val, struct mem_mmap_data *buf) -{ - buf->entrys[index].id[MEM_TGID] = val.pid; - buf->entrys[index].id[MEM_UID] = val.uid; - buf->entrys[index].rss = val.rss; - buf->entrys[index].oom_score_adj = val.oom_score_adj; - buf->entrys[index].gl_dev = val.gl_dev; - strncpy(buf->entrys[index].comm, val.comm, TASK_COMM_LEN); -} - -static struct process_mem pmem[ENTRY_MAX] = {0}; -void midas_update_procmem(struct midas_priv_info *info) -{ - unsigned long flags; - int i, cnt; - struct mem_mmap_data *buf = info->mmap_addr; - - mm_get_all_pmem(&cnt, pmem); - - spin_lock_irqsave(&info->lock, flags); - - for (i = 0; i < cnt; i++) - update_procmem_entry_locked(i, pmem[i], buf); - - buf->cnt = cnt; - - spin_unlock_irqrestore(&info->lock, flags); -} - -static void update_meminfo_locked(int index, unsigned long value, struct mem_mmap_data* buf) -{ - buf->meminfo_entrys[index].value = value; -} - -/* - * meminfo_list: - * 0, "MemFree", - * 1, "MemAvailable", - * 2 - 9, reserved. - */ -enum { - MI_MEMFREE = 0, - MI_MEMAVAIL, - MI_MAX, -}; - -static void midas_update_meminfo(struct midas_priv_info *info) -{ - struct sysinfo i; - unsigned long available; - unsigned long flags; - - si_meminfo(&i); - available = (unsigned long)si_mem_available(); - - spin_lock_irqsave(&info->lock, flags); - - update_meminfo_locked(MI_MEMFREE, (unsigned long)(i.freeram << (PAGE_SHIFT - 10)), info->mmap_addr); - update_meminfo_locked(MI_MEMAVAIL, available << (PAGE_SHIFT - 10), info->mmap_addr); - - spin_unlock_irqrestore(&info->lock, flags); -} - -int midas_ioctl_get_meminfo(void *kdata, void *priv_info) -{ - unsigned long flags; - struct midas_priv_info *info = priv_info; - - if (IS_ERR_OR_NULL(info) || - IS_ERR_OR_NULL(info->mmap_addr)) - return -EINVAL; - - spin_lock_irqsave(&info->lock, flags); - memset(info->mmap_addr, 0, sizeof(struct mem_mmap_data)); - spin_unlock_irqrestore(&info->lock, flags); - - midas_update_meminfo(info); - midas_update_procmem(info); - - return 0; -} - -int midas_ioctl_get_totalmem(void *kdata, void *priv_info) -{ - unsigned long *tmp = (unsigned long *)kdata; - struct sysinfo i; - - si_meminfo(&i); - *tmp = (unsigned long)(i.totalram << (PAGE_SHIFT - 10)); - return 0; -} diff --git a/drivers/soc/oplus/midas/v2/midas_mem.h b/drivers/soc/oplus/midas/v2/midas_mem.h deleted file mode 100644 index ca3fcd23c6ac..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_mem.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#ifndef __MIDAS_MEM_H__ -#define __MIDAS_MEM_H__ - -#include -#include "midas_dev.h" - -#define MEMINFO_NUM 10 - -enum { - MEM_TGID = 0, - MEM_UID, - MEM_ID_TOTAL, -}; - -struct procmem_entry { - int id[MEM_ID_TOTAL]; - char comm[TASK_COMM_LEN]; - int oom_score_adj; - unsigned long rss; - unsigned long gl_dev; -}; - -struct meminfo_entry { - unsigned long value; -}; - -struct mem_mmap_data { - unsigned int cnt; - struct procmem_entry entrys[ENTRY_MAX]; - struct meminfo_entry meminfo_entrys[MEMINFO_NUM]; -}; - -int midas_ioctl_get_meminfo(void *kdata, void *priv_info); -int midas_ioctl_get_totalmem(void *kdata, void *priv_info); -#endif diff --git a/drivers/soc/oplus/midas/v2/midas_module.c b/drivers/soc/oplus/midas/v2/midas_module.c deleted file mode 100644 index a696a4290694..000000000000 --- a/drivers/soc/oplus/midas/v2/midas_module.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include "midas_dev.h" - -extern int __init binder_stats_dev_init(void); -extern void __exit binder_stats_dev_exit(void); - -static int __init midas_module_init(void) -{ - midas_dev_init(); - binder_stats_dev_init(); - - return 0; -} - -static void __exit midas_module_exit(void) -{ - midas_dev_exit(); - binder_stats_dev_exit(); -} - -module_init(midas_module_init); -module_exit(midas_module_exit); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/midas/v2/vpu_pw_off_latency_proc.c b/drivers/soc/oplus/midas/v2/vpu_pw_off_latency_proc.c deleted file mode 100755 index 05b19ccbca1d..000000000000 --- a/drivers/soc/oplus/midas/v2/vpu_pw_off_latency_proc.c +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020-2021 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY - -// import from MTK vpu driver -extern int set_all_vpu_power_off_latency(uint64_t pw_off_latency); - -#define BUF_LEN 1024 - -static struct proc_dir_entry *g_vpu_pw_off_latency_pentry = NULL; - -static ssize_t vpu_pw_off_latency_proc_write(struct file *file, const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len; - uint64_t latency_ms; - char tmp[BUF_LEN + 1]; - - if (cnt == 0) - return 0; - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') - tmp[len - 1] = '\0'; - else - tmp[len] = '\0'; - - ret = sscanf(tmp, "%llu", &latency_ms); - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - pr_info("latency_ms cmd:%llu\n", latency_ms); - - set_all_vpu_power_off_latency(latency_ms); - - return cnt; -} - -static const struct file_operations vpu_pw_off_latency_proc_fops = { - .write = vpu_pw_off_latency_proc_write, -}; - -int __init vpu_pw_off_latency_proc_init(void) -{ - g_vpu_pw_off_latency_pentry = proc_create("all_vpu_pw_off_latency", - 0666, NULL, &vpu_pw_off_latency_proc_fops); - return 0; -} - - -void __exit vpu_pw_off_latency_proc_exit(void) -{ - if (NULL != g_vpu_pw_off_latency_pentry) { - proc_remove(g_vpu_pw_off_latency_pentry); - g_vpu_pw_off_latency_pentry = NULL; - } -} - -module_init(vpu_pw_off_latency_proc_init); -module_exit(vpu_pw_off_latency_proc_exit); - -#endif // #ifdef CONFIG_OPLUS_FEATURE_SET_ALL_VPU_LATENCY diff --git a/drivers/soc/oplus/oplus_als_cali_value/Makefile b/drivers/soc/oplus/oplus_als_cali_value/Makefile index aebb084f2d03..9a40272ea3fd 100755 --- a/drivers/soc/oplus/oplus_als_cali_value/Makefile +++ b/drivers/soc/oplus/oplus_als_cali_value/Makefile @@ -1,3 +1,3 @@ # ifdef OPLUS_FEATURE_SENSOR -obj-y += oplus_als_cali_value.o +obj-$(CONFIG_OPLUS_ALS_CALI) += oplus_als_cali_value.o # endif /* OPLUS_FEATURE_SENSOR */ \ No newline at end of file diff --git a/drivers/soc/oplus/oplus_criticallog/Kconfig b/drivers/soc/oplus/oplus_criticallog/Kconfig deleted file mode 100755 index 4df103d58e91..000000000000 --- a/drivers/soc/oplus/oplus_criticallog/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -config OPLUS_CRITICALLOG - bool "config oplus critical log" - help - define this config to init oplus critical log driver. diff --git a/drivers/soc/oplus/oplus_criticallog/Makefile b/drivers/soc/oplus/oplus_criticallog/Makefile deleted file mode 100755 index de09498e1ee2..000000000000 --- a/drivers/soc/oplus/oplus_criticallog/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -obj-y += oplus_criticallog.o criticallog_class.o -#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ - diff --git a/drivers/soc/oplus/oplus_criticallog/criticallog_class.c b/drivers/soc/oplus/oplus_criticallog/criticallog_class.c deleted file mode 100755 index dfc6980f556c..000000000000 --- a/drivers/soc/oplus/oplus_criticallog/criticallog_class.c +++ /dev/null @@ -1,167 +0,0 @@ -/************************************************************************************ -** File: - drivers/soc/oplus/oplus_criticallog/criticallog_class.c -** Copyright (C), 2008-2012, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** critical log dev -** -** Version: 0.1 -** Date created: 11:28:11,16/01/2019 -** -** --------------------------- Revision History: -------------------------------- -** -** -************************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -#define MAX_REASON_LEN 256 - -struct class *criticallog_class; -static atomic_t device_count; - -static ssize_t get_keylog_logid(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct criticallog_dev *sdev = (struct criticallog_dev *) - dev_get_drvdata(dev); - - if (sdev->print_logId) { - int ret = sdev->print_logId(sdev, buf); - if (ret >= 0) - return ret; - } - return sprintf(buf, "%d\n", sdev->logid); -} - -static ssize_t get_modem_reason(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct criticallog_dev *sdev = (struct criticallog_dev *) - dev_get_drvdata(dev); - - if (sdev->print_logInfo) { - int ret = sdev->print_logInfo(sdev, buf); - if (ret >= 0) - return ret; - } - return sprintf(buf, "%s\n", sdev->name); -} - -static DEVICE_ATTR(logid, S_IRUGO, get_keylog_logid, NULL); -static DEVICE_ATTR(name, S_IRUGO, get_modem_reason, NULL); - -void criticallog_set_state(struct criticallog_dev *sdev, int logid, char *subsys) -{ - char modemReason_buf[MAX_REASON_LEN]; - char modemHashReason_buf[MAX_REASON_LEN]; - char modem_event[] = "MODEM_EVENT=modem_failure"; - char *prop_buf; - char *envp[4]; - int length; - - memset(modemReason_buf, 0, sizeof(modemReason_buf)); - memset(modemHashReason_buf, 0, sizeof(modemHashReason_buf)); - - if (strcmp(subsys, "modem") == 0) { - envp[0] = (char *)&modem_event; - prop_buf = (char *)get_zeroed_page(GFP_KERNEL); - if (prop_buf) { - length = get_modem_reason(sdev->dev, NULL, prop_buf); - if (length > 0) { - if (prop_buf[length - 1] == '\n') - prop_buf[length - 1] = 0; - snprintf(modemReason_buf, sizeof(modemReason_buf), "MODEM_REASON=%s", prop_buf); - envp[1] = modemReason_buf; - snprintf(modemHashReason_buf, sizeof(modemHashReason_buf), "MODEM_HASH_REASON=%s", prop_buf); - envp[2] = modemHashReason_buf; - } - printk(KERN_ERR "criticallog: criticallog_set_state length = %d, modemHashReason_buf = %s\n", length, modemHashReason_buf); - envp[3] = NULL; - kobject_uevent_env(&sdev->dev->kobj, KOBJ_CHANGE, envp); - free_page((unsigned long)prop_buf); - } else { - printk(KERN_ERR "out of memory in criticallog_set_state\n"); - kobject_uevent(&sdev->dev->kobj, KOBJ_CHANGE); - } - } -} -EXPORT_SYMBOL_GPL(criticallog_set_state); - -static int create_criticallog_class(void) -{ - if (!criticallog_class) { - criticallog_class = class_create(THIS_MODULE, "critical_log"); - if (IS_ERR(criticallog_class)) - return PTR_ERR(criticallog_class); - atomic_set(&device_count, 0); - } - return 0; -} - -int criticallog_dev_register(struct criticallog_dev *sdev) -{ - int ret; - if (!criticallog_class) { - ret = create_criticallog_class(); - if (ret < 0) - return ret; - } - sdev->index = atomic_inc_return(&device_count); - sdev->dev = device_create(criticallog_class, NULL, - MKDEV(0, sdev->index), NULL, sdev->name); - if (IS_ERR(sdev->dev)) - return PTR_ERR(sdev->dev); - ret = device_create_file(sdev->dev, &dev_attr_logid); - if (ret < 0) - goto err_create_file_1; - ret = device_create_file(sdev->dev, &dev_attr_name); - if (ret < 0) - goto err_create_file_2; - dev_set_drvdata(sdev->dev, sdev); - sdev->logid = 0; - return 0; - -err_create_file_2: - device_remove_file(sdev->dev, &dev_attr_logid); - return ret; - -err_create_file_1: - device_destroy(criticallog_class, MKDEV(0, sdev->index)); - printk(KERN_ERR "criticallog: Failed to register driver %s\n", sdev->name); - - return ret; -} -EXPORT_SYMBOL_GPL(criticallog_dev_register); - -void criticallog_dev_unregister(struct criticallog_dev *sdev) -{ - device_remove_file(sdev->dev, &dev_attr_name); - device_remove_file(sdev->dev, &dev_attr_logid); - device_destroy(criticallog_class, MKDEV(0, sdev->index)); - dev_set_drvdata(sdev->dev, NULL); -} -EXPORT_SYMBOL_GPL(criticallog_dev_unregister); - -static int __init criticallog_class_init(void) -{ - return create_criticallog_class(); -} - -static void __exit criticallog_class_exit(void) -{ - class_destroy(criticallog_class); -} - -module_init(criticallog_class_init); -module_exit(criticallog_class_exit); - -MODULE_AUTHOR("Zhaoan.Xu"); -MODULE_DESCRIPTION("criticallog class driver"); -MODULE_LICENSE("GPL"); -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ diff --git a/drivers/soc/oplus/oplus_criticallog/criticallog_class.h b/drivers/soc/oplus/oplus_criticallog/criticallog_class.h deleted file mode 100755 index 1fa7b2a1a845..000000000000 --- a/drivers/soc/oplus/oplus_criticallog/criticallog_class.h +++ /dev/null @@ -1,51 +0,0 @@ -/************************************************************************************ -** File: - drivers/soc/oplus/oplus_criticallog/criticallog_class.h -** Copyright (C), 2008-2019, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** critical log dev -** -** Version: 0.1 -** Date created: 11:28:11,16/01/2019 -** -** --------------------------- Revision History: -------------------------------- -** -** -************************************************************************************/ - -#ifndef __LINUX_CRITICALLOG_H__ -#define __LINUX_CRITICALLOG_H__ - -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -struct criticallog_dev { - const char *name; - struct device *dev; - int index; - int logid; - ssize_t (*print_logInfo)(struct criticallog_dev *sdev, char *buf); - ssize_t (*print_logId)(struct criticallog_dev *sdev, char *buf); -}; - -struct gpio_criticallog_platform_data { - const char *name; - unsigned gpio; - /* if NULL, criticallog_dev.name will be printed */ - const char *name_on; - const char *name_off; - /* if NULL, "0" or "1" will be printed */ - const char *state_on; - const char *state_off; -}; - -extern int criticallog_dev_register(struct criticallog_dev *sdev); -extern void criticallog_dev_unregister(struct criticallog_dev *sdev); - -static inline int criticallog_get_logid(struct criticallog_dev *sdev) -{ - return sdev->logid; -} - -extern void criticallog_set_state(struct criticallog_dev *sdev, int logid, char *subsys); -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ - -#endif /* __LINUX_CRITICALLOG_H__ */ diff --git a/drivers/soc/oplus/oplus_criticallog/oplus_criticallog.c b/drivers/soc/oplus/oplus_criticallog/oplus_criticallog.c deleted file mode 100755 index d66aca41fdae..000000000000 --- a/drivers/soc/oplus/oplus_criticallog/oplus_criticallog.c +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include -#include -#include - -//#ifdef OPLUS_FEATURE_MODEM_MINIDUMP -static int keylog_registered = 0; -static struct criticallog_dev keylog_swthdev; -static wait_queue_head_t keylog_thread_wq; -static struct task_struct *keylog_thread_task = NULL; - -#define KEYLOG_BUF_MAX 5 -#define LOGNAME_BUF_LEN 2148 -#define SUBSYSTME_NAME_LEN 10 - -struct keylog_data{ - char buf[LOGNAME_BUF_LEN]; - int id; - char subsystem[SUBSYSTME_NAME_LEN]; -}; - -struct keylog_buf{ - spinlock_t keylog_lock; - unsigned int index_write; - unsigned int index_read; - struct keylog_data data[KEYLOG_BUF_MAX]; -}; - -static struct keylog_buf gKeylog_buf; - -void mm_keylog_write_modemdump(unsigned int hashId, const char *cause, int id, char *subsys) { - if(keylog_thread_task && keylog_registered){ - struct keylog_data * keylog_data; - spin_lock(&gKeylog_buf.keylog_lock); - keylog_data = &gKeylog_buf.data[gKeylog_buf.index_write%KEYLOG_BUF_MAX]; - snprintf(keylog_data->buf, LOGNAME_BUF_LEN,"fid:%u;cause:%s\n", hashId, cause); - keylog_data->id = id; - memset(keylog_data->subsystem, 0, sizeof(char)*SUBSYSTME_NAME_LEN); - strcpy(keylog_data->subsystem, subsys); - gKeylog_buf.index_write++; - spin_unlock(&gKeylog_buf.keylog_lock); - wake_up_interruptible(&keylog_thread_wq); - } -} -EXPORT_SYMBOL_GPL(mm_keylog_write_modemdump); - -static ssize_t keylog_snprintf_logInfo(struct criticallog_dev *sdev, char *buf) { - struct keylog_data *keylog_data = &gKeylog_buf.data[gKeylog_buf.index_read%KEYLOG_BUF_MAX]; - pr_err("name = %s\n", keylog_data->buf); - return snprintf(buf, LOGNAME_BUF_LEN,"%s", keylog_data->buf); -} - -static int keylog_thread(void *data){ - while(1){ - wait_event_interruptible(keylog_thread_wq, (gKeylog_buf.index_write - gKeylog_buf.index_read)); - while(gKeylog_buf.index_write > gKeylog_buf.index_read){ - struct keylog_data *keylog_data = &gKeylog_buf.data[gKeylog_buf.index_read%KEYLOG_BUF_MAX]; - pr_info("keylog_data->buf lenth = %d\n", (int)strlen(keylog_data->buf)); - criticallog_set_state(&keylog_swthdev, keylog_data->id, keylog_data->subsystem); - gKeylog_buf.index_read++; - } - } - keylog_thread_task = NULL; - return 0; -} - - -static int __init oplus_criticallog_init(void) -{ - int ret = 0; - init_waitqueue_head(&keylog_thread_wq); - keylog_swthdev.name = "oplus_critical_log"; - keylog_swthdev.print_logInfo = keylog_snprintf_logInfo; - - ret = criticallog_dev_register(&keylog_swthdev); - - if(ret){ - goto keylog_err; - } - spin_lock_init(&gKeylog_buf.keylog_lock); - gKeylog_buf.index_write = 0; - gKeylog_buf.index_read = 0; - keylog_thread_task = kthread_create(keylog_thread, (void *)&gKeylog_buf,"keylog"); - if(!keylog_thread_task){ - ret = -1; - goto keylog_err; - } - keylog_registered = 1; - wake_up_process(keylog_thread_task); - return 0; -keylog_err: - criticallog_dev_unregister(&keylog_swthdev); - keylog_registered = 0; - return ret; -} -arch_initcall(oplus_criticallog_init); - -MODULE_DESCRIPTION("OPLUS critical log"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("John.Xu "); -//#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/ diff --git a/drivers/soc/oplus/oplus_nandswap/Kconfig b/drivers/soc/oplus/oplus_nandswap/Kconfig deleted file mode 100644 index f79f0ef50f24..000000000000 --- a/drivers/soc/oplus/oplus_nandswap/Kconfig +++ /dev/null @@ -1,12 +0,0 @@ -config NANDSWAP - bool "nandswap feature" - default n - help - nandswap feature - -config NANDSWAP_DEBUG - bool "nandswap debug" - depends on F2FS_FS - default n - help - nandswap debug diff --git a/drivers/soc/oplus/oplus_nandswap/Makefile b/drivers/soc/oplus/oplus_nandswap/Makefile deleted file mode 100644 index 45ee0fa865c1..000000000000 --- a/drivers/soc/oplus/oplus_nandswap/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y += nandswap_core.o diff --git a/drivers/soc/oplus/oplus_nandswap/nandswap.h b/drivers/soc/oplus/oplus_nandswap/nandswap.h deleted file mode 100644 index 3d3aa3583465..000000000000 --- a/drivers/soc/oplus/oplus_nandswap/nandswap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Copyright (C) 2020 Oplus. All rights reserved. -*/ - -#ifndef _NAND_SWAP_H -#define _NAND_SWAP_H - -#include - -/* must check if this flag is repeat in */ -#define VM_NANDSWAP 0x8000000000UL /* swapin mark */ - -#define AID_APP 10000 /* first app user */ -#define AID_USER_OFFSET 100000 /* offset for uid ranges for each user */ - -enum { - NS_OUT_STANDBY, - NS_OUT_QUEUE, - NS_OUT_CACHE, - NS_OUT_DONE, - NS_IN_QUEUE, -}; - -enum { - NS_TYPE_FG, - NS_TYPE_NAND_ACT, - NS_TYPE_NAND_ALL, - NS_TYPE_DROP, - NS_TYPE_RATIO, - NS_TYPE_END -}; - -extern struct task_struct *nswapoutd; -static inline bool current_is_nswapoutd() -{ - return current == nswapoutd; -} -#endif /* _NAND_SWAP_H */ diff --git a/drivers/soc/oplus/oplus_nandswap/nandswap_core.c b/drivers/soc/oplus/oplus_nandswap/nandswap_core.c deleted file mode 100755 index c13e189a19c9..000000000000 --- a/drivers/soc/oplus/oplus_nandswap/nandswap_core.c +++ /dev/null @@ -1,1591 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* -* Copyright (C) 2020 Oplus. All rights reserved. -*/ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "nandswap.h" - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) -#include -#endif - -/* -#ifdef CONFIG_OPLUS_FEATURE_OF2FS -#include <../../../../fs/f2fs/f2fs.h> -#endif -*/ - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) -#define walk_page_range_hook(mm, start, end, walk, rp) \ - ({ \ - int _err = walk_page_range(mm, start, end, walk, rp); \ - _err; \ - }) -#else -#define walk_page_range_hook(mm, start, end, walk, rp) \ - ({ \ - int _err = walk_page_range(start, end, walk); \ - _err; \ - }) -#endif - - -#define RD_SIZE 128 -#define DEBUG_TIME_INFO 0 - -#define NS_QUOTA_DAY_64G 5242880 /* 5G kB */ -#define NS_QUOTA_DAY_128G 10485760 /* 10G kB */ -#define NS_WRITE_UPPER_64G 31457280 /* 30G kB */ -#define NS_WRITE_UPPER_128G 52428800 /* 50G kB */ -#define NS_DATA_THRESHOLD_64G 1179648 /* 4.5G blks */ -#define NS_DATA_THRESHOLD_128G 1835008 /* 7G blks */ -#define NS_DATA_64G 9175040 /* 35G blks */ -#define NS_DATA_128G 18350080 /* 70G blks */ - -#define NS_CHECK_INTERVAL 3600 /* 1 hour */ -#define NS_CHECK_COUNT 12 /* at least half day */ - -enum { - NS_NORMAL = 0, /* function is normal */ - NS_CAPACITY = (1 << 0), /* data capacity is not enough */ - NS_FRAGMENT = (1 << 1), /* frag_score is too high */ - NS_UNDISCARD = (1 << 2), /* undiscard_score is too high */ - NS_DEV_LIFE = (1 << 3), /* device life is not enough */ - NS_QUOTA = (1 << 4), /* nandswap write more than quota */ - NS_CHECK_ERROR = (1 << 5), -}; - -struct ns_reclaim_param { - struct vm_area_struct *vma; - /* Number of pages scanned */ - int nr_scanned; - /* max pages to reclaim */ - int nr_to_reclaim; - /* pages reclaimed */ - int nr_reclaimed; - int type; - long nr_act; - long nr_inact; -}; - -struct reclaim_data { - pid_t pid; - int prev_adj; -}; - -struct reclaim_info { - struct reclaim_data rd[RD_SIZE]; - int i_idx; - int o_idx; - int count; -}; - -struct ns_swap_ratio { - struct vm_area_struct *vma; - unsigned long nand; - unsigned long ram; - unsigned long type; -}; - -struct ns_stat_info { - bool life_protect; - bool swap_limit; - bool dev_life_end; - struct tm tm; - struct timer_list timer; - struct work_struct work; - long quota_today; - long write_lifelong; - long quota; - long write_upper; - long swap_total; /* total kB swap out yesterday */ - long swap_out; /* total kB swap out for now */ - long swap_in; /* total kB swap in for now */ - long swap_out_pg_act; - long swap_out_pg_inact; - unsigned int wake_cnt; /* wake per hour */ - unsigned int frag_score; - unsigned int undiscard_score; - unsigned int swap_out_cnt; - unsigned int swap_in_cnt; - unsigned long write_total; /* total kB write yesterday */ - unsigned long data_avail; - unsigned long data_threshold; - unsigned long fn_status; - pid_t pid; - unsigned long swap_ratio; - unsigned long nand_type; -}; - -struct ns_task_struct { - pid_t pid; - int state; - int type; - int retry; /* drop cache retry */ - spinlock_t lock; - unsigned long timeout; - struct kref kref; -}; - -static RADIX_TREE(ns_tree, GFP_ATOMIC); -static DEFINE_SPINLOCK(ns_tree_lock); -static struct ns_stat_info nsi; -static struct proc_dir_entry *ns_proc_root = NULL; -static struct proc_dir_entry *ns_proc_root_vnd = NULL; - -struct task_struct *nswapoutd = NULL; -struct task_struct *nswapdropd = NULL; -struct task_struct *nswapind = NULL; -static struct reclaim_info out_info = { {{0}}, 0, 0, 0 }; -static struct reclaim_info drop_info = { {{0}}, 0, 0, 0 }; -static struct reclaim_info in_info = { {{0}}, 0, 0, 0 }; -static DEFINE_SPINLOCK(rd_lock); - -bool nandswap_enable __read_mostly = false; -extern int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk); -extern unsigned long nswap_reclaim_page_list(struct list_head *page_list, - struct vm_area_struct *vma, bool scan); - -static void ns_free_task(struct kref *kref) -{ - struct ns_task_struct *ntask; - - ntask = container_of(kref, struct ns_task_struct, kref); - kfree(ntask); -} - -static inline void ns_get_task(struct ns_task_struct *ntask) -{ - kref_get(&ntask->kref); -} - -static inline void ns_put_task(struct ns_task_struct *ntask) -{ - kref_put(&ntask->kref, ns_free_task); -} - -static int process_notifier(struct notifier_block *self, - unsigned long cmd, void *v) -{ - struct task_struct *task = v; - struct ns_task_struct *ntask = NULL; - - if (!task) - return NOTIFY_OK; - - spin_lock(&ns_tree_lock); - ntask = radix_tree_lookup(&ns_tree, task->pid); - if (ntask) { - radix_tree_delete(&ns_tree, task->pid); - ns_put_task(ntask); - } - spin_unlock(&ns_tree_lock); - - return NOTIFY_OK; -} - -static struct notifier_block process_notifier_block = { - .notifier_call = process_notifier, -}; - -static inline struct ns_task_struct *ns_task_insert(pid_t pid, int type) -{ - struct ns_task_struct *ntask = NULL; - - ntask = kzalloc(sizeof(struct ns_task_struct), - GFP_KERNEL); - if (!ntask) - goto out; - - ntask->pid = pid; - ntask->state = NS_OUT_STANDBY; - ntask->lock = __SPIN_LOCK_UNLOCKED(lock); - ntask->type = type; - ntask->timeout = jiffies; - ntask->retry = 0; - kref_init(&ntask->kref); - - spin_lock(&ns_tree_lock); - if (radix_tree_insert(&ns_tree, pid, ntask)) { - ns_put_task(ntask); - ntask = NULL; - } - if (ntask) - ns_get_task(ntask); - spin_unlock(&ns_tree_lock); - -out: - return ntask; -} - -/* -#ifdef CONFIG_OPLUS_FEATURE_OF2FS -extern block_t of2fs_seg_freefrag(struct f2fs_sb_info *sbi, unsigned int segno, - block_t* blocks, unsigned int n); -static inline unsigned int f2fs_frag_score(struct super_block *sb) -{ - struct f2fs_sb_info *sbi = F2FS_SB(sb); - unsigned int i, total_segs = - le32_to_cpu(sbi->raw_super->segment_count_main); - block_t blocks[9], total_blocks = 0; - memset(blocks, 0, sizeof(blocks)); - for (i = 0; i < total_segs; i++) { - total_blocks += of2fs_seg_freefrag(sbi, i, - blocks, ARRAY_SIZE(blocks)); - cond_resched(); - } - return total_blocks ? (blocks[0] + blocks[1]) * 100ULL / total_blocks : 0; -} - -static inline unsigned int f2fs_undiscard_score(struct super_block *sb) -{ - struct f2fs_sb_info *sbi = F2FS_SB(sb); - unsigned int undiscard_blks = 0; - unsigned int score; - unsigned int free_blks = sbi->user_block_count - valid_user_blocks(sbi); - if (SM_I(sbi) && SM_I(sbi)->dcc_info) - undiscard_blks = SM_I(sbi)->dcc_info->undiscard_blks; - score = free_blks ? undiscard_blks * 100ULL / free_blks : 0; - return score; -} -#endif -*/ - -static void ns_life_protect_update(void) -{ - nsi.fn_status = (nsi.data_avail < nsi.data_threshold - ? NS_CAPACITY : NS_NORMAL) | - (nsi.frag_score > 80 ? NS_FRAGMENT : NS_NORMAL) | - (nsi.undiscard_score > 80 ? NS_UNDISCARD : NS_NORMAL) | - (nsi.dev_life_end ? NS_DEV_LIFE : NS_NORMAL) | - (nsi.swap_out - nsi.swap_total > nsi.quota_today - ? NS_QUOTA : NS_NORMAL); - - if (likely(nsi.swap_limit)) - nsi.life_protect = nsi.fn_status; - else - nsi.life_protect = false; - -/* - if (nsi.life_protect) - printk("NandSwap: life protect, data %llu frag %d " - "undiscard %d dev_life %d " - "quota_today %lld swap_inc %llu\n", - nsi.data_avail, nsi.frag_score, - nsi.undiscard_score, nsi.dev_life_end, - nsi.quota_today, nsi.swap_out - nsi.swap_total); -*/ - - return; -} - -//TODO: EXT4 score -static inline void ns_data_check(void) -{ - struct path kpath; - struct kstatfs st; - - if (kern_path("/data", LOOKUP_FOLLOW, &kpath)) - goto out; - if (vfs_statfs(&kpath, &st)) - goto out; - - if (unlikely(nsi.quota == 0)) - if (st.f_blocks > NS_DATA_64G) { - nsi.write_upper = NS_WRITE_UPPER_128G; - nsi.quota_today = nsi.quota = NS_QUOTA_DAY_128G; - nsi.data_threshold = NS_DATA_THRESHOLD_128G; - } - nsi.data_avail = st.f_bavail; - -/* -#ifdef CONFIG_OPLUS_FEATURE_OF2FS - if (kpath.dentry->d_sb->s_magic == F2FS_SUPER_MAGIC) { - nsi.frag_score = f2fs_frag_score(kpath.dentry->d_sb); - nsi.undiscard_score = f2fs_undiscard_score(kpath.dentry->d_sb); - } - else - goto out; -#endif -*/ - -out: - return; -} - -static void ns_life_ctrl_update(bool timer) -{ - unsigned long events[NR_VM_EVENT_ITEMS]; - long write_inc; - struct tm tm; - struct timespec64 ts; - - ns_data_check(); - all_vm_events(events); - if (unlikely(events[PGPGOUT]/2 < nsi.write_total)) - nsi.write_total = 0; - - if (!timer) - goto out; - - ktime_get_real_ts64(&ts); - time64_to_tm(ts.tv_sec - sys_tz.tz_minuteswest * 60, 0, &tm); - - if (tm.tm_mday != nsi.tm.tm_mday && tm.tm_hour > 2 - && nsi.wake_cnt >= NS_CHECK_COUNT) { - nsi.tm = tm; - write_inc = events[PGPGOUT]/2 - nsi.write_total; - nsi.write_total = events[PGPGOUT]/2; - nsi.swap_total = nsi.swap_out; - nsi.write_lifelong = nsi.write_lifelong - write_inc + - nsi.write_upper; - nsi.quota_today = nsi.write_lifelong > 0 - ? nsi.quota - : nsi.quota + nsi.write_lifelong; - nsi.wake_cnt = 0; - } -out: - ns_life_protect_update(); - return; -} - -static void ns_life_ctrl_work(struct work_struct *work) -{ - nsi.wake_cnt++; - ns_life_ctrl_update(true); -} - -static void ns_life_ctrl_timer(struct timer_list *t) -{ - schedule_work(&nsi.work); - nsi.timer.expires = jiffies + NS_CHECK_INTERVAL * HZ; - add_timer(&nsi.timer); -} - -static inline void ns_life_ctrl_init(void) -{ - unsigned long events[NR_VM_EVENT_ITEMS]; - struct timespec64 ts; - - memset(&nsi, 0, sizeof(nsi)); - nsi.life_protect = false; -#if defined(OPLUS_AGING_TEST) - nsi.swap_limit = false; -#else - nsi.swap_limit = true; -#endif - nsi.dev_life_end = false; - - all_vm_events(events); - nsi.write_total = events[PGPGOUT]/2; - - ktime_get_real_ts64(&ts); - time64_to_tm(ts.tv_sec - sys_tz.tz_minuteswest * 60, 0, &nsi.tm); - - INIT_WORK(&nsi.work, ns_life_ctrl_work); - timer_setup(&nsi.timer, ns_life_ctrl_timer, 0); - nsi.timer.expires = jiffies + NS_CHECK_INTERVAL * HZ; - add_timer(&nsi.timer); - - return; -} - -static void enqueue_reclaim_data(pid_t nr, struct reclaim_info *info) -{ - int idx; - struct task_struct *waken_task; - - spin_lock(&rd_lock); - if (info->count < RD_SIZE) { - info->count++; - idx = info->i_idx++ % RD_SIZE; - info->rd[idx].pid = nr; - } - spin_unlock(&rd_lock); - WARN_ON(info->count > RD_SIZE || info->count < 0); - - waken_task = (info == &out_info? nswapoutd : nswapind); - if (!waken_task) - return; - if (waken_task->state == TASK_INTERRUPTIBLE) - wake_up_process(waken_task); - if (nswapdropd->state == TASK_INTERRUPTIBLE) - wake_up_process(nswapdropd); -} - -static bool dequeue_reclaim_data(struct reclaim_data *data, struct reclaim_info *info) -{ - int idx; - bool has_data = false; - - spin_lock(&rd_lock); - if (info->count > 0) { - has_data = true; - info->count--; - idx = info->o_idx++ % RD_SIZE; - *data = info->rd[idx]; - } - spin_unlock(&rd_lock); - WARN_ON(info->count > RD_SIZE || info->count < 0); - - return has_data; -} - -static void ns_state_check(int cur_adj, struct task_struct* task, int type) -{ - int uid = task_uid(task).val; - struct ns_task_struct *ntask = NULL; - - if (!nandswap_enable) - return; - - if (uid % AID_USER_OFFSET < AID_APP) - return; - - spin_lock(&ns_tree_lock); - ntask = radix_tree_lookup(&ns_tree, task->pid); - if (ntask) - ns_get_task(ntask); - spin_unlock(&ns_tree_lock); - - if (cur_adj > 0) { - if (!ntask) - ntask = ns_task_insert(task->pid, type); - if (!ntask) - return; - - if (!time_after_eq(jiffies, ntask->timeout)) { - ns_put_task(ntask); - return; - } - - spin_lock(&ntask->lock); - /* reclaim should not kick-in within 2 secs */ - ntask->timeout = jiffies + 2*HZ; - - if (ntask->state == NS_OUT_STANDBY) { - ntask->state = NS_OUT_QUEUE; - enqueue_reclaim_data(ntask->pid, &out_info); - } - spin_unlock(&ntask->lock); - } else if (cur_adj == 0 && ntask) { - spin_lock(&ntask->lock); - /* swapin kicked in, don't reclaim within 2 secs */ - ntask->timeout = jiffies + 2*HZ; - - if (ntask->state == NS_OUT_QUEUE) { - ntask->state = NS_OUT_STANDBY; - } else if ((ntask->state == NS_OUT_CACHE) || - (ntask->state == NS_OUT_DONE)) { - ntask->state = NS_IN_QUEUE; - enqueue_reclaim_data(task->pid, &in_info); - } - spin_unlock(&ntask->lock); - } - - if (ntask) - ns_put_task(ntask); - - return; -} - -static ssize_t swapin_anon(struct task_struct *task) -{ - struct mm_struct *mm; - struct vm_area_struct *vma; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - struct mm_walk walk = {}; -#else - const struct mm_walk_ops walk = { - .pmd_entry = swapin_walk_pmd_entry, - }; -#endif - struct ns_task_struct *ntask = NULL; - int task_anon = 0, task_swap = 0, err = 0; - -retry: - /* TODO: do we need to use p = find_lock_task_mm(task); in case main thread got killed */ - mm = get_task_mm(task); - if (!mm) - goto out; - - task_anon = get_mm_counter(mm, MM_ANONPAGES); - task_swap = get_mm_counter(mm, MM_SWAPENTS); - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - walk.mm = mm; - walk.pmd_entry = swapin_walk_pmd_entry; -#endif - - - down_read(&mm->mmap_sem); - - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (vma->vm_flags & VM_NANDSWAP) - continue; - - if (is_vm_hugetlb_page(vma)) - continue; - - if (vma->vm_file) - continue; - - /* if mlocked, don't reclaim it */ - if (vma->vm_flags & VM_LOCKED) - continue; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - walk.private = vma; -#endif - err = walk_page_range_hook(mm, vma->vm_start, vma->vm_end, - &walk, vma); - if (err == -1) - break; - vma->vm_flags |= VM_NANDSWAP; - } - - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); - mmput(mm); - if (err) { - err = 0; - //schedule(); - goto retry; - } -out: - /* TODO */ - lru_add_drain(); /* Push any new pages onto the LRU now */ - -#ifdef CONFIG_NANDSWAP_DEBUG - printk("NandSwap: in %s (pid %d) (size %d-%d)\n", - task->comm, task->pid, task_anon, task_swap); -#endif - - spin_lock(&ns_tree_lock); - ntask = radix_tree_lookup(&ns_tree, task->pid); - if (ntask) - ns_get_task(ntask); - spin_unlock(&ns_tree_lock); - if (!ntask) - return 0; - - spin_lock(&ntask->lock); - WARN_ON(ntask->state != NS_IN_QUEUE); - ntask->state = NS_OUT_STANDBY; - spin_unlock(&ntask->lock); - ns_put_task(ntask); - - nsi.swap_in_cnt++; - - return 0; -} - -//TODO: blk_plug don't seem to work -static int swapind_fn(void *p) -{ - struct reclaim_data data; - struct task_struct *task; - - set_freezable(); - for ( ; ; ) { - while (!pm_freezing && dequeue_reclaim_data(&data, &in_info)) { - rcu_read_lock(); - task = find_task_by_vpid(data.pid); - - /* KTHREAD is almost impossible to hit this */ - //if (task->flags & PF_KTHREAD) { - // rcu_read_unlock(); - // continue; - //} - - if (!task) { - rcu_read_unlock(); - continue; - } - - get_task_struct(task); - rcu_read_unlock(); - swapin_anon(task); - put_task_struct(task); - } - - set_current_state(TASK_INTERRUPTIBLE); - freezable_schedule(); - - if (kthread_should_stop()) - break; - } - - return 0; -} - -static int ns_reclaim_pte(pmd_t *pmd, unsigned long addr, - unsigned long end, struct mm_walk *walk) -{ - struct ns_reclaim_param *rp = walk->private; - struct vm_area_struct *vma = rp->vma; - pte_t *pte, ptent; - spinlock_t *ptl; - struct page *page; - LIST_HEAD(page_list); - int isolated; - int reclaimed = 0; - int reclaim_type = rp->type; - - split_huge_pmd(vma, addr, pmd); - if (pmd_trans_unstable(pmd) || !rp->nr_to_reclaim) - return 0; -cont: - isolated = 0; - pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); - for (; addr != end; pte++, addr += PAGE_SIZE) { - ptent = *pte; - if (!pte_present(ptent)) - continue; - - page = vm_normal_page(vma, addr, ptent); - if (!page) - continue; - - /* About 11% of pages have more than 1 map_count - * only take care mapcount == 1 is good enough */ - /* - if (page_mapcount(page) != 1) - continue; - */ - if (PageActive(page)) { - rp->nr_act++; - if (reclaim_type == NS_TYPE_NAND_ACT) - continue; - } else - rp->nr_inact++; - - if (isolate_lru_page(page)) - continue; - - list_add(&page->lru, &page_list); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); -#endif - isolated++; - rp->nr_scanned++; - - if ((isolated >= SWAP_CLUSTER_MAX) || !rp->nr_to_reclaim) - break; - } - pte_unmap_unlock(pte - 1, ptl); - - if (reclaim_type == NS_TYPE_NAND_ACT || reclaim_type == NS_TYPE_NAND_ALL) - reclaimed = nswap_reclaim_page_list(&page_list, vma, true); - - rp->nr_reclaimed += reclaimed; - rp->nr_to_reclaim -= reclaimed; - if (rp->nr_to_reclaim < 0) - rp->nr_to_reclaim = 0; - - if (rp->nr_to_reclaim && (addr != end)) - goto cont; - - /* TODO: is there other reschedule point we can add */ - cond_resched(); - - return 0; -} - -/* get_task_struct before using this function */ -static ssize_t reclaim_anon(struct task_struct *task) -{ - struct mm_struct *mm; - struct vm_area_struct *vma; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - struct mm_walk reclaim_walk = {}; -#else - const struct mm_walk_ops reclaim_walk = { - .pmd_entry = ns_reclaim_pte, - }; -#endif - - struct ns_reclaim_param rp; - struct ns_task_struct *ntask = NULL; - -#ifdef CONFIG_NANDSWAP_DEBUG - int task_anon = 0, task_swap = 0; - int a_task_anon = 0, a_task_swap = 0; -#endif - - spin_lock(&ns_tree_lock); - ntask = radix_tree_lookup(&ns_tree, task->pid); - if (ntask) - ns_get_task(ntask); - spin_unlock(&ns_tree_lock); - if (!ntask) - return 0; - - spin_lock(&ntask->lock); - if (ntask->state != NS_OUT_QUEUE) { -#ifdef CONFIG_NANDSWAP_DEBUG - printk("NandSwap: exit reclaim\n"); -#endif - spin_unlock(&ntask->lock); - goto out; - } - ntask->state = NS_OUT_CACHE; - spin_unlock(&ntask->lock); - - /* TODO: do we need to use p = find_lock_task_mm(task); in case main thread got killed */ - mm = get_task_mm(task); - if (!mm) - goto out; - -#ifdef CONFIG_NANDSWAP_DEBUG - task_anon = get_mm_counter(mm, MM_ANONPAGES); - task_swap = get_mm_counter(mm, MM_SWAPENTS); -#endif - - rp.nr_act = 0; - rp.nr_inact = 0; - rp.nr_to_reclaim = INT_MAX; - rp.nr_reclaimed = 0; - rp.nr_scanned = 0; - rp.type = ntask->type; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - reclaim_walk.mm = mm; - reclaim_walk.private = &rp; - reclaim_walk.pmd_entry = ns_reclaim_pte; -#endif - - down_read(&mm->mmap_sem); - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (is_vm_hugetlb_page(vma)) - continue; - - if (vma->vm_file) - continue; - - /* if mlocked, don't reclaim it */ - if (vma->vm_flags & VM_LOCKED) - continue; - - if (ntask->state != NS_OUT_CACHE) - break; - - rp.vma = vma; - walk_page_range_hook(mm, vma->vm_start, vma->vm_end, - &reclaim_walk, &rp); - vma->vm_flags &= ~VM_NANDSWAP; - if (!rp.nr_to_reclaim) - break; - } - - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); -#ifdef CONFIG_NANDSWAP_DEBUG - a_task_anon = get_mm_counter(mm, MM_ANONPAGES); - a_task_swap = get_mm_counter(mm, MM_SWAPENTS); -#endif - mmput(mm); -#ifdef CONFIG_NANDSWAP_DEBUG - /* it's possible that rp data isn't initialized because mm don't exist */ - printk("NandSwap: out %s (pid %d) (size %d-%d to %d-%d) " - "scan %d cache %d active %d inactive %d\n" - , task->comm, task->pid, task_anon, task_swap - , a_task_anon, a_task_swap - , rp.nr_scanned, rp.nr_reclaimed, rp.nr_act, rp.nr_inact); -#endif - nsi.swap_out_cnt++; - nsi.swap_out += rp.nr_reclaimed * 4; - nsi.swap_out_pg_act += rp.nr_act; - nsi.swap_out_pg_inact += rp.nr_inact; - ns_life_protect_update(); -out: - ns_put_task(ntask); - /* TODO : return proper value */ - return 0; -} - -//TODO: should we mark swapoutd/swapind freezable? -static int swapoutd_fn(void *p) -{ - struct reclaim_data data; - struct task_struct *task; - - set_freezable(); - for ( ; ; ) { - while (!pm_freezing && dequeue_reclaim_data(&data, &out_info)) { - rcu_read_lock(); - task = find_task_by_vpid(data.pid); - - /* KTHREAD is almost impossible to hit this */ - //if (task->flags & PF_KTHREAD) { - // rcu_read_unlock(); - // continue; - //} - - if (!task) { - rcu_read_unlock(); - continue; - } - - get_task_struct(task); - rcu_read_unlock(); - - do { - msleep(30); - } while (nswapind && (nswapind->state == TASK_RUNNING)); - - reclaim_anon(task); - enqueue_reclaim_data(task->pid, &drop_info); - put_task_struct(task); - } - - ns_life_ctrl_update(false); - set_current_state(TASK_INTERRUPTIBLE); - freezable_schedule(); - - if (kthread_should_stop()) - break; - } - - return 0; -} - -static int drop_swapcache_pte(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk) -{ - struct ns_reclaim_param *rp = walk->private; - struct vm_area_struct *vma = rp->vma; - pte_t *orig_pte; - unsigned long index; - LIST_HEAD(page_list); - int reclaimed = 0; - - if (pmd_none_or_trans_huge_or_clear_bad(pmd)) - return 0; - - for (index = start; index != end; index += PAGE_SIZE) { - pte_t pte; - spinlock_t *ptl; - swp_entry_t entry; - struct address_space *swapper_space; - struct page *page = NULL; - - orig_pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl); - pte = *(orig_pte + ((index - start) / PAGE_SIZE)); - pte_unmap_unlock(orig_pte, ptl); - - if (pte_present(pte) || pte_none(pte)) - continue; - - entry = pte_to_swp_entry(pte); - if (unlikely(non_swap_entry(entry))) - continue; - swapper_space = swap_address_space(entry); - page = find_get_page(swapper_space, swp_offset(entry)); - if (!page) - continue; - put_page(page); - - if (page_count(page) > 1) - continue; - if (isolate_lru_page(page)) - continue; - - list_add(&page->lru, &page_list); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); -#endif - rp->nr_scanned++; - } - - reclaimed = nswap_reclaim_page_list(&page_list, vma, false); - rp->nr_reclaimed += reclaimed; - rp->nr_to_reclaim -= reclaimed; - - return 0; -} - -static bool drop_swapcache_task(struct task_struct *task) -{ - struct mm_struct *mm; - struct vm_area_struct *vma; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - struct mm_walk reclaim_walk = {}; -#else - const struct mm_walk_ops reclaim_walk = { - .pmd_entry = drop_swapcache_pte, - }; -#endif - struct ns_reclaim_param rp; - struct ns_task_struct *ntask = NULL; - bool retry = false; - -#ifdef CONFIG_NANDSWAP_DEBUG - int task_anon = 0, task_swap = 0; - int a_task_anon = 0, a_task_swap = 0; -#endif - - spin_lock(&ns_tree_lock); - ntask = radix_tree_lookup(&ns_tree, task->pid); - if (ntask) - ns_get_task(ntask); - spin_unlock(&ns_tree_lock); - if (!ntask) - return retry; - - spin_lock(&ntask->lock); - if (ntask->state != NS_OUT_CACHE) { -#ifdef CONFIG_NANDSWAP_DEBUG - printk("NandSwap: exit dropcache\n"); -#endif - spin_unlock(&ntask->lock); - goto out; - } - ntask->state = NS_OUT_DONE; - spin_unlock(&ntask->lock); - - mm = get_task_mm(task); - if (!mm) - goto out; - -#ifdef CONFIG_NANDSWAP_DEBUG - task_anon = get_mm_counter(mm, MM_ANONPAGES); - task_swap = get_mm_counter(mm, MM_SWAPENTS); -#endif - - rp.nr_to_reclaim = INT_MAX; - rp.nr_reclaimed = 0; - rp.nr_scanned = 0; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - reclaim_walk.mm = mm; - reclaim_walk.private = &rp; - reclaim_walk.pmd_entry = drop_swapcache_pte; -#endif - - down_read(&mm->mmap_sem); - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (is_vm_hugetlb_page(vma)) - continue; - - if (vma->vm_file) - continue; - - if (vma->vm_flags & VM_LOCKED) - continue; - - if (ntask->state != NS_OUT_DONE) - break; - - rp.vma = vma; - walk_page_range_hook(mm, vma->vm_start, vma->vm_end, - &reclaim_walk, &rp); - if (!rp.nr_to_reclaim) - break; - } - - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); -#ifdef CONFIG_NANDSWAP_DEBUG - a_task_anon = get_mm_counter(mm, MM_ANONPAGES); - a_task_swap = get_mm_counter(mm, MM_SWAPENTS); -#endif - mmput(mm); -#ifdef CONFIG_NANDSWAP_DEBUG - printk("NandSwap: cache %s (pid %d) (size %d-%d to %d-%d) scan %d reclaim %d\n" - , task->comm, task->pid, task_anon, task_swap - , a_task_anon, a_task_swap, rp.nr_scanned, rp.nr_reclaimed); -#endif - if (rp.nr_reclaimed < rp.nr_scanned * 9 /10 && ntask->retry < 3) { - spin_lock(&ntask->lock); - ntask->state = NS_OUT_CACHE; - spin_unlock(&ntask->lock); - ntask->retry++; - retry = true; - } else { - ntask->retry = 0; - retry = false; - } -out: - ns_put_task(ntask); - - return retry; -} - -static int swapdropd_fn(void *p) -{ - struct reclaim_data data; - struct task_struct *task; - bool retry; - - set_freezable(); - for ( ; ; ) { - while (!pm_freezing && dequeue_reclaim_data(&data, &drop_info)) { - rcu_read_lock(); - task = find_task_by_vpid(data.pid); - - /* KTHREAD is almost impossible to hit this */ - //if (task->flags & PF_KTHREAD) { - // rcu_read_unlock(); - // continue; - //} - - if (!task) { - rcu_read_unlock(); - continue; - } - - get_task_struct(task); - rcu_read_unlock(); - - do { - msleep(30); - } while (nswapind && (nswapind->state == TASK_RUNNING)); - - retry = drop_swapcache_task(task); - put_task_struct(task); - - if (retry) { - enqueue_reclaim_data(task->pid, &drop_info); - msleep_interruptible(1000); - } - } - - set_current_state(TASK_INTERRUPTIBLE); - freezable_schedule(); - - if (kthread_should_stop()) - break; - } - - return 0; -} - -static inline unsigned long nandswap_type(void) -{ - unsigned long type; - for (type = 0; type < MAX_SWAPFILES; type++) - if ((swap_info[type]->flags & SWP_NANDSWAP) && - (swap_info[type]->flags & SWP_USED)) - break; - - return type; -} - -static int swap_ratio_pte(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk) -{ - pte_t *orig_pte; - unsigned long index; - struct ns_swap_ratio *nsr = walk->private; - struct vm_area_struct *vma = nsr->vma; - - if (pmd_none_or_trans_huge_or_clear_bad(pmd)) - return 0; - - for (index = start; index != end; index += PAGE_SIZE) { - pte_t pte; - spinlock_t *ptl; - unsigned long type; - - orig_pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl); - pte = *(orig_pte + ((index - start) / PAGE_SIZE)); - pte_unmap_unlock(orig_pte, ptl); - - if (pte_present(pte) || pte_none(pte)) - continue; - - type = swp_type(pte_to_swp_entry(pte)); - if (type == nsr->type) - nsr->nand++; - else - nsr->ram++; - } - - return 0; -} - -/* get_task_struct before using this function */ -static unsigned long swap_ratio_task(struct task_struct *task, unsigned long type) -{ - struct mm_struct *mm; - struct vm_area_struct *vma; - struct ns_swap_ratio nsr = {}; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - struct mm_walk walk = {}; -#else - const struct mm_walk_ops walk = { - .pmd_entry = swap_ratio_pte, - }; -#endif - - mm = get_task_mm(task); - if (!mm) - goto out; - - nsr.nand = 0; - nsr.ram = 0; - nsr.type = type; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - walk.mm = mm; - walk.pmd_entry = swap_ratio_pte; - walk.private = &nsr; -#endif - - down_read(&mm->mmap_sem); - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (is_vm_hugetlb_page(vma)) - continue; - - if (vma->vm_file) - continue; - - /* if mlocked, don't reclaim it */ - if (vma->vm_flags & VM_LOCKED) - continue; - - nsr.vma = vma; - walk_page_range_hook(mm, vma->vm_start, vma->vm_end, - &walk, &nsr); - } - - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); - mmput(mm); -out: - return nsr.nand + nsr.ram ? nsr.nand * 100 / (nsr.nand + nsr.ram) : 0; -} - -static int swap_ctl_seq_show(struct seq_file *seq, void *p) -{ - seq_printf(seq, "%d %llu\n", nsi.pid, nsi.swap_ratio); - return 0; -} - -static int swap_ctl_open(struct inode *inode, struct file *file) -{ - return single_open(file, swap_ctl_seq_show, NULL); -} - -static ssize_t swap_ctl_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char kbuf[16]; - char *act_str; - char *end; - long value; - int type; - pid_t task_pid; - struct task_struct* task; - unsigned long nand_type; - - if (cnt > 16) - return -EINVAL; - - memset(kbuf, 0, 16); - if (copy_from_user(&kbuf, ubuf, cnt)) - return -EFAULT; - kbuf[15] = '\0'; - - act_str = strstrip(kbuf); - if (*act_str <= '0' || *act_str > '9') { - pr_err("NandSwap: write [%s] pid format is invalid.\n", kbuf); - return -EINVAL; - } - - value = simple_strtol(act_str, &end, 10); - if (value < 0 || value > INT_MAX) { - pr_err("NandSwap: write [%s] is invalid.\n", kbuf); - return -EINVAL; - } - - task_pid = (pid_t)value; - - if (end == (act_str + strlen(act_str))) { - pr_err("NandSwap: write [%s] do not set reclaim type.\n", kbuf); - return -EINVAL; - } - - if (*end != ' ' && *end != ' ') { - pr_err("NandSwap: write [%s] format is wrong.\n", kbuf); - return -EINVAL; - } - - if (kstrtoint(strstrip(end), 0, &type)) - return -EINVAL; - - if (type >= NS_TYPE_END || type < 0) - return -EINVAL; - - rcu_read_lock(); - task = find_task_by_vpid(task_pid); - if (!task) { - rcu_read_unlock(); - pr_err("NandSwap: can not find task of pid:%d\n", task_pid); - return -ESRCH; - } - - if (task != task->group_leader) - task = task->group_leader; - get_task_struct(task); - rcu_read_unlock(); - - if (type == NS_TYPE_FG) - ns_state_check(0, task, type); - else if ((type == NS_TYPE_NAND_ACT || type == NS_TYPE_NAND_ALL) - && nandswap_enable) - ns_state_check(task->signal->oom_score_adj, task, type); - else if (type == NS_TYPE_DROP) { - nand_type = nandswap_type(); - if (nand_type < MAX_SWAPFILES) - drop_swapcache_task(task); - } else if (type == NS_TYPE_RATIO) { - nand_type = nandswap_type(); - if (nand_type < MAX_SWAPFILES) { - nsi.pid = task_pid; - nsi.swap_ratio = swap_ratio_task(task, nand_type); - } - } - - put_task_struct(task); - - return cnt; -} - -static struct file_operations swap_ctl_fops = { - .open = swap_ctl_open, - .read = seq_read, - .write = swap_ctl_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static int fn_enable_seq_show(struct seq_file *seq, void *p) -{ - seq_printf(seq, "%d\n", nandswap_enable); - return 0; -} - -static int fn_enable_open(struct inode *inode, struct file *file) -{ - return single_open(file, fn_enable_seq_show, NULL); -} - -static ssize_t fn_enable_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char kbuf[8] = { 0 }; - ssize_t buf_size; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(kbuf)-1)); - if (copy_from_user(kbuf, ubuf, buf_size)) - return -EFAULT; - - if (kbuf[0] == '0') - nandswap_enable = false; - else - nandswap_enable = true; - - ns_data_check(); - ns_life_protect_update(); - - return cnt; -} - -static const struct file_operations fn_enable_fops = { - .open = fn_enable_open, - .read = seq_read, - .write = fn_enable_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t swap_limit_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char kbuf[8] = { 0 }; - ssize_t buf_size; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(kbuf)-1)); - if (copy_from_user(kbuf, ubuf, buf_size)) - return -EFAULT; - - if (kbuf[0] == '0') - nsi.swap_limit = false; - else - nsi.swap_limit = true; - - return cnt; -} - -static struct file_operations swap_limit_fops = { - .write = swap_limit_write, -}; - -static ssize_t dev_life_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char kbuf[8] = { 0 }; - ssize_t buf_size; - - if (!cnt) - return 0; - - buf_size = min(cnt, (size_t)(sizeof(kbuf)-1)); - if (copy_from_user(kbuf, ubuf, buf_size)) - return -EFAULT; - - if (kbuf[0] == '0') - nsi.dev_life_end = false; - else - nsi.dev_life_end = true; - - ns_life_protect_update(); - - return cnt; -} - -static struct file_operations dev_life_fops = { - .write = dev_life_write, -}; - -static int life_protect_seq_show(struct seq_file *seq, void *offset) -{ - seq_printf(seq, "%d\n", nsi.life_protect); - return 0; -} - -static int life_protect_open(struct inode *inode, struct file *file) -{ - return single_open(file, life_protect_seq_show, NULL); -} - -static struct file_operations life_protect_fops = { - .open = life_protect_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int stat_info_seq_show(struct seq_file *seq, void *offset) -{ - unsigned long events[NR_VM_EVENT_ITEMS]; - all_vm_events(events); - - seq_printf(seq, "ns_fn_enable: %d\n" - "ns_fn_status: %lld\n" - "ns_life_protect: %d\n" - "ns_swap_limit: %d\n" - "ns_write_lifelong: %lld\n" - "ns_quota_today: %lld\n" - "ns_swap_out: %u\n" - "ns_swap_in: %u\n" - "ns_pg_out: %lld\n" - "ns_pg_in: %lld\n" - "ns_pg_out_act: %lld\n" - "ns_pg_out_inact: %lld\n" - "pswpout: %llu\n" - "pswpin: %llu\n" - "ns_dev_life_end: %u\n", - nandswap_enable, - nsi.fn_status, - nsi.life_protect, - nsi.swap_limit, - nsi.write_lifelong, - nsi.quota_today, - nsi.swap_out_cnt, - nsi.swap_in_cnt, - nsi.swap_out, - nsi.swap_in, - nsi.swap_out_pg_act, - nsi.swap_out_pg_inact, - events[PSWPOUT], - events[PSWPIN], - nsi.dev_life_end); - return 0; -} - -static int stat_info_open(struct inode *inode, struct file *file) -{ - return single_open(file, stat_info_seq_show, NULL); -} - -static struct file_operations stat_info_fops = { - .open = stat_info_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static inline void ns_create_proc(struct proc_dir_entry *parent) { - if (parent) { - proc_create("swap_ctl", S_IRUGO | S_IWUGO, parent, - &swap_ctl_fops); - proc_create("fn_enable", S_IRUGO | S_IWUGO, parent, - &fn_enable_fops); - proc_create("swap_limit", S_IWUGO, parent, - &swap_limit_fops); - proc_create("dev_life", S_IWUGO, parent, - &dev_life_fops); - proc_create("life_protect", S_IRUGO, parent, - &life_protect_fops); - proc_create("stat_info", S_IRUGO, parent, - &stat_info_fops); - } -} - -static inline void ns_create_proc_dir(void) -{ - ns_proc_root = proc_mkdir("nandswap", NULL); - ns_create_proc(ns_proc_root); - ns_proc_root_vnd = proc_mkdir("nandswap_vnd", NULL); - ns_create_proc(ns_proc_root_vnd); -} - -static inline void ns_remove_proc(struct proc_dir_entry *parent) { - if (parent) { - remove_proc_entry("stat_info", parent); - remove_proc_entry("life_protect", parent); - remove_proc_entry("dev_life", parent); - remove_proc_entry("swap_limit", parent); - remove_proc_entry("fn_enable", parent); - remove_proc_entry("swap_ctl", parent); - if (parent == ns_proc_root) - remove_proc_entry("nandswap", NULL); - else - remove_proc_entry("nandswap_vnd", NULL); - parent = NULL; - } -} - -static inline void ns_remove_proc_dir(void) -{ - ns_remove_proc(ns_proc_root); - ns_remove_proc(ns_proc_root_vnd); -} - -static void nandswap_stop(void) -{ - if (nswapoutd) { - kthread_stop(nswapoutd); - nswapoutd = NULL; - } - if (nswapdropd) { - kthread_stop(nswapdropd); - nswapdropd = NULL; - } - if (nswapind) { - kthread_stop(nswapind); - nswapind = NULL; - } -} - -static int __init nandswap_init(void) -{ - //TODO: priority tuning for nswapoutd/nswapind - //struct sched_param param = { .sched_priority = MAX_USER_RT_PRIO -1 }; - //struct sched_param param = { .sched_priority = 1 }; - - nswapoutd = kthread_run(swapoutd_fn, 0, "nswapoutd"); - if (IS_ERR(nswapoutd)) { - pr_err("NandSwap: [%s] Failed to start nswapoutd\n", __func__); - nswapoutd = NULL; - } - - nswapdropd = kthread_run(swapdropd_fn, 0, "nswapdropd"); - if (IS_ERR(nswapdropd)) { - pr_err("NandSwap: [%s] Failed to start nswapdropd\n", __func__); - nswapdropd = NULL; - } - - nswapind = kthread_run(swapind_fn, 0, "nswapind"); - if (IS_ERR(nswapind)) { - pr_err("NandSwap: [%s] Failed to start nswapind\n", __func__); - nswapind = NULL; - } else { - //if (sched_setscheduler_nocheck(nswapind, SCHED_FIFO, ¶m)) { - // pr_warn("%s: failed to set SCHED_FIFO\n", __func__); - //} - //set_task_ioprio(nswapind, IOPRIO_CLASS_RT); - } - - profile_event_register(PROFILE_TASK_EXIT, &process_notifier_block); - ns_life_ctrl_init(); - ns_create_proc_dir(); - - return 0; -} - -static void __exit nandswap_exit(void) -{ - ns_remove_proc_dir(); - profile_event_unregister(PROFILE_TASK_EXIT, &process_notifier_block); - nandswap_stop(); -} - -module_init(nandswap_init); -module_exit(nandswap_exit); diff --git a/drivers/soc/oplus/system/Kconfig b/drivers/soc/oplus/system/Kconfig index 5fee8b862987..07a486e68588 100755 --- a/drivers/soc/oplus/system/Kconfig +++ b/drivers/soc/oplus/system/Kconfig @@ -36,66 +36,16 @@ config OPLUS_FEATURE_DETAILHEAD help define this config to add cpu number and current id and current comm to kmsg -source "drivers/soc/oplus/system/feedback/Kconfig" -source "drivers/soc/oplus/system/uboot_log/Kconfig" -source "drivers/soc/oplus/system/shutdown_detect/Kconfig" -source "drivers/soc/oplus/system/slabtrace/Kconfig" source "drivers/soc/oplus/system/oplus_project/Kconfig" -source "drivers/soc/oplus/system/qcom_minidump/Kconfig" -source "drivers/soc/oplus/system/hung_task_enhance/Kconfig" -source "drivers/soc/oplus/system/oplus_phoenix/Kconfig" -source "drivers/soc/oplus/system/oplus_pmic_monitor/Kconfig" source "drivers/soc/oplus/system/oplus_pmic_monitor_mtk/Kconfig" -source "drivers/soc/oplus/system/oplus_saupwk/Kconfig" source "drivers/soc/oplus/system/project_info/Kconfig" source "drivers/soc/oplus/system/cmdline_parser/Kconfig" -source "drivers/soc/oplus/system/dump_device_info/Kconfig" -source "drivers/soc/oplus/system/mdmrst/Kconfig" -source "drivers/soc/oplus/system/full_aging/Kconfig" -#ifdef OPLUS_FEATURE_QCOM_PMICWD -source "drivers/soc/oplus/system/qcom_pmicwd/Kconfig" -#endif /* OPLUS_FEATURE_QCOM_PMICWD */ -#ifdef OPLUS_FEATURE_MM_OSVELTE -source "drivers/soc/oplus/system/mm_osvelte/Kconfig" -#endif /* OPLUS_FEATURE_MM_OSVELTE */ - -#ifdef OPLUS_FEATURE_DUMP_REASON -#terry.zhong@optimization.Stability, 2020/11/30, Add for dump reason -source "drivers/soc/oplus/system/dump_reason/Kconfig" -#endif /* OPLUS_FEATURE_DUMP_REASON */ - -#ifdef OPLUS_FEATURE_MM_FEEDBACK -source "drivers/soc/oplus/system/oplus_mm_fb/Kconfig" -#endif /* OPLUS_FEATURE_MM_FEEDBACK */ - -#ifdef OPLUS_FEATURE_QCOM_WATCHDOG -source "drivers/soc/oplus/system/qcom_watchdog/Kconfig" -#endif /* OPLUS_FEATURE_QCOM_WATCHDOG */ - -#ifdef OPLUS_FEATURE_ACM -source "drivers/soc/oplus/system/acm/Kconfig" -#endif /* OPLUS_FEATURE_ACM */ -#ifdef OPLUS_FEATURE_THEIA -source "drivers/soc/oplus/system/theia/Kconfig" -#endif /* OPLUS_FEATURE_THEIA */ #ifdef OPLUS_FEATURE_MISC #terry.zhong@OPTI.Kernel.Stability, 2020/09/7, enable oplus misc feature source "drivers/soc/oplus/system/misc/Kconfig" #endif /* OPLUS_FEATURE_MISC */ -#ifdef OPLUS_FEATURE_FORCE_SHUTDOWN -source "drivers/soc/oplus/system/mtk_shutdown_reboot/Kconfig" -#endif - -#ifdef OPLUS_FEATURE_RT_OPT_INFO -source "drivers/soc/oplus/system/rt_info/Kconfig" -#endif -#ifdef OPLUS_FEATURE_HANS -#Zhou.Kun@Android.Power, 2021/06/30, enable oplus app freezer feature -source "drivers/soc/oplus/system/oplus_hans/Kconfig" -#endif /* OPLUS_FEATURE_HANS */ - #ifdef OPLUS_FEATURE_LOG_CORE source "drivers/soc/oplus/system/olc/Kconfig" #endif /* OPLUS_FEATURE_LOG_CORE */ diff --git a/drivers/soc/oplus/system/Makefile b/drivers/soc/oplus/system/Makefile index 6c7921998a7c..844aeb2f81c0 100755 --- a/drivers/soc/oplus/system/Makefile +++ b/drivers/soc/oplus/system/Makefile @@ -2,66 +2,19 @@ # Copyright (C) 2018-2020 Oplus. All rights reserved. obj-y += platform.o -obj-$(CONFIG_OPLUS_FEATURE_FEEDBACK) += feedback/ -obj-$(CONFIG_OPLUS_FEATURE_UBOOT_LOG) += uboot_log/ -obj-$(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) += shutdown_detect/ -obj-$(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) += slabtrace/ obj-$(CONFIG_OPLUS_FEATURE_OPROJECT) += oplus_project/ -obj-$(CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE) += qcom_minidump/ -obj-$(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) += hung_task_enhance/ -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += oplus_phoenix/ -obj-$(CONFIG_OPLUS_FEATURE_PMIC_MONITOR) += oplus_pmic_monitor/ obj-$(CONFIG_OPLUS_FEATURE_PMIC_MONITOR_MTK) += oplus_pmic_monitor_mtk/ -obj-$(CONFIG_OPLUS_FEATURE_SAUPWK) += oplus_saupwk/ -obj-$(CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO) += dump_device_info/ -obj-$(CONFIG_OPLUS_FEATURE_RECORD_MDMRST) += mdmrst/ obj-$(CONFIG_OPLUS_FEATURE_CMDLINE) += cmdline_parser/ -#ifdef OPLUS_FEATURE_DUMP_REASON -#terry.zhong@optimization.Stability, 2020/11/30, Add for dump reason -obj-$(CONFIG_OPLUS_FEATURE_DUMP_REASON) += dump_reason/ -#endif /* OPLUS_FEATURE_DUMP_REASON */ ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM obj-$(CONFIG_OPLUS_FEATURE_PROJECTINFO) += project_info/ endif -#ifdef OPLUS_FEATURE_QCOM_PMICWD -obj-$(CONFIG_OPLUS_FEATURE_QCOM_PMICWD) += qcom_pmicwd/ -#endif /* OPLUS_FEATURE_QCOM_PMICWD */ - -#ifdef OPLUS_FEATURE_MM_OSVELTE -obj-y += mm_osvelte/ -#endif /* OPLUS_FEATURE_MM_OSVELTE */ - -#ifdef OPLUS_FEATURE_MM_FEEDBACK -obj-$(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) += oplus_mm_fb/ -#endif /* OPLUS_FEATURE_MM_FEEDBACK */ - -#ifdef OPLUS_FEATURE_QCOM_WATCHDOG -obj-$(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) += qcom_watchdog/ -#endif /* OPLUS_FEATURE_QCOM_WATCHDOG */ - -#ifdef OPLUS_FEATURE_ACM -obj-$(CONFIG_OPLUS_FEATURE_ACM) += acm/ -#endif /* OPLUS_FEATURE_ACM */ -#ifdef OPLUS_FEATURE_THEIA -obj-$(CONFIG_OPLUS_FEATURE_THEIA) += theia/ -#endif /* OPLUS_FEATURE_THEIA */ #ifdef OPLUS_FEATURE_MISC #terry.zhong@OPTI.Kernel.Stability, 2020/09/7, enable oplus misc feature obj-y += misc/ #endif /* OPLUS_FEATURE_MISC */ -#ifdef OPLUS_FEATURE_FORCE_SHUTDOWN -obj-$(CONFIG_OPLUS_FEATURE_MTK_FORCE_SHUTDOWN) += mtk_shutdown_reboot/ -#endif - -obj-$(CONFIG_OPLUS_FEATURE_RT_OPT_INFO) += rt_info/ -#ifdef OPLUS_FEATURE_HANS -#Zhou.Kun@Android.Power, 2021/06/30, enable oplus app freezer feature -obj-$(CONFIG_OPLUS_FEATURE_HANS_GKI) += oplus_hans/ -#endif /* OPLUS_FEATURE_HANS */ - #ifdef OPLUS_FEATURE_LOG_CORE obj-$(CONFIG_OPLUS_FEATURE_LOG_CORE) += olc/ #endif /* OPLUS_FEATURE_LOG_CORE */ diff --git a/drivers/soc/oplus/system/acm/Kconfig b/drivers/soc/oplus/system/acm/Kconfig deleted file mode 100755 index f74ca4761d08..000000000000 --- a/drivers/soc/oplus/system/acm/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -config OPLUS_FEATURE_ACM - bool "Enable Access Control Module" - depends on OPLUS_SYSTEM_KERNEL - default n - help - Access Control Module device driver. The purpose of this module - is to prevent third-party apps from deleting media files illegally. - This module maintains a white list of apps. Apps in the whitelist - can delete media file without any constrains, while apps not int - the whitelist may not able to delete media files, instead, the files - to be deleted were moved to the recycle directory by Gallery. - -config OPLUS_FEATURE_ACM_LOGGING - bool "Enable ACM logging features" - depends on OPLUS_FEATURE_ACM - default n - help - Enable logging features for ACM. Report delete information to Quality. diff --git a/drivers/soc/oplus/system/acm/Makefile b/drivers/soc/oplus/system/acm/Makefile deleted file mode 100755 index b3dea7912c2a..000000000000 --- a/drivers/soc/oplus/system/acm/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-$(CONFIG_OPLUS_FEATURE_ACM) += acm.o diff --git a/drivers/soc/oplus/system/acm/acm.c b/drivers/soc/oplus/system/acm/acm.c deleted file mode 100755 index 85449fce0128..000000000000 --- a/drivers/soc/oplus/system/acm/acm.c +++ /dev/null @@ -1,1863 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/******************************************************************************** - ** File: - acm.c - ** Description: - ** Add this file for ACM - ** - ** Version: 1.0 - ** Date: 2020-06-26 - ** TAG: OPLUS_FEATURE_ACM - ** - ** ------------------------- Revision History: -------------------------------- - ** - ** ------------------------------------------------------------------------------ - ********************************************************************************/ -#include -#include "acm.h" - -#define ACM_PHOTO_TYPE 1 -#define ACM_VIDEO_TYPE 2 -#define ACM_NOMEDIA_TYPE 3 -#define ACM_NOMEDIA_FNAME ".nomedia" -#define MIN_FNAME_LENGTH 2 - -#ifndef ACM_FLAG_LOGGING -#define ACM_FLAG_LOGGING (0x01) -#endif -#ifndef ACM_FLAG_DEL -#define ACM_FLAG_DEL (0x01 << 1) -#endif -#ifndef ACM_FLAG_CRT -#define ACM_FLAG_CRT (0x01 << 2) -#endif - -static int acm_flag = (ACM_FLAG_LOGGING | ACM_FLAG_DEL | ACM_FLAG_CRT); - -/* Hash table for white list */ -static struct acm_htbl acm_hash; - -static dev_t acm_devno; -static struct cdev *acm_cdev; -static struct class *acm_class; -static struct device *acm_device; -static struct kset *acm_kset; - -/* List for dir */ -static struct acm_list acm_dir_list; -/* List for nomedia dir */ -static struct acm_list acm_nomediadir_list; -/* List for framework */ -static struct acm_list acm_fwk_list; -static struct task_struct *acm_fwk_task; -static struct acm_env fwk_env; - -static struct acm_list acm_logging_list; -static struct task_struct *acm_logging_task; -static struct acm_cache logging_cache; -DECLARE_COMPLETION(acm_logging_comp); -static struct acm_env logging_env; - -/* - * The flag of acm state after acm_init. - * 0 is successful or none-zero errorno failed. - * It should be initialized as none-zero. - */ -static long acm_init_state = -ENOTTY; - -static int valid_len(const char *str, size_t maxlen) -{ - size_t len; - - len = strnlen(str, maxlen); - if (len == 0 || len > maxlen - 1) { - return -EINVAL; - } - - return ACM_SUCCESS; -} - -static size_t get_valid_strlen(char *p, size_t maxlen) -{ - size_t len; - - len = strnlen(p, maxlen); - if (len > maxlen - 1) { - len = maxlen - 1; - *(p + len) = '\0'; - } - - return len; -} - -static void sleep_if_list_empty(struct acm_list *list) -{ - set_current_state(TASK_INTERRUPTIBLE); - spin_lock(&list->spinlock); - if (list_empty(&list->head)) { - spin_unlock(&list->spinlock); - schedule(); - } else { - spin_unlock(&list->spinlock); - } - set_current_state(TASK_RUNNING); -} - -static struct acm_lnode *get_first_entry(struct list_head *head) -{ - struct list_head *pos = NULL; - struct acm_lnode *node = NULL; - - pos = head->next; - node = (struct acm_lnode *)list_entry(pos, struct acm_lnode, lnode); - list_del(pos); - - return node; -} - -/* elf_hash function */ -static unsigned int elf_hash(const char *str) -{ - unsigned int x = 0; - unsigned int hash = 0; - unsigned int ret; - - while (*str) { - hash = (hash << ACM_HASH_LEFT_SHIFT) + (*str++); - x = hash & ACM_HASH_MASK; - if (x != 0) { - hash ^= (x >> ACM_HASH_RIGHT_SHIFT); - hash &= ~x; - } - } - ret = (hash & ACM_HASH_RESULT_MASK) % ACM_HASHTBL_SZ; - return ret; -} - -static struct acm_hnode *acm_hsearch_with_flag(const struct hlist_head *hash, - const char *keystring, unsigned long long flag) -{ - const struct hlist_head *phead = NULL; - struct acm_hnode *pnode = NULL; - unsigned int idx; - - idx = elf_hash(keystring); - spin_lock(&acm_hash.spinlock); - phead = &hash[idx]; - hlist_for_each_entry(pnode, phead, hnode) { - if (pnode) { - if (!strcmp(pnode->afp.pkgname, keystring)) { - if (pnode->afp.flag & flag) { - break; - } - } - } - } - spin_unlock(&acm_hash.spinlock); - return pnode; -} - -static struct acm_hnode *acm_hsearch(const struct hlist_head *hash, - const char *keystring) -{ - const struct hlist_head *phead = NULL; - struct acm_hnode *pnode = NULL; - unsigned int idx; - - idx = elf_hash(keystring); - spin_lock(&acm_hash.spinlock); - phead = &hash[idx]; - hlist_for_each_entry(pnode, phead, hnode) { - if (pnode) { - if (!strcmp(pnode->afp.pkgname, keystring)) { - break; - } - } - } - spin_unlock(&acm_hash.spinlock); - return pnode; -} - -static void acm_hash_add(struct acm_htbl *hash_table, struct acm_hnode *hash_node) -{ - struct hlist_head *phead = NULL; - struct hlist_head *hash = hash_table->head; - - spin_lock(&hash_table->spinlock); - WARN_ON(hash_table->nr_nodes > HASHTBL_MAX_SZ - 1); - phead = &hash[elf_hash(hash_node->afp.pkgname)]; - hlist_add_head(&hash_node->hnode, phead); - hash_table->nr_nodes++; - spin_unlock(&hash_table->spinlock); -} - -static void acm_hash_del(struct acm_htbl *hash_table, struct acm_hnode *hash_node) -{ - spin_lock(&hash_table->spinlock); - WARN_ON(hash_table->nr_nodes < 1); - hlist_del(&(hash_node->hnode)); - hash_table->nr_nodes--; - spin_unlock(&hash_table->spinlock); - kfree(hash_node); -} - -static void acm_dir_list_add(struct list_head *head, struct acm_dnode *node) -{ - spin_lock(&acm_dir_list.spinlock); - WARN_ON(acm_dir_list.nr_nodes > ACM_DIR_LIST_MAX - 1); - list_add_tail(&node->lnode, head); - acm_dir_list.nr_nodes++; - spin_unlock(&acm_dir_list.spinlock); -} - -static void acm_nomediadir_list_add(struct list_head *head, struct acm_ndnode *node) -{ - spin_lock(&acm_nomediadir_list.spinlock); - WARN_ON(acm_nomediadir_list.nr_nodes > ACM_DIR_LIST_MAX - 1); - list_add_tail(&node->lnode, head); - acm_nomediadir_list.nr_nodes++; - spin_unlock(&acm_nomediadir_list.spinlock); -} - -static void acm_fwk_add(struct list_head *head, struct acm_lnode *node) -{ - spin_lock(&acm_fwk_list.spinlock); - list_add_tail(&node->lnode, head); - spin_unlock(&acm_fwk_list.spinlock); -} - -int acm_opstat(int flag) -{ - return (acm_flag & flag); -} - -static int do_cmd_set_opstat(unsigned long args) -{ - int err = 0; - int acm_flag_bk = acm_flag; - - if (copy_from_user(&acm_flag, (int *)args, sizeof(acm_flag))) { - err = -EFAULT; - acm_flag = acm_flag_bk; - goto do_cmd_set_opstat_ret; - } else { - acm_flag &= (ACM_FLAG_LOGGING | ACM_FLAG_DEL | ACM_FLAG_CRT); - } -do_cmd_set_opstat_ret: - return err; -} - -static int do_cmd_get_opstat(unsigned long args) -{ - int err = 0; - if (copy_to_user((int *)args, &acm_flag, sizeof(acm_flag))) { - err = -EFAULT; - goto do_cmd_get_opstat_ret; - } -do_cmd_get_opstat_ret: - return err; -} - -static int do_cmd_add_pkg(unsigned long args) -{ - int err = 0; - struct acm_hnode *hnode = NULL; - struct acm_hnode *result = NULL; - - hnode = kzalloc(sizeof(*hnode), GFP_KERNEL); - if (!hnode) { - return -ENOMEM; - } - INIT_HLIST_NODE(&hnode->hnode); - - if (copy_from_user(&hnode->afp, (struct acm_fwk_pkg *)args, - sizeof(struct acm_fwk_pkg))) { - err = -EFAULT; - goto do_cmd_add_ret; - } - - if (valid_len(hnode->afp.pkgname, ACM_PKGNAME_LEN_MAX)) { - err = -EINVAL; - goto do_cmd_add_ret; - } - - hnode->afp.pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - result = acm_hsearch(acm_hash.head, hnode->afp.pkgname); - if (result) { - if (result->afp.flag != hnode->afp.flag) { - result->afp.flag = hnode->afp.flag; - } - err = ACM_SUCCESS; - goto do_cmd_add_ret; - } - - acm_hash_add(&acm_hash, hnode); - - return err; - -do_cmd_add_ret: - kfree(hnode); - return err; -} - -static int do_cmd_del_pkg(unsigned long args) -{ - int err = 0; - struct acm_hnode *hnode = NULL; - struct acm_fwk_pkg *fwk_pkg = NULL; - - fwk_pkg = kzalloc(sizeof(*fwk_pkg), GFP_KERNEL); - if (!fwk_pkg) { - return -ENOMEM; - } - - if (copy_from_user(fwk_pkg->pkgname, (char *)args, - sizeof(fwk_pkg->pkgname))) { - err = -EFAULT; - goto do_cmd_delete_ret; - } - if (valid_len(fwk_pkg->pkgname, ACM_PKGNAME_LEN_MAX)) { - err = -EINVAL; - goto do_cmd_delete_ret; - } - fwk_pkg->pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - hnode = acm_hsearch(acm_hash.head, fwk_pkg->pkgname); - if (!hnode) { - pr_err("ACM: Package not found!\n"); - err = -ENODATA; - goto do_cmd_delete_ret; - } - - acm_hash_del(&acm_hash, hnode); - hnode = NULL; - -do_cmd_delete_ret: - kfree(fwk_pkg); - return err; -} - -static int do_cmd_get_pkgflag(unsigned long args) -{ - int err = 0; - struct acm_hnode *hnode = NULL; - struct acm_fwk_pkg *fwk_pkg = NULL; - - fwk_pkg = kzalloc(sizeof(*fwk_pkg), GFP_KERNEL); - if (!fwk_pkg) { - return -ENOMEM; - } - - if (copy_from_user(fwk_pkg, (struct acm_fwk_pkg *)args, - sizeof(struct acm_fwk_pkg))) { - err = -EFAULT; - goto do_cmd_get_pkgflag_ret; - } - if (valid_len(fwk_pkg->pkgname, ACM_PKGNAME_LEN_MAX)) { - err = -EINVAL; - goto do_cmd_get_pkgflag_ret; - } - fwk_pkg->pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - hnode = acm_hsearch(acm_hash.head, fwk_pkg->pkgname); - if (!hnode) { - pr_err("ACM: Package not found!\n"); - err = -ENODATA; - goto do_cmd_get_pkgflag_ret; - } - fwk_pkg->flag = hnode->afp.flag; - - if (copy_to_user((struct acm_fwk_pkg *)args, fwk_pkg, - sizeof(struct acm_fwk_pkg))) { - err = -EFAULT; - goto do_cmd_get_pkgflag_ret; - } - -do_cmd_get_pkgflag_ret: - kfree(fwk_pkg); - return err; -} - -static int do_cmd_add_dir(unsigned long args) -{ - int err = 0; - struct acm_dnode *dir_node = NULL; - struct acm_fwk_dir *fwk_dir = NULL; - - fwk_dir = kzalloc(sizeof(*fwk_dir), GFP_KERNEL); - if (!fwk_dir) { - return -ENOMEM; - } - - if (copy_from_user(fwk_dir, (struct acm_fwk_dir *)args, - sizeof(struct acm_fwk_dir))) { - pr_err("ACM: Failed to copy dir from user space!\n"); - err = -EFAULT; - goto add_dir_ret; - } - - if (valid_len(fwk_dir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - err = -EINVAL; - goto add_dir_ret; - } - fwk_dir->dir[ACM_DIR_MAX - 1] = '\0'; - - /* Check whether dir is already in the acm_dir_list */ - spin_lock(&acm_dir_list.spinlock); - list_for_each_entry(dir_node, &acm_dir_list.head, lnode) { - if (strncmp(fwk_dir->dir, dir_node->afd.dir, ACM_DIR_MAX - 1) == 0) { - if (dir_node->afd.flag != fwk_dir->flag) { - dir_node->afd.flag = fwk_dir->flag; - } - spin_unlock(&acm_dir_list.spinlock); - goto add_dir_ret; - } - } - spin_unlock(&acm_dir_list.spinlock); - - dir_node = kzalloc(sizeof(*dir_node), GFP_KERNEL); - if (!dir_node) { - err = -ENOMEM; - goto add_dir_ret; - } - - dir_node->afd.flag = fwk_dir->flag; - memcpy(dir_node->afd.dir, fwk_dir->dir, ACM_DIR_MAX - 1); - dir_node->afd.dir[ACM_DIR_MAX - 1] = '\0'; - - acm_dir_list_add(&acm_dir_list.head, dir_node); - -add_dir_ret: - kfree(fwk_dir); - return err; -} - -static int do_cmd_del_dir(unsigned long args) -{ - int err = 0; - struct acm_dnode *n = NULL; - struct acm_dnode *dir_node = NULL; - struct acm_fwk_dir *fwk_dir = NULL; - - fwk_dir = kzalloc(sizeof(*fwk_dir), GFP_KERNEL); - if (!fwk_dir) { - return -ENOMEM; - } - - if (copy_from_user(fwk_dir->dir, (char *)args, sizeof(fwk_dir->dir))) { - pr_err("ACM: Failed to copy dir from user space!\n"); - err = -EFAULT; - goto del_dir_ret; - } - if (valid_len(fwk_dir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - err = -EINVAL; - goto del_dir_ret; - } - fwk_dir->dir[ACM_DIR_MAX - 1] = '\0'; - - spin_lock(&acm_dir_list.spinlock); - list_for_each_entry_safe(dir_node, n, &acm_dir_list.head, lnode) { - if (strncmp(dir_node->afd.dir, fwk_dir->dir, ACM_DIR_MAX - 1) == 0) { - WARN_ON(acm_dir_list.nr_nodes < 1); - list_del(&dir_node->lnode); - acm_dir_list.nr_nodes--; - spin_unlock(&acm_dir_list.spinlock); - kfree(dir_node); - dir_node = NULL; - goto del_dir_ret; - } - } - spin_unlock(&acm_dir_list.spinlock); - -del_dir_ret: - kfree(fwk_dir); - return err; -} - -static int do_cmd_get_dirflag(unsigned long args) -{ - int err = 0; - struct acm_dnode *dir_node = NULL; - struct acm_fwk_dir *fwk_dir = NULL; - - fwk_dir = kzalloc(sizeof(*fwk_dir), GFP_KERNEL); - if (!fwk_dir) { - return -ENOMEM; - } - - if (copy_from_user(fwk_dir, (struct acm_fwk_dir *)args, - sizeof(struct acm_fwk_dir))) { - pr_err("ACM: Failed to copy dir from user space!\n"); - err = -EFAULT; - goto add_dir_ret; - } - - if (valid_len(fwk_dir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - err = -EINVAL; - goto add_dir_ret; - } - fwk_dir->dir[ACM_DIR_MAX - 1] = '\0'; - - /* Check whether dir is already in the acm_dir_list */ - spin_lock(&acm_dir_list.spinlock); - list_for_each_entry(dir_node, &acm_dir_list.head, lnode) { - if (strncmp(fwk_dir->dir, dir_node->afd.dir, ACM_DIR_MAX - 1) == 0) { - fwk_dir->flag = dir_node->afd.flag; - break; - } - } - spin_unlock(&acm_dir_list.spinlock); - - if (copy_to_user((struct acm_fwk_dir *)args, fwk_dir, - sizeof(struct acm_fwk_dir))) { - pr_err("ACM: Failed to copy dir to user space!\n"); - err = -EFAULT; - goto add_dir_ret; - } - -add_dir_ret: - kfree(fwk_dir); - return err; -} - -static int do_cmd_add_nomediadir(unsigned long args) -{ - int err = 0; - struct acm_ndnode *dir_node = NULL; - struct acm_fwk_nomediadir *fwk_ndir = NULL; - - fwk_ndir = kzalloc(sizeof(*fwk_ndir), GFP_KERNEL); - if (!fwk_ndir) { - return -ENOMEM; - } - - if (copy_from_user(fwk_ndir, (struct acm_fwk_nomediadir *)args, - sizeof(struct acm_fwk_nomediadir))) { - pr_err("ACM: Failed to copy nomedia dir from user space!\n"); - err = -EFAULT; - goto add_dir_ret; - } - - if (valid_len(fwk_ndir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - err = -EINVAL; - goto add_dir_ret; - } - fwk_ndir->dir[ACM_DIR_MAX - 1] = '\0'; - - /* Check whether dir is already in the acm_nomediadir_list */ - spin_lock(&acm_nomediadir_list.spinlock); - list_for_each_entry(dir_node, &acm_nomediadir_list.head, lnode) { - if (strncasecmp(fwk_ndir->dir, dir_node->afnd.dir, ACM_DIR_MAX - 1) == 0) { - spin_unlock(&acm_nomediadir_list.spinlock); - goto add_dir_ret; - } - } - spin_unlock(&acm_nomediadir_list.spinlock); - - dir_node = kzalloc(sizeof(*dir_node), GFP_KERNEL); - if (!dir_node) { - err = -ENOMEM; - goto add_dir_ret; - } - - memcpy(dir_node->afnd.dir, fwk_ndir->dir, ACM_DIR_MAX - 1); - dir_node->afnd.dir[ACM_DIR_MAX - 1] = '\0'; - - acm_nomediadir_list_add(&acm_nomediadir_list.head, dir_node); - -add_dir_ret: - kfree(fwk_ndir); - return err; -} - -static int do_cmd_del_nomediadir(unsigned long args) -{ - int err = 0; - struct acm_ndnode *n = NULL; - struct acm_ndnode *dir_node = NULL; - struct acm_fwk_nomediadir *fwk_ndir = NULL; - - fwk_ndir = kzalloc(sizeof(*fwk_ndir), GFP_KERNEL); - if (!fwk_ndir) { - return -ENOMEM; - } - - if (copy_from_user(fwk_ndir->dir, (struct acm_fwk_nomediadir *)args, - sizeof(struct acm_fwk_nomediadir))) { - pr_err("ACM: Failed to copy nomedia dir from user space!\n"); - err = -EFAULT; - goto del_dir_ret; - } - - if (valid_len(fwk_ndir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - err = -EINVAL; - goto del_dir_ret; - } - fwk_ndir->dir[ACM_DIR_MAX - 1] = '\0'; - - spin_lock(&acm_nomediadir_list.spinlock); - list_for_each_entry_safe(dir_node, n, &acm_nomediadir_list.head, lnode) { - if (strncasecmp(dir_node->afnd.dir, fwk_ndir->dir, ACM_DIR_MAX - 1) == 0) { - WARN_ON(acm_nomediadir_list.nr_nodes < 1); - list_del(&dir_node->lnode); - acm_nomediadir_list.nr_nodes--; - spin_unlock(&acm_nomediadir_list.spinlock); - kfree(dir_node); - dir_node = NULL; - goto del_dir_ret; - } - } - spin_unlock(&acm_nomediadir_list.spinlock); - -del_dir_ret: - kfree(fwk_ndir); - return err; -} - -static int do_cmd_search_nomediadir(unsigned long args) -{ - int err = 0; - struct acm_ndnode *dir_node = NULL; - struct acm_fwk_nomediadir *fwk_ndir = NULL; - - fwk_ndir = kzalloc(sizeof(*fwk_ndir), GFP_KERNEL); - if (!fwk_ndir) { - return err; - } - - if (copy_from_user(fwk_ndir, (struct acm_fwk_nomediadir *)args, - sizeof(struct acm_fwk_nomediadir))) { - pr_err("ACM: Failed to copy nomedia dir from user space!\n"); - goto add_dir_ret; - } - - if (valid_len(fwk_ndir->dir, ACM_DIR_MAX)) { - pr_err("ACM: Failed to check the length of dir name!\n"); - goto add_dir_ret; - } - fwk_ndir->dir[ACM_DIR_MAX - 1] = '\0'; - - /* Check whether dir is already in the acm_nomediadir_list */ - spin_lock(&acm_nomediadir_list.spinlock); - list_for_each_entry(dir_node, &acm_nomediadir_list.head, lnode) { - if (strncasecmp(fwk_ndir->dir, dir_node->afnd.dir, ACM_DIR_MAX - 1) == 0) { - err = 1; - break; - } - } - spin_unlock(&acm_nomediadir_list.spinlock); - -add_dir_ret: - kfree(fwk_ndir); - return err; -} - -static void acm_logging_add(struct list_head *head, struct acm_lnode *node) -{ - spin_lock(&acm_logging_list.spinlock); - if (acm_logging_list.nr_nodes > ACM_LIST_MAX_NODES - 1) { - pr_err("List was too long! Dropped a pkgname!\n"); - spin_unlock(&acm_logging_list.spinlock); - return; - } - list_add_tail(&node->lnode, head); - acm_logging_list.nr_nodes++; - spin_unlock(&acm_logging_list.spinlock); -} - -static long acm_ioctl(struct file *filp, unsigned int cmd, unsigned long args) -{ - int err = 0; - - if (acm_init_state) { - pr_err("ACM: Access Control Module init failed! err = %ld\n", - acm_init_state); - return -ENOTTY; - } - - if (_IOC_TYPE(cmd) != ACM_MAGIC) { - pr_err("ACM: Failed to check ACM_MAGIC!\n"); - return -EINVAL; - } - - if (_IOC_NR(cmd) > ACM_CMD_MAXNR) { - pr_err("ACM: Failed to check ACM_CMD_MAXNR!\n"); - return -EINVAL; - } - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if ((_IOC_DIR(cmd) & _IOC_READ) || (_IOC_DIR(cmd) & _IOC_WRITE)) { - err = !access_ok((void *)args, _IOC_SIZE(cmd)); - } -#else - if (_IOC_DIR(cmd) & _IOC_READ) { - err = !access_ok(VERIFY_WRITE, (void *)args, _IOC_SIZE(cmd)); - } else if (_IOC_DIR(cmd) & _IOC_WRITE) { - err = !access_ok(VERIFY_READ, (void *)args, _IOC_SIZE(cmd)); - } -#endif - - if (err) { - pr_err("ACM: Failed to check access permission!\n"); - return -EINVAL; - } - - switch (cmd) { - case ACM_SET_OPCTRL: - err = do_cmd_set_opstat(args); - break; - case ACM_GET_OPCTRL: - err = do_cmd_get_opstat(args); - break; - case ACM_ADD_PKG: - err = do_cmd_add_pkg(args); - break; - case ACM_DEL_PKG: - err = do_cmd_del_pkg(args); - break; - case ACM_GET_PKG_FLAG: - err = do_cmd_get_pkgflag(args); - break; - case ACM_ADD_DIR: - err = do_cmd_add_dir(args); - break; - case ACM_DEL_DIR: - err = do_cmd_del_dir(args); - break; - case ACM_GET_DIR_FLAG: - err = do_cmd_get_dirflag(args); - break; - case ACM_ADD_NOMEDIADIR: - err = do_cmd_add_nomediadir(args); - break; - case ACM_DEL_NOMEDIADIR: - err = do_cmd_del_nomediadir(args); - break; - case ACM_SEARCH_NOMEDIADIR: - err = do_cmd_search_nomediadir(args); - break; - default: - pr_err("ACM: Unknown command!\n"); - return -EINVAL; - } - - return err; -} - -static int set_path(struct acm_lnode *node, struct dentry *dentry) -{ - char *buffer = NULL; - char *dentry_path = NULL; - size_t path_len; - - buffer = kzalloc(ACM_PATH_MAX, GFP_KERNEL); - if (!buffer) { - return -ENOMEM; - } - - dentry_path = dentry_path_raw(dentry, buffer, ACM_PATH_MAX); - if (IS_ERR(dentry_path)) { - kfree(buffer); - pr_err("ACM: Failed to get path! err = %lu\n", PTR_ERR(dentry_path)); - return -EINVAL; - } - - path_len = get_valid_strlen(dentry_path, ACM_PATH_MAX); - memcpy(node->path, dentry_path, path_len); - node->path[path_len] = '\0'; - kfree(buffer); - return ACM_SUCCESS; -} - -static int do_get_path_error(struct acm_lnode *node, struct dentry *dentry) -{ - int i; - int err; - int depth; - struct dentry *d[ERR_PATH_MAX_DENTRIES] = {NULL}; - - for (i = 0; i < ERR_PATH_MAX_DENTRIES; i++) { - d[i] = dget(dentry); - } - - /* - * Find the root dentry of the current file system.The d[i] saves the - * top ERR_PATH_MAX_DENTRIES-1 dentries to the root dentry. - */ - depth = 0; - while (!IS_ROOT(dentry)) { - dput(d[0]); - for (i = 0; i < ERR_PATH_MAX_DENTRIES - 1; i++) { - d[i] = d[i + 1]; - } - dentry = d[ERR_PATH_MAX_DENTRIES - 1] = dget_parent(dentry); - depth++; - } - node->depth = depth; - - dentry = d[ERR_PATH_LAST_DENTRY]; - - for (i = 0; i < ERR_PATH_MAX_DENTRIES; i++) { - dput(d[i]); - } - - dentry = dget(dentry); - err = set_path(node, dentry); - if (err) { - dput(dentry); - pr_err("ACM: Unknown error! err = %d\n", err); - return -EINVAL; - } - dput(dentry); - - return ACM_SUCCESS; -} - -static int delete_log_upload(const char *pkgname, uid_t uid, - struct dentry *dentry, int file_type, int op) -{ - int err; - struct dentry *parent; - struct acm_lnode *new_dmd_node = NULL; - - new_dmd_node = kzalloc(sizeof(*new_dmd_node), GFP_NOFS); - if (!new_dmd_node) { - return -ENOMEM; - } - - if (pkgname != NULL) { - memcpy(new_dmd_node->pkgname, pkgname, ACM_PKGNAME_LEN_MAX - 1); - } - new_dmd_node->pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - new_dmd_node->depth = DEPTH_INIT; - new_dmd_node->file_type = file_type; - new_dmd_node->op = op; - new_dmd_node->uid = uid; - - parent = dget_parent(dentry); - err = set_path(new_dmd_node, parent); - if (err) { - pr_err("ACM: Failed to get full path! err = %d\n", err); - err = do_get_path_error(new_dmd_node, dentry); - if (err) { - pr_err("ACM: Failed to get path for dmd! err = %d\n", err); - } - } - - /* - * Data in new_dmd_list will be uploaded to unrmd by acm_logging_task, and - * then uploaded to dmd server. - */ - acm_logging_add(&acm_logging_list.head, new_dmd_node); - complete(&acm_logging_comp); - - return err; -} - -inline void acm_fuse_init_cache(void) -{ - /* do nothing */ -} - -inline void acm_fuse_free_cache(void) -{ - /* do nothing */ -} - -static void get_real_pkg_name(char *pkgname, struct task_struct *tsk, - const uid_t uid) -{ - int i; - int res; - struct task_struct *p_tsk = NULL; - - if (uid >= UID_THRESHOLD) { - p_tsk = tsk; - while (__kuid_val(task_uid(p_tsk)) >= UID_THRESHOLD) { - if ((p_tsk->real_parent) != NULL) { - tsk = p_tsk; - p_tsk = p_tsk->real_parent->group_leader; - } else { - break; - } - } - } - - res = get_cmdline(tsk, pkgname, ACM_PKGNAME_LEN_MAX - 1); - pkgname[res] = '\0'; - - for (i = 0; i < ACM_PKGNAME_LEN_MAX && pkgname[i] != '\0'; i++) { - if (pkgname[i] == ':') { - pkgname[i] = '\0'; - break; - } - } -} - -static int delete_log_upload_fwk(const char *pkgname, uid_t taskuid, - struct dentry *dentry, int op) -{ - int err; - struct acm_lnode *new_fwk_node = NULL; - - /* Data not found */ - new_fwk_node = kzalloc(sizeof(*new_fwk_node), GFP_NOFS); - if (!new_fwk_node) { - return -ENOMEM; - } - - if (pkgname != NULL) { - memcpy(new_fwk_node->pkgname, pkgname, ACM_PKGNAME_LEN_MAX - 1); - } - new_fwk_node->pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - err = set_path(new_fwk_node, dentry); - if (err) { - kfree(new_fwk_node); - new_fwk_node = NULL; - pr_err("ACM: Failed to get path for framework! err = %d\n", err); - return err; - } - - new_fwk_node->op = op; - new_fwk_node->uid = taskuid; - - /* Data in new_fwk_list will be uploaded - * to framework by acm_fwk_task - */ - acm_fwk_add(&acm_fwk_list.head, new_fwk_node); - wake_up_process(acm_fwk_task); - - return ACM_SUCCESS; -} - -static char *dentry_without_usrrootentry(char *str) -{ - int i; - int num = 0; - - for (i = 0; i < strlen(str); i++) { - if (num == 2) { - break; - } - if (*(str + i) == '/') { - num++; - } - } - - return num == 2 ? (str + i) : str; -} - -static int inquiry_delete_policy(char *pkgname, uid_t taskuid, - struct dentry *dentry, int file_type, int op) -{ - struct acm_hnode *hsearch_ret = NULL; - struct acm_dnode *n = NULL; - struct acm_dnode *dir_node = NULL; - unsigned int dir_flag = 0; - char *buffer = NULL; - char *dentry_path = NULL; - - buffer = kzalloc(ACM_PATH_MAX, GFP_KERNEL); - if (!buffer) { - return DEL_ALLOWED; - } - - dentry_path = dentry_path_raw(dentry, buffer, ACM_PATH_MAX); - if (IS_ERR(dentry_path)) { - kfree(buffer); - pr_err("ACM: Failed to get path! err = %lu\n", PTR_ERR(dentry_path)); - return DEL_ALLOWED; - } - - spin_lock(&acm_dir_list.spinlock); - list_for_each_entry_safe(dir_node, n, &acm_dir_list.head, lnode) { - if (strlen(dentry_path) >= strlen(dir_node->afd.dir)) { - if (strncasecmp(dentry_without_usrrootentry(dentry_path), - dir_node->afd.dir, strlen(dir_node->afd.dir)) == 0) { - dir_flag = dir_node->afd.flag; - break; - } - } - } - spin_unlock(&acm_dir_list.spinlock); - - kfree(buffer); - if (dir_flag == 0) { - return DEL_ALLOWED; - } else { - if (acm_opstat(ACM_FLAG_LOGGING)) { - if (delete_log_upload(pkgname, taskuid, dentry, file_type, op)) { - pr_err("ACM: Failed to upload to dmd! file_type = %d op = %d\n", - file_type, op); - } - } - - if (op == FUSE_RENAME || op == FUSE_RENAME2) { - return DEL_ALLOWED; - } - - if (acm_opstat(ACM_FLAG_LOGGING) - && !acm_opstat(ACM_FLAG_DEL)) { - return DEL_ALLOWED; - } - - if (taskuid < UID_THRESHOLD) { - return DEL_ALLOWED; - } - } - - hsearch_ret = acm_hsearch_with_flag(acm_hash.head, pkgname, dir_flag); - if (!hsearch_ret) { - return -ENODATA; - } - - return DEL_ALLOWED; -} - -static int inquiry_create_nomedia_policy(struct dentry *dentry) -{ - int ret = CRT_ALLOWED; - struct acm_ndnode *dir_node = NULL; - char *buffer = NULL; - char *dentry_path = NULL; - struct dentry *parent = dget_parent(dentry); - - buffer = kzalloc(ACM_PATH_MAX, GFP_KERNEL); - if (!buffer) { - return CRT_ALLOWED; - } - - dentry_path = dentry_path_raw(parent, buffer, ACM_PATH_MAX); - if (IS_ERR(dentry_path)) { - kfree(buffer); - pr_err("ACM: Failed to get path! err = %lu\n", PTR_ERR(dentry_path)); - return CRT_ALLOWED; - } - - if (IS_ROOT(dget_parent(parent))) { - kfree(buffer); - return CRT_NOT_ALLOWED; - } - - spin_lock(&acm_nomediadir_list.spinlock); - list_for_each_entry(dir_node, &acm_nomediadir_list.head, lnode) { - if (strlen(dentry_path) >= strlen(dir_node->afnd.dir)) { - if (strncasecmp(dentry_path + (strlen(dentry_path) - strlen(dir_node->afnd.dir)), - dir_node->afnd.dir, strlen(dir_node->afnd.dir)) == 0) { - if (strstr(dir_node->afnd.dir, "/") == NULL) { - if (IS_ROOT(dget_parent(dget_parent(parent)))) { - ret = CRT_NOT_ALLOWED; - break; - } - } else { - ret = CRT_NOT_ALLOWED; - break; - } - } - } - } - spin_unlock(&acm_nomediadir_list.spinlock); - kfree(buffer); - return ret; -} - -int acm_search(struct dentry *dentry, int file_type, int op) -{ - int ret = DEL_ALLOWED; - int err = 0; - struct task_struct *tsk = NULL; - char *pkgname = NULL; - uid_t taskuid = 0; - /* - struct timespec __maybe_unused start; - struct timespec __maybe_unused end; - - getrawmonotonic(&start); - */ - - if (acm_init_state) { - pr_err("ACM: Access Control Module init failed! err = %ld\n", - acm_init_state); - err = -EINVAL; - return err; - } - - tsk = current->group_leader; - if (!tsk) { - err = -EINVAL; - return err; - } - taskuid = __kuid_val(task_uid(tsk)); - - pkgname = kzalloc(ACM_PKGNAME_LEN_MAX, GFP_NOFS); - if (!pkgname) { - err = -ENOMEM; - return err; - } - - get_real_pkg_name(pkgname, tsk, taskuid); - - if (valid_len(pkgname, ACM_PKGNAME_LEN_MAX)) { - pr_err("ACM: Failed to check the length of package name!\n"); - kfree(pkgname); - return DEL_ALLOWED; - } - - pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - if ((acm_opstat(ACM_FLAG_DEL | ACM_FLAG_LOGGING)) - && (op == FUSE_UNLINK || op == FUSE_RMDIR - || op == FUSE_RENAME || op == FUSE_RENAME2)) { - ret = inquiry_delete_policy(pkgname, taskuid, dentry, file_type, op); - if (ret != DEL_ALLOWED) { - err = delete_log_upload_fwk(pkgname, taskuid, dentry, op); - if (err) { - pr_err("ACM: Failed to upload to fwk! err = %d ret=%d\n", err, ret); - } - } - } else if ((acm_opstat(ACM_FLAG_CRT)) - && (op == FUSE_CREATE || op == FUSE_MKNOD)) { - ret = inquiry_create_nomedia_policy(dentry); - if (ret != CRT_ALLOWED) { - err = delete_log_upload_fwk(pkgname, taskuid, dentry, op); - if (err) { - pr_err("ACM: Failed to upload to fwk! err = %d ret = %d\n", err, ret); - } - } - } - - if (pkgname != NULL) { - kfree(pkgname); - } - - /* - getrawmonotonic(&end); - pr_err("ACM: %s TIME_COST: start.tv_sec = %lu start.tv_nsec = %lu - end.tv_sec = %lu end.tv_nsec = %lu duraion = %lu\n", - __func__, - start.tv_sec, start.tv_nsec, end.tv_sec, - end.tv_nsec, end.tv_nsec - start.tv_nsec); - */ - - return ret; -} - -static int acm_search2(struct dentry *dentry, struct dentry *dentry2, - int file_type, int op) -{ - int ret = DEL_ALLOWED; - int err = 0; - struct task_struct *tsk = NULL; - char *pkgname = NULL; - uid_t taskuid = 0; - /* - struct timespec __maybe_unused start; - struct timespec __maybe_unused end; - - getrawmonotonic(&start); - */ - - if (acm_init_state) { - pr_err("ACM: Access Control Module init failed! err = %ld\n", - acm_init_state); - err = -EINVAL; - return err; - } - - tsk = current->group_leader; - if (!tsk) { - err = -EINVAL; - return err; - } - taskuid = __kuid_val(task_uid(tsk)); - - pkgname = kzalloc(ACM_PKGNAME_LEN_MAX, GFP_NOFS); - if (!pkgname) { - err = -ENOMEM; - return err; - } - - get_real_pkg_name(pkgname, tsk, taskuid); - - if (valid_len(pkgname, ACM_PKGNAME_LEN_MAX)) { - pr_err("ACM: Failed to check the length of package name!\n"); - kfree(pkgname); - return DEL_ALLOWED; - } - - pkgname[ACM_PKGNAME_LEN_MAX - 1] = '\0'; - - if ((acm_opstat(ACM_FLAG_DEL | ACM_FLAG_LOGGING)) - && (op == FUSE_UNLINK || op == FUSE_RMDIR - || op == FUSE_RENAME || op == FUSE_RENAME2)) { - ret = inquiry_delete_policy(pkgname, taskuid, dentry, file_type, op); - if (ret != DEL_ALLOWED) { - err = delete_log_upload_fwk(pkgname, taskuid, dentry, op); - if (err) { - pr_err("ACM: Failed to upload to fwk! err = %d ret=%d\n", err, ret); - } - } - } else if ((acm_opstat(ACM_FLAG_CRT)) - && (op == FUSE_CREATE || op == FUSE_MKNOD || op == FUSE_MKDIR)) { - ret = inquiry_create_nomedia_policy(dentry); - if (ret != CRT_ALLOWED) { - err = delete_log_upload_fwk(pkgname, taskuid, dentry, op); - if (err) { - pr_err("ACM: Failed to upload to fwk! err = %d ret = %d\n", err, ret); - } - } - } - - if (pkgname != NULL) { - kfree(pkgname); - } - - /* - getrawmonotonic(&end); - pr_err("ACM: %s TIME_COST: start.tv_sec = %lu start.tv_nsec = %lu - end.tv_sec = %lu end.tv_nsec = %lu duraion = %lu\n", - __func__, - start.tv_sec, start.tv_nsec, end.tv_sec, - end.tv_nsec, end.tv_nsec - start.tv_nsec); - */ - - return ret; -} - -static int is_media_extension(const unsigned char *s, const char *sub) -{ - size_t slen = strlen((const char *)s); - size_t sublen = strlen(sub); - - if (slen < sublen + MIN_FNAME_LENGTH) - return 0; - - if (s[slen - sublen - 1] != '.') - return 0; - - if (!strncasecmp((const char *)s + slen - sublen, sub, sublen)) - return 1; - return 0; -} - -static int is_photo_file(struct dentry *dentry) -{ - static const char *const ext[] = { - "jpg", "jpe", "jpeg", "gif", "png", "bmp", "wbmp", - "webp", "dng", "cr2", "nef", "nrw", "arw", "rw2", - "orf", "raf", "pef", "srw", "heic", "heif", NULL - }; - int i; - - for (i = 0; ext[i]; i++) { - if (is_media_extension(dentry->d_name.name, ext[i])) - return ACM_PHOTO_TYPE; - } - - return 0; -} - -static int is_video_file(struct dentry *dentry) -{ - static const char *const ext[] = { - "mpeg", "mpg", "mp4", "m4v", "mov", "3gp", "3gpp", "3g2", - "3gpp2", "mkv", "webm", "ts", "avi", "f4v", "flv", "m2ts", - "divx", "wmv", "asf", NULL - }; - int i; - - for (i = 0; ext[i]; i++) { - if (is_media_extension(dentry->d_name.name, ext[i])) - return ACM_VIDEO_TYPE; - } - - return 0; -} - -static int is_nomedia_file(struct dentry *dentry) -{ - if (strncasecmp(dentry->d_name.name, ACM_NOMEDIA_FNAME, strlen(ACM_NOMEDIA_FNAME)) == 0) - return ACM_NOMEDIA_TYPE; - else - return 0; -} - -static int get_monitor_file_type(struct dentry *dentry) -{ - int file_type = 0; - - if ((file_type = is_photo_file(dentry)) != 0) - return file_type; - - file_type = is_video_file(dentry); - - return file_type; -} - -static int should_monitor_file(struct dentry *dentry, int operation) -{ - int file_type = 0; - - if (operation == FUSE_UNLINK) { - if (acm_opstat(ACM_FLAG_LOGGING | ACM_FLAG_DEL)) - file_type = get_monitor_file_type(dentry); - } else if (operation == FUSE_RENAME || operation == FUSE_RENAME2) { - if (acm_opstat(ACM_FLAG_LOGGING)) - file_type = get_monitor_file_type(dentry); - } else if (operation == FUSE_CREATE || operation == FUSE_MKNOD || - operation == FUSE_MKDIR) { - if (acm_opstat(ACM_FLAG_CRT)) - file_type = is_nomedia_file(dentry); - } - - return file_type; -} - -int monitor_acm2(struct dentry *dentry, struct dentry *dentry2, int op) -{ - struct inode *inode = d_inode(dentry); - int file_type = 0x0f; - int err = 0; - - if (!acm_opstat(ACM_FLAG_LOGGING | ACM_FLAG_DEL | ACM_FLAG_CRT)) { - goto monitor_ret; - } - - if (!inode) { - goto monitor_ret; - } - - if (S_ISREG(inode->i_mode)) { - file_type = should_monitor_file(dentry, op); - if (file_type == 0) { - goto monitor_ret; - } - } else if (S_ISDIR(inode->i_mode)) { - if (!(acm_opstat(ACM_FLAG_DEL)) && - should_monitor_file(dentry, op) != ACM_NOMEDIA_TYPE) { - goto monitor_ret; - } - } else { - goto monitor_ret; - } - - err = acm_search2(dentry, dentry2, file_type, op); - -monitor_ret: - return err; -} - -static void set_logging_uevent_env(struct acm_lnode *node) -{ - int idx; - - memset(&logging_env, 0, sizeof(struct acm_env)); - snprintf(logging_env.pkgname, sizeof(logging_env.pkgname), "PKGNAME=%s", - node->pkgname); - snprintf(logging_env.uid, sizeof(logging_env.uid), "UID=%u", node->uid); - snprintf(logging_env.path, sizeof(logging_env.path), "PATH=%s", node->path); - snprintf(logging_env.depth, sizeof(logging_env.depth), "DEPTH=%d", - node->depth); - snprintf(logging_env.file_type, sizeof(logging_env.file_type), "FTYPE=%d", - node->file_type); - snprintf(logging_env.nr, sizeof(logging_env.nr), "NR=%d", node->nr); - snprintf(logging_env.op, sizeof(logging_env.op), "OP=%d", node->op); - - idx = 0; - logging_env.envp[idx++] = "LOGGING_STAT"; - logging_env.envp[idx++] = logging_env.pkgname; - logging_env.envp[idx++] = logging_env.uid; - logging_env.envp[idx++] = logging_env.path; - logging_env.envp[idx++] = logging_env.depth; - logging_env.envp[idx++] = logging_env.file_type; - logging_env.envp[idx++] = logging_env.nr; - logging_env.envp[idx++] = logging_env.op; - logging_env.envp[idx] = NULL; - /* for test */ - pr_info("ACM: %s %s %s %s %s %s %s\n", - logging_env.envp[0], logging_env.envp[1], logging_env.envp[2], - logging_env.envp[4], logging_env.envp[5], - logging_env.envp[6], logging_env.envp[7]); -} - -static void upload_delete_log(void) -{ - int i; - int err = 0; - - for (i = 0; i < logging_cache.count; i++) { - set_logging_uevent_env(&logging_cache.cache[i]); - err = kobject_uevent_env(&(acm_cdev->kobj), KOBJ_CHANGE, - logging_env.envp); - if (err) { - pr_err("ACM: Failed to send uevent!\n"); - } - } - - memset(&logging_cache, 0, sizeof(struct acm_cache)); - - /* - * Compiler optimization may remove the call to memset(), - * causing logging_cache uncleaned, if logging_cache is not accessed - * after memset(). So we access the count member after memset() - * to avoid this optimization. - */ - logging_cache.count = 0; -} - -static bool is_a_cache(struct acm_lnode *node, struct acm_lnode *cache_node) -{ - return (node->depth == cache_node->depth) && (node->op == cache_node->op) && - (node->file_type == cache_node->file_type) && - (strcmp(node->path, cache_node->path) == 0) && - (strcmp(node->pkgname, cache_node->pkgname) == 0); -} - -static void add_cache(struct acm_lnode *node) -{ - if (logging_cache.count > MAX_CACHED_DELETE_LOG - 1) { - return; - } - - memcpy(&logging_cache.cache[logging_cache.count], node, - sizeof(struct acm_lnode)); - logging_cache.cache[logging_cache.count].nr++; - logging_cache.count++; -} - -/* - * Return true if in the cache, false if NOT in the cache. - */ -static bool is_cached(struct acm_lnode *node, int *idx) -{ - int i; - - for (i = 0; i < logging_cache.count; i++) { - if (is_a_cache(node, &logging_cache.cache[i])) { - *idx = i; - return true; - } - } - return false; -} - -static void cache_log(struct acm_lnode *node) -{ - int which = -1; - - if (is_cached(node, &which)) { - WARN_ON((which < 0) || (which > MAX_CACHED_DELETE_LOG - 1)); - logging_cache.cache[which].nr++; - } else { - add_cache(node); - } -} - -static int cal_nr_slashes(char *str) -{ - int i; - int len; - int nr_slashes = 0; - - len = get_valid_strlen(str, ACM_PATH_MAX); - - for (i = 0; i < len; i++) { - if (*(str + i) == '/') { - nr_slashes++; - } - } - return nr_slashes; -} - -static void set_depth(struct acm_lnode *node) -{ - if (node->depth == DEPTH_INIT) { - node->depth = cal_nr_slashes(node->path) - 1; - } -} - -static void process_delete_log(struct acm_lnode *node) -{ - set_depth(node); - cache_log(node); -} - -static void process_and_upload_delete_log(struct list_head *list) -{ - struct acm_lnode *node = NULL; - - while (1) { - if (list_empty(list)) { - break; - } - node = get_first_entry(list); - process_delete_log(node); - kfree(node); - node = NULL; - - if (logging_cache.count > MAX_CACHED_DELETE_LOG - 1) { - upload_delete_log(); - } - } - if (logging_cache.count > 0) { - upload_delete_log(); - } -} - -static int acm_logging_loop(void *data) -{ - struct list_head list = LIST_HEAD_INIT(list); - /* - struct timespec __maybe_unused start; - struct timespec __maybe_unused end; - */ - - while (!kthread_should_stop()) { - if (wait_for_completion_interruptible(&acm_logging_comp)) { - pr_err("ACM: %s is interrupted!\n", __func__); - } - - msleep(DELETE_LOG_UPLOAD_INTERVAL_MS); - - spin_lock(&acm_logging_list.spinlock); - list_cut_position(&list, &acm_logging_list.head, - acm_logging_list.head.prev); - acm_logging_list.nr_nodes = 0; - spin_unlock(&acm_logging_list.spinlock); - - /* getrawmonotonic(&start); */ - process_and_upload_delete_log(&list); - /* getrawmonotonic(&end); */ - /* - pr_err("ACM: %s TIME_COST: start.tv_sec = %lu start.tv_nsec = %lu, - end.tv_sec = %lu end.tv_nsec = %lu duraion = %lu\n", - __func__, - start.tv_sec, start.tv_nsec, - end.tv_sec, end.tv_nsec, - end.tv_nsec - start.tv_nsec); - */ - } - - return ACM_SUCCESS; -} - -static void acm_cache_init(void) -{ - memset(&logging_cache.cache, 0, sizeof(logging_cache.cache)); - logging_cache.count = 0; -} - -static void set_fwk_uevent_env(struct acm_lnode *node) -{ - int idx; - - memset(&fwk_env, 0, sizeof(struct acm_env)); - snprintf(fwk_env.pkgname, sizeof(fwk_env.pkgname), "PKGNAME=%s", - node->pkgname); - snprintf(fwk_env.uid, sizeof(fwk_env.uid), "UID=%u", node->uid); - snprintf(fwk_env.path, sizeof(fwk_env.path), "FILE_PATH=%s", node->path); - snprintf(fwk_env.op, sizeof(fwk_env.op), "OP=%d", node->op); - - idx = 0; - fwk_env.envp[idx++] = "OPERATION_STAT"; - fwk_env.envp[idx++] = fwk_env.pkgname; - fwk_env.envp[idx++] = fwk_env.uid; - fwk_env.envp[idx++] = fwk_env.path; - fwk_env.envp[idx++] = fwk_env.op; - fwk_env.envp[idx] = NULL; - - /* for test */ - /* - pr_info("ACM: %s %s %s %s %s\n", fwk_env.envp[0], - fwk_env.envp[1], fwk_env.envp[2], fwk_env.envp[3], fwk_env.envp[4]); - */ -} - -static void upload_data_to_fwk(void) -{ - int err = 0; - struct acm_lnode *node = NULL; - /* - struct timespec __maybe_unused start; - struct timespec __maybe_unused end; - */ - - while (1) { - spin_lock(&acm_fwk_list.spinlock); - if (list_empty(&acm_fwk_list.head)) { - spin_unlock(&acm_fwk_list.spinlock); - break; - } - node = get_first_entry(&acm_fwk_list.head); - spin_unlock(&acm_fwk_list.spinlock); - /* getrawmonotonic(&start); */ - set_fwk_uevent_env(node); - err = kobject_uevent_env(&(acm_cdev->kobj), KOBJ_CHANGE, fwk_env.envp); - if (err) { - pr_err("ACM: Failed to upload to fwk!\n"); - } - - kfree(node); - node = NULL; - /* - getrawmonotonic(&end); - pr_err("ACM: %s TIME_COST: start.tv_sec = %lu start.tv_nsec = %lu, - end.tv_sec = %lu end.tv_nsec = %lu duraion = %lu\n", - __func__, - start.tv_sec, start.tv_nsec, - end.tv_sec, end.tv_nsec, - end.tv_nsec - start.tv_nsec); - */ - } -} - -static int acm_fwk_loop(void *data) -{ - while (!kthread_should_stop()) { - upload_data_to_fwk(); - sleep_if_list_empty(&acm_fwk_list); - } - return ACM_SUCCESS; -} - -static int acm_hash_init(void) -{ - int i; - struct hlist_head *head = NULL; - - head = kzalloc(sizeof(*head) * ACM_HASHTBL_SZ, GFP_KERNEL); - if (!head) { - return -ENOMEM; - } - for (i = 0; i < ACM_HASHTBL_SZ; i++) { - INIT_HLIST_HEAD(&(head[i])); - } - - acm_hash.head = head; - acm_hash.nr_nodes = 0; - spin_lock_init(&acm_hash.spinlock); - return ACM_SUCCESS; -} - -static void acm_list_init(struct acm_list *list) -{ - INIT_LIST_HEAD(&list->head); - list->nr_nodes = 0; - spin_lock_init(&list->spinlock); -} - -static int acm_task_init(void) -{ - long err = 0; - - /* - *Create the acm_fwk_loop task to asynchronously - * upload data to framework. - */ - acm_fwk_task = kthread_run(acm_fwk_loop, NULL, "acm_fwk_loop"); - if (IS_ERR(acm_fwk_task)) { - err = PTR_ERR(acm_fwk_task); - pr_err("ACM: Failed to create acm_fwk_task! err = %ld\n", err); - return err; - } - - acm_logging_task = kthread_run(acm_logging_loop, NULL, "acm_logging_loop"); - if (IS_ERR(acm_logging_task)) { - err = PTR_ERR(acm_logging_task); - pr_err("ACM: Failed to create acm_logging_task! err = %ld\n", err); - return err; - } - pr_info("ACM: init acm_logging_loop\n"); - - return err; -} - -static const struct file_operations acm_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = acm_ioctl, -}; - -static int acm_chr_dev_init(void) -{ - long err; - - /* Dynamiclly allocate a device number */ - err = alloc_chrdev_region(&acm_devno, ACM_DEV_BASE_MINOR, ACM_DEV_COUNT, - ACM_DEV_NAME); - if (err) { - pr_err("ACM: Failed to alloc device number! err = %ld\n", err); - return err; - } - - /* Initialize and add a cdev data structure to kernel */ - acm_cdev = cdev_alloc(); - if (!acm_cdev) { - err = -ENOMEM; - pr_err("ACM: Failed to alloc memory for cdev! err = %ld\n", err); - goto free_devno; - } - acm_cdev->owner = THIS_MODULE; - acm_cdev->ops = &acm_fops; - err = cdev_add(acm_cdev, acm_devno, ACM_DEV_COUNT); - if (err) { - pr_err("ACM: Failed to register cdev! err = %ld\n", err); - goto free_cdev; - } - - /* Dynamiclly create a device file */ - acm_class = class_create(THIS_MODULE, ACM_DEV_NAME); - if (IS_ERR(acm_class)) { - err = PTR_ERR(acm_class); - pr_err("ACM: Failed to create a class! err = %ld\n", err); - goto free_cdev; - } - acm_device = device_create(acm_class, NULL, acm_devno, NULL, ACM_DEV_NAME); - if (IS_ERR(acm_device)) { - err = PTR_ERR(acm_device); - pr_err("ACM: Failed to create a class! err = %ld\n", err); - goto free_class; - } - - /* Initialize uevent stuff */ - acm_kset = kset_create_and_add(ACM_DEV_NAME, NULL, kernel_kobj); - if (!acm_kset) { - err = -ENOMEM; - pr_err("ACM: Failed to create kset! err = %ld\n", err); - goto free_device; - } - acm_cdev->kobj.kset = acm_kset; - acm_cdev->kobj.uevent_suppress = 0; - err = kobject_add(&(acm_cdev->kobj), &(acm_kset->kobj), "acm_cdev_kobj"); - if (err) { - kobject_put(&(acm_cdev->kobj)); - pr_err("ACM: Failed to add kobject to kernel! err = %ld\n", err); - goto free_kset; - } - - return err; - -free_kset: - kset_unregister(acm_kset); -free_device: - device_destroy(acm_class, acm_devno); -free_class: - class_destroy(acm_class); -free_cdev: - cdev_del(acm_cdev); -free_devno: - unregister_chrdev_region(acm_devno, ACM_DEV_COUNT); - - pr_err("ACM: Failed to init acm character device! err = %ld\n", err); - return err; -} - -static int __init acm_init(void) -{ - long err = 0; - - /* Initialize hash table */ - err = acm_hash_init(); - if (err) { - pr_err("ACM: Failed to initialize hash table! err = %ld\n", err); - goto fail_hash; - } - - acm_list_init(&acm_dir_list); - acm_list_init(&acm_nomediadir_list); - acm_list_init(&acm_fwk_list); - acm_list_init(&acm_logging_list); - acm_cache_init(); - - err = acm_task_init(); - if (err) { - pr_err("ACM: Failed to initialize main task! err = %ld\n", err); - goto fail_task; - } - - /* Initialize acm character device */ - err = acm_chr_dev_init(); - if (err) { - pr_err("ACM: Failed to initialize acm chrdev! err = %ld\n", err); - goto fail_task; - } - - pr_info("ACM: Initialize ACM moudule succeed!\n"); - - acm_init_state = err; - return err; - -fail_task: - kfree(acm_hash.head); - acm_hash.head = NULL; -fail_hash: - acm_init_state = err; - return err; -} - -static void acm_hash_cleanup(struct hlist_head *hash) -{ - int i; - struct hlist_head *phead = NULL; - struct acm_hnode *pnode = NULL; - - spin_lock(&acm_hash.spinlock); - for (i = 0; i < ACM_HASHTBL_SZ; i++) { - phead = &hash[i]; - while (!hlist_empty(phead)) { - pnode = hlist_entry(phead->first, struct acm_hnode, hnode); - hlist_del(&pnode->hnode); - kfree(pnode); - pnode = NULL; - } - } - acm_hash.nr_nodes = 0; - spin_unlock(&acm_hash.spinlock); -} - -static void acm_list_cleanup(struct acm_list *list) -{ - struct acm_lnode *node = NULL; - struct list_head *head = NULL, *pos = NULL; - - spin_lock(&list->spinlock); - head = &list->head; - while (!list_empty(head)) { - pos = head->next; - node = (struct acm_lnode *)list_entry(pos, struct acm_lnode, lnode); - list_del(pos); - kfree(node); - node = NULL; - } - list->nr_nodes = 0; - spin_unlock(&list->spinlock); -} - -static void __exit acm_exit(void) -{ - device_destroy(acm_class, acm_devno); - class_destroy(acm_class); - cdev_del(acm_cdev); - unregister_chrdev_region(acm_devno, ACM_DEV_COUNT); - kset_unregister(acm_kset); - - acm_hash_cleanup(acm_hash.head); - acm_list_cleanup(&acm_dir_list); - acm_list_cleanup(&acm_nomediadir_list); - - pr_info("ACM: Exited from ACM module.\n"); -} - -MODULE_LICENSE("GPL"); -module_init(acm_init); -module_exit(acm_exit); diff --git a/drivers/soc/oplus/system/acm/acm.h b/drivers/soc/oplus/system/acm/acm.h deleted file mode 100755 index 343c1b485c3a..000000000000 --- a/drivers/soc/oplus/system/acm/acm.h +++ /dev/null @@ -1,190 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/******************************************************************************** - ** File: - acm.h - ** Description: - ** Add this file for ACM - ** - ** Version: 1.0 - ** Date: 2020-06-26 - ** TAG: OPLUS_FEATURE_ACM - ** - ** ------------------------------- Revision History: ---------------------------- - ** - ** ------------------------------------------------------------------------------ - ********************************************************************************/ - -#ifndef __DRIVERS_SOC_OPLUS_SYSTEM_ACM_H__ -#define __DRIVERS_SOC_OPLUS_SYSTEM_ACM_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ACM_DEV_NAME "acm" -#define ACM_DEV_BASE_MINOR 0 -#define ACM_DEV_COUNT 1 - -#define ACM_MAGIC 'a' -#define ACM_SET_OPCTRL _IOW(ACM_MAGIC, 0, int) -#define ACM_GET_OPCTRL _IOW(ACM_MAGIC, 1, int) -#define ACM_ADD_PKG _IOW(ACM_MAGIC, 2, struct acm_fwk_pkg) -#define ACM_DEL_PKG _IOW(ACM_MAGIC, 3, char*) -#define ACM_GET_PKG_FLAG _IOW(ACM_MAGIC, 4, struct acm_fwk_pkg) -#define ACM_ADD_DIR _IOR(ACM_MAGIC, 5, struct acm_fwk_dir) -#define ACM_DEL_DIR _IOR(ACM_MAGIC, 6, char*) -#define ACM_GET_DIR_FLAG _IOR(ACM_MAGIC, 7, struct acm_fwk_dir) -#define ACM_ADD_NOMEDIADIR _IOR(ACM_MAGIC, 8, struct acm_fwk_nomediadir) -#define ACM_DEL_NOMEDIADIR _IOR(ACM_MAGIC, 9, struct acm_fwk_nomediadir) -#define ACM_SEARCH_NOMEDIADIR _IOR(ACM_MAGIC, 10, struct acm_fwk_nomediadir) -#define ACM_CMD_MAXNR 10 - -#define ACM_HASHTBL_SZ 512 -#define HASHTBL_MAX_SZ 4096 -#define ACM_PATH_MAX 1024 -#define DEPTH_INIT (-1) -#define ACM_DIR_MAX 64 -#define ACM_DIR_LIST_MAX 1024 -#define ACM_DNAME_MAX 256 -#define ACM_LIST_MAX_NODES 2048 -#define MAX_CACHED_DELETE_LOG 3 -#define DELETE_LOG_UPLOAD_INTERVAL_MS 1000 - -#define PATH_PREFIX_MEDIA "/media" -#define PATH_PREFIX_STORAGE_EMULATED "/storage/emulated" -#define PATH_UNKNOWN "unknown_path" - -#define UEVENT_KEY_STR_MAX 16 -#define ENV_PKGNAME_MAX (UEVENT_KEY_STR_MAX + ACM_PKGNAME_LEN_MAX) -#define ENV_PATH_MAX 1024 -#define ENV_NR_STR_MAX 32 -#define ENV_DEPTH_STR_MAX 32 -#define ENV_FILE_TYPE_STR_MAX 32 - -#define ERR_PATH_MAX_DENTRIES 6 -#define ERR_PATH_LAST_DENTRY 0 - -#define ACM_HASH_LEFT_SHIFT 4 -#define ACM_HASH_MASK 0xF0000000L -#define ACM_HASH_RESULT_MASK 0x7FFFFFFF -#define ACM_HASH_RIGHT_SHIFT 24 - -#define DEL_ALLOWED 0 -#define ACM_SUCCESS 0 - -#define CRT_NOT_ALLOWED 0 -#define CRT_ALLOWED 1 - -#define DIR_NONEED_FLAG 0 -#define DIR_NEED_FLAG 1 - -#define ACM_PKGNAME_LEN_MAX 100 -#define UID_THRESHOLD 10000 - -/* package name received from framework */ -struct acm_fwk_pkg { - unsigned long long flag; - char pkgname[ACM_PKGNAME_LEN_MAX]; -}; - -/* directory received from framework */ -struct acm_fwk_dir { - unsigned long long flag; - char dir[ACM_DIR_MAX]; -}; - -/* nomedia directory received from framework */ -struct acm_fwk_nomediadir { - char dir[ACM_DIR_MAX]; -}; - -/* white list node */ -struct acm_hnode { - struct hlist_node hnode; - struct acm_fwk_pkg afp; -}; - -/* a hash table for white list */ -struct acm_htbl { - struct hlist_head *head; - spinlock_t spinlock; - int nr_nodes; -}; - -/* data node for directory */ -struct acm_dnode { - struct list_head lnode; - struct acm_fwk_dir afd; -}; - -/* data node for nomedia directory */ -struct acm_ndnode { - struct list_head lnode; - struct acm_fwk_nomediadir afnd; -}; - -/* data node for framework and DMD */ -struct acm_lnode { - struct list_head lnode; - char pkgname[ACM_PKGNAME_LEN_MAX]; - uid_t uid; - char path[ACM_PATH_MAX]; - int file_type; - int depth; - int op; - /* - * Number of deleted files in a period of time, - * only used in cache - */ - int nr; -}; - -struct acm_list { - struct list_head head; - unsigned long nr_nodes; - spinlock_t spinlock; -}; - -struct acm_cache { - struct acm_lnode cache[MAX_CACHED_DELETE_LOG]; - int count; -}; - -struct acm_env { - char pkgname[ENV_PKGNAME_MAX]; - char uid[ENV_NR_STR_MAX]; - char path[ENV_PATH_MAX]; - char depth[ENV_DEPTH_STR_MAX]; - char file_type[ENV_FILE_TYPE_STR_MAX]; - char nr[ENV_NR_STR_MAX]; - char op[ENV_NR_STR_MAX]; - char *envp[UEVENT_NUM_ENVP]; -}; - -#endif /* __DRIVERS_SOC_OPLUS_SYSTEM_ACM_H__ */ diff --git a/drivers/soc/oplus/system/dump_device_info/Kconfig b/drivers/soc/oplus/system/dump_device_info/Kconfig deleted file mode 100755 index e84b61ff4f23..000000000000 --- a/drivers/soc/oplus/system/dump_device_info/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_DUMP_DEVICE_INFO - bool "config dump device info" - default n - help - define this config to dump device info. diff --git a/drivers/soc/oplus/system/dump_device_info/Makefile b/drivers/soc/oplus/system/dump_device_info/Makefile deleted file mode 100755 index ac8ed13a7a39..000000000000 --- a/drivers/soc/oplus/system/dump_device_info/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO) += dump_device_info.o diff --git a/drivers/soc/oplus/system/dump_device_info/dump_device_info.c b/drivers/soc/oplus/system/dump_device_info/dump_device_info.c deleted file mode 100755 index e9c3377c1317..000000000000 --- a/drivers/soc/oplus/system/dump_device_info/dump_device_info.c +++ /dev/null @@ -1,263 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#endif -#include -#include "../../../fs/pstore/internal.h" -#include -#include - - -#define SMEM_CHIP_INFO 137 - -extern struct pstore_info *psinfo; - -static char project_version[8]; -static char pcb_version[8]; -static char rf_version[8]; - -#define BUILD_PROP "/my_product/build.prop" -char build_version_key[24] = "ro.build.version.ota="; -char build_version[64]; - -static char buf[8192] = {'\0'}; - - -#define GET_VERSION_INFO_TIMEOUT_MS 150000 - -struct get_version_info { - struct delayed_work version_info_work; - wait_queue_head_t info_thread_wq; -}; - -struct get_version_info g_version_info; - -#define MAX_ITEM 2 -#define MAX_LENGTH 32 - -enum { - serialno = 0, - platform_name, -}; - - -char oem_serialno[16]; -char oem_platform_name[16]; - -const char cmdline_info[MAX_ITEM][MAX_LENGTH] = { - "androidboot.serialno=", - "androidboot.platform_name=", -}; - -static int __init device_info_init(void) -{ - int i, j; - char *substr, *target_str; - - for (i = 0; i < MAX_ITEM; i++) { - substr = strstr(boot_command_line, cmdline_info[i]); - - if (substr != NULL) { - substr += strlen(cmdline_info[i]); - - } else { - continue; - } - - if (i == serialno) { - target_str = oem_serialno; - - } else if (i == platform_name) { - target_str = oem_platform_name; - } - - for (j = 0; substr[j] != ' '; j++) { - target_str[j] = substr[j]; - } - - target_str[j] = '\0'; - } - - return 1; -} - -/*device info init to black*/ -static void pstore_device_info_init(void) -{ - size_t oldsize; - size_t size = 0; - - struct ramoops_context *cxt = psinfo->data; - struct pstore_record record; - - if (psinfo == NULL) { - return; - } - - size = cxt->device_info_size; - - pstore_record_init(&record, psinfo); - record.type = PSTORE_TYPE_DEVICE_INFO; - record.buf = psinfo->buf; - record.size = size; - - oldsize = psinfo->bufsize; - - - if (size > psinfo->bufsize) { - size = psinfo->bufsize; - } - - memset(record.buf, ' ', size); - psinfo->write(&record); - - psinfo->bufsize = oldsize; -} -static void pstore_write_device_info(const char *s, unsigned int c) -{ - const char *e = s + c; - - if (psinfo == NULL) { - return; - } - - while (s < e) { - struct pstore_record record; - pstore_record_init(&record, psinfo); - record.type = PSTORE_TYPE_DEVICE_INFO; - - if (c > psinfo->bufsize) { - c = psinfo->bufsize; - } - - record.buf = (char *)s; - record.size = c; - psinfo->write(&record); - s += c; - c = e - s; - } -} - -static void board_hw_info_init() -{ - scnprintf(pcb_version, sizeof(pcb_version), "%d", get_PCB_Version()); - scnprintf(project_version, sizeof(project_version), "%d", get_project()); - scnprintf(rf_version, sizeof(rf_version), "%d", get_Modem_Version()); -} - -static void write_device_info(const char *key, const char *value) -{ - pstore_write_device_info(key, strlen(key)); - pstore_write_device_info(": ", 2); - pstore_write_device_info(value, strlen(value)); - pstore_write_device_info("\r\n", 2); -} - - -static void get_version_info_handle(struct work_struct *work) -{ - struct file *fp; - int i = 0; - ssize_t len = 0; - char *substr; - int old_fs; - loff_t pos; - printk("[get_version_info_handle]\n"); - fp = filp_open(BUILD_PROP, O_RDONLY, 0600); - - if (IS_ERR(fp)) { - pr_info("open %s file fail fp:%p %d \n", BUILD_PROP, fp, PTR_ERR(fp)); - goto out; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - - pos = 0; - len = vfs_read(fp, buf, sizeof(buf), &pos); - - if (len < 0) { - pr_info("read %s file error\n", BUILD_PROP); - } - - substr = strstr(buf, build_version_key); - pr_info("\n"); - pr_info("build_version:-%s--\n", substr); - - if (substr != NULL) { - while (*substr != '\n') { - if (*substr == '=') { - break; - } - - substr++; - } - - while (*(++substr) != '\n') { - build_version[i] = *(substr); - i++; - } - } - - pr_info("build_version_value:%s--\n", build_version); - write_device_info("software version", build_version); - - -out: - - if (IS_ERR(fp)) { - pr_info("open is failed, cannot to read\n"); - - } else { - filp_close(fp, NULL); - set_fs(old_fs); - } -} - -static int __init init_device_info(void) -{ - printk("pstore device info init"); - pstore_device_info_init(); - board_hw_info_init(); - device_info_init(); - - write_device_info("project version", project_version); - write_device_info("pcb version", pcb_version); - write_device_info("rf version", rf_version); - write_device_info("soc version", oem_platform_name); - write_device_info("serial no", oem_serialno); - - write_device_info("kernel version", linux_banner); - write_device_info("boot command", saved_command_line); - - INIT_DELAYED_WORK(&g_version_info.version_info_work, get_version_info_handle); - schedule_delayed_work(&g_version_info.version_info_work, - msecs_to_jiffies(GET_VERSION_INFO_TIMEOUT_MS)); - - return 0; -} - -late_initcall(init_device_info); - -void save_dump_reason_to_device_info(char *reason) -{ - write_device_info("dump reason is ", reason); -} -EXPORT_SYMBOL(save_dump_reason_to_device_info); - diff --git a/drivers/soc/oplus/system/dump_reason/Kconfig b/drivers/soc/oplus/system/dump_reason/Kconfig deleted file mode 100755 index 1762bd01e94e..000000000000 --- a/drivers/soc/oplus/system/dump_reason/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_DUMP_REASON - bool "config oplus dump reason" - default n - help - define this config to dump reason. diff --git a/drivers/soc/oplus/system/dump_reason/Makefile b/drivers/soc/oplus/system/dump_reason/Makefile deleted file mode 100755 index 30830c595c8c..000000000000 --- a/drivers/soc/oplus/system/dump_reason/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_DUMP_REASON) += dump_reason.o diff --git a/drivers/soc/oplus/system/dump_reason/dump_reason.c b/drivers/soc/oplus/system/dump_reason/dump_reason.c deleted file mode 100755 index d6ddadac08c0..000000000000 --- a/drivers/soc/oplus/system/dump_reason/dump_reason.c +++ /dev/null @@ -1,101 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : dump_reason.c -** Description : dump reason feature -** Version : 1.0 -******************************************************************/ - -#include -#include -#include -#include -#include - -static char caller_function_name[KSYM_SYMBOL_LEN]; -static struct dump_info *dp_info; - -char *parse_function_builtin_return_address(unsigned long function_address) -{ - char *cur = caller_function_name; - - if (!function_address) { - return NULL; - } - - sprint_symbol(caller_function_name, function_address); - strsep(&cur, "+"); - return caller_function_name; -} -EXPORT_SYMBOL(parse_function_builtin_return_address); - -void save_dump_reason_to_smem(char *info, char *function_name) -{ - int strlinfo = 0, strlfun = 0; - size_t size; - static int flag = 0; - - /* Make sure save_dump_reason_to_smem() is not - called infinite times by nested panic caller fns etc*/ - if (flag > 1) { - return; - } - - dp_info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_DUMP_INFO, &size); - - if (IS_ERR_OR_NULL(dp_info)) { - pr_debug("%s: get dp_info failure\n", __func__); - return; - - } else { - pr_debug("%s: info : %s\n", __func__, info); - - strlinfo = strlen(info) + 1; - strlfun = strlen(function_name) + 1; - strlinfo = strlinfo < DUMP_REASON_SIZE ? strlinfo : DUMP_REASON_SIZE; - strlfun = strlfun < DUMP_REASON_SIZE ? strlfun : DUMP_REASON_SIZE; - - if ((strlen(dp_info->dump_reason) + strlinfo) < DUMP_REASON_SIZE) { - strncat(dp_info->dump_reason, info, strlinfo); - } - - if (function_name != NULL && - ((strlen(dp_info->dump_reason) + strlfun + sizeof("\r\n") + 1) < - DUMP_REASON_SIZE)) { - strncat(dp_info->dump_reason, "\r\n", sizeof("\r\n")); - strncat(dp_info->dump_reason, function_name, strlfun); - } - - pr_debug("\r%s: dump_reason : %s strl=%d function caused panic :%s strl1=%d \n", - __func__, - dp_info->dump_reason, strlinfo, function_name, strlfun); - save_dump_reason_to_device_info(dp_info->dump_reason); - flag++; - } -} - -EXPORT_SYMBOL(save_dump_reason_to_smem); - -void dump_reason_init_smem(void) -{ - int ret; - - ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_DUMP_INFO, - sizeof(struct dump_info)); - - if (ret < 0 && ret != -EEXIST) { - pr_err("%s:unable to allocate dp_info \n", __func__); - return; - } -} - -static int __init dump_reason_init(void) -{ - dump_reason_init_smem(); - return 0; -} - -module_init(dump_reason_init); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/feedback/Kconfig b/drivers/soc/oplus/system/feedback/Kconfig deleted file mode 100755 index 7aae6099a55d..000000000000 --- a/drivers/soc/oplus/system/feedback/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_FEEDBACK - tristate "Oplus system feedback" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to init oplus system feedback. diff --git a/drivers/soc/oplus/system/feedback/Makefile b/drivers/soc/oplus/system/feedback/Makefile deleted file mode 100755 index 014c15757d31..000000000000 --- a/drivers/soc/oplus/system/feedback/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -obj-$(CONFIG_OPLUS_FEATURE_FEEDBACK) += kernel_fb.o -else -ifeq ($(CONFIG_OPLUS_FEATURE_FEEDBACK), y) -obj-$(CONFIG_OPLUS_FEATURE_FEEDBACK) += kernel_fb.o -endif -ifeq ($(CONFIG_OPLUS_FEATURE_FEEDBACK), m) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ -obj-$(CONFIG_OPLUS_FEATURE_FEEDBACK) += gki/kernel_fb.o -endif -endif diff --git a/drivers/soc/oplus/system/feedback/gki/Kconfig b/drivers/soc/oplus/system/feedback/gki/Kconfig deleted file mode 100755 index 317ef1dc697d..000000000000 --- a/drivers/soc/oplus/system/feedback/gki/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_FEEDBACK - tristate "Oplus system feedback" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to init oplus system feedback. - - diff --git a/drivers/soc/oplus/system/feedback/gki/kernel_fb.c b/drivers/soc/oplus/system/feedback/gki/kernel_fb.c deleted file mode 100755 index f2a0287d12d6..000000000000 --- a/drivers/soc/oplus/system/feedback/gki/kernel_fb.c +++ /dev/null @@ -1,697 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : kerbel_fb.c -** Description : BSP kevent fb data -** Version : 1.0 -******************************************************************/ -#define pr_fmt(fmt) "" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "oplus_fb_guard_netlink.h" -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -/*Peng.Yao, 2021/11/08, meta or factory mode not run kernel_fb*/ -#include "mtk_boot_common.h" -#include -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ - -#define MAX_LOG (31) -#define MAX_ID (19) -#define LIST_MAX (50) -#define DELAY_REPORT_US (30*1000*1000) -#define MAX_BUF_LEN (2048) -#define CAUSENAME_SIZE 128 - -struct packets_pool { - struct list_head packets; - struct task_struct *flush_task; - spinlock_t wlock; - bool wlock_init; -}; - -struct packet { - struct kernel_packet_info *pkt; - struct list_head list; - int retry; -}; - -static struct packets_pool *g_pkts = NULL; - -static char *const _tag[FB_MAX_TYPE + 1] = { - "fb_stability", - "fb_fs", - "fb_storage", - "PSW_BSP_SENSOR", - "fb_boot", -}; -static char fid[CAUSENAME_SIZE]={""}; - -/* feedback reboot monitor start */ -#undef ARRAY_SIZE -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - -#define INT_MAX ((int)(~0U >> 1)) - -static char *fb_reasons[] = { - "dm-verity device corrupted", -}; - -static int fb_reboot_check(struct notifier_block *nb, - unsigned long action, void *cmd) -{ - int i; - if (cmd != NULL) { - for (i = 0; i < ARRAY_SIZE(fb_reasons); ++i) { - if (strstr(cmd, fb_reasons[i])) { - panic(cmd); - } - } - } - else { - printk(KERN_WARNING "feedback: cmd pointer is null.\n"); - return NOTIFY_OK; - } - - printk(KERN_INFO "feedback: normal reboot\n"); - return NOTIFY_OK; -} - -struct notifier_block fb_reboot_nb = { - .notifier_call = fb_reboot_check, - .priority = INT_MAX, -}; - -static void fb_reboot_monitor_init(void) -{ - register_reboot_notifier(&fb_reboot_nb); - return; -} -/* feedback reboot monitor done */ - -static volatile unsigned int kevent_pid; - -#define OPLUS_KEVENT_MAX_UP_PALOAD_LEN 2048 -#define OPLUS_KEVENT_TEST_TAG "test_event" -#define OPLUS_KEVENT_TEST_ID "test_check" - -static int fb_keventupload_sendpid_cmd(struct sk_buff *skb, - struct genl_info *info) -{ - struct nlattr *na = NULL; - unsigned int *p_data = NULL; - - pr_info(" kernel recv cmd \n"); - - if (info->attrs[FB_GUARD_CMD_ATTR_MSG]) { - na = info->attrs[FB_GUARD_CMD_ATTR_MSG]; - /*PRINT_FORMAT(nla_data(na), nla_len(na));*/ - pr_info(" nla_len(na) is %d \n", nla_len(na)); - p_data = nla_data(na); - kevent_pid = *p_data; - pr_info(" kevent_pid is 0x%x \n", kevent_pid); - } - - return 0; -} - -static int fb_keventupload_test_upload(struct sk_buff *skb, - struct genl_info *info) -{ - int ret = 0; - struct nlattr *na = NULL; - struct msg_test_upload *p_test_upload = NULL; - struct kernel_packet_info *p_dcs_event = NULL; - size_t data_len = 0; - - pr_info(" fb_keventupload_test_upload \n"); - - if (info->attrs[FB_GUARD_CMD_ATTR_OPT]) { - na = info->attrs[FB_GUARD_CMD_ATTR_OPT]; - /*PRINT_FORMAT(nla_data(na), nla_len(na));*/ - pr_info(" nla_len(na) is %d \n", nla_len(na)); - p_test_upload = (struct msg_test_upload *)nla_data(na); - kevent_pid = p_test_upload->pro_pid; - pr_info(" p_test_upload->pro_pid is %u, p_test_upload->val is %u, \n", - p_test_upload->pro_pid, p_test_upload->val); - - - if ((p_test_upload->val) > OPLUS_KEVENT_MAX_UP_PALOAD_LEN) { - pr_err("[ERROR]:p_test_upload->val too long \n", p_test_upload->val); - return -1; - } - - data_len = p_test_upload->val + sizeof(struct kernel_packet_info); - pr_info(" data_len is %u\n", data_len); - p_dcs_event = (struct kernel_packet_info *)kmalloc(data_len, GFP_ATOMIC); - - if (NULL == p_dcs_event) { - pr_err("[ERROR]:kmalloc for p_dcs_event err\n"); - return -1; - } - - pr_info(" p_dcs_event kmalloc ok .\n"); - - memset((unsigned char *)p_dcs_event, 0x00, data_len); - p_dcs_event->type = 1; - strncpy(p_dcs_event->log_tag, OPLUS_KEVENT_TEST_TAG, - sizeof(p_dcs_event->log_tag)); - strncpy(p_dcs_event->event_id, OPLUS_KEVENT_TEST_ID, - sizeof(p_dcs_event->event_id)); - p_dcs_event->payload_length = p_test_upload->val; - memset(p_dcs_event->payload, 0xFF, p_test_upload->val); - - ret = fb_kevent_send_to_user(p_dcs_event); - - if (ret) { - pr_err("[ERROR]:fb_kevent_send_to_user err, ret is %d \n", ret); - } - - kfree(p_dcs_event); - } - - return 0; -} - - -static const struct genl_ops oplus_fb_kevent_upload_ops[] = { - { - .cmd = FB_GUARD_CMD_GENL_SENDPID, - .doit = fb_keventupload_sendpid_cmd, - /*.policy = taskstats_cmd_get_policy,*/ - /*.flags = GENL_ADMIN_PERM,*/ - }, - { - .cmd = FB_GUARD_CMD_GENL_TEST_UPLOAD, - .doit = fb_keventupload_test_upload, - /*.dumpit = taskstats2_foreach,*/ - /*.policy = taskstats_cmd_get_policy,*/ - }, -}; - -#ifdef CONFIG_OPLUS_KEVENT_UPLOAD -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) && !IS_ENABLED(CONFIG_OPLUS_KERNEL_SECURE_GUARD) -int kevent_send_to_user(struct kernel_packet_info *userinfo) {return 0;} -#endif -#endif - -static struct genl_family oplus_fb_kevent_family __ro_after_init = { - .name = OPLUS_FB_GUARD_PROTOCAL_NAME, - .version = OPLUS_FB_GUARD_GENL_VERSION, - .maxattr = FB_GUARD_CMD_ATTR_MAX, - .module = THIS_MODULE, - .ops = oplus_fb_kevent_upload_ops, - .n_ops = ARRAY_SIZE(oplus_fb_kevent_upload_ops), -}; - - -static inline int genl_msg_prepare_usr_msg(unsigned char cmd, size_t size, - pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_KERNEL); - - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_fb_kevent_family, 0, cmd); - - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, - int len) -{ - int ret; - - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - - -int fb_kevent_send_to_user(struct kernel_packet_info *userinfo) -{ - int ret = 0; - struct sk_buff *skbuff = NULL; - void *head = NULL; - size_t data_len = 0; - - /*max_len */ - pr_info(" fb_kevent_send_to_user\n"); - - if(!userinfo) { - pr_err("[ERROR]:fb_kevent_send_to_user: userinfo is null\n"); - ret = -1; - return ret; - } - - if (userinfo->payload_length >= OPLUS_KEVENT_MAX_UP_PALOAD_LEN) { - pr_err("[ERROR]:fb_kevent_send_to_user: payload_length out of range\n"); - ret = -1; - return ret; - } - - data_len = userinfo->payload_length + sizeof(struct kernel_packet_info); - pr_info(" data_len is %u\n", data_len); - - ret = genl_msg_prepare_usr_msg(FB_GUARD_CMD_GENL_UPLOAD, data_len, kevent_pid, - &skbuff); - - if (ret) { - pr_err("[ERROR]:genl_msg_prepare_usr_msg err, ret is %d \n"); - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, FB_GUARD_CMD_ATTR_MSG, userinfo, data_len); - - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - - genlmsg_end(skbuff, head); - - ret = genlmsg_unicast(&init_net, skbuff, kevent_pid); - - if (ret < 0) { - return ret; - } - - return 0; -} - -EXPORT_SYMBOL(fb_kevent_send_to_user); - - - -/* -int kevent_send_to_user(struct kernel_packet_info *userinfo) -{ - return fb_kevent_send_to_user(userinfo); -}*/ - - -static struct packet *package_alloc( - fb_tag tag_id, const char *event_id, unsigned char *payload) -{ - struct packet *packet; - struct kernel_packet_info *pkt; - char *tmp = payload; - - if (tag_id > FB_MAX_TYPE || !event_id || !payload || !_tag[tag_id]) { - return NULL; - } - - packet = (struct packet *)kmalloc(sizeof(struct packet), GFP_ATOMIC); - - if (!packet) { - return NULL; - } - - /*presplit payload, '\n' is not allowed*/ - for (; *tmp != '\0'; tmp++) { - if (*tmp == '\n') { - *tmp = '\0'; - break; - } - } - - pkt = (struct kernel_packet_info *) - kzalloc(sizeof(struct kernel_packet_info) + strlen(payload) + 1, GFP_ATOMIC); - - if (!pkt) { - kfree(packet); - return NULL; - } - - packet->pkt = pkt; - packet->retry = 4; /* retry 4 times at most*/ - pkt->type = 1; /*means only string is available*/ - - memcpy(pkt->log_tag, _tag[tag_id], - strlen(_tag[tag_id]) > MAX_LOG ? MAX_LOG : strlen(_tag[tag_id])); - memcpy(pkt->event_id, event_id, - strlen(event_id) > MAX_ID ? MAX_ID : strlen(event_id)); - pkt->payload_length = strlen(payload) + 1; - memcpy(pkt->payload, payload, strlen(payload)); - - return packet; -} - -static void package_release(struct packet *packet) -{ - if (packet) { - kfree(packet->pkt); - kfree(packet); - } -} - -int oplus_kevent_fb(fb_tag tag_id, const char *event_id, unsigned char *payload) -{ - struct packet *packet; - unsigned long flags; - - /*ignore before wlock init*/ - if (!g_pkts || !g_pkts->wlock_init) { - return -ENODEV; - } - - packet = package_alloc(tag_id, event_id, payload); - - if (!packet) { - return -ENODEV; - } - - spin_lock_irqsave(&g_pkts->wlock, flags); - list_add(&packet->list, &g_pkts->packets); - spin_unlock_irqrestore(&g_pkts->wlock, flags); - - wake_up_process(g_pkts->flush_task); - - return 0; -} -EXPORT_SYMBOL(oplus_kevent_fb); - - - -static unsigned int BKDRHash(char *str, unsigned int len) -{ - unsigned int seed = 131; - /* 31 131 1313 13131 131313 etc.. */ - unsigned int hash = 0; - unsigned int i = 0; - - if (str == NULL) { - return 0; - } - - for (i = 0; i < len; str++, i++) { - hash = (hash * seed) + (*str); - } - - return hash; -} - -int oplus_kevent_fb_str(fb_tag tag_id, const char *event_id, unsigned char *str) -{ - unsigned char payload[1024] = {0x00}; - unsigned int hashid = 0; - int ret = 0; - char strHashSource[CAUSENAME_SIZE] = {0x00}; - /*struct timespec64 ts64;*/ - unsigned long rdm = 0; - /*ktime_get_coarse_real_ts64(&ts64);*/ - get_random_bytes(&rdm, sizeof(unsigned long)); - snprintf(strHashSource, CAUSENAME_SIZE, "%s %lu", str, rdm); - hashid = BKDRHash(strHashSource, strlen(strHashSource)); - memset(fid, 0 , CAUSENAME_SIZE); - snprintf(fid, CAUSENAME_SIZE, "%u", hashid); - ret = snprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%s$$detailData@@%s", fid, str, - _tag[tag_id]); - pr_info("payload= %s, ret=%d\n", payload, ret); - return oplus_kevent_fb(tag_id, event_id, payload); -} -EXPORT_SYMBOL(oplus_kevent_fb_str); - - -/*thread to deal with the buffer list*/ -static int fb_flush_thread(void *arg) -{ - struct packets_pool *pkts_pool = (struct packets_pool *)arg; - struct packet *tmp, *s; - unsigned long flags; - struct list_head list_tmp; - - while (!kthread_should_stop()) { - if (list_empty(&pkts_pool->packets)) { - set_current_state(TASK_INTERRUPTIBLE); - schedule(); - } - - set_current_state(TASK_RUNNING); - - spin_lock_irqsave(&pkts_pool->wlock, flags); - INIT_LIST_HEAD(&list_tmp); - list_splice_init(&pkts_pool->packets, &list_tmp); - spin_unlock_irqrestore(&pkts_pool->wlock, flags); - - list_for_each_entry_safe(s, tmp, &list_tmp, list) { - if (s->pkt) { - if (fb_kevent_send_to_user(s->pkt) && s->retry) { - pr_debug("failed to send feedback %s\n", s->pkt->log_tag); - s->retry--; - spin_lock_irqsave(&pkts_pool->wlock, flags); - list_add(&s->list, &pkts_pool->packets); - spin_unlock_irqrestore(&pkts_pool->wlock, flags); - - } else { - package_release(s); - } - - msleep(20); - } - } - } - - return 0; -} - -/* -* @format: tag_id:event_id:payload -*/ -static ssize_t kernel_fb_write(struct file *file, - const char __user *buf, - size_t count, - loff_t *lo) -{ - char *r_buf; - int tag_id = 0; - char event_id[MAX_ID] = {0}; - int idx1 = 0, idx2 = 0; - int len; - - r_buf = (char *)kzalloc(MAX_BUF_LEN, GFP_KERNEL); - - if (!r_buf) { - return count; - } - - if (copy_from_user(r_buf, buf, MAX_BUF_LEN > count ? count : MAX_BUF_LEN)) { - goto exit; - } - - r_buf[MAX_BUF_LEN - 1] = '\0'; /*make sure last bype is eof*/ - len = strlen(r_buf); - - tag_id = r_buf[0] - '0'; - - if (tag_id > FB_MAX_TYPE || tag_id < 0) { - goto exit; - } - - while (idx1 < len) { - if (r_buf[idx1++] == ':') { - idx2 = idx1; - - while (idx2 < len) { - if (r_buf[idx2++] == ':') { - break; - } - } - - break; - } - } - - if (idx1 == len || idx2 == len) { - goto exit; - } - - memcpy(event_id, &r_buf[idx1], - idx2 - idx1 - 1 > MAX_ID ? MAX_ID : idx2 - idx1 - 1); - event_id[MAX_ID - 1] = '\0'; - - oplus_kevent_fb(tag_id, event_id, r_buf + idx2); - -exit: - - kfree(r_buf); - return count; -} - -static ssize_t kernel_fb_read(struct file *file, - char __user *buf, - size_t count, - loff_t *ppos) -{ - return count; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static const struct proc_ops kern_fb_fops = { - .proc_write = kernel_fb_write, - .proc_read = kernel_fb_read, - .proc_open = simple_open, -}; -#else -static const struct file_operations kern_fb_fops = { - .write = kernel_fb_write, - .read = kernel_fb_read, - .open = simple_open, - .owner = THIS_MODULE, -}; -#endif - -static ssize_t crash_cause_read(struct file *file, - char __user *buf, - size_t count, - loff_t *off) -{ - char page[512] = {0x00}; - int len = 0; - - len = snprintf(page, sizeof(page), "%s", fid); - len = simple_read_from_buffer(buf, count, off, page, strlen(page)); - return len; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static const struct proc_ops crash_cause_fops = { - .proc_read = crash_cause_read, - .proc_open = simple_open, -}; -#else -static const struct file_operations crash_cause_fops = { - .read = crash_cause_read, - .open = simple_open, - .owner = THIS_MODULE, -}; -#endif - -static int __init kernel_fb_init(void) -{ - struct proc_dir_entry *d_entry = NULL; - int ret = 0; - - #ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /*Peng.Yao, 2021/11/08, meta or factory mode not run kernel_fb*/ - int boot_mode = get_boot_mode(); - - if (boot_mode == META_BOOT || boot_mode == FACTORY_BOOT) - return ret; - #endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ - - pr_err("%s\n", __func__); - - g_pkts = (struct packets_pool *)kzalloc(sizeof(struct packets_pool), - GFP_KERNEL); - - if (!g_pkts) { - ret = -ENOMEM; - goto failed_kzalloc; - } - - /*register gen_link family*/ - ret = genl_register_family(&oplus_fb_kevent_family); - - if (ret) { - pr_err("failed genl_register_family"); - goto failed_genl_register_family; - } - - INIT_LIST_HEAD(&g_pkts->packets); - spin_lock_init(&g_pkts->wlock); - - g_pkts->flush_task = kthread_create(fb_flush_thread, g_pkts, "fb_flush"); - - if (!g_pkts->flush_task) { - pr_err("failed to kthread_create fb_flush\n"); - ret = -ENODEV; - goto failed_kthread_create; - } - - g_pkts->wlock_init = true; - - d_entry = proc_create_data("kern_fb", 0664, NULL, &kern_fb_fops, NULL); - - if (!d_entry) { - pr_err("failed to create kern_fb node\n"); - ret = -ENODEV; - goto failed_proc_create_data; - } - - d_entry = proc_create_data("crash_cause", 0664, NULL, &crash_cause_fops, NULL); - - if (!d_entry) { - pr_err("failed to create crash_cause node\n"); - ret = -ENODEV; - goto failed_proc_create_data; - } - - fb_reboot_monitor_init(); - - pr_info("kernel_fb_init probe ok\n"); - return 0; - -failed_proc_create_data: -failed_kthread_create: - genl_unregister_family(&oplus_fb_kevent_family); -failed_genl_register_family: - kfree(g_pkts->flush_task); -failed_kzalloc: - return ret; -} - -static void __exit kernel_fb_exit() -{ - genl_unregister_family(&oplus_fb_kevent_family); - kfree(g_pkts->flush_task); - return; -} - -/*core_initcall(kernel_fb_init);*/ - -module_init(kernel_fb_init); -module_exit(kernel_fb_exit); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/feedback/kernel_fb.c b/drivers/soc/oplus/system/feedback/kernel_fb.c deleted file mode 100755 index c0f766348a2e..000000000000 --- a/drivers/soc/oplus/system/feedback/kernel_fb.c +++ /dev/null @@ -1,687 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : kerbel_fb.c -** Description : BSP kevent fb data -** Version : 1.0 -******************************************************************/ -#define pr_fmt(fmt) "" fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include "oplus_fb_guard_netlink.h" - - -#define MAX_LOG (31) -#define MAX_ID (19) -#define LIST_MAX (50) -#define DELAY_REPORT_US (30*1000*1000) -#define MAX_BUF_LEN (2048) -#define CAUSENAME_SIZE 128 - -typedef struct bsp_fb_work_struct { - struct delayed_work dwork; - spinlock_t lock; - int tag_id; - char event_id[15]; - char reason[256U]; -} bsp_fb_work_struct; - -static bsp_fb_work_struct *bsp_fb_dwork = NULL; -static struct workqueue_struct *bsp_kevent_wq = NULL; - -struct packets_pool { - struct list_head packets; - struct task_struct *flush_task; - spinlock_t wlock; - bool wlock_init; -}; - -struct packet { - struct kernel_packet_info *pkt; - struct list_head list; - int retry; -}; - -static struct packets_pool *g_pkts = NULL; - -static char *const _tag[FB_MAX_TYPE + 1] = { - "fb_stability", - "fb_fs", - "fb_storage", - "PSW_BSP_SENSOR", - "fb_boot", -}; -static char fid[CAUSENAME_SIZE]={""}; - - -static volatile unsigned int kevent_pid; - -#define OPLUS_KEVENT_MAX_UP_PALOAD_LEN 2048 -#define OPLUS_KEVENT_TEST_TAG "test_event" -#define OPLUS_KEVENT_TEST_ID "test_check" - -static int fb_keventupload_sendpid_cmd(struct sk_buff *skb, - struct genl_info *info) -{ - struct nlattr *na = NULL; - unsigned int *p_data = NULL; - - pr_info(" kernel recv cmd \n"); - - if (info->attrs[FB_GUARD_CMD_ATTR_MSG]) { - na = info->attrs[FB_GUARD_CMD_ATTR_MSG]; - /*PRINT_FORMAT(nla_data(na), nla_len(na));*/ - pr_info(" nla_len(na) is %d \n", nla_len(na)); - p_data = nla_data(na); - kevent_pid = *p_data; - pr_info(" kevent_pid is 0x%x \n", kevent_pid); - } - - return 0; -} - -static int fb_keventupload_test_upload(struct sk_buff *skb, - struct genl_info *info) -{ - int ret = 0; - struct nlattr *na = NULL; - struct msg_test_upload *p_test_upload = NULL; - struct kernel_packet_info *p_dcs_event = NULL; - size_t data_len = 0; - - pr_info(" fb_keventupload_test_upload \n"); - - if (info->attrs[FB_GUARD_CMD_ATTR_OPT]) { - na = info->attrs[FB_GUARD_CMD_ATTR_OPT]; - /*PRINT_FORMAT(nla_data(na), nla_len(na));*/ - pr_info(" nla_len(na) is %d \n", nla_len(na)); - p_test_upload = (struct msg_test_upload *)nla_data(na); - kevent_pid = p_test_upload->pro_pid; - pr_info(" p_test_upload->pro_pid is %u, p_test_upload->val is %u, \n", - p_test_upload->pro_pid, p_test_upload->val); - - - if ((p_test_upload->val) > OPLUS_KEVENT_MAX_UP_PALOAD_LEN) { - pr_err("[ERROR]:p_test_upload->val too long \n", p_test_upload->val); - return -1; - } - - data_len = p_test_upload->val + sizeof(struct kernel_packet_info); - pr_info(" data_len is %u\n", data_len); - p_dcs_event = (struct kernel_packet_info *)kmalloc(data_len, GFP_ATOMIC); - - if (NULL == p_dcs_event) { - pr_err("[ERROR]:kmalloc for p_dcs_event err\n"); - return -1; - } - - pr_info(" p_dcs_event kmalloc ok .\n"); - - memset((unsigned char *)p_dcs_event, 0x00, data_len); - p_dcs_event->type = 1; - strncpy(p_dcs_event->log_tag, OPLUS_KEVENT_TEST_TAG, - sizeof(p_dcs_event->log_tag)); - strncpy(p_dcs_event->event_id, OPLUS_KEVENT_TEST_ID, - sizeof(p_dcs_event->event_id)); - p_dcs_event->payload_length = p_test_upload->val; - memset(p_dcs_event->payload, 0xFF, p_test_upload->val); - - ret = fb_kevent_send_to_user(p_dcs_event); - - if (ret) { - pr_err("[ERROR]:fb_kevent_send_to_user err, ret is %d \n", ret); - } - - kfree(p_dcs_event); - } - - return 0; -} - - -static const struct genl_ops oplus_fb_kevent_upload_ops[] = { - { - .cmd = FB_GUARD_CMD_GENL_SENDPID, - .doit = fb_keventupload_sendpid_cmd, - /*.policy = taskstats_cmd_get_policy,*/ - /*.flags = GENL_ADMIN_PERM,*/ - }, - { - .cmd = FB_GUARD_CMD_GENL_TEST_UPLOAD, - .doit = fb_keventupload_test_upload, - /*.dumpit = taskstats2_foreach,*/ - /*.policy = taskstats_cmd_get_policy,*/ - }, -}; - -static struct genl_family oplus_fb_kevent_family __ro_after_init = { - .name = OPLUS_FB_GUARD_PROTOCAL_NAME, - .version = OPLUS_FB_GUARD_GENL_VERSION, - .maxattr = FB_GUARD_CMD_ATTR_MAX, - .module = THIS_MODULE, - .ops = oplus_fb_kevent_upload_ops, - .n_ops = ARRAY_SIZE(oplus_fb_kevent_upload_ops), -}; - - -static inline int genl_msg_prepare_usr_msg(unsigned char cmd, size_t size, - pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_KERNEL); - - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_fb_kevent_family, 0, cmd); - - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, - int len) -{ - int ret; - - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - - -int fb_kevent_send_to_user(struct kernel_packet_info *userinfo) -{ - int ret = 0; - struct sk_buff *skbuff = NULL; - void *head = NULL; - size_t data_len = 0; - - /*max_len */ - pr_info(" fb_kevent_send_to_user\n"); - - if (userinfo->payload_length >= OPLUS_KEVENT_MAX_UP_PALOAD_LEN) { - pr_err("[ERROR]:fb_kevent_send_to_user: payload_length out of range\n"); - ret = -1; - return ret; - } - - data_len = userinfo->payload_length + sizeof(struct kernel_packet_info); - pr_info(" data_len is %u\n", data_len); - - ret = genl_msg_prepare_usr_msg(FB_GUARD_CMD_GENL_UPLOAD, data_len, kevent_pid, - &skbuff); - - if (ret) { - pr_err("[ERROR]:genl_msg_prepare_usr_msg err, ret is %d \n"); - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, FB_GUARD_CMD_ATTR_MSG, userinfo, data_len); - - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - - genlmsg_end(skbuff, head); - - ret = genlmsg_unicast(&init_net, skbuff, kevent_pid); - - if (ret < 0) { - return ret; - } - - return 0; -} - -EXPORT_SYMBOL(fb_kevent_send_to_user); - - - -/* -int kevent_send_to_user(struct kernel_packet_info *userinfo) -{ - return fb_kevent_send_to_user(userinfo); -}*/ - - -static struct packet *package_alloc( - fb_tag tag_id, const char *event_id, unsigned char *payload) -{ - struct packet *packet; - struct kernel_packet_info *pkt; - char *tmp = payload; - - if (tag_id > FB_MAX_TYPE || !event_id || !payload || !_tag[tag_id]) { - return NULL; - } - - packet = (struct packet *)kmalloc(sizeof(struct packet), GFP_ATOMIC); - - if (!packet) { - return NULL; - } - - /*presplit payload, '\n' is not allowed*/ - for (; *tmp != '\0'; tmp++) { - if (*tmp == '\n') { - *tmp = '\0'; - break; - } - } - - pkt = (struct kernel_packet_info *) - kzalloc(sizeof(struct kernel_packet_info) + strlen(payload) + 1, GFP_ATOMIC); - - if (!pkt) { - kfree(packet); - return NULL; - } - - packet->pkt = pkt; - packet->retry = 4; /* retry 4 times at most*/ - pkt->type = 1; /*means only string is available*/ - - memcpy(pkt->log_tag, _tag[tag_id], - strlen(_tag[tag_id]) > MAX_LOG ? MAX_LOG : strlen(_tag[tag_id])); - memcpy(pkt->event_id, event_id, - strlen(event_id) > MAX_ID ? MAX_ID : strlen(event_id)); - pkt->payload_length = strlen(payload) + 1; - memcpy(pkt->payload, payload, strlen(payload)); - - return packet; -} - -static void package_release(struct packet *packet) -{ - if (packet) { - kfree(packet->pkt); - kfree(packet); - } -} - -int oplus_kevent_fb(fb_tag tag_id, const char *event_id, unsigned char *payload) -{ - struct packet *packet; - unsigned long flags; - - /*ignore before wlock init*/ - if (!g_pkts->wlock_init) { - return -ENODEV; - } - - packet = package_alloc(tag_id, event_id, payload); - - if (!packet) { - return -ENODEV; - } - - spin_lock_irqsave(&g_pkts->wlock, flags); - list_add(&packet->list, &g_pkts->packets); - spin_unlock_irqrestore(&g_pkts->wlock, flags); - - wake_up_process(g_pkts->flush_task); - - return 0; -} -EXPORT_SYMBOL(oplus_kevent_fb); - - - -static unsigned int BKDRHash(char *str, unsigned int len) -{ - unsigned int seed = 131; - /* 31 131 1313 13131 131313 etc.. */ - unsigned int hash = 0; - unsigned int i = 0; - - if (str == NULL) { - return 0; - } - - for (i = 0; i < len; str++, i++) { - hash = (hash * seed) + (*str); - } - - return hash; -} - -static int oplus_subsystem_schedule_kevent_fb_work(fb_tag tag_id, const char *event_id, unsigned char *str) -{ - unsigned char payload[1024] = {0x00}; - unsigned int hashid = 0; - int ret = 0; - char strHashSource[CAUSENAME_SIZE] = {0x00}; - /*struct timespec64 ts64;*/ - unsigned long rdm = 0; - - /*ktime_get_coarse_real_ts64(&ts64);*/ - get_random_bytes(&rdm, sizeof(unsigned long)); - - snprintf(strHashSource, CAUSENAME_SIZE, "%s %lu", str, rdm); - hashid = BKDRHash(strHashSource, strlen(strHashSource)); - memset(fid, 0 , CAUSENAME_SIZE); - snprintf(fid, CAUSENAME_SIZE, "%u", hashid); - ret = snprintf(payload, sizeof(payload), - "NULL$$EventField@@%s$$FieldData@@%s$$detailData@@%s", fid, str, - _tag[tag_id]); - pr_info("payload= %s, ret=%d\n", payload, ret); - - return oplus_kevent_fb(tag_id, event_id, payload); -} - - -static void oplus_kevent_fb_upload_work(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - bsp_fb_work_struct *bsp_kevent = container_of(dwork, struct bsp_fb_work_struct, dwork); - - oplus_subsystem_schedule_kevent_fb_work(bsp_kevent->tag_id, bsp_kevent->event_id, bsp_kevent->reason); -} - -int oplus_kevent_fb_str(fb_tag tag_id, const char *event_id, unsigned char *str) -{ - if (!bsp_kevent_wq) { - pr_err("%s: error: not init or bsp_kevent_wq is null\n", __func__); - return -EINVAL; - } - - spin_lock(&bsp_fb_dwork->lock); - memset((void*)&bsp_fb_dwork->event_id, 0, sizeof(bsp_fb_dwork->event_id)); - memset((void*)&bsp_fb_dwork->reason, 0, sizeof(bsp_fb_dwork->reason)); - - strlcpy((char*)&bsp_fb_dwork->event_id, event_id, sizeof(bsp_fb_dwork->event_id)); - strlcpy((char*)&bsp_fb_dwork->reason, str, sizeof(bsp_fb_dwork->reason)); - bsp_fb_dwork->tag_id = tag_id; - spin_unlock(&bsp_fb_dwork->lock); - - if (bsp_kevent_wq) { - queue_delayed_work(bsp_kevent_wq, &bsp_fb_dwork->dwork, 1); - } - - return 0; -} -EXPORT_SYMBOL(oplus_kevent_fb_str); - - -/*thread to deal with the buffer list*/ -static int fb_flush_thread(void *arg) -{ - struct packets_pool *pkts_pool = (struct packets_pool *)arg; - struct packet *tmp, *s; - unsigned long flags; - struct list_head list_tmp; - - while (!kthread_should_stop()) { - if (list_empty(&pkts_pool->packets)) { - set_current_state(TASK_INTERRUPTIBLE); - schedule(); - } - - set_current_state(TASK_RUNNING); - - spin_lock_irqsave(&pkts_pool->wlock, flags); - INIT_LIST_HEAD(&list_tmp); - list_splice_init(&pkts_pool->packets, &list_tmp); - spin_unlock_irqrestore(&pkts_pool->wlock, flags); - - list_for_each_entry_safe(s, tmp, &list_tmp, list) { - if (s->pkt) { - if (fb_kevent_send_to_user(s->pkt) && s->retry) { - pr_debug("failed to send feedback %s\n", s->pkt->log_tag); - s->retry--; - spin_lock_irqsave(&pkts_pool->wlock, flags); - list_add(&s->list, &pkts_pool->packets); - spin_unlock_irqrestore(&pkts_pool->wlock, flags); - - } else { - package_release(s); - } - - msleep(20); - } - } - } - - return 0; -} - -/* -* @format: tag_id:event_id:payload -*/ -static ssize_t kernel_fb_write(struct file *file, - const char __user *buf, - size_t count, - loff_t *lo) -{ - char *r_buf; - int tag_id = 0; - char event_id[MAX_ID] = {0}; - int idx1 = 0, idx2 = 0; - int len; - - r_buf = (char *)kzalloc(MAX_BUF_LEN, GFP_KERNEL); - - if (!r_buf) { - return count; - } - - if (copy_from_user(r_buf, buf, MAX_BUF_LEN > count ? count : MAX_BUF_LEN)) { - goto exit; - } - - r_buf[MAX_BUF_LEN - 1] = '\0'; /*make sure last bype is eof*/ - len = strlen(r_buf); - - tag_id = r_buf[0] - '0'; - - if (tag_id > FB_MAX_TYPE || tag_id < 0) { - goto exit; - } - - while (idx1 < len) { - if (r_buf[idx1++] == ':') { - idx2 = idx1; - - while (idx2 < len) { - if (r_buf[idx2++] == ':') { - break; - } - } - - break; - } - } - - if (idx1 == len || idx2 == len) { - goto exit; - } - - memcpy(event_id, &r_buf[idx1], - idx2 - idx1 - 1 > MAX_ID ? MAX_ID : idx2 - idx1 - 1); - event_id[MAX_ID - 1] = '\0'; - - oplus_kevent_fb(tag_id, event_id, r_buf + idx2); - -exit: - - kfree(r_buf); - return count; -} - -static ssize_t kernel_fb_read(struct file *file, - char __user *buf, - size_t count, - loff_t *ppos) -{ - return count; -} - -static const struct file_operations kern_fb_fops = { - .write = kernel_fb_write, - .read = kernel_fb_read, - .open = simple_open, - .owner = THIS_MODULE, -}; - -static ssize_t crash_cause_read(struct file *file, - char __user *buf, - size_t count, - loff_t *off) -{ - char page[512] = {0x00}; - int len = 0; - - len = snprintf(page, sizeof(page), "%s", fid); - len = simple_read_from_buffer(buf, count, off, page, strlen(page)); - return len; -} - -static const struct file_operations crash_cause_fops = { - .read = crash_cause_read, - .open = simple_open, - .owner = THIS_MODULE, -}; - -static int __init kernel_fb_init(void) -{ - struct proc_dir_entry *d_entry = NULL; - int ret = 0; - - pr_err("%s\n", __func__); - - bsp_kevent_wq = create_singlethread_workqueue("bsp_kevent_wq"); - if (bsp_kevent_wq == NULL) { - pr_err("bsp_kevent_wq alloc fail\n"); - ret = -ENOMEM; - goto failed_create_wq; - } - - bsp_fb_dwork = kzalloc(sizeof(bsp_fb_work_struct), GFP_ATOMIC); - if (!bsp_fb_dwork) { - pr_err("bsp_kevent_wq alloc fail\n"); - ret = -ENOMEM; - goto failed_alloc_dwork; - } - - spin_lock_init(&bsp_fb_dwork->lock); - INIT_DELAYED_WORK(&bsp_fb_dwork->dwork, oplus_kevent_fb_upload_work); - - g_pkts = (struct packets_pool *)kzalloc(sizeof(struct packets_pool), - GFP_KERNEL); - - if (!g_pkts) { - ret = -ENOMEM; - goto failed_kzalloc; - } - - /*register gen_link family*/ - ret = genl_register_family(&oplus_fb_kevent_family); - - if (ret) { - pr_err("failed genl_register_family"); - goto failed_genl_register_family; - } - - INIT_LIST_HEAD(&g_pkts->packets); - spin_lock_init(&g_pkts->wlock); - - g_pkts->flush_task = kthread_create(fb_flush_thread, g_pkts, "fb_flush"); - - if (!g_pkts->flush_task) { - pr_err("failed to kthread_create fb_flush\n"); - ret = -ENODEV; - goto failed_kthread_create; - } - - g_pkts->wlock_init = true; - - d_entry = proc_create_data("kern_fb", 0664, NULL, &kern_fb_fops, NULL); - - if (!d_entry) { - pr_err("failed to create kern_fb node\n"); - ret = -ENODEV; - goto failed_proc_create_data; - } - - d_entry = proc_create_data("crash_cause", 0664, NULL, &crash_cause_fops, NULL); - - if (!d_entry) { - pr_err("failed to create crash_cause node\n"); - ret = -ENODEV; - goto failed_proc_create_data; - } - - pr_info("kernel_fb_init probe ok\n"); - return 0; - -failed_proc_create_data: -failed_kthread_create: - genl_unregister_family(&oplus_fb_kevent_family); -failed_genl_register_family: - kfree(g_pkts); -failed_kzalloc: - kfree(bsp_fb_dwork); -failed_alloc_dwork: - destroy_workqueue(bsp_kevent_wq); -failed_create_wq: - return ret; -} - -static void __exit kernel_fb_exit() -{ - kfree(bsp_fb_dwork); - bsp_fb_dwork = NULL; - if (bsp_kevent_wq) { - destroy_workqueue(bsp_kevent_wq); - bsp_kevent_wq = NULL; - } - genl_unregister_family(&oplus_fb_kevent_family); - kfree(g_pkts); - return; -} - -/*core_initcall(kernel_fb_init);*/ - -module_init(kernel_fb_init); -module_exit(kernel_fb_exit); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/feedback/oplus_fb_guard_netlink.h b/drivers/soc/oplus/system/feedback/oplus_fb_guard_netlink.h deleted file mode 100755 index f4e39c968539..000000000000 --- a/drivers/soc/oplus/system/feedback/oplus_fb_guard_netlink.h +++ /dev/null @@ -1,64 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/************************************************************** -* Copyright (c) 2008- 2030 OPLUS Mobile communication Corp.ltd All rights reserved. -* -* File : oplus_feedback_guard_netlink.h -* Description: For oplus_feedback_guard_netlink -* Version : 1.0 -* Date : 2020-11-24 -* Author : -* TAG : -****************************************************************/ -#ifndef _OPLUS_FB_GUARD_NETLINK_H -#define _OPLUS_FB_GUARD_NETLINK_H - -#define OPLUS_FB_GUARD_TEST_NETLINK_CMD_MIN 0 -#define OPLUS_FB_GUARD_TEST_NETLINK_SEND_PID 1 -#define OPLUS_FB_GUARD_TEST_NETLINK_RECEV 2 -#define OPLUS_FB_GUARD_TEST_NETLINK_CMD_MAX 3 - -#define OPLUS_FB_GUARD_MSG_TO_KERNEL_BUF_LEN 256 -#define OPLUS_FB_GUARD_MSG_FROM_KERNEL_BUF_LEN (2048 + 128) - - -#define OPLUS_FB_GUARD_PROTOCAL_NAME "fb_guard" -#define OPLUS_FB_GUARD_GENL_VERSION 0x01 -#define OPLUS_FB_GUARD_PROTOCAL_NAME_MAX_LEN 100 - -enum { - FB_GUARD_CMD_ATTR_UNSPEC = 0, - FB_GUARD_CMD_ATTR_MSG, - FB_GUARD_CMD_ATTR_OPT, - __FB_GUARD_CMD_ATTR_MAX, -}; - -#define FB_GUARD_CMD_ATTR_MAX (__FB_GUARD_CMD_ATTR_MAX - 1) - -enum { - FB_GUARD_CMD_GENL_UNSPEC = 0, - FB_GUARD_CMD_GENL_SENDPID, - FB_GUARD_CMD_GENL_UPLOAD, - FB_GUARD_CMD_GENL_TEST_UPLOAD, -}; - - -struct msg_to_kernel { - struct nlmsghdr n_hd; - struct genlmsghdr g_hd; - char buf[OPLUS_FB_GUARD_MSG_TO_KERNEL_BUF_LEN]; -}; - -struct msg_from_kernel { - struct nlmsghdr n_hd; - struct genlmsghdr g_hd; - char buf[OPLUS_FB_GUARD_MSG_FROM_KERNEL_BUF_LEN]; -}; - -struct msg_test_upload { - unsigned int pro_pid; - unsigned int val; -}; - -int oplus_fb_guard_test_netlink(int cmd, unsigned int val); - -#endif /*_OPLUS_FB_GUARD_NETLINK_H*/ diff --git a/drivers/soc/oplus/system/full_aging/Kconfig b/drivers/soc/oplus/system/full_aging/Kconfig deleted file mode 100755 index 834c1b53dd26..000000000000 --- a/drivers/soc/oplus/system/full_aging/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_AGINGTEST - tristate "Oplus system full aging" - default n - help - define this config to init oplus system full aging. diff --git a/drivers/soc/oplus/system/hung_task_enhance/Kconfig b/drivers/soc/oplus/system/hung_task_enhance/Kconfig deleted file mode 100755 index 494eea0c5ba9..000000000000 --- a/drivers/soc/oplus/system/hung_task_enhance/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_HUNG_TASK_ENHANCE - tristate "system hung task enhance" - default n - depends on DETECT_HUNG_TASK - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable QCOM platform uboot log . - -config OPLUS_FEATURE_DEATH_HEALER - tristate "Enable DeathHealer" - depends on DETECT_HUNG_TASK - depends on OPLUS_FEATURE_HUNG_TASK_ENHANCE - default y - help - define this config to enable DEATH_HEALER . diff --git a/drivers/soc/oplus/system/hung_task_enhance/Makefile b/drivers/soc/oplus/system/hung_task_enhance/Makefile deleted file mode 100755 index e06dfea9a955..000000000000 --- a/drivers/soc/oplus/system/hung_task_enhance/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -obj-$(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) += hung_task_enhance.o -else -ifeq ($(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE), y) -obj-$(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) += hung_task_enhance.o -endif -ifeq ($(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE), m) -obj-$(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) += gki/hung_task_enhance.o -endif -endif diff --git a/drivers/soc/oplus/system/hung_task_enhance/gki/Kconfig b/drivers/soc/oplus/system/hung_task_enhance/gki/Kconfig deleted file mode 100755 index 795891cce7e8..000000000000 --- a/drivers/soc/oplus/system/hung_task_enhance/gki/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_HUNG_TASK_ENHANCE - tristate "system hung task enhance" - default n - depends on DETECT_HUNG_TASK - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable QCOM platform uboot log . - -config OPLUS_FEATURE_DEATH_HEALER - tristate "Enable DeathHealer" - depends on DETECT_HUNG_TASK - depends on OPLUS_FEATURE_HUNG_TASK_ENHANCE - default n - help - define this config to enable DEATH_HEALER . diff --git a/drivers/soc/oplus/system/hung_task_enhance/gki/hung_task_enhance.c b/drivers/soc/oplus/system/hung_task_enhance/gki/hung_task_enhance.c deleted file mode 100755 index bbd5bd6ed325..000000000000 --- a/drivers/soc/oplus/system/hung_task_enhance/gki/hung_task_enhance.c +++ /dev/null @@ -1,284 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : uboot_log.c -** Description : BSP uboot_log back up xbl uefi kernel boot log , cat /proc/boot_dmesg -** Version : 1.0 -******************************************************************/ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* - * format: task_name,reason. e.g. system_server,uninterruptible for 60 secs - */ -#define HUNG_TASK_KILL_LEN 128 -char __read_mostly sysctl_hung_task_kill[HUNG_TASK_KILL_LEN]; -#define TWICE_DEATH_PERIOD 300000000000ULL /* 300s */ -#define MAX_DEATH_COUNT 3 -#define MAX_DEATH_COUNT_FOR_AGING 2 -#define DISP_TASK_COMM_LEN_MASK 10 - -/* Foreground background optimization,change max io count */ -#define MAX_IO_WAIT_HUNG 5 -int __read_mostly sysctl_hung_task_maxiowait_count = MAX_IO_WAIT_HUNG; -static int io_wait_count = 0; -#endif - -/* key process:zygote system_server surfaceflinger*/ -static bool is_usersapce_key_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 && !strcmp(t->parent->comm,"init"))) - return true; - if(!strncmp(t->comm,"system_server", TASK_COMM_LEN) - || !strncmp(t->comm,"surfaceflinger", TASK_COMM_LEN) ) - return true; - if (!strncmp(t->comm, "Binder:", 7) && (t->group_leader->pid == t->pid) - && (tcred->uid.val == 1000) && (t->parent != 0 && !strcmp(t->parent->comm, "main"))) - return true; - - return false; -} - - -static bool is_ignore_process(struct task_struct *t) -{ - if(!strncmp(t->comm,"mdss_dsi_event", TASK_COMM_LEN)|| - !strncmp(t->comm,"msm-core:sampli", TASK_COMM_LEN)|| - !strncmp(t->comm,"mdss_fb0", TASK_COMM_LEN)|| - !strncmp(t->comm,"mdss_fb_ffl0", TASK_COMM_LEN)|| - !strncmp(t->comm,"hdcp_2x", TASK_COMM_LEN)|| - !strncmp(t->comm,"dp_hdcp2p2", TASK_COMM_LEN)|| - !strncmp(t->comm,"opmonitor_boot", TASK_COMM_LEN)|| - !strncmp(t->comm,"panic_flush", TASK_COMM_LEN)|| - !strncmp(t->comm,"fb_flush", TASK_COMM_LEN)|| - !strncmp(t->comm,"crtc_commit", DISP_TASK_COMM_LEN_MASK)|| - !strncmp(t->comm,"crtc_event", DISP_TASK_COMM_LEN_MASK)){ - return true; - } - return false; -} - -/* because of KMI, define local val */ -int __read_mostly sysctl_hung_task_warnings = 10; -/* - * Should we panic (and reboot, if panic_timeout= is set) when a - * hung task is detected: - */ -unsigned int __read_mostly sysctl_hung_task_panic = CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE; -extern int send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p); - -static void oplus_check_hung_task(struct task_struct *t, unsigned long timeout, bool *need_check) -{ - unsigned long switch_count = t->nvcsw + t->nivcsw; - -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) - static unsigned long long last_death_time = 0; - unsigned long long cur_death_time = 0; - static int death_count = 0; - unsigned int local_iowait = 0; -#endif - - if(is_ignore_process(t)) - return; - - /* - * Ensure the task is not frozen. - * Also, skip vfork and any other user process that freezer should skip. - */ - if (unlikely(t->flags & (PF_FROZEN | PF_FREEZER_SKIP))) - { -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* DeathHealer, kill D/T/t state tasks */ - if (is_usersapce_key_process(t)) - { - if (t->flags & PF_FROZEN) - return; - } - else -#endif - return; - } - - /* - * When a freshly created task is scheduled once, changes its state to - * TASK_UNINTERRUPTIBLE without having ever been switched out once, it - * musn't be checked. - */ - if (unlikely(!switch_count)) - return; - - if (switch_count != t->last_switch_count) { - t->last_switch_count = switch_count; - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) || defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) - t->last_switch_time = jiffies; - #endif - return; - } - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) || defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) - if (time_is_after_jiffies(t->last_switch_time + timeout * HZ)) - return; - #endif - -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) - /* kill D/T/t state tasks ,if this task blocked at iowait. so maybe we should reboot system first */ - if(t->in_iowait){ - printk(KERN_ERR "DeathHealer io wait too long time\n"); - if(t->mm != NULL && t == t->group_leader)// only work on user main thread - { - io_wait_count = io_wait_count + 1; - local_iowait = 1; - } - } - if (is_usersapce_key_process(t)) - { - if (t->state == TASK_UNINTERRUPTIBLE) - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, "%s,uninterruptible for %ld seconds", t->comm, timeout); - else if (t->state == TASK_STOPPED) - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, "%s,stopped for %ld seconds", t->comm, timeout); - else if (t->state == TASK_TRACED) - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, "%s,traced for %ld seconds", t->comm, timeout); - else - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, "%s,unknown hung for %ld seconds", t->comm, timeout); - - printk(KERN_ERR "DeathHealer: task %s:%d blocked for more than %ld seconds in state 0x%lx. Count:%d\n", - t->comm, t->pid, timeout, t->state, death_count+1); - - sched_show_task(t); - debug_show_held_locks(t); - trigger_all_cpu_backtrace(); - - death_count++; - cur_death_time = local_clock(); - if ((death_count >= MAX_DEATH_COUNT) - || (death_count >= MAX_DEATH_COUNT_FOR_AGING && get_eng_version() == AGING)) { - if (cur_death_time - last_death_time < TWICE_DEATH_PERIOD) { - printk(KERN_ERR "DeathHealer has been triggered %d times, \ - last time at: %llu\n", death_count, last_death_time); - BUG(); - } else { - death_count = 0; - printk(KERN_ERR "DeathHealer reset death_count to 0"); - } - } - last_death_time = cur_death_time; - - if (get_eng_version() == AGING) - BUG(); - - t->flags |= PF_KILLING; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - send_sig_info(SIGKILL, SEND_SIG_PRIV, t); -#else - send_sig_info(SIGKILL, SEND_SIG_FORCED, t); -#endif - wake_up_process(t); - } -#endif - - if (sysctl_hung_task_panic) { - console_verbose(); - - /* Panic on critical process D-state */ - if (is_usersapce_key_process(t)) - { - trigger_all_cpu_backtrace(); - panic("hung_task: blocked tasks"); - } - - } - - /* - * Ok, the task did not get scheduled for more than 2 minutes, - * complain: - */ -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) - /* Modify for make sure we could print the stack of iowait thread before panic */ - if (sysctl_hung_task_warnings || local_iowait) -#else - if (sysctl_hung_task_warnings) -#endif - { - if (sysctl_hung_task_warnings > 0) - sysctl_hung_task_warnings--; - pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", - t->comm, t->pid, timeout); - sched_show_task(t); - } - touch_nmi_watchdog(); -} - - - -void io_check_hung_detection(void *ignore, struct task_struct *t, unsigned long timeout, bool *need_check) -{ -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) - /* add io wait monitor */ - if (t->state == TASK_UNINTERRUPTIBLE || t->state == TASK_STOPPED || t->state == TASK_TRACED) - oplus_check_hung_task(t, timeout, need_check); -#endif - return; -} -EXPORT_SYMBOL(io_check_hung_detection); - -void io_block_panic(void *ignore, void *extra) -{ -#if IS_ENABLED (CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* Foreground background optimization,change max io count */ - if (io_wait_count >= sysctl_hung_task_maxiowait_count) { - panic("hung_task:[%u]IO blocked too long time", io_wait_count); - } -#endif - return; -} -EXPORT_SYMBOL(io_block_panic); - -static int __init hung_task_enhance_init(void) -{ - int ret; - - ret = register_trace_android_vh_check_uninterruptible_tasks( - io_check_hung_detection, NULL); - if (ret) - return ret; - - ret = register_trace_android_vh_check_uninterruptible_tasks_dn( - io_block_panic, NULL); - if (ret) { - unregister_trace_android_vh_check_uninterruptible_tasks( - io_check_hung_detection, NULL); - return ret; - } - - return 0; -} -late_initcall(hung_task_enhance_init); - -static void __exit hung_task_enh_exit(void) -{ - unregister_trace_android_vh_check_uninterruptible_tasks( - io_check_hung_detection, NULL); - unregister_trace_android_vh_check_uninterruptible_tasks_dn( - io_block_panic, NULL); -} -module_exit(hung_task_enh_exit); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/hung_task_enhance/hung_task_enhance.c b/drivers/soc/oplus/system/hung_task_enhance/hung_task_enhance.c deleted file mode 100755 index 3d98774c6a64..000000000000 --- a/drivers/soc/oplus/system/hung_task_enhance/hung_task_enhance.c +++ /dev/null @@ -1,295 +0,0 @@ -/*************************************************************** -** Copyright (C), 2019-2020, OPPO Mobile Comm Corp., Ltd -** VENDOR_EDIT -** File : uboot_log.c -** Description : BSP uboot_log back up xbl uefi kernel boot log , cat /proc/boot_dmesg -** Version : 1.0 -** Date : 2020/02/25 -** -** ------------------------------- Revision History: ----------- -** -** Wen.Luo 2020/02/25 1.0 Build this moudle -******************************************************************/ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER -/* - * format: task_name,reason. e.g. system_server,uninterruptible for 60 secs - */ -#define HUNG_TASK_KILL_LEN 128 -char __read_mostly sysctl_hung_task_kill[HUNG_TASK_KILL_LEN]; -#define TWICE_DEATH_PERIOD 300000000000ULL /* 300s */ -#define MAX_DEATH_COUNT 3 -#define MAX_DEATH_COUNT_FOR_AGING 2 -#define DISP_TASK_COMM_LEN_MASK 10 - -/* Foreground background optimization,change max io count */ -#define MAX_IO_WAIT_HUNG 5 -int __read_mostly sysctl_hung_task_maxiowait_count = MAX_IO_WAIT_HUNG; -#endif - -/* key process:zygote system_server surfaceflinger*/ -static bool is_usersapce_key_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - - if (!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 - && !strcmp(t->parent->comm, "init"))) { - return true; - } - - if (!strncmp(t->comm, "system_server", TASK_COMM_LEN) - || !strncmp(t->comm, "surfaceflinger", TASK_COMM_LEN)) { - return true; - } - - if (!strncmp(t->comm, "Binder:", 7) && (t->group_leader->pid == t->pid) - && (tcred->uid.val == 1000) && (t->parent != 0 - && !strcmp(t->parent->comm, "main"))) { - return true; - } - - return false; -} - - -static bool is_ignore_process(struct task_struct *t) -{ - if (!strncmp(t->comm, "mdss_dsi_event", TASK_COMM_LEN) || - !strncmp(t->comm, "msm-core:sampli", TASK_COMM_LEN) || - !strncmp(t->comm, "mdss_fb0", TASK_COMM_LEN) || - !strncmp(t->comm, "mdss_fb_ffl0", TASK_COMM_LEN) || - !strncmp(t->comm, "hdcp_2x", TASK_COMM_LEN) || - !strncmp(t->comm, "dp_hdcp2p2", TASK_COMM_LEN) || - !strncmp(t->comm, "opmonitor_boot", TASK_COMM_LEN) || - !strncmp(t->comm, "panic_flush", TASK_COMM_LEN) || - !strncmp(t->comm, "fb_flush", TASK_COMM_LEN) || - !strncmp(t->comm, "crtc_commit", DISP_TASK_COMM_LEN_MASK) || - !strncmp(t->comm, "crtc_event", DISP_TASK_COMM_LEN_MASK)) { - return true; - } - - return false; -} - -static void oplus_check_hung_task(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic) -{ - unsigned long switch_count = t->nvcsw + t->nivcsw; - -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - static unsigned long long last_death_time = 0; - unsigned long long cur_death_time = 0; - static int death_count = 0; - unsigned int local_iowait = 0; -#endif - - if (is_ignore_process(t)) { - return; - } - - /* - * Ensure the task is not frozen. - * Also, skip vfork and any other user process that freezer should skip. - */ - if (unlikely(t->flags & (PF_FROZEN | PF_FREEZER_SKIP))) { -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - - /* DeathHealer, kill D/T/t state tasks */ - if (is_usersapce_key_process(t)) { - if (t->flags & PF_FROZEN) { - return; - } - } else -#endif - return; - } - - /* - * When a freshly created task is scheduled once, changes its state to - * TASK_UNINTERRUPTIBLE without having ever been switched out once, it - * musn't be checked. - */ - if (unlikely(!switch_count)) { - return; - } - - if (switch_count != t->last_switch_count) { - t->last_switch_count = switch_count; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) || defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) - t->last_switch_time = jiffies; -#endif - return; - } - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) || defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) - - if (time_is_after_jiffies(t->last_switch_time + timeout * HZ)) { - return; - } - -#endif - - trace_sched_process_hang(t); - -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - - /* kill D/T/t state tasks ,if this task blocked at iowait. so maybe we should reboot system first */ - if (t->in_iowait) { - printk(KERN_ERR "DeathHealer io wait too long time\n"); - - if (t->mm != NULL && t == t->group_leader) { /*only work on user main thread*/ - *iowait_count = *iowait_count + 1; - local_iowait = 1; - } - } - - if (is_usersapce_key_process(t)) { - if (t->state == TASK_UNINTERRUPTIBLE) { - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, - "%s,uninterruptible for %ld seconds", t->comm, timeout); - - } else if (t->state == TASK_STOPPED) { - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, - "%s,stopped for %ld seconds", t->comm, timeout); - - } else if (t->state == TASK_TRACED) { - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, "%s,traced for %ld seconds", - t->comm, timeout); - - } else { - snprintf(sysctl_hung_task_kill, HUNG_TASK_KILL_LEN, - "%s,unknown hung for %ld seconds", t->comm, timeout); - } - - printk(KERN_ERR - "DeathHealer: task %s:%d blocked for more than %ld seconds in state 0x%lx. Count:%d\n", - t->comm, t->pid, timeout, t->state, death_count + 1); - - sched_show_task(t); - debug_show_held_locks(t); - trigger_all_cpu_backtrace(); - - death_count++; - cur_death_time = local_clock(); - - if ((death_count >= MAX_DEATH_COUNT) - || (death_count >= MAX_DEATH_COUNT_FOR_AGING && get_eng_version() == AGING)) { - if (cur_death_time - last_death_time < TWICE_DEATH_PERIOD) { - printk(KERN_ERR "DeathHealer has been triggered %d times, \ - last time at: %llu\n", death_count, last_death_time); - BUG(); - - } else { - death_count = 0; - printk(KERN_ERR "DeathHealer reset death_count to 0"); - } - } - last_death_time = cur_death_time; - - - t->flags |= PF_KILLING; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - do_send_sig_info(SIGKILL, SEND_SIG_PRIV, t, true); -#else - do_send_sig_info(SIGKILL, SEND_SIG_FORCED, t, true); -#endif - wake_up_process(t); - } - -#endif - - if (sysctl_hung_task_panic) { - console_verbose(); - *show_lock = true; - *call_panic = true; - - /* Panic on critical process D-state */ - if (is_usersapce_key_process(t)) { - trigger_all_cpu_backtrace(); - panic("hung_task: blocked tasks"); - } - } - - /* - * Ok, the task did not get scheduled for more than 2 minutes, - * complain: - */ -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - - /* Modify for make sure we could print the stack of iowait thread before panic */ - if (sysctl_hung_task_warnings || local_iowait) -#else - if (sysctl_hung_task_warnings) -#endif - { - if (sysctl_hung_task_warnings > 0) { - sysctl_hung_task_warnings--; - } - - pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", - t->comm, t->pid, timeout); - pr_err(" %s %s %.*s\n", - print_tainted(), init_utsname()->release, - (int)strcspn(init_utsname()->version, " "), - init_utsname()->version); - pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\"" - " disables this message.\n"); - sched_show_task(t); - *show_lock = true; - } - - touch_nmi_watchdog(); -} - - - -void io_check_hung_detection(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic) -{ -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - - /* add io wait monitor */ - if (t->state == TASK_UNINTERRUPTIBLE || t->state == TASK_STOPPED - || t->state == TASK_TRACED) - - /* Check for selective monitoring */ - if (!sysctl_hung_task_selective_monitoring || - t->hang_detection_enabled) { - oplus_check_hung_task(t, timeout, iowait_count, show_lock, call_panic); - } - -#endif - return; -} -EXPORT_SYMBOL(io_check_hung_detection); - -void io_block_panic(unsigned int *iowait_count, - unsigned int sys_mamxiowait_count) -{ -#ifdef CONFIG_OPLUS_FEATURE_DEATH_HEALER - - /* Foreground background optimization,change max io count */ - if (*iowait_count >= sysctl_hung_task_maxiowait_count) { - panic("hung_task:[%u]IO blocked too long time", *iowait_count); - } - -#endif - return; -} -EXPORT_SYMBOL(io_block_panic); - diff --git a/drivers/soc/oplus/system/include/boot_mode.h b/drivers/soc/oplus/system/include/boot_mode.h deleted file mode 100755 index 6643137e566e..000000000000 --- a/drivers/soc/oplus/system/include/boot_mode.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _OPLUS_BOOT_H -#define _OPLUS_BOOT_H -enum { - MSM_BOOT_MODE__NORMAL, - MSM_BOOT_MODE__FASTBOOT, - MSM_BOOT_MODE__RECOVERY, - MSM_BOOT_MODE__FACTORY, - MSM_BOOT_MODE__RF, - MSM_BOOT_MODE__WLAN, - MSM_BOOT_MODE__MOS, - MSM_BOOT_MODE__CHARGE, - MSM_BOOT_MODE__SILENCE, - MSM_BOOT_MODE__SAU, - MSM_BOOT_MODE__AGING = 998, - MSM_BOOT_MODE__SAFE = 999, -}; - -extern int get_boot_mode(void); -#ifdef OPLUS_BUG_STABILITY -/*add for charge*/ -extern bool qpnp_is_power_off_charging(void); -#endif -#ifdef OPLUS_BUG_STABILITY -/*add for detect charger when reboot */ -extern bool qpnp_is_charger_reboot(void); -#endif /*OPLUS_BUG_STABILITY*/ -#endif /*_OPLUS_BOOT_H*/ - -#ifdef OPLUS_BUG_STABILITY -/*Add for kernel monitor whole bootup*/ -#ifdef PHOENIX_PROJECT -extern bool op_is_monitorable_boot(void); -#endif -#endif /*_OPLUS_BOOT_H*/ - diff --git a/drivers/soc/oplus/system/include/device_info.h b/drivers/soc/oplus/system/include/device_info.h deleted file mode 100755 index 8d6fec5eb2e9..000000000000 --- a/drivers/soc/oplus/system/include/device_info.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _DEVICE_INFO_H -#define _DEVICE_INFO_H - -#ifdef CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO -void save_dump_reason_to_device_info(char *buf); -#else -inline void save_dump_reason_to_device_info(char *reason) {} -#endif - -#endif /*_DEVICE_INFO_H*/ diff --git a/drivers/soc/oplus/system/include/dump_reason.h b/drivers/soc/oplus/system/include/dump_reason.h deleted file mode 100755 index c27d70c407ee..000000000000 --- a/drivers/soc/oplus/system/include/dump_reason.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _DUMP_REASON_H -#define _DUMP_REASON_H - -#ifdef CONFIG_OPLUS_FEATURE_DUMP_REASON - -#define SMEM_DUMP_INFO 129 -#define DUMP_REASON_SIZE 256 - -struct dump_info { - char dump_reason[DUMP_REASON_SIZE]; /*dump reason*/ -}; - -extern char *parse_function_builtin_return_address(unsigned long - function_address); -extern void save_dump_reason_to_smem(char *info, char *function_name); -#else -static char *parse_function_builtin_return_address(unsigned long - function_address) {} -static void save_dump_reason_to_smem(char *info, char *function_name) {} -#endif - -#endif /*_DUMP_REASON_H*/ diff --git a/drivers/soc/oplus/system/include/hung_task_enhance.h b/drivers/soc/oplus/system/include/hung_task_enhance.h deleted file mode 100755 index 573bc370330b..000000000000 --- a/drivers/soc/oplus/system/include/hung_task_enhance.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __HUNG_TASK_ENHANCE_H -#define __HUNG_TASK_ENHANCE_H -#include -#include -#include -#include - - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* format: task_name,reason. e.g. system_server,uninterruptible for 60 secs */ -extern char sysctl_hung_task_kill[]; -/* Foreground background optimization,change max io count */ -extern int sysctl_hung_task_maxiowait_count; -static int five = 5; -#endif - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) -void io_check_hung_detection(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic); -void io_block_panic(unsigned int *iowait_count, - unsigned int sys_mamxiowait_count); -#else -void io_check_hung_detection(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic) {} -static void io_block_panic(unsigned int *iowait_count, - unsigned int sys_mamxiowait_count) {} -#endif - -#endif/*__HUNG_TASK_ENHANCE_H*/ diff --git a/drivers/soc/oplus/system/include/kernel_fb.h b/drivers/soc/oplus/system/include/kernel_fb.h deleted file mode 100755 index d686ba7b5917..000000000000 --- a/drivers/soc/oplus/system/include/kernel_fb.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************** -SPDX-License-Identifier: GPL-2.0-only - * Copyright (C) 2018-2020 Oplus. All rights reserved. -** File : kernel_fb.h -** Description : BSP kevent fb data -** Version : 1.0 -******************************************************************/ - -#ifndef __KERNEL_FEEDBACK_H -#define __KERNEL_FEEDBACK_H - -typedef enum { - FB_STABILITY = 0, - FB_FS, - FB_STORAGE, - FB_SENSOR, - FB_BOOT, - FB_MAX_TYPE = FB_BOOT, -} fb_tag; - -#define FB_STABILITY_ID_CRASH "202007272030" -#define FB_SENSOR_ID_CRASH "10004" -#define FB_SENSOR_ID_QMI "202007272041" - -struct kernel_packet_info { - int type; /* 0:root,1:only string,other number represent other type */ - char log_tag[32]; /* logTag */ - char event_id[20]; /*eventID */ - size_t payload_length; /* Length of packet data */ - unsigned char payload[0]; /* Optional packet data */ -} __attribute__((packed)); - -int fb_kevent_send_to_user(struct kernel_packet_info *userinfo); -/*int kevent_send_to_user(struct kernel_packet_info *userinfo);*/ -int oplus_kevent_fb(fb_tag tag_id, const char *event_id, - unsigned char *payload); -int oplus_kevent_fb_str(fb_tag tag_id, const char *event_id, - unsigned char *str); -#endif /*__KERNEL_FEEDBACK_H*/ diff --git a/drivers/soc/oplus/system/include/oplus_brightscreen_check.h b/drivers/soc/oplus/system/include/oplus_brightscreen_check.h deleted file mode 100755 index 672e31ab31cc..000000000000 --- a/drivers/soc/oplus/system/include/oplus_brightscreen_check.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * - * yixue.ge - * - */ -#ifndef _OPLUS_BRIGHTSCREEN_CHECK_H_ -#define _OPLUS_BRIGHTSCREEN_CHECK_H_ - -int bright_screen_timer_restart(void); - -#endif /*_OPLUS_BRIGHTSCREEN_CHECK_H_*/ diff --git a/drivers/soc/oplus/system/include/oplus_bscheck.h b/drivers/soc/oplus/system/include/oplus_bscheck.h deleted file mode 100755 index 002764351f37..000000000000 --- a/drivers/soc/oplus/system/include/oplus_bscheck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * - * yixue.ge - * - */ -#ifndef _OPLUS_BS_CHECK_H_ -#define _OPLUS_BS_CHECK_H_ - -int black_screen_timer_restart(void); - -#endif /*_OPLUS_BS_CHECK_H_*/ diff --git a/drivers/soc/oplus/system/include/oplus_mm_kevent_fb.h b/drivers/soc/oplus/system/include/oplus_mm_kevent_fb.h deleted file mode 100755 index 6204cc0dac2e..000000000000 --- a/drivers/soc/oplus/system/include/oplus_mm_kevent_fb.h +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************** -** Copyright (C), 2018, OPLUS Mobile Comm Corp., Ltd -** File : oplus_mm_kevent_fb.h -** Description : MM kevent fb data -** Version : 1.0 -** Date : 2018/12/03 -** -** ------------------------------- Revision History: ----------- -** -** Guo.Ling 2018/12/03 1.0 Build this moudle -** LiPing-M 2019/01/29 1.1 Add SMMU for QCOM -******************************************************************/ -#ifndef _OPLUS_MM_KEVENT_FB_ -#define _OPLUS_MM_KEVENT_FB_ - -#define MM_KEVENT_MAX_PAYLOAD_SIZE 256 - -enum { - MM_FB_KEY_RATELIMIT_NONE = 0, - MM_FB_KEY_RATELIMIT_1MIN = 60 * 1000, - MM_FB_KEY_RATELIMIT_5MIN = 60 * 5 * 1000, - MM_FB_KEY_RATELIMIT_30MIN = 60 * 30 * 1000, - MM_FB_KEY_RATELIMIT_1H = MM_FB_KEY_RATELIMIT_30MIN * 2, - MM_FB_KEY_RATELIMIT_1DAY = MM_FB_KEY_RATELIMIT_1H * 24, -}; - -#define OPLUS_FB_ADSP_CRASH_RATELIMIT (60 * 5 * 1000) /*ms, for mtk*/ - -enum OPLUS_MM_DIRVER_FB_EVENT_MODULE { - OPLUS_MM_DIRVER_FB_EVENT_DISPLAY = 0, - OPLUS_MM_DIRVER_FB_EVENT_AUDIO -}; - -/*------- multimedia bigdata feedback event id, start ------------ */ -#define OPLUS_AUDIO_EVENTID_ADSP_CRASH (10001) -#define OPLUS_AUDIO_EVENTID_HEADSET_DET (10009) -#define OPLUS_AUDIO_EVENTID_ADSP_RECOVERY_FAIL (10045) - -#define OPLUS_DISPLAY_EVENTID_DRIVER_ERR (12002) - -#define OPLUS_DISPLAY_EVENTID_GPU_FAULT (12005) - -/*this id just for test or debug */ -#define OPLUS_MM_EVENTID_TEST_OR_DEBUG (30000) -/*------- multimedia bigdata feedback event id, end ------------*/ - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -int upload_mm_fb_kevent_to_atlas_limit(unsigned int event_id, unsigned char *payload, int limit_ms); - -int upload_mm_fb_kevent_limit(enum OPLUS_MM_DIRVER_FB_EVENT_MODULE module, unsigned int event_id, - const char *name, int rate_limit_ms, char *payload); - -#define mm_fb_kevent(m, id, name, rate_limit_ms, fmt, ...) \ - do { \ - char kv_data[MM_KEVENT_MAX_PAYLOAD_SIZE] = ""; \ - scnprintf(kv_data, sizeof(kv_data), fmt, ##__VA_ARGS__); \ - upload_mm_fb_kevent_limit(m, id, name, rate_limit_ms, kv_data); \ - } while (0) - -#define mm_fb_display_kevent(name, rate_limit_ms, fmt, ...) \ - mm_fb_kevent(OPLUS_MM_DIRVER_FB_EVENT_DISPLAY, OPLUS_DISPLAY_EVENTID_DRIVER_ERR, name, rate_limit_ms, fmt, ##__VA_ARGS__) - -#define mm_fb_display_kevent_named(rate_limit_ms, fmt, ...) \ - do { \ - char name[MM_KEVENT_MAX_PAYLOAD_SIZE]; \ - scnprintf(name, sizeof(name), "%s:%d", __func__, __LINE__); \ - mm_fb_display_kevent(name, rate_limit_ms, fmt, ##__VA_ARGS__); \ - } while (0) - -#define mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ...) \ - mm_fb_kevent(OPLUS_MM_DIRVER_FB_EVENT_AUDIO, event_id, name, rate_limit_ms, fmt, ##__VA_ARGS__) - -#define mm_fb_audio_kevent_named(event_id, rate_limit_ms, fmt, ...) \ - do { \ - char name[MM_KEVENT_MAX_PAYLOAD_SIZE]; \ - scnprintf(name, sizeof(name), "%s:%d", __func__, __LINE__); \ - mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ##__VA_ARGS__); \ - } while (0) - -int mm_fb_kevent_init(void); -void mm_fb_kevent_deinit(void); - -#else /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ -#define upload_mm_fb_kevent_to_atlas_limit(event_id, payload, limit_ms) (0) -#define mm_fb_kevent(m, name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_display_kevent(name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_display_kevent_named(rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_audio_kevent_named(event_id, rate_limit_ms, fmt, ...) do {} while (0) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - -#endif /* _OPLUS_MM_KEVENT_FB_ */ - diff --git a/drivers/soc/oplus/system/include/oplus_signal.h b/drivers/soc/oplus/system/include/oplus_signal.h deleted file mode 100755 index b8f3f6b20cd1..000000000000 --- a/drivers/soc/oplus/system/include/oplus_signal.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __OPLUS_SIGNAL_H -#define __OPLUS_SIGNAL_H - -#include -#include - -/* signal pending, fatal_signal_pending from signal.h*/ -#define PF_KILLING 0x00000001 - - -/* - * wait.h cannot include linux/shed/signal.h , so workaround as hung_long_and_fatal_signal_pending - * return fatal_signal_pending(p) && (p->flags & PF_KILLING) - */ -static inline int hung_long_and_fatal_signal_pending(struct task_struct *p) -{ -#ifdef CONFIG_DETECT_HUNG_TASK - return (unlikely(test_tsk_thread_flag(p, TIF_SIGPENDING))) - && (unlikely(sigismember(&p->pending.signal, SIGKILL))) - && (p->flags & PF_KILLING); -#else - return 0; -#endif -} - -#endif /*__OPLUS_SIGNAL_H*/ diff --git a/drivers/soc/oplus/system/include/oplus_sync_time.h b/drivers/soc/oplus/system/include/oplus_sync_time.h deleted file mode 100755 index 65c93477ab21..000000000000 --- a/drivers/soc/oplus/system/include/oplus_sync_time.h +++ /dev/null @@ -1,74 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, Oplus Mobile Comm Corp., Ltd. -** -** File: oplus_sync_time.h -** Description: Add for Sync App and Kernel time -** -** Version: 1.0 -** Date : 2020/07/22 -** Author: #Zhiming.Chen@ANDROID.DEBUG, 2020/08/06, Add for Sync App and Kernel time -** -** ------------------ Revision History:------------------------ -** -** Zhiming.Chen 2020/08/06 1.0 OPLUS_FEATURE_LOGKIT -****************************************************************/ - -#ifndef _OPLUS_SYNC_TIME_H -#define _OPLUS_SYNC_TIME_H -#include - -static ssize_t watchdog_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - s32 value; - struct timespec ts; - struct rtc_time tm; - - if (count == sizeof(s32)) { - if (copy_from_user(&value, buf, sizeof(s32))) { - return -EFAULT; - } - - } else if (count <= 11) { /* ASCII perhaps? */ - char ascii_value[11]; - unsigned long int ulval; - int ret; - - if (copy_from_user(ascii_value, buf, count)) { - return -EFAULT; - } - - if (count > 10) { - if (ascii_value[10] == '\n') { - ascii_value[10] = '\0'; - - } else { - return -EINVAL; - } - - } else { - ascii_value[count] = '\0'; - } - - ret = kstrtoul(ascii_value, 16, &ulval); - - if (ret) { - pr_debug("%s, 0x%lx, 0x%x\n", ascii_value, ulval, ret); - return -EINVAL; - } - - value = (s32)lower_32_bits(ulval); - - } else { - return -EINVAL; - } - - getnstimeofday(&ts); - rtc_time_to_tm(ts.tv_sec, &tm); - pr_warn("!@WatchDog_%d; %d-%02d-%02d %02d:%02d:%02d.%09lu UTC\n", - value, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); - - return count; -} -#endif /*_OPLUS_SYNC_TIME_H */ diff --git a/drivers/soc/oplus/system/include/oppo_process.h b/drivers/soc/oplus/system/include/oppo_process.h deleted file mode 100755 index d1fdf5860803..000000000000 --- a/drivers/soc/oplus/system/include/oppo_process.h +++ /dev/null @@ -1,103 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, Oplus., All rights reserved. -** File: oplus_process.h -** Description: Add for dump android critical process log -** -** Version: 1.0 -****************************************************************/ - -#ifndef _OPPO_PROCESS_H -#define _OPPO_PROCESS_H - -static inline bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - - struct task_struct *first_child = NULL; - - if (t->children.next - && t->children.next != (struct list_head *)&t->children.next) { - first_child = container_of(t->children.next, struct task_struct, sibling); - } - - if (!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 - && !strcmp(t->parent->comm, "init"))) { - return true; - - } else { - return false; - } - - return false; -} - -static inline bool is_systemserver_process(struct task_struct *t) -{ - if (!strcmp(t->comm, "system_server") - || !strncmp(t->group_leader->comm, "Binder:", 7)) { - return true; - - } else { - return false; - } -} - -static inline bool is_key_process(struct task_struct *t) -{ - struct pid *pgrp; - struct task_struct *taskp; - - if (t->pid == t->tgid) { - if (is_systemserver_process(t) || is_zygote_process(t)) { - return true; - } - - } else { - pgrp = task_pgrp(t); - - if (pgrp != NULL) { - taskp = pid_task(pgrp, PIDTYPE_PID); - - if (taskp != NULL && (is_systemserver_process(taskp) - || is_zygote_process(taskp))) { - return true; - } - } - } - - return false; -} - -static inline bool oppo_is_android_core_group(struct pid *pgrp) -{ - struct task_struct *p; - - do_each_pid_task(pgrp, PIDTYPE_PGID, p) { - if ((!strcmp(p->comm, "zygote")) || (!strcmp(p->comm, "main"))) { - printk("oppo_is_android_core_group: find zygote will be hungup, ignore it \n"); - return true; - } - } - while_each_pid_task(pgrp, PIDTYPE_PGID, p); - - return false; -} - -static inline bool is_critial_process(struct task_struct *t) -{ - if (t->group_leader && (!strcmp(t->group_leader->comm, "system_server") - || !strncmp(t->group_leader->comm, "Binder:", 7) - || is_zygote_process(t) || !strcmp(t->group_leader->comm, "surfaceflinger") - || !strcmp(t->group_leader->comm, "servicemanager"))) { - if (t->pid == t->tgid) { - return true; - - } else { - return false; - } - - } else { - return false; - } -} -#endif /*_OPPO_PROCESS_H */ diff --git a/drivers/soc/oplus/system/include/proc.h b/drivers/soc/oplus/system/include/proc.h deleted file mode 100755 index ce709c5828ac..000000000000 --- a/drivers/soc/oplus/system/include/proc.h +++ /dev/null @@ -1,21 +0,0 @@ -/************************************************************ - * Copyright 2017 OPLUS Mobile Comm Corp., Ltd. - * All rights reserved. - * - * Description : disable selinux denied log in MP version - * - * - ** Version: 1 - ** Date created: 2016/01/06 - ** Author: sijiaquan@ANDROID.SELINUX - ** ------------------------------- Revision History: --------------------------------------- - ** - ** sijiaquan 2017/12/12 create this file - ************************************************************/ -#ifndef _SELINUX_PROC_H_ -#define _SELINUX_PROC_H_ - -int is_avc_audit_enable(void); -int init_denied_proc(void); - -#endif /* _SELINUX_PROC_H_ */ diff --git a/drivers/soc/oplus/system/include/qcom_minidump_enhance.h b/drivers/soc/oplus/system/include/qcom_minidump_enhance.h deleted file mode 100755 index 108a8feaa4a1..000000000000 --- a/drivers/soc/oplus/system/include/qcom_minidump_enhance.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _QCOM_MINIDUMP_CUSTOMIZED_H_ -#define _QCOM_MINIDUMP_CUSTOMIZED_H_ - -#include - -bool is_fulldump_enable(void); -void oplus_switch_fulldump(int on); -void do_restart_early(enum reboot_mode reboot_mode, const char *cmd); -void do_poweroff_early(void); -void dumpcpuregs(struct pt_regs *pt_regs); -void register_cpu_contex(void); - -#endif /* _QCOM_MINIDUMP_CUSTOMIZED_H_ */ - diff --git a/drivers/soc/oplus/system/include/qcom_pmicwd.h b/drivers/soc/oplus/system/include/qcom_pmicwd.h deleted file mode 100755 index 95ff41628472..000000000000 --- a/drivers/soc/oplus/system/include/qcom_pmicwd.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __QCOM_PMICWD_H__ -#define __QCOM_PMICWD_H__ - -#include -#include - -static inline int qpnp_pon_masked_write(struct qpnp_pon *pon, u16 addr, u8 mask, - u8 val) -{ - int rc; - - rc = regmap_update_bits(pon->regmap, addr, mask, val); - - if (rc) - dev_err(pon->dev, "Register write failed, addr=0x%04X, rc=%d\n", - addr, rc); - - return rc; -} - -#endif /*__QCOM_PMICWD_H__*/ diff --git a/drivers/soc/oplus/system/include/uboot_utils.h b/drivers/soc/oplus/system/include/uboot_utils.h deleted file mode 100755 index 1050945efa5f..000000000000 --- a/drivers/soc/oplus/system/include/uboot_utils.h +++ /dev/null @@ -1,163 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __OPPO_UBOOT_UTIL__ -#define __OPPO_UBOOT_UTIL__ - -#include -#include - -#define SIZE_128B 0x00000080 -#define SIZE_256B 0x00000100 -#define SIZE_1KB 0x00000400 -#define SIZE_2KB 0x00000800 -#define SIZE_3KB 0x00000C00 -#define SIZE_4KB 0x00001000 -#define SIZE_5KB 0x00001400 -#define SIZE_6KB 0x00001800 -#define SIZE_8KB 0x00002000 -#define SIZE_10KB 0x00002800 -#define SIZE_12KB 0x00003000 -#define SIZE_16KB 0x00004000 -#define SIZE_18KB 0x00004800 -#define SIZE_20KB 0x00005000 -#define SIZE_22KB 0x00005800 -#define SIZE_24KB 0x00006000 -#define SIZE_26KB 0x00006800 -#define SIZE_28KB 0x00007000 -#define SIZE_30KB 0x00007800 -#define SIZE_32KB 0x00008000 -#define SIZE_36KB 0x00009000 -#define SIZE_34KB 0x00008800 -#define SIZE_38KB 0x00009800 -#define SIZE_36KB 0x00009000 -#define SIZE_40KB 0x0000A000 -#define SIZE_42KB 0x0000A800 -#define SIZE_44KB 0x0000B000 -#define SIZE_46KB 0x0000B800 -#define SIZE_48KB 0x0000C000 -#define SIZE_52KB 0x0000D000 -#define SIZE_56KB 0x0000E000 -#define SIZE_60KB 0x0000F000 -#define SIZE_64KB 0x00010000 -#define SIZE_66KB 0x00010800 -#define SIZE_68KB 0x00011000 -#define SIZE_70KB 0x00011800 -#define SIZE_72KB 0x00012000 -#define SIZE_76KB 0x00013000 -#define SIZE_78KB 0x00013800 -#define SIZE_80KB 0x00014000 -#define SIZE_84KB 0x00015000 -#define SIZE_88KB 0x00016000 -#define SIZE_90KB 0x00016800 -#define SIZE_92KB 0x00017000 -#define SIZE_94KB 0x00017800 -#define SIZE_95KB 0x00017C00 -#define SIZE_96KB 0x00018000 -#define SIZE_100KB 0x00019000 -#define SIZE_110KB 0x0001B800 -#define SIZE_120KB 0x0001E000 -#define SIZE_128KB 0x00020000 -#define SIZE_140KB 0x00023000 -#define SIZE_144KB 0x00024000 -#define SIZE_148KB 0x00025000 -#define SIZE_152KB 0x00026000 -#define SIZE_153KB 0x00026400 -#define SIZE_154KB 0x00026800 -#define SIZE_156KB 0x00027000 -#define SIZE_160KB 0x00028000 -#define SIZE_172KB 0x0002B000 -#define SIZE_184KB 0x0002E000 -#define SIZE_192KB 0x00030000 -#define SIZE_204KB 0x00033000 -#define SIZE_212KB 0x00035000 -#define SIZE_216KB 0x00036000 -#define SIZE_232KB 0x0003A000 -#define SIZE_240KB 0x0003C000 -#define SIZE_256KB 0x00040000 -#define SIZE_294KB 0x00049800 -#define SIZE_296KB 0x0004A000 -#define SIZE_298KB 0x0004A800 -#define SIZE_300KB 0x0004B000 -#define SIZE_306KB 0x0004C800 -#define SIZE_310KB 0x0004D800 -#define SIZE_312KB 0x0004E000 -#define SIZE_314KB 0x0004E800 -#define SIZE_316KB 0x0004f000 -#define SIZE_320KB 0x00050000 -#define SIZE_324KB 0x00051000 -#define SIZE_332KB 0x00053000 -#define SIZE_340KB 0x00055000 -#define SIZE_344KB 0x00056000 -#define SIZE_350KB 0x00057800 -#define SIZE_392KB 0x00062000 -#define SIZE_400KB 0x00064000 -#define SIZE_402KB 0x00064800 -#define SIZE_416KB 0x00068000 -#define SIZE_436KB 0x0006D000 -#define SIZE_440KB 0x0006E000 -#define SIZE_448KB 0x00070000 -#define SIZE_450KB 0x00070800 -#define SIZE_454KB 0x00071800 -#define SIZE_456KB 0x00072000 -#define SIZE_458KB 0x00072800 -#define SIZE_460KB 0x00073000 -#define SIZE_466KB 0x00074800 -#define SIZE_470KB 0x00075800 -#define SIZE_478KB 0x00077800 -#define SIZE_482KB 0x00078800 -#define SIZE_486KB 0x00079800 -#define SIZE_490KB 0x0007A800 -#define SIZE_498KB 0x0007C800 -#define SIZE_504KB 0x0007e000 -#define SIZE_506KB 0x0007e800 -#define SIZE_512KB 0x00080000 -#define SIZE_530KB 0x00084800 -#define SIZE_545KB 0x00088400 -#define SIZE_561KB 0x0008C400 -#define SIZE_612KB 0x00099000 -#define SIZE_680KB 0x000AA000 -#define SIZE_712KB 0x000B2000 -#define SIZE_716KB 0x000B3000 -#define SIZE_724KB 0x000B5000 -#define SIZE_1MB 0x00100000 -#define SIZE_1_5_MB 0x00180000 -#define SIZE_2MB 0x00200000 -#define SIZE_6MB 0x00600000 -#define SIZE_16MB 0x01000000 -#define SIZE_17MB 0x01100000 -#define SIZE_68MB 0x04400000 -#define SIZE_72MB 0x04800000 -#define SIZE_80MB 0x05000000 -#define SIZE_150MB 0x09600000 -#define SIZE_1GB 0x40000000 -#define SIZE_1_5GB 0x60000000 -#define SIZE_2GB 0x80000000 - -#define SCL_SBL1_DDR_BASE 0x80700000 -#define SCL_SBL1_DDR_SIZE SIZE_1MB - -#define SCL_SBL1_DDR_BOOT_LOG_BUF_SIZE SIZE_8KB -#define SCL_SBL1_DDR_BOOT_TIME_MARKER_BUF_SIZE SIZE_256B -#define SERIAL_BUFFER_SIZE SIZE_32KB - -static void *uboot_reserved_remap = NULL; -static phys_addr_t uboot_base; -static phys_addr_t uboot_size; - - -#if defined(CONFIG_PRINTK) && defined(CONFIG_OPLUS_FEATURE_UBOOT_LOG) -bool back_kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, - char *buf, size_t size, size_t *len); - -#else -static inline bool back_kmsg_dump_get_buffer(struct kmsg_dumper *dumper, - bool syslog, - char *buf, size_t size, size_t *len) -{ - return false; -} -#endif - -#endif/*__OPPO_UBOOT_UTIL__*/ diff --git a/drivers/soc/oplus/system/mdmrst/Kconfig b/drivers/soc/oplus/system/mdmrst/Kconfig deleted file mode 100755 index f7db81574d24..000000000000 --- a/drivers/soc/oplus/system/mdmrst/Kconfig +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_RECORD_MDMRST -bool "config record mdmrst" -help - define this config to count the modem restart times. \ No newline at end of file diff --git a/drivers/soc/oplus/system/mdmrst/Makefile b/drivers/soc/oplus/system/mdmrst/Makefile deleted file mode 100755 index c14b7a41fc35..000000000000 --- a/drivers/soc/oplus/system/mdmrst/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_RECORD_MDMRST) += oplus_mdmrst.o diff --git a/drivers/soc/oplus/system/mdmrst/oplus_mdmrst.c b/drivers/soc/oplus/system/mdmrst/oplus_mdmrst.c deleted file mode 100755 index 22ef05eebcb7..000000000000 --- a/drivers/soc/oplus/system/mdmrst/oplus_mdmrst.c +++ /dev/null @@ -1,174 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include - - -/*****yixue.ge ******/ -#define MDMREASON_BUF_LEN 128 -static wait_queue_head_t mdmreason_wq; -static int mdmreason_flag = 0; -static char mdmreason_buf[MDMREASON_BUF_LEN] = {0}; -void mdmreason_set(char * buf) -{ - if ((buf != NULL) && (buf[0] != '\0')) { - if (strlen(buf) >= MDMREASON_BUF_LEN) { - memcpy(mdmreason_buf, buf, MDMREASON_BUF_LEN - 1); - mdmreason_buf[MDMREASON_BUF_LEN - 1] = '\0'; - } else { - strcpy(mdmreason_buf, buf); - } - mdmreason_flag = 1; - wake_up_interruptible(&mdmreason_wq); - } -} -EXPORT_SYMBOL(mdmreason_set); - -/*this write interface just use for test*/ -static ssize_t mdmreason_write(struct file *file, const char __user * buf, - size_t count, loff_t * ppos) -{ - /*just for test*/ - if (count > MDMREASON_BUF_LEN) { - count = MDMREASON_BUF_LEN; - } - if (count > *ppos) { - count -= *ppos; - } - else - count = 0; - - printk("mdmreason_write is called\n"); - - if (copy_from_user(mdmreason_buf, buf, count)) { - return -EFAULT; - } - *ppos += count; - - mdmreason_flag = 1; - wake_up_interruptible(&mdmreason_wq); - - return count; -} - - -static unsigned int mdmreason_poll (struct file *file, struct poll_table_struct *pt) -{ - unsigned int ptr = 0; - - poll_wait(file, &mdmreason_wq, pt); - - if (mdmreason_flag) { - ptr |= POLLIN | POLLRDNORM; - mdmreason_flag = 0; - } - return ptr; -} - -static ssize_t mdmreason_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - size_t size = 0; - - if (count > MDMREASON_BUF_LEN) { - count = MDMREASON_BUF_LEN; - } - size = count < strlen(mdmreason_buf) ? count : strlen(mdmreason_buf); - - if (size > *ppos) { - size -= *ppos; - } - else - size = 0; - - if (copy_to_user(buf, mdmreason_buf, size)) { - return -EFAULT; - } - /*mdmreason_flag = 0;*/ - *ppos += size; - - return size; -} - -static int mdmreason_release (struct inode *inode, struct file *file) -{ - /*mdmreason_flag = 0;*/ - /*memset(mdmreason_buf, 0, MDMREASON_BUF_LEN);*/ - return 0; -} - - -static const struct file_operations mdmreason_device_fops = { - .owner = THIS_MODULE, - .read = mdmreason_read, - .write = mdmreason_write, - .poll = mdmreason_poll, - .llseek = generic_file_llseek, - .release = mdmreason_release, -}; - -static struct miscdevice mdmreason_device = { - MISC_DYNAMIC_MINOR, "mdmreason", &mdmreason_device_fops -}; - - - -/*****yixue.ge add end******/ - -wait_queue_head_t mdmrst_wq; -/*unsigned int mdmrest_flg;*/ -unsigned int mdmrest_count = 0; - -ssize_t mdmrst_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - char *tmp = "1"; - - /*wait_event_interruptible(mdmrst_wq, mdmrest_flg);*/ - /*if (copy_to_user(buf, tmp, strlen(tmp)))*/ - if (copy_to_user(buf, &mdmrest_count, 1)) { - return -EFAULT; - } - /*mdmrest_flg = 0;*/ - - return strlen(tmp); -} - -static const struct file_operations mdmrst_device_fops = { - .owner = THIS_MODULE, - .read = mdmrst_read, -}; - -static struct miscdevice mdmrst_device = { - MISC_DYNAMIC_MINOR, "mdmrst", &mdmrst_device_fops -}; - -static int __init mdmrst_init(void) -{ - init_waitqueue_head(&mdmrst_wq); - init_waitqueue_head(&mdmreason_wq); - misc_register(&mdmreason_device); - return misc_register(&mdmrst_device); -} - -static void __exit mdmrst_exit(void) -{ - misc_deregister(&mdmreason_device); - misc_deregister(&mdmrst_device); -} - -module_init(mdmrst_init); -module_exit(mdmrst_exit); -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Oplus"); diff --git a/drivers/soc/oplus/system/mm_osvelte/CHANGELOG.md b/drivers/soc/oplus/system/mm_osvelte/CHANGELOG.md deleted file mode 100644 index 7946083b5d69..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/CHANGELOG.md +++ /dev/null @@ -1,45 +0,0 @@ -# mm_osvelte 0.1.1 (2022-02-24) - ---- - -Bug fixes: - -* 修复在注册 vendor_hook 失败,打印导致 dump 的问题 - - ```osvelte: - pr_err("%s regist extra meminfo proc failed.\n"); - ``` - -Feature enhancements: - -* **lowmem-dbg** 打印增加版本号 - - ```osvelte: - [ 174.763430] osvelte: lowmem_dbg start osvelte v0.1.1 <<<<<<< - ``` -* **lowmem-dbg** 增加 zone 和 node 的使用打印,因为有遇到过 `isolated_file` 过大,导致内存分配过程中 `msleep` 的问题 - - ```osvelte: - [ 174.763491] osvelte: active_anon:37064 inactive_anon:2092183 isolated_anon:0 active_file:120745 inactive_file:93988 isolated_file:0 unevictable:33154 dirty:150 writeback:0 slab_reclaimable:35687 slab_unreclaimable:106681 mapped:174055 shmem:5104 pagetables:28048 bounce:0 free:65242 free_pcp:3930 free_cma:3410 - [ 174.763528] osvelte: DMA32 free:127856kB min:2896kB low:23148kB high:29356kB reserved_highatomic:0KB active_anon:26500kB inactive_anon:2077496kB active_file:79400kB inactive_file:11400kB unevictable:20kB writepending:32kB present:3143676kB managed:2484184kB mlocked:20kB pagetables:10880kB bounce:0kB free_pcp:8984kB local_pcp:1496kB free_cma:13680kB - [ 174.763559] osvelte: Normal free:133112kB min:10712kB low:85616kB high:108560kB reserved_highatomic:4096KB active_anon:121756kB inactive_anon:6291256kB active_file:403580kB inactive_file:364552kB unevictable:132596kB writepending:552kB - ``` -* **lowmem-dbg** 支持增加 zram 使用率打印 - - ```osvelte: - [ 174.763609] osvelte: hybridswap same_pages: 118604 compr_data_size: 140730 pages_stored: 575892 - ``` -* **sys-memstat** 支持打印 osvelte 版本号 - - ```osvelte: - OP520F:/ # cat /proc/osvelte/version - osvelte v0.1.1 based on kernel-5.10 - ``` -* **sys-memstat** 支持打印 zram 使用情况 - - ```osvelte: - OP520F:/ # cat /proc/osvelte/hybridswap_info - SamePages: 5765648 kB - ComprDataSize: 204724 kB - PagesStored: 6551528 kB - ``` diff --git a/drivers/soc/oplus/system/mm_osvelte/Kconfig b/drivers/soc/oplus/system/mm_osvelte/Kconfig deleted file mode 100644 index 53d8b9163deb..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -config OPLUS_FEATURE_MM_OSVELTE - tristate "osvelte driver" - default n - help - This driver used for memory debugging. diff --git a/drivers/soc/oplus/system/mm_osvelte/Makefile b/drivers/soc/oplus/system/mm_osvelte/Makefile deleted file mode 100644 index 902d59d2cded..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -oplus_bsp_mm_osvelte-y += proc-memstat.o -oplus_bsp_mm_osvelte-y += logger.o -oplus_bsp_mm_osvelte-y += lowmem-dbg.o -oplus_bsp_mm_osvelte-y += sys-memstat.o -oplus_bsp_mm_osvelte-y += vsprintf-dup.o - -ifdef CONFIG_QCOM_KGSL -ccflags-y += -I$(srctree)/drivers/gpu/msm/ -endif - -obj-$(CONFIG_OPLUS_FEATURE_MM_OSVELTE) += oplus_bsp_mm_osvelte.o diff --git a/drivers/soc/oplus/system/mm_osvelte/VERSION b/drivers/soc/oplus/system/mm_osvelte/VERSION deleted file mode 100755 index 15e4d58342e4..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/VERSION +++ /dev/null @@ -1 +0,0 @@ -67917c7dec6a sync code & fix coverity diff --git a/drivers/soc/oplus/system/mm_osvelte/common.h b/drivers/soc/oplus/system/mm_osvelte/common.h deleted file mode 100755 index 062b2ba29dea..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/common.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#ifndef _OSVELTE_COMMON_H -#define _OSVELTE_COMMON_H - -#include - -#define KMODULE_NAME "oplus_bsp_mm_osvelte" - -#define DEV_NAME "osvelte" -#define DEV_PATH "/dev/" DEV_NAME - -#define LOG_TAG DEV_NAME - -#define __COMMONIO 0xFA -#define CMD_OSVELTE_GET_VERSION _IO(__COMMONIO, 1) /* osvelte version */ - -#define OSVELTE_MAJOR (0) -#define OSVELTE_MINOR (1) -#define OSVELTE_PATCH_NUM (1) -#define OSVELTE_VERSION (OSVELTE_MAJOR << 16 | OSVELTE_MINOR) - -#define osvelte_info(fmt, ...) \ - pr_info(LOG_TAG ": " fmt, ##__VA_ARGS__) - -#define osvelte_err(fmt, ...) \ - pr_err(LOG_TAG ": " fmt, ##__VA_ARGS__) - -#endif /* _OSVELTE_COMMON_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/logger.c b/drivers/soc/oplus/system/mm_osvelte/logger.c deleted file mode 100755 index 3e2c5069ad16..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/logger.c +++ /dev/null @@ -1,885 +0,0 @@ -/* - * drivers/misc/logger.c - * - * A Logging Subsystem - * - * Copyright (C) 2007-2008 Google, Inc. - * - * Robert Love - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#define pr_fmt(fmt) "logger: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "logger.h" -#include "common.h" -#include "memstat.h" -#include "sys-memstat.h" -#include "proc-memstat.h" -#include "lowmem-dbg.h" - -/** - * struct logger_log - represents a specific log, such as 'main' or 'radio' - * @buffer: The actual ring buffer - * @misc: The "misc" device representing the log - * @wq: The wait queue for @readers - * @readers: This log's readers - * @mutex: The mutex that protects the @buffer - * @w_off: The current write head offset - * @head: The head, or location that readers start reading at. - * @size: The size of the log - * @logs: The list of log channels - * - * This structure lives from module insertion until module removal, so it does - * not need additional reference counting. The structure is protected by the - * mutex 'mutex'. - */ -struct logger_log { - unsigned char *buffer; - unsigned char *cache; - struct miscdevice misc; - wait_queue_head_t wq; - struct list_head readers; - struct mutex mutex; - size_t w_off; - size_t head; - size_t size; - struct list_head logs; -}; - -static LIST_HEAD(log_list); - -static inline void current_kernel_time(struct timespec64 *ts) -{ - ktime_get_coarse_real_ts64(ts); -} - -/* logger_offset - returns index 'n' into the log via (optimized) modulus */ -static size_t logger_offset(struct logger_log *log, size_t n) -{ - return n & (log->size - 1); -} - - -/* - * file_get_log - Given a file structure, return the associated log - * - * This isn't aesthetic. We have several goals: - * - * 1) Need to quickly obtain the associated log during an I/O operation - * 2) Readers need to maintain state (logger_reader) - * 3) Writers need to be very fast (open() should be a near no-op) - * - * In the reader case, we can trivially go file->logger_reader->logger_log. - * For a writer, we don't want to maintain a logger_reader, so we just go - * file->logger_log. Thus what file->private_data points at depends on whether - * or not the file was opened for reading. This function hides that dirtiness. - */ -static inline struct logger_log *file_get_log(struct file *file) -{ - if (file->f_mode & FMODE_READ) { - struct logger_reader *reader = file->private_data; - - return reader->log; - } - - return file->private_data; -} - -/* - * get_entry_header - returns a pointer to the logger_entry header within - * 'log' starting at offset 'off'. A temporary logger_entry 'scratch' must - * be provided. Typically the return value will be a pointer within - * 'logger->buf'. However, a pointer to 'scratch' may be returned if - * the log entry spans the end and beginning of the circular buffer. - */ -static struct logger_entry *get_entry_header(struct logger_log *log, - size_t off, struct logger_entry *scratch) -{ - size_t len = min(sizeof(struct logger_entry), log->size - off); - - if (len != sizeof(struct logger_entry)) { - memcpy(((void *) scratch), log->buffer + off, len); - memcpy(((void *) scratch) + len, log->buffer, - sizeof(struct logger_entry) - len); - return scratch; - } - - return (struct logger_entry *)(log->buffer + off); -} - -/* - * get_entry_msg_len - Grabs the length of the message of the entry - * starting from from 'off'. - * - * An entry length is 2 bytes (16 bits) in host endian order. - * In the log, the length does not include the size of the log entry structure. - * This function returns the size including the log entry structure. - * - * Caller needs to hold log->mutex. - */ -static __u32 get_entry_msg_len(struct logger_log *log, size_t off) -{ - struct logger_entry scratch; - struct logger_entry *entry; - - entry = get_entry_header(log, off, &scratch); - return entry->len; -} - -static size_t get_user_hdr_len(int ver) -{ - if (ver < 2) { - return sizeof(struct user_logger_entry_compat); - } - - return sizeof(struct logger_entry); -} - -static ssize_t copy_header_to_user(int ver, struct logger_entry *entry, - char __user *buf) -{ - void *hdr; - size_t hdr_len; - struct user_logger_entry_compat v1; - - if (ver < 2) { - v1.len = entry->len; - v1.__pad = 0; - v1.pid = entry->pid; - v1.tid = entry->tid; - v1.sec = entry->sec; - v1.nsec = entry->nsec; - hdr = &v1; - hdr_len = sizeof(struct user_logger_entry_compat); - - } else { - hdr = entry; - hdr_len = sizeof(struct logger_entry); - } - - return copy_to_user(buf, hdr, hdr_len); -} - -/* - * do_read_log_to_user - reads exactly 'count' bytes from 'log' into the - * user-space buffer 'buf'. Returns 'count' on success. - * - * Caller must hold log->mutex. - */ -static ssize_t do_read_log_to_user(struct logger_log *log, - struct logger_reader *reader, - char __user *buf, - size_t count) -{ - struct logger_entry scratch; - struct logger_entry *entry; - size_t len; - size_t msg_start; - - /* - * First, copy the header to userspace, using the version of - * the header requested - */ - entry = get_entry_header(log, reader->r_off, &scratch); - - if (copy_header_to_user(reader->r_ver, entry, buf)) { - return -EFAULT; - } - - count -= get_user_hdr_len(reader->r_ver); - buf += get_user_hdr_len(reader->r_ver); - msg_start = logger_offset(log, - reader->r_off + sizeof(struct logger_entry)); - - /* - * We read from the msg in two disjoint operations. First, we read from - * the current msg head offset up to 'count' bytes or to the end of - * the log, whichever comes first. - */ - len = min(count, log->size - msg_start); - - if (copy_to_user(buf, log->buffer + msg_start, len)) { - return -EFAULT; - } - - /* - * Second, we read any remaining bytes, starting back at the head of - * the log. - */ - if (count != len) { - if (copy_to_user(buf + len, log->buffer, count - len)) { - return -EFAULT; - } - } - - reader->r_off = logger_offset(log, reader->r_off + - sizeof(struct logger_entry) + count); - - return count + get_user_hdr_len(reader->r_ver); -} - -/* - * get_next_entry_by_uid - Starting at 'off', returns an offset into - * 'log->buffer' which contains the first entry readable by 'euid' - */ -static size_t get_next_entry_by_uid(struct logger_log *log, - size_t off, kuid_t euid) -{ - while (off != log->w_off) { - struct logger_entry *entry; - struct logger_entry scratch; - size_t next_len; - - entry = get_entry_header(log, off, &scratch); - - if (uid_eq(entry->euid, euid)) { - return off; - } - - next_len = sizeof(struct logger_entry) + entry->len; - off = logger_offset(log, off + next_len); - } - - return off; -} - -/* - * logger_read - our log's read() method - * - * Behavior: - * - * - O_NONBLOCK works - * - If there are no log entries to read, blocks until log is written to - * - Atomically reads exactly one log entry - * - * Will set errno to EINVAL if read - * buffer is insufficient to hold next entry. - */ -static ssize_t logger_read(struct file *file, char __user *buf, - size_t count, loff_t *pos) -{ - struct logger_reader *reader = file->private_data; - struct logger_log *log = reader->log; - ssize_t ret; - DEFINE_WAIT(wait); - -start: - - while (1) { - mutex_lock(&log->mutex); - - prepare_to_wait(&log->wq, &wait, TASK_INTERRUPTIBLE); - - ret = (log->w_off == reader->r_off); - mutex_unlock(&log->mutex); - - if (!ret) { - break; - } - - if (file->f_flags & O_NONBLOCK) { - ret = -EAGAIN; - break; - } - - if (signal_pending(current)) { - ret = -EINTR; - break; - } - - schedule(); - } - - finish_wait(&log->wq, &wait); - - if (ret) { - return ret; - } - - mutex_lock(&log->mutex); - - if (!reader->r_all) - reader->r_off = get_next_entry_by_uid(log, - reader->r_off, current_euid()); - - /* is there still something to read or did we race? */ - if (unlikely(log->w_off == reader->r_off)) { - mutex_unlock(&log->mutex); - goto start; - } - - /* get the size of the next entry */ - ret = get_user_hdr_len(reader->r_ver) + - get_entry_msg_len(log, reader->r_off); - - if (count < ret) { - ret = -EINVAL; - goto out; - } - - /* get exactly one entry from the log */ - ret = do_read_log_to_user(log, reader, buf, ret); - -out: - mutex_unlock(&log->mutex); - - return ret; -} - -/* - * get_next_entry - return the offset of the first valid entry at least 'len' - * bytes after 'off'. - * - * Caller must hold log->mutex. - */ -static size_t get_next_entry(struct logger_log *log, size_t off, size_t len) -{ - size_t count = 0; - - do { - size_t nr = sizeof(struct logger_entry) + - get_entry_msg_len(log, off); - off = logger_offset(log, off + nr); - count += nr; - } while (count < len); - - return off; -} - -/* - * is_between - is a < c < b, accounting for wrapping of a, b, and c - * positions in the buffer - * - * That is, if ab, check for c outside (not between) a and b - * - * |------- a xxxxxxxx b --------| - * c^ - * - * |xxxxx b --------- a xxxxxxxxx| - * c^ - * or c^ - */ -static inline int is_between(size_t a, size_t b, size_t c) -{ - if (a < b) { - /* is c between a and b? */ - if (a < c && c <= b) { - return 1; - } - - } else { - /* is c outside of b through a? */ - if (c <= b || a < c) { - return 1; - } - } - - return 0; -} - -/* - * fix_up_readers - walk the list of all readers and "fix up" any who were - * lapped by the writer; also do the same for the default "start head". - * We do this by "pulling forward" the readers and start head to the first - * entry after the new write head. - * - * The caller needs to hold log->mutex. - */ -static void fix_up_readers(struct logger_log *log, size_t len) -{ - size_t old = log->w_off; - size_t new = logger_offset(log, old + len); - struct logger_reader *reader; - - if (is_between(old, new, log->head)) { - log->head = get_next_entry(log, log->head, len); - } - - list_for_each_entry(reader, &log->readers, list) - - if (is_between(old, new, reader->r_off)) { - reader->r_off = get_next_entry(log, reader->r_off, len); - } -} - -/* - * logger_write_iter - our write method, implementing support for write(), - * writev(), and aio_write(). Writes are our fast path, and we try to optimize - * them above all else. - */ -static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) -{ - struct logger_log *log = file_get_log(iocb->ki_filp); - struct logger_entry header; - struct timespec64 now; - size_t len, count, w_off; - - count = min_t(size_t, iov_iter_count(from), LOGGER_ENTRY_MAX_PAYLOAD); - - current_kernel_time(&now); - - header.pid = current->tgid; - header.tid = current->pid; - header.sec = now.tv_sec; - header.nsec = now.tv_nsec; - header.euid = current_euid(); - header.len = count; - header.hdr_size = sizeof(struct logger_entry); - - /* null writes succeed, return zero */ - if (unlikely(!header.len)) { - return 0; - } - - mutex_lock(&log->mutex); - - /* - * Fix up any readers, pulling them forward to the first readable - * entry after (what will be) the new write offset. We do this now - * because if we partially fail, we can end up with clobbered log - * entries that encroach on readable buffer. - */ - fix_up_readers(log, sizeof(struct logger_entry) + header.len); - - len = min(sizeof(header), log->size - log->w_off); - memcpy(log->buffer + log->w_off, &header, len); - memcpy(log->buffer, (char *)&header + len, sizeof(header) - len); - - /* Work with a copy until we are ready to commit the whole entry */ - w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry)); - - len = min(count, log->size - w_off); - - if (copy_from_iter(log->buffer + w_off, len, from) != len) { - /* - * Note that by not updating log->w_off, this abandons the - * portion of the new entry that *was* successfully - * copied, just above. This is intentional to avoid - * message corruption from missing fragments. - */ - mutex_unlock(&log->mutex); - return -EFAULT; - } - - if (copy_from_iter(log->buffer, count - len, from) != count - len) { - mutex_unlock(&log->mutex); - return -EFAULT; - } - - log->w_off = logger_offset(log, w_off + count); - mutex_unlock(&log->mutex); - - /* wake up any blocked readers */ - wake_up_interruptible(&log->wq); - - return len; -} - -static struct logger_log *get_log_from_minor(int minor) -{ - struct logger_log *log; - - list_for_each_entry(log, &log_list, logs) - - if (log->misc.minor == minor) { - return log; - } - - return NULL; -} - -/* - * logger_open - the log's open() file operation - * - * Note how near a no-op this is in the write-only case. Keep it that way! - */ -static int logger_open(struct inode *inode, struct file *file) -{ - struct logger_log *log; - int ret; - - ret = nonseekable_open(inode, file); - - if (ret) { - return ret; - } - - log = get_log_from_minor(MINOR(inode->i_rdev)); - - if (!log) { - return -ENODEV; - } - - if (file->f_mode & FMODE_READ) { - struct logger_reader *reader; - - reader = kmalloc(sizeof(struct logger_reader), GFP_KERNEL); - - if (!reader) { - return -ENOMEM; - } - - reader->log = log; - reader->r_ver = 1; - reader->r_all = in_egroup_p(inode->i_gid) || - capable(CAP_SYSLOG); - - mutex_init(&reader->mutex); - reader->arr_ms = NULL; - - INIT_LIST_HEAD(&reader->list); - - mutex_lock(&log->mutex); - reader->r_off = log->head; - list_add_tail(&reader->list, &log->readers); - mutex_unlock(&log->mutex); - - file->private_data = reader; - - } else { - file->private_data = log; - } - - return 0; -} - -/* - * logger_release - the log's release file operation - * - * Note this is a total no-op in the write-only case. Keep it that way! - */ -static int logger_release(struct inode *ignored, struct file *file) -{ - if (file->f_mode & FMODE_READ) { - struct logger_reader *reader = file->private_data; - struct logger_log *log = reader->log; - - mutex_lock(&log->mutex); - list_del(&reader->list); - mutex_unlock(&log->mutex); - - if (reader->arr_ms) - vfree(reader->arr_ms); - kfree(reader); - } - - return 0; -} - -/* - * logger_poll - the log's poll file operation, for poll/select/epoll - * - * Note we always return POLLOUT, because you can always write() to the log. - * Note also that, strictly speaking, a return value of POLLIN does not - * guarantee that the log is readable without blocking, as there is a small - * chance that the writer can lap the reader in the interim between poll() - * returning and the read() request. - */ -static unsigned int logger_poll(struct file *file, poll_table *wait) -{ - struct logger_reader *reader; - struct logger_log *log; - unsigned int ret = POLLOUT | POLLWRNORM; - - if (!(file->f_mode & FMODE_READ)) { - return ret; - } - - reader = file->private_data; - log = reader->log; - - poll_wait(file, &log->wq, wait); - - mutex_lock(&log->mutex); - - if (!reader->r_all) - reader->r_off = get_next_entry_by_uid(log, - reader->r_off, current_euid()); - - if (log->w_off != reader->r_off) { - ret |= POLLIN | POLLRDNORM; - } - - mutex_unlock(&log->mutex); - - return ret; -} - -static long logger_set_version(struct logger_reader *reader, void __user *arg) -{ - int version; - - if (copy_from_user(&version, arg, sizeof(int))) { - return -EFAULT; - } - - if ((version < 1) || (version > 2)) { - return -EINVAL; - } - - reader->r_ver = version; - return 0; -} - -static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - struct logger_log *log = file_get_log(file); - struct logger_reader *reader; - long ret = -EINVAL; - void __user *argp = (void __user *) arg; - - switch (cmd) { - case CMD_OSVELTE_GET_VERSION: - if (!(file->f_mode & FMODE_READ)) { - ret = -EBADF; - break; - } - return OSVELTE_VERSION; - } - - ret = proc_memstat_ioctl(file, cmd, arg); - - if (ret != CMD_PROC_MS_INVALID) { - return ret; - } - - mutex_lock(&log->mutex); - - switch (cmd) { - case LOGGER_GET_LOG_BUF_SIZE: - ret = log->size; - break; - - case LOGGER_GET_LOG_LEN: - if (!(file->f_mode & FMODE_READ)) { - ret = -EBADF; - break; - } - - reader = file->private_data; - - if (log->w_off >= reader->r_off) { - ret = log->w_off - reader->r_off; - - } else { - ret = (log->size - reader->r_off) + log->w_off; - } - - break; - - case LOGGER_GET_NEXT_ENTRY_LEN: - if (!(file->f_mode & FMODE_READ)) { - ret = -EBADF; - break; - } - - reader = file->private_data; - - if (!reader->r_all) - reader->r_off = get_next_entry_by_uid(log, - reader->r_off, current_euid()); - - if (log->w_off != reader->r_off) - ret = get_user_hdr_len(reader->r_ver) + - get_entry_msg_len(log, reader->r_off); - - else { - ret = 0; - } - - break; - - case LOGGER_FLUSH_LOG: - if (!(file->f_mode & FMODE_WRITE)) { - ret = -EBADF; - break; - } - - if (!(in_egroup_p(file_inode(file)->i_gid) || - capable(CAP_SYSLOG))) { - ret = -EPERM; - break; - } - - list_for_each_entry(reader, &log->readers, list) - reader->r_off = log->w_off; - log->head = log->w_off; - ret = 0; - break; - - case LOGGER_GET_VERSION: - if (!(file->f_mode & FMODE_READ)) { - ret = -EBADF; - break; - } - - reader = file->private_data; - ret = reader->r_ver; - break; - - case LOGGER_SET_VERSION: - if (!(file->f_mode & FMODE_READ)) { - ret = -EBADF; - break; - } - - reader = file->private_data; - ret = logger_set_version(reader, argp); - break; - } - - mutex_unlock(&log->mutex); - - return ret; -} - -static const struct file_operations logger_fops = { - .owner = THIS_MODULE, - .read = logger_read, - .write_iter = logger_write_iter, - .poll = logger_poll, - .unlocked_ioctl = logger_ioctl, - .compat_ioctl = logger_ioctl, - .open = logger_open, - .release = logger_release, -}; - -/* - * Log size must must be a power of two, and greater than - * (LOGGER_ENTRY_MAX_PAYLOAD + sizeof(struct logger_entry)). - */ -static int __init create_log(char *log_name, int size) -{ - int ret = 0; - struct logger_log *log; - unsigned char *buffer; - - buffer = vmalloc(size); - - if (buffer == NULL) { - return -ENOMEM; - } - - log = kzalloc(sizeof(struct logger_log), GFP_KERNEL); - - if (log == NULL) { - ret = -ENOMEM; - goto out_free_buffer; - } - - log->buffer = buffer; - log->cache = NULL; - - log->misc.minor = MISC_DYNAMIC_MINOR; - log->misc.name = kstrdup(log_name, GFP_KERNEL); - - if (log->misc.name == NULL) { - ret = -ENOMEM; - goto out_free_log; - } - - log->misc.fops = &logger_fops; - log->misc.parent = NULL; - - init_waitqueue_head(&log->wq); - INIT_LIST_HEAD(&log->readers); - mutex_init(&log->mutex); - log->w_off = 0; - log->head = 0; - log->size = size; - - INIT_LIST_HEAD(&log->logs); - list_add_tail(&log->logs, &log_list); - - /* finally, initialize the misc device for this log */ - ret = misc_register(&log->misc); - - if (unlikely(ret)) { - pr_err("failed to register misc device for log '%s'!\n", - log->misc.name); - goto out_free_misc_name; - } - - pr_info("created %luK log '%s'\n", - (unsigned long) log->size >> 10, log->misc.name); - - return 0; - -out_free_misc_name: - kfree(log->misc.name); - -out_free_log: - kfree(log); - -out_free_buffer: - vfree(buffer); - return ret; -} - -static int __init logger_init(void) -{ - int ret; - - ret = create_log(DEV_NAME, 1*1024*1024); - if (unlikely(ret)) - goto out; - - ret = osvelte_lowmem_dbg_init(); - if (unlikely(ret)) - goto out; - - ret = osvelte_sys_memstat_init(); - if (unlikely(ret)) - goto out; -out: - return ret; -} - -static void __exit logger_exit(void) -{ - struct logger_log *current_log, *next_log; - - list_for_each_entry_safe(current_log, next_log, &log_list, logs) { - /* we have to delete all the entry inside log_list */ - misc_deregister(¤t_log->misc); - vfree(current_log->buffer); - kfree(current_log->misc.name); - list_del(¤t_log->logs); - kfree(current_log); - } - - osvelte_lowmem_dbg_exit(); - osvelte_sys_memstat_exit(); -} -device_initcall(logger_init); -module_exit(logger_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Robert Love, "); -MODULE_DESCRIPTION("Android Logger"); diff --git a/drivers/soc/oplus/system/mm_osvelte/logger.h b/drivers/soc/oplus/system/mm_osvelte/logger.h deleted file mode 100644 index bb111fdab367..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/logger.h +++ /dev/null @@ -1,106 +0,0 @@ -/* include/linux/logger.h - * - * Copyright (C) 2007-2008 Google, Inc. - * Author: Robert Love - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef _LINUX_LOGGER_H -#define _LINUX_LOGGER_H - -#include -#include - -/** - * struct user_logger_entry_compat - defines a single entry that is given to a logger - * @len: The length of the payload - * @__pad: Two bytes of padding that appear to be required - * @pid: The generating process' process ID - * @tid: The generating process' thread ID - * @sec: The number of seconds that have elapsed since the Epoch - * @nsec: The number of nanoseconds that have elapsed since @sec - * @msg: The message that is to be logged - * - * The userspace structure for version 1 of the logger_entry ABI. - * This structure is returned to userspace unless the caller requests - * an upgrade to a newer ABI version. - */ -struct user_logger_entry_compat { - __u16 len; - __u16 __pad; - __s32 pid; - __s32 tid; - __s64 sec; - __s64 nsec; - char msg[0]; -}; - -#ifdef __KERNEL__ -/** - * struct logger_entry - defines a single entry that is given to a logger - * @len: The length of the payload - * @hdr_size: sizeof(struct logger_entry_v2) - * @pid: The generating process' process ID - * @tid: The generating process' thread ID - * @sec: The number of seconds that have elapsed since the Epoch - * @nsec: The number of nanoseconds that have elapsed since @sec - * @euid: Effective UID of logger - * @msg: The message that is to be logged - * - * The structure for version 2 of the logger_entry ABI. - * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION) - * is called with version >= 2 - */ -struct logger_entry { - __u16 len; - __u16 hdr_size; - __s32 pid; - __s32 tid; - __s64 sec; - __s64 nsec; - kuid_t euid; - char msg[0]; -}; - -/** - * struct logger_reader - a logging device open for reading - * @log: The associated log - * @list: The associated entry in @logger_log's list - * @r_off: The current read head offset. - * @r_all: Reader can read all entries - * @r_ver: Reader ABI version - * - * This object lives from open to release, so we don't need additional - * reference counting. The structure is protected by log->mutex. - */ -struct logger_reader { - struct logger_log *log; - struct mutex mutex; - struct proc_ms *arr_ms; - struct list_head list; - size_t r_off; - bool r_all; - int r_ver; -}; -#endif - -#define LOGGER_ENTRY_MAX_PAYLOAD 4076 - -#define __LOGGERIO 0xAE - -#define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */ -#define LOGGER_GET_LOG_LEN _IO(__LOGGERIO, 2) /* used log len */ -#define LOGGER_GET_NEXT_ENTRY_LEN _IO(__LOGGERIO, 3) /* next entry len */ -#define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) /* flush log */ -#define LOGGER_GET_VERSION _IO(__LOGGERIO, 5) /* abi version */ -#define LOGGER_SET_VERSION _IO(__LOGGERIO, 6) /* abi version */ - -#endif /* _LINUX_LOGGER_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.c b/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.c deleted file mode 100755 index abdba75781ef..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.c +++ /dev/null @@ -1,613 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../../mm/slab.h" - -#include - -#include "common.h" -#include "memstat.h" -#include "sys-memstat.h" -#include "lowmem-dbg.h" - -static void lowmem_dbg_dump(struct work_struct *work); - -static DEFINE_MUTEX(dump_mutex); -static DECLARE_WORK(lowmem_dbg_work, lowmem_dbg_dump); - -struct files_acct { - bool verbose; - size_t sz; -}; - -struct lowmem_dbg_cfg { - u64 interval; - u64 last_jiffies; - u64 watermark_low; - u64 watermark_anon; - u64 watermark_slab; - u64 watermark_shmem; - u64 watermark_dmabuf; - u64 watermark_gpu; -}; - -static struct lowmem_dbg_cfg g_cfg; - -struct task_struct *find_lock_task_mm_dup(struct task_struct *p) -{ - struct task_struct *t; - - rcu_read_lock(); - - for_each_thread(p, t) { - task_lock(t); - - if (likely(t->mm)) { - goto found; - } - - task_unlock(t); - } - t = NULL; -found: - rcu_read_unlock(); - - return t; -} - -static int dump_procs(bool verbose) -{ - struct task_struct *p; - struct task_struct *tsk; - char task_state = ' '; - char frozen_mark = ' '; - unsigned long tsk_nr_ptes = 0; - pid_t ppid = 0; - - osvelte_info("======= %s\n", __func__); - osvelte_info("comm 32 uid s f pid ppid oom vss anon file shmem swap\n"); - rcu_read_lock(); - for_each_process(p) { - tsk = find_lock_task_mm_dup(p); - - if (!tsk) { - continue; - } - - tsk_nr_ptes = mm_pgtables_bytes(tsk->mm); - task_state = task_state_to_char(tsk); - /* check whether we have freezed a task. */ - frozen_mark = frozen(tsk) ? '*' : ' '; - ppid = task_pid_nr(rcu_dereference(tsk->real_parent)); - - osvelte_info("%-16s %2d %5d %c %c %5d %5d %5d %9lu %7lu %7lu %7lu %7lu\n", - tsk->comm, test_ti_thread_flag(task_thread_info(tsk), TIF_32BIT) != 0, - from_kuid(&init_user_ns, task_uid(tsk)), - task_state, frozen_mark, - tsk->pid, ppid, tsk->signal->oom_score_adj, - tsk->mm->total_vm, - get_mm_counter(tsk->mm, MM_ANONPAGES), - get_mm_counter(tsk->mm, MM_FILEPAGES), - get_mm_counter(tsk->mm, MM_SHMEMPAGES), - get_mm_counter(tsk->mm, MM_SWAPENTS)); - task_unlock(tsk); - } - rcu_read_unlock(); - - return 0; -} - -static int match_dmabuf_file(const void *p, struct file *file, unsigned fd) -{ - struct dma_buf *dmabuf; - struct files_acct *acct = (struct files_acct *)p; - - if (!file) { - return 0; - } - - if (!is_dma_buf_file(file)) { - return 0; - } - - dmabuf = file->private_data; - - if (!dmabuf->size) { - return 0; - } - - if (acct->verbose) - osvelte_info("inode: %ld sz: %zu\n", - file_inode(dmabuf->file)->i_ino, dmabuf->size / SZ_1K); - - acct->sz += dmabuf->size; - return 0; -} - -int dump_procs_dmabuf_info(bool verbose) -{ - struct task_struct *tsk = NULL; - - osvelte_info("======= %s\n", __func__); - osvelte_info("%-16s %-5s size\n", "comm", "pid"); - - rcu_read_lock(); - for_each_process(tsk) { - struct files_acct acct = { - .verbose = verbose, - .sz = 0, - }; - - if (tsk->flags & PF_KTHREAD) { - continue; - } - - task_lock(tsk); - iterate_fd(tsk->files, 0, match_dmabuf_file, (void *)&acct); - task_unlock(tsk); - - if (acct.sz) - osvelte_info("%-16s %5d %zu\n", tsk->comm, tsk->pid, acct.sz / SZ_1K); - } - rcu_read_unlock(); - return 0; -} - -#if IS_ENABLED(CONFIG_QCOM_KGSL) -static int gpu_proc_show(const struct kgsl_process_private *kp, void *unused) -{ - u64 gpumem_total = atomic64_read(&kp->stats[KGSL_MEM_ENTRY_KERNEL].cur); - - osvelte_info("%-16s %-5d %zu\n", kp->comm, pid_nr(kp->pid), gpumem_total / SZ_1K); - return 0; -} - -static int dump_procs_gpu_info(bool verbose) -{ - osvelte_info("======= %s\n", __func__); - osvelte_info("%-16s %-5s size\n", "comm", "pid"); - - read_each_kgsl_process_private(gpu_proc_show, NULL); - return 0; -} -#else /* CONFIG_QCOM_KGSL */ -static inline int dump_procs_gpu_info(bool verbose) -{ - return 0; -} -#endif /* CONFIG_QCOM_KGSL */ - -#ifdef CONFIG_SLUB_DEBUG -static int dump_slab_info(bool verbose) -{ - struct list_head *slab_caches; - struct mutex *slab_mutex; - - slab_caches = (struct list_head *)android_debug_symbol(ADS_SLAB_CACHES); - slab_mutex = (struct mutex *) android_debug_symbol(ADS_SLAB_MUTEX); - - osvelte_info("======= %s\n", __func__); - - if (likely(!verbose)) { - unsigned long slab_pages = 0; - struct kmem_cache *cachep = NULL; - struct kmem_cache *max_cachep = NULL; - struct kmem_cache *prev_max_cachep = NULL; - - mutex_lock(slab_mutex); - list_for_each_entry(cachep, slab_caches, list) { - struct slabinfo sinfo; - unsigned long scratch; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - scratch = sinfo.num_slabs << sinfo.cache_order; - - if (slab_pages < scratch) { - slab_pages = scratch; - prev_max_cachep = max_cachep; - max_cachep = cachep; - } - } - - if (max_cachep || prev_max_cachep) - osvelte_info("name :" - " tunables : slabdata \n"); - - if (max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(max_cachep, &sinfo); - - osvelte_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - max_cachep->name, sinfo.active_objs, - sinfo.num_objs, max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - - if (prev_max_cachep) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(prev_max_cachep, &sinfo); - - osvelte_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - prev_max_cachep->name, sinfo.active_objs, - sinfo.num_objs, prev_max_cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - - mutex_unlock(slab_mutex); - - } else { - struct kmem_cache *cachep = NULL; - - osvelte_info("# name :" - " tunables : slabdata \n"); - - mutex_lock(slab_mutex); - list_for_each_entry(cachep, slab_caches, list) { - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(cachep, &sinfo); - - osvelte_info("%-17s %6lu %6lu %6u %4u %4d : tunables %4u %4u %4u : slabdata %6lu %6lu %6lu\n", - cachep->name, sinfo.active_objs, - sinfo.num_objs, cachep->size, - sinfo.objects_per_slab, - (1 << sinfo.cache_order), - sinfo.limit, sinfo.batchcount, sinfo.shared, - sinfo.active_slabs, sinfo.num_slabs, - sinfo.shared_avail); - } - mutex_unlock(slab_mutex); - } - - return 0; -} -#else /* CONFIG_SLUB_DEBUG */ -static inline int dump_slab_info(bool verbose) -{ - return 0; -} -#endif /* CONFIG_SLUB_DEBUG */ - -#define for_each_populated_zone_dup(zone) \ - for (zone = (first_online_pgdat_dup())->node_zones; \ - zone; \ - zone = next_zone_dup(zone)) \ - if (!populated_zone(zone)) \ - ; /* do nothing */ \ - else - -static struct pglist_data *first_online_pgdat_dup(void) -{ - return NODE_DATA(first_online_node); -} - -static struct pglist_data *next_online_pgdat_dup(struct pglist_data *pgdat) -{ - int nid = next_online_node(pgdat->node_id); - - if (nid == MAX_NUMNODES) - return NULL; - return NODE_DATA(nid); -} - -struct zone *next_zone_dup(struct zone *zone) -{ - pg_data_t *pgdat = zone->zone_pgdat; - - if (zone < pgdat->node_zones + MAX_NR_ZONES - 1) - zone++; - else { - pgdat = next_online_pgdat_dup(pgdat); - if (pgdat) - zone = pgdat->node_zones; - else - zone = NULL; - } - return zone; -} - -static void dump_each_zone(void) -{ - unsigned long free_pcp = 0; - int cpu; - struct zone *zone; - - for_each_populated_zone_dup(zone) { - for_each_online_cpu(cpu) - free_pcp += per_cpu_ptr(zone->pageset, cpu)->pcp.count; - } - - osvelte_info("active_anon:%lu inactive_anon:%lu isolated_anon:%lu" - " active_file:%lu inactive_file:%lu isolated_file:%lu" - " unevictable:%lu dirty:%lu writeback:%lu" - " slab_reclaimable:%lu slab_unreclaimable:%lu" - " mapped:%lu shmem:%lu pagetables:%lu bounce:%lu" - " free:%lu free_pcp:%lu free_cma:%lu\n", - global_node_page_state(NR_ACTIVE_ANON), - global_node_page_state(NR_INACTIVE_ANON), - global_node_page_state(NR_ISOLATED_ANON), - global_node_page_state(NR_ACTIVE_FILE), - global_node_page_state(NR_INACTIVE_FILE), - global_node_page_state(NR_ISOLATED_FILE), - global_node_page_state(NR_UNEVICTABLE), - global_node_page_state(NR_FILE_DIRTY), - global_node_page_state(NR_WRITEBACK), - global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B), - global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B), - global_node_page_state(NR_FILE_MAPPED), - global_node_page_state(NR_SHMEM), - global_zone_page_state(NR_PAGETABLE), - global_zone_page_state(NR_BOUNCE), - global_zone_page_state(NR_FREE_PAGES), - free_pcp, - global_zone_page_state(NR_FREE_CMA_PAGES)); - - for_each_populated_zone_dup(zone) { - free_pcp = 0; - for_each_online_cpu(cpu) - free_pcp += per_cpu_ptr(zone->pageset, cpu)->pcp.count; - - if (IS_ENABLED(CONFIG_NUMA)) - osvelte_info("Node %d \n", zone_to_nid(zone)); - osvelte_info("%s" - " free:%lukB" - " min:%lukB" - " low:%lukB" - " high:%lukB" - " reserved_highatomic:%luKB" - " active_anon:%lukB" - " inactive_anon:%lukB" - " active_file:%lukB" - " inactive_file:%lukB" - " unevictable:%lukB" - " writepending:%lukB" - " present:%lukB" - " managed:%lukB" - " mlocked:%lukB" - " pagetables:%lukB" - " bounce:%lukB" - " free_pcp:%lukB" - " local_pcp:%ukB" - " free_cma:%lukB" - "\n", - zone->name, K(zone_page_state(zone, NR_FREE_PAGES)), - K(min_wmark_pages(zone)), - K(low_wmark_pages(zone)), - K(high_wmark_pages(zone)), - K(zone->nr_reserved_highatomic), - K(zone_page_state(zone, NR_ZONE_ACTIVE_ANON)), - K(zone_page_state(zone, NR_ZONE_INACTIVE_ANON)), - K(zone_page_state(zone, NR_ZONE_ACTIVE_FILE)), - K(zone_page_state(zone, NR_ZONE_INACTIVE_FILE)), - K(zone_page_state(zone, NR_ZONE_UNEVICTABLE)), - K(zone_page_state(zone, NR_ZONE_WRITE_PENDING)), - K(zone->present_pages), - K(zone_managed_pages(zone)), - K(zone_page_state(zone, NR_MLOCK)), - K(zone_page_state(zone, NR_PAGETABLE)), - K(zone_page_state(zone, NR_BOUNCE)), - K(free_pcp), - K(this_cpu_read(zone->pageset->pcp.count)), - K(zone_page_state(zone, NR_FREE_CMA_PAGES))); - } -} - -static void __lowmem_dbg_dump(struct lowmem_dbg_cfg *cfg) -{ - unsigned long tot, free, available; - unsigned long slab_reclaimable, slab_unreclaimable; - unsigned long anon, active_anon, inactive_anon; - unsigned long file, active_file, inactive_file, shmem; - unsigned long vmalloc, pgtbl, kernel_stack, kernel_misc_reclaimable; - unsigned long dmabuf, dmabuf_pool, gpu, unaccounted; - struct sysinfo si; - - mutex_lock(&dump_mutex); - tot = sys_totalram(); - free = sys_freeram(); - available = si_mem_available(); - - slab_reclaimable = sys_slab_reclaimable(); - slab_unreclaimable = sys_slab_unreclaimable(); - - si_swapinfo(&si); - - anon = sys_anon(); - active_anon = sys_active_anon(); - inactive_anon = sys_inactive_anon(); - shmem = sys_sharedram(); - - file = sys_file(); - active_file = sys_active_file(); - inactive_file = sys_inactive_file(); - - vmalloc = sys_vmalloc(); - pgtbl = sys_page_tables(); - kernel_stack = sys_kernel_stack(); - kernel_misc_reclaimable = sys_kernel_misc_reclaimable(); - - dmabuf = sys_dmabuf(); - dmabuf_pool = sys_dmabuf_pool(); - gpu = sys_gpu(); - unaccounted = tot - free - slab_reclaimable - slab_unreclaimable - - vmalloc - anon - file - pgtbl - kernel_stack - dmabuf - - gpu - kernel_misc_reclaimable; - - osvelte_info("lowmem_dbg start osvelte v%d.%d.%d <<<<<<<\n", - OSVELTE_MAJOR, OSVELTE_MINOR, OSVELTE_PATCH_NUM); - dump_each_zone(); - - osvelte_info("total: %lu free: %lu available: %lu\n", - K(tot), K(free), K(available)); - osvelte_info("swap_total: %lu swap_free: %lu\n", - K(si.totalswap), K(si.freeswap)); - osvelte_info("hybridswap same_pages: %lu compr_data_size: %lu pages_stored: %lu\n", - K(get_hybridswap_meminfo("same_pages")), - get_hybridswap_meminfo("compr_data_size") / SZ_1K, - K(get_hybridswap_meminfo("pages_stored"))); - osvelte_info("slab_reclaimable: %lu slab_unreclaimable: %lu", - K(slab_reclaimable), K(slab_unreclaimable)); - osvelte_info("anon: %lu active_anon: %lu inactive_anon: %lu\n", - K(anon), K(active_anon), K(inactive_anon)); - osvelte_info("file: %lu active_file: %lu inactive_file: %lu shmem: %lu\n", - K(file), K(active_file), K(inactive_file), K(shmem)); - osvelte_info("vmalloc: %lu page_tables: %lu kernel_stack: %lu kernel_misc_reclaimable: %lu\n", - K(vmalloc), K(pgtbl), K(kernel_stack), K(kernel_misc_reclaimable)); - osvelte_info("dmabuf: %lu dmabuf_pool: %lu gpu: %lu unaccounted: %lu\n", - K(dmabuf), K(dmabuf_pool), K(gpu), K(unaccounted)); - - if (likely(cfg)) { - dump_procs(anon + si.totalswap - si.freeswap > cfg->watermark_anon); - dump_slab_info(slab_unreclaimable > cfg->watermark_slab); - dump_procs_dmabuf_info(dmabuf > cfg->watermark_dmabuf); - dump_procs_gpu_info(gpu > cfg->watermark_gpu); - } else { - dump_procs(true); - dump_slab_info(true); - dump_procs_dmabuf_info(false); - dump_procs_gpu_info(false); - } - - osvelte_info("lowmem_dbg end >>>>>>>\n"); - mutex_unlock(&dump_mutex); -} - -static void lowmem_dbg_dump(struct work_struct *work) -{ - __lowmem_dbg_dump(&g_cfg); -} - -void oplus_memory_dump(struct work_struct *work) -{ - __lowmem_dbg_dump(NULL); -} -EXPORT_SYMBOL_GPL(oplus_memory_dump); - -static unsigned long lowmem_dbg_count(struct shrinker *s, - struct shrink_control *sc) -{ - return sys_active_file() + sys_inactive_file() + - sys_active_anon() + sys_inactive_anon(); -} - -static unsigned long lowmem_dbg_scan(struct shrinker *s, - struct shrink_control *sc) -{ - static atomic_t atomic_lmk = ATOMIC_INIT(0); - struct lowmem_dbg_cfg *cfg = &g_cfg; - long available; - u64 now; - - if (atomic_inc_return(&atomic_lmk) > 1) { - atomic_dec(&atomic_lmk); - return 0; - } - - now = get_jiffies_64(); - - if (time_before64(now, (cfg->last_jiffies + cfg->interval))) { - goto done; - } - - cfg->last_jiffies = now; - - available = si_mem_available(); - - if (available > cfg->watermark_low) { - goto done; - } - - schedule_work(&lowmem_dbg_work); - -done: - atomic_dec(&atomic_lmk); - - return 0; -} - -static struct shrinker lowmem_dbg_shrinker = { - .scan_objects = lowmem_dbg_scan, - .count_objects = lowmem_dbg_count, - .seeks = DEFAULT_SEEKS -}; - -int osvelte_lowmem_dbg_init(void) -{ - int ret; - struct lowmem_dbg_cfg *cfg = &g_cfg; - unsigned long total_ram = sys_totalram(); - - ret = register_shrinker(&lowmem_dbg_shrinker); - - if (ret) { - return -ENOMEM; - } - - cfg->interval = 10 * HZ; - - if (total_ram >= PAGES(SZ_2G + SZ_2G)) { - cfg->watermark_low = PAGES(SZ_1G); - - } else if (total_ram >= PAGES(SZ_2G + SZ_1G)) { - cfg->watermark_low = PAGES(SZ_512M); - - } else { - cfg->watermark_low = PAGES(SZ_256M); - } - - cfg->watermark_anon = total_ram / 2; - cfg->watermark_slab = PAGES(SZ_1G); - cfg->watermark_shmem = PAGES(SZ_1G); - cfg->watermark_dmabuf = PAGES(SZ_2G + SZ_512M); - cfg->watermark_gpu = PAGES(SZ_2G + SZ_512M); - - osvelte_info("%s interval: %lu watermark low: %lu anon: %lu ashmem: %lu dmabuf: %lu\n", - __func__, cfg->interval, cfg->watermark_low, cfg->watermark_anon, - cfg->watermark_shmem, cfg->watermark_dmabuf); - return 0; -} - -int osvelte_lowmem_dbg_exit(void) -{ - unregister_shrinker(&lowmem_dbg_shrinker); - return 0; -} diff --git a/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.h b/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.h deleted file mode 100644 index 4cf8ad8dfa14..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/lowmem-dbg.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#ifndef _LOWMEM_DBG_H -#define _LOWMEM_DBG_H - -int osvelte_lowmem_dbg_init(void); -int osvelte_lowmem_dbg_exit(void); -#endif /* _LOWMEM_DBG_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/memstat.h b/drivers/soc/oplus/system/mm_osvelte/memstat.h deleted file mode 100755 index 2e44e456886d..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/memstat.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#ifndef _OSVELTE_MEMSTAT_H -#define _OSVELTE_MEMSTAT_H - -/* not safe, need upstream patch. */ -#define ASHMEM_NAME_LEN 256 -#define ASHMEM_NAME_PREFIX "dev/ashmem/" -#define ASHMEM_NAME_PREFIX_LEN (sizeof(ASHMEM_NAME_PREFIX) - 1) -#define ASHMEM_FULL_NAME_LEN (ASHMEM_NAME_LEN + ASHMEM_NAME_PREFIX_LEN) - -struct ashmem_area { - char name[ASHMEM_FULL_NAME_LEN]; - struct list_head unpinned_list; - struct file *file; - size_t size; - unsigned long prot_mask; -}; - -#define PAGES(size) ((size) >> PAGE_SHIFT) -#define K(x) ((__u64)(x) << (PAGE_SHIFT - 10)) - -extern inline int is_dma_buf_file(struct file *file); -/* extern int is_ashmem_file(struct file *file); */ -extern struct task_struct *find_lock_task_mm_dup(struct task_struct *p); - -#endif /* _OSVELTE_MEMSTAT_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/proc-memstat.c b/drivers/soc/oplus/system/mm_osvelte/proc-memstat.c deleted file mode 100755 index 4d0872330c60..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/proc-memstat.c +++ /dev/null @@ -1,279 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) "osvelte: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "memstat.h" -#include "proc-memstat.h" -#include "logger.h" - -static bool is_ashmem_file(struct file *file) -{ - return false; -} - -static int match_file(const void *p, struct file *file, unsigned fd) -{ - struct dma_buf *dmabuf; - struct ashmem_area *ashmem_data; - struct proc_ms *ms = (struct proc_ms *)p; - - if (is_dma_buf_file(file)) { - dmabuf = file->private_data; - - if (dmabuf) { - ms->dmabuf += dmabuf->size; - } - - return 0; - } - -#ifdef CONFIG_ASHMEM - - if (is_ashmem_file(file)) { - ashmem_data = file->private_data; - - if (ashmem_data) { - ms->ashmem += ashmem_data->size; - } - - return 0; - } - -#endif /* CONFIG_ASHMEM */ - - ms->nr_fds += 1; - return 0; -} - -/* - * Must be called under rcu_read_lock() & increment task_struct counter. - */ -static int __proc_memstat(struct task_struct *p, struct proc_ms *ms, u32 flags) -{ - struct mm_struct *mm = NULL; - struct task_struct *tsk; - - if (flags & PROC_MS_UID) - ms->uid = from_kuid(&init_user_ns, task_uid(p)); - - if (flags & PROC_MS_PID) - ms->pid = p->pid; - - if (flags & PROC_MS_OOM_SCORE_ADJ) - ms->oom_score_adj = p->signal->oom_score_adj; - - if (flags & PROC_MS_32BIT) - ms->is_32bit = test_ti_thread_flag(task_thread_info(p), - TIF_32BIT); - - if (flags & PROC_MS_COMM) - strncpy(ms->comm, p->comm, sizeof(ms->comm)); - - tsk = find_lock_task_mm_dup(p); - if (!tsk) - return -EEXIST; - - if (flags & PROC_MS_ITERATE_FD) { - iterate_fd(p->files, 0, match_file, ms); - - /* dma_buf size use byte */ - ms->dmabuf = ms->dmabuf >> PAGE_SHIFT; - ms->ashmem = ms->ashmem >> PAGE_SHIFT; - } - - mm = tsk->mm; - - if (flags & PROC_MS_VSS) { - ms->vss = mm->total_vm; - } - - if (flags & PROC_MS_ANON) { - ms->anon = get_mm_counter(mm, MM_ANONPAGES); - } - - if (flags & PROC_MS_FILE) { - ms->file = get_mm_counter(mm, MM_FILEPAGES); - } - - if (flags & PROC_MS_SHMEM) { - ms->shmem = get_mm_counter(mm, MM_SHMEMPAGES); - } - - if (flags & PROC_MS_SWAP) { - ms->swap = get_mm_counter(mm, MM_SWAPENTS); - } - - task_unlock(tsk); - return 0; -} - -static int proc_pid_memstat(unsigned long arg) -{ - long ret = -EINVAL; - struct proc_pid_ms ppm; - struct task_struct *p; - pid_t pid; - void __user *argp = (void __user *) arg; - - if (copy_from_user(&ppm, argp, sizeof(ppm))) { - return -EFAULT; - } - - pid = ppm.pid; - /* zeroed data */ - memset(&ppm.ms, 0, sizeof(ppm.ms)); - - rcu_read_lock(); - p = find_task_by_vpid(pid); - - if (!p) { - rcu_read_unlock(); - return -EINVAL; - } - - if ((ppm.flags & PROC_MS_PPID) && pid_alive(p)) - ppm.ms.ppid = task_pid_nr(rcu_dereference(p->real_parent)); - ret = __proc_memstat(p, &ppm.ms, ppm.flags); - rcu_read_unlock(); - - if (ret) { - return ret; - } - - if (copy_to_user(argp, &ppm, sizeof(ppm))) { - return -EFAULT; - } - - return 0; -} - -static int proc_size_memstat(struct file *file, unsigned int cmd, unsigned long arg) -{ - struct logger_reader *reader = file->private_data; - struct proc_size_ms psm; - struct task_struct *p = NULL; - int ret = 0; - int cnt = 0; - - void __user *argp = (void __user *) arg; - - if (copy_from_user(&psm, argp, sizeof(psm))) { - return -EFAULT; - } - - if (psm.size > PROC_MS_MAX_SIZE) { - return -EINVAL; - } - - mutex_lock(&reader->mutex); - if (unlikely(!reader->arr_ms)) { - reader->arr_ms = vzalloc(PROC_MS_MAX_SIZE * sizeof(struct proc_ms)); - - if (!reader->arr_ms) { - mutex_unlock(&reader->mutex); - return -ENOMEM; - } - } - memset(reader->arr_ms, 0, PROC_MS_MAX_SIZE * sizeof(struct proc_ms)); - mutex_unlock(&reader->mutex); - - rcu_read_lock(); - for_each_process(p) { - struct proc_ms *ms = reader->arr_ms + cnt; - - if (cnt >= psm.size) { - break; - } - - if (p->flags & PF_KTHREAD) { - continue; - } - - if (p->pid != p->tgid) { - continue; - } - - if (cmd == CMD_PROC_MS_SIZE_UID) { - /* don't need fetch uid again */ - psm.flags &= ~PROC_MS_UID; - ms->uid = from_kuid(&init_user_ns, task_uid(p)); - - if (ms->uid != psm.uid) { - continue; - } - } - - if ((psm.flags & PROC_MS_PPID) && pid_alive(p)) { - ms->ppid = task_pid_nr(rcu_dereference(p->real_parent)); - } - - ret = __proc_memstat(p, ms, psm.flags); - - if (likely(!ret)) { - cnt++; - } - } - rcu_read_unlock(); - - psm.size = cnt; - if (copy_to_user(argp, &psm, sizeof(psm))) { - ret = -EFAULT; - goto err_buf; - } - - /* if cnt is zero, copy nothin. */ - if (copy_to_user(argp + sizeof(psm), reader->arr_ms, cnt * sizeof(struct proc_ms))) { - ret = -EFAULT; - goto err_buf; - } - -err_buf: - return ret; -} - -long proc_memstat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - long ret = -EINVAL; - - if (cmd < CMD_PROC_MS_MIN || cmd > CMD_PROC_MS_MAX) { - osvelte_err("cmd invalid.\n"); - return CMD_PROC_MS_INVALID; - } - - if (!(file->f_mode & FMODE_READ)) - return -EBADF; - - switch (cmd) { - case CMD_PROC_MS_PID: - ret = proc_pid_memstat(arg); - break; - - case CMD_PROC_MS_SIZE: - ret = proc_size_memstat(file, cmd, arg); - break; - - case CMD_PROC_MS_SIZE_UID: - ret = proc_size_memstat(file, cmd, arg); - break; - } - - return ret; -} diff --git a/drivers/soc/oplus/system/mm_osvelte/proc-memstat.h b/drivers/soc/oplus/system/mm_osvelte/proc-memstat.h deleted file mode 100644 index a2ea0e1b0942..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/proc-memstat.h +++ /dev/null @@ -1,153 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#ifndef _OSVELTE_PROC_MEMSTAT_H -#define _OSVELTE_PROC_MEMSTAT_H - -#ifdef __KERNEL__ -#include -#include -#include -#include -#else -#include -#include -#endif - -/* Don't edit this region! It is auto-generated by scripts, region_start */ -#define PROC_MS_UID 0x1 -#define PROC_MS_PID 0x2 -#define PROC_MS_PPID 0x4 -#define PROC_MS_OOM_SCORE_ADJ 0x8 -#define PROC_MS_32BIT 0x10 -#define PROC_MS_COMM 0x20 - -#define PROC_MS_VSS 0x40 -#define PROC_MS_ANON 0x80 -#define PROC_MS_FILE 0x100 -#define PROC_MS_SHMEM 0x200 -#define PROC_MS_SWAP 0x400 - -#define PROC_MS_NR_FDS 0x800 -#define PROC_MS_ASHMEM 0x1000 -#define PROC_MS_DMABUF 0x2000 - -#define PROC_MS_PSS 0x4000 -#define PROC_MS_NATIVEHEAP 0x8000 -#define PROC_MS_JAVAHEAP 0x10000 - -#define PROC_MS_INFO (PROC_MS_UID | PROC_MS_PID | PROC_MS_PPID | PROC_MS_OOM_SCORE_ADJ | PROC_MS_32BIT | PROC_MS_COMM) -#define PROC_MS_MM (PROC_MS_VSS | PROC_MS_ANON | PROC_MS_FILE | PROC_MS_SHMEM | PROC_MS_SWAP) -#define PROC_MS_COMMON (PROC_MS_INFO | PROC_MS_MM) -#define PROC_MS_ITERATE_FD (PROC_MS_NR_FDS | PROC_MS_ASHMEM | PROC_MS_DMABUF) -#define PROC_MS_ITERATE_VMA (PROC_MS_PSS | PROC_MS_NATIVEHEAP | PROC_MS_JAVAHEAP) -#define PROC_MS_ITERATE_VMA_NAME (PROC_MS_NATIVEHEAP | PROC_MS_JAVAHEAP) - -#define PROC_MS_VALID_FLAGS (PROC_MS_COMMON | PROC_MS_ITERATE_FD | PROC_MS_ITERATE_VMA) - -#define PROC_MS_MAX_SIZE 400 - -/* ioctl cmd */ -#define __PROC_MSIO 0xFB - -#define CMD_PROC_MS_PID _IO(__PROC_MSIO, 1) -#define CMD_PROC_MS_SIZE _IO(__PROC_MSIO, 2) -#define CMD_PROC_MS_SIZE_UID _IO(__PROC_MSIO, 3) - -#define CMD_PROC_MS_MIN CMD_PROC_MS_PID -#define CMD_PROC_MS_MAX CMD_PROC_MS_SIZE_UID - -#define CMD_PROC_MS_INVALID 0xFFFFFFFF - -#ifdef __KERNEL__ -struct proc_ms { - char comm[TASK_COMM_LEN]; - u8 is_32bit; - short oom_score_adj; - int nr_fds; - uid_t uid; - pid_t pid; - pid_t ppid; - - /* pages */ - u32 anon; - u32 file; - u32 shmem; - u32 swap; - u32 vss; - - /* read from vma */ - u32 rss; - u32 swap_rss; - u32 javaheap; - u32 nativeheap; - - /*read from fdinfo */ - u32 ashmem; - u32 dmabuf; - u32 gpu; -}; - -struct proc_size_ms { - u32 flags; - uid_t uid; - u32 size; - struct proc_ms arr_ms[0]; -}; - -struct proc_pid_ms { - u32 flags; - pid_t pid; - struct proc_ms ms; -}; - -long proc_memstat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); -#else /* __KERNEL__ */ - -#define TASK_COMM_LEN (16) -#define PAGE_SHIFT (12) - -struct proc_ms { - char comm[TASK_COMM_LEN]; - __u8 is_32bit; - short oom_score_adj; - int nr_fds; - uid_t uid; - pid_t pid; - pid_t ppid; - - /* pages */ - __u32 anon; - __u32 file; - __u32 shmem; - __u32 swap; - __u32 vss; - - /* read from vma */ - __u32 pss; - __u32 swap_rss; - __u32 javaheap; - __u32 nativeheap; - - /*re;ad from fdinfo */ - __u32 ashmem; - __u32 dmabuf; - __u32 gpu; -}; - -struct proc_size_ms { - __u32 flags; - uid_t uid; - __u32 size; - struct proc_ms arr_ms[0]; -}; - -struct proc_pid_ms { - __u32 flags; - pid_t pid; - struct proc_ms ms; -}; -#endif /* __KERNEL__ */ - -#endif /* _OSVELTE_PROC_MEMSTAT_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/sys-memstat.c b/drivers/soc/oplus/system/mm_osvelte/sys-memstat.c deleted file mode 100644 index 8678d6b8062d..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/sys-memstat.c +++ /dev/null @@ -1,382 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "common.h" -#include "memstat.h" -#include "sys-memstat.h" - -struct dma_info { - struct dma_buf *dmabuf; - struct hlist_node head; -}; - -struct dma_proc { - char name[TASK_COMM_LEN]; - pid_t pid; - size_t size; - struct hlist_head dma_bufs[1 << 10]; - struct list_head head; -}; - -struct dma_buf_priv { - int count; - size_t size; - struct seq_file *s; -}; - -static void show_val_kb(struct seq_file *m, const char *s, unsigned long num) -{ - seq_put_decimal_ull_width_dup(m, s, num << (PAGE_SHIFT - 10), 8); - seq_write(m, " kB\n", 4); -} - -#if IS_ENABLED(CONFIG_QCOM_KGSL) -struct gpu_priv { - size_t size; - struct seq_file *s; -}; - -inline unsigned long sys_gpu(void) -{ - return read_kgsl_memstat("page_alloc") >> PAGE_SHIFT; -} - -static int gpu_proc_show(const struct kgsl_process_private *kp, void *private) -{ - struct gpu_priv *priv = (struct gpu_priv *)private; - u64 gpumem_total = atomic64_read(&kp->stats[KGSL_MEM_ENTRY_KERNEL].cur); - u64 gpumem_mapped = atomic64_read(&kp->gpumem_mapped); - - seq_printf(priv->s, "%-5d %-8lu %-8lu %-16s\n", - pid_nr(kp->pid), gpumem_total / SZ_1K, gpumem_mapped / SZ_1K, - kp->comm); - priv->size += gpumem_total; - return 0; -} - -static int gpu_procinfo_show(struct seq_file *s, void *unused) -{ - struct gpu_priv priv; - - priv.size = 0; - priv.s = s; - - seq_printf(s, "%-5s %-8s %-8s %-8s\n", - "pid", "size", "mapped", "comm"); - - read_each_kgsl_process_private(gpu_proc_show, &priv); - - seq_printf(s, "\nTotal %zu kB\n", K(sys_gpu())); - return 0; -} - -#else /* CONFIG_QCOM_KGSL */ - -static int gpu_procinfo_show(struct seq_file *s, void *unused) -{ - seq_puts(s, "Not supported for now\n"); - return 0; -} - -inline unsigned long sys_gpu(void) -{ - return 0; -} -#endif /* CONFIG_QCOM_KGSL */ -DEFINE_PROC_SHOW_ATTRIBUTE(gpu_procinfo); - -static int dma_buf_show(const struct dma_buf *buf_obj, void *private) -{ - int ret; - struct dma_buf_attachment *attach_obj; - struct dma_resv *robj; - struct dma_resv_list *fobj; - struct dma_fence *fence; - unsigned seq; - int attach_count, shared_count, i; - struct dma_buf_priv *buf = (struct dma_buf_priv *)private; - struct seq_file *s = buf->s; - - ret = dma_resv_lock_interruptible(buf_obj->resv, NULL); - - if (ret) - goto err; - - spin_lock((spinlock_t *)&buf_obj->name_lock); - seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n", - buf_obj->size, - buf_obj->file->f_flags, buf_obj->file->f_mode, - file_count(buf_obj->file), - buf_obj->exp_name, - file_inode(buf_obj->file)->i_ino, - buf_obj->name ?: ""); - spin_unlock((spinlock_t *)&buf_obj->name_lock); - - robj = buf_obj->resv; - while (true) { - seq = read_seqcount_begin(&robj->seq); - rcu_read_lock(); - fobj = rcu_dereference(robj->fence); - shared_count = fobj ? fobj->shared_count : 0; - fence = rcu_dereference(robj->fence_excl); - if (!read_seqcount_retry(&robj->seq, seq)) - break; - rcu_read_unlock(); - } - - if (fence) - seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", - fence->ops->get_driver_name(fence), - fence->ops->get_timeline_name(fence), - dma_fence_is_signaled(fence) ? "" : "un"); - for (i = 0; i < shared_count; i++) { - fence = rcu_dereference(fobj->shared[i]); - if (!dma_fence_get_rcu(fence)) - continue; - seq_printf(s, "\tShared fence: %s %s %ssignalled\n", - fence->ops->get_driver_name(fence), - fence->ops->get_timeline_name(fence), - dma_fence_is_signaled(fence) ? "" : "un"); - dma_fence_put(fence); - } - rcu_read_unlock(); - - seq_puts(s, "\tAttached Devices:\n"); - attach_count = 0; - - list_for_each_entry(attach_obj, &buf_obj->attachments, node) { - seq_printf(s, "\t%s\n", dev_name(attach_obj->dev)); - attach_count++; - } - dma_resv_unlock(buf_obj->resv); - - seq_printf(s, "Total %d devices attached\n\n", attach_count); - - buf->count++; - buf->size += buf_obj->size; - - return 0; -err: - return ret; -} - -static int dma_buf_bufinfo_show(struct seq_file *s, void *unused) -{ - struct dma_buf_priv dma_buf_priv; - - dma_buf_priv.count = 0; - dma_buf_priv.size = 0; - dma_buf_priv.s = s; - - seq_puts(s, "\nDma-buf Objects:\n"); - seq_printf(s, "%-8s\t%-8s\t%-8s\t%-8s\texp_name\t%-8s\n", - "size", "flags", "mode", "count", "ino"); - - get_each_dmabuf(dma_buf_show, &dma_buf_priv); - - seq_printf(s, "\nTotal %d objects, %zu bytes\n", - dma_buf_priv.count, dma_buf_priv.size); - - return 0; -} -DEFINE_PROC_SHOW_ATTRIBUTE(dma_buf_bufinfo); - -static int get_dma_buf_info(const void *data, struct file *file, unsigned int n) -{ - struct dma_proc *dma_proc; - struct dma_info *dma_info; - - if (!is_dma_buf_file(file)) - return 0; - - dma_proc = (struct dma_proc *)data; - hash_for_each_possible(dma_proc->dma_bufs, dma_info, head, - (unsigned long) file->private_data) - if (file->private_data == dma_info->dmabuf) - return 0; - - dma_info = kzalloc(sizeof(*dma_info), GFP_ATOMIC); - if (!dma_info) - return -ENOMEM; - - get_file(file); - dma_info->dmabuf = file->private_data; - dma_proc->size += dma_info->dmabuf->size; - hash_add(dma_proc->dma_bufs, &dma_info->head, - (unsigned long)dma_info->dmabuf); - return 0; -} - -static void free_dma_proc(struct dma_proc *proc) -{ - struct dma_info *tmp; - struct hlist_node *n; - int i; - - hash_for_each_safe(proc->dma_bufs, i, n, tmp, head) { - fput(tmp->dmabuf->file); - hash_del(&tmp->head); - kfree(tmp); - } - kfree(proc); -} - -static void dma_proc_show(struct seq_file *s, struct dma_proc *proc) -{ - struct dma_info *tmp; - int i; - - seq_printf(s, "\n%s (PID %d) size: %ld kB\nDMA Buffers:\n", - proc->name, proc->pid, proc->size / SZ_1K); - seq_printf(s, "%-8s\t%-8s\t%-8s\t%-10s\t%-10s\t%-s\n", - "ino", "size", "count", "flags", "mode", "exp_name"); - - hash_for_each(proc->dma_bufs, i, tmp, head) { - struct dma_buf *dmabuf = tmp->dmabuf; - - spin_lock((spinlock_t *)&dmabuf->name_lock); - seq_printf(s, "%08lu\t%-8zu\t%-8ld\t0x%08x\t0x%08x\t%-s\t%-s\n", - file_inode(dmabuf->file)->i_ino, - dmabuf->size / SZ_1K, - file_count(dmabuf->file), - dmabuf->file->f_flags, dmabuf->file->f_mode, - dmabuf->exp_name, - dmabuf->name ?: ""); - spin_unlock((spinlock_t *)&dmabuf->name_lock); - } -} - -static int dma_buf_procinfo_show(struct seq_file *s, void *unused) -{ - struct task_struct *task, *thread; - struct files_struct *files; - int ret = 0; - struct dma_proc *tmp, *n; - LIST_HEAD(plist); - - rcu_read_lock(); - for_each_process(task) { - struct files_struct *group_leader_files = NULL; - - tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC); - if (!tmp) { - ret = -ENOMEM; - rcu_read_unlock(); - goto mem_err; - } - hash_init(tmp->dma_bufs); - for_each_thread(task, thread) { - task_lock(thread); - if (unlikely(!group_leader_files)) - group_leader_files = task->group_leader->files; - files = thread->files; - if (files && (group_leader_files != files || - thread == task->group_leader)) - ret = iterate_fd(files, 0, get_dma_buf_info, tmp); - task_unlock(thread); - } - - if (ret || hash_empty(tmp->dma_bufs)) - goto skip; - - get_task_comm(tmp->name, task); - tmp->pid = task->tgid; - list_add(&tmp->head, &plist); - continue; -skip: - free_dma_proc(tmp); - } - rcu_read_unlock(); - - list_for_each_entry(tmp, &plist, head) - dma_proc_show(s, tmp); - - ret = 0; -mem_err: - list_for_each_entry_safe(tmp, n, &plist, head) { - list_del(&tmp->head); - free_dma_proc(tmp); - } - return ret; -} -DEFINE_PROC_SHOW_ATTRIBUTE(dma_buf_procinfo); - -static int hybridswap_info_show(struct seq_file *m, void *unused) -{ - show_val_kb(m, "SamePages: ", - get_hybridswap_meminfo("same_pages")); - show_val_kb(m, "ComprDataSize: ", - get_hybridswap_meminfo("compr_data_size") >> PAGE_SHIFT); - show_val_kb(m, "PagesStored: ", - get_hybridswap_meminfo("pages_stored")); - return 0; -} -DEFINE_PROC_SHOW_ATTRIBUTE(hybridswap_info); - -static int version_show(struct seq_file *m, void *unused) -{ - seq_printf(m, "osvelte v%d.%d.%d based on kernel-5.10\n", - OSVELTE_MAJOR, OSVELTE_MINOR, OSVELTE_PATCH_NUM); - return 0; -} -DEFINE_PROC_SHOW_ATTRIBUTE(version); - -static void extra_meminfo_proc_show(void *data, struct seq_file *m) -{ - show_val_kb(m, "IonTotalCache: ", sys_dmabuf_pool()); - show_val_kb(m, "IonTotalUsed: ", sys_dmabuf()); -} - -int osvelte_sys_memstat_init(void) -{ - struct proc_dir_entry *root; - struct proc_dir_entry *dmabuf_root, *gpu_root; - - if (register_trace_android_vh_meminfo_proc_show(extra_meminfo_proc_show, NULL)) { - pr_err("register extra meminfo proc failed.\n"); - return -1; - } - - root = proc_mkdir("osvelte", NULL); - if (!root) { - pr_err("create osvelte dir failed\n"); - return -ENOMEM; - } - proc_create("version", 0444, root, &version_proc_ops); - proc_create("hybridswap_info", 0444, root, &hybridswap_info_proc_ops); - - dmabuf_root = proc_mkdir("osvelte/dma_buf", NULL); - if (!dmabuf_root) { - pr_err("create osvelte dmabuf dir failed\n"); - return -ENOMEM; - } - proc_create("procinfo", 0444, dmabuf_root, &dma_buf_procinfo_proc_ops); - proc_create("bufinfo", 0444, dmabuf_root, &dma_buf_bufinfo_proc_ops); - - gpu_root = proc_mkdir("osvelte/gpu", NULL); - if (!gpu_root) { - pr_err("create osvelte gpu root dir failed\n"); - return -ENOMEM; - } - proc_create("procinfo", 0444, gpu_root, &gpu_procinfo_proc_ops); - - return 0; -} - -int osvelte_sys_memstat_exit(void) -{ - remove_proc_subtree("osvelte", NULL); - unregister_trace_android_vh_meminfo_proc_show(extra_meminfo_proc_show, NULL); - return 0; -} diff --git a/drivers/soc/oplus/system/mm_osvelte/sys-memstat.h b/drivers/soc/oplus/system/mm_osvelte/sys-memstat.h deleted file mode 100644 index d3da53d92c90..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/sys-memstat.h +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ -#ifndef _OSVELTE_SYS_MEMSTAT_H -#define _OSVELTE_SYS_MEMSTAT_H - -#include -#include -#include -#include - -extern atomic64_t dma_heap_normal_total; - -#if IS_ENABLED(CONFIG_QCOM_KGSL) -#include "kgsl.h" -#include "kgsl_device.h" -extern int read_each_kgsl_process_private(int (*callback)(const struct kgsl_process_private *kp, - void *private), void *private); -extern ssize_t read_kgsl_memstat(const char *name); -#endif - -#if IS_ENABLED(CONFIG_HYBRIDSWAP_ZRAM) -u64 get_hybridswap_meminfo(const char *type); -#endif /* CONFIG_HYBRIDSWAP_ZRAM */ - -static inline unsigned long sys_totalram(void) -{ - return totalram_pages(); -} - -static inline unsigned long sys_freeram(void) -{ - return global_zone_page_state(NR_FREE_PAGES); -} - -static inline unsigned long sys_inactive_file(void) -{ - return global_node_page_state(NR_ACTIVE_FILE); -} - -static inline unsigned long sys_active_file(void) -{ - return global_node_page_state(NR_INACTIVE_FILE); -} - -static inline unsigned long sys_file(void) -{ - return global_node_page_state(NR_FILE_PAGES); -} - -static inline unsigned long sys_slab_reclaimable(void) -{ - return global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B); -} - -static inline unsigned long sys_slab_unreclaimable(void) -{ - return global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B); -} - -static inline unsigned long sys_vmalloc(void) -{ - return vmalloc_nr_pages(); -} - -static inline unsigned long sys_inactive_anon(void) -{ - return global_node_page_state(NR_INACTIVE_ANON); -} - -static inline unsigned long sys_active_anon(void) -{ - return global_node_page_state(NR_ACTIVE_ANON); -} - -static inline unsigned long sys_anon(void) -{ - return global_node_page_state(NR_ANON_MAPPED); -} - -static inline unsigned long sys_page_tables(void) -{ - return global_zone_page_state(NR_PAGETABLE); -} - -static inline unsigned long sys_kernel_stack(void) -{ - return global_node_page_state(NR_KERNEL_STACK_KB) >> (PAGE_SHIFT - 10); -} - -static inline unsigned long sys_kernel_misc_reclaimable(void) -{ - return global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE); -} - -static inline unsigned long sys_sharedram(void) -{ - return global_node_page_state(NR_SHMEM); -} - -static inline unsigned long sys_dmabuf(void) -{ - return atomic64_read(&dma_heap_normal_total) >> PAGE_SHIFT; -} - -static inline unsigned long sys_dmabuf_pool(void) -{ - /* for qcom we need also decrease gpu pool but mtk not*/ - return sys_kernel_misc_reclaimable(); -} - -unsigned long sys_gpu(void); -void seq_put_decimal_ull_width_dup(struct seq_file *m, const char *delimiter, - unsigned long long num, unsigned int width); - - -int osvelte_sys_memstat_init(void); -int osvelte_sys_memstat_exit(void); -#endif /* _OSVELTE_SYS_MEMSTAT_H */ diff --git a/drivers/soc/oplus/system/mm_osvelte/vsprintf-dup.c b/drivers/soc/oplus/system/mm_osvelte/vsprintf-dup.c deleted file mode 100644 index d5516d3e2005..000000000000 --- a/drivers/soc/oplus/system/mm_osvelte/vsprintf-dup.c +++ /dev/null @@ -1,278 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include - -/* - * Decimal conversion is by far the most typical, and is used for - * /proc and /sys data. This directly impacts e.g. top performance - * with many processes running. We optimize it for speed by emitting - * two characters at a time, using a 200 byte lookup table. This - * roughly halves the number of multiplications compared to computing - * the digits one at a time. Implementation strongly inspired by the - * previous version, which in turn used ideas described at - * (with permission - * from the author, Douglas W. Jones). - * - * It turns out there is precisely one 26 bit fixed-point - * approximation a of 64/100 for which x/100 == (x * (u64)a) >> 32 - * holds for all x in [0, 10^8-1], namely a = 0x28f5c29. The actual - * range happens to be somewhat larger (x <= 1073741898), but that's - * irrelevant for our purpose. - * - * For dividing a number in the range [10^4, 10^6-1] by 100, we still - * need a 32x32->64 bit multiply, so we simply use the same constant. - * - * For dividing a number in the range [100, 10^4-1] by 100, there are - * several options. The simplest is (x * 0x147b) >> 19, which is valid - * for all x <= 43698. - */ - -static const u16 decpair[100] = { -#define _(x) (__force u16) cpu_to_le16(((x % 10) | ((x / 10) << 8)) + 0x3030) - _( 0), _( 1), _( 2), _( 3), _( 4), _( 5), _( 6), _( 7), _( 8), _( 9), - _(10), _(11), _(12), _(13), _(14), _(15), _(16), _(17), _(18), _(19), - _(20), _(21), _(22), _(23), _(24), _(25), _(26), _(27), _(28), _(29), - _(30), _(31), _(32), _(33), _(34), _(35), _(36), _(37), _(38), _(39), - _(40), _(41), _(42), _(43), _(44), _(45), _(46), _(47), _(48), _(49), - _(50), _(51), _(52), _(53), _(54), _(55), _(56), _(57), _(58), _(59), - _(60), _(61), _(62), _(63), _(64), _(65), _(66), _(67), _(68), _(69), - _(70), _(71), _(72), _(73), _(74), _(75), _(76), _(77), _(78), _(79), - _(80), _(81), _(82), _(83), _(84), _(85), _(86), _(87), _(88), _(89), - _(90), _(91), _(92), _(93), _(94), _(95), _(96), _(97), _(98), _(99), -#undef _ -}; - -/* - * This will print a single '0' even if r == 0, since we would - * immediately jump to out_r where two 0s would be written but only - * one of them accounted for in buf. This is needed by ip4_string - * below. All other callers pass a non-zero value of r. -*/ -static noinline_for_stack -char *put_dec_trunc8(char *buf, unsigned r) -{ - unsigned q; - - /* 1 <= r < 10^8 */ - if (r < 100) - goto out_r; - - /* 100 <= r < 10^8 */ - q = (r * (u64)0x28f5c29) >> 32; - *((u16 *)buf) = decpair[r - 100*q]; - buf += 2; - - /* 1 <= q < 10^6 */ - if (q < 100) - goto out_q; - - /* 100 <= q < 10^6 */ - r = (q * (u64)0x28f5c29) >> 32; - *((u16 *)buf) = decpair[q - 100*r]; - buf += 2; - - /* 1 <= r < 10^4 */ - if (r < 100) - goto out_r; - - /* 100 <= r < 10^4 */ - q = (r * 0x147b) >> 19; - *((u16 *)buf) = decpair[r - 100*q]; - buf += 2; -out_q: - /* 1 <= q < 100 */ - r = q; -out_r: - /* 1 <= r < 100 */ - *((u16 *)buf) = decpair[r]; - buf += r < 10 ? 1 : 2; - return buf; -} - -#if BITS_PER_LONG == 64 && BITS_PER_LONG_LONG == 64 -static noinline_for_stack -char *put_dec_full8(char *buf, unsigned r) -{ - unsigned q; - - /* 0 <= r < 10^8 */ - q = (r * (u64)0x28f5c29) >> 32; - *((u16 *)buf) = decpair[r - 100*q]; - buf += 2; - - /* 0 <= q < 10^6 */ - r = (q * (u64)0x28f5c29) >> 32; - *((u16 *)buf) = decpair[q - 100*r]; - buf += 2; - - /* 0 <= r < 10^4 */ - q = (r * 0x147b) >> 19; - *((u16 *)buf) = decpair[r - 100*q]; - buf += 2; - - /* 0 <= q < 100 */ - *((u16 *)buf) = decpair[q]; - buf += 2; - return buf; -} - -static noinline_for_stack -char *put_dec(char *buf, unsigned long long n) -{ - if (n >= 100*1000*1000) - buf = put_dec_full8(buf, do_div(n, 100*1000*1000)); - /* 1 <= n <= 1.6e11 */ - if (n >= 100*1000*1000) - buf = put_dec_full8(buf, do_div(n, 100*1000*1000)); - /* 1 <= n < 1e8 */ - return put_dec_trunc8(buf, n); -} - -#elif BITS_PER_LONG == 32 && BITS_PER_LONG_LONG == 64 - -static void -put_dec_full4(char *buf, unsigned r) -{ - unsigned q; - - /* 0 <= r < 10^4 */ - q = (r * 0x147b) >> 19; - *((u16 *)buf) = decpair[r - 100*q]; - buf += 2; - /* 0 <= q < 100 */ - *((u16 *)buf) = decpair[q]; -} - -/* - * Call put_dec_full4 on x % 10000, return x / 10000. - * The approximation x/10000 == (x * 0x346DC5D7) >> 43 - * holds for all x < 1,128,869,999. The largest value this - * helper will ever be asked to convert is 1,125,520,955. - * (second call in the put_dec code, assuming n is all-ones). - */ -static noinline_for_stack -unsigned put_dec_helper4(char *buf, unsigned x) -{ - uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43; - - put_dec_full4(buf, x - q * 10000); - return q; -} - -/* Based on code by Douglas W. Jones found at - * - * (with permission from the author). - * Performs no 64-bit division and hence should be fast on 32-bit machines. - */ -static -char *put_dec(char *buf, unsigned long long n) -{ - uint32_t d3, d2, d1, q, h; - - if (n < 100*1000*1000) - return put_dec_trunc8(buf, n); - - d1 = ((uint32_t)n >> 16); /* implicit "& 0xffff" */ - h = (n >> 32); - d2 = (h ) & 0xffff; - d3 = (h >> 16); /* implicit "& 0xffff" */ - - /* n = 2^48 d3 + 2^32 d2 + 2^16 d1 + d0 - = 281_4749_7671_0656 d3 + 42_9496_7296 d2 + 6_5536 d1 + d0 */ - q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); - q = put_dec_helper4(buf, q); - - q += 7671 * d3 + 9496 * d2 + 6 * d1; - q = put_dec_helper4(buf+4, q); - - q += 4749 * d3 + 42 * d2; - q = put_dec_helper4(buf+8, q); - - q += 281 * d3; - buf += 12; - if (q) - buf = put_dec_trunc8(buf, q); - else while (buf[-1] == '0') - --buf; - - return buf; -} - -#endif - -/* - * Convert passed number to decimal string. - * Returns the length of string. On buffer overflow, returns 0. - * - * If speed is not important, use snprintf(). It's easy to read the code. - */ -int num_to_str(char *buf, int size, unsigned long long num, unsigned int width) -{ - /* put_dec requires 2-byte alignment of the buffer. */ - char tmp[sizeof(num) * 3] __aligned(2); - int idx, len; - - /* put_dec() may work incorrectly for num = 0 (generate "", not "0") */ - if (num <= 9) { - tmp[0] = '0' + num; - len = 1; - } else { - len = put_dec(tmp, num) - tmp; - } - - if (len > size || width > size) - return 0; - - if (width > len) { - width = width - len; - for (idx = 0; idx < width; idx++) - buf[idx] = ' '; - } else { - width = 0; - } - - for (idx = 0; idx < len; ++idx) - buf[idx + width] = tmp[len - idx - 1]; - - return len + width; -} - -static void seq_set_overflow(struct seq_file *m) -{ - m->count = m->size; -} - -void seq_put_decimal_ull_width_dup(struct seq_file *m, const char *delimiter, - unsigned long long num, unsigned int width) -{ - int len; - - if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ - goto overflow; - - if (delimiter && delimiter[0]) { - if (delimiter[1] == 0) - seq_putc(m, delimiter[0]); - else - seq_puts(m, delimiter); - } - - if (!width) - width = 1; - - if (m->count + width >= m->size) - goto overflow; - - len = num_to_str(m->buf + m->count, m->size - m->count, num, width); - if (!len) - goto overflow; - - m->count += len; - return; - -overflow: - seq_set_overflow(m); -} diff --git a/drivers/soc/oplus/system/mtk_shutdown_reboot/Kconfig b/drivers/soc/oplus/system/mtk_shutdown_reboot/Kconfig deleted file mode 100755 index 2555a057f715..000000000000 --- a/drivers/soc/oplus/system/mtk_shutdown_reboot/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_MTK_FORCE_SHUTDOWN - tristate "mtk pmic custom made" - default n - help - define this config to mtk pmic custom made diff --git a/drivers/soc/oplus/system/mtk_shutdown_reboot/Makefile b/drivers/soc/oplus/system/mtk_shutdown_reboot/Makefile deleted file mode 100755 index 70a74106572a..000000000000 --- a/drivers/soc/oplus/system/mtk_shutdown_reboot/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_MTK_FORCE_SHUTDOWN) += mtk_force_shutdown/mtk_force_shutdown.o diff --git a/drivers/soc/oplus/system/mtk_shutdown_reboot/mtk_force_shutdown/mtk_force_shutdown.c b/drivers/soc/oplus/system/mtk_shutdown_reboot/mtk_force_shutdown/mtk_force_shutdown.c deleted file mode 100755 index 5373e7a6f432..000000000000 --- a/drivers/soc/oplus/system/mtk_shutdown_reboot/mtk_force_shutdown/mtk_force_shutdown.c +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define REG_ADDR 0xA08 -#define DISABLE_PMIC_CTRL_FUNCTION 0 -#define ENABLE_PMIC_CTRL_FUNCTION 1 -#define TRIGGER_PM_POWEROFF 2 -#define TRIGGER_HARD_RESET 3 - - -/*#if IS_ENABLED(CONFIG_64BIT) -#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN64_##name -#else -#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN_##name -#endif*/ - -extern void (*pm_power_off)(void); - -static int mtk_pmic_custommade_enable = 1; - -static void psci_sys_reset(void) -{ - struct arm_smccc_res res; - - arm_smccc_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0, 0, 0, 0, 0, &res); -} - -static ssize_t mtk_pmic_custommade_write(struct file *file, - const char __user *buf, size_t size, loff_t *ppos) -{ - int ret = 0; - char buffer[4] = {0}; - unsigned int value = 0; - - if (size > 2) { - pr_err("size error\n"); - return size; - } - - if (copy_from_user(buffer, buf, size)) { - pr_err("%s: read proc input error.\n", __func__); - return size; - } - - if (size != 0) { - pr_info("[%s] buffer is %s, size is %d\n", __func__, buffer, (int)size); - ret = kstrtou32(buffer, 16, (unsigned int *)&value); - - if (mtk_pmic_custommade_enable == 0 && value != 1) { - pr_err("mtk_pmic_custommade closed\n"); - return size; - } - - switch (value) { - case DISABLE_PMIC_CTRL_FUNCTION: - pr_info("mtk_pmic_custommade_enable set 0\n"); - mtk_pmic_custommade_enable = 0; - break; - - case ENABLE_PMIC_CTRL_FUNCTION: - pr_info("mtk_pmic_custommade_enable set 1\n"); - mtk_pmic_custommade_enable = 1; - break; - - case TRIGGER_PM_POWEROFF: - pr_info("trigger machine_power_off"); - - if (pm_power_off) { - pm_power_off(); - } - - break; - - case TRIGGER_HARD_RESET: - psci_sys_reset(); - break; - - default: - pr_info("not support\n"); - break; - } - } - - return size; -} - -static int mtk_pmic_custommade_read_func(struct seq_file *s, void *v) -{ - seq_printf(s, "-------------notice------------\n"); - seq_printf(s, "%d: DISABLE_PMIC_CTRL_FUNCTION\n", DISABLE_PMIC_CTRL_FUNCTION); - seq_printf(s, "%d: ENABLE_PMIC_CTRL_FUNCTION\n", ENABLE_PMIC_CTRL_FUNCTION); - seq_printf(s, "%d: TRIGGER_PM_POWEROFF\n", TRIGGER_PM_POWEROFF); - seq_printf(s, "%d: TRIGGER_HARD_RESET\n", TRIGGER_HARD_RESET); - seq_printf(s, "\nmtk_pmic_custommade_enable : %d\n", - mtk_pmic_custommade_enable); - - return 0; -} - -static int mtk_pmic_custommade_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtk_pmic_custommade_read_func, PDE_DATA(inode)); -} -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static const struct file_operations mtk_pmic_custommade_fops = { - .open = mtk_pmic_custommade_open, - .read = seq_read, - .write = mtk_pmic_custommade_write, - .release = single_release, -}; -#else -static const struct proc_ops mtk_pmic_custommade_fops = { - .proc_open = mtk_pmic_custommade_open, - .proc_read = seq_read, - .proc_write = mtk_pmic_custommade_write, - .proc_release = single_release, -}; -#endif - -static int __init mtk_pmic_custommade_init(void) -{ - struct proc_dir_entry *p_entry; - - p_entry = proc_create_data("mtk_pmic_shutdown", S_IRUGO, NULL, - &mtk_pmic_custommade_fops, NULL); - - if (!p_entry) { - goto error_init; - } - - return 0; - -error_init: - return -ENOENT; -} - -late_initcall(mtk_pmic_custommade_init); - -MODULE_DESCRIPTION("mtk pmic custommade version"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("DJ"); diff --git a/drivers/soc/oplus/system/oplus_hans/Kconfig b/drivers/soc/oplus/system/oplus_hans/Kconfig deleted file mode 100755 index e679dcc7463b..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -#ifdef OPLUS_FEATURE_HANS_FREEZE -#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -config OPLUS_FEATURE_HANS_GKI - tristate "HANS kernel and HANS native communication channel" - default n - help - Key events (signal/network package/binder) report to HAS native. -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ - diff --git a/drivers/soc/oplus/system/oplus_hans/Makefile b/drivers/soc/oplus/system/oplus_hans/Makefile deleted file mode 100755 index 900aede10e7c..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -ifeq ($(CONFIG_OPLUS_FEATURE_HANS_GKI), m) -obj-$(CONFIG_OPLUS_FEATURE_HANS_GKI) += oplus_hans.o -oplus_hans-objs += hans_help.o hans.o hans_netfilter.o -endif diff --git a/drivers/soc/oplus/system/oplus_hans/hans.c b/drivers/soc/oplus/system/oplus_hans/hans.c deleted file mode 100755 index 2e0e16c918aa..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/hans.c +++ /dev/null @@ -1,318 +0,0 @@ -/*********************************************************** -** Copyright (C) 2018-2020 Oplus. All rights reserved. -** File: hans.c -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2020/05/27 1.1 OPLUS_FEATURE_HANS_FREEZE -** Qingxin Guo 2021/08/04 1.2 GENERIC NETLINK -****************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include "hans.h" - -#define NETLINK_PORT_HANS (0x15356) - -static atomic_t hans_deamon_port; -bool trans_binder_debug = false; -static int hans_handler(struct sk_buff *skb, struct genl_info *info); - -static const struct genl_ops hans_genl_ops[] = { - { - .cmd = HANS_CMD_GENL, - .flags = 0, - .doit = hans_handler, - .dumpit = NULL, - }, -}; - -static struct genl_family hans_genl_family = { - .id = GENL_ID_GENERATE, - .hdrsize = 0, - .name = HANS_FAMILY, - .version = HANS_FAMILY_VERSION, - .maxattr = HANS_ATTR_MSG_MAX, - .ops = hans_genl_ops, - .n_ops = ARRAY_SIZE(hans_genl_ops), -}; - - -static inline int genl_msg_prepare_usr_msg(unsigned char cmd, size_t size, - pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_ATOMIC); - - if (skb == NULL) { - pr_err("oplus_hans: new genlmsg alloc failed\n"); - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &hans_genl_family, 0, cmd); - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, - int len) -{ - int ret = 0; - - /* add a netlink attribute to a socket buffer */ - ret = nla_put(skb, type, len, data); - - return ret; -} - -/* - * netlink report function to tell HANS native deamon unfreeze process info - * if the parameters is empty, fill it with (pid/uid with -1) - */ -int hans_report(enum message_type type, int caller_pid, int caller_uid, - int target_pid, int target_uid, const char *rpc_name, int code) -{ - int len = 0; - int ret = 0; - void *head; - size_t size; - struct hans_message data; - struct sk_buff *skb = NULL; - - if (atomic_read(&hans_deamon_port) == -1) { - pr_err("%s: hans_deamon_port invalid!\n", __func__); - return HANS_ERROR; - } - - if (type >= TYPE_MAX) { - pr_err("%s: type = %d invalid!\n", __func__, type); - return HANS_ERROR; - } - - len = sizeof(struct hans_message); - size = nla_total_size(len); - - ret = genl_msg_prepare_usr_msg(HANS_CMD_GENL, size, - (pid_t)atomic_read(&hans_deamon_port), &skb); - - if (ret) { - pr_err("%s: genl_msg_prepare_usr_msg failed!\n", __func__); - return HANS_ERROR; - } - - data.type = type; - data.port = NETLINK_PORT_HANS; - data.caller_pid = caller_pid; - data.caller_uid = caller_uid; - data.target_pid = target_pid; - data.target_uid = target_uid; - data.pkg_cmd = -1; /* invalid package cmd */ - data.code = code; - strlcpy(data.rpc_name, rpc_name, INTERFACETOKEN_BUFF_SIZE); - - ret = genl_msg_mk_usr_msg(skb, HANS_ATTR_MSG_GENL, &data, len); - - if (ret) { - pr_err("%s: genl_msg_mk_usr_msg failed!\n", __func__); - kfree_skb(skb); - return HANS_ERROR; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skb))); - genlmsg_end(skb, head); - - if ((ret = genlmsg_unicast(&init_net, skb, - (u32)atomic_read(&hans_deamon_port))) < 0) { - pr_err("%s: genlmsg_unicast failed! err = %d\n", __func__ , ret); - return HANS_ERROR; - } - - return HANS_NOERROR; -} - -/* HANS kernel module handle the message from HANS native deamon */ -static int hans_handler(struct sk_buff *skb, struct genl_info *info) -{ - struct hans_message *data = NULL; - struct nlmsghdr *nlh = NULL; - struct genlmsghdr *genlhdr = NULL; - struct nlattr *nla = NULL; - - unsigned int len = 0; - int uid = -1; - - if (!skb) { - pr_err("%s: recv skb NULL!\n", __func__); - return HANS_ERROR; - } - - /* safety check */ - uid = (*NETLINK_CREDS(skb)).uid.val; - /* only allow native deamon talk with HANS kernel. */ - /*if (uid != 1000) { - pr_err("%s: uid: %d, permission denied\n", __func__, uid); - return; - }*/ - - if (skb->len >= NLMSG_SPACE(0)) { - nlh = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlh); - nla = genlmsg_data(genlhdr); - - if (nla->nla_type == HANS_ATTR_MSG_GENL) { - len = NLA_PAYLOAD(nla->nla_len); - data = (struct hans_message *)NLA_DATA(nla); - - if (len < sizeof(struct hans_message)) { - pr_err("%s: hans_message len check faied! len = %d min_expected_len = %lu!\n", - __func__, len, sizeof(struct hans_message)); - return HANS_ERROR; - } - - if (data->port < 0) { - pr_err("%s: portid = %d invalid!\n", __func__, data->port); - return HANS_ERROR; - } - - if (data->type >= TYPE_MAX) { - pr_err("%s: type = %d invalid!\n", __func__, data->type); - return HANS_ERROR; - } - - if (atomic_read(&hans_deamon_port) == -1 && data->type != LOOP_BACK) { - pr_err("%s: handshake not setup, type = %d!\n", __func__, data->type); - return HANS_ERROR; - } - - switch (data->type) { - case LOOP_BACK: /*Loop back message, only for native deamon and kernel handshake*/ - atomic_set(&hans_deamon_port, data->port); - hans_report(LOOP_BACK, -1, -1, -1, -1, "loop back", CPUCTL_VERSION); - printk(KERN_ERR "%s: --> LOOP_BACK, port = %d\n", __func__, data->port); - break; - - case PKG: - printk(KERN_ERR "%s: --> PKG, uid = %d, pkg_cmd = %d\n", __func__, - data->target_uid, data->pkg_cmd); - hans_network_cmd_parse(data->target_uid, data->pkg_cmd); - break; - - case FROZEN_TRANS: - case CPUCTL_TRANS: - printk(KERN_ERR "%s: --> FROZEN_TRANS, uid = %d\n", __func__, data->target_uid); - hans_check_frozen_transcation(data->target_uid, data->type); - break; - - default: - pr_err("%s: hans_messag type invalid %d\n", __func__, data->type); - break; - } - } - } - - return HANS_NOERROR; -} - -int register_hans_vendor_hooks(void) -{ - int rc = 0; - - rc = register_trace_android_vh_binder_preset(binder_preset_handler, NULL); - - if (rc != 0) { - pr_err("register_trace_android_vh_binder_preset failed, rc=%d\n", rc); - return rc; - } - - rc = register_trace_android_vh_binder_trans(binder_trans_handler, NULL); - - if (rc != 0) { - pr_err("register_trace_android_vh_binder_trans failed, rc=%d\n", rc); - return rc; - } - - rc = register_trace_android_vh_binder_reply(binder_reply_handler, NULL); - - if (rc != 0) { - pr_err("register_trace_android_vh_binder_reply failed, rc=%d\n", rc); - return rc; - } - - rc = register_trace_android_vh_binder_alloc_new_buf_locked(binder_alloc_handler, - NULL); - - if (rc != 0) { - pr_err("register_trace_android_vh_binder_alloc_new_buf_locked failed, rc=%d\n", - rc); - return rc; - } - - rc = register_trace_android_vh_do_send_sig_info(send_signal_handler, NULL); - - if (rc != 0) { - pr_err("register_trace_android_vh_do_send_sig_info failed, rc=%d\n", rc); - return rc; - } - - return rc; -} - -void unregister_hans_vendor_hooks(void) -{ - unregister_trace_android_vh_binder_preset(binder_preset_handler, NULL); - unregister_trace_android_vh_binder_trans(binder_trans_handler, NULL); - unregister_trace_android_vh_binder_reply(binder_reply_handler, NULL); - unregister_trace_android_vh_binder_alloc_new_buf_locked(binder_alloc_handler, - NULL); - unregister_trace_android_vh_do_send_sig_info(send_signal_handler, NULL); -} - -static int __init hans_core_init(void) -{ - if (genl_register_family(&hans_genl_family) != 0) { - pr_err("%s: genl_register_family error!\n", __func__); - return HANS_ERROR; - } - - if (register_hans_vendor_hooks() != 0) { - pr_err("%s: hans vendor hook register failed!\n", __func__); - return HANS_ERROR; - } - - atomic_set(&hans_deamon_port, -1); - - if (hans_netfilter_init() == HANS_ERROR) { - pr_err("%s: netfilter init failed!\n", __func__); - return HANS_ERROR; - } - - printk(KERN_INFO "%s: -\n", __func__); - return HANS_NOERROR; -} - -static void __exit hans_core_exit(void) -{ - genl_unregister_family(&hans_genl_family); - unregister_hans_vendor_hooks(); - hans_netfilter_deinit(); - printk(KERN_INFO "%s: -\n", __func__); -} - -module_init(hans_core_init); -module_exit(hans_core_exit); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("zhoukun1 "); - diff --git a/drivers/soc/oplus/system/oplus_hans/hans.h b/drivers/soc/oplus/system/oplus_hans/hans.h deleted file mode 100755 index da7ac543af0f..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/hans.h +++ /dev/null @@ -1,185 +0,0 @@ -/*********************************************************** -** Copyright (C) 2018-2020 Oplus. All rights reserved. -** File: hans.h -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2019/09/23 1.1 OPLUS_FEATURE_HANS_FREEZE -** Qingxin Guo 2021/08/04 1.2 GENERIC NETLINK -****************************************************************/ - -#ifndef _HANS_H -#define _HANS_H - -#include -#include -#include -#include -#include -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#include "../../../../../kernel_platform/common/kernel/sched/sched.h" -#include "../../../../../kernel_platform/common/drivers/android/binder_internal.h" -#include "../../../../../kernel_platform/common/drivers/android/binder_alloc.h" -#else -#include "../../../../../kernel-5.10/kernel/sched/sched.h" -#include "../../../../../kernel-5.10/drivers/android/binder_internal.h" -#include "../../../../../kernel-5.10/drivers/android/binder_alloc.h" -#endif - -#define HANS_NOERROR (0) -#define HANS_ERROR (-1) -#define MIN_USERAPP_UID (10000) -#define MAX_SYSTEM_UID (2000) -#define HANS_SYSTEM_UID (1000) -#define INTERFACETOKEN_BUFF_SIZE (140) -#define PARCEL_OFFSET (16) /* sync with the writeInterfaceToken */ -#define CPUCTL_VERSION (2) -#define TRANS_BINDER_DEBUG_ON (-10000) -#define TRANS_BINDER_DEBUG_OFF (-9000) - -#define HANS_FAMILY_VERSION 1 -#define HANS_FAMILY "oplus_hans" -#define GENL_ID_GENERATE 0 -#define NLA_DATA(na) ((char *)((char *)(na) + NLA_HDRLEN)) -#define NLA_PAYLOAD(len) (len - NLA_HDRLEN) - -/* attribute type */ -enum { - HANS_ATTR_MSG_UNDEFINE = 0, - HANS_ATTR_MSG_GENL, - __HANS_ATTR_MSG_MAX -}; -#define HANS_ATTR_MSG_MAX (__HANS_ATTR_MSG_MAX - 1) - -/* cmd type */ -enum { - HANS_CMD_UNDEFINE = 0, - HANS_CMD_GENL, - __HANS_CMD_MAX, -}; -#define HANS_CMD_MAX (__HANS_CMD_MAX - 1) - -/* hans_message for comunication with HANS native deamon - * type: async binder/sync binder/signal/pkg/loopback - * Only loop back type is duplex (native deamon <---> kernel) for handshake - * port: native deamon pid - * caller_pid: binder, caller -> unfreeze (target) UID - * target_uid: UID want to be unfrozen - * pkg_cmd: Add/Remove monitored UID - */ -struct hans_message { - int type; - int port; /* pid */ - - int caller_uid; /*caller -> unfreeze UID*/ - int caller_pid; /*caller -> unfreeze UID*/ - int target_pid; /*unfreeze UID, pkg add/remove UID*/ - int target_uid; /*unfreeze UID, pkg add/remove UID*/ - - int pkg_cmd; /*Add/remove monitored uid*/ - - int code; - char rpc_name[INTERFACETOKEN_BUFF_SIZE]; -}; - -/* hans message type definition */ -enum message_type { - /* kernel --> native deamon */ - ASYNC_BINDER, - SYNC_BINDER, - FROZEN_TRANS, - SIGNAL, - PKG, - - /*For cpuclt solution*/ - SYNC_BINDER_CPUCTL, - SIGNAL_CPUCTL, - CPUCTL_TRANS, - - /*kernel <--> native deamon*/ - LOOP_BACK, - TYPE_MAX -}; - -/* pkg cmd type */ -enum pkg_cmd { - ADD_ONE_UID, - DEL_ONE_UID, - DEL_ALL_UID, - - PKG_CMD_MAX -}; - -extern bool trans_binder_debug; - -/* Check if the thread group is frozen */ -static inline bool is_jobctl_frozen(struct task_struct *task) -{ - return ((task->jobctl & JOBCTL_TRAP_FREEZE) != 0); -} -static inline bool is_frozen_tg(struct task_struct *task) -{ - return ((cgroup_task_frozen(task) && is_jobctl_frozen(task)) || frozen(task->group_leader) || freezing(task->group_leader)); -} - -static inline bool is_zombie_tg(struct task_struct *task) -{ - if(task != NULL && task->group_leader != NULL) { - return (task->group_leader->exit_state == EXIT_ZOMBIE); - } - return false; -} - -int hans_report(enum message_type type, int caller_pid, int caller_uid, - int target_pid, int target_uid, const char *rpc_name, int code); -void hans_network_cmd_parse(uid_t uid, enum pkg_cmd cmd); -void hans_check_frozen_transcation(uid_t uid, enum message_type type); -int hans_netfilter_init(void); -void hans_netfilter_deinit(void); -void hans_check_async_binder_buffer(bool is_async, int free_async_space, - int size, int binder_buffer_size, int alloc_buffer_size, int pid); -void hans_check_signal(struct task_struct *p, int sig); - -void binder_preset_handler(void *data, struct hlist_head *hhead, - struct mutex *lock); -void binder_trans_handler(void *data, struct binder_proc *target_proc, - struct binder_proc *proc, struct binder_thread *thread, - struct binder_transaction_data *tr); -void binder_reply_handler(void *data, struct binder_proc *target_proc, - struct binder_proc *proc, struct binder_thread *thread, - struct binder_transaction_data *tr); -void binder_alloc_handler(void *data, size_t size, struct binder_alloc *alloc, - int is_async); -void send_signal_handler(void *data, int sig, struct task_struct *killer, - struct task_struct *dst); - - -#if defined(CONFIG_CFS_BANDWIDTH) -static inline bool is_belong_cpugrp(struct task_struct *task) -{ - if (task->sched_task_group != NULL) { - struct cfs_bandwidth cfs_b = task->sched_task_group->cfs_bandwidth; - - if (cfs_b.quota != -1) { - return true; - - } else if (cfs_b.quota == -1) { - return false; - } - } - - return false; -} -#else -static inline bool is_belong_cpugrp(struct task_struct *task) -{ - return false; -} -#endif /*CONFIG_CFS_BANDWIDTH*/ -#endif /*_HANS_H*/ diff --git a/drivers/soc/oplus/system/oplus_hans/hans_help.c b/drivers/soc/oplus/system/oplus_hans/hans_help.c deleted file mode 100755 index b77984f731ab..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/hans_help.c +++ /dev/null @@ -1,381 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "hans.h" - -struct hlist_head *binder_procs = NULL; -struct mutex *binder_procs_lock = NULL; - -/** - * binder_inner_proc_lock() - Acquire inner lock for given binder_proc - * @proc: struct binder_proc to acquire - * - * Acquires proc->inner_lock. Used to protect todo lists - */ -#define binder_inner_proc_lock(proc) _binder_inner_proc_lock(proc, __LINE__) -static void -_binder_inner_proc_lock(struct binder_proc *proc, int line) -__acquires(&proc->inner_lock) -{ - spin_lock(&proc->inner_lock); -} - -/** - * binder_inner_proc_unlock() - Release inner lock for given binder_proc - * @proc: struct binder_proc to acquire - * - * Release lock acquired via binder_inner_proc_lock() - */ -#define binder_inner_proc_unlock(proc) _binder_inner_proc_unlock(proc, __LINE__) -static void -_binder_inner_proc_unlock(struct binder_proc *proc, int line) -__releases(&proc->inner_lock) -{ - spin_unlock(&proc->inner_lock); -} - -static bool binder_worklist_empty_ilocked(struct list_head *list) -{ - return list_empty(list); -} - - -void binder_preset_handler(void *data, struct hlist_head *hhead, - struct mutex *lock) -{ - if (binder_procs == NULL) { - binder_procs = hhead; - } - - if (binder_procs_lock == NULL) { - binder_procs_lock = lock; - } -} - -void binder_trans_handler(void *data, struct binder_proc *target_proc, - struct binder_proc *proc, - struct binder_thread *thread, - struct binder_transaction_data *tr) -{ - char buf_data[INTERFACETOKEN_BUFF_SIZE]; - size_t buf_data_size; - char buf[INTERFACETOKEN_BUFF_SIZE] = {0}; - int i = 0; - int j = 0; - - /*Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager*/ - if (!(tr->flags & TF_ONE_WAY) /*report sync binder call*/ - && target_proc - && (NULL != target_proc->tsk) - && (NULL != proc->tsk) - && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) - && (proc->pid != target_proc->pid) - && (is_frozen_tg(target_proc->tsk) || is_zombie_tg(target_proc->tsk))) { - hans_report(SYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER", -1); - } - -#if defined(CONFIG_CFS_BANDWIDTH) - - if (!(tr->flags & TF_ONE_WAY) /*report sync binder call*/ - && target_proc - && (NULL != target_proc->tsk) - && (NULL != proc->tsk) - && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID || task_uid(target_proc->tsk).val == HANS_SYSTEM_UID) //uid >10000 - && (is_belong_cpugrp(target_proc->tsk) || is_zombie_tg(target_proc->tsk))) { - hans_report(SYNC_BINDER_CPUCTL, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER_CPUCTL", -1); - } -#endif - - if ((tr->flags & TF_ONE_WAY) /*report async binder call*/ - && target_proc - && (NULL != target_proc->tsk) - && (NULL != proc->tsk) - && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) - && (proc->pid != target_proc->pid) - && is_frozen_tg(target_proc->tsk)) { - buf_data_size = tr->data_size>INTERFACETOKEN_BUFF_SIZE ?INTERFACETOKEN_BUFF_SIZE:tr->data_size; - if (!copy_from_user(buf_data, (char*)tr->data.ptr.buffer, buf_data_size)) { - /*1.skip first PARCEL_OFFSET bytes (useless data) - 2.make sure the invalid address issue is not occuring(j =PARCEL_OFFSET+1, j+=2) - 3.java layer uses 2 bytes char. And only the first bytes has the data.(p+=2)*/ - if (buf_data_size > PARCEL_OFFSET) { - char *p = (char *)(buf_data) + PARCEL_OFFSET; - j = PARCEL_OFFSET + 1; - - while (i < INTERFACETOKEN_BUFF_SIZE && j < buf_data_size && *p != '\0') { - buf[i++] = *p; - j += 2; - p += 2; - } - - if (i == INTERFACETOKEN_BUFF_SIZE) { - buf[i - 1] = '\0'; - } - } - - hans_report(ASYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, - task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, buf, tr->code); - } - } -} - -void binder_reply_handler(void *data, struct binder_proc *target_proc, - struct binder_proc *proc, - struct binder_thread *thread, - struct binder_transaction_data *tr) -{ - /*Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager*/ - /*only sync binder call has BC_REPLY*/ - if (target_proc - && (NULL != target_proc->tsk) - && (NULL != proc->tsk) - && (task_uid(target_proc->tsk).val <= MAX_SYSTEM_UID) - && (proc->pid != target_proc->pid) - && is_frozen_tg(target_proc->tsk)) { - hans_report(SYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER_REPLY", -1); - } -} - -void binder_alloc_handler(void *data, size_t size, struct binder_alloc *alloc, - int is_async) -{ - struct task_struct *p = NULL; - - if (is_async - && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer)) - || (alloc->free_async_space < ((alloc->buffer_size / 2) * 9 / 10)))) { - rcu_read_lock(); - p = find_task_by_vpid(alloc->pid); - rcu_read_unlock(); - - if (p != NULL && is_frozen_tg(p)) { - hans_report(ASYNC_BINDER, task_tgid_nr(current), task_uid(current).val, - task_tgid_nr(p), task_uid(p).val, "free_buffer_full", -1); - } - } -} - -void send_signal_handler(void *data, int sig, struct task_struct *killer, - struct task_struct *dst) -{ - - if ((is_frozen_tg(dst) || is_zombie_tg(dst)) /*signal receiver thread group is frozen?*/ - && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT - || sig == SIGQUIT || sig == SIGIO)) { - if (hans_report(SIGNAL, task_tgid_nr(killer), task_uid(killer).val, task_tgid_nr(dst), task_uid(dst).val, "signal", -1) == HANS_ERROR) { - printk(KERN_ERR "HANS: report signal-freeze failed, sig = %d, caller = %d, target_uid = %d\n", sig, task_tgid_nr(killer), task_uid(dst).val); - } - } - -#if defined(CONFIG_CFS_BANDWIDTH) - - if ((is_belong_cpugrp(dst) || is_zombie_tg(dst)) /*signal receiver thread group is cpuctl?*/ - && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)) { - if (hans_report(SIGNAL, task_tgid_nr(killer), task_uid(killer).val, - task_tgid_nr(dst), task_uid(dst).val, "signal", -1) == HANS_ERROR) { - printk(KERN_ERR - "HANS: report signal-cpuctl failed, sig = %d, caller = %d, target_uid = %d\n", - sig, task_tgid_nr(killer), task_uid(dst).val); - } - } - -#endif -} - -static void get_uid_pid(int *from_pid, int *from_uid, int *to_pid, int *to_uid, - struct binder_transaction *tr) -{ - if (tr->from != NULL && tr->from->proc != NULL - && tr->from->proc->tsk != NULL) { - *from_pid = task_tgid_nr(tr->from->proc->tsk); - - } else { - *from_pid = -1; - } - - *from_uid = tr->sender_euid.val; - *to_pid = tr->to_thread ? tr->to_thread->proc->pid : -1; - *to_uid = tr->to_thread ? task_uid(tr->to_thread->task).val : -1; -} - -/* Only used for debuging, controled by FW */ -void hans_check_uid_proc_status_debug(struct binder_proc *proc, - enum message_type type) -{ - struct rb_node *n = NULL; - struct binder_thread *thread = NULL; - int from_uid = -1; - int from_pid = -1; - int to_uid = -1; - int to_pid = -1; - struct binder_transaction *btrans = NULL; - bool empty = true; - int need_reply = -1; - struct binder_work *w = NULL; - - /*check binder_thread/transaction_stack/binder_proc ongoing transaction*/ - binder_inner_proc_lock(proc); - - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) { - thread = rb_entry(n, struct binder_thread, rb_node); - empty = binder_worklist_empty_ilocked(&thread->todo); - - if (thread->task != NULL) { - /*has "todo" binder thread in worklist?*/ - to_uid = task_uid(thread->task).val; - - if (!empty) { - /*scan thread->todo list*/ - list_for_each_entry(w, &thread->todo, entry) { - if (w != NULL && w->type == BINDER_WORK_TRANSACTION) { - btrans = container_of(w, struct binder_transaction, work); - spin_lock(&btrans->lock); - - if (btrans != NULL && btrans->to_thread == thread) { - need_reply = (int)(btrans->need_reply == 1); - get_uid_pid(&from_pid, &from_uid, &to_pid, &to_uid, btrans); - spin_unlock(&btrans->lock); - hans_report(type, from_pid, from_uid, to_pid, to_uid, "FROZEN_TRANS_THREAD", - need_reply); - - } else { - spin_unlock(&btrans->lock); - } - } - } - } - - /*has transcation in transaction_stack?*/ - btrans = thread->transaction_stack; - - if (btrans) { - spin_lock(&btrans->lock); - - if (btrans->to_thread == thread) { - /*only report incoming binder call*/ - need_reply = (int)(btrans->need_reply == 1); - get_uid_pid(&from_pid, &from_uid, &to_pid, &to_uid, btrans); - spin_unlock(&btrans->lock); - hans_report(type, from_pid, from_uid, to_pid, to_uid, "FROZEN_TRANS_STACK", - need_reply); - - } else { - spin_unlock(&btrans->lock); - } - } - } - } - - /*has "todo" binder proc in worklist*/ - empty = binder_worklist_empty_ilocked(&proc->todo); - - if (proc->tsk != NULL && !empty) { - to_uid = task_uid(proc->tsk).val; - list_for_each_entry(w, &proc->todo, entry) { - if (w != NULL && w->type == BINDER_WORK_TRANSACTION) { - btrans = container_of(w, struct binder_transaction, work); - spin_lock(&btrans->lock); - - if (btrans != NULL && btrans->to_thread == thread) { - need_reply = (int)(btrans->need_reply == 1); - get_uid_pid(&from_pid, &from_uid, &to_pid, &to_uid, btrans); - spin_unlock(&btrans->lock); - hans_report(type, from_pid, from_uid, to_pid, to_uid, "FROZEN_TRANS_PROC", - need_reply); - - } else { - spin_unlock(&btrans->lock); - } - } - } - } - - binder_inner_proc_unlock(proc); -} - -static void hans_check_uid_proc_status(struct binder_proc *proc, - enum message_type type) -{ - struct rb_node *n = NULL; - struct binder_thread *thread = NULL; - int uid = -1; - struct binder_transaction *btrans = NULL; - bool empty = true; - - /* check binder_thread/transaction_stack/binder_proc ongoing transaction */ - binder_inner_proc_lock(proc); - - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) { - thread = rb_entry(n, struct binder_thread, rb_node); - empty = binder_worklist_empty_ilocked(&thread->todo); - - if (thread->task != NULL) { - /* has "todo" binder thread in worklist? */ - uid = task_uid(thread->task).val; - - if (!empty) { - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_THREAD", 1); - return; - } - - /* has transcation in transaction_stack? */ - btrans = thread->transaction_stack; - - if (btrans) { - spin_lock(&btrans->lock); - - if (btrans->to_thread == thread) { - /* only report incoming binder call */ - spin_unlock(&btrans->lock); - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_STACK", 1); - return; - } - - spin_unlock(&btrans->lock); - } - } - } - - /* has "todo" binder proc in worklist */ - empty = binder_worklist_empty_ilocked(&proc->todo); - - if (proc->tsk != NULL && !empty) { - uid = task_uid(proc->tsk).val; - binder_inner_proc_unlock(proc); - hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_PROC", 1); - return; - } - - binder_inner_proc_unlock(proc); -} - -void hans_check_frozen_transcation(uid_t uid, enum message_type type) -{ - struct binder_proc *proc; - - if (uid == TRANS_BINDER_DEBUG_ON) { - trans_binder_debug = true; - - } else if (uid == TRANS_BINDER_DEBUG_OFF) { - trans_binder_debug = false; - } - - mutex_lock(binder_procs_lock); - hlist_for_each_entry(proc, binder_procs, proc_node) { - if (proc != NULL && (proc->tsk != NULL) && (task_uid(proc->tsk).val == uid)) { - if (trans_binder_debug == true) { - hans_check_uid_proc_status_debug(proc, type); - - } else { - hans_check_uid_proc_status(proc, type); - } - } - } - mutex_unlock(binder_procs_lock); -} diff --git a/drivers/soc/oplus/system/oplus_hans/hans_netfilter.c b/drivers/soc/oplus/system/oplus_hans/hans_netfilter.c deleted file mode 100755 index 25dca17010d6..000000000000 --- a/drivers/soc/oplus/system/oplus_hans/hans_netfilter.c +++ /dev/null @@ -1,283 +0,0 @@ -/*********************************************************** -** Copyright (C) 2018-2020 Oplus. All rights reserved. -** File: hans_netfilter.c -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2019/09/23 1.1 OPLUS_FEATURE_HANS_FREEZE -****************************************************************/ - -#include -#include -#include -#include -#include -#include -#include "hans.h" - -#define MAX_SLOT (100) -static uid_t monitored_uids[MAX_SLOT]; -spinlock_t uids_lock; - -static inline uid_t sock2uid(struct sock *sk) -{ - if (sk && sk->sk_socket) { - return SOCK_INODE(sk->sk_socket)->i_uid.val; - - } else { - return 0; - } -} - -/* Add netlink monitor uid. When the monitored UID has incoming network package, tell HANS native deamon */ -static void hans_add_monitored_uid(uid_t target_uid) -{ - int i = 0; - int fisrt_empty_slot = MAX_SLOT; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - - for (i = 0; i < MAX_SLOT; i++) { - if (monitored_uids[i] == target_uid) { /* already in the monitored array */ - spin_unlock_irqrestore(&uids_lock, flags); - /* printk(KERN_WARNING "%s: uid = %d already in array\n", __func__, target_uid); */ - return; - - } else if (monitored_uids[i] == 0 - && fisrt_empty_slot == MAX_SLOT) { /* first empty slot for monitoring uid */ - fisrt_empty_slot = i; - } - } - - if (fisrt_empty_slot >= MAX_SLOT) { - spin_unlock_irqrestore(&uids_lock, flags); - pr_err("%s: monitored uid = %d add failed!\n", __func__, target_uid); - return; - } - - monitored_uids[fisrt_empty_slot] = target_uid; - spin_unlock_irqrestore(&uids_lock, flags); -} - -static void hans_remove_monitored_uid(uid_t target_uid) -{ - int i = 0; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - - for (i = 0; i < MAX_SLOT; i++) { - if (monitored_uids[i] == target_uid) { - monitored_uids[i] = 0; - spin_unlock_irqrestore(&uids_lock, flags); - return; - } - } - - spin_unlock_irqrestore(&uids_lock, flags); - printk(KERN_WARNING "%s: uid = %d remove uid not found\n", __func__, - target_uid); -} - -static void hans_remove_all_monitored_uid(void) -{ - int i; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - - for (i = 0; i < MAX_SLOT; i++) { - monitored_uids[i] = 0; - } - - spin_unlock_irqrestore(&uids_lock, flags); -} - -static bool hans_find_remove_monitored_uid(uid_t target_uid) -{ - bool found = false; - int i = 0; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - - for (i = 0; i < MAX_SLOT; i++) { - if (unlikely(monitored_uids[i] == target_uid)) { - found = true; - monitored_uids[i] = 0; - break; - } - } - - spin_unlock_irqrestore(&uids_lock, flags); - - if (found) { - printk(KERN_WARNING "%s: uid = %d found and removed\n", __func__, target_uid); - } - - return found; -} - -void hans_network_cmd_parse(uid_t uid, enum pkg_cmd cmd) -{ - switch (cmd) { - case ADD_ONE_UID: - hans_add_monitored_uid(uid); - break; - - case DEL_ONE_UID: - hans_remove_monitored_uid(uid); - break; - - case DEL_ALL_UID: - hans_remove_all_monitored_uid(); - break; - - default: - pr_err("%s: pkg_cmd type invalid %d\n", __func__, cmd); - break; - } -} - -/* Moniter the uid by netlink filter hook function. */ -static unsigned int hans_nf_ipv4v6_in(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - struct sock *sk; - uid_t uid; - unsigned int thoff = 0; - unsigned short frag_off = 0; - bool found = false; - uint hook; - struct net_device *dev = NULL; - - /* skb protection code */ - if (!skb || !skb->len || !state) { - pr_err("%s, buffer empty\n", __func__); - return NF_ACCEPT; - } - - hook = state->hook; - - if (NF_INET_LOCAL_IN == hook) { - dev = state->in; - } - - if (NULL == dev) { - return NF_ACCEPT; - } - - /* skb protection code end */ - - if (ip_hdr(skb)->version == 4) { - if (ip_hdr(skb)->protocol != IPPROTO_TCP) { - return NF_ACCEPT; - } - -#if IS_ENABLED(CONFIG_IPV6) - - } else if (ip_hdr(skb)->version == 6) { - if (ipv6_find_hdr(skb, &thoff, -1, &frag_off, NULL) != IPPROTO_TCP) { - return NF_ACCEPT; - } - -#endif - - } else { - return NF_ACCEPT; - } - - sk = skb_to_full_sk(skb); - - if (sk == NULL) { - return NF_ACCEPT; - } - - if (!sk_fullsock(sk)) { - return NF_ACCEPT; - } - - uid = sock2uid(sk); - - if (uid < MIN_USERAPP_UID) { - return NF_ACCEPT; - } - - /* Find the monitored UID and clear it from the monitor array */ - found = hans_find_remove_monitored_uid(uid); - - if (!found) { - return NF_ACCEPT; - } - - if (hans_report(PKG, -1, -1, -1, uid, "PKG", -1) != HANS_NOERROR) { - pr_err("%s: hans_report PKG failed!, uid = %d\n", __func__, uid); - } - - return NF_ACCEPT; -} - -/* Only monitor input network packages */ -static struct nf_hook_ops hans_nf_ops[] = { - { - .hook = hans_nf_ipv4v6_in, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_SELINUX_LAST + 1, - }, -#if IS_ENABLED(CONFIG_IPV6) - { - .hook = hans_nf_ipv4v6_in, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP6_PRI_SELINUX_LAST + 1, - }, -#endif -}; - -void hans_netfilter_deinit(void) -{ - struct net *net; - - rtnl_lock(); - for_each_net(net) { - nf_unregister_net_hooks(net, hans_nf_ops, ARRAY_SIZE(hans_nf_ops)); - } - rtnl_unlock(); -} - -int hans_netfilter_init(void) -{ - struct net *net = NULL; - int err = 0; - - spin_lock_init(&uids_lock); - hans_remove_all_monitored_uid(); - - rtnl_lock(); - for_each_net(net) { - err = nf_register_net_hooks(net, hans_nf_ops, ARRAY_SIZE(hans_nf_ops)); - - if (err != 0) { - pr_err("%s: register netfilter hooks failed!\n", __func__); - break; - } - } - rtnl_unlock(); - - if (err != 0) { - hans_netfilter_deinit(); - return HANS_ERROR; - } - - return HANS_NOERROR; -} - diff --git a/drivers/soc/oplus/system/oplus_midas/Kconfig b/drivers/soc/oplus/system/oplus_midas/Kconfig deleted file mode 100644 index f0bce8d0e2c9..000000000000 --- a/drivers/soc/oplus/system/oplus_midas/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ifdef OPLUS_FEATURE_MIDAS -config OPLUS_FEATURE_MIDAS -bool "config oplus midas feature" -help - This selects midas driver -#endif /*OPLUS_FEATURE_MIDAS*/ diff --git a/drivers/soc/oplus/system/oplus_midas/Makefile b/drivers/soc/oplus/system/oplus_midas/Makefile deleted file mode 100644 index 5b63e0609507..000000000000 --- a/drivers/soc/oplus/system/oplus_midas/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ifdef OPLUS_FEATURE_MIDAS -oplus_midas-objs := midas_proc.o dispcap_dev.o vpu_pw_off_latency_proc.o -obj-$(CONFIG_OPLUS_FEATURE_MIDAS) += oplus_midas.o -#endif /* OPLUS_FEATURE_MIDAS */ - diff --git a/drivers/soc/oplus/system/oplus_midas/dispcap_dev.c b/drivers/soc/oplus/system/oplus_midas/dispcap_dev.c deleted file mode 100755 index 5b6f33b661e2..000000000000 --- a/drivers/soc/oplus/system/oplus_midas/dispcap_dev.c +++ /dev/null @@ -1,487 +0,0 @@ -/* - * linux/drivers/soc/oplus/oppo_midas/dispcap_dev.c - * - * Added dispcap drivers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef OPLUS_FEATURE_MIDAS - -#define DISPCAP_CTL_SET_CAPTURE_RECT 97 -#define DISPCAP_CTL_SET_CAPTURE_INTERVAL 98 -#define DISPCAP_CTL_ENABLE_CAPTURE 99 -#define DISPCAP_CTL_SET_BUFFER 100 -#define DISPCAP_CTL_WAIT_BUFFER_COMPLETE 101 -#define DISPCAP_CTL_RET_SUCC 0 -#define DISPCAP_CTL_RET_WAIT_TIMEOUT 1 -#define DISPCAP_CTL_RET_INVALID -1 -#define DISPCAP_CTL_RET_ERROR -2 -#define DISPCAP_LOGD(...) -#define DISPCAP_LOGE pr_err - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -bool setCaptureRect(int left, int top, int width, int height) -{ - return false; -} -bool setCaptureInterval(int interval) -{ - return false; -} -bool enableCapture(int en) -{ - return false; -} -bool setUserBuffer(u8 *user_buffer) -{ - return false; -} -#else /*#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ -/*import from display driver*/ -extern bool setCaptureRect(int left, int top, int width, int height); -extern bool setCaptureInterval(int interval); -extern bool enableCapture(int en); -extern bool setUserBuffer(u8 *user_buffer); -#endif /*#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - -/*import from ion driver*/ -typedef void (*fp_buffer_complete_notify)(void *user_buffer); -struct ion_handle; -extern struct ion_device *g_ion_device; -extern void *ion_map_kernel(struct ion_client *client, - struct ion_handle *handle); -extern void ion_unmap_kernel(struct ion_client *client, - struct ion_handle *handle); -extern bool setBufferCompleteNotifyCallback(fp_buffer_complete_notify cb); - -struct disp_capture_rect { - int x; - int y; - int w; - int h; -}; - -struct disp_driver_context { - struct ion_handle *dispcap_ion_handle; -}; - -struct disp_driver { - dev_t dev; - struct cdev cdev; - struct class *dev_class; - struct device *device; - struct ion_client *ion_client; - struct completion dispcap_cmp; - struct mutex dispcap_lock; - bool dispcap_used; -}; - -static struct disp_driver g_disp_driver; - -void dispcap_notify_buffer_complete(void *result_buf) -{ - DISPCAP_LOGD("start result_buf:%p\n", result_buf); - complete(&g_disp_driver.dispcap_cmp); - DISPCAP_LOGD("complete g_disp_driver.dispcap_cmp notify\n"); -} -EXPORT_SYMBOL(dispcap_notify_buffer_complete); - -static int driver_open(struct inode *inode, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - if (g_disp_driver.dispcap_used) { - DISPCAP_LOGD("dispcap is in used.\n"); - mutex_unlock(&g_disp_driver.dispcap_lock); - return -1; - } - - context_ptr = kmalloc(sizeof(struct disp_driver_context), GFP_KERNEL); - - if (NULL == context_ptr) { - mutex_unlock(&g_disp_driver.dispcap_lock); - return -ENOMEM; - } - - context_ptr->dispcap_ion_handle = NULL; - - filp->private_data = context_ptr; - - g_disp_driver.dispcap_used = true; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static int driver_release(struct inode *ignored, struct file *filp) -{ - struct disp_driver_context *context_ptr; - - DISPCAP_LOGD("start\n"); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr = filp->private_data; - - if (NULL != context_ptr) { - /*disable capture buffer and unmap*/ - setUserBuffer(NULL); - - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - kfree(context_ptr); - filp->private_data = NULL; - } - - g_disp_driver.dispcap_used = false; - - mutex_unlock(&g_disp_driver.dispcap_lock); - - return 0; -} - -static long driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) -{ - long ret = -1; - struct disp_driver_context *context_ptr = filp->private_data; - - DISPCAP_LOGD("start cmd:%d arg:%lu\n", cmd, arg); - - if (NULL == context_ptr) { - DISPCAP_LOGE("context_ptr error!\n"); - return ret; - } - - switch (cmd) { - case DISPCAP_CTL_SET_CAPTURE_RECT: { - struct disp_capture_rect rect; - - if (0 != copy_from_user(&rect, (void __user *)arg, - sizeof(struct disp_capture_rect))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_CAPTURE_RECT arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - if (!setCaptureRect(rect.x, rect.y, rect.w, rect.h)) { - DISPCAP_LOGE("setCaptureRect error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("setCaptureRect:%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); - ret = DISPCAP_CTL_RET_SUCC; - } - break; - - case DISPCAP_CTL_SET_CAPTURE_INTERVAL: { - int interval; - - if (0 != copy_from_user(&interval, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_CAPTURE_INTERVAL arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - if (!setCaptureInterval(interval)) { - DISPCAP_LOGE("setCaptureInterval error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("setCaptureInterval:%d\n", interval); - ret = DISPCAP_CTL_RET_SUCC; - } - break; - - case DISPCAP_CTL_ENABLE_CAPTURE: { - int capture; - - if (0 != copy_from_user(&capture, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_ENABLE_CAPTURE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - if (!enableCapture(capture)) { - DISPCAP_LOGE("setCaptureInterval error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("enableCapture:%d\n", capture); - - setBufferCompleteNotifyCallback(dispcap_notify_buffer_complete); - DISPCAP_LOGD("setBufferCompleteNotifyCallback:%p\n", - dispcap_notify_buffer_complete); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - - case DISPCAP_CTL_SET_BUFFER: { - int ion_share_fd; - struct dma_buf *cur_dma_buf; - void *map_ion_va; - - if (0 != copy_from_user(&ion_share_fd, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_SET_BUFFER arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("ion_share_fd:%d\n", ion_share_fd); - - cur_dma_buf = dma_buf_get(ion_share_fd); - - if (NULL == cur_dma_buf) { - DISPCAP_LOGE("dma_buf_get failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - break; - } - - DISPCAP_LOGD("cur_dma_buf:%p\n", cur_dma_buf); - DISPCAP_LOGD("cur_dma_buf size:%lu\n", cur_dma_buf->size); - - mutex_lock(&g_disp_driver.dispcap_lock); - - context_ptr->dispcap_ion_handle = ion_import_dma_buf_fd( - g_disp_driver.ion_client, ion_share_fd); - - if (NULL == context_ptr->dispcap_ion_handle) { - DISPCAP_LOGE("ion_import_dma_buf_fd failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - DISPCAP_LOGD("ion_import_dma_buf_fd ion_handle:%p\n", - context_ptr->dispcap_ion_handle); - - map_ion_va = ion_map_kernel(g_disp_driver.ion_client, - context_ptr->dispcap_ion_handle); - - if (NULL == map_ion_va) { - DISPCAP_LOGE("ion_map_kernel failed!\n"); - ret = DISPCAP_CTL_RET_ERROR; - mutex_unlock(&g_disp_driver.dispcap_lock); - break; - } - - DISPCAP_LOGD("ion_map_kernel map_ion_va:%p\n", map_ion_va); - - DISPCAP_LOGD("reinit_completion\n"); - reinit_completion(&g_disp_driver.dispcap_cmp); - - DISPCAP_LOGD("setUserBuffer: %p\n", map_ion_va); - setUserBuffer(map_ion_va); - - mutex_unlock(&g_disp_driver.dispcap_lock); - - ret = DISPCAP_CTL_RET_SUCC; - } - break; - - case DISPCAP_CTL_WAIT_BUFFER_COMPLETE: { - int wait_ms; - int wait_ret; - - if (0 != copy_from_user(&wait_ms, (void __user *)arg, sizeof(int))) { - DISPCAP_LOGE("DISPCAP_CTL_WAIT_BUFFER_COMPLETE arg error!\n"); - ret = DISPCAP_CTL_RET_INVALID; - break; - } - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout timeout:%dms begin ...\n", - wait_ms); - wait_ret = wait_for_completion_interruptible_timeout(&g_disp_driver.dispcap_cmp, - msecs_to_jiffies(wait_ms)); - - mutex_lock(&g_disp_driver.dispcap_lock); - - setUserBuffer(NULL); - - if (NULL != context_ptr->dispcap_ion_handle) { - ion_unmap_kernel(g_disp_driver.ion_client, context_ptr->dispcap_ion_handle); - context_ptr->dispcap_ion_handle = NULL; - } - - mutex_unlock(&g_disp_driver.dispcap_lock); - - DISPCAP_LOGD("wait_for_completion_interruptible_timeout OK wait_ret:%d\n", - wait_ret); - - if (0 == wait_ret) { - ret = DISPCAP_CTL_RET_WAIT_TIMEOUT; - - } else if (0 < wait_ret) { - ret = DISPCAP_CTL_RET_SUCC; - - } else { - ret = DISPCAP_CTL_RET_INVALID; - } - } - break; - - default: { - DISPCAP_LOGE("unknown ioctl cmd:%d\n", cmd); - ret = DISPCAP_CTL_RET_INVALID; - } - break; - } - - return ret; -} - -static struct file_operations io_dev_fops = { - .owner = THIS_MODULE, - .open = driver_open, - .release = driver_release, - .unlocked_ioctl = driver_ioctl, -}; - -int __init dispcap_dev_init(void) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - return 0; -#else - int err = 0; - - DISPCAP_LOGD("start\n"); - - g_disp_driver.dev_class = NULL; - g_disp_driver.device = NULL; - g_disp_driver.dev_class = NULL; - g_disp_driver.ion_client = NULL; - g_disp_driver.dispcap_used = false; - mutex_init(&g_disp_driver.dispcap_lock); - - err = alloc_chrdev_region(&g_disp_driver.dev, 0, 1, "midas_dispcap"); - - if (err < 0) { - DISPCAP_LOGE("failed to alloc chrdev\n"); - goto fail; - } - - cdev_init(&g_disp_driver.cdev, &io_dev_fops); - - err = cdev_add(&g_disp_driver.cdev, g_disp_driver.dev, 1); - - if (err < 0) { - DISPCAP_LOGE("cdev_add g_disp_driver.cdev failed!\n"); - goto unreg_region; - } - - g_disp_driver.dev_class = class_create(THIS_MODULE, "midas_dispcap_class"); - - if (IS_ERR(g_disp_driver.dev_class)) { - DISPCAP_LOGE("create class g_disp_driver.dev_class error\n"); - goto destroy_cdev; - } - - g_disp_driver.device = device_create(g_disp_driver.dev_class, NULL, - g_disp_driver.dev, NULL, "midas_dispcap"); - - if (IS_ERR(g_disp_driver.device)) { - DISPCAP_LOGE("device_create g_disp_driver.device error\n"); - goto destroy_class; - } - - g_disp_driver.ion_client = ion_client_create(g_ion_device, - "dispcap_ion_client"); - - if (NULL == g_disp_driver.ion_client) { - DISPCAP_LOGE("ion_client_create g_disp_driver.ion_client failed\n"); - goto destroy_device; - } - - init_completion(&g_disp_driver.dispcap_cmp); - - return 0; - -destroy_device: - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - -destroy_class: - class_destroy(g_disp_driver.dev_class); - -destroy_cdev: - cdev_del(&g_disp_driver.cdev); - -unreg_region: - unregister_chrdev_region(g_disp_driver.dev, 1); - -fail: - return -1; -#endif -} - -void __exit dispcap_dev_exit(void) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#else - DISPCAP_LOGD("start\n"); - - if (NULL != g_disp_driver.ion_client) { - ion_client_destroy(g_disp_driver.ion_client); - g_disp_driver.ion_client = NULL; - } - - if (g_disp_driver.dev_class) { - device_destroy(g_disp_driver.dev_class, g_disp_driver.dev); - class_destroy(g_disp_driver.dev_class); - g_disp_driver.dev_class = NULL; - } - - cdev_del(&g_disp_driver.cdev); - - unregister_chrdev_region(g_disp_driver.dev, 1); -#endif -} - -#else /*#ifdef OPLUS_FEATURE_MIDAS*/ - -int __init dispcap_dev_init(void) -{ - return 0; -} - -void __exit dispcap_dev_exit(void) -{ - return; -} - -#endif /*#ifdef OPLUS_FEATURE_MIDAS*/ diff --git a/drivers/soc/oplus/system/oplus_midas/midas_proc.c b/drivers/soc/oplus/system/oplus_midas/midas_proc.c deleted file mode 100755 index 7bb43b2e14ac..000000000000 --- a/drivers/soc/oplus/system/oplus_midas/midas_proc.c +++ /dev/null @@ -1,341 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -extern int __init dispcap_dev_init(void); -extern void __exit dispcap_dev_exit(void); -extern int __init vpu_pw_off_latency_proc_init(void); -extern void __exit vpu_pw_off_latency_proc_exit(void); - -#define BUF_LEN 1024 - -static struct proc_dir_entry *g_midas_pentry; -static struct proc_dir_entry *g_midas_pname_pentry; -static struct midas_id_state *g_midas_data; -static char g_midas_pname[TASK_COMM_LEN]; -static DEFINE_SPINLOCK(midas_data_lock); -static DEFINE_SPINLOCK(midas_pname_lock); - -#define MAX_RASMEVENT_PARAM 4 -static char *rasm_env[MAX_RASMEVENT_PARAM]; - - -struct rasm_data { - long last_suspend_time; - long last_resume_time; -}; - -static int rasm_resume(struct device *dev) -{ - struct timeval resume_time; - struct rasm_data *data; - - data = dev->driver_data; - do_gettimeofday(&resume_time); - data->last_resume_time = resume_time.tv_sec; - dev_dbg(dev, "Now it is %ld, system will resume.", data->last_resume_time); - - rasm_env[0] = kasprintf(GFP_KERNEL, "NAME=rasm"); - rasm_env[1] = kasprintf(GFP_KERNEL, "suspend=%ld", data->last_suspend_time); - rasm_env[2] = kasprintf(GFP_KERNEL, "resume=%ld", data->last_resume_time); - rasm_env[3] = NULL; - - kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, rasm_env); - return 0; -} - -static int rasm_suspend(struct device *dev) -{ - struct timeval suspend_time; - struct rasm_data *data; - - data = dev->driver_data; - do_gettimeofday(&suspend_time); - data->last_suspend_time = suspend_time.tv_sec; - dev_dbg(dev, "Now it is %ld, system will suspend.", data->last_suspend_time); - return 0; -} - -static int rasm_probe(struct platform_device *pdev) -{ - struct rasm_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(struct rasm_data), GFP_KERNEL); - - if (data == NULL) { - dev_err(&pdev->dev, "devm_kzalloc failed!"); - return -1; - } - - dev_set_drvdata(&pdev->dev, data); - return 0; -} - -static int rasm_remove(struct platform_device *pdev) -{ - return 0; -} - -static const struct dev_pm_ops rasm_pm_ops = { - .suspend = rasm_suspend, - .resume = rasm_resume, -}; -static struct platform_device_id tbl[] = { - {"rasm"}, - {}, -}; -MODULE_DEVICE_TABLE(platform, tbl); - -struct of_device_id of_tbl[] = { - { .compatible = "oplus,rasm", }, - {}, -}; - -struct platform_device dev = { - .id = -1, - .name = "rasm", -}; - -static struct platform_driver drv = { - .probe = rasm_probe, - .remove = rasm_remove, - - .driver = { - .name = "rasm", - .of_match_table = of_tbl, - .pm = &rasm_pm_ops, - }, - - .id_table = tbl, -}; - -static int midas_proc_mmap(struct file *file, struct vm_area_struct *vma) -{ - if (remap_vmalloc_range(vma, g_midas_data, - vma->vm_pgoff)) { - pr_err("remap failed\n"); - return -EAGAIN; - } - - return 0; -} - -static ssize_t midas_proc_write(struct file *file, const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len, type; - char tmp[BUF_LEN + 1]; - unsigned long flags; - - if (cnt == 0) { - return 0; - } - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') { - tmp[len - 1] = '\0'; - - } else { - tmp[len] = '\0'; - } - - ret = sscanf(tmp, "%d", &type); - - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - - if (type >= TYPE_TOTAL || type < TYPE_UID) { - pr_err("write invalid para\n"); - return -EINVAL; - } - - spin_lock_irqsave(&midas_data_lock, flags); - - if (type == TYPE_UID) { - midas_get_uid_state(g_midas_data); - - } else { - midas_get_pid_state(g_midas_data, type); - } - - spin_unlock_irqrestore(&midas_data_lock, flags); - - return cnt; -} - -static ssize_t midas_proc_pname_write(struct file *file, const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len, pid; - char tmp[BUF_LEN + 1]; - struct task_struct *p; - unsigned long flags; - - if (cnt == 0) { - return 0; - } - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') { - tmp[len - 1] = '\0'; - - } else { - tmp[len] = '\0'; - } - - ret = sscanf(tmp, "%d", &pid); - - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - - spin_lock_irqsave(&midas_pname_lock, flags); - - p = find_task_by_vpid(pid); - - if (!IS_ERR_OR_NULL(p)) { - strncpy(g_midas_pname, p->comm, TASK_COMM_LEN); - } - - spin_unlock_irqrestore(&midas_pname_lock, flags); - - return cnt; -} - -static int midas_pname_proc_show(struct seq_file *m, void *v) -{ - seq_printf(m, "%s", g_midas_pname); - return 0; -} - -static int midas_proc_pname_open(struct inode *inode, struct file *file) -{ - return single_open(file, midas_pname_proc_show, NULL); -} - -static const struct file_operations proc_midas_fops = { - .write = midas_proc_write, - .mmap = midas_proc_mmap, -}; - -static const struct file_operations proc_midas_pname_fops = { - .open = midas_proc_pname_open, - .write = midas_proc_pname_write, - .read = seq_read, - .release = single_release, -}; - -static int __init midas_proc_init(void) -{ - int ret = 0; - - g_midas_pentry = proc_create("midas_time_in_state", - 0660, NULL, &proc_midas_fops); - - g_midas_pname_pentry = proc_create("midas_pname", - 0660, NULL, &proc_midas_pname_fops); - - g_midas_data = vmalloc_user(sizeof(struct midas_id_state)); - - if (IS_ERR_OR_NULL(g_midas_data)) { - pr_err("malloc failed!\n"); - ret = -ENOMEM; - goto err_malloc; - } - - ret = platform_device_register(&dev); - - if (ret < 0) { - dev_err(&dev.dev, "platform_device_register failed!"); - return ret; - } - - ret = platform_driver_register(&drv); - - if (ret < 0) { - dev_err(&dev.dev, "platform_driver_register!"); - goto err_register_driver; - } - - /*create dispcap dev*/ - if (dispcap_dev_init() < 0) { - ret = -ENOMEM; - goto err_malloc; - } - - /*create vpu pw_off_latency_proc*/ - if (vpu_pw_off_latency_proc_init() < 0) { - ret = -ENOMEM; - goto err_malloc; - } - - return 0; - -err_malloc: - proc_remove(g_midas_pname_pentry); - proc_remove(g_midas_pentry); - return ret; -err_register_driver: - platform_device_unregister(&dev); - return ret; -} - - -static void __exit midas_proc_exit(void) -{ - vpu_pw_off_latency_proc_exit(); - dispcap_dev_exit(); - - vfree(g_midas_data); - proc_remove(g_midas_pname_pentry); - proc_remove(g_midas_pentry); - platform_driver_unregister(&drv); - platform_device_unregister(&dev); -} - -module_init(midas_proc_init); -module_exit(midas_proc_exit); diff --git a/drivers/soc/oplus/system/oplus_midas/vpu_pw_off_latency_proc.c b/drivers/soc/oplus/system/oplus_midas/vpu_pw_off_latency_proc.c deleted file mode 100755 index 0c0237206f47..000000000000 --- a/drivers/soc/oplus/system/oplus_midas/vpu_pw_off_latency_proc.c +++ /dev/null @@ -1,125 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, __func__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef OPLUS_FEATURE_MIDAS - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -int set_all_vpu_power_off_latency(uint64_t pw_off_latency) -{ - return -1; -} -#else -/*import from MTK vpu driver*/ -extern int set_all_vpu_power_off_latency(uint64_t pw_off_latency); -#endif - -#define BUF_LEN 1024 - -static struct proc_dir_entry *g_vpu_pw_off_latency_pentry = NULL; - -static ssize_t vpu_pw_off_latency_proc_write(struct file *file, - const char __user *buf, - size_t cnt, loff_t *offset) -{ - int ret, len; - uint64_t latency_ms; - char tmp[BUF_LEN + 1]; - - if (cnt == 0) { - return 0; - } - - len = cnt > BUF_LEN ? BUF_LEN : cnt; - - ret = copy_from_user(tmp, buf, len); - - if (ret) { - pr_err("copy_from_user failed, ret=%d\n", ret); - return -EFAULT; - } - - if (tmp[len - 1] == '\n') { - tmp[len - 1] = '\0'; - - } else { - tmp[len] = '\0'; - } - - ret = sscanf(tmp, "%llu", &latency_ms); - - if (ret < 1) { - pr_err("write failed, ret=%d\n", ret); - return -EINVAL; - } - - pr_info("latency_ms cmd:%llu\n", latency_ms); - - set_all_vpu_power_off_latency(latency_ms); - - return cnt; -} - -static const struct file_operations vpu_pw_off_latency_proc_fops = { - .write = vpu_pw_off_latency_proc_write, -}; - -int __init vpu_pw_off_latency_proc_init(void) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#else - g_vpu_pw_off_latency_pentry = proc_create("all_vpu_pw_off_latency", - 0666, NULL, &vpu_pw_off_latency_proc_fops); -#endif - return 0; -} - - -void __exit vpu_pw_off_latency_proc_exit(void) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#else - - if (NULL != g_vpu_pw_off_latency_pentry) { - proc_remove(g_vpu_pw_off_latency_pentry); - g_vpu_pw_off_latency_pentry = NULL; - } - -#endif -} - -#else /*#ifdef OPLUS_FEATURE_MIDAS*/ - -int __init vpu_pw_off_latency_proc_init(void) -{ - return 0; -} - -void __exit vpu_pw_off_latency_proc_exit(void) -{ -} - -#endif /*#ifdef OPLUS_FEATURE_MIDAS*/ diff --git a/drivers/soc/oplus/system/oplus_mm_fb/Kconfig b/drivers/soc/oplus/system/oplus_mm_fb/Kconfig deleted file mode 100755 index f62c78039f0c..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -config OPLUS_FEATURE_MM_FEEDBACK - tristate "Oplus multimedia kevent feedback" - default n - help - define this config to init oplus multimedia kevent feedback driver diff --git a/drivers/soc/oplus/system/oplus_mm_fb/Makefile b/drivers/soc/oplus/system/oplus_mm_fb/Makefile deleted file mode 100755 index 203a401641d0..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -obj-$(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) += oplus_mm_kevent.o -obj-$(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) += oplus_mm_kevent_fb.o diff --git a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_fb_netlink.h b/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_fb_netlink.h deleted file mode 100755 index 865ccd6cf68a..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_fb_netlink.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/************************************************************** -* Copyright (c) 2008- 2030 OPLUS Mobile communication Corp.ltd All rights reserved. -* -* File : oplus_mm_fb_netlink.h -* Description : For oplus_mm_fb_netlink -* Version : 1.0 -* Date : 2020-11-24 -* Author : -* TAG : -****************************************************************/ -#ifndef _OPLUS_MM_NETLINK_H -#define _OPLUS_MM_NETLINK_H - -#define OPLUS_MM_MSG_TO_KERNEL_BUF_LEN 256 -#define OPLUS_MM_MSG_FROM_KERNEL_BUF_LEN (1024) - - -#define OPLUS_MM_PROTOCAL_NAME "mm_fb" -#define OPLUS_MM_GENL_VERSION 0x01 -#define OPLUS_MM_PROTOCAL_NAME_MAX_LEN 100 - -enum { - MM_FB_CMD_ATTR_UNSPEC = 0, - MM_FB_CMD_ATTR_MSG, - MM_FB_CMD_ATTR_OPT, - __MM_FB_CMD_ATTR_MAX, -}; - -#define MM_FB_CMD_ATTR_MAX (__MM_FB_CMD_ATTR_MAX - 1) - -enum { - MM_FB_CMD_GENL_UNSPEC = 0, - MM_FB_CMD_GENL_SEND_MODULE, - MM_FB_CMD_GENL_UPLOAD, - MM_FB_CMD_GENL_TEST_UPLOAD, -}; - - -struct msg_to_kernel { - struct nlmsghdr n_hd; - struct genlmsghdr g_hd; - char buf[OPLUS_MM_MSG_TO_KERNEL_BUF_LEN]; -}; - -struct msg_from_kernel { - struct nlmsghdr n_hd; - struct genlmsghdr g_hd; - char buf[OPLUS_MM_MSG_FROM_KERNEL_BUF_LEN]; -}; - -#endif /*_OPLUS_MM_NETLINK_H*/ diff --git a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.c b/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.c deleted file mode 100755 index a996cd098bf9..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.c +++ /dev/null @@ -1,343 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "oplus_mm_kevent.h" - -#include -#include "oplus_mm_fb_netlink.h" - -static struct mm_kevent_module mm_modules[MM_KEVENT_MODULE_SIZE_MAX]; -static volatile bool mm_kevent_init_flag = false; -static spinlock_t mm_slock; -static mm_kevent_recv_user_func mm_fb_kevent_recv_fb = NULL; - -/* record connect pid and modules*/ -void mm_fb_kevent_add_module(u32 pid, char *module) -{ - int i = 0x0; - int len = 0x0; - - if (!module) { - return; - } - - len = strlen(module); - - if (len > (MM_KEVENT_MODULE_LEN_MAX - 1)) { - pr_err("mm_kevent: module len is larger than %d error\n", - MM_KEVENT_MODULE_LEN_MAX); - return; - } - - for (i = 0; i < MM_KEVENT_MODULE_SIZE_MAX; i++) { - if ((!mm_modules[i].pid) || (!strcmp(mm_modules[i].modl, module))) { - spin_lock(&mm_slock); - mm_modules[i].pid = pid; - memcpy(mm_modules[i].modl, module, len); - mm_modules[i].modl[len] = 0x0; - spin_unlock(&mm_slock); - return; - } - } - - return; -} - -/* record connect pid and modules*/ -int mm_fb_kevent_get_pid(char *module) -{ - int i = 0; - - if (!module) { - return MM_KEVENT_BAD_VALUE; - } - - for (i = 0; i < MM_KEVENT_MODULE_SIZE_MAX; i++) { - if (!strcmp(mm_modules[i].modl, module)) { - return mm_modules[i].pid; - } - } - - return MM_KEVENT_BAD_VALUE; -} - -static int mm_fb_kevent_send_module(struct sk_buff *skb, - struct genl_info *info) -{ - struct sk_buff *skbu = NULL; - struct nlmsghdr *nlh; - struct nlattr *na = NULL; - char *pmesg = NULL; - - pr_info("mm_kevent: mm_fb_kevent_send_module enter\n"); - - if (!mm_kevent_init_flag) { - pr_err("%s: mm_kevent: not init error\n", __func__); - return -1; - } - - skbu = skb_get(skb); - - if (!skbu) { - pr_err("mm_kevent: skb_get result is null error\n"); - return -1; - } - - if (info->attrs[MM_FB_CMD_ATTR_MSG]) { - na = info->attrs[MM_FB_CMD_ATTR_MSG]; - nlh = nlmsg_hdr(skbu); - pmesg = (char *)kmalloc(nla_len(na) + 0x10, GFP_KERNEL); - - if (pmesg) { - memcpy(pmesg, nla_data(na), nla_len(na)); - pmesg[nla_len(na)] = 0x0; - pr_info("mm_kevent: nla_len(na) %d, pid %d, module: %s\n", - nla_len(na), nlh->nlmsg_pid, pmesg); - mm_fb_kevent_add_module(nlh->nlmsg_pid, pmesg); - } - } - - if (pmesg) { - kfree(pmesg); - } - - if (skbu) { - kfree_skb(skbu); - } - - return 0; -} - -void mm_fb_kevent_set_recv_user(mm_kevent_recv_user_func recv_func) -{ - mm_fb_kevent_recv_fb = recv_func; -} - -EXPORT_SYMBOL(mm_fb_kevent_set_recv_user); - -static int mm_fb_kevent_test_upload(struct sk_buff *skb, - struct genl_info *info) -{ - struct sk_buff *skbu = NULL; - struct nlattr *na = NULL; - char *pmesg = NULL; - - pr_info("mm_kevent: mm_fb_kevent_test_upload enter\n"); - - if (!mm_kevent_init_flag) { - pr_err("%s: mm_kevent: not init error\n", __func__); - return -1; - } - - skbu = skb_get(skb); - - if (!skbu) { - pr_err("mm_kevent: skb_get result is null error\n"); - return -1; - } - - if (info->attrs[MM_FB_CMD_ATTR_MSG]) { - na = info->attrs[MM_FB_CMD_ATTR_MSG]; - pr_info("mm_kevent: nla_len(na) is %d, data= %s\n", nla_len(na), - (char *)nla_data(na)); - - if (nla_len(na) > OPLUS_MM_MSG_TO_KERNEL_BUF_LEN) { - pr_err("mm_kevent: message len %d too long error\n", nla_len(na)); - return -1; - } - - pmesg = (char *)kmalloc(nla_len(na) + 0x10, GFP_KERNEL); - - if (!pmesg) { - pr_err("mm_kevent: kmalloc return null error\n"); - return -1; - } - - memcpy(pmesg, nla_data(na), nla_len(na)); - pmesg[nla_len(na)] = 0x0; - - if (mm_fb_kevent_recv_fb) { - mm_fb_kevent_recv_fb(0, OPLUS_NETLINK_MM_DBG_LV2, pmesg); - } - - if (pmesg) { - kfree(pmesg); - } - } - - if (skbu) { - kfree_skb(skbu); - } - - return 0; -} - - -#define MM_FB_FAMILY_VERSION 1 -#define MM_FB_FAMILY "mm_fb" -#define GENL_ID_GENERATE 0 - -static const struct genl_ops mm_fb_genl_ops[] = { - { - .cmd = MM_FB_CMD_GENL_SEND_MODULE, - .doit = mm_fb_kevent_send_module, - }, - { - .cmd = MM_FB_CMD_GENL_TEST_UPLOAD, - .doit = mm_fb_kevent_test_upload, - }, -}; - -static struct genl_family mm_fb_genl_family __ro_after_init = { - .id = GENL_ID_GENERATE, - .name = MM_FB_FAMILY, - .version = MM_FB_FAMILY_VERSION, - .maxattr = MM_FB_CMD_ATTR_MAX, - .module = THIS_MODULE, - .ops = mm_fb_genl_ops, - .n_ops = ARRAY_SIZE(mm_fb_genl_ops), -}; - -static inline int genl_msg_prepare_usr_msg(unsigned char cmd, size_t size, - pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_KERNEL); - - if (skb == NULL) { - pr_err("mm_kevent: genlmsg_new failed\n"); - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &mm_fb_genl_family, 0, cmd); - - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, - int len) -{ - int ret = 0; - - /* add a netlink attribute to a socket buffer */ - ret = nla_put(skb, type, len, data); - - return ret; -} - -/* send to user space */ -int mm_fb_kevent_send_to_user(struct mm_kevent_packet *userinfo) -{ - int ret; - int size_use; - struct sk_buff *skbuff; - void *head; - int pid; - - if (!mm_kevent_init_flag) { - pr_err("%s: mm_kevent: not init error\n", __func__); - return MM_KEVENT_BAD_VALUE; - } - - /* protect payload too long problem*/ - if (userinfo->len >= MAX_PAYLOAD_DATASIZE) { - pr_err("mm_kevent: payload_length out of range error\n"); - return MM_KEVENT_BAD_VALUE; - } - - pid = mm_fb_kevent_get_pid(userinfo->tag); - - if (pid == MM_KEVENT_BAD_VALUE) { - pr_err("mm_kevent: tag=%s get pid error\n", userinfo->tag); - return MM_KEVENT_BAD_VALUE; - } - - size_use = sizeof(struct mm_kevent_packet) + userinfo->len; - ret = genl_msg_prepare_usr_msg(MM_FB_CMD_GENL_UPLOAD, size_use, pid, &skbuff); - - if (ret) { - pr_err("mm_kevent: genl_msg_prepare_usr_msg error, ret is %d \n", ret); - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, MM_FB_CMD_ATTR_MSG, userinfo, size_use); - - if (ret) { - pr_err("mm_kevent: genl_msg_mk_usr_msg error, ret is %d \n", ret); - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - ret = genlmsg_unicast(&init_net, skbuff, pid); - - if (ret < 0) { - pr_err("mm_kevent: genlmsg_unicast fail=%d \n", ret); - return MM_KEVENT_BAD_VALUE; - } - - return MM_KEVENT_NO_ERROR; -} -EXPORT_SYMBOL(mm_fb_kevent_send_to_user); - -int __init mm_fb_kevent_module_init(void) -{ - int ret; - ret = genl_register_family(&mm_fb_genl_family); - - if (ret) { - pr_err("mm_kevent: genl_register_family:%s error,ret = %d\n", MM_FB_FAMILY, - ret); - return ret; - - } else { - pr_info("mm_kevent: genl_register_family complete, id = %d!\n", - mm_fb_genl_family.id); - } - - spin_lock_init(&mm_slock); - memset(mm_modules, 0x0, sizeof(mm_modules)); - mm_kevent_init_flag = true; - - pr_info("mm_kevent: init ok\n"); - return MM_KEVENT_NO_ERROR; -} - -void __exit mm_fb_kevent_module_exit(void) -{ - genl_unregister_family(&mm_fb_genl_family); - mm_kevent_init_flag = false; - pr_info("mm_kevent: exit\n"); -} - -module_init(mm_fb_kevent_module_init); -module_exit(mm_fb_kevent_module_exit); - -MODULE_DESCRIPTION("mm_kevent@1.0"); -MODULE_VERSION("1.0"); -MODULE_LICENSE("GPL v2"); - diff --git a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.h b/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.h deleted file mode 100755 index 8016e4bf3f61..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent.h +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * oplus_kevent.h - for kevent action upload upload to user layer - * author by pdl - */ -#ifndef _OPLUS_MM_KEVENT_ -#define _OPLUS_MM_KEVENT_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_PAYLOAD_TAG (128) -#define MAX_PAYLOAD_EVENTID (128) -#define MAX_PAYLOAD_DATASIZE (512) - -#define MM_KEVENT_MODULE_SIZE_MAX (16) -#define MM_KEVENT_MODULE_LEN_MAX (64) - -#define MM_KEVENT_BAD_VALUE (-1) -#define MM_KEVENT_NO_ERROR (0) - -#define OPLUS_NETLINK_MM_DBG_LV1 0x1 -#define OPLUS_NETLINK_MM_DBG_LV2 0x2 - -#define DP_FB_EVENT "mm_kevent_dp" -#define ATLAS_FB_EVENT "mm_kevent_atlas" - -enum mm_kevent_type { - MM_KEVENT_NOME = 0x0, - MM_KEVENT_CONNECT, -}; - -struct mm_kevent_module { - u32 pid; - char modl[MM_KEVENT_MODULE_LEN_MAX]; -}; - -typedef void (*mm_kevent_recv_user_func)(int type, int flags, char *data); - -struct mm_kevent_packet { - int type; /* 0:warrning,1:error,2:hw error*/ - char tag[MAX_PAYLOAD_TAG]; /* logTag */ - char event_id[MAX_PAYLOAD_EVENTID]; /* eventID */ - size_t len; /* Length of packet data */ - unsigned char data[0]; /* Optional packet data */ -} __attribute__((packed)); - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -int mm_fb_kevent_send_to_user(struct mm_kevent_packet *userinfo); -void mm_fb_kevent_set_recv_user(mm_kevent_recv_user_func recv_func); -#else /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ -int mm_fb_kevent_send_to_user(struct mm_kevent_packet *userinfo) -{ - return 0; -} -void mm_fb_kevent_set_recv_user(mm_kevent_recv_user_func recv_func) -{ - return; -} -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ -#endif /*_OPLUS_MM_KEVENT_*/ - diff --git a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent_fb.c b/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent_fb.c deleted file mode 100755 index 061d93bb5c60..000000000000 --- a/drivers/soc/oplus/system/oplus_mm_fb/oplus_mm_kevent_fb.c +++ /dev/null @@ -1,573 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include "oplus_mm_kevent.h" -#include - -static void mm_fb_kevent_upload_jobs(struct work_struct *work); - -static LIST_HEAD(mm_kevent_list); -static DEFINE_MUTEX(mm_kevent_lock); -static DECLARE_DELAYED_WORK(mm_kevent_upload_work_thread, - mm_fb_kevent_upload_jobs); -static struct workqueue_struct *mm_kevent_wq = NULL; -static int mm_kevent_len = 0; -static bool mm_fb_init = false; -#define CAUSENAME_SIZE 128 -static char fid[CAUSENAME_SIZE] = {"12345678"}; - -#define LIMIT_UPLOAD_TIME_MS 10000 /*ms*/ -struct limit_upload_frq { - unsigned int last_id; - ktime_t last_time; -}; -static struct limit_upload_frq g_limit; - -struct mm_kevent { - struct list_head head; - enum OPLUS_MM_DIRVER_FB_EVENT_MODULE module; - unsigned int event_id; - struct mutex lock; - int count; - int count_total; - u32 count_limit; - int rate_limit_ms; - ktime_t first; - ktime_t last; - ktime_t last_upload; - struct delayed_work dwork; - char *payload; - char name[0]; -}; - -static unsigned int BKDRHash(char *str, unsigned int len) -{ - unsigned int seed = 131; /* 31 131 1313 13131 131313 etc.. */ - unsigned int hash = 0; - unsigned int i = 0; - - if (str == NULL) { - return 0; - } - - for (i = 0; i < len; str++, i++) { - hash = (hash * seed) + (*str); - } - - return hash; -} - -static void calc_fid(unsigned char *str) -{ - char strHashSource[MAX_PAYLOAD_DATASIZE] = {0x00}; - unsigned int hashid = 0; - /*struct timespec64 ts64;*/ - unsigned long rdm = 0; - ktime_t t; - - t = ktime_get(); - /*get_random_bytes(&rdm, sizeof(unsigned long));*/ - rdm = get_random_u64(); - snprintf(strHashSource, MAX_PAYLOAD_DATASIZE, "%lu %lu %s", rdm, t, str); - hashid = BKDRHash(strHashSource, strlen(strHashSource)); - memset(fid, 0 , CAUSENAME_SIZE); - snprintf(fid, CAUSENAME_SIZE, "%u", hashid); - printk(KERN_INFO "calc_fid: fid=%u\n", hashid); -} - -static int upload_mm_fb_kevent(unsigned int event_id, unsigned char *payload) -{ - struct mm_kevent_packet *user_msg_info; - char event_id_str[MAX_PAYLOAD_EVENTID] = {0}; - void *buffer = NULL; - int len, size; - int ret = 0; - - printk(KERN_INFO "%s: mm_kevent fb: enter, event_id = %d\n", __func__, - event_id); - - mutex_lock(&mm_kevent_lock); - len = strlen(payload); - - if (len > MAX_PAYLOAD_DATASIZE) { - printk(KERN_INFO "%s: error: payload len=%d > %d\n", - __func__, len, MAX_PAYLOAD_DATASIZE); - ret = -1; - goto _exit; - } - - size = sizeof(struct mm_kevent_packet) + len + 1; - - buffer = kmalloc(size, GFP_ATOMIC); - - if (!buffer) { - printk(KERN_INFO "%s: kmalloc %d bytes failed\n", __func__, size); - ret = -1; - goto _exit; - } - - memset(buffer, 0, size); - user_msg_info = (struct mm_kevent_packet *)buffer; - user_msg_info->type = 1; - - memcpy(user_msg_info->tag, ATLAS_FB_EVENT, sizeof(ATLAS_FB_EVENT)); - - snprintf(event_id_str, sizeof(event_id_str) - 1, "%d", event_id); - memcpy(user_msg_info->event_id, event_id_str, strlen(event_id_str)); - - user_msg_info->len = len + 1; - memcpy(user_msg_info->data, payload, len + 1); - - mm_fb_kevent_send_to_user(user_msg_info); - - kfree(buffer); - -_exit: - mutex_unlock(&mm_kevent_lock); - return ret; -} - - -static void mm_fb_kevent_upload_work(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - struct mm_kevent *new_kevent = container_of(dwork, struct mm_kevent, dwork); - struct mm_kevent *kevent = NULL, *n = NULL; - bool found = false; - int cnt = 0; - - list_for_each_entry_safe(kevent, n, &mm_kevent_list, head) { - if (!strcmp(kevent->name, new_kevent->name)) { - found = true; - break; - } - } - - if (!found) { - if (mm_kevent_len > 200) { - unsigned char payload[MM_KEVENT_MAX_PAYLOAD_SIZE] = ""; - pr_err("mm_kevent large than 200"); - - if (OPLUS_MM_DIRVER_FB_EVENT_AUDIO == new_kevent->module) { -#define PAYLOAD(fmt, ...) \ - if (sizeof(payload) > cnt) \ - cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, fmt, ##__VA_ARGS__); - PAYLOAD("func@@%s$$", new_kevent->name); - PAYLOAD("%s", new_kevent->payload ? new_kevent->payload : "NULL"); - - } else { - scnprintf(payload, sizeof(payload), "MSG@@%s", new_kevent->name); - } - - upload_mm_fb_kevent(new_kevent->event_id, payload); - goto done; - } - - kevent = new_kevent; - kevent->count = 1; - kevent->count_total = 1; - new_kevent = NULL; - mm_kevent_len++; - list_add_tail(&kevent->head, &mm_kevent_list); - goto done; - } - - if (WARN_ON(!kevent)) { - goto done; - } - - mutex_lock(&kevent->lock); - kevent->count++; - kevent->count_total++; - kevent->last = new_kevent->first; - kfree(kevent->payload); - kevent->payload = new_kevent->payload; - new_kevent->payload = NULL; - mutex_unlock(&kevent->lock); -done: - mm_fb_kevent_upload_jobs(NULL); - - if (new_kevent) { - kfree(new_kevent->payload); - } - - kfree(new_kevent); -} - -static void mm_fb_kevent_upload_jobs(struct work_struct *work) -{ - struct mm_kevent *kevent = NULL, *n = NULL; - unsigned char payload[MM_KEVENT_MAX_PAYLOAD_SIZE] = ""; - int cnt; - - list_for_each_entry_safe(kevent, n, &mm_kevent_list, head) { - if (ktime_before(kevent->last, kevent->last_upload)) { - continue; - } - - if (kevent->count_limit && (kevent->count_total % kevent->count_limit == 0)) { - kevent->count_limit <<= 1; - - if (kevent->count_limit > 4096) { - kevent->count_limit = 4096; - } - - } else if (!kevent->rate_limit_ms || (kevent->rate_limit_ms && - ktime_before(ktime_get(), ktime_add_ms(kevent->last_upload, - kevent->rate_limit_ms)))) { - continue; - } - - mutex_lock(&kevent->lock); - cnt = 0; -#define PAYLOAD(fmt, ...) \ - if (sizeof(payload) > cnt) \ - cnt += scnprintf(payload + cnt, sizeof(payload) - cnt, fmt, ##__VA_ARGS__); - - if (OPLUS_MM_DIRVER_FB_EVENT_AUDIO == kevent->module) { - PAYLOAD("func@@%s$$", kevent->name); - PAYLOAD("CT@@%d$$", kevent->count); - PAYLOAD("%s", kevent->payload ? kevent->payload : "NULL"); - - } else { - PAYLOAD("EventName@@%s$$", kevent->name); - PAYLOAD("CT@@%d$$", kevent->count); - PAYLOAD("FT@@%lu$$", ktime_to_ms(kevent->first) / 1000); - PAYLOAD("ET@@%lu$$", ktime_to_ms(kevent->last) / 1000); - PAYLOAD("MSG@@%s", kevent->payload ? kevent->payload : "NULL"); - } - - if (kevent->payload) { - kfree(kevent->payload); - kevent->payload = NULL; - } - - kevent->count = 0; - kevent->last_upload = ktime_get(); - mutex_unlock(&kevent->lock); - upload_mm_fb_kevent(kevent->event_id, payload); - } - - if (mm_kevent_wq) { - mod_delayed_work(mm_kevent_wq, &mm_kevent_upload_work_thread, 60 * 60 * HZ); - } -} - -static void mm_fb_kevent_upload_recv_user(int type, int flags, char *data) { - printk(KERN_INFO "mm_kevent fb recv user type=0x%x, flags=0x%x, data=%s\n", - type, flags, data); - #ifdef OPLUS_NETLINK_MM_KEVENT_TEST - if (flags & OPLUS_NETLINK_MM_DBG_LV2) { - upload_mm_fb_kevent(OPLUS_MM_EVENTID_TEST_OR_DEBUG, data); - } - #endif -} - -/* queue a delaywork to upload the feedback info, can used in interrupt function or timeliness requirement place*/ -int upload_mm_fb_kevent_limit(enum OPLUS_MM_DIRVER_FB_EVENT_MODULE module, - unsigned int event_id, - const char *name, int rate_limit_ms, char *payload) -{ - struct mm_kevent *kevent = NULL; - int size; - char buf[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; - - if (!mm_fb_init || !mm_kevent_wq) { - pr_err("%s: error: not init or mm_kevent_wq is null\n", __func__); - return -EINVAL; - } - - size = strlen(name) + sizeof(*kevent) + 1; - kevent = kzalloc(size, GFP_ATOMIC); - - if (!kevent) { - return -ENOMEM; - } - - kevent->module = module; - kevent->event_id = event_id; - kevent->count_limit = 1; - kevent->last_upload = ktime_get(); - kevent->first = ktime_get(); - kevent->last = ktime_get(); - kevent->rate_limit_ms = rate_limit_ms; - memcpy(kevent->name, name, strlen(name) + 1); - - if (OPLUS_AUDIO_EVENTID_ADSP_CRASH == event_id) { - calc_fid(payload); - scnprintf(buf, MM_KEVENT_MAX_PAYLOAD_SIZE, "EventField@@%s$$%s", - fid, payload ? payload : "NULL"); - kevent->payload = kmemdup(buf, strlen(buf) + 1, GFP_ATOMIC); - - } else { - kevent->payload = kmemdup(payload, strlen(payload) + 1, GFP_ATOMIC); - } - - mutex_init(&kevent->lock); - INIT_DELAYED_WORK(&kevent->dwork, mm_fb_kevent_upload_work); - queue_delayed_work(mm_kevent_wq, &kevent->dwork, 0); - printk(KERN_INFO "%s:event_id=%d,payload:%s\n", __func__, event_id, payload); - - return 0; -} -EXPORT_SYMBOL(upload_mm_fb_kevent_limit); - -/* upload the feedback info immediately, can't used in interrupt function */ -int upload_mm_fb_kevent_to_atlas_limit(unsigned int event_id, - unsigned char *payload, int limit_ms) -{ - struct mm_kevent_packet *user_msg_info; - char event_id_str[MAX_PAYLOAD_EVENTID] = {0}; - void *buffer = NULL; - int len, size; - int ret = 0; - - printk(KERN_INFO "mm_kevent fb:upload_mm_fb_kevent_to_atlas_limit enter\n"); - - if (!mm_fb_init) { - pr_err("%s: error, module not init\n", __func__); - return -EINVAL; - } - - mutex_lock(&mm_kevent_lock); - - if ((limit_ms > 0) && (g_limit.last_id == event_id)) { - if (ktime_before(ktime_get(), ktime_add_ms(g_limit.last_time, limit_ms))) { - printk(KERN_INFO "upload event_id=%d failed, report too often, limit_ms=%d\n", - event_id, limit_ms); - ret = -1; - goto _exit; - } - } - - len = strlen(payload); - - if (len > MAX_PAYLOAD_DATASIZE) { - printk(KERN_INFO "error: payload len=%d > %d\n", len, MAX_PAYLOAD_DATASIZE); - ret = -1; - goto _exit; - } - - size = sizeof(struct mm_kevent_packet) + len + 1; - buffer = kmalloc(size, GFP_ATOMIC); - - if (!buffer) { - printk(KERN_INFO "%s: kmalloc %d bytes failed\n", __func__, size); - ret = -1; - goto _exit; - } - - memset(buffer, 0, size); - user_msg_info = (struct mm_kevent_packet *)buffer; - user_msg_info->type = 1; - - memcpy(user_msg_info->tag, ATLAS_FB_EVENT, strlen(ATLAS_FB_EVENT)); - - snprintf(event_id_str, sizeof(event_id_str) - 1, "%d", event_id); - memcpy(user_msg_info->event_id, event_id_str, strlen(event_id_str)); - - user_msg_info->len = len + 1; - memcpy(user_msg_info->data, payload, len + 1); - - pr_info("%s: mm_kevent: type %d, tag=%s, event_id=%s, len=%zu, payload=%s\n", - __func__, - user_msg_info->type, user_msg_info->tag, user_msg_info->event_id, - user_msg_info->len, user_msg_info->data); - mm_fb_kevent_send_to_user(user_msg_info); - /*msleep(20);*/ - kfree(buffer); - g_limit.last_id = event_id; - g_limit.last_time = ktime_get(); - -_exit: - mutex_unlock(&mm_kevent_lock); - return ret; -} -EXPORT_SYMBOL(upload_mm_fb_kevent_to_atlas_limit); - -#define MM_FB_EVENTID_LEN 5 -#define MM_FB_HAL_LIMIT (60*1000) -#define IS_DIGITAL(x) (((x) >= '0') && ((x) <= '9')) -static ssize_t mm_fb_write(struct file *file, - const char __user *buf, - size_t count, - loff_t *lo) -{ - char *r_buf; - unsigned int event_id = 0; - int len, i; - - if (!mm_fb_init) { - pr_err("%s: error, module not init\n", __func__); - return -EINVAL; - } - - r_buf = (char *)kzalloc(MAX_PAYLOAD_DATASIZE, GFP_KERNEL); - - if (!r_buf) { - return count; - } - - if (copy_from_user(r_buf, buf, - MAX_PAYLOAD_DATASIZE > count ? count : MAX_PAYLOAD_DATASIZE)) { - goto exit; - } - - r_buf[MAX_PAYLOAD_DATASIZE - 1] = '\0'; /*make sure last bype is eof*/ - len = strlen(r_buf); - printk(KERN_INFO "%s: mm_kevent fb len=%d, data=%s\n", __func__, len, r_buf); - - if (len < (MM_FB_EVENTID_LEN + 2)) { - printk(KERN_INFO "%s: mm_kevent fb data len=%d is error\n", __func__, len); - goto exit; - } - - for (i = 0; i < MM_FB_EVENTID_LEN; i++) { - if (IS_DIGITAL(r_buf[i])) { - event_id = event_id * 10 + r_buf[i] - '0'; - - } else { - printk(KERN_INFO "%s: mm_kevent fb eventid is error, data=%s\n", __func__, - r_buf); - goto exit; - } - } - - upload_mm_fb_kevent_to_atlas_limit(event_id, r_buf + MM_FB_EVENTID_LEN + 1, - MM_FB_HAL_LIMIT); - -exit: - kfree(r_buf); - return count; -} - -static ssize_t mm_fb_read(struct file *file, - char __user *buf, - size_t count, - loff_t *ppos) -{ - if (!mm_fb_init) { - pr_err("%s: error, module not init\n", __func__); - return -EINVAL; - } - - return count; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static const struct proc_ops mm_fb_fops = { - .proc_write = mm_fb_write, - .proc_read = mm_fb_read, - .proc_open = simple_open, -}; -#else -static const struct file_operations mm_fb_fops = { - .write = mm_fb_write, - .read = mm_fb_read, - .open = simple_open, - .owner = THIS_MODULE, -}; -#endif - -static ssize_t adsp_crash_cause_read(struct file *file, - char __user *buf, - size_t count, - loff_t *off) -{ - char page[CAUSENAME_SIZE] = {0x00}; - int len = 0; - - len = snprintf(page, sizeof(page) - 1, "%s", fid); - len = simple_read_from_buffer(buf, count, off, page, strlen(page)); - return len; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static const struct proc_ops adsp_crash_cause_fops = { - .proc_read = adsp_crash_cause_read, - .proc_open = simple_open, -}; -#else -static const struct file_operations adsp_crash_cause_fops = { - .read = adsp_crash_cause_read, - .open = simple_open, - .owner = THIS_MODULE, -}; -#endif - -int mm_fb_kevent_init(void) -{ - struct proc_dir_entry *d_entry = NULL; - int ret = 0; - - mm_kevent_wq = create_workqueue("mm_kevent"); - - if (!mm_kevent_wq) { - ret = -ENOMEM; - goto failed_create_workqueue; - } - - queue_delayed_work(mm_kevent_wq, &mm_kevent_upload_work_thread, 0); - - mm_fb_kevent_set_recv_user(mm_fb_kevent_upload_recv_user); - - g_limit.last_id = 0xFFFFFFFF; - g_limit.last_time = 0; - - d_entry = proc_create_data("mm_fb", 0664, NULL, &mm_fb_fops, NULL); - - if (!d_entry) { - pr_err("%s: failed to create node\n", __func__); - ret = -ENODEV; - goto failed_proc_create_data; - } - - d_entry = proc_create_data("adsp_crash_cause", 0664, NULL, - &adsp_crash_cause_fops, NULL); - - if (!d_entry) { - pr_err("failed to adsp_crash_cause node\n"); - ret = -ENODEV; - goto failed_proc_create_data; - } - - mm_fb_init = true; - pr_info("%s: init success\n", __func__); - - return 0; - -failed_proc_create_data: - if (mm_kevent_wq) { - destroy_workqueue(mm_kevent_wq); - mm_kevent_wq = NULL; - } -failed_create_workqueue: - return ret; -} - -void mm_fb_kevent_deinit(void) -{ - if (mm_kevent_wq) { - destroy_workqueue(mm_kevent_wq); - mm_kevent_wq = NULL; - } - - mm_fb_kevent_set_recv_user(NULL); - mm_fb_init = false; - pr_info("%s: deinit\n", __func__); -} - - -module_init(mm_fb_kevent_init); -module_exit(mm_fb_kevent_deinit); - -MODULE_LICENSE("GPL v2"); - diff --git a/drivers/soc/oplus/system/oplus_phoenix/Kconfig b/drivers/soc/oplus/system/oplus_phoenix/Kconfig deleted file mode 100755 index a6e805b4a3a0..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/15, Add for PHOENIX_PROJECT -#change 'y' to 'n', if you want fo close phoenix feature -config OPLUS_FEATURE_PHOENIX - tristate "oplus phoenix project" - default n - help - define this config to init oplus phoenix project. diff --git a/drivers/soc/oplus/system/oplus_phoenix/Makefile b/drivers/soc/oplus/system/oplus_phoenix/Makefile deleted file mode 100755 index 79e90d283cc9..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/15, Add for PHOENIX_PROJECT -ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += op_bootprof.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_base.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_dump.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_watchdog.o -else -ifeq ($(CONFIG_OPLUS_FEATURE_PHOENIX), y) -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += op_bootprof.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_base.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_dump.o -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += phoenix_watchdog.o -endif -ifeq ($(CONFIG_OPLUS_FEATURE_PHOENIX), m) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include -obj-$(CONFIG_OPLUS_FEATURE_PHOENIX) += oplus_phoenix.o -oplus_phoenix-y := gki/op_bootprof.o gki/phoenix_base.o gki/phoenix_dump.o gki/phoenix_watchdog.o -endif -endif diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/Kconfig b/drivers/soc/oplus/system/oplus_phoenix/gki/Kconfig deleted file mode 100755 index a6e805b4a3a0..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/15, Add for PHOENIX_PROJECT -#change 'y' to 'n', if you want fo close phoenix feature -config OPLUS_FEATURE_PHOENIX - tristate "oplus phoenix project" - default n - help - define this config to init oplus phoenix project. diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.c b/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.c deleted file mode 100755 index 3ece17ed0b93..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.c +++ /dev/null @@ -1,249 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/*============================================================================= - - INCLUDE FILES FOR MODULE - -=============================================================================*/ -#include "op_bootprof.h" -#include "oplus_phoenix.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BOOT_STR_SIZE 256 -#define BOOT_LOG_NUM 192 -//#define TRACK_TASK_COMM -#define BOOT_FROM_SIZE 16 - -extern unsigned long long notrace sched_clock(void); - -struct boot_log_struct { - /* task cmdline for first 16 bytes -* and boot event for the rest -* if TRACK_TASK_COMM is on */ - char *comm_event; -#ifdef TRACK_TASK_COMM - pid_t pid; -#endif - u64 timestamp; -} op_bootprof[BOOT_LOG_NUM]; - -static int boot_log_count; -static DEFINE_MUTEX(op_bootprof_lock); -static bool op_bootprof_enabled; -static int boot_finish = 0; -char boot_from[BOOT_FROM_SIZE] = { '\0' }; - -#define MSG_SIZE 128 - -/* - * Ease the printing of nsec fields: -*/ - -static long long nsec_high(unsigned long long nsec) -{ - if ((long long)nsec < 0) { - nsec = -nsec; - do_div(nsec, 1000000); - return -nsec; - } - do_div(nsec, 1000000); - - return nsec; -} - -static unsigned long nsec_low(unsigned long long nsec) -{ - if ((long long)nsec < 0) { - nsec = -nsec; - } - - return do_div(nsec, 1000000); -} - -void op_log_boot(const char *str) -{ - unsigned long long ts; - struct boot_log_struct *p = &op_bootprof[boot_log_count]; - size_t n = strlen(str) + 1; - - if (!op_bootprof_enabled) { - return; - } - ts = sched_clock(); - if (boot_log_count >= BOOT_LOG_NUM) { - pr_err("[BOOTPROF] not enuough bootprof buffer\n"); - return; - } - mutex_lock(&op_bootprof_lock); - p->timestamp = ts; -#ifdef TRACK_TASK_COMM - p->pid = current->pid; - n += TASK_COMM_LEN; -#endif - p->comm_event = kzalloc(n, GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN); - if (!p->comm_event) { - op_bootprof_enabled = false; - goto out; - } -#ifdef TRACK_TASK_COMM - memcpy(p->comm_event, current->comm, TASK_COMM_LEN); - memcpy(p->comm_event + TASK_COMM_LEN, str, n - TASK_COMM_LEN); -#else - memcpy(p->comm_event, str, n); -#endif - boot_log_count++; -out: - mutex_unlock(&op_bootprof_lock); -} - -static void op_bootprof_switch(int on) -{ - mutex_lock(&op_bootprof_lock); - if (op_bootprof_enabled ^ on) { - unsigned long long ts = sched_clock(); - - pr_info("BOOTPROF:%10Ld.%06ld: %s\n", nsec_high(ts), - nsec_low(ts), on ? "ON" : "OFF"); - - if (on) { - op_bootprof_enabled = 1; - } else { - /* boot up complete */ - boot_finish = 1; - } - } - mutex_unlock(&op_bootprof_lock); -} - -static ssize_t op_bootprof_write(struct file *filp, const char *ubuf, - size_t cnt, loff_t *data) -{ - char buf[BOOT_STR_SIZE]; - size_t copy_size = cnt; - - if (cnt >= sizeof(buf)) { - copy_size = BOOT_STR_SIZE - 1; - } - - if (copy_from_user(&buf, ubuf, copy_size)) { - return -EFAULT; - } - - if (cnt == 1 && buf[0] == '1') { - op_bootprof_switch(1); - return 1; - } else if (cnt == 1 && buf[0] == '0') { - op_bootprof_switch(0); - return 1; - } - - buf[copy_size] = 0; - phx_monit(buf); - - return cnt; -} - -static ssize_t op_bootfrom_write(struct file *filp, const char *ubuf, - size_t cnt, loff_t *data) -{ - size_t copy_size = cnt; - - if (cnt >= sizeof(boot_from)) { - copy_size = BOOT_FROM_SIZE - 1; - } - - if (copy_from_user(&boot_from, ubuf, copy_size)) { - return -EFAULT; - } - - boot_from[copy_size] = 0; - - return cnt; -} - -static int op_bootprof_show(struct seq_file *m, void *v) -{ - int i; - struct boot_log_struct *p; - - for (i = 0; i < boot_log_count; i++) { - p = &op_bootprof[i]; - if (!p->comm_event) { - continue; - } - -#ifdef TRACK_TASK_COMM -#define FMT "%10Ld.%06ld :%5d-%-16s: %s\n" -#else -#define FMT "%s\n" -#endif - SEQ_printf(m, FMT, -#ifdef TRACK_TASK_COMM - nsec_high(p->timestamp), nsec_low(p->timestamp), - - p->pid, p->comm_event, p->comm_event + TASK_COMM_LEN); -#else - p->comm_event); -#endif - } - - return 0; -} - -static int op_bootfrom_show(struct seq_file *m, void *v) -{ - SEQ_printf(m, "%s\n", boot_from); - return 0; -} - -static int op_bootprof_open(struct inode *inode, struct file *file) -{ - return single_open(file, op_bootprof_show, inode->i_private); -} - -static int op_bootfrom_open(struct inode *inode, struct file *file) -{ - return single_open(file, op_bootfrom_show, inode->i_private); -} - -static const struct proc_ops op_bootprof_fops = { - .proc_open = op_bootprof_open, - .proc_write = op_bootprof_write, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; - -static const struct proc_ops op_bootfrom_fops = { - .proc_open = op_bootfrom_open, - .proc_write = op_bootfrom_write, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; - -/* device_initcall */ -void __init init_boot_prof(void) -{ - proc_create("phoenix", 0666, NULL, &op_bootprof_fops); - proc_create("opbootfrom", 0666, NULL, &op_bootfrom_fops); -} - -/* early_initcall */ -void __init init_bootprof_buf(void) -{ - op_bootprof_switch(1); -} diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.h b/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.h deleted file mode 100755 index 34d1f4879d2c..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/op_bootprof.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*============================================================================= - - INCLUDE FILES FOR MODULE - -=============================================================================*/ -#ifndef OP_BOOTPROF_H -#define OP_BOOTPROF_H -#include -#define SEQ_printf(m, x...) \ - do { \ - if (m) \ - seq_printf(m, x); \ - else \ - pr_info(x); \ - } while (0) - - -void op_log_boot(const char *str); - -#endif diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/oplus_phoenix.h b/drivers/soc/oplus/system/oplus_phoenix/gki/oplus_phoenix.h deleted file mode 100755 index 49e8d6ec2185..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/oplus_phoenix.h +++ /dev/null @@ -1,137 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_base.h -## Description : add for project phoenix(hang), PHOENIX_PROJECT -## -## -## -## Version: 1.0 -## Date: 2018/11/15 -## Author: hukun -## ----------------- Revision History: ---------------------- -## -## Kun Hu 2018/11/15 create this file -################################################################################ -*/ - -#ifndef PHOENIX_BASE_H - -/* stage kernel */ -#define KERNEL_MM_INIT_DONE "KERNEL_MM_INIT_DONE" -#define KERNEL_LOCAL_IRQ_ENABLE "KERNEL_LOCAL_IRQ_ENABLE" -#define KERNEL_DELAYACCT_INIT_DONE "KERNEL_DELAYACCT_INIT_DONE" -#define KERNEL_DRIVER_INIT_DONE "KERNEL_DRIVER_INIT_DONE" -#define KERNEL_DO_INITCALLS_DONE "KERNEL_DO_INITCALLS_DONE" -#define KERNEL_DO_BASIC_SETUP_DONE "KERNEL_DO_BASIC_SETUP_DONE" -#define KERNEL_INIT_DONE "KERNEL_INIT_DONE" - -/* stage native */ -#define NATIVE_INIT_START "NATIVE_INIT_START" -#define NATIVE_INIT_DO_MOUNTALL_START "NATIVE_INIT_DO_MOUNTALL_START" -#define NATIVE_INIT_DO_MOUNTALL_END "NATIVE_INIT_DO_MOUNTALL_END" -#define NATIVE_INIT_COMMAND_RESTORECON_DATA_START \ - "NATIVE_INIT_COMMAND_RESTORECON_DATA_START" -#define NATIVE_INIT_COMMAND_RESTORECON_DATA_END \ - "NATIVE_INIT_COMMAND_RESTORECON_DATA_END" -#define NATIVE_INIT_POST_FS "NATIVE_INIT_POST_FS" -#define NATIVE_INIT_TRIGGER_POST_FS_DATA "NATIVE_INIT_TRIGGER_POST_FS_DATA" -#define NATIVE_INIT_TRGGIER_RESTART_FRAMEWORK \ - "NATIVE_INIT_TRGGIER_RESTART_FRAMEWORK" -#define NATIVE_FSMGR_CHECKFS_START "NATIVE_FSMGR_CHECKFS_START" -#define NATIVE_FSMGR_CHECKFS_END "NATIVE_FSMGR_CHECKFS_END" -#define NATIVE_SURFACEFLINGER_START "NATIVE_SURFACEFLINGER_START" -#define NATIVE_SF_BOOTANIMATION_START "NATIVE_SF_BOOTANIMATION_START" -#define NATIVE_SF_BOOTANIMATION_END "NATIVE_SF_BOOTANIMATION_END" -#define NATIVE_VOLD_START "NATIVE_VOLD_START" -#define NATIVE_VOLD_DECRYPT_MASTER_KEY_START \ - "NATIVE_VOLD_DECRYPT_MASTER_KEY_START" -#define NATIVE_VOLD_DECRYPT_MASTER_KEY_END "NATIVE_VOLD_DECRYPT_MASTER_KEY_END" -#define NATIVE_VOLD_SCRYPT_KEYMASTER_START "NATIVE_VOLD_SCRYPT_KEYMASTER_START" -#define NATIVE_VOLD_SCRYPT_KEYMASTER_END "NATIVE_VOLD_SCRYPT_KEYMASTER_END" -#define NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_START \ - "NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_START" -#define NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_END \ - "NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_END" -#define NATIVE_BOOT_PROGRESS_START "NATIVE_BOOT_PROGRESS_START" - -/* stage android framework */ -#define ANDROID_ZYGOTE_PRELOAD_START "ANDROID_ZYGOTE_PRELOAD_START" -#define ANDROID_ZYGOTE_PRELOAD_END "ANDROID_ZYGOTE_PRELOAD_END" -#define ANDROID_SYSTEMSERVER_INIT_START "ANDROID_SYSTEMSERVER_INIT_START" -#define ANDROID_PMS_INIT_START "ANDROID_PMS_INIT_START" -#define ANDROID_PMS_SCAN_START "ANDROID_PMS_SCAN_START" -#define ANDROID_PMS_SCAN_END "ANDROID_PMS_SCAN_END" -#define ANDROID_PMS_DEXOPT_PERSISTPKGS_START \ - "ANDROID_PMS_DEXOPT_PERSISTPKGS_START" -#define ANDROID_PMS_DEXOPT_PERSISTPKGS_END "ANDROID_PMS_DEXOPT_PERSISTPKGS_END" -#define ANDROID_PMS_DEXOPT_START "ANDROID_PMS_DEXOPT_START" -#define ANDROID_PMS_DEXOPT_END "ANDROID_PMS_DEXOPT_END" -#define ANDROID_PMS_READY "ANDROID_PMS_READY" -#define ANDROID_AMS_READY "ANDROID_AMS_READY" -#define ANDROID_SYSTEMSERVER_READY "ANDROID_SYSTEMSERVER_READY" -#define ANDROID_AMS_ENABLE_SCREEN "ANDROID_AMS_ENABLE_SCREEN" -#define ANDROID_BOOT_COMPLETED "ANDROID_BOOT_COMPLETED" -#define PHOENIX_BOOT_COMPLETED "PHOENIX_BOOT_COMPLETED" - -/* error */ -#define ERROR_HANG_OPLUS "ERROR_HANG_OPLUS" -#define ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES \ - "ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES" -#define ERROR_KERNEL_PANIC "ERROR_KERNEL_PANIC" -#define ERROR_REBOOT_FROM_PANIC_SUCCESS "ERROR_REBOOT_FROM_PANIC_SUCCESS" -#define ERROR_NATIVE_REBOOT_INTO_RECOVERY "ERROR_NATIVE_REBOOT_INTO_RECOVERY" -#define ERROR_SYSTEM_SERVER_WATCHDOG "ERROR_SYSTEM_SERVER_WATCHDOG" -#define ERROR_HWT "ERROR_HWT" -#define ERROR_HW_REBOOT "ERROR_HW_REBOOT" - -/* action */ -#define ACTION_SET_BOOTSTAGE "SET_BOOTSTAGE" -#define ACTION_SET_BOOTERROR "SET_BOOTERROR" -#define CMD_STR_MAX_SIZE 256 - -/* signal */ -#define SIGPHX_HANG (SIGRTMIN + 0x11) - -#define DO_NOT_RECOVERY 0 -#define ONLY_RESTART 1 -#define RESTART_AND_RECOVERY 2 - -#define PHX_KLOG_ERROR(fmt, args...) \ - do { \ - printk(KERN_ERR "[PHOENIX] %s: " fmt, __func__, ##args); \ - } while (0) -#define PHX_KLOG_INFO(fmt, args...) \ - do { \ - printk(KERN_INFO "[PHOENIX] %s: " fmt, __func__, ##args); \ - } while (0) - -typedef struct _phx_baseinfo { - char stage[96]; - char error[96]; - char happen_time[64]; -} phx_baseinfo; - -typedef struct _phx_action_mapping { - char action[CMD_STR_MAX_SIZE]; - void (*map_func)(const char *); -} phx_action_mapping; - -/* -ATTENTION: - if phoenix project swithoff these function would evaluate to false - so make a if-else condition when use these function -*/ -extern int __weak phx_is_system_boot_completed(void); -extern int __weak phx_is_phoenix_boot_completed(void); -extern void __weak phx_set_boot_error(const char *error); -extern void __weak phx_set_boot_stage(const char *stage); -extern int __weak phx_get_current_stage_len(void); - -/* for native command deleiver to kernel */ -void phx_monit(const char *monitoring_command); - -#endif /* !PHOENIX_BASE_H */ diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_base.c b/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_base.c deleted file mode 100755 index c09b441aee61..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_base.c +++ /dev/null @@ -1,321 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: boologhelper.te -## Description : add for project phoenix(hang) -## PHOENIX_PROJECT -## Version: 1.0 -################################################################################ -*/ -#include "op_bootprof.h" -#include "oplus_phoenix.h" -#include -#include -#include -#include -#include -#include -#include - -#define PHX_KE_MARK "PHX_KE_HAPPEND" -#define TIME_FORMAT "yyyy-mm-dd HH:mm:ss" - -extern int is_phoenix_enable(void); -extern void phx_log_dump(const char *phx_error); - -static void phx_handle_hang_oplus(const char *); -static void phx_handle_critical_service_crash_4_times(const char *); -static void phx_handle_kernel_panic(const char *); -static void phx_handle_hwt(const char *); -static void phx_handle_reboot_from_panic_success_log(const char *); -static void phx_handle_system_server_watchdog(const char *); -static void phx_handle_native_reboot_into_recovery(const char *); - -static void phx_choose_action_handler(const char *, const phx_action_mapping *, - size_t); - -static phx_action_mapping monitor_action_mapping[] = { - { ACTION_SET_BOOTSTAGE, phx_set_boot_stage }, - { ACTION_SET_BOOTERROR, phx_set_boot_error }, -}; - -static phx_action_mapping errno_handle_action_mapping[] = { - { ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES, - phx_handle_critical_service_crash_4_times }, - { ERROR_KERNEL_PANIC, phx_handle_kernel_panic }, - { ERROR_HWT, phx_handle_hwt }, - { ERROR_REBOOT_FROM_PANIC_SUCCESS, - phx_handle_reboot_from_panic_success_log }, - { ERROR_HANG_OPLUS, phx_handle_hang_oplus }, - { ERROR_SYSTEM_SERVER_WATCHDOG, phx_handle_system_server_watchdog }, - { ERROR_NATIVE_REBOOT_INTO_RECOVERY, - phx_handle_native_reboot_into_recovery }, -}; - -static int is_system_boot_completed = 0; -static int is_phoenix_boot_completed = 0; -static int is_filesystem_prepared = 0; -static phx_baseinfo *phx_curr_info = 0; - -static void phx_get_local_time(char* strtime, size_t strtime_length) -{ - struct rtc_time tm; - struct timespec64 ts = { 0 }; - ktime_get_real_ts64(&ts); - rtc_time64_to_tm(ts.tv_sec, &tm); - snprintf(strtime, strtime_length, "%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, - tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); -} - -static void phx_update_current_stage(const char *stage) -{ - if (!phx_curr_info) { - return; - } - snprintf(phx_curr_info->stage, sizeof(phx_curr_info->stage), "%s", - stage); -} - -int phx_get_current_stage_len(void) -{ - if (!phx_curr_info) { - return 0; - } - return strlen(phx_curr_info->stage); -} -EXPORT_SYMBOL(phx_get_current_stage_len); - -static void phx_update_current_error(const char *error) -{ - if (!phx_curr_info) { - return; - } - snprintf(phx_curr_info->error, sizeof(phx_curr_info->error), "%s", - error); -} - -static void phx_update_happen_time(const char *happen_time) -{ - if (!phx_curr_info) { - return; - } - snprintf(phx_curr_info->happen_time, sizeof(phx_curr_info->happen_time), - "%s", happen_time); -} - -static void phx_klog_bootstage(const char *stage) -{ - char stage_pnt[CMD_STR_MAX_SIZE] = { 0 }; - snprintf(stage_pnt, CMD_STR_MAX_SIZE, "STAGE_%s", stage); - op_log_boot(stage_pnt); - phx_update_current_stage(stage); - PHX_KLOG_INFO("%s\n", stage); -} - -static void phx_klog_booterror(const char *errno, const char *time) -{ - char error_pnt[CMD_STR_MAX_SIZE] = { 0 }; - snprintf(error_pnt, CMD_STR_MAX_SIZE, "ERROR_%s", errno); - /* panic will diable local interrupts, msleep behaviour is not permissive */ - if (strcmp(errno, ERROR_KERNEL_PANIC)) { - op_log_boot(error_pnt); - } - phx_update_current_error(errno); - phx_update_happen_time(time); - PHX_KLOG_INFO("%s, happen_time: %s\n", errno, time); -} - -static void phx_handle_critical_service_crash_4_times(const char *happen_time) -{ - phx_klog_booterror(ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES, happen_time); -} - -static void phx_handle_kernel_panic(const char *happen_time) -{ - phx_klog_booterror(ERROR_KERNEL_PANIC, happen_time); - PHX_KLOG_INFO("%s\n", PHX_KE_MARK); -} - -static void phx_handle_hwt(const char *happen_time) -{ - phx_klog_booterror(ERROR_HWT, happen_time); - PHX_KLOG_INFO("%s\n", PHX_KE_MARK); -} - -static void phx_handle_reboot_from_panic_success_log(const char *happen_time) -{ - phx_klog_booterror(ERROR_REBOOT_FROM_PANIC_SUCCESS, happen_time); -} - -static void phx_handle_system_server_watchdog(const char *happen_time) -{ - phx_klog_booterror(ERROR_SYSTEM_SERVER_WATCHDOG, happen_time); -} - -static void phx_handle_native_reboot_into_recovery(const char *happen_time) -{ - phx_klog_booterror(ERROR_NATIVE_REBOOT_INTO_RECOVERY, happen_time); -} - -static void phx_handle_hang_oplus(const char *happen_time) -{ - phx_klog_booterror(ERROR_HANG_OPLUS, happen_time); - phx_log_dump(ERROR_HANG_OPLUS); -} - -static void -phx_choose_action_handler(const char *cmd, - const phx_action_mapping *action_map_array, - size_t action_map_array_size) -{ - char action[CMD_STR_MAX_SIZE] = { 0 }; - char *p = strchr(cmd, '@'); - size_t i = 0; - if (NULL == p) { - PHX_KLOG_INFO("invalid command\n"); - return; - } - strncpy(action, cmd, p - cmd); - for (; i < action_map_array_size; i++) { - if (!strcmp(action_map_array[i].action, action)) { - action_map_array[i].map_func(p + 1); - return; - } - } - PHX_KLOG_INFO("undefined command\n"); - return; -} - -static void phx_strip_line_break(const char *line, char *result) -{ - size_t line_length = strlen(line); - size_t copy_length = - strchr(line, '\n') != NULL ? line_length - 1 : line_length; - strncpy(result, line, copy_length); -} - -void phx_get_base_info(phx_baseinfo **baseinfo) -{ - *baseinfo = phx_curr_info; -} - -EXPORT_SYMBOL(phx_get_base_info); - -int phx_is_system_boot_completed(void) -{ - return is_system_boot_completed; -} - -EXPORT_SYMBOL(phx_is_system_boot_completed); - -int phx_is_phoenix_boot_completed(void) -{ - return is_phoenix_boot_completed; -} - -EXPORT_SYMBOL(phx_is_phoenix_boot_completed); - -int phx_is_filesystem_ready(void) -{ - return is_filesystem_prepared; -} - -EXPORT_SYMBOL(phx_is_filesystem_ready); - -void phx_set_boot_stage(const char *stage) -{ - if (!is_phoenix_enable()) { - /* phoenix off */ - return; - } - if (!is_phoenix_boot_completed) { - phx_klog_bootstage(stage); - } - - if (!strcmp(stage, ANDROID_BOOT_COMPLETED)) { - is_system_boot_completed = 1; - } - - if (!is_filesystem_prepared && !strcmp(stage, NATIVE_INIT_POST_FS)) { - is_filesystem_prepared = 1; - } - - if (!is_phoenix_boot_completed && - !strcmp(stage, PHOENIX_BOOT_COMPLETED)) { - is_phoenix_boot_completed = 1; - } -} - -EXPORT_SYMBOL(phx_set_boot_stage); - -void phx_set_boot_error(const char *errno) -{ - int i = 0; - char time_pattern[ARRAY_SIZE(TIME_FORMAT) + 1] = { 0 }; - if (!is_phoenix_enable()) { - /* phoenix off */ - return; - } - phx_get_local_time(time_pattern, ARRAY_SIZE(time_pattern)); - for (; i < ARRAY_SIZE(errno_handle_action_mapping); i++) { - if (!strcmp(errno_handle_action_mapping[i].action, errno)) { - errno_handle_action_mapping[i].map_func(time_pattern); - return; - } - } -} - -EXPORT_SYMBOL(phx_set_boot_error); - -void phx_monit(const char *monitoring_command) -{ - char stripped_command[CMD_STR_MAX_SIZE] = { 0 }; - if (!is_phoenix_enable()) { - /* phoenix off */ - return; - } - if (strlen(monitoring_command) > CMD_STR_MAX_SIZE - 1) { - PHX_KLOG_INFO("monitor command too long\n"); - return; - } - phx_strip_line_break(monitoring_command, stripped_command); - phx_choose_action_handler(stripped_command, monitor_action_mapping, - ARRAY_SIZE(monitor_action_mapping)); -} - -EXPORT_SYMBOL(phx_monit); - -extern void __init init_bootprof_buf(void); -extern void __init init_boot_prof(void); -extern void __init phoenix_hlos_watchdog_init(void); - -/* postcore_initcall */ -static int __init phoenix_base_init(void) -{ - /* bootprof->early_initcall */ - init_bootprof_buf(); - - phx_curr_info = - (phx_baseinfo *)kmalloc(sizeof(phx_baseinfo), GFP_KERNEL); - if (!phx_curr_info) { - PHX_KLOG_ERROR("kmalloc to phx_curr_info failed\n"); - return -1; - } - - /* bootprof->device_initcall */ - init_boot_prof(); - - /* watchdog->arch_initcall */ - phoenix_hlos_watchdog_init(); - - return 0; -} - -postcore_initcall(phoenix_base_init); - -MODULE_DESCRIPTION("phoenix base"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Kun.Hu "); diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_dump.c b/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_dump.c deleted file mode 100755 index 1c1cec2be52b..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_dump.c +++ /dev/null @@ -1,318 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_dump.c -## Description : responsible for log management, PHOENIX_PROJECT -## -## Version: 1.0 -################################################################################ -*/ -#define FILP_OPEN_FUNCTION_CLOSE 0 - -#include "oplus_phoenix.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TASK_INIT_COMM "init" -#define KE_LOG_GENERATE_TIMEOUT msecs_to_jiffies(4 * 500) -#define KMSG_DEV_FILE "/dev/kmsg" -#define KMSG_BUFFER_SIZE (8 * 1024) -#define KEYINFO_FILE_SIZE (8 * 1024) -#define FILE_MODE_0666 0666 -#define AID_SYSTEM 1000 -#define FILE_DMESG "/data/persist_log/oplusreserve/phoenix/kmsg" -#define PHOENIX_TEMP_DIR "/data/persist_log/oplusreserve/phoenix" -#define FILE_KERNEL_EXPETION_INFO \ - "/data/persist_log/oplusreserve/phoenix/ERROR_KERNEL_EXCEPTION" - -#define PHX_KEYINFO_FORMAT \ - "stage: %s\n\ -error: %s\n\ -happen_time: %s\n\ -is_boot_complete: %d\n" - -typedef struct _phx_keyinfo { - phx_baseinfo *baseinfo; - int is_system_boot_completed; - /* TODO: more information */ -} phx_keyinfo; - -extern int hang_oplus_recovery_method; -extern int hang_oplus_main_on; - -/* kernel, fix extfs crash */ -extern int phx_is_system_boot_completed(void); -extern int phx_is_filesystem_ready(void); -extern void phx_get_base_info(phx_baseinfo **); - -static DECLARE_COMPLETION(phx_comp); -/* mutex for write file */ -static DEFINE_MUTEX(phx_wf_mutex); - -static void phx_dump_hang_oplus_log(const char *); -static void phx_dump_kernel_exception_log(const char *); - -/* static struct kmsg_dumper phx_kmsg_dumper; */ - -static phx_action_mapping phx_log_dumper_mapping[] = { - { ERROR_HANG_OPLUS, phx_dump_hang_oplus_log }, - { ERROR_KERNEL_PANIC, phx_dump_kernel_exception_log }, - { ERROR_HWT, phx_dump_kernel_exception_log }, - /* TODO: dump hw reboot log */ -}; - -static void find_task_by_comm(const char *pcomm, struct task_struct **t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) { - if (!strcmp(t->comm, pcomm)) { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -/* handle two situation */ -/* 1. hang and filesystem ready */ -/* 2. hang and filesystem not ready(hang kernel or early native) */ -static void phx_dump_hang_oplus_log(const char *happen_time) -{ - struct task_struct *t_init; - t_init = NULL; - find_task_by_comm(TASK_INIT_COMM, &t_init); - if (NULL != t_init && phx_is_filesystem_ready()) { - PHX_KLOG_INFO("send hang oplus signal %d at %s", SIGPHX_HANG, - happen_time); - send_sig_info(SIGPHX_HANG, SEND_SIG_NOINFO, t_init); - /* native process will handle remaining work */ - schedule_timeout_interruptible(30 * HZ); - } - /* incase native error handle process hang or filesystem not ready */ - panic(ERROR_HANG_OPLUS); -} - -#if FILP_OPEN_FUNCTION_CLOSE -/* dump kmsg to file or raw block */ -static int dump_kmsg(struct file *opfile, size_t offset_of_start, - struct kmsg_dumper *kmsg_dumper) -{ - loff_t offset; - char line[1024] = { 0 }; - size_t len = 0; - size_t bytes_writed = 0; - - offset = offset_of_start; - kmsg_dumper->active = true; - while (kmsg_dump_get_line(kmsg_dumper, true, line, sizeof(line), - &len)) { - line[len] = '\0'; - mutex_lock(&phx_wf_mutex); - - bytes_writed = kernel_write(opfile, line, len, &offset); - if (len != bytes_writed) { - PHX_KLOG_ERROR("kernel_write failed, error: %lu\n", - bytes_writed); - mutex_unlock(&phx_wf_mutex); - return -1; - } - mutex_unlock(&phx_wf_mutex); - } - - return 0; -} - -static int phx_store_kmsg(void) -{ - int result = -1; - struct file *opfile; - - opfile = filp_open(FILE_DMESG, O_CREAT | O_WRONLY | O_TRUNC, - FILE_MODE_0666); - if (IS_ERR(opfile)) { - PHX_KLOG_ERROR("filp_open failed, error: %ld\n", - PTR_ERR(opfile)); - return -1; - } - - if (dump_kmsg(opfile, 0, &phx_kmsg_dumper)) { - PHX_KLOG_ERROR("dump kmsg failed\n"); - result = -1; - } - - vfs_fsync(opfile, 0); - filp_close(opfile, NULL); - - return result; -} - -static void phx_format_keyinfo(const phx_keyinfo *kinfo, char *buffer, - int buffer_size) -{ - const phx_baseinfo *binfo = kinfo->baseinfo; - snprintf(buffer, buffer_size, PHX_KEYINFO_FORMAT, binfo->stage, - binfo->error, binfo->happen_time, - kinfo->is_system_boot_completed); -} - -static int phx_generate_keyinfo(const char *keyinfo_file, - const phx_keyinfo *kinfo) -{ - struct file *opfile; - loff_t offset; - size_t bytes_to_write = 0; - int result = -1; - char *buf = NULL; - - opfile = filp_open(keyinfo_file, O_CREAT | O_WRONLY | O_TRUNC, - FILE_MODE_0666); - if (IS_ERR(opfile)) { - pr_err("filp_open %s failed, error: %ld\n", keyinfo_file, - PTR_ERR(opfile)); - return -1; - } - - buf = (char *)kmalloc(KEYINFO_FILE_SIZE, GFP_KERNEL); - if (!buf) { - PHX_KLOG_ERROR("kmalloc %u bytes failed\n", KEYINFO_FILE_SIZE); - result = -1; - goto phx_bail; - } - memset(buf, 0, KEYINFO_FILE_SIZE); - phx_format_keyinfo(kinfo, buf, KEYINFO_FILE_SIZE); - bytes_to_write = strlen(buf); - if (!bytes_to_write) { - result = -1; - goto phx_bail; - } - mutex_lock(&phx_wf_mutex); - offset = 0; - if (strlen(buf) != (bytes_to_write = kernel_write( - opfile, buf, strlen(buf), &offset))) { - PHX_KLOG_ERROR("kernel_write %s failed, error: %lu\n", - keyinfo_file, bytes_to_write); - mutex_unlock(&phx_wf_mutex); - result = -1; - goto phx_bail; - } - - /* nouse */ -#if FILP_OPEN_FUNCTION_CLOSE -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_chown(keyinfo_file, AID_SYSTEM, AID_SYSTEM); -#else - sys_chown(keyinfo_file, AID_SYSTEM, AID_SYSTEM); -#endif -#endif - - mutex_unlock(&phx_wf_mutex); - result = 0; - -phx_bail: - vfs_fsync(opfile, 0); - filp_close(opfile, NULL); - if (buf) { - kfree(buf); - buf = NULL; - } - return result; -} - -static int phx_generate_ke_keyinfo(void) -{ - int result = -1; - phx_keyinfo *kinfo = - (phx_keyinfo *)kmalloc(sizeof(phx_keyinfo), GFP_KERNEL); - if (!kinfo) { - PHX_KLOG_ERROR("kmalloc %lu bytes failed\n", - sizeof(phx_keyinfo)); - return result; - } - - memset(kinfo, 0, sizeof(phx_keyinfo)); - phx_get_base_info(&kinfo->baseinfo); - kinfo->is_system_boot_completed = phx_is_system_boot_completed(); - result = phx_generate_keyinfo(FILE_KERNEL_EXPETION_INFO, kinfo); - kfree(kinfo); - return result; -} - -static int phx_collect_ke_log(void *args) -{ - if (0 != phx_generate_ke_keyinfo()) { - PHX_KLOG_ERROR("generate panic keyinfo failed\n"); - goto phx_bail; - } - - /* we boot in post-fs-data, save kmsg to file */ - if (phx_store_kmsg()) { - PHX_KLOG_ERROR("store kmsg failed\n"); - /* goto phx_bail; */ - } - - /* nouse */ - - /* TODO: we have not boot in post-fs-data, save kmsg to raw block */ - -phx_bail: - complete(&phx_comp); - return -1; -} -#endif - -static void phx_dump_kernel_exception_log(const char *error) -{ - PHX_KLOG_INFO( - "Due to calling filp_open is forbidden in GKI, kernel log " - "will not be dumped here in driver"); -#if FILP_OPEN_FUNCTION_CLOSE - struct task_struct *tsk; - tsk = kthread_run(phx_collect_ke_log, NULL, "phx_collect_ke_log"); - if (IS_ERR(tsk)) { - PHX_KLOG_ERROR( - "create kernel thread phx_collect_ke_log failed\n"); - return; - } - if (!wait_for_completion_timeout(&phx_comp, KE_LOG_GENERATE_TIMEOUT)) { - PHX_KLOG_ERROR("collect kernel exception %s log timeout\n", - error); - } -#endif -} - -void phx_log_dump(const char *phx_error) -{ - size_t i = 0; - for (; i < ARRAY_SIZE(phx_log_dumper_mapping); i++) { - if (!strcmp(phx_log_dumper_mapping[i].action, phx_error)) { - phx_log_dumper_mapping[i].map_func(phx_error); - return; - } - } -} - -EXPORT_SYMBOL(phx_log_dump); - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_PHOENIX) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_watchdog.c b/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_watchdog.c deleted file mode 100755 index ea5efd33b509..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/gki/phoenix_watchdog.c +++ /dev/null @@ -1,288 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_watchdog.c -## Description : add for project phenix(hang ) -## -## Version: 1.0 -################################################################################ -*/ -#include "oplus_phoenix.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DELAY_TIME 30 -#define MAX_CMD_LENGTH 32 -#define DEFAULT_PHX_WD_PET_TIME (60 * 4) - -static int hang_oplus_main_on = 1; /* default on */ -static int hang_oplus_recovery_method = RESTART_AND_RECOVERY; -static int phx_hlos_wd_pet_time = DEFAULT_PHX_WD_PET_TIME; - -static bool is_qcom_hardware; -static bool is_userdebug; - -static char *bootargs_ptr; -#define BOOTARGS_LEN (4 * 1024) /* 4K */ - -static void reinitialze_pet_time_for_debug_build(void) -{ - if (is_userdebug) { - phx_hlos_wd_pet_time = 60 * 5; - } - if (AGING == get_eng_version()) { - phx_hlos_wd_pet_time = 60 * 10; /* aging test version */ - } - -#ifdef CONFIG_MEMLEAK_DETECT_THREAD - if (AGING != get_eng_version()) { - phx_hlos_wd_pet_time += 60 * 5; - } -#endif -} - -int is_phoenix_enable(void) -{ - return hang_oplus_main_on; -} - -EXPORT_SYMBOL(is_phoenix_enable); - -extern char boot_from[]; -static void phx_pet(void) -{ - /* give abnormal boot another timeslice */ - if (strncmp(boot_from, "normal", 6)) { - schedule_timeout_interruptible(phx_hlos_wd_pet_time * HZ); - } - - if (phx_is_system_boot_completed()) { - return; - } - - /* for GSI detecting, boot stage will not have any string */ - if (phx_get_current_stage_len() == 0) { - return; - } - - /* for debug/eng ver, not reboot ... */ - if (is_userdebug || (get_eng_version() == AGING)) { - PHX_KLOG_INFO( - "will not set ERROR_HANG_OPLUS with userdebug/aging version\n"); - return; - } - - PHX_KLOG_INFO("phoenix watchdog pet!\n"); - phx_set_boot_error(ERROR_HANG_OPLUS); - return; -} - -/* start phoenix high level os watchdog */ -static int phoenix_watchdog_kthread(void *dummy) -{ - schedule_timeout_interruptible(phx_hlos_wd_pet_time * HZ); - phx_pet(); - return 0; -} - -static int phx_is_normal_mode_qcom(void) -{ - int i; - char *substr; - char boot_mode[MAX_CMD_LENGTH + 1]; - const char *const normal_boot_mode_list[] = { "normal", "reboot", - "kernel" }; - - substr = strstr(bootargs_ptr, "oplusboot.mode="); - if (substr) { - substr += strlen("oplusboot.mode="); - for (i = 0; substr[i] != ' ' && i < MAX_CMD_LENGTH && - substr[i] != '\0'; - i++) { - boot_mode[i] = substr[i]; - } - boot_mode[i] = '\0'; - - if (MSM_BOOT_MODE__NORMAL != get_boot_mode()) { - return 0; - } - - for (i = 0; i < ARRAY_SIZE(normal_boot_mode_list); i++) { - if (!strcmp(boot_mode, normal_boot_mode_list[i])) { - return 1; - } - } - } - return 0; -} - -/* copy mtk_boot_common.h */ -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 -static int phx_is_normal_mode_mtk(void) -{ - int mtk_boot_mode = 0; - - mtk_boot_mode = get_boot_mode(); - PHX_KLOG_INFO("mtk_boot_mode: %d\n", mtk_boot_mode); - - if ((mtk_boot_mode == NORMAL_BOOT) || (mtk_boot_mode == ALARM_BOOT)) { - return 1; - } else { - return 0; - } -} - -static const char *phx_get_machine_name(void) -{ - int ret; - const char *str; - struct device_node *np; - - np = of_find_node_by_path("/"); - ret = of_property_read_string(np, "model", &str); - if (!ret) { - return str; - } - - ret = of_property_read_string(np, "compatible", &str); - if (!ret) { - return str; - } - - return "unknown"; -} - -static int phx_is_qcom_platform(void) -{ - const char *platform_name; - char *substr; - int i; - const char *const qcom_platform_keywords[] = { "Qualcomm", "SDM" }; - - platform_name = phx_get_machine_name(); - for (i = 0; i < ARRAY_SIZE(qcom_platform_keywords); i++) { - substr = strstr(platform_name, qcom_platform_keywords[i]); - if (substr) { - PHX_KLOG_INFO("Qcom platform"); - return 1; - } - } - - if (is_qcom_hardware) { - PHX_KLOG_INFO("Qcom platform hardware"); - return 1; - } - - PHX_KLOG_INFO("MTK platform"); - return 0; -} - -static int __init phx_is_normal_mode(void) -{ - return phx_is_qcom_platform() ? phx_is_normal_mode_qcom() : - phx_is_normal_mode_mtk(); -} - -static void phx_parse_cmdline(void) -{ - char *str; - - if (strstr(bootargs_ptr, "androidboot.hardware=qcom")) { - is_qcom_hardware = true; - } - - if (strstr(bootargs_ptr, "buildvariant=userdebug")) { - is_userdebug = true; - } - - str = strstr(bootargs_ptr, "phx_rus_conf.main_on="); - if (str) { - str += strlen("phx_rus_conf.main_on="); - get_option(&str, &hang_oplus_main_on); - PHX_KLOG_INFO("hang_oplus_main_on %d\n", hang_oplus_main_on); - } - - /* nouse ? */ - str = strstr(bootargs_ptr, "phx_rus_conf.recovery_method="); - if (str) { - str += strlen("phx_rus_conf.recovery_method="); - get_option(&str, &hang_oplus_recovery_method); - PHX_KLOG_INFO("hang_oplus_recovery_method %d\n", - hang_oplus_recovery_method); - } - - str = strstr(bootargs_ptr, "phx_rus_conf.kernel_time="); - if (str) { - str += strlen("phx_rus_conf.kernel_time="); - get_option(&str, &phx_hlos_wd_pet_time); - PHX_KLOG_INFO("phx_hlos_wd_pet_time %d\n", - phx_hlos_wd_pet_time); - } -} - -static int phx_prepare_bootargs(void) -{ - int ret; - struct device_node *of_chosen; - - bootargs_ptr = (char *)kmalloc(BOOTARGS_LEN, GFP_KERNEL); - if (!bootargs_ptr) { - PHX_KLOG_ERROR("kmalloc for bootargs ptr failed !\n"); - return -1; - } - - of_chosen = of_find_node_by_path("/chosen"); - if (!of_chosen) { - of_chosen = of_find_node_by_path("/chosen@0"); - } - - if (of_chosen) { - ret = of_property_read_string(of_chosen, "bootargs", - (const char **)&bootargs_ptr); - if (ret) { - PHX_KLOG_ERROR("try to get bootargs failed !"); - return -1; - } - } - - phx_parse_cmdline(); - - return 0; -} - -void __init phoenix_hlos_watchdog_init(void) -{ - int ret; - - ret = phx_prepare_bootargs(); - if (ret) { - BUG_ON(1); - } - - PHX_KLOG_INFO("phoenix hlos watchdog: %s\n", - hang_oplus_main_on ? "on" : "off"); - if (hang_oplus_main_on && phx_is_normal_mode()) { - reinitialze_pet_time_for_debug_build(); - PHX_KLOG_ERROR("phoenix hlos watchdog pet time: %d\n", - phx_hlos_wd_pet_time); - kthread_run(phoenix_watchdog_kthread, NULL, - "phoenix_hlos_watchdog"); - } -} -/* arch_initcall(phoenix_hlos_watchdog_init); */ - -MODULE_DESCRIPTION("PHOENIX HLOS WATCHDOG"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Bright.Zhang "); diff --git a/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.c b/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.c deleted file mode 100755 index c09b677992e3..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.c +++ /dev/null @@ -1,280 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/*============================================================================= - - INCLUDE FILES FOR MODULE - -=============================================================================*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "oplus_phoenix.h" -#include "op_bootprof.h" - -#define BOOT_STR_SIZE 256 -#define BOOT_LOG_NUM 192 -/*#define TRACK_TASK_COMM*/ -#define BOOT_FROM_SIZE 16 - -extern unsigned long long notrace sched_clock(void); - -struct boot_log_struct { - /* task cmdline for first 16 bytes - * and boot event for the rest - * if TRACK_TASK_COMM is on */ - char *comm_event; -#ifdef TRACK_TASK_COMM - pid_t pid; -#endif - u64 timestamp; -} op_bootprof[BOOT_LOG_NUM]; - -static int boot_log_count; -static DEFINE_MUTEX(op_bootprof_lock); -static bool op_bootprof_enabled; -static int boot_finish = 0; -char boot_from[BOOT_FROM_SIZE] = {'\0'}; - -#define MSG_SIZE 128 - -extern int is_phoenix_enable(void); - -/* - * Ease the printing of nsec fields: -*/ - -static long long nsec_high(unsigned long long nsec) -{ - if ((long long)nsec < 0) { - nsec = -nsec; - do_div(nsec, 1000000); - return -nsec; - } - - do_div(nsec, 1000000); - - return nsec; -} - -static unsigned long nsec_low(unsigned long long nsec) -{ - if ((long long)nsec < 0) { - nsec = -nsec; - } - - return do_div(nsec, 1000000); -} - - -void op_log_boot(const char *str) -{ - unsigned long long ts; - struct boot_log_struct *p = &op_bootprof[boot_log_count]; - size_t n = strlen(str) + 1; - - if (!op_bootprof_enabled) { - return; - } - - ts = sched_clock(); - - if (boot_log_count >= BOOT_LOG_NUM) { - pr_err("[BOOTPROF] not enuough bootprof buffer\n"); - return; - } - - mutex_lock(&op_bootprof_lock); - p->timestamp = ts; -#ifdef TRACK_TASK_COMM - p->pid = current->pid; - n += TASK_COMM_LEN; -#endif - p->comm_event = kzalloc(n, GFP_ATOMIC | __GFP_NORETRY | - __GFP_NOWARN); - - if (!p->comm_event) { - op_bootprof_enabled = false; - goto out; - } - -#ifdef TRACK_TASK_COMM - memcpy(p->comm_event, current->comm, TASK_COMM_LEN); - memcpy(p->comm_event + TASK_COMM_LEN, str, n - TASK_COMM_LEN); -#else - memcpy(p->comm_event, str, n); -#endif - boot_log_count++; -out: - mutex_unlock(&op_bootprof_lock); -} - -static void op_bootprof_switch(int on) -{ - mutex_lock(&op_bootprof_lock); - - if (op_bootprof_enabled ^ on) { - unsigned long long ts = sched_clock(); - - pr_info("BOOTPROF:%10Ld.%06ld: %s\n", - nsec_high(ts), nsec_low(ts), on ? "ON" : "OFF"); - - if (on) { - op_bootprof_enabled = 1; - - } else { - /* boot up complete */ - boot_finish = 1; - } - } - - mutex_unlock(&op_bootprof_lock); -} - -static ssize_t -op_bootprof_write(struct file *filp, const char *ubuf, size_t cnt, loff_t *data) -{ - char buf[BOOT_STR_SIZE]; - size_t copy_size = cnt; - - if (cnt >= sizeof(buf)) { - copy_size = BOOT_STR_SIZE - 1; - } - - if (copy_from_user(&buf, ubuf, copy_size)) { - return -EFAULT; - } - - if (cnt == 1 && buf[0] == '1') { - op_bootprof_switch(1); - return 1; - - } else if (cnt == 1 && buf[0] == '0') { - op_bootprof_switch(0); - return 1; - } - - buf[copy_size] = 0; - phx_monit(buf); - - return cnt; -} - -static ssize_t -op_bootfrom_write(struct file *filp, const char *ubuf, size_t cnt, loff_t *data) -{ - size_t copy_size = cnt; - - if (cnt >= sizeof(boot_from)) { - copy_size = BOOT_FROM_SIZE - 1; - } - - if (copy_from_user(&boot_from, ubuf, copy_size)) { - return -EFAULT; - } - - boot_from[copy_size] = 0; - - return cnt; -} - -static int op_bootprof_show(struct seq_file *m, void *v) -{ - int i; - struct boot_log_struct *p; - - for (i = 0; i < boot_log_count; i++) { - p = &op_bootprof[i]; - - if (!p->comm_event) { - continue; - } - -#ifdef TRACK_TASK_COMM -#define FMT "%10Ld.%06ld :%5d-%-16s: %s\n" -#else -#define FMT "%s\n" -#endif - SEQ_printf(m, FMT, -#ifdef TRACK_TASK_COMM - nsec_high(p->timestamp), nsec_low(p->timestamp), - - p->pid, p->comm_event, p->comm_event + TASK_COMM_LEN -#else - p->comm_event -#endif -); - } - - return 0; -} - -static int op_bootfrom_show(struct seq_file *m, void *v) -{ - SEQ_printf(m, "%s\n", boot_from); - return 0; -} - -static int op_bootprof_open(struct inode *inode, struct file *file) -{ - return single_open(file, op_bootprof_show, inode->i_private); -} - -static int op_bootfrom_open(struct inode *inode, struct file *file) -{ - return single_open(file, op_bootfrom_show, inode->i_private); -} - -static const struct file_operations op_bootprof_fops = { - .open = op_bootprof_open, - .write = op_bootprof_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations op_bootfrom_fops = { - .open = op_bootfrom_open, - .write = op_bootfrom_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int __init init_boot_prof(void) -{ - struct proc_dir_entry *pe; - - pe = proc_create("phoenix", 0666, NULL, &op_bootprof_fops); - - if (!pe) { - return -ENOMEM; - } - - pe = proc_create("opbootfrom", 0666, NULL, &op_bootfrom_fops); - - if (!pe) { - return -ENOMEM; - } - - return 0; -} - -static int __init init_bootprof_buf(void) -{ - op_bootprof_switch(1); - return 0; -} - -early_initcall(init_bootprof_buf); -device_initcall(init_boot_prof); diff --git a/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.h b/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.h deleted file mode 100755 index ebffd99d4fbf..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/op_bootprof.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*============================================================================= - - INCLUDE FILES FOR MODULE - -=============================================================================*/ -#ifndef OP_BOOTPROF_H -#define OP_BOOTPROF_H -#include -#define SEQ_printf(m, x...) \ - do { \ - if (m) \ - seq_printf(m, x); \ - else \ - pr_info(x); \ - } while (0) - - -void op_log_boot(const char *str); - -#endif /*OP_BOOTPROF_H*/ diff --git a/drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h b/drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h deleted file mode 100755 index d1bb2cdad6f4..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h +++ /dev/null @@ -1,129 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_base.h -## Description : add for project phoenix(hang), PHOENIX_PROJECT -## -## -## -## Version: 1.0 -## Date: 2018/11/15 -## Author: hukun -## ----------------- Revision History: ---------------------- -## -## Kun Hu 2018/11/15 create this file -################################################################################ -*/ - -#ifndef PHOENIX_BASE_H -#define PHOENIX_BASE_H -/*stage kernel*/ -#define KERNEL_MM_INIT_DONE "KERNEL_MM_INIT_DONE" -#define KERNEL_LOCAL_IRQ_ENABLE "KERNEL_LOCAL_IRQ_ENABLE" -#define KERNEL_DELAYACCT_INIT_DONE "KERNEL_DELAYACCT_INIT_DONE" -#define KERNEL_DRIVER_INIT_DONE "KERNEL_DRIVER_INIT_DONE" -#define KERNEL_DO_INITCALLS_DONE "KERNEL_DO_INITCALLS_DONE" -#define KERNEL_DO_BASIC_SETUP_DONE "KERNEL_DO_BASIC_SETUP_DONE" -#define KERNEL_INIT_DONE "KERNEL_INIT_DONE" - -/*stage native*/ -#define NATIVE_INIT_START "NATIVE_INIT_START" -#define NATIVE_INIT_DO_MOUNTALL_START "NATIVE_INIT_DO_MOUNTALL_START" -#define NATIVE_INIT_DO_MOUNTALL_END "NATIVE_INIT_DO_MOUNTALL_END" -#define NATIVE_INIT_COMMAND_RESTORECON_DATA_START "NATIVE_INIT_COMMAND_RESTORECON_DATA_START" -#define NATIVE_INIT_COMMAND_RESTORECON_DATA_END "NATIVE_INIT_COMMAND_RESTORECON_DATA_END" -#define NATIVE_INIT_POST_FS "NATIVE_INIT_POST_FS" -#define NATIVE_INIT_TRIGGER_POST_FS_DATA "NATIVE_INIT_TRIGGER_POST_FS_DATA" -#define NATIVE_INIT_TRGGIER_RESTART_FRAMEWORK "NATIVE_INIT_TRGGIER_RESTART_FRAMEWORK" -#define NATIVE_FSMGR_CHECKFS_START "NATIVE_FSMGR_CHECKFS_START" -#define NATIVE_FSMGR_CHECKFS_END "NATIVE_FSMGR_CHECKFS_END" -#define NATIVE_SURFACEFLINGER_START "NATIVE_SURFACEFLINGER_START" -#define NATIVE_SF_BOOTANIMATION_START "NATIVE_SF_BOOTANIMATION_START" -#define NATIVE_SF_BOOTANIMATION_END "NATIVE_SF_BOOTANIMATION_END" -#define NATIVE_VOLD_START "NATIVE_VOLD_START" -#define NATIVE_VOLD_DECRYPT_MASTER_KEY_START "NATIVE_VOLD_DECRYPT_MASTER_KEY_START" -#define NATIVE_VOLD_DECRYPT_MASTER_KEY_END "NATIVE_VOLD_DECRYPT_MASTER_KEY_END" -#define NATIVE_VOLD_SCRYPT_KEYMASTER_START "NATIVE_VOLD_SCRYPT_KEYMASTER_START" -#define NATIVE_VOLD_SCRYPT_KEYMASTER_END "NATIVE_VOLD_SCRYPT_KEYMASTER_END" -#define NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_START "NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_START" -#define NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_END "NATIVE_VOLD_CRYPTFS_RESTART_INTERNAL_END" -#define NATIVE_BOOT_PROGRESS_START "NATIVE_BOOT_PROGRESS_START" - -/*stage android framework*/ -#define ANDROID_ZYGOTE_PRELOAD_START "ANDROID_ZYGOTE_PRELOAD_START" -#define ANDROID_ZYGOTE_PRELOAD_END "ANDROID_ZYGOTE_PRELOAD_END" -#define ANDROID_SYSTEMSERVER_INIT_START "ANDROID_SYSTEMSERVER_INIT_START" -#define ANDROID_PMS_INIT_START "ANDROID_PMS_INIT_START" -#define ANDROID_PMS_SCAN_START "ANDROID_PMS_SCAN_START" -#define ANDROID_PMS_SCAN_END "ANDROID_PMS_SCAN_END" -#define ANDROID_PMS_DEXOPT_PERSISTPKGS_START "ANDROID_PMS_DEXOPT_PERSISTPKGS_START" -#define ANDROID_PMS_DEXOPT_PERSISTPKGS_END "ANDROID_PMS_DEXOPT_PERSISTPKGS_END" -#define ANDROID_PMS_DEXOPT_START "ANDROID_PMS_DEXOPT_START" -#define ANDROID_PMS_DEXOPT_END "ANDROID_PMS_DEXOPT_END" -#define ANDROID_PMS_READY "ANDROID_PMS_READY" -#define ANDROID_AMS_READY "ANDROID_AMS_READY" -#define ANDROID_SYSTEMSERVER_READY "ANDROID_SYSTEMSERVER_READY" -#define ANDROID_AMS_ENABLE_SCREEN "ANDROID_AMS_ENABLE_SCREEN" -#define ANDROID_BOOT_COMPLETED "ANDROID_BOOT_COMPLETED" -#define PHOENIX_BOOT_COMPLETED "PHOENIX_BOOT_COMPLETED" - -/*error*/ -#define ERROR_HANG_OPLUS "ERROR_HANG_OPLUS" -#define ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES "ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES" -#define ERROR_KERNEL_PANIC "ERROR_KERNEL_PANIC" -#define ERROR_REBOOT_FROM_PANIC_SUCCESS "ERROR_REBOOT_FROM_PANIC_SUCCESS" -#define ERROR_NATIVE_REBOOT_INTO_RECOVERY "ERROR_NATIVE_REBOOT_INTO_RECOVERY" -#define ERROR_SYSTEM_SERVER_WATCHDOG "ERROR_SYSTEM_SERVER_WATCHDOG" -#define ERROR_HWT "ERROR_HWT" -#define ERROR_HW_REBOOT "ERROR_HW_REBOOT" - -/*action*/ -#define ACTION_SET_BOOTSTAGE "SET_BOOTSTAGE" -#define ACTION_SET_BOOTERROR "SET_BOOTERROR" -#define CMD_STR_MAX_SIZE 256 - -/*signal*/ -#define SIGPHX_HANG (SIGRTMIN + 0x11) - -#define DO_NOT_RECOVERY 0 -#define ONLY_RESTART 1 -#define RESTART_AND_RECOVERY 2 - -#define PHX_KLOG_ERROR(fmt, args...)\ - do { \ - printk(KERN_ERR "[PHOENIX] %s: " fmt, \ - __func__, ##args); \ - } while (0) -#define PHX_KLOG_INFO(fmt, args...) \ - do { \ - printk(KERN_INFO "[PHOENIX] %s: " fmt, \ - __func__, ##args); \ - } while (0) - -typedef struct _phx_baseinfo { - char stage[96]; - char error[96]; - char happen_time[64]; -} phx_baseinfo; - -typedef struct _phx_action_mapping { - char action[CMD_STR_MAX_SIZE]; - void (*map_func)(const char *); -} phx_action_mapping; - -/* ATTENTION: -* if phoenix project swithoff these function would evaluate to false -* so make a if-else condition when use these function -*/ -extern int __weak phx_is_system_boot_completed(void); -extern int __weak phx_is_phoenix_boot_completed(void); -extern void __weak phx_set_boot_error(const char *error); -extern void __weak phx_set_boot_stage(const char *stage); - -/*for native command deleiver to kernel*/ -void phx_monit(const char *monitoring_command); - -#endif /*PHOENIX_BASE_H*/ diff --git a/drivers/soc/oplus/system/oplus_phoenix/phoenix_base.c b/drivers/soc/oplus/system/oplus_phoenix/phoenix_base.c deleted file mode 100755 index d22c84781857..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/phoenix_base.c +++ /dev/null @@ -1,309 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: boologhelper.te -## Description : add for project phoenix(hang) -## PHOENIX_PROJECT -## Version: 1.0 -################################################################################ -*/ -#include -#include -#include -#include -#include -#include -#include -#include "oplus_phoenix.h" -#include "op_bootprof.h" - -#define PHX_KE_MARK "PHX_KE_HAPPEND" -#define TIME_FORMAT "yyyy-mm-dd HH:mm:ss" - -extern int is_phoenix_enable(void); -extern void phx_log_dump(const char *phx_error); - -static void phx_handle_hang_oplus(const char *); -static void phx_handle_critical_service_crash_4_times(const char *); -static void phx_handle_kernel_panic(const char *); -static void phx_handle_hwt(const char *); -static void phx_handle_reboot_from_panic_success_log(const char *); -static void phx_handle_system_server_watchdog(const char *); -static void phx_handle_native_reboot_into_recovery(const char *); - - -static void phx_choose_action_handler(const char *, const phx_action_mapping *, - size_t); - - -static phx_action_mapping monitor_action_mapping[] = { - {ACTION_SET_BOOTSTAGE, phx_set_boot_stage}, - {ACTION_SET_BOOTERROR, phx_set_boot_error}, -}; - -static phx_action_mapping errno_handle_action_mapping[] = { - {ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES, phx_handle_critical_service_crash_4_times}, - {ERROR_KERNEL_PANIC, phx_handle_kernel_panic}, - {ERROR_HWT, phx_handle_hwt}, - {ERROR_REBOOT_FROM_PANIC_SUCCESS, phx_handle_reboot_from_panic_success_log}, - {ERROR_HANG_OPLUS, phx_handle_hang_oplus}, - {ERROR_SYSTEM_SERVER_WATCHDOG, phx_handle_system_server_watchdog}, - {ERROR_NATIVE_REBOOT_INTO_RECOVERY, phx_handle_native_reboot_into_recovery}, -}; - -static int is_system_boot_completed = 0; -static int is_phoenix_boot_completed = 0; -static int is_filesystem_prepared = 0; -static phx_baseinfo *phx_curr_info = 0; - -static void phx_get_local_time(char *strtime, size_t strtime_length) -{ - struct timespec ts; - struct rtc_time tm; - getnstimeofday(&ts); - rtc_time_to_tm(ts.tv_sec, &tm); - snprintf(strtime, strtime_length, "%04d-%02d-%02d %02d:%02d:%02d", - tm.tm_year + 1900, - tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); -} - -static void phx_update_current_stage(const char *stage) -{ - if (!phx_curr_info) { - return; - } - - snprintf(phx_curr_info->stage, sizeof(phx_curr_info->stage), "%s", stage); -} - -static void phx_update_current_error(const char *error) -{ - if (!phx_curr_info) { - return; - } - - snprintf(phx_curr_info->error, sizeof(phx_curr_info->error), "%s", error); -} - -static void phx_update_happen_time(const char *happen_time) -{ - if (!phx_curr_info) { - return; - } - - snprintf(phx_curr_info->happen_time, sizeof(phx_curr_info->happen_time), "%s", - happen_time); -} - -static void phx_klog_bootstage(const char *stage) -{ - char stage_pnt[CMD_STR_MAX_SIZE] = {0}; - snprintf(stage_pnt, CMD_STR_MAX_SIZE, "STAGE_%s", stage); - op_log_boot(stage_pnt); - phx_update_current_stage(stage); - PHX_KLOG_INFO("%s\n", stage); -} - -static void phx_klog_booterror(const char *errno, const char *time) -{ - char error_pnt[CMD_STR_MAX_SIZE] = {0}; - snprintf(error_pnt, CMD_STR_MAX_SIZE, "ERROR_%s", errno); - - /*panic will diable local interrupts, msleep behaviour is not permissive*/ - if (strcmp(errno, ERROR_KERNEL_PANIC)) { - op_log_boot(error_pnt); - } - - phx_update_current_error(errno); - phx_update_happen_time(time); - PHX_KLOG_INFO("%s, happen_time: %s\n", errno, time); -} - -static void phx_handle_critical_service_crash_4_times(const char *happen_time) -{ - phx_klog_booterror(ERROR_CRITICAL_SERVICE_CRASHED_4_TIMES, happen_time); -} - -static void phx_handle_kernel_panic(const char *happen_time) -{ - phx_klog_booterror(ERROR_KERNEL_PANIC, happen_time); - PHX_KLOG_INFO("%s\n", PHX_KE_MARK); -} - -static void phx_handle_hwt(const char *happen_time) -{ - phx_klog_booterror(ERROR_HWT, happen_time); - PHX_KLOG_INFO("%s\n", PHX_KE_MARK); -} - -static void phx_handle_reboot_from_panic_success_log(const char *happen_time) -{ - phx_klog_booterror(ERROR_REBOOT_FROM_PANIC_SUCCESS, happen_time); -} - -static void phx_handle_system_server_watchdog(const char *happen_time) -{ - phx_klog_booterror(ERROR_SYSTEM_SERVER_WATCHDOG, happen_time); -} - -static void phx_handle_native_reboot_into_recovery(const char *happen_time) -{ - phx_klog_booterror(ERROR_NATIVE_REBOOT_INTO_RECOVERY, happen_time); -} - -static void phx_handle_hang_oplus(const char *happen_time) -{ - phx_klog_booterror(ERROR_HANG_OPLUS, happen_time); - phx_log_dump(ERROR_HANG_OPLUS); -} - -static void phx_choose_action_handler(const char *cmd, - const phx_action_mapping *action_map_array, - size_t action_map_array_size) -{ - char action[CMD_STR_MAX_SIZE] = {0}; - char *p = strchr(cmd, '@'); - size_t i = 0; - - if (NULL == p) { - PHX_KLOG_INFO("invalid command\n"); - return; - } - - strncpy(action, cmd, p - cmd); - - for (; i < action_map_array_size; i++) { - if (!strcmp(action_map_array[i].action, action)) { - action_map_array[i].map_func(p + 1); - return; - } - } - - PHX_KLOG_INFO("undefined command\n"); - return; -} - -static void phx_strip_line_break(const char *line, char *result) -{ - size_t line_length = strlen(line); - size_t copy_length = strchr(line, '\n') != NULL ? line_length - 1 : line_length; - strncpy(result, line, copy_length); -} - -void phx_get_base_info(phx_baseinfo **baseinfo) -{ - *baseinfo = phx_curr_info; -} - -EXPORT_SYMBOL(phx_get_base_info); - -int phx_is_system_boot_completed(void) -{ - return is_system_boot_completed; -} - -EXPORT_SYMBOL(phx_is_system_boot_completed); - -int phx_is_phoenix_boot_completed(void) -{ - return is_phoenix_boot_completed; -} - -EXPORT_SYMBOL(phx_is_phoenix_boot_completed); - -int phx_is_filesystem_ready(void) -{ - return is_filesystem_prepared; -} - -EXPORT_SYMBOL(phx_is_filesystem_ready); - -void phx_set_boot_stage(const char *stage) -{ - if (!is_phoenix_enable()) { - /*phoenix off*/ - return; - } - - if (!is_phoenix_boot_completed) { - phx_klog_bootstage(stage); - } - - if (!strcmp(stage, ANDROID_BOOT_COMPLETED)) { - is_system_boot_completed = 1; - } - - if (!is_filesystem_prepared && !strcmp(stage, NATIVE_INIT_POST_FS)) { - is_filesystem_prepared = 1; - } - - if (!is_phoenix_boot_completed && !strcmp(stage, PHOENIX_BOOT_COMPLETED)) { - is_phoenix_boot_completed = 1; - } -} - -EXPORT_SYMBOL(phx_set_boot_stage); - -void phx_set_boot_error(const char *errno) -{ - int i = 0; - char time_pattern[ARRAY_SIZE(TIME_FORMAT) + 1] = {0}; - - if (!is_phoenix_enable()) { - /*phoenix off*/ - return; - } - - phx_get_local_time(time_pattern, ARRAY_SIZE(time_pattern)); - - for (; i < ARRAY_SIZE(errno_handle_action_mapping); i++) { - if (!strcmp(errno_handle_action_mapping[i].action, errno)) { - errno_handle_action_mapping[i].map_func(time_pattern); - return; - } - } -} - -EXPORT_SYMBOL(phx_set_boot_error); - -void phx_monit(const char *monitoring_command) -{ - char stripped_command[CMD_STR_MAX_SIZE] = {0}; - - if (!is_phoenix_enable()) { - /*phoenix off*/ - return; - } - - if (strlen(monitoring_command) > CMD_STR_MAX_SIZE - 1) { - PHX_KLOG_INFO("monitor command too long\n"); - return; - } - - phx_strip_line_break(monitoring_command, stripped_command); - phx_choose_action_handler(stripped_command, monitor_action_mapping, - ARRAY_SIZE(monitor_action_mapping)); -} - -EXPORT_SYMBOL(phx_monit); - -static int __init phoenix_base_init(void) -{ - phx_curr_info = (phx_baseinfo *)kmalloc(sizeof(phx_baseinfo), GFP_KERNEL); - - if (!phx_curr_info) { - PHX_KLOG_ERROR("kmalloc to phx_curr_info failed\n"); - return -1; - } - - return 0; -} - -postcore_initcall(phoenix_base_init); - -MODULE_DESCRIPTION("phoenix base"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Kun.Hu "); diff --git a/drivers/soc/oplus/system/oplus_phoenix/phoenix_dump.c b/drivers/soc/oplus/system/oplus_phoenix/phoenix_dump.c deleted file mode 100755 index 75aa5792a741..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/phoenix_dump.c +++ /dev/null @@ -1,407 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_dump.c -## Description : responsible for log management, PHOENIX_PROJECT -## -## Version: 1.0 -################################################################################ -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "oplus_phoenix.h" - -#define TASK_INIT_COMM "init" -#define KE_LOG_GENERATE_TIMEOUT msecs_to_jiffies(4 * 500) -#define KMSG_DEV_FILE "/dev/kmsg" -#define KMSG_BUFFER_SIZE (8 * 1024) -#define KEYINFO_FILE_SIZE (8 * 1024) -#define FILE_MODE_0666 0666 -#define AID_SYSTEM 1000 -#define FILE_DMESG "/data/persist_log/oplusreserve/phoenix/kmsg" -#define PHOENIX_TEMP_DIR "/data/persist_log/oplusreserve/phoenix" -#define FILE_KERNEL_EXPETION_INFO "/data/persist_log/oplusreserve/phoenix/ERROR_KERNEL_EXCEPTION" - - - -#define PHX_KEYINFO_FORMAT \ -"stage: %s\n\ -error: %s\n\ -happen_time: %s\n\ -is_boot_complete: %d\n" - -typedef struct _phx_keyinfo { - phx_baseinfo *baseinfo; - int is_system_boot_completed; - /*/TODO: more information*/ -} phx_keyinfo; - -extern int hang_oplus_recovery_method; -extern int hang_oplus_main_on; - -extern int phx_is_system_boot_completed(void); -extern int phx_is_filesystem_ready(void); -extern void phx_get_base_info(phx_baseinfo **); - -static DECLARE_COMPLETION(phx_comp); -/*mutex for write file*/ -static DEFINE_MUTEX(phx_wf_mutex); - -static void phx_dump_hang_oplus_log(const char *); -static void phx_dump_kernel_exception_log(const char *); - -static struct kmsg_dumper phx_kmsg_dumper; - -static phx_action_mapping phx_log_dumper_mapping[] = { - {ERROR_HANG_OPLUS, phx_dump_hang_oplus_log}, - {ERROR_KERNEL_PANIC, phx_dump_kernel_exception_log}, - {ERROR_HWT, phx_dump_kernel_exception_log}, - /*TODO: dump hw reboot log*/ -}; - -static void find_task_by_comm(const char *pcomm, struct task_struct **t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) { - if (!strcmp(t->comm, pcomm)) { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -/* handle two situation -* 1. hang and filesystem ready -* 2. hang and filesystem not ready(hang kernel or early native) -*/ -static void phx_dump_hang_oplus_log(const char *happen_time) -{ - struct task_struct *t_init; - t_init = NULL; - find_task_by_comm(TASK_INIT_COMM, &t_init); - - if (NULL != t_init && phx_is_filesystem_ready()) { - PHX_KLOG_INFO("send hang oplus signal %d at %s", SIGPHX_HANG, happen_time); - send_sig(SIGPHX_HANG, t_init, 0); - /*native process will handle remaining work*/ - schedule_timeout_interruptible(30 * HZ); - } - - /*incase native error handle process hang or filesystem not ready*/ - panic(ERROR_HANG_OPLUS); -} - -/*dump kmsg to file or raw block*/ -static int dump_kmsg(const char *filepath, size_t offset_of_start, - struct kmsg_dumper *kmsg_dumper) -{ - mm_segment_t old_fs; - char line[1024] = {0}; - int file_fd = -1; - size_t len = 0; - int result = -1; - - old_fs = get_fs(); - set_fs(KERNEL_DS); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - file_fd = ksys_open(filepath, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); -#else - file_fd = sys_open(filepath, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); -#endif - - if (file_fd < 0) { - PHX_KLOG_ERROR("sys_open %s failed, error: %d", filepath, file_fd); - result = -1; - goto phx_bail; - } - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_lseek(file_fd, offset_of_start, SEEK_SET); -#else - sys_lseek(file_fd, offset_of_start, SEEK_SET); -#endif - kmsg_dumper->active = true; - - while (kmsg_dump_get_line(kmsg_dumper, true, line, sizeof(line), &len)) { - line[len] = '\0'; - mutex_lock(&phx_wf_mutex); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - - if (len != ksys_write(file_fd, line, len)) -#else - if (len != sys_write(file_fd, line, len)) -#endif - { - PHX_KLOG_ERROR("sys_write %s failed, error: %lu\n", filepath, len); - mutex_unlock(&phx_wf_mutex); - result = -1; - goto phx_bail; - } - - mutex_unlock(&phx_wf_mutex); - } - - result = 0; - -phx_bail: - set_fs(old_fs); - - if (file_fd >= 0) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_close(file_fd); - ksys_sync(); -#else - sys_close(file_fd); - sys_sync(); -#endif - } - - return result; -} - - -static void phx_format_keyinfo(const phx_keyinfo *kinfo, char *buffer, - int buffer_size) -{ - const phx_baseinfo *binfo = kinfo->baseinfo; - snprintf(buffer, buffer_size, PHX_KEYINFO_FORMAT, binfo->stage, binfo->error, - binfo->happen_time, - kinfo->is_system_boot_completed); -} - -static int phx_generate_keyinfo(const char *keyinfo_file, - const phx_keyinfo *kinfo) -{ - mm_segment_t old_fs; - int fd = -1; - size_t bytes_to_write = 0; - int result = -1; - char *buf = NULL; - old_fs = get_fs(); - set_fs(KERNEL_DS); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - fd = ksys_open(keyinfo_file, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); -#else - fd = sys_open(keyinfo_file, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); -#endif - - if (fd < 0) { - PHX_KLOG_ERROR("sys_open %s failed, error: %d\n", keyinfo_file, fd); - result = -1; - goto phx_bail; - } - - buf = (char *)kmalloc(KEYINFO_FILE_SIZE, GFP_KERNEL); - - if (!buf) { - PHX_KLOG_ERROR("kmalloc %u bytes failed\n", KEYINFO_FILE_SIZE); - result = -1; - goto phx_bail; - } - - memset(buf, 0, KEYINFO_FILE_SIZE); - phx_format_keyinfo(kinfo, buf, KEYINFO_FILE_SIZE); - bytes_to_write = strlen(buf); - - if (!bytes_to_write) { - result = -1; - goto phx_bail; - } - - mutex_lock(&phx_wf_mutex); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - - if (strlen(buf) != (bytes_to_write = ksys_write(fd, buf, strlen(buf)))) -#else - if (strlen(buf) != (bytes_to_write = sys_write(fd, buf, strlen(buf)))) -#endif - { - PHX_KLOG_ERROR("sys_write %s failed, error: %lu\n", keyinfo_file, - bytes_to_write); - mutex_unlock(&phx_wf_mutex); - result = -1; - goto phx_bail; - } - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_chown(keyinfo_file, AID_SYSTEM, AID_SYSTEM); -#else - sys_chown(keyinfo_file, AID_SYSTEM, AID_SYSTEM); -#endif - mutex_unlock(&phx_wf_mutex); - result = 0; - -phx_bail: - set_fs(old_fs); - - if (fd >= 0) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_close(fd); - ksys_sync(); -#else - sys_close(fd); - sys_sync(); -#endif - } - - if (buf) { - kfree(buf); - buf = NULL; - } - - return result; -} - -static int creds_change_dac(void) -{ - /* need to add cred for Kernel RW file in SELINUX */ - struct cred *new; - int rc = 0; - - pr_info("creds_change_dac enter!\n"); - - new = prepare_creds(); - - if (!new) { - pr_err("opmonitor_boot_kthread init err!\n"); - rc = -1; - return rc; - } - - cap_raise(new->cap_effective, CAP_DAC_OVERRIDE); - cap_raise(new->cap_effective, CAP_DAC_READ_SEARCH); - - rc = commit_creds(new); - - return rc; -} - -static int creds_change_id(void) -{ - /* need to add cred for Kernel RW file in SELINUX */ - struct cred *new; - int rc = 0; - - pr_info("creds_change_id enter!\n"); - - new = prepare_creds(); - - if (!new) { - pr_err("opmonitor_boot_kthread init err!\n"); - rc = -1; - return rc; - } - - new->fsuid = new->euid = KUIDT_INIT(1000); - - rc = commit_creds(new); - - return rc; -} - -static int phx_generate_ke_keyinfo(void) -{ - int result = -1; - phx_keyinfo *kinfo = (phx_keyinfo *)kmalloc(sizeof(phx_keyinfo), GFP_KERNEL); - - if (!kinfo) { - PHX_KLOG_ERROR("kmalloc %lu bytes failed\n", sizeof(phx_keyinfo)); - return result; - } - - creds_change_dac(); - creds_change_id(); - - memset(kinfo, 0 , sizeof(phx_keyinfo)); - phx_get_base_info(&kinfo->baseinfo); - kinfo->is_system_boot_completed = phx_is_system_boot_completed(); - result = phx_generate_keyinfo(FILE_KERNEL_EXPETION_INFO, kinfo); - kfree(kinfo); - return result; -} - -static int phx_collect_ke_log(void *args) -{ - int result = -1; - - if (0 != phx_generate_ke_keyinfo()) { - PHX_KLOG_ERROR("generate panic keyinfo failed\n"); - result = -1; - goto phx_bail; - } - - /*we boot in post-fs-data, save kmsg to file*/ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - - if (!ksys_access(PHOENIX_TEMP_DIR, 0)) -#else - if (!sys_access(PHOENIX_TEMP_DIR, 0)) -#endif - { - if (0 != dump_kmsg(FILE_DMESG, 0, &phx_kmsg_dumper)) { - PHX_KLOG_ERROR("dump kmsg failed\n"); - result = -1; - goto phx_bail; - } - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - ksys_chown(FILE_DMESG, AID_SYSTEM, AID_SYSTEM); -#else - sys_chown(FILE_DMESG, AID_SYSTEM, AID_SYSTEM); -#endif - } - - /*TODO: we have not boot in post-fs-data, save kmsg to raw block*/ - -phx_bail: - complete(&phx_comp); - return result; -} - -static void phx_dump_kernel_exception_log(const char *error) -{ - struct task_struct *tsk; - tsk = kthread_run(phx_collect_ke_log, NULL, "phx_collect_ke_log"); - - if (IS_ERR(tsk)) { - PHX_KLOG_ERROR("create kernel thread phx_collect_ke_log failed\n"); - return; - } - - if (!wait_for_completion_timeout(&phx_comp, KE_LOG_GENERATE_TIMEOUT)) { - PHX_KLOG_ERROR("collect kernel exception %s log timeout\n", error); - } -} - -void phx_log_dump(const char *phx_error) -{ - size_t i = 0; - - for (; i < ARRAY_SIZE(phx_log_dumper_mapping); i++) { - if (!strcmp(phx_log_dumper_mapping[i].action, phx_error)) { - phx_log_dumper_mapping[i].map_func(phx_error); - return; - } - } -} - -EXPORT_SYMBOL(phx_log_dump); diff --git a/drivers/soc/oplus/system/oplus_phoenix/phoenix_watchdog.c b/drivers/soc/oplus/system/oplus_phoenix/phoenix_watchdog.c deleted file mode 100755 index 1ad2f68a978b..000000000000 --- a/drivers/soc/oplus/system/oplus_phoenix/phoenix_watchdog.c +++ /dev/null @@ -1,300 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -############################################################################### -## File: phoenix_watchdog.c -## Description : add for project phenix(hang ) -## -## Version: 1.0 -################################################################################ -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "oplus_phoenix.h" - -#define DELAY_TIME 30 -#define MAX_CMD_LENGTH 32 -#define DEFAULT_PHX_WD_PET_TIME (60 * 4) - -static int hang_oplus_main_on = 1; /*default on*/ -int hang_oplus_recovery_method = RESTART_AND_RECOVERY; -static int phx_hlos_wd_pet_time = DEFAULT_PHX_WD_PET_TIME; -static char buildvariant[20]; -static char hardwaretype[16]; - -static int __init phoenix_get_hardwaretype(char *line) -{ - strlcpy(hardwaretype, line, sizeof(hardwaretype)); - return 1; -} - -__setup("androidboot.hardware=", phoenix_get_hardwaretype); - -static int __init phoenix_get_buildvariant(char *line) -{ - strlcpy(buildvariant, line, sizeof(buildvariant)); - return 1; -} - -__setup("buildvariant=", phoenix_get_buildvariant); - -static inline bool is_userdebug(void) -{ - static const char typeuserdebug[] = "userdebug"; - - return !strncmp(buildvariant, typeuserdebug, sizeof(typeuserdebug)); -} - -static void reinitialze_pet_time_for_debug_build(void) -{ - if (is_userdebug()) { - phx_hlos_wd_pet_time = 60 * 5; - } - - if (AGING == get_eng_version()) { - phx_hlos_wd_pet_time = 60 * 10; /*aging test version*/ - } - -#ifdef CONFIG_MEMLEAK_DETECT_THREAD - - if (AGING != get_eng_version()) { - phx_hlos_wd_pet_time += 60 * 5; - } - -#endif -} - -static int __init hang_oplus_main_on_init(char *str) -{ - get_option(&str, &hang_oplus_main_on); - - pr_info("hang_oplus_main_on %d\n", hang_oplus_main_on); - - return 1; -} -__setup("phx_rus_conf.main_on=", hang_oplus_main_on_init); - -static int __init hang_oplus_recovery_method_init(char *str) -{ - get_option(&str, &hang_oplus_recovery_method); - - pr_info("hang_oplus_recovery_method %d\n", hang_oplus_recovery_method); - - return 1; -} -__setup("phx_rus_conf.recovery_method=", hang_oplus_recovery_method_init); - -static int __init phx_hlos_wd_pet_time_init(char *str) -{ - get_option(&str, &phx_hlos_wd_pet_time); - - pr_info("phx_hlos_wd_pet_time %d\n", phx_hlos_wd_pet_time); - - return 1; -} -__setup("phx_rus_conf.kernel_time=", phx_hlos_wd_pet_time_init); - -int is_phoenix_enable(void) -{ - return hang_oplus_main_on; -} - -EXPORT_SYMBOL(is_phoenix_enable); - -int phx_is_long_time(void) -{ - struct file *opfile; - ssize_t size; - loff_t offsize; - char data_info[16] = {'\0'}; - mm_segment_t old_fs; - - opfile = filp_open("/proc/opbootfrom", O_RDONLY, 0444); - - if (IS_ERR(opfile)) { - PHX_KLOG_ERROR("open /proc/opbootfrom error:\n"); - return -1; - } - - offsize = 0; - old_fs = get_fs(); - set_fs(KERNEL_DS); - size = vfs_read(opfile, data_info, sizeof(data_info), &offsize); - - if (size < 0) { - PHX_KLOG_ERROR("data_info %s size %ld", data_info, size); - set_fs(old_fs); - return -1; - } - - set_fs(old_fs); - filp_close(opfile, NULL); - - if (strncmp(data_info, "normal", 6) == 0) { - return 0; - } - - return 1; -} - -static int phx_is_boot_into_native(void) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - return !ksys_access("/proc/opbootfrom", 0); -#else - return !sys_access("/proc/opbootfrom", 0); -#endif -} - -static int phx_is_gsi_test(void) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - return ksys_access("/system/system_ext/etc/init/init.oplus.rootdir.rc", 0); -#else - return sys_access("/system/system_ext/etc/init/init.oplus.rootdir.rc", 0); -#endif -} - -static int phx_pet(void) -{ - if (phx_is_long_time()) { - schedule_timeout_interruptible(phx_hlos_wd_pet_time * HZ); - } - - PHX_KLOG_INFO("phoenix watchdog pet!\n"); - - if (!phx_is_system_boot_completed()) { - /*check if this version is google gsi version*/ - if (phx_is_boot_into_native() && phx_is_gsi_test()) { - return 0; - } - - if (is_userdebug() || (get_eng_version() == AGING)) { - PHX_KLOG_INFO("will not set ERROR_HANG_OPLUS with userdebug/aging version\n"); - return 0; - } - - phx_set_boot_error(ERROR_HANG_OPLUS); - } - - return 0; -} - -/*start phoenix high level os watchdog*/ -static int phoenix_watchdog_kthread(void *dummy) -{ - schedule_timeout_interruptible(phx_hlos_wd_pet_time * HZ); - phx_pet(); - return 0; -} - -static int phx_is_normal_mode_qcom(void) -{ - int i; - char *substr; - char boot_mode[MAX_CMD_LENGTH + 1]; - const char *const normal_boot_mode_list[] = {"normal", "reboot", "kernel"}; - substr = strstr(boot_command_line, "androidboot.mode="); - - if (substr) { - substr += strlen("androidboot.mode="); - - for (i = 0; substr[i] != ' ' && i < MAX_CMD_LENGTH && substr[i] != '\0'; i++) { - boot_mode[i] = substr[i]; - } - - boot_mode[i] = '\0'; - - if (MSM_BOOT_MODE__NORMAL != get_boot_mode()) { - return 0; - } - - for (i = 0; i < ARRAY_SIZE(normal_boot_mode_list); i++) { - if (!strcmp(boot_mode, normal_boot_mode_list[i])) { - return 1; - } - } - } - - return 0; -} - -/*copy mtk_boot_common.h*/ -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 -static int phx_is_normal_mode_mtk(void) -{ - int mtk_boot_mode = 0; - - mtk_boot_mode = get_boot_mode(); - PHX_KLOG_INFO("mtk_boot_mode: %d\n", mtk_boot_mode); - - if ((mtk_boot_mode == NORMAL_BOOT) || (mtk_boot_mode == ALARM_BOOT)) { - return 1; - - } else { - return 0; - } -} - -static int phx_is_qcom_platform(void) -{ - const char *platform_name; - char *substr; - int i; - const char *const qcom_platform_keywords[] = {"Qualcomm", "SDM"}; - static const char qcomhardware[] = "qcom"; - - platform_name = of_flat_dt_get_machine_name(); - - for (i = 0; i < ARRAY_SIZE(qcom_platform_keywords); i++) { - substr = strstr(platform_name, qcom_platform_keywords[i]); - - if (substr) { - PHX_KLOG_INFO("Qcom platform"); - return 1; - } - } - - if (!strncmp(hardwaretype, qcomhardware, sizeof(qcomhardware))) { - PHX_KLOG_INFO("Qcom platform hardware"); - return 1; - } - - PHX_KLOG_INFO("MTK platform"); - return 0; -} - -static int __init phx_is_normal_mode(void) -{ - return phx_is_qcom_platform() ? phx_is_normal_mode_qcom() : - phx_is_normal_mode_mtk(); -} - -static int __init phoenix_hlos_watchdog_init(void) -{ - int ret = 0; - PHX_KLOG_INFO("phoenix hlos watchdog: %s\n", hang_oplus_main_on ? "on" : "off"); - - if (hang_oplus_main_on && phx_is_normal_mode()) { - reinitialze_pet_time_for_debug_build(); - PHX_KLOG_INFO("phoenix hlos watchdog pet time: %d\n", phx_hlos_wd_pet_time); - kthread_run(phoenix_watchdog_kthread, NULL, "phoenix_hlos_watchdog"); - } - - return ret; -} -arch_initcall_sync(phoenix_hlos_watchdog_init); - -MODULE_DESCRIPTION("PHOENIX HLOS WATCHDOG"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Bright.Zhang "); diff --git a/drivers/soc/oplus/system/oplus_pmic_monitor/Kconfig b/drivers/soc/oplus/system/oplus_pmic_monitor/Kconfig deleted file mode 100755 index 69814fb04ce7..000000000000 --- a/drivers/soc/oplus/system/oplus_pmic_monitor/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#change 'y' to 'n', if you want fo close pmic monitor -config OPLUS_FEATURE_PMIC_MONITOR - tristate "oplus pmic monitor" - default n - help - define this config to init oplus pmic monitor. diff --git a/drivers/soc/oplus/system/oplus_pmic_monitor/Makefile b/drivers/soc/oplus/system/oplus_pmic_monitor/Makefile deleted file mode 100755 index c26f7652fc20..000000000000 --- a/drivers/soc/oplus/system/oplus_pmic_monitor/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_PMIC_MONITOR) += pmic_monitor.o -pmic_monitor-objs := oplus_pmic_info_smem.o main.o - - diff --git a/drivers/soc/oplus/system/oplus_pmic_monitor/main.c b/drivers/soc/oplus/system/oplus_pmic_monitor/main.c deleted file mode 100755 index 5f81dc2645e6..000000000000 --- a/drivers/soc/oplus/system/oplus_pmic_monitor/main.c +++ /dev/null @@ -1,1126 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include "oplus_pmic_info.h" - -/**************** PMIC GEN2 Begin ****************/ -/**********************************************/ -static ssize_t pmic_history_magic_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[16] = {0}; - int len = 0; - struct PMICHistoryKernelStruct *pmic_history_ptr = NULL; - - pmic_history_ptr = (struct PMICHistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 16 - len, "NULL\n"); - - } else { - len += snprintf(&page[len], 16 - len, "%s\n", pmic_history_ptr->pmic_magic); - } - - memcpy(buf, page, len); - return len; -} -pmic_info_attr_ro(pmic_history_magic); - -/**********************************************/ - -/**********************************************/ -static ssize_t pmic_history_count_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[16] = {0}; - int len = 0; - struct PMICHistoryKernelStruct *pmic_history_ptr = NULL; - - pmic_history_ptr = (struct PMICHistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 16 - len, "NULL\n"); - - } else { - len += snprintf(&page[len], 16 - len, "%ld\n", pmic_history_ptr->log_count); - } - - memcpy(buf, page, len); - return len; -} -pmic_info_attr_ro(pmic_history_count); - -/**********************************************/ -static char *const pon_poff_reason_str[] = { - [0] = "POWER OFF by N/A 0 ", - [1] = "POWER OFF by N/A 1 ", - [2] = "POWER OFF by RAW_XVDD_RB_OCCURED ", - [3] = "POWER OFF by RAW_DVDD_RB_OCCURED ", - [4] = "POWER OFF by IMMEDIATE_XVDD_SHUTDOWN ", - [5] = "POWER OFF by S3_RESET ", - [6] = "POWER OFF by FAULT_SEQ ", - [7] = "POWER OFF by POFF_SEQ ", -}; - -static char *const pon_poff_reason1_str[] = { - [0] = ":SOFT (Software)", - [1] = ":PS_HOLD (PS_HOLD/MSM Controlled Shutdown)", - [2] = ":PMIC_WD (PMIC Watchdog)", - [3] = ":GP1 (Keypad_Reset1)", - [4] = ":GP2 (Keypad_Reset2)", - [5] = ":KPDPWR_AND_RESIN (Power Key and Reset Line)", - [6] = ":RESIN_N (Reset Line/Volume Down Key)", - [7] = ":KPDPWR_N (Long Power Key Hold)", -}; - -static char *const pon_fault_reason_str[] = { - [0] = ":GP_FAULT0", - [1] = ":GP_FAULT1", - [2] = ":GP_FAULT2", - [3] = ":GP_FAULT3", - [4] = ":MBG_FAULT", - [5] = ":OVLO", - [6] = ":UVLO", - [7] = ":AVDD_RB", - [8] = ":N/A 8", - [9] = ":N/A 9", - [10] = ":N/A 10", - [11] = ":FAULT_N", - [12] = ":PBS_WATCHDOG_TO", - [13] = ":PBS_NACK", - [14] = ":RESTART_PON", - [15] = ":OTST3", -}; - -static char *const pon_s3_reset_reason[] = { - [0] = ":N/A 0", - [1] = ":N/A 1", - [2] = ":N/A 2", - [3] = ":N/A 3", - [4] = ":FAULT_N", - [5] = ":PBS_WATCHDOG_TO", - [6] = ":PBS_NACK", - [7] = ":KPDPWR_ANDOR_RESIN", -}; - -static char *const unknow_reason_str = ":UNKNOW REASON"; -static char *const no_L2_reason_str = ":don't have L2 reason"; - -static ssize_t poff_reason_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[512] = {0}; - int len = 0; - u8 L1_poff_index = 0, L2_poff_index = 0; - char *L1_str_ptr = unknow_reason_str; - char *L2_str_ptr = unknow_reason_str; - struct PMICHistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICRecordKernelStruct pmic_first_record; - u8 pmic_device_index = 0; - u64 pmic_history_count = 0; - - pmic_history_ptr = (struct PMICHistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 512 - len, "PMIC|0|0x00|0x0000|NULL\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - pmic_history_count = pmic_history_ptr->log_count; - - for (pmic_device_index = 0; pmic_device_index < 8; pmic_device_index++) { - if (DATA_VALID_FLAG != - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].data_is_valid) { - continue; - } - - L1_poff_index = ffs( - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_OFF_REASON); - - switch (L1_poff_index) { - case INDEX_RAW_XVDD_RB_OCCURED: - case INDEX_RAW_DVDD_RB_OCCURED: - case INDEX_IMMEDIATE_XVDD_SHUTDOWN: - L1_str_ptr = pon_poff_reason_str[L1_poff_index - 1]; - L2_poff_index = 0; - L2_str_ptr = no_L2_reason_str; - break; - - case INDEX_S3_RESET: - L1_str_ptr = pon_poff_reason_str[L1_poff_index - 1]; - L2_poff_index = ffs( - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_S3_RESET_REASON); - - if (L2_poff_index <= 0 || L2_poff_index > 8) { - L2_str_ptr = unknow_reason_str; - - } else { - L2_str_ptr = pon_s3_reset_reason[L2_poff_index - 1]; - } - - break; - - case INDEX_FAULT_SEQ: - L1_str_ptr = pon_poff_reason_str[L1_poff_index - 1]; - L2_poff_index = ffs(( - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_FAULT_REASON2 << - 8) - | (pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_FAULT_REASON1) -); - - if (L2_poff_index <= 0 || L2_poff_index > 16) { - L2_str_ptr = unknow_reason_str; - - } else { - L2_str_ptr = pon_fault_reason_str[L2_poff_index - 1]; - } - - break; - - case INDEX_POFF_SEQ: - L1_str_ptr = pon_poff_reason_str[L1_poff_index - 1]; - L2_poff_index = ffs( - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_POFF_REASON1); - - if (L2_poff_index <= 0 || L2_poff_index > 8) { - L2_str_ptr = unknow_reason_str; - - } else { - L2_str_ptr = pon_poff_reason1_str[L2_poff_index - 1]; - } - - break; - - default: - L1_poff_index = 0; - L2_poff_index = 0; - L1_str_ptr = unknow_reason_str; - L2_str_ptr = unknow_reason_str; - break; - } - - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|0x%04X|%s %s (1/%ld)\n", - pmic_device_index, - L1_poff_index == 0 ? 0 : 0x1 << (L1_poff_index - 1), - L2_poff_index == 0 ? 0 : 0x1 << (L2_poff_index - 1), - L1_str_ptr, - L2_str_ptr, - pmic_history_count); - } - - memcpy(buf, page, len); - return len; -} -pmic_info_attr_ro(poff_reason); -/**********************************************/ - -/**********************************************/ -static char *const pon_pon_reason1_str[] = { - [0] = "POWER ON by HARD_RESET", - [1] = "POWER ON by SMPL", - [2] = "POWER ON by RTC", - [3] = "POWER ON by DC_CHG", - [4] = "POWER ON by USB_CHG", - [5] = "POWER ON by PON1", - [6] = "POWER ON by CBLPWR_N", - [7] = "POWER ON by KPDPWR_N", -}; - -static char *const pon_warm_reset_reason1_str[] = { - [0] = ":SOFT", - [1] = ":PS_HOLD", - [2] = ":PMIC_WD", - [3] = ":GP1", - [4] = ":GP2", - [5] = ":KPDPWR_AND_RESIN", - [6] = ":RESIN_N", - [7] = ":KPDPWR_N", -}; - -#define QPNP_WARM_SEQ BIT(6) - -static ssize_t pon_reason_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[512] = {0}; - int len = 0; - struct PMICHistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICRecordKernelStruct pmic_first_record; - u8 pmic_device_index = 0; - u8 pon_index = 0, pon_warm_reset_index = 0; - u8 pon_pon_reason1_reg_vaule = 0, pon_warm_reset_reason1 = 0; - u64 pmic_history_count = 0; - - pmic_history_ptr = (struct PMICHistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 512 - len, "PMIC|0|0x000000000000\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - pmic_history_count = pmic_history_ptr->log_count; - - for (pmic_device_index = 0; pmic_device_index < 8; pmic_device_index++) { - if (DATA_VALID_FLAG != - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].data_is_valid) { - continue; - } - - pon_pon_reason1_reg_vaule = - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_PON_REASON1; - pon_index = ffs(pon_pon_reason1_reg_vaule); - - if (0 == pon_index) { - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|NKNOW PON REASON\n", - pmic_device_index, 0x0); - continue; - } - - if (QPNP_WARM_SEQ & - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_ON_REASON) { - pon_warm_reset_reason1 = - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].PON_WARM_RESET_REASON1; - pon_warm_reset_index = ffs(pon_pon_reason1_reg_vaule); - len += snprintf(&page[len], 512 - len, - "PMIC|%d|0x%02X|WARM_SEQ:%s %s (1/%ld)\n", - pmic_device_index, - pon_pon_reason1_reg_vaule, - pon_pon_reason1_str[pon_index - 1], - 0 == pon_warm_reset_index ? "NULL" : - pon_warm_reset_reason1_str[pon_warm_reset_index - 1], - pmic_history_count); - - } else { - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|PON_SEQ:%s (1/%ld)\n", - pmic_device_index, - pon_pon_reason1_reg_vaule, - pon_pon_reason1_str[pon_index - 1], - pmic_history_count); - } - } - - memcpy(buf, page, len); - return len; -} -pmic_info_attr_ro(pon_reason); -/**********************************************/ - -/**********************************************/ -static ssize_t ocp_status_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[256] = {0}; - int len = 0; - struct PMICHistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICRecordKernelStruct pmic_first_record; - u8 pmic_device_index = 0; - - pmic_history_ptr = (struct PMICHistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 256 - len, "PMIC|0|0x000000000000\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - - for (pmic_device_index = 0; pmic_device_index < 8; pmic_device_index++) { - if (DATA_VALID_FLAG != - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].data_is_valid) { - continue; - } - - len += snprintf(&page[len], 256 - len, "PMIC|%d|0x%08X%02X%02X\n", - pmic_device_index, - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].ldo_ocp_status, - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].spms_ocp_status, - pmic_first_record.pmic_pon_poff_reason[pmic_device_index].bob_ocp_status); - } - - memcpy(buf, page, len); - return len; -} -pmic_info_attr_ro(ocp_status); - -static struct attribute *gen2[] = { - &pmic_history_magic_attr.attr, - &pmic_history_count_attr.attr, - &poff_reason_attr.attr, - &pon_reason_attr.attr, - &ocp_status_attr.attr, - NULL, -}; - -static struct attribute_group attr_group = { - .attrs = gen2, -}; - -/**********************************************/ -/**************** PMIC GEN2 End ****************/ - -/**************** PMIC GEN3 Begin ****************/ - -enum pmic_pon_state { - PMIC_PON_STATE_FAULT0 = 0x0, - PMIC_PON_STATE_PON = 0x1, - PMIC_PON_STATE_POFF = 0x2, - PMIC_PON_STATE_ON = 0x3, - PMIC_PON_STATE_RESET = 0x4, - PMIC_PON_STATE_OFF = 0x5, - PMIC_PON_STATE_FAULT6 = 0x6, - PMIC_PON_STATE_WARM_RESET = 0x7, - PMIC_PON_STATE_MAX = 0x08, -}; - -static const char *const pmic_pon_state_label[] = { - [PMIC_PON_STATE_FAULT0] = "FAULT", - [PMIC_PON_STATE_PON] = "PON", - [PMIC_PON_STATE_POFF] = "POFF", - [PMIC_PON_STATE_ON] = "ON", - [PMIC_PON_STATE_RESET] = "RESET", - [PMIC_PON_STATE_OFF] = "OFF", - [PMIC_PON_STATE_FAULT6] = "FAULT", - [PMIC_PON_STATE_WARM_RESET] = "WARM_RESET", -}; - -enum pmic_pon_event { - PMIC_PON_EVENT_PON_TRIGGER_RECEIVED = 0x01, - PMIC_PON_EVENT_OTP_COPY_COMPLETE = 0x02, - PMIC_PON_EVENT_TRIM_COMPLETE = 0x03, - PMIC_PON_EVENT_XVLO_CHECK_COMPLETE = 0x04, - PMIC_PON_EVENT_PMIC_CHECK_COMPLETE = 0x05, - PMIC_PON_EVENT_RESET_TRIGGER_RECEIVED = 0x06, - PMIC_PON_EVENT_RESET_TYPE = 0x07, - PMIC_PON_EVENT_WARM_RESET_COUNT = 0x08, - PMIC_PON_EVENT_FAULT_REASON_1_2 = 0x09, - PMIC_PON_EVENT_FAULT_REASON_3 = 0x0A, - PMIC_PON_EVENT_PBS_PC_DURING_FAULT = 0x0B, - PMIC_PON_EVENT_FUNDAMENTAL_RESET = 0x0C, - PMIC_PON_EVENT_PON_SEQ_START = 0x0D, - PMIC_PON_EVENT_PON_SUCCESS = 0x0E, - PMIC_PON_EVENT_WAITING_ON_PSHOLD = 0x0F, - PMIC_PON_EVENT_PMIC_SID1_FAULT = 0x10, - PMIC_PON_EVENT_PMIC_SID2_FAULT = 0x11, - PMIC_PON_EVENT_PMIC_SID3_FAULT = 0x12, - PMIC_PON_EVENT_PMIC_SID4_FAULT = 0x13, - PMIC_PON_EVENT_PMIC_SID5_FAULT = 0x14, - PMIC_PON_EVENT_PMIC_VREG_READY_CHECK = 0x15, - PMIC_PON_EVENT_PMIC_MAX = 0x16, -}; - -enum pmic_pon_reset_type { - PMIC_PON_RESET_TYPE_WARM_RESET = 0x1, - PMIC_PON_RESET_TYPE_SHUTDOWN = 0x4, - PMIC_PON_RESET_TYPE_HARD_RESET = 0x7, -}; - -static const char *const pmic_pon_reset_type_label[] = { - [PMIC_PON_RESET_TYPE_WARM_RESET] = "WARM_RESET", - [PMIC_PON_RESET_TYPE_SHUTDOWN] = "SHUTDOWN", - [PMIC_PON_RESET_TYPE_HARD_RESET] = "HARD_RESET", -}; - -static const char *const pmic_pon_fault_reason1[8] = { - [0] = "GP_FAULT0", - [1] = "GP_FAULT1", - [2] = "GP_FAULT2", - [3] = "GP_FAULT3", - [4] = "MBG_FAULT", - [5] = "OVLO", - [6] = "UVLO", - [7] = "AVDD_RB", -}; - -static const char *const pmic_pon_fault_reason2[8] = { - [0] = "UNKNOWN(0)", - [1] = "UNKNOWN(1)", - [2] = "UNKNOWN(2)", - [3] = "FAULT_N", - [4] = "FAULT_WATCHDOG", - [5] = "PBS_NACK", - [6] = "RESTART_PON", - [7] = "OVERTEMP_STAGE3", -}; - -static const char *const pmic_pon_fault_reason3[8] = { - [0] = "GP_FAULT4", - [1] = "GP_FAULT5", - [2] = "GP_FAULT6", - [3] = "GP_FAULT7", - [4] = "GP_FAULT8", - [5] = "GP_FAULT9", - [6] = "GP_FAULT10", - [7] = "GP_FAULT11", -}; - -static const char *const pmic_pon_s3_reset_reason[8] = { - [0] = "UNKNOWN(0)", - [1] = "UNKNOWN(1)", - [2] = "UNKNOWN(2)", - [3] = "UNKNOWN(3)", - [4] = "FAULT_N", - [5] = "FAULT_WATCHDOG", - [6] = "PBS_NACK", - [7] = "KPDPWR_AND/OR_RESIN", -}; - -static const char *const pmic_pon_pon_pbl_status[8] = { - [0] = "UNKNOWN(0)", - [1] = "UNKNOWN(1)", - [2] = "UNKNOWN(2)", - [3] = "UNKNOWN(3)", - [4] = "UNKNOWN(4)", - [5] = "UNKNOWN(5)", - [6] = "XVDD", - [7] = "DVDD", -}; - -struct pmic_pon_trigger_mapping { - u16 code; - const char *label; -}; - -static const struct pmic_pon_trigger_mapping pmic_pon_pon_trigger_map[] = { - {0x0084, "PS_HOLD"}, - {0x0085, "HARD_RESET"}, - {0x0086, "RESIN_N"}, - {0x0087, "KPDPWR_N"}, - {0x0621, "RTC_ALARM"}, - {0x0640, "SMPL"}, - {0x18C0, "PMIC_SID1_GPIO5"}, - {0x31C2, "USB_CHARGER"}, -}; - -static const struct pmic_pon_trigger_mapping pmic_pon_reset_trigger_map[] = { - {0x0080, "KPDPWR_N_S2"}, - {0x0081, "RESIN_N_S2"}, - {0x0082, "KPDPWR_N_AND_RESIN_N_S2"}, - {0x0083, "PMIC_WATCHDOG_S2"}, - {0x0084, "PS_HOLD"}, - {0x0085, "SW_RESET"}, - {0x0086, "RESIN_N_DEBOUNCE"}, - {0x0087, "KPDPWR_N_DEBOUNCE"}, - {0x21E3, "PMIC_SID2_BCL_ALARM"}, - {0x31F5, "PMIC_SID3_BCL_ALARM"}, - {0x11D0, "PMIC_SID1_OCP"}, - {0x21D0, "PMIC_SID2_OCP"}, - {0x41D0, "PMIC_SID4_OCP"}, - {0x51D0, "PMIC_SID5_OCP"}, -}; - -static int pmic_pon_log_print_reason(char *buf, int buf_size, u8 data, - const char *const *reason) -{ - int pos = 0; - int i; - bool first; - - if (data == 0) { - pos += scnprintf(buf + pos, buf_size - pos, "None"); - - } else { - first = true; - - for (i = 0; i < 8; i++) { - if (data & BIT(i)) { - pos += scnprintf(buf + pos, buf_size - pos, - "%s%s", - (first ? "" : ", "), reason[i]); - first = false; - } - } - } - - return pos; -} - -static int get_pon_log_by_state_event(u8 state , u8 event , - int skip , struct PMICGen3RecordKernelStruct *pmic_record_ptr , - struct PmicGen3PonStateStruct *pon_log) -{ - int i; - u8 tmp_state; - u8 tmp_event; - - if ((NULL == pmic_record_ptr) || (NULL == pon_log)) { - return -1; - } - - for (i = 0 ; i < MAX_STATE_RECORDS ; i++) { - tmp_state = pmic_record_ptr->pmic_state_machine_log[i].state; - tmp_event = pmic_record_ptr->pmic_state_machine_log[i].event; - - if (0 == tmp_state && 0 == tmp_event) { - pon_log->state = 0; - pon_log->event = 0; - pon_log->data1 = 0; - pon_log->data0 = 0; - return -1; - } - - if (((state == tmp_state) && (event == tmp_event)) - || /* match state & event */ - ((state == PMIC_PON_STATE_MAX) && (event == tmp_event)) || /* match event */ - ((state == tmp_state) - && (event == PMIC_PON_EVENT_PMIC_MAX)) /* match state */) { - if (skip > 0) { - skip = skip - 1; - - } else { - *pon_log = pmic_record_ptr->pmic_state_machine_log[i]; - return i; - } - } - } - - return -1; -} - -#define BUF_SIZE 128 -static int pmic_pon_log_parse(struct PmicGen3PonStateStruct *pon_state_machine, - char *parse_log) -{ - char buf[BUF_SIZE]; - const char *label = NULL; - int pos = 0; - int i = 0; - u16 data; - - if (NULL == pon_state_machine || NULL == parse_log) { - return -1; - } - - data = (pon_state_machine->data1 << 8) | pon_state_machine->data0; - buf[0] = '\0'; - - switch (pon_state_machine->event) { - case PMIC_PON_EVENT_PON_TRIGGER_RECEIVED: - for (i = 0; i < ARRAY_SIZE(pmic_pon_pon_trigger_map); i++) { - if (pmic_pon_pon_trigger_map[i].code == data) { - label = pmic_pon_pon_trigger_map[i].label; - break; - } - } - - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "PON Trigger: "); - - if (label) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, "%s", - label); - - } else { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "SID=0x%X, PID=0x%02X, IRQ=0x%X", - pon_state_machine->data1 >> 4, (data >> 4) & 0xFF, - pon_state_machine->data0 & 0x7); - } - - break; - - case PMIC_PON_EVENT_OTP_COPY_COMPLETE: - scnprintf(buf, BUF_SIZE, - "OTP Copy Complete: last addr written=0x%04X", - data); - break; - - case PMIC_PON_EVENT_TRIM_COMPLETE: - scnprintf(buf, BUF_SIZE, "Trim Complete: %u bytes written", - data); - break; - - case PMIC_PON_EVENT_XVLO_CHECK_COMPLETE: - scnprintf(buf, BUF_SIZE, "XVLO Check Complete"); - break; - - case PMIC_PON_EVENT_PMIC_CHECK_COMPLETE: - scnprintf(buf, BUF_SIZE, "PMICs Detected: SID Mask=0x%04X", - data); - break; - - case PMIC_PON_EVENT_RESET_TRIGGER_RECEIVED: - for (i = 0; i < ARRAY_SIZE(pmic_pon_reset_trigger_map); i++) { - if (pmic_pon_reset_trigger_map[i].code == data) { - label = pmic_pon_reset_trigger_map[i].label; - break; - } - } - - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "Reset Trigger: "); - - if (label) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, "%s", - label); - - } else { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "SID=0x%X, PID=0x%02X, IRQ=0x%X", - pon_state_machine->data1 >> 4, (data >> 4) & 0xFF, - pon_state_machine->data0 & 0x7); - } - - break; - - case PMIC_PON_EVENT_RESET_TYPE: - if (pon_state_machine->data0 < ARRAY_SIZE(pmic_pon_reset_type_label) && - pmic_pon_reset_type_label[pon_state_machine->data0]) - scnprintf(buf, BUF_SIZE, "Reset Type: %s", - pmic_pon_reset_type_label[pon_state_machine->data0]); - - else - scnprintf(buf, BUF_SIZE, "Reset Type: UNKNOWN (%u)", - pon_state_machine->data0); - - break; - - case PMIC_PON_EVENT_WARM_RESET_COUNT: - scnprintf(buf, BUF_SIZE, "Warm Reset Count: %u", data); - break; - - case PMIC_PON_EVENT_FAULT_REASON_1_2: - if (pon_state_machine->data0) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "FAULT_REASON1="); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data0, - pmic_pon_fault_reason1); - } - - if (pon_state_machine->data1) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "%sFAULT_REASON2=", - (pon_state_machine->data0) - ? "; " : ""); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data1, - pmic_pon_fault_reason2); - } - - break; - - case PMIC_PON_EVENT_FAULT_REASON_3: - if (!pon_state_machine->data0) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, "FAULT_REASON3="); - } - - pos += pmic_pon_log_print_reason(buf + pos, BUF_SIZE - pos, - pon_state_machine->data0, pmic_pon_fault_reason3); - break; - - case PMIC_PON_EVENT_PBS_PC_DURING_FAULT: - scnprintf(buf, BUF_SIZE, "PBS PC at Fault: 0x%04X", data); - break; - - case PMIC_PON_EVENT_FUNDAMENTAL_RESET: - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "Fundamental Reset: "); - - if (pon_state_machine->data1) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "PON_PBL_STATUS="); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data1, - pmic_pon_pon_pbl_status); - } - - if (pon_state_machine->data0) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "%sS3_RESET_REASON=", - (pon_state_machine->data1) - ? "; " : ""); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data0, - pmic_pon_s3_reset_reason); - } - - break; - - case PMIC_PON_EVENT_PON_SEQ_START: - scnprintf(buf, BUF_SIZE, "Begin PON Sequence"); - break; - - case PMIC_PON_EVENT_PON_SUCCESS: - scnprintf(buf, BUF_SIZE, "PON Successful"); - break; - - case PMIC_PON_EVENT_WAITING_ON_PSHOLD: - scnprintf(buf, BUF_SIZE, "Waiting on PS_HOLD"); - break; - - case PMIC_PON_EVENT_PMIC_SID1_FAULT: - case PMIC_PON_EVENT_PMIC_SID2_FAULT: - case PMIC_PON_EVENT_PMIC_SID3_FAULT: - case PMIC_PON_EVENT_PMIC_SID4_FAULT: - case PMIC_PON_EVENT_PMIC_SID5_FAULT: - pos += scnprintf(buf + pos, BUF_SIZE - pos, "PMIC SID%u ", - pon_state_machine->event - PMIC_PON_EVENT_PMIC_SID1_FAULT + 1); - - if (pon_state_machine->data0) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "FAULT_REASON1="); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data0, - pmic_pon_fault_reason1); - } - - if (pon_state_machine->data1) { - pos += scnprintf(buf + pos, BUF_SIZE - pos, - "%sFAULT_REASON2=", - (pon_state_machine->data0) - ? "; " : ""); - pos += pmic_pon_log_print_reason(buf + pos, - BUF_SIZE - pos, pon_state_machine->data1, - pmic_pon_fault_reason2); - } - - break; - - case PMIC_PON_EVENT_PMIC_VREG_READY_CHECK: - scnprintf(buf, BUF_SIZE, "VREG Check: %sVREG_FAULT detected", - data ? "" : "No "); - break; - - default: - scnprintf(buf, BUF_SIZE, "Unknown Event (0x%02X): data=0x%04X", - pon_state_machine->event, data); - break; - } - - scnprintf(parse_log, BUF_SIZE, buf); - - return 0; -} - -/**********************************************/ -static ssize_t pmic_history_magic_gen3_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[16] = {0}; - int len = 0; - struct PMICGen3HistoryKernelStruct *pmic_history_ptr = NULL; - - pmic_history_ptr = (struct PMICGen3HistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 16 - len, "NULL\n"); - - } else { - len += snprintf(&page[len], 16 - len, "%s\n", pmic_history_ptr->pmic_magic); - } - - memcpy(buf, page, len); - return len; -} -pmic_gen3_info_attr_ro(pmic_history_magic); - -/**********************************************/ - -/**********************************************/ -static ssize_t pmic_history_count_gen3_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[16] = {0}; - int len = 0; - struct PMICGen3HistoryKernelStruct *pmic_history_ptr = NULL; - - pmic_history_ptr = (struct PMICGen3HistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 16 - len, "NULL\n"); - - } else { - len += snprintf(&page[len], 16 - len, "%ld\n", pmic_history_ptr->log_count); - } - - memcpy(buf, page, len); - return len; -} -pmic_gen3_info_attr_ro(pmic_history_count); - -/**********************************************/ -static ssize_t poff_reason_gen3_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[512] = {0}; - int len = 0, skip = 0; - u8 L1_poff_code = 0, L2_poff_code = 0; - struct PMICGen3HistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICGen3RecordKernelStruct pmic_first_record; - u64 pmic_history_count = 0; - struct PmicGen3PonStateStruct tmp_pon_log; - char parse_log_str1[128] = {0}; - char parse_log_str2[128] = {0}; - char parse_log_str3[128] = {0}; - - pmic_history_ptr = (struct PMICGen3HistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 512 - len, "PMIC|0|0x00|0x0000|NULL\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - pmic_history_count = pmic_history_ptr->log_count; - - /* Fundamental Reset */ - if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_MAX, /* ignore state */ - PMIC_PON_EVENT_FUNDAMENTAL_RESET, - 0, - &pmic_first_record, - &tmp_pon_log)) { - /* FAULT */ - L1_poff_code = 0x08; - L2_poff_code = tmp_pon_log.data1 << 8 | tmp_pon_log.data0; - pmic_pon_log_parse(&tmp_pon_log, parse_log_str1); - - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|0x%04X|%s (%ld)\n", - 0, - L1_poff_code, - L2_poff_code, - parse_log_str1, - pmic_history_count); - } - - /* ->fault(state:6) */ - else if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_FAULT6, - PMIC_PON_EVENT_FAULT_REASON_1_2, - 0, - &pmic_first_record, - &tmp_pon_log)) { - /* FAULT */ - L1_poff_code = 0x40; - L2_poff_code = tmp_pon_log.data1 << 8 | tmp_pon_log.data0; - pmic_pon_log_parse(&tmp_pon_log, parse_log_str1); - - /* PMIC0 fault log */ - if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_FAULT6, - PMIC_PON_EVENT_FAULT_REASON_3, - 0, - &pmic_first_record, - &tmp_pon_log)) { - pmic_pon_log_parse(&tmp_pon_log , parse_log_str2); - - } else { - snprintf(parse_log_str2, 32, "Can't find Fault_REASON3"); - } - - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|0x%04X|%s,%s (%ld)\n", - 0, - L1_poff_code, - L2_poff_code, - parse_log_str1, - parse_log_str2, - pmic_history_count); - } - - /* on(state:3)->reset(state:4) */ - else if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_RESET, - PMIC_PON_EVENT_RESET_TYPE, - 0, - &pmic_first_record, - &tmp_pon_log)) { - L1_poff_code = 0x80; - pmic_pon_log_parse(&tmp_pon_log, - parse_log_str1); /* warm reset/shutdown/hard reset */ - - if (PMIC_PON_RESET_TYPE_WARM_RESET == tmp_pon_log.data0) { - if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_WARM_RESET, - PMIC_PON_EVENT_WARM_RESET_COUNT, - 0, - &pmic_first_record, - &tmp_pon_log)) { - pmic_pon_log_parse(&tmp_pon_log, parse_log_str3); /* warm reset count */ - skip = tmp_pon_log.data1 << 8 | - tmp_pon_log.data0; /* For warm reset case, we need skip warm reset count-1 */ - skip = skip > 0 ? skip - 1 : 0; - - } else { - skip = 2; /* If we can't find reset count, we output the logs for the 3rd reset */ - } - - } else { - skip = 0; - } - - if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_RESET, - PMIC_PON_EVENT_RESET_TRIGGER_RECEIVED, - skip, - &pmic_first_record, - &tmp_pon_log)) { - pmic_pon_log_parse(&tmp_pon_log , parse_log_str2); - L2_poff_code = tmp_pon_log.data1 << 8 | tmp_pon_log.data0; - - } else { - L2_poff_code = 0; - snprintf(parse_log_str2 , 32 , "can't find RESET_TRIGGER"); - } - - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|0x%04X|%s,%s,%s (%ld)\n", - 0, - L1_poff_code, - L2_poff_code, - parse_log_str1, - parse_log_str2, - parse_log_str3, - pmic_history_count); - - } else { - len += snprintf(&page[len], 512 - len, - "PMIC|0|0x00|0x0000|Can't parse poff reason (%ld)\n", pmic_history_count); - } - - memcpy(buf, page, len); - return len; -} -pmic_gen3_info_attr_ro(poff_reason); -/**********************************************/ - -static ssize_t pon_reason_gen3_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[512] = {0}; - int len = 0; - struct PMICGen3HistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICGen3RecordKernelStruct pmic_first_record; - u64 pmic_history_count = 0; - struct PmicGen3PonStateStruct tmp_pon_log; - char parse_log_str1[128] = {0}; - u8 pon_code = 0; - - pmic_history_ptr = (struct PMICGen3HistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 512 - len, "PMIC|0|0x000000000000\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - pmic_history_count = pmic_history_ptr->log_count; - - if (-1 != get_pon_log_by_state_event(PMIC_PON_STATE_OFF, - PMIC_PON_EVENT_PON_TRIGGER_RECEIVED, - 0, - &pmic_first_record, - &tmp_pon_log)) { - pon_code = tmp_pon_log.data1 << 8 | tmp_pon_log.data0; - pmic_pon_log_parse(&tmp_pon_log, parse_log_str1); - len += snprintf(&page[len], 512 - len, "PMIC|%d|0x%02X|%s (%ld)\n", - 0, - pon_code, - parse_log_str1, - pmic_history_count); - - } else { - len += snprintf(&page[len], 512 - len, - "PMIC|0|0x00|Can't parse pon reason (%ld)\n", pmic_history_count); - } - - memcpy(buf, page, len); - return len; -} -pmic_gen3_info_attr_ro(pon_reason); - -/**********************************************/ -static ssize_t ocp_status_gen3_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - char page[256] = {0}; - int len = 0; - struct PMICGen3HistoryKernelStruct *pmic_history_ptr = NULL; - struct PMICGen3RecordKernelStruct pmic_first_record; - u8 pmic_device_index = 0; - - pmic_history_ptr = (struct PMICGen3HistoryKernelStruct *)get_pmic_history(); - - if (NULL == pmic_history_ptr) { - len += snprintf(&page[len], 256 - len, "PMIC|0|0x000000000000\n"); - memcpy(buf, page, len); - return len; - } - - pmic_first_record = pmic_history_ptr->pmic_record[0]; - - for (pmic_device_index = 0; pmic_device_index < 8; pmic_device_index++) { - if (DATA_VALID_FLAG != - pmic_first_record.pmic_ocp_record[pmic_device_index].data_is_valid) { - continue; - } - - len += snprintf(&page[len], 256 - len, "PMIC|%d|0x%08X%02X%02X\n", - pmic_device_index, - pmic_first_record.pmic_ocp_record[pmic_device_index].ldo_ocp_status, - pmic_first_record.pmic_ocp_record[pmic_device_index].spms_ocp_status, - pmic_first_record.pmic_ocp_record[pmic_device_index].bob_ocp_status); - } - - memcpy(buf, page, len); - return len; -} -pmic_gen3_info_attr_ro(ocp_status); -/**********************************************/ - -static struct attribute *gen3[] = { - &pmic_history_magic_gen3_attr.attr, - &pmic_history_count_gen3_attr.attr, - &poff_reason_gen3_attr.attr, - &pon_reason_gen3_attr.attr, - &ocp_status_gen3_attr.attr, - NULL, -}; - -static struct attribute_group attr_gen3_group = { - .attrs = gen3, -}; - -/**************** PMIC GEN3 End ****************/ - -struct kobject *pmic_info_kobj; - -static int __init pmic_info_init(void) -{ - int error; - - u64 *magic; - - pmic_info_kobj = kobject_create_and_add("pmic_info", NULL); - - if (!pmic_info_kobj) { - return -ENOMEM; - } - - magic = (u64 *)get_pmic_history(); - - if (NULL == magic) { - return -1; - } - - if (PMIC_GEN3_INFO_MAGIC == *magic) { - error = sysfs_create_group(pmic_info_kobj, &attr_gen3_group); - - } else { - error = sysfs_create_group(pmic_info_kobj, &attr_group); - } - - if (error) { - return error; - } - - return 0; -} - -late_initcall_sync(pmic_info_init); - -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info.h b/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info.h deleted file mode 100755 index 474e22239627..000000000000 --- a/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info.h +++ /dev/null @@ -1,189 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*============================================================================== - -FILE: oplus_pmic_info.h - -DESCRIPTION: - -=============================================================================*/ -#ifndef __OPLUS_PMIC_INFO_H__ -#define __OPLUS_PMIC_INFO_H__ - -#define PMIC_INFO_MAGIC 0x43494D504F50504F -#define PMIC_GEN3_INFO_MAGIC 0x43494d50334e4547 /* GEN3PMIC */ - -#define DATA_VALID_FLAG 0xCC -#define MAX_HISTORY_COUNT 4 - -#define MAX_RECORD_LDO_NUM 32 -#define MAX_RECORD_SPMS_NUM 8 -#define MAX_RECORD_BOB_NUM 8 - -/**************** PMIC GEN2 Begin ****************/ - -/* PON_OFF_REASON |0x8C7 */ -#define INDEX_RAW_XVDD_RB_OCCURED 3 -#define INDEX_RAW_DVDD_RB_OCCURED 4 -#define INDEX_IMMEDIATE_XVDD_SHUTDOWN 5 -#define INDEX_S3_RESET 6 -#define INDEX_FAULT_SEQ 7 -#define INDEX_POFF_SEQ 8 - -/* xbl struct */ -struct PMICRegStruct { - u64 pon_reason; - u64 fault_reason; - u32 ldo_ocp_status; - u8 spms_ocp_status; - u8 bob_ocp_status; - u16 data_is_valid; -}; - -struct PMICRecordStruct { - struct PMICRegStruct pmic_pon_poff_reason[8]; /*PM_MAX_NUM_PMICS is 8*/ -}; - -struct PMICHistoryStruct { - u64 pmic_magic; - u64 log_count; - struct PMICRecordStruct pmic_record[MAX_HISTORY_COUNT]; -}; - -/*kernel struct*/ -struct PMICRegKernelStruct { - /*u64 pon_reason;*/ - u8 PON_PON_REASON1; /*0x8C0*/ - u8 PON_RESERVE1; /*0x8C1*/ - u8 PON_WARM_RESET_REASON1; /*0x8C2*/ - u8 PON_RESERVE2; /*0x8C3*/ - u8 PON_ON_REASON; /*0x8C4*/ - u8 PON_POFF_REASON1; /*0x8C5*/ - u8 PON_RESERVE3; /*0x8C6*/ - u8 PON_OFF_REASON; /*0x8C7*/ - - /*u64 fault_reason;*/ - u8 PON_FAULT_REASON1; /*0x8C8*/ - u8 PON_FAULT_REASON2; /*0x8C9*/ - u8 PON_S3_RESET_REASON; /*0x8CA*/ - u8 PON_SOFT_RESET_REASON1; /*0x8CB*/ - u8 PON_RESERVE4; /*0x8CC*/ - u8 PON_RESERVE5; /*0x8CD*/ - u8 PON_RESERVE6; /*0x8CE*/ - u8 PON_RESERVE7; /*0x8DF*/ - - - u32 ldo_ocp_status; - u8 spms_ocp_status; - u8 bob_ocp_status; - u16 data_is_valid; -}; - -struct PMICRecordKernelStruct { - struct PMICRegKernelStruct pmic_pon_poff_reason[8]; /*PM_MAX_NUM_PMICS is 8*/ -}; - -struct PMICHistoryKernelStruct { - char pmic_magic[8]; - u64 log_count; - struct PMICRecordKernelStruct pmic_record[MAX_HISTORY_COUNT]; -}; - -#define pmic_info_attr(_name) \ -static struct kobj_attribute _name##_attr = { \ - .attr = { \ - .name = __stringify(_name), \ - .mode = 0644, \ - }, \ - .show = _name##_show, \ - .store = _name##_store, \ -} - -#define pmic_info_attr_ro(_name) \ -static struct kobj_attribute _name##_attr = { \ - .attr = { \ - .name = __stringify(_name), \ - .mode = S_IRUGO, \ - }, \ - .show = _name##_show, \ -} -/**************** PMIC GEN2 End ****************/ - -/**************** PMIC GEN3 Begin ****************/ - -/* xbl struct */ -#define MAX_STATE_RECORDS 25 -/* -typedef struct -{ - u8 state; - u8 event; - u8 byte1; - u8 byte0; -} pm_pon_log_type; -*/ - -struct PMICStateMachineStruct { - u8 state_record[MAX_STATE_RECORDS * 4]; /* pm_pon_log_type state_record[MAX_STATE_RECORDS] */ -}; - -struct PMICOcpStruct { - u32 ldo_ocp_status; - u8 spms_ocp_status; - u8 bob_ocp_status; - u16 data_is_valid; -}; - -struct PMICGen3RecordStruct { - struct PMICStateMachineStruct pmic_state_machine; - struct PMICOcpStruct pmic_ocp_record[8]; /* PM_MAX_NUM_PMICS is 8 */ -}; - -struct PMICGen3HistoryStruct { - u64 pmic_magic; - u64 log_count; - struct PMICGen3RecordStruct pmic_record[MAX_HISTORY_COUNT]; -}; - -/* kernel struct */ -struct PmicGen3PonStateStruct { - u8 state; - u8 event; - u8 data1; - u8 data0; -}; - -struct PMICOcpKernelStruct { - u32 ldo_ocp_status; - u8 spms_ocp_status; - u8 bob_ocp_status; - u16 data_is_valid; -}; - -struct PMICGen3RecordKernelStruct { - struct PmicGen3PonStateStruct pmic_state_machine_log[MAX_STATE_RECORDS]; - struct PMICOcpKernelStruct pmic_ocp_record[8]; /* PM_MAX_NUM_PMICS is 8 */ -}; - -struct PMICGen3HistoryKernelStruct { - char pmic_magic[8]; - u64 log_count; - struct PMICGen3RecordKernelStruct pmic_record[MAX_HISTORY_COUNT]; -}; - -#define pmic_gen3_info_attr_ro(_name) \ -static struct kobj_attribute _name##_gen3_attr = { \ - .attr = { \ - .name = __stringify(_name), \ - .mode = S_IRUGO, \ - }, \ - .show = _name##_gen3_show, \ -} -/**************** PMIC GEN3 End ****************/ - - -void *get_pmic_history(void); - -#endif /*__OPLUS_PMIC_INFO_H__*/ diff --git a/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info_smem.c b/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info_smem.c deleted file mode 100755 index cb36f0431cc0..000000000000 --- a/drivers/soc/oplus/system/oplus_pmic_monitor/oplus_pmic_info_smem.c +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "oplus_pmic_info.h" - -#define SMEM_PMIC_INFO 134 - -static void *format = NULL; - -void init_pmic_history_smem(void) -{ - size_t smem_size = 0; - - format = qcom_smem_get(QCOM_SMEM_HOST_ANY, - SMEM_PMIC_INFO, - &smem_size); - - if (IS_ERR(format) || !smem_size) { - format = NULL; - } -} - -void *get_pmic_history(void) -{ - if (format == NULL) { - init_pmic_history_smem(); - } - - return format; -} - -MODULE_DESCRIPTION("oplus ocp status"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Lee "); diff --git a/drivers/soc/oplus/system/oplus_saupwk/Kconfig b/drivers/soc/oplus/system/oplus_saupwk/Kconfig deleted file mode 100755 index e36bf1500406..000000000000 --- a/drivers/soc/oplus/system/oplus_saupwk/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Bin.Wen@TECH.BSP.Stability.SAUPWK 2020/06/15, Add for SAUPWK -#change 'y' to 'n', if you want fo close saupwk feature -config OPLUS_FEATURE_SAUPWK - tristate "oplus saupwk project" - default n - help - define this config to init oplus saupwk. diff --git a/drivers/soc/oplus/system/oplus_saupwk/Makefile b/drivers/soc/oplus/system/oplus_saupwk/Makefile deleted file mode 100755 index c742505b6cee..000000000000 --- a/drivers/soc/oplus/system/oplus_saupwk/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -ifneq ($(CONFIG_OPLUS_FEATURE_SAUPWK),n) -ccflags-y += -I$(srctree)/drivers/ -I$(srctree)/drivers/input/ -endif -ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -obj-$(CONFIG_OPLUS_FEATURE_SAUPWK) += oplus_saupwk.o -else -ifeq ($(CONFIG_OPLUS_FEATURE_SAUPWK), y) -obj-$(CONFIG_OPLUS_FEATURE_SAUPWK) += oplus_saupwk.o -endif -ifeq ($(CONFIG_OPLUS_FEATURE_SAUPWK), m) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include -obj-$(CONFIG_OPLUS_FEATURE_SAUPWK) += gki/oplus_saupwk.o -endif -endif diff --git a/drivers/soc/oplus/system/oplus_saupwk/gki/Kconfig b/drivers/soc/oplus/system/oplus_saupwk/gki/Kconfig deleted file mode 100755 index e36bf1500406..000000000000 --- a/drivers/soc/oplus/system/oplus_saupwk/gki/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Bin.Wen@TECH.BSP.Stability.SAUPWK 2020/06/15, Add for SAUPWK -#change 'y' to 'n', if you want fo close saupwk feature -config OPLUS_FEATURE_SAUPWK - tristate "oplus saupwk project" - default n - help - define this config to init oplus saupwk. diff --git a/drivers/soc/oplus/system/oplus_saupwk/gki/oplus_saupwk.c b/drivers/soc/oplus/system/oplus_saupwk/gki/oplus_saupwk.c deleted file mode 100755 index 91cdeb53a3fb..000000000000 --- a/drivers/soc/oplus/system/oplus_saupwk/gki/oplus_saupwk.c +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include "input-compat.h" -#if IS_ENABLED(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) -#include -#else -#include -#endif //CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#include -#include -#include - -#define SAUPWK_KEY_DOWN 1 - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SAUPWK) -extern char saupwk_enable[]; -#endif -bool __read_mostly saupwk_en = false; -static int sau_pwknum = 0; -static int saupwk_cache_obtained = 0; - -bool is_silent_reboot_or_sau(void) { - int boot_mode = get_boot_mode(); -#if IS_ENABLED(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) - return MSM_BOOT_MODE__SILENCE == boot_mode || MSM_BOOT_MODE__SAU == boot_mode; -#else - return SILENCE_BOOT == boot_mode; -#endif -} - -inline void oplus_sync_saupwk_event(unsigned int type, unsigned int code, int value) -{ - if (saupwk_en && is_silent_reboot_or_sau() && (!saupwk_cache_obtained) && - type == EV_KEY && code == KEY_POWER && value == SAUPWK_KEY_DOWN){ - sau_pwknum += 1; - pr_debug("[SAUPWK]:power key pressed\n"); - } -} - -static int sau_pwknum_seq_show(struct seq_file *seq, void*offset) -{ - seq_printf(seq, "%d", sau_pwknum); - saupwk_cache_obtained = 1; - return 0; -} - -extern void* PDE_DATA(const struct inode*inode); -static int sau_pwknum_open(struct inode *inode, struct file* file) -{ - return single_open(file, sau_pwknum_seq_show, PDE_DATA(inode)); -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static const struct file_operations oplus_sau_pwknum_fops = { - .owner = THIS_MODULE, - .open = sau_pwknum_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; -#else -static const struct proc_ops oplus_sau_pwknum_fops = { - .proc_open = sau_pwknum_open, - .proc_read = seq_read, -}; -#endif - -static int __init get_saupwk_enable(char* str) -{ - if(!strncmp("1", str, sizeof("1"))){ - saupwk_en = 1; - } - return 1; -} -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_SAUPWK) -__setup("saupwk.en=",get_saupwk_enable); -#endif - -static int __init -oplus_saupwk_during_init(void) -{ - struct proc_dir_entry * pentry; -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SAUPWK) - get_saupwk_enable(saupwk_enable); -#endif - if (!saupwk_en){ - return 0; - } - - pentry = proc_create("sau_pwknum", 0, NULL, &oplus_sau_pwknum_fops); - if(!pentry){ - pr_err("[SAUPWK] sau_pwknum proc entory create failure.\n"); - return -ENOENT; - } - pr_warn("[SAUPWK]:sau_pwknum proc entry create success.\n"); - return 0; -} - - -module_init(oplus_saupwk_during_init); - -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/oplus_saupwk/oplus_saupwk.c b/drivers/soc/oplus/system/oplus_saupwk/oplus_saupwk.c deleted file mode 100755 index 81a32666e440..000000000000 --- a/drivers/soc/oplus/system/oplus_saupwk/oplus_saupwk.c +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include "input-compat.h" -#include -#include -#include - -#define SAUPWK_KEY_DOWN 1 - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SAUPWK) -extern char saupwk_enable[]; -#endif -bool __read_mostly saupwk_en = false; -static int sau_pwknum = 0; -static int saupwk_cache_obtained = 0; - -bool is_silent_reboot_or_sau(void) -{ - int boot_mode = get_boot_mode(); - return MSM_BOOT_MODE__SILENCE == boot_mode || MSM_BOOT_MODE__SAU == boot_mode; -} - -inline void oplus_sync_saupwk_event(unsigned int type, unsigned int code, - int value) -{ - if (saupwk_en && is_silent_reboot_or_sau() && (!saupwk_cache_obtained) && - type == EV_KEY && code == KEY_POWER && value == SAUPWK_KEY_DOWN) { - sau_pwknum += 1; - pr_debug("[SAUPWK]:power key pressed\n"); - } -} - -static int sau_pwknum_seq_show(struct seq_file *seq, void *offset) -{ - seq_printf(seq, "%d", sau_pwknum); - saupwk_cache_obtained = 1; - return 0; -} - -extern void *PDE_DATA(const struct inode *inode); -static int sau_pwknum_open(struct inode *inode, struct file *file) -{ - return single_open(file, sau_pwknum_seq_show, PDE_DATA(inode)); -} - - -static const struct file_operations oplus_sau_pwknum_fops = { - .owner = THIS_MODULE, - .open = sau_pwknum_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int __init get_saupwk_enable(char *str) -{ - if (!strncmp("1", str, sizeof("1"))) { - saupwk_en = 1; - } - - return 1; -} -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_SAUPWK) -__setup("saupwk.en=", get_saupwk_enable); -#endif - -static int __init -oplus_saupwk_during_init(void) -{ - struct proc_dir_entry *pentry; -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SAUPWK) - - if (saupwk_enable != NULL) { - get_saupwk_enable(saupwk_enable); - - } else { - get_saupwk_enable("1"); - } - -#endif - - if (!saupwk_en) { - return 0; - } - - pentry = proc_create("sau_pwknum", 0, NULL, &oplus_sau_pwknum_fops); - - if (!pentry) { - pr_err("sau_pwknum proc entory create failure.\n"); - return -ENOENT; - } - - pr_warn("[SAUPWK]:sau_pwknum proc entry create success.\n"); - return 0; -} - - -module_init(oplus_saupwk_during_init); - -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/qcom_minidump/Kconfig b/drivers/soc/oplus/system/qcom_minidump/Kconfig deleted file mode 100755 index 42b2e87754ac..000000000000 --- a/drivers/soc/oplus/system/qcom_minidump/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE - bool "qcom minidump enhance" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable qcom minidump enhance. diff --git a/drivers/soc/oplus/system/qcom_minidump/Makefile b/drivers/soc/oplus/system/qcom_minidump/Makefile deleted file mode 100755 index 4c50940f0450..000000000000 --- a/drivers/soc/oplus/system/qcom_minidump/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE) += qcom_minidump_enhance.o -obj-$(CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE) += get_regs.o \ No newline at end of file diff --git a/drivers/soc/oplus/system/qcom_minidump/get_regs.S b/drivers/soc/oplus/system/qcom_minidump/get_regs.S deleted file mode 100755 index d371cb44b029..000000000000 --- a/drivers/soc/oplus/system/qcom_minidump/get_regs.S +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/* -*/ -#include -#include -#include -#include - -.text -/* - * x0 = struct pt_regs - */ -ENTRY(get_arm64_cpuregs) - stp x0, x1, [x0] - stp x2, x3, [x0, 0x10] - stp x4, x5, [x0, 0x20] - stp x6, x7, [x0, 0x30] - stp x8, x9, [x0, 0x40] - stp x10, x11, [x0, 0x50] - stp x12, x13, [x0, 0x60] - stp x14, x15, [x0, 0x70] - stp x16, x17, [x0, 0x80] - stp x18, x19, [x0, 0x90] - stp x20, x21, [x0, 0xA0] - stp x22, x23, [x0, 0xB0] - stp x24, x25, [x0, 0xC0] - stp x26, x27, [x0, 0xd0] - stp x28, x29, [x0, 0xe0] - str x30, [x0, 0xf0] - mov x1, sp - stp x1, x30, [x0, 0xf8] - mrs x1, spsr_el1 - str x1, [x0, 0x108] - ldr x1, [x0, 0x08] -ENDPROC(get_arm64_cpuregs) diff --git a/drivers/soc/oplus/system/qcom_minidump/qcom_minidump_enhance.c b/drivers/soc/oplus/system/qcom_minidump/qcom_minidump_enhance.c deleted file mode 100755 index 5c77719ea969..000000000000 --- a/drivers/soc/oplus/system/qcom_minidump/qcom_minidump_enhance.c +++ /dev/null @@ -1,316 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#else -#include -#endif -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define CPUCTX_VERSION 1 -#define CPUCTX_MAIGC1 0x4D494E49 -#define CPUCTX_MAIGC2 (CPUCTX_MAIGC1 + CPUCTX_VERSION) - -struct cpudatas { - struct pt_regs pt; - unsigned int regs[32][512];/*X0-X30 pc*/ - unsigned int sps[1024]; - unsigned int ti[16];/*thread_info*/ - unsigned int task_struct[4096]; -};/*16 byte alignment*/ - -struct cpuctx { - unsigned int magic_nubmer1; - unsigned int magic_nubmer2; - unsigned int dump_cpus; - unsigned int reserve; - struct cpudatas datas[0]; -}; - -static struct cpuctx *Cpucontex_buf = NULL; -extern struct pt_regs *get_arm64_cpuregs(struct pt_regs *regs); - -/*maybe system crashed at early boot time .at that time maybe pm_power_off and - *arm_pm_restart are not defined - */ -static void pull_down_pshold(void) -{ - struct device_node *np; - void __iomem *msm_ps_hold; - - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - printk("user do_msm_restart_early to reboot\n"); - qcom_scm_deassert_ps_hold(); -#else -#define SCM_IO_DEASSERT_PS_HOLD 2 /*msm-poweroff.c*/ - struct scm_desc desc = { - .args[0] = 0, - .arginfo = SCM_ARGS(1), - }; - printk("user do_msm_restart_early to reboot\n"); - - if (scm_is_call_available(SCM_SVC_PWR, SCM_IO_DEASSERT_PS_HOLD) > 0) { - /* This call will be available on ARMv8 only */ - scm_call2_atomic(SCM_SIP_FNID(SCM_SVC_PWR, - SCM_IO_DEASSERT_PS_HOLD), &desc); - } - -#endif - - np = of_find_compatible_node(NULL, NULL, "qcom,pshold"); - - if (!np) { - printk("unable to find DT node qcom,pshold\n"); - goto ERR; - - } else { - msm_ps_hold = of_io_request_and_map(np, 0, "pshold-base"); - - if (!msm_ps_hold) { - printk("unable to map pshold-base reg\n"); - goto ERR; - } - } - - /* Fall-through to the direct write in case the scm_call "returns" */ - if (msm_ps_hold) { - __raw_writel(0, msm_ps_hold); - } - - mdelay(10000); -ERR: - printk("pull down pshold early failed, halt\n"); - return; -} - -void do_restart_early(enum reboot_mode reboot_mode, const char *cmd) -{ - pull_down_pshold(); -} - -void do_poweroff_early(void) -{ - pull_down_pshold(); -} - -void dumpcpuregs(struct pt_regs *pt_regs) -{ - unsigned int cpu = smp_processor_id(); - struct cpudatas *cpudata = NULL; - struct pt_regs *regs = pt_regs; - struct pt_regs regtmp; - u32 *p; - unsigned long addr; - mm_segment_t fs; - int i, j; - - if (is_fulldump_enable()) { - return; - } - - if (Cpucontex_buf == NULL) { - return; - } - - cpudata = &Cpucontex_buf->datas[cpu]; - - if (regs != NULL && user_mode(regs)) { /*at user mode we must clear pt struct*/ - /*clear flag*/ - Cpucontex_buf->dump_cpus &= ~(0x01 << cpu); - return; - } - - if (regs == NULL) { - regs = get_irq_regs(); - - if (regs == NULL) { - memset((void *)®tmp, 0, sizeof(struct pt_regs)); - get_arm64_cpuregs(®tmp); - regs = ®tmp; - } - } - - /*set flag*/ - Cpucontex_buf->dump_cpus |= (0x01 << cpu); - - fs = get_fs(); - set_fs(KERNEL_DS); - /*1.fill pt*/ - memcpy((void *)&cpudata->pt, (void *)regs, sizeof(struct pt_regs)); - - /*2.fill regs - *2.1 fill x0-x30 - */ - for (i = 0; i < 31; i++) { - addr = regs->regs[i]; - - if (!virt_addr_valid(addr) || addr < KIMAGE_VADDR || addr > -256UL) { - continue; - } - - addr = addr - 256 * sizeof(int); - p = (u32 *)((addr) & ~(sizeof(u32) - 1)); - addr = (unsigned long)p; - cpudata->regs[i][0] = (unsigned int)(addr & 0xffffffff); - cpudata->regs[i][1] = (unsigned int)((addr >> 32) & 0xffffffff); - - for (j = 2; j < 256; j++) { - u32 data; - - if (probe_kernel_address(p, data)) { - break; - - } else { - cpudata->regs[i][j] = data; - } - - ++p; - } - } - - /*2.2 fill pc*/ - addr = regs->pc; - - if (virt_addr_valid(addr) && addr >= KIMAGE_VADDR - && addr < -256UL) { - addr = addr - 256 * sizeof(int); - p = (u32 *)((addr) & ~(sizeof(u32) - 1)); - addr = (unsigned long)p; - cpudata->regs[i][0] = (unsigned int)(addr & 0xffffffff); - cpudata->regs[i][1] = (unsigned int)((addr >> 32) & 0xffffffff); - - for (j = 2; j < 256; j++) { - u32 data; - - if (probe_kernel_address(p, data)) { - break; - - } else { - cpudata->regs[31][j] = data; - } - - ++p; - } - } - - /*3. fill sp*/ - addr = regs->sp; - - if (virt_addr_valid(addr) && addr >= KIMAGE_VADDR && addr < -256UL) { - addr = addr - 512 * sizeof(int); - p = (u32 *)((addr) & ~(sizeof(u32) - 1)); - addr = (unsigned long)p; - cpudata->sps[0] = (unsigned int)(addr & 0xffffffff); - cpudata->sps[1] = (unsigned int)((addr >> 32) & 0xffffffff); - - for (j = 2; j < 512; j++) { - u32 data; - - if (probe_kernel_address(p, data)) { - break; - - } else { - cpudata->sps[j] = data; - } - - ++p; - } - } - - /*4. fill task_strcut thread_info*/ - addr = (unsigned long)current; - - if (virt_addr_valid(addr) && addr >= KIMAGE_VADDR && addr < -256UL) { - cpudata->task_struct[0] = (unsigned int)(addr & 0xffffffff); - cpudata->task_struct[1] = (unsigned int)((addr >> 32) & 0xffffffff); - memcpy(&cpudata->task_struct[2], (void *)current, sizeof(struct task_struct)); - addr = (unsigned long)(current->stack); - - if (virt_addr_valid(addr) && addr >= KIMAGE_VADDR && addr < -256UL) { - cpudata->ti[0] = (unsigned int)(addr & 0xffffffff); - cpudata->ti[1] = (unsigned int)((addr >> 32) & 0xffffffff); - memcpy(&cpudata->ti[2], (void *)addr, sizeof(struct thread_info)); - } - } - - set_fs(fs); -} -EXPORT_SYMBOL(dumpcpuregs); - -void register_cpu_contex(void) -{ - int ret; - struct msm_dump_entry dump_entry; - struct msm_dump_data *dump_data; - - if (MSM_DUMP_MAJOR(msm_dump_table_version()) > 1) { - dump_data = kzalloc(sizeof(struct msm_dump_data), GFP_KERNEL); - - if (!dump_data) { - return; - } - - Cpucontex_buf = (struct cpuctx *)kzalloc(sizeof(struct cpuctx) + - sizeof(struct cpudatas) * num_present_cpus(), GFP_KERNEL); - - if (!Cpucontex_buf) { - goto err0; - } - - /*init magic number*/ - Cpucontex_buf->magic_nubmer1 = CPUCTX_MAIGC1; - Cpucontex_buf->magic_nubmer2 = CPUCTX_MAIGC2;/*version*/ - Cpucontex_buf->dump_cpus = 0;/*version*/ - - strlcpy(dump_data->name, "cpucontex", sizeof(dump_data->name)); - dump_data->addr = virt_to_phys(Cpucontex_buf); - dump_data->len = sizeof(struct cpuctx) + sizeof(struct cpudatas) * - num_present_cpus(); - dump_entry.id = 0; - dump_entry.addr = virt_to_phys(dump_data); - ret = msm_dump_data_register(MSM_DUMP_TABLE_APPS, &dump_entry); - - if (ret) { - pr_err("Registering cpu contex dump region failed\n"); - goto err1; - } - - return; - err1: - kfree(Cpucontex_buf); - Cpucontex_buf = NULL; - err0: - kfree(dump_data); - } -} - diff --git a/drivers/soc/oplus/system/qcom_pmicwd/Kconfig b/drivers/soc/oplus/system/qcom_pmicwd/Kconfig deleted file mode 100755 index ee52f3723584..000000000000 --- a/drivers/soc/oplus/system/qcom_pmicwd/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_QCOM_PMICWD - tristate "qcom pmic watchdog" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable qcom pmic watchdog. - export pwk dump interface to android for control pwkdump. diff --git a/drivers/soc/oplus/system/qcom_pmicwd/Makefile b/drivers/soc/oplus/system/qcom_pmicwd/Makefile deleted file mode 100755 index 0bbc405be8fd..000000000000 --- a/drivers/soc/oplus/system/qcom_pmicwd/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_QCOM_PMICWD) += oplus_pmicwd.o -oplus_pmicwd-y := qcom_pmicwd.o qcom_pwkpwr.o - diff --git a/drivers/soc/oplus/system/qcom_pmicwd/qcom_pmicwd.c b/drivers/soc/oplus/system/qcom_pmicwd/qcom_pmicwd.c deleted file mode 100755 index f406d2b662b8..000000000000 --- a/drivers/soc/oplus/system/qcom_pmicwd/qcom_pmicwd.c +++ /dev/null @@ -1,737 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** OPLUS_SYSTEM_QCOM_PMICWD -** File : qcom_pmicwd.c -** Description : qcom pmic watchdog driver -** Version : 1.0 -******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "soc/oplus/system/oplus_project.h" -#include -#include -#include -#include -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#else -#include -#endif -#include - -#define QPNP_PON_WD_RST_S1_TIMER(pon) ((pon)->base + 0x54) -#define QPNP_PON_WD_RST_S2_TIMER(pon) ((pon)->base + 0x55) -#define QPNP_PON_WD_RST_S2_CTL(pon) ((pon)->base + 0x56) -#define QPNP_PON_WD_RST_S2_CTL2(pon) ((pon)->base + 0x57) -#define QPNP_PON_WD_RESET_PET(pon) ((pon)->base + 0x58) -#define QPNP_PON_RT_STS(pon) ((pon)->base + 0x10) - -#define QPNP_PON_S2_CNTL_TYPE_MASK (0xF) -#define QPNP_PON_WD_S2_TIMER_MASK (0x7F) -#define QPNP_PON_WD_S1_TIMER_MASK (0x7F) -#define QPNP_PON_WD_RESET_PET_MASK BIT(0) - -#define PMIC_WD_DEFAULT_TIMEOUT 254 - -#define OPLUS_KE_PROC_ENTRY(name, entry, mode)\ - ({if (!proc_create(#name, S_IFREG | mode, oplus_ke_proc_dir, \ - &proc_##entry##_fops)){ \ - pr_info("proc_create %s failed\n", #name);}}) - -#define OPLUS_KE_FILE_OPS(entry) \ - static const struct file_operations proc_##entry##_fops = { \ - .read = proc_##entry##_read, \ - .write = proc_##entry##_write, \ - } - -static struct proc_dir_entry *oplus_ke_proc_dir; - -static ssize_t proc_force_shutdown_read(struct file *file, - char __user *buf, size_t size, loff_t *ppos) -{ - return 0; -} - -static ssize_t proc_force_shutdown_write(struct file *file, - const char __user *buf, size_t size, loff_t *ppos) -{ - qpnp_pon_system_pwr_off(PON_POWER_OFF_SHUTDOWN); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - qcom_scm_deassert_ps_hold(); -#else - - if (pm_power_off) { - pm_power_off(); - } - -#endif - - return 0; -} - -OPLUS_KE_FILE_OPS(force_shutdown); - -const struct dev_pm_ops qpnp_pm_ops; -struct qpnp_pon *sys_reset_dev; -EXPORT_SYMBOL(sys_reset_dev); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#define PON_GEN3_PBS 0x08 -#define PON_GEN3_HLOS 0x09 -#define QPNP_PON_WD_EN BIT(7) - -static bool is_pon_gen3(struct qpnp_pon *pon) -{ - return pon->subtype == PON_GEN3_PBS || - pon->subtype == PON_GEN3_HLOS; -} - -static int oplus_qpnp_pon_wd_config(bool enable) -{ - if (!sys_reset_dev) { - return -EPROBE_DEFER; - } - - if (is_pon_gen3(sys_reset_dev)) { - return -EPERM; - } - - return qpnp_pon_masked_write(sys_reset_dev, - QPNP_PON_WD_RST_S2_CTL2(sys_reset_dev), - QPNP_PON_WD_EN, enable ? QPNP_PON_WD_EN : 0); -} -#else -static int oplus_qpnp_pon_wd_config(bool enable) -{ - return qpnp_pon_wd_config(enable); -} -#endif - -int qpnp_pon_wd_timer(unsigned char timer, enum pon_power_off_type reset_type) -{ - struct qpnp_pon *pon = sys_reset_dev; - int rc = 0; - u8 s1_timer, s2_timer; - - if (!pon) { - return -EPROBE_DEFER; - } - - if (timer > 127) { - s2_timer = 127; - - if (timer - 127 > 127) { - s1_timer = 127; - - } else { - s1_timer = timer - 127; - } - - } else { - s2_timer = timer & 0xff; - s1_timer = 0; - } - - rc = qpnp_pon_masked_write(pon, QPNP_PON_WD_RST_S2_TIMER(pon), - QPNP_PON_WD_S2_TIMER_MASK, s2_timer); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_WD_RST_S2_TIMER(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_WD_RST_S1_TIMER(pon), - QPNP_PON_WD_S1_TIMER_MASK, s1_timer); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_WD_RST_S1_TIMER(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_WD_RST_S2_CTL(pon), - QPNP_PON_S2_CNTL_TYPE_MASK, reset_type); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_WD_RST_S2_CTL(pon), rc); - - return rc; -} - -int qpnp_pon_wd_pet(void) -{ - struct qpnp_pon *pon = sys_reset_dev; - int rc = 0; - - if (!pon) { - return -EPROBE_DEFER; - } - - rc = qpnp_pon_masked_write(pon, QPNP_PON_WD_RESET_PET(pon), - QPNP_PON_WD_RESET_PET_MASK, 1); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_WD_RESET_PET(pon), rc); - - return rc; -} - -static int pmicwd_kthread(void *arg) -{ - struct qpnp_pon *pon = (struct qpnp_pon *)arg; - struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1}; - sched_setscheduler(current, SCHED_FIFO, ¶m); - - while (!kthread_should_stop()) { - schedule_timeout_interruptible(msecs_to_jiffies((((pon->pmicwd_state >> 8) & - 0xff) * 1000) / 2)); - dev_info(pon->dev, "pmicwd_kthread PET wd suspend state %d\n", - pon->suspend_state); - qpnp_pon_wd_pet(); - - if ((pon->suspend_state & 0x0F) >= 1) { - /* before panic need show the blocked task first */ - show_state_filter(TASK_UNINTERRUPTIBLE); - panic("suspend resume state %d\n", pon->suspend_state); - - } else if (pon->suspend_state & 0xF0) { - pon->suspend_state++; - } - } - - oplus_qpnp_pon_wd_config(0); - return 0; -} -static ssize_t pmicwd_proc_read(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - struct qpnp_pon *pon = sys_reset_dev; - unsigned int val; - char page[128] = {0}; - int len = 0; - - if (!pon) { - return -EFAULT; - } - - mutex_lock(&pon->wd_task_mutex); - regmap_read(pon->regmap, QPNP_PON_WD_RST_S2_CTL2(pon), &val); - dev_info(pon->dev, "pmicwd_proc_read:%x wd=%x\n", pon->pmicwd_state, val); - /*|reserver|rst type|timeout|enable|*/ - len = snprintf(&page[len], 128 - len, "enable = %d timeout = %d rstype = %d\n", - pon->pmicwd_state & 0xff, (pon->pmicwd_state >> 8) & 0xff, - (pon->pmicwd_state >> 16) & 0xff); - mutex_unlock(&pon->wd_task_mutex); - - if (len > *off) { - len -= *off; - - } else { - len = 0; - } - - if (copy_to_user(buf, page, (len < count ? len : count))) { - return -EFAULT; - } - - *off += len < count ? len : count; - return (len < count ? len : count); -} - -static ssize_t pmicwd_proc_write(struct file *file, const char __user *buf, - size_t count, loff_t *off) -{ - struct qpnp_pon *pon = sys_reset_dev; - int tmp_rstypt = 0; - int tmp_timeout = 0; - int tmp_enable = 0; - int ret = 0; - char buffer[64] = {0}; - unsigned int new_state; - - if (!pon) { - return -EFAULT; - } - - if (count > 64) { - count = 64; - } - - if (copy_from_user(buffer, buf, count)) { - dev_err(pon->dev, "%s: read proc input error.\n", __func__); - return count; - } - - ret = sscanf(buffer, "%d %d %d", &tmp_enable, &tmp_timeout, &tmp_rstypt); - - if (ret <= 0) { - dev_err(pon->dev, "%s: input error\n", __func__); - return count; - } - - if (tmp_timeout < 60 || tmp_timeout > 255) { - tmp_timeout = PMIC_WD_DEFAULT_TIMEOUT; - } - - if (tmp_rstypt >= PON_POWER_OFF_MAX_TYPE - || tmp_rstypt <= PON_POWER_OFF_RESERVED) { - if (get_eng_version() == AGING) { - tmp_rstypt = PON_POWER_OFF_WARM_RESET; - - } else { - tmp_rstypt = PON_POWER_OFF_HARD_RESET; - } - } - - new_state = (tmp_enable & 0xff) | ((tmp_timeout & 0xff) << 8) | (( - tmp_rstypt & 0xff) << 16); - dev_info(pon->dev, "pmicwd_proc_write:old:%x new:%x\n", pon->pmicwd_state, - new_state); - - if (new_state == pon->pmicwd_state) { - return count; - } - - mutex_lock(&pon->wd_task_mutex); - - if (pon->wd_task) { - oplus_qpnp_pon_wd_config(0); - pon->pmicwd_state &= ~0xff; - kthread_stop(pon->wd_task); - pon->wd_task = NULL; - } - - qpnp_pon_wd_timer(tmp_timeout, tmp_rstypt); - pon->pmicwd_state = new_state; - - if (tmp_enable) { - pon->wd_task = kthread_create(pmicwd_kthread, pon, "pmicwd"); - - if (pon->wd_task) { - oplus_qpnp_pon_wd_config(1); - wake_up_process(pon->wd_task); - - } else { - oplus_qpnp_pon_wd_config(0); - pon->pmicwd_state &= ~0xff; - } - } - - qpnp_pon_wd_pet(); - mutex_unlock(&pon->wd_task_mutex); - return count; -} - -void set_pmicWd_state(int enable) -{ - struct qpnp_pon *pon = sys_reset_dev; - unsigned int new_state; - - new_state = (pon->pmicwd_state & ~0x1) | (enable & 0x1); - - dev_info(pon->dev, "set_pmicWd_state:old:%x new:%x\n", pon->pmicwd_state, - new_state); - - if (new_state == pon->pmicwd_state) { - return; - } - - mutex_lock(&pon->wd_task_mutex); - - if (pon->wd_task) { - oplus_qpnp_pon_wd_config(0); - pon->pmicwd_state &= ~0xff; - kthread_stop(pon->wd_task); - pon->wd_task = NULL; - } - - pon->pmicwd_state = new_state; - - if (enable) { - pon->wd_task = kthread_create(pmicwd_kthread, pon, "pmicwd"); - - if (pon->wd_task) { - oplus_qpnp_pon_wd_config(1); - wake_up_process(pon->wd_task); - - } else { - oplus_qpnp_pon_wd_config(0); - pon->pmicwd_state &= ~0xff; - } - } - - qpnp_pon_wd_pet(); - mutex_unlock(&pon->wd_task_mutex); -} -EXPORT_SYMBOL(set_pmicWd_state); - -/* - * This function is register as callback function to get notifications - * from the PM module on the system suspend state. - */ -static int pmicWd_pm_notifier(struct notifier_block *nb, - unsigned long event, void *unused) -{ - struct qpnp_pon *pon = sys_reset_dev; - - switch (event) { - case PM_SUSPEND_PREPARE: - pon->suspend_state = 0x80; - pr_info("pmicwd start suspend\n"); - break; - - case PM_POST_SUSPEND: - pon->suspend_state = 0; - pr_info("pmicwd finish resume\n"); - break; - } - - return NOTIFY_DONE; -} - -static struct notifier_block pmicWd_pm_nb = { - .notifier_call = pmicWd_pm_notifier, - .priority = INT_MAX, -}; - -static struct file_operations pmicwd_proc_fops = { - .read = pmicwd_proc_read, - .write = pmicwd_proc_write, -}; - -#if defined(CONFIG_DEBUG_FS) -static const struct file_operations pmicwd_config_fops = { - .open = simple_open, - .read = pmicwd_proc_read, - .write = pmicwd_proc_write, -}; - -static bool pmicwd_test_flag = false; -static int pmicwd_test_get(void *data, u64 *val) -{ - struct qpnp_pon *pon = data; - *val = (u64)pmicwd_test_flag; - dev_info(pon->dev, "%s: pmicwd test flag: %d\n", __func__, pmicwd_test_flag); - return 0; -} - -static int pmicwd_test_set(void *data, u64 val) -{ - struct qpnp_pon *pon = data; - - mutex_lock(&pon->wd_task_mutex); - - if (val) { - if (pmicwd_test_flag) { - dev_info(pon->dev, "%s: pmicwd test already started!\n", __func__); - mutex_unlock(&pon->wd_task_mutex); - return 0; - } - - /*stop wd_task, and keep wd enbled, cause wd timeout!*/ - if (pon->wd_task) { - kthread_stop(pon->wd_task); - oplus_qpnp_pon_wd_config( - 1); /*wd will be disabled in wd_task stop flow, so re-enabled*/ - pon->wd_task = NULL; - dev_info(pon->dev, - "%s: pmicwd test start: after %d seconds reboot or enter RAMDUMP! \n", __func__, - (pon->pmicwd_state >> 8) & 0xFF); - - } else { - dev_info(pon->dev, "%s: pmicwd test start: wd task not run, ignore! \n", - __func__); - } - - pmicwd_test_flag = true; - - } else { - dev_info(pon->dev, "%s: pmicwd test exit!\n", __func__); - - if (!pon->wd_task) { - pon->wd_task = kthread_create(pmicwd_kthread, pon, "pmicwd"); - - if (pon->wd_task) { - oplus_qpnp_pon_wd_config(1); - wake_up_process(pon->wd_task); - } - - qpnp_pon_wd_pet(); - } - - pmicwd_test_flag = false; - } - - mutex_unlock(&pon->wd_task_mutex); - - return 0; -} - -DEFINE_DEBUGFS_ATTRIBUTE(pmicwd_test_fops, - pmicwd_test_get, - pmicwd_test_set, - "%llu\n"); - -static void pmicwd_debugfs_init(struct qpnp_pon *pon) -{ - struct dentry *file; - - if (!pon->debugfs) { - dev_err(pon->dev, "%s: debugfs directory invalid!\n", __func__); - return; - } - - file = debugfs_create_file("pmicwd_config", 0666, - pon->debugfs, NULL, &pmicwd_config_fops); - - if (IS_ERR_OR_NULL(file)) { - dev_err(pon->dev, "%s: Couldn't create pmicwd_config debugfs file\n", - __func__); - } - - file = debugfs_create_file("pmicwd_test", 0666, - pon->debugfs, pon, &pmicwd_test_fops); - - if (IS_ERR_OR_NULL(file)) { - dev_err(pon->dev, "%s: Couldn't create pmicwd_test debugfs file\n", __func__); - } - - return; -} - -#else - -static void pmicwd_debugfs_init(struct qpnp_pon *pon) -{} -#endif - -void pmicwd_init(struct platform_device *pdev, struct qpnp_pon *pon, - bool sys_reset) -{ - u32 pon_rt_sts = 0; - int rc; - - oplus_ke_proc_dir = proc_mkdir("oplus_ke", NULL); - - if (oplus_ke_proc_dir == NULL) { - pr_err("oplus_ke proc_mkdir failed\n"); - } - - OPLUS_KE_PROC_ENTRY(force_shutdown, force_shutdown, 0600); - - if (!pon) { - return; - } - - if (!sys_reset) { - return; - } - - pon->pmicwd_state = of_property_read_bool(pdev->dev.of_node, "qcom,pmicwd"); - pon->wd_task = NULL; - pon->suspend_state = 0; - - dev_info(pon->dev, "%s: sys_reset = 0x%x, pon pmicwd_state = 0x%x\n", __func__, - sys_reset, pon->pmicwd_state); - - if (sys_reset && pon->pmicwd_state) { - if (get_eng_version() == AGING) { - pon->pmicwd_state = PMIC_WD_DEFAULT_ENABLE | (PMIC_WD_DEFAULT_TIMEOUT << 8) | - (PON_POWER_OFF_WARM_RESET << 16); - - } else { - pon->pmicwd_state = PMIC_WD_DEFAULT_ENABLE | (PMIC_WD_DEFAULT_TIMEOUT << 8) | - (PON_POWER_OFF_HARD_RESET << 16); - } - - proc_create("pmicWd", 0666, NULL, &pmicwd_proc_fops); - mutex_init(&pon->wd_task_mutex); -#if PMIC_WD_DEFAULT_ENABLE - pon->wd_task = kthread_create(pmicwd_kthread, pon, "pmicwd"); - - if (pon->wd_task) { - if (get_eng_version() == AGING) { - qpnp_pon_wd_timer(PMIC_WD_DEFAULT_TIMEOUT, PON_POWER_OFF_WARM_RESET); - - } else { - qpnp_pon_wd_timer(PMIC_WD_DEFAULT_TIMEOUT, PON_POWER_OFF_HARD_RESET); - } - - oplus_qpnp_pon_wd_config(1); - wake_up_process(pon->wd_task); - - } else { - pon->pmicwd_state &= ~0xff; - } - -#endif - - rc = register_pm_notifier(&pmicWd_pm_nb); - - if (rc) { - dev_err(pon->dev, "%s: pmicWd power state notif error %d\n", __func__, rc); - } - } - - regmap_read(pon->regmap, QPNP_PON_RT_STS(pon), &pon_rt_sts); - dev_info(pon->dev, "probe keycode = 116, key_st = 0x%x\n", pon_rt_sts); - - pmicwd_debugfs_init(pon); - - return; -} -EXPORT_SYMBOL(pmicwd_init); - -static int setalarm(unsigned long time, bool enable) -{ - struct qpnp_pon *pon = sys_reset_dev; - static struct rtc_device *rtc; - static struct rtc_wkalrm alm; - static struct rtc_wkalrm org_alm; - unsigned long now; - int rc = -1; - static bool store_alm_success = false; - - if (!rtc) { - rtc = rtc_class_open("rtc0"); - } - - if (!rtc) { - dev_err(pon->dev, "open rtc fail %d\n", rc); - return rc; - } - - if (enable) { - rc = rtc_read_alarm(rtc, &org_alm); - - if (rc < 0) { - dev_err(pon->dev, "setalarm read alarm fail %d\n", rc); - store_alm_success = false; - return rc; - } - - store_alm_success = true; - rc = rtc_read_time(rtc, &alm.time); - - if (rc < 0) { - dev_err(pon->dev, "setalarm read time fail %d\n", rc); - return rc; - } - - rtc_tm_to_time(&alm.time, &now); - memset(&alm, 0, sizeof(alm)); - rtc_time_to_tm(now + time, &alm.time); - alm.enabled = true; - rc = rtc_set_alarm(rtc, &alm); - - if (rc < 0) { - dev_err(pon->dev, "setalarm set alarm fail %d\n", rc); - return rc; - } - - } else if (store_alm_success) { - alm.enabled = false; - rc = rtc_set_alarm(rtc, &alm); - - if (rc < 0) { - dev_err(pon->dev, "setalarm set alarm fail %d\n", rc); - return rc; - } - - /* consider setting timer and orginal timer. we store orginal timer at pon suspend, - and reset rtc from store at pon resume, no matter which one is greater. bottom - driver would judge write to RTC or not. */ - rc = rtc_set_alarm(rtc, &org_alm); - - if (rc < 0) { - dev_err(pon->dev, "setalarm set org alarm fail %d\n", rc); - return rc; - } - - } else { - dev_info(pon->dev, "%s store_alm_success:%d\n", __func__, store_alm_success); - } - - return 0; -} -static int qpnp_suspend(struct device *dev) -{ - struct qpnp_pon *pon = - (struct qpnp_pon *)dev_get_drvdata(dev); - unsigned long time = 0; - - if (sys_reset_dev == NULL || sys_reset_dev != pon) { - return 0; - } - - if (!(pon->pmicwd_state & 0xff)) { - dev_err(pon->dev, "%s:qpnp_suspend disable wd\n", dev_name(dev)); - return 0; - } - - pon->suspend_state = 0; - time = (pon->pmicwd_state >> 8) & 0xff; - dev_info(pon->dev, "%s:qpnp_suspend wd has enable\n", dev_name(dev)); - qpnp_pon_wd_pet(); - setalarm(time - 30, true); - return 0; -} - -static int qpnp_resume(struct device *dev) -{ - struct qpnp_pon *pon = - (struct qpnp_pon *)dev_get_drvdata(dev); - - - if (sys_reset_dev == NULL || sys_reset_dev != pon - || !(pon->pmicwd_state & 0xff)) { - return 0; - } - - pon->suspend_state = 0x70; - dev_info(pon->dev, "%s:qpnp_resume wd has enable\n", dev_name(dev)); - /*disable alarm*/ - setalarm(0, false); - qpnp_pon_wd_pet(); - return 0; -} - -static int qpnp_poweroff(struct device *dev) -{ - struct qpnp_pon *pon = - (struct qpnp_pon *)dev_get_drvdata(dev); - dev_info(pon->dev, "qpnp_poweroff is call\n"); - - if (sys_reset_dev == NULL || sys_reset_dev != pon) { - return 0; - } - - qpnp_pon_wd_pet(); - oplus_qpnp_pon_wd_config(0); - return 0; -} - -const struct dev_pm_ops qpnp_pm_ops = { - .suspend = qpnp_suspend, - .resume = qpnp_resume, - .poweroff = qpnp_poweroff, -}; -EXPORT_SYMBOL(qpnp_pm_ops); - -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/qcom_pmicwd/qcom_pwkpwr.c b/drivers/soc/oplus/system/qcom_pmicwd/qcom_pwkpwr.c deleted file mode 100755 index cf28912a5e74..000000000000 --- a/drivers/soc/oplus/system/qcom_pmicwd/qcom_pwkpwr.c +++ /dev/null @@ -1,246 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include "soc/oplus/system/oplus_project.h" -#include -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#else -#include -#endif - -#define QPNP_PON_KPDPWR_S1_TIMER(pon) ((pon)->base + 0x40) -#define QPNP_PON_KPDPWR_S2_TIMER(pon) ((pon)->base + 0x41) -#define QPNP_PON_KPDPWR_S2_CNTL(pon) ((pon)->base + 0x42) -#define QPNP_PON_KPDPWR_S2_CNTL2(pon) ((pon)->base + 0x43) - -#define QPNP_PON_RESET_S1_TIMER(pon) ((pon)->base + 0x44) -#define QPNP_PON_RESET_S2_TIMER(pon) ((pon)->base + 0x45) -#define QPNP_PON_RESET_S2_CNTL(pon) ((pon)->base + 0x46) -#define QPNP_PON_RESET_S2_CNTL2(pon) ((pon)->base + 0x47) - -#define QPNP_PON_S2_CNTL2_EN BIT(7) -#define QPNP_PON_S2_CNTL2_DIS 0x0 - -#define QPNP_PON_S2_CNTL_TYPE_MASK (0xF) -#define QPNP_PON_S2_CNTL_EN 0x1 -#define QPNP_PON_S2_CNTL_DIS 0x7 - -#define QPNP_PON_S1_TIMER_MASK (0xF) -#define QPNP_PON_KPDPWR_S1_TIMER_TIME 0xF - -#define QPNP_PON_S2_TIMER_MASK (0x7) -#define QPNP_PON_KPDPWR_S2_TIMER_TIME 0x7 - -#define SEQ_printf(m, x...) \ - do { \ - if (m) \ - seq_printf(m, x); \ - else \ - pr_debug(x); \ - } while (0) - -/** - * add qpnp-power-on kpdpwr off/on - * -**/ -static bool pwkpwr_enable; -static bool volup_enable; - -static ssize_t kpdpwr_proc_write(struct file *filep, const char __user *ubuf, - size_t cnt, loff_t *data) -{ - struct qpnp_pon *pon = sys_reset_dev; - char buf[64]; - long val = 0; - int rc = 0; - - if (cnt >= sizeof(buf)) { - return -EINVAL; - } - - if (copy_from_user(&buf, ubuf, cnt)) { - return -EFAULT; - } - - buf[cnt] = 0; - rc = kstrtoul(buf, 0, (unsigned long *)&val); - - if (rc < 0) { - return rc; - } - - if (!pon) { - return -EFAULT; - } - - if (val == 1) { - pr_err("QPNP_PON_KPDPWR_S2_CNTL2(pon) addr:%x", QPNP_PON_KPDPWR_S2_CNTL2(pon)); - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S2_CNTL2(pon), - QPNP_PON_S2_CNTL2_EN, QPNP_PON_S2_CNTL2_EN); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S2_CNTL2(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S2_CNTL(pon), - QPNP_PON_S2_CNTL_TYPE_MASK, QPNP_PON_S2_CNTL_EN); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S2_CNTL(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S1_TIMER(pon), - QPNP_PON_S1_TIMER_MASK, QPNP_PON_KPDPWR_S1_TIMER_TIME); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S1_TIMER(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S2_TIMER(pon), - QPNP_PON_S2_TIMER_MASK, QPNP_PON_KPDPWR_S2_TIMER_TIME); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S2_TIMER(pon), rc); - - pwkpwr_enable = true; - } - - if (val == 0) { - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S2_CNTL2(pon), - QPNP_PON_S2_CNTL2_EN, QPNP_PON_S2_CNTL2_DIS); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S2_CNTL2(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_KPDPWR_S2_CNTL(pon), - QPNP_PON_S2_CNTL_TYPE_MASK, QPNP_PON_S2_CNTL_DIS); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_KPDPWR_S2_CNTL(pon), rc); - - pwkpwr_enable = false; - } - - if (val == 101) { - pr_err("QPNP_PON_RESET_S2_CNTL2(pon) addr:%x", QPNP_PON_RESET_S2_CNTL2(pon)); - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S2_CNTL2(pon), - QPNP_PON_S2_CNTL2_EN, QPNP_PON_S2_CNTL2_EN); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S2_CNTL2(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S2_CNTL(pon), - QPNP_PON_S2_CNTL_TYPE_MASK, QPNP_PON_S2_CNTL_EN); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S2_CNTL(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S1_TIMER(pon), - QPNP_PON_S1_TIMER_MASK, QPNP_PON_KPDPWR_S1_TIMER_TIME); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S1_TIMER(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S2_TIMER(pon), - QPNP_PON_S2_TIMER_MASK, QPNP_PON_KPDPWR_S2_TIMER_TIME); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S2_TIMER(pon), rc); - - volup_enable = true; - } - - if (val == 100) { - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S2_CNTL2(pon), - QPNP_PON_S2_CNTL2_EN, QPNP_PON_S2_CNTL2_DIS); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S2_CNTL2(pon), rc); - - rc = qpnp_pon_masked_write(pon, QPNP_PON_RESET_S2_CNTL(pon), - QPNP_PON_S2_CNTL_TYPE_MASK, QPNP_PON_S2_CNTL_DIS); - - if (rc) - dev_err(pon->dev, - "Unable to write to addr=%x, rc(%d)\n", - QPNP_PON_RESET_S2_CNTL(pon), rc); - - volup_enable = false; - } - - return cnt; -} - -static int kpdpwr_proc_show(struct seq_file *m, void *v) -{ - SEQ_printf(m, "%s\n%s\n", - pwkpwr_enable ? "Long pwk dump enable\n" : "Long pwk dump disable\n", - volup_enable ? "Long volup dump enable\n" : "Long volup dump disable\n"); - return 0; -} - -static int kpdpwr_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, kpdpwr_proc_show, inode->i_private); -} - -static struct file_operations kpdpwr_proc_fops = { - .open = kpdpwr_proc_open, - .read = seq_read, - .write = kpdpwr_proc_write, - .release = single_release, -}; - - -void kpdpwr_init(struct qpnp_pon *pon, bool sys_reset) -{ - struct proc_dir_entry *pe; - - if (!sys_reset) { - return; - } - - if (!pon) { - pr_err("%s: pon invalid!\n", __func__); - return; - } - - pe = proc_create("kpdpwr", 0664, NULL, &kpdpwr_proc_fops); - - if (!pe) { - pr_err("kpdpwr:Failed to register kpdpwr interface\n"); - return; - } -} -EXPORT_SYMBOL(kpdpwr_init); diff --git a/drivers/soc/oplus/system/qcom_watchdog/Kconfig b/drivers/soc/oplus/system/qcom_watchdog/Kconfig deleted file mode 100755 index 75a8fb0e085d..000000000000 --- a/drivers/soc/oplus/system/qcom_watchdog/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_QCOM_WATCHDOG - tristate "qcom watchdog" - default n - depends on OPLUS_SYSTEM_KERNEL - help - enhance the qcom watchdog. diff --git a/drivers/soc/oplus/system/qcom_watchdog/Makefile b/drivers/soc/oplus/system/qcom_watchdog/Makefile deleted file mode 100755 index 8c15e6b3d182..000000000000 --- a/drivers/soc/oplus/system/qcom_watchdog/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) += qcom_enhance_watchdog.o - diff --git a/drivers/soc/oplus/system/qcom_watchdog/qcom_enhance_watchdog.c b/drivers/soc/oplus/system/qcom_watchdog/qcom_enhance_watchdog.c deleted file mode 100755 index 12892967420c..000000000000 --- a/drivers/soc/oplus/system/qcom_watchdog/qcom_enhance_watchdog.c +++ /dev/null @@ -1,298 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if IS_MODULE(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) -#include "../../../kernel/irq/internals.h" -#endif - -#define MASK_SIZE 32 -#define MAX_IRQ_NO 1200 - -unsigned int smp_call_any_cpu; -unsigned long smp_call_many_cpumask; - -static oplus_print_utc_cnt = 0; - -struct oplus_irq_counter { - unsigned int all_irqs_last; - unsigned int all_irqs_delta; - unsigned int *irqs_last; - unsigned int *irqs_delta; -}; - -static struct oplus_irq_counter o_irq_counter; -static int irqno_sort[10]; - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) -static bool irq_is_nmi(struct irq_desc *desc) -{ - return desc->istate & IRQS_NMI; -} - -static unsigned int oplus_kstat_irqs(unsigned int irq) -{ - struct irq_desc *desc = irq_to_desc(irq); - unsigned int sum = 0; - int cpu; - - if (!desc || !desc->kstat_irqs) { - return 0; - } - - if (!irq_settings_is_per_cpu_devid(desc) && - !irq_settings_is_per_cpu(desc) && - !irq_is_nmi(desc)) { - return desc->tot_count; - } - - for_each_possible_cpu(cpu) - sum += *per_cpu_ptr(desc->kstat_irqs, cpu); - return sum; -} - -static int oplus_task_curr(const struct task_struct *p) -{ - return p->state & TASK_RUNNING; -} -#endif - -static int init_oplus_watchdog(void) -{ - if (!o_irq_counter.irqs_last) { - o_irq_counter.irqs_last = (unsigned int *)kzalloc( - sizeof(unsigned int) * MAX_IRQ_NO, - GFP_KERNEL); - - if (!o_irq_counter.irqs_last) { - return -ENOMEM; - } - } - - if (!o_irq_counter.irqs_delta) { - o_irq_counter.irqs_delta = (unsigned int *)kzalloc( - sizeof(unsigned int) * MAX_IRQ_NO, - GFP_KERNEL); - - if (!o_irq_counter.irqs_delta) { - kfree(o_irq_counter.irqs_last); - return -ENOMEM; - } - } - - return 0; -} - -static void update_irq_counter(void) -{ - int n; - struct irq_desc *desc; - unsigned int all_count = 0; - unsigned int irq_count = 0; - - BUG_ON(nr_irqs > MAX_IRQ_NO); - - if (!o_irq_counter.irqs_delta || !o_irq_counter.irqs_last) { - return; - } - - for_each_irq_desc(n, desc) { -#if IS_MODULE(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) - irq_count = oplus_kstat_irqs(n); -#else - irq_count = kstat_irqs(n); -#endif - - if (!desc->action && !irq_count) { - continue; - } - - if (irq_count <= o_irq_counter.irqs_last[n]) { - o_irq_counter.irqs_delta[n] = 0; - - } else { - o_irq_counter.irqs_delta[n] = irq_count - o_irq_counter.irqs_last[n]; - } - - o_irq_counter.irqs_last[n] = irq_count; - all_count += irq_count; - } - o_irq_counter.all_irqs_delta = all_count - o_irq_counter.all_irqs_last; - o_irq_counter.all_irqs_last = all_count; -} - -static void insert_irqno(int no, int i, int size) -{ - int n; - - for (n = size - 1; n > i; n--) { - irqno_sort[n] = irqno_sort[n - 1]; - } - - irqno_sort[i] = no; -} - -static void sort_irqs_delta(void) -{ - int irq, i; - - for (i = 0; i < 10; i++) { - irqno_sort[i] = -1; - } - - for_each_irq_nr(irq) { - for (i = 0; i < 10; i++) { - if (irqno_sort[i] == -1) { - irqno_sort[i] = irq; - break; - } - - if (o_irq_counter.irqs_delta[irq] > o_irq_counter.irqs_delta[irqno_sort[i]]) { - insert_irqno(irq, i, 10); - break; - } - } - } -} - -static void print_top10_irqs(void) -{ - sort_irqs_delta(); - printk(KERN_INFO - "Top10 irqs since last: %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; %d:%u; Total: %u\n", - irqno_sort[0], o_irq_counter.irqs_delta[irqno_sort[0]], irqno_sort[1], - o_irq_counter.irqs_delta[irqno_sort[1]], - irqno_sort[2], o_irq_counter.irqs_delta[irqno_sort[2]], irqno_sort[3], - o_irq_counter.irqs_delta[irqno_sort[3]], - irqno_sort[4], o_irq_counter.irqs_delta[irqno_sort[4]], irqno_sort[5], - o_irq_counter.irqs_delta[irqno_sort[5]], - irqno_sort[6], o_irq_counter.irqs_delta[irqno_sort[6]], irqno_sort[7], - o_irq_counter.irqs_delta[irqno_sort[7]], - irqno_sort[8], o_irq_counter.irqs_delta[irqno_sort[8]], irqno_sort[9], - o_irq_counter.irqs_delta[irqno_sort[9]], o_irq_counter.all_irqs_delta); -} - -void oplus_dump_cpu_online_smp_call(void) -{ - static char alive_mask_buf[MASK_SIZE]; - struct cpumask avail_mask; -#ifdef CONFIG_SCHED_WALT - cpumask_andnot(&avail_mask, cpu_online_mask, cpu_isolated_mask); -#else - cpumask_copy(&avail_mask, cpu_online_mask); -#endif - scnprintf(alive_mask_buf, MASK_SIZE, "%*pb1", cpumask_pr_args(&avail_mask)); - printk(KERN_INFO "cpu avail mask %s\n", alive_mask_buf); - /* print_smp_call_cpu */ - printk(KERN_INFO "cpu of last smp_call_function_any: %d\n", - smp_call_any_cpu); - printk(KERN_INFO "cpumask of last smp_call_function_many: 0x%lx\n", - smp_call_many_cpumask); -} -EXPORT_SYMBOL(oplus_dump_cpu_online_smp_call); - -void oplus_get_cpu_ping_mask(cpumask_t *pmask, int *cpu_idle_pc_state) -{ - int cpu; - struct cpumask avail_mask; - update_irq_counter(); - cpumask_copy(pmask, cpu_online_mask); -#ifdef CONFIG_SCHED_WALT - cpumask_andnot(&avail_mask, cpu_online_mask, cpu_isolated_mask); -#else - cpumask_copy(&avail_mask, cpu_online_mask); -#endif - for_each_cpu(cpu, cpu_online_mask) { - if (cpu_idle_pc_state[cpu] || cpu_isolated(cpu)) { - cpumask_clear_cpu(cpu, pmask); - } - } - printk(KERN_INFO - "[wdog_util]cpu avail mask: 0x%lx; ping mask: 0x%lx; irqs since last: %u\n", - *cpumask_bits(&avail_mask), *cpumask_bits(pmask), o_irq_counter.all_irqs_delta); -} -EXPORT_SYMBOL(oplus_get_cpu_ping_mask); - -void oplus_dump_wdog_cpu(struct task_struct *w_task) -{ - int work_cpu = 0; - int wdog_busy = 0; -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) - struct pt_regs *regs = get_irq_regs(); -#endif - update_irq_counter(); - print_top10_irqs(); - work_cpu = task_cpu(w_task); -#if IS_MODULE(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) - wdog_busy = oplus_task_curr(w_task); -#else - wdog_busy = task_curr(w_task); -#endif - - if (wdog_busy) { - printk(KERN_EMERG "Watchdog work is running at CPU(%d)\n", work_cpu); - - } else { - printk(KERN_EMERG "Watchdog work is pending at CPU(%d)\n", work_cpu); - } - -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_QCOM_WATCHDOG) - - if (regs) { - show_regs(regs); - } - -#endif -} -EXPORT_SYMBOL(oplus_dump_wdog_cpu); - -/* replace android trigger utc time show, using watchdog print - * petwatchdog 9s, 4 times print once - */ -void oplus_show_utc_time(void) -{ - struct timespec ts; - struct rtc_time tm; - - if (oplus_print_utc_cnt > 2) { - oplus_print_utc_cnt = 0; - - } else { - oplus_print_utc_cnt++; - return; - } - - getnstimeofday(&ts); - rtc_time_to_tm(ts.tv_sec, &tm); - pr_warn("!@WatchDog: %d-%02d-%02d %02d:%02d:%02d.%09lu UTC\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); -} -EXPORT_SYMBOL(oplus_show_utc_time); - -static int __init oplus_wd_init(void) -{ - int ret = 0; - - ret = init_oplus_watchdog(); - - if (ret != 0) { - pr_err("Failed to init oplus watchlog"); - } - - return ret; -} -module_init(oplus_wd_init); - -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/rt_info/Kconfig b/drivers/soc/oplus/system/rt_info/Kconfig deleted file mode 100755 index b7c39ed5755c..000000000000 --- a/drivers/soc/oplus/system/rt_info/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -config OPLUS_FEATURE_RT_OPT_INFO - tristate "rt info stat" - default n - help - Schedule info statistics for render thread diff --git a/drivers/soc/oplus/system/rt_info/Makefile b/drivers/soc/oplus/system/rt_info/Makefile deleted file mode 100755 index a7d3b54672d9..000000000000 --- a/drivers/soc/oplus/system/rt_info/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2021 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_RT_OPT_INFO) += rt_info.o diff --git a/drivers/soc/oplus/system/rt_info/rt_info.c b/drivers/soc/oplus/system/rt_info/rt_info.c deleted file mode 100755 index 1c32a4e3eab7..000000000000 --- a/drivers/soc/oplus/system/rt_info/rt_info.c +++ /dev/null @@ -1,334 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/*#ifdef CONFIG_OPLUS_FEATURE_RT_INFO*/ -#include "rt_info.h" - -static int rt_num = 0; -struct kmem_cache *rt_waker_cache = NULL; -struct proc_dir_entry *game_dir = NULL; -DEFINE_SPINLOCK(rt_info_lock); - -/* render thread information - */ -struct render_thread_info_t { - pid_t rt_tid; - struct task_struct *rt_task; - struct list_head waker_list; -} render_thread_info[MAX_RT_NUM]; - -/* render thread waker information - */ -struct rt_waker_info_t { - struct list_head list; - pid_t waker_tid; - int count; -}; - -static void add_rt_waker_stat(pid_t waker_tid, - struct render_thread_info_t *info) -{ - struct list_head *pos, *n; - struct rt_waker_info_t *new_waker; - struct rt_waker_info_t *waker; - - list_for_each_safe(pos, n, &info->waker_list) { - waker = list_entry(pos, struct rt_waker_info_t, list); - - if (waker->waker_tid == waker_tid) { - if (waker->count % 30 == 0) { - rt_err("%d wake up %d %d times\n", waker_tid, info->rt_tid, waker->count); - } - - waker->count++; - return; - } - } - - /*add a new waker*/ - new_waker = kmem_cache_zalloc(rt_waker_cache, GFP_ATOMIC); - - if (new_waker) { - rt_err("Add a new waker %d for %d\n", waker_tid, info->rt_tid); - new_waker->waker_tid = waker_tid; - new_waker->count = 1; - list_add_tail(&new_waker->list, &info->waker_list); - } - return; -} - -/* - * render_thread_info_handler is callback funtion called in core.c->try_to_wake_up - */ -static void render_thread_info_handler(void *unused, struct task_struct *taskp) -{ - int i = 0; - struct task_struct *task = taskp; - pid_t wakee_tid = 0, waker_tid = 0; - - if (rt_num <= 0) { - return; - } - - if (current != NULL) { - waker_tid = current->pid; - - } else { - rt_err("current is NULL\n"); - return; - } - - if (taskp == NULL) { - return; - } - - wakee_tid = task->pid; - - /* only update waker stat when lock is available, - * if not available, skip these information - */ - if (spin_trylock(&rt_info_lock)) { - for (i = 0; i < rt_num; i++) { - if (wakee_tid == render_thread_info[i].rt_tid) { - /* found one wakeup - * rt_err("waker: %d:%s, tgid: %d\n", current->pid, current->comm, current->tgid); - * rt_err("wakee: %d:%s, tgid: %d\n", render_thread_info[i].rt_task->pid, - * render_thread_info[i].rt_task->comm, - * render_thread_info[i].rt_task->tgid); - */ - /*waker and wakee belongs to same pid*/ - if (current->tgid == render_thread_info[i].rt_task->tgid) { - add_rt_waker_stat(waker_tid, &render_thread_info[i]); - } - } - } - - spin_unlock(&rt_info_lock); - - } else { - rt_err("fail to get lock\n"); - } -} - -static int proc_rt_num_show(struct seq_file *m, void *v) -{ - int i; - seq_printf(m, "%d: ", rt_num); - - for (i = 0; i < rt_num; i++) { - seq_printf(m, "%d ", render_thread_info[i].rt_tid); - } - - seq_printf(m, "\n"); - - return 0; -} -static int proc_rt_sched_info_show(struct seq_file *m, void *v) -{ - int i; - struct list_head *pos, *n; - struct rt_waker_info_t *waker; - - rt_err("%d render thread\n", rt_num); - - spin_lock(&rt_info_lock); - - for (i = 0; i < rt_num; i++) { - list_for_each_safe(pos, n, &render_thread_info[i].waker_list) { - waker = list_entry(pos, struct rt_waker_info_t, list); - - if (waker != NULL) { - rt_err("waker: %d\n", waker->waker_tid); - seq_printf(m, "%d %d %d\n", waker->waker_tid, - render_thread_info[i].rt_tid, waker->count); - } - } - } - - spin_unlock(&rt_info_lock); - - return 0; -} - -static int proc_rt_info_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, proc_rt_sched_info_show, inode); -} - -static int proc_rt_num_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, proc_rt_num_show, inode); -} - -static void free_waker_list(struct list_head *waker_list) -{ - struct list_head *pos, *n; - struct rt_waker_info_t *waker; - - list_for_each_safe(pos, n, waker_list) { - waker = list_entry(pos, struct rt_waker_info_t, list); - list_del(&waker->list); - kmem_cache_free(rt_waker_cache, waker); - } - return; -} - -static ssize_t proc_rt_info_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[128] = {0, }; - char *iter = buffer; - int i; - struct task_struct *task; - pid_t tid; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) { - count = sizeof(buffer) - 1; - } - - if (copy_from_user(buffer, buf, count)) { - return -EFAULT; - } - - rt_err("Input string %s\n", buffer); - - /*input should be "123 234 345"*/ - rt_num = 0; - - /*TODO: clear pervious rt stat, need to free rt_waker_info_t*/ - for (i = 0; i < rt_num; i++) { - put_task_stack(render_thread_info[i].rt_task); - - free_waker_list(&render_thread_info[i].waker_list); - } - - memset(render_thread_info, 0, sizeof(render_thread_info)); - - spin_lock(&rt_info_lock); - - while (iter != NULL) { - sscanf(iter, "%d", &tid); - - rt_err("read pid %d\n", tid); - iter = strchr(iter + 1, ' '); - - rcu_read_lock(); - task = pid_task(find_pid_ns(tid, task_active_pid_ns(current)), PIDTYPE_PID); - - if (task) { - get_task_struct(task); - } - - rcu_read_unlock(); - - if (task) { - rt_err("find task %d:%s\n", task->pid, task->comm); - render_thread_info[rt_num].rt_tid = tid; - render_thread_info[rt_num].rt_task = task; - INIT_LIST_HEAD(&render_thread_info[rt_num].waker_list); - - } else { - rt_err("failed to find task_struct for %d\n", tid); - continue; - } - - rt_num++; - - if (rt_num > MAX_RT_NUM) { - break; - } - } - - spin_unlock(&rt_info_lock); - - rt_err("total %d tid to track\n", rt_num); - - return count; -} - -const struct proc_ops proc_rt_info_operations = { - .proc_open = proc_rt_info_open, - .proc_write = proc_rt_info_write, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; - -const struct proc_ops rt_num_operations = { - .proc_open = proc_rt_num_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; - -static int __init rt_info_init(void) -{ - struct proc_dir_entry *rt_sched_info; - - game_dir = proc_mkdir("game_opt", NULL); - - if (NULL == game_dir) { - rt_err("fail to mkdir /proc/game_opt\n"); - return -ENOMEM; - } - - rt_sched_info = proc_create_data("render_thread_info", 0770, game_dir, - &proc_rt_info_operations, NULL); - - if (NULL == rt_sched_info) { - rt_err("fail to create /proc/game_opt/render_thread_info\n"); - return -ENOMEM; - } - - proc_create_data("rt_num", 0770, game_dir, &rt_num_operations, NULL); - - rt_waker_cache = kmem_cache_create("rt_waker_cache", - sizeof(struct render_thread_info_t), 0, 0, NULL); - - if (NULL == rt_waker_cache) { - rt_err("fail to create rt_waker_cache\n"); - return -ENOMEM; - } - - register_trace_android_rvh_try_to_wake_up(render_thread_info_handler, NULL); - - return 0; -} - -static void __exit rt_info_exit(void) -{ - if (rt_waker_cache) { - kmem_cache_destroy(rt_waker_cache); - } - - remove_proc_entry("render_thread_info", game_dir); - remove_proc_entry("game_opt", NULL); -} - - -module_init(rt_info_init); -module_exit(rt_info_exit); - - -MODULE_DESCRIPTION("RT info for game optimization"); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("JiangFei@GameOpt"); diff --git a/drivers/soc/oplus/system/rt_info/rt_info.h b/drivers/soc/oplus/system/rt_info/rt_info.h deleted file mode 100755 index e5b7f1b209af..000000000000 --- a/drivers/soc/oplus/system/rt_info/rt_info.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _RT_INFO_H_ -#define _RT_INFO_H_ - -#include -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#include "../../../../../kernel_platform/common/kernel/sched/sched.h" -#include "../../../../../kernel_platform/common/drivers/android/binder_internal.h" -#include "../../../../../kernel_platform/common/drivers/android/binder_alloc.h" -#else -#include "../../../../../kernel-5.10/kernel/sched/sched.h" -#include "../../../../../kernel-5.10/drivers/android/binder_internal.h" -#include "../../../../../kernel-5.10/drivers/android/binder_alloc.h" -#endif - -#define MAX_RT_NUM 8 - -#ifdef RT_INFO_DEBUG -#define rt_err(fmt, ...) \ - printk_deferred(KERN_ERR "[RT_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#else -#define rt_err(fmt, ...) -#endif - -#endif /*_RT_INFO_H_*/ diff --git a/drivers/soc/oplus/system/shutdown_detect/Kconfig b/drivers/soc/oplus/system/shutdown_detect/Kconfig deleted file mode 100755 index 6a51b1180ce7..000000000000 --- a/drivers/soc/oplus/system/shutdown_detect/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_SHUTDOWN_DETECT - tristate "shutdown hang detect" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable shutdown_detect. diff --git a/drivers/soc/oplus/system/shutdown_detect/Makefile b/drivers/soc/oplus/system/shutdown_detect/Makefile deleted file mode 100755 index 1ba7d4aa81d4..000000000000 --- a/drivers/soc/oplus/system/shutdown_detect/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -obj-$(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) += shutdown_detect.o -else -ifeq ($(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT), y) -obj-$(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) += shutdown_detect.o -endif -ifeq ($(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT), m) -obj-$(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) += gki/shutdown_detect.o -endif -endif - diff --git a/drivers/soc/oplus/system/shutdown_detect/gki/Kconfig b/drivers/soc/oplus/system/shutdown_detect/gki/Kconfig deleted file mode 100755 index 6a51b1180ce7..000000000000 --- a/drivers/soc/oplus/system/shutdown_detect/gki/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_SHUTDOWN_DETECT - tristate "shutdown hang detect" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable shutdown_detect. diff --git a/drivers/soc/oplus/system/shutdown_detect/gki/shutdown_detect.c b/drivers/soc/oplus/system/shutdown_detect/gki/shutdown_detect.c deleted file mode 100755 index 3b4d60748617..000000000000 --- a/drivers/soc/oplus/system/shutdown_detect/gki/shutdown_detect.c +++ /dev/null @@ -1,629 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/********************************************************************************** -* Description: shutdown_detect Monitor Kernel Driver -* -* Version : 1.0 -***********************************************************************************/ -#define FILP_OPEN_FUNCTION_CLOSE 0 - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#endif - -#include - -#define SEQ_printf(m, x...) \ - do { \ - if (m) \ - seq_printf(m, x); \ - else \ - pr_debug(x); \ - } while (0) - -#define OPLUS_SHUTDOWN_LOG_START_BLOCK_EMMC 10240 -#define OPLUS_SHUTDOWN_LOG_START_BLOCK_UFS 1280 -#define OPLUS_SHUTDOWN_KERNEL_LOG_SIZE_BYTES 1024 * 1024 -#define OPLUS_SHUTDOWN_FLAG_OFFSET 0 * 1024 * 1024 -#define OPLUS_SHUTDOWN_KMSG_OFFSET 61 * 1024 * 1024 -#define FILE_MODE_0666 0666 - -#define BLOCK_SIZE_EMMC 512 -#define BLOCK_SIZE_UFS 4096 - -#define SHUTDOWN_MAGIC_LEN 8 - -#define ShutDownTO 0x9B - -#define TASK_INIT_COMM "init" - -#define OPLUS_PARTITION_OPLUSRESERVE3_LINK "/dev/block/by-name/oplusreserve3" - -#define ST_LOG_NATIVE_HELPER "/system/bin/phoenix_log_native_helper.sh" - -#define SIG_SHUTDOWN (SIGRTMIN + 0x12) - -#define SHUTDOWN_STAGE_KERNEL 20 -#define SHUTDOWN_STAGE_INIT 30 -#define SHUTDOWN_STAGE_SYSTEMSERVER 40 -#define SHUTDOWN_TIMEOUNT_UMOUNT 31 -#define SHUTDOWN_TIMEOUNT_VOLUME 32 -#define SHUTDOWN_TIMEOUNT_SUBSYSTEM 43 -#define SHUTDOWN_TIMEOUNT_RADIOS 44 -#define SHUTDOWN_TIMEOUNT_PM 45 -#define SHUTDOWN_TIMEOUNT_AM 46 -#define SHUTDOWN_TIMEOUNT_BC 47 -#define SHUTDOWN_STAGE_INIT_POFF 70 -#define SHUTDOWN_RUS_MIN 255 -#define SHUTDOWN_TOTAL_TIME_MIN 60 -#define SHUTDOWN_DEFAULT_NATIVE_TIME 60 -#define SHUTDOWN_DEFAULT_JAVA_TIME 60 -#define SHUTDOWN_DEFAULT_TOTAL_TIME 150 -#define SHUTDOWN_INCREASE_TIME 5 - -#define KE_LOG_COLLECT_TIMEOUT msecs_to_jiffies(10000) - -static struct kmsg_dumper shutdown_kmsg_dumper; - -static DECLARE_COMPLETION(shd_comp); -static DEFINE_MUTEX(shd_wf_mutex); - -static unsigned int shutdown_phase; -static bool shutdown_detect_started = false; -static bool shutdown_detect_enable = true; -static bool is_shutdows = false; -static unsigned int gtimeout = 0; -static unsigned int gtotaltimeout = SHUTDOWN_DEFAULT_TOTAL_TIME; -static unsigned int gjavatimeout = SHUTDOWN_DEFAULT_JAVA_TIME; -static unsigned int gnativetimeout = SHUTDOWN_DEFAULT_NATIVE_TIME; - -static struct task_struct *shutdown_task = NULL; -struct task_struct *shd_complete_monitor = NULL; - -struct shd_info -{ - char magic[SHUTDOWN_MAGIC_LEN]; - int shutdown_err; - int shutdown_times; -}; - -#define SIZEOF_STRUCT_SHD_INFO sizeof(struct shd_info) - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -time_t shutdown_start_time = 0; -time_t shutdown_end_time = 0; -time_t shutdown_systemserver_start_time = 0; -time_t shutdown_init_start_time = 0; -time_t shutdown_kernel_start_time = 0; -#else -time64_t shutdown_start_time = 0; -time64_t shutdown_end_time = 0; -time64_t shutdown_systemserver_start_time = 0; -time64_t shutdown_init_start_time = 0; -time64_t shutdown_kernel_start_time = 0; -#endif - -static int shutdown_kthread(void *data){ - kernel_power_off(); - return 0; -} - -unsigned int g_shutdown_flag = 0; -EXPORT_SYMBOL(g_shutdown_flag); - -static int shutdown_detect_func(void *dummy); - -static void shutdown_timeout_flag_write(int timeout); -static void shutdown_dump_kernel_log(void); -static int shutdown_timeout_flag_write_now(void *args); - -extern int creds_change_dac(void); -extern int shutdown_kernel_log_save(void *args); -extern void shutdown_dump_android_log(void); - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static struct timespec current_boottime_time(void) -{ - struct timespec ts; - - getboottime(&ts); - - return ts; -} -#else -static time64_t current_kernel_time(void) -{ - struct timespec64 ts64; - - ktime_get_real_ts64(&ts64); - - return ts64.tv_sec; -} -#endif - -static ssize_t shutdown_detect_trigger(struct file *filp, const char *ubuf, size_t cnt, loff_t *data) -{ - char buf[64]; - long val = 0; - int ret = 0; -#ifdef OPLUS_BUG_STABILITY - struct task_struct *tsk = NULL; -#endif - unsigned int temp = SHUTDOWN_DEFAULT_TOTAL_TIME; - - if(shutdown_detect_enable == false) { - return -EPERM; - } - - if (cnt >= sizeof(buf)) { - return -EINVAL; - } - - if (copy_from_user(&buf, ubuf, cnt)) { - return -EFAULT; - } - - buf[cnt] = 0; - - ret = kstrtoul(buf, 0, (unsigned long *)&val); - - if (ret < 0) { - return ret; - } - - if (val == SHUTDOWN_STAGE_INIT_POFF) { - is_shutdows = true; - val = SHUTDOWN_STAGE_INIT; - } - - if (OEM_RELEASE != get_eng_version()) { - gnativetimeout += SHUTDOWN_INCREASE_TIME; - gjavatimeout += SHUTDOWN_INCREASE_TIME; - } -#ifdef OPLUS_BUG_STABILITY - tsk = current->group_leader; - pr_info("%s:%d shutdown_detect, GroupLeader is %s:%d\n", current->comm, task_pid_nr(current), tsk->comm, task_pid_nr(tsk)); -#endif /*OPLUS_BUG_STABILITY*/ - //val: 0x gtotaltimeout|gjavatimeout|gnativetimeout , gnativetimeout < F, gjavatimeout < F - if (val > SHUTDOWN_RUS_MIN) { - gnativetimeout = val % 16; - gjavatimeout = ((val - gnativetimeout) % 256 ) / 16; - temp = val / 256; - gtotaltimeout = (temp < SHUTDOWN_TOTAL_TIME_MIN) ? SHUTDOWN_TOTAL_TIME_MIN : temp;// for safe - pr_info("shutdown_detect_trigger rus val %ld %d %d %d\n", val, gnativetimeout, gjavatimeout, gtotaltimeout); - return cnt; - } - - //pr_err("shutdown_detect_trigger final val %ld %d %d %d\n", val, gnativetimeout, gjavatimeout, gtotaltimeout); - - switch (val) { - case 0: - if (shutdown_detect_started) { - shutdown_detect_started = false; - shutdown_phase = 0; - } - shutdown_detect_enable = false; - pr_err("shutdown_detect: abort shutdown detect\n"); - break; - case SHUTDOWN_STAGE_KERNEL: -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) - shutdown_kernel_start_time = current_boottime_time().tv_sec; -#else - shutdown_kernel_start_time = current_kernel_time(); -#endif - pr_info("shutdown_kernel_start_time %ld\n", shutdown_kernel_start_time); - if((shutdown_kernel_start_time - shutdown_init_start_time) > gnativetimeout) { - pr_err("shutdown_detect_timeout: timeout happened in reboot.cpp\n"); - shutdown_dump_kernel_log(); - shutdown_timeout_flag_write(1); - } else { - if(((shutdown_init_start_time - shutdown_systemserver_start_time) > gjavatimeout) && shutdown_systemserver_start_time) { - // timeout happend in system_server stage - shutdown_timeout_flag_write(1); - } - } - shutdown_phase = val; - pr_err("shutdown_detect_phase: shutdown current phase systemcall\n"); - break; - case SHUTDOWN_STAGE_INIT: - if (!shutdown_detect_started) { - shutdown_detect_started = true; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) - shutdown_init_start_time = current_boottime_time().tv_sec; -#else - shutdown_init_start_time = current_kernel_time(); -#endif - shutdown_start_time = shutdown_init_start_time; - shd_complete_monitor = kthread_run(shutdown_detect_func, NULL, "shutdown_detect_thread"); - if (IS_ERR(shd_complete_monitor)) { - ret = PTR_ERR(shd_complete_monitor); - pr_err("shutdown_detect: cannot start thread: %d\n", ret); - } - - } else { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) - shutdown_init_start_time = current_boottime_time().tv_sec; -#else - shutdown_init_start_time = current_kernel_time(); -#endif - if((shutdown_init_start_time - shutdown_systemserver_start_time) > gjavatimeout) { - pr_err("shutdown_detect_timeout: timeout happened in system_server stage\n"); - shutdown_dump_android_log(); - shutdown_dump_kernel_log(); - } - } - //pr_err("shutdown_init_start_time %ld\n", shutdown_init_start_time); - shutdown_phase = val; - pr_err("shutdown_detect_phase: shutdown current phase init\n"); - break; - case SHUTDOWN_TIMEOUNT_UMOUNT: - pr_err("shutdown_detect_timeout: umount timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_VOLUME: - pr_err("shutdown_detect_timeout: volume shutdown timeout\n"); - break; - case SHUTDOWN_STAGE_SYSTEMSERVER: -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) - shutdown_systemserver_start_time = current_boottime_time().tv_sec; -#else - shutdown_systemserver_start_time = current_kernel_time(); -#endif - //pr_err("shutdown_systemserver_start_time %ld\n", shutdown_systemserver_start_time); - if (!shutdown_detect_started) { - shutdown_detect_started = true; - shutdown_start_time = shutdown_systemserver_start_time; - shd_complete_monitor = kthread_run(shutdown_detect_func, NULL, "shutdown_detect_thread"); - } - shutdown_phase = val; - g_shutdown_flag = 1; - pr_err("shutdown_detect_phase: shutdown current phase systemserver\n"); - break; - case SHUTDOWN_TIMEOUNT_SUBSYSTEM: - pr_err("shutdown_detect_timeout: ShutdownSubSystem timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_RADIOS: - pr_err("shutdown_detect_timeout: ShutdownRadios timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_PM: - pr_err("shutdown_detect_timeout: ShutdownPackageManager timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_AM: - pr_err("shutdown_detect_timeout: ShutdownActivityManager timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_BC: - pr_err("shutdown_detect_timeout: SendShutdownBroadcast timeout\n"); - break; - default: - break; - } - if(!shutdown_task && is_shutdows) { - shutdown_task = kthread_create(shutdown_kthread, NULL,"shutdown_kthread"); - if (IS_ERR(shutdown_task)) { - pr_err("create shutdown thread fail, will BUG()\n"); - msleep(60*1000); - BUG(); - } - } - return cnt; -} - -static int shutdown_detect_show(struct seq_file *m, void *v) -{ - SEQ_printf(m, "=== shutdown_detect controller ===\n"); - SEQ_printf(m, "0: shutdown_detect abort\n"); - SEQ_printf(m, "20: shutdown_detect systemcall reboot phase\n"); - SEQ_printf(m, "30: shutdown_detect init reboot phase\n"); - SEQ_printf(m, "40: shutdown_detect system server reboot phase\n"); - SEQ_printf(m, "=== shutdown_detect controller ===\n\n"); - SEQ_printf(m, "shutdown_detect: shutdown phase: %u\n", shutdown_phase); - return 0; -} - -static int shutdown_detect_open(struct inode *inode, struct file *file) -{ - return single_open(file, shutdown_detect_show, inode->i_private); -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static const struct file_operations shutdown_detect_fops = { - .open = shutdown_detect_open, - .write = shutdown_detect_trigger, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; -#else -static const struct proc_ops shutdown_detect_fops = { - .proc_open = shutdown_detect_open, - .proc_write = shutdown_detect_trigger, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; -#endif - -static int dump_kmsg(const char * filepath, size_t offset_of_start, struct kmsg_dumper *kmsg_dumper) -{ -#if FILP_OPEN_FUNCTION_CLOSE - struct file *opfile; - loff_t offset; - char line[1024] = {0}; - size_t len = 0; - int result = -1; - size_t bytes_writed = 0; - - opfile = filp_open(filepath, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); - if (IS_ERR(opfile)) - { - pr_err("filp_open %s failed, error: %ld\n", filepath, PTR_ERR(opfile)); - return -1; - } - offset = offset_of_start; - - kmsg_dumper->active = true; - while (kmsg_dump_get_line(kmsg_dumper, true, line, sizeof(line), &len)) { - line[len] = '\0'; - mutex_lock(&shd_wf_mutex); - - bytes_writed = kernel_write(opfile, line, len, &offset); - - if(len != bytes_writed) - { - pr_err("kernel_write %s failed, len: %lu bytes_writed: %lu\n", filepath, len, bytes_writed); - mutex_unlock(&shd_wf_mutex); - result = -1; - goto shd_fail; - } - mutex_unlock(&shd_wf_mutex); - } - result = 0; - -shd_fail: - vfs_fsync(opfile, 0); - filp_close(opfile, NULL); - return result; -#endif - return 0; /* FILP_OPEN_FUNCTION_CLOSE */ -} - -int shutdown_kernel_log_save(void *args) -{ - if (0 != dump_kmsg(OPLUS_PARTITION_OPLUSRESERVE3_LINK, OPLUS_SHUTDOWN_KMSG_OFFSET, &shutdown_kmsg_dumper)) { - pr_err("dump kmsg to OPLUS_PARTITION_OPLUSRESERVE3_LINK failed\n"); - complete(&shd_comp); - return -1; - } - complete(&shd_comp); - return 1; -} - -static int shutdown_timeout_flag_write_now(void *args) -{ -#if FILP_OPEN_FUNCTION_CLOSE - struct file *opfile; - ssize_t size; - loff_t offsize; - char data_info[SIZEOF_STRUCT_SHD_INFO] = {'\0'}; - int rc; - struct shd_info shutdown_flag; - - opfile = filp_open(OPLUS_PARTITION_OPLUSRESERVE3_LINK, O_RDWR, 0600); - if (IS_ERR(opfile)) { - pr_err("open OPLUS_PARTITION_OPLUSRESERVE3_LINK error: %ld\n", PTR_ERR(opfile)); - complete(&shd_comp); - return -1; - } - - offsize = OPLUS_SHUTDOWN_FLAG_OFFSET; - - strncpy(shutdown_flag.magic, "ShutDown", SHUTDOWN_MAGIC_LEN); - if(gtimeout) { - shutdown_flag.shutdown_err = ShutDownTO; - } else { - shutdown_flag.shutdown_err = 0; - } - - shutdown_flag.shutdown_times = (int)(shutdown_end_time - shutdown_start_time); - - memcpy(data_info, &shutdown_flag, SIZEOF_STRUCT_SHD_INFO); - - size = kernel_write(opfile, data_info, SIZEOF_STRUCT_SHD_INFO, &offsize); - if (size < 0) { - pr_err("kernel_write data_info %s size %ld \n", data_info, size); - filp_close(opfile,NULL); - complete(&shd_comp); - return -1; - } - - rc = vfs_fsync(opfile, 1); - if (rc) - pr_err("sync returns %d\n", rc); - - filp_close(opfile,NULL); - pr_info("shutdown_timeout_flag_write_now done \n"); - complete(&shd_comp); -#endif - return 0; -} - -static void task_comm_to_struct(const char * pcomm, struct task_struct ** t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) - { - if(!strcmp(t->comm, pcomm)) - { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) -#define __si_special(priv) \ - ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO) -#endif -void shutdown_dump_android_log(void) -{ - struct task_struct *sd_init; - sd_init = NULL; - task_comm_to_struct(TASK_INIT_COMM, &sd_init); - if(NULL != sd_init) - { - pr_err("send shutdown_dump_android_log signal %d", SIG_SHUTDOWN); -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) - send_sig_info(SIG_SHUTDOWN, __si_special(0), sd_init); -#else - send_sig(SIG_SHUTDOWN, sd_init, 0); -#endif - pr_err("after send shutdown_dump_android_log signal %d", SIG_SHUTDOWN); - // wait to collect shutdown log finished - schedule_timeout_interruptible(20 * HZ); - } -} - -static void shutdown_dump_kernel_log(void) -{ - struct task_struct *tsk; - tsk = kthread_run(shutdown_kernel_log_save, NULL, "shd_collect_dmesg"); - if(IS_ERR(tsk)) - { - pr_err("create kernel thread shd_collect_dmesg failed\n"); - return; - } - // wait max 10s to collect shutdown log finished - if(!wait_for_completion_timeout(&shd_comp, KE_LOG_COLLECT_TIMEOUT)) - { - pr_err("collect kernel log timeout\n"); - } -} - -static void shutdown_timeout_flag_write(int timeout) -{ - struct task_struct *tsk; - - gtimeout = timeout; - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) - shutdown_end_time = current_boottime_time().tv_sec; -#else - shutdown_end_time = current_kernel_time(); -#endif - - tsk = kthread_run(shutdown_timeout_flag_write_now, NULL, "shd_to_flag"); - if(IS_ERR(tsk)) - { - pr_err("create kernel thread shd_to_flag failed\n"); - return; - } - // wait max 10s to collect shutdown log finished - if(!wait_for_completion_timeout(&shd_comp, KE_LOG_COLLECT_TIMEOUT)) - { - pr_err("shutdown_timeout_flag_write timeout\n"); - } -} - -static int shutdown_detect_func(void *dummy) -{ - //schedule_timeout_uninterruptible(gtotaltimeout * HZ); - msleep(gtotaltimeout * 1000); - - pr_err("shutdown_detect:%s call sysrq show block and cpu thread. BUG\n", __func__); - handle_sysrq('w'); - handle_sysrq('l'); - pr_err("shutdown_detect:%s shutdown_detect status:%u. \n", __func__, shutdown_phase); - - if(shutdown_phase >= SHUTDOWN_STAGE_INIT) { - shutdown_dump_android_log(); - } - - shutdown_dump_kernel_log(); - - shutdown_timeout_flag_write(1);// timeout happened - - if (OEM_RELEASE == get_eng_version()) { - if(is_shutdows){ - pr_err("shutdown_detect: shutdown or reboot? shutdown\n"); - if(shutdown_task) { - wake_up_process(shutdown_task); - } - }else{ - pr_err("shutdown_detect: shutdown or reboot? reboot\n"); - BUG(); - } - } else { - pr_err("shutdown_detect_error, keep origin follow in !release build, but you can still get log in oplusreserve3\n"); - } - return 0; -} - -static int __init init_shutdown_detect_ctrl(void) -{ - struct proc_dir_entry *pe; - pr_err("shutdown_detect:register shutdown_detect interface\n"); - pe = proc_create("shutdown_detect", 0664, NULL, &shutdown_detect_fops); - if (!pe) { - pr_err("shutdown_detect:Failed to register shutdown_detect interface\n"); - return -ENOMEM; - } - return 0; -} - -device_initcall(init_shutdown_detect_ctrl); - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/shutdown_detect/shutdown_detect.c b/drivers/soc/oplus/system/shutdown_detect/shutdown_detect.c deleted file mode 100755 index cbc300523934..000000000000 --- a/drivers/soc/oplus/system/shutdown_detect/shutdown_detect.c +++ /dev/null @@ -1,619 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/********************************************************************************** -* Description: shutdown_detect Monitor Kernel Driver -* -* Version : 1.0 -***********************************************************************************/ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include -#endif - -#include - -#define SEQ_printf(m, x...) \ - do { \ - if (m) \ - seq_printf(m, x); \ - else \ - pr_debug(x); \ - } while (0) - -#define OPLUS_SHUTDOWN_LOG_START_BLOCK_EMMC 10240 -#define OPLUS_SHUTDOWN_LOG_START_BLOCK_UFS 1280 -#define OPLUS_SHUTDOWN_KERNEL_LOG_SIZE_BYTES 1024 * 1024 -#define OPLUS_SHUTDOWN_FLAG_OFFSET 0 * 1024 * 1024 -#define OPLUS_SHUTDOWN_KMSG_OFFSET 61 * 1024 * 1024 -#define FILE_MODE_0666 0666 - -#define BLOCK_SIZE_EMMC 512 -#define BLOCK_SIZE_UFS 4096 - -#define SHUTDOWN_MAGIC_LEN 8 - -#define ShutDownTO 0x9B - -#define TASK_INIT_COMM "init" - -#define OPPO_PARTITION_OPPORESERVE3_LINK "/dev/block/by-name/opporeserve3" -#define OPLUS_PARTITION_OPLUSRESERVE3_LINK "/dev/block/by-name/oplusreserve3" - -#define ST_LOG_NATIVE_HELPER "/system/bin/phoenix_log_native_helper.sh" - -#define SIG_SHUTDOWN (SIGRTMIN + 0x12) - -#define SHUTDOWN_STAGE_KERNEL 20 -#define SHUTDOWN_STAGE_INIT 30 -#define SHUTDOWN_STAGE_SYSTEMSERVER 40 -#define SHUTDOWN_TIMEOUNT_UMOUNT 31 -#define SHUTDOWN_TIMEOUNT_VOLUME 32 -#define SHUTDOWN_TIMEOUNT_SUBSYSTEM 43 -#define SHUTDOWN_TIMEOUNT_RADIOS 44 -#define SHUTDOWN_TIMEOUNT_PM 45 -#define SHUTDOWN_TIMEOUNT_AM 46 -#define SHUTDOWN_TIMEOUNT_BC 47 -#define SHUTDOWN_STAGE_INIT_POFF 70 -#define SHUTDOWN_RUS_MIN 255 -#define SHUTDOWN_TOTAL_TIME_MIN 60 -#define SHUTDOWN_DEFAULT_NATIVE_TIME 60 -#define SHUTDOWN_DEFAULT_JAVA_TIME 60 -#define SHUTDOWN_DEFAULT_TOTAL_TIME 150 -#define SHUTDOWN_INCREASE_TIME 5 - -#define KE_LOG_COLLECT_TIMEOUT msecs_to_jiffies(10000) - -static struct kmsg_dumper shutdown_kmsg_dumper; - -static DECLARE_COMPLETION(shd_comp); -static DEFINE_MUTEX(shd_wf_mutex); - -static unsigned int shutdown_phase; -static bool shutdown_detect_started = false; -static bool shutdown_detect_enable = true; -static bool is_shutdows = false; -static unsigned int gtimeout = 0; -static unsigned int gtotaltimeout = SHUTDOWN_DEFAULT_TOTAL_TIME; -static unsigned int gjavatimeout = SHUTDOWN_DEFAULT_JAVA_TIME; -static unsigned int gnativetimeout = SHUTDOWN_DEFAULT_NATIVE_TIME; - -static struct task_struct *shutdown_task = NULL; -struct task_struct *shd_complete_monitor = NULL; - -unsigned int g_shutdown_flag = 0; -EXPORT_SYMBOL(g_shutdown_flag); -struct shd_info -{ - char magic[SHUTDOWN_MAGIC_LEN]; - int shutdown_err; - int shutdown_times; -}; - -#define SIZEOF_STRUCT_SHD_INFO sizeof(struct shd_info) - -time_t shutdown_start_time = 0; -time_t shutdown_end_time = 0; -time_t shutdown_systemserver_start_time = 0; -time_t shutdown_init_start_time = 0; -time_t shutdown_kernel_start_time = 0; - -static int shutdown_kthread(void *data) -{ - kernel_power_off(); - return 0; -} - -static int shutdown_detect_func(void *dummy); - -static void shutdown_timeout_flag_write(int timeout); -static void shutdown_dump_kernel_log(void); -static int shutdown_timeout_flag_write_now(void *args); - -extern int creds_change_dac(void); -extern int shutdown_kernel_log_save(void *args); -extern void shutdown_dump_android_log(void); - -static struct timespec current_boottime_time(void) -{ - struct timespec ts; - - getboottime(&ts); - - return ts; -} - -static ssize_t shutdown_detect_trigger(struct file *filp, const char *ubuf, - size_t cnt, loff_t *data) -{ - char buf[64]; - long val = 0; - int ret = 0; -#ifdef OPLUS_BUG_STABILITY - struct task_struct *tsk = NULL; -#endif - unsigned int temp = SHUTDOWN_DEFAULT_TOTAL_TIME; - - if (shutdown_detect_enable == false) { - return -EPERM; - } - - if (cnt >= sizeof(buf)) { - return -EINVAL; - } - - if (copy_from_user(&buf, ubuf, cnt)) { - return -EFAULT; - } - - buf[cnt] = 0; - - ret = kstrtoul(buf, 0, (unsigned long *)&val); - - if (ret < 0) { - return ret; - } - - if (val == SHUTDOWN_STAGE_INIT_POFF) { - is_shutdows = true; - val = SHUTDOWN_STAGE_INIT; - } - - if (OEM_RELEASE != get_eng_version()) { - gnativetimeout += SHUTDOWN_INCREASE_TIME; - gjavatimeout += SHUTDOWN_INCREASE_TIME; - } - -#ifdef OPLUS_BUG_STABILITY - tsk = current->group_leader; - pr_info("%s:%d shutdown_detect, GroupLeader is %s:%d\n", current->comm, - task_pid_nr(current), tsk->comm, task_pid_nr(tsk)); -#endif /*OPLUS_BUG_STABILITY*/ - //val: 0x gtotaltimeout|gjavatimeout|gnativetimeout , gnativetimeout < F, gjavatimeout < F - if (val > SHUTDOWN_RUS_MIN) { - gnativetimeout = val % 16; - gjavatimeout = ((val - gnativetimeout) % 256 ) / 16; - temp = val / 256; - gtotaltimeout = (temp < SHUTDOWN_TOTAL_TIME_MIN) ? SHUTDOWN_TOTAL_TIME_MIN : temp;// for safe - pr_info("shutdown_detect_trigger rus val %ld %d %d %d\n", val, gnativetimeout, gjavatimeout, gtotaltimeout); - return cnt; - } - - //pr_err("shutdown_detect_trigger final val %ld %d %d %d\n", val, gnativetimeout, gjavatimeout, gtotaltimeout); - - switch (val) { - case 0: - if (shutdown_detect_started) { - shutdown_detect_started = false; - shutdown_phase = 0; - } - shutdown_detect_enable = false; - pr_err("shutdown_detect: abort shutdown detect\n"); - break; - case SHUTDOWN_STAGE_KERNEL: - shutdown_kernel_start_time = current_boottime_time().tv_sec; - pr_info("shutdown_kernel_start_time %ld\n", shutdown_kernel_start_time); - if((shutdown_kernel_start_time - shutdown_init_start_time) > gnativetimeout) { - pr_err("shutdown_detect_timeout: timeout happened in reboot.cpp\n"); - shutdown_dump_kernel_log(); - shutdown_timeout_flag_write(1); - } else { - if(((shutdown_init_start_time - shutdown_systemserver_start_time) > gjavatimeout) && shutdown_systemserver_start_time) { - // timeout happend in system_server stage - shutdown_timeout_flag_write(1); - } - } - shutdown_phase = val; - pr_err("shutdown_detect_phase: shutdown current phase systemcall\n"); - break; - case SHUTDOWN_STAGE_INIT: - if (!shutdown_detect_started) { - shutdown_detect_started = true; - shutdown_init_start_time = current_boottime_time().tv_sec; - shutdown_start_time = shutdown_init_start_time; - shd_complete_monitor = kthread_run(shutdown_detect_func, NULL, "shutdown_detect_thread"); - if (IS_ERR(shd_complete_monitor)) { - ret = PTR_ERR(shd_complete_monitor); - pr_err("shutdown_detect: cannot start thread: %d\n", ret); - } - - } else { - shutdown_init_start_time = current_boottime_time().tv_sec; - - if((shutdown_init_start_time - shutdown_systemserver_start_time) > gjavatimeout) { - pr_err("shutdown_detect_timeout: timeout happened in system_server stage\n"); - shutdown_dump_android_log(); - shutdown_dump_kernel_log(); - } - } - //pr_err("shutdown_init_start_time %ld\n", shutdown_init_start_time); - shutdown_phase = val; - pr_err("shutdown_detect_phase: shutdown current phase init\n"); - break; - case SHUTDOWN_TIMEOUNT_UMOUNT: - pr_err("shutdown_detect_timeout: umount timeout\n"); - break; - case SHUTDOWN_TIMEOUNT_VOLUME: - pr_err("shutdown_detect_timeout: volume shutdown timeout\n"); - break; - case SHUTDOWN_STAGE_SYSTEMSERVER: - shutdown_systemserver_start_time = current_boottime_time().tv_sec; - - //pr_err("shutdown_systemserver_start_time %ld\n", shutdown_systemserver_start_time); - if (!shutdown_detect_started) { - shutdown_detect_started = true; - shutdown_start_time = shutdown_systemserver_start_time; - shd_complete_monitor = kthread_run(shutdown_detect_func, NULL, "shutdown_detect_thread"); - } - shutdown_phase = val; - g_shutdown_flag = 1; - pr_err("shutdown_detect_phase: shutdown current phase systemserver\n"); - break; - case SHUTDOWN_TIMEOUNT_SUBSYSTEM: - pr_err("shutdown_detect_timeout: ShutdownSubSystem timeout\n"); - break; - - case SHUTDOWN_TIMEOUNT_RADIOS: - pr_err("shutdown_detect_timeout: ShutdownRadios timeout\n"); - break; - - case SHUTDOWN_TIMEOUNT_PM: - pr_err("shutdown_detect_timeout: ShutdownPackageManager timeout\n"); - break; - - case SHUTDOWN_TIMEOUNT_AM: - pr_err("shutdown_detect_timeout: ShutdownActivityManager timeout\n"); - break; - - case SHUTDOWN_TIMEOUNT_BC: - pr_err("shutdown_detect_timeout: SendShutdownBroadcast timeout\n"); - break; - - default: - break; - } - - if (!shutdown_task && is_shutdows) { - shutdown_task = kthread_create(shutdown_kthread, NULL, "shutdown_kthread"); - - if (IS_ERR(shutdown_task)) { - pr_err("create shutdown thread fail, will BUG()\n"); - msleep(60 * 1000); - BUG(); - } - } - - return cnt; -} - -static int shutdown_detect_show(struct seq_file *m, void *v) -{ - SEQ_printf(m, "=== shutdown_detect controller ===\n"); - SEQ_printf(m, "0: shutdown_detect abort\n"); - SEQ_printf(m, "20: shutdown_detect systemcall reboot phase\n"); - SEQ_printf(m, "30: shutdown_detect init reboot phase\n"); - SEQ_printf(m, "40: shutdown_detect system server reboot phase\n"); - SEQ_printf(m, "=== shutdown_detect controller ===\n\n"); - SEQ_printf(m, "shutdown_detect: shutdown phase: %u\n", shutdown_phase); - return 0; -} - -static int shutdown_detect_open(struct inode *inode, struct file *file) -{ - return single_open(file, shutdown_detect_show, inode->i_private); -} - -static const struct file_operations shutdown_detect_fops = { - .open = shutdown_detect_open, - .write = shutdown_detect_trigger, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int dump_kmsg(const char *filepath, size_t offset_of_start, - struct kmsg_dumper *kmsg_dumper) -{ - struct file *opfile; - loff_t offset; - char line[1024] = {0}; - size_t len = 0; - int result = -1; - size_t bytes_writed = 0; - - opfile = filp_open(filepath, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE_0666); - - if (IS_ERR(opfile)) { - pr_err("filp_open %s failed, error: %ld\n", filepath, PTR_ERR(opfile)); - return -1; - } - - offset = offset_of_start; - - kmsg_dumper->active = true; - - while (kmsg_dump_get_line(kmsg_dumper, true, line, sizeof(line), &len)) { - line[len] = '\0'; - mutex_lock(&shd_wf_mutex); - - bytes_writed = kernel_write(opfile, line, len, &offset); - - if (len != bytes_writed) { - pr_err("kernel_write %s failed, len: %lu bytes_writed: %lu\n", filepath, len, - bytes_writed); - mutex_unlock(&shd_wf_mutex); - result = -1; - goto shd_fail; - } - - mutex_unlock(&shd_wf_mutex); - } - - result = 0; - -shd_fail: - vfs_fsync(opfile, 0); - filp_close(opfile, NULL); - - return result; -} - -int shutdown_kernel_log_save(void *args) -{ - if (0 != dump_kmsg(OPPO_PARTITION_OPPORESERVE3_LINK, OPLUS_SHUTDOWN_KMSG_OFFSET, - &shutdown_kmsg_dumper)) { - pr_err("dump kmsg to OPPO_PARTITION_OPPORESERVE3_LINK failed\n"); - - if (0 != dump_kmsg(OPLUS_PARTITION_OPLUSRESERVE3_LINK, - OPLUS_SHUTDOWN_KMSG_OFFSET, &shutdown_kmsg_dumper)) { - pr_err("dump kmsg to OPLUS_PARTITION_OPLUSRESERVE3_LINK failed\n"); - complete(&shd_comp); - return -1; - } - } - - complete(&shd_comp); - return 1; -} - -static int shutdown_timeout_flag_write_now(void *args) -{ - struct file *opfile; - ssize_t size; - loff_t offsize; - char data_info[SIZEOF_STRUCT_SHD_INFO] = {'\0'}; - int rc; - struct shd_info shutdown_flag; - - opfile = filp_open(OPPO_PARTITION_OPPORESERVE3_LINK, O_RDWR, 0600); - - if (IS_ERR(opfile)) { - pr_err("open OPPO_PARTITION_OPPORESERVE3_LINK error: %ld\n", PTR_ERR(opfile)); - - opfile = filp_open(OPLUS_PARTITION_OPLUSRESERVE3_LINK, O_RDWR, 0600); - - if (IS_ERR(opfile)) { - pr_err("open OPLUS_PARTITION_OPLUSRESERVE3_LINK error: %ld\n", PTR_ERR(opfile)); - complete(&shd_comp); - return -1; - } - } - - offsize = OPLUS_SHUTDOWN_FLAG_OFFSET; - - strncpy(shutdown_flag.magic, "ShutDown", SHUTDOWN_MAGIC_LEN); - - if (gtimeout) { - shutdown_flag.shutdown_err = ShutDownTO; - - } else { - shutdown_flag.shutdown_err = 0; - } - - shutdown_flag.shutdown_times = (int)(shutdown_end_time - shutdown_start_time); - - memcpy(data_info, &shutdown_flag, SIZEOF_STRUCT_SHD_INFO); - - size = kernel_write(opfile, data_info, SIZEOF_STRUCT_SHD_INFO, &offsize); - - if (size < 0) { - pr_err("kernel_write data_info %s size %ld \n", data_info, size); - filp_close(opfile, NULL); - complete(&shd_comp); - return -1; - } - - rc = vfs_fsync(opfile, 1); - - if (rc) { - pr_err("sync returns %d\n", rc); - } - - filp_close(opfile, NULL); - pr_info("shutdown_timeout_flag_write_now done \n"); - complete(&shd_comp); - - return 0; -} - -static void task_comm_to_struct(const char *pcomm, - struct task_struct **t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) { - if (!strcmp(t->comm, pcomm)) { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) -#define __si_special(priv) \ - ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO) -#endif -void shutdown_dump_android_log(void) -{ - struct task_struct *sd_init; - sd_init = NULL; - task_comm_to_struct(TASK_INIT_COMM, &sd_init); - - if (NULL != sd_init) { - pr_err("send shutdown_dump_android_log signal %d", SIG_SHUTDOWN); -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) - send_sig_info(SIG_SHUTDOWN, __si_special(0), sd_init); -#else - send_sig(SIG_SHUTDOWN, sd_init, 0); -#endif - pr_err("after send shutdown_dump_android_log signal %d", SIG_SHUTDOWN); - /*wait to collect shutdown log finished*/ - schedule_timeout_interruptible(20 * HZ); - } -} - -static void shutdown_dump_kernel_log(void) -{ - struct task_struct *tsk; - tsk = kthread_run(shutdown_kernel_log_save, NULL, "shd_collect_dmesg"); - - if (IS_ERR(tsk)) { - pr_err("create kernel thread shd_collect_dmesg failed\n"); - return; - } - - /*wait max 10s to collect shutdown log finished*/ - if (!wait_for_completion_timeout(&shd_comp, KE_LOG_COLLECT_TIMEOUT)) { - pr_err("collect kernel log timeout\n"); - } -} - -static void shutdown_timeout_flag_write(int timeout) -{ - struct task_struct *tsk; - - gtimeout = timeout; - - shutdown_end_time = current_boottime_time().tv_sec; - - tsk = kthread_run(shutdown_timeout_flag_write_now, NULL, "shd_to_flag"); - - if (IS_ERR(tsk)) { - pr_err("create kernel thread shd_to_flag failed\n"); - return; - } - - /*wait max 10s to collect shutdown log finished*/ - if (!wait_for_completion_timeout(&shd_comp, KE_LOG_COLLECT_TIMEOUT)) { - pr_err("shutdown_timeout_flag_write timeout\n"); - } -} - -static int shutdown_detect_func(void *dummy) -{ - /*schedule_timeout_uninterruptible(gtotaltimeout * HZ);*/ - msleep(gtotaltimeout * 1000); - - pr_err("shutdown_detect:%s call sysrq show block and cpu thread. BUG\n", - __func__); - handle_sysrq('w'); - handle_sysrq('l'); - pr_err("shutdown_detect:%s shutdown_detect status:%u. \n", __func__, - shutdown_phase); - - if (shutdown_phase >= SHUTDOWN_STAGE_INIT) { - shutdown_dump_android_log(); - } - - shutdown_dump_kernel_log(); - - shutdown_timeout_flag_write(1);/*timeout happened*/ - - if (OEM_RELEASE == get_eng_version()) { - if (is_shutdows) { - pr_err("shutdown_detect: shutdown or reboot? shutdown\n"); - - if (shutdown_task) { - wake_up_process(shutdown_task); - } - - } else { - pr_err("shutdown_detect: shutdown or reboot? reboot\n"); - BUG(); - } - - } else { - pr_err("shutdown_detect_error, keep origin follow in !release build, but you can still get log in oplusreserve3\n"); - } - - return 0; -} - -static int __init init_shutdown_detect_ctrl(void) -{ - struct proc_dir_entry *pe; - pr_err("shutdown_detect:register shutdown_detect interface\n"); - pe = proc_create("shutdown_detect", 0664, NULL, &shutdown_detect_fops); - - if (!pe) { - pr_err("shutdown_detect:Failed to register shutdown_detect interface\n"); - return -ENOMEM; - } - - return 0; -} - -device_initcall(init_shutdown_detect_ctrl); - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/slabtrace/Kconfig b/drivers/soc/oplus/system/slabtrace/Kconfig deleted file mode 100755 index 7ca9276c4f43..000000000000 --- a/drivers/soc/oplus/system/slabtrace/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_SLABTRACE_DEBUG - bool "SLABTRACE debugging on by default" - depends on SLUB && SLUB_DEBUG -# default y - default n - help - Boot with debugging on by default. SLUB boots by default with - the runtime debug capabilities switched off. Add for check - common kmalloc caches memleak. diff --git a/drivers/soc/oplus/system/slabtrace/Makefile b/drivers/soc/oplus/system/slabtrace/Makefile deleted file mode 100755 index e2a08bb39c39..000000000000 --- a/drivers/soc/oplus/system/slabtrace/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) += slabtrace.o \ No newline at end of file diff --git a/drivers/soc/oplus/system/slabtrace/slabtrace.c b/drivers/soc/oplus/system/slabtrace/slabtrace.c deleted file mode 100755 index 1c55f7846515..000000000000 --- a/drivers/soc/oplus/system/slabtrace/slabtrace.c +++ /dev/null @@ -1,581 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : slabtrace.c -** Description : slabtrace -** Version : 1.0 -******************************************************************/ -#include "slabtrace.h" -/* Enalbe slabtrace: - * CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG=y - * Get more info disable Randomize_base - * CONFIG_RANDOMIZE_BASE=n - * after add the config, cat /proc/slabtrace to get slab userinfo - */ -static inline unsigned int oo_objects(struct kmem_cache_order_objects x) -{ - return x.x & OO_MASK; -} - -static void free_loc_track(struct loc_track *t) -{ - if (t->max) - free_pages((unsigned long)t->loc, - get_order(sizeof(struct location) * t->max)); -} - -static inline unsigned int slab_index(void *p, struct kmem_cache *s, void *addr) -{ - return (p - addr) / s->size; -} - -static struct track *get_track(struct kmem_cache *s, void *object, - enum track_item alloc) -{ - struct track *p; - - if (s->offset) { - p = object + s->offset + sizeof(void *); - - } else { - p = object + s->inuse; - } - - return p + alloc; -} - -#if defined(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) - -int oplus_cnt_pid(int pid) -{ - struct pid_cnt_struct *tmp; - int ret = 0; - bool find = false; - list_for_each_entry(tmp, &pid_head, list) { - if (tmp->pid == pid) { - tmp->cnt++; - find = true; - break; - } - } - - if (!find && pid_cnt_cachep) { - tmp = kmem_cache_zalloc(pid_cnt_cachep, GFP_ATOMIC); - tmp->pid = pid; - tmp->cnt = 1; - list_add_tail(&(tmp->list), &pid_head); - } - - return ret; -} - -static int oplus_memcfg_add_location(struct loc_track *t, struct kmem_cache *s, - const struct track *track) -{ - long start, end, pos; - struct location *l; - /* Caller from addresses */ - unsigned long (*caddrs)[OPLUS_MEMCFG_SLABTRACE_CNT]; - /* Called from addresses of track */ - unsigned long taddrs[OPLUS_MEMCFG_SLABTRACE_CNT] - = { [0 ... OPLUS_MEMCFG_SLABTRACE_CNT - 1] = 0, }; - unsigned long age = jiffies - track->when; - int i, cnt; - - start = -1; - end = t->count; - - /* find the index of track->addr */ - for (i = 0; i < TRACK_ADDRS_COUNT; i++) { -#ifdef COMPACT_OPLUS_SLUB_TRACK - /* we store the offset after MODULES_VADDR for - * kernel module and kernel text address - */ - unsigned long addr = (MODULES_VADDR + track->addrs[i]); - - if (track->addr == addr || - ((track->addr - 4) == addr)) -#else - if ((track->addr == track->addrs[i]) || - (track->addr - 4 == track->addrs[i])) -#endif - break; - } - - /* copy all addrs if we cannot match track->addr */ - if (i == TRACK_ADDRS_COUNT) { - i = 0; - } - - cnt = min(OPLUS_MEMCFG_SLABTRACE_CNT, TRACK_ADDRS_COUNT - i); -#ifdef COMPACT_OPLUS_SLUB_TRACK - { - int j = 0; - unsigned long addrs[TRACK_ADDRS_COUNT]; - - for (j = 0; j < TRACK_ADDRS_COUNT; j++) { - /* we store the offset after MODULES_VADDR for - * kernel module and kernel text address - */ - if (track->addrs[j]) { - addrs[j] = MODULES_VADDR + track->addrs[j]; - - } else { - addrs[j] = 0; - } - } - - memcpy(taddrs, addrs + i, (cnt * sizeof(unsigned long))); - } -#else - memcpy(taddrs, track->addrs + i, (cnt * sizeof(unsigned long))); -#endif - - for (; ;) { - pos = start + (end - start + 1) / 2; - - /* - * There is nothing at "end". If we end up there - * we need to add something to before end. - */ - if (pos == end) { - break; - } - - caddrs = &(t->loc[pos].addrs); - - if (!memcmp(caddrs, taddrs, - OPLUS_MEMCFG_SLABTRACE_CNT * sizeof(unsigned long))) { - l = &t->loc[pos]; - l->count++; - -/*sort by pid*/ - if ((isbypid && !isbystacks) && !strcmp(s->name, sort_cache_name)) { - oplus_cnt_pid(track->pid); - } - - if (isbystacks && !strcmp(s->name, sort_cache_name)) { - if (!memcmp(l->addrs, sort_addrs, - OPLUS_MEMCFG_SLABTRACE_CNT * sizeof(unsigned long))) { - oplus_cnt_pid(track->pid); - } - } - - if (track->when) { - l->sum_time += age; - - if (age < l->min_time) { - l->min_time = age; - } - - if (age > l->max_time) { - l->max_time = age; - } - - if (track->pid < l->min_pid) { - l->min_pid = track->pid; - } - - if (track->pid > l->max_pid) { - l->max_pid = track->pid; - } - - cpumask_set_cpu(track->cpu, - to_cpumask(l->cpus)); - } - - node_set(page_to_nid(virt_to_page(track)), l->nodes); - return 1; - } - - if (memcmp(caddrs, taddrs, - OPLUS_MEMCFG_SLABTRACE_CNT * sizeof(unsigned long)) < 0) { - end = pos; - - } else { - start = pos; - } - } - - /* - * Not found. Insert new tracking element. - */ - if (t->count >= t->max && - !alloc_loc_track(t, 2 * t->max, __GFP_HIGH | __GFP_ATOMIC)) { - return 0; - } - - l = t->loc + pos; - - if (pos < t->count) - memmove(l + 1, l, - (t->count - pos) * sizeof(struct location)); - - t->count++; - l->count = 1; - l->addr = track->addr; - memcpy(l->addrs, taddrs, - OPLUS_MEMCFG_SLABTRACE_CNT * sizeof(unsigned long)); - - /*sort by pid*/ - if ((isbypid && !isbystacks) && !strcmp(s->name, sort_cache_name)) { - oplus_cnt_pid(track->pid); - } - - if (isbystacks && !strcmp(s->name, sort_cache_name)) { - if (!memcmp(l->addrs, sort_addrs, - OPLUS_MEMCFG_SLABTRACE_CNT * sizeof(unsigned long))) { - oplus_cnt_pid(track->pid); - } - } - - l->sum_time = age; - l->min_time = age; - l->max_time = age; - l->min_pid = track->pid; - l->max_pid = track->pid; - cpumask_clear(to_cpumask(l->cpus)); - cpumask_set_cpu(track->cpu, to_cpumask(l->cpus)); - nodes_clear(l->nodes); - node_set(page_to_nid(virt_to_page(track)), l->nodes); - return 1; -} - -static void oplus_memcfg_process_slab(struct loc_track *t, struct kmem_cache *s, - struct page *page, enum track_item alloc, - unsigned long *map) -{ - void *addr = page_address(page); - void *p; - - bitmap_zero(map, page->objects); - get_map(s, page, map); - - for_each_object(p, s, addr, page->objects) - - if (!test_bit(slab_index(p, s, addr), map)) { - oplus_memcfg_add_location(t, s, get_track(s, p, alloc)); - } -} - -static int oplus_memcfg_list_locations(struct kmem_cache *s, struct seq_file *m, - enum track_item alloc) -{ - unsigned long i, j; - struct loc_track t = { 0, 0, NULL }; - int node; - unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) * - sizeof(unsigned long), GFP_KERNEL); - struct kmem_cache_node *n; - -/*sort by pid*/ - struct pid_cnt_struct *tmp; - struct list_head *pos, *q; - - if ((isbypid || isbystacks) && !strcmp(s->name, sort_cache_name)) { - INIT_LIST_HEAD(&pid_head); - } - - if (!map || !alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location), - GFP_KERNEL)) { - kfree(map); - seq_puts(m, "Out of memory\n"); - return 0; - } - - /* Push back cpu slabs */ - flush_all(s); - - for_each_kmem_cache_node(s, node, n) { - unsigned long flags; - struct page *page; - - if (!atomic_long_read(&n->nr_slabs)) { - continue; - } - - spin_lock_irqsave(&n->list_lock, flags); - list_for_each_entry(page, &n->partial, lru) - oplus_memcfg_process_slab(&t, s, page, alloc, map); - list_for_each_entry(page, &n->full, lru) - oplus_memcfg_process_slab(&t, s, page, alloc, map); - spin_unlock_irqrestore(&n->list_lock, flags); - } - - for (i = 0; i < t.count; i++) { - struct location *l = &t.loc[i]; - - seq_printf(m, "%7ld ", l->count); - - if (l->addr) { - seq_printf(m, "%pS", (void *)l->addr); - - } else { - seq_puts(m, ""); - } - - for (j = 0; j < OPLUS_MEMCFG_SLABTRACE_CNT; j++) { - if (l->addrs[j]) { - if (isprintSyms) { - seq_printf(m, " %pS", (void *)l->addrs[j]); - - } else { - seq_printf(m, " 0x%px", (void *)l->addrs[j]); - } - } - } - - seq_puts(m, "\n"); - } - - free_loc_track(&t); - kfree(map); - -/*sort by pid*/ - if ((isbypid || isbystacks) && !strcmp(s->name, sort_cache_name)) { - list_for_each_safe(pos, q, &pid_head) { - tmp = list_entry(pos, struct pid_cnt_struct, list); - - for (i = 0; i < 5; i ++) { - if (top_pid[i].cnt == 0) { - top_pid[i].pid = tmp->pid; - top_pid[i].cnt = tmp->cnt; - break; - } - - if (top_pid[i].cnt < tmp->cnt) { - for (j = 4; j > i; j--) { - top_pid[j].pid = top_pid[j - 1].pid; - top_pid[j].cnt = top_pid[j - 1].cnt; - } - - top_pid[i].pid = tmp->pid; - top_pid[i].cnt = tmp->cnt; - break; - } - } - - list_del(pos); - kmem_cache_free(pid_cnt_cachep, tmp); - } - seq_printf(m, "\n\tThe top five of the number of %s alloced\n", - sort_cache_name); - - for (i = 0; i < 5; i ++) { - seq_printf(m, "\t Top%u: Pid %d, \t cnt %d \n", i, top_pid[i].pid, - top_pid[i].cnt); - } - - memset(top_pid, 0 , sizeof(top_pid)); - } - - - if (!t.count) { - seq_puts(m, "No data\n"); - } - - return 0; -} - -static int oplus_memcfg_slabtrace_show(struct seq_file *m, void *p) -{ - struct kmem_cache *s; - - pid_cnt_cachep = kmem_cache_create("pid_cnt_cache", - sizeof(struct pid_cnt_struct), - 0, 0, NULL); - - if (!pid_cnt_cachep) { - pr_err("slabtrace: pid_cnt_cachep create failed\n"); - return -ENOMEM; - } - - mutex_lock(&slab_mutex); - list_for_each_entry(s, &slab_caches, list) { - /* We only want to know the backtraces of kmalloc-* - * Backtraces of other kmem_cache can be find easily - */ - if (!strstr(s->name, "kmalloc-")) { - continue; - } - - if (strlen(sort_cache_name) > 8 && strcmp(s->name, sort_cache_name)) { - continue; - } - - seq_printf(m, "======= kmem_cache: %s alloc_calls =======\n", - s->name); - - if (!(s->flags & SLAB_STORE_USER)) { - continue; - - } else { - oplus_memcfg_list_locations(s, m, TRACK_ALLOC); - } - } - mutex_unlock(&slab_mutex); - kmem_cache_destroy(pid_cnt_cachep); - return 0; -} - -static int slabtrace_open(struct inode *inode, struct file *file) -{ - return single_open(file, oplus_memcfg_slabtrace_show, NULL); -} - -static const struct file_operations proc_slabtrace_operations = { - .open = slabtrace_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int oplus_memcfg_slabcfg_show(struct seq_file *m, void *p) -{ - mutex_lock(&slab_mutex); - seq_printf(m, "=== slabtrace config ===\n"); - seq_printf(m, "Reset config:echo \"reset\" > /proc/slab_memcfg/slabcfg\n"); - seq_printf(m, - "Print type:echo \"print symbol/address\" > /proc/slab_memcfg/slabcfg\n"); - seq_printf(m, - "Specific kmalloc:echo \"kmalloc-x pid\" > /proc/slab_memcfg/slabcfg\n"); - seq_printf(m, - "Specific kmalloc sort by stacks:echo \"kmalloc-x stacks add1 add2 ....\" > /proc/slab_memcfg/slabcfg\n"); - seq_printf(m, "slabtrace config: current config\n"); - - if (isbypid) { - seq_printf(m, "sort by pid, sort_cache_name:%s\n", sort_cache_name); - } - - if (isbystacks) { - seq_printf(m, "sort by stacks, sort_cache_name:%s\n", sort_cache_name); - } - - mutex_unlock(&slab_mutex); - - return 0; -} - -static int slabcfg_open(struct inode *inode, struct file *file) -{ - return single_open(file, oplus_memcfg_slabcfg_show, NULL); -} - -static ssize_t slabcfg_write(struct file *filp, const char *ubuf, size_t cnt, - loff_t *data) -{ - char buf[1024] = {}; - char mchar[] = "kmalloc-"; - char argv1[10] = {}; - char argv2[10] = {}; - - /*sort_addrs*/ - if (cnt >= sizeof(buf)) { - return -EINVAL; - } - - if (copy_from_user(&buf, ubuf, cnt)) { - return -EFAULT; - } - - buf[cnt] = 0; - pr_info("debug for slabconfig\n"); - - mutex_lock(&sort_mutex); - sscanf(buf, "%s %s %lx %lx %lx %lx", argv1, argv2, &sort_addrs[0], - &sort_addrs[1], &sort_addrs[2], &sort_addrs[3]); - pr_info("slabtrace:%s %s %lx %lx %lx %lx\n", argv1, argv2, sort_addrs[0], - sort_addrs[1], sort_addrs[2], sort_addrs[3]); - - /* reset */ - if (!strcmp(argv1, "reset")) { - isbypid = false; - isbystacks = false; - isprintSyms = false; - memset(sort_addrs, 0, sizeof(sort_addrs)); - memset(sort_cache_name, 0, sizeof(sort_cache_name)); - goto out; - } - - /* print type addr */ - if (!strcmp(argv1, "print")) { - if (!strcmp(argv2, "symbol")) { - isprintSyms = true; - } - - if (!strcmp(argv2, "address")) { - isprintSyms = false; - } - - goto out; - } - - /* pick kmalloc-x */ - if (strncmp(argv1, mchar, strlen(mchar))) { - pr_info("slabtrace config args invalid\n"); - goto out; - } - - strcpy(sort_cache_name, argv1); - pr_info("slabtrace sort_cache_name:%s\n", sort_cache_name); - - /* only by pid */ - if (!strcmp(argv2, "pid")) { - isbypid = true; - pr_info("slabtrace sort simple by pid\n"); - goto out; - } - - /* specific stack sort by pid */ - if (!strcmp(argv2, "stacks")) { - isbystacks = true; - pr_info("slabtrace sort by stacks\n"); - } - -out: - mutex_unlock(&sort_mutex); - return cnt; -} - -static const struct file_operations proc_slabcfg_operations = { - .open = slabcfg_open, - .write = slabcfg_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - - -static int __init oplus_memcfg_late_init(void) -{ - struct proc_dir_entry *pEntry = NULL; - struct proc_dir_entry *oplus_memcfg_dir = NULL; - - oplus_memcfg_dir = proc_mkdir("slab_memcfg", NULL); - - if (!oplus_memcfg_dir) { - pr_info("%s mkdir /proc/slab_memcfg failed\n", __func__); - - } else { - pEntry = proc_create("slabtrace", 0400, oplus_memcfg_dir, - &proc_slabtrace_operations); - - if (!pEntry) { - pr_info("create slabtrace proc entry failed\n"); - } - - pEntry = proc_create("slabcfg", 0600, oplus_memcfg_dir, - &proc_slabcfg_operations); - - if (!pEntry) { - pr_info("create slabcfg proc entry failed\n"); - } - } - - mutex_init(&sort_mutex); - return 0; -} -late_initcall(oplus_memcfg_late_init); -#endif diff --git a/drivers/soc/oplus/system/slabtrace/slabtrace.h b/drivers/soc/oplus/system/slabtrace/slabtrace.h deleted file mode 100755 index 78a175431d90..000000000000 --- a/drivers/soc/oplus/system/slabtrace/slabtrace.h +++ /dev/null @@ -1,135 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _SLAB_TRACE_H_ -#define _SLAB_TRACE_H_ -#include -#include /* struct reclaim_state */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include <../../../../kernel/msm-5.4/mm/internal.h> -#include <../../../../kernel/msm-5.4/mm/slab.h> -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) -#include <../../../../kernel/msm-4.19/mm/internal.h> -#include <../../../../kernel/msm-4.19/mm/slab.h> -#else -#include <../../../../kernel/msm-4.14/mm/internal.h> -#include <../../../../kernel/msm-4.14/mm/slab.h> -#endif /*(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))*/ -#else -#include <../../../../../kernel-4.19/mm/slab.h> -#include <../../../../../kernel-4.19/mm/internal.h> -#endif - -#if defined(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) -#ifndef CONFIG_RANDOMIZE_BASE -#define COMPACT_OPLUS_SLUB_TRACK -#endif -#endif -/* - * Tracking user of a slab. - */ -#define TRACK_ADDRS_COUNT 16 -struct track { - unsigned long addr; /* Called from address */ -#ifdef CONFIG_STACKTRACE -#if defined(COMPACT_OPLUS_SLUB_TRACK) - /* Store the offset after MODULES_VADDR for - * kernel module and kernel text address - */ - u32 addrs[TRACK_ADDRS_COUNT]; -#else - unsigned long addrs[TRACK_ADDRS_COUNT]; /* Called from address */ -#endif -#endif - int cpu; /* Was running on cpu */ - int pid; /* Pid context */ - unsigned long when; /* When did the operation occur */ -}; - -enum track_item { TRACK_ALLOC, TRACK_FREE }; - - - -#if defined(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) -#define OPLUS_MEMCFG_SLABTRACE_CNT 4 -#if (OPLUS_MEMCFG_SLABTRACE_CNT > TRACK_ADDRS_COUNT) -#error(OPLUS_MEMCFG_SLABTRACE_CNT > TRACK_ADDRS_COUNT) -#endif -#endif -struct location { - unsigned long count; - unsigned long addr; -#if defined(CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG) -#ifdef CONFIG_STACKTRACE - unsigned long addrs[OPLUS_MEMCFG_SLABTRACE_CNT]; /* caller address */ -#endif -#endif - long long sum_time; - long min_time; - long max_time; - long min_pid; - long max_pid; - DECLARE_BITMAP(cpus, NR_CPUS); - nodemask_t nodes; -}; - -struct loc_track { - unsigned long max; - unsigned long count; - struct location *loc; -}; - -static bool isbypid; -static bool isbystacks; -static bool isprintSyms = true; -static char sort_cache_name[13]; -static struct mutex sort_mutex; - -struct pid_cnt_struct { - struct list_head list; - unsigned cnt; /* slab pid count */ - int pid; /* Pid context */ -}; -static struct list_head pid_head; -static struct pid_cnt_struct top_pid[5]; /* record the top 5 pid */ -static unsigned long -sort_addrs[OPLUS_MEMCFG_SLABTRACE_CNT]; /*sort by caller address */ -static struct kmem_cache *pid_cnt_cachep; -extern alloc_loc_track(struct loc_track *t, unsigned long max, gfp_t flags); -extern void get_map(struct kmem_cache *s, struct page *page, - unsigned long *map); -extern void flush_all(struct kmem_cache *s); - -#define for_each_object(__p, __s, __addr, __objects) \ - for (__p = fixup_red_left(__s, __addr); \ - __p < (__addr) + (__objects) * (__s)->size; \ - __p += (__s)->size) -#define OO_SHIFT 16 -#define OO_MASK ((1 << OO_SHIFT) - 1) -#endif /*_SLAB_TRACE_H_*/ diff --git a/drivers/soc/oplus/system/theia/Kconfig b/drivers/soc/oplus/system/theia/Kconfig deleted file mode 100755 index 927d84b294c1..000000000000 --- a/drivers/soc/oplus/system/theia/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Gang.Yang@TECH.BSP.Stability.THEIA_PROJECT 2019/06/15, Add for THEIA_PROJECT -#change 'y' to 'n', if you want fo close theia feature -config OPLUS_FEATURE_THEIA - tristate "theia project" - default n - help - define this config to init theia project. diff --git a/drivers/soc/oplus/system/theia/Makefile b/drivers/soc/oplus/system/theia/Makefile deleted file mode 100755 index d99c081cd802..000000000000 --- a/drivers/soc/oplus/system/theia/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -#Yang.Gang@TECH.BSP.Stability.THEIA_PROJECT 2020/06/15, Add for THEIA_PROJECT -obj-$(CONFIG_OPLUS_FEATURE_THEIA) += oplus_theia.o -oplus_theia-y := black_screen_check.o bright_screen_check.o theia_kevent_kernel.o powerkey_monitor.o - diff --git a/drivers/soc/oplus/system/theia/black_screen_check.c b/drivers/soc/oplus/system/theia/black_screen_check.c deleted file mode 100755 index a8ba14f49aa6..000000000000 --- a/drivers/soc/oplus/system/theia/black_screen_check.c +++ /dev/null @@ -1,379 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include "powerkey_monitor.h" -#include "theia_kevent_kernel.h" - -#define BLACK_MAX_WRITE_NUMBER 50 -#define BLACK_SLOW_STATUS_TIMEOUT_MS 20000 - -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) -#define THEIA_TOUCHPANEL_BLANK_EVENT MTK_DISP_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT MTK_DISP_EARLY_EVENT_BLANK -#elif IS_ENABLED (CONFIG_DRM_MSM) -#define THEIA_TOUCHPANEL_BLANK_EVENT MSM_DRM_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT MSM_DRM_EARLY_EVENT_BLANK -#else -#define THEIA_TOUCHPANEL_BLANK_EVENT FB_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT FB_EARLY_EVENT_BLANK -#endif - -#define BLACK_DEBUG_PRINTK(a, arg...)\ - do {\ - printk("[powerkey_monitor_black]: " a, ##arg);\ - }while(0) - -static void black_timer_func(struct timer_list *t); - -struct black_data g_black_data = { - .is_panic = 0, - .status = BLACK_STATUS_INIT, -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - .blank = MTK_DISP_BLANK_UNBLANK, -#elif IS_ENABLED (CONFIG_DRM_MSM) - .blank = MSM_DRM_BLANK_UNBLANK, -#else - .blank = FB_BLANK_UNBLANK, -#endif - .timeout_ms = BLACK_SLOW_STATUS_TIMEOUT_MS, - .get_log = 1, - .error_count = 0, -}; - -static int bl_start_check_systemid = -1; - -int black_screen_timer_restart(void) -{ - BLACK_DEBUG_PRINTK("black_screen_timer_restart:blank = %d,status = %d\n", - g_black_data.blank, g_black_data.status); - - if (g_black_data.status != BLACK_STATUS_CHECK_ENABLE - && g_black_data.status != BLACK_STATUS_CHECK_DEBUG) { - BLACK_DEBUG_PRINTK("black_screen_timer_restart:g_black_data.status = %d return\n", - g_black_data.status); - return g_black_data.status; - } - - if(g_black_data.status != BLACK_STATUS_CHECK_ENABLE && g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - BLACK_DEBUG_PRINTK("black_screen_timer_restart:g_black_data.status = %d return\n",g_black_data.status); - return g_black_data.status; - } -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - if (g_black_data.blank == MTK_DISP_BLANK_POWERDOWN) { -#elif IS_ENABLED (CONFIG_DRM_MSM) - if (g_black_data.blank == MSM_DRM_BLANK_POWERDOWN) { -#else - if (g_black_data.blank == FB_BLANK_POWERDOWN) { -#endif - bl_start_check_systemid = get_systemserver_pid(); - mod_timer(&g_black_data.timer,jiffies + msecs_to_jiffies(g_black_data.timeout_ms)); - BLACK_DEBUG_PRINTK("black_screen_timer_restart: black screen check start %u\n",g_black_data.timeout_ms); - theia_pwk_stage_start("POWERKEY_START_BL"); - return 0; - } - return g_black_data.blank; -} -EXPORT_SYMBOL(black_screen_timer_restart); - -/*copy mtk_boot_common.h*/ -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 -static int get_status(void) -{ -#ifdef CONFIG_DRM_MSM - - if (MSM_BOOT_MODE__NORMAL == get_boot_mode()) { - return g_black_data.status; - } - - return BLACK_STATUS_INIT_SUCCEES; -#else - - if ((get_boot_mode() == NORMAL_BOOT) || (get_boot_mode() == ALARM_BOOT)) { - return g_black_data.status; - } - - return BLACK_STATUS_INIT_SUCCEES; - -#endif -} - -static bool get_log_swich() -{ - return (BLACK_STATUS_CHECK_ENABLE == get_status() - || BLACK_STATUS_CHECK_DEBUG == get_status()) && g_black_data.get_log; -} - -/* -logmap format: -logmap{key1:value1;key2:value2;key3:value3 ...} -*/ -static void get_blackscreen_check_dcs_logmap(char *logmap) -{ - char stages[512] = {0}; - int stages_len; - - stages_len = get_pwkey_stages(stages); - snprintf(logmap, 512, - "logmap{logType:%s;error_id:%s;error_count:%d;systemserver_pid:%d;stages:%s;catchlog:%s}", - PWKKEY_BLACK_SCREEN_DCS_LOGTYPE, - g_black_data.error_id, g_black_data.error_count, get_systemserver_pid(), stages, - get_log_swich() ? "true" : "false"); -} - -/*if the error id contain current pid, we think is a normal resume*/ -static bool is_normal_resume() -{ - char current_pid_str[32]; - sprintf(current_pid_str, "%d", get_systemserver_pid()); - - if (!strncmp(g_black_data.error_id, current_pid_str, strlen(current_pid_str))) { - return true; - } - - return false; -} - -static void get_blackscreen_resume_dcs_logmap(char *logmap) -{ - snprintf(logmap, 512, - "logmap{logType:%s;error_id:%s;resume_count:%d;normalReborn:%s;catchlog:false}", - PWKKEY_BLACK_SCREEN_DCS_LOGTYPE, - g_black_data.error_id, g_black_data.error_count, - (is_normal_resume() ? "true" : "false")); -} - -void send_black_screen_dcs_msg(void) -{ - char logmap[512] = {0}; - get_blackscreen_check_dcs_logmap(logmap); - SendDcsTheiaKevent(PWKKEY_DCS_TAG, PWKKEY_DCS_EVENTID, logmap); -} - -static void send_black_screen_resume_dcs_msg(void) -{ - /*check the current systemserver pid and the error_id, judge if it is a normal resume or reboot resume*/ - char resume_logmap[512] = {0}; - get_blackscreen_resume_dcs_logmap(resume_logmap); - SendDcsTheiaKevent(PWKKEY_DCS_TAG, PWKKEY_DCS_EVENTID, resume_logmap); -} - -static void delete_timer(char *reason, bool cancel) -{ - /*BLACK_DEBUG_PRINTK("delete_timer reason:%s", reason);*/ - del_timer(&g_black_data.timer); - - if (cancel && g_black_data.error_count != 0) { - send_black_screen_resume_dcs_msg(); - g_black_data.error_count = 0; - sprintf(g_black_data.error_id, "%s", "null"); - } - - theia_pwk_stage_end(reason); -} - -static ssize_t black_screen_cancel_proc_write(struct file *file, - const char __user *buf, - size_t count, loff_t *off) -{ - char buffer[40] = {0}; - char cancel_str[64] = {0}; - - if (g_black_data.status == BLACK_STATUS_INIT - || g_black_data.status == BLACK_STATUS_INIT_FAIL) { - BLACK_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, - g_black_data.status); - return count; - } - - if (count >= 40) { - count = 39; - } - - if (copy_from_user(buffer, buf, count)) { - BLACK_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - snprintf(cancel_str, sizeof(cancel_str), "CANCELED_BL_%s", buffer); - delete_timer(cancel_str, true); - - return count; -} - -static ssize_t black_screen_cancel_proc_read(struct file *file, - char __user *buf, - size_t count, loff_t *off) -{ - return 0; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int black_screen_cancel_proc_show(struct seq_file *seq_file, void *data) { - seq_printf(seq_file, "%s called\n", __func__); - return 0; -} - -static int black_screen_cancel_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, black_screen_cancel_proc_show, NULL); -} -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static const struct proc_ops black_screen_cancel_proc_fops = { - .proc_open = black_screen_cancel_proc_open, - .proc_read = black_screen_cancel_proc_read, - .proc_write = black_screen_cancel_proc_write, - .proc_lseek = seq_lseek, - .proc_release = single_release, -}; -#else -struct file_operations black_screen_cancel_proc_fops = { - .read = black_screen_cancel_proc_read, - .write = black_screen_cancel_proc_write, -}; -#endif - -static void dump_freeze_log(void) -{ - /*send kevent dcs msg*/ - send_black_screen_dcs_msg(); -} - -static void black_error_happen_work(struct work_struct *work) -{ - struct black_data *bla_data = container_of(work, struct black_data, error_happen_work); - - if (bla_data->error_count == 0) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - struct timespec64 ts = { 0 }; - ktime_get_real_ts64(&ts); - sprintf(g_black_data.error_id, "%d.%lld.%ld", get_systemserver_pid(), ts.tv_sec, ts.tv_nsec); -#else - struct timespec ts; - getnstimeofday(&ts); - sprintf(g_black_data.error_id, "%d.%ld.%ld", get_systemserver_pid(), ts.tv_sec, ts.tv_nsec); -#endif - } - - if (bla_data->error_count < BLACK_MAX_WRITE_NUMBER) { - bla_data->error_count++; - dump_freeze_log(); - } - BLACK_DEBUG_PRINTK("black_error_happen_work error_id = %s, error_count = %d\n", - bla_data->error_id, bla_data->error_count); - - delete_timer("BR_ERROR_HAPPEN", false); - - if(bla_data->is_panic) { - doPanic(); - } -} - -static void black_timer_func(struct timer_list *t) -{ - struct black_data *p = from_timer(p, t, timer); - BLACK_DEBUG_PRINTK("black_timer_func is called\n"); - - if (bl_start_check_systemid == get_systemserver_pid()) { - schedule_work(&p->error_happen_work); - - } else { - BLACK_DEBUG_PRINTK("black_timer_func, not valid for check, skip\n"); - } -} - -static int check_black_screen_tp_event(int *blank, unsigned long event) -{ - switch (event) { - case THEIA_TOUCHPANEL_BLANK_EVENT: - case THEIA_TOUCHPANEL_EARLY_BLANK_EVENT: - g_black_data.blank = *blank; - if (g_black_data.status != BLACK_STATUS_CHECK_DEBUG) { - delete_timer("FINISH_FB", true); - BLACK_DEBUG_PRINTK("black_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } - break; - default: - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - break; - } - return 0; -} - -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) -static int black_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - int *blank = (int *)data; - ret = check_black_screen_tp_event(blank, event); - return ret; -} -#elif IS_ENABLED (CONFIG_DRM_MSM) -static int black_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - struct msm_drm_notifier *evdata = data; - int *blank; - if (evdata && evdata->data) { - blank = evdata->data; - } - ret = check_black_screen_tp_event(blank, event); - return ret; -} -#else -static int black_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - struct fb_event *evdata = data; - int *blank = NULL; - if (evdata && evdata->data) { - blank = evdata->data; - } - if (blank) { - ret = check_black_screen_tp_event(blank, event); - } - return ret; -} -#endif - -void black_screen_check_init(void) -{ - sprintf(g_black_data.error_id, "%s", "null"); - g_black_data.fb_notif.notifier_call = black_fb_notifier_callback; -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - if (mtk_disp_notifier_register("oplus_theia", &g_black_data.fb_notif)) { - BLACK_DEBUG_PRINTK("mtk_disp_notifier_register failed!"); - } -#elif IS_ENABLED (CONFIG_DRM_MSM) - msm_drm_register_client(&g_black_data.fb_notif); -#else - fb_register_client(&g_black_data.fb_notif); -#endif - - g_black_data.status = 0; - //the node for cancel black screen check - proc_create("blackSwitch", S_IRWXUGO, NULL, &black_screen_cancel_proc_fops); - - INIT_WORK(&g_black_data.error_happen_work, black_error_happen_work); - timer_setup((&g_black_data.timer), (black_timer_func),TIMER_DEFERRABLE); - g_black_data.status = BLACK_STATUS_CHECK_ENABLE; -} -void black_screen_exit(void) -{ - delete_timer("FINISH_DRIVER_EXIT", true); - fb_unregister_client(&g_black_data.fb_notif); -} -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/bright_screen_check.c b/drivers/soc/oplus/system/theia/bright_screen_check.c deleted file mode 100755 index 09bba4e33810..000000000000 --- a/drivers/soc/oplus/system/theia/bright_screen_check.c +++ /dev/null @@ -1,448 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include "powerkey_monitor.h" -#include "theia_kevent_kernel.h" - -#define BRIGHT_MAX_WRITE_NUMBER 50 -#define BRIGHT_SLOW_TIMEOUT_MS 20000 - -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) -#define THEIA_TOUCHPANEL_BLANK_EVENT MTK_DISP_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT MTK_DISP_EARLY_EVENT_BLANK -#elif IS_ENABLED (CONFIG_DRM_MSM) -#define THEIA_TOUCHPANEL_BLANK_EVENT MSM_DRM_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT MSM_DRM_EARLY_EVENT_BLANK -#else -#define THEIA_TOUCHPANEL_BLANK_EVENT FB_EVENT_BLANK -#define THEIA_TOUCHPANEL_EARLY_BLANK_EVENT FB_EARLY_EVENT_BLANK -#endif - -#define BRIGHT_DEBUG_PRINTK(a, arg...)\ - do {\ - printk("[powerkey_monitor_bright]: " a, ##arg);\ - }while(0) - -struct bright_data g_bright_data = { - .is_panic = 0, - .status = BRIGHT_STATUS_INIT, -#if IS_ENABLED(CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - .blank = MTK_DISP_BLANK_UNBLANK, -#elif IS_ENABLED (CONFIG_DRM_MSM) - .blank = MSM_DRM_BLANK_UNBLANK, -#else - .blank = FB_BLANK_UNBLANK, -#endif - .timeout_ms = BRIGHT_SLOW_TIMEOUT_MS, - .get_log = 1, - .error_count = 0, - /*.timer.function = bright_timer_func,*/ -}; - -/* if last stage in this array, skip */ -static char bright_last_skip_block_stages[][64] = { - { "POWERKEY_interceptKeyBeforeQueueing" }, /* framework policy may not goto sleep when bright check, skip */ -}; - -/* if contain stage in this array, skip */ -static char bright_skip_stages[][64] = { - { "POWER_wakeUpInternal" }, /* quick press powerkey, power decide wakeup when bright check, skip */ - { "POWERKEY_wakeUpFromPowerKey" }, /* quick press powerkey, power decide wakeup when bright check, skip */ - { "CANCELED_" }, /* if CANCELED_ event write in bright check stage, skip */ -}; - -static void bright_timer_func(struct timer_list *t); - -static int br_start_check_systemid = -1; - -int bright_screen_timer_restart(void) -{ - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart:blank = %d,status = %d\n", g_bright_data.blank, g_bright_data.status); - - if(g_bright_data.status != BRIGHT_STATUS_CHECK_ENABLE && g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart:g_bright_data.status = %d return\n",g_bright_data.status); - return g_bright_data.status; - } -#if IS_ENABLED(CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - if (g_bright_data.blank == MTK_DISP_BLANK_UNBLANK) { -#elif IS_ENABLED (CONFIG_DRM_MSM) - if (g_bright_data.blank == MSM_DRM_BLANK_UNBLANK) { -#else - if (g_bright_data.blank == FB_BLANK_UNBLANK) { -#endif - br_start_check_systemid = get_systemserver_pid(); - mod_timer(&g_bright_data.timer,jiffies + msecs_to_jiffies(g_bright_data.timeout_ms)); - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart: bright screen check start %u\n",g_bright_data.timeout_ms); - theia_pwk_stage_start("POWERKEY_START_BR"); - return 0; - } - return g_bright_data.blank; -} -EXPORT_SYMBOL(bright_screen_timer_restart); - -/*copy mtk_boot_common.h*/ -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 - -static int get_status(void) -{ -#ifdef CONFIG_DRM_MSM - - if (MSM_BOOT_MODE__NORMAL == get_boot_mode()) { - return g_bright_data.status; - } - - return BRIGHT_STATUS_INIT_SUCCEES; -#else - - if ((get_boot_mode() == NORMAL_BOOT) || (get_boot_mode() == ALARM_BOOT)) { - return g_bright_data.status; - } - - return BRIGHT_STATUS_INIT_SUCCEES; - -#endif -} - -static bool get_log_swich() -{ - return (BRIGHT_STATUS_CHECK_ENABLE == get_status() - || BRIGHT_STATUS_CHECK_DEBUG == get_status()) && g_bright_data.get_log; -} - -/* -logmap format: -logmap{key1:value1;key2:value2;key3:value3 ...} -*/ -static void get_brightscreen_check_dcs_logmap(char *logmap) -{ - char stages[512] = {0}; - int stages_len; - - stages_len = get_pwkey_stages(stages); - snprintf(logmap, 512, - "logmap{logType:%s;error_id:%s;error_count:%d;systemserver_pid:%d;stages:%s;catchlog:%s}", - PWKKEY_BRIGHT_SCREEN_DCS_LOGTYPE, - g_bright_data.error_id, g_bright_data.error_count, get_systemserver_pid(), - stages, get_log_swich() ? "true" : "false"); -} - -void send_bright_screen_dcs_msg(void) -{ - char logmap[512] = {0}; - get_brightscreen_check_dcs_logmap(logmap); - SendDcsTheiaKevent(PWKKEY_DCS_TAG, PWKKEY_DCS_EVENTID, logmap); -} - -static void dump_freeze_log(void) -{ - /*send kevent dcs msg*/ - send_bright_screen_dcs_msg(); -} - -static bool is_bright_last_stage_skip() -{ - int i = 0, nLen; - char stage[64] = {0};; - get_last_pwkey_stage(stage); - - nLen = sizeof(bright_last_skip_block_stages) / sizeof( - bright_last_skip_block_stages[0]); - - /* BRIGHT_DEBUG_PRINTK("is_bright_last_stage_skip stage:%s nLen:%d", stage, nLen); */ - for (i = 0; i < nLen; i++) { - /* BRIGHT_DEBUG_PRINTK("is_bright_last_stage_skip stage:%s i:%d nLen:%d bright_last_skip_block_stages[i]:%s", - stage, i, nLen, bright_last_skip_block_stages[i]); */ - if (!strcmp(stage, bright_last_skip_block_stages[i])) { - BRIGHT_DEBUG_PRINTK("is_bright_last_stage_skip return true, stage:%s", stage); - return true; - } - } - - return false; -} - -static bool is_bright_contain_skip_stage() -{ - char stages[512] = {0}; - int i = 0, nArrayLen; - get_pwkey_stages(stages); - - nArrayLen = sizeof(bright_skip_stages) / sizeof(bright_skip_stages[0]); - - for (i = 0; i < nArrayLen; i++) { - if (strstr(stages, bright_skip_stages[i]) != NULL) { - BRIGHT_DEBUG_PRINTK("is_bright_contain_skip_stage return true, stages:%s", - stages); - return true; - } - } - - return false; -} - -static bool is_need_skip() -{ - if (is_bright_last_stage_skip()) { - return true; - } - - if (is_bright_contain_skip_stage()) { - return true; - } - - return false; -} - -/*if the error id contain current pid, we think is a normal resume*/ -static bool is_normal_resume() -{ - char current_pid_str[32]; - sprintf(current_pid_str, "%d", get_systemserver_pid()); - - if (!strncmp(g_bright_data.error_id, current_pid_str, - strlen(current_pid_str))) { - return true; - } - - return false; -} - -static void get_bright_resume_dcs_logmap(char *logmap) -{ - snprintf(logmap, 512, - "logmap{logType:%s;error_id:%s;resume_count:%d;normalReborn:%s;catchlog:false}", - PWKKEY_BRIGHT_SCREEN_DCS_LOGTYPE, - g_bright_data.error_id, g_bright_data.error_count, - (is_normal_resume() ? "true" : "false")); -} - -static void send_bright_screen_resume_dcs_msg(void) -{ - /*check the current systemserver pid and the error_id, judge if it is a normal resume or reboot resume*/ - char resume_logmap[512] = {0}; - get_bright_resume_dcs_logmap(resume_logmap); - SendDcsTheiaKevent(PWKKEY_DCS_TAG, PWKKEY_DCS_EVENTID, resume_logmap); -} - -static void delete_timer(char *reason, bool cancel) -{ - /*BRIGHT_DEBUG_PRINTK("delete_timer reason:%s", reason);*/ - del_timer(&g_bright_data.timer); - - if (cancel && g_bright_data.error_count != 0) { - send_bright_screen_resume_dcs_msg(); - g_bright_data.error_count = 0; - sprintf(g_bright_data.error_id, "%s", "null"); - } - - theia_pwk_stage_end(reason); -} - -static void bright_error_happen_work(struct work_struct *work) -{ - struct bright_data *bri_data = container_of(work, struct bright_data, - error_happen_work); - - /* for bright screen check, check if need skip, we direct return */ - if (is_need_skip()) { - return; - } - - if (bri_data->error_count == 0) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - struct timespec64 ts = { 0 }; - ktime_get_real_ts64(&ts); - sprintf(g_bright_data.error_id, "%d.%lld.%ld", get_systemserver_pid(), ts.tv_sec, ts.tv_nsec); -#else - struct timespec ts; - getnstimeofday(&ts); - sprintf(g_bright_data.error_id, "%d.%ld.%ld", get_systemserver_pid(), ts.tv_sec, ts.tv_nsec); -#endif - } - - if (bri_data->error_count < BRIGHT_MAX_WRITE_NUMBER) { - bri_data->error_count++; - dump_freeze_log(); - } - BRIGHT_DEBUG_PRINTK("bright_error_happen_work error_id = %s, error_count = %d\n", - bri_data->error_id, bri_data->error_count); - - delete_timer("BL_ERROR_HAPPEN", false); - - if(bri_data->is_panic) { - doPanic(); - } -} - -static void bright_timer_func(struct timer_list *t) -{ - struct bright_data *p = from_timer(p, t, timer); - - - BRIGHT_DEBUG_PRINTK("bright_timer_func is called\n"); - - if (br_start_check_systemid == get_systemserver_pid()) { - schedule_work(&p->error_happen_work); - - } else { - BRIGHT_DEBUG_PRINTK("bright_timer_func, not valid for check, skip\n"); - } -} - -static int check_bright_screen_tp_event(int *blank, unsigned long event) -{ - switch (event) { - case THEIA_TOUCHPANEL_BLANK_EVENT: - case THEIA_TOUCHPANEL_EARLY_BLANK_EVENT: - g_bright_data.blank = *blank; - if (g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG) { - delete_timer("FINISH_FB", true); - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } - break; - default: - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - break; - } - return 0; -} - -#if IS_ENABLED (CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - int *blank = (int *)data; - ret = check_bright_screen_tp_event(blank, event); - return ret; -} -#elif IS_ENABLED (CONFIG_DRM_MSM) -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - struct msm_drm_notifier *evdata = data; - int *blank; - if (evdata && evdata->data) { - blank = evdata->data; - } - ret = check_bright_screen_tp_event(blank, event); - return ret; -} -#else -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - int ret = 0; - struct fb_event *evdata = data; - int *blank = NULL; - if (evdata && evdata->data) { - blank = evdata->data; - } - if (blank) { - ret = check_bright_screen_tp_event(blank, event); - } - return ret; -} -#endif - -static ssize_t bright_screen_cancel_proc_write(struct file *file, - const char __user *buf, - size_t count, loff_t *off) -{ - char buffer[40] = {0}; - char cancel_str[64] = {0}; - - if (g_bright_data.status == BRIGHT_STATUS_INIT - || g_bright_data.status == BRIGHT_STATUS_INIT_FAIL) { - BRIGHT_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, - g_bright_data.status); - return count; - } - - if (count >= 40) { - count = 39; - } - - if (copy_from_user(buffer, buf, count)) { - BRIGHT_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - snprintf(cancel_str, sizeof(cancel_str), "CANCELED_BR_%s", buffer); - delete_timer(cancel_str, true); - - return count; -} -static ssize_t bright_screen_cancel_proc_read(struct file *file, - char __user *buf, - size_t count, loff_t *off) -{ - return 0; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int bright_screen_cancel_proc_show(struct seq_file *seq_file, void *data) { - seq_printf(seq_file, "%s called\n", __func__); - return 0; -} - -static int bright_screen_cancel_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, bright_screen_cancel_proc_show, NULL); -} -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static const struct proc_ops bright_screen_cancel_proc_fops = { - .proc_open = bright_screen_cancel_proc_open, - .proc_read = bright_screen_cancel_proc_read, - .proc_write = bright_screen_cancel_proc_write, - .proc_lseek = seq_lseek, - .proc_release = single_release, - }; -#else - struct file_operations bright_screen_cancel_proc_fops = { - .read = bright_screen_cancel_proc_read, - .write = bright_screen_cancel_proc_write, - }; -#endif - - -void bright_screen_check_init(void) -{ - sprintf(g_bright_data.error_id, "%s", "null"); - g_bright_data.fb_notif.notifier_call = bright_fb_notifier_callback; -#if IS_ENABLED(CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) - if (mtk_disp_notifier_register("oplus_theia", &g_bright_data.fb_notif)) { - BRIGHT_DEBUG_PRINTK("mtk_disp_notifier_register failed!"); - } -#elif IS_ENABLED (CONFIG_DRM_MSM) - msm_drm_register_client(&g_bright_data.fb_notif); -#else - fb_register_client(&g_bright_data.fb_notif); -#endif - - g_bright_data.status = 0; - //the node for cancel bright screen check - proc_create("brightSwitch", S_IRWXUGO, NULL, &bright_screen_cancel_proc_fops); - - INIT_WORK(&g_bright_data.error_happen_work, bright_error_happen_work); - timer_setup((&g_bright_data.timer), (bright_timer_func),TIMER_DEFERRABLE); - g_bright_data.status = BRIGHT_STATUS_CHECK_ENABLE; -} - -void bright_screen_exit(void) -{ - delete_timer("FINISH_DRIVER_EXIT", true); - fb_unregister_client(&g_bright_data.fb_notif); -} -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/oplus_BScheck.c b/drivers/soc/oplus/system/theia/oplus_BScheck.c deleted file mode 100755 index 6c80bd4f00f9..000000000000 --- a/drivers/soc/oplus/system/theia/oplus_BScheck.c +++ /dev/null @@ -1,938 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -#include -#endif -#include - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -#include -#endif - -#define BLACKSCREEN_COUNT_FILE "/data/oplus/log/bsp/blackscreen_count.txt" -#define BLACKSCREEN_HAPPENED_FILE "/data/oplus/log/bsp/blackscreen_happened.txt" -//#define BRIGHTSCREEN_COUNT_FILE "/data/oplus/log/bsp/brightscreen_count.txt" -//#define BRIGHTSCREEN_HAPPENED_FILE "/data/oplus/log/bsp/brightscreen_happened.txt" - -#define BLACK_DEBUG_PRINTK(a, arg...)\ - do{\ - printk("[black_check]: " a, ##arg);\ - }while(0) - -#define BLACK_STATUS_INIT 1 -#define BLACK_STATUS_INIT_FAIL 2 -#define BLACK_STATUS_INIT_SUCCEES 3 -#define BLACK_STATUS_CHECK_ENABLE 4 -#define BLACK_STATUS_CHECK_DISABLE 5 -#define BLACK_STATUS_CHECK_DEBUG 6 - -#define BLACK_CLEAR_ERROR_HAPPENED 0 -#define BLACK_MARK_ERROR_HAPPENED 1 - -#define BLACK_MAX_WRITE_NUMBER 3000 - -#define BLACK_DEFAULT_TIMEOUT_MS 120000 -#define BLACK_INIT_STATUS_TIMEOUT_MS 150000 -#define BLACK_SLOW_STATUS_TIMEOUT_MS 20000 - -#define BLACK_STAGE_CONSUMED 80000 -#define BLACK_STAGE_END 90000 - -#define SIG_THEIA (SIGRTMIN + 0x13) -#define TASK_INIT_COMM "init" - -static int def_swich=1; - -static char *flow_buf=NULL; -static char *flow_buf_curr=NULL; -#define flow_size 16 -#define stage_brief_size 64 -#define stage_total_size ((stage_brief_size) * (flow_size)) - -static int flow_index=0; -static int stage_start=0; -static int stage_end=0; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int black_screen_error_counter = 0; -static int black_screen_error_happened_flag = 0; -#endif - -struct black_data{ - int is_panic; - int status; - int blank; - int get_log; - unsigned int timeout_ms; - int error_detected; - unsigned int error_count_new; - unsigned int error_count_old; - struct notifier_block fb_notif; - struct timer_list timer; - wait_queue_head_t keylog_thread_wq; - struct work_struct error_happen_work; - struct work_struct clear_error_happened_flag_work; - struct delayed_work determine_init_status_work; -}; - -static void black_timer_func(struct timer_list *t); - -static struct black_data g_black_data = { - .is_panic = 0, - .status = BLACK_STATUS_INIT, -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - .blank = MSM_DRM_BLANK_UNBLANK, -#else - .blank = FB_BLANK_UNBLANK, -#endif - .timeout_ms = BLACK_SLOW_STATUS_TIMEOUT_MS, - .error_detected = 0, - .error_count_new = 0, - .error_count_old = 0, -}; - -static wait_queue_head_t black_check_wq; -static int ur_stage; - -void theia_pwk_stage_start(void) -{ - BLACK_DEBUG_PRINTK("set start %x: %x %x flow_buf\n", flow_buf,flow_buf_curr,flow_index); - - stage_start = flow_index; -} -EXPORT_SYMBOL(theia_pwk_stage_start); - -void theia_pwk_stage_end(void) -{ - BLACK_DEBUG_PRINTK("set end %x: %x %x flow_buf\n", flow_buf,flow_buf_curr,flow_index); - - stage_end = flow_index; -} -EXPORT_SYMBOL(theia_pwk_stage_end); - -int black_screen_timer_restart(void) -{ - //BLACK_DEBUG_PRINTK("black_screen_timer_restart:blank = %d,status = %d\n",g_black_data.blank,g_black_data.status); - if(g_black_data.status != BLACK_STATUS_CHECK_ENABLE && g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - BLACK_DEBUG_PRINTK("black_screen_timer_restart:g_black_data.status = %d return\n",g_black_data.status); - return g_black_data.status; - } -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if(g_black_data.blank == MSM_DRM_BLANK_POWERDOWN) -#else - if(g_black_data.blank == FB_BLANK_POWERDOWN) -#endif - { - mod_timer(&g_black_data.timer,jiffies + msecs_to_jiffies(g_black_data.timeout_ms)); - BLACK_DEBUG_PRINTK("black_screen_timer_restart: black screen check start %u\n",g_black_data.timeout_ms); - theia_pwk_stage_start(); - return 0; - } - return g_black_data.blank; -} -EXPORT_SYMBOL(black_screen_timer_restart); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int black_screen_proc_open(struct inode *inode, struct file *file) -{ - int ret; - - ret = nonseekable_open(inode, file); - if (unlikely(ret)) - return ret; - file->private_data = NULL; - - return 0; -} -#endif - -static ssize_t black_screen_check_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - char page[256] = {0}; - int len = 0; - - len = sprintf(&page[len],"%d %u %d %d\n", - g_black_data.status,g_black_data.timeout_ms,g_black_data.is_panic,g_black_data.get_log); - - if(len > *off) - len -= *off; - else - len = 0; - - if(copy_to_user(buf,page,(len < count ? len : count))){ - return -EFAULT; - } - *off += len < count ? len : count; - return (len < count ? len : count); - -} - -static ssize_t black_screen_check_proc_write(struct file *file, const char __user *buf, - size_t count,loff_t *off) -{ - int tmp_status = 0; - int tmp_timeout = 0; - int tmp_isPanic = 0; - int tmp_log = 0; - int ret = 0; - char buffer[40] = {0}; - - if(g_black_data.status == BLACK_STATUS_INIT || g_black_data.status == BLACK_STATUS_INIT_FAIL){ - BLACK_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_black_data.status); - return count; - } - - if (count > 40) { - count = 40; - } - - if (copy_from_user(buffer, buf, count)) { - BLACK_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - ret = sscanf(buffer, "%d %u %d %d", &tmp_status,&tmp_timeout,&tmp_isPanic,&tmp_log); - - if (ret == 1) { - g_black_data.status = tmp_status; - } else if(ret == 4){ - g_black_data.status = tmp_status; - if(tmp_timeout) - g_black_data.timeout_ms = tmp_timeout; - g_black_data.is_panic = tmp_isPanic; - g_black_data.get_log = tmp_log; - }else{ - BLACK_DEBUG_PRINTK("%s invalid content: '%s', length = %zd\n", __func__, buffer, count); - } - def_swich = tmp_status == BLACK_STATUS_CHECK_ENABLE|| BLACK_STATUS_CHECK_DEBUG == tmp_status; - - BLACK_DEBUG_PRINTK("%s: status = %d timeout_ms = %u is_panic = %d\n", - __func__, g_black_data.status,g_black_data.timeout_ms,g_black_data.is_panic); - - return count; - -} -static void record_stage(const char *buf) -{ - - memset(flow_buf_curr, 0, stage_brief_size); - memcpy(flow_buf_curr, buf, stage_brief_size - 1); - *(flow_buf_curr + stage_brief_size - 1)='\n'; - flow_buf_curr+=stage_brief_size; - - //w lock index - flow_index++; - if(flow_index == flow_size){ - flow_index = 0; - flow_buf_curr = flow_buf; - } - //w lock index - - //flow_buf_curr+=stage_brief_size; - -} - -static ssize_t black_screen_report_proc_write(struct file *file, const char __user *buf, - size_t count,loff_t *off) -{ - - char buffer[stage_brief_size] = {0}; - - if(g_black_data.status == BLACK_STATUS_INIT || g_black_data.status == BLACK_STATUS_INIT_FAIL){ - BLACK_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_black_data.status); - return count; - } - - if (count > stage_brief_size) { - count = stage_brief_size; - } - - if (copy_from_user(buffer, buf, count)) { - BLACK_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - record_stage(buffer); - return count; -} - - -static ssize_t rick_pick_fail_stage(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - - int start,end; - char *t_sbuf= NULL; - char *buf_curr = NULL; - char sbuf[stage_total_size] = {0}; - - if(stage_start == stage_end) - { - return 0; - } - - buf_curr = stage_start*stage_brief_size + flow_buf; - start = stage_start; - end = stage_end+1; - if(end == flow_size) - { - end = 0; - } - BLACK_DEBUG_PRINTK("rick_pick_fail_stage %d: %d \n", stage_start,stage_end); - BLACK_DEBUG_PRINTK("rick_pick_fail_stage %x: %x %x \n", flow_buf,flow_buf_curr,flow_index); - - t_sbuf= sbuf; - for(;start!= end;) - { - memset(t_sbuf,0,stage_brief_size); - memcpy(t_sbuf,buf_curr,stage_brief_size); - - buf_curr+=stage_brief_size; - t_sbuf+=stage_brief_size; - - //w lock index - start++; - if(start == flow_size) - { - start = 0; - buf_curr = flow_buf; - } - } - - return simple_read_from_buffer(buf, count, off, sbuf, - stage_brief_size*flow_size); - -} -static void print_all_flow(void) -{ - char *t_sbuf= NULL; - - int start = 0; - t_sbuf = flow_buf; - - for(;start < flow_size;start++) - { - BLACK_DEBUG_PRINTK("%s \n", t_sbuf); - t_sbuf+=stage_brief_size; - } - BLACK_DEBUG_PRINTK("exit print_all \n"); -} - -static ssize_t black_screen_report_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - BLACK_DEBUG_PRINTK("enter black_screen_report_proc_read %d %d",count,*off); - - print_all_flow(); - - return rick_pick_fail_stage( file, buf, count, off); -} - -static int passok(int stage) -{ - return stage==0 || stage == BLACK_STAGE_END || stage == BLACK_STAGE_CONSUMED; -} -static ssize_t black_screen_ur_process(int stage) -{ - if(passok(stage)) - { - ur_stage = stage; - del_timer(&g_black_data.timer); - BLACK_DEBUG_PRINTK("del timer,stage: %d blank:%d\n", - stage, g_black_data.blank); - } - return 0; -} - -static ssize_t black_screen_switch_proc_write(struct file *file, const char __user *buf, - size_t count,loff_t *off) -{ - int tmp_stage = 0; - int ret = 0; - char buffer[40] = {0}; - - if(g_black_data.status == BLACK_STATUS_INIT || g_black_data.status == BLACK_STATUS_INIT_FAIL){ - BLACK_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_black_data.status); - return count; - } - - if (count > 40) { - count = 40; - } - - if (copy_from_user(buffer, buf, count)) { - BLACK_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - ret = sscanf(buffer, "%d", &tmp_stage); - if(1 == tmp_stage) - { - del_timer(&g_black_data.timer); - } - - if (ret == 1) { - BLACK_DEBUG_PRINTK("%s recv us report stage: %d\n", __func__, tmp_stage); - black_screen_ur_process(tmp_stage); - }else{ - BLACK_DEBUG_PRINTK("%s invalid content: '%s', length = %zd\n", __func__, buf, count); - } - - return count; -} -static ssize_t black_screen_switch_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - return 0; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -struct file_operations black_screen_check_proc_fops = { - .read = black_screen_check_proc_read, - .write = black_screen_check_proc_write, -}; - -struct file_operations black_screen_report_proc_fops = { - .read = black_screen_report_proc_read, - .write = black_screen_report_proc_write, -}; -struct file_operations black_screen_switch_proc_fops = { - .read = black_screen_switch_proc_read, - .write = black_screen_switch_proc_write, -}; -#else -static const struct proc_ops black_screen_check_proc_fops = { - .proc_open = black_screen_proc_open, - .proc_read = black_screen_check_proc_read, - .proc_write = black_screen_check_proc_write, -}; - -static const struct proc_ops black_screen_report_proc_fops = { - .proc_open = black_screen_proc_open, - .proc_read = black_screen_report_proc_read, - .proc_write = black_screen_report_proc_write, -}; - -static const struct proc_ops black_screen_switch_proc_fops = { - .proc_open = black_screen_proc_open, - .proc_read = black_screen_switch_proc_read, - .proc_write = black_screen_switch_proc_write, -}; -#endif - -static ssize_t black_screen_check_status_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - char page[256] = {0}; - int len = 0; - int error_detected = 0; - - BLACK_DEBUG_PRINTK("read black_err_detected:%d count:%d begin\n", - g_black_data.error_detected, g_black_data.error_count_new); - wait_event_interruptible(black_check_wq, g_black_data.error_detected>0); - BLACK_DEBUG_PRINTK("read black_err_detected:%d count:%d end\n", - g_black_data.error_detected, g_black_data.error_count_new); - - if (g_black_data.error_detected) { - len = sprintf(&page[len], "%u", g_black_data.error_count_new); - } else { - len = sprintf(&page[len],"%d", 0); - } - error_detected = g_black_data.error_detected; - g_black_data.error_detected = 0; - if(len > *off) - len -= *off; - else - len = 0; - if(copy_to_user(buf,page,(len < count ? len : count))){ - return -EFAULT; - } - *off += len < count ? len : count; - if (error_detected) { - schedule_work(&g_black_data.clear_error_happened_flag_work); - } - return (len < count ? len : count); -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -struct file_operations black_screen_check_status_proc_fops = { - .read = black_screen_check_status_proc_read, -}; -#else -static const struct proc_ops black_screen_check_status_proc_fops = { - .proc_open = black_screen_proc_open, - .proc_read = black_screen_check_status_proc_read, -}; -#endif - -static bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && - (t->parent != 0 && !strcmp(t->parent->comm,"init"))) - return true; - else - return false; - return false; -} - - -static void black_show_coretask_state(void) -{ - struct task_struct *g, *p; - - rcu_read_lock(); - for_each_process_thread(g, p) { - if (is_zygote_process(p) || !strncmp(p->comm,"system_server", TASK_COMM_LEN) - || !strncmp(p->comm,"surfaceflinger", TASK_COMM_LEN)) { -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - touch_nmi_watchdog(); -#endif - sched_show_task(p); - } - } - -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_THEIA) - touch_all_softlockup_watchdogs(); -#endif - rcu_read_unlock(); -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static bool black_check_error_happened_before(struct black_data *bla_data) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - int error_happened = 0; - - fp = filp_open(BLACKSCREEN_HAPPENED_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BLACK_DEBUG_PRINTK("create %s file error fp:%p\n", BLACKSCREEN_HAPPENED_FILE, fp); - return false; - } - - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BLACK_DEBUG_PRINTK("read %s file error\n", BLACKSCREEN_HAPPENED_FILE); - goto out; - } - sscanf(buf, "%d", &error_happened); -out: - BLACK_DEBUG_PRINTK("error_happened before:%d\n", error_happened); - filp_close(fp, NULL); - - return (error_happened > 0 ? true : false); -} -#else -static bool black_check_error_happened_before(struct black_data *bla_data) -{ - BLACK_DEBUG_PRINTK("error_happened before:%d\n", black_screen_error_happened_flag); - return (black_screen_error_happened_flag > 0 ? true : false); -} -#endif - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static int black_mark_or_clear_error_happened_flag(struct black_data *bla_data, int mark_or_clear) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - int old_value = 0; - - fp = filp_open(BLACKSCREEN_HAPPENED_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BLACK_DEBUG_PRINTK("create %s file error fp:%p\n", BLACKSCREEN_HAPPENED_FILE, fp); - return -1; - } - - //read to check whether write or not - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BLACK_DEBUG_PRINTK("read %s file error\n", BLACKSCREEN_HAPPENED_FILE); - goto out; - } - sscanf(buf, "%d", &old_value); - if (old_value == mark_or_clear) { - BLACK_DEBUG_PRINTK("buf:%s, old_value:%d, mark_or_clear:%d\n", - buf, old_value, mark_or_clear); - goto out; - } - //read end - - //write begin - sprintf(buf, "%d\n", mark_or_clear); - pos = 0; - len = kernel_write(fp, buf, strlen(buf), &pos); - if (len < 0) - BLACK_DEBUG_PRINTK("write %s file error\n", BLACKSCREEN_HAPPENED_FILE); - //write end - - pos = 0; - kernel_read(fp, buf, sizeof(buf), &pos); - BLACK_DEBUG_PRINTK("black_mark_or_clear_error_happened_flag %s, mark:%d\n", - buf, mark_or_clear); -out: - filp_close(fp, NULL); - - return len; -} -#else -static int black_mark_or_clear_error_happened_flag(struct black_data *bla_data, int mark_or_clear) -{ - black_screen_error_happened_flag = mark_or_clear; - return black_screen_error_happened_flag; -} -#endif - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static int black_write_error_count(struct black_data *bla_data) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - static bool have_read_old = false; - - fp = filp_open(BLACKSCREEN_COUNT_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BLACK_DEBUG_PRINTK("create %s file error fp:%p %d \n", BLACKSCREEN_COUNT_FILE, fp,PTR_ERR(fp)); - return -1; - } - - //read old error_count begin - if (have_read_old == false) { - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BLACK_DEBUG_PRINTK("read %s file error\n", BLACKSCREEN_COUNT_FILE); - goto out; - } - sscanf(buf, "%d", &bla_data->error_count_old); - bla_data->error_count_new = bla_data->error_count_new + bla_data->error_count_old; - have_read_old = true; - BLACK_DEBUG_PRINTK("read_buf:%s count_old:%d count_new:%d\n", - buf, bla_data->error_count_old, bla_data->error_count_new); - } - //read old error_count_new end - - sprintf(buf, "%d\n", bla_data->error_count_new); - - pos = 0; - len = kernel_write(fp, buf, strlen(buf), &pos); - if (len < 0) - BLACK_DEBUG_PRINTK("write %s file error\n", BLACKSCREEN_COUNT_FILE); - - pos = 0; - kernel_read(fp, buf, sizeof(buf), &pos); - BLACK_DEBUG_PRINTK("black_write_error_count %s\n", buf); - -out: - filp_close(fp, NULL); - - return len; -} -#else -static int black_write_error_count(struct black_data *bla_data) -{ - - bla_data->error_count_old = black_screen_error_counter; - bla_data->error_count_new = bla_data->error_count_new + bla_data->error_count_old; - black_screen_error_counter = bla_data->error_count_new; - BLACK_DEBUG_PRINTK("black_error_count %d\n", black_screen_error_counter); - return black_screen_error_counter; -} -#endif - -static void find_task_by_comm(const char * pcomm, struct task_struct ** t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) - { - if(!strcmp(t->comm, pcomm)) - { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -//copy mtk_boot_common.h -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 -static int get_status(void) -{ -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if(MSM_BOOT_MODE__NORMAL == get_boot_mode()) - { - if(def_swich) - return BLACK_STATUS_CHECK_ENABLE; - } - return BLACK_STATUS_INIT_SUCCEES; -#else - if((get_boot_mode() == NORMAL_BOOT) || (get_boot_mode() == ALARM_BOOT)) - { - if(def_swich) - return BLACK_STATUS_CHECK_ENABLE; - } - return BLACK_STATUS_INIT_SUCCEES; - -#endif -} - -static int get_log_swich() -{ - return (BLACK_STATUS_CHECK_ENABLE == get_status()||BLACK_STATUS_CHECK_DEBUG == get_status())&& g_black_data.get_log; -} - -static void dump_freeze_log(void) -{ - struct task_struct *t_init; - t_init = NULL; - - if (!get_log_swich()) - { - BLACK_DEBUG_PRINTK("log swich is disable ,return !!!"); - return; - } - - find_task_by_comm(TASK_INIT_COMM, &t_init); - if(NULL != t_init) - { - BLACK_DEBUG_PRINTK("send signal %d ", SIG_THEIA); - send_sig_info(SIG_THEIA, SEND_SIG_PRIV, 0); - } -} - -static void black_determine_init_status_work(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - struct black_data *bla_data = - container_of(dwork, struct black_data, determine_init_status_work); - - if(bla_data->status != BLACK_STATUS_CHECK_ENABLE && bla_data->status != BLACK_STATUS_CHECK_DEBUG){ - BLACK_DEBUG_PRINTK("init_status status: %d, return\n", bla_data->status); - return; - } - if (black_check_error_happened_before(bla_data)) { - bla_data->error_detected = 1; - wake_up_interruptible(&black_check_wq); - } -} - -static void black_clear_error_happened_flag_work(struct work_struct *work) -{ - struct black_data *bla_data - = container_of(work, struct black_data, clear_error_happened_flag_work); - - black_mark_or_clear_error_happened_flag(bla_data, BLACK_CLEAR_ERROR_HAPPENED); -} - -static void black_error_happen_work(struct work_struct *work) -{ - struct black_data *bla_data - = container_of(work, struct black_data, error_happen_work); - - if (bla_data->error_count_new < BLACK_MAX_WRITE_NUMBER) { - bla_data->error_count_new++; - dump_freeze_log(); - black_write_error_count(bla_data); - black_mark_or_clear_error_happened_flag(bla_data, BLACK_MARK_ERROR_HAPPENED); - } - BLACK_DEBUG_PRINTK("black_error_happen_work error_count_new = %d old = %d stage = %d\n", - bla_data->error_count_new, bla_data->error_count_old,ur_stage); - theia_pwk_stage_end(); - if(bla_data->is_panic) { - //1.meminfo - //2. show all D task -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - handle_sysrq('w'); -#else - show_state_filter(TASK_UNINTERRUPTIBLE); -#endif - //3. show system_server zoygot surfacefliger state - black_show_coretask_state(); - //4.current cpu registers :skip for minidump - //panic("black screen detected, force panic"); - } - bla_data->error_detected = 1; - wake_up_interruptible(&black_check_wq); -} - -static void black_timer_func(struct timer_list *t) -{ - struct black_data *p = from_timer(p, t, timer); - BLACK_DEBUG_PRINTK("black_timer_func is called\n"); - schedule_work(&p->error_happen_work); -} - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -static int black_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct msm_drm_notifier *evdata = data; - int *blank; - - if (event == MSM_DRM_EVENT_BLANK && evdata && evdata->data) - { - blank = evdata->data; - g_black_data.blank = *blank; - if(g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - del_timer(&g_black_data.timer); - BLACK_DEBUG_PRINTK("black_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_black_data.status,g_black_data.blank); - } - } - else if (event == MSM_DRM_EARLY_EVENT_BLANK && evdata && evdata->data) - { - blank = evdata->data; - - blank = evdata->data; - g_black_data.blank = *blank; - if(g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - del_timer(&g_black_data.timer); - BLACK_DEBUG_PRINTK("black_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_black_data.status,g_black_data.blank); - } - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d\n",event,g_black_data.status); - } - return 0; -} -#else -static int black_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct fb_event *evdata = data; - int *blank; - - if (evdata && evdata->data && event == FB_EVENT_BLANK) - { - blank = evdata->data; - g_black_data.blank = *blank; - if(g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - del_timer(&g_black_data.timer); - BLACK_DEBUG_PRINTK("black_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_black_data.status,g_black_data.blank); - } - } -#ifdef FB_EARLY_EVENT_BLANK - else if (evdata && evdata->data && event == FB_EARLY_EVENT_BLANK) - { - blank = evdata->data; - g_black_data.blank = *blank; - if(g_black_data.status != BLACK_STATUS_CHECK_DEBUG){ - del_timer(&g_black_data.timer); - BLACK_DEBUG_PRINTK("black_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_black_data.status, g_black_data.blank); - } else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_black_data.status,g_black_data.blank); - } - } -#endif - else { - BLACK_DEBUG_PRINTK("black_fb_notifier_callback:event = %lu status:%d\n",event,g_black_data.status); - } - return 0; -} -#endif /* CONFIG_DRM_MSM */ - -static int __init black_screen_check_init(void) -{ - int ret = 0; - - g_black_data.fb_notif.notifier_call = black_fb_notifier_callback; -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - ret = msm_drm_register_client(&g_black_data.fb_notif); -#else - ret= fb_register_client(&g_black_data.fb_notif); -#endif - if (ret) { - printk("black_fb_notifier_callback register failed !\n"); - g_black_data.status = ret; - return ret; - } - - proc_create("blackCheck", S_IRWXUGO, NULL, &black_screen_check_proc_fops); - proc_create("blackCheckStatus", S_IRWXUGO, NULL, &black_screen_check_status_proc_fops); - proc_create("theiaPwkReport", S_IRWXUGO, NULL, &black_screen_report_proc_fops); - proc_create("blackSwitch", S_IRWXUGO, NULL, &black_screen_switch_proc_fops); - init_waitqueue_head(&black_check_wq); - INIT_WORK(&g_black_data.error_happen_work, black_error_happen_work); - INIT_WORK(&g_black_data.clear_error_happened_flag_work, black_clear_error_happened_flag_work); - INIT_DELAYED_WORK(&g_black_data.determine_init_status_work, black_determine_init_status_work); - - timer_setup((&g_black_data.timer), (black_timer_func),TIMER_DEFERRABLE); - schedule_delayed_work(&g_black_data.determine_init_status_work, - msecs_to_jiffies(BLACK_INIT_STATUS_TIMEOUT_MS)); - g_black_data.status = get_status(); - - flow_buf= vmalloc(stage_brief_size*flow_size); - if (!flow_buf) { - return -ENOMEM; - } - memset(flow_buf,0,stage_brief_size*flow_size); - flow_buf_curr = flow_buf; - - return 0; -} - -static void __exit black_screen_exit(void) -{ - del_timer(&g_black_data.timer); - fb_unregister_client(&g_black_data.fb_notif); - if (!flow_buf) { - vfree(flow_buf); - flow_buf = NULL; - } -} - -late_initcall(black_screen_check_init); -module_exit(black_screen_exit); - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/oplus_brightscreen_check.c b/drivers/soc/oplus/system/theia/oplus_brightscreen_check.c deleted file mode 100755 index 8d0e5e9db511..000000000000 --- a/drivers/soc/oplus/system/theia/oplus_brightscreen_check.c +++ /dev/null @@ -1,792 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -#include -#endif - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -#include -#endif -#include - -//#define BLACKCREEN_COUNT_FILE "/data/oplus/log/bsp/blackscreen_count.txt" -//#define BLACKSCREEN_HAPPENED_FILE "/data/oplus/log/bsp/blackscreen_happened.txt" -#define BRIGHTSCREEN_COUNT_FILE "/data/oplus/log/bsp/brightscreen_count.txt" -#define BRIGHTSCREEN_HAPPENED_FILE "/data/oplus/log/bsp/brightscreen_happened.txt" - -#define BRIGHT_DEBUG_PRINTK(a, arg...)\ - do{\ - printk("[bright_check]: " a, ##arg);\ - }while(0) - -#define BRIGHT_STATUS_INIT 1 -#define BRIGHT_STATUS_INIT_FAIL 2 -#define BRIGHT_STATUS_INIT_SUCCEES 3 -#define BRIGHT_STATUS_CHECK_ENABLE 4 -#define BRIGHT_STATUS_CHECK_DISABLE 5 -#define BRIGHT_STATUS_CHECK_DEBUG 6 - -#define BRIGHT_CLEAR_ERROR_HAPPENED 0 -#define BRIGHT_MARK_ERROR_HAPPENED 1 - -#define BRIGHT_MAX_WRITE_NUMBER 3000 -#define BRIGHT_DEFAULT_TIMEOUT_MS 120000 -#define BRIGHT_INIT_STATUS_TIMEOUT_MS 150000 -#define BRIGHT_SLOW_TIMEOUT_MS 20000 - -#define SIG_THEIA (SIGRTMIN + 0x13) -#define TASK_INIT_COMM "init" -static int def_swich=1; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int bright_screen_error_counter = 0; -static int bright_screen_error_happened_flag = 0; -#endif -struct bright_data{ - int is_panic; - int status; - int blank; - int get_log; - unsigned int timeout_ms; - int error_detected; - unsigned int error_count_new; - unsigned int error_count_old; - struct notifier_block fb_notif; - struct timer_list timer; - wait_queue_head_t keylog_thread_wq; - struct work_struct error_happen_work; - struct work_struct clear_error_happened_flag_work; - struct delayed_work determine_init_status_work; -}; - -static void bright_timer_func(struct timer_list *t); -static int get_status(void); - -static struct bright_data g_bright_data = { - .is_panic = 0, - .status = BRIGHT_STATUS_INIT, -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - .blank = MSM_DRM_BLANK_UNBLANK, -#else - .blank = FB_BLANK_UNBLANK, -#endif - .timeout_ms = BRIGHT_SLOW_TIMEOUT_MS, - .error_detected = 0, - .error_count_new = 0, - .error_count_old = 0, - //.timer.function = bright_timer_func, -}; - -static wait_queue_head_t bright_check_wq; - -int bright_screen_timer_restart(void) -{ - static bool start_check = false; - - //BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart:blank = %d,status = %d\n",g_bright_data.blank,g_bright_data.status); - if(g_bright_data.status != BRIGHT_STATUS_CHECK_ENABLE && g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart:g_bright_data.status = %d return\n",g_bright_data.status); - return g_bright_data.status; - } -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if(g_bright_data.blank == MSM_DRM_BLANK_POWERDOWN) //MSM_DRM_BLANK_POWERDOWN -#else - if(g_bright_data.blank == FB_BLANK_POWERDOWN) //FB_BLANK_POWERDOWN -#endif - { - start_check = true; - } - - if (start_check == false) { - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart: blank:%d status:%d never bright, return\n", - g_bright_data.blank, g_bright_data.status); - return g_bright_data.status; - } - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if(g_bright_data.blank == MSM_DRM_BLANK_UNBLANK) //MSM_DRM_BLANK_POWERDOWN -#else - if(g_bright_data.blank == FB_BLANK_UNBLANK) //FB_BLANK_POWERDOWN -#endif - { - mod_timer(&g_bright_data.timer,jiffies + msecs_to_jiffies(g_bright_data.timeout_ms)); - BRIGHT_DEBUG_PRINTK("bright_screen_timer_restart: bright screen check start %u\n",g_bright_data.timeout_ms); - theia_pwk_stage_start(); - return 0; - } - return g_bright_data.blank; -} -EXPORT_SYMBOL(bright_screen_timer_restart); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int bright_screen_proc_open(struct inode *inode, struct file *file) -{ - int ret; - - ret = nonseekable_open(inode, file); - if (unlikely(ret)) - return ret; - file->private_data = NULL; - - return 0; -} -#endif - -static ssize_t bright_screen_check_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - char page[256] = {0}; - int len = 0; - - len = sprintf(&page[len],"%d %u %d %d\n", - g_bright_data.status,g_bright_data.timeout_ms,g_bright_data.is_panic,g_bright_data.get_log); - - if(len > *off) - len -= *off; - else - len = 0; - - if(copy_to_user(buf,page,(len < count ? len : count))){ - return -EFAULT; - } - *off += len < count ? len : count; - return (len < count ? len : count); - -} - -static ssize_t bright_screen_check_proc_write(struct file *file, const char __user *buf, - size_t count,loff_t *off) -{ - int tmp_status = 0; - int tmp_timeout = 0; - int tmp_isPanic = 0; - int tmp_log = 0; - int ret = 0; - char buffer[40] = {0}; - - if(g_bright_data.status == BRIGHT_STATUS_INIT || g_bright_data.status == BRIGHT_STATUS_INIT_FAIL){ - BRIGHT_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_bright_data.status); - return count; - } - - if (count > 40) { - count = 40; - } - - if (copy_from_user(buffer, buf, count)) { - BRIGHT_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - ret = sscanf(buffer, "%d %u %d %d", &tmp_status,&tmp_timeout,&tmp_isPanic,&tmp_log); - - if (ret == 1) { - g_bright_data.status = tmp_status; - } else if(ret == 4){ - g_bright_data.status = tmp_status; - if(tmp_timeout) - g_bright_data.timeout_ms = tmp_timeout; - g_bright_data.is_panic = tmp_isPanic; - g_bright_data.get_log = tmp_log; - }else{ - BRIGHT_DEBUG_PRINTK("%s invalid content: '%s', length = %zd\n", __func__, buffer, count); - } - - def_swich = tmp_status == BRIGHT_STATUS_CHECK_ENABLE || BRIGHT_STATUS_CHECK_DEBUG == tmp_status; - BRIGHT_DEBUG_PRINTK("%s: status = %d timeout_ms = %u is_panic = %d\n", - __func__, g_bright_data.status,g_bright_data.timeout_ms,g_bright_data.is_panic); - - return count; - -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -struct file_operations bright_screen_check_proc_fops = { - .read = bright_screen_check_proc_read, - .write = bright_screen_check_proc_write, -}; -#else -static const struct proc_ops bright_screen_check_proc_fops = { - .proc_open = bright_screen_proc_open, - .proc_read = bright_screen_check_proc_read, - .proc_write = bright_screen_check_proc_write, -}; -#endif - -static ssize_t bright_screen_check_status_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - char page[256] = {0}; - int len = 0; - int error_detected = 0; - - BRIGHT_DEBUG_PRINTK("read bright_err_detected:%d count:%d begin\n", - g_bright_data.error_detected, g_bright_data.error_count_new); - wait_event_interruptible(bright_check_wq,g_bright_data.error_detected>0); - BRIGHT_DEBUG_PRINTK("read bright_err_detected:%d count:%d end\n", - g_bright_data.error_detected, g_bright_data.error_count_new); - - if (g_bright_data.error_detected) { - len = sprintf(&page[len], "%u", g_bright_data.error_count_new); - } else { - len = sprintf(&page[len],"%d", 0); - } - error_detected = g_bright_data.error_detected; - g_bright_data.error_detected = 0; - if(len > *off) - len -= *off; - else - len = 0; - if(copy_to_user(buf,page,(len < count ? len : count))){ - return -EFAULT; - } - *off += len < count ? len : count; - if (error_detected) { - schedule_work(&g_bright_data.clear_error_happened_flag_work); - } - - return (len < count ? len : count); - -} - - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -struct file_operations bright_screen_check_status_proc_fops = { - .read = bright_screen_check_status_proc_read, -}; -#else -static const struct proc_ops bright_screen_check_status_proc_fops = { - .proc_open = bright_screen_proc_open, - .proc_read = bright_screen_check_status_proc_read, -}; -#endif - -static bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && - (t->parent != 0 && !strcmp(t->parent->comm,"init"))) - return true; - else - return false; - return false; -} -extern void touch_all_softlockup_watchdogs(void); - -static void bright_show_coretask_state(void) -{ - struct task_struct *g, *p; - - rcu_read_lock(); - for_each_process_thread(g, p) { - if (is_zygote_process(p) || !strncmp(p->comm,"system_server", TASK_COMM_LEN) - || !strncmp(p->comm,"surfaceflinger", TASK_COMM_LEN)) { -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - touch_nmi_watchdog(); -#endif - sched_show_task(p); - } - } - -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_THEIA) - touch_all_softlockup_watchdogs(); -#endif - rcu_read_unlock(); -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -static bool bright_check_error_happened_before(struct bright_data *bri_data) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - int error_happened = 0; - - fp = filp_open(BRIGHTSCREEN_HAPPENED_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BRIGHT_DEBUG_PRINTK("create %s file error fp:%p\n", BRIGHTSCREEN_COUNT_FILE, fp); - return false; - } - - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BRIGHT_DEBUG_PRINTK("read %s file error\n", BRIGHTSCREEN_HAPPENED_FILE); - goto out; - } - sscanf(buf, "%d", &error_happened); -out: - BRIGHT_DEBUG_PRINTK("error_happened before:%d\n", error_happened); - filp_close(fp, NULL); - - return (error_happened > 0 ? true : false); -} - -static int bright_mark_or_clear_error_happened_flag(struct bright_data *bri_data, int mark_or_clear) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - int old_value = 0; - - fp = filp_open(BRIGHTSCREEN_HAPPENED_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BRIGHT_DEBUG_PRINTK("create %s file error fp:%p\n", BRIGHTSCREEN_HAPPENED_FILE, fp); - return -1; - } - - //read to check whether write or not - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BRIGHT_DEBUG_PRINTK("read %s file error\n", BRIGHTSCREEN_HAPPENED_FILE); - goto out; - } - sscanf(buf, "%d", &old_value); - if (old_value == mark_or_clear) { - BRIGHT_DEBUG_PRINTK("buf:%s, old_value:%d, mark_or_clear:%d\n", - buf, old_value, mark_or_clear); - goto out; - } - //read end - - //write begin - sprintf(buf, "%d\n", mark_or_clear); - pos = 0; - len = kernel_write(fp, buf, strlen(buf), &pos); - if (len < 0) - BRIGHT_DEBUG_PRINTK("write %s file error\n", BRIGHTSCREEN_HAPPENED_FILE); - //write end - - pos = 0; - kernel_read(fp, buf, sizeof(buf), &pos); - BRIGHT_DEBUG_PRINTK("bright_mark_or_clear_error_happened_flag %s, mark:%d\n", - buf, mark_or_clear); -out: - filp_close(fp, NULL); - - return len; -} - -static int bright_write_error_count(struct bright_data *bri_data) -{ - struct file *fp; - loff_t pos; - ssize_t len = 0; - char buf[256] = {'\0'}; - static bool have_read_old = false; - - fp = filp_open(BRIGHTSCREEN_COUNT_FILE, O_RDWR | O_CREAT, 0664); - if (IS_ERR(fp)) { - BRIGHT_DEBUG_PRINTK("create %s file error fp:%p\n", BRIGHTSCREEN_COUNT_FILE, fp); - return -1; - } - - //read old error_count begin - if (have_read_old == false) { - pos = 0; - len = kernel_read(fp, buf, sizeof(buf), &pos); - if (len < 0) { - BRIGHT_DEBUG_PRINTK("read %s file error\n", BRIGHTSCREEN_COUNT_FILE); - goto out; - } - sscanf(buf, "%d", &bri_data->error_count_old); - bri_data->error_count_new = bri_data->error_count_new + bri_data->error_count_old; - have_read_old = true; - BRIGHT_DEBUG_PRINTK("read_buf:%s count_old:%d count_new:%d\n", - buf, bri_data->error_count_old, bri_data->error_count_new); - - } - //read old error_count_new end - - sprintf(buf, "%d\n", bri_data->error_count_new); - - pos = 0; - len = kernel_write(fp, buf, strlen(buf), &pos); - if (len < 0) - BRIGHT_DEBUG_PRINTK("write %s file error\n", BRIGHTSCREEN_COUNT_FILE); - - pos = 0; - kernel_read(fp, buf, sizeof(buf), &pos); - BRIGHT_DEBUG_PRINTK("bright_write_error_count %s\n", buf); - -out: - filp_close(fp, NULL); - - return len; -} -#else -static bool bright_check_error_happened_before(struct bright_data *bri_data) -{ - BRIGHT_DEBUG_PRINTK("error_happened before:%d\n", bright_screen_error_happened_flag); - return (bright_screen_error_happened_flag > 0 ? true : false); -} - -static int bright_mark_or_clear_error_happened_flag(struct bright_data *bla_data, int mark_or_clear) -{ - bright_screen_error_happened_flag = mark_or_clear; - return bright_screen_error_happened_flag; -} - -static int bright_write_error_count(struct bright_data *bri_data) -{ - - bri_data->error_count_old = bright_screen_error_counter; - bri_data->error_count_new = bri_data->error_count_new + bri_data->error_count_old; - bright_screen_error_counter = bri_data->error_count_new; - BRIGHT_DEBUG_PRINTK("black_error_count %d\n", bright_screen_error_counter); - return bright_screen_error_counter; -} -#endif - -static void bright_determine_init_status_work(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - struct bright_data *bri_data = - container_of(dwork, struct bright_data, determine_init_status_work); - - if(bri_data->status != BRIGHT_STATUS_CHECK_ENABLE && bri_data->status != BRIGHT_STATUS_CHECK_DEBUG){ - BRIGHT_DEBUG_PRINTK("init_status status: %d, return\n", bri_data->status); - return; - } - if (bright_check_error_happened_before(bri_data)) { - bri_data->error_detected = 1; - wake_up_interruptible(&bright_check_wq); - } -} -static void find_task_by_comm(const char * pcomm, struct task_struct ** t_result) -{ - struct task_struct *g, *t; - rcu_read_lock(); - for_each_process_thread(g, t) - { - if(!strcmp(t->comm, pcomm)) - { - *t_result = t; - rcu_read_unlock(); - return; - } - } - t_result = NULL; - rcu_read_unlock(); -} - -//copy mtk_boot_common.h -#define NORMAL_BOOT 0 -#define ALARM_BOOT 7 - -static int get_status(void) -{ -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - if(MSM_BOOT_MODE__NORMAL == get_boot_mode()) - { - if(def_swich) - return BRIGHT_STATUS_CHECK_ENABLE; - } - return BRIGHT_STATUS_INIT_SUCCEES; -#else - if((get_boot_mode() == NORMAL_BOOT) || (get_boot_mode() == ALARM_BOOT)) - { - if(def_swich) - return BRIGHT_STATUS_CHECK_ENABLE; - } - return BRIGHT_STATUS_INIT_SUCCEES; - -#endif -} - -static int get_log_swich() -{ - return (BRIGHT_STATUS_CHECK_ENABLE == get_status()||BRIGHT_STATUS_CHECK_DEBUG == get_status())&& g_bright_data.get_log; -} -static void dump_freeze_log(void) -{ - struct task_struct *t_init; - if (!get_log_swich()) - { - BRIGHT_DEBUG_PRINTK("log swich is disable ,return !!!"); - return; - } - t_init = NULL; - find_task_by_comm(TASK_INIT_COMM, &t_init); - if(NULL != t_init) - { - BRIGHT_DEBUG_PRINTK("send signal %d at ", SIG_THEIA); - send_sig_info(SIG_THEIA, SEND_SIG_PRIV, 0); - } -} - -static void bright_clear_error_happened_flag_work(struct work_struct *work) -{ - struct bright_data *bri_data - = container_of(work, struct bright_data, clear_error_happened_flag_work); - - bright_mark_or_clear_error_happened_flag(bri_data, BRIGHT_CLEAR_ERROR_HAPPENED); -} - -static void bright_error_happen_work(struct work_struct *work) -{ - struct bright_data *bri_data - = container_of(work, struct bright_data, error_happen_work); - - if (bri_data->error_count_new < BRIGHT_MAX_WRITE_NUMBER) { - bri_data->error_count_new++; - dump_freeze_log(); - bright_write_error_count(bri_data); - bright_mark_or_clear_error_happened_flag(bri_data, BRIGHT_MARK_ERROR_HAPPENED); - } - BRIGHT_DEBUG_PRINTK("bright_error_happen_work error_count_new = %d old = %d\n", - bri_data->error_count_new, bri_data->error_count_old); - theia_pwk_stage_end(); - if(bri_data->is_panic) { - //1.meminfo - //2. show all D task -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - handle_sysrq('w'); -#else - show_state_filter(TASK_UNINTERRUPTIBLE); -#endif - //3. show system_server zoygot surfacefliger state - bright_show_coretask_state(); - //4.current cpu registers :skip for minidump - panic("bright screen detected, force panic"); - } - bri_data->error_detected = 1; - wake_up_interruptible(&bright_check_wq); -} -static void bright_timer_func(struct timer_list *t) -{ -// struct bright_data * p = (struct bright_data *)data; - struct bright_data * p = from_timer(p, t, timer); - - - BRIGHT_DEBUG_PRINTK("bright_timer_func is called\n"); - - schedule_work(&p->error_happen_work); -} - -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct msm_drm_notifier *evdata = data; - int *blank; - - if (event == MSM_DRM_EVENT_BLANK && evdata && evdata->data) - { - blank = evdata->data; - g_bright_data.blank = *blank; - if(g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - del_timer(&g_bright_data.timer); - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback: del timer,event:%lu status:%d blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_bright_data.status,g_bright_data.blank); - } - } - else if (event == MSM_DRM_EARLY_EVENT_BLANK && evdata && evdata->data) - { - blank = evdata->data; - - blank = evdata->data; - g_bright_data.blank = *blank; - if(g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - del_timer(&g_bright_data.timer); - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback: del timer event:%lu status:%d blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu status:%d blank:%d\n", - event,g_bright_data.status,g_bright_data.blank); - } - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu status:%d\n",event,g_bright_data.status); - } - - return 0; -} -#else -static int bright_fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct fb_event *evdata = data; - int *blank; - - if (evdata && evdata->data && event == FB_EVENT_BLANK) - { - blank = evdata->data; - g_bright_data.blank = *blank; - if(g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - del_timer(&g_bright_data.timer); - BRIGHT_DEBUG_PRINTK("bright fb_notifier_callback: del timer,event:%d,status:%d,blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu,status:%d,blank:%d\n", - event,g_bright_data.status,g_bright_data.blank = *blank); - } - } -#ifdef FB_EARLY_EVENT_BLANK - else if (evdata && evdata->data && event == FB_EARLY_EVENT_BLANK) - { - blank = evdata->data; - g_bright_data.blank = *blank; - if(g_bright_data.status != BRIGHT_STATUS_CHECK_DEBUG){ - del_timer(&g_bright_data.timer); - BRIGHT_DEBUG_PRINTK("bright fb_notifier_callback: del timer,event:%d,status:%d,blank:%d\n", - event, g_bright_data.status, g_bright_data.blank); - } else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu,status:%d,blank:%d\n", - event,g_bright_data.status,g_bright_data.blank = *blank); - } - } -#endif - else { - BRIGHT_DEBUG_PRINTK("bright_fb_notifier_callback:event = %lu,status:%d\n",event,g_bright_data.status); - } - return 0; -} -#endif /* CONFIG_DRM_MSM */ -static int passok(int stage) -{ - return stage==0; -} -static ssize_t bright_screen_ur_process(int stage) -{ - if(passok(stage)) - { - - del_timer(&g_bright_data.timer); - BRIGHT_DEBUG_PRINTK("del timer,stage: %d \n", - stage); - } - return 0; -} - -static ssize_t bright_screen_switch_proc_write(struct file *file, const char __user *buf, - size_t count,loff_t *off) -{ - int tmp_stage = 0; - int ret = 0; - char buffer[40] = {0}; - - if(g_bright_data.status == BRIGHT_STATUS_INIT || g_bright_data.status == BRIGHT_STATUS_INIT_FAIL){ - BRIGHT_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_bright_data.status); - return count; - } - - if (count > 40) { - count = 40; - } - - if (copy_from_user(buffer, buf, count)) { - BRIGHT_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - ret = sscanf(buffer, "%d", &tmp_stage); - if(1 == tmp_stage) - { - del_timer(&g_bright_data.timer); - } - - if (ret == 1) { - BRIGHT_DEBUG_PRINTK("%s recv us report stage: %d\n", __func__, tmp_stage); - bright_screen_ur_process(tmp_stage); - //g_black_data.status = tmp_status; - }else{ - BRIGHT_DEBUG_PRINTK("%s invalid content: '%s', length = %zd\n", __func__, buf, count); - } - - return count; -} -static ssize_t bright_screen_switch_proc_read(struct file *file, char __user *buf, - size_t count,loff_t *off) -{ - return 0; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) -struct file_operations bright_screen_switch_proc_fops = { - .read = bright_screen_switch_proc_read, - .write = bright_screen_switch_proc_write, -}; -#else -static const struct proc_ops bright_screen_switch_proc_fops = { - .proc_open = bright_screen_proc_open, - .proc_read = bright_screen_switch_proc_read, - .proc_write = bright_screen_switch_proc_write, -}; -#endif - -static int __init bright_screen_check_init(void) -{ - int ret = 0; - - g_bright_data.fb_notif.notifier_call = bright_fb_notifier_callback; -#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY) - ret = msm_drm_register_client(&g_bright_data.fb_notif); -#else - ret = fb_register_client(&g_bright_data.fb_notif); -#endif - if (ret) { - g_bright_data.status = ret; - printk("bright block_screen_init register fb client fail\n"); - return ret; - } - - proc_create("brightCheck", S_IRWXUGO, NULL, &bright_screen_check_proc_fops); - proc_create("brightCheckStatus", S_IRWXUGO, NULL, &bright_screen_check_status_proc_fops); - proc_create("brightSwitch", S_IRWXUGO, NULL, &bright_screen_switch_proc_fops); - init_waitqueue_head(&bright_check_wq); - INIT_WORK(&g_bright_data.error_happen_work, bright_error_happen_work); - INIT_WORK(&g_bright_data.clear_error_happened_flag_work, bright_clear_error_happened_flag_work); - INIT_DELAYED_WORK(&g_bright_data.determine_init_status_work, bright_determine_init_status_work); - - timer_setup((&g_bright_data.timer), (bright_timer_func),TIMER_DEFERRABLE); - schedule_delayed_work(&g_bright_data.determine_init_status_work, - msecs_to_jiffies(BRIGHT_INIT_STATUS_TIMEOUT_MS)); - g_bright_data.status = get_status(); - return 0; -} - -static void __exit bright_screen_exit(void) -{ - - del_timer(&g_bright_data.timer); - fb_unregister_client(&g_bright_data.fb_notif); -} - -late_initcall(bright_screen_check_init); -module_exit(bright_screen_exit); - -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/powerkey_monitor.c b/drivers/soc/oplus/system/theia/powerkey_monitor.c deleted file mode 100755 index 53207f7593fa..000000000000 --- a/drivers/soc/oplus/system/theia/powerkey_monitor.c +++ /dev/null @@ -1,509 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#include -#include "powerkey_monitor.h" -#include "theia_kevent_kernel.h" - -#define POWER_MONITOR_DEBUG_PRINTK(a, arg...)\ - do {\ - printk("[powerkey_monitor]: " a, ##arg);\ - }while(0) - -static char *flow_buf = NULL; -static char *flow_buf_curr = NULL; -static int flow_index = 0; -static int stage_start = 0; -#define FLOW_SIZE 16 -#define STAGE_BRIEF_SIZE 64 -#define STAGE_TOTAL_SIZE ((STAGE_BRIEF_SIZE)*(FLOW_SIZE)) - -static struct task_struct *block_thread = NULL; -static bool timer_started = false; -static int systemserver_pid = -1; - -int get_systemserver_pid(void) -{ - return systemserver_pid; -} - -/*bool is_valid_systemserver_pid(int pid) -{ - struct task_struct *task; - - if (pid < 0) { - return false; - } - - rcu_read_lock(); - task = find_task_by_vpid(pid); - rcu_read_unlock(); - - if (task != NULL) { - const struct cred *tcred = __task_cred(task); - if ((task->group_leader->pid == task->pid) - && (tcred->uid.val == 1000) - && (task->parent != 0 && !strcmp(task->parent->comm, "main"))) { - return true; - } - } - - return false; -} - -bool is_powerkey_check_valid(void) -{ - return is_valid_systemserver_pid(systemserver_pid); -}*/ - -static ssize_t powerkey_monitor_param_proc_read(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - char page[512] = {0}; - int len = 0; - - len = sprintf(&page[len], "status=%d timeout_ms=%u is_panic=%d get_log=%d systemserver_pid=%d\n", - g_black_data.status, g_black_data.timeout_ms, g_black_data.is_panic, g_black_data.get_log, systemserver_pid); - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buf, page, (len < count ? len : count))) { - return -EFAULT; - } - *off += len < count ? len : count; - return (len < count ? len : count); -} - -static bool handle_param_setup(char *key, char *value) -{ - bool ret = true; - - POWER_MONITOR_DEBUG_PRINTK("%s: setup param key:%s, value:%s\n", __func__, key, value); - if (!strncmp(key, "state", 5)) { - int state; - if (sscanf(value, "%d", &state) == 1) { - g_black_data.status = g_bright_data.status = state; - } - } else if (!strncmp(key, "timeout", 7)) { - int timeout; - if (sscanf(value, "%d", &timeout) == 1) { - g_black_data.timeout_ms = g_bright_data.timeout_ms = timeout; - } - } else if (!strncmp(key, "log", 3)) { - int get_log; - if (sscanf(value, "%d", &get_log) == 1) { - g_black_data.get_log = g_bright_data.get_log = get_log; - } - } else if (!strncmp(key, "panic", 5)) { - int is_panic; - if (sscanf(value, "%d", &is_panic) == 1) { - g_black_data.is_panic = g_bright_data.is_panic = is_panic; - } - } else if (!strncmp(key, "systemserver_pid", 16)) { - int s_pid; - if (sscanf(value, "%d", &s_pid) == 1) { - systemserver_pid = s_pid; - } - } else { - ret = false; - } - - return ret; -} - -/* -param format: -state 4;timeout 20000;panic 0;log 1 -systemserver_pid 32639 -*/ -static ssize_t powerkey_monitor_param_proc_write(struct file *file, const char __user *buf, - size_t count, loff_t *off) -{ - char buffer[256] = {0}; - char *pBuffer = NULL; - char *param; - int ret = 0; - - if (count > 255) { - count = 255; - } - - if (copy_from_user(buffer, buf, count)) { - POWER_MONITOR_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - buffer[count] = '\0'; - pBuffer = buffer; - - POWER_MONITOR_DEBUG_PRINTK("%s: buffer:%s\n", __func__, buffer); - - while ((param = strsep(&pBuffer, ";"))) { - char key[64] = {0}, value[64] = {0}; - ret = sscanf(param, "%s %s", key, value); - POWER_MONITOR_DEBUG_PRINTK("%s: param:%s ret:%d key:%s value:%s\n", __func__, param, ret, key, value); - if (ret == 2) { - if (!handle_param_setup(key, value)) { - POWER_MONITOR_DEBUG_PRINTK("%s: setup param fail! key:%s, value:%s\n", __func__, key, value); - } - } - } - - return count; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) -static int powerkey_monitor_param_proc_show(struct seq_file *seq_file, void *data) { - seq_printf(seq_file, "%s called\n", __func__); - return 0; -} - -static int powerkey_monitor_param_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, powerkey_monitor_param_proc_show, NULL); -} -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static const struct proc_ops powerkey_monitor_param_proc_fops = { - .proc_open = powerkey_monitor_param_proc_open, - .proc_read = powerkey_monitor_param_proc_read, - .proc_write = powerkey_monitor_param_proc_write, - .proc_lseek = seq_lseek, - .proc_release = single_release, - }; -#else - struct file_operations powerkey_monitor_param_proc_fops = { - .read = powerkey_monitor_param_proc_read, - .write = powerkey_monitor_param_proc_write, - }; -#endif - - - -ssize_t get_last_pwkey_stage(char *buf) -{ - if (stage_start != flow_index) { - int last_index = (flow_index == 0) ? (FLOW_SIZE - 1) : (flow_index - 1); - snprintf(buf, 64, (last_index*STAGE_BRIEF_SIZE + flow_buf)); - } else { - sprintf(buf, ""); - } - - return strlen(buf); -} - -ssize_t get_pwkey_stages(char *buf) -{ - char *buf_curr = NULL; - int start_index = stage_start; - int end_index = flow_index; - - if (start_index == end_index) { - return 0; - } - - buf_curr = start_index*STAGE_BRIEF_SIZE + flow_buf; - POWER_MONITOR_DEBUG_PRINTK("get_pwkey_stages start_index:%d end_index:%d\n", start_index, end_index); - - while (start_index!= end_index) { - strcat(buf, buf_curr); - strcat(buf, ","); - POWER_MONITOR_DEBUG_PRINTK("get_pwkey_stages buf:%s\n", buf); - - buf_curr += STAGE_BRIEF_SIZE; - - /*w lock index*/ - start_index++; - if (start_index == FLOW_SIZE) { - start_index = 0; - buf_curr = flow_buf; - } - } - - return strlen(buf); -} - -static ssize_t theia_powerkey_report_proc_read(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - char stages[STAGE_TOTAL_SIZE] = {0}; - int stages_len; - - POWER_MONITOR_DEBUG_PRINTK("enter theia_powerkey_report_proc_read %d %d", count, *off); - - stages_len = get_pwkey_stages(stages); - - return simple_read_from_buffer(buf, count, off, stages, stages_len); -} - -void record_stage(const char *buf) -{ - if (!timer_started) { - return; - } - - POWER_MONITOR_DEBUG_PRINTK("%s: buf:%s\n", __func__, buf); - - memset(flow_buf_curr, 0, STAGE_BRIEF_SIZE); - snprintf(flow_buf_curr, STAGE_BRIEF_SIZE, buf); - flow_buf_curr+=STAGE_BRIEF_SIZE; - - /*w lock index*/ - flow_index++; - if (flow_index == FLOW_SIZE) { - flow_index = 0; - flow_buf_curr = flow_buf; - } - /*w lock index*/ - - /*flow_buf_curr+=STAGE_BRIEF_SIZE;*/ -} - -static ssize_t theia_powerkey_report_proc_write(struct file *file, const char __user *buf, - size_t count, loff_t *off) -{ - char buffer[STAGE_BRIEF_SIZE] = {0}; - - POWER_MONITOR_DEBUG_PRINTK("%s: read proc input called.\n", __func__); - - if(g_black_data.status == BLACK_STATUS_INIT || g_black_data.status == BLACK_STATUS_INIT_FAIL) { - POWER_MONITOR_DEBUG_PRINTK("%s init not finish: status = %d\n", __func__, g_black_data.status); - return count; - } - - if (count >= STAGE_BRIEF_SIZE) { - count = STAGE_BRIEF_SIZE - 1; - } - - if (copy_from_user(buffer, buf, count)) { - POWER_MONITOR_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - record_stage(buffer); - return count; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static int theia_powerkey_report_proc_show(struct seq_file *seq_file, void *data) { - seq_printf(seq_file, "%s called\n", __func__); - return 0; - } - - static int theia_powerkey_report_proc_open(struct inode *inode, struct file *file) { - return single_open(file, theia_powerkey_report_proc_show, NULL); - } -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static const struct proc_ops theia_powerkey_report_proc_fops = { - .proc_open = theia_powerkey_report_proc_open, - .proc_read = theia_powerkey_report_proc_read, - .proc_write = theia_powerkey_report_proc_write, - .proc_lseek = seq_lseek, - .proc_release = single_release, - }; -#else - struct file_operations theia_powerkey_report_proc_fops = { - .read = theia_powerkey_report_proc_read, - .write = theia_powerkey_report_proc_write, - }; -#endif - - - -static ssize_t theia_powerkey_test_node_proc_read(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - return 0; -} - -static ssize_t theia_powerkey_test_node_proc_write(struct file *file, const char __user *buf, - size_t count, loff_t *off) -{ - char buffer[128] = {0}; - if (count > 127 || copy_from_user(buffer, buf, count)) { - POWER_MONITOR_DEBUG_PRINTK("%s: read proc input error.\n", __func__); - return count; - } - - POWER_MONITOR_DEBUG_PRINTK("theia_powerkey_test_node_proc_write buffer:%s\n", buffer); - if (!strncmp(buffer, "test_d_block\n", 13)) { - block_thread = get_current(); - POWER_MONITOR_DEBUG_PRINTK("theia_powerkey_test_node_proc_write set TASK_UNINTERRUPTIBLE block_thread pid:%d\n", block_thread->pid); - set_current_state(TASK_UNINTERRUPTIBLE); - schedule(); - POWER_MONITOR_DEBUG_PRINTK("theia_powerkey_test_node_proc_write set TASK_UNINTERRUPTIBLE, after schedule\n"); - block_thread = NULL; - } else if (!strncmp(buffer, "test_d_unblock\n", 15)) { - if (block_thread != NULL) { - POWER_MONITOR_DEBUG_PRINTK("theia_powerkey_test_node_proc_write call wake_up_process pid:%d\n", block_thread->pid); - wake_up_process(block_thread); - } - } else if (!strncmp(buffer, "test_d_unblock_with_kill\n", 25)) { -/* - if (block_thread != NULL) { - POWER_MONITOR_DEBUG_PRINTK("theia_powerkey_test_node_proc_write call wake_up_process with kill pid:%d\n", block_thread->pid); - block_thread->flags |= PF_KILLING; - do_send_sig_info(SIGKILL, SEND_SIG_FORCED, block_thread, true); - wake_up_process(block_thread); - } -*/ - } else if (!strncmp(buffer, "test_blackscreen_dcs\n", 21)) { - send_black_screen_dcs_msg(); - } else if (!strncmp(buffer, "test_kevent\n", 12)) { - SendTheiaKevent(THEIA_KEVENT_TYPE_COMMON_STRING, "logTagTest", "eventIDTest", "Powerkey test kevent!"); - } - - return count; -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static int theia_powerkey_test_node_proc_open(struct inode *inode, struct file *file) { - int ret; - - ret = nonseekable_open(inode, file); - if (unlikely(ret)) - return ret; - file->private_data = NULL; - - return 0; - } -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) - static const struct proc_ops theia_powerkey_test_node_proc_fops = { - .proc_open = theia_powerkey_test_node_proc_open, - .proc_read = theia_powerkey_test_node_proc_read, - .proc_write = theia_powerkey_test_node_proc_write, - }; - -#else - struct file_operations theia_powerkey_test_node_proc_fops = { - .read = theia_powerkey_test_node_proc_read, - .write = theia_powerkey_test_node_proc_write, - }; -#endif - -void theia_pwk_stage_start(char *reason) -{ - POWER_MONITOR_DEBUG_PRINTK("theia_pwk_stage_start start %x: %x %x flow_buf\n", flow_buf, flow_buf_curr, flow_index); - stage_start = flow_index; - timer_started = true; - record_stage(reason); -} - -void theia_pwk_stage_end(char *reason) -{ - if (timer_started) { - POWER_MONITOR_DEBUG_PRINTK("theia_pwk_stage_end, reason:%s\n", reason); - record_stage(reason); - timer_started = false; - } -} - - -static bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - if(!strncmp(t->comm, "main", 4) && (tcred->uid.val == 0) && - (t->parent != 0 && !strncmp(t->parent->comm, "init", 4))) { - return true; - } else { - return false; - } - return false; -} -extern void touch_all_softlockup_watchdogs(void); - -static void show_coretask_state(void) -{ - struct task_struct *g, *p; - - rcu_read_lock(); - for_each_process_thread(g, p) { - if (is_zygote_process(p) || !strncmp(p->comm, "system_server", TASK_COMM_LEN) - || !strncmp(p->comm, "surfaceflinger", TASK_COMM_LEN)) { -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - touch_nmi_watchdog(); -#endif - sched_show_task(p); - } - } - -#if IS_BUILTIN(CONFIG_OPLUS_FEATURE_THEIA) - touch_all_softlockup_watchdogs(); -#endif - rcu_read_unlock(); -} - -void doPanic(void) -{ - /*1.meminfo*/ - /*2. show all D task*/ -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) - handle_sysrq('w'); -#else - show_state_filter(TASK_UNINTERRUPTIBLE); -#endif - /*3. show system_server zoygot surfacefliger state*/ - show_coretask_state(); - /*4.current cpu registers :skip for minidump*/ - panic("bright screen detected, force panic"); -} - -int __init powerkey_monitor_init(void) -{ - POWER_MONITOR_DEBUG_PRINTK("powerkey_monitor_init\n"); - - theia_kevent_module_init(); - bright_screen_check_init(); - black_screen_check_init(); - - /*a node for param setup*/ - proc_create("pwkMonitorParam", S_IRWXUGO, NULL, &powerkey_monitor_param_proc_fops); - - /*a node for normal stage record*/ - proc_create("theiaPwkReport", S_IRWXUGO, NULL, &theia_powerkey_report_proc_fops); - - /*a node fo test*/ - /*proc_create("theiaPwkTestNode", S_IRWXUGO, NULL, &theia_powerkey_test_node_proc_fops);*/ - - flow_buf = vmalloc(STAGE_BRIEF_SIZE*FLOW_SIZE); - if (!flow_buf) { - return -ENOMEM; - } - memset(flow_buf, 0, STAGE_BRIEF_SIZE*FLOW_SIZE); - flow_buf_curr = flow_buf; - - return 0; -} - -void __exit powerkey_monitor_exit(void) -{ - POWER_MONITOR_DEBUG_PRINTK("powerkey_monitor_exit\n"); - - black_screen_exit(); - bright_screen_exit(); - theia_kevent_module_exit(); - - if (!flow_buf) { - vfree(flow_buf); - flow_buf = NULL; - } -} - -late_initcall(powerkey_monitor_init); -module_exit(powerkey_monitor_exit); - -MODULE_AUTHOR("jianping.zheng "); -MODULE_DESCRIPTION("powerkey_monitor@1.0"); -MODULE_VERSION("1.0"); -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); -#endif -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/powerkey_monitor.h b/drivers/soc/oplus/system/theia/powerkey_monitor.h deleted file mode 100755 index b9dc06877961..000000000000 --- a/drivers/soc/oplus/system/theia/powerkey_monitor.h +++ /dev/null @@ -1,113 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Copyright (C) 2018-2020 Oplus. All rights reserved. -*/ -#ifndef __POWERKEY_MONITOR_H_ -#define __POWERKEY_MONITOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_ARM -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if IS_MODULE(CONFIG_OPLUS_FEATURE_THEIA) -#include -#endif - -#if IS_ENABLED(CONFIG_OPLUS_MTK_DRM_GKI_NOTIFY) -#include "../../drivers/gpu/drm/mediatek/mediatek_v2/mtk_panel_ext.h" -#include "../../drivers/gpu/drm/mediatek/mediatek_v2/mtk_disp_notify.h" -#endif - -#ifdef CONFIG_DRM_MSM -#include -#endif /*CONFIG_DRM_MSM*/ - -#include - -#include -#include - -#define PWKKEY_DCS_TAG "CriticalLog" -#define PWKKEY_DCS_EVENTID "Theia" -#define PWKKEY_BLACK_SCREEN_DCS_LOGTYPE "black_screen_monitor" -#define PWKKEY_BRIGHT_SCREEN_DCS_LOGTYPE "bright_screen_monitor" - -#define BRIGHT_STATUS_INIT 1 -#define BRIGHT_STATUS_INIT_FAIL 2 -#define BRIGHT_STATUS_INIT_SUCCEES 3 -#define BRIGHT_STATUS_CHECK_ENABLE 4 -#define BRIGHT_STATUS_CHECK_DISABLE 5 -#define BRIGHT_STATUS_CHECK_DEBUG 6 - -struct bright_data { - int is_panic; - int status; - int blank; - int get_log; - unsigned int timeout_ms; - unsigned int error_count; - struct notifier_block fb_notif; - struct timer_list timer; - struct work_struct error_happen_work; - char error_id[64]; /*format: systemserver_pid:time_sec:time_usec*/ -}; - -#define BLACK_STATUS_INIT 1 -#define BLACK_STATUS_INIT_FAIL 2 -#define BLACK_STATUS_INIT_SUCCEES 3 -#define BLACK_STATUS_CHECK_ENABLE 4 -#define BLACK_STATUS_CHECK_DISABLE 5 -#define BLACK_STATUS_CHECK_DEBUG 6 - -struct black_data { - int is_panic; - int status; - int blank; - int get_log; - unsigned int timeout_ms; - unsigned int error_count; - struct notifier_block fb_notif; - struct timer_list timer; - struct work_struct error_happen_work; - char error_id[64]; /*format: systemserver_pid:time_sec:time_usec*/ -}; - -extern struct bright_data g_bright_data; -extern struct black_data g_black_data; - -void bright_screen_check_init(void); -void bright_screen_exit(void); -void black_screen_check_init(void); -void black_screen_exit(void); -void theia_pwk_stage_start(char *reason); -void theia_pwk_stage_end(char *reason); -void send_black_screen_dcs_msg(void); -void send_bright_screen_dcs_msg(void); -/*bool is_powerkey_check_valid(void);*/ -ssize_t get_last_pwkey_stage(char *buf); -ssize_t get_pwkey_stages(char *buf); -void record_stage(const char *buf); -/*bool is_valid_systemserver_pid(int pid);*/ -int get_systemserver_pid(void); -void doPanic(void); -#endif /*endif*/ diff --git a/drivers/soc/oplus/system/theia/theia_kevent_kernel.c b/drivers/soc/oplus/system/theia/theia_kevent_kernel.c deleted file mode 100755 index 7744d26f4ded..000000000000 --- a/drivers/soc/oplus/system/theia/theia_kevent_kernel.c +++ /dev/null @@ -1,216 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "theia_kevent_kernel.h" - -/*should match with oplus_theia/include/TheiaKeventThread.h define -*if netlink.h not define, we define here -*/ -#ifndef OPLUS_NETLINK_THEIA_KEVENT -#define OPLUS_NETLINK_THEIA_KEVENT 29 -#endif - -static struct sock *theia_netlink_fd = NULL; -static u32 theia_kevent_pid = -1; -static DEFINE_MUTEX(theia_kevent_mutex); - -#define THEIA_KEVENT_DEBUG_PRINTK(a, arg...)\ - do {\ - printk("[theia_kevent]: " a, ##arg);\ - }while(0) - -/* kernel receive message from userspace */ -void theia_kevent_receive_from_user(struct sk_buff *__skbbr) { - struct sk_buff *skbu = NULL; - struct nlmsghdr *nlh = NULL; - char* pdata = NULL; - uint32_t size = 0x0; - - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_receive_from_user called\n"); - - skbu = skb_get(__skbbr); - - if (skbu && skbu->len >= sizeof(struct nlmsghdr)) { - nlh = (struct nlmsghdr *)skbu->data; - if((nlh->nlmsg_len >= sizeof(struct nlmsghdr)) - && (__skbbr->len >= nlh->nlmsg_len)){ - size = (nlh->nlmsg_len - NLMSG_LENGTH(0)); - if (size > 0) { - pdata = (char*)kmalloc(size + 0x10, GFP_KERNEL); - if (pdata) { - memcpy(pdata, NLMSG_DATA(nlh), size); - pdata[size] = 0x0; - - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_receive_from_user, type:%d pdata:%s\n", nlh->nlmsg_type, pdata); - if ((nlh->nlmsg_type == THEIA_KEVENT_CONNECT) && (!strcmp(pdata, THEIA_KEVENT_MODULE))) { - theia_kevent_pid = nlh->nlmsg_pid; - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_receive_from_user, theia_kevent_pid is %u ..\n", theia_kevent_pid); - } - } - } - } - } - - if (pdata) { - kfree(pdata); - } - - if (skbu) { - kfree_skb(skbu); - } -} - -/* kernel send message to userspace */ -int theia_kevent_send_to_user(struct theia_kevent_packet *userinfo) -{ - int ret, size, size_use; - unsigned int o_tail; - struct sk_buff *skbuff; - struct nlmsghdr *nlh; - struct theia_kevent_packet *packet; - - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user called\n"); - - if (theia_kevent_pid == -1) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user theia_kevent_pid is -1, return\n"); - return -1; - } - - /* protect payload too long problem*/ - if (userinfo->len >= MAX_PAYLOAD_DATASIZE) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user payload_length out of range\n"); - return -1; - } - - size = NLMSG_SPACE(sizeof(struct theia_kevent_packet) + userinfo->len); - - /*allocate new buffer cache */ - skbuff = alloc_skb(size, GFP_ATOMIC); - - if (skbuff == NULL) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user skbuff alloc_skb failed\n"); - return -1; - } - - /* fill in the data structure */ - nlh = nlmsg_put(skbuff, 0, 0, 0, size - sizeof(*nlh), 0); - - if (nlh == NULL) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user nlmsg_put failaure\n"); - nlmsg_free(skbuff); - return -1; - } - - o_tail = skbuff->tail; - size_use = sizeof(struct theia_kevent_packet) + userinfo->len; - packet = NLMSG_DATA(nlh); - memset(packet, 0, size_use); - memcpy(packet, userinfo, size_use); - nlh->nlmsg_len = skbuff->tail - o_tail; - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)) - NETLINK_CB(skbuff).pid = 0; -#else - NETLINK_CB(skbuff).portid = 0; -#endif - NETLINK_CB(skbuff).dst_group = 0; - - ret = netlink_unicast(theia_netlink_fd, skbuff, theia_kevent_pid, MSG_DONTWAIT); - - if (ret < 0) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent_send_to_user send fail=%d, theia_kevent_pid=%d \n", - ret, theia_kevent_pid); - return -1; - } - - return 0; -} - -/*send msg to userspace*/ -void SendTheiaKevent(int type, char *log_tag, char *event_id, char *payload) -{ - struct theia_kevent_packet *user_msg_info; - void *buffer = NULL; - int len, size; - - THEIA_KEVENT_DEBUG_PRINTK("SendTheiaKevent begin\n"); - - mutex_lock(&theia_kevent_mutex); - - /*alloc memory*/ - len = strlen(payload); - size = sizeof(struct theia_kevent_packet) + len + 1; - buffer = kmalloc(size, GFP_ATOMIC); - memset(buffer, 0, size); - user_msg_info = (struct theia_kevent_packet *)buffer; - - /*setup type*/ - user_msg_info->type = type; - - /*setup tag*/ - memcpy(user_msg_info->tag, log_tag, strlen(log_tag) + 1); - - /*setup event id*/ - memcpy(user_msg_info->event_id, event_id, strlen(event_id) + 1); - - /*setup payload*/ - user_msg_info->len = len + 1; - memcpy(user_msg_info->data, payload, len + 1); - - /*send to userspace*/ - theia_kevent_send_to_user(user_msg_info); - THEIA_KEVENT_DEBUG_PRINTK("SendTheiaKevent, theia_kevent_send_to_user user_msg_info->data:%s\n", - user_msg_info->data); - - kfree(buffer); - mutex_unlock(&theia_kevent_mutex); - return; -} - -void SendDcsTheiaKevent(char *log_tag, char *event_id, char *logmap) -{ - SendTheiaKevent(THEIA_KEVENT_TYPE_DCS_MSG, log_tag, event_id, logmap); -} - -int theia_kevent_module_init(void) -{ - struct netlink_kernel_cfg cfg = { - .groups = 0x0, - .input = theia_kevent_receive_from_user, - }; - - theia_netlink_fd = netlink_kernel_create(&init_net, OPLUS_NETLINK_THEIA_KEVENT, - &cfg); - - if (!theia_netlink_fd) { - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent can not create a socket\n"); - return -1; - } - - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent ok\n"); - return 0; -} - -void theia_kevent_module_exit(void) -{ - sock_release(theia_netlink_fd->sk_socket); - THEIA_KEVENT_DEBUG_PRINTK("theia_kevent exit\n"); -} -MODULE_LICENSE("GPL v2"); diff --git a/drivers/soc/oplus/system/theia/theia_kevent_kernel.h b/drivers/soc/oplus/system/theia/theia_kevent_kernel.h deleted file mode 100755 index 5eaed8e951a1..000000000000 --- a/drivers/soc/oplus/system/theia/theia_kevent_kernel.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Copyright (C) 2018-2020 Oplus. All rights reserved. -*/ -#ifndef __THEIA_KEVENT_KERNEL_H_ -#define __THEIA_KEVENT_KERNEL_H_ - -#define MAX_PAYLOAD_TAG_SIZE 128 -#define MAX_PAYLOAD_EVENTID_SIZE 128 -#define MAX_PAYLOAD_DATASIZE 1024 -#define THEIA_KEVENT_CONNECT 0x01 - -/* -THEIA_KEVENT_TYPE_COMMON_STRING: -theia_kevent_packet.data: string -*/ -#define THEIA_KEVENT_TYPE_COMMON_STRING 1 - -/* -THEIA_KEVENT_TYPE_DCS_MSG -theia_kevent_packet.tag: dcs tag -theia_kevent_packet.event_id: dcs event id -theia_kevent_packet.data: is logmap format: logmap{key1:value1;key2:value2;key3:value3 ...} -*/ -#define THEIA_KEVENT_TYPE_DCS_MSG 2 - -#define THEIA_KEVENT_MODULE "theia_kevent" - -struct theia_kevent_packet { - int type; /* 1: common string 2: dcs message*/ - char tag[MAX_PAYLOAD_TAG_SIZE]; /* tag */ - char event_id[MAX_PAYLOAD_EVENTID_SIZE]; /* eventID */ - size_t len; /* Length of packet data */ - unsigned char data[0]; /* Optional packet data */ -} __attribute__((packed)); - -int theia_kevent_module_init(void); -void theia_kevent_module_exit(void); -void SendTheiaKevent(int type, char *log_tag, char *event_id, char *payload); -void SendDcsTheiaKevent(char *log_tag, char *event_id, char *logmap); - -#endif /* THEIA_KEVENT_KERNEL_H_ */ diff --git a/drivers/soc/oplus/system/uboot_log/Kconfig b/drivers/soc/oplus/system/uboot_log/Kconfig deleted file mode 100755 index 0357951a9d06..000000000000 --- a/drivers/soc/oplus/system/uboot_log/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -config OPLUS_FEATURE_UBOOT_LOG - bool "oplus system uboot log" - default n - depends on OPLUS_SYSTEM_KERNEL - help - define this config to enable QCOM platform uboot log . - diff --git a/drivers/soc/oplus/system/uboot_log/Makefile b/drivers/soc/oplus/system/uboot_log/Makefile deleted file mode 100755 index b5fb8b62d9af..000000000000 --- a/drivers/soc/oplus/system/uboot_log/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. -obj-$(CONFIG_OPLUS_FEATURE_UBOOT_LOG) += uboot_log.o - diff --git a/drivers/soc/oplus/system/uboot_log/uboot_log.c b/drivers/soc/oplus/system/uboot_log/uboot_log.c deleted file mode 100755 index 8d4252f7ea27..000000000000 --- a/drivers/soc/oplus/system/uboot_log/uboot_log.c +++ /dev/null @@ -1,265 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -/*************************************************************** -** File : uboot_log.c -** Description : BSP uboot_log back up xbl uefi kernel boot log , cat /proc/boot_dmesg -** Version : 1.0 -******************************************************************/ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include - -#include - -#define __KBOOT_LOG_OFFSET 0 -#define LINE_MAX_SIZE 1024 - -static u32 xbl_uefi_logoffset; - -/* record kernel boot buffer */ -static char *kboot_log_buf = NULL; -static u32 kboot_log_buf_len; -static size_t total_size = 0; - -static struct kmsg_dumper kboot_dumper; -static struct task_struct *ubootback_thread = NULL; - - -/* record xbl uefi boot buffer */ -static char *uboot_log_buf = NULL; -static u32 uboot_log_buf_len; - - - - -/* - * init uboot/kboot log buffer addr/size - */ -static int uboot_kboot_buffer_init() -{ - struct reserved_mem *r_mem = NULL; - struct device_node *reserved_memory, *kboot_uboot_logmemory; - - reserved_memory = of_find_node_by_path("/reserved-memory"); - - if (!reserved_memory) { - pr_err("No reserved-memory information found in DT\n"); - return -EINVAL; - } - - kboot_uboot_logmemory = of_get_child_by_name(reserved_memory, - "kboot_uboot_logmem"); - - if (!kboot_uboot_logmemory) { - pr_err("Can not find kboot_uboot_logmemory node in reserved-memory\n"); - return -EINVAL; - } - - r_mem = of_reserved_mem_lookup(kboot_uboot_logmemory); - - if (!r_mem) { - pr_err("failed to acquire memory region\n"); - return -EINVAL; - } - - if (of_property_read_u32(kboot_uboot_logmemory, "xbluefi-offset", - &xbl_uefi_logoffset)) { - pr_err("failed to acquire kboot_uboot_logmemory log offset\n"); - return -EINVAL; - } - - pr_debug("xbl_uefi_memory:base:%llx, size:%llx, xbl_uefi_logoffset:%x\n", - r_mem->base, r_mem->size, xbl_uefi_logoffset); - - if ((xbl_uefi_logoffset + SERIAL_BUFFER_SIZE) > r_mem->size) { - WARN(1, "xbl_uefi logbuf may be out of bounds\n"); - return -ENOMEM; - } - - uboot_reserved_remap = memremap(r_mem->base, r_mem->size, MEMREMAP_WB); - - if (IS_ERR_OR_NULL(uboot_reserved_remap)) { - pr_err("failed to remap uefi memory \n"); - uboot_reserved_remap = NULL; - return -EINVAL; - } - - uboot_base = r_mem->base; - uboot_size = r_mem->size; - - uboot_log_buf_len = r_mem->size - xbl_uefi_logoffset; - kboot_log_buf_len = xbl_uefi_logoffset; - uboot_log_buf = uboot_reserved_remap + xbl_uefi_logoffset; - kboot_log_buf = uboot_reserved_remap + __KBOOT_LOG_OFFSET; - - return 0; -} - - - - -/* - * backup and show kernel boot log - */ -static int kboot_seq_read(struct seq_file *s, void *v) -{ - int i = 0; - uboot_log_buf[uboot_log_buf_len - 1] = '\0'; - seq_printf(s, "xbl_uefi boot log begin: \n"); - - while (i < uboot_log_buf_len - 1) { - while (!uboot_log_buf[i] && i < uboot_log_buf_len - 1) { - i++; - } - - seq_printf(s, "%s\n", uboot_log_buf + i); - - while (uboot_log_buf[i] && i < uboot_log_buf_len - 1) { - i++; - } - } - - - i = 0; - kboot_log_buf[kboot_log_buf_len - 1] = '\0'; - seq_printf(s, "kernel boot log begin: \n"); - - while (i < total_size) { - /* find valid data to print out */ - while (!kboot_log_buf[i] && i < total_size) { - i++; - } - - seq_printf(s, "%s\n", kboot_log_buf + i); - - /* find invalid data to avoild interruption by '\0' */ - while (kboot_log_buf[i] && i < total_size) { - i++; - } - } - - return 0; -} - - -static int kboot_file_open(struct inode *inode, struct file *file) -{ - return single_open(file, &kboot_seq_read, PDE_DATA(inode)); -} - -const struct file_operations kboot_fops = { - .owner = THIS_MODULE, - .open = kboot_file_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -/* - * Dont printk any log int this thread - */ -int ubootback_thread_fn(void *data) -{ - size_t line_len = 0; - u32 idx = 0; - u64 seq = 0; - - kboot_dumper.active = true; - - while (kboot_log_buf_len > total_size + 2 * LINE_MAX_SIZE) { - kmsg_dump_rewind(&kboot_dumper); - kboot_dumper.cur_seq = seq; - kboot_dumper.cur_idx = idx; - - if (back_kmsg_dump_get_buffer(&kboot_dumper, true, kboot_log_buf + total_size, - kboot_log_buf_len - total_size, &line_len)) { - total_size += line_len; - line_len = 0; - } - - seq = kboot_dumper.cur_seq; - idx = kboot_dumper.cur_idx; - msleep(10 * 1000); - } - - return 0; -} - -static int __init kernel_uboot_log_init() -{ - struct proc_dir_entry *pEntry = NULL; - - memset(kboot_log_buf, 0, kboot_log_buf_len); - pEntry = proc_create_data("boot_dmesg", 0444, NULL, &kboot_fops, NULL); - - if (!pEntry) { - pr_err("failed to make boot_dmesg proc node\n"); - return -EINVAL; - } - - ubootback_thread = kthread_run(ubootback_thread_fn, NULL, "ubootback_thread"); - - if (IS_ERR(ubootback_thread)) { - pr_err("Creating kbootback_thread failed!\n"); - return -EINVAL; - } - - return 0; -} - -/* - * Add for dump kernel bootlog for minidump - */ -static void __init register_boot_log_buf(void) -{ - struct md_region md_entry = {}; - - /*Register ubootlog to minidump, first idx would be from bss section */ - strlcpy(md_entry.name, "UBOOTLOG", sizeof(md_entry.name)); - md_entry.virt_addr = (uintptr_t) uboot_reserved_remap; - md_entry.phys_addr = uboot_base; - md_entry.size = uboot_size; - - if (msm_minidump_add_region(&md_entry)) { - pr_err("Failed to add UBOOTLOG in Minidump\n"); - } - - return; -} - -static int __init oplus_uboot_device_init(void) -{ - if (!uboot_kboot_buffer_init()) { - register_boot_log_buf(); - kernel_uboot_log_init(); - } - - return 0; -} - - -late_initcall(oplus_uboot_device_init); diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig index 56b027516e3a..01edd136d77c 100755 --- a/drivers/staging/android/Kconfig +++ b/drivers/staging/android/Kconfig @@ -89,15 +89,6 @@ config MTK_ENABLE_AGO Do not use this options in Kernel directly. this is a group kernel setting of AGO - -#ifdef OPLUS_FEATURE_HANS_FREEZE -#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -config OPLUS_HANS - bool "HANS kernel and HANS native communication channel" - default n - ---help--- - Key events (signal/network package/binder) report to HAS native. -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ source "drivers/staging/android/ion/Kconfig" diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile index ca86ad16670a..596d63c6c7df 100755 --- a/drivers/staging/android/Makefile +++ b/drivers/staging/android/Makefile @@ -6,8 +6,3 @@ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_DEBUG_KINFO) += debug_kinfo.o obj-$(CONFIG_ANDROID_VSOC) += vsoc.o obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o -#ifdef OPLUS_FEATURE_HANS_FREEZE -#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -obj-$(CONFIG_OPLUS_HANS) += hans.o -obj-$(CONFIG_OPLUS_HANS) += hans_netfilter.o -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ diff --git a/drivers/staging/android/hans.c b/drivers/staging/android/hans.c deleted file mode 100755 index 792cf1f40086..000000000000 --- a/drivers/staging/android/hans.c +++ /dev/null @@ -1,196 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, OPPO Mobile Comm Corp., Ltd. -** File: hans.c -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2020/05/27 1.1 OPLUS_FEATURE_HANS_FREEZE -****************************************************************/ - -#include -#include -#include -#include -#include -#include - -#define NETLINK_PORT_HANS (0x15356) - -static struct sock *sock_handle = NULL; -static atomic_t hans_deamon_port; - -/* - * netlink report function to tell HANS native deamon unfreeze process info - * if the parameters is empty, fill it with (pid/uid with -1) - */ -int hans_report(enum message_type type, int caller_pid, int caller_uid, int target_pid, int target_uid, const char *rpc_name, int code) -{ - int len = 0; - int ret = 0; - struct hans_message *data = NULL; - struct sk_buff *skb = NULL; - struct nlmsghdr *nlh = NULL; - - if (atomic_read(&hans_deamon_port) == -1) { - pr_err("%s: hans_deamon_port invalid!\n", __func__); - return HANS_ERROR; - } - - if (sock_handle == NULL) { - pr_err("%s: sock_handle invalid!\n", __func__); - return HANS_ERROR; - } - - if (type >= TYPE_MAX) { - pr_err("%s: type = %d invalid!\n", __func__, type); - return HANS_ERROR; - } - - len = sizeof(struct hans_message); - skb = nlmsg_new(len, GFP_ATOMIC); - if (skb == NULL) { - pr_err("%s: type =%d, nlmsg_new failed!\n", __func__, type); - return HANS_ERROR; - } - - nlh = nlmsg_put(skb, 0, 0, 0, len, 0); - if (nlh == NULL) { - pr_err("%s: type =%d, nlmsg_put failed!\n", __func__, type); - kfree_skb(skb); - return HANS_ERROR; - } - - data = nlmsg_data(nlh); - if(data == NULL) { - pr_err("%s: type =%d, nlmsg_data failed!\n", __func__, type); - return HANS_ERROR; - } - data->type = type; - data->port = NETLINK_PORT_HANS; - data->caller_pid = caller_pid; - data->caller_uid = caller_uid; - data->target_pid = target_pid; - data->target_uid = target_uid; - data->pkg_cmd = -1; /*invalid package cmd*/ - data->code = code; - strlcpy(data->rpc_name, rpc_name, INTERFACETOKEN_BUFF_SIZE); - nlmsg_end(skb, nlh); - - if ((ret = nlmsg_unicast(sock_handle, skb, (u32)atomic_read(&hans_deamon_port))) < 0) { - pr_err("%s: nlmsg_unicast failed! err = %d\n", __func__ , ret); - return HANS_ERROR; - } - - return HANS_NOERROR; -} - -/*HANS kernel module handle the message from HANS native deamon*/ -static void hans_handler(struct sk_buff *skb) -{ - struct hans_message *data = NULL; - struct nlmsghdr *nlh = NULL; - unsigned int len = 0; - int uid = -1; - - if (!skb) { - pr_err("%s: recv skb NULL!\n", __func__); - return; - } - - /*safety check*/ - uid = (*NETLINK_CREDS(skb)).uid.val; - /*only allow native deamon talk with HANS kernel.*/ - if (uid != 1000) { - pr_err("%s: uid: %d, permission denied\n", __func__, uid); - return; - } - - if (skb->len >= NLMSG_SPACE(0)) { - nlh = nlmsg_hdr(skb); - len = NLMSG_PAYLOAD(nlh, 0); - data = (struct hans_message *)NLMSG_DATA(nlh); - - if (len < sizeof(struct hans_message)) { - pr_err("%s: hans_message len check faied! len = %d min_expected_len = %lu!\n", __func__, len, sizeof(struct hans_message)); - return; - } - - if (data->port < 0) { - pr_err("%s: portid = %d invalid!\n", __func__, data->port); - return; - } - if (data->type >= TYPE_MAX) { - pr_err("%s: type = %d invalid!\n", __func__, data->type); - return; - } - if (atomic_read(&hans_deamon_port) == -1 && data->type != LOOP_BACK) { - pr_err("%s: handshake not setup, type = %d!\n", __func__, data->type); - return; - } - - switch (data->type) { - case LOOP_BACK: /*Loop back message, only for native deamon and kernel handshake*/ - atomic_set(&hans_deamon_port, data->port); - hans_report(LOOP_BACK, -1, -1, -1, -1, "loop back", CPUCTL_VERSION); - printk(KERN_ERR "%s: --> LOOP_BACK, port = %d\n", __func__, data->port); - break; - case PKG: - printk(KERN_ERR "%s: --> PKG, uid = %d, pkg_cmd = %d\n", __func__, data->target_uid, data->pkg_cmd); - hans_network_cmd_parse(data->target_uid, data->pkg_cmd); - break; - case FROZEN_TRANS: - case CPUCTL_TRANS: - printk(KERN_ERR "%s: --> FROZEN_TRANS, uid = %d\n", __func__, data->target_uid); - hans_check_frozen_transcation(data->target_uid, data->type); - break; - - default: - pr_err("%s: hans_messag type invalid %d\n", __func__, data->type); - break; - } - } -} - -static int __init hans_core_init(void) -{ - struct netlink_kernel_cfg cfg = { - .input = hans_handler, - }; - - atomic_set(&hans_deamon_port, -1); - - sock_handle = netlink_kernel_create(&init_net, NETLINK_OPPO_HANS, &cfg); - if (sock_handle == NULL) { - pr_err("%s: create netlink socket failed!\n", __func__); - return HANS_ERROR; - } - - if (hans_netfilter_init() == HANS_ERROR) { - pr_err("%s: netfilter init failed!\n", __func__); - netlink_kernel_release(sock_handle); /*release socket*/ - return HANS_ERROR; - } - - printk(KERN_INFO "%s: -\n", __func__); - return HANS_NOERROR; -} - -static void __exit hans_core_exit(void) -{ - if (sock_handle) - netlink_kernel_release(sock_handle); - - hans_netfilter_deinit(); - printk(KERN_INFO "%s: -\n", __func__); -} - -module_init(hans_core_init); -module_exit(hans_core_exit); - -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/android/hans_netfilter.c b/drivers/staging/android/hans_netfilter.c deleted file mode 100755 index 2bb7eda5991b..000000000000 --- a/drivers/staging/android/hans_netfilter.c +++ /dev/null @@ -1,223 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, OPPO Mobile Comm Corp., Ltd. -** File: hans_netfilter.c -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2019/09/23 1.1 OPLUS_FEATURE_HANS_FREEZE -****************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#define MAX_SLOT (100) -static uid_t monitored_uids[MAX_SLOT]; -spinlock_t uids_lock; - -static inline uid_t sock2uid(struct sock *sk) -{ - if(sk && sk->sk_socket) - return SOCK_INODE(sk->sk_socket)->i_uid.val; - else - return 0; -} - -/*Add netlink monitor uid. When the monitored UID has incoming network package, tell HANS native deamon*/ -static void hans_add_monitored_uid(uid_t target_uid) -{ - int i = 0; - int fisrt_empty_slot = MAX_SLOT; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - for (i = 0; i < MAX_SLOT; i++) { - if (monitored_uids[i] == target_uid) { /*already in the monitored array*/ - spin_unlock_irqrestore(&uids_lock, flags); - /*printk(KERN_WARNING "%s: uid = %d already in array\n", __func__, target_uid);*/ - return; - } else if (monitored_uids[i] == 0 && fisrt_empty_slot == MAX_SLOT) { /*first empty slot for monitoring uid*/ - fisrt_empty_slot = i; - } - } - - if (fisrt_empty_slot >= MAX_SLOT) { - spin_unlock_irqrestore(&uids_lock, flags); - pr_err("%s: monitored uid = %d add failed!\n", __func__, target_uid); - return; - } - monitored_uids[fisrt_empty_slot] = target_uid; - spin_unlock_irqrestore(&uids_lock, flags); -} - -static void hans_remove_monitored_uid(uid_t target_uid) -{ - int i = 0; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - for (i = 0; i < MAX_SLOT; i++) { - if (monitored_uids[i] == target_uid) { - monitored_uids[i] = 0; - spin_unlock_irqrestore(&uids_lock, flags); - return; - } - } - spin_unlock_irqrestore(&uids_lock, flags); - printk(KERN_WARNING "%s: uid = %d remove uid not found\n", __func__, target_uid); -} - -static void hans_remove_all_monitored_uid(void) -{ - int i; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - for (i = 0; i < MAX_SLOT; i++) { - monitored_uids[i] = 0; - } - spin_unlock_irqrestore(&uids_lock, flags); -} - -static bool hans_find_remove_monitored_uid(uid_t target_uid) -{ - bool found = false; - int i = 0; - unsigned long flags; - - spin_lock_irqsave(&uids_lock, flags); - for (i = 0; i < MAX_SLOT; i++) { - if (unlikely(monitored_uids[i] == target_uid)) { - found = true; - monitored_uids[i] = 0; - break; - } - } - spin_unlock_irqrestore(&uids_lock, flags); - - if (found) - printk(KERN_WARNING "%s: uid = %d found and removed\n", __func__, target_uid); - return found; -} - -void hans_network_cmd_parse(uid_t uid, enum pkg_cmd cmd) -{ - switch (cmd) { - case ADD_ONE_UID: - hans_add_monitored_uid(uid); - break; - case DEL_ONE_UID: - hans_remove_monitored_uid(uid); - break; - case DEL_ALL_UID: - hans_remove_all_monitored_uid(); - break; - default: - pr_err("%s: pkg_cmd type invalid %d\n", __func__, cmd); - break; - } -} - -/*Moniter the uid by netlink filter hook function.*/ -static unsigned int hans_nf_ipv4v6_in(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - struct sock *sk; - uid_t uid; - unsigned int thoff = 0; - unsigned short frag_off = 0; - bool found = false; - - if (ip_hdr(skb)->version == 4) { - if (ip_hdr(skb)->protocol != IPPROTO_TCP) - return NF_ACCEPT; -#if IS_ENABLED(CONFIG_IPV6) - } else if (ip_hdr(skb)->version == 6) { - if (ipv6_find_hdr(skb, &thoff, -1, &frag_off, NULL) != IPPROTO_TCP) - return NF_ACCEPT; -#endif - } else { - return NF_ACCEPT; - } - - sk = skb_to_full_sk(skb); - if (sk == NULL) return NF_ACCEPT; - if (!sk_fullsock(sk)) return NF_ACCEPT; - - uid = sock2uid(sk); - if (uid < MIN_USERAPP_UID) return NF_ACCEPT; - - /*Find the monitored UID and clear it from the monitor array*/ - found = hans_find_remove_monitored_uid(uid); - if (!found) - return NF_ACCEPT; - if (hans_report(PKG, -1, -1, -1, uid, "PKG", -1) != HANS_NOERROR) - pr_err("%s: hans_report PKG failed!, uid = %d\n", __func__, uid); - - return NF_ACCEPT; -} - -/*Only monitor input network packages*/ -static struct nf_hook_ops hans_nf_ops[] = { - { - .hook = hans_nf_ipv4v6_in, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_SELINUX_LAST + 1, - }, -#if IS_ENABLED(CONFIG_IPV6) - { - .hook = hans_nf_ipv4v6_in, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP6_PRI_SELINUX_LAST + 1, - }, -#endif -}; - -void hans_netfilter_deinit(void) -{ - struct net *net; - - rtnl_lock(); - for_each_net(net) { - nf_unregister_net_hooks(net, hans_nf_ops, ARRAY_SIZE(hans_nf_ops)); - } - rtnl_unlock(); -} - -int hans_netfilter_init(void) -{ - struct net *net = NULL; - int err = 0; - - spin_lock_init(&uids_lock); - hans_remove_all_monitored_uid(); - - rtnl_lock(); - for_each_net(net) { - err = nf_register_net_hooks(net, hans_nf_ops, ARRAY_SIZE(hans_nf_ops)); - if (err != 0) { - pr_err("%s: register netfilter hooks failed!\n", __func__); - break; - } - } - rtnl_unlock(); - - if (err != 0) { - hans_netfilter_deinit(); - return HANS_ERROR; - } - return HANS_NOERROR; -} diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index e78916aa33b6..9efd3b054403 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -23,5 +23,3 @@ ccflags-y += -DION_RUNTIME_DEBUGGER=1 else ccflags-y += -DION_RUNTIME_DEBUGGER=0 endif - -obj-$(CONFIG_OPLUS_HEALTHINFO) += oplus_ion/ diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index d58ecbbc8279..b5d14389a667 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -53,20 +53,12 @@ #include "mtk/mtk_ion.h" #include "mtk/ion_drv_priv.h" -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -#include -#endif #include #ifdef CONFIG_MTK_IOMMU_V2 #include #endif -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO -#include -#endif -#endif /* OPLUS_FEATURE_HEALTHINFO */ static atomic_long_t total_heap_bytes; @@ -257,11 +249,7 @@ static inline void ion_buffer_page_clean(struct page **page) *page = (struct page *)((unsigned long)(*page) & ~(1UL)); } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK -/* this function should only be called while dev->heap_lock is held */ -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ /* this function should only be called while dev->lock is held */ -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ static void ion_buffer_add(struct ion_device *dev, struct ion_buffer *buffer) { @@ -287,11 +275,7 @@ static void ion_buffer_add(struct ion_device *dev, rb_insert_color(&buffer->node, &dev->buffers); } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK -/* this function should only be called while dev->heap_lock is held */ -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ /* this function should only be called while dev->lock is held */ -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, struct ion_device *dev, unsigned long len, @@ -393,26 +377,11 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, sg_dma_len(sg) = sg->length; } exit: -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) - buffer->tsk = current->group_leader; - get_task_struct(buffer->tsk); - atomic64_add(buffer->size, &buffer->tsk->ions); -#endif -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) - buffer->jiffies = jiffies; -#endif mutex_lock(&dev->buffer_lock); ion_buffer_add(dev, buffer); mutex_unlock(&dev->buffer_lock); atomic_long_add(len, &total_heap_bytes); atomic_long_add(len, &heap->total_allocated); -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO - /* add ion total used account*/ - if (ion_cnt_enable) - atomic_long_add(buffer->size, &ion_total_size); -#endif -#endif /* OPLUS_FEATURE_HEALTHINFO */ return buffer; err1: @@ -428,21 +397,7 @@ void ion_buffer_destroy(struct ion_buffer *buffer) WARN_ON(1); buffer->heap->ops->unmap_kernel(buffer->heap, buffer); } -#ifdef OPLUS_FEATURE_HEALTHINFO -#ifdef CONFIG_OPLUS_HEALTHINFO - /* add ion total used account */ - if (ion_cnt_enable) - atomic_long_sub(buffer->size, &ion_total_size); -#endif -#endif /* OPLUS_FEATURE_HEALTHINFO */ atomic_long_sub(buffer->size, &buffer->heap->total_allocated); -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) - if (buffer->tsk) { - atomic64_sub(buffer->size, &buffer->tsk->ions); - put_task_struct(buffer->tsk); - buffer->tsk = NULL; - } -#endif /* OPLUS_FEATURE_MEMLEAK_DETECT && CONFIG_DUMP_TASKS_MEM */ buffer->heap->ops->free(buffer); vfree(buffer->pages); kfree(buffer); @@ -700,41 +655,6 @@ static int ion_handle_add(struct ion_client *client, struct ion_handle *handle) return 0; } -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -pid_t alloc_svc_tgid; - -static int chg_sched(struct task_struct *tsk, bool enter) -{ - int ret; - struct sched_param param = { .sched_priority = 0 }; - int policy = SCHED_NORMAL; - - if (!tsk) - return false; - - if (enter) { - policy = SCHED_FIFO; - param.sched_priority = 1; - } - - ret = sched_setscheduler_nocheck(tsk, policy, ¶m); - - if (ret) { - pr_info("alloc_svc %s failed %d. enter %d\n", - __func__, ret, enter); - } else { - - } - - return ret; -} - -/* TODO use task comm may not safe. */ -inline is_allocator_svc(struct task_struct *tsk) -{ - return (tsk->tgid == alloc_svc_tgid); -} -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ struct ion_handle *__ion_alloc(struct ion_client *client, size_t len, size_t align, unsigned int heap_id_mask, @@ -778,38 +698,22 @@ struct ion_handle *__ion_alloc(struct ion_client *client, size_t len, trace_ion_alloc_start(len, heap_id_mask, flags, client->dbg_name); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /*OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ plist_for_each_entry(heap, &dev->heaps, node) { /* if the caller didn't specify this heap id */ if (!((1 << heap->id) & heap_id_mask)) continue; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (is_allocator_svc(current)) - chg_sched(current, true); -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ buffer = ion_buffer_create(heap, dev, len, align, flags); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (is_allocator_svc(current)) - chg_sched(current, false); -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ if (!IS_ERR(buffer)) break; if (IS_ERR(buffer)) alloc_err_heap |= (1 << heap->id); } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /*OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ trace_ion_alloc_end(len, heap_id_mask, flags, ""); @@ -1110,11 +1014,7 @@ static int ion_debug_client_show(struct seq_file *s, void *unused) return -ENOMEM; } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) { -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!down_read_trylock(&dev->lock)) { -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ IONMSG("%s get lock fail\n", __func__); kfree(sizes); kfree(names); @@ -1124,11 +1024,7 @@ static int ion_debug_client_show(struct seq_file *s, void *unused) seq_printf(s, "ion_client 0x%pK dead, can't dump its buffers\n", client); IONMSG("%s:client invalid\n", __func__); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ kfree(sizes); kfree(names); return 0; @@ -1154,11 +1050,7 @@ static int ion_debug_client_show(struct seq_file *s, void *unused) buffer->handle_count, handle, buffer); } mutex_unlock(&client->lock); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ seq_puts(s, "----------------------------------------------------\n"); @@ -1266,20 +1158,12 @@ struct ion_client *ion_client_create(struct ion_device *dev, if (!client->name) goto err_free_client; -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_write(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ client->display_serial = ion_get_client_serial(&dev->clients, name); client->display_name = kasprintf( GFP_KERNEL, "%s-%d", name, client->display_serial); if (!client->display_name) { -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_write(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ goto err_free_client_name; } p = &dev->clients.rb_node; @@ -1307,11 +1191,7 @@ struct ion_client *ion_client_create(struct ion_device *dev, client->display_name); #endif -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_write(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return client; @@ -1365,11 +1245,7 @@ void ion_client_destroy(struct ion_client *client) __func__, (time_e_unlock - time_s), task_comm, pid); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_write(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (client->task) put_task_struct(client->task); rb_erase(&client->node, &dev->clients); @@ -1379,11 +1255,7 @@ void ion_client_destroy(struct ion_client *client) #if IS_ENABLED(CONFIG_PROC_FS) proc_remove(client->proc_root); #endif -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_write(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ time_e_lock = sched_clock(); if ((time_e_lock - time_s) > 100000000) // 100ms @@ -2231,11 +2103,7 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query) memset(&hdata, 0, sizeof(hdata)); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!buffer) { query->cnt = dev->heap_cnt; ret = 0; @@ -2265,11 +2133,7 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query) query->cnt = cnt; out: -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return ret; } @@ -2365,11 +2229,7 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused) "size(cnt)--size(cnt)", "address", "threshold"); seq_puts(s, "----------------------------------------------------\n"); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ current_ts = sched_clock(); do_div(current_ts, 1000000); @@ -2404,11 +2264,7 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused) } client->dbg_hnd_cnt = 0; } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ seq_puts(s, "----------------------------------------------------\n"); seq_puts(s, "orphaned allocation (info is from last known client):\n"); @@ -2573,11 +2429,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) ion_heap_init_shrinker(heap); heap->dev = dev; -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_write(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ /* * use negative heap->id to reverse the priority -- when traversing * the list later attempt higher id numbers first @@ -2647,11 +2499,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) #endif dev->heap_cnt++; -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_write(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ } EXPORT_SYMBOL(ion_device_add_heap); @@ -2705,9 +2553,6 @@ static int ion_init_sysfs(void) return 0; } -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#include "ion_track/ion_track.h" -#endif struct ion_device *ion_device_create(long (*custom_ioctl) (struct ion_client *client, unsigned int cmd, @@ -2775,17 +2620,9 @@ procfs_done: idev->custom_ioctl = custom_ioctl; idev->buffers = RB_ROOT; mutex_init(&idev->buffer_lock); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - init_rwsem(&idev->client_lock); - init_rwsem(&idev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ init_rwsem(&idev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ plist_head_init(&idev->heaps); idev->clients = RB_ROOT; -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) - update_internal_dev(idev); -#endif return idev; err_sysfs: @@ -2914,11 +2751,7 @@ struct ion_heap *ion_drv_get_heap(struct ion_device *dev, struct ion_heap *_heap, *heap = NULL, *tmp; if (need_lock) { -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->heap_lock)) { -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!down_read_trylock(&dev->lock)) { -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ IONMSG("%s get lock fail\n", __func__); return NULL; } @@ -2932,11 +2765,7 @@ struct ion_heap *ion_drv_get_heap(struct ion_device *dev, } if (need_lock) -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return heap; } @@ -2973,7 +2802,4 @@ file2buf_exit: return ERR_PTR(-EINVAL); } -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#include "ion_track/ion_track.c" -#endif /* ===================================== */ diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 26ad4a77950c..c51967739160 100755 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -23,10 +23,6 @@ #include #include #include -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) -#include -#include -#endif #include "ion.h" #include "ion_priv.h" @@ -192,13 +188,6 @@ void ion_heap_freelist_add(struct ion_heap *heap, struct ion_buffer *buffer) size_t free_list_size = 0; size_t unit = 200 * 1024 * 1024; //200M -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) - if (buffer->tsk) { - atomic64_sub(buffer->size, &buffer->tsk->ions); - put_task_struct(buffer->tsk); - buffer->tsk = NULL; - } -#endif spin_lock(&heap->free_lock); list_add(&buffer->list, &heap->free_list); diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 9faf4f02bb95..08218863ebaa 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -77,10 +77,6 @@ static void ion_page_pool_free_pages(struct ion_page_pool *pool, static int ion_page_pool_add(struct ion_page_pool *pool, struct page *page) { mutex_lock(&pool->mutex); -#ifdef OPLUS_FEATURE_HEALTHINFO - /*add ion cached account*/ - zone_page_state_add(1L << pool->order, page_zone(page), NR_IONCACHE_PAGES); -#endif /* OPLUS_FEATURE_HEALTHINFO */ if (PageHighMem(page)) { list_add_tail(&page->lru, &pool->high_items); pool->high_count++; @@ -110,10 +106,6 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) pool->low_count--; } -#ifdef OPLUS_FEATURE_HEALTHINFO - /*add ion cached account*/ - zone_page_state_add(-(1L << pool->order), page_zone(page), NR_IONCACHE_PAGES); -#endif /* OPLUS_FEATURE_HEALTHINFO */ list_del(&page->lru); nr_total_pages -= 1 << pool->order; diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 553c8c17e84b..0b5fcbcac8c7 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -93,12 +93,6 @@ struct ion_buffer { #ifdef MTK_ION_DMABUF_SUPPORT struct list_head attachments; #endif -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_DUMP_TASKS_MEM) - struct task_struct *tsk; -#endif -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) - unsigned long jiffies; -#endif }; void ion_buffer_destroy(struct ion_buffer *buffer); @@ -117,12 +111,7 @@ struct ion_device { struct miscdevice dev; struct rb_root buffers; struct mutex buffer_lock; /* mutex */ -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - struct rw_semaphore client_lock; - struct rw_semaphore heap_lock; -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ struct rw_semaphore lock; -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ struct plist_head heaps; long (*custom_ioctl)(struct ion_client *client, unsigned int cmd, unsigned long arg); @@ -559,9 +548,6 @@ int ion_share_dma_buf_fd_nolock(struct ion_client *client, struct ion_handle *pass_to_user(struct ion_handle *handle); void user_ion_free_nolock(struct ion_client *client, struct ion_handle *handle); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -inline is_allocator_svc(struct task_struct *tsk); -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ struct ion_handle *__ion_alloc(struct ion_client *client, size_t len, size_t align, unsigned int heap_id_mask, unsigned int flags, bool grab_handle); diff --git a/drivers/staging/android/ion/ion_track/ion_track.c b/drivers/staging/android/ion/ion_track/ion_track.c deleted file mode 100755 index 1a80ab7cc8fa..000000000000 --- a/drivers/staging/android/ion/ion_track/ion_track.c +++ /dev/null @@ -1,264 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#if defined(CONFIG_DUMP_TASKS_MEM) && defined(CONFIG_OPLUS_HEALTHINFO) -#include - -#define ION_DEBUG_LOG_TAG "ion_debug" -#define BUFLEN(total, len) (total - len - 1) -#define ION_DEBUG_MIN_WATERMARK 220lu -#define ION_DEBUG_MAX_WATERMARK 650lu -#define ION_DEBUG_DUMP_STEP 30lu -#define MAX_TASK_NUM 124 -#define MAX_HEAP_CNT 5 - -struct ion_heap_info { - struct ion_heap *heap; - unsigned long size; - unsigned long jfs_max; - unsigned long jfs_min; - unsigned long jfs_sum; - unsigned int count; -}; - -struct ion_buff_info { - struct task_struct *tsk; - unsigned long size; - unsigned long jfs_max; - unsigned long jfs_min; - unsigned long jfs_sum; - unsigned int count; - struct ion_heap_info heaps[MAX_HEAP_CNT]; - int heap_cnt; -}; - -extern void dump_meminfo_to_logger(const char *tag, char *msg, size_t len); - -static int ion_buff_cmp(const void *la, const void *lb) -{ - return ((struct ion_buff_info *)lb)->size - ((struct ion_buff_info *)la)->size; -} - -static void ion_buff_swap(void *la, void *lb, int size) -{ - struct ion_buff_info l_tmp; - - memcpy(&l_tmp, la, size); - memcpy(la, lb, size); - memcpy(lb, &l_tmp, size); -} - -static int array_add_ion_info(struct ion_buff_info *array, int *len, - struct ion_buffer *entry) -{ - long start, end, pos; - struct ion_buff_info *l; - unsigned long age; - struct task_struct *tsk; - int i; - struct ion_heap_info *heap; - - age = jiffies - entry->jiffies; - start = -1; - end = *len; - - for ( ; ; ) { - pos = start + (end - start + 1) / 2; - - if (pos == end) - break; - - tsk = array[pos].tsk; - if (entry->tsk == tsk) { - l = &array[pos]; - l->size += entry->size; - l->count++; - l->jfs_sum += age; - if (age < l->jfs_min) - l->jfs_min = age; - if (age > l->jfs_max) - l->jfs_max = age; - - for (i = 0; i < l->heap_cnt; i++) { - heap = &l->heaps[i]; - - if (heap->heap == entry->heap) { - heap->jfs_sum += age; - if (age < heap->jfs_min) - heap->jfs_min = age; - if (age >heap->jfs_max) - heap->jfs_max = age; - heap->count++; - heap->size += entry->size; - break; - } - } - - if ((i == l->heap_cnt) && (i < MAX_HEAP_CNT)) { - heap = &l->heaps[l->heap_cnt]; - heap->heap = entry->heap; - heap->jfs_sum = age; - heap->jfs_min = age; - heap->jfs_max = age; - heap->size = entry->size; - heap->count = 1; - l->heap_cnt++; - } - return 0; - } - - if (entry->tsk < tsk) - end = pos; - else - start = pos; - } - - if (*len >= MAX_TASK_NUM) - return -ENOMEM; - - l = &array[pos]; - if (pos < *len) - memmove(l + 1, l, (*len - pos) * sizeof(struct ion_buff_info)); - (*len)++; - l->count = 1; - l->tsk = entry->tsk; - l->jfs_sum = age; - l->jfs_min = age; - l->jfs_max = age; - l->size = entry->size; - l->heap_cnt = 0; - memset(&l->heaps[0], 0, sizeof(l->heaps)); - heap = &l->heaps[l->heap_cnt]; - heap->size = entry->size; - heap->jfs_sum = age; - heap->jfs_min = age; - heap->jfs_max = age; - heap->count = 1; - heap->heap = entry->heap; - l->heap_cnt++; - return 0; -} - -void dump_ion_info(char *dump_buff, int len) -{ - struct ion_device *dev = internal_dev; - struct ion_heap_info *heap; - struct rb_root *root; - struct ion_buffer *entry, *entry_next; - struct task_struct *tsk; - int dump_buff_len = 0; - static unsigned long last_ion_size = ION_DEBUG_MIN_WATERMARK; - unsigned long ion_size; - struct ion_buff_info *array; - int buff_index = 0, i, j; - int ret; - unsigned long record_sum; - - if (!ion_cnt_enable) { - pr_warn("[ion_debug] ion_cnt_enable is disabled.\n"); - return; - } - - if (!dump_buff) { - pr_warn("[ion_debug] dump_buff is NULL.\n"); - return; - } - - ion_size = (unsigned long)atomic_long_read(&ion_total_size) >> 20; - if (ion_size < last_ion_size) { - if (last_ion_size < ION_DEBUG_MAX_WATERMARK) - return; - } else { - /* - * ION have many instantaneous value, so upate with step, it is - * differenet with kmalloc and vmalloc. - */ - last_ion_size += ION_DEBUG_DUMP_STEP; - } - - if (!dev) { - pr_warn("[ion_debug] internal_dev is NULL.\n"); - return; - } - - array = vmalloc(sizeof(struct ion_buff_info) * MAX_TASK_NUM); - if (!array) { - pr_err("[ion_debug] vmalloc array failed.\n"); - return; - } - memset(array, 0, sizeof(struct ion_buff_info) * MAX_TASK_NUM); - - memset(dump_buff, 0, len); - dump_buff_len = scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "used %lu MB , show all buffer:\n", ion_size); - - root = &dev->buffers; - mutex_lock(&dev->buffer_lock); - if (RB_EMPTY_ROOT(root)){ - pr_err("[ion_debug] dev->buffers is empty.\n"); - mutex_unlock(&dev->buffer_lock); - goto out; - } - - rbtree_postorder_for_each_entry_safe(entry, entry_next, root, node) { - if (unlikely(!entry->tsk)) - continue; - - ret = array_add_ion_info(array, &buff_index, entry); - if (ret) - break; - } - - sort((void *)array, buff_index, sizeof(struct ion_buff_info), - ion_buff_cmp, ion_buff_swap); - - record_sum = 0; - for (i = 0; i < buff_index; i++) { - struct ion_buff_info *ion_buff_i = &array[i]; - - tsk = ion_buff_i->tsk; - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%s %d %d %lu %u age %lu/%lu/%lu\n", - tsk->comm, tsk->pid, tsk->tgid, ion_buff_i->size, - ion_buff_i->count, - ion_buff_i->jfs_min, ion_buff_i->jfs_sum / ion_buff_i->count, - ion_buff_i->jfs_max); - record_sum += ion_buff_i->size; - - for (j = 0; j < ion_buff_i->heap_cnt; j++) { - heap = &ion_buff_i->heaps[j]; - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%s %lu %u age %lu/%lu/%lu\n", - heap->heap->name, heap->size, heap->count, - heap->jfs_min, heap->jfs_sum / heap->count, heap->jfs_max); - } - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), "-\n"); - - if (BUFLEN(len, dump_buff_len) == 0) - break; - } - mutex_unlock(&dev->buffer_lock); - - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), "record_sum %lu MB\n", - record_sum >> 20); - dump_buff[dump_buff_len++] = '\n'; - dump_meminfo_to_logger(ION_DEBUG_LOG_TAG, dump_buff, dump_buff_len); - -out: - vfree(array); -} -#else -void dump_ion_info(char *dump_buff, int len) -{ - pr_warn("[ion_debug] CONFIG_DUMP_TASKS_MEM=%d CONFIG_OPLUS_HEALTHINFO=%d.\n", - IS_ENABLED(CONFIG_DUMP_TASKS_MEM), IS_ENABLED(CONFIG_OPLUS_HEALTHINFO)); -} -#endif -EXPORT_SYMBOL(dump_ion_info); diff --git a/drivers/staging/android/ion/ion_track/ion_track.h b/drivers/staging/android/ion/ion_track/ion_track.h deleted file mode 100644 index 64bb93246315..000000000000 --- a/drivers/staging/android/ion/ion_track/ion_track.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -static struct ion_device *internal_dev = NULL; - -static inline void update_internal_dev(struct ion_device *dev) -{ - if (!internal_dev) - internal_dev = dev; -} diff --git a/drivers/staging/android/ion/mtk/Kconfig b/drivers/staging/android/ion/mtk/Kconfig index 2051cbb1368a..4e683401c449 100644 --- a/drivers/staging/android/ion/mtk/Kconfig +++ b/drivers/staging/android/ion/mtk/Kconfig @@ -18,9 +18,3 @@ config MTK_ION It means support ION. It set in xxxx_defconfig.mk default is on. - -config OPLUS_ION_BOOSTPOOL - bool "Support ION Boost pool" - default n - help - This driver supports ION boost pool. diff --git a/drivers/staging/android/ion/mtk/Makefile b/drivers/staging/android/ion/mtk/Makefile index a4ee124fb7e0..3289dd642a33 100644 --- a/drivers/staging/android/ion/mtk/Makefile +++ b/drivers/staging/android/ion/mtk/Makefile @@ -30,7 +30,6 @@ ccflags-y += -I$(srctree)/drivers/iommu/ # obj-$(CONFIG_MTK_ION) += ion_history.o obj-$(CONFIG_MTK_ION) += ion_comm.o -obj-$(CONFIG_OPLUS_ION_BOOSTPOOL) += oplus_ion_boost_pool.o ifeq ($(CONFIG_MTK_ENG_BUILD), y) ccflags-y += -DION_RUNTIME_DEBUGGER=1 diff --git a/drivers/staging/android/ion/mtk/ion_drv.c b/drivers/staging/android/ion/mtk/ion_drv.c index d1be81ec06d3..11e199022842 100644 --- a/drivers/staging/android/ion/mtk/ion_drv.c +++ b/drivers/staging/android/ion/mtk/ion_drv.c @@ -823,22 +823,14 @@ int ion_device_destroy_heaps(struct ion_device *dev) { struct ion_heap *heap, *tmp; -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_write(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ plist_for_each_entry_safe(heap, tmp, &dev->heaps, node) { plist_del((struct plist_node *)heap, &dev->heaps); ion_mtk_heap_destroy(heap); } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_write(&dev->heap_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_write(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return 0; } @@ -854,11 +846,7 @@ static int ion_clients_summary_show(struct seq_file *s, void *unused) enum mtk_ion_heap_type cam_heap = ION_HEAP_TYPE_MULTIMEDIA_FOR_CAMERA; enum mtk_ion_heap_type mm_heap = ION_HEAP_TYPE_MULTIMEDIA; -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!down_read_trylock(&dev->lock)) -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return 0; seq_printf(s, "%-16.s %-8.s %-8.s\n", "client_name", "pid", "size"); seq_puts(s, "------------------------------------------\n"); @@ -892,11 +880,7 @@ static int ion_clients_summary_show(struct seq_file *s, void *unused) } seq_puts(s, "-------------------------------------------\n"); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return 0; } @@ -930,9 +914,6 @@ static const struct file_operations proc_client_fops = { #endif #endif -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -struct proc_dir_entry *boost_root_dir; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ #ifdef CONFIG_MTK_IOMMU_V2 struct device *g_iommu_device; @@ -962,9 +943,6 @@ static int ion_drv_probe(struct platform_device *pdev) num_heaps = pdata->nr; g_ion_device = ion_device_create(ion_custom_ioctl); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - boost_root_dir = proc_mkdir("boost_pool", NULL); -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ if (IS_ERR_OR_NULL(g_ion_device)) { IONMSG("ion_device_create() error! device=%p\n", g_ion_device); return PTR_ERR(g_ion_device); diff --git a/drivers/staging/android/ion/mtk/ion_drv.h b/drivers/staging/android/ion/mtk/ion_drv.h index 94b34cde7eda..1226cf0b1bcf 100644 --- a/drivers/staging/android/ion/mtk/ion_drv.h +++ b/drivers/staging/android/ion/mtk/ion_drv.h @@ -259,9 +259,6 @@ struct ion_mm_data { /* Exported global variables */ extern struct ion_device *g_ion_device; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -extern struct proc_dir_entry *boost_root_dir; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ /* Exported functions */ long ion_kernel_ioctl(struct ion_client *client, unsigned int cmd, diff --git a/drivers/staging/android/ion/mtk/ion_history.c b/drivers/staging/android/ion/mtk/ion_history.c index e1123874d6ae..69f6e8b08813 100644 --- a/drivers/staging/android/ion/mtk/ion_history.c +++ b/drivers/staging/android/ion/mtk/ion_history.c @@ -752,11 +752,7 @@ static int ion_history_record(void *data) /* == client == */ if (g_client_history) { -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ start = sched_clock(); for (n = rb_first(&dev->clients); n; n = rb_next(n)) { struct ion_client @@ -806,11 +802,7 @@ static int ion_history_record(void *data) "kernel", size, client); } } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ } } diff --git a/drivers/staging/android/ion/mtk/ion_mm_heap.c b/drivers/staging/android/ion/mtk/ion_mm_heap.c index 6d4cd6ca02af..cd51ee951335 100755 --- a/drivers/staging/android/ion/mtk/ion_mm_heap.c +++ b/drivers/staging/android/ion/mtk/ion_mm_heap.c @@ -53,9 +53,6 @@ #define MTK_ION_MAPPING_PERF_DEBUG #endif -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -#include "oplus_ion_boost_pool.h" -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ #define SZ_4G _AC(0x100000000, ULL) @@ -102,10 +99,6 @@ static unsigned int order_gfp_flags[] = { static const unsigned int orders[] = { 4, 1, 0 }; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -struct kmem_cache *boost_ion_info_cachep; -bool create_kmemcache_ion_info_success = false; -#endif /* static const unsigned int orders[] = {8, 4, 0}; */ static const int num_orders = ARRAY_SIZE(orders); @@ -129,19 +122,12 @@ struct ion_system_heap { struct ion_heap heap; struct ion_page_pool **pools; struct ion_page_pool **cached_pools; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - struct ion_boost_pool *cached_boost_pool; - struct ion_boost_pool *uncached_boost_pool; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ }; struct page_info { struct page *page; unsigned int order; struct list_head list; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - bool from_boost_kmem_cache; -#endif }; unsigned int caller_pid; @@ -181,14 +167,6 @@ static void free_buffer_page(struct ion_system_heap *heap, int order_idx = order_to_index(order); unsigned long private_flags = buffer->private_flags; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - struct ion_boost_pool* boost_pool = - cached ? heap->cached_boost_pool : heap->uncached_boost_pool; - - if (boost_pool && !(private_flags & ION_PRIV_FLAG_SHRINKER_FREE) && - (0 == boost_pool_free(boost_pool, page, order))) - return; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ if (!cached && !(private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) { struct ion_page_pool *pool = heap->pools[order_idx]; @@ -218,25 +196,11 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, struct page_info *info; int i; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(create_kmemcache_ion_info_success)) { - info = kmem_cache_zalloc(boost_ion_info_cachep, GFP_KERNEL); - if (!info) - return ERR_PTR(-ENOMEM); - info->from_boost_kmem_cache = true; - } else { - info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) - return ERR_PTR(-ENOMEM); - info->from_boost_kmem_cache = false; - } -#else info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) { IONMSG("%s kmalloc failed info is null.\n", __func__); return NULL; } -#endif for (i = 0; i < num_orders; i++) { if (size < order_to_size(orders[i])) @@ -253,14 +217,7 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, INIT_LIST_HEAD(&info->list); return info; } -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(info->from_boost_kmem_cache)) - kmem_cache_free(boost_ion_info_cachep, info); - else - kfree(info); -#else kfree(info); -#endif return NULL; } @@ -410,15 +367,6 @@ static int ion_mm_heap_allocate(struct ion_heap *heap, unsigned long long start, end; unsigned long user_va = 0; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - bool cached = ion_buffer_cached(buffer); - struct ion_boost_pool *boost_pool = - cached ? sys_heap->cached_boost_pool : sys_heap->uncached_boost_pool; -#ifdef BOOSTPOOL_DEBUG - int boostpool_order[3] = {0}; - unsigned long alloc_start = jiffies; -#endif /* BOOSTPOOL_DEBUG */ -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ INIT_LIST_HEAD(&pages); if (size / PAGE_SIZE > totalram_pages / 2) { @@ -429,69 +377,6 @@ static int ion_mm_heap_allocate(struct ion_heap *heap, start = sched_clock(); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (size < SZ_1M) - boost_pool = NULL; - - if (boost_pool) { - unsigned int alloc_sz = 0; - struct page *page = NULL; - - while (size_remaining > 0) { - if (likely(create_kmemcache_ion_info_success)) { - info = kmem_cache_zalloc(boost_ion_info_cachep, GFP_KERNEL); - if (!info) - break; - info->from_boost_kmem_cache = true; - } else { - info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) - break; - info->from_boost_kmem_cache = false; - } - page = boost_pool_allocate(boost_pool, - size_remaining, max_order); - if (!page) { - if (info->from_boost_kmem_cache) - kmem_cache_free(boost_ion_info_cachep, info); - else - kfree(info); - break; - } - - info->page = page; - /* TODO if not use GFP_COMP, we should save page order. */ - info->order = compound_order(page); - alloc_sz += (1 << info->order); - INIT_LIST_HEAD(&info->list); -#ifdef BOOSTPOOL_DEBUG - boostpool_order[order_to_index(info->order)] += 1; -#endif /* BOOSTPOOL_DEBUG */ - - list_add_tail(&info->list, &pages); - - size_remaining -= (1 << info->order) * PAGE_SIZE; - max_order = info->order; - i++; - } - - boost_pool_dec_high(boost_pool, alloc_sz); - - -#ifdef BOOSTPOOL_DEBUG - if (size_remaining != 0 || true) { - pr_info("boostpool %s-%d alloc failed. boostpool_sz: %d size: %d orders(%d, %d, %d) %d ms\n", - boost_pool->name, sys_heap->heap.id, - size_remaining, (int) size, - boostpool_order[0], boostpool_order[1], - boostpool_order[2], - jiffies_to_msecs(jiffies - alloc_start)); - } -#endif /* BOOSTPOOL_DEBUG */ - - max_order = orders[0]; - } -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ /* add time interval to alloc 64k page in low memory status*/ if (((start - alloc_large_fail_ts) < 1000000000) && @@ -542,14 +427,7 @@ static int ion_mm_heap_allocate(struct ion_heap *heap, sg_dma_len(sg) = sg->length; sg = sg_next(sg); list_del(&info->list); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(info->from_boost_kmem_cache)) - kmem_cache_free(boost_ion_info_cachep, info); - else - kfree(info); -#else kfree(info); -#endif } /* create MM buffer info for it */ @@ -596,10 +474,6 @@ static int ion_mm_heap_allocate(struct ion_heap *heap, caller_pid = 0; caller_tid = 0; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - /* if (boost_pool) */ - /* boost_pool_wakeup_process(boost_pool); */ -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ return 0; err1: @@ -611,14 +485,7 @@ err: list_for_each_entry_safe(info, tmp_info, &pages, list) { free_buffer_page(sys_heap, buffer, info->page, info->order); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(info->from_boost_kmem_cache)) - kmem_cache_free(boost_ion_info_cachep, info); - else kfree(info); -#else - kfree(info); -#endif } } IONMSG("error: mm_alloc fail: size=%lu, flag=%lu.\n", size, flags); @@ -783,85 +650,9 @@ static int ion_mm_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask, struct ion_system_heap *sys_heap; int nr_total = 0; int i; -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - struct ion_boost_pool *boost_pool = NULL; - int nr_freed; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ sys_heap = container_of(heap, struct ion_system_heap, heap); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - for (i = 0; i < num_orders; i++) { - if (!nr_to_scan) { - boost_pool = sys_heap->cached_boost_pool; - if (boost_pool) { - nr_total += boost_pool_shrink(boost_pool, - boost_pool->pools[i], - gfp_mask, - nr_to_scan); - } - boost_pool = sys_heap->uncached_boost_pool; - if (boost_pool) { - nr_total += boost_pool_shrink(boost_pool, - boost_pool->pools[i], - gfp_mask, - nr_to_scan); - } - - /* shrink cached pool */ - nr_total += - ion_page_pool_shrink(sys_heap->pools[i], - gfp_mask, - nr_to_scan); - nr_total += - ion_page_pool_shrink(sys_heap->cached_pools[i], - gfp_mask, - nr_to_scan); - } else { - - boost_pool = sys_heap->uncached_boost_pool; - if (boost_pool) { - nr_freed = boost_pool_shrink(boost_pool, - boost_pool->pools[i], - gfp_mask, - nr_to_scan); - nr_to_scan -= nr_freed; - nr_total += nr_freed; - if (nr_to_scan <= 0) - break; - } - - boost_pool = sys_heap->cached_boost_pool; - if (boost_pool) { - nr_freed = boost_pool_shrink(boost_pool, - boost_pool->pools[i], - gfp_mask, - nr_to_scan); - nr_to_scan -= nr_freed; - nr_total += nr_freed; - if (nr_to_scan <= 0) - break; - } - - nr_freed = ion_page_pool_shrink(sys_heap->pools[i], - gfp_mask, nr_to_scan); - nr_total += nr_freed; - nr_to_scan -= nr_freed; - if (nr_to_scan <= 0) - break; - - /* shrink cached pool */ - nr_freed = - ion_page_pool_shrink(sys_heap->cached_pools[i], - gfp_mask, - nr_to_scan); - nr_to_scan -= nr_freed; - nr_total += nr_freed; - if (nr_to_scan <= 0) - break; - } - } -#else /* CONFIG_OPLUS_ION_BOOSTPOOL */ for (i = 0; i < num_orders; i++) { struct ion_page_pool *pool = sys_heap->pools[i]; @@ -872,7 +663,6 @@ static int ion_mm_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask, ion_page_pool_shrink(sys_heap->cached_pools[i], gfp_mask, nr_to_scan); } -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ return nr_total; } @@ -1536,11 +1326,7 @@ static int ion_mm_heap_debug_show(struct ion_heap *heap, struct seq_file *s, "----------------------------------------------------\n"); /* dump all handle's backtrace */ -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ for (n = rb_first(&dev->clients); n; n = rb_next(n)) { struct ion_client *client = rb_entry(n, struct ion_client, node); @@ -1593,11 +1379,7 @@ static int ion_mm_heap_debug_show(struct ion_heap *heap, struct seq_file *s, #ifdef CONFIG_MTK_IOMMU_V2 mtk_iommu_log_dump(s); #endif -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return 0; } @@ -1676,11 +1458,7 @@ void ion_mm_heap_memory_detail(void) "client", "dbg_name", "pid", "size", "address"); ION_DUMP(NULL, "--------------------------------------\n"); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) { -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!down_read_trylock(&dev->lock)) { -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ ION_DUMP(NULL, "detail trylock fail, alloc pid(%d-%d)\n", caller_pid, caller_tid); @@ -1733,11 +1511,7 @@ void ion_mm_heap_memory_detail(void) ION_DUMP(NULL, "%s\n", seq_log); if (need_dev_lock) -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ ION_DUMP(NULL, "---------ion_mm_heap buffer info------\n"); @@ -1903,59 +1677,6 @@ size_t ion_mm_heap_total_memory(void) return (size_t)(atomic64_read(&page_sz_cnt) * 4096); } -#ifdef OPLUS_BUG_STABILITY -size_t get_ion_heap_by_pid(pid_t pid) -{ - struct ion_device *dev = g_ion_device; - struct rb_node *n, *m; - int buffer_size = 0; - unsigned int id = 0; - enum mtk_ion_heap_type cam_heap = ION_HEAP_TYPE_MULTIMEDIA_FOR_CAMERA; - enum mtk_ion_heap_type mm_heap = ION_HEAP_TYPE_MULTIMEDIA; - -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - if (!down_read_trylock(&dev->lock)) -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - return 0; - for (n = rb_first(&dev->clients); n; n = rb_next(n)) { - struct ion_client *client = rb_entry(n, struct ion_client, node); - if(client->pid == pid) { - mutex_lock(&client->lock); - for (m = rb_first(&client->handles); m; - m = rb_next(m)) { - struct ion_handle *handle = - rb_entry(m, struct ion_handle, - node); - id = handle->buffer->heap->id; - - if ((id == mm_heap || id == cam_heap) && - (handle->buffer->handle_count) != 0) { - buffer_size += - (int)(handle->buffer->size) / - (handle->buffer->handle_count); - } - } - mutex_unlock(&client->lock); - } - } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ - return buffer_size/1024; -} -EXPORT_SYMBOL(get_ion_heap_by_pid); -#endif - -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -static void init_once(void *foo) -{ - ; -} -#endif struct ion_heap *ion_mm_heap_create(struct ion_platform_heap *unused) { @@ -2001,43 +1722,6 @@ struct ion_heap *ion_mm_heap_create(struct ion_platform_heap *unused) heap->heap.debug_show = ion_mm_heap_debug_show; ion_comm_init(); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (unused->id == ION_HEAP_TYPE_MULTIMEDIA_FOR_CAMERA && - !IS_ERR_OR_NULL(boost_root_dir)) { - if (!kcrit_scene_init()) - pr_err("%s: init kcrit scene failed!\n", - __func__); - - unsigned long cam_sz = 32 * 256, uncached_sz = 32 * 256; - /* on low memory target, we should not set 128Mib on camera pool. */ - if (totalram_pages > (SZ_4G >> PAGE_SHIFT)) { - cam_sz = 128 * 256; - uncached_sz = 64 * 256; - } - - heap->uncached_boost_pool = boost_pool_create(0, - uncached_sz, - boost_root_dir, - "ion_uncached"); - if (!heap->uncached_boost_pool) - pr_err("%s: create boost_pool ion_uncached failed!\n", - __func__); - - heap->cached_boost_pool = boost_pool_create(ION_FLAG_CACHED, - cam_sz, - boost_root_dir, - "camera"); - if (!heap->cached_boost_pool) - pr_err("%s: create boost_pool camera failed!\n", - __func__); - boost_ion_info_cachep = kmem_cache_create("boost_ion_info_cachep", - sizeof(struct page_info), 0,0, init_once); - if (boost_ion_info_cachep != NULL) - create_kmemcache_ion_info_success = true; - else - pr_err("boost_ion_info_cachep create failed\n"); - } -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ return &heap->heap; err_create_pool: @@ -2792,14 +2476,7 @@ int ion_mm_heap_cache_allocate(struct ion_heap *heap, sg = sg_next(sg); list_del(&info->list); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(info->from_boost_kmem_cache)) - kmem_cache_free(boost_ion_info_cachep, info); - else - kfree(info); -#else kfree(info); -#endif } buffer->sg_table = table; @@ -2815,14 +2492,7 @@ err: list_for_each_entry_safe(info, tmp_info, &pages, list) { free_buffer_page(sys_heap, buffer, info->page, info->order); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (likely(info->from_boost_kmem_cache)) - kmem_cache_free(boost_ion_info_cachep, info); - else - kfree(info); -#else kfree(info); -#endif } IONMSG("mm_cache_alloc fail: size=%lu, flag=%lu.\n", size, flags); diff --git a/drivers/staging/android/ion/mtk/ion_sec_heap.c b/drivers/staging/android/ion/mtk/ion_sec_heap.c index 712466ce5be3..04b3bbeb6675 100644 --- a/drivers/staging/android/ion/mtk/ion_sec_heap.c +++ b/drivers/staging/android/ion/mtk/ion_sec_heap.c @@ -647,11 +647,7 @@ void ion_sec_heap_dump_info(void) "client", "dbg_name", "pid", "size", "address"); ION_DUMP(NULL, "%s\n", seq_line); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - if (!down_read_trylock(&dev->client_lock)) { -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ if (!down_read_trylock(&dev->lock)) { -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ ION_DUMP( NULL, "detail trylock fail, alloc pid(%d-%d)\n", @@ -699,11 +695,7 @@ void ion_sec_heap_dump_info(void) } if (need_dev_lock) -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ ION_DUMP(NULL, "%s\n", seq_line); ION_DUMP( @@ -900,11 +892,7 @@ static int ion_sec_heap_debug_show( ION_DUMP(s, "%16s %16zu\n", "2d-fr-sz:", fr_size); ION_DUMP(s, "%s\n", seq_line); -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - down_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ down_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ for (n = rb_first(&dev->clients); n; n = rb_next(n)) { struct ion_client @@ -952,11 +940,7 @@ static int ion_sec_heap_debug_show( mutex_unlock(&client->lock); } } -#ifdef OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK - up_read(&dev->client_lock); -#else /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ up_read(&dev->lock); -#endif /* OPLUS_FEATURE_MTK_ION_SEPARATE_LOCK */ return 0; } diff --git a/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.c b/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.c deleted file mode 100755 index 3416a283f862..000000000000 --- a/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.c +++ /dev/null @@ -1,777 +0,0 @@ -#define pr_fmt(fmt) "boostpool: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include <../../../../kernel/sched/sched.h> - -#include "oplus_ion_boost_pool.h" - -#ifdef OPLUS_FEATURE_HEALTHINFO -#include -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#define MAX_BOOST_POOL_HIGH (1024 * 256) - -static bool boost_pool_enable = true; -static void kcrit_scene_wakeup_lmkd(void); - -#define K(x) ((x) << (PAGE_SHIFT-10)) -#define M(x) (K(x) >> 10) - -/* copy from ion_mm_heap.c */ -static const unsigned int orders[] = { 4, 1, 0 }; -static unsigned int order_gfp_flags[] = { - (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & - ~__GFP_RECLAIM, - (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & - ~__GFP_RECLAIM, - (GFP_HIGHUSER | __GFP_ZERO) -}; - -#define NUM_ORDERS ARRAY_SIZE(orders) - -static int order_to_index(unsigned int order) -{ - int i; - - for (i = 0; i < NUM_ORDERS; i++) - if (order == orders[i]) - return i; - BUG(); - return -1; -} - -static inline unsigned int order_to_size(int order) -{ - return PAGE_SIZE << order; -} - -static int page_pool_nr_pages(struct ion_page_pool *pool) -{ - if (NULL == pool) { - pr_err("%s: pool is NULL!\n", __func__); - return 0; - } - return (pool->low_count + pool->high_count) << pool->order; -} - -static int boost_pool_nr_pages(struct ion_boost_pool *pool) -{ - int i; - int count = 0; - - if (NULL == pool) { - pr_err("%s: pool is NULL!\n", __func__); - return 0; - } - - for (i = 0; i < NUM_ORDERS; i++) - count += page_pool_nr_pages(pool->pools[i]); - - return count; -} - -static int fill_boost_page_pool(struct ion_page_pool *pool) -{ - struct page *page; - - if (NULL == pool) { - pr_err("%s: pool is NULL!\n", __func__); - return -ENOENT; - } - - page = ion_page_pool_alloc_pages(pool); - if (NULL == page) - return -ENOMEM; - - ion_page_pool_free(pool, page); - - return 0; -} - -void boost_pool_dump(struct ion_boost_pool *pool) -{ - int i; - - pr_info("Name:%s: %dMib, low: %dMib, high:%dMib\n", - pool->name, - boost_pool_nr_pages(pool) >> 8, - pool->low >> 8, - pool->high >> 8); - for (i = 0; i < NUM_ORDERS; i++) { - struct ion_page_pool *page_pool = pool->pools[i]; - - pr_info("%d order %u highmem pages in boost pool = %lu total\n", - page_pool->high_count, page_pool->order, - (PAGE_SIZE << page_pool->order) * page_pool->high_count); - pr_info("%d order %u lowmem pages in boost pool = %lu total\n", - page_pool->low_count, page_pool->order, - (PAGE_SIZE << page_pool->order) * page_pool->low_count); - } -} - -static int boost_pool_kworkthread(void *p) -{ - int i; - struct ion_boost_pool *pool; - int ret; - - if (NULL == p) { - pr_err("%s: p is NULL!\n", __func__); - return 0; - } - - pool = (struct ion_boost_pool *)p; - while (true) { - ret = wait_event_interruptible(pool->waitq, - (pool->wait_flag == 1)); - if (ret < 0) - continue; - - pool->wait_flag = 0; - - for (i = 0; i < NUM_ORDERS; i++) { - while (!pool->force_stop && boost_pool_nr_pages(pool) < pool->high) { - if (fill_boost_page_pool(pool->pools[i]) < 0) - break; - } - } - } - - return 0; -} - -#define BOOSTPOOL_DEBUG -/* extern int direct_vm_swappiness; */ -static int boost_prefill_kworkthread(void *p) -{ - int i; - struct ion_boost_pool *pool; - u64 timeout_jiffies; - int ret; -#ifdef BOOSTPOOL_DEBUG - unsigned long begin; -#endif /* BOOSTPOOL_DEBUG */ - - if (NULL == p) { - pr_err("%s: p is NULL!\n", __func__); - return 0; - } - - pool = (struct ion_boost_pool *)p; - while (true) { - ret = wait_event_interruptible(pool->prefill_waitq, - (pool->prefill_wait_flag == 1)); - if (ret < 0) - continue; - - pool->prefill_wait_flag = 0; - - mutex_lock(&pool->prefill_mutex); - timeout_jiffies = get_jiffies_64() + 2 * HZ; - /* direct_vm_swappiness = 20; */ -#ifdef BOOSTPOOL_DEBUG - begin = jiffies; - - pr_info("prefill start >>>>> nr_page: %dMib high: %dMib.\n", - M(boost_pool_nr_pages(pool)), M(pool->high)); -#endif /* BOOSTPOOL_DEBUG */ - - for (i = 0; i < NUM_ORDERS; i++) { - while (!pool->force_stop && - boost_pool_nr_pages(pool) < pool->high) { - - /* support timeout to limit alloc pages. */ - if (time_after64(get_jiffies_64(), timeout_jiffies)) { - pr_warn("prefill timeout.\n"); - break; - } - - if (fill_boost_page_pool(pool->pools[i]) < 0) - break; - } - } - -#ifdef BOOSTPOOL_DEBUG - pr_info("prefill end <<<<< nr_page: %dMib high:%dMib use %dms\n", - M(boost_pool_nr_pages(pool)), M(pool->high), - jiffies_to_msecs(jiffies - begin)); -#endif /* BOOSTPOOL_DEBUG */ - - pool->high = max(boost_pool_nr_pages(pool), pool->low); - pool->prefill = false; - /* direct_vm_swappiness = 60; */ - - mutex_unlock(&pool->prefill_mutex); - } - - return 0; -} - -struct page *boost_pool_allocate(struct ion_boost_pool *pool, - unsigned long size, unsigned int max_order) -{ - int i; - struct page *page; - - if (NULL == pool) { - pr_err("%s: pool is NULL!\n", __func__); - return NULL; - } - - for (i = 0; i < NUM_ORDERS; i++) { - if (size < order_to_size(orders[i])) - continue; - if (max_order < orders[i]) - continue; - - page = ion_page_pool_alloc(pool->pools[i]); - - if (page) { - BUG_ON(compound_order(page) != orders[i]); - } else { - continue; - } - return page; - } - - return NULL; -} - -void boost_pool_wakeup_process(struct ion_boost_pool *pool) -{ - if (!boost_pool_enable) - return; - - if (NULL == pool) { - pr_err("%s: boost_pool is NULL!\n", __func__); - return; - } - - if (!pool->force_stop) { - pool->wait_flag = 1; - wake_up_interruptible(&pool->waitq); - } -} - -static void boost_pool_all_free(struct ion_boost_pool *pool, gfp_t gfp_mask, - int nr_to_scan) -{ - int i; - - if (NULL == pool) { - pr_err("%s: boost_pool is NULL!\n", __func__); - return; - } - - for (i = 0; i < NUM_ORDERS; i++) - ion_page_pool_shrink(pool->pools[i], gfp_mask, nr_to_scan); -} - -int boost_pool_free(struct ion_boost_pool *pool, struct page *page, - int order) -{ - if (!boost_pool_enable) { - boost_pool_all_free(pool, __GFP_HIGHMEM, MAX_POOL_SIZE); - return -1; - } - - if ((NULL == pool) || (NULL == page)) { - pr_err("%s: pool/page is NULL!\n", __func__); - return -1; - } - - if (order == 0) - return -1; - - if (!((order == orders[0]) || (order == orders[1]) - || (order == orders[2]))) { - pr_err("%s: order:%d is error!\n", __func__, order); - return -1; - } - - if (boost_pool_nr_pages(pool) < pool->low + (SZ_128M >> PAGE_SHIFT)) { - ion_page_pool_free(pool->pools[order_to_index(order)], page); - return 0; - } - - return -1; -} - -int boost_pool_shrink(struct ion_boost_pool *boost_pool, - struct ion_page_pool *pool, gfp_t gfp_mask, - int nr_to_scan) -{ - int nr_max_free; - int nr_to_free; - int nr_total = 0; - - if ((NULL == boost_pool) || (NULL == pool)) { - pr_err("%s: boostpool/pool is NULL!\n", __func__); - return 0; - } - - /* don't shrink self.. */ - if (boost_pool->tsk->pid == current->pid || - boost_pool->prefill_tsk->pid == current->pid) - return 0; - - if (nr_to_scan == 0) - return ion_page_pool_shrink(pool, gfp_mask, 0); - - nr_max_free = boost_pool_nr_pages(boost_pool) - - (boost_pool->high + LOWORDER_WATER_MASK); - nr_to_free = min(nr_max_free, nr_to_scan); - - if (nr_to_free <= 0) - return 0; - - nr_total = ion_page_pool_shrink(pool, gfp_mask, nr_to_free); - return nr_total; -} - -void boost_pool_dec_high(struct ion_boost_pool *pool, int nr_pages) -{ - if (pool->prefill) - return; - - if (unlikely(nr_pages < 0)) - return; - - pool->high = max(pool->low, - pool->high - nr_pages); -} - -static int boost_pool_proc_show(struct seq_file *s, void *v) -{ - struct ion_boost_pool *boost_pool = s->private; - int i; - - seq_printf(s, "Name:%s: %dMib, prefill: %d origin: %dMib low: %dMib high: %dMib\n", - boost_pool->name, - M(boost_pool_nr_pages(boost_pool)), - boost_pool->prefill, - M(boost_pool->origin), - M(boost_pool->low), - M(boost_pool->high)); - - for (i = 0; i < NUM_ORDERS; i++) { - struct ion_page_pool *pool = boost_pool->pools[i]; - - seq_printf(s, "%d order %u highmem pages in boost pool = %lu total\n", - pool->high_count, pool->order, - (PAGE_SIZE << pool->order) * pool->high_count); - seq_printf(s, "%d order %u lowmem pages in boost pool = %lu total\n", - pool->low_count, pool->order, - (PAGE_SIZE << pool->order) * pool->low_count); - } - return 0; -} - -static int boost_pool_proc_open(struct inode *inode, struct file *file) -{ - struct ion_boost_pool *data = PDE_DATA(inode); - return single_open(file, boost_pool_proc_show, data); -} - -static inline void set_cpumask(int end_cpu, struct cpumask *mask) -{ - int i; - - cpumask_clear(mask); - for (i = 0; i <= end_cpu; i++) - cpumask_set_cpu(i, mask); -} - -static ssize_t boost_pool_proc_write(struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[13]; - int err, num; - struct ion_boost_pool *boost_pool = PDE_DATA(file_inode(file)); - int end_cpu, nr_pages; - - if (IS_ERR_OR_NULL(boost_pool)) { - pr_err("%s: boost pool is NULL.\n"); - return -EFAULT; - } - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtoint(strstrip(buffer), 0, &num); - if(err) - return err; - - if (num == 0) { - pr_info("reset flag.\n"); - boost_pool->high = boost_pool->low = boost_pool->origin; - boost_pool->force_stop = false; - return count; - } - - if (num == -1) { - pr_info("force stop.\n"); - boost_pool->force_stop = true; - return count; - } - - /* ugly code. */ - nr_pages = num & (0xfffff); - end_cpu = (num >> 20); - pr_info("dbg %d %d.\n", nr_pages, end_cpu); - - if (nr_pages < 0 || nr_pages >= MAX_BOOST_POOL_HIGH || - nr_pages <= boost_pool->low) { - pr_err("nr_page param invalid %d.\n", nr_pages); - return -EINVAL; - } - - if (end_cpu >= NR_CPUS || end_cpu < 0) { - pr_err("end_cpu param invalid %d.\n", end_cpu); - return -EINVAL; - } - - if (mutex_trylock(&boost_pool->prefill_mutex)) { - long mem_avail = si_mem_available(); - struct cpumask mask; - - pr_info("%s: set high wm => %dMib. current avail => %dMib end_cpu => %d\n", - current->comm, M(nr_pages), M(mem_avail), end_cpu); - - boost_pool->prefill = true; - boost_pool->force_stop = false; - boost_pool->high = nr_pages; - - /* kill one heavy process on low end target. */ - if (mem_avail < (SZ_2G >> PAGE_SHIFT)) - kcrit_scene_wakeup_lmkd(); - - if (end_cpu > 0) { - set_cpumask(end_cpu, &mask); - set_cpus_allowed_ptr(boost_pool->prefill_tsk, &mask); - } - - boost_pool->prefill_wait_flag = 1; - wake_up_interruptible(&boost_pool->prefill_waitq); - - mutex_unlock(&boost_pool->prefill_mutex); - } else { - pr_err("%s: prefill already running. \n"); - return -EBUSY; - } - - return count; -} - -static const struct file_operations boost_pool_proc_ops = { - .owner = THIS_MODULE, - .open = boost_pool_proc_open, - .read = seq_read, - .write = boost_pool_proc_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static int boost_pool_low_proc_show(struct seq_file *s, void *v) -{ - struct ion_boost_pool *boost_pool = s->private; - - seq_printf(s, "low %dMib.\n", M(boost_pool->low)); - - return 0; -} - -static int boost_pool_low_proc_open(struct inode *inode, struct file *file) -{ - struct ion_boost_pool *data = PDE_DATA(inode); - return single_open(file, boost_pool_low_proc_show, data); -} - -static ssize_t boost_pool_low_proc_write(struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[13]; - int err, nr_pages; - struct ion_boost_pool *boost_pool = PDE_DATA(file_inode(file)); - - if (IS_ERR_OR_NULL(boost_pool)) { - pr_err("%s: boost pool is NULL.\n"); - return -EFAULT; - } - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtoint(strstrip(buffer), 0, &nr_pages); - if(err) - return err; - - if (nr_pages <= 0 || nr_pages >= MAX_BOOST_POOL_HIGH) - return -EINVAL; - - boost_pool->low = boost_pool->high = nr_pages; - - return count; -} - -static const struct file_operations boost_pool_low_proc_ops = { - .owner = THIS_MODULE, - .open = boost_pool_low_proc_open, - .read = seq_read, - .write = boost_pool_low_proc_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static void ion_heap_destroy_pools(struct ion_page_pool **pools) -{ - int i; - - for (i = 0; i < NUM_ORDERS; i++) - if (pools[i]) - ion_page_pool_destroy(pools[i]); -} - -static int ion_heap_create_pools(struct ion_page_pool **pools, - bool cached, bool boost_flag) -{ - int i; - gfp_t gfp_flags; - - for (i = 0; i < NUM_ORDERS; i++) { - struct ion_page_pool *pool; - - gfp_flags = order_gfp_flags[i]; - - pool = ion_page_pool_create(gfp_flags, orders[i], cached, - boost_flag); - if (!pool) - goto err_create_pool; - pools[i] = pool; - } - return 0; - -err_create_pool: - ion_heap_destroy_pools(pools); - return -ENOMEM; -} - -static int boost_pool_stat_proc_show(struct seq_file *s, void *v) -{ - struct ion_boost_pool *boost_pool = s->private; - - seq_printf(s, "%d,%d,%d,%d\n", - M(boost_pool_nr_pages(boost_pool)), - boost_pool->prefill, M(si_mem_available()), - M(global_zone_page_state(NR_IONCACHE_PAGES))); - - return 0; -} - -static int boost_pool_stat_proc_open(struct inode *inode, struct file *file) -{ - struct ion_boost_pool *data = PDE_DATA(inode); - return single_open(file, boost_pool_stat_proc_show, data); -} - -static const struct file_operations boost_pool_stat_proc_ops = { - .owner = THIS_MODULE, - .open = boost_pool_stat_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -struct ion_boost_pool *boost_pool_create(unsigned int ion_flag, - unsigned int nr_pages, - struct proc_dir_entry *root_dir, - char *name) -{ - bool graphic_buffer_flag = true; - struct task_struct *tsk; - struct ion_boost_pool *boost_pool; - char buf[128]; - struct cpumask mask; - int end_cpu = 3; - - if (NULL == root_dir) { - pr_err("boost_pool dir not exits.\n"); - return NULL; - } - pr_info("%d boost_pool.\n", NUM_ORDERS); - - boost_pool = kzalloc(sizeof(struct ion_boost_pool) + - sizeof(struct ion_page_pool *) * NUM_ORDERS, - GFP_KERNEL); - - if (NULL == boost_pool) { - pr_err("%s: boost_pool is NULL!\n", __func__); - return NULL; - } - - if (ion_heap_create_pools(boost_pool->pools, - ion_flag == ION_FLAG_CACHED, - graphic_buffer_flag)) - goto free_heap; - - boost_pool->origin = boost_pool->high = boost_pool->low = nr_pages; - boost_pool->name = name; - boost_pool->flag = ion_flag; - - boost_pool->proc_info = proc_create_data(name, 0666, - root_dir, - &boost_pool_proc_ops, - boost_pool); - if (IS_ERR_OR_NULL(boost_pool->proc_info)) { - pr_info("Unable to initialise /proc/%s\n", - name); - goto destroy_pools; - } else { - pr_info("procfs entry /proc/%s allocated. data=%p\n", - name, boost_pool); - } - - snprintf(buf, 128, "%s_low", name); - boost_pool->proc_low_info = proc_create_data(buf, 0666, - root_dir, - &boost_pool_low_proc_ops, - boost_pool); - if (IS_ERR_OR_NULL(boost_pool->proc_low_info)) { - pr_info("Unable to initialise /proc/boost_pool/%s_low\n", - name); - goto destroy_proc_info; - } else { - pr_info("procfs entry /proc/boost_pool/%s_low allocated.\n", - name); - } - - snprintf(buf, 128, "%s_stat", name); - boost_pool->proc_stat = proc_create_data(buf, 0444, - root_dir, - &boost_pool_stat_proc_ops, - boost_pool); - if (IS_ERR_OR_NULL(boost_pool->proc_stat)) { - pr_info("Unable to initialise /proc/boost_pool/%s_stat\n", - name); - goto destroy_proc_low_info; - } else { - pr_info("procfs entry /proc/boost_pool/%s_stat allocated.\n", - name); - } - - init_waitqueue_head(&boost_pool->waitq); - tsk = kthread_run(boost_pool_kworkthread, boost_pool, - "%s", name); - if (IS_ERR_OR_NULL(tsk)) { - pr_err("%s: kthread_create failed!\n", __func__); - goto destroy_proc_stat; - } - boost_pool->tsk = tsk; - set_cpumask(end_cpu, &mask); - set_cpus_allowed_ptr(tsk, &mask); - - mutex_init(&boost_pool->prefill_mutex); - init_waitqueue_head(&boost_pool->prefill_waitq); - - tsk = kthread_run(boost_prefill_kworkthread, boost_pool, - "bp_prefill_%s", name); - if (IS_ERR_OR_NULL(tsk)) { - pr_err("%s: kthread_create failed!\n", __func__); - goto destroy_proc_stat; - } - boost_pool->prefill_tsk = tsk; - set_cpus_allowed_ptr(tsk, &mask); - - boost_pool_wakeup_process(boost_pool); - - return boost_pool; - -destroy_proc_stat: - proc_remove(boost_pool->proc_stat); -destroy_proc_low_info: - proc_remove(boost_pool->proc_low_info); -destroy_proc_info: - proc_remove(boost_pool->proc_info); -destroy_pools: - ion_heap_destroy_pools(boost_pool->pools); -free_heap: - kfree(boost_pool); - boost_pool = NULL; - - return NULL; -} - -static wait_queue_head_t kcrit_scene_wait; -static int kcrit_scene_flag = 0; -static unsigned int kcrit_scene_proc_poll(struct file *file, poll_table *table) -{ - int mask = 0; - - poll_wait(file, &kcrit_scene_wait, table); - - if (kcrit_scene_flag == 1) { - mask |= POLLIN | POLLRDNORM; - kcrit_scene_flag = 0; - } - return mask; -} - -static int kcrit_scene_proc_open(struct inode *inode, struct file *file) -{ - return nonseekable_open(inode, file); -} - -static int kcrit_scene_proc_release(struct inode *inode, struct file *file) -{ - return 0; -} - -/* TODO add read ops. */ -static const struct file_operations kcrit_scene_proc_fops = { - .owner = THIS_MODULE, - .open = kcrit_scene_proc_open, - .release = kcrit_scene_proc_release, - .poll = kcrit_scene_proc_poll, -}; - -bool kcrit_scene_init(void) -{ - init_waitqueue_head(&kcrit_scene_wait); - return proc_create("kcritical_scene", S_IRUGO, NULL, - &kcrit_scene_proc_fops) != NULL; -} - -static void kcrit_scene_wakeup_lmkd(void) -{ - kcrit_scene_flag = 1; - wake_up_interruptible(&kcrit_scene_wait); -} -module_param_named(debug_boost_pool_enable, boost_pool_enable, bool, 0644); diff --git a/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.h b/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.h deleted file mode 100644 index e111dda568b9..000000000000 --- a/drivers/staging/android/ion/mtk/oplus_ion_boost_pool.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _ION_BOOST_POOL_H -#define _ION_BOOST_POOL_H - -#include -#include - -#include "ion_priv.h" - -#define LOWORDER_WATER_MASK (64*4) -#define MAX_POOL_SIZE (128*64*4) - -struct ion_boost_pool { - char *name; - struct task_struct *tsk, *prefill_tsk; - bool force_stop, prefill; - int low, high, origin; - unsigned long flag; - unsigned int wait_flag, prefill_wait_flag; - wait_queue_head_t waitq, prefill_waitq; - struct mutex prefill_mutex; - struct proc_dir_entry *proc_info, *proc_low_info, *proc_stat; - struct ion_page_pool *pools[0]; -}; - -#define ION_FLAG_GRAPHIC_BUFFER BIT(20) -#define ION_FLAG_CAMERA_BUFFER BIT(21) - -struct page *boost_pool_allocate(struct ion_boost_pool *pool, - unsigned long size, unsigned int max_order); -int boost_pool_free(struct ion_boost_pool *pool, struct page *page, - int order); -int boost_pool_shrink(struct ion_boost_pool *boost_pool, - struct ion_page_pool *pool, gfp_t gfp_mask, - int nr_to_scan); -struct ion_boost_pool *boost_pool_create(unsigned int ion_flag, - unsigned int nr_pages, - struct proc_dir_entry *root_dir, - char *name); -void boost_pool_wakeup_process(struct ion_boost_pool *pool); -void boost_pool_dec_high(struct ion_boost_pool *pool, int nr_pages); -void boost_pool_dump(struct ion_boost_pool *pool); - -bool kcrit_scene_init(void); -#endif /* _ION_SMART_POOL_H */ diff --git a/drivers/staging/android/ion/oplus_ion/Makefile b/drivers/staging/android/ion/oplus_ion/Makefile deleted file mode 100644 index 805a54eaca57..000000000000 --- a/drivers/staging/android/ion/oplus_ion/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -#//Jiheng.Xie@TECH.BSP.Performance.Sched, 2020/04/07, Add for Healthinfo monitor -obj-y += ion.o -#endif /* OPLUS_FEATURE_HEALTHINFO */ - diff --git a/drivers/staging/android/ion/oplus_ion/ion.c b/drivers/staging/android/ion/oplus_ion/ion.c deleted file mode 100644 index 6300081bcebd..000000000000 --- a/drivers/staging/android/ion/oplus_ion/ion.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -atomic_long_t ion_total_size; -bool ion_cnt_enable = true; - -unsigned long ion_total(void) -{ - if (!ion_cnt_enable) - return 0; - return (unsigned long)atomic_long_read(&ion_total_size); -} diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 5900c811ce5b..227781d6ede7 100755 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -159,19 +159,6 @@ static struct sysrq_key_op sysrq_reboot_op = { .enable_mask = SYSRQ_ENABLE_BOOT, }; -#ifdef CONFIG_OPLUS_FEATURE_PANIC_FLUSH -extern int panic_flush_device_cache(int timeout); -static void sysrq_handle_flush(int key) -{ - panic_flush_device_cache(0); -} -static struct sysrq_key_op sysrq_flush_op = { - .handler = sysrq_handle_flush, - .help_msg = "flush(y)", - .action_msg = "Emergency Flush", - .enable_mask = SYSRQ_ENABLE_SYNC, -}; -#endif static void sysrq_handle_sync(int key) { @@ -496,11 +483,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = { /* x: May be registered on sparc64 for global PMU dump */ NULL, /* x */ /* y: May be registered on sparc64 for global register dump */ -#ifdef CONFIG_OPLUS_FEATURE_PANIC_FLUSH - &sysrq_flush_op, /* y */ -#else NULL, /* y */ -#endif &sysrq_ftrace_dump_op, /* z */ }; diff --git a/drivers/watchdog/mediatek/wdk/wd_api.c b/drivers/watchdog/mediatek/wdk/wd_api.c index 82a161419684..a240f651c5ca 100755 --- a/drivers/watchdog/mediatek/wdk/wd_api.c +++ b/drivers/watchdog/mediatek/wdk/wd_api.c @@ -707,10 +707,6 @@ void arch_reset(char mode, const char *cmd) oppo_rtc_mark_safe(); } else if (cmd && !strcmp(cmd, "edl")) { oppo_rtc_mark_edl(); -#ifdef OPLUS_FEATURE_AGINGTEST - } else if (cmd && (!strcmp(cmd, "sblmemtest") || !strcmp(cmd, "usermemaging"))) { - oppo_rtc_mark_agingtest(); -#endif /*OPLUS_FEATURE_AGINGTEST */ #endif } else { reboot = WD_SW_RESET_BYPASS_PWR_KEY; diff --git a/fs/block_dev.c b/fs/block_dev.c index b0141aa0582e..9584df0e29b1 100755 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -35,9 +35,6 @@ #include #include #include "internal.h" -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ struct bdev_inode { struct block_device bdev; @@ -259,9 +256,6 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, bio.bi_opf = dio_bio_write_op(iocb); task_io_account_write(ret); } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(DIO_WRITE, file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ qc = submit_bio(&bio); for (;;) { @@ -403,9 +397,6 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) } else { bio->bi_opf = dio_bio_write_op(iocb); task_io_account_write(bio->bi_iter.bi_size); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(DIO_WRITE, file, bio->bi_iter.bi_size); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } dio->size += bio->bi_iter.bi_size; diff --git a/fs/direct-io.c b/fs/direct-io.c index e687396790ac..094421f05fda 100755 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -38,9 +38,6 @@ #include #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ /* * How many user pages to map in one call to get_user_pages(). This determines @@ -879,9 +876,6 @@ submit_page_section(struct dio *dio, struct dio_submit *sdio, struct page *page, * Read accounting is performed in submit_bio() */ task_io_account_write(len); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(DIO_WRITE, NULL, len); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } /* diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 0951b012017d..3d8543580f45 100755 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1826,15 +1826,9 @@ fetch_events: } spin_unlock_irqrestore(&ep->lock, flags); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_epoll = 1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ if (!freezable_schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS)) timed_out = 1; -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_epoll = 0; -#endif /* OPLUS_FEATURE_HEALTHINFO */ spin_lock_irqsave(&ep->lock, flags); } diff --git a/fs/exec.c b/fs/exec.c index 5cc199f8aba7..836ee524aa45 100755 --- a/fs/exec.c +++ b/fs/exec.c @@ -1237,9 +1237,6 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) task_lock(tsk); trace_task_rename(tsk, buf); strlcpy(tsk->comm, buf, sizeof(tsk->comm)); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - sched_assist_target_comm(tsk); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ task_unlock(tsk); perf_event_comm(tsk, exec); mtk_pidmap_update(tsk); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fae4659706da..594c386b4818 100755 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -28,9 +28,6 @@ #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ #ifdef CONFIG_F2FS_CHECK_FS #define f2fs_bug_on(sbi, condition) BUG_ON(condition) @@ -3082,12 +3079,6 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, spin_lock(&sbi->iostat_lock); sbi->rw_iostat[type] += io_bytes; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (type == FS_GC_DATA_IO || type == FS_GC_NODE_IO) - iomonitor_update_fs_stats(FS_GC_OPT, 1); - else if (type == FS_DISCARD) - iomonitor_update_fs_stats(FS_DISCARD_OPT, 1); -#endif /*OPLUS_FEATURE_IOMONITOR*/ if (type == APP_WRITE_IO || type == APP_DIRECT_IO) sbi->rw_iostat[APP_BUFFERED_IO] = diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index ff624c9d5162..9317e0db2839 100755 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3882,11 +3882,6 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) allow_outplace_dio(inode, iocb, from)) goto write; -#ifdef CONFIG_HYBRIDSWAP_CORE - if (f2fs_overwrite_io(inode, iocb->ki_pos, - iov_iter_count(from))) - goto write; -#endif } preallocated = true; target_size = iocb->ki_pos + iov_iter_count(from); diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index beab4b70e1b5..727641a4b435 100755 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -29,9 +29,6 @@ #include #include #include "internal.h" -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ /* * 4MB minimal write chunk size @@ -1991,9 +1988,6 @@ void wb_workfn(struct work_struct *work) WB_REASON_FORKER_THREAD); trace_writeback_pages_written(pages_written); } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_fs_stats(FS_DIRTY_PAGES, pages_written); -#endif /*OPLUS_FEATURE_IOMONITOR*/ if (!list_empty(&wb->work_list)) wb_wakeup(wb); else if (wb_has_dirty_io(wb) && dirty_writeback_interval) diff --git a/fs/iomap.c b/fs/iomap.c index 879913992b25..1e573a59ea71 100755 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -28,9 +28,6 @@ #include #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ #include "internal.h" @@ -933,9 +930,6 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, if (dio->flags & IOMAP_DIO_WRITE) { bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_SYNC | REQ_IDLE); task_io_account_write(bio->bi_iter.bi_size); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(DIO_WRITE, NULL, n); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } else { bio_set_op_attrs(bio, REQ_OP_READ, 0); if (dio->flags & IOMAP_DIO_DIRTY) diff --git a/fs/pipe.c b/fs/pipe.c index 73fcabd4e0e8..e743bf99aec3 100755 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1104,58 +1104,6 @@ static inline unsigned int round_pipe_size(unsigned int size) return roundup_pow_of_two(nr_pages) << PAGE_SHIFT; } -#ifdef OPLUS_BUG_STABILITY -//Weitao.Chen@ANDROID.STABILITY, 2020/11/07, Add for avoiding critical process set pipe buffer error -static inline bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - - struct task_struct * first_child = NULL; - if(t->children.next && t->children.next != (struct list_head*)&t->children.next) - first_child = container_of(t->children.next, struct task_struct, sibling); - if(!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 && !strcmp(t->parent->comm,"init")) ) - return true; - else - return false; - return false; -} -#define SYSTEM_APP_UID 1000 -static inline bool is_system_uid(struct task_struct *t) -{ - int cur_uid; - cur_uid = task_uid(t).val; - if (cur_uid == SYSTEM_APP_UID) - return true; - - return false; -} - -static inline bool is_system_process(struct task_struct *t) -{ - pr_err("in system_process, t->comm is %s,grouplead command is %s",t->comm,t->group_leader->comm); - if (is_system_uid(t)) { - if (t->group_leader && (!strncmp(t->group_leader->comm,"system_server", 13) || - !strncmp(t->group_leader->comm, "surfaceflinger", 14) || - !strncmp(t->group_leader->comm, "Binder:", 7) || - !strncmp(t->group_leader->comm, "sensor", 6) || - !strncmp(t->group_leader->comm, "suspend", 7) || - !strncmp(t->group_leader->comm, "composer", 8))) - return true; - } - return false; -} - -static inline bool is_critial_process(struct task_struct *t) -{ - if( is_zygote_process(t) || is_system_process(t)) { - pr_err("in pipe set buffer size, critical svc, we are not gonna return EPERM"); - return true; - } - - return false; -} -#endif /* OPLUS_BUG_STABILITY */ - /* * Allocate a new array of pipe buffers and copy the info over. Returns the * pipe size if successful, or return -ERROR on error. @@ -1182,30 +1130,16 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg) * Decreasing the pipe capacity is always permitted, even * if the user is currently over a limit. */ -#ifndef OPLUS_BUG_STABILITY -//Weitao.Chen@ANDROID.STABILITY, 2020/11/07, Add for avoiding critical process set pipe buffer error if (nr_pages > pipe->buffers && size > pipe_max_size && !capable(CAP_SYS_RESOURCE)) -#else /* OPLUS_BUG_STABILITY */ - if (nr_pages > pipe->buffers && - size > pipe_max_size && !capable(CAP_SYS_RESOURCE) && !is_critial_process(current)) -#endif /* OPLUS_BUG_STABILITY */ return -EPERM; user_bufs = account_pipe_buffers(pipe->user, pipe->buffers, nr_pages); -#ifndef OPLUS_BUG_STABILITY -//Weitao.Chen@ANDROID.STABILITY, 2020/11/07, Add for avoiding critical process set pipe buffer error if (nr_pages > pipe->buffers && (too_many_pipe_buffers_hard(user_bufs) || too_many_pipe_buffers_soft(user_bufs)) && is_unprivileged_user()) { -#else /* OPLUS_BUG_STABILITY */ - if (nr_pages > pipe->buffers && - (too_many_pipe_buffers_hard(user_bufs) || - too_many_pipe_buffers_soft(user_bufs)) && - is_unprivileged_user() && !is_critial_process(current)) { -#endif /* OPLUS_BUG_STABILITY */ ret = -EPERM; goto out_revert_acct; } diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index 94103f17333e..08dce22afec1 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -88,11 +88,3 @@ config PROC_UID depends on PROC_FS && RT_MUTEXES help Provides aggregated per-uid information under /proc/uid. - -#ifdef OPLUS_FEATURE_HEALTHINFO -source fs/proc/healthinfo/Kconfig -#endif /*OPLUS_FEATURE_HEALTHINFO*/ - -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -source "fs/proc/task_cpustats/Kconfig" -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ diff --git a/fs/proc/Makefile b/fs/proc/Makefile index aeb121150737..d8dcb188db6d 100644 --- a/fs/proc/Makefile +++ b/fs/proc/Makefile @@ -33,11 +33,3 @@ proc-$(CONFIG_PROC_KCORE) += kcore.o proc-$(CONFIG_PROC_VMCORE) += vmcore.o proc-$(CONFIG_PRINTK) += kmsg.o proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o - -#ifdef OPLUS_FEATURE_HEALTHINFO -obj-y += healthinfo/ -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -obj-$(CONFIG_OPLUS_CTP) += task_cpustats/ -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ diff --git a/fs/proc/array.c b/fs/proc/array.c index 8d779e69c556..53218b29694d 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -644,24 +644,6 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, return 0; } -#ifdef OPLUS_FEATURE_PERFORMANCE -int proc_pid_statm_as(struct seq_file *m, struct pid_namespace *ns, - struct pid *pid, struct task_struct *task) -{ - unsigned long size = 0; - struct mm_struct *mm = get_task_mm(task); - - if (mm) { - size = get_mm_counter(mm, MM_ANONPAGES) + - get_mm_counter(mm, MM_SWAPENTS); - mmput(mm); - } - seq_put_decimal_ull(m, "", size); - seq_putc(m, '\n'); - - return 0; -} -#endif /* OPLUS_FEATURE_PERFORMANCE */ #ifdef CONFIG_PROC_CHILDREN static struct pid * diff --git a/fs/proc/base.c b/fs/proc/base.c index 8bbc576f8692..5b5ded6c4a01 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -103,22 +103,6 @@ #include "../../lib/kstrtox.h" -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) -#include -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#define GLOBAL_SYSTEM_UID KUIDT_INIT(1000) -#define GLOBAL_SYSTEM_GID KGIDT_INIT(1000) -extern const struct file_operations proc_ux_state_operations; -extern bool is_special_entry(struct dentry *dentry, const char* special_proc); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - -#ifdef OPLUS_BUG_STABILITY -extern size_t get_ion_heap_by_pid(pid_t pid); -extern int get_gl_mem_by_pid(pid_t pid); -#endif - /* NOTE: * Implementing inode permission operations in /proc is almost * certainly an error. Permission checks need to happen during @@ -398,57 +382,6 @@ static const struct file_operations proc_pid_cmdline_ops = { .llseek = generic_file_llseek, }; -#ifdef OPLUS_BUG_STABILITY -#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ - -static ssize_t proc_pid_real_phymemory_read(struct file *file, char __user *buf, - size_t _count, loff_t *pos) -{ - struct task_struct *tsk; - struct task_struct *p; - char buffer[128]; - unsigned long rss = 0; - unsigned long rswap = 0; - unsigned long ion = 0; - unsigned long gpu = 0; - unsigned long totalram_size = 0; - size_t len; - - BUG_ON(*pos < 0); - - tsk = get_proc_task(file_inode(file)); //first_tid find will get_proc_task - if (!tsk) - return 0; - if (tsk->flags & PF_KTHREAD) { - put_task_struct(tsk); - return 0; - } - put_task_struct(tsk); - - tsk = tsk->group_leader; - get_task_struct(tsk); - ion = get_ion_heap_by_pid(tsk->pid); - gpu = get_gl_mem_by_pid(tsk->pid); - - p = find_lock_task_mm(tsk); - if (p) { - rss = P2K(get_mm_rss(p->mm)); - rswap = P2K(get_mm_counter(p->mm, MM_SWAPENTS)); - task_unlock(p); - } - totalram_size = ion + gpu + rss + rswap; - put_task_struct(tsk); - len = snprintf(buffer, sizeof(buffer), "RSS:%luKB \nRswap:%luKB \nION:%luKB \nGPU:%luKB \nTotalsize:%luKB \n", - rss, rswap, ion, gpu, totalram_size); - return simple_read_from_buffer(buf, _count, pos, buffer, len); -} - -static const struct file_operations proc_pid_real_phymemory_ops = { - .read = proc_pid_real_phymemory_read, - .llseek = generic_file_llseek, -}; -#endif - #ifdef CONFIG_KALLSYMS /* * Provides a wchan file via kallsyms in a proper one-value-per-file format. @@ -1943,12 +1876,6 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags) if (task) { task_dump_owner(task, inode->i_mode, &inode->i_uid, &inode->i_gid); -#ifdef OPLUS_FEATURE_USCHED_ASSIST - if (is_special_entry(dentry, "ux_state")) { - inode->i_uid = GLOBAL_SYSTEM_UID; - inode->i_gid = GLOBAL_SYSTEM_GID; - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ inode->i_mode &= ~(S_ISUID | S_ISGID); security_task_to_inode(task, inode); put_task_struct(task); @@ -3088,9 +3015,6 @@ static const struct pid_entry tgid_base_stuff[] = { REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), ONE("stat", S_IRUGO, proc_tgid_stat), ONE("statm", S_IRUGO, proc_pid_statm), -#ifdef OPLUS_FEATURE_PERFORMANCE - ONE("statm_as", S_IRUGO, proc_pid_statm_as), -#endif /* OPLUS_FEATURE_PERFORMANCE */ REG("maps", S_IRUGO, proc_pid_maps_operations), #ifdef CONFIG_NUMA REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), @@ -3168,14 +3092,6 @@ static const struct pid_entry tgid_base_stuff[] = { #ifdef CONFIG_CPU_FREQ_TIMES ONE("time_in_state", 0444, proc_time_in_state_show), #endif - -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - REG("jank_info", S_IRUGO | S_IWUGO, proc_jank_trace_operations), -#endif /* OPLUS_FEATURE_HEALTHINFO */ - -#ifdef OPLUS_BUG_STABILITY - REG("real_phymemory", S_IRUGO, proc_pid_real_phymemory_ops), -#endif }; static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx) @@ -3506,9 +3422,6 @@ static const struct pid_entry tid_base_stuff[] = { REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), ONE("stat", S_IRUGO, proc_tid_stat), ONE("statm", S_IRUGO, proc_pid_statm), -#ifdef OPLUS_FEATURE_PERFORMANCE - ONE("statm_as", S_IRUGO, proc_pid_statm_as), -#endif /* OPLUS_FEATURE_PERFORMANCE */ REG("maps", S_IRUGO, proc_pid_maps_operations), #ifdef CONFIG_PROC_CHILDREN REG("children", S_IRUGO, proc_tid_children_operations), @@ -3584,14 +3497,6 @@ static const struct pid_entry tid_base_stuff[] = { #ifdef CONFIG_MTK_TASK_TURBO ONE("turbo", 0444, proc_turbo_task_show), #endif - -#ifdef OPLUS_FEATURE_SCHED_ASSIST - REG("ux_state", S_IRUGO | S_IWUGO, proc_ux_state_operations), -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - -#ifdef OPLUS_BUG_STABILITY - REG("real_phymemory", S_IRUGO, proc_pid_real_phymemory_ops), -#endif }; static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx) diff --git a/fs/proc/healthinfo/Kconfig b/fs/proc/healthinfo/Kconfig deleted file mode 100644 index d6a62075451d..000000000000 --- a/fs/proc/healthinfo/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -config FG_TASK_UID - bool "Enable /proc/fg_info/ if EXPERT" - default y - help - Add foreground process optimize support to promote performance . -#endif -#ifdef OPLUS_FEATURE_HEALTHINFO -#Liujie.Xie@TECH.Kernel.Sched, 2020/05/20, add jank monitor opt support -config OPLUS_JANK_INFO - bool "Enable /proc/pid/jank_info if EXPERT" - default n - help - Add jank monitor opt support . -#endif diff --git a/fs/proc/healthinfo/Makefile b/fs/proc/healthinfo/Makefile deleted file mode 100644 index 28ebfdc0730c..000000000000 --- a/fs/proc/healthinfo/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -#Jiheng.Xie@TECH.BSP.Performance.Sched, 2020/04/07, Add for Healthinfo monitor -obj-$(CONFIG_OPLUS_HEALTHINFO) += cpuload.o -#Liujie.Xie@TECH.BSP.Kernel.Sched, 2020/05/07, Add for Jank monitor -obj-$(CONFIG_OPLUS_JANK_INFO) += jank_monitor.o -#endif /* OPLUS_FEATURE_HEALTHINFO */ -obj-$(CONFIG_FG_TASK_UID) += fg_uid/ diff --git a/fs/proc/healthinfo/cpuload.c b/fs/proc/healthinfo/cpuload.c deleted file mode 100755 index f3c5da390ea6..000000000000 --- a/fs/proc/healthinfo/cpuload.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -extern u64 get_idle_time(int cpu); -extern u64 get_iowait_time(int cpu); -#else -extern u64 get_idle_time(struct kernel_cpustat *kcs, int cpu); -extern u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu); -#endif - -struct cpu_load_stat { - u64 t_user; - u64 t_system; - u64 t_idle; - u64 t_iowait; - u64 t_irq; - u64 t_softirq; -}; - -#define OPPO_CPUTIME -int ohm_get_cur_cpuload(bool ctrl) -{ - int i; - struct cpu_load_stat cpu_load = { 0, 0, 0, 0, 0, 0}; - struct cpu_load_stat cpu_load_temp = { 0, 0, 0, 0, 0, 0}; - clock_t ct_user, ct_system, ct_idle, ct_iowait, ct_irq, ct_softirq, load, sum = 0; - if (!ctrl) - return -1; - - for_each_online_cpu(i) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - struct kernel_cpustat *kcs = &kcpustat_cpu(i); -#endif - cpu_load_temp.t_user += kcpustat_cpu(i).cpustat[CPUTIME_USER]; - cpu_load_temp.t_system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) - cpu_load_temp.t_idle += get_idle_time(i); - cpu_load_temp.t_iowait += get_iowait_time(i); -#else - cpu_load_temp.t_idle += get_idle_time(kcs, i); - cpu_load_temp.t_iowait += get_iowait_time(kcs, i); -#endif - cpu_load_temp.t_irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; - cpu_load_temp.t_softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; - } - msleep(25); - for_each_online_cpu(i) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - struct kernel_cpustat *kcs = &kcpustat_cpu(i); -#endif - cpu_load.t_user += kcpustat_cpu(i).cpustat[CPUTIME_USER]; - cpu_load.t_system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) - cpu_load.t_idle += get_idle_time(i); - cpu_load.t_iowait += get_iowait_time(i); -#else - cpu_load.t_idle += get_idle_time(kcs, i); - cpu_load.t_iowait += get_iowait_time(kcs, i); -#endif - cpu_load.t_irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; - cpu_load.t_softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; - } - - ct_user = nsec_to_clock_t(cpu_load.t_user) - nsec_to_clock_t(cpu_load_temp.t_user); - ct_system = nsec_to_clock_t(cpu_load.t_system) - nsec_to_clock_t(cpu_load_temp.t_system); - ct_idle = nsec_to_clock_t(cpu_load.t_idle) - nsec_to_clock_t(cpu_load_temp.t_idle); - ct_iowait = nsec_to_clock_t(cpu_load.t_iowait) - nsec_to_clock_t(cpu_load_temp.t_iowait); - ct_irq = nsec_to_clock_t(cpu_load.t_irq) - nsec_to_clock_t(cpu_load_temp.t_irq); - ct_softirq = nsec_to_clock_t(cpu_load.t_softirq) - nsec_to_clock_t(cpu_load_temp.t_softirq); - - sum = ct_user + ct_system + ct_idle + ct_iowait + ct_irq + ct_softirq; - load = ct_user + ct_system + ct_iowait + ct_irq + ct_softirq; - - if (sum == 0) - return -1; - - return 100 * load / sum; -} -EXPORT_SYMBOL(ohm_get_cur_cpuload); diff --git a/fs/proc/healthinfo/fg_uid/Makefile b/fs/proc/healthinfo/fg_uid/Makefile deleted file mode 100644 index 6310edafadba..000000000000 --- a/fs/proc/healthinfo/fg_uid/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -obj-y += fg_uid.o - diff --git a/fs/proc/healthinfo/fg_uid/fg_uid.c b/fs/proc/healthinfo/fg_uid/fg_uid.c deleted file mode 100755 index d2d0800b6c00..000000000000 --- a/fs/proc/healthinfo/fg_uid/fg_uid.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include <../fs/proc/internal.h> -#include "fg_uid.h" - -#define FG_RW (S_IWUSR|S_IRUSR|S_IWGRP|S_IRGRP|S_IWOTH|S_IROTH) - -struct fg_info fginfo = { - .fg_num = 0, - .fg_uids = -555, -}; - -static struct proc_dir_entry *fg_dir; - -bool is_fg(int uid) -{ - bool ret = false; - - if (uid == fginfo.fg_uids) - ret = true; - return ret; -} - -EXPORT_SYMBOL_GPL(is_fg); - -static int fg_uids_show(struct seq_file *m, void *v) -{ - seq_printf(m, "fg_uids: %d\n", fginfo.fg_uids); - return 0; -} - -static int fg_uids_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, fg_uids_show, inode); -} - -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -extern void oblist_dequeue_topapp_change(uid_t topuid); -#endif -static ssize_t fg_uids_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[MAX_ARRAY_LENGTH]; - int err = 0; - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user((void *)buffer, buf, count)) { - err = -EFAULT; - goto out; - } - fginfo.fg_uids = simple_strtol(buffer, NULL, 0); - fginfo.fg_num = 1; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - if (fginfo.fg_uids > 0) - oblist_dequeue_topapp_change(fginfo.fg_uids); -#endif -out: - return err < 0 ? err : count; -} - -static const struct file_operations proc_fg_uids_operations = { - .open = fg_uids_open, - .read = seq_read, - .write = fg_uids_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static void uids_proc_fs_init(struct proc_dir_entry *p_parent) -{ - struct proc_dir_entry *p_temp; - - if (!p_parent) - goto out_p_temp; - p_temp = proc_create(FS_FG_UIDS, FG_RW, p_parent, &proc_fg_uids_operations); - if (!p_temp) - goto out_p_temp; - -out_p_temp: - return; -} - -static int __init fg_uids_init(void) -{ - struct proc_dir_entry *p_parent; - - p_parent = proc_mkdir(FS_FG_INFO_PATH, fg_dir); - if (!p_parent) - return -ENOMEM; - uids_proc_fs_init(p_parent); - return 0; -} - -static void __exit fg_uids_exit(void) -{ - if (!fg_dir) - return; - remove_proc_entry(FS_FG_UIDS, fg_dir); -} - -module_init(fg_uids_init); -module_exit(fg_uids_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("OPLUS"); -MODULE_DESCRIPTION("optimize foreground process to promote performance"); diff --git a/fs/proc/healthinfo/fg_uid/fg_uid.h b/fs/proc/healthinfo/fg_uid/fg_uid.h deleted file mode 100644 index 23be1d619d9c..000000000000 --- a/fs/proc/healthinfo/fg_uid/fg_uid.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#ifndef _FG_UID_H -#define _FG_UID_H - -#include - -#define MAX_ARRAY_LENGTH 256 -#define FS_FG_INFO_PATH "fg_info" -#define FS_FG_UIDS "fg_uids" - -extern bool is_fg(int uid); -struct fg_info { - int fg_num; - int fg_uids; -}; - -#endif /*_FG_UID_H*/ - diff --git a/fs/proc/healthinfo/jank_monitor.c b/fs/proc/healthinfo/jank_monitor.c deleted file mode 100755 index 7995789ef968..000000000000 --- a/fs/proc/healthinfo/jank_monitor.c +++ /dev/null @@ -1,171 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include -#include <../fs/proc/internal.h> -#include <../kernel/sched/sched.h> - -#include - -void update_jank_trace_info(struct task_struct *tsk, int trace_type, unsigned int cpu, u64 delta) -{ - struct root_domain *rd = NULL; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - static unsigned int ltt_cpu_nr = 0; -#endif /*CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - - if (!tsk->jank_trace) { - return; - } - - rd = cpu_rq(smp_processor_id())->rd; - - if (!rd) - return; - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (!ltt_cpu_nr) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#ifdef CONFIG_SCHED_WALT - ltt_cpu_nr = cpumask_weight(topology_core_cpumask(rd->wrd.min_cap_orig_cpu)); -#else - ltt_cpu_nr = 4; -#endif -#else /* KERNEL_VERSION */ - ltt_cpu_nr = cpumask_weight(topology_core_cpumask(rd->min_cap_orig_cpu)); -#endif /* KERNEL_VERSION */ - } -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ - - if (trace_type == JANK_TRACE_RUNNABLE) { - tsk->jank_info.runnable_state += delta; - } else if (trace_type == JANK_TRACE_DSTATE) { - tsk->jank_info.d_state.cnt++; - if (tsk->in_iowait) { - tsk->jank_info.d_state.iowait_ns += delta; - } else if (tsk->in_mutex) { - tsk->jank_info.d_state.mutex_ns += delta; - } else if (tsk->in_downread) { - tsk->jank_info.d_state.downread_ns += delta; - } else if (tsk->in_downwrite) { - tsk->jank_info.d_state.downwrite_ns += delta; - } else { - tsk->jank_info.d_state.other_ns += delta; - } - } else if (trace_type == JANK_TRACE_SSTATE) { - tsk->jank_info.s_state.cnt++; - if (tsk->in_binder) { - tsk->jank_info.s_state.binder_ns += delta; - } else if (tsk->in_futex) { - tsk->jank_info.s_state.futex_ns += delta; - } else if (tsk->in_epoll) { - tsk->jank_info.s_state.epoll_ns += delta; - } else { - tsk->jank_info.s_state.other_ns += delta; - } - } else if (trace_type == JANK_TRACE_RUNNING) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) && !defined(CONFIG_SCHED_WALT) - bool ltt_cpu = capacity_orig_of(cpu) < rd->max_cpu_capacity.val; -#else - bool ltt_cpu = cpu < ltt_cpu_nr; -#endif -#else /*CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - bool ltt_cpu = capacity_orig_of(cpu) < rd->max_cpu_capacity.val; -#endif /*CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - if (ltt_cpu) { - tsk->jank_info.ltt_running_state += delta; - } else { - tsk->jank_info.big_running_state += delta; - } - } -} - -static int proc_jank_trace_show(struct seq_file *m, void *v) -{ - struct inode *inode = m->private; - struct task_struct *p; - u64 d_time, s_time, ltt_time, big_time, rn_time, iow_time, binder_time, futex_time; - p = get_proc_task(inode); - if (!p) { - return -ESRCH; - } - task_lock(p); - iow_time = p->jank_info.d_state.iowait_ns; - binder_time = p->jank_info.s_state.binder_ns; - futex_time = p->jank_info.s_state.futex_ns; - - d_time = p->jank_info.d_state.iowait_ns + p->jank_info.d_state.mutex_ns + - p->jank_info.d_state.downread_ns + p->jank_info.d_state.downwrite_ns + - p->jank_info.d_state.other_ns; - - s_time = p->jank_info.s_state.binder_ns + p->jank_info.s_state.futex_ns + - p->jank_info.s_state.epoll_ns + p->jank_info.s_state.other_ns; - - ltt_time = p->jank_info.ltt_running_state; - - big_time = p->jank_info.big_running_state; - - rn_time = p->jank_info.runnable_state; - - task_unlock(p); - - seq_printf(m, "BR:%llu LR:%llu RN:%llu D:%llu IOW:%llu S:%llu BD:%llu FT:%llu\n", - big_time / NSEC_PER_MSEC, ltt_time / NSEC_PER_MSEC, rn_time / NSEC_PER_MSEC, - d_time / NSEC_PER_MSEC, iow_time / NSEC_PER_MSEC, - s_time / NSEC_PER_MSEC, binder_time / NSEC_PER_MSEC, futex_time / NSEC_PER_MSEC); - put_task_struct(p); - return 0; -} - -static int proc_jank_trace_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, proc_jank_trace_show, inode); -} - -static ssize_t proc_jank_trace_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - struct task_struct *task; - char buffer[PROC_NUMBUF]; - int err, jank_trace; - - memset(buffer, 0, sizeof(buffer)); - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) { - return -EFAULT; - } - - err = kstrtoint(strstrip(buffer), 0, &jank_trace); - if(err) { - return err; - } - task = get_proc_task(file_inode(file)); - if (!task) { - return -ESRCH; - } - - if (jank_trace == 1) { - task->jank_trace = 1; - } else if (jank_trace == 0) { - task->jank_trace = 0; - memset(&task->jank_info, 0, sizeof(struct jank_monitor_info)); - } - - put_task_struct(task); - return count; -} - -const struct file_operations proc_jank_trace_operations = { - .open = proc_jank_trace_open, - .write = proc_jank_trace_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; diff --git a/fs/proc/internal.h b/fs/proc/internal.h index d4b246d241ec..7e36df441ca9 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -146,10 +146,6 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *, struct pid *, struct task_struct *); extern int proc_pid_statm(struct seq_file *, struct pid_namespace *, struct pid *, struct task_struct *); -#ifdef OPLUS_FEATURE_PERFORMANCE -extern int proc_pid_statm_as(struct seq_file *m, struct pid_namespace *ns, - struct pid *pid, struct task_struct *task); -#endif /* OPLUS_FEATURE_PERFORMANCE */ /* * base.c diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index d0819e6db2e0..9e33510e5ba4 100755 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -20,15 +20,8 @@ #include #include "internal.h" -#ifdef OPLUS_FEATURE_HEALTHINFO -#include -#endif /*OPLUS_FEATURE_HEALTHINFO*/ #include -//#ifdef OPLUS_FEATURE_HEALTHINFO -//extern unsigned long gpu_total(void); -//#endif /*OPLUS_FEATURE_HEALTHINFO*/ - void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) { } @@ -168,14 +161,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_zone_page_state(NR_FREE_CMA_PAGES)); #endif -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_ION) && defined(CONFIG_OPLUS_HEALTHINFO) - show_val_kb(m, "IonTotalCache: ", global_zone_page_state(NR_IONCACHE_PAGES)); - show_val_kb(m, "IonTotalUsed: ", ion_total() >> PAGE_SHIFT); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ -//#ifdef OPLUS_FEATURE_HEALTHINFO - //show_val_kb(m, "GPUTotalUsed: ", gpu_total() >> PAGE_SHIFT); -//#endif /*OPLUS_FEATURE_HEALTHINFO*/ - hugetlb_report_meminfo(m); arch_report_meminfo(m); diff --git a/fs/proc/task_cpustats/Kconfig b/fs/proc/task_cpustats/Kconfig deleted file mode 100644 index 033d4a320a57..000000000000 --- a/fs/proc/task_cpustats/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -config OPLUS_CTP - tristate "task_cpustats" - default n - help - record cpu status - -config OPLUS_SCHED - tristate "task_sched_info" - default n - help - record task sched info - -config UTILS_MONITOR - tristate "task_load" - default n - help - record task load diff --git a/fs/proc/task_cpustats/Makefile b/fs/proc/task_cpustats/Makefile deleted file mode 100644 index d4f675e597cc..000000000000 --- a/fs/proc/task_cpustats/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef OPLUS_FEATURE_TASK_CPUSTATS - -ifeq ($(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM), y) -obj-$(CONFIG_OPLUS_CTP) += task_cpustats.o -else -ifeq ($(VERSION).$(PATCHLEVEL), 4.14) -obj-$(CONFIG_OPLUS_CTP) += task_cpustats_mtk_v414.o -else -obj-$(CONFIG_OPLUS_CTP) += task_cpustats.o -endif -endif - -obj-$(CONFIG_OPLUS_SCHED) += task_sched_info.o -obj-$(CONFIG_UTILS_MONITOR) += task_load.o -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ diff --git a/fs/proc/task_cpustats/task_cpustats.c b/fs/proc/task_cpustats/task_cpustats.c deleted file mode 100755 index 24bdabd4f97c..000000000000 --- a/fs/proc/task_cpustats/task_cpustats.c +++ /dev/null @@ -1,258 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* FIXME get max_pid on the runtime.*/ -#define MAX_PID (32768) -#define CTP_WINDOW_SZ (5) -unsigned int sysctl_task_cpustats_enable; -DEFINE_PER_CPU(struct kernel_task_cpustat, ktask_cpustat); -static int cputime_one_jiffy; - -void account_task_time(struct task_struct *p, unsigned int ticks, - enum cpu_usage_stat type) -{ - struct kernel_task_cpustat *kstat; - int idx; - struct task_cpustat *s; - - if (!sysctl_task_cpustats_enable) - return; - if (!cputime_one_jiffy) - cputime_one_jiffy = nsecs_to_jiffies(TICK_NSEC); - kstat = this_cpu_ptr(&ktask_cpustat); - idx = kstat->idx % MAX_CTP_WINDOW; - s = &kstat->cpustat[idx]; - s->pid = p->pid; - s->tgid = p->tgid; - s->type = type; - s->freq = cpufreq_quick_get(p->cpu); - s->begin = jiffies - cputime_one_jiffy * ticks; - s->end = jiffies; - memcpy(s->comm, p->comm, TASK_COMM_LEN); - kstat->idx = idx + 1; -} - -struct acct_cpustat { - pid_t tgid; - unsigned int pwr; - char comm[TASK_COMM_LEN]; -}; - -static struct acct_cpustat cpustats[MAX_PID]; - -static int get_power(int cpu, int freq) -{ - int i; - struct em_perf_domain *domain = em_cpu_get(cpu); - - if (!domain) - goto err_found; - - for (i = domain->nr_cap_states - 1; i > -1; i--) { - struct em_cap_state *cs = domain->table + i; - - if (cs->frequency == freq) - return cs->power; - } -err_found: - pr_err("not found %d %d in sge.\n", cpu, freq); - return 0; -} - -static int task_cpustats_show(struct seq_file *m, void *v) -{ - int *idx = (int *) v; - struct acct_cpustat *s = cpustats + *idx; - - seq_printf(m, "%d\t%d\t%d\t%s\n", *idx, s->tgid, - s->pwr, s->comm); - return 0; -} - -static void *task_cpustats_next(struct seq_file *m, void *v, loff_t *ppos) -{ - int *idx = (int *)v; - - (*idx)++; - (*ppos)++; - for (; *idx < MAX_PID; (*idx)++, (*ppos)++) { - struct acct_cpustat *s = cpustats + *idx; - - if (s->pwr) - return idx; - } - return NULL; -} - -static void *task_cpustats_start(struct seq_file *m, loff_t *ppos) -{ - int *idx = m->private; - - if (!sysctl_task_cpustats_enable) - return NULL; - *idx = *ppos; - if (*idx >= MAX_PID) - goto start_error; - for (; *idx < MAX_PID; (*idx)++, (*ppos)++) { - struct acct_cpustat *as = cpustats + *idx; - - if (as->pwr) - return idx; - } -start_error: - return NULL; -} - -static void task_cpustats_stop(struct seq_file *m, void *v) -{ -} - -static const struct seq_operations seq_ops = { - .start = task_cpustats_start, - .next = task_cpustats_next, - .stop = task_cpustats_stop, - .show = task_cpustats_show -}; - -static int sge_show(struct seq_file *m, void *v) -{ - int i, cpu; - - for_each_possible_cpu(cpu) { - struct em_perf_domain *domain = em_cpu_get(cpu); - struct cpufreq_policy *p = cpufreq_cpu_get_raw(cpu); - int max_freq; - int min_freq; - - if (!domain || !p) - continue; - max_freq = p->cpuinfo.max_freq; - min_freq = p->cpuinfo.min_freq; - seq_printf(m, "cpu %d\n", cpu); - for (i = domain->nr_cap_states - 1; i > -1; i--) { - struct em_cap_state *cs = domain->table + i; - - if (cs->frequency >= min_freq && cs->frequency <= max_freq) - seq_printf(m, "freq %lu pwr %lu\n", cs->frequency, cs->power); - } - } - return 0; -} - -static int sge_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, sge_show, NULL); -} - -static int sgefreq_show(struct seq_file *m, void *v) -{ - int cpu; - bool show_boost = false; - - for_each_possible_cpu(cpu) { - struct cpufreq_policy *p = cpufreq_cpu_get_raw(cpu); - struct cpufreq_frequency_table *pos, *pt; - - if (!p) - continue; - - pt = p->freq_table; - if (!pt) - continue; - - seq_printf(m, "cpu %d\n", cpu); - - cpufreq_for_each_valid_entry(pos, pt) { - if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ)) - continue; - seq_printf(m, "%d\n", pos->frequency); - } - } - return 0; -} - -static int sgefreq_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, sgefreq_show, NULL); -} - -static int task_cpustats_open(struct inode *inode, struct file *file) -{ - int i, j; - int *offs; - unsigned long begin = jiffies - CTP_WINDOW_SZ * HZ, end = jiffies; - - if (!sysctl_task_cpustats_enable) - return -ENOMEM; - - memset(cpustats, 0, MAX_PID * sizeof(struct acct_cpustat)); - - for_each_possible_cpu(i) { - struct kernel_task_cpustat *kstat = &per_cpu(ktask_cpustat, i); - - for (j = 0; j < MAX_CTP_WINDOW; j++) { - struct task_cpustat *ts = kstat->cpustat + j; - unsigned long r_time = ts->end - ts->begin; - - if (ts->pid >= MAX_PID) - continue; - if (ts->begin >= begin && ts->end <= end) { - struct acct_cpustat *as = cpustats + ts->pid; - - if (as->pwr == 0) - memcpy(as->comm, ts->comm, TASK_COMM_LEN); - as->pwr += get_power(i, ts->freq) * jiffies_to_msecs(r_time); - as->tgid = ts->tgid; - } - } - } - - offs = __seq_open_private(file, &seq_ops, sizeof(int)); - - if (!offs) - return -ENOMEM; - return 0; -} - -static int task_cpustats_release(struct inode *inode, struct file *file) -{ - return seq_release_private(inode, file); -} - -static const struct file_operations sge_proc_fops = { - .open = sge_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations sgefreq_proc_fops = { - .open = sgefreq_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations task_cpustats_proc_fops = { - .open = task_cpustats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = task_cpustats_release, -}; - -static int __init proc_task_cpustat_init(void) -{ - sysctl_task_cpustats_enable = 0; - proc_create("sgeinfo", S_IRUGO | S_IWUGO, NULL, &sge_proc_fops); - proc_create("sgefreqinfo", S_IRUGO | S_IWUGO, NULL, &sgefreq_proc_fops); - proc_create("task_cpustats", S_IRUGO | S_IWUGO, NULL, &task_cpustats_proc_fops); - return 0; -} -fs_initcall(proc_task_cpustat_init); diff --git a/fs/proc/task_cpustats/task_cpustats.h b/fs/proc/task_cpustats/task_cpustats.h deleted file mode 100755 index a1efeb4dd874..000000000000 --- a/fs/proc/task_cpustats/task_cpustats.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _TASK_CPUSTATS_H -#define _TASK_CPUSTATS_H - -#include -#include - -#define MAX_CTP_WINDOW (10 * NSEC_PER_SEC / TICK_NSEC) - -struct task_cpustat { - pid_t pid; - pid_t tgid; - enum cpu_usage_stat type; -#ifdef CONFIG_MTK_UNIFY_POWER - unsigned long cap; -#endif - int freq; - unsigned long begin; - unsigned long end; - char comm[TASK_COMM_LEN]; -}; - -struct kernel_task_cpustat { - unsigned int idx; - struct task_cpustat cpustat[MAX_CTP_WINDOW]; -}; - -DECLARE_PER_CPU(struct kernel_task_cpustat, ktask_cpustat); - -extern unsigned int sysctl_task_cpustats_enable; -extern void account_task_time(struct task_struct *p, unsigned int ticks, - enum cpu_usage_stat type); -#endif /* _TASK_CPUSTATS_H */ diff --git a/fs/proc/task_cpustats/task_cpustats_mtk_v414.c b/fs/proc/task_cpustats/task_cpustats_mtk_v414.c deleted file mode 100755 index f834114ed029..000000000000 --- a/fs/proc/task_cpustats/task_cpustats_mtk_v414.c +++ /dev/null @@ -1,331 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "../../drivers/misc/mediatek/base/power/include/mtk_upower.h" - -#include "task_cpustats.h" - -/* FIXME get max_pid on the runtime.*/ -#define MAX_PID (32768) -#define CTP_WINDOW_SZ (5) -unsigned int sysctl_task_cpustats_enable; -static int cputime_one_jiffy; -DEFINE_PER_CPU(struct kernel_task_cpustat, ktask_cpustat); - -struct acct_cpustat { - pid_t tgid; - unsigned int pwr; - char comm[TASK_COMM_LEN]; -}; - -static struct acct_cpustat cpustats[MAX_PID]; - -void account_task_time(struct task_struct *p, unsigned int ticks, - enum cpu_usage_stat type) -{ - struct kernel_task_cpustat *kstat; - int idx, i; - struct task_cpustat *s; - const struct sched_group_energy *sge = cpu_core_energy(p->cpu); - int cap_idx = -1; - - if (!sge) - return; - if (!sysctl_task_cpustats_enable) - return; - if (!cputime_one_jiffy) - cputime_one_jiffy = nsecs_to_jiffies(TICK_NSEC); - - kstat = this_cpu_ptr(&ktask_cpustat); - idx = kstat->idx % MAX_CTP_WINDOW; - s = &kstat->cpustat[idx]; - s->pid = p->pid; - s->tgid = p->tgid; - s->type = type; -#ifdef CONFIG_MTK_UNIFY_POWER - for (i = 0; i < sge->nr_cap_states - 1; i++) { - if (sge->cap_states[i].cap >= capacity_curr_of(p->cpu)) { - cap_idx = i; - break; - } - } - if (cap_idx < 0) - return; - s->cap = sge->cap_states[cap_idx].cap; -#else - s->freq = cpufreq_quick_get(p->cpu); -#endif - s->begin = jiffies - cputime_one_jiffy * ticks; - s->end = jiffies; - memcpy(s->comm, p->comm, TASK_COMM_LEN); - kstat->idx = idx + 1; -} - -#ifdef CONFIG_MTK_UNIFY_POWER -int get_power(int cpu, unsigned long cap) -{ - int i; - unsigned long pwr, dyn_pwr, stc_pwr; - const struct sched_group_energy *sge = cpu_core_energy(cpu); - - if (!sge) - goto err_found; - for (i = sge->nr_cap_states - 1; i > -1; i--) { - struct upower_tbl_row *cap_states = sge->cap_states + i; - - if (cap_states->cap == cap) { - dyn_pwr = cap_states->dyn_pwr; - stc_pwr = cap_states->lkg_pwr[sge->lkg_idx]; - pwr = dyn_pwr + stc_pwr; - - return pwr; - } - } -err_found: - pr_err("not found %d %d in sge.\n", cpu); - return 0; -} -#else -int get_power(int cpu, int freq) -{ - int i; - struct sched_group_energy *sge = sge_array[cpu][SD_LEVEL0]; - - if (!sge) - goto err_found; - - for (i = sge->nr_cap_states - 1; i > -1; i--) { - struct capacity_state *cs = sge->cap_states + i; - - if (cs->frequency == freq) - return cs->power; - } -err_found: - pr_err("not found %d %d in sge.\n", cpu, freq); - return 0; -} - -#endif -EXPORT_SYMBOL(get_power); - -static int task_cpustats_show(struct seq_file *m, void *v) -{ - int *idx = (int *) v; - struct acct_cpustat *s = cpustats + *idx; - - seq_printf(m, "%d\t%d\t%d\t%s\n", *idx, s->tgid, - s->pwr, s->comm); - return 0; -} - -static void *task_cpustats_next(struct seq_file *m, void *v, loff_t *ppos) -{ - int *idx = (int *)v; - - (*idx)++; - (*ppos)++; - for (; *idx < MAX_PID; (*idx)++, (*ppos)++) { - struct acct_cpustat *s = cpustats + *idx; - - if (s->pwr) - return idx; - } - return NULL; -} - -static void *task_cpustats_start(struct seq_file *m, loff_t *ppos) -{ - int *idx = m->private; - - if (!sysctl_task_cpustats_enable) - return NULL; - - *idx = *ppos; - - if (*idx >= MAX_PID) - goto start_error; - - for (; *idx < MAX_PID; (*idx)++, (*ppos)++) { - struct acct_cpustat *as = cpustats + *idx; - - if (as->pwr) - return idx; - } -start_error: - return NULL; -} - -static void task_cpustats_stop(struct seq_file *m, void *v) -{ -} - -static const struct seq_operations seq_ops = { - .start = task_cpustats_start, - .next = task_cpustats_next, - .stop = task_cpustats_stop, - .show = task_cpustats_show -}; - -static int sge_show(struct seq_file *m, void *v) -{ -#ifdef CONFIG_MTK_UNIFY_POWER - unsigned long dyn_pwr; - unsigned long stc_pwr; - unsigned long pwr; -#else - unsigned long pwr; - unsigned long freq; -#endif - const struct sched_group_energy *core_eng; - int cpu; - int core_nr_cap = 0; - unsigned long cap_idx; - int i; - - for_each_possible_cpu(cpu) { - core_eng = cpu_core_energy(cpu); - if (!core_eng) - continue; - core_nr_cap = core_eng->nr_cap_states; - seq_printf(m, "cpu %d\n", cpu); - - for (i = 0; i < core_nr_cap; i++) { -#ifdef CONFIG_MTK_UNIFY_POWER - dyn_pwr = - core_eng->cap_states[i].dyn_pwr; - stc_pwr = - core_eng->cap_states[i].lkg_pwr[core_eng->lkg_idx]; - pwr = dyn_pwr + stc_pwr; - cap_idx = - core_eng->cap_states[i].cap; - seq_printf(m, "cap %lu pwr %lu \n", cap_idx, pwr); -#else - pwr = core_eng->cap_states[i].power; - seq_printf(m, "freq: %lu pwr: %lu\n", freq, pwr); -#endif - } - } - return 0; -} - -static int sge_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, sge_show, NULL); -} - -static int sgefreq_show(struct seq_file *m, void *v) -{ - int cpu; - bool show_boost = false; - - for_each_possible_cpu(cpu) { - struct cpufreq_policy *p = cpufreq_cpu_get_raw(cpu); - struct cpufreq_frequency_table *pos, *pt; - - if (!p) - continue; - - pt = p->freq_table; - if (!pt) - continue; - - seq_printf(m, "cpu %d\n", cpu); - - cpufreq_for_each_valid_entry(pos, pt) { - if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ)) - continue; - seq_printf(m, "%d\n", pos->frequency); - } - } - return 0; -} - -static int sgefreq_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, sgefreq_show, NULL); -} - -static int task_cpustats_open(struct inode *inode, struct file *file) -{ - int i, j; - int *offs; - unsigned long begin = jiffies - CTP_WINDOW_SZ * HZ, end = jiffies; - - if (!sysctl_task_cpustats_enable) - return -ENOMEM; - - memset(cpustats, 0, MAX_PID * sizeof(struct acct_cpustat)); - - for_each_possible_cpu(i) { - struct kernel_task_cpustat *kstat = &per_cpu(ktask_cpustat, i); - - for (j = 0; j < MAX_CTP_WINDOW; j++) { - struct task_cpustat *ts = kstat->cpustat + j; - unsigned long r_time = ts->end - ts->begin; - - if (ts->pid >= MAX_PID) - continue; - - if (ts->begin >= begin && ts->end <= end) { - struct acct_cpustat *as = cpustats + ts->pid; - - if (as->pwr == 0) - memcpy(as->comm, ts->comm, TASK_COMM_LEN); - -#ifdef CONFIG_MTK_UNIFY_POWER - as->pwr += get_power(i, ts->cap) * jiffies_to_msecs(r_time); -#else - as->pwr += get_power(i, ts->freq) * jiffies_to_msecs(r_time); -#endif - as->tgid = ts->tgid; - } - } - } - - offs = __seq_open_private(file, &seq_ops, sizeof(int)); - - if (!offs) - return -ENOMEM; - return 0; -} - -static int task_cpustats_release(struct inode *inode, struct file *file) -{ - return seq_release_private(inode, file); -} - -static const struct file_operations sge_proc_fops = { - .open = sge_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations sgefreq_proc_fops = { - .open = sgefreq_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations task_cpustats_proc_fops = { - .open = task_cpustats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = task_cpustats_release, -}; - -static int __init proc_task_cpustat_init(void) -{ - sysctl_task_cpustats_enable = 0; - proc_create("sgeinfo", S_IRUGO | S_IWUGO, NULL, &sge_proc_fops); - proc_create("sgefreqinfo", S_IRUGO | S_IWUGO, NULL, &sgefreq_proc_fops); - proc_create("task_cpustats", S_IRUGO | S_IWUGO, NULL, &task_cpustats_proc_fops); - return 0; -} -fs_initcall(proc_task_cpustat_init); diff --git a/fs/proc/task_cpustats/task_load.c b/fs/proc/task_cpustats/task_load.c deleted file mode 100755 index 278580997d37..000000000000 --- a/fs/proc/task_cpustats/task_load.c +++ /dev/null @@ -1,372 +0,0 @@ -#include -#include -#include -#include -#include <../fs/proc/internal.h> -#include <../kernel/sched/sched.h> -#include -#include -#include -#include -#include -#include -#include - -#define MAX_PID_NUM 3 - -static unsigned int monitor_status; -static u64 all_running_time; -static u64 realtime_base; -static u64 normalize_all_running_time; -static int target_pid_num = -1; -static u64 target_pid[MAX_PID_NUM] = {0}; - -#ifdef CONFIG_SCHED_WALT -static inline u64 scale_exec_time(u64 delta, struct rq *rq) -{ - return (delta * rq->wrq.task_exec_scale) >> 10; -} -#else -static inline u64 scale_exec_time(u64 delta, struct rq *rq) -{ - return delta; -} -#endif /* CONFIG_SCHED_WALT */ - -void account_normalize_runtime(struct task_struct *p, u64 delta, struct rq *rq) -{ - u64 normalize_delta = 0; - - if (!monitor_status) - return; - - normalize_delta = scale_exec_time(delta, rq); - p->signal->sum_runtime += delta; - all_running_time += delta; - normalize_all_running_time += normalize_delta; -} - -static int proc_target_process_show(struct seq_file *m, void *v) -{ - struct task_struct *p; - - if (!monitor_status) - return -EFAULT; - - if (target_pid_num == -1 || target_pid_num >= MAX_PID_NUM) { - task_load_err("get target pid fail\n"); - goto ERROR_INFO; - } - - p = find_get_task_by_vpid(target_pid[target_pid_num]); - - if (!p) { - task_load_err("get target task fail\n"); - goto ERROR_INFO; - } - - seq_printf(m, "%llu\n", p->signal->sum_runtime>>20); - put_task_struct(p); - - return 0; - -ERROR_INFO: - seq_puts(m, "0\n"); - return 0; -} - -static int proc_target_process_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_target_process_show, inode); -} - -static ssize_t proc_target_process_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[PROC_NUMBUF]; - int err, target_process_num; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtouint(strstrip(buffer), 0, &target_process_num); - if (err) - return err; - - target_pid_num = target_process_num; - - return count; -} - - -static const struct file_operations proc_target_process_operations = { - .open = proc_target_process_open, - .write = proc_target_process_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_running_time_show(struct seq_file *m, void *v) -{ - if (!monitor_status) - return -EFAULT; - - seq_printf(m, "%llu\n", all_running_time>>20); - - return 0; -} - -static int proc_running_time_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_running_time_show, inode); -} - -static const struct file_operations proc_running_time_operations = { - .open = proc_running_time_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_normalize_running_time_show(struct seq_file *m, void *v) -{ - if (!monitor_status) - return -EFAULT; - - seq_printf(m, "%llu\n", normalize_all_running_time>>20); - - return 0; -} - -static int proc_normalize_running_time_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_normalize_running_time_show, inode); -} - -static const struct file_operations proc_normalize_running_time_operations = { - .open = proc_normalize_running_time_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_real_time_show(struct seq_file *m, void *v) -{ - struct timespec ts; - u64 wall_time; - - if (!monitor_status) - return -EFAULT; - - getnstimeofday(&ts); - wall_time = ts.tv_sec * 1e6 + ts.tv_nsec / 1000 - realtime_base; - seq_printf(m, "%llu\n", wall_time>>10); - - return 0; -} - -static int proc_real_time_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_real_time_show, inode); -} - - -static const struct file_operations proc_real_time_operations = { - .open = proc_real_time_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_normalize_real_time_show(struct seq_file *m, void *v) -{ - int i; - struct timespec ts; - u64 wall_time = 0; - u64 normalize_wall_time = 0; - - if (!monitor_status) - return -EFAULT; - - getnstimeofday(&ts); - wall_time = ts.tv_sec * 1e6 + ts.tv_nsec / 1000 - realtime_base; - - for_each_possible_cpu(i) - normalize_wall_time += wall_time * (u64)topology_get_cpu_scale(i); - - seq_printf(m, "%llu\n", normalize_wall_time>>20); - - return 0; -} - -static int proc_normalize_real_time_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_normalize_real_time_show, inode); -} - - -static const struct file_operations proc_normalize_real_time_operations = { - .open = proc_normalize_real_time_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t proc_monitor_status_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[PROC_NUMBUF]; - int err, enable; - struct timespec ts; - struct task_struct *g; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtouint(strstrip(buffer), 0, &enable); - if (err) - return err; - - getnstimeofday(&ts); - monitor_status = enable; - realtime_base = ts.tv_sec * 1e6 + ts.tv_nsec / 1000; - - if (!monitor_status) { - for_each_process(g) { - g->signal->sum_runtime = 0; - } - - all_running_time = 0; - normalize_all_running_time = 0; - } - - return count; -} - -static ssize_t proc_monitor_status_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[PROC_NUMBUF]; - - size_t len = 0; - - len = snprintf(buffer, sizeof(buffer), "%d\n", monitor_status); - - return simple_read_from_buffer(buf, count, ppos, buffer, len); -} - - -static const struct file_operations proc_monitor_status_operations = { - .write = proc_monitor_status_write, - .read = proc_monitor_status_read, -}; - -void get_target_process(struct task_struct *task) -{ - struct task_struct *grp; - - if (strstr(task->comm, "om.oplus.camera")) { - target_pid[camera] = task->pid; - return; - } - - grp = task->group_leader; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (strstr(grp->comm, "cameraserver")) { - target_pid[cameraserver] = grp->pid; - return; - } -#else - if (strstr(grp->comm, "camerahalserver")) { - target_pid[cameraserver] = grp->pid; - return; - } -#endif - - if (strstr(grp->comm, "provider@2.4-se")) { - target_pid[cameraprovider] = grp->pid; - return; - } -} - -#define RUNTIME_DIR "task_info" -#define TASK_LOAD_NODE "task_load_info" -#define TASK_LOAD_EXIST_NODE "task_info/task_load_info" -static struct proc_dir_entry *task_load_info; - -static int __init load_info_init(void) -{ - struct proc_dir_entry *proc_entry, *task_runtime; - - monitor_status = 0; - all_running_time = 0; - realtime_base = 0; - normalize_all_running_time = 0; - task_load_info = NULL; - - task_load_info = proc_mkdir(RUNTIME_DIR, NULL); - if (!task_load_info) - task_runtime = proc_mkdir(TASK_LOAD_EXIST_NODE, NULL); - else - task_runtime = proc_mkdir(TASK_LOAD_NODE, task_load_info); - - if (!task_runtime) { - task_load_err("create task_load_info fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("monitor_status", 0666, task_runtime, &proc_monitor_status_operations); - if (!proc_entry) { - task_load_err("create monitor_status fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("running_time", 0666, task_runtime, &proc_running_time_operations); - if (!proc_entry) { - task_load_err("create running_time fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("normalize_running_time", 0666, task_runtime, &proc_normalize_running_time_operations); - if (!proc_entry) { - task_load_err("create normalize_running_time fail\n"); - goto ERROR_INIT_VERSION; - } - - - proc_entry = proc_create("real_time", 0666, task_runtime, &proc_real_time_operations); - if (!proc_entry) { - task_load_err("create real_time fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("normalize_real_time", 0666, task_runtime, &proc_normalize_real_time_operations); - if (!proc_entry) { - task_load_err("create normalize_real_time fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("target_process", 0666, task_runtime, &proc_target_process_operations); - if (!proc_entry) { - task_load_err("create target_process fail\n"); - goto ERROR_INIT_VERSION; - } - - return 0; - -ERROR_INIT_VERSION: - remove_proc_entry(TASK_LOAD_NODE, NULL); - return -ENOENT; -} -module_init(load_info_init); - -MODULE_DESCRIPTION("task_load"); -MODULE_LICENSE("GPL v2"); diff --git a/fs/proc/task_cpustats/task_load.h b/fs/proc/task_cpustats/task_load.h deleted file mode 100755 index 55fdd6e8cd6e..000000000000 --- a/fs/proc/task_cpustats/task_load.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _OPLUS_TASK_LOAD_H -#define _OPLUS_TASK_LOAD_H - -#define task_load_err(fmt, ...) \ - printk(KERN_ERR "[TASK_LOAD_INFO_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -enum { - camera = 0, - cameraserver, - cameraprovider, -}; - - -extern void account_normalize_runtime(struct task_struct *p, u64 delta, struct rq *rq); -extern void get_target_process(struct task_struct *task); - - -#endif /* _OPLUS_TASK_LOAD_H */ diff --git a/fs/proc/task_cpustats/task_sched_info.c b/fs/proc/task_cpustats/task_sched_info.c deleted file mode 100755 index a263c8fdeeab..000000000000 --- a/fs/proc/task_cpustats/task_sched_info.c +++ /dev/null @@ -1,765 +0,0 @@ -#include -#include -#include -#include -#include -#include <../fs/proc/internal.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include <../kernel/sched/sched.h> - -#define MAX_PID_NUM 10 -#define BUFFER_SIZE 5760 -#define NOTIFY_SIZE 2880 -#define DURATION_THRESHOLD 16777215 -#define CPU_NUM 8 -#define NUM_LEN 21 -#define SYSTEM_SERVER_NAME "SS" -#define SURFACE_FLINGER_NAME "SF" -#define MAX_THRESHOLD_NUM 5 - -int systemserver_pid = -1; -int surfaceflinger_pid = -1; -unsigned int task_sched_info_enable; -static unsigned int arr_read; -static unsigned int arr_write; -u64 time_threshold[MAX_THRESHOLD_NUM] = {4000000, 4000000, 4000000, 4000000, 4000000}; -static int target_pids[MAX_PID_NUM] = {-1}; -unsigned int target_pids_num; -static u64 data_arr[BUFFER_SIZE]; -static u64 datainfo[BUFFER_SIZE]; -static int data_size = BUFFER_SIZE; -static unsigned int dt; -static int prev_freq[CPU_NUM] = {-1}; -static int prev_freq_min[CPU_NUM] = {-1}; -static int prev_freq_max[CPU_NUM] = {-1}; - -#define MAX_UEVENT_PARAM 4 -static struct kobject *sched_kobj; -static struct work_struct sched_detect_ws; -char *sched_detect_env[MAX_UEVENT_PARAM] = {"SCHEDACTION=uevent", NULL}; -static int uevent_id; - -static spinlock_t read_write_lock; -static DEFINE_SPINLOCK(read_write_lock); - -static bool sched_info_ctrl = true; -bool ctp_send_message; - -static u64 write_pid_time; - -static int last_read_idx; - -static unsigned long d_convert_info; - -void sched_action_trig(void) -{ - if (!sched_info_ctrl) { - sched_err("sched_info_ctrl off\n"); - return; - } - - if (sched_kobj == NULL) { - sched_err("kobj NULL\n"); - return; - } - - sprintf(sched_detect_env[1], "SCHEDNUM=%d", uevent_id); - sched_detect_env[MAX_UEVENT_PARAM - 2] = NULL; - sched_detect_env[MAX_UEVENT_PARAM - 1] = NULL; - schedule_work(&sched_detect_ws); - - uevent_id++; -} - -void sched_detect_work(struct work_struct *work) -{ - kobject_uevent_env(sched_kobj, KOBJ_CHANGE, sched_detect_env); -} - -void sched_action_init(void) -{ - int i = 0; - - for (i = 1; i < MAX_UEVENT_PARAM - 2; i++) { - sched_detect_env[i] = kzalloc(50, GFP_KERNEL); - - if (!sched_detect_env[i]) { - sched_err("kzalloc sched uevent param failed\n"); - goto sched_action_init_free_memory; - } - } - sched_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); - if (sched_kobj == NULL) { - sched_err("sched_kobj init err\n"); - return; - } - INIT_WORK(&sched_detect_ws, sched_detect_work); - return; - -sched_action_init_free_memory: - for (i--; i > 0; i--) - kfree(sched_detect_env[i]); - - sched_err("Failed!\n"); -} - -void get_target_thread_pid(struct task_struct *task) -{ - struct task_struct *grp; - - if (task_uid(task).val == 1000) { - if (strstr(task->comm, "android.anim")) { - systemserver_pid = task->tgid; - return; - } - - grp = task->group_leader; - if (strstr(grp->comm, "surfaceflinger")) { - surfaceflinger_pid = grp->pid; - return; - } - } -} - -void update_wake_tid(struct task_struct *p, struct task_struct *cur, unsigned int type) -{ - u64 cur_tid; - - if (!p || !cur) - return; - - cur_tid = cur->pid; - p->wake_tid = cur_tid | (type << 16); -} - -void update_running_start_time(struct task_struct *prev, struct task_struct *next) -{ - u64 clock, delay; - - if (!prev || !next) - return; - - clock = sched_clock_cpu(prev->cpu); - delay = clock - prev->running_start_time; - update_task_sched_info(prev, delay, 0, prev->cpu); - prev->running_start_time = 0; - next->running_start_time = clock; -} - -static void put_in_arr(struct task_sched_info *info, u64 *data_arr) -{ - unsigned long flags; - - spin_lock_irqsave(&read_write_lock, flags); - - data_arr[arr_write] = info->sched_info_one; - data_arr[arr_write + 1] = info->sched_info_two; - - arr_write = (arr_write + 2) < BUFFER_SIZE ? arr_write + 2 : 0; - dt += 2; - - if (arr_read == arr_write) - arr_read = (arr_read + 2) < BUFFER_SIZE ? arr_read + 2 : 0; - - spin_unlock_irqrestore(&read_write_lock, flags); - - if (dt >= NOTIFY_SIZE) { - ctp_send_message = true; - dt -= NOTIFY_SIZE; - } -} - -u64 is_target_pid(int tgid) -{ - unsigned int num = 0; - - while (num < target_pids_num) { - if (target_pids[num] == tgid) - return num; - - num++; - } - - return MAX_PID_NUM; -} - -void update_backtrace_info(struct task_struct *p, u64 start_time) -{ - struct task_sched_info task_backtrace; - - task_backtrace.sched_info_one = task_sched_info_backtrace | (p->pid << 8); - task_backtrace.sched_info_two = get_wchan(p); - - if (!d_convert_info) - d_convert_info = (unsigned long)task_backtrace.sched_info_two; - - put_in_arr(&task_backtrace, data_arr); -} - -void update_task_sched_info(struct task_struct *p, u64 delay, int type, int cpu) -{ - struct task_sched_info sched_info; - u64 p_tid, wake_tid; - u64 cur_sched_clock; - u64 pid_num = MAX_PID_NUM; - - if (!task_sched_info_enable) - return; - - if (!p) - return; - - if (delay < time_threshold[type]) - return; - - pid_num = is_target_pid(p->tgid); - if (pid_num != MAX_PID_NUM) { - sched_info.sched_info_one = 0; - sched_info.sched_info_two = 0; - - p_tid = p->pid; - wake_tid = p->wake_tid; - cur_sched_clock = sched_clock_cpu(cpu); - delay = delay >> 20; - if (delay > DURATION_THRESHOLD) - delay = DURATION_THRESHOLD; - - switch (type) { - case task_sched_info_running: - sched_info.sched_info_one = type | (cpu << 5); - sched_info.sched_info_one = sched_info.sched_info_one | (cur_sched_clock << 8); - sched_info.sched_info_two = delay | (p_tid << 24); - sched_info.sched_info_two = sched_info.sched_info_two | (pid_num << 58); - break; - - case task_sched_info_runnable: - sched_info.sched_info_one = type | (cpu << 5); - sched_info.sched_info_one = sched_info.sched_info_one | (cur_sched_clock << 8); - sched_info.sched_info_two = delay | (p_tid << 24); - sched_info.sched_info_two = sched_info.sched_info_two | (wake_tid << 40); - sched_info.sched_info_two = sched_info.sched_info_two | (pid_num << 58); - break; - - case task_sched_info_D: - update_backtrace_info(p, cur_sched_clock); - - case task_sched_info_IO: - case task_sched_info_S: - wake_tid = wake_tid & (~(1 << 16)); - sched_info.sched_info_one = type | (cpu << 5); - sched_info.sched_info_one = sched_info.sched_info_one | (cur_sched_clock << 8); - sched_info.sched_info_two = delay | (p_tid << 24); - sched_info.sched_info_two = sched_info.sched_info_two | (wake_tid << 40); - sched_info.sched_info_two = sched_info.sched_info_two | (pid_num << 58); - } - - - put_in_arr(&sched_info, data_arr); - } -} - -void update_freq_info(struct cpufreq_policy *policy) -{ - u64 cur, clock, cpu; - struct task_sched_info freq_info; - - if (!task_sched_info_enable) - return; - - if (!policy) - return; - - clock = sched_clock_cpu(policy->cpu); - cur = (u64)policy->cur; - cpu = policy->cpu; - - if (prev_freq[policy->cpu] == cur) - return; - - prev_freq[policy->cpu] = cur; - - freq_info.sched_info_one = task_sched_info_freq | (cpu << 5); - freq_info.sched_info_one = freq_info.sched_info_one | (clock << 8); - freq_info.sched_info_two = cur; - put_in_arr(&freq_info, data_arr); -} - -void update_freq_limit_info(struct cpufreq_policy *policy) -{ - u64 min, max, clock, cur_tid, cpu; - struct task_sched_info freq_limit_info; - - if (!task_sched_info_enable) - return; - - if (!policy) - return; - - clock = sched_clock_cpu(policy->cpu); - - cur_tid = current->pid; - cpu = policy->cpu; - min = (u64)policy->min; - max = (u64)policy->max; - - if (prev_freq_min[policy->cpu] == min && prev_freq_max[policy->cpu] == max) - return; - - prev_freq_min[policy->cpu] = min; - prev_freq_max[policy->cpu] = max; - - freq_limit_info.sched_info_one = task_sched_info_freq_limit | (cpu << 5); - freq_limit_info.sched_info_one = freq_limit_info.sched_info_one | (clock << 8); - freq_limit_info.sched_info_two = min | (max << 24); - freq_limit_info.sched_info_two = freq_limit_info.sched_info_two | (cur_tid << 48); - put_in_arr(&freq_limit_info, data_arr); -} - -void update_cpu_isolate_info(int cpu, u64 type) -{ - u64 clock, cur_tid; - struct task_sched_info isolate_info; - - if (!task_sched_info_enable) - return; - - clock = sched_clock_cpu(cpu); - cur_tid = current->pid; - - isolate_info.sched_info_one = task_sched_info_isolate | (cpu << 5); - isolate_info.sched_info_one = isolate_info.sched_info_one | (clock << 8); - isolate_info.sched_info_two = type | (cur_tid << 8); - put_in_arr(&isolate_info, data_arr); -} - -static int proc_pids_set_show(struct seq_file *m, void *v) -{ - int i = 0; - - if (!task_sched_info_enable) - return -EFAULT; - - seq_printf(m, "%llu ", write_pid_time); - - while (i < target_pids_num) { - seq_printf(m, "%d ", target_pids[i]); - i++; - } - seq_puts(m, "\n"); - - return 0; -} - -static int proc_pids_set_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_pids_set_show, inode); -} - -static ssize_t proc_pids_set_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[NUM_LEN * MAX_PID_NUM]; - char *all, *single; - const char *target = NULL; - int err; - struct timespec ts; - - if (!task_sched_info_enable) - return -EFAULT; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - all = buffer; - - target_pids_num = 2; - while ((single = strsep(&all, " ")) != NULL && target_pids_num < MAX_PID_NUM) { - target = single; - - err = kstrtouint(target, 0, &target_pids[target_pids_num]); - if (err) { - target = NULL; - continue; - } - target = NULL; - target_pids_num++; - } - - getnstimeofday(&ts); - write_pid_time = ts.tv_sec * 1e6 + ts.tv_nsec / 1000; - - return count; -} - -static const struct file_operations proc_pids_set_operations = { - .open = proc_pids_set_open, - .read = seq_read, - .write = proc_pids_set_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static void *sched_start(struct seq_file *m, loff_t *ppos) -{ - int *idx = m->private; - - *ppos = *ppos < last_read_idx ? last_read_idx : *ppos; - - *idx = *ppos; - - if (*idx >= BUFFER_SIZE) - return NULL; - - return idx; -} - -static void *sched_next(struct seq_file *m, void *v, loff_t *ppos) -{ - int *idx = (int *)v; - int new = (*idx + 256) < data_size ? 256 : (data_size-*idx); - - *idx += new; - *ppos += new; - if (*idx == data_size) - return NULL; - - return idx; -} - -static int sched_show(struct seq_file *m, void *v) -{ - int *idx = (int *)v; - int num = 0; - int cur = *idx; - - while (num < 256 && cur < data_size) { - seq_printf(m, "%llu %llu\n", datainfo[cur], datainfo[cur + 1]); - num += 2; - cur = num + *idx; - } - - if (m->count == m->size) - return 0; - - last_read_idx = cur; - - return 0; -} - -static void sched_stop(struct seq_file *m, void *v) -{ -} - -static const struct seq_operations seq_ops = { - .start = sched_start, - .next = sched_next, - .stop = sched_stop, - .show = sched_show, -}; - -static int sched_buffer_open(struct inode *inode, struct file *file) -{ - unsigned int cur_read, cur_write; - unsigned long flags; - unsigned int num1 = 0; - int *offs; - - if (!task_sched_info_enable) - return -ENOMEM; - - memset(datainfo, 0, BUFFER_SIZE * sizeof(u64)); - spin_lock_irqsave(&read_write_lock, flags); - - data_size = (arr_write < arr_read) ? (BUFFER_SIZE + arr_write - arr_read) : arr_write - arr_read; - cur_read = arr_read; - cur_write = arr_write; - - arr_read = arr_write; - - dt = 0; - - if (cur_write < cur_read) { - num1 = BUFFER_SIZE - cur_read; - memcpy(datainfo, data_arr + cur_read, sizeof(u64) * num1); - memcpy(datainfo + num1, data_arr, sizeof(u64) * cur_write); - } else - memcpy(datainfo, data_arr + cur_read, sizeof(u64) * data_size); - - spin_unlock_irqrestore(&read_write_lock, flags); - - last_read_idx = 0; - - offs = __seq_open_private(file, &seq_ops, sizeof(int)); - - if (!offs) - return -ENOMEM; - - return 0; -} - -static int sched_buffer_release(struct inode *inode, struct file *file) -{ - last_read_idx = 0; - - return seq_release_private(inode, file); -} - -static const struct file_operations proc_sched_buffer_operations = { - .open = sched_buffer_open, - .read = seq_read, - .llseek = seq_lseek, - .release = sched_buffer_release, -}; - -static int proc_task_sched_info_enable_show(struct seq_file *m, void *v) -{ - u64 cur_cpu_clock[CPU_NUM]; - struct timespec ts; - unsigned int i = 0; - u64 wall_time; - - if (!task_sched_info_enable) - return -EFAULT; - - getnstimeofday(&ts); - wall_time = ts.tv_sec * 1e6 + ts.tv_nsec / 1000; - - seq_printf(m, "%llu ", wall_time); - - while (i < CPU_NUM) { - cur_cpu_clock[i] = sched_clock_cpu(i); - seq_printf(m, "%llu ", cur_cpu_clock[i]); - i++; - } - seq_puts(m, "\n"); - return 0; -} - -static int proc_task_sched_info_enable_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_task_sched_info_enable_show, inode); -} - -static ssize_t proc_task_sched_info_enable_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[PROC_NUMBUF]; - int err, enable; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - err = kstrtouint(strstrip(buffer), 0, &enable); - if (err) { - sched_err("enable/disable task_sched_info_enable fail. buffer_info: %s\n", buffer); - return err; - } - - if (enable) { - target_pids[0] = systemserver_pid; - target_pids[1] = surfaceflinger_pid; - target_pids_num = 2; - } - - task_sched_info_enable = enable; - if (!task_sched_info_enable) { - arr_read = 0; - arr_write = 0; - dt = 0; - memset(data_arr, 0, BUFFER_SIZE * sizeof(u64)); - memset(target_pids, -1, MAX_PID_NUM * sizeof(int)); - target_pids_num = 0; - write_pid_time = 0; - d_convert_info = 0; - } - - return count; -} - -static const struct file_operations proc_task_sched_info_enable_operations = { - .open = proc_task_sched_info_enable_open, - .write = proc_task_sched_info_enable_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_sched_info_threshold_show(struct seq_file *m, void *v) -{ - if (!task_sched_info_enable) - return -EFAULT; - - seq_printf(m, "running:%llu\trunnable:%llu\tblock/IO:%llu\tD:%llu\tS:%llu\n", time_threshold[0], - time_threshold[1], time_threshold[2], time_threshold[3], time_threshold[4]); - return 0; -} - -static int proc_sched_info_threshold_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_sched_info_threshold_show, inode); -} - -static ssize_t proc_sched_info_threshold_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) -{ - char buffer[NUM_LEN * 5]; - char *all, *single; - const char *target = NULL; - int err, threshold_num = 0; - - memset(buffer, 0, sizeof(buffer)); - - if (!task_sched_info_enable) - return -EFAULT; - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - - if (copy_from_user(buffer, buf, count)) - return -EFAULT; - - all = buffer; - - while ((single = strsep(&all, " ")) != NULL && threshold_num < MAX_THRESHOLD_NUM) { - target = single; - err = kstrtou64(target, 0, &time_threshold[threshold_num]); - if (err) { - sched_err("sched_info_threshold: %s\n", target); - target = NULL; - continue; - } - target = NULL; - threshold_num++; - } - - return count; -} - -static const struct file_operations proc_sched_info_threshold_operations = { - .open = proc_sched_info_threshold_open, - .write = proc_sched_info_threshold_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int proc_d_convert_show(struct seq_file *m, void *v) -{ - if (!task_sched_info_enable) - return -EFAULT; - - if (d_convert_info) - seq_printf(m, "%pS %px\n", (void *)d_convert_info, (void *)d_convert_info); - else - seq_puts(m, "\n"); - - return 0; -} - -static int proc_d_convert_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_d_convert_show, inode); -} - -static const struct file_operations proc_d_convert_operations = { - .open = proc_d_convert_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -#define SCHED_INFO_DIR "task_info" -#define SCHED_INFO_PROC_NODE "task_sched_info" -#define SCHED_INFO_EXIST_PROC_NODE "task_info/task_sched_info" -static struct proc_dir_entry *task_info; - -static int __init sched_info_init(void) -{ - struct proc_dir_entry *proc_entry, *sched_info; - - task_sched_info_enable = 0; - arr_read = 0; - arr_write = 0; - target_pids_num = 0; - dt = 0; - sched_kobj = NULL; - uevent_id = 0; - ctp_send_message = false; - write_pid_time = 0; - last_read_idx = 0; - d_convert_info = 0; - - task_info = NULL; - - sched_action_init(); - - task_info = proc_mkdir(SCHED_INFO_DIR, NULL); - if (!task_info) - sched_info = proc_mkdir(SCHED_INFO_EXIST_PROC_NODE, NULL); - else - sched_info = proc_mkdir(SCHED_INFO_PROC_NODE, task_info); - - if (!sched_info) { - sched_err("create task_info fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("pids_set", 0666, sched_info, &proc_pids_set_operations); - if (!proc_entry) { - sched_err("create pids_set fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("sched_buffer", 0666, sched_info, &proc_sched_buffer_operations); - if (!proc_entry) { - sched_err("create sched_buffer fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("task_sched_info_enable", 0666, sched_info, &proc_task_sched_info_enable_operations); - if (!proc_entry) { - sched_err("create task_sched_info_enable fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("sched_info_threshold", 0666, sched_info, &proc_sched_info_threshold_operations); - if (!proc_entry) { - sched_err("create sched_info_threshold fail\n"); - goto ERROR_INIT_VERSION; - } - - proc_entry = proc_create("d_convert", 0666, sched_info, &proc_d_convert_operations); - if (!proc_entry) { - sched_err("create d_convert fail\n"); - goto ERROR_INIT_VERSION; - } - - return 0; - -ERROR_INIT_VERSION: - remove_proc_entry(SCHED_INFO_PROC_NODE, NULL); - return -ENOENT; -} -module_init(sched_info_init); -module_param_named(sched_info_ctrl, sched_info_ctrl, bool, 0755); -MODULE_DESCRIPTION("sched_info"); -MODULE_LICENSE("GPL v2"); diff --git a/fs/proc/task_cpustats/task_sched_info.h b/fs/proc/task_cpustats/task_sched_info.h deleted file mode 100755 index 27cae2952eb9..000000000000 --- a/fs/proc/task_cpustats/task_sched_info.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _OPLUS_TASK_SCHED_INFO_H -#define _OPLUS_TASK_SCHED_INFO_H - -#include - -#define sched_err(fmt, ...) \ - printk(KERN_ERR "[SCHED_INFO_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -enum { - task_sched_info_running = 0, - task_sched_info_runnable, - task_sched_info_IO, - task_sched_info_D, - task_sched_info_S, - task_sched_info_freq, - task_sched_info_freq_limit, - task_sched_info_isolate, - task_sched_info_backtrace, -}; - -enum { - other_runnable = 1, - running_runnable, -}; - -enum { - cpu_unisolate = 0, - cpu_isolate, -}; - -struct task_sched_info { - u64 sched_info_one; - u64 sched_info_two; -}; - -extern void update_task_sched_info(struct task_struct *p, u64 delay, int type, int cpu); -extern void update_freq_info(struct cpufreq_policy *policy); -extern void update_freq_limit_info(struct cpufreq_policy *policy); -extern void update_cpu_isolate_info(int cpu, u64 type); -extern void update_wake_tid(struct task_struct *p, struct task_struct *cur, unsigned int type); -extern void update_running_start_time(struct task_struct *prev, struct task_struct *next); -extern void sched_action_trig(void); -extern void get_target_thread_pid(struct task_struct *p); - -extern bool ctp_send_message; - -#endif /* _OPLUS_TASK_SCHED_INFO_H */ diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 132fed7ad6c2..4d14b232cce3 100755 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -858,29 +858,6 @@ static int show_smap(struct seq_file *m, void *v) smap_gather_stats(vma, &mss); - - - if (strcmp(current->comm, "android.bg") == 0) { - if ((unsigned long)(mss.pss >> (10 + PSS_SHIFT)) > 0) { - seq_printf(m, - "Pss: %8lu kB\n", - ( unsigned long)(mss.pss >> (10 + PSS_SHIFT))); - } - if ((mss.private_clean >> 10) > 0) { - seq_printf(m, - "Private_Clean: %8lu kB\n", - mss.private_clean >> 10); - } - if ((mss.private_dirty >> 10) > 0) { - seq_printf(m, - "Private_Dirty: %8lu kB\n", - mss.private_dirty >> 10); - } - m_cache_vma(m, vma); - return 0; - } - //#endif /*OPLUS_BUG_STABILITY*/ - show_map_vma(m, vma); if (vma_get_anon_name(vma)) { seq_puts(m, "Name: "); @@ -1824,11 +1801,7 @@ cont: break; } pte_unmap_unlock(pte - 1, ptl); -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - (void)reclaim_pages_from_list(&page_list, vma, NULL); -#else reclaim_pages_from_list(&page_list, vma); -#endif if (addr != end) goto cont; diff --git a/fs/read_write.c b/fs/read_write.c index 0aec43467f4c..5315c25f3904 100755 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -24,12 +24,6 @@ #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#include -DEFINE_TRACE(syscall_read_timeout); -DEFINE_TRACE(syscall_write_timeout); -#endif /*OPLUS_FEATURE_IOMONITOR*/ const struct file_operations generic_ro_fops = { .llseek = generic_file_llseek, @@ -431,9 +425,6 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) /* The cast to a user pointer is valid due to the set_fs() */ result = vfs_read(file, (void __user *)buf, count, pos); set_fs(old_fs); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(KERNEL_READ, file, result); -#endif /*OPLUS_FEATURE_IOMONITOR*/ return result; } EXPORT_SYMBOL(kernel_read); @@ -515,11 +506,6 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t fsnotify_modify(file); add_wchar(current, ret); } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if(ret > 0) { - iomonitor_update_rw_stats(KERNEL_WRITE, file, ret); - } -#endif /*OPLUS_FEATURE_IOMONITOR*/ inc_syscw(current); return ret; } @@ -536,9 +522,6 @@ ssize_t kernel_write(struct file *file, const void *buf, size_t count, /* The cast to a user pointer is valid due to the set_fs() */ res = vfs_write(file, (__force const char __user *)buf, count, pos); set_fs(old_fs); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_update_rw_stats(KERNEL_WRITE, file, res); -#endif /*OPLUS_FEATURE_IOMONITOR*/ return res; } EXPORT_SYMBOL(kernel_write); @@ -588,20 +571,11 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) { struct fd f = fdget_pos(fd); ssize_t ret = -EBADF; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - unsigned long read_time = jiffies; -#endif /*OPLUS_FEATURE_IOMONITOR*/ if (f.file) { loff_t pos = file_pos_read(f.file); ret = vfs_read(f.file, buf, count, &pos); if (ret >= 0) file_pos_write(f.file, pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (ret > 0) { - iomonitor_update_rw_stats(USER_READ, f.file, ret); - trace_syscall_read_timeout(f.file, jiffies_to_msecs(jiffies - read_time)); - } -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput_pos(f); } return ret; @@ -612,20 +586,11 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, { struct fd f = fdget_pos(fd); ssize_t ret = -EBADF; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - unsigned long write_time = jiffies; -#endif /*OPLUS_FEATURE_IOMONITOR*/ if (f.file) { loff_t pos = file_pos_read(f.file); ret = vfs_write(f.file, buf, count, &pos); if (ret >= 0) file_pos_write(f.file, pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (ret > 0) { - iomonitor_update_rw_stats(USER_WRITE, f.file, ret); - trace_syscall_write_timeout(f.file, jiffies_to_msecs(jiffies - write_time)); - } -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput_pos(f); } @@ -646,11 +611,6 @@ SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf, ret = -ESPIPE; if (f.file->f_mode & FMODE_PREAD) ret = vfs_read(f.file, buf, count, &pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_READ, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput(f); } return ret; @@ -670,11 +630,6 @@ SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf, ret = -ESPIPE; if (f.file->f_mode & FMODE_PWRITE) ret = vfs_write(f.file, buf, count, &pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_WRITE, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput(f); } return ret; @@ -1058,11 +1013,6 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec, ret = vfs_readv(f.file, vec, vlen, &pos, flags); if (ret >= 0) file_pos_write(f.file, pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_READ, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput_pos(f); } @@ -1083,11 +1033,6 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec, ret = vfs_writev(f.file, vec, vlen, &pos, flags); if (ret >= 0) file_pos_write(f.file, pos); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_WRITE, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput_pos(f); } @@ -1117,11 +1062,6 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec, ret = -ESPIPE; if (f.file->f_mode & FMODE_PREAD) ret = vfs_readv(f.file, vec, vlen, &pos, flags); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_READ, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput(f); } @@ -1145,11 +1085,6 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec, ret = -ESPIPE; if (f.file->f_mode & FMODE_PWRITE) ret = vfs_writev(f.file, vec, vlen, &pos, flags); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -/* Hank.liu@TECH.PLAT.Storage, 2020-02-18, add fs daily info*/ - if (ret > 0) - iomonitor_update_rw_stats(USER_WRITE, f.file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ fdput(f); } @@ -1228,10 +1163,6 @@ static size_t compat_readv(struct file *file, } if (ret > 0) add_rchar(current, ret); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (ret > 0) - iomonitor_update_rw_stats(USER_READ, file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ inc_syscr(current); return ret; } @@ -1342,10 +1273,6 @@ static size_t compat_writev(struct file *file, } if (ret > 0) add_wchar(current, ret); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (ret > 0) - iomonitor_update_rw_stats(USER_WRITE, file, ret); -#endif /*OPLUS_FEATURE_IOMONITOR*/ inc_syscw(current); return ret; } @@ -1524,12 +1451,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, else in.file->f_pos = pos; } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (retval > 0) { - iomonitor_update_rw_stats(USER_READ, in.file, retval); - iomonitor_update_rw_stats(USER_WRITE,in.file, retval); - } -#endif /*OPLUS_FEATURE_IOMONITOR*/ inc_syscr(current); inc_syscw(current); if (pos > max) @@ -1692,12 +1613,6 @@ done: fsnotify_modify(file_out); add_wchar(current, ret); } -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - if (ret > 0) { - iomonitor_update_rw_stats(USER_READ, file_in, ret); - iomonitor_update_rw_stats(USER_WRITE,file_in, ret); - } -#endif /*OPLUS_FEATURE_IOMONITOR*/ inc_syscr(current); inc_syscw(current); diff --git a/fs/sync.c b/fs/sync.c index 44903850ad8c..3d1445804125 100755 --- a/fs/sync.c +++ b/fs/sync.c @@ -18,16 +18,7 @@ #include #include "internal.h" -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for get cpu load -#include -#endif /*OPLUS_FEATURE_HEALTHINFO*/ -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#include -DEFINE_TRACE(syscall_sync_timeout); -#endif /*OPLUS_FEATURE_IOMONITOR*/ #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \ SYNC_FILE_RANGE_WAIT_AFTER) @@ -227,24 +218,13 @@ static int do_fsync(unsigned int fd, int datasync) struct fd f = fdget(fd); int ret = -EBADF; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for record fsync time - unsigned long fsync_time = jiffies; -#endif /*OPLUS_FEATURE_HEALTHINFO*/ if (f.file) { ret = vfs_fsync(f.file, datasync); fdput(f); -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) && defined(CONFIG_OPLUS_HEALTHINFO) - iomonitor_update_fs_stats(FS_FSYNC, 1); - trace_syscall_sync_timeout(f.file, jiffies_to_msecs(jiffies - fsync_time)); -#endif /*OPLUS_FEATURE_IOMONITOR & OPLUS_FEATURE_HEALTHINFO*/ inc_syscfs(current); } -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) - ohm_schedstats_record(OHM_SCHED_FSYNC, current, jiffies_to_msecs(jiffies - fsync_time)); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ return ret; } diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h index 6304ff30678b..0760ca1cb009 100755 --- a/include/linux/alarmtimer.h +++ b/include/linux/alarmtimer.h @@ -44,9 +44,6 @@ struct alarm { enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); enum alarmtimer_type type; int state; -#ifdef OPLUS_FEATURE_ALARMINFO_STANDBY - char comm[TASK_COMM_LEN]; -#endif /* OPLUS_FEATURE_ALARMINFO_STANDBY */ void *data; }; diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index 72ac0b2a7cdd..b186c4b464e0 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -185,11 +185,6 @@ struct backing_dev_info { enum { BLK_RW_ASYNC = 0, BLK_RW_SYNC = 1, -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue - BLK_RW_BG = 2, - BLK_RW_FG = 3, -#endif /*OPLUS_FEATURE_HEALTHINFO*/ }; void clear_wb_congested(struct bdi_writeback_congested *congested, int sync); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 7dfa7cc0018b..1616e14835fa 100755 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -250,9 +250,6 @@ enum req_flag_bits { __REQ_INTEGRITY, /* I/O includes block integrity payload */ __REQ_FUA, /* forced unit access */ __REQ_PREFLUSH, /* request for cache flush */ -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - __REQ_UX, /* ux activity */ -#endif __REQ_FG, /* foreground activity */ __REQ_RAHEAD, /* read ahead, can fail anytime */ __REQ_BACKGROUND, /* background IO */ @@ -278,9 +275,6 @@ enum req_flag_bits { #define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY) #define REQ_FUA (1ULL << __REQ_FUA) #define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH) -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#define REQ_UX (1ULL << __REQ_UX) -#endif #define REQ_FG (1ULL << __REQ_FG) #define REQ_RAHEAD (1ULL << __REQ_RAHEAD) #define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 00e200005928..fff4217f1aab 100755 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -146,12 +146,6 @@ struct request { int cpu; unsigned int cmd_flags; /* op and common flags */ req_flags_t rq_flags; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - ktime_t req_tg; - ktime_t req_ti; - ktime_t req_td; - ktime_t req_tc; -#endif /*OPLUS_FEATURE_IOMONITOR*/ int internal_tag; @@ -164,10 +158,6 @@ struct request { struct bio *bio; struct bio *biotail; -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - struct list_head fg_list; -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ /* * The hash is used inside the scheduler, and killed once the * request reaches the dispatch list. The ipi_list is only used @@ -416,14 +406,6 @@ struct request_queue { * Together with queue_head for cacheline sharing */ struct list_head queue_head; - #if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - struct list_head fg_head; - int fg_count; - int both_count; - int fg_count_max; - int both_count_max; -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ struct request *last_merge; struct elevator_queue *elevator; int nr_rqs[2]; /* # allocated [a]sync rqs */ @@ -551,12 +533,7 @@ struct request_queue { struct list_head tag_busy_list; unsigned int nr_sorted; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Modify for ioqueue - unsigned int in_flight[4]; -#else unsigned int in_flight[2]; -#endif /*OPLUS_FEATURE_HEALTHINFO*/ /* * Number of active block driver functions for which blk_drain_queue() @@ -761,26 +738,6 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) __clear_bit(flag, &q->queue_flags); } -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for ioqueue -static inline void ohm_ioqueue_add_inflight(struct request_queue *q, - struct request *rq) -{ - if (rq->cmd_flags & REQ_FG) - q->in_flight[BLK_RW_FG]++; - else - q->in_flight[BLK_RW_BG]++; -} - -static inline void ohm_ioqueue_dec_inflight(struct request_queue *q, - struct request *rq) -{ - if (rq->cmd_flags & REQ_FG) - q->in_flight[BLK_RW_FG]--; - else - q->in_flight[BLK_RW_BG]--; -} -#endif /*OPLUS_FEATURE_HEALTHINFO*/ #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags) #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 2702115c73b1..aaf9dbd19dea 100755 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -909,9 +909,6 @@ static inline bool policy_has_boost_freq(struct cpufreq_policy *policy) } #endif -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -ssize_t set_sugov_tl(unsigned int cpu, char *buf); -#endif extern void arch_freq_prepare_all(void); extern unsigned int arch_freq_get_on_cpu(int cpu); diff --git a/include/linux/hans.h b/include/linux/hans.h deleted file mode 100755 index bb6c62681c02..000000000000 --- a/include/linux/hans.h +++ /dev/null @@ -1,112 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, OPPO Mobile Comm Corp., Ltd. -** File: hans.h -** Description: Add for hans freeze manager -** -** Version: 1.0 -** Date : 2019/09/23 -** Author: #Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -** -** ------------------ Revision History:------------------------ -** -** Kun Zhou 2019/09/23 1.0 OPLUS_ARCH_EXTENDS -** Kun Zhou 2019/09/23 1.1 OPLUS_FEATURE_HANS_FREEZE -****************************************************************/ - -#ifndef _HANS_H -#define _HANS_H - -#include -#include -#include "../../kernel/sched/sched.h" - -#define HANS_NOERROR (0) -#define HANS_ERROR (-1) -#define MIN_USERAPP_UID (10000) -#define HANS_SYSTEM_UID (1000) -#define INTERFACETOKEN_BUFF_SIZE (140) -#define PARCEL_OFFSET (16) /*sync with the writeInterfaceToken*/ -#define CPUCTL_VERSION (2) - -/* hans_message for comunication with HANS native deamon - * type: async binder/sync binder/signal/pkg/loopback - * Only loop back type is duplex (native deamon <---> kernel) for handshake - * port: native deamon pid - * caller_pid: binder, caller -> unfreeze (target) UID - * target_uid: UID want to be unfrozen - * pkg_cmd: Add/Remove monitored UID - */ -struct hans_message { - int type; - int port; /*pid*/ - - int caller_uid; /*caller -> unfreeze UID*/ - int caller_pid; /*caller -> unfreeze UID*/ - int target_pid; /*unfreeze UID, pkg add/remove UID*/ - int target_uid; /*unfreeze UID, pkg add/remove UID*/ - - int pkg_cmd; /*Add/remove monitored uid*/ - - int code; - char rpc_name[INTERFACETOKEN_BUFF_SIZE]; -}; - -/*hans message type definition*/ -enum message_type { - ASYNC_BINDER, - SYNC_BINDER, - FROZEN_TRANS, - SIGNAL, - PKG, - - /*For cpuclt solution*/ - SYNC_BINDER_CPUCTL, - SIGNAL_CPUCTL, - CPUCTL_TRANS, - - /*kernel <--> native deamon*/ - LOOP_BACK, - TYPE_MAX -}; - -/*pkg cmd type*/ -enum pkg_cmd { - ADD_ONE_UID, - DEL_ONE_UID, - DEL_ALL_UID, - PKG_CMD_MAX -}; - -/*Check if the thread group is frozen*/ -static inline bool is_frozen_tg(struct task_struct *task) -{ - return (freezing(task->group_leader) || frozen(task->group_leader)); -} - -int hans_report(enum message_type type, int caller_pid, int caller_uid, int target_pid, int target_uid, const char *rpc_name, int code); -void hans_network_cmd_parse(uid_t uid, enum pkg_cmd cmd); -void hans_check_frozen_transcation(uid_t uid, enum message_type type); -int hans_netfilter_init(void); -void hans_netfilter_deinit(void); - -#if defined(CONFIG_CFS_BANDWIDTH) -static inline bool is_belong_cpugrp(struct task_struct *task) -{ - if (task->sched_task_group != NULL) { - struct cfs_bandwidth cfs_b = task->sched_task_group->cfs_bandwidth; - if (cfs_b.quota != -1) { - return true; - } else if (cfs_b.quota == -1) { - return false; - } - } - - return false; -} -#else -static inline bool is_belong_cpugrp(struct task_struct *task) -{ - return false; -} -#endif /*CONFIG_CFS_BANDWIDTH*/ -#endif /*_HANS_H*/ diff --git a/include/linux/healthinfo/fg.h b/include/linux/healthinfo/fg.h deleted file mode 100644 index ebb22ebf8bde..000000000000 --- a/include/linux/healthinfo/fg.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _FG_H_ -#define _FG_H_ - -#include -#include "../../../fs/proc/healthinfo/fg_uid/fg_uid.h" - -#ifdef CONFIG_FG_TASK_UID -static inline int current_is_fg(void) -{ - int cur_uid; - cur_uid = current_uid().val; - if (is_fg(cur_uid)) - return 1; - return 0; -} - -static inline int task_is_fg(struct task_struct *tsk) -{ - int cur_uid; - cur_uid = task_uid(tsk).val; - if (is_fg(cur_uid)) - return 1; - return 0; -} -#else -static inline int current_is_fg(void) -{ - return 0; -} - -static inline int task_is_fg(struct task_struct *tsk) -{ - return 0; -} - -static inline bool is_fg(int uid) -{ - return false; -} -#endif -#endif /*_FG_H_*/ diff --git a/include/linux/healthinfo/ion.h b/include/linux/healthinfo/ion.h deleted file mode 100644 index 5eead00eaeca..000000000000 --- a/include/linux/healthinfo/ion.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef __LINUX_ION_H__ -#define __LINUX_ION_H__ - -extern atomic_long_t ion_total_size; -extern bool ion_cnt_enable; -extern unsigned long ion_total(void); - -#endif /* __LINUX_ION_H__ */ - diff --git a/include/linux/healthinfo/jank_monitor.h b/include/linux/healthinfo/jank_monitor.h deleted file mode 100755 index 54ec86c7ec74..000000000000 --- a/include/linux/healthinfo/jank_monitor.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _OPPO_JANK_MONITOR_H_ -#define _OPPO_JANK_MONITOR_H_ - -enum { - JANK_TRACE_RUNNABLE = 0, - JANK_TRACE_DSTATE, - JANK_TRACE_SSTATE, - JANK_TRACE_RUNNING, -}; - -struct jank_d_state { - u64 iowait_ns; - u64 downread_ns; - u64 downwrite_ns; - u64 mutex_ns; - u64 other_ns; - int cnt; -}; - -struct jank_s_state{ - u64 binder_ns; - u64 epoll_ns; - u64 futex_ns; - u64 other_ns; - int cnt; -}; - -struct jank_monitor_info { - u64 runnable_state; - u64 ltt_running_state; /* ns */ - u64 big_running_state; /* ns */ - struct jank_d_state d_state; - struct jank_s_state s_state; -}; - -extern const struct file_operations proc_jank_trace_operations; - -#endif /*_OPPO_JANK_MONITOR_H_*/ diff --git a/include/linux/healthinfo/memory_monitor.h b/include/linux/healthinfo/memory_monitor.h deleted file mode 100755 index 5566e295c76c..000000000000 --- a/include/linux/healthinfo/memory_monitor.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#ifndef _MEMORY_MONITOR_H_ -#define _MEMORY_MONITOR_H_ -extern struct ion_wait_para ionwait_para; -extern void memory_alloc_monitor(gfp_t gfp_mask, unsigned int order, u64 wait_ms); - -extern struct alloc_wait_para allocwait_para; -extern void ionwait_monitor(u64 wait_ms); - - -#endif /*_MEMORY_MONITOR_H_*/ diff --git a/include/linux/healthinfo/slub_debug.h b/include/linux/healthinfo/slub_debug.h deleted file mode 100644 index 78492ebdc31c..000000000000 --- a/include/linux/healthinfo/slub_debug.h +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include /* struct reclaim_state */ -#include -#include -#include -#include -#include -#include "slab.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "internal.h" - -extern unsigned long slabs_node(struct kmem_cache *s, int node); -extern unsigned long node_nr_slabs(struct kmem_cache_node *n); -extern void inc_slabs_node(struct kmem_cache *s, int node, int objects); -extern void dec_slabs_node(struct kmem_cache *s, int node, int objects); - -extern int count_free(struct page *page); -extern unsigned long node_nr_objs(struct kmem_cache_node *n); - diff --git a/include/linux/iomonitor/iomonitor.h b/include/linux/iomonitor/iomonitor.h deleted file mode 100755 index 11557dd8cd4d..000000000000 --- a/include/linux/iomonitor/iomonitor.h +++ /dev/null @@ -1,263 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _IOMONITOR_H_ -#define _IOMONITOR_H_ - -/* Add for calculate free memory. */ -#include -#include - -/* Add for calculate free disk with f2fs. */ -#include -#include - -/* Add for statistical IO time-consuming distribution. */ -#include -#include -#include - -/* - * io monitor entry type - * NUM_ENTRY_TYPE: int value - * STR_ENTRY_TYPE: str value - * STR_FREE_ENTRY_TYPE: str value, need free string mem - */ -#define NUM_ENTRY_TYPE 0 -#define STR_ENTRY_TYPE 1 -#define STR_FREE_ENTRY_TYPE 2 -#define PRIVATE_ENTRY_TYPE 3 -#define IO_WAIT_TIMEOUT 500 -#define UX_IO_WAIT_TIMEOUT 300 -#define IO_WAIT_LOW 200 -#define IO_WAIT_HIGH 500 -enum { - IO_MONITOR_DELAY_SYNC = 0, - IO_MONITOR_DELAY_NSYNC, - IO_MONITOR_DELAY_BLOCK_NUM, -}; - -struct block_delay_data { - /* sync = 0, nsync = 1 */ - u64 stage_one[2]; - u64 stage_two[2]; - u64 stage_thr[2]; - u64 stage_fou[2]; - u64 stage_fiv[2]; - u64 stage_six[2]; - u64 stage_sev[2]; - u64 stage_eig[2]; - u64 stage_nin[2]; - u64 stage_ten[2]; - u64 max_delay[2]; - u64 cnt[2]; - u64 total_delay[2]; -}; - -enum { - IO_MONITOR_DELAY_READ = 0, - IO_MONITOR_DELAY_WRITE, - IO_MONITOR_DELAY_OPTION_NUM, -}; - -enum { - IO_MONITOR_DELAY_4K = 0, - IO_MONITOR_DELAY_512K, - IO_MONITOR_DELAY_DEVICE_NUM, -}; - -struct device_delay_data { - /* read = 0, write = 1 */ - u64 stage_one[2]; - u64 stage_two[2]; - u64 stage_thr[2]; - u64 stage_fou[2]; - u64 stage_fiv[2]; - u64 max_delay[2]; - u64 cnt[2]; - u64 total_delay[2]; -}; - -struct block_delay_data_ux { - u64 stage_one; - u64 stage_two; - u64 stage_thr; - u64 stage_fou; - u64 stage_fiv; - u64 stage_six; - u64 stage_sev; - u64 stage_eig; - u64 stage_nin; - u64 stage_ten; - u64 max_delay; - u64 cnt; - u64 total_delay; -}; - -struct req_delay_data { - struct block_delay_data_ux uxreq_block_para; - struct block_delay_data req_block_para; - /* 4K = 0, 512K = 1 */ - struct device_delay_data req_device_para[2]; -}; - -struct cal_data_info { - u64 user_read_data; - u64 user_write_data; - u64 kernel_read_data; - u64 kernel_write_data; - u64 dio_write_data; -}; - -struct cal_page_info { - u64 page_in; - u64 page_out; -}; - -struct fs_status_info { - atomic64_t major_fpage; - atomic64_t nfsync; - u64 discard; - u64 gc; - u64 task_rw_data; - u64 low_iowait; - u64 high_iowait; - atomic64_t dirty_page; -}; - -struct iowait_info { - u64 iowait_total_ms; - u64 iowait_total_count; - u64 iowait_1ms; - u64 iowait_10ms; - u64 iowait_20ms; - u64 iowait_60ms; - u64 iowait_100ms; - u64 iowait_200ms; - u64 iowait_300ms; - u64 iowait_400ms; - u64 iowait_500ms; - u64 iowait_600ms; - u64 iowait_800ms; - u64 iowait_1000ms; - u64 iowait_1500ms; - u64 iowait_2000ms; - u64 iowait_above2000ms; -}; - -struct abnormal_info { - int reason; - pid_t pid; - int delay; -}; - -enum iomointor_io_type { - IO_WAIT, - UX_IO_WAIT, - FRAME_DROP, - USER_TRIGGER -}; - -enum daily_data_type { - USER_READ, - USER_WRITE, - KERNEL_READ, - KERNEL_WRITE, - DIO_WRITE -}; - -enum rt_record_type { - RECORD_INIT, - RECORD_STOP, - RECORD_START, - RECORD_SIZE -}; - -/* monitor fs event like gc, discard, fsync*/ -enum fs_event_type { - FS_GC_OPT, - FS_DISCARD_OPT, - FS_FSYNC, - FS_MAJOR_FAULT, - FS_DIRTY_PAGES, -}; - -extern void iomonitor_update_rw_stats(enum daily_data_type type, - struct file *file, ssize_t ret); -extern void iomonitor_update_vm_stats(enum vm_event_item type, u64 delta); -extern void iomonitor_update_fs_stats(enum fs_event_type type, long delta); -extern void iomonitor_record_iowait(struct task_struct *tsk, u64 delta_ms); -#define PID_LENGTH 32 -#define PID_HASH_LEGNTH 199 -#define TASK_STATUS_LENGTH 4096 -#define UID_SHOW_DAILY_LIMIT (300*1024*1024) /* 300M */ -#define TASK_SHOW_DAILY_LIMIT (100*1024*1024) /* 100M */ -struct task_io_info { - pid_t pid; - pid_t tgid; - uid_t uid; - u64 read_bytes; - u64 write_bytes; - bool used; - char comm[TASK_COMM_LEN]; - unsigned long time; -}; - -struct disk_info { - unsigned int score; - unsigned int free; /* blocks */ - /* - * 4..8K |8..16K | 16..32K |32..64K | 64..128K | - * 128..256K | 256..512K | 512K..1M | 1M+ - */ - unsigned blocks[9]; -}; - -struct inter_disk_data { - unsigned int len; - char *buf; -}; - -#define IO_HISTORY_DEPTH 32 -struct io_history { - unsigned int cmd_flags; - unsigned long jiffies; -}; - -extern void iomonitor_record_io_history(const struct request *req); -extern int exit_uid_find_or_register(struct task_struct *task); -extern void free_all_uid_entry(void); - -int abnormal_handle(enum iomointor_io_type reason, pid_t pid, u64 delta_ms); - -struct proc_dir_entry *create_uid_proc(struct proc_dir_entry *parent); -struct proc_dir_entry *create_iotrace_proc(struct proc_dir_entry *parent); -/* extern void iomonitor_get_disk_info(struct super_block *sb, void *arg); */ - -void add_pid_to_list(struct task_struct *task, size_t bytes, bool opt); -static inline void iomonitor_record_task_io(struct task_struct *task, - size_t bytes, bool rw) -{ - add_pid_to_list(task, bytes, rw); -} - -static inline void iomonitor_init_reqstats(struct request *rq) -{ - rq->req_tg = ktime_get(); - rq->req_ti = ktime_set(0, 0); - rq->req_td = ktime_set(0, 0); - rq->req_tc = ktime_set(0, 0); -} - -void reqstats_record(struct request *req, unsigned nr_bytes); -static inline void iomonitor_record_reqstats(struct request *req, - unsigned int nr_bytes) -{ - req->req_tc = ktime_get(); - if (nr_bytes && req->req_tg && req->req_td && req->req_tc) - reqstats_record(req, nr_bytes); -} - -#endif /* _IOMONITOR_H_ */ diff --git a/include/linux/iomonitor/iotrace.h b/include/linux/iomonitor/iotrace.h deleted file mode 100755 index 4441b5883926..000000000000 --- a/include/linux/iomonitor/iotrace.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _IO_TRACE_H -#define _IO_TRACE_H - -#include - -DECLARE_TRACE(syscall_read_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -DECLARE_TRACE(syscall_write_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -DECLARE_TRACE(syscall_sync_timeout, - TP_PROTO(struct file *file, u64 delay), TP_ARGS(file, delay) -); - -#endif diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index b7cc46894852..15647d7e7c92 100755 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -20,9 +20,6 @@ #include #include -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) -#include -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ /* Free memory management - zoned buddy allocator. */ #ifndef CONFIG_FORCE_MAX_ZONEORDER @@ -32,9 +29,6 @@ #endif #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#define FREE_AREA_COUNTS 4 -#endif /* * PAGE_ALLOC_COSTLY_ORDER is the order at which allocations are deemed @@ -159,9 +153,6 @@ enum zone_stat_item { NR_ZSPAGES, /* allocated in zsmalloc */ #endif NR_FREE_CMA_PAGES, -#ifdef OPLUS_FEATURE_HEALTHINFO - NR_IONCACHE_PAGES, -#endif /* OPLUS_FEATURE_HEALTHINFO */ NR_VM_ZONE_STAT_ITEMS }; enum node_stat_item { @@ -371,12 +362,6 @@ enum zone_type { #ifndef __GENERATING_BOUNDS_H -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -struct page_label { - unsigned long label; - unsigned long segment; -}; -#endif struct zone { /* Read-mostly fields */ @@ -458,9 +443,6 @@ struct zone { unsigned long managed_pages; unsigned long spanned_pages; unsigned long present_pages; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct page_label zone_label[FREE_AREA_COUNTS]; -#endif const char *name; #ifdef CONFIG_MEMORY_ISOLATION @@ -483,11 +465,7 @@ struct zone { ZONE_PADDING(_pad1_) /* free areas of different sizes */ -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct free_area free_area[FREE_AREA_COUNTS][MAX_ORDER]; -#else struct free_area free_area[MAX_ORDER]; -#endif /* zone flags, see below */ unsigned long flags; @@ -682,12 +660,8 @@ typedef struct pglist_data { int node_id; wait_queue_head_t kswapd_wait; wait_queue_head_t pfmemalloc_wait; -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - struct task_struct *kswapd[MAX_KSWAPD_THREADS]; -#else struct task_struct *kswapd; /* Protected by mem_hotplug_begin/end() */ -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ int kswapd_order; enum zone_type kswapd_classzone_idx; diff --git a/include/linux/mutex.h b/include/linux/mutex.h index ad485b48ad75..079a425bcf4c 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -64,9 +64,6 @@ struct mutex { #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - struct task_struct *ux_dep_task; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ }; static inline struct task_struct *__mutex_owner(struct mutex *lock) @@ -87,9 +84,6 @@ struct mutex_waiter { #endif }; -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_DEBUG_MUTEXES @@ -128,22 +122,12 @@ do { \ # define __DEP_MAP_MUTEX_INITIALIZER(lockname) #endif -#ifndef OPLUS_FEATURE_SCHED_ASSIST #define __MUTEX_INITIALIZER(lockname) \ { .owner = ATOMIC_LONG_INIT(0) \ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \ __DEBUG_MUTEX_INITIALIZER(lockname) \ __DEP_MAP_MUTEX_INITIALIZER(lockname) } -#else /* OPLUS_FEATURE_SCHED_ASSIST */ -#define __MUTEX_INITIALIZER(lockname) \ - { .owner = ATOMIC_LONG_INIT(0) \ - , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ - , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \ - , .ux_dep_task = NULL \ - __DEBUG_MUTEX_INITIALIZER(lockname) \ - __DEP_MAP_MUTEX_INITIALIZER(lockname) } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 6bbb897bca5f..cb408ed438b9 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -49,9 +49,6 @@ void fdt_init_reserved_mem(void); void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size); struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); -#ifdef OPLUS_FEATURE_LOWMEM_DBG -unsigned long dt_memory_reserved_pages(void); -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ #else static inline int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx) @@ -67,12 +64,6 @@ static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np { return NULL; } -#ifdef OPLUS_FEATURE_LOWMEM_DBG -unsigned long dt_memory_reserved_pages(void) -{ - return 0; -} -#endif /* OPLUS_FEATURE_LOWMEM_DBG */ #endif /** diff --git a/include/linux/oplus_midas.h b/include/linux/oplus_midas.h deleted file mode 100644 index 2f2b98b2fa2a..000000000000 --- a/include/linux/oplus_midas.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-2.0-only - * - * Copyright (C) 2019-2020 Oplus. All rights reserved. - */ - -#ifndef __OPLUS_MIDAS_H__ -#define __OPLUS_MIDAS_H__ - -#include - -#ifdef CONFIG_OPLUS_FEATURE_MIDAS -void midas_record_task_times(uid_t uid, u64 cputime, - struct task_struct *p, unsigned int state); -#else -static inline void midas_record_task_times(uid_t uid, u64 cputime, - struct task_struct *p, unsigned int state) { } -#endif - -#endif /* __OPLUS_MIDAS_H__ */ diff --git a/include/linux/oppo_mm_kevent_fb.h b/include/linux/oppo_mm_kevent_fb.h deleted file mode 100755 index 11808b0cf52b..000000000000 --- a/include/linux/oppo_mm_kevent_fb.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************** -** Copyright (C), 2018, OPPO Mobile Comm Corp., Ltd -** File : oppo_mm_kevent_fb.h -** Description : MM kevent fb data -** Version : 1.0 -** Date : 2018/12/03 -** -** ------------------------------- Revision History: ----------- -** -** Guo.Ling 2018/12/03 1.0 Build this moudle -******************************************************************/ -#ifndef _OPPO_MM_KEVENT_FB_ -#define _OPPO_MM_KEVENT_FB_ - -enum OPPO_MM_DIRVER_FB_EVENT_ID { - OPPO_MM_DIRVER_FB_EVENT_ID_ESD = 401, - OPPO_MM_DIRVER_FB_EVENT_ID_VSYNC, - OPPO_MM_DIRVER_FB_EVENT_ID_HBM, - OPPO_MM_DIRVER_FB_EVENT_ID_FFLSET, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_CMDQ, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_UNDERFLOW, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_FENCE, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_GPU_JS, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_GPU_SOFT_RESET, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_GPU_MMU_FAULT, - OPPO_MM_DIRVER_FB_EVENT_ID_MTK_GPU_FAULT, - OPPO_MM_DIRVER_FB_EVENT_ID_AUDIO = 801, -}; - -enum OPPO_MM_DIRVER_FB_EVENT_MODULE { - OPPO_MM_DIRVER_FB_EVENT_MODULE_DISPLAY = 0, - OPPO_MM_DIRVER_FB_EVENT_MODULE_AUDIO -}; - -enum OPPO_MM_DIRVER_FB_EVENT_REPORTLEVEL { - OPPO_MM_DIRVER_FB_EVENT_REPORTLEVEL_LOW = 0, - OPPO_MM_DIRVER_FB_EVENT_REPORTLEVEL_HIGH -}; - -int upload_mm_kevent_fb_data(enum OPPO_MM_DIRVER_FB_EVENT_MODULE module, unsigned char *payload); - -#endif /* _OPPO_MM_KEVENT_FB_ */ - diff --git a/include/linux/prefer_silver.h b/include/linux/prefer_silver.h deleted file mode 100644 index e86f15b33258..000000000000 --- a/include/linux/prefer_silver.h +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _OPLUS_PREFER_SILVER_H_ -#define _OPLUS_PREFER_SILVER_H_ - -#ifdef CONFIG_SCHED_WALT -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#define scale_demand(d) ((d)/walt_scale_demand_divisor) -#endif - -extern int sysctl_prefer_silver; -extern int sysctl_heavy_task_thresh; -extern int sysctl_cpu_util_thresh; -extern int sysctl_silver_trigger_freq; - -extern bool prefer_silver_check_ux(struct task_struct *task); - -extern bool prefer_silver_check_freq(int cpu); -extern bool prefer_silver_check_task_util(struct task_struct *p); -extern bool prefer_silver_check_cpu_util(int cpu); - -#endif /*_OPLUS_PREFER_SILVER_H_*/ diff --git a/include/linux/process_mm_reclaim.h b/include/linux/process_mm_reclaim.h deleted file mode 100755 index c86e26479dd7..000000000000 --- a/include/linux/process_mm_reclaim.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef __PROCESS_MM_RECLAIM_H__ -#define __PROCESS_MM_RECLAIM_H__ - -#include -#include -#include -#include -#include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0) -#include -#endif -#define PR_PASS 0 -#define PR_SEM_OUT 1 -#define PR_TASK_FG 2 -#define PR_TIME_OUT 3 -#define PR_ADDR_OVER 4 -#define PR_FULL 5 -#define PR_TASK_RUN 6 -#define PR_TASK_DIE 7 - -#define RECLAIM_TIMEOUT_JIFFIES (HZ/3) -#define RECLAIM_PAGE_NUM 1024ul - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -/* - * qualcomm has define the sturct in mm.h, - * mtk do not define it, used for transfer param during scan pages. - */ -struct reclaim_param { - struct vm_area_struct *vma; - /* Number of pages scanned */ - int nr_scanned; - /* max pages to reclaim */ - int nr_to_reclaim; - /* pages reclaimed */ - int nr_reclaimed; - /* - * flag that relcaim inactive pages only - */ - bool inactive_lru; - /* - * the target reclaimed process - */ - struct task_struct *reclaimed_task; -}; -#endif - -extern int is_reclaim_should_cancel(struct mm_walk *walk); -extern int is_reclaim_addr_over(struct mm_walk *walk, unsigned long addr); -extern int __weak create_process_reclaim_enable_proc(struct proc_dir_entry *parent); -#endif /* __PROCESS_MM_RECLAIM_H__ */ diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 0b60022c710a..a3627476d8e3 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -14,13 +14,8 @@ extern int isolate_lru_page(struct page *page); extern void putback_lru_page(struct page *page); -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -extern unsigned long reclaim_pages_from_list(struct list_head *page_list, - struct vm_area_struct *vma, struct mm_walk *walk); -#else extern unsigned long reclaim_pages_from_list(struct list_head *page_list, struct vm_area_struct *vma); -#endif /* * The anon_vma heads a list of private "related" vmas, to scan if diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 18dd21d4fdc3..a79b7845fb40 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -22,14 +22,6 @@ struct rw_semaphore; -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 -extern void uxchain_rwsem_wake(struct task_struct *tsk, - struct rw_semaphore *sem); -extern void uxchain_rwsem_down(struct rw_semaphore *sem); -extern void uxchain_rwsem_up(struct rw_semaphore *sem); -#define PREEMPT_DISABLE_RWSEM 3000000 -#endif #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK #include /* use a generic implementation */ @@ -54,9 +46,6 @@ struct rw_semaphore { #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - struct task_struct *ux_dep_task; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ }; /* @@ -72,9 +61,6 @@ extern struct rw_semaphore *rwsem_down_write_failed_killable(struct rw_semaphore extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *); extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* Include the arch specific part */ #include @@ -97,11 +83,7 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem) #endif #ifdef CONFIG_RWSEM_SPIN_ON_OWNER -#ifndef OPLUS_FEATURE_SCHED_ASSIST #define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED, .owner = NULL -#else /* OPLUS_FEATURE_SCHED_ASSIST */ -#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED, .owner = NULL, .ux_dep_task = NULL -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #else #define __RWSEM_OPT_INIT(lockname) #endif diff --git a/include/linux/sched.h b/include/linux/sched.h index db3a5749ceb2..1d4a0a33cc33 100755 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -27,12 +27,6 @@ #include #include -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) -#include -#endif /* OPLUS_FEATURE_HEALTHINFO */ -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -#include -#endif /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context; @@ -209,21 +203,8 @@ struct task_group; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern int sysctl_sched_assist_enabled; -extern int sysctl_sched_assist_scene; -extern int sysctl_animation_type; -extern int sysctl_slide_boost_enabled; -extern int sysctl_boost_task_threshold; -extern int sysctl_input_boost_enabled; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - -#ifdef CONFIG_OPLUS_PREFER_SILVER -extern int sysctl_prefer_silver; -#endif /* CONFIG_OPLUS_PREFER_SILVER */ - /* Task command name length: */ #define TASK_COMM_LEN 16 @@ -767,15 +748,6 @@ struct wake_q_node { struct wake_q_node *next; }; -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -/* Kui.Zhang@TEC.Kernel.Performance, 2019/03/04 - * Record process reclaim memory information - */ -union reclaim_limit { - unsigned long stop_jiffies; - unsigned long stop_scan_addr; -}; -#endif struct task_struct { #ifdef CONFIG_THREAD_INFO_IN_TASK @@ -800,10 +772,6 @@ struct task_struct { unsigned int flags; unsigned int ptrace; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - u64 wake_tid; - u64 running_start_time; -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ #ifdef CONFIG_SMP struct llist_node wake_entry; @@ -841,9 +809,6 @@ struct task_struct { u64 last_sleep_ts; #endif u64 last_enqueued_ts; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - u64 last_wake_ts; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_CGROUP_SCHED struct task_group *sched_task_group; @@ -1072,9 +1037,6 @@ struct task_struct { #endif #ifdef CONFIG_DETECT_HUNG_TASK unsigned long last_switch_count; -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - bool hang_detection_enabled; -#endif /* CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE */ #endif /* Filesystem information: */ @@ -1323,10 +1285,6 @@ struct task_struct { int latency_record_count; struct latency_record latency_record[LT_SAVECOUNT]; #endif -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_ION) && defined(CONFIG_DUMP_TASKS_MEM) - struct list_head user_tasks; - atomic64_t ions; -#endif #ifdef CONFIG_OPLUS_FEATURE_UID_PERF #define UID_PERF_EVENTS 3 @@ -1401,24 +1359,7 @@ struct task_struct { /* KCOV sequence number: */ int kcov_sequence; #endif -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - struct task_info oplus_task_info; -#endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - int ux_state; - atomic64_t inherit_ux; - struct list_head ux_entry; - int ux_depth; - u64 enqueue_time; - u64 inherit_ux_start; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - int ux_once; - u64 get_mmlock_ts; - int get_mmlock; -#endif #ifdef CONFIG_MEMCG struct mem_cgroup *memcg_in_oom; @@ -1428,12 +1369,6 @@ struct task_struct { /* Number of pages to reclaim on returning to userland: */ unsigned int memcg_nr_pages_over_high; #endif -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - /* Kui.Zhang@TEC.Kernel.Performance, 2019/03/04 - * Record process reclaim infor - */ - union reclaim_limit reclaim; -#endif #ifdef CONFIG_UPROBES struct uprobe_task *utask; #endif @@ -1470,16 +1405,6 @@ struct task_struct { atomic_t inherit_types; #endif -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - int jank_trace; - struct jank_monitor_info jank_info; - unsigned in_mutex:1; - unsigned in_downread:1; - unsigned in_downwrite:1; - unsigned in_futex:1; - unsigned in_binder:1; - unsigned in_epoll:1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ /* * New fields for task_struct should be added above here, so that @@ -1704,11 +1629,6 @@ extern struct pid *cad_pid; #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ #define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */ -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -#define PF_RECLAIM_SHRINK 0x02000000 /* Flag the task is memory compresser */ - -#define current_is_reclaimer() (current->flags & PF_RECLAIM_SHRINK) -#endif /* * Only the _current_ task can read/write to tsk->flags, but other @@ -1901,26 +1821,10 @@ extern void kick_process(struct task_struct *tsk); static inline void kick_process(struct task_struct *tsk) { } #endif -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL -extern pid_t alloc_svc_tgid; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern void sched_assist_target_comm(struct task_struct *task); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -extern void get_target_thread_pid(struct task_struct *p); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ static inline void set_task_comm(struct task_struct *tsk, const char *from) { __set_task_comm(tsk, from, false); -#ifdef CONFIG_OPLUS_ION_BOOSTPOOL - if (!strncmp(from, "allocator@4.0-s", TASK_COMM_LEN)) - alloc_svc_tgid = tsk->tgid; -#endif /* CONFIG_OPLUS_ION_BOOSTPOOL */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - get_target_thread_pid(tsk); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ } extern char *__get_task_comm(char *to, size_t len, struct task_struct *tsk); diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index 04b4d1291c40..8aba19dc0c94 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -12,11 +12,6 @@ #define SCHED_CPUFREQ_DL (1U << 1) #define SCHED_CPUFREQ_IOWAIT (1U << 2) -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -#define SCHED_CPUFREQ_WALT (1U << 4) -#define SCHED_CPUFREQ_RESET (1U << 7) -#define SCHED_CPUFREQ_BOOST (1U << 9) -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_CPU_FREQ struct update_util_data { diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h index 97a48d5f4314..585f168112f6 100755 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h @@ -11,9 +11,6 @@ extern int sysctl_hung_task_check_count; extern unsigned int sysctl_hung_task_panic; extern unsigned long sysctl_hung_task_timeout_secs; extern int sysctl_hung_task_warnings; -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -extern int sysctl_hung_task_selective_monitoring; -#endif extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); @@ -117,11 +114,5 @@ extern int sysctl_schedstats(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern int sysctl_sched_assist_scene_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #endif /* _LINUX_SCHED_SYSCTL_H */ diff --git a/include/linux/sched_assist/Kconfig b/include/linux/sched_assist/Kconfig deleted file mode 100755 index 4a7313f0ca61..000000000000 --- a/include/linux/sched_assist/Kconfig +++ /dev/null @@ -1,27 +0,0 @@ -config OPLUS_FEATURE_SCHED_ASSIST - tristate "sched_assist" - default n - help - turning sched for ui, render and so on to improve UX -config OPLUS_FEATURE_SCHED_SPREAD - bool "sched_spread" - default n - help - This is the uifirst 5.0 feature, which will spread tasks, - kick runnable time from task demand and adjust bg's time slice. -config OPLUS_FEATURE_AUDIO_OPT - bool "config audio opt" - default n - help - audio task schedule opt -config MMAP_LOCK_OPT - bool "config mmap lock opt" - default n - depends on OPLUS_FEATURE_SCHED_ASSIST - help - reduce sleep time in mmap lock -config OPLUS_ALLBOOST_OPT - bool "config allboost opt" - default n - help - Make the SCHED_ALL_BOOST function take effect diff --git a/include/linux/sched_assist/Makefile b/include/linux/sched_assist/Makefile deleted file mode 100755 index 61875582e24c..000000000000 --- a/include/linux/sched_assist/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -obj-y += sched_assist_common.o -obj-y += sched_assist_mutex.o -obj-y += sched_assist_rwsem.o -obj-y += sched_assist_futex.o -obj-y += sched_assist_workqueue.o -obj-y += sched_assist_rt.o - -#qcom -ifeq ($(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM), y) -ifeq ($(VERSION).$(PATCHLEVEL), 5.4) -obj-y += sched_assist_slide.o -endif -#mtk -else -obj-$(CONFIG_SCHED_WALT) += sched_assist_slide_v1.o -endif diff --git a/include/linux/sched_assist/sched_assist_binder.h b/include/linux/sched_assist/sched_assist_binder.h deleted file mode 100755 index f95ee6ba2bf5..000000000000 --- a/include/linux/sched_assist/sched_assist_binder.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_BINDER_H_ -#define _OPLUS_SCHED_BINDER_H_ -#include "sched_assist_common.h" - -extern const struct sched_class rt_sched_class; -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern inline bool is_audio_task(struct task_struct *task); -#endif -static inline void binder_set_inherit_ux(struct task_struct *thread_task, struct task_struct *from_task) -{ - if (from_task && test_set_inherit_ux(from_task)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, from_task->ux_state); - else - reset_inherit_ux(thread_task, from_task, INHERIT_UX_BINDER); - } else if (from_task && test_task_identify_ux(from_task, SA_TYPE_ID_CAMERA_PROVIDER)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } else if (from_task && (from_task->sched_class == &rt_sched_class)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - else if (from_task && (is_audio_task(from_task))) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } -#endif -} - -static inline void binder_unset_inherit_ux(struct task_struct *thread_task) -{ - if (test_inherit_ux(thread_task, INHERIT_UX_BINDER)) { - unset_inherit_ux(thread_task, INHERIT_UX_BINDER); - } -} -#endif /* _OPLUS_SCHED_BINDER_H_ */ diff --git a/include/linux/sched_assist/sched_assist_common.c b/include/linux/sched_assist/sched_assist_common.c deleted file mode 100755 index 46fd2c298774..000000000000 --- a/include/linux/sched_assist/sched_assist_common.c +++ /dev/null @@ -1,2583 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include -#include <../kernel/sched/sched.h> -#include -#include -#include -#include <../fs/proc/internal.h> -#include -#include -#include -#include "sched_assist_common.h" -#include "sched_assist_slide.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) -#include -#include -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include <../kernel/sched/walt/walt.h> -#else -#include <../kernel/sched/walt.h> -#endif - -#define THRESHOLD_BOOST 102 - -int ux_min_sched_delay_granularity; -int ux_max_inherit_exist = 1000; -int ux_max_inherit_granularity = 32; -int ux_min_migration_delay = 10; -int ux_max_over_thresh = 2000; - -/* Params for slide boost */ -int sysctl_animation_type = 0; -int sysctl_input_boost_enabled = 0; -int sysctl_sched_assist_ib_duration_coedecay = 1; -u64 sched_assist_input_boost_duration = 0; -int sched_assist_ib_duration_coedecay = 1; -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -int sysctl_sched_impt_tgid = 0; -#endif - -#define S2NS_T 1000000 - -static int param_ux_debug = 0; -unsigned int ux_uclamp_value = 256; -module_param_named(debug, param_ux_debug, uint, 0644); -module_param_named(ux_uclamp_value, ux_uclamp_value, uint, 0664); - -#define MAX_IMPT_SAVE_PID (2) -pid_t save_impt_tgid[MAX_IMPT_SAVE_PID]; -pid_t save_top_app_tgid; -unsigned int top_app_type; -struct cpumask nr_mask; - -struct ux_sched_cputopo ux_sched_cputopo; - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -DEFINE_PER_CPU(struct task_count_rq, task_lb_count); -void init_rq_cpu(int cpu) -{ - per_cpu(task_lb_count, cpu).ux_low = 0; - per_cpu(task_lb_count, cpu).ux_high = 0; - per_cpu(task_lb_count, cpu).top_low = 0; - per_cpu(task_lb_count, cpu).top_high = 0; - per_cpu(task_lb_count, cpu).foreground_low = 0; - per_cpu(task_lb_count, cpu).foreground_high = 0; - per_cpu(task_lb_count, cpu).background_low = 0; - per_cpu(task_lb_count, cpu).background_high = 0; -} -#endif - -static inline void sched_init_ux_cputopo(void) -{ - int i = 0; - - ux_sched_cputopo.cls_nr = 0; - for (; i < NR_CPUS; ++i) { - cpumask_clear(&ux_sched_cputopo.sched_cls[i].cpus); - ux_sched_cputopo.sched_cls[i].capacity = ULONG_MAX; - } -} - -void update_ux_sched_cputopo(void) -{ - unsigned long prev_cap = 0; - unsigned long cpu_cap = 0; - unsigned int cpu = 0; - int i = 0, insert_idx = 0, cls_nr = 0; - struct ux_sched_cluster sched_cls; - - /* reset prev cpu topo info */ - sched_init_ux_cputopo(); - - /* update new cpu topo info */ - for_each_possible_cpu(cpu) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - cpu_cap = arch_scale_cpu_capacity(cpu); -#else - cpu_cap = arch_scale_cpu_capacity(NULL, cpu); -#endif - - /* add cpu with same capacity into target sched_cls */ - if (cpu_cap == prev_cap) { - for (i = 0; i < ux_sched_cputopo.cls_nr; ++i) { - if (cpu_cap == ux_sched_cputopo.sched_cls[i].capacity) { - cpumask_set_cpu(cpu, &ux_sched_cputopo.sched_cls[i].cpus); - break; - } - } - - continue; - } - - cpumask_clear(&sched_cls.cpus); - cpumask_set_cpu(cpu, &sched_cls.cpus); - sched_cls.capacity = cpu_cap; - cls_nr = ux_sched_cputopo.cls_nr; - - if (!cls_nr) { - ux_sched_cputopo.sched_cls[cls_nr] = sched_cls; - } else { - for (i = 0; i <= ux_sched_cputopo.cls_nr; ++i) { - if (sched_cls.capacity < ux_sched_cputopo.sched_cls[i].capacity) { - insert_idx = i; - break; - } - } - if (insert_idx == ux_sched_cputopo.cls_nr) { - ux_sched_cputopo.sched_cls[insert_idx] = sched_cls; - } else { - for (; cls_nr > insert_idx; cls_nr--) { - ux_sched_cputopo.sched_cls[cls_nr] = ux_sched_cputopo.sched_cls[cls_nr-1]; - } - ux_sched_cputopo.sched_cls[insert_idx] = sched_cls; - } - } - ux_sched_cputopo.cls_nr++; - - prev_cap = cpu_cap; - } - - for (i = 0; i < ux_sched_cputopo.cls_nr; i++) - ux_debug("update ux sched cpu topology [cls_nr:%d cpus:%*pbl cap:%lu]", - i, cpumask_pr_args(&ux_sched_cputopo.sched_cls[i].cpus), ux_sched_cputopo.sched_cls[i].capacity); -} - -static inline struct task_struct *task_of(struct sched_entity *se) -{ - return container_of(se, struct task_struct, se); -} - -static int entity_before(struct sched_entity *a, struct sched_entity *b) -{ - return (s64)(a->vruntime - b->vruntime) < 0; -} - -static int entity_over(struct sched_entity *a, struct sched_entity *b) -{ - return (s64)(a->vruntime - b->vruntime) > (s64)ux_max_over_thresh * S2NS_T; -} - -extern const struct sched_class fair_sched_class; - -/* identify ux only opt in some case, but always keep it's id_type, and wont do inherit through test_task_ux() */ -bool test_task_identify_ux(struct task_struct *task, int id_type_ux) -{ - if (id_type_ux == SA_TYPE_ID_CAMERA_PROVIDER) { - struct task_struct *grp_leader = task->group_leader; - /* consider provider's HwBinder in configstream */ - if ((task->ux_state & SA_TYPE_LISTPICK) && (grp_leader->ux_state & SA_TYPE_ID_CAMERA_PROVIDER)) - return true; - return (task->ux_state & SA_TYPE_ID_CAMERA_PROVIDER) && (sysctl_sched_assist_scene & SA_CAMERA); - } else if (id_type_ux == SA_TYPE_ID_ALLOCATOR_SER) { - if (task && (task->ux_state & SA_TYPE_ID_ALLOCATOR_SER) && (sysctl_sched_assist_scene & SA_CAMERA)) - return true; - } - - return false; -} - -inline bool test_task_ux(struct task_struct *task) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - if (!task) - return false; - - if (task->sched_class != &fair_sched_class) - return false; -#ifdef CONFIG_KERNEL_LOCK_OPT - if (test_task_lock_ux(task)) - return true; -#endif - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - /* during gesture animation, top application should not be optimized except launcher */ - if (sched_assist_scene(SA_ANIM) && save_top_app_tgid && (task->tgid == save_top_app_tgid) && (top_app_type != 1)) - return false; -#endif - - if (task->ux_state & (SA_TYPE_HEAVY | SA_TYPE_LIGHT | SA_TYPE_ANIMATOR | SA_TYPE_LISTPICK)) - return true; - - return false; -} - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -static unsigned long task_util_mtk(struct task_struct *p, bool flag) -{ -#ifdef CONFIG_SCHED_WALT - if (likely(!walt_disabled && (sysctl_sched_use_walt_task_util || flag))) - return (p->ravg.demand / (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif - return READ_ONCE(p->se.avg.util_avg); -} -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_MTK */ - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -#define NR_IMBALANCE_THRESHOLD (24) -void update_rq_nr_imbalance(int cpu) -{ - int total_nr = 0; - int i = -1; - int threshold = NR_IMBALANCE_THRESHOLD; - - /* Note: check without holding rq lock */ - for_each_cpu(i, cpu_active_mask) { - total_nr += cpu_rq(i)->cfs.nr_running; - if (idle_cpu(i)) - cpumask_clear_cpu(i, &nr_mask); - } - - if (!idle_cpu(cpu) && (total_nr >= threshold)) { - cpumask_set_cpu(cpu, &nr_mask); - } else { - cpumask_clear_cpu(cpu, &nr_mask); - } -} - -bool should_force_spread_tasks(void) { - return !cpumask_empty(&nr_mask); -} - -#ifdef CONFIG_CGROUP_SCHED -static inline int task_cgroup_id(struct task_struct *task) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - struct cgroup_subsys_state *css = task_css(task, cpu_cgrp_id); -#else - struct cgroup_subsys_state *css = task_css(task, schedtune_cgrp_id); -#endif - - return css ? css->id : -1; -} -#else -static inline int task_cgroup_id(struct task_struct *task) -{ - return -1; -} -#endif - -int task_lb_sched_type(struct task_struct *tsk) -{ - int cgroup_type = task_cgroup_id(tsk); - - if (test_task_ux(tsk)) - return SA_UX; - else if (cgroup_type == SA_CGROUP_TOP_APP) - return SA_TOP; - else if (cgroup_type == SA_CGROUP_FOREGROUD || cgroup_type == SA_CGROUP_DEFAULT) - return SA_FG; - else if (cgroup_type == SA_CGROUP_BACKGROUD) - return SA_BG; - - return -1; -} - -#ifdef CONFIG_SCHED_WALT -bool task_high_load(struct task_struct *tsk) -{ - unsigned int cpu = 0; - unsigned long capacity = capacity_orig_of(cpu); - unsigned long max_capacity = cpu_rq(cpu)->rd->max_cpu_capacity.val; - unsigned int margin; - int sched_type = task_lb_sched_type(tsk); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - unsigned long load = tsk->wts.demand_scaled; -#else - unsigned long load = (tsk->ravg.demand / (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif - - if (sched_type == SA_BG) - load = min(load, tsk->se.avg.util_avg); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - load = clamp(load, - uclamp_eff_value(tsk, UCLAMP_MIN), - uclamp_eff_value(tsk, UCLAMP_MAX)); -#endif - if (capacity == max_capacity) - return true; - - if (capacity_orig_of(task_cpu(tsk)) > capacity_orig_of(cpu)) - margin = sched_capacity_margin_down[cpu]; - else - margin = sched_capacity_margin_up[task_cpu(tsk)]; - - return capacity * 1024 < load * margin; -} -#endif -void dec_task_lb(struct task_struct *tsk, struct rq *rq, - int high_load, int task_type) -{ - int cpu = cpu_of(rq); - - if (high_load == SA_HIGH_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_high--; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_high--; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_high--; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_high--; - break; - } - } else if (high_load == SA_LOW_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_low--; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_low--; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_low--; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_low--; - break; - } - } -} - -void inc_task_lb(struct task_struct *tsk, struct rq *rq, - int high_load, int task_type) -{ - int cpu = cpu_of(rq); - - if (high_load == SA_HIGH_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_high++; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_high++; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_high++; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_high++; - break; - } - } else if (high_load == SA_LOW_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_low++; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_low++; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_low++; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_low++; - break; - } - } -} - -void update_load_flag(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = task_high_load(tsk); - int curr_task_type = task_lb_sched_type(tsk); - - if (tsk->lb_state != 0) { - int prev_high_load = tsk->lb_state & 0x1; - int prev_task_type = (tsk->lb_state >> 1) & 0x7; - - if (prev_high_load == curr_high_load && prev_task_type == curr_task_type) - return; - else - dec_task_lb(tsk, rq, prev_high_load, prev_task_type); - } - inc_task_lb(tsk, rq, curr_high_load, curr_task_type); - tsk->lb_state = (curr_task_type << 1) | curr_high_load; -} - -void inc_ld_stats(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = tsk->lb_state & 0x1; - int curr_task_type = (tsk->lb_state >> 1) & 0x7; - - inc_task_lb(tsk, rq, curr_high_load, curr_task_type); - tsk->ld_flag = 1; -} - -void dec_ld_stats(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = tsk->lb_state & 0x1; - int curr_task_type = (tsk->lb_state >> 1) & 0x7; - - tsk->ld_flag = 0; - dec_task_lb(tsk, rq, curr_high_load, curr_task_type); -} - -#define MAX_ADJ_NICE (5) -#define MAX_ADJ_PRIO (DEFAULT_PRIO + MAX_ADJ_NICE - 1) -const int sched_prio_to_weight_bg[MAX_ADJ_NICE] = { 716, 601, 510, 438, 380, }; -const int sched_prio_to_wmult_bg[MAX_ADJ_NICE] = { 5998558, 7146368, 8421505, 9805861, 11302546, }; - -/* keep same as defined in sched/fair.c */ -#define OPLUS_WMULT_CONST (~0U) -#define OPLUS_WMULT_SHIFT 32 - -/* keep same as defined in sched/fair.c */ -static void __oplus_update_inv_weight(struct load_weight *lw) -{ - unsigned long w; - - if (likely(lw->inv_weight)) - return; - - w = scale_load_down(lw->weight); - - if (BITS_PER_LONG > 32 && unlikely(w >= OPLUS_WMULT_CONST)) - lw->inv_weight = 1; - else if (unlikely(!w)) - lw->inv_weight = OPLUS_WMULT_CONST; - else - lw->inv_weight = OPLUS_WMULT_CONST / w; -} - -static struct load_weight sa_new_weight(struct sched_entity *se) { - struct task_struct *task = NULL; - struct load_weight lw; - int sched_type = -1; - int idx = -1; - int i = 0; - - if ((sysctl_sched_assist_enabled < 2) || !entity_is_task(se) || sched_assist_scene(SA_CAMERA)) { - return se->load; - } - - task = container_of(se, struct task_struct, se); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if ((task->static_prio < DEFAULT_PRIO) || (task->static_prio > MAX_ADJ_PRIO) || (task_util(task) < 51)) -#else - if ((task->static_prio < DEFAULT_PRIO) || (task->static_prio > MAX_ADJ_PRIO) || (task_util_mtk(task, true) < 51)) -#endif - return se->load; - - /* skip important process such as audio proc */ - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] && (task->tgid == save_impt_tgid[i])) - return se->load; - } - - /* we only adjust background group's load weight */ - sched_type = task_lb_sched_type(task); - if (sched_type != SA_BG) - return se->load; - - idx = task->static_prio - DEFAULT_PRIO; - lw.weight = scale_load(sched_prio_to_weight_bg[idx]); - lw.inv_weight = sched_prio_to_wmult_bg[idx]; - - return lw; -} - -u64 sa_calc_delta(struct sched_entity *se, u64 delta_exec, unsigned long weight, struct load_weight *lw, bool calc_fair) -{ - u64 fact = 0; - u32 inv_weight = 0; - int shift = OPLUS_WMULT_SHIFT; - struct load_weight sa_lw = sa_new_weight(se); - - if (calc_fair && (sa_lw.weight == lw->weight) && (lw->weight == NICE_0_LOAD)) - return delta_exec; - - __oplus_update_inv_weight(lw); - - if (calc_fair) { /* __calc_delta(delta, NICE_0_LOAD, &se->load) */ - fact = scale_load_down(weight); - inv_weight = sa_lw.inv_weight; - } else { /* __calc_delta(slice, sa_lw.weight, load) */ - fact = scale_load_down(sa_lw.weight); - inv_weight = lw->inv_weight; - } - - if (unlikely(fact >> 32)) { - while (fact >> 32) { - fact >>= 1; - shift--; - } - } - - /* hint to use a 32x32->64 mul */ - fact = (u64)(u32)fact * inv_weight; - - while (fact >> 32) { - fact >>= 1; - shift--; - } - - return mul_u64_u32_shr(delta_exec, fact, shift); -} - -bool should_force_adjust_vruntime(struct sched_entity *se) -{ - struct task_struct *se_task = NULL; - - if (sysctl_sched_assist_enabled < 2 || sched_assist_scene(SA_CAMERA)) - return false; - - if (!entity_is_task(se)) - return false; - - se_task = task_of(se); - /* requeue runnable inherit ux task should be adjusted */ - if (se_task && (se_task->ux_state & SA_TYPE_INHERIT)) - return true; - - return false; -} -static void find_spread_lowest_nr_cpu(struct task_struct *p, cpumask_t *visit_cpus_t, int sched_type, int prev_cpu, int skip_cpu, - int *lowest_nr, int *lowest_nr_load, int *lowest_nr_cpu) -{ - int i = 0; - for_each_cpu(i, visit_cpus_t) { - int ux_nr = 0; - int top_nr = 0; - int fg_nr = 0; - int bg_nr = 0; - int rq_nr = 0; - int rq_nr_load = 0; - - if (!cpu_active(i) || cpu_isolated(i)) - continue; - if (is_reserved(i)) - continue; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (sched_cpu_high_irqload(i)) - continue; -#endif -#ifdef CONFIG_MTK_SCHED_INTEROP - if (cpu_rq(i)->rt.rt_nr_running && - likely(!is_rt_throttle(i))) - continue; -#endif - if (skip_cpu == i) - continue; - - ux_nr = per_cpu(task_lb_count, i).ux_high + per_cpu(task_lb_count, i).ux_low; - top_nr = per_cpu(task_lb_count, i).top_high + per_cpu(task_lb_count, i).top_low; - fg_nr = per_cpu(task_lb_count, i).foreground_high + per_cpu(task_lb_count, i).foreground_low; - bg_nr = per_cpu(task_lb_count, i).background_high + per_cpu(task_lb_count, i).background_low; - - if (sched_type == SA_UX) { - rq_nr = ux_nr; - } else if (sched_type == SA_TOP) { - rq_nr = ux_nr + top_nr; - } else if (sched_type == SA_FG) { - rq_nr = ux_nr + top_nr + fg_nr; - } else if (sched_type == SA_BG) { - rq_nr = ux_nr + top_nr + fg_nr + bg_nr; - } - - rq_nr_load = 1000 * ux_nr + 100 * top_nr + 10 * fg_nr + bg_nr; - - if (rq_nr > *lowest_nr) { - continue; - } - - if (rq_nr == *lowest_nr) { - if (rq_nr_load < *lowest_nr_load) - goto find; - if (rq_nr_load == *lowest_nr_load && i == prev_cpu) - goto find; - - continue; - } - -find: - *lowest_nr = rq_nr; - *lowest_nr_load = rq_nr_load; - *lowest_nr_cpu = i; - } -} -#if !defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) || (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int start_cpu, int skip_cpu, cpumask_t *cpus, bool strict) -{ - int sched_type = task_lb_sched_type(p); - int cluster; - cpumask_t visit_cpus; - int lowest_nr = INT_MAX; - int lowest_nr_load = INT_MAX; - int lowest_nr_cpu = -1; - int prev_cpu = task_cpu(p); - bool force_spread = false; - int tmp_idx = 0; - int order_index = 0; - int end_index = 0; - struct ux_sched_cputopo cputopo = ux_sched_cputopo; - - if (!is_spread_task_enabled()) - return; - if (cputopo.cls_nr <= 1 || sched_type == -1) - return; - for (cluster = 0; cluster < cputopo.cls_nr; cluster++) { - if (start_cpu == cpumask_first(&cputopo.sched_cls[cluster].cpus)) { - order_index = cluster; - break; - } - } - /* add for launch boost */ - if (sched_assist_scene(SA_LAUNCH) && is_heavy_ux_task(p)) { - strict = true; - order_index = cputopo.cls_nr - 1; - end_index = (p->pid == p->tgid) ? 0 : 1; - } - /* in launch or animation scene, force scheduler to spread tasks */ - if (should_force_spread_tasks()) - force_spread = true; - else - return; - tmp_idx = order_index; - for (cluster = 0; cluster < cputopo.cls_nr; cluster++) { - cpumask_and(&visit_cpus, &new_allowed_cpus, - &cputopo.sched_cls[tmp_idx].cpus); - find_spread_lowest_nr_cpu(p, &visit_cpus, sched_type, prev_cpu, skip_cpu, - &lowest_nr, &lowest_nr_load, &lowest_nr_cpu); - /* - * order_index <= 1, order is cluster(0-1-2 or 1-2-0) - * order_index > 1, order is cluster(2-1-0) - */ - if (order_index <= 1) { - tmp_idx++; - } else { - tmp_idx--; - } - if (tmp_idx >= cputopo.cls_nr) - tmp_idx = 0; - if (tmp_idx < 0) - tmp_idx = cputopo.cls_nr - 1; - /* should we visit next cluster? */ - if (strict && cluster >= end_index) { - break; - } - if (force_spread) - continue; - break; - } - if (lowest_nr_cpu != -1) { - cpumask_set_cpu(lowest_nr_cpu, cpus); - } -} -#else -void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int order_index, int end_index, int skip_cpu, cpumask_t *cpus, bool strict) -{ - int sched_type = task_lb_sched_type(p); - int cluster; - cpumask_t visit_cpus; - int lowest_nr = INT_MAX; - int lowest_nr_load = INT_MAX; - int lowest_nr_cpu = -1; - int prev_cpu = task_cpu(p); - bool force_spread = false; - - if (!is_spread_task_enabled()) - return; - if (num_sched_clusters <= 1 || sched_type == -1) - return; - /* add for launch boost */ - if (sched_assist_scene(SA_LAUNCH) && is_heavy_ux_task(p)) { - strict = true; - order_index = num_sched_clusters - 1; - end_index = (p->pid == p->tgid) ? 0 : 1; - } - /* in launch or animation scene, force scheduler to spread tasks */ - if (should_force_spread_tasks()) - force_spread = true; - else - return; - for (cluster = 0; cluster < num_sched_clusters; cluster++) { - cpumask_and(&visit_cpus, &new_allowed_cpus, - &cpu_array[order_index][cluster]); - find_spread_lowest_nr_cpu(p, &visit_cpus, sched_type, prev_cpu, skip_cpu, - &lowest_nr, &lowest_nr_load, &lowest_nr_cpu); - /* should we visit next cluster? */ - if (strict && cluster >= end_index) { - break; - } - if (force_spread) - continue; - break; - } - if (lowest_nr_cpu != -1) { - cpumask_set_cpu(lowest_nr_cpu, cpus); - } -} -#endif -#endif - -inline int get_ux_state_type(struct task_struct *task) -{ - if (!task) { - return UX_STATE_INVALID; - } - - if (task->sched_class != &fair_sched_class) - return UX_STATE_INVALID; - - if (task->ux_state & SA_TYPE_INHERIT) - return UX_STATE_INHERIT; - - if (task->ux_state & (SA_TYPE_HEAVY | SA_TYPE_LIGHT | SA_TYPE_ANIMATOR | SA_TYPE_LISTPICK)) - return UX_STATE_SCHED_ASSIST; - - return UX_STATE_NONE; -} - -inline bool test_list_pick_ux(struct task_struct *task) -{ - return (task->ux_state & SA_TYPE_LISTPICK) || (task->ux_state & SA_TYPE_ONCE_UX) || -#ifdef CONFIG_KERNEL_LOCK_OPT - test_task_identify_ux(task, SA_TYPE_ID_ALLOCATOR_SER) || test_task_lock_ux(task); -#else - test_task_identify_ux(task, SA_TYPE_ID_ALLOCATOR_SER); -#endif -} - -void enqueue_ux_thread(struct rq *rq, struct task_struct *p) -{ - struct list_head *pos, *n; - bool exist = false; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - if (!rq || !p || !list_empty(&p->ux_entry)) { - return; - } - - p->enqueue_time = rq->clock; - if (test_list_pick_ux(p)) { - list_for_each_safe(pos, n, &rq->ux_thread_list) { - if (pos == &p->ux_entry) { - exist = true; - break; - } - } - if (!exist) { - list_add_tail(&p->ux_entry, &rq->ux_thread_list); - get_task_struct(p); - } - } -} - -#define ux_max_dynamic_granularity ((u64)(64 * S2NS_T)) -void dequeue_ux_thread(struct rq *rq, struct task_struct *p) -{ - struct list_head *pos, *n; - - if (!rq || !p) { - return; - } - p->enqueue_time = 0; - if (!list_empty(&p->ux_entry)) { - u64 now = jiffies_to_nsecs(jiffies); - list_for_each_safe(pos, n, &rq->ux_thread_list) { - if (pos == &p->ux_entry) { - list_del_init(&p->ux_entry); - if (p->ux_state & SA_TYPE_ONCE_UX) { - p->ux_state &= ~SA_TYPE_ONCE_UX; - } - if (get_ux_state_type(p) == UX_STATE_INHERIT && - now - p->inherit_ux_start > ux_max_dynamic_granularity) { - p->ux_state &= ~SA_TYPE_LISTPICK; - } - put_task_struct(p); - return; - } - } - } -} - -static struct task_struct *pick_first_ux_thread(struct rq *rq) -{ - struct list_head *ux_thread_list = &rq->ux_thread_list; - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct task_struct *temp = NULL; - struct task_struct *leftmost_task = NULL; - list_for_each_safe(pos, n, ux_thread_list) { - temp = list_entry(pos, struct task_struct, ux_entry); - /*ensure ux task in current rq cpu otherwise delete it*/ - if (unlikely(task_cpu(temp) != rq->cpu)) { - list_del_init(&temp->ux_entry); - put_task_struct(temp); - continue; - } - if (unlikely(!test_list_pick_ux(temp))) { - list_del_init(&temp->ux_entry); - put_task_struct(temp); - continue; - } - - if (leftmost_task == NULL) { - leftmost_task = temp; - } else if (entity_before(&temp->se, &leftmost_task->se)) { - leftmost_task = temp; - } - } - - return leftmost_task; -} - -void pick_ux_thread(struct rq *rq, struct task_struct **p, struct sched_entity **se) -{ - struct task_struct *ori_p = *p; - struct task_struct *key_task; - struct sched_entity *key_se; - - if (!rq || !ori_p || !se) { - return; - } - -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if ((*p)->oplus_task_info.im_small) - return; -#endif - if ((ori_p->ux_state & SA_TYPE_ANIMATOR) || test_list_pick_ux(ori_p)) - return; - - if (!list_empty(&rq->ux_thread_list)) { - key_task = pick_first_ux_thread(rq); - /* in case that ux thread keep running too long */ - if (key_task && entity_over(&key_task->se, &ori_p->se)) - return; - - if (key_task) { - key_se = &key_task->se; - if (key_se && (rq->clock >= key_task->enqueue_time) && - rq->clock - key_task->enqueue_time >= ((u64)ux_min_sched_delay_granularity * S2NS_T)) { - *p = key_task; - *se = key_se; - } - } - } -} - -#define INHERIT_UX_SEC_WIDTH 8 -#define INHERIT_UX_MASK_BASE 0x00000000ff - -#define inherit_ux_offset_of(type) (type * INHERIT_UX_SEC_WIDTH) -#define inherit_ux_mask_of(type) ((u64)(INHERIT_UX_MASK_BASE) << (inherit_ux_offset_of(type))) -#define inherit_ux_get_bits(value, type) ((value & inherit_ux_mask_of(type)) >> inherit_ux_offset_of(type)) -#define inherit_ux_value(type, value) ((u64)value << inherit_ux_offset_of(type)) - - -bool test_inherit_ux(struct task_struct *task, int type) -{ - u64 inherit_ux; - if (!task) { - return false; - } - inherit_ux = atomic64_read(&task->inherit_ux); - return inherit_ux_get_bits(inherit_ux, type) > 0; -} - -static bool test_task_exist(struct task_struct *task, struct list_head *head) -{ - struct list_head *pos, *n; - list_for_each_safe(pos, n, head) { - if (pos == &task->ux_entry) { - return true; - } - } - return false; -} - -inline void inherit_ux_inc(struct task_struct *task, int type) -{ - atomic64_add(inherit_ux_value(type, 1), &task->inherit_ux); -} - -inline void inherit_ux_sub(struct task_struct *task, int type, int value) -{ - atomic64_sub(inherit_ux_value(type, value), &task->inherit_ux); -} - -static void __inherit_ux_dequeue(struct task_struct *task, int type, int value) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - bool exist = false; - struct rq *rq = NULL; - u64 inherit_ux = 0; - - rq = task_rq_lock(task, &flags); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux <= 0) { - task_rq_unlock(rq, task, &flags); - return; - } - inherit_ux_sub(task, type, value); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux > 0) { - task_rq_unlock(rq, task, &flags); - return; - } - task->ux_depth = 0; - - exist = test_task_exist(task, &rq->ux_thread_list); - if (exist) { - list_del_init(&task->ux_entry); - put_task_struct(task); - } - task_rq_unlock(rq, task, &flags); -} - -void inherit_ux_dequeue(struct task_struct *task, int type) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_dequeue(task, type, 1); -} -void inherit_ux_dequeue_refs(struct task_struct *task, int type, int value) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_dequeue(task, type, value); -} - -static void __inherit_ux_enqueue(struct task_struct *task, int type, int depth) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - bool exist = false; - struct rq *rq = NULL; - - rq = task_rq_lock(task, &flags); - - if (unlikely(!list_empty(&task->ux_entry))) { - task_rq_unlock(rq, task, &flags); - return; - } - - inherit_ux_inc(task, type); - task->inherit_ux_start = jiffies_to_nsecs(jiffies); - task->ux_depth = task->ux_depth > depth + 1 ? task->ux_depth : depth + 1; - if (task->state == TASK_RUNNING && task->sched_class == &fair_sched_class) { - exist = test_task_exist(task, &rq->ux_thread_list); - if (!exist) { - get_task_struct(task); - list_add_tail(&task->ux_entry, &rq->ux_thread_list); - } - } - task_rq_unlock(rq, task, &flags); -} - -void inherit_ux_enqueue(struct task_struct *task, int type, int depth) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_enqueue(task, type, depth); -} - -inline bool test_task_ux_depth(int ux_depth) -{ - return ux_depth < UX_DEPTH_MAX; -} - -inline bool test_set_inherit_ux(struct task_struct *tsk) -{ - return tsk && test_task_ux(tsk) && test_task_ux_depth(tsk->ux_depth); -} - -void ux_init_rq_data(struct rq *rq) -{ - if (!rq) { - return; - } - - INIT_LIST_HEAD(&rq->ux_thread_list); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - cpumask_clear(&nr_mask); - - per_cpu(task_lb_count, cpu_of(rq)).ux_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).ux_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).top_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).top_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).foreground_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).foreground_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).background_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).background_high = 0; -#endif -} - -int ux_prefer_cpu[NR_CPUS] = {0}; -void ux_init_cpu_data(void) { - int i = 0; - int min_cpu = 0, ux_cpu = 0; - - for (; i < nr_cpu_ids; ++i) { - ux_prefer_cpu[i] = -1; - } - - ux_cpu = cpumask_weight(topology_core_cpumask(min_cpu)); - if (ux_cpu == 0) { - ux_warn("failed to init ux cpu data\n"); - return; - } - - for (i = 0; i < nr_cpu_ids && ux_cpu < nr_cpu_ids; ++i) { - ux_prefer_cpu[i] = ux_cpu++; - } -} - -bool test_ux_task_cpu(int cpu) { - return (cpu >= ux_prefer_cpu[0]); -} - -bool test_ux_prefer_cpu(struct task_struct *tsk, int cpu) { - struct root_domain *rd = cpu_rq(smp_processor_id())->rd; - - if (cpu < 0) - return false; - - if (tsk->pid == tsk->tgid) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - return cpu >= rd->wrd.max_cap_orig_cpu; -#else - return cpu >= rd->max_cap_orig_cpu; -#endif -#else - return capacity_orig_of(cpu) >= rd->max_cpu_capacity.val; -#endif /*CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - } - - return (cpu >= ux_prefer_cpu[0]); -} - -void find_ux_task_cpu(struct task_struct *tsk, int *target_cpu) { - int i = 0; - int temp_cpu = 0; - struct rq *rq = NULL; - for (i = (nr_cpu_ids - 1); i >= 0; --i) { - temp_cpu = ux_prefer_cpu[i]; - if (temp_cpu <= 0 || temp_cpu >= nr_cpu_ids) - continue; - - rq = cpu_rq(temp_cpu); - if (!rq) - continue; - - if (rq->curr->prio <= MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!test_task_ux(rq->curr) && cpu_online(temp_cpu) && !cpu_isolated(temp_cpu) - && cpumask_test_cpu(temp_cpu, tsk->cpus_ptr)) { -#else - if (!test_task_ux(rq->curr) && cpu_online(temp_cpu) && !cpu_isolated(temp_cpu) - && cpumask_test_cpu(temp_cpu, &tsk->cpus_allowed)) { -#endif - *target_cpu = temp_cpu; - return; - } - } - return; -} - -static inline bool oplus_is_min_capacity_cpu(int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - - if (unlikely(cls_nr <= 0)) - return false; - - return capacity_orig_of(cpu) == ux_cputopo.sched_cls[0].capacity; -} - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -extern unsigned long capacity_curr_of(int cpu); -#endif -/* - * taget cpu is - * unboost: the one in all domain, with lowest prio running task - * boost: the one in power domain, with lowest prio running task which is not ux - * !!this func will ignore task's start cpu -*/ -int set_ux_task_cpu_common_by_prio(struct task_struct *task, int *target_cpu, bool boost, bool prefer_idle, unsigned int type) -{ - int i; - int lowest_prio = INT_MIN; - unsigned long lowest_prio_max_cap = 0; - int ret = -1; - - if (unlikely(!sysctl_sched_assist_enabled)) - return -1; - - if (!(task->ux_state & SA_TYPE_ANIMATOR) && !test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER)) - return -1; - - if ((*target_cpu < 0) || (*target_cpu >= NR_CPUS)) - return -1; - -#ifdef CONFIG_SCHED_WALT - if (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - boost = ((scale_demand(task->wts.sum) >= THRESHOLD_BOOST) || -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - (task_util(task) >= THRESHOLD_BOOST)) ? true : false; -#else - (task_util_mtk(task, true) >= THRESHOLD_BOOST)) ? true : false; -#endif -#else /* KERNEL-5-4 */ - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - boost = ((scale_demand(task->ravg.sum) >= THRESHOLD_BOOST) || - (task_util(task) >= THRESHOLD_BOOST)) ? true : false; -#else - boost = (scale_demand(task->ravg.sum) >= THRESHOLD_BOOST); -#endif - -#endif /* KERNEL-5-4 */ - } -#endif /* CONFIG_SCHED_WALT */ - - for_each_cpu(i, cpu_active_mask) { - unsigned long capacity_curr; - struct task_struct *curr; - bool curr_ux = false; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!cpumask_test_cpu(i, task->cpus_ptr) || cpu_isolated(i)) -#else - if (!cpumask_test_cpu(i, &task->cpus_allowed) || cpu_isolated(i)) -#endif - continue; - - /* avoid placing task into high power cpu and break it's idle state if !prefer_idle */ - if (prefer_idle && idle_cpu(i)) { - *target_cpu = i; - return 0; - } - - curr = cpu_rq(i)->curr; - /* avoid placing task into cpu with rt */ - if (!curr || !(curr->sched_class == &fair_sched_class)) - continue; - - curr_ux = test_task_ux(curr) || test_task_identify_ux(curr, SA_TYPE_ID_CAMERA_PROVIDER); - if (curr_ux) - continue; - - capacity_curr = capacity_curr_of(i); - if ((curr->prio > lowest_prio) || (boost && (capacity_curr > lowest_prio_max_cap))) { - lowest_prio = curr->prio; - lowest_prio_max_cap = capacity_curr; - *target_cpu = i; - ret = 0; - } - } - - return ret; -} - -bool is_sf(struct task_struct *p) -{ - return (task_index_of_sf_union(p) >= 0); -} - -void drop_ux_task_cpus(struct task_struct *p, struct cpumask *lowest_mask) -{ - unsigned int cpu = cpumask_first(lowest_mask); -#ifdef CONFIG_SCHED_WALT - bool sf = false; -#endif - - while (cpu < nr_cpu_ids) { - /* unlocked access */ - struct task_struct *task = READ_ONCE(cpu_rq(cpu)->curr); - - if ((sysctl_sched_assist_scene & SA_LAUNCH) && (task->ux_state & SA_TYPE_HEAVY)) - cpumask_clear_cpu(cpu, lowest_mask); - - if (test_task_ux(task) || !list_empty(&task->ux_entry) || - (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER) && oplus_is_min_capacity_cpu(cpu))) { - cpumask_clear_cpu(cpu, lowest_mask); - } - -#ifdef CONFIG_SCHED_WALT - if (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) { - sf = is_sf(p); - if (sf && is_task_util_over(p, sysctl_boost_task_threshold) && oplus_is_min_capacity_cpu(cpu)) - cpumask_clear_cpu(cpu, lowest_mask); - } -#endif - - cpu = cpumask_next(cpu, lowest_mask); - } -} - -static inline bool test_sched_assist_ux_type(struct task_struct *task, unsigned int sa_ux_type) -{ - return task->ux_state & sa_ux_type; -} - -static inline u64 max_vruntime(u64 max_vruntime, u64 vruntime) -{ - s64 delta = (s64)(vruntime - max_vruntime); - if (delta > 0) - max_vruntime = vruntime; - - return max_vruntime; -} - -#define MALI_THREAD_NAME "mali-cmar-backe" -#define LAUNCHER_THREAD_NAME "ndroid.launcher" -#define ALLOCATOR_THREAD_NAME "allocator-servi" -#define CAMERA_PROVIDER_NAME "provider@2.4-se" -#define CAMERA_HAL_SERVER_NAME "camerahalserver" - -#define CAMERA_MAINTHREAD_NAME "com.oppo.camera" -#define OPLUS_CAMERA_MAINTHREAD_NAME "om.oplus.camera" -#define CAMERA_PREMR_NAME "previewManagerR" -#define CAMERA_PREPT_NAME "PreviewProcessT" -#define CAMERA_HALCONT_NAME "Camera Hal Cont" -#define CAMERA_IMAGEPROC_NAME "ImageProcessThr" - -#define SURFACE_FLINGER_NAME "surfaceflinger" -#define SF_RENDER_ENGINE_NAME "RenderEngine" - -#define SF_RENDER_PID_NUM 3 -static pid_t sSF_union[SF_RENDER_PID_NUM] = {-1, -1, -1}; -static unsigned long sSF_union_util[SF_RENDER_PID_NUM] = {0, 0, 0}; -static unsigned long sSF_union_ux_load[SF_RENDER_PID_NUM] = {0, 0, 0}; - - -void sched_assist_target_comm(struct task_struct *task) -{ - struct task_struct *grp_leader; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - /* Surfaceflinger is rt */ - if (task->pid == task->tgid && (task_uid(task).val == 1000 /* SURFACE_FLINGER_UID */) && !strncmp(task->comm, SURFACE_FLINGER_NAME, TASK_COMM_LEN)) { - sSF_union[0] = task->pid; - /* If sf restart, reset union to -1; */ - sSF_union[1] = sSF_union[2] = -1; - /* sched_assist_systrace_pid(task->tgid, sSF_union[0], "sf_union %d", task->pid); */ - return; - } - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /* Actually there are two "RenderEngine", only match one by set_task_comm(); */ - if ((task_uid(task).val == 1000 /* SURFACE_FLINGER_UID */) && !strncmp(task->comm, SF_RENDER_ENGINE_NAME, TASK_COMM_LEN)) { - if (sSF_union[1] == -1) { - sSF_union[1] = task->pid; - /* sched_assist_systrace_pid(task->tgid, sSF_union[1], "sf_union %d", task->pid); */ - } else if (sSF_union[2] == -1) { - sSF_union[2] = task->pid; - /* sched_assist_systrace_pid(task->tgid, sSF_union[2], "sf_union %d", task->pid); */ - } - return; - } -#endif - - grp_leader = task->group_leader; - - if (!grp_leader || (get_ux_state_type(task) != UX_STATE_NONE)) - return; - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /* mali thread only exist in mtk platform */ - if (strstr(grp_leader->comm, LAUNCHER_THREAD_NAME) && strstr(task->comm, MALI_THREAD_NAME)) { - task->ux_state |= SA_TYPE_ANIMATOR; - return; - } - - if (!strncmp(grp_leader->comm, CAMERA_HAL_SERVER_NAME, TASK_COMM_LEN) && (task_uid(task).val == 1047 /* CAMERASERVER_UID */)) { - if (task->sched_class == &fair_sched_class) { - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - return; - } - } -#endif - - if (strstr(grp_leader->comm, CAMERA_PROVIDER_NAME) && strstr(task->comm, CAMERA_PROVIDER_NAME)) { - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - return; - } - - if ((strstr(grp_leader->comm, CAMERA_MAINTHREAD_NAME) || strstr(grp_leader->comm, OPLUS_CAMERA_MAINTHREAD_NAME)) && (strstr(task->comm, CAMERA_PREMR_NAME) - || strstr(task->comm, CAMERA_PREPT_NAME) - || strstr(task->comm, CAMERA_HALCONT_NAME) - || strstr(task->comm, CAMERA_IMAGEPROC_NAME))) { - task->ux_state |= SA_TYPE_LIGHT; - return; - } - - if (!strncmp(grp_leader->comm, ALLOCATOR_THREAD_NAME, TASK_COMM_LEN) || !strncmp(task->comm, ALLOCATOR_THREAD_NAME, TASK_COMM_LEN)) { - task->ux_state |= SA_TYPE_ID_ALLOCATOR_SER; - return; - } - - return; -} - -#ifdef CONFIG_FAIR_GROUP_SCHED -/* An entity is a task if it doesn't "own" a runqueue */ -#define oplus_entity_is_task(se) (!se->my_q) -#else -#define oplus_entity_is_task(se) (1) -#endif - -void place_entity_adjust_ux_task(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) -{ - u64 vruntime = cfs_rq->min_vruntime; - unsigned long thresh = sysctl_sched_latency; - unsigned long launch_adjust = 0; - struct task_struct *se_task = NULL; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - if (!oplus_entity_is_task(se) || initial) - return; - - if (sysctl_sched_assist_scene & SA_LAUNCH) - launch_adjust = sysctl_sched_latency; - - se_task = task_of(se); - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - if (se_task->ux_once) { - vruntime -= 3 * thresh; - se->vruntime = vruntime; - se_task->ux_once = 0; - return; - } -#endif - - if (test_sched_assist_ux_type(se_task, SA_TYPE_ANIMATOR)) { - vruntime -= 3 * thresh + (thresh >> 1); - se->vruntime = vruntime - (launch_adjust >> 1); - return; - } - - if (test_sched_assist_ux_type(se_task, SA_TYPE_LIGHT | SA_TYPE_HEAVY)) { - vruntime -= 2 * thresh; - se->vruntime = vruntime - (launch_adjust >> 1); - return; - } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if (!sysctl_sched_impt_tgid && test_task_identify_ux(se_task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#else - if (test_task_identify_ux(se_task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#endif -#ifdef CONFIG_MACH_MT6765 - vruntime -= 4 * thresh; - se->vruntime = vruntime; -#else - vruntime -= 2 * thresh + (thresh >> 1); - se->vruntime = vruntime - (launch_adjust >> 1); -#endif - return; - } - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - if (should_force_adjust_vruntime(se)) { - se->vruntime = vruntime - (thresh + (thresh >> 1)); - return; - } -#endif -} - -bool should_ux_preempt_wakeup(struct task_struct *wake_task, struct task_struct *curr_task) -{ - bool wake_ux = false; - bool curr_ux = false; - - if (!sysctl_sched_assist_enabled) - return false; - - wake_ux = test_task_ux(wake_task) || test_list_pick_ux(wake_task) || test_task_identify_ux(wake_task, SA_TYPE_ID_CAMERA_PROVIDER); - curr_ux = test_task_ux(curr_task) || test_list_pick_ux(curr_task) || test_task_identify_ux(curr_task, SA_TYPE_ID_CAMERA_PROVIDER); - - /* exit animation ux is set as highest ux which other ux can't preempt and can preempt other ux */ - if (!(sysctl_sched_assist_scene & SA_LAUNCH)) { - if (is_animation_ux(curr_task)) - return false; - else if (is_animation_ux(wake_task)) - return true; - } - - /* ux can preemt cfs */ - if (wake_ux && !curr_ux) - return true; - - /* animator ux can preemt un-animator */ - if ((wake_task->ux_state & SA_TYPE_ANIMATOR) && !(curr_task->ux_state & SA_TYPE_ANIMATOR)) - return true; - - /* heavy type can be preemt by other type */ - if (wake_ux && !(wake_task->ux_state & SA_TYPE_HEAVY) && (curr_task->ux_state & SA_TYPE_HEAVY)) - return true; - - return false; -} - -bool should_ux_task_skip_further_check(struct sched_entity *se) -{ - return oplus_entity_is_task(se) && test_sched_assist_ux_type(task_of(se), SA_TYPE_ANIMATOR); -} - -static inline bool is_ux_task_prefer_cpu(struct task_struct *task, int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - - if(cpu < 0) - return false; - - /* only one cluster or init failed */ - if (unlikely(cls_nr <= 0)) - return true; - - if (cpu_rq(cpu)->curr && test_sched_assist_ux_type(cpu_rq(cpu)->curr, SA_TYPE_HEAVY)) - return false; - - if (test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) { - return capacity_orig_of(cpu) >= ux_cputopo.sched_cls[cls_nr].capacity; - } - - return true; -} - -bool is_task_util_over(struct task_struct *task, int threshold) -{ - bool sum_over = false; - bool demand_over = false; - -#ifdef CONFIG_SCHED_WALT -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - sum_over = scale_demand(task->wts.sum) >= threshold; -#else - sum_over = scale_demand(task->ravg.sum) >= threshold; -#endif -#else /* !CONFIG_SCHED_WALT */ - sum_over = READ_ONCE(task->se.avg.util_avg) >= threshold; -#endif /* CONFIG_SCHED_WALT */ - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - demand_over = task_util(task) >= threshold; -#else - if (unlikely(task_index_of_sf_union(task) >= 0)) { - unsigned long util = sSF_union_util[0] + sSF_union_util[1] + sSF_union_util[2]; - demand_over = (util >= threshold); - } -#endif - - return sum_over || demand_over; -} - -static inline int get_task_cls_for_scene(struct task_struct *task) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_max = ux_cputopo.cls_nr - 1; - int cls_mid = cls_max - 1; - - /* only one cluster or init failed */ - if (unlikely(cls_max <= 0)) - return 0; - - /* for 2 clusters cpu, mid = max */ - if (cls_mid == 0) { - cls_mid = cls_max; - } - - /* just change cpu selection for heavy ux task */ - if (!test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) - return 0; - - /* for launch scene, heavy ux task move to max capacity cluster */ - if (sched_assist_scene(SA_LAUNCH)) { - return cls_max; - } - - if ((sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) && - is_task_util_over(task, sysctl_boost_task_threshold)) { - return cls_mid; - } - - return 0; -} - -static inline bool is_ux_task_prefer_cpu_for_scene(struct task_struct *task, unsigned int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_id = ux_cputopo.cls_nr - 1; - - /* only one cluster or init failed */ - if (unlikely(cls_id <= 0)) - return true; - - cls_id = get_task_cls_for_scene(task); - return capacity_orig_of(cpu) >= ux_cputopo.sched_cls[cls_id].capacity; -} - -#ifdef CONFIG_SCHED_WALT -/* 2ms default for 20ms window size scaled to 1024 */ -bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - /* for SA_TYPE_ID_CAMERA_PROVIDER */ - if (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER) - && is_task_util_over(task, THRESHOLD_BOOST) && oplus_is_min_capacity_cpu(cpu)) { - return true; - } - - if(is_task_util_over(task, sysctl_boost_task_threshold) - && !is_ux_task_prefer_cpu_for_scene(task, cpu)) { - return true; - } - - return false; -} -#endif - -bool should_ux_task_skip_cpu(struct task_struct *task, unsigned int cpu) -{ - if (!sysctl_sched_assist_enabled || !test_task_ux(task)) - return false; - - if (!is_ux_task_prefer_cpu_for_scene(task, cpu)) - return true; - - if (!(sysctl_sched_assist_scene & SA_LAUNCH) || !test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) { - if (cpu_rq(cpu)->rt.rt_nr_running) - return true; - - /* avoid placing turbo ux into cpu which has animator ux or list ux */ - if (cpu_rq(cpu)->curr && (test_sched_assist_ux_type(cpu_rq(cpu)->curr, SA_TYPE_ANIMATOR) - || !list_empty(&cpu_rq(cpu)->ux_thread_list))) - return true; - } - - return false; -} - -void set_ux_task_to_prefer_cpu_v1(struct task_struct *task, int *orig_target_cpu, bool *cond) { - struct rq *rq = NULL; - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - int cpu = 0; - - if (!sysctl_sched_assist_enabled || !(sysctl_sched_assist_scene & SA_LAUNCH)) - return; - - if (unlikely(cls_nr <= 0)) - return; - - if (is_ux_task_prefer_cpu(task, *orig_target_cpu)) - return; - *cond = true; -retry: - for_each_cpu(cpu, &ux_cputopo.sched_cls[cls_nr].cpus) { - rq = cpu_rq(cpu); - if (test_sched_assist_ux_type(rq->curr, SA_TYPE_HEAVY)) - continue; - - if (rq->curr->prio < MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, task->cpus_ptr)) { -#else - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, &task->cpus_allowed)) { -#endif - *orig_target_cpu = cpu; - return; - } - } - - cls_nr = cls_nr - 1; - if (cls_nr > 0) - goto retry; - - return; -} - -bool set_ux_task_to_prefer_cpu(struct task_struct *task, int *orig_target_cpu) { - struct rq *rq = NULL; - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - int cpu = 0; - int direction = -1; - - if (!sysctl_sched_assist_enabled || !(sysctl_sched_assist_scene & SA_LAUNCH)) - return false; - - if (unlikely(cls_nr <= 0)) - return false; - - if (is_ux_task_prefer_cpu(task, *orig_target_cpu)) - return false; - - cls_nr = get_task_cls_for_scene(task); - if (cls_nr != ux_cputopo.cls_nr - 1) - direction = 1; -retry: - for_each_cpu(cpu, &ux_cputopo.sched_cls[cls_nr].cpus) { - rq = cpu_rq(cpu); - if (test_sched_assist_ux_type(rq->curr, SA_TYPE_HEAVY)) - continue; - - if (rq->curr->prio < MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, task->cpus_ptr)) { -#else - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, &task->cpus_allowed)) { -#endif - *orig_target_cpu = cpu; - return true; - } - } - - cls_nr = cls_nr + direction; - if (cls_nr > 0 && cls_nr < ux_cputopo.cls_nr) - goto retry; - - return false; -} - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -static void requeue_runnable_task(struct task_struct *p) -{ - bool queued, running; - struct rq_flags rf; - struct rq *rq; - - rq = task_rq_lock(p, &rf); - queued = task_on_rq_queued(p); - running = task_current(rq, p); - - if (!queued || running) { - task_rq_unlock(rq, p, &rf); - return; - } - - update_rq_clock(rq); - deactivate_task(rq, p, DEQUEUE_NOCLOCK); - activate_task(rq, p, ENQUEUE_NOCLOCK); - resched_curr(rq); - - task_rq_unlock(rq, p, &rf); -} -#endif - -void set_inherit_ux(struct task_struct *task, int type, int depth, int inherit_val) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq = NULL; - int old_state = 0; - - if (!task || type >= INHERIT_UX_MAX) { - return; - } - - rq = task_rq_lock(task, &flags); - - if (task->sched_class != &fair_sched_class) { - task_rq_unlock(rq, task, &flags); - return; - } - - inherit_ux_inc(task, type); - task->ux_depth = depth + 1; - old_state = task->ux_state; - task->ux_state = (inherit_val & SCHED_ASSIST_UX_MASK) | SA_TYPE_INHERIT; - /* identify type like allocator ux, keep it, but can not inherit */ - if (old_state & SA_TYPE_ID_ALLOCATOR_SER) - task->ux_state |= SA_TYPE_ID_ALLOCATOR_SER; - if (old_state & SA_TYPE_ID_CAMERA_PROVIDER) - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - task->inherit_ux_start = jiffies_to_nsecs(jiffies); - - if (task->on_rq && (!rq->curr || (!test_task_ux(rq->curr) && rq->curr->prio > 110))) { - set_once_ux(task); - enqueue_ux_thread(task_rq(task), task); - } - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - task_rq_unlock(rq, task, &flags); - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - /* requeue runnable task to ensure vruntime adjust */ - requeue_runnable_task(task); -#endif -} - -void reset_inherit_ux(struct task_struct *inherit_task, struct task_struct *ux_task, int reset_type) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - int reset_depth = 0; - int reset_inherit = 0; - - if (!inherit_task || !ux_task || reset_type >= INHERIT_UX_MAX) { - return; - } - - reset_inherit = ux_task->ux_state; - reset_depth = ux_task->ux_depth; - /* animator ux is important, so we just reset in this type */ - if (!test_inherit_ux(inherit_task, reset_type) || !test_sched_assist_ux_type(ux_task, SA_TYPE_ANIMATOR)) - return; - - rq = task_rq_lock(inherit_task, &flags); - - inherit_task->ux_depth = reset_depth + 1; - /* identify type like allocator ux, keep it, but can not inherit */ - if (reset_inherit & SA_TYPE_ID_ALLOCATOR_SER) - reset_inherit &= ~SA_TYPE_ID_ALLOCATOR_SER; - if (reset_inherit & SA_TYPE_ID_CAMERA_PROVIDER) - reset_inherit &= ~SA_TYPE_ID_CAMERA_PROVIDER; - inherit_task->ux_state = (inherit_task->ux_state & ~SCHED_ASSIST_UX_MASK) | reset_inherit; - - sched_assist_systrace_pid(inherit_task->tgid, inherit_task->ux_state, "ux_state %d", inherit_task->pid); - - task_rq_unlock(rq, inherit_task, &flags); -} - -void unset_inherit_ux_value(struct task_struct *task, int type, int value) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - s64 inherit_ux; - - if (!task || type >= INHERIT_UX_MAX) { - return; - } - - rq = task_rq_lock(task, &flags); - - inherit_ux_sub(task, type, value); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux > 0) { - task_rq_unlock(rq, task, &flags); - return; - } - if (inherit_ux < 0) { - atomic64_set(&(task->inherit_ux), 0); - } - task->ux_depth = 0; - /* identify type like allocator ux, keep it, but can not inherit */ - task->ux_state &= SA_TYPE_ID_ALLOCATOR_SER | SA_TYPE_ID_CAMERA_PROVIDER; - - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - task_rq_unlock(rq, task, &flags); -} - -void unset_inherit_ux(struct task_struct *task, int type) -{ - unset_inherit_ux_value(task, type, 1); -} - -void inc_inherit_ux_refs(struct task_struct *task, int type) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - - rq = task_rq_lock(task, &flags); - inherit_ux_inc(task, type); - task_rq_unlock(rq, task, &flags); -} - -int task_index_of_sf_union(struct task_struct *p) -{ - int i; - for (i = 0; i < SF_RENDER_PID_NUM; i++) { - if (p->pid == sSF_union[i]) { - return i; - } - } - return -1; -} - -void sf_task_util_record(struct task_struct *p) -{ - int index = task_index_of_sf_union(p); - if (unlikely(index >= 0)) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - sSF_union_util[index] = task_util(p); -#else - sSF_union_util[index] = task_util_mtk(p, true); -#endif - } -} - -u64 sf_union_ux_load(struct task_struct *tsk, u64 timeline) { - int index = task_index_of_sf_union(tsk); - if (unlikely(index >= 0)) { - sSF_union_ux_load[index] = timeline; - /* sched_assist_systrace_pid(tsk->tgid, sSF_union_ux_load[0] + sSF_union_ux_load[1] + sSF_union_ux_load[2], "sf_union_ux_load %d", tsk->pid); */ - return sSF_union_ux_load[0] + sSF_union_ux_load[1] + sSF_union_ux_load[2]; - } - return timeline; -} - -bool oplus_task_misfit(struct task_struct *p, int cpu) { - int num_mincpu; - - int index = task_index_of_sf_union(p); - if (unlikely(index >= 0)) { - unsigned long util = sSF_union_util[0] + sSF_union_util[1] + sSF_union_util[2]; - /* sched_assist_systrace_pid(p->tgid, util, "sf_union_util %d", p->pid); */ - num_mincpu = cpumask_weight(topology_core_cpumask(0)); - if (util >= sysctl_boost_task_threshold && cpu < num_mincpu) { - return true; - } - } - -#ifdef CONFIG_SCHED_WALT -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - #ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - num_mincpu = cpumask_weight(topology_core_cpumask(0)); - if ((scale_demand(p->wts.sum) >= sysctl_boost_task_threshold || - task_util(p) >= sysctl_boost_task_threshold) && cpu < num_mincpu) - return true; - #endif -#else - num_mincpu = cpumask_weight(topology_core_cpumask(0)); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if ((scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold || - task_util(p) >= sysctl_boost_task_threshold) && cpu < num_mincpu) -#else - if ((scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold || - task_util_mtk(p, true) > sysctl_boost_task_threshold) && cpu < num_mincpu) -#endif - return true; -#endif -#endif - return false; -} - -void kick_min_cpu_from_mask(struct cpumask *lowest_mask) -{ - unsigned int cpu = cpumask_first(lowest_mask); - while(cpu < nr_cpu_ids) { - if (cpumask_test_cpu(cpu, &ux_sched_cputopo.sched_cls[0].cpus)) { - cpumask_clear_cpu(cpu, lowest_mask); - } - cpu = cpumask_next(cpu, lowest_mask); - } -} - -bool ux_skip_sync_wakeup(struct task_struct *task, int *sync) -{ - bool ret = false; - - if (test_sched_assist_ux_type(task, SA_TYPE_ANIMATOR)) { - *sync = 0; - ret = true; - } - - return ret; -} - -/* - * add for create proc node: proc/pid/task/pid/ux_state -*/ -bool is_special_entry(struct dentry *dentry, const char *special_proc) -{ - const unsigned char *name; - if (NULL == dentry || NULL == special_proc) - return false; - - name = dentry->d_name.name; - if (NULL != name && !strncmp(special_proc, name, 32)) - return true; - else - return false; -} - -static unsigned long __read_mostly mark_addr; - -static int _sched_assist_update_tracemark(void) -{ - if (mark_addr) - return 1; - - mark_addr = kallsyms_lookup_name("tracing_mark_write"); - - if (unlikely(!mark_addr)) - return 0; - - return 1; -} - -void sched_assist_systrace_pid(pid_t pid, int val, const char *fmt, ...) -{ - char log[256]; - va_list args; - int len; - - if (likely(!param_ux_debug)) - return; - - if (unlikely(!_sched_assist_update_tracemark())) - return; - - memset(log, ' ', sizeof(log)); - va_start(args, fmt); - len = vsnprintf(log, sizeof(log), fmt, args); - va_end(args); - - if (unlikely(len < 0)) - return; - else if (unlikely(len == 256)) - log[255] = '\0'; - - preempt_disable(); - event_trace_printk(mark_addr, "C|%d|%s|%d\n", pid, log, val); - preempt_enable(); -} - -static int proc_ux_state_show(struct seq_file *m, void *v) -{ - struct inode *inode = m->private; - struct task_struct *p; - p = get_proc_task(inode); - if (!p) { - return -ESRCH; - } - task_lock(p); - seq_printf(m, "%d\n", p->ux_state); - task_unlock(p); - put_task_struct(p); - return 0; -} - -static int proc_ux_state_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, proc_ux_state_show, inode); -} - -static ssize_t proc_ux_state_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - struct task_struct *task; - char buffer[PROC_NUMBUF]; - int err, ux_state; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) { - return -EFAULT; - } - - err = kstrtoint(strstrip(buffer), 0, &ux_state); - if(err) { - return err; - } - task = get_proc_task(file_inode(file)); - if (!task) { - return -ESRCH; - } - - if (ux_state < 0) { - put_task_struct(task); - return -EINVAL; - } - - if (ux_state == SA_OPT_CLEAR) { /* clear all ux type but animator */ - task->ux_state &= ~(SA_TYPE_LISTPICK | SA_TYPE_HEAVY | SA_TYPE_LIGHT); - } else if (ux_state & SA_OPT_SET) { /* set target ux type and clear set opt */ - task->ux_state |= ux_state & (~SA_OPT_SET); - } else if (task->ux_state & ux_state) { /* reset target ux type */ - task->ux_state &= ~ux_state; - } - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - put_task_struct(task); - - return count; -} - -static ssize_t proc_ux_state_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[256]; - struct task_struct *task = NULL; - int ux_state = -1; - size_t len = 0; - int cpuset_id = 0; - - task = get_proc_task(file_inode(file)); - - if (!task) - return -ESRCH; - -#ifdef CONFIG_CGROUP_SCHED - cpuset_id = task_css(task, cpuset_cgrp_id)->id; -#endif - ux_state = task->ux_state; - put_task_struct(task); - - len = snprintf(buffer, sizeof(buffer), "pid=%d ux_state=%d inherit=%llx(fu:%d mu:%d rw:%d bi:%d) cpuset_id=%d\n", - task->pid, ux_state, (u64)atomic64_read(&task->inherit_ux), - test_inherit_ux(task, INHERIT_UX_FUTEX), test_inherit_ux(task, INHERIT_UX_MUTEX), - test_inherit_ux(task, INHERIT_UX_RWSEM), test_inherit_ux(task, INHERIT_UX_BINDER), - cpuset_id); - - return simple_read_from_buffer(buf, count, ppos, buffer, len); -} - -const struct file_operations proc_ux_state_operations = { - .open = proc_ux_state_open, - .write = proc_ux_state_write, - .read = proc_ux_state_read, - .llseek = seq_lseek, - .release = single_release, -}; - -/* - * add for proc node: proc/sys/kernel/sched_assist_scene -*/ -int sysctl_sched_assist_scene_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int result, save_sa; - static DEFINE_MUTEX(sa_scene_mutex); - - mutex_lock(&sa_scene_mutex); - - save_sa = sysctl_sched_assist_scene; - result = proc_dointvec(table, write, buffer, lenp, ppos); - - if (!write) - goto out; - - if (sysctl_sched_assist_scene == SA_SCENE_OPT_CLEAR) { - goto out; - } - - if (sysctl_sched_assist_scene & SA_SCENE_OPT_SET) { - save_sa |= sysctl_sched_assist_scene & (~SA_SCENE_OPT_SET); - } else if (save_sa & sysctl_sched_assist_scene) { - save_sa &= ~sysctl_sched_assist_scene; - } - - sysctl_sched_assist_scene = save_sa; - sched_assist_systrace(sysctl_sched_assist_scene, "scene"); -out: - mutex_unlock(&sa_scene_mutex); - - return result; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) -static inline bool is_mmap_lock_opt_enabled(void) -{ - return sysctl_uxchain_v2 && !sched_assist_scene(SA_CAMERA); -} - -void uxchain_rwsem_wake(struct task_struct *tsk, struct rw_semaphore *sem) -{ - int set_ux_once; - - if (!is_mmap_lock_opt_enabled()) - return; - - if (current->mm) { - set_ux_once = (sem == &(current->mm->mmap_sem)); - if (set_ux_once) - tsk->ux_once = 1; - } -} -void uxchain_rwsem_down(struct rw_semaphore *sem) -{ - if (!is_mmap_lock_opt_enabled()) - return; - - if (current->mm && sem == &(current->mm->mmap_sem)) { - current->get_mmlock = 1; - current->get_mmlock_ts = sched_clock(); - } -} - -void uxchain_rwsem_up(struct rw_semaphore *sem) -{ - if (current->mm && sem == &(current->mm->mmap_sem) && - current->get_mmlock == 1) { - current->get_mmlock = 0; - } -} -#endif - -bool skip_check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) -{ - u64 wallclock = 0; - - wallclock = sched_clock(); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - if (!is_mmap_lock_opt_enabled()) - return false; - - if (wallclock - rq->curr->get_mmlock_ts < PREEMPT_DISABLE_RWSEM && - rq->curr->get_mmlock && - !(p->flags & PF_WQ_WORKER) && !task_has_rt_policy(p)) - return true; -#endif - - return false; -} - -#define TOP_APP_GROUP_ID 4 -bool im_mali(struct task_struct *p) -{ - return strstr(p->comm, "mali-cmar-backe"); -} -bool cgroup_check_set_sched_assist_boost(struct task_struct *p) -{ - return im_mali(p); -} -int get_st_group_id(struct task_struct *task) -{ -#if IS_ENABLED(CONFIG_SCHED_TUNE) - const int subsys_id = schedtune_cgrp_id; - struct cgroup *grp; - - rcu_read_lock(); - grp = task_cgroup(task, subsys_id); - rcu_read_unlock(); - return grp->id; -#else - return 0; -#endif -} -void cgroup_set_sched_assist_boost_task(struct task_struct *p) -{ - if(cgroup_check_set_sched_assist_boost(p)) { - if (get_st_group_id(p) == TOP_APP_GROUP_ID) { - p->ux_state |= SA_TYPE_HEAVY; - } else - p->ux_state &= ~SA_TYPE_HEAVY; - } else { - return; - } -} - - -#define DEFAULT_LIMIT_CORE_USE (4) -#define MAX_LIMIT_PROCESS (5) -#define ULIMIT_PROCESS_TYPE (3) - -bool is_limit_task(struct task_struct *task) -{ - return false; -} - -static inline bool should_limit_core_use(struct task_struct *task) -{ - return task && is_limit_task(task); -} - -bool should_limit_task_skip_cpu(struct task_struct *task, int cpu) -{ - return should_limit_core_use(task) && (cpu >= DEFAULT_LIMIT_CORE_USE); -} - -bool set_limit_task_target_cpu(struct task_struct *task, int *target_cpu) -{ - bool res = false; - - if (should_limit_core_use(task)) { - int i = 0; - int core_limit = DEFAULT_LIMIT_CORE_USE; - unsigned int best_nr = UINT_MAX; - struct cpumask allowed_mask; - cpumask_clear(&allowed_mask); - - if (core_limit <= 0 || core_limit >= NR_CPUS) - return false; - - for (i = 0; i < core_limit; ++i) - cpumask_set_cpu(i, &allowed_mask); - - if (cpumask_test_cpu(*target_cpu, &allowed_mask)) - return true; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - for_each_cpu_and(i, &allowed_mask, task->cpus_ptr) { -#else - for_each_cpu_and(i, &allowed_mask, &task->cpus_allowed) { -#endif - if (!cpu_online(i) || cpu_isolated(i)) - continue; - - if (cpu_rq(i)->nr_running < best_nr) { - best_nr = cpu_rq(i)->nr_running; - *target_cpu = i; - res = true; - } - } - } - - return res; -} - -static ssize_t proc_sched_impt_task_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - char temp_buf[32]; - char *temp_str, *token; - char in_str[2][16]; - int cnt, err, pid; - - static DEFINE_MUTEX(impt_thd_mutex); - static unsigned int save_idx = 0; - - mutex_lock(&impt_thd_mutex); - - memset(temp_buf, 0, sizeof(temp_buf)); - - if (count > sizeof(temp_buf) - 1) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - if (copy_from_user(temp_buf, buf, count)) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - cnt = 0; - temp_str = strstrip(temp_buf); - while ((token = strsep(&temp_str, " ")) && *token && (cnt < 2)) { - strncpy(in_str[cnt], token, sizeof(in_str[cnt])); - cnt += 1; - } - - if (cnt != 2) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - err = kstrtoint(strstrip(in_str[1]), 0, &pid); - if (err) { - mutex_unlock(&impt_thd_mutex); - return err; - } - - if (pid <= 0 || pid > PID_MAX_DEFAULT) { - mutex_unlock(&impt_thd_mutex); - return -EINVAL; - } - - /* set top app */ - if (!strncmp(in_str[0], "fg", 2)) { - save_top_app_tgid = pid; - top_app_type = 0; - if (!strncmp(in_str[0], "fgLauncher", 10)) - top_app_type = 1; /* 1 is launcher */ - goto out; - } - - /* set audio app */ - if (!strncmp(in_str[0], "addAu", 5)) { - int i = 0; - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] == pid) { - break; - } - } - - /* we can't found save_tgid, update it. */ - if (i >= MAX_IMPT_SAVE_PID) { - save_impt_tgid[save_idx++] = pid; - } - - if (save_idx >= MAX_IMPT_SAVE_PID) - save_idx = 0; - - goto out; - } else if (!strncmp(in_str[0], "remAu", 5)) { - int i = 0; - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] == pid) { - save_impt_tgid[i] = 0; - save_idx = i; - break; - } - } - } - -out: - mutex_unlock(&impt_thd_mutex); - - return count; -} - -static ssize_t proc_sched_impt_task_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[32]; - size_t len = 0; - - len = snprintf(buffer, sizeof(buffer), "top(%d %u) au(%d %d)\n", save_top_app_tgid, top_app_type, save_impt_tgid[0], save_impt_tgid[1]); - - return simple_read_from_buffer(buf, count, ppos, buffer, len); -} - -static const struct file_operations proc_sched_impt_task_fops = { - .write = proc_sched_impt_task_write, - .read = proc_sched_impt_task_read, -}; - -#define OPLUS_SCHEDULER_PROC_DIR "oplus_scheduler" -#define OPLUS_SCHEDASSIST_PROC_DIR "sched_assist" -struct proc_dir_entry *d_oplus_scheduler = NULL; -struct proc_dir_entry *d_sched_assist = NULL; -static int __init oplus_sched_assist_init(void) -{ - struct proc_dir_entry *proc_node; - - d_oplus_scheduler = proc_mkdir(OPLUS_SCHEDULER_PROC_DIR, NULL); - if(!d_oplus_scheduler) { - ux_err("failed to create proc dir oplus_scheduler\n"); - goto err_dir_scheduler; - } - - d_sched_assist = proc_mkdir(OPLUS_SCHEDASSIST_PROC_DIR, d_oplus_scheduler); - if(!d_sched_assist) { - ux_err("failed to create proc dir sched_assist\n"); - goto err_dir_sa; - } - - proc_node = proc_create("sched_impt_task", 0666, d_sched_assist, &proc_sched_impt_task_fops); - if(!proc_node) { - ux_err("failed to create proc node sched_impt_task\n"); - goto err_node_impt; - } - - return 0; - -err_node_impt: - remove_proc_entry(OPLUS_SCHEDASSIST_PROC_DIR, NULL); - -err_dir_sa: - remove_proc_entry(OPLUS_SCHEDULER_PROC_DIR, NULL); - -err_dir_scheduler: - return -ENOENT; -} -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -static inline bool is_sched_boost_group(struct task_struct *tsk) -{ - return (sysctl_sched_impt_tgid != 0 && tsk->tgid == sysctl_sched_impt_tgid); -} - -#define ANDROID_PRIORITY_URGENT_AUDIO 101 -#define ANDROID_PRIORITY_AUDIO 104 -#define FIT_SMALL_THREASH 3 -#define RUNNABLE_MIN_THREASH 20000000 -#define RUNNING_MIN_THREASH 3000000 - -inline bool is_small_task(struct task_struct *task) -{ - if (task->oplus_task_info.im_small) - return true; - else - return false; -} - -inline bool is_audio_task(struct task_struct *task) -{ - if (((task->prio == ANDROID_PRIORITY_URGENT_AUDIO) || (task->prio == ANDROID_PRIORITY_AUDIO))) - return true; - else - return false; -} -extern void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se); -bool sched_assist_pick_next_task(struct cfs_rq *cfs_rq, struct sched_entity *se) -{ - if (cfs_rq->next && oplus_entity_is_task(cfs_rq->next)) { - struct task_struct *tsk = task_of(cfs_rq->next); - if (tsk->oplus_task_info.im_small) { - sched_assist_im_systrace_c(tsk, -1); - se = cfs_rq->next; - clear_buddies(cfs_rq, se); - return true; - } - return false; - } else { - return false; - } -} - -bool sched_assist_pick_next_task_opt(struct cfs_rq *cfs_rq, struct sched_entity **se) -{ - if (cfs_rq->next && oplus_entity_is_task(cfs_rq->next)) { - struct task_struct *tsk = task_of(cfs_rq->next); - if (tsk->oplus_task_info.im_small) { - sched_assist_im_systrace_c(tsk, -1); - *se = cfs_rq->next; - clear_buddies(cfs_rq, *se); - return true; - } - return false; - } else { - return false; - } -} - -void update_task_sched_stat_common(struct task_struct *tsk, u64 delta_ns, int stats_type) -{ - int i = TASK_INFO_SAMPLE -1; - while (i > 0) { - tsk->oplus_task_info.sa_info[stats_type][i] = tsk->oplus_task_info.sa_info[stats_type][i-1]; - i--; - } - tsk->oplus_task_info.sa_info[stats_type][0] = delta_ns; -} - -enum { - TASK_SMALL, - TASK_TYPE_TOTAL, -}; - - -u64 task_info_sum(struct task_struct *task, int type) -{ - int i; - u64 sum = 0; - - for (i = 0; i < TASK_INFO_SAMPLE; i++) { - sum += task->oplus_task_info.sa_info[type][i]; - } - - return sum; -} - -void try_to_mark_task_type(struct task_struct *tsk, int type) -{ - int i = 0; - int fit_small = 0; - - switch (type) { - case TASK_SMALL: - if ((tsk->oplus_task_info.sa_info[TST_EXEC][TASK_INFO_SAMPLE-1] != 0) && (tsk->oplus_task_info.sa_info[TST_SLEEP][TASK_INFO_SAMPLE-1] != 0)) { - while (i < TASK_INFO_SAMPLE) { - if ((tsk->oplus_task_info.sa_info[TST_EXEC][i] < RUNNING_MIN_THREASH) && - ((tsk->oplus_task_info.sa_info[TST_EXEC][i] * 5) < tsk->oplus_task_info.sa_info[TST_SLEEP][i])) - fit_small++; - - if (fit_small >= FIT_SMALL_THREASH) { - tsk->oplus_task_info.im_small = true; - goto out; - } - i++; - } - } - tsk->oplus_task_info.im_small = false; - break; - default: - break; - } -out: - return; -} - -void update_sa_task_stats(struct task_struct *tsk, u64 delta_ns, int stats_type) -{ - if (!tsk) - return; - if (unlikely(!sysctl_sched_assist_enabled)) - return; - if (tsk->oplus_task_info.im_small && (!is_sched_boost_group(tsk) || !sched_assist_scene(SA_CAMERA))) { - memset(&tsk->oplus_task_info, 0, sizeof(struct task_info)); - return; - } - if (!sched_assist_scene(SA_CAMERA)) - return; - update_task_sched_stat_common(tsk, delta_ns, stats_type); - - try_to_mark_task_type(tsk, TASK_SMALL); -} - -void sched_assist_update_record(struct task_struct *p, u64 delta_ns, int stats_type) -{ - update_sa_task_stats(p, delta_ns, stats_type); - sched_assist_im_systrace_c(p, stats_type + 1); -} - -void sched_assist_im_systrace_c(struct task_struct *tsk, int tst_type) -{ - if (unlikely(!_sched_assist_update_tracemark())) - return; - - if (!is_sched_boost_group(tsk)) - return; - - if (likely(!param_ux_debug)) - return; - - preempt_disable(); - if (tst_type != -1) { - event_trace_printk(mark_addr, "C|10001|short_run_target_%d|%d\n", tsk->pid, tsk->oplus_task_info.im_small ? 1 : 0); - } else if (tst_type == -1) { - event_trace_printk(mark_addr, "C|10001|short_run_target_buddy_%d|%d\n", tsk->pid, 1); - event_trace_printk(mark_addr, "C|10001|short_run_target_buddy_%d|%d\n", tsk->pid, 0); - } - preempt_enable(); -} -#endif - -device_initcall(oplus_sched_assist_init); diff --git a/include/linux/sched_assist/sched_assist_common.h b/include/linux/sched_assist/sched_assist_common.h deleted file mode 100755 index 990a381cc6fc..000000000000 --- a/include/linux/sched_assist/sched_assist_common.h +++ /dev/null @@ -1,310 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _OPLUS_SCHED_COMMON_H_ -#define _OPLUS_SCHED_COMMON_H_ - -#include - -#define ux_err(fmt, ...) \ - printk_deferred(KERN_ERR "[SCHED_ASSIST_ERR][%s]"fmt, __func__, ##__VA_ARGS__) -#define ux_warn(fmt, ...) \ - printk_deferred(KERN_WARNING "[SCHED_ASSIST_WARN][%s]"fmt, __func__, ##__VA_ARGS__) -#define ux_debug(fmt, ...) \ - printk_deferred(KERN_INFO "[SCHED_ASSIST_INFO][%s]"fmt, __func__, ##__VA_ARGS__) - -#define UX_MSG_LEN 64 -#define UX_DEPTH_MAX 5 - -/* define for sched assist thread type, keep same as the define in java file */ -#define SA_OPT_CLEAR (0) -#define SA_TYPE_LIGHT (1 << 0) -#define SA_TYPE_HEAVY (1 << 1) -#define SA_TYPE_ANIMATOR (1 << 2) -#define SA_TYPE_LISTPICK (1 << 3) -#ifdef CONFIG_UCLAMP_TASK -#define SA_TYPE_TURBO (1 << 4) /* for high load rt boost, used in audio*/ -#endif -#ifdef CONFIG_KERNEL_LOCK_OPT -#define SA_TYPE_LISTPICK_LOCK (1 << 5) -#endif -#define SA_OPT_SET (1 << 7) -#define SA_TYPE_INHERIT (1 << 8) -#define SA_TYPE_ONCE_UX (1 << 9) -#define SA_TYPE_ID_CAMERA_PROVIDER (1 << 10) -#define SA_TYPE_ID_ALLOCATOR_SER (1 << 11) - - - -#define SCHED_ASSIST_UX_MASK (0xFF) - -/* define for sched assist scene type, keep same as the define in java file */ -#define SA_SCENE_OPT_CLEAR (0) -#define SA_LAUNCH (1 << 0) -#define SA_SLIDE (1 << 1) -#define SA_CAMERA (1 << 2) -#define SA_ANIM_START (1 << 3) /* we care about both launcher and top app */ -#define SA_ANIM (1 << 4) /* we only care about launcher */ -#define SA_INPUT (1 << 5) -#define SA_LAUNCHER_SI (1 << 6) -#define SA_SCENE_OPT_SET (1 << 7) - -#ifdef CONFIG_CGROUP_SCHED -#define SA_CGROUP_DEFAULT (1) -#define SA_CGROUP_FOREGROUD (2) -#define SA_CGROUP_BACKGROUD (3) -#define SA_CGROUP_TOP_APP (4) -#endif - -/* define for load balance task type */ -#define SA_HIGH_LOAD 1 -#define SA_LOW_LOAD 0 -#define SA_UX 1 -#define SA_TOP 2 -#define SA_FG 3 -#define SA_BG 4 - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -DECLARE_PER_CPU(struct task_count_rq, task_lb_count); -#endif - -enum UX_STATE_TYPE -{ - UX_STATE_INVALID = 0, - UX_STATE_NONE, - UX_STATE_SCHED_ASSIST, - UX_STATE_INHERIT, - MAX_UX_STATE_TYPE, -}; - -enum INHERIT_UX_TYPE -{ - INHERIT_UX_BINDER = 0, - INHERIT_UX_RWSEM, - INHERIT_UX_MUTEX, - INHERIT_UX_SEM, - INHERIT_UX_FUTEX, - INHERIT_UX_MAX, -}; - -struct ux_sched_cluster { - struct cpumask cpus; - unsigned long capacity; -}; - -struct ux_sched_cputopo { - int cls_nr; - struct ux_sched_cluster sched_cls[NR_CPUS]; -}; - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -extern unsigned int walt_scale_demand_divisor; -#else -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#endif -#define scale_demand(d) ((d)/walt_scale_demand_divisor) - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -struct task_count_rq{ - int ux_high; - int ux_low; - int top_high; - int top_low; - int foreground_high; - int foreground_low; - int background_high; - int background_low; -}; - -enum OPLUS_LB_TYPE -{ - OPLUS_LB_UX = 1, - OPLUS_LB_TOP, - OPLUS_LB_FG, - OPLUS_LB_BG, - OPLUS_LB_MAX, -}; -#endif - -enum ANMATION_TYPE -{ - ANNIMATION_END = 0, - APP_START_ANIMATION, - APP_EXIT_ANIMATION, - ULIMIT_PROCESS, - LAUNCHER_SI_START, - BACKUP, - SYSTEMUI_SPLIT_STARTM, -}; - -struct rq; -extern unsigned int ux_uclamp_value; -extern int sysctl_input_boost_enabled; -extern int sysctl_animation_type; -extern int sysctl_input_boost_enabled; -extern int sysctl_sched_assist_ib_duration_coedecay; -extern int sched_assist_ib_duration_coedecay; -extern u64 sched_assist_input_boost_duration; -extern int ux_prefer_cpu[]; -extern int sysctl_animation_type; - -extern void ux_init_rq_data(struct rq *rq); -extern void ux_init_cpu_data(void); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -extern void init_rq_cpu(int cpu); -#endif - -extern bool test_list_pick_ux(struct task_struct *task); -extern void enqueue_ux_thread(struct rq *rq, struct task_struct *p); -extern void dequeue_ux_thread(struct rq *rq, struct task_struct *p); -extern void pick_ux_thread(struct rq *rq, struct task_struct **p, struct sched_entity **se); -extern bool sched_assist_pick_next_task_opt(struct cfs_rq *cfs_rq, struct sched_entity **se); -extern void inherit_ux_dequeue(struct task_struct *task, int type); -extern void inherit_ux_dequeue_refs(struct task_struct *task, int type, int value); -extern void inherit_ux_enqueue(struct task_struct *task, int type, int depth); -extern void inherit_ux_inc(struct task_struct *task, int type); -extern void inherit_ux_sub(struct task_struct *task, int type, int value); - -extern void set_inherit_ux(struct task_struct *task, int type, int depth, int inherit_val); -extern void reset_inherit_ux(struct task_struct *inherit_task, struct task_struct *ux_task, int reset_type); -extern void unset_inherit_ux(struct task_struct *task, int type); -extern void unset_inherit_ux_value(struct task_struct *task, int type, int value); -extern void inc_inherit_ux_refs(struct task_struct *task, int type); - -extern bool test_task_ux(struct task_struct *task); -extern bool test_task_ux_depth(int ux_depth); -extern bool test_inherit_ux(struct task_struct *task, int type); -extern bool test_set_inherit_ux(struct task_struct *task); -extern int get_ux_state_type(struct task_struct *task); - -extern bool test_ux_task_cpu(int cpu); -extern bool test_ux_prefer_cpu(struct task_struct *task, int cpu); -extern void find_ux_task_cpu(struct task_struct *task, int *target_cpu); -static inline void find_slide_boost_task_cpu(struct task_struct *task, int *target_cpu) {} - -extern void sched_assist_systrace_pid(pid_t pid, int val, const char *fmt, ...); -#define SA_SYSTRACE_MAGIC 123 -#define sched_assist_systrace(...) sched_assist_systrace_pid(SA_SYSTRACE_MAGIC, __VA_ARGS__) - -extern void place_entity_adjust_ux_task(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial); -extern bool should_ux_task_skip_further_check(struct sched_entity *se); -extern bool should_ux_preempt_wakeup(struct task_struct *wake_task, struct task_struct *curr_task); -extern bool should_ux_task_skip_cpu(struct task_struct *task, unsigned int cpu); -extern bool set_ux_task_to_prefer_cpu(struct task_struct *task, int *orig_target_cpu); -extern int set_ux_task_cpu_common_by_prio(struct task_struct *task, int *target_cpu, bool boost, bool prefer_idle, unsigned int type); -extern bool ux_skip_sync_wakeup(struct task_struct *task, int *sync); -extern void set_ux_task_to_prefer_cpu_v1(struct task_struct *task, int *orig_target_cpu, bool *cond); -extern bool im_mali(struct task_struct *p); -extern bool cgroup_check_set_sched_assist_boost(struct task_struct *p); -extern int get_st_group_id(struct task_struct *task); -extern void cgroup_set_sched_assist_boost_task(struct task_struct *p); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -extern void inc_ld_stats(struct task_struct *tsk, struct rq *rq); -extern void dec_ld_stats(struct task_struct *tsk, struct rq *rq); -extern void update_load_flag(struct task_struct *tsk, struct rq *rq); - -extern int task_lb_sched_type(struct task_struct *tsk); -extern unsigned long reweight_cgroup_task(u64 slice, struct sched_entity *se, unsigned long task_weight, struct load_weight *lw); -#if !defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) || (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -extern void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int start_cpu, int skip_cpu, cpumask_t *cpus, bool strict); -#else -extern void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int order_index, int end_index, int skip_cpu, cpumask_t *cpus, bool strict); -#endif -extern bool should_force_spread_tasks(void); -extern bool should_force_adjust_vruntime(struct sched_entity *se); -extern u64 sa_calc_delta(struct sched_entity *se, u64 delta_exec, unsigned long weight, struct load_weight *lw, bool calc_fair); -extern void update_rq_nr_imbalance(int cpu); -#endif - -extern bool test_task_identify_ux(struct task_struct *task, int id_type_ux); -extern bool is_task_util_over(struct task_struct *task, int threshold); - -#ifdef CONFIG_SCHED_WALT -extern bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag); -extern bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock); -#else -static inline bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag) { return false; } -static inline bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock) { return false; } -#endif - -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern void update_sa_task_stats(struct task_struct *tsk, u64 delta_ns, int stats_type); -extern void sched_assist_im_systrace_c(struct task_struct *tsk, int tst_type); -extern void sched_assist_update_record(struct task_struct *p, u64 delta_ns, int stats_type); -extern bool sched_assist_pick_next_task(struct cfs_rq *cfs_rq, struct sched_entity *se); -#endif - -extern bool skip_check_preempt_curr(struct rq *rq, struct task_struct *p, int flags); - -static inline bool is_heavy_ux_task(struct task_struct *task) -{ - return task->ux_state & SA_TYPE_HEAVY; -} - -static inline bool is_animation_ux(struct task_struct *task) -{ - return task->ux_state & SA_TYPE_ANIMATOR; -} -static inline void set_once_ux(struct task_struct *task) -{ - task->ux_state |= SA_TYPE_ONCE_UX; -} - -static inline bool sched_assist_scene(unsigned int scene) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - switch (scene) { - case SA_LAUNCH: - return sysctl_sched_assist_scene & SA_LAUNCH; - case SA_SLIDE: - return sysctl_slide_boost_enabled; - case SA_INPUT: - return sysctl_input_boost_enabled; - case SA_CAMERA: - return sysctl_sched_assist_scene & SA_CAMERA; - case SA_LAUNCHER_SI: - return sysctl_animation_type == LAUNCHER_SI_START; - case SA_ANIM: - return sysctl_sched_assist_scene & SA_ANIM; - default: - return sysctl_sched_assist_scene & scene; - } -} - -static inline bool is_sched_assist_scene() { - return sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM); -} - -static inline bool should_skip_detach_tasks(struct task_struct *tsk) -{ - return (sysctl_sched_assist_enabled >= 2) && test_task_ux(tsk) && !sched_assist_scene(SA_CAMERA); -} - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -static inline bool is_spread_task_enabled(void) -{ - return (sysctl_sched_assist_enabled >= 2) && !sched_assist_scene(SA_CAMERA); -} -#endif - -static inline bool task_demand_ignore_wait_time(int event) -{ - return false; -} - -bool should_limit_task_skip_cpu(struct task_struct *p, int cpu); -bool set_limit_task_target_cpu(struct task_struct *p, int *cpu); -bool is_sf(struct task_struct *p); - -int task_index_of_sf_union(struct task_struct *p); -void sf_task_util_record(struct task_struct *p); -u64 sf_union_ux_load(struct task_struct *tsk, u64 timeline); - -#endif /* _OPLUS_SCHED_COMMON_H_ */ diff --git a/include/linux/sched_assist/sched_assist_fork.h b/include/linux/sched_assist/sched_assist_fork.h deleted file mode 100755 index 63f8e26cb992..000000000000 --- a/include/linux/sched_assist/sched_assist_fork.h +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include - -#ifndef _OPLUS_SCHED_FORK_H_ -#define _OPLUS_SCHED_FORK_H_ - -static inline void init_task_ux_info(struct task_struct *p) -{ - p->ux_state = 0; - atomic64_set(&(p->inherit_ux), 0); - INIT_LIST_HEAD(&p->ux_entry); - p->ux_depth = 0; - p->enqueue_time = 0; - p->inherit_ux_start = 0; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - p->ux_once = 0; - p->get_mmlock = 0; - p->get_mmlock_ts = 0; -#endif -#ifdef CONFIG_KERNEL_LOCK_OPT - INIT_LIST_HEAD(&p->own_rwsem); - p->lock_waiting_start = 0; - p->mt_count = 0; - p->hold_rwsem = NULL; -#endif -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - p->lb_state = 0; - p->ld_flag = 0; -#endif -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - memset(&p->oplus_task_info, 0, sizeof(struct task_info)); -#endif -} -#endif /* _OPLUS_SCHED_FORK_H_ */ diff --git a/include/linux/sched_assist/sched_assist_futex.c b/include/linux/sched_assist/sched_assist_futex.c deleted file mode 100755 index f0798273dcde..000000000000 --- a/include/linux/sched_assist/sched_assist_futex.c +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include "sched_assist_common.h" - -#define CREATE_TRACE_POINTS -#include "sched_assist_trace.h" - -struct task_struct* get_futex_owner_by_pid(u32 owner_tid) -{ - struct task_struct* futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { - rcu_read_lock(); - futex_owner = find_task_by_vpid(owner_tid); - rcu_read_unlock(); - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) -static inline struct task_struct *oplus_find_get_task_by_vpid(pid_t nr) -{ - struct task_struct *task; - - rcu_read_lock(); - task = find_task_by_vpid(nr); - if (task) - get_task_struct(task); - rcu_read_unlock(); - - return task; -} -#endif - -struct task_struct* get_futex_owner_by_pid_v2(u32 owner_tid) { - struct task_struct* futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - futex_owner = find_get_task_by_vpid(owner_tid); -#else - futex_owner = oplus_find_get_task_by_vpid(owner_tid); -#endif - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -struct task_struct *get_futex_owner(u32 owner_tid) -{ - struct task_struct *futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { - rcu_read_lock(); - futex_owner = find_task_by_vpid(owner_tid); - rcu_read_unlock(); - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -void futex_set_inherit_ux(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = false; - is_ux = test_set_inherit_ux(task); - - if (is_ux && owner && !test_task_ux(owner)) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - } -} - -void futex_unset_inherit_ux(struct task_struct *task) -{ - if (test_inherit_ux(task, INHERIT_UX_FUTEX)) { - unset_inherit_ux(task, INHERIT_UX_FUTEX); - } -} - -void futex_set_inherit_ux_refs(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = test_set_inherit_ux(task); - - if (is_ux && owner) { - bool type = get_ux_state_type(owner); - if (UX_STATE_NONE == type) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - } else { - inherit_ux_inc(owner, INHERIT_UX_FUTEX); - } - } -} - -int futex_set_inherit_ux_refs_v2(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = test_set_inherit_ux(task); - - if (is_ux && owner) { - int type = get_ux_state_type(owner); - if (UX_STATE_NONE == type) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - return 1; - } else if (UX_STATE_INHERIT == type) { - inc_inherit_ux_refs(owner, INHERIT_UX_FUTEX); - return 2; - } - } - - return 0; -} - -void futex_unset_inherit_ux_refs(struct task_struct *task, int value) -{ - if (test_inherit_ux(task, INHERIT_UX_FUTEX)) { - unset_inherit_ux_value(task, INHERIT_UX_FUTEX, value); - } -} diff --git a/include/linux/sched_assist/sched_assist_futex.h b/include/linux/sched_assist/sched_assist_futex.h deleted file mode 100755 index eba5f11740d3..000000000000 --- a/include/linux/sched_assist/sched_assist_futex.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_FUTEX_H_ -#define _OPLUS_SCHED_FUTEX_H_ -extern bool test_task_ux(struct task_struct *task); -extern struct task_struct* get_futex_owner(u32 __user *uaddr2); -extern struct task_struct* get_futex_owner_by_pid(u32 owner_tid); -extern struct task_struct* get_futex_owner_by_pid_v2(u32 owner_tid); -extern void futex_set_inherit_ux(struct task_struct *owner, struct task_struct *task); -extern void futex_unset_inherit_ux(struct task_struct *task); -extern void futex_set_inherit_ux_refs(struct task_struct *owner, struct task_struct *task); -extern int futex_set_inherit_ux_refs_v2(struct task_struct *owner, struct task_struct *task); -extern void futex_unset_inherit_ux_refs(struct task_struct *task, int value); -#endif /* _OPLUS_SCHED_FUTEX_H_ */ diff --git a/include/linux/sched_assist/sched_assist_mutex.c b/include/linux/sched_assist/sched_assist_mutex.c deleted file mode 100755 index bf61a14b3254..000000000000 --- a/include/linux/sched_assist/sched_assist_mutex.c +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include "sched_assist_common.h" -#ifdef CONFIG_KERNEL_LOCK_OPT -#include -#endif -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#define MUTEX_FLAGS 0x07 -static inline struct task_struct *__mutex_owner(struct mutex *lock) -{ - return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS); -} -#endif - -static void mutex_list_add_ux(struct list_head *entry, struct list_head *head) -{ - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct mutex_waiter *waiter = NULL; - list_for_each_safe(pos, n, head) { - waiter = list_entry(pos, struct mutex_waiter, list); -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task)) { -#else - if (!test_task_ux(waiter->task)) { -#endif - list_add(entry, waiter->list.prev); - return; - } - } - if (pos == head) { - list_add_tail(entry, head); - } -} - -void mutex_list_add(struct task_struct *task, struct list_head *entry, struct list_head *head, struct mutex *lock) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(task); -#else - bool is_ux = test_task_ux(task); -#endif - if (!entry || !head || !lock) { - return; - } -#ifdef CONFIG_KERNEL_LOCK_OPT - if (is_ux) { -#else - if (is_ux && !lock->ux_dep_task) { -#endif - mutex_list_add_ux(entry, head); - } else { - list_add_tail(entry, head); - } -} - -void mutex_set_inherit_ux(struct mutex *lock, struct task_struct *task) -{ - bool is_ux = false; - struct task_struct *owner = NULL; - if (!lock) { - return; - } - is_ux = test_set_inherit_ux(task); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) - owner = __mutex_owner(lock); -#else - owner = lock->owner; -#endif - if (is_ux && !lock->ux_dep_task) { - int type = get_ux_state_type(owner); - if ((UX_STATE_NONE == type) || (UX_STATE_INHERIT == type)) { - set_inherit_ux(owner, INHERIT_UX_MUTEX, task->ux_depth, task->ux_state); - lock->ux_dep_task = owner; - } - } -} - -void mutex_unset_inherit_ux(struct mutex *lock, struct task_struct *task) -{ - if (lock && lock->ux_dep_task == task) { - unset_inherit_ux(task, INHERIT_UX_MUTEX); - lock->ux_dep_task = NULL; - } -} diff --git a/include/linux/sched_assist/sched_assist_mutex.h b/include/linux/sched_assist/sched_assist_mutex.h deleted file mode 100755 index a862aec004e6..000000000000 --- a/include/linux/sched_assist/sched_assist_mutex.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_MUTEX_H_ -#define _OPLUS_SCHED_MUTEX_H_ - -extern void mutex_list_add(struct task_struct *task, struct list_head *entry, struct list_head *head, struct mutex *lock); -extern void mutex_set_inherit_ux(struct mutex *lock, struct task_struct *task); -extern void mutex_unset_inherit_ux(struct mutex *lock, struct task_struct *task); - -#endif /* _OPLUS_SCHED_MUTEX_H_ */ diff --git a/include/linux/sched_assist/sched_assist_rt.c b/include/linux/sched_assist/sched_assist_rt.c deleted file mode 100755 index ed832f8d5b3f..000000000000 --- a/include/linux/sched_assist/sched_assist_rt.c +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include <../kernel/sched/sched.h> - -#define WALT_RT_PULL_THRESHOLD_NS 250000 -#define CPUSET_AUDIO_APP (7) - -static inline int has_pushable_tasks(struct rq *rq) -{ - return !plist_head_empty(&rq->rt.pushable_tasks); -} - -static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!task_running(rq, p) && cpumask_test_cpu(cpu, p->cpus_ptr)) - return 1; -#else - if (!task_running(rq, p) && cpumask_test_cpu(cpu, &p->cpus_allowed)) - return 1; -#endif - - return 0; -} - -static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu) -{ - struct plist_head *head = &rq->rt.pushable_tasks; - struct task_struct *p; - - if (!has_pushable_tasks(rq)) - return NULL; - - plist_for_each_entry(p, head, pushable_tasks) { - if (pick_rt_task(rq, p, cpu)) - return p; - } - - return NULL; -} - - -static inline bool is_audio_app_group(struct task_struct *p) -{ -#ifdef CONFIG_CGROUP_SCHED - return task_css(p, cpuset_cgrp_id)->id == CPUSET_AUDIO_APP; -#else - return false; -#endif -} - -#ifdef CONFIG_SCHED_WALT -bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock) -{ - int i, this_cpu = this_rq->cpu, src_cpu = this_cpu; - struct rq *src_rq; - struct task_struct *p; - bool pulled = false; - - /* can't help if this has a runnable RT */ - if (this_rq->rt.rt_queued > 0) - return false; - - /* check if any CPU has a pushable RT task */ - for_each_possible_cpu(i) { - struct rq *rq = cpu_rq(i); - - if (!has_pushable_tasks(rq)) - continue; - src_cpu = i; - break; - } - - if (src_cpu == this_cpu) - return false; - - src_rq = cpu_rq(src_cpu); - double_lock_balance(this_rq, src_rq); - - /* lock is dropped, so check again */ - if (this_rq->rt.rt_queued > 0) - goto unlock; - - p = pick_highest_pushable_task(src_rq, this_cpu); - - if (!p) - goto unlock; - - /* we only allow audio-app group task doing this work */ - if (!is_audio_app_group(p)) - goto unlock; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (wallclock - p->wts.last_wake_ts < WALT_RT_PULL_THRESHOLD_NS) - goto unlock; -#else - if (wallclock - p->last_wake_ts < WALT_RT_PULL_THRESHOLD_NS) - goto unlock; -#endif - - pulled = true; - deactivate_task(src_rq, p, 0); - set_task_cpu(p, this_cpu); - activate_task(this_rq, p , 0); -unlock: - double_unlock_balance(this_rq, src_rq); - - return pulled; -} -#endif diff --git a/include/linux/sched_assist/sched_assist_rwsem.c b/include/linux/sched_assist/sched_assist_rwsem.c deleted file mode 100755 index c43618a0835a..000000000000 --- a/include/linux/sched_assist/sched_assist_rwsem.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include "sched_assist_common.h" - -enum rwsem_waiter_type { - RWSEM_WAITING_FOR_WRITE, - RWSEM_WAITING_FOR_READ -}; - -struct rwsem_waiter { - struct list_head list; - struct task_struct *task; - enum rwsem_waiter_type type; -}; - -#define RWSEM_READER_OWNED ((struct task_struct *)1UL) - -static inline bool rwsem_owner_is_writer(struct task_struct *owner) -{ - return owner && owner != RWSEM_READER_OWNED; -} - -static void rwsem_list_add_ux(struct list_head *entry, struct list_head *head) -{ - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct rwsem_waiter *waiter = NULL; - list_for_each_safe(pos, n, head) { - waiter = list_entry(pos, struct rwsem_waiter, list); -#ifdef CONFIG_RWSEM_PRIO_AWARE -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task) && waiter->task->prio > MAX_RT_PRIO) { -#else - if (!test_task_ux(waiter->task) && waiter->task->prio > MAX_RT_PRIO) { -#endif -#else -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task)) { -#else - if (!test_task_ux(waiter->task)) { -#endif -#endif - list_add(entry, waiter->list.prev); - return; - } - } - if (pos == head) { - list_add_tail(entry, head); - } -} - -#ifndef CONFIG_MTK_TASK_TURBO -#ifdef CONFIG_RWSEM_PRIO_AWARE -bool rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head, struct rw_semaphore *sem) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(tsk); -#else - bool is_ux = test_task_ux(tsk); -#endif - if (!entry || !head) { - return false; - } - if (is_ux) { - rwsem_list_add_ux(entry, head); - sem->m_count++; - return true; - } else { - return false; - } - return false; -} -#else /* CONFIG_RWSEM_PRIO_AWARE */ -void rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(tsk); -#else - bool is_ux = test_task_ux(tsk); -#endif - if (!entry || !head) { - return; - } - if (is_ux) { - rwsem_list_add_ux(entry, head); - } else { - list_add_tail(entry, head); - } -} -#endif /* CONFIG_RWSEM_PRIO_AWARE */ -#endif /* CONFIG_MTK_TASK_TURBO */ - -void rwsem_set_inherit_ux(struct task_struct *tsk, struct task_struct *waiter_task, struct task_struct *owner, struct rw_semaphore *sem) -{ - bool is_ux = test_set_inherit_ux(tsk); - if (waiter_task && is_ux) { - if (rwsem_owner_is_writer(owner) && sem && !sem->ux_dep_task) { - int type = get_ux_state_type(owner); - if ((UX_STATE_NONE == type) || (UX_STATE_INHERIT == type)) { - set_inherit_ux(owner, INHERIT_UX_RWSEM, tsk->ux_depth, tsk->ux_state); - sem->ux_dep_task = owner; - } - } - } -} - -void rwsem_unset_inherit_ux(struct rw_semaphore *sem, struct task_struct *tsk) -{ - if (tsk && sem && sem->ux_dep_task == tsk) { - unset_inherit_ux(tsk, INHERIT_UX_RWSEM); - sem->ux_dep_task = NULL; - } -} diff --git a/include/linux/sched_assist/sched_assist_rwsem.h b/include/linux/sched_assist/sched_assist_rwsem.h deleted file mode 100755 index f10a16658755..000000000000 --- a/include/linux/sched_assist/sched_assist_rwsem.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_RWSEM_H_ -#define _OPLUS_SCHED_RWSEM_H_ - -#ifndef CONFIG_MTK_TASK_TURBO -#ifdef CONFIG_RWSEM_PRIO_AWARE -extern bool rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head, struct rw_semaphore *sem); -#else /* CONFIG_RWSEM_PRIO_AWARE */ -extern void rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head); -#endif /* CONFIG_RWSEM_PRIO_AWARE */ -#endif /* CONFIG_MTK_TASK_TURBO */ - -extern void rwsem_set_inherit_ux(struct task_struct *tsk, struct task_struct *waiter_task, struct task_struct *owner, struct rw_semaphore *sem); -extern void rwsem_unset_inherit_ux(struct rw_semaphore *sem, struct task_struct *tsk); -#endif /* _OPLUS_SCHED_RWSEM_H_ */ diff --git a/include/linux/sched_assist/sched_assist_slide.c b/include/linux/sched_assist/sched_assist_slide.c deleted file mode 100755 index 790c8c166974..000000000000 --- a/include/linux/sched_assist/sched_assist_slide.c +++ /dev/null @@ -1,237 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include <../kernel/sched/sched.h> - -#include "sched_assist_common.h" -#include "sched_assist_slide.h" - -#define UX_LOAD_WINDOW 8000000 -#define DEFAULT_INPUT_BOOST_DURATION 1000 -u64 ux_task_load[NR_CPUS] = {0}; -u64 ux_load_ts[NR_CPUS] = {0}; - -int sysctl_slide_boost_enabled = 0; -int sysctl_boost_task_threshold = 51; -int sysctl_frame_rate = 60; - -void sched_assist_adjust_slide_param(unsigned int *maxtime) { - /*give each scene with default boost value*/ - if (sched_assist_scene(SA_SLIDE)) { - if (sysctl_frame_rate <= 90) - *maxtime = 5; - else if (sysctl_frame_rate <= 120) - *maxtime = 4; - else - *maxtime = 3; - } else if (sched_assist_scene(SA_INPUT)) { - if (sysctl_frame_rate <= 90) - *maxtime = 8; - else if (sysctl_frame_rate <= 120) - *maxtime = 7; - else - *maxtime = 6; - } -} - -static u64 calc_freq_ux_load(struct task_struct *p, u64 wallclock) -{ - unsigned int maxtime = 5, factor = 0; - unsigned int window_size = sched_ravg_window / NSEC_PER_MSEC; - u64 timeline = 0, freq_exec_load = 0, freq_ravg_load = 0; - u64 wakeclock = p->wts.last_wake_ts; - - if (wallclock < wakeclock) - return 0; - - sched_assist_adjust_slide_param(&maxtime); - timeline = wallclock - wakeclock; - timeline = sf_union_ux_load(p, timeline); - factor = window_size / maxtime; - freq_exec_load = timeline * factor; - if (freq_exec_load > sched_ravg_window) - freq_exec_load = sched_ravg_window; - - freq_ravg_load = (p->wts.prev_window + p->wts.curr_window) << 1; - if (freq_ravg_load > sched_ravg_window) - freq_ravg_load = sched_ravg_window; - - return max(freq_exec_load, freq_ravg_load); -} - -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ - if (task_util(p) >= sysctl_boost_task_threshold || - scale_demand(p->wts.sum) >= sysctl_boost_task_threshold) { - *start_cpu = rd->wrd.mid_cap_orig_cpu == -1 ? - rd->wrd.max_cap_orig_cpu : rd->wrd.mid_cap_orig_cpu; - } -} - -bool _slide_task_misfit(struct task_struct *p, int cpu) -{ - int num_mincpu = cpumask_weight(topology_core_cpumask(0)); - return (is_task_util_over(p, sysctl_boost_task_threshold)&& cpu < num_mincpu); -} - -u64 _slide_get_boost_load(int cpu) { - u64 wallclock = sched_ktime_clock(); - u64 timeline = 0; - u64 ret_load = 0; - - if ((sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT)|| sched_assist_scene(SA_ANIM)) && ux_task_load[cpu]) { - timeline = wallclock - ux_load_ts[cpu]; - if (timeline >= UX_LOAD_WINDOW) - ux_task_load[cpu] = 0; - - ret_load = ux_task_load[cpu]; - } - - return ret_load; -} - -void adjust_sched_assist_input_ctrl(void) { - static int input_boost_old = 0; - - if (sysctl_input_boost_enabled) { - if(sysctl_slide_boost_enabled || jiffies_to_msecs(jiffies) >= sched_assist_input_boost_duration) { - sysctl_input_boost_enabled = 0; - sched_assist_input_boost_duration = 0; - } - } - if (input_boost_old != sysctl_input_boost_enabled) { - input_boost_old = sysctl_input_boost_enabled; - sched_assist_systrace(sysctl_input_boost_enabled, "ux input"); - } -} - -/* we may need to always keep slide-scene, use it! */ -bool __weak keep_slide_nolimit(struct task_struct *p) -{ - return false; -} - -void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu) { - u64 wallclock = sched_ktime_clock(); - adjust_sched_assist_input_ctrl(); - if (keep_slide_nolimit(rq->curr) || sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) { - if(rq->curr && (is_heavy_ux_task(rq->curr) || rq->curr->sched_class == &rt_sched_class) && !_slide_task_misfit(rq->curr, rq->cpu)) { - ux_task_load[cpu] = calc_freq_ux_load(rq->curr, wallclock); - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } - else if (ux_task_load[cpu] != 0) { - ux_task_load[cpu] = 0; - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_RESET); - } - } else { - ux_task_load[cpu] = 0; - ux_load_ts[cpu] = 0; - } - sched_assist_systrace(ux_task_load[cpu], "ux_load_%d", cpu); -} - -bool should_adjust_slide_task_placement(struct task_struct *p, int cpu) -{ - struct rq *rq = NULL; - - if (!check_slide_scene() && !keep_slide_nolimit(p)) - return false; - - if (!is_heavy_ux_task(p)) - return false; - - /* slide task running on silver core with util over threshold, boost it */ - if (oplus_task_misfit(p, cpu)) - return true; - - /* slide task should not share it's core with another slide task */ - rq = cpu_rq(cpu); - if (rq->curr && is_heavy_ux_task(rq->curr)) - return true; - - return false; -} - -int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_frame_rate, "ux frate"); - - return ret; -} - -int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table * table, int write, - void __user * buffer, size_t * lenp, loff_t * ppos) -{ - int result; - static DEFINE_MUTEX(sa_boost_mutex); - mutex_lock(&sa_boost_mutex); - result = proc_dointvec(table, write, buffer, lenp, ppos); - if (!write) - goto out; - /*orms write just write this proc to tell us update input window*/ - sched_assist_input_boost_duration = jiffies_to_msecs(jiffies) + DEFAULT_INPUT_BOOST_DURATION / sched_assist_ib_duration_coedecay; -out: - mutex_unlock(&sa_boost_mutex); - return result; -} - -int sysctl_sched_slide_boost_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_slide_boost_enabled, "ux slide"); - - return ret; -} - -int sysctl_sched_boost_task_threshold_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_boost_task_threshold, "ux threshold"); - - return ret; -} - -int sysctl_sched_animation_type_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_animation_type, "ux anima"); - - return ret; -} - - diff --git a/include/linux/sched_assist/sched_assist_slide.h b/include/linux/sched_assist/sched_assist_slide.h deleted file mode 100755 index 915daa5fb59a..000000000000 --- a/include/linux/sched_assist/sched_assist_slide.h +++ /dev/null @@ -1,81 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_SLIDE_H_ -#define _OPLUS_SCHED_SLIDE_H_ - -#include -#include "sched_assist_common.h" - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) && defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) -extern unsigned int sched_ravg_window; -extern unsigned int walt_scale_demand_divisor; -#else -#ifdef CONFIG_HZ_300 -#define DEFAULT_SCHED_RAVG_WINDOW (3333333 * 6) -#else -#define DEFAULT_SCHED_RAVG_WINDOW 20000000 -#endif -#define sched_ravg_window DEFAULT_SCHED_RAVG_WINDOW -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#endif -#define scale_demand(d) ((d)/walt_scale_demand_divisor) - -extern int sysctl_slide_boost_enabled; -extern int sysctl_boost_task_threshold; -extern int sysctl_frame_rate; - -extern bool oplus_task_misfit(struct task_struct *p, int cpu); -extern bool _slide_task_misfit(struct task_struct *p, int cpu); -extern u64 _slide_get_boost_load(int cpu); -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu); - -extern void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu); -extern bool should_adjust_slide_task_placement(struct task_struct *p, int cpu); -extern int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_slide_boost_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_animation_type_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_boost_task_threshold_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table * table, int write, void __user * buffer, size_t * lenp, loff_t * ppos); -extern bool keep_slide_nolimit(struct task_struct *p); - -static bool inline check_slide_scene(void) -{ - return sched_assist_scene(SA_SLIDE) - || sched_assist_scene(SA_LAUNCHER_SI) - || sched_assist_scene(SA_INPUT) - || sched_assist_scene(SA_ANIM); -} - -static bool inline slide_task_misfit(struct task_struct *p, int cpu) -{ - return check_slide_scene() && (is_heavy_ux_task(p) || is_sf(p)) && - oplus_task_misfit(p, cpu); -} - -static void inline slide_set_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ - if (check_slide_scene() && (is_heavy_ux_task(p) || is_sf(p))) - _slide_find_start_cpu(rd, p, start_cpu); -} - -static void inline slide_set_task_cpu(struct task_struct *p, int *best_energy_cpu) -{ - if (should_adjust_slide_task_placement(p, *best_energy_cpu)) - find_ux_task_cpu(p, best_energy_cpu); -} - -static void inline slide_set_boost_load(u64 *load, int cpu) -{ - u64 tmpload = *load; - - if (check_slide_scene()) { - tmpload = max_t(u64, tmpload, _slide_get_boost_load(cpu)); - *load = tmpload; - } -} -#endif /* _OPLUS_SCHED_SLIDE_H_ */ diff --git a/include/linux/sched_assist/sched_assist_slide_v1.c b/include/linux/sched_assist/sched_assist_slide_v1.c deleted file mode 100755 index 38374a577ae5..000000000000 --- a/include/linux/sched_assist/sched_assist_slide_v1.c +++ /dev/null @@ -1,239 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include <../kernel/sched/sched.h> -#include <../kernel/sched/walt.h> -#include -#include "sched_assist_common.h" -#include "sched_assist_slide.h" - -#define UX_LOAD_WINDOW 8000000 -#define DEFAULT_INPUT_BOOST_DURATION 1000 -extern struct ux_sched_cputopo ux_sched_cputopo; -u64 ux_task_load[NR_CPUS] = {0}; -u64 ux_load_ts[NR_CPUS] = {0}; -int sysctl_slide_boost_enabled = 0; -int sysctl_boost_task_threshold = 51; -int sysctl_frame_rate = 60; - -void sched_assist_adjust_slide_param(unsigned int *maxtime) { -/* Give each scene with default boost value */ - if (sched_assist_scene(SA_SLIDE)) { - if (sysctl_frame_rate <= 90) - *maxtime = 5; - else if (sysctl_frame_rate <= 120) - *maxtime = 4; - else - *maxtime = 3; - } else if (sched_assist_scene(SA_INPUT)) { - if (sysctl_frame_rate <= 90) - *maxtime = 8; - else if (sysctl_frame_rate <= 120) - *maxtime = 7; - else - *maxtime = 6; - } -} - -static u64 calc_freq_ux_load(struct task_struct *p, u64 wallclock) -{ - unsigned int maxtime = 0, factor = 0; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - unsigned int window_size = sched_ravg_window / NSEC_PER_MSEC; -#else - unsigned int window_size = walt_ravg_window / NSEC_PER_MSEC; -#endif - u64 timeline = 0, freq_exec_load = 0, freq_ravg_load = 0; - u64 wakeclock = p->last_wake_ts; - - if (wallclock < wakeclock) - return 0; - - sched_assist_adjust_slide_param(&maxtime); - timeline = wallclock - wakeclock; - timeline = sf_union_ux_load(p, timeline); - factor = window_size / maxtime; - freq_exec_load = timeline * factor; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (freq_exec_load > sched_ravg_window) - freq_exec_load = sched_ravg_window; -#else - if (freq_exec_load > walt_ravg_window) - freq_exec_load = walt_ravg_window; -#endif - freq_ravg_load = (p->ravg.prev_window + p->ravg.curr_window) << 1; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (freq_ravg_load > sched_ravg_window) - freq_ravg_load = sched_ravg_window; -#else - if (freq_ravg_load > walt_ravg_window) - freq_ravg_load = walt_ravg_window; -#endif - return max(freq_exec_load, freq_ravg_load); -} - -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (task_util(p) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold) { -#else - if (READ_ONCE(p->se.avg.util_avg) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold) { -#endif - if (ux_sched_cputopo.cls_nr > 2) { - *start_cpu = cpumask_first(&ux_sched_cputopo.sched_cls[1].cpus); - } else if (rd->max_cap_orig_cpu != -1) { - *start_cpu = rd->max_cap_orig_cpu; - } - } -} - -u64 _slide_get_boost_load(int cpu) { - u64 timeline = 0; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - u64 wallclock = sched_ktime_clock(); -#else - u64 wallclock = walt_ktime_clock(); -#endif - - if ((sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || - sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) - && ux_task_load[cpu]) { - timeline = wallclock - ux_load_ts[cpu]; - - if (timeline >= UX_LOAD_WINDOW) - ux_task_load[cpu] = 0; - - return ux_task_load[cpu]; - } else { - return 0; - } -} - -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#define SCHED_CPUFREQ_RESET (1U << 7) -#define SCHED_CPUFREQ_BOOST (1U << 9) -#else -#define SCHED_CPUFREQ_WALT (1U << 4) -#define SCHED_CPUFREQ_RESET (1U << 7) -#define SCHED_CPUFREQ_BOOST (1U << 9) -#endif -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - -void adjust_sched_assist_input_ctrl() { - if (!sysctl_input_boost_enabled) - return; - - if (sysctl_slide_boost_enabled) { - sysctl_input_boost_enabled = 0; - sched_assist_input_boost_duration = 0; - return; - } - - if (jiffies_to_msecs(jiffies) < sched_assist_input_boost_duration) { - return; - } else { - sched_assist_input_boost_duration = 0; - sysctl_input_boost_enabled = 0; - } -} - -void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - u64 wallclock = sched_ktime_clock(); -#else - u64 wallclock = walt_ktime_clock(); -#endif - adjust_sched_assist_input_ctrl(); - if (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT)) { - if(rq->curr && (is_heavy_ux_task(rq->curr) || rq->curr->sched_class == &rt_sched_class) && !oplus_task_misfit(rq->curr, rq->cpu)) { - ux_task_load[cpu] = calc_freq_ux_load(rq->curr, wallclock); - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } else if (ux_task_load[cpu] && !test_task_ux(rq->curr)) { - ux_task_load[cpu] = 0; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } - } -} - -bool should_adjust_slide_task_placement(struct task_struct *p, int cpu) -{ - struct rq *rq = NULL; - - if (!check_slide_scene()) - return false; - - if (!is_heavy_ux_task(p)) - return false; - - /* slide task running on silver core with util over threshold, boost it */ - if (oplus_task_misfit(p, cpu)) - return true; - - /* slide task should not share it's core with another slide task */ - rq = cpu_rq(cpu); - if (rq->curr && is_heavy_ux_task(rq->curr)) - return true; - - return false; -} - -int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - return ret; -} - -int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int result; - static DEFINE_MUTEX(sa_boost_mutex); - - mutex_lock(&sa_boost_mutex); - result = proc_dointvec(table, write, buffer, lenp, ppos); - if (!write) - goto out; - - /* Orms write just write this proc to tell us update input window */ - sched_assist_input_boost_duration = jiffies_to_msecs(jiffies) + DEFAULT_INPUT_BOOST_DURATION / sysctl_sched_assist_ib_duration_coedecay; -#ifndef CONFIG_MACH_MT6877 - sysctl_boost_task_threshold = 102; -#endif -out: - mutex_unlock(&sa_boost_mutex); - return result; -} - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) -void oplus_get_cpu_util_mtk(int cpu, u64 *walt_cpu_util, int *boosted) -{ - if (sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_LAUNCHER_SI) || - sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) && ux_task_load[cpu]) { - *boosted = true; - *walt_cpu_util = cpu_rq(cpu)->prev_runnable_sum; - slide_set_boost_load(walt_cpu_util, cpu); - *walt_cpu_util <<= SCHED_CAPACITY_SHIFT; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - do_div(*walt_cpu_util, sched_ravg_window); -#else - do_div(*walt_cpu_util, walt_ravg_window); -#endif - } else { - return; - } -} -#endif diff --git a/include/linux/sched_assist/sched_assist_status.h b/include/linux/sched_assist/sched_assist_status.h deleted file mode 100755 index b01f8c4d3f69..000000000000 --- a/include/linux/sched_assist/sched_assist_status.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_STATUS_H_ -#define _OPLUS_SCHED_STATUS_H_ -enum task_stats_type { - TST_SLEEP = 0, /* update sleeping time when enq-wakeup */ - TST_RUNNABLE, /* update runnable time when enq_deq */ - TST_EXEC, /* update exec time when deq-sleep */ - TST_SCHED_TYPE_TOTAL, /* total type*/ -}; - -#define TASK_INFO_SAMPLE 4 -struct task_info { - u64 sa_info[TST_SCHED_TYPE_TOTAL][TASK_INFO_SAMPLE]; - bool im_small; -}; - -extern int sysctl_sched_impt_tgid; -#endif /* _OPLUS_SCHED_STATUS_H_ */ diff --git a/include/linux/sched_assist/sched_assist_trace.h b/include/linux/sched_assist/sched_assist_trace.h deleted file mode 100755 index 98129a9aaf56..000000000000 --- a/include/linux/sched_assist/sched_assist_trace.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#if !defined(_OPLUS_SCHED_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) -#define _OPLUS_SCHED_TRACE_H - -#include - -#undef TRACE_SYSTEM -#define TRACE_SYSTEM oplus_sched -#define TRACE_INCLUDE_FILE sched_assist_trace - -TRACE_EVENT(oplus_tp_sched_change_ux, - TP_PROTO(int chg_ux, int target_cpu), - TP_ARGS(chg_ux, target_cpu), - TP_STRUCT__entry( - __field(int, chg_ux) - __field(int, target_cpu)), - TP_fast_assign( - __entry->chg_ux = chg_ux; - __entry->target_cpu = target_cpu;), - TP_printk("chg_ux=%d target_cpu=%d", __entry->chg_ux, __entry->target_cpu) -); - -TRACE_EVENT(oplus_tp_sched_switch_ux, - TP_PROTO(int chg_ux, int target_cpu), - TP_ARGS(chg_ux, target_cpu), - TP_STRUCT__entry( - __field(int, chg_ux) - __field(int, target_cpu)), - TP_fast_assign( - __entry->chg_ux = chg_ux; - __entry->target_cpu = target_cpu;), - TP_printk("chg_ux=%d target_cpu=%d", __entry->chg_ux, __entry->target_cpu) -); - -#endif /* _OPLUS_SCHED_TRACE_H */ - -/* This part must be outside protection */ -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . -#include diff --git a/include/linux/sched_assist/sched_assist_workqueue.c b/include/linux/sched_assist/sched_assist_workqueue.c deleted file mode 100755 index dd542b607719..000000000000 --- a/include/linux/sched_assist/sched_assist_workqueue.c +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - -#include -#include - -int is_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return 0; - - return work->ux_work; -} - -inline int set_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return false; - return work->ux_work = 1; -} - -inline int unset_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return false; - return work->ux_work = 0; -} - -inline void set_ux_worker_task(struct task_struct *task) -{ - task->ux_state = 1; -} - -inline void reset_ux_worker_task(struct task_struct *task) -{ - task->ux_state = 0; -} - -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ -#endif diff --git a/include/linux/sched_assist/sched_assist_workqueue.h b/include/linux/sched_assist/sched_assist_workqueue.h deleted file mode 100755 index c5156c36dcf1..000000000000 --- a/include/linux/sched_assist/sched_assist_workqueue.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_WORKQUEUE_H_ -#define _OPLUS_WORKQUEUE_H_ - -struct worker; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -int is_uxwork(struct work_struct *work); -inline int set_uxwork(struct work_struct *work); -inline int unset_uxwork(struct work_struct *work); -inline void set_ux_worker_task(struct task_struct *task); -inline void reset_ux_worker_task(struct task_struct *task); -#else /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ -static inline int is_uxwork(struct work_struct *work) { return false; } -static inline int set_uxwork(struct work_struct *work) { return false; } -static inline int unset_uxwork(struct work_struct *work) { return false; } -static inline void set_ux_worker_task(struct task_struct *task) {} -static inline void reset_ux_worker_task(struct task_struct *task) {} -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ - -#endif /* _OPLUS_WORKQUEUE_H_ */ diff --git a/include/linux/slab.h b/include/linux/slab.h index 68fa38949150..6b8884ccd440 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -281,13 +281,6 @@ enum kmalloc_cache_type { }; #ifndef CONFIG_SLOB -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) -/* Kui.Zhang@tech.kernel.mm, 2020-02-13, record the kmalloc cache with debug - * flag, such as SLAB_STORE_USER - */ -extern atomic64_t kmalloc_debug_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1]; -extern int kmalloc_debug_enable; -#endif extern struct kmem_cache * kmalloc_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1]; @@ -525,17 +518,6 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) if (!index) return ZERO_SIZE_PTR; -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) - /* Kui.Zhang@tech.kernel.mm, 2020-02-13, try to kmalloc from kmalloc_debug - * caches fisrt. - */ - if (unlikely(kmalloc_debug_enable)) { - struct kmem_cache *s; - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[kmalloc_type(flags)][index]); - if (s) - return kmem_cache_alloc_trace(s, flags, size); - } -#endif return kmem_cache_alloc_trace( kmalloc_caches[kmalloc_type(flags)][index], diff --git a/include/linux/swap.h b/include/linux/swap.h index a972824f546b..440af261ba38 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -14,10 +14,6 @@ #include #include -#if defined(CONFIG_NANDSWAP) -#include <../drivers/soc/oplus/oplus_nandswap/nandswap.h> -#define SWAP_NANDSWAP_PRIO 2020 /* just a magic number */ -#endif struct notifier_block; @@ -177,12 +173,7 @@ enum { SWP_PAGE_DISCARD = (1 << 9), /* freed swap page-cluster discards */ SWP_STABLE_WRITES = (1 << 10), /* no overwrite PG_writeback pages */ /* add others here before... */ -#if defined(CONFIG_NANDSWAP) - SWP_NANDSWAP = (1 << 11), /* mark the device used for nandswap */ - SWP_SCANNING = (1 << 12), /* refcount in scan_swap_map */ -#else SWP_SCANNING = (1 << 11), /* refcount in scan_swap_map */ -#endif }; #define SWAP_CLUSTER_MAX 32UL @@ -454,9 +445,6 @@ extern atomic_long_t nr_swap_pages; extern long total_swap_pages; extern atomic_t nr_rotate_swap; extern bool has_usable_swap(void); -#if defined(CONFIG_NANDSWAP) -extern struct swap_info_struct *nandswap_si; -#endif static inline bool swap_use_vma_readahead(void) { @@ -466,22 +454,11 @@ static inline bool swap_use_vma_readahead(void) /* Swap 50% full? Release swapcache more aggressively.. */ static inline bool vm_swap_full(void) { -#if defined(CONFIG_NANDSWAP) - if (nandswap_si) - return (atomic_long_read(&nr_swap_pages) - - (nandswap_si->pages - nandswap_si->inuse_pages)) * 2 - < (total_swap_pages - nandswap_si->pages); -#endif return atomic_long_read(&nr_swap_pages) * 2 < total_swap_pages; } static inline long get_nr_swap_pages(void) { -#if defined(CONFIG_NANDSWAP) - if (nandswap_si) - return atomic_long_read(&nr_swap_pages) - - (nandswap_si->pages - nandswap_si->inuse_pages); -#endif return atomic_long_read(&nr_swap_pages); } diff --git a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h index 4f52ae4329bf..709ec6c52de9 100755 --- a/include/linux/task_io_accounting_ops.h +++ b/include/linux/task_io_accounting_ops.h @@ -6,17 +6,11 @@ #define __TASK_IO_ACCOUNTING_OPS_INCLUDED #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ #ifdef CONFIG_TASK_IO_ACCOUNTING static inline void task_io_account_read(size_t bytes) { current->ioac.read_bytes += bytes; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_record_task_io(current, bytes, false); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } /* @@ -31,9 +25,6 @@ static inline unsigned long task_io_get_inblock(const struct task_struct *p) static inline void task_io_account_write(size_t bytes) { current->ioac.write_bytes += bytes; -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_record_task_io(current, bytes, true); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } diff --git a/include/linux/task_sched_info.h b/include/linux/task_sched_info.h deleted file mode 100755 index 27cae2952eb9..000000000000 --- a/include/linux/task_sched_info.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _OPLUS_TASK_SCHED_INFO_H -#define _OPLUS_TASK_SCHED_INFO_H - -#include - -#define sched_err(fmt, ...) \ - printk(KERN_ERR "[SCHED_INFO_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -enum { - task_sched_info_running = 0, - task_sched_info_runnable, - task_sched_info_IO, - task_sched_info_D, - task_sched_info_S, - task_sched_info_freq, - task_sched_info_freq_limit, - task_sched_info_isolate, - task_sched_info_backtrace, -}; - -enum { - other_runnable = 1, - running_runnable, -}; - -enum { - cpu_unisolate = 0, - cpu_isolate, -}; - -struct task_sched_info { - u64 sched_info_one; - u64 sched_info_two; -}; - -extern void update_task_sched_info(struct task_struct *p, u64 delay, int type, int cpu); -extern void update_freq_info(struct cpufreq_policy *policy); -extern void update_freq_limit_info(struct cpufreq_policy *policy); -extern void update_cpu_isolate_info(int cpu, u64 type); -extern void update_wake_tid(struct task_struct *p, struct task_struct *cur, unsigned int type); -extern void update_running_start_time(struct task_struct *prev, struct task_struct *next); -extern void sched_action_trig(void); -extern void get_target_thread_pid(struct task_struct *p); - -extern bool ctp_send_message; - -#endif /* _OPLUS_TASK_SCHED_INFO_H */ diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index a058c2cda1be..88ee26a1ce71 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -39,10 +39,6 @@ struct vm_struct { unsigned int nr_pages; phys_addr_t phys_addr; const void *caller; -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_VMALLOC_DEBUG) - /* Kui.Zhang@tech.kernel.mm, 2020-02-13, record the stack hash. */ - unsigned int hash; -#endif }; struct vmap_area { diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 0f4805e20cfd..13757cbd497a 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -474,11 +474,7 @@ extern unsigned int work_busy(struct work_struct *work); extern __printf(1, 2) void set_worker_desc(const char *fmt, ...); extern void print_worker_info(const char *log_lvl, struct task_struct *task); extern void show_workqueue_state(void); -#ifdef CONFIG_OPLUS_FEATURE_MIDAS -extern void get_worker_info(struct task_struct *task, char *buf); -#else static inline void get_worker_info(struct task_struct *task, char *buf) { } -#endif /** * queue_work - queue work on a workqueue * @wq: workqueue to use diff --git a/include/net/oplus/oplus_wfd_wlan.h b/include/net/oplus/oplus_wfd_wlan.h deleted file mode 100755 index 2ea21f9ade65..000000000000 --- a/include/net/oplus/oplus_wfd_wlan.h +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************************************************ -** File: - oplus_wfd_wlan.h -** OPLUS_EDIT -** Copyright (C), 2008-2020, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** 1. oplus_wfd_wlan.h -** -** Version: 1.0 -** Date : 2020-08-11 -** Author: XiaZijian@CONNECTIVITY.WIFI.P2P.26106 -** TAG : OPLUS_FEATURE_WIFI_OPLUSWFD -** -** ---------------------Revision History: --------------------- -** -** --------------------------------------------------------------- -** XiaZijian@CONNECTIVITY.WIFI.P2P.26106 2020/08/11 1.0 build this module -** -************************************************************************************/ - -#ifndef _OPLUS_WFD_WLAN_H -#define _OPLUS_WFD_WLAN_H - -#include - -struct oplus_wfd_wlan_ops_t { - void (*remove_he_ie_from_probe_request)(int remove); - int (*get_dbs_capacity)(void); - int (*get_phy_capacity)(int band); - void (*get_supported_channels)(int band, int* len, int* freqs, int max_num); - void (*get_avoid_channels)(int* len, int* freqs, int max_num); -}; - -extern void register_oplus_wfd_wlan_ops(struct oplus_wfd_wlan_ops_t *ops); -#endif diff --git a/include/net/oplus_nwpower.h b/include/net/oplus_nwpower.h deleted file mode 100755 index aba6281b3b89..000000000000 --- a/include/net/oplus_nwpower.h +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/**************************************************************** -** ------------------ Revision History:------------------------ -** -** Asiga 2019/07/31 1.0 build this module -****************************************************************/ -#ifndef __OPLUS_NWPOWER_H_ -#define __OPLUS_NWPOWER_H_ - -#include -#include - -#define OPLUS_TCP_TYPE_V4 1 -#define OPLUS_TCP_TYPE_V6 2 -#define OPLUS_NET_OUTPUT 0 -#define OPLUS_NET_INPUT 1 - -#define OPLUS_NW_WAKEUP_SUM 8 -#define OPLUS_NW_MPSS 0 -#define OPLUS_NW_QRTR 1 -#define OPLUS_NW_MD 2 -#define OPLUS_NW_WIFI 3 -#define OPLUS_NW_TCP_IN 4 -#define OPLUS_NW_TCP_OUT 5 -#define OPLUS_NW_TCP_RE_IN 6 -#define OPLUS_NW_TCP_RE_OUT 7 - -extern void oplus_match_modem_wakeup(void); -extern void oplus_match_wlan_wakeup(void); - -extern void oplus_match_qrtr_service_port(int type, int id, int port); -extern void oplus_match_qrtr_wakeup(int src_node, int src_port, int dst_port, unsigned int arg1, unsigned int arg2); -extern void oplus_update_qrtr_flag(int val); - -extern void oplus_match_ipa_ip_wakeup(int type, struct sk_buff *skb); -extern void oplus_match_ipa_tcp_wakeup(int type, struct sock *sk); -extern void oplus_ipa_schedule_work(void); - -extern void oplus_match_tcp_output(struct sock *sk); - -extern void oplus_match_tcp_input_retrans(struct sock *sk); -extern void oplus_match_tcp_output_retrans(struct sock *sk); - -extern bool oplus_check_socket_in_blacklist(int is_input, struct socket *sock); - -#endif /* __OPLUS_NWPOWER_H_ */ diff --git a/include/net/sock.h b/include/net/sock.h index 0c3a0db5cc8c..034388169385 100755 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -185,11 +185,6 @@ struct sock_common { struct proto *skc_prot; possible_net_t skc_net; - //#ifdef OPLUS_FEATURE_NWPOWER - u32 skc_oplus_pid; - u64 skc_oplus_last_rcv_stamp[2];//index 0 = last, index 1 = now - u64 skc_oplus_last_send_stamp[2];//index 0 = last, index 1 = now - //#endif /* OPLUS_FEATURE_NWPOWER */ #if IS_ENABLED(CONFIG_IPV6) struct in6_addr skc_v6_daddr; struct in6_addr skc_v6_rcv_saddr; @@ -356,11 +351,6 @@ struct sock { #define sk_incoming_cpu __sk_common.skc_incoming_cpu #define sk_flags __sk_common.skc_flags #define sk_rxhash __sk_common.skc_rxhash -//#ifdef OPLUS_FEATURE_NWPOWER -#define sk_oplus_pid __sk_common.skc_oplus_pid -#define oplus_last_rcv_stamp __sk_common.skc_oplus_last_rcv_stamp -#define oplus_last_send_stamp __sk_common.skc_oplus_last_send_stamp -//#endif /* OPLUS_FEATURE_NWPOWER */ socket_lock_t sk_lock; atomic_t sk_drops; @@ -1846,12 +1836,6 @@ static inline void sk_dst_confirm(struct sock *sk) static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n) { - #ifdef OPLUS_BUG_STABILITY - //WangWei@CONNECTIVITY.WIFI.NETWORK.1357567, 2018/04/27. - //Remove for [1357567],some AP doesn't send arp when it needs to send data to DUT - //We remove this code to send arp more frequently to notify our mac to AP - return; - #endif /* OPLUS_BUG_STABILITY */ if (skb_get_dst_pending_confirm(skb)) { struct sock *sk = skb->sk; unsigned long now = jiffies; diff --git a/include/soc/oplus/boot_mode.h b/include/soc/oplus/boot_mode.h deleted file mode 100755 index 8dbd16afc7a2..000000000000 --- a/include/soc/oplus/boot_mode.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _OPLUS_BOOT_H -#define _OPLUS_BOOT_H -enum{ - MSM_BOOT_MODE__NORMAL, - MSM_BOOT_MODE__FASTBOOT, - MSM_BOOT_MODE__RECOVERY, - MSM_BOOT_MODE__FACTORY, - MSM_BOOT_MODE__RF, - MSM_BOOT_MODE__WLAN, - MSM_BOOT_MODE__MOS, - MSM_BOOT_MODE__CHARGE, - MSM_BOOT_MODE__SILENCE, - MSM_BOOT_MODE__SAU, - MSM_BOOT_MODE__AGING = 998, - MSM_BOOT_MODE__SAFE = 999, -}; - -extern int get_boot_mode(void); -#ifdef OPLUS_BUG_STABILITY -/*add for charge*/ -extern bool qpnp_is_power_off_charging(void); -#endif -#ifdef OPLUS_BUG_STABILITY -/*add for detect charger when reboot */ -extern bool qpnp_is_charger_reboot(void); -#endif /*OPLUS_BUG_STABILITY*/ -#endif /*_OPLUS_BOOT_H*/ - -#ifdef OPLUS_BUG_STABILITY -/*Add for kernel monitor whole bootup*/ -#ifdef PHOENIX_PROJECT -extern bool op_is_monitorable_boot(void); -#endif -#endif - diff --git a/include/soc/oplus/healthinfo.h b/include/soc/oplus/healthinfo.h deleted file mode 100644 index 2740faa49216..000000000000 --- a/include/soc/oplus/healthinfo.h +++ /dev/null @@ -1,138 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _HEALTHINFO_H_ -#define _HEALTHINFO_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ohm_err(fmt, ...) \ - printk(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug(fmt, ...) \ - printk(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug_deferred(fmt, ...) \ - printk_deferred(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_err_deferred(fmt, ...) \ - printk_deferred(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -#define OHM_FLASH_TYPE_EMC 1 -#define OHM_FLASH_TYPE_UFS 2 -#define SA_CGROUP_FOREGROUND (2) -#define SA_CGROUP_BACKGROUND (3) -#define OHM_SCHED_TYPE_MAX 12 - -enum { - TYPE_TOPAPP, - TYPE_UNTOPAPP, - TYPE_ALL, - TYPE_DEFAULT, -}; -enum { - IN_THREAD_TODO_LIST, - IN_PROC_TODO_LIST, - IN_ALL, - IN_DEFAULT, -}; - -struct oplus_binder_proc_status{ - bool ctrl; - int warning; - int warning_cg_bg; - int warning_cg_fg; - int trans2proc[TYPE_DEFAULT][IN_DEFAULT]; - char comm[TASK_COMM_LEN]; -}; - -enum { - /* SCHED_STATS 0 -11 */ - OHM_SCHED_IOWAIT = 0, - OHM_SCHED_SCHEDLATENCY, - OHM_SCHED_FSYNC, - OHM_SCHED_EMMCIO, - OHM_SCHED_DSTATE, - OHM_SCHED_TOTAL, - /* OTHER_TYPE 12 - */ - OHM_CPU_LOAD_CUR = OHM_SCHED_TYPE_MAX, - OHM_MEM_MON, - OHM_IOPANIC_MON, - OHM_SVM_MON, - OHM_RLIMIT_MON, - OHM_ION_MON, - OHM_MEM_VMA_ALLOC_ERR, - OHM_TYPE_TOTAL -}; - -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -struct ob_struct{ - struct binder_proc *ob_proc; - struct list_head ob_list; - pid_t pid; - u64 ob_check_ts; - bool init; -}; - -struct binder_proc_status{ - u64 warning; - u64 warning_cg_bg; - u64 async_mem_over_high; - u64 async_mem_over_low; - u64 sync_mem_over_high; - u64 sync_mem_over_low; -}; -#endif - -struct sched_stat_common { - u64 max_ms; - u64 high_cnt; - u64 low_cnt; - u64 total_ms; - u64 total_cnt; -}; - -struct sched_stat_para { - bool ctrl; - bool logon; - bool trig; - int low_thresh_ms; - int high_thresh_ms; - u64 delta_ms; - struct sched_stat_common all; - struct sched_stat_common fg; - struct sched_stat_common ux; -}; - -struct alloc_wait_para { - u64 total_alloc_wait_max_order; - u64 fg_alloc_wait_max_order; - u64 ux_alloc_wait_max_order; - struct sched_stat_common total_alloc_wait; - struct sched_stat_common fg_alloc_wait; - struct sched_stat_common ux_alloc_wait; -}; - -struct ion_wait_para { - struct sched_stat_common ux_ion_wait; - struct sched_stat_common fg_ion_wait; - struct sched_stat_common total_ion_wait; -}; - -extern void ohm_schedstats_record(int sched_type, struct task_struct *task, u64 delta_ms); -extern int ohm_get_cur_cpuload(bool ctrl); -extern void ohm_action_trig_with_msg(int type, char *msg); -extern struct oplus_binder_proc_status system_server_proc; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -extern struct binder_proc_status system_server_proc_status; -#endif -#endif /* _HEALTHINFO_H_*/ - diff --git a/include/soc/oplus/lowmem_dbg.h b/include/soc/oplus/lowmem_dbg.h deleted file mode 100644 index fd07654302b2..000000000000 --- a/include/soc/oplus/lowmem_dbg.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef __LOWMEM_DBG_H -#define __LOWMEM_DBG_H -#include -#include - -void oplus_lowmem_dbg(bool critical); - -#ifndef CONFIG_MTK_ION -inline int oplus_is_dma_buf_file(struct file *file); -#endif /* CONFIG_MTK_ION */ -#ifdef CONFIG_KSWAPD_DEBUG_STATISTICS -int kswapd_debug_init(struct proc_dir_entry *parent); -#endif - -#endif /* __LOWMEM_DBG_H */ diff --git a/include/soc/oplus/system/boot_mode.h b/include/soc/oplus/system/boot_mode.h deleted file mode 100755 index 6643137e566e..000000000000 --- a/include/soc/oplus/system/boot_mode.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _OPLUS_BOOT_H -#define _OPLUS_BOOT_H -enum { - MSM_BOOT_MODE__NORMAL, - MSM_BOOT_MODE__FASTBOOT, - MSM_BOOT_MODE__RECOVERY, - MSM_BOOT_MODE__FACTORY, - MSM_BOOT_MODE__RF, - MSM_BOOT_MODE__WLAN, - MSM_BOOT_MODE__MOS, - MSM_BOOT_MODE__CHARGE, - MSM_BOOT_MODE__SILENCE, - MSM_BOOT_MODE__SAU, - MSM_BOOT_MODE__AGING = 998, - MSM_BOOT_MODE__SAFE = 999, -}; - -extern int get_boot_mode(void); -#ifdef OPLUS_BUG_STABILITY -/*add for charge*/ -extern bool qpnp_is_power_off_charging(void); -#endif -#ifdef OPLUS_BUG_STABILITY -/*add for detect charger when reboot */ -extern bool qpnp_is_charger_reboot(void); -#endif /*OPLUS_BUG_STABILITY*/ -#endif /*_OPLUS_BOOT_H*/ - -#ifdef OPLUS_BUG_STABILITY -/*Add for kernel monitor whole bootup*/ -#ifdef PHOENIX_PROJECT -extern bool op_is_monitorable_boot(void); -#endif -#endif /*_OPLUS_BOOT_H*/ - diff --git a/include/soc/oplus/system/device_info.h b/include/soc/oplus/system/device_info.h deleted file mode 100755 index 8d6fec5eb2e9..000000000000 --- a/include/soc/oplus/system/device_info.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _DEVICE_INFO_H -#define _DEVICE_INFO_H - -#ifdef CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO -void save_dump_reason_to_device_info(char *buf); -#else -inline void save_dump_reason_to_device_info(char *reason) {} -#endif - -#endif /*_DEVICE_INFO_H*/ diff --git a/include/soc/oplus/system/dump_reason.h b/include/soc/oplus/system/dump_reason.h deleted file mode 100755 index c27d70c407ee..000000000000 --- a/include/soc/oplus/system/dump_reason.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _DUMP_REASON_H -#define _DUMP_REASON_H - -#ifdef CONFIG_OPLUS_FEATURE_DUMP_REASON - -#define SMEM_DUMP_INFO 129 -#define DUMP_REASON_SIZE 256 - -struct dump_info { - char dump_reason[DUMP_REASON_SIZE]; /*dump reason*/ -}; - -extern char *parse_function_builtin_return_address(unsigned long - function_address); -extern void save_dump_reason_to_smem(char *info, char *function_name); -#else -static char *parse_function_builtin_return_address(unsigned long - function_address) {} -static void save_dump_reason_to_smem(char *info, char *function_name) {} -#endif - -#endif /*_DUMP_REASON_H*/ diff --git a/include/soc/oplus/system/hung_task_enhance.h b/include/soc/oplus/system/hung_task_enhance.h deleted file mode 100755 index 573bc370330b..000000000000 --- a/include/soc/oplus/system/hung_task_enhance.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __HUNG_TASK_ENHANCE_H -#define __HUNG_TASK_ENHANCE_H -#include -#include -#include -#include - - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* format: task_name,reason. e.g. system_server,uninterruptible for 60 secs */ -extern char sysctl_hung_task_kill[]; -/* Foreground background optimization,change max io count */ -extern int sysctl_hung_task_maxiowait_count; -static int five = 5; -#endif - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) -void io_check_hung_detection(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic); -void io_block_panic(unsigned int *iowait_count, - unsigned int sys_mamxiowait_count); -#else -void io_check_hung_detection(struct task_struct *t, unsigned long timeout, - unsigned int *iowait_count, bool *show_lock, bool *call_panic) {} -static void io_block_panic(unsigned int *iowait_count, - unsigned int sys_mamxiowait_count) {} -#endif - -#endif/*__HUNG_TASK_ENHANCE_H*/ diff --git a/include/soc/oplus/system/kernel_fb.h b/include/soc/oplus/system/kernel_fb.h deleted file mode 100755 index d686ba7b5917..000000000000 --- a/include/soc/oplus/system/kernel_fb.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************** -SPDX-License-Identifier: GPL-2.0-only - * Copyright (C) 2018-2020 Oplus. All rights reserved. -** File : kernel_fb.h -** Description : BSP kevent fb data -** Version : 1.0 -******************************************************************/ - -#ifndef __KERNEL_FEEDBACK_H -#define __KERNEL_FEEDBACK_H - -typedef enum { - FB_STABILITY = 0, - FB_FS, - FB_STORAGE, - FB_SENSOR, - FB_BOOT, - FB_MAX_TYPE = FB_BOOT, -} fb_tag; - -#define FB_STABILITY_ID_CRASH "202007272030" -#define FB_SENSOR_ID_CRASH "10004" -#define FB_SENSOR_ID_QMI "202007272041" - -struct kernel_packet_info { - int type; /* 0:root,1:only string,other number represent other type */ - char log_tag[32]; /* logTag */ - char event_id[20]; /*eventID */ - size_t payload_length; /* Length of packet data */ - unsigned char payload[0]; /* Optional packet data */ -} __attribute__((packed)); - -int fb_kevent_send_to_user(struct kernel_packet_info *userinfo); -/*int kevent_send_to_user(struct kernel_packet_info *userinfo);*/ -int oplus_kevent_fb(fb_tag tag_id, const char *event_id, - unsigned char *payload); -int oplus_kevent_fb_str(fb_tag tag_id, const char *event_id, - unsigned char *str); -#endif /*__KERNEL_FEEDBACK_H*/ diff --git a/include/soc/oplus/system/oplus_brightscreen_check.h b/include/soc/oplus/system/oplus_brightscreen_check.h deleted file mode 100755 index 672e31ab31cc..000000000000 --- a/include/soc/oplus/system/oplus_brightscreen_check.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * - * yixue.ge - * - */ -#ifndef _OPLUS_BRIGHTSCREEN_CHECK_H_ -#define _OPLUS_BRIGHTSCREEN_CHECK_H_ - -int bright_screen_timer_restart(void); - -#endif /*_OPLUS_BRIGHTSCREEN_CHECK_H_*/ diff --git a/include/soc/oplus/system/oplus_bscheck.h b/include/soc/oplus/system/oplus_bscheck.h deleted file mode 100755 index 002764351f37..000000000000 --- a/include/soc/oplus/system/oplus_bscheck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * - * yixue.ge - * - */ -#ifndef _OPLUS_BS_CHECK_H_ -#define _OPLUS_BS_CHECK_H_ - -int black_screen_timer_restart(void); - -#endif /*_OPLUS_BS_CHECK_H_*/ diff --git a/include/soc/oplus/system/oplus_mm_kevent_fb.h b/include/soc/oplus/system/oplus_mm_kevent_fb.h deleted file mode 100755 index 6204cc0dac2e..000000000000 --- a/include/soc/oplus/system/oplus_mm_kevent_fb.h +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************** -** Copyright (C), 2018, OPLUS Mobile Comm Corp., Ltd -** File : oplus_mm_kevent_fb.h -** Description : MM kevent fb data -** Version : 1.0 -** Date : 2018/12/03 -** -** ------------------------------- Revision History: ----------- -** -** Guo.Ling 2018/12/03 1.0 Build this moudle -** LiPing-M 2019/01/29 1.1 Add SMMU for QCOM -******************************************************************/ -#ifndef _OPLUS_MM_KEVENT_FB_ -#define _OPLUS_MM_KEVENT_FB_ - -#define MM_KEVENT_MAX_PAYLOAD_SIZE 256 - -enum { - MM_FB_KEY_RATELIMIT_NONE = 0, - MM_FB_KEY_RATELIMIT_1MIN = 60 * 1000, - MM_FB_KEY_RATELIMIT_5MIN = 60 * 5 * 1000, - MM_FB_KEY_RATELIMIT_30MIN = 60 * 30 * 1000, - MM_FB_KEY_RATELIMIT_1H = MM_FB_KEY_RATELIMIT_30MIN * 2, - MM_FB_KEY_RATELIMIT_1DAY = MM_FB_KEY_RATELIMIT_1H * 24, -}; - -#define OPLUS_FB_ADSP_CRASH_RATELIMIT (60 * 5 * 1000) /*ms, for mtk*/ - -enum OPLUS_MM_DIRVER_FB_EVENT_MODULE { - OPLUS_MM_DIRVER_FB_EVENT_DISPLAY = 0, - OPLUS_MM_DIRVER_FB_EVENT_AUDIO -}; - -/*------- multimedia bigdata feedback event id, start ------------ */ -#define OPLUS_AUDIO_EVENTID_ADSP_CRASH (10001) -#define OPLUS_AUDIO_EVENTID_HEADSET_DET (10009) -#define OPLUS_AUDIO_EVENTID_ADSP_RECOVERY_FAIL (10045) - -#define OPLUS_DISPLAY_EVENTID_DRIVER_ERR (12002) - -#define OPLUS_DISPLAY_EVENTID_GPU_FAULT (12005) - -/*this id just for test or debug */ -#define OPLUS_MM_EVENTID_TEST_OR_DEBUG (30000) -/*------- multimedia bigdata feedback event id, end ------------*/ - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -int upload_mm_fb_kevent_to_atlas_limit(unsigned int event_id, unsigned char *payload, int limit_ms); - -int upload_mm_fb_kevent_limit(enum OPLUS_MM_DIRVER_FB_EVENT_MODULE module, unsigned int event_id, - const char *name, int rate_limit_ms, char *payload); - -#define mm_fb_kevent(m, id, name, rate_limit_ms, fmt, ...) \ - do { \ - char kv_data[MM_KEVENT_MAX_PAYLOAD_SIZE] = ""; \ - scnprintf(kv_data, sizeof(kv_data), fmt, ##__VA_ARGS__); \ - upload_mm_fb_kevent_limit(m, id, name, rate_limit_ms, kv_data); \ - } while (0) - -#define mm_fb_display_kevent(name, rate_limit_ms, fmt, ...) \ - mm_fb_kevent(OPLUS_MM_DIRVER_FB_EVENT_DISPLAY, OPLUS_DISPLAY_EVENTID_DRIVER_ERR, name, rate_limit_ms, fmt, ##__VA_ARGS__) - -#define mm_fb_display_kevent_named(rate_limit_ms, fmt, ...) \ - do { \ - char name[MM_KEVENT_MAX_PAYLOAD_SIZE]; \ - scnprintf(name, sizeof(name), "%s:%d", __func__, __LINE__); \ - mm_fb_display_kevent(name, rate_limit_ms, fmt, ##__VA_ARGS__); \ - } while (0) - -#define mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ...) \ - mm_fb_kevent(OPLUS_MM_DIRVER_FB_EVENT_AUDIO, event_id, name, rate_limit_ms, fmt, ##__VA_ARGS__) - -#define mm_fb_audio_kevent_named(event_id, rate_limit_ms, fmt, ...) \ - do { \ - char name[MM_KEVENT_MAX_PAYLOAD_SIZE]; \ - scnprintf(name, sizeof(name), "%s:%d", __func__, __LINE__); \ - mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ##__VA_ARGS__); \ - } while (0) - -int mm_fb_kevent_init(void); -void mm_fb_kevent_deinit(void); - -#else /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ -#define upload_mm_fb_kevent_to_atlas_limit(event_id, payload, limit_ms) (0) -#define mm_fb_kevent(m, name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_display_kevent(name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_display_kevent_named(rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_audio_kevent(event_id, name, rate_limit_ms, fmt, ...) do {} while (0) -#define mm_fb_audio_kevent_named(event_id, rate_limit_ms, fmt, ...) do {} while (0) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - -#endif /* _OPLUS_MM_KEVENT_FB_ */ - diff --git a/include/soc/oplus/system/oplus_signal.h b/include/soc/oplus/system/oplus_signal.h deleted file mode 100755 index b8f3f6b20cd1..000000000000 --- a/include/soc/oplus/system/oplus_signal.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __OPLUS_SIGNAL_H -#define __OPLUS_SIGNAL_H - -#include -#include - -/* signal pending, fatal_signal_pending from signal.h*/ -#define PF_KILLING 0x00000001 - - -/* - * wait.h cannot include linux/shed/signal.h , so workaround as hung_long_and_fatal_signal_pending - * return fatal_signal_pending(p) && (p->flags & PF_KILLING) - */ -static inline int hung_long_and_fatal_signal_pending(struct task_struct *p) -{ -#ifdef CONFIG_DETECT_HUNG_TASK - return (unlikely(test_tsk_thread_flag(p, TIF_SIGPENDING))) - && (unlikely(sigismember(&p->pending.signal, SIGKILL))) - && (p->flags & PF_KILLING); -#else - return 0; -#endif -} - -#endif /*__OPLUS_SIGNAL_H*/ diff --git a/include/soc/oplus/system/oplus_sync_time.h b/include/soc/oplus/system/oplus_sync_time.h deleted file mode 100755 index 65c93477ab21..000000000000 --- a/include/soc/oplus/system/oplus_sync_time.h +++ /dev/null @@ -1,74 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, Oplus Mobile Comm Corp., Ltd. -** -** File: oplus_sync_time.h -** Description: Add for Sync App and Kernel time -** -** Version: 1.0 -** Date : 2020/07/22 -** Author: #Zhiming.Chen@ANDROID.DEBUG, 2020/08/06, Add for Sync App and Kernel time -** -** ------------------ Revision History:------------------------ -** -** Zhiming.Chen 2020/08/06 1.0 OPLUS_FEATURE_LOGKIT -****************************************************************/ - -#ifndef _OPLUS_SYNC_TIME_H -#define _OPLUS_SYNC_TIME_H -#include - -static ssize_t watchdog_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - s32 value; - struct timespec ts; - struct rtc_time tm; - - if (count == sizeof(s32)) { - if (copy_from_user(&value, buf, sizeof(s32))) { - return -EFAULT; - } - - } else if (count <= 11) { /* ASCII perhaps? */ - char ascii_value[11]; - unsigned long int ulval; - int ret; - - if (copy_from_user(ascii_value, buf, count)) { - return -EFAULT; - } - - if (count > 10) { - if (ascii_value[10] == '\n') { - ascii_value[10] = '\0'; - - } else { - return -EINVAL; - } - - } else { - ascii_value[count] = '\0'; - } - - ret = kstrtoul(ascii_value, 16, &ulval); - - if (ret) { - pr_debug("%s, 0x%lx, 0x%x\n", ascii_value, ulval, ret); - return -EINVAL; - } - - value = (s32)lower_32_bits(ulval); - - } else { - return -EINVAL; - } - - getnstimeofday(&ts); - rtc_time_to_tm(ts.tv_sec, &tm); - pr_warn("!@WatchDog_%d; %d-%02d-%02d %02d:%02d:%02d.%09lu UTC\n", - value, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); - - return count; -} -#endif /*_OPLUS_SYNC_TIME_H */ diff --git a/include/soc/oplus/system/oppo_process.h b/include/soc/oplus/system/oppo_process.h deleted file mode 100755 index d1fdf5860803..000000000000 --- a/include/soc/oplus/system/oppo_process.h +++ /dev/null @@ -1,103 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, Oplus., All rights reserved. -** File: oplus_process.h -** Description: Add for dump android critical process log -** -** Version: 1.0 -****************************************************************/ - -#ifndef _OPPO_PROCESS_H -#define _OPPO_PROCESS_H - -static inline bool is_zygote_process(struct task_struct *t) -{ - const struct cred *tcred = __task_cred(t); - - struct task_struct *first_child = NULL; - - if (t->children.next - && t->children.next != (struct list_head *)&t->children.next) { - first_child = container_of(t->children.next, struct task_struct, sibling); - } - - if (!strcmp(t->comm, "main") && (tcred->uid.val == 0) && (t->parent != 0 - && !strcmp(t->parent->comm, "init"))) { - return true; - - } else { - return false; - } - - return false; -} - -static inline bool is_systemserver_process(struct task_struct *t) -{ - if (!strcmp(t->comm, "system_server") - || !strncmp(t->group_leader->comm, "Binder:", 7)) { - return true; - - } else { - return false; - } -} - -static inline bool is_key_process(struct task_struct *t) -{ - struct pid *pgrp; - struct task_struct *taskp; - - if (t->pid == t->tgid) { - if (is_systemserver_process(t) || is_zygote_process(t)) { - return true; - } - - } else { - pgrp = task_pgrp(t); - - if (pgrp != NULL) { - taskp = pid_task(pgrp, PIDTYPE_PID); - - if (taskp != NULL && (is_systemserver_process(taskp) - || is_zygote_process(taskp))) { - return true; - } - } - } - - return false; -} - -static inline bool oppo_is_android_core_group(struct pid *pgrp) -{ - struct task_struct *p; - - do_each_pid_task(pgrp, PIDTYPE_PGID, p) { - if ((!strcmp(p->comm, "zygote")) || (!strcmp(p->comm, "main"))) { - printk("oppo_is_android_core_group: find zygote will be hungup, ignore it \n"); - return true; - } - } - while_each_pid_task(pgrp, PIDTYPE_PGID, p); - - return false; -} - -static inline bool is_critial_process(struct task_struct *t) -{ - if (t->group_leader && (!strcmp(t->group_leader->comm, "system_server") - || !strncmp(t->group_leader->comm, "Binder:", 7) - || is_zygote_process(t) || !strcmp(t->group_leader->comm, "surfaceflinger") - || !strcmp(t->group_leader->comm, "servicemanager"))) { - if (t->pid == t->tgid) { - return true; - - } else { - return false; - } - - } else { - return false; - } -} -#endif /*_OPPO_PROCESS_H */ diff --git a/include/soc/oplus/system/proc.h b/include/soc/oplus/system/proc.h deleted file mode 100755 index ce709c5828ac..000000000000 --- a/include/soc/oplus/system/proc.h +++ /dev/null @@ -1,21 +0,0 @@ -/************************************************************ - * Copyright 2017 OPLUS Mobile Comm Corp., Ltd. - * All rights reserved. - * - * Description : disable selinux denied log in MP version - * - * - ** Version: 1 - ** Date created: 2016/01/06 - ** Author: sijiaquan@ANDROID.SELINUX - ** ------------------------------- Revision History: --------------------------------------- - ** - ** sijiaquan 2017/12/12 create this file - ************************************************************/ -#ifndef _SELINUX_PROC_H_ -#define _SELINUX_PROC_H_ - -int is_avc_audit_enable(void); -int init_denied_proc(void); - -#endif /* _SELINUX_PROC_H_ */ diff --git a/include/soc/oplus/system/qcom_minidump_enhance.h b/include/soc/oplus/system/qcom_minidump_enhance.h deleted file mode 100755 index 108a8feaa4a1..000000000000 --- a/include/soc/oplus/system/qcom_minidump_enhance.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef _QCOM_MINIDUMP_CUSTOMIZED_H_ -#define _QCOM_MINIDUMP_CUSTOMIZED_H_ - -#include - -bool is_fulldump_enable(void); -void oplus_switch_fulldump(int on); -void do_restart_early(enum reboot_mode reboot_mode, const char *cmd); -void do_poweroff_early(void); -void dumpcpuregs(struct pt_regs *pt_regs); -void register_cpu_contex(void); - -#endif /* _QCOM_MINIDUMP_CUSTOMIZED_H_ */ - diff --git a/include/soc/oplus/system/qcom_pmicwd.h b/include/soc/oplus/system/qcom_pmicwd.h deleted file mode 100755 index 95ff41628472..000000000000 --- a/include/soc/oplus/system/qcom_pmicwd.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __QCOM_PMICWD_H__ -#define __QCOM_PMICWD_H__ - -#include -#include - -static inline int qpnp_pon_masked_write(struct qpnp_pon *pon, u16 addr, u8 mask, - u8 val) -{ - int rc; - - rc = regmap_update_bits(pon->regmap, addr, mask, val); - - if (rc) - dev_err(pon->dev, "Register write failed, addr=0x%04X, rc=%d\n", - addr, rc); - - return rc; -} - -#endif /*__QCOM_PMICWD_H__*/ diff --git a/include/soc/oplus/system/uboot_utils.h b/include/soc/oplus/system/uboot_utils.h deleted file mode 100755 index 1050945efa5f..000000000000 --- a/include/soc/oplus/system/uboot_utils.h +++ /dev/null @@ -1,163 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#ifndef __OPPO_UBOOT_UTIL__ -#define __OPPO_UBOOT_UTIL__ - -#include -#include - -#define SIZE_128B 0x00000080 -#define SIZE_256B 0x00000100 -#define SIZE_1KB 0x00000400 -#define SIZE_2KB 0x00000800 -#define SIZE_3KB 0x00000C00 -#define SIZE_4KB 0x00001000 -#define SIZE_5KB 0x00001400 -#define SIZE_6KB 0x00001800 -#define SIZE_8KB 0x00002000 -#define SIZE_10KB 0x00002800 -#define SIZE_12KB 0x00003000 -#define SIZE_16KB 0x00004000 -#define SIZE_18KB 0x00004800 -#define SIZE_20KB 0x00005000 -#define SIZE_22KB 0x00005800 -#define SIZE_24KB 0x00006000 -#define SIZE_26KB 0x00006800 -#define SIZE_28KB 0x00007000 -#define SIZE_30KB 0x00007800 -#define SIZE_32KB 0x00008000 -#define SIZE_36KB 0x00009000 -#define SIZE_34KB 0x00008800 -#define SIZE_38KB 0x00009800 -#define SIZE_36KB 0x00009000 -#define SIZE_40KB 0x0000A000 -#define SIZE_42KB 0x0000A800 -#define SIZE_44KB 0x0000B000 -#define SIZE_46KB 0x0000B800 -#define SIZE_48KB 0x0000C000 -#define SIZE_52KB 0x0000D000 -#define SIZE_56KB 0x0000E000 -#define SIZE_60KB 0x0000F000 -#define SIZE_64KB 0x00010000 -#define SIZE_66KB 0x00010800 -#define SIZE_68KB 0x00011000 -#define SIZE_70KB 0x00011800 -#define SIZE_72KB 0x00012000 -#define SIZE_76KB 0x00013000 -#define SIZE_78KB 0x00013800 -#define SIZE_80KB 0x00014000 -#define SIZE_84KB 0x00015000 -#define SIZE_88KB 0x00016000 -#define SIZE_90KB 0x00016800 -#define SIZE_92KB 0x00017000 -#define SIZE_94KB 0x00017800 -#define SIZE_95KB 0x00017C00 -#define SIZE_96KB 0x00018000 -#define SIZE_100KB 0x00019000 -#define SIZE_110KB 0x0001B800 -#define SIZE_120KB 0x0001E000 -#define SIZE_128KB 0x00020000 -#define SIZE_140KB 0x00023000 -#define SIZE_144KB 0x00024000 -#define SIZE_148KB 0x00025000 -#define SIZE_152KB 0x00026000 -#define SIZE_153KB 0x00026400 -#define SIZE_154KB 0x00026800 -#define SIZE_156KB 0x00027000 -#define SIZE_160KB 0x00028000 -#define SIZE_172KB 0x0002B000 -#define SIZE_184KB 0x0002E000 -#define SIZE_192KB 0x00030000 -#define SIZE_204KB 0x00033000 -#define SIZE_212KB 0x00035000 -#define SIZE_216KB 0x00036000 -#define SIZE_232KB 0x0003A000 -#define SIZE_240KB 0x0003C000 -#define SIZE_256KB 0x00040000 -#define SIZE_294KB 0x00049800 -#define SIZE_296KB 0x0004A000 -#define SIZE_298KB 0x0004A800 -#define SIZE_300KB 0x0004B000 -#define SIZE_306KB 0x0004C800 -#define SIZE_310KB 0x0004D800 -#define SIZE_312KB 0x0004E000 -#define SIZE_314KB 0x0004E800 -#define SIZE_316KB 0x0004f000 -#define SIZE_320KB 0x00050000 -#define SIZE_324KB 0x00051000 -#define SIZE_332KB 0x00053000 -#define SIZE_340KB 0x00055000 -#define SIZE_344KB 0x00056000 -#define SIZE_350KB 0x00057800 -#define SIZE_392KB 0x00062000 -#define SIZE_400KB 0x00064000 -#define SIZE_402KB 0x00064800 -#define SIZE_416KB 0x00068000 -#define SIZE_436KB 0x0006D000 -#define SIZE_440KB 0x0006E000 -#define SIZE_448KB 0x00070000 -#define SIZE_450KB 0x00070800 -#define SIZE_454KB 0x00071800 -#define SIZE_456KB 0x00072000 -#define SIZE_458KB 0x00072800 -#define SIZE_460KB 0x00073000 -#define SIZE_466KB 0x00074800 -#define SIZE_470KB 0x00075800 -#define SIZE_478KB 0x00077800 -#define SIZE_482KB 0x00078800 -#define SIZE_486KB 0x00079800 -#define SIZE_490KB 0x0007A800 -#define SIZE_498KB 0x0007C800 -#define SIZE_504KB 0x0007e000 -#define SIZE_506KB 0x0007e800 -#define SIZE_512KB 0x00080000 -#define SIZE_530KB 0x00084800 -#define SIZE_545KB 0x00088400 -#define SIZE_561KB 0x0008C400 -#define SIZE_612KB 0x00099000 -#define SIZE_680KB 0x000AA000 -#define SIZE_712KB 0x000B2000 -#define SIZE_716KB 0x000B3000 -#define SIZE_724KB 0x000B5000 -#define SIZE_1MB 0x00100000 -#define SIZE_1_5_MB 0x00180000 -#define SIZE_2MB 0x00200000 -#define SIZE_6MB 0x00600000 -#define SIZE_16MB 0x01000000 -#define SIZE_17MB 0x01100000 -#define SIZE_68MB 0x04400000 -#define SIZE_72MB 0x04800000 -#define SIZE_80MB 0x05000000 -#define SIZE_150MB 0x09600000 -#define SIZE_1GB 0x40000000 -#define SIZE_1_5GB 0x60000000 -#define SIZE_2GB 0x80000000 - -#define SCL_SBL1_DDR_BASE 0x80700000 -#define SCL_SBL1_DDR_SIZE SIZE_1MB - -#define SCL_SBL1_DDR_BOOT_LOG_BUF_SIZE SIZE_8KB -#define SCL_SBL1_DDR_BOOT_TIME_MARKER_BUF_SIZE SIZE_256B -#define SERIAL_BUFFER_SIZE SIZE_32KB - -static void *uboot_reserved_remap = NULL; -static phys_addr_t uboot_base; -static phys_addr_t uboot_size; - - -#if defined(CONFIG_PRINTK) && defined(CONFIG_OPLUS_FEATURE_UBOOT_LOG) -bool back_kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, - char *buf, size_t size, size_t *len); - -#else -static inline bool back_kmsg_dump_get_buffer(struct kmsg_dumper *dumper, - bool syslog, - char *buf, size_t size, size_t *len) -{ - return false; -} -#endif - -#endif/*__OPPO_UBOOT_UTIL__*/ diff --git a/include/soc/oppo/boot_mode.h b/include/soc/oppo/boot_mode.h deleted file mode 100755 index 527b84dc1500..000000000000 --- a/include/soc/oppo/boot_mode.h +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************************ -** File: - android\kernel\arch\arm\mach-msm\include\mach\oppo_boot.h -** Copyright (C), 2008-2012, OPPO Mobile Comm Corp., Ltd -** -** Description: -** change define of boot_mode here for other place to use it -** Version: 1.0 -** --------------------------- Revision History: -------------------------------- -** -** tong.han@BasicDrv.TP&LCD 11/01/2014 add this file -************************************************************************************/ -#ifndef _OPPO_BOOT_H -#define _OPPO_BOOT_H -#include -//Ke.Li@ROM.Security, KernelEvent, 2019-9-30, remove the "static" flag for kernel kevent -//extern static int get_boot_mode(void); -extern int get_boot_mode(void); -//#endif -//Fuchun.Liao@Mobile.BSP.CHG 2016-01-14 add for charge -extern bool qpnp_is_power_off_charging(void); -//PengNan@SW.BSP add for detect charger when reboot 2016-04-22 -extern bool qpnp_is_charger_reboot(void); -#endif diff --git a/include/soc/oppo/boot_mode_types.h b/include/soc/oppo/boot_mode_types.h deleted file mode 100755 index bcc77790ad95..000000000000 --- a/include/soc/oppo/boot_mode_types.h +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************************ - ** File: - android\kernel\arch\arm\mach-msm\include\mach\oppo_boot.h - ** Copyright (C), 2008-2012, OPPO Mobile Comm Corp., Ltd - ** - ** Description: - ** change define of boot_mode here for other place to use it - ** Version: 1.0 - ** --------------------------- Revision History: -------------------------------- - ** - ** tong.han@BasicDrv.TP&LCD 11/01/2014 add this file - ************************************************************************************/ -#ifndef _OPPO_BOOT_TYPE_H -#define _OPPO_BOOT_TYPE_H -enum{ - MSM_BOOT_MODE__NORMAL, - MSM_BOOT_MODE__FASTBOOT, - MSM_BOOT_MODE__RECOVERY, - MSM_BOOT_MODE__FACTORY, - MSM_BOOT_MODE__RF, - MSM_BOOT_MODE__WLAN, - MSM_BOOT_MODE__MOS, - MSM_BOOT_MODE__CHARGE, - MSM_BOOT_MODE__SILENCE, - MSM_BOOT_MODE__SAU, - MSM_BOOT_MODE__AGING, - MSM_BOOT_MODE__SAFE = 999, - //TODO - MSM_BOOT_MODE__MAX, -}; -#endif diff --git a/include/soc/oppo/healthinfo.h b/include/soc/oppo/healthinfo.h deleted file mode 100644 index 2740faa49216..000000000000 --- a/include/soc/oppo/healthinfo.h +++ /dev/null @@ -1,138 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _HEALTHINFO_H_ -#define _HEALTHINFO_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ohm_err(fmt, ...) \ - printk(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug(fmt, ...) \ - printk(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_debug_deferred(fmt, ...) \ - printk_deferred(KERN_INFO "[OHM_INFO][%s]"fmt, __func__, ##__VA_ARGS__) -#define ohm_err_deferred(fmt, ...) \ - printk_deferred(KERN_ERR "[OHM_ERR][%s]"fmt, __func__, ##__VA_ARGS__) - -#define OHM_FLASH_TYPE_EMC 1 -#define OHM_FLASH_TYPE_UFS 2 -#define SA_CGROUP_FOREGROUND (2) -#define SA_CGROUP_BACKGROUND (3) -#define OHM_SCHED_TYPE_MAX 12 - -enum { - TYPE_TOPAPP, - TYPE_UNTOPAPP, - TYPE_ALL, - TYPE_DEFAULT, -}; -enum { - IN_THREAD_TODO_LIST, - IN_PROC_TODO_LIST, - IN_ALL, - IN_DEFAULT, -}; - -struct oplus_binder_proc_status{ - bool ctrl; - int warning; - int warning_cg_bg; - int warning_cg_fg; - int trans2proc[TYPE_DEFAULT][IN_DEFAULT]; - char comm[TASK_COMM_LEN]; -}; - -enum { - /* SCHED_STATS 0 -11 */ - OHM_SCHED_IOWAIT = 0, - OHM_SCHED_SCHEDLATENCY, - OHM_SCHED_FSYNC, - OHM_SCHED_EMMCIO, - OHM_SCHED_DSTATE, - OHM_SCHED_TOTAL, - /* OTHER_TYPE 12 - */ - OHM_CPU_LOAD_CUR = OHM_SCHED_TYPE_MAX, - OHM_MEM_MON, - OHM_IOPANIC_MON, - OHM_SVM_MON, - OHM_RLIMIT_MON, - OHM_ION_MON, - OHM_MEM_VMA_ALLOC_ERR, - OHM_TYPE_TOTAL -}; - -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -struct ob_struct{ - struct binder_proc *ob_proc; - struct list_head ob_list; - pid_t pid; - u64 ob_check_ts; - bool init; -}; - -struct binder_proc_status{ - u64 warning; - u64 warning_cg_bg; - u64 async_mem_over_high; - u64 async_mem_over_low; - u64 sync_mem_over_high; - u64 sync_mem_over_low; -}; -#endif - -struct sched_stat_common { - u64 max_ms; - u64 high_cnt; - u64 low_cnt; - u64 total_ms; - u64 total_cnt; -}; - -struct sched_stat_para { - bool ctrl; - bool logon; - bool trig; - int low_thresh_ms; - int high_thresh_ms; - u64 delta_ms; - struct sched_stat_common all; - struct sched_stat_common fg; - struct sched_stat_common ux; -}; - -struct alloc_wait_para { - u64 total_alloc_wait_max_order; - u64 fg_alloc_wait_max_order; - u64 ux_alloc_wait_max_order; - struct sched_stat_common total_alloc_wait; - struct sched_stat_common fg_alloc_wait; - struct sched_stat_common ux_alloc_wait; -}; - -struct ion_wait_para { - struct sched_stat_common ux_ion_wait; - struct sched_stat_common fg_ion_wait; - struct sched_stat_common total_ion_wait; -}; - -extern void ohm_schedstats_record(int sched_type, struct task_struct *task, u64 delta_ms); -extern int ohm_get_cur_cpuload(bool ctrl); -extern void ohm_action_trig_with_msg(int type, char *msg); -extern struct oplus_binder_proc_status system_server_proc; -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -extern struct binder_proc_status system_server_proc_status; -#endif -#endif /* _HEALTHINFO_H_*/ - diff --git a/include/soc/oppo/mmkey_log.h b/include/soc/oppo/mmkey_log.h deleted file mode 100755 index 71f24e37f701..000000000000 --- a/include/soc/oppo/mmkey_log.h +++ /dev/null @@ -1,51 +0,0 @@ -/************************************************************************************ -** File: - android\kernel\include\soc\oppo\mmkey_log.h -** Copyright (C), 2008-2015, OPPO Mobile Comm Corp., Ltd -** -** Description: -** oppo key log multimedia issue id header file -** Version: 1.0 -** --------------------------- Revision History: -------------------------------- -** -** John.Xu@PhoneSw.AudioDriver.OppoDebug.CriticalLog, 2016/02/22, Add for critical_log -************************************************************************************/ - -#ifndef MMKEYLOG_H_ -#define MMKEYLOG_H_ - -//MultiMedia issue type range is 200~399, -//mediaser and surfaceflinger use 200~299 -//kernel use 300~399 -enum mmkeylog_issue{ - TYPE_SOUND_CARD_REGISTER_FAIL = 300, - TYPE_ADSP_LOAD_FAIL, - TYPE_SMART_PA_EXCEPTION, - TYPE_NO_DATA_TO_SHOW, - TYPE_KGSL_EXCEPTION, - TYPE_VSYNC_EXCEPTION, - TYPE_ESD_EXCEPTION, - TYPE_GPU_EXCEPTION, - TYPE_IOMMU_ERROR, - TYPE_FENCE_TIMEOUT, - TYPE_BL_EXCEPTION, - TYPE_ADSP_CLK_OPEN_TIMEOUT, - TYPE_HP_PA_EXCEPTION, -}; - -//Yadong.Hu@Prd.Svc.Wifi, 2016/01/04, Add for wifi critical log -enum conkeylog_issue{ - TYPE_SYMBOL_VERSION_DISAGREE = 803, - TYPE_WDI_EXCEPTION, -}; - -//Canjie.Zheng@Swdp.Android.OppoDebug.CriticalLog,2016/06/03,add for critical -//record subSystem crash -enum androidlog_issue{ - TYPE_SUBSYSTEM_RESTART = 1001, -}; - -extern void mm_keylog_write(const char *logmessage, const char *cause, int id); -/* #ifdef OPLUS_FEATURE_MODEM_MINIDUMP */ -extern void mm_keylog_write_modemdump(unsigned int hashId, const char *cause, int id, char *subsys); -/* #endif OPLUS_FEATURE_MODEM_MINIDUMP */ -#endif diff --git a/include/trace/events/power.h b/include/trace/events/power.h index 5f4b2ee8961e..af1324823208 100755 --- a/include/trace/events/power.h +++ b/include/trace/events/power.h @@ -551,56 +551,6 @@ DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request, TP_ARGS(name, type, new_value) ); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -TRACE_EVENT(sugov_next_util_tl, - TP_PROTO(unsigned int cpu, unsigned long util, unsigned long max, - unsigned int target_util), - TP_ARGS(cpu, util, max, target_util), - TP_STRUCT__entry( - __field(unsigned int, cpu) - __field(unsigned long, util) - __field(unsigned long, max) - __field(unsigned int, target_util) - ), - TP_fast_assign( - __entry->cpu = cpu; - __entry->util = util; - __entry->max = max; - __entry->target_util = target_util; - ), - TP_printk("cpu=%u util=%lu max=%lu target_util=%u", - __entry->cpu, - __entry->util, - __entry->max, - __entry->target_util) -); - -TRACE_EVENT(choose_util, - TP_PROTO(unsigned int util, unsigned int prevutil, unsigned int utilmax, - unsigned int utilmin, unsigned int tl), - TP_ARGS(util, prevutil, utilmax, utilmin, tl), - TP_STRUCT__entry( - __field(unsigned int, util) - __field(unsigned int, prevutil) - __field(unsigned int, utilmax) - __field(unsigned int, utilmin) - __field(unsigned int, tl) - ), - TP_fast_assign( - __entry->util = util; - __entry->prevutil = prevutil; - __entry->utilmax = utilmax; - __entry->utilmin = utilmin; - __entry->tl = tl; - ), - TP_printk("util=%u prevutil=%u utilmax=%u utilmin=%u tl=%u", - __entry->util, - __entry->prevutil, - __entry->utilmax, - __entry->utilmin, - __entry->tl) -); -#endif #endif /* _TRACE_POWER_H */ diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 7d9cb3ed130c..e534a96ec677 100755 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -1157,39 +1157,6 @@ TRACE_EVENT_CONDITION(sched_overutilized, __entry->overutilized ? 1 : 0, __entry->cpulist) ); -#ifdef CONFIG_OPLUS_PREFER_SILVER -TRACE_EVENT(sched_cpu_skip, - - TP_PROTO(struct task_struct *p, bool sysctl_prefer_silver, bool is_ux_task, bool check_freq, bool check_task_util, bool check_cpu_util), - - TP_ARGS(p, sysctl_prefer_silver, is_ux_task, check_freq, check_task_util, check_cpu_util), - - TP_STRUCT__entry( - __field(int, pid) - __array(char, comm, TASK_COMM_LEN) - __field(bool, sysctl_prefer_silver) - __field(bool, is_ux_task) - __field(bool, check_freq) - __field(bool, check_task_util) - __field(bool, check_cpu_util) - ), - - TP_fast_assign( - __entry->pid = p ? p->pid : -1; - memcpy(__entry->comm, p ? p->comm:"NULL", TASK_COMM_LEN); - __entry->sysctl_prefer_silver = sysctl_prefer_silver; - __entry->is_ux_task = is_ux_task; - __entry->check_freq = check_freq; - __entry->check_task_util = check_task_util; - __entry->check_cpu_util = check_cpu_util; - ), - - TP_printk("pid=%d comm=%s prefer_silver_enabled=%d is_ux_task=%d check_freq=%d check_task_util=%d check_cpu_util=%d", - __entry->pid, __entry->comm, __entry->sysctl_prefer_silver, - __entry->is_ux_task, __entry->check_freq, - __entry->check_task_util, __entry->check_cpu_util) -); -#endif /* CONFIG_OPLUS_PREFER_SILVER */ /* * Tracepoint for find_best_target diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h index 2814f8a208a0..fd993622d6db 100755 --- a/include/uapi/linux/netlink.h +++ b/include/uapi/linux/netlink.h @@ -32,26 +32,6 @@ #define NETLINK_INET_DIAG NETLINK_SOCK_DIAG -//#ifdef OPLUS_FEATURE_WIFI_CAPCENTER -//XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453, 2020/07/05, Add for Oplus WIFI Cap Center -#define NETLINK_OPLUS_WIFI_CAP_CENTER_SYNC 39 -#define NETLINK_OPLUS_WIFI_CAP_CENTER_ASYNC 40 -//#endif /* OPLUS_FEATURE_WIFI_CAPCENTER */ - -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager -#define NETLINK_OPPO_HANS 29 /* Socket for freezing solution*/ -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ - -//#ifdef OPLUS_FEATURE_NWPOWER -#define NETLINK_OPLUS_NWPOWERSTATE 36 /*OPLUS NW PowerState*/ -//#endif /* OPLUS_FEATURE_NWPOWER */ -//#ifdef OPLUS_FEATURE_THEIA -//Jianping.Zheng@TECH.AD.Stability.Crash, 2020/11/19, Add for theia powerkey check notify -//should match with oppo_theia/include/TheiaKeventThread.h define -#define OPLUS_NETLINK_THEIA_KEVENT 43 -//#endif /* OPLUS_FEATURE_THEIA */ - //#ifdef OPLUS_FEATURE_SECURITY_COMMON #define MAX_LINKS 44 //#endif /*OPLUS_FEATURE_SECURITY_COMMON*/ diff --git a/init/Kconfig b/init/Kconfig index 6885aa0f184a..2092e1774117 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -706,9 +706,6 @@ config NONLINEAR_FREQ_CTL loading tracking/opp calculation will be affected. If unsure, say N. -#ifdef OPLUS_FEATURE_SCHED_ASSIST -source "kernel/sched_assist/Kconfig" -#endif endmenu menu "FAIR Scheuler tunables" diff --git a/init/main.c b/init/main.c index e635cda004b3..6a1945b8c1d0 100644 --- a/init/main.c +++ b/init/main.c @@ -99,10 +99,6 @@ #include #endif -#ifdef OPLUS_FEATURE_PHOENIX -// Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project -#include "../drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h" -#endif static int kernel_init(void *); @@ -603,10 +599,6 @@ asmlinkage __visible void __init start_kernel(void) sort_main_extable(); trap_init(); mm_init(); - #ifdef OPLUS_FEATURE_PHOENIX - if(phx_set_boot_stage) - phx_set_boot_stage(KERNEL_MM_INIT_DONE); - #endif ftrace_init(); @@ -660,12 +652,6 @@ asmlinkage __visible void __init start_kernel(void) WARN(!irqs_disabled(), "Interrupts were enabled early\n"); early_boot_irqs_disabled = false; local_irq_enable(); - #ifdef OPLUS_FEATURE_PHOENIX - // Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project - if(phx_set_boot_stage) { - phx_set_boot_stage(KERNEL_LOCAL_IRQ_ENABLE); - } - #endif kmem_cache_init_late(); @@ -736,11 +722,6 @@ asmlinkage __visible void __init start_kernel(void) cgroup_init(); taskstats_init_early(); delayacct_init(); - #ifdef OPLUS_FEATURE_PHOENIX - if(phx_set_boot_stage) { - phx_set_boot_stage(KERNEL_DELAYACCT_INIT_DONE); - } - #endif check_bugs(); @@ -977,21 +958,10 @@ static void __init do_basic_setup(void) cpuset_init_smp(); shmem_init(); driver_init(); - #ifdef OPLUS_FEATURE_PHOENIX - // Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project - if(phx_set_boot_stage) { - phx_set_boot_stage(KERNEL_DRIVER_INIT_DONE); - } - #endif init_irq_proc(); do_ctors(); usermodehelper_enable(); do_initcalls(); - #ifdef OPLUS_FEATURE_PHOENIX - // Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project - if(phx_set_boot_stage) - phx_set_boot_stage(KERNEL_DO_INITCALLS_DONE); - #endif } static void __init do_pre_smp_initcalls(void) @@ -1084,12 +1054,6 @@ static int __ref kernel_init(void *unused) rcu_end_inkernel_boot(); - #ifdef OPLUS_FEATURE_PHOENIX - // Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project - if(phx_set_boot_stage) { - phx_set_boot_stage(KERNEL_INIT_DONE); - } - #endif #ifdef CONFIG_MTPROF log_boot("Kernel_init_done"); @@ -1160,12 +1124,6 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); - #ifdef OPLUS_FEATURE_PHOENIX - // Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project - if(phx_set_boot_stage) { - phx_set_boot_stage(KERNEL_DO_BASIC_SETUP_DONE); - } - #endif /* Open the /dev/console on the rootfs, this should never fail */ if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) pr_err("Warning: unable to open an initial console.\n"); diff --git a/kernel/Makefile b/kernel/Makefile index d2d40e1d2677..f49af3b65be2 100755 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -21,10 +21,6 @@ obj-y = fork.o exec_domain.o panic.o \ obj-$(CONFIG_MODULES) += kmod.o obj-$(CONFIG_MULTIUSER) += groups.o -ifdef CONFIG_OPLUS_FEATURE_PANIC_FLUSH -obj-y += panic_flush.o -endif - ifdef CONFIG_FUNCTION_TRACER # Do not trace internal ftrace files CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE) @@ -56,10 +52,6 @@ obj-y += irq/ obj-y += rcu/ obj-y += livepatch/ -#ifdef OPLUS_FEATURE_PREFER_SILVER -obj-$(CONFIG_OPLUS_PREFER_SILVER) += prefer_silver/ -#endif /* OPLUS_FEATURE_PREFER SILVER */ - obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o obj-$(CONFIG_FREEZER) += freezer.o obj-$(CONFIG_PROFILING) += profile.o @@ -131,10 +123,6 @@ obj-$(CONFIG_TORTURE_TEST) += torture.o obj-$(CONFIG_HAS_IOMEM) += memremap.o -#ifdef OPLUS_FEATURE_SCHED_ASSIST -obj-y += sched_assist/ -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - $(obj)/configs.o: $(obj)/config_data.h targets += config_data.gz diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 5d2716e6940a..a1fd71d25b2a 100755 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -19,9 +19,6 @@ #include #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* * pidlists linger the following amount before being destroyed. The goal * is avoiding frequent destruction in the middle of consecutive read calls @@ -557,10 +554,6 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of, goto out_finish; ret = cgroup_attach_task(cgrp, task, threadgroup); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (!ret) - cgroup_set_sched_assist_boost_task(task); -#endif #ifdef CONFIG_MTK_TASK_TURBO if (!ret) cgroup_set_turbo_task(task); diff --git a/kernel/exit.c b/kernel/exit.c index 8efebda8fc3e..ac89200871c1 100755 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -68,11 +68,6 @@ #include #include -#ifdef OPLUS_BUG_STABILITY -//Tian.Pan@ANDROID.STABILITY.NA.2020/07/22.add for dump android critical process log -#include -#endif - #ifdef CONFIG_OPLUS_FEATURE_UID_PERF extern void uid_check_out_pevent(struct task_struct *task); #endif @@ -87,9 +82,6 @@ static void __unhash_process(struct task_struct *p, bool group_dead) detach_pid(p, PIDTYPE_SID); list_del_rcu(&p->tasks); -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_ION) && defined(CONFIG_DUMP_TASKS_MEM) - list_del_rcu(&p->user_tasks); -#endif list_del_init(&p->sibling); __this_cpu_dec(process_counts); } @@ -408,13 +400,6 @@ kill_orphaned_pgrp(struct task_struct *tsk, struct task_struct *parent) task_session(parent) == task_session(tsk) && will_become_orphaned_pgrp(pgrp, ignored_task) && has_stopped_jobs(pgrp)) { -#ifdef OPLUS_BUG_STABILITY -//Shu.Liu@ANDROID.STABILITY.1052210, 2014/01/10, Add for clean backstage - if (oppo_is_android_core_group(pgrp)) { - printk("kill_orphaned_pgrp: find android core process will be hungup, ignored it, only hungup itself:%s:%d , current=%d \n",tsk->comm,tsk->pid,current->pid); - return; - } -#endif /*OPLUS_BUG_STABILITY*/ __kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp); __kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp); } @@ -562,10 +547,6 @@ static void exit_mm(void) enter_lazy_tlb(mm, current); task_unlock(current); mm_update_next_owner(mm); -#if defined(OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY) && defined(CONFIG_OPLUS_HEALTHINFO) && defined(CONFIG_VIRTUAL_RESERVE_MEMORY) - //Trigger and upload the event. - trigger_svm_oom_event(mm, false, false); -#endif mmput(mm); if (test_thread_flag(TIF_MEMDIE)) exit_oom_victim(); @@ -794,12 +775,6 @@ void __noreturn do_exit(long code) { struct task_struct *tsk = current; int group_dead; -#ifdef OPLUS_BUG_STABILITY -//Haoran.Zhang@ANDROID.STABILITY.1052210, 2016/05/24, Add for debug critical svc crash - if (is_critial_process(tsk)) { - printk("critical svc %d:%s exit with %ld !\n", tsk->pid, tsk->comm,code); - } -#endif /*OPLUS_BUG_STABILITY*/ /* * We can get here from a kernel oops, sometimes with preemption off. diff --git a/kernel/fork.c b/kernel/fork.c index 2bf8148c8ff7..9f14ea61e49c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -106,17 +106,11 @@ #define CREATE_TRACE_POINTS #include -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #include #ifdef CONFIG_MTK_TASK_TURBO #include #endif -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) -#include -#endif /* OPLUS_FEATURE_HEALTHINFO */ /* * Minimum number of threads to boot the kernel @@ -128,9 +122,6 @@ */ #define MAX_THREADS FUTEX_TID_MASK -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_ION) && defined(CONFIG_DUMP_TASKS_MEM) -extern void update_user_tasklist(struct task_struct *tsk); -#endif /* * Protected counters by write_lock_irq(&tasklist_lock) @@ -1917,17 +1908,6 @@ static __latent_entropy struct task_struct *copy_process( #ifdef CONFIG_MTK_TASK_TURBO init_turbo_attr(p, current); #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - init_task_ux_info(p); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - p->jank_trace = 0; - memset(&p->jank_info, 0, sizeof(struct jank_monitor_info)); -#endif /* OPLUS_FEATURE_HEALTHINFO */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - p->wake_tid = 0; - p->running_start_time = 0; -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ /* Perform scheduler related setup. Assign this task to a CPU. */ retval = sched_fork(clone_flags, p); if (retval) @@ -2141,10 +2121,6 @@ static __latent_entropy struct task_struct *copy_process( p->real_parent->signal->is_child_subreaper; list_add_tail(&p->sibling, &p->real_parent->children); list_add_tail_rcu(&p->tasks, &init_task.tasks); -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_ION) && defined(CONFIG_DUMP_TASKS_MEM) - INIT_LIST_HEAD(&p->user_tasks); - update_user_tasklist(p); -#endif attach_pid(p, PIDTYPE_PGID); attach_pid(p, PIDTYPE_SID); __this_cpu_inc(process_counts); @@ -2315,10 +2291,6 @@ long _do_fork(unsigned long clone_flags, pid = get_task_pid(p, PIDTYPE_PID); nr = pid_vnr(pid); -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_ION) && defined(CONFIG_DUMP_TASKS_MEM) - //perifeng.Li@Kernel.Permance, 2019/09/06, accounts process-real-phymem - atomic64_set(&p->ions, 0); -#endif if (clone_flags & CLONE_PARENT_SETTID) put_user(nr, parent_tidptr); diff --git a/kernel/futex.c b/kernel/futex.c index ca83850d201e..1150d56e6b8e 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -2731,13 +2731,7 @@ static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q, * is no timeout, or if it has yet to expire. */ if (!timeout || timeout->task){ -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_futex = 1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ freezable_schedule(); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_futex = 0; -#endif /* OPLUS_FEATURE_HEALTHINFO */ } } __set_current_state(TASK_RUNNING); diff --git a/kernel/hung_task.c b/kernel/hung_task.c index f6aa5a68c51b..379f44651fe2 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -21,25 +21,12 @@ #include #include -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -#include -#include -#endif /* * The number of tasks checked: */ int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -/* - * Selective monitoring of hung tasks. - * - * if set to 1, khungtaskd skips monitoring tasks, which has - * task_struct->hang_detection_enabled value not set, else monitors all tasks. - */ -int sysctl_hung_task_selective_monitoring = 1; -#endif /* * Limit number of tasks checked in a batch. @@ -92,7 +79,6 @@ static struct notifier_block panic_block = { .notifier_call = hung_task_panic, }; -#ifndef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE static void check_hung_task(struct task_struct *t, unsigned long timeout) { unsigned long switch_count = t->nvcsw + t->nivcsw; @@ -146,7 +132,6 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout) touch_nmi_watchdog(); } -#endif /* * To avoid extending the RCU grace period for an unbounded amount of time, @@ -181,9 +166,6 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) int max_count = sysctl_hung_task_check_count; unsigned long last_break = jiffies; struct task_struct *g, *t; -#if defined(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) && defined(CONFIG_OPLUS_FEATURE_DEATH_HEALER) - unsigned int iowait_count = 0; -#endif /* * If the system crashed already then all bets are off, @@ -202,22 +184,11 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) goto unlock; last_break = jiffies; } -#if defined(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) && defined(CONFIG_OPLUS_FEATURE_DEATH_HEALER) - io_check_hung_detection(t, timeout, &iowait_count, &hung_task_show_lock, &hung_task_call_panic); -#else /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ if (t->state == TASK_UNINTERRUPTIBLE) -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - if (!sysctl_hung_task_selective_monitoring || - t->hang_detection_enabled) -#endif check_hung_task(t, timeout); -#endif } unlock: -#if defined(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) && defined(CONFIG_OPLUS_FEATURE_DEATH_HEALER) - io_block_panic(&iowait_count, sysctl_hung_task_maxiowait_count); -#endif rcu_read_unlock(); if (hung_task_show_lock) debug_show_all_locks(); diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index ffc2fa2eae85..1d83309cd239 100755 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -35,9 +35,6 @@ # include "mutex.h" #endif -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -#include -#endif void __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) { @@ -47,9 +44,6 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) #ifdef CONFIG_MUTEX_SPIN_ON_OWNER osq_lock_init(&lock->osq); #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - lock->ux_dep_task = NULL; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ debug_mutex_init(lock, name, key); } EXPORT_SYMBOL(__mutex_init); @@ -788,15 +782,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, if (!use_ww_ctx) { /* add waiting tasks to the end of the waitqueue (FIFO): */ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_sched_assist_enabled) { - mutex_list_add(current, &waiter.list, &lock->wait_list, lock); - } else { - list_add_tail(&waiter.list, &lock->wait_list); - } -#else /* OPLUS_FEATURE_SCHED_ASSIST */ list_add_tail(&waiter.list, &lock->wait_list); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_DEBUG_MUTEXES waiter.ww_ctx = MUTEX_POISON_WW_CTX; @@ -831,12 +817,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, * wait_lock. This ensures the lock cancellation is ordered * against mutex_unlock() and wake-ups do not go missing. */ -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - if (unlikely(signal_pending_state(state, current)) - || hung_long_and_fatal_signal_pending(current)) { -#else if (unlikely(signal_pending_state(state, current))) { -#endif ret = -EINTR; goto err; } @@ -846,23 +827,8 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, if (ret) goto err; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - mutex_set_inherit_ux(lock, current); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ spin_unlock(&lock->wait_lock); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - if (state & TASK_UNINTERRUPTIBLE) { - current->in_mutex = 1; - } -#endif /* OPLUS_FEATURE_HEALTHINFO */ schedule_preempt_disabled(); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - if (state & TASK_UNINTERRUPTIBLE) { - current->in_mutex = 0; - } -#endif /* OPLUS_FEATURE_HEALTHINFO */ /* * ww_mutex needs to always recheck its position since its waiter @@ -1082,11 +1048,6 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne spin_lock(&lock->wait_lock); debug_mutex_unlock(lock); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - mutex_unset_inherit_ux(lock, current); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ if (!list_empty(&lock->wait_list)) { /* get the first entry from the wait-list: */ struct mutex_waiter *waiter = diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index b5f58ddcd20a..6acdcf4fa707 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -24,13 +24,6 @@ #include #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 -#include -#include -#include -extern int sysctl_mmapsem_uninterruptable_time; -#endif /* * Guide to the rw_semaphore's count field for common values. * (32-bit case illustrated, similar for 64-bit) @@ -103,9 +96,6 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, #ifdef CONFIG_MTK_TASK_TURBO sem->turbo_owner = NULL; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - sem->ux_dep_task = NULL; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } EXPORT_SYMBOL(__init_rwsem); @@ -156,10 +146,6 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, if (waiter->type == RWSEM_WAITING_FOR_WRITE) { if (wake_type == RWSEM_WAKE_ANY) { -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_wake(waiter->task, sem); -#endif /* * Mark writer at the front of the queue for wakeup. * Until the task is actually later awoken later by @@ -252,10 +238,6 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, * to the task to wakeup. */ smp_store_release(&waiter->task, NULL); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_wake(tsk, sem); -#endif /* * Ensure issuing the wakeup (either by us or someone else) * after setting the reader waiter to nil. @@ -275,11 +257,6 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) long count, adjustment = -RWSEM_ACTIVE_READ_BIAS; struct rwsem_waiter waiter; DEFINE_WAKE_Q(wake_q); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - int mem_sem_flag = 0; - u64 sleep_begin, sleep_end; -#endif waiter.task = current; @@ -288,18 +265,11 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) raw_spin_lock_irq(&sem->wait_lock); if (list_empty(&sem->wait_list)) adjustment += RWSEM_WAITING_BIAS; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && !defined(CONFIG_MTK_TASK_TURBO) - if (sysctl_sched_assist_enabled) - rwsem_list_add(waiter.task, &waiter.list, &sem->wait_list); - else - list_add_tail(&waiter.list, &sem->wait_list); -#else #ifdef CONFIG_MTK_TASK_TURBO rwsem_list_add(waiter.task, &waiter.list, &sem->wait_list); #else list_add_tail(&waiter.list, &sem->wait_list); #endif -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* we're now waiting on the lock, but no longer actively locking */ count = atomic_long_add_return(adjustment, &sem->count); @@ -314,11 +284,6 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) (count > RWSEM_WAITING_BIAS && adjustment != -RWSEM_ACTIVE_READ_BIAS)) __rwsem_mark_wake(sem, RWSEM_WAKE_ANY, &wake_q); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - rwsem_set_inherit_ux(current, waiter.task, READ_ONCE(sem->owner), sem); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_MTK_TASK_TURBO if (waiter.task) rwsem_start_turbo_inherit(sem); @@ -328,13 +293,6 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) /* wait to be given the lock */ while (true) { -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - if (current->mm && sem == &(current->mm->mmap_sem)) { - mem_sem_flag = 1; - sleep_begin = sched_clock(); - } -#endif set_current_state(state); if (!waiter.task) break; @@ -345,24 +303,10 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) raw_spin_unlock_irq(&sem->wait_lock); break; } -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_downread = 1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ schedule(); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_downread = 0; -#endif /* OPLUS_FEATURE_HEALTHINFO */ } __set_current_state(TASK_RUNNING); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - if (mem_sem_flag) { - sleep_end = sched_clock(); - sysctl_mmapsem_uninterruptable_time += - (sleep_end - sleep_begin) >> 20; - } -#endif return sem; out_nolock: list_del(&waiter.list); @@ -591,11 +535,6 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) struct rwsem_waiter waiter; struct rw_semaphore *ret = sem; DEFINE_WAKE_Q(wake_q); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - int mem_sem_flag = 0; - u64 sleep_begin, sleep_end; -#endif /* undo write bias from down_write operation, stop active locking */ @@ -617,18 +556,11 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) /* account for this before adding a new element to the list */ if (list_empty(&sem->wait_list)) waiting = false; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && !defined(CONFIG_MTK_TASK_TURBO) - if (sysctl_sched_assist_enabled) - rwsem_list_add(waiter.task, &waiter.list, &sem->wait_list); - else - list_add_tail(&waiter.list, &sem->wait_list); -#else /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_MTK_TASK_TURBO rwsem_list_add(waiter.task, &waiter.list, &sem->wait_list); #else list_add_tail(&waiter.list, &sem->wait_list); #endif -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* we're now waiting on the lock, but no longer actively locking */ if (waiting) { @@ -663,19 +595,7 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) /* inherit if current is turbo */ rwsem_start_turbo_inherit(sem); #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - rwsem_set_inherit_ux(waiter.task, current, READ_ONCE(sem->owner), sem); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - if (current->mm && sem == &(current->mm->mmap_sem)) { - mem_sem_flag = 1; - sleep_begin = sched_clock(); - } -#endif /* wait until we successfully acquire the lock */ set_current_state(state); @@ -688,13 +608,7 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) do { if (signal_pending_state(state, current)) goto out_nolock; -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_downwrite = 1; -#endif /* OPLUS_FEATURE_HEALTHINFO */ schedule(); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - current->in_downwrite = 0; -#endif /* OPLUS_FEATURE_HEALTHINFO */ set_current_state(state); } while ((count = atomic_long_read(&sem->count)) & RWSEM_ACTIVE_MASK); @@ -703,14 +617,6 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) __set_current_state(TASK_RUNNING); list_del(&waiter.list); raw_spin_unlock_irq(&sem->wait_lock); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - if (mem_sem_flag) { - sleep_end = sched_clock(); - sysctl_mmapsem_uninterruptable_time += - (sleep_end - sleep_begin) >> 20; - } -#endif return ret; @@ -814,11 +720,6 @@ locked: if (!list_empty(&sem->wait_list)) __rwsem_mark_wake(sem, RWSEM_WAKE_ANY, &wake_q); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (sysctl_sched_assist_enabled) { - rwsem_unset_inherit_ux(sem, current); - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ raw_spin_unlock_irqrestore(&sem->wait_lock, flags); wake_up_q(&wake_q); diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index ad0a97dcea4d..525f434bd292 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -18,13 +18,6 @@ #include #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 -#include -#include -#include <../sched/sched.h> -#include -#endif /* * lock for reading @@ -36,10 +29,6 @@ void __sched down_read(struct rw_semaphore *sem) LOCK_CONTENDED(sem, __down_read_trylock, __down_read); rwsem_set_reader_owned(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } EXPORT_SYMBOL(down_read); @@ -54,10 +43,6 @@ int down_read_trylock(struct rw_semaphore *sem) if (ret == 1) { rwsem_acquire_read(&sem->dep_map, 0, 1, _RET_IP_); rwsem_set_reader_owned(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } return ret; } @@ -74,10 +59,6 @@ void __sched down_write(struct rw_semaphore *sem) LOCK_CONTENDED(sem, __down_write_trylock, __down_write); rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } EXPORT_SYMBOL(down_write); @@ -96,10 +77,6 @@ int __sched down_write_killable(struct rw_semaphore *sem) } rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif return 0; } @@ -115,10 +92,6 @@ int down_write_trylock(struct rw_semaphore *sem) if (ret == 1) { rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_); rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } return ret; @@ -134,10 +107,6 @@ void up_read(struct rw_semaphore *sem) rwsem_release(&sem->dep_map, 1, _RET_IP_); __up_read(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_up(sem); -#endif } EXPORT_SYMBOL(up_read); @@ -154,10 +123,6 @@ void up_write(struct rw_semaphore *sem) rwsem_stop_turbo_inherit(sem); #endif __up_write(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_up(sem); -#endif } EXPORT_SYMBOL(up_write); @@ -187,10 +152,6 @@ void down_read_nested(struct rw_semaphore *sem, int subclass) LOCK_CONTENDED(sem, __down_read_trylock, __down_read); rwsem_set_reader_owned(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } EXPORT_SYMBOL(down_read_nested); @@ -202,10 +163,6 @@ void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest) LOCK_CONTENDED(sem, __down_write_trylock, __down_write); rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } EXPORT_SYMBOL(_down_write_nest_lock); @@ -215,10 +172,6 @@ void down_read_non_owner(struct rw_semaphore *sem) might_sleep(); __down_read(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } @@ -231,10 +184,6 @@ void down_write_nested(struct rw_semaphore *sem, int subclass) LOCK_CONTENDED(sem, __down_write_trylock, __down_write); rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif } EXPORT_SYMBOL(down_write_nested); @@ -250,10 +199,6 @@ int __sched down_write_killable_nested(struct rw_semaphore *sem, int subclass) } rwsem_set_owner(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_down(sem); -#endif return 0; } @@ -262,10 +207,6 @@ EXPORT_SYMBOL(down_write_killable_nested); void up_read_non_owner(struct rw_semaphore *sem) { __up_read(sem); -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - uxchain_rwsem_up(sem); -#endif } EXPORT_SYMBOL(up_read_non_owner); diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c index c0ec763687dc..561acdd39960 100644 --- a/kernel/locking/semaphore.c +++ b/kernel/locking/semaphore.c @@ -34,9 +34,6 @@ #include #include -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -#include -#endif static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); static noinline int __down_killable(struct semaphore *sem); @@ -215,11 +212,7 @@ static inline int __sched __down_common(struct semaphore *sem, long state, waiter.up = false; for (;;) { -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - if (signal_pending_state(state, current) || hung_long_and_fatal_signal_pending(current)) -#else if (signal_pending_state(state, current)) -#endif goto interrupted; if (unlikely(timeout <= 0)) goto timed_out; diff --git a/kernel/panic.c b/kernel/panic.c index 3e85f658fbdc..a65843ca094b 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -32,26 +32,13 @@ #define PANIC_TIMER_STEP 100 #define PANIC_BLINK_SPD 18 -#ifdef OPLUS_FEATURE_PHOENIX -// Kun.Hu@TECH.BSP.Stability.PHOENIX_PROJECT 2019/06/11, Add for phoenix project -#include "../drivers/soc/oplus/system/oplus_phoenix/oplus_phoenix.h" -#include -#include -#include -int kernel_panic_happened = 0; -int hwt_happened = 0; -#endif #ifdef OPLUS_BUG_STABILITY /* Bin.Li@EXP.BSP.bootloader.bootflow, 2017/05/24, Add for interface reboot reason */ int is_kernel_panic = 0; #endif -#ifdef OPLUS_FEATURE_PERFORMANCE -//ZuoTong@ANDROID.PERFORMANCE, 2020/06/28,Add for flushing device cache before goto dump mode! -bool is_triggering_panic = false; -bool is_triggering_hwt = false; -#endif /*OPLUS_FEATURE_PERFORMANCE*/ + int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE; static unsigned long tainted_mask; @@ -95,32 +82,6 @@ void __weak nmi_panic_self_stop(struct pt_regs *regs) panic_smp_self_stop(); } -#ifdef OPLUS_FEATURE_PHOENIX -void deal_fatal_err(void) -{ - if(!phx_is_phoenix_boot_completed()) { - - if(kernel_panic_happened) { - phx_set_boot_error(ERROR_KERNEL_PANIC); - } else if(hwt_happened) { - phx_set_boot_error(ERROR_HWT); - } - - } else { - struct timespec ts; - struct rtc_time tm; - char err_info[60] = {0}; - - getnstimeofday(&ts); - rtc_time_to_tm(ts.tv_sec, &tm); - - sprintf(err_info, "panic after bootup @%d-%d-%d %d:%d:%d", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - pr_err("panic after bootup @%d-%d-%d %d:%d:%d\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - } -} -#endif /*OPLUS_FEATURE_PHOENIX*/ /* * Stop other CPUs in panic. Architecture dependent code may override this @@ -170,19 +131,6 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); -#ifdef OPLUS_FEATURE_PERFORMANCE -//ZuoTong@ANDROID.PERFORMANCE, 2020/06/28,Add for flushing device cache before goto dump mode! -extern int panic_flush_device_cache(int timeout); -extern unsigned int get_eng_version(void); -void flush_cache_on_panic(void){ - if (get_eng_version() == 1){ - pr_err("In full dump mode!\n"); - }else{ - pr_err("In mini dump mode and start flushing the devices cache!"); - panic_flush_device_cache(2000); - } -} -#endif /*OPLUS_FEATURE_PERFORMANCE*/ /** * panic - halt the system diff --git a/kernel/panic_flush.c b/kernel/panic_flush.c deleted file mode 100755 index dc460a5f625e..000000000000 --- a/kernel/panic_flush.c +++ /dev/null @@ -1,133 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2021 Oplus. All rights reserved. - */ - -#define DEBUG -#include -#include -#include -#include -#include -#include -#include - -#define PANIC_FLUSH_POLL_MS (10) - - -struct panic_flush_control { - struct task_struct *flush_thread; - wait_queue_head_t flush_wq; - atomic_t flush_issuing; - atomic_t flush_issued; -}; - -static struct panic_flush_control *pfc; -static void panic_issue_flush(struct super_block *sb ,void *arg) -{ - int ret = -1; - int *flush_count = (int *)arg; - if (!(sb->s_flags & MS_RDONLY) && NULL != sb->s_bdev) { - ret = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL); - } - if (!ret) { - (*flush_count)++; - pr_emerg("blkdev_issue_flush before panic return %d\n", *flush_count); - } -} - -static int panic_flush_thread(void *data) -{ - int flush_count = 0; -repeat: - if (kthread_should_stop()) - return 0; - wait_event(pfc->flush_wq, kthread_should_stop() || - atomic_read(&pfc->flush_issuing) > 0); - if (atomic_read(&pfc->flush_issuing) > 0) { - iterate_supers(panic_issue_flush, &flush_count); - pr_emerg("Up to now, total %d panic_issue_flush_count\n", flush_count); - atomic_inc(&pfc->flush_issued); - atomic_dec(&pfc->flush_issuing); - } - goto repeat; -} - -static inline bool is_fulldump_enable(void) -{ - if (get_eng_version() == 1) { - pr_err("In full dump mode!\n"); - return true; - } else { - pr_err("In mini dump mode and start flushing the devices cache!"); - return false; - } -} - -static inline bool need_flush_device_cache(void) -{ - if (is_fulldump_enable()) - return false; - - return true; - -} - -int panic_flush_device_cache(int timeout) -{ - pr_emerg("%s\n", __func__); - if (!pfc || !need_flush_device_cache()) { - pr_emerg("%s: skip flush device cache\n", __func__); - return timeout; - } - - if (atomic_inc_return(&pfc->flush_issuing) == 1 && - waitqueue_active(&pfc->flush_wq)) { - pr_emerg("%s: flush device cache\n", __func__); - atomic_set(&pfc->flush_issued, 0); - wake_up(&pfc->flush_wq); - while (timeout > 0 && atomic_read(&pfc->flush_issued) == 0) { - mdelay(PANIC_FLUSH_POLL_MS); - timeout -= PANIC_FLUSH_POLL_MS; - } - pr_emerg("%s: remaining timeout = %d\n", __func__, timeout); - } - return timeout; -} - -static int __init create_panic_flush_control(void) -{ - int err = 0; - pr_debug("%s\n", __func__); - pfc = kzalloc(sizeof(*pfc), GFP_KERNEL); - if (!pfc) { - pr_err("%s: fail to allocate memory\n", __func__); - return -ENOMEM; - } - - init_waitqueue_head(&pfc->flush_wq); - atomic_set(&pfc->flush_issuing, 0); - atomic_set(&pfc->flush_issued, 0); - pfc->flush_thread = kthread_run(panic_flush_thread, pfc, "panic_flush"); - if (IS_ERR(pfc->flush_thread)) { - err = PTR_ERR(pfc->flush_thread); - kfree(pfc); - pfc = NULL; - } - return err; -} - -static void __exit destroy_panic_flush_control(void) -{ - pr_debug("%s\n", __func__); - if (pfc && pfc->flush_thread) { - pr_debug("%s: stop panic_flush thread\n", __func__); - kthread_stop(pfc->flush_thread); - kfree(pfc); - pfc = NULL; - } -} -module_init(create_panic_flush_control); -module_exit(destroy_panic_flush_control); -MODULE_DESCRIPTION("OPPO panic flush control"); -MODULE_LICENSE("GPL v2"); diff --git a/kernel/prefer_silver/Kconfig b/kernel/prefer_silver/Kconfig deleted file mode 100644 index 772ce2aa424a..000000000000 --- a/kernel/prefer_silver/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -config OPLUS_PREFER_SILVER - default n - bool "a task placement decision for non-ui task" - help - task placement decision feature for non-ui task diff --git a/kernel/prefer_silver/Makefile b/kernel/prefer_silver/Makefile deleted file mode 100644 index c457412fdac9..000000000000 --- a/kernel/prefer_silver/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-$(CONFIG_OPLUS_PREFER_SILVER) += prefer_silver.o diff --git a/kernel/prefer_silver/prefer_silver.c b/kernel/prefer_silver/prefer_silver.c deleted file mode 100644 index 24293ab0bc9c..000000000000 --- a/kernel/prefer_silver/prefer_silver.c +++ /dev/null @@ -1,101 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include -#include <../kernel/sched/sched.h> -#include - -#include "prefer_silver.h" - -int sysctl_prefer_silver = 0; -int sysctl_heavy_task_thresh = 50; -int sysctl_cpu_util_thresh = 85; -int sysctl_silver_trigger_freq = 1503000; - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern bool test_task_ux(struct task_struct *task); -#endif - -bool prefer_silver_check_ux(struct task_struct *task) { - bool is_ux = false; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - is_ux = test_task_ux(current); -#endif - return is_ux; -} - -bool prefer_silver_check_freq(int cpu) -{ - unsigned int freq = 0; - freq = cpufreq_quick_get(cpu); - - return freq < sysctl_silver_trigger_freq; -} - -static inline unsigned long task_util(struct task_struct *p) -{ -#ifdef CONFIG_SCHED_WALT - static int sched_use_walt_nice = 101; - if (!walt_disabled && (sysctl_sched_use_walt_task_util || - p->prio < sched_use_walt_nice)) { - unsigned long demand = p->ravg.demand; - return (demand << SCHED_CAPACITY_SHIFT) / walt_ravg_window; - } -#endif - return p->se.avg.util_avg; -} - -static inline unsigned long cpu_util(int cpu) -{ - struct cfs_rq *cfs_rq; - unsigned int util; - -#ifdef CONFIG_SCHED_WALT - if (likely(!walt_disabled && sysctl_sched_use_walt_cpu_util)) { - u64 walt_cpu_util = cpu_rq(cpu)->cumulative_runnable_avg; - - walt_cpu_util <<= SCHED_CAPACITY_SHIFT; - do_div(walt_cpu_util, walt_ravg_window); - - return min_t(unsigned long, walt_cpu_util, - capacity_orig_of(cpu)); - } -#endif - - cfs_rq = &cpu_rq(cpu)->cfs; - util = READ_ONCE(cfs_rq->avg.util_avg); - - if (sched_feat(UTIL_EST)) - util = max(util, READ_ONCE(cfs_rq->avg.util_est.enqueued)); - - return min_t(unsigned long, util, capacity_orig_of(cpu)); -} - - -bool prefer_silver_check_task_util(struct task_struct *p) -{ - int cpu; - unsigned long thresh_load; - struct reciprocal_value spc_rdiv = reciprocal_value(100); - - if (!p) - return false; - - cpu = task_cpu(p); - thresh_load = capacity_orig_of(cpu) * sysctl_heavy_task_thresh; - if(task_util(p) < reciprocal_divide(thresh_load,spc_rdiv) || - scale_demand(p->ravg.sum) < reciprocal_divide(thresh_load,spc_rdiv)) - return true; - - return false; -} - -bool prefer_silver_check_cpu_util(int cpu) -{ - return (capacity_orig_of(cpu) * sysctl_cpu_util_thresh) > - (cpu_util(cpu) * 100); -} diff --git a/kernel/prefer_silver/prefer_silver.h b/kernel/prefer_silver/prefer_silver.h deleted file mode 100644 index e86f15b33258..000000000000 --- a/kernel/prefer_silver/prefer_silver.h +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _OPLUS_PREFER_SILVER_H_ -#define _OPLUS_PREFER_SILVER_H_ - -#ifdef CONFIG_SCHED_WALT -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#define scale_demand(d) ((d)/walt_scale_demand_divisor) -#endif - -extern int sysctl_prefer_silver; -extern int sysctl_heavy_task_thresh; -extern int sysctl_cpu_util_thresh; -extern int sysctl_silver_trigger_freq; - -extern bool prefer_silver_check_ux(struct task_struct *task); - -extern bool prefer_silver_check_freq(int cpu); -extern bool prefer_silver_check_task_util(struct task_struct *p); -extern bool prefer_silver_check_cpu_util(int cpu); - -#endif /*_OPLUS_PREFER_SILVER_H_*/ diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c index 44d716c107f7..30e2c2ab37ca 100644 --- a/kernel/sched/completion.c +++ b/kernel/sched/completion.c @@ -16,9 +16,6 @@ #include #include -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE -#include -#endif /** * complete: - signals a single thread waiting on this completion @@ -86,11 +83,7 @@ do_wait_for_common(struct completion *x, __add_wait_queue_entry_tail_exclusive(&x->wait, &wait); do { -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - if (signal_pending_state(state, current) || hung_long_and_fatal_signal_pending(current)) { -#else if (signal_pending_state(state, current)) { -#endif timeout = -ERESTARTSYS; break; } diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 996f033356ab..37640e6202a5 100755 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -65,16 +65,7 @@ #include #endif /* CONFIG_MTK_QOS_FRAMEWORK */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -#include -#endif /* defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_SCHED_ASSIST) */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); @@ -1936,19 +1927,6 @@ unsigned int get_capacity_margin(void) } EXPORT_SYMBOL(get_capacity_margin); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -void set_capacity_margin_dvfs(unsigned int margin) -{ - capacity_margin_dvfs = margin; -} -EXPORT_SYMBOL(set_capacity_margin_dvfs); - -unsigned int get_capacity_margin_dvfs(void) -{ - return capacity_margin_dvfs; -} -EXPORT_SYMBOL(get_capacity_margin_dvfs); -#endif static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags) @@ -2081,16 +2059,6 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) { const struct sched_class *class; -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - u64 wallclock = sched_clock(); - - if (sysctl_uxchain_v2 && - wallclock - rq->curr->get_mmlock_ts < PREEMPT_DISABLE_RWSEM && - rq->curr->get_mmlock && - !(p->flags & PF_WQ_WORKER) && !task_has_rt_policy(p)) - return; -#endif if (p->sched_class == rq->curr->sched_class) { rq->curr->sched_class->check_preempt_curr(rq, p, flags); @@ -3252,11 +3220,6 @@ static inline void walt_try_to_wake_up(struct task_struct *p) wallclock = walt_ktime_clock(); walt_update_task_ravg(rq->curr, rq, TASK_UPDATE, wallclock, 0); walt_update_task_ravg(p, rq, TASK_WAKE, wallclock, 0); -#ifdef CONFIG_SCHED_WALT -#ifdef OPLUS_FEATURE_SCHED_ASSIST - p->last_wake_ts = wallclock; -#endif /* CONFIG_SCHED_WALT */ -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ rq_unlock_irqrestore(rq, &rf); } #else @@ -3302,9 +3265,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags, trace_sched_waking(p); -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_wake_tid(p, current, other_runnable); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ /* We're going to change ->state: */ success = 1; @@ -3438,9 +3398,6 @@ static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf) trace_sched_waking(p); -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_wake_tid(p, current, other_runnable); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ if (!task_on_rq_queued(p)) { u64 wallclock = walt_ktime_clock(); @@ -3453,11 +3410,6 @@ static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf) atomic_dec(&rq->nr_iowait); } ttwu_activate(rq, p, ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK); -#ifdef CONFIG_SCHED_WALT -#ifdef OPLUS_FEATURE_SCHED_ASSIST - p->last_wake_ts = wallclock; -#endif /* CONFIG_SCHED_WALT */ -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } ttwu_do_wakeup(rq, p, 0, rf); @@ -3830,9 +3782,6 @@ void wake_up_new_task(struct task_struct *p) walt_mark_task_starting(p); p->on_rq = TASK_ON_RQ_QUEUED; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_wake_tid(p, current, other_runnable); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_sched_wakeup_new(p); check_preempt_curr(rq, p, WF_FORK); #ifdef CONFIG_SMP @@ -4376,10 +4325,6 @@ unsigned long long task_sched_runtime(struct task_struct *p) } -#if defined(OPLUS_FEATURE_CORE_CTL) && defined(CONFIG_SCHED_CORE_CTL) -extern int tick_do_timer_cpu __read_mostly; -#include -#endif /* OPLUS_FEATURE_CORE_CTL */ /* * This function gets called by the timer code, with HZ frequency. * We call it with interrupts disabled. @@ -4398,11 +4343,6 @@ void scheduler_tick(void) walt_update_task_ravg(rq->curr, rq, TASK_UPDATE, walt_ktime_clock(), 0); update_rq_clock(rq); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - unsigned int flag = 0; - slide_calc_boost_load(rq, &flag, cpu); - cpufreq_update_util(rq, flag); -#endif curr->sched_class->task_tick(rq, curr, 0); cpu_load_update_active(rq); calc_global_load_tick(rq); @@ -4754,9 +4694,6 @@ static void __sched notrace __schedule(bool preempt) } switch_count = &prev->nvcsw; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - prev->enqueue_time = rq->clock; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ next = pick_next_task(rq, prev, &rf); wallclock = walt_ktime_clock(); walt_update_task_ravg(prev, rq, PUT_PREV_TASK, wallclock, 0); @@ -4788,10 +4725,6 @@ static void __sched notrace __schedule(bool preempt) */ ++*switch_count; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_wake_tid(prev, next, running_runnable); - update_running_start_time(prev, next); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_sched_switch(preempt, prev, next); @@ -6648,19 +6581,9 @@ void sched_show_task(struct task_struct *p) if (pid_alive(p)) ppid = task_pid_nr(rcu_dereference(p->real_parent)); rcu_read_unlock(); -//#ifdef OPLUS_BUG_STABILITY -#ifdef CONFIG_SCHED_WALT - if (task_state_to_char(p) == 'D') - printk(KERN_CONT "%5lu %5d %6d 0x%08lx %5lus\n", free, - task_pid_nr(p), ppid, - (unsigned long)task_thread_info(p)->flags, - (walt_ktime_clock() - p->last_sleep_ts) / NSEC_PER_SEC); - else -#endif -//#endif /*OPLUS_BUG_STABILITY*/ - printk(KERN_CONT "%5lu %5d %6d 0x%08lx\n", free, - task_pid_nr(p), ppid, - (unsigned long)task_thread_info(p)->flags); + printk(KERN_CONT "%5lu %5d %6d 0x%08lx\n", free, + task_pid_nr(p), ppid, + (unsigned long)task_thread_info(p)->flags); print_worker_info(KERN_INFO, p); show_stack(p, NULL); put_task_stack(p); @@ -7233,9 +7156,6 @@ int _sched_isolate_cpu(int cpu) out: cpu_maps_update_done(); -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_cpu_isolate_info(cpu, cpu_isolate); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_sched_isolate(cpu, cpumask_bits(cpu_isolated_mask)[0], start_time, 1); printk_deferred("%s: prio=%d, cpu=%d, isolation_cpus=0x%lx\n", @@ -7292,9 +7212,6 @@ int sched_deisolate_cpu_unlocked(int cpu) out: trace_sched_isolate(cpu, cpumask_bits(cpu_isolated_mask)[0], start_time, 0); -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_cpu_isolate_info(cpu, cpu_unisolate); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ printk_deferred("%s: prio=%d, cpu=%d, isolation_cpus=0x%lx\n", __func__, iso_prio, cpu, cpu_isolated_mask->bits[0]); return ret_code; @@ -7658,9 +7575,6 @@ void __init sched_init_smp(void) BUG(); sched_init_granularity(); free_cpumask_var(non_isolated_cpus); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - ux_init_cpu_data(); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ init_sched_rt_class(); init_sched_dl_class(); @@ -7780,9 +7694,6 @@ void __init sched_init(void) init_cfs_rq(&rq->cfs); init_rt_rq(&rq->rt); init_dl_rq(&rq->dl); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - ux_init_rq_data(rq); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_FAIR_GROUP_SCHED root_task_group.shares = ROOT_TASK_GROUP_LOAD; INIT_LIST_HEAD(&rq->leaf_cfs_rq_list); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 709fbee03e28..df9f63bb72d3 100755 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -21,16 +21,7 @@ #include "sched.h" #include "tune.h" #include "cpufreq_schedutil.h" -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && (CONFIG_SCHED_WALT) -#include -extern int sysctl_slide_boost_enabled; -extern int sysctl_sched_assist_enabled; -extern u64 ux_task_load[]; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ static struct cpufreq_governor schedutil_gov; unsigned long boosted_cpu_util(int cpu); @@ -40,22 +31,11 @@ EXPORT_SYMBOL(cpufreq_notifier_fp); #define SUGOV_KTHREAD_PRIORITY 50 -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -/* Target load. Lower values result in higher CPU speeds. */ -#define DEFAULT_TARGET_LOAD 80 -static unsigned int default_target_loads[] = {DEFAULT_TARGET_LOAD}; -#endif struct sugov_tunables { struct gov_attr_set attr_set; unsigned int up_rate_limit_us; unsigned int down_rate_limit_us; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - spinlock_t target_loads_lock; - unsigned int *target_loads; - unsigned int *util_loads; - int ntarget_loads; -#endif }; struct sugov_policy { @@ -72,9 +52,6 @@ struct sugov_policy { unsigned int next_freq; unsigned int cached_raw_freq; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - unsigned int len; -#endif /* The next fields are only needed if fast switch cannot be used. */ struct irq_work irq_work; struct kthread_work work; @@ -84,9 +61,6 @@ struct sugov_policy { bool work_in_progress; bool need_freq_update; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - unsigned int flags; -#endif }; struct sugov_cpu { @@ -158,10 +132,6 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) * limit once frequency change direction is decided, according * to the separate rate limits. */ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (sg_policy->flags & SCHED_CPUFREQ_BOOST) - return true; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ delta_ns = time - sg_policy->last_freq_update_time; return delta_ns >= sg_policy->min_rate_limit_ns; } @@ -172,10 +142,6 @@ static bool sugov_up_down_rate_limit(struct sugov_policy *sg_policy, u64 time, s64 delta_ns; delta_ns = time - sg_policy->last_freq_update_time; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (sg_policy->flags & SCHED_CPUFREQ_BOOST) - return false; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ if (next_freq > sg_policy->next_freq && delta_ns < sg_policy->up_rate_delay_ns) return true; @@ -208,9 +174,6 @@ static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, #ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT mt_cpufreq_set_by_wfi_load_cluster(cid, next_freq); policy->cur = next_freq; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_freq_info(policy); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_sched_util(cid, next_freq, time); #else if (policy->fast_switch_enabled) { @@ -219,9 +182,6 @@ static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, return; policy->cur = next_freq; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_freq_info(policy); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ trace_cpu_frequency(next_freq, smp_processor_id()); } else { sg_policy->work_in_progress = true; @@ -230,189 +190,6 @@ static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, #endif } -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -#ifdef CONFIG_NONLINEAR_FREQ_CTL -static inline unsigned int get_opp_capacity(struct cpufreq_policy *policy, - int row) -{ - struct upower_tbl *upower_tbl; - - upower_tbl = upower_get_core_tbl(policy->cpu); - - return upower_tbl->row[row].cap; -} -#else -static inline unsigned int get_opp_capacity(struct cpufreq_policy *policy, - int row) -{ - unsigned int cap, orig_cap; - unsigned long freq, max_freq; - - max_freq = policy->cpuinfo.max_freq; - orig_cap = capacity_orig_of(policy->cpu); - - freq = policy->freq_table[row].frequency; - cap = orig_cap * freq / max_freq; - - return cap; -} -#endif - -static unsigned int util_to_targetload( - struct sugov_tunables *tunables, unsigned int util) -{ - int i; - unsigned int ret; - unsigned long flags; - - spin_lock_irqsave(&tunables->target_loads_lock, flags); - - for (i = 0; i < tunables->ntarget_loads - 1 && - util >= tunables->util_loads[i+1]; i += 2) - ; - - ret = tunables->util_loads[i]; - spin_unlock_irqrestore(&tunables->target_loads_lock, flags); - return ret; -} - -unsigned int find_util_l(struct sugov_policy *sg_policy, unsigned int util) -{ - unsigned int idx, capacity; - - for (idx = 0; idx < sg_policy->len; idx++) { - /*TODO: find the first bigger one in table, to match below orginal codes - *in cpufreq_schedutil_plus.c - *tbl = upower_get_core_tbl(cpu); - *for (idx = 0; idx < tbl->row_num ; idx++) { - * cap = tbl->row[idx].cap; - * if (!cap) - * break; - * - * target_idx = idx; - * - * if (cap > util) - * break; - *} - */ -// if (sg_policy->freq2util[idx].cap >= util) - capacity = get_opp_capacity(sg_policy->policy, idx); - if (capacity >= util) - return capacity; - } - return get_opp_capacity(sg_policy->policy, sg_policy->len - 1); -} - -unsigned int find_util_h(struct sugov_policy *sg_policy, unsigned int util) -{ - unsigned int idx, capacity; - int target_idx = -1; - - for (idx = 0; idx < sg_policy->len; idx++) { - capacity = get_opp_capacity(sg_policy->policy, idx); - if (capacity == util) { - return util; - } - if (capacity < util) { - target_idx = idx; - continue; - } - if (target_idx == -1) - return capacity; - return get_opp_capacity(sg_policy->policy, target_idx); - } - return get_opp_capacity(sg_policy->policy, target_idx); -} - -unsigned int find_closest_util(struct sugov_policy *sg_policy, unsigned int util - , unsigned int policy) -{ - switch (policy) { - case CPUFREQ_RELATION_L: - return find_util_l(sg_policy, util); - case CPUFREQ_RELATION_H: - return find_util_h(sg_policy, util); - default: - return util; - } -} - -unsigned int choose_util(struct sugov_policy *sg_policy, - unsigned int util) -{ - unsigned int prevutil, utilmin, utilmax; - unsigned int tl; - unsigned long orig_util = util; - - if (!sg_policy) { - pr_err("sg_policy is null\n"); - return -EINVAL; - } - - utilmin = 0; - utilmax = UINT_MAX; - - do { - prevutil = util; - tl = util_to_targetload(sg_policy->tunables, util); - - /* - * Find the lowest frequency where the computed load is less - * than or equal to the target load. - */ - - util = find_closest_util(sg_policy, (orig_util * 100 / tl), CPUFREQ_RELATION_L); - trace_choose_util(util, prevutil, utilmax, utilmin, tl); - - if (util > prevutil) { - /* The previous frequency is too low. */ - utilmin = prevutil; - - if (util >= utilmax) { - /* - * Find the highest frequency that is less - * than freqmax. - */ - util = find_closest_util(sg_policy, utilmax - 1,CPUFREQ_RELATION_H); - - if (util == utilmin) { - /* - * The first frequency below freqmax - * has already been found to be too - * low. freqmax is the lowest speed - * we found that is fast enough. - */ - util = utilmax; - break; - } - } - } else if (util < prevutil) { - /* The previous frequency is high enough. */ - utilmax = prevutil; - - if (util <= utilmin) { - /* - * Find the lowest frequency that is higher - * than freqmin. - */ - util = find_closest_util(sg_policy, utilmin + 1, CPUFREQ_RELATION_L); - - /* - * If freqmax is the first frequency above - * freqmin then we have already found that - * this speed is fast enough. - */ - if (util == utilmax) - break; - } - } - - /* If same frequency chosen as previous then done. */ - } while (util != prevutil); - - return util; -} -#endif #ifdef CONFIG_NONLINEAR_FREQ_CTL @@ -465,15 +242,8 @@ static void sugov_get_util(unsigned long *util, unsigned long *max, int cpu) max_cap = arch_scale_cpu_capacity(NULL, cpu); *util = boosted_cpu_util(cpu); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (!sysctl_sched_assist_enabled || !(sysctl_slide_boost_enabled || sched_assist_scene(SA_LAUNCHER_SI))|| !ux_task_load[cpu]) { - if (idle_cpu(cpu)) - *util = 0; - } -#else /* OPLUS_FEATURE_SCHED_ASSIST */ if (idle_cpu(cpu)) *util = 0; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ *util = min(*util, max_cap); *max = max_cap; @@ -658,9 +428,6 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sg_cpu->util = util; sg_cpu->max = max; sg_cpu->flags = flags; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - sg_policy->flags = flags; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; @@ -866,183 +633,14 @@ int schedutil_set_up_rate_limit_us(int cpu, unsigned int rate_limit_us) } EXPORT_SYMBOL(schedutil_set_up_rate_limit_us); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -static ssize_t target_loads_show(struct gov_attr_set *attr_set, char *buf) -{ - struct sugov_tunables *tunables = to_sugov_tunables(attr_set); - int i; - ssize_t ret = 0; - unsigned long flags; - - spin_lock_irqsave(&tunables->target_loads_lock, flags); - for (i = 0; i < tunables->ntarget_loads; i++) - ret += snprintf(buf + ret, PAGE_SIZE - ret - 1, "%u%s", tunables->target_loads[i], - i & 0x1 ? ":" : " "); - - snprintf(buf + ret - 1, PAGE_SIZE - ret - 1, "\n"); - spin_unlock_irqrestore(&tunables->target_loads_lock, flags); - return ret; -} - -static unsigned int *get_tokenized_data(const char *buf, int *num_tokens) -{ - const char *cp; - int i; - int ntokens = 1; - unsigned int *tokenized_data; - int err = -EINVAL; - - cp = buf; - while ((cp = strpbrk(cp + 1, " :"))) - ntokens++; - - if (!(ntokens & 0x1)) - goto err; - - tokenized_data = kmalloc(ntokens * sizeof(unsigned int), GFP_KERNEL); - if (!tokenized_data) { - err = -ENOMEM; - goto err; - } - - cp = buf; - i = 0; - while (i < ntokens) { - if (sscanf(cp, "%u", &tokenized_data[i++]) != 1) - goto err_kfree; - - cp = strpbrk(cp, " :"); - if (!cp) - break; - cp++; - } - - if (i != ntokens) - goto err_kfree; - - *num_tokens = ntokens; - - return tokenized_data; -err_kfree: - kfree(tokenized_data); -err: - return ERR_PTR(err); -} - -static unsigned int freq2util(struct sugov_policy *sg_policy, unsigned int freq) -{ - int idx; - unsigned int capacity, opp_freq; -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT - int cpu = sg_policy->policy->cpu; - int cid = arch_get_cluster_id(cpu); - - cid = arch_get_cluster_id(cpu); - freq = mt_cpufreq_find_close_freq(cid, freq); -#endif - for (idx = 0; idx < sg_policy->len; idx++) { - capacity = get_opp_capacity(sg_policy->policy, idx); - opp_freq = mt_cpufreq_get_cpu_freq(sg_policy->policy->cpu, idx); - if (freq <= opp_freq) - return capacity; - } - return get_opp_capacity(sg_policy->policy, sg_policy->len - 1); -} - -static ssize_t target_loads_store(struct gov_attr_set *attr_set, const char *buf, - size_t count) -{ - int ntokens, i; - unsigned int *new_target_loads = NULL; - unsigned long flags; - struct sugov_tunables *tunables = to_sugov_tunables(attr_set); - struct sugov_policy *sg_policy; - unsigned int *new_util_loads = NULL; - - - //get the first policy if this tunnables have mutil policies - sg_policy = list_first_entry(&attr_set->policy_list, struct sugov_policy, tunables_hook); - if (!sg_policy) { - pr_err("sg_policy is null\n"); - return count; - } - - new_target_loads = get_tokenized_data(buf, &ntokens); - for(i = 0; i < ntokens; i++) { - printk("token %d is %d\n", i, new_target_loads[i]); - } - if (IS_ERR(new_target_loads)) - return PTR_ERR(new_target_loads); - - new_util_loads = kzalloc(ntokens * sizeof(unsigned int), GFP_KERNEL); - if (!new_util_loads) - return -ENOMEM; - - memcpy(new_util_loads, new_target_loads, sizeof(unsigned int) * ntokens); - for (i = 0; i < ntokens - 1; i += 2) { - new_util_loads[i+1] = freq2util(sg_policy, new_target_loads[i+1]); - printk("freq = %d, util = %d\n", new_target_loads[i+1], new_util_loads[i+1]); - } - - spin_lock_irqsave(&tunables->target_loads_lock, flags); - if (tunables->target_loads != default_target_loads) - kfree(tunables->target_loads); - if (tunables->util_loads != default_target_loads) - kfree(tunables->util_loads); - - tunables->target_loads = new_target_loads; - tunables->ntarget_loads = ntokens; - tunables->util_loads = new_util_loads; - spin_unlock_irqrestore(&tunables->target_loads_lock, flags); - - return count; -} - -ssize_t set_sugov_tl(unsigned int cpu, char *buf) -{ - struct cpufreq_policy *policy; - struct sugov_policy *sg_policy; - struct sugov_tunables *tunables; - struct gov_attr_set *attr_set; - size_t count; - - if (!buf) - return -EFAULT; - - policy = cpufreq_cpu_get(cpu); - if (!policy) - return -ENODEV; - - sg_policy = policy->governor_data; - if (!sg_policy) - return -EINVAL; - - tunables = sg_policy->tunables; - if (!tunables) - return -ENOMEM; - - attr_set = &tunables->attr_set; - count = strlen(buf); - - return target_loads_store(attr_set, buf, count); -} -EXPORT_SYMBOL_GPL(set_sugov_tl); -#endif static struct governor_attr up_rate_limit_us = __ATTR_RW(up_rate_limit_us); static struct governor_attr down_rate_limit_us = __ATTR_RW(down_rate_limit_us); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -static struct governor_attr target_loads = - __ATTR(target_loads, 0664, target_loads_show, target_loads_store); -#endif static struct attribute *sugov_attributes[] = { &up_rate_limit_us.attr, &down_rate_limit_us.attr, -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - &target_loads.attr, -#endif NULL }; @@ -1164,9 +762,6 @@ static int sugov_init(struct cpufreq_policy *policy) goto disable_fast_switch; } -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - sg_policy->len = UPOWER_OPP_NUM; -#endif ret = sugov_kthread_create(sg_policy); if (ret) @@ -1195,13 +790,6 @@ static int sugov_init(struct cpufreq_policy *policy) tunables->up_rate_limit_us = cpufreq_policy_transition_delay_us(policy); tunables->down_rate_limit_us = cpufreq_policy_transition_delay_us(policy); -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - tunables->target_loads = default_target_loads; - tunables->ntarget_loads = ARRAY_SIZE(default_target_loads); - //same with target_loads by default - tunables->util_loads = default_target_loads; - spin_lock_init(&tunables->target_loads_lock); -#endif policy->governor_data = sg_policy; sg_policy->tunables = tunables; @@ -1270,9 +858,6 @@ static int sugov_start(struct cpufreq_policy *policy) sg_policy->work_in_progress = false; sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = 0; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - sg_policy->flags = 0; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ for_each_cpu(cpu, policy->cpus) { struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu); diff --git a/kernel/sched/cpufreq_schedutil_plus.c b/kernel/sched/cpufreq_schedutil_plus.c index 9deeac92d449..854dd4818a19 100755 --- a/kernel/sched/cpufreq_schedutil_plus.c +++ b/kernel/sched/cpufreq_schedutil_plus.c @@ -5,14 +5,6 @@ #include "../../drivers/misc/mediatek/base/power/include/mtk_upower.h" -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -extern unsigned int capacity_margin_dvfs; -bool capacity_margin_dvfs_changed = false; -void set_capacity_margin_dvfs_changed(bool changed) -{ - capacity_margin_dvfs_changed = changed; -} -#endif static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned long util, unsigned long max) @@ -25,23 +17,7 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned int freq = arch_scale_freq_invariant() ? policy->cpuinfo.max_freq : policy->cur; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - unsigned long target_util; - - if (!capacity_margin_dvfs_changed) { - target_util = choose_util(sg_policy, util); - if (target_util < 0) - return freq; - trace_sugov_next_util_tl(cpu, util, max, target_util); - util = target_util; - } else { - util = util * capacity_margin_dvfs / SCHED_CAPACITY_SCALE; -#else util = util * capacity_margin / SCHED_CAPACITY_SCALE; -#endif -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - } -#endif tbl = upower_get_core_tbl(cpu); for (idx = 0; idx < tbl->row_num ; idx++) { cap = tbl->row[idx].cap; @@ -50,13 +26,8 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, target_idx = idx; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) - if (cap >= util) - break; -#else if (cap > util) break; -#endif } freq = mt_cpufreq_get_cpu_freq(cpu, target_idx); diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c index b8607c9adce1..ebdc2fd74fd9 100755 --- a/kernel/sched/cpupri.c +++ b/kernel/sched/cpupri.c @@ -32,9 +32,6 @@ #include #include #include "cpupri.h" -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* Convert between a 140 based task->prio, and our 102 based cpupri */ static int convert_prio(int prio) { @@ -51,9 +48,6 @@ static int convert_prio(int prio) return cpupri; } -#if defined(OPLUS_FEATURE_SCHED_ASSIST) -extern void drop_ux_task_cpus(struct task_struct *p, struct cpumask *lowest_mask); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /** * cpupri_find - find the best (lowest-pri) CPU in the system * @cp: The cpupri context @@ -114,14 +108,6 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p, if (lowest_mask) { cpumask_and(lowest_mask, &p->cpus_allowed, vec->mask); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_sched_assist_enabled) - drop_ux_task_cpus(p, lowest_mask); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined (CONFIG_SCHED_WALT) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE)|| sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) && oplus_task_misfit(p, task_cpu(p))) - kick_min_cpu_from_mask(lowest_mask); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * We have to ensure that we have at least one bit diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 91773073edcf..07475c078138 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -9,14 +9,6 @@ #include "sched.h" #include "walt.h" -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -#ifdef CONFIG_OPLUS_CTP -#include -#endif -#ifdef CONFIG_OPLUS_SCHED -#include -#endif -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ #ifdef CONFIG_IRQ_TIME_ACCOUNTING @@ -414,34 +406,14 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, * Also, p->stime needs to be updated for ksoftirqd. */ account_system_index_time(p, cputime, CPUTIME_SOFTIRQ); -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -#ifdef CONFIG_OPLUS_CTP - account_task_time(p, ticks, CPUTIME_SOFTIRQ); -#endif -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ } else if (user_tick) { account_user_time(p, cputime); -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -#ifdef CONFIG_OPLUS_CTP - account_task_time(p, ticks, CPUTIME_USER); -#endif -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ } else if (p == rq->idle) { account_idle_time(cputime); } else if (p->flags & PF_VCPU) { /* System time or guest time */ account_guest_time(p, cputime); -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -#ifdef CONFIG_OPLUS_CTP - account_task_time(p, ticks, CPUTIME_USER); -#endif -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ } else { account_system_index_time(p, cputime, CPUTIME_SYSTEM); -#ifdef OPLUS_FEATURE_TASK_CPUSTATS -#ifdef CONFIG_OPLUS_CTP - account_task_time(p, ticks, CPUTIME_SYSTEM); -#endif -#endif /* OPLUS_FEATURE_TASK_CPUSTATS */ } } @@ -525,12 +497,6 @@ void account_process_tick(struct task_struct *p, int user_tick) u64 cputime, steal; struct rq *rq = this_rq(); -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - if (ctp_send_message && (rq->cpu < 2)) { - sched_action_trig(); - ctp_send_message = false; - } -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ if (vtime_accounting_cpu_enabled()) return; @@ -548,24 +514,12 @@ void account_process_tick(struct task_struct *p, int user_tick) cputime -= steal; -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) - if (user_tick) { - account_user_time(p, cputime); - account_task_time(p, 1, CPUTIME_USER); - } else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) { - account_system_time(p, HARDIRQ_OFFSET, cputime); - account_task_time(p, 1, CPUTIME_SYSTEM); - } else { - account_idle_time(cputime); - } -#else if (user_tick) account_user_time(p, cputime); else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) account_system_time(p, HARDIRQ_OFFSET, cputime); else account_idle_time(cputime); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) */ } /* diff --git a/kernel/sched/eas_plus.c b/kernel/sched/eas_plus.c index ffe70b56c08b..999013253ee1 100755 --- a/kernel/sched/eas_plus.c +++ b/kernel/sched/eas_plus.c @@ -54,9 +54,6 @@ static int share_buck[3] = {0, 1, 2}; #define CCI_ID (arch_get_nr_clusters()) -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ static void update_system_overutilized(struct lb_env *env) @@ -817,10 +814,6 @@ static unsigned int aggressive_idle_pull(int this_cpu) */ if (hmp_cpu_is_slowest(this_cpu)) { hmp_slowest_idle_prefer_pull(this_cpu, &p, &target); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (p && sysctl_sched_assist_enabled && sched_assist_scene(SA_ANIM) && is_heavy_ux_task(p) && test_ux_task_cpu(task_cpu(p))) - goto done; -#endif if (p) { trace_sched_hmp_migrate(p, this_cpu, 0x10); moved = migrate_runnable_task(p, this_cpu, target); @@ -829,10 +822,6 @@ static unsigned int aggressive_idle_pull(int this_cpu) } } else { hmp_fastest_idle_prefer_pull(this_cpu, &p, &target); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (p && sysctl_sched_assist_enabled && sched_assist_scene(SA_ANIM) && is_heavy_ux_task(p) && test_ux_task_cpu(task_cpu(p))) - goto done; -#endif if (p) { trace_sched_hmp_migrate(p, this_cpu, 0x10); moved = migrate_runnable_task(p, this_cpu, target); @@ -1929,11 +1918,6 @@ void task_check_for_rotation(struct rq *src_rq) if (rq->nr_running > 1) continue; -#if defined (CONFIG_SCHED_WALT) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) - && (is_heavy_ux_task(rq->curr) || is_sf(rq->curr))) - continue; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ run = wc - rq->curr->last_enqueued_ts; if (run < TASK_ROTATION_THRESHOLD_NS) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c3d1a18b6a3f..c9ad3dc98d30 100755 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -35,43 +35,15 @@ #include #include -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) -#include -#endif /*OPLUS_FEATURE_IOMONITOR*/ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ #include "sched.h" #include "tune.h" #include "walt.h" #include "eas_plus.h" #include "hmp.h" -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -bool ux_task_misfit(struct task_struct *p, int cpu); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef CONFIG_OPLUS_PREFER_SILVER -#include -#endif /* CONFIG_OPLUS_PREFER_SILVER */ -#ifdef OPLUS_FEATURE_HEALTHINFO -// Add for get cpu load -#ifdef CONFIG_OPLUS_HEALTHINFO -#include -#endif -#endif /* OPLUS_FEATURE_HEALTHINFO */ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -#include -extern u64 ux_task_load[]; -extern u64 ux_load_ts[]; -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#define scale_demand(d) ((d)/walt_scale_demand_divisor) -#define UX_LOAD_WINDOW 8000000 -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * Targeted preemption latency for CPU-bound tasks: * @@ -150,13 +122,8 @@ unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL; const_debug unsigned int sysctl_sched_migration_cost = 33000UL; #ifdef CONFIG_SCHED_WALT -#ifdef OPLUS_FEATURE_SCHED_ASSIST -unsigned int sysctl_sched_use_walt_cpu_util = 0; -unsigned int sysctl_sched_use_walt_task_util = 0; -#else /* OPLUS_FEATURE_SCHED_ASSIST */ unsigned int sysctl_sched_use_walt_cpu_util = 1; unsigned int sysctl_sched_use_walt_task_util = 1; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ __read_mostly unsigned int sysctl_sched_walt_cpu_high_irqload = (10 * NSEC_PER_MSEC); #endif @@ -193,10 +160,6 @@ unsigned int sysctl_sched_cfs_bandwidth_slice = 5000UL; */ unsigned int capacity_margin = 1280; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -#define DEFAULT_CAP_MARGIN_DVFS 1280 /* ~20% margin */ -unsigned int capacity_margin_dvfs = DEFAULT_CAP_MARGIN_DVFS; -#endif static inline void update_load_add(struct load_weight *lw, unsigned long inc) @@ -898,9 +861,6 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq, int force) } #endif /* CONFIG_SMP */ -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) -extern void update_jank_trace_info(struct task_struct *tsk, int trace_type, unsigned int cpu, u64 delta); -#endif /* OPLUS_FEATURE_HEALTHINFO */ /* * Update the current task's runtime statistics. @@ -935,9 +895,6 @@ static void update_curr(struct cfs_rq *cfs_rq) trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime); cpuacct_charge(curtask, delta_exec); account_group_exec_runtime(curtask, delta_exec); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - update_jank_trace_info(curtask, JANK_TRACE_RUNNING, cpu_of(rq_of(cfs_rq)), delta_exec); -#endif /* OPLUS_FEATURE_HEALTHINFO */ } account_cfs_rq_runtime(cfs_rq, delta_exec); @@ -989,16 +946,6 @@ update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) return; } trace_sched_stat_wait(p, delta); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for get sched latency stat - ohm_schedstats_record(OHM_SCHED_SCHEDLATENCY, p, (delta >> 20)); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - update_jank_trace_info(p, JANK_TRACE_RUNNABLE, 0, delta); -#endif /* OPLUS_FEATURE_HEALTHINFO */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_task_sched_info(p, delta, task_sched_info_runnable, cpu_of(rq_of(cfs_rq))); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ } schedstat_set(se->statistics.wait_max, @@ -1038,15 +985,6 @@ update_stats_enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) if (tsk) { account_scheduler_latency(tsk, delta >> 10, 1); trace_sched_stat_sleep(tsk, delta); -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - sched_assist_update_record(tsk, delta, TST_SLEEP); -#endif -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - update_jank_trace_info(tsk, JANK_TRACE_SSTATE, 0, delta); -#endif /* OPLUS_FEATURE_HEALTHINFO */ -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - update_task_sched_info(tsk, delta, task_sched_info_S, task_cpu(tsk)); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ } } if (block_start) { @@ -1062,37 +1000,13 @@ update_stats_enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) schedstat_add(se->statistics.sum_sleep_runtime, delta); if (tsk) { -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) - if (tsk->in_iowait) - update_task_sched_info(tsk, delta, task_sched_info_IO, task_cpu(tsk)); - else - update_task_sched_info(tsk, delta, task_sched_info_D, task_cpu(tsk)); -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */ if (tsk->in_iowait) { schedstat_add(se->statistics.iowait_sum, delta); schedstat_inc(se->statistics.iowait_count); trace_sched_stat_iowait(tsk, delta); -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) -// Add for get iowait - ohm_schedstats_record(OHM_SCHED_IOWAIT, tsk, (delta >> 20)); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ -#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR) - iomonitor_record_iowait(tsk, (delta >> 20)); -#endif /*OPLUS_FEATURE_IOMONITOR*/ } -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) - if(!tsk->in_iowait) { - ohm_schedstats_record(OHM_SCHED_DSTATE, tsk, (delta >> 20)); - } -#endif /*OPLUS_FEATURE_HEALTHINFO*/ -#if defined (OPLUS_FEATURE_HEALTHINFO) && defined (CONFIG_OPLUS_JANK_INFO) - update_jank_trace_info(tsk, JANK_TRACE_DSTATE, 0, delta); -#endif /* OPLUS_FEATURE_HEALTHINFO */ trace_sched_stat_blocked(tsk, delta); -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - sched_assist_update_record(tsk, delta, TST_SLEEP); -#endif trace_sched_blocked_reason(tsk); /* @@ -3836,12 +3750,6 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) static inline unsigned long task_util(struct task_struct *p) { - sf_task_util_record(p); -#ifdef CONFIG_SCHED_WALT - if (likely(!walt_disabled && (sysctl_sched_use_walt_task_util || (test_task_ux(p) && sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE)|| sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)))))) - return (p->ravg.demand / - (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif return READ_ONCE(p->se.avg.util_avg); } @@ -3854,11 +3762,6 @@ static inline unsigned long _task_util_est(struct task_struct *p) unsigned long task_util_est(struct task_struct *p) { -#ifdef CONFIG_SCHED_WALT - if (likely(!walt_disabled && (sysctl_sched_use_walt_task_util || (test_task_ux(p) && sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE)|| sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)))))) - return (p->ravg.demand / - (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif return max(task_util(p), _task_util_est(p)); } @@ -4057,9 +3960,6 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) /* ensure we never gain time by being placed backwards. */ se->vruntime = max_vruntime(se->vruntime, vruntime); -#ifdef OPLUS_FEATURE_SCHED_ASSIST - place_entity_adjust_ux_task(cfs_rq, se, initial); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } static void check_enqueue_throttle(struct cfs_rq *cfs_rq); @@ -4201,11 +4101,7 @@ static void __clear_buddies_skip(struct sched_entity *se) } } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) -#else static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) -#endif { if (cfs_rq->last == se) __clear_buddies_last(se); @@ -4367,10 +4263,6 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) left = curr; se = left; /* ideally we run the leftmost entity */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (should_ux_task_skip_further_check(se)) - return se; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * Avoid running the skip buddy, if running something else can * be done without getting too unfair. @@ -4401,11 +4293,6 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) */ if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) se = cfs_rq->next; -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if (sched_assist_pick_next_task_opt(cfs_rq, &se)) { - return se; - } -#endif clear_buddies(cfs_rq, se); return se; @@ -5493,9 +5380,6 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) flags = ENQUEUE_WAKEUP; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - enqueue_ux_thread(rq, p); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ for_each_sched_entity(se) { cfs_rq = cfs_rq_of(se); cfs_rq->h_nr_running++; @@ -5577,9 +5461,6 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) } flags |= DEQUEUE_SLEEP; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST - dequeue_ux_thread(rq, p); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ for_each_sched_entity(se) { cfs_rq = cfs_rq_of(se); cfs_rq->h_nr_running--; @@ -5599,11 +5480,6 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) #endif walt_dec_cumulative_runnable_avg(rq, p); } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if (!se && task_sleep) { - sched_assist_update_record(p, p->se.sum_exec_runtime - p->se.prev_sum_exec_runtime, TST_EXEC); - } -#endif util_est_dequeue(&rq->cfs, p, task_sleep); hrtick_update(rq); } @@ -6103,21 +5979,10 @@ static inline unsigned long cpu_util_rt(int cpu) return rt_rq->avg.util_avg; } -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && (CONFIG_SCHED_WALT) -extern oplus_get_cpu_util_mtk(int cpu ,u64 *walt_cpu_util, int *boosted); -#endif static inline unsigned long cpu_util_freq(int cpu) { #ifdef CONFIG_SCHED_WALT u64 walt_cpu_util; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - int boosted = false; - oplus_get_cpu_util_mtk(cpu, &walt_cpu_util,&boosted); - if(boosted) - return min_t(unsigned long, walt_cpu_util, capacity_orig_of(cpu)); - else - return min(cpu_util(cpu) + cpu_util_rt(cpu), capacity_orig_of(cpu)); -#else /* OPLUS_FEATURE_SCHED_ASSIST */ if (unlikely(walt_disabled || !sysctl_sched_use_walt_cpu_util)) { return min(cpu_util(cpu) + cpu_util_rt(cpu), capacity_orig_of(cpu)); @@ -6128,7 +5993,6 @@ static inline unsigned long cpu_util_freq(int cpu) do_div(walt_cpu_util, walt_ravg_window); return min_t(unsigned long, walt_cpu_util, capacity_orig_of(cpu)); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #else return min(cpu_util(cpu) + cpu_util_rt(cpu), capacity_orig_of(cpu)); #endif @@ -7650,13 +7514,6 @@ static int start_cpu(struct task_struct *p, bool prefer_idle, if (boosted && (task_util(p) >= stune_task_threshold)) return boosted ? rd->max_cap_orig_cpu : rd->min_cap_orig_cpu; -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (sysctl_sched_assist_enabled && (sysctl_slide_boost_enabled || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) && is_heavy_ux_task(p) && - (scale_demand(p->ravg.demand) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold)) { - return rd->max_cap_orig_cpu; - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ return rd->min_cap_orig_cpu; } @@ -7728,20 +7585,7 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu, if (walt_cpu_high_irqload(i)) continue; -#if defined (CONFIG_OPLUS_PREFER_SILVER) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_prefer_silver && sysctl_sched_assist_enabled) { - if (!prefer_silver_check_ux(p) && is_max_capacity_cpu(i)) { - if (prefer_silver_check_freq(cpu) && (prefer_silver_check_task_util(p) || prefer_silver_check_cpu_util(cpu))) { - continue; - } - } - } -#endif /* CONFIG_OPLUS_PREFER_SILVER && OPLUS_FEATURE_SCHED_ASSIST*/ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - if (should_ux_task_skip_cpu(p, i)) - continue; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * p's blocked utilization is still accounted for on prev_cpu * so prev_cpu will receive a negative bias due to the double @@ -8068,12 +7912,6 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu, * f) ACTIVE little core and use frequency core higher thane turning * point: backup_active_min_cpu */ -#if defined (OPLUS_FEATURE_SCHED_ASSIST) && defined (CONFIG_OPLUS_PREFER_SILVER) - trace_sched_cpu_skip(p, sysctl_prefer_silver, test_task_ux(p), - prefer_silver_check_freq(cpu), - prefer_silver_check_task_util(p), - prefer_silver_check_cpu_util(cpu)); -#endif /* CONFIG_OPLUS_PREFER_SILVER && OPLUS_FEATURE_SCHED_ASSIST */ if (prefer_idle) { if (best_idle_cpu == -1) @@ -8610,17 +8448,6 @@ pick_cpu: p, prev_cpu, new_cpu); select_reason = LB_HMP; } -#if defined (CONFIG_SCHED_WALT) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_sched_assist_enabled && (sysctl_slide_boost_enabled || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) && - is_heavy_ux_task(p) && ux_task_misfit(p, new_cpu)) { - find_ux_task_cpu(p, &new_cpu); - select_reason = LB_UX_BOOST; - } - if(sysctl_sched_assist_scene & SA_LAUNCH) { - if (set_ux_task_to_prefer_cpu(p, &new_cpu)) - select_reason = LB_UX_BOOST; - } -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ return select_reason | new_cpu; } @@ -8778,9 +8605,6 @@ static void set_skip_buddy(struct sched_entity *se) cfs_rq_of(se)->skip = se; } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern bool is_small_task(struct task_struct *task); -#endif /* * Preempt the current task with a newly woken task if needed: */ @@ -8837,19 +8661,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ find_matching_se(&se, &pse); update_curr(cfs_rq_of(se)); BUG_ON(!pse); -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if (unlikely(is_small_task(p))) { - if (!next_buddy_marked) - set_next_buddy(pse); - goto preempt; - } -#endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - if (should_ux_preempt_wakeup(p, curr)) - goto preempt; - else if (test_task_ux(curr)) - return; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ if (wakeup_preempt_entity(se, pse) == 1) { /* * Bias pick_next to pick the sched entity that is @@ -8940,9 +8751,6 @@ again: } while (cfs_rq); p = task_of(se); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - pick_ux_thread(rq, &p, &se); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * Since we haven't yet done put_prev_entity and if the selected task * is a different task than we started out with, try and touch the @@ -9525,19 +9333,6 @@ static int detach_tasks(struct lb_env *env, struct rq_flags *rf) if (!can_migrate_task(p, env)) goto next; -#if defined (CONFIG_OPLUS_PREFER_SILVER) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (sysctl_prefer_silver && sysctl_sched_assist_enabled) { - if (!prefer_silver_check_ux(p) && is_max_capacity_cpu(env->dst_cpu)) { - if (prefer_silver_check_freq(env->src_cpu) && (prefer_silver_check_task_util(p) || prefer_silver_check_cpu_util(env->src_cpu))) { - goto next; - } - } - } -#endif /* CONFIG_OPLUS_PREFER_SILVER && OPLUS_FEATURE_SCHED_ASSIST*/ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) - if (should_ux_task_skip_cpu(p, env->dst_cpu)) - goto next; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ load = task_h_load(p); if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed) @@ -9571,12 +9366,6 @@ static int detach_tasks(struct lb_env *env, struct rq_flags *rf) continue; next: -#if defined (CONFIG_OPLUS_PREFER_SILVER) && defined (OPLUS_FEATURE_SCHED_ASSIST) - trace_sched_cpu_skip(p, sysctl_prefer_silver, test_task_ux(p), - prefer_silver_check_freq(env->src_cpu), - prefer_silver_check_task_util(p), - prefer_silver_check_cpu_util(env->src_cpu)); -#endif /* CONFIG_OPLUS_PREFER_SILVER && OPLUS_FEATURE_SCHED_ASSIST*/ list_move_tail(&p->se.group_node, tasks); } @@ -12241,17 +12030,6 @@ static void rq_offline_fair(struct rq *rq) /* Ensure any throttled groups are reachable by pick_next_task */ unthrottle_offline_cfs_rqs(rq); } -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -bool ux_task_misfit(struct task_struct *p, int cpu) -{ - int num_mincpu = cpumask_weight(topology_core_cpumask(0)); - if ((scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.demand) >= sysctl_boost_task_threshold) && cpu < num_mincpu) - return true; - - return false; -} -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ static DEFINE_RAW_SPINLOCK(migration_lock); void check_for_migration(struct rq *rq, struct task_struct *p) @@ -12277,11 +12055,7 @@ void check_for_migration(struct rq *rq, struct task_struct *p) queue_work_on(cpu, system_highpri_wq, &wr->w); } } -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (rq->misfit_task_load || (sysctl_sched_assist_enabled && (sysctl_slide_boost_enabled || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT)) && is_heavy_ux_task(p) && ux_task_misfit(p, cpu))) { -#else if (rq->misfit_task_load) { -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ if (rq->curr->state != TASK_RUNNING || rq->curr->nr_cpus_allowed == 1) return; @@ -12290,13 +12064,8 @@ void check_for_migration(struct rq *rq, struct task_struct *p) rcu_read_lock(); new_cpu = select_task_rq_fair(p, cpu, SD_BALANCE_WAKE, 0, 1); rcu_read_unlock(); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - if (capacity_orig_of(new_cpu) > capacity_orig_of(cpu) && - (!should_hmp(cpu)|| (sysctl_sched_assist_enabled && (sysctl_slide_boost_enabled || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT)) && is_heavy_ux_task(p) && ux_task_misfit(p, cpu)))) { -#else if (capacity_orig_of(new_cpu) > capacity_orig_of(cpu) && !should_hmp(cpu)) { -#endif #if defined(CONFIG_SCHED_HMP) || defined(CONFIG_MTK_IDLE_BALANCE_ENHANCEMENT) raw_spin_unlock(&migration_lock); get_task_struct(p); diff --git a/kernel/sched/hmp.c b/kernel/sched/hmp.c index bc19c4afa8b1..fd0c2b75aba9 100644 --- a/kernel/sched/hmp.c +++ b/kernel/sched/hmp.c @@ -20,9 +20,6 @@ #include #include #include -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#include -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * Heterogenous multiprocessor (HMP) optimizations @@ -1052,11 +1049,7 @@ static void hmp_force_down_migration(int this_cpu) hmp_down_migration(this_cpu, &target_cpu, se, &clbenv) && !cpu_park(cpu_of(target))) { -#if defined (CONFIG_SCHED_WALT) && defined (OPLUS_FEATURE_SCHED_ASSIST) - if (p->state != TASK_DEAD && (!sysctl_sched_assist_enabled || !sched_assist_scene(SA_ANIM) || !is_heavy_ux_task(p))) { -#else if (p->state != TASK_DEAD) { -#endif /* defined (CONFIG_SCHED_WALT) && defined (OPLUS_FEATURE_SCHED_ASSIST) */ get_task_struct(p); target->active_balance = MIGR_DOWN_MIGRATE; target->push_cpu = target_cpu; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 646a9309aec0..5e937cd94272 100755 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -54,10 +54,6 @@ struct cpuidle_state; #define TASK_ON_RQ_QUEUED 1 #define TASK_ON_RQ_MIGRATING 2 -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 -extern int sysctl_uxchain_v2; -#endif extern __read_mostly int scheduler_running; @@ -933,9 +929,6 @@ struct rq { struct cpuidle_state *idle_state; int idle_state_idx; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST - struct list_head ux_thread_list; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ }; static inline int cpu_of(struct rq *rq) diff --git a/kernel/sched/sched_plus.h b/kernel/sched/sched_plus.h index d2b9f8a7fa3b..b19ff80a2a9a 100755 --- a/kernel/sched/sched_plus.h +++ b/kernel/sched/sched_plus.h @@ -11,9 +11,6 @@ * See http://www.gnu.org/licenses/gpl-2.0.html for more details. */ extern unsigned int capacity_margin; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -extern unsigned int capacity_margin_dvfs; -#endif extern void unthrottle_offline_rt_rqs(struct rq *rq); DECLARE_PER_CPU(struct hmp_domain *, hmp_cpu_domain); #include "../../drivers/misc/mediatek/base/power/include/mtk_upower.h" @@ -22,9 +19,6 @@ extern int l_plus_cpu; extern unsigned long get_cpu_util(int cpu); extern void init_sched_groups_capacity(int cpu, struct sched_domain *sd); extern unsigned int capacity_margin; -#if defined(OPLUS_FEATURE_SCHEDUTIL_USE_TL) && defined(CONFIG_SCHEDUTIL_USE_TL) -extern unsigned int capacity_margin_dvfs; -#endif #ifdef CONFIG_SMP #ifdef CONFIG_ARM64 diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8cf137913fdc..fba9b40c4a9c 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1821,9 +1821,6 @@ static struct sched_domain *build_sched_domain(struct sched_domain_topology_leve return sd; } -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern void update_ux_sched_cputopo(void); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ /* * Build sched domains for a given set of CPUs and attach the sched domains @@ -1907,9 +1904,6 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att update_asym_cpucapacity(cpumask_first(cpu_map)); ret = 0; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - update_ux_sched_cputopo(); -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ error: __free_domain_allocs(&d, alloc_state, cpu_map); return ret; diff --git a/kernel/sched/tune.c b/kernel/sched/tune.c index 1dd407679ee5..b9dd5f5985e9 100755 --- a/kernel/sched/tune.c +++ b/kernel/sched/tune.c @@ -690,31 +690,6 @@ int schedtune_task_boost(struct task_struct *p) return task_boost; } -#ifdef CONFIG_MTK_SCHED_BOOST -#include "eas_plus.h" -#include <../../drivers/misc/mediatek/sched/sched_ctl.h> -/* For multi-scheduling boost support */ -extern int sysctl_animation_type; -extern int sched_boost_type; -void oplus_task_sched_boost(struct task_struct *p, int *task_prefer) -{ - int boost = sched_boost_type == SCHED_FG_BOOST? 1 :0; - struct schedtune *st = NULL; - if(!boost) - return; - //filter top-app and foreground - rcu_read_lock(); - st = task_schedtune(p); - if (((st-> idx == 3) || (st-> idx == 1))){ - if (READ_ONCE(p->se.avg.util_avg) > sysctl_boost_task_threshold){ - *task_prefer = SCHED_PREFER_MEDIUM; - } - } - else - *task_prefer = SCHED_PREFER_LITTLE; - rcu_read_unlock(); -} -#endif int schedtune_prefer_idle(struct task_struct *p) { diff --git a/kernel/sched/walt.c b/kernel/sched/walt.c index c8ba352ea364..deee6fa8ecf3 100755 --- a/kernel/sched/walt.c +++ b/kernel/sched/walt.c @@ -311,11 +311,7 @@ u64 walt_irqload(int cpu) { } int walt_cpu_high_irqload(int cpu) { -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - return false; -#else /* OPLUS_FEATURE_SCHED_ASSIST */ return walt_irqload(cpu) >= sysctl_sched_walt_cpu_high_irqload; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ } static int account_busy_for_cpu_time(struct rq *rq, struct task_struct *p, @@ -818,9 +814,6 @@ void walt_mark_task_starting(struct task_struct *p) } wallclock = walt_ktime_clock(); -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - p->last_wake_ts = wallclock; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ p->ravg.mark_start = wallclock; } diff --git a/kernel/sched_assist/Kconfig b/kernel/sched_assist/Kconfig deleted file mode 100755 index 4a7313f0ca61..000000000000 --- a/kernel/sched_assist/Kconfig +++ /dev/null @@ -1,27 +0,0 @@ -config OPLUS_FEATURE_SCHED_ASSIST - tristate "sched_assist" - default n - help - turning sched for ui, render and so on to improve UX -config OPLUS_FEATURE_SCHED_SPREAD - bool "sched_spread" - default n - help - This is the uifirst 5.0 feature, which will spread tasks, - kick runnable time from task demand and adjust bg's time slice. -config OPLUS_FEATURE_AUDIO_OPT - bool "config audio opt" - default n - help - audio task schedule opt -config MMAP_LOCK_OPT - bool "config mmap lock opt" - default n - depends on OPLUS_FEATURE_SCHED_ASSIST - help - reduce sleep time in mmap lock -config OPLUS_ALLBOOST_OPT - bool "config allboost opt" - default n - help - Make the SCHED_ALL_BOOST function take effect diff --git a/kernel/sched_assist/Makefile b/kernel/sched_assist/Makefile deleted file mode 100755 index 61875582e24c..000000000000 --- a/kernel/sched_assist/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -obj-y += sched_assist_common.o -obj-y += sched_assist_mutex.o -obj-y += sched_assist_rwsem.o -obj-y += sched_assist_futex.o -obj-y += sched_assist_workqueue.o -obj-y += sched_assist_rt.o - -#qcom -ifeq ($(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM), y) -ifeq ($(VERSION).$(PATCHLEVEL), 5.4) -obj-y += sched_assist_slide.o -endif -#mtk -else -obj-$(CONFIG_SCHED_WALT) += sched_assist_slide_v1.o -endif diff --git a/kernel/sched_assist/sched_assist_binder.h b/kernel/sched_assist/sched_assist_binder.h deleted file mode 100755 index f95ee6ba2bf5..000000000000 --- a/kernel/sched_assist/sched_assist_binder.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_BINDER_H_ -#define _OPLUS_SCHED_BINDER_H_ -#include "sched_assist_common.h" - -extern const struct sched_class rt_sched_class; -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern inline bool is_audio_task(struct task_struct *task); -#endif -static inline void binder_set_inherit_ux(struct task_struct *thread_task, struct task_struct *from_task) -{ - if (from_task && test_set_inherit_ux(from_task)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, from_task->ux_state); - else - reset_inherit_ux(thread_task, from_task, INHERIT_UX_BINDER); - } else if (from_task && test_task_identify_ux(from_task, SA_TYPE_ID_CAMERA_PROVIDER)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } else if (from_task && (from_task->sched_class == &rt_sched_class)) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - else if (from_task && (is_audio_task(from_task))) { - if (!test_task_ux(thread_task)) - set_inherit_ux(thread_task, INHERIT_UX_BINDER, from_task->ux_depth, SA_TYPE_LIGHT); - } -#endif -} - -static inline void binder_unset_inherit_ux(struct task_struct *thread_task) -{ - if (test_inherit_ux(thread_task, INHERIT_UX_BINDER)) { - unset_inherit_ux(thread_task, INHERIT_UX_BINDER); - } -} -#endif /* _OPLUS_SCHED_BINDER_H_ */ diff --git a/kernel/sched_assist/sched_assist_common.c b/kernel/sched_assist/sched_assist_common.c deleted file mode 100755 index 46fd2c298774..000000000000 --- a/kernel/sched_assist/sched_assist_common.c +++ /dev/null @@ -1,2583 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include -#include <../kernel/sched/sched.h> -#include -#include -#include -#include <../fs/proc/internal.h> -#include -#include -#include -#include "sched_assist_common.h" -#include "sched_assist_slide.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) -#include -#include -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#include <../kernel/sched/walt/walt.h> -#else -#include <../kernel/sched/walt.h> -#endif - -#define THRESHOLD_BOOST 102 - -int ux_min_sched_delay_granularity; -int ux_max_inherit_exist = 1000; -int ux_max_inherit_granularity = 32; -int ux_min_migration_delay = 10; -int ux_max_over_thresh = 2000; - -/* Params for slide boost */ -int sysctl_animation_type = 0; -int sysctl_input_boost_enabled = 0; -int sysctl_sched_assist_ib_duration_coedecay = 1; -u64 sched_assist_input_boost_duration = 0; -int sched_assist_ib_duration_coedecay = 1; -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -int sysctl_sched_impt_tgid = 0; -#endif - -#define S2NS_T 1000000 - -static int param_ux_debug = 0; -unsigned int ux_uclamp_value = 256; -module_param_named(debug, param_ux_debug, uint, 0644); -module_param_named(ux_uclamp_value, ux_uclamp_value, uint, 0664); - -#define MAX_IMPT_SAVE_PID (2) -pid_t save_impt_tgid[MAX_IMPT_SAVE_PID]; -pid_t save_top_app_tgid; -unsigned int top_app_type; -struct cpumask nr_mask; - -struct ux_sched_cputopo ux_sched_cputopo; - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -DEFINE_PER_CPU(struct task_count_rq, task_lb_count); -void init_rq_cpu(int cpu) -{ - per_cpu(task_lb_count, cpu).ux_low = 0; - per_cpu(task_lb_count, cpu).ux_high = 0; - per_cpu(task_lb_count, cpu).top_low = 0; - per_cpu(task_lb_count, cpu).top_high = 0; - per_cpu(task_lb_count, cpu).foreground_low = 0; - per_cpu(task_lb_count, cpu).foreground_high = 0; - per_cpu(task_lb_count, cpu).background_low = 0; - per_cpu(task_lb_count, cpu).background_high = 0; -} -#endif - -static inline void sched_init_ux_cputopo(void) -{ - int i = 0; - - ux_sched_cputopo.cls_nr = 0; - for (; i < NR_CPUS; ++i) { - cpumask_clear(&ux_sched_cputopo.sched_cls[i].cpus); - ux_sched_cputopo.sched_cls[i].capacity = ULONG_MAX; - } -} - -void update_ux_sched_cputopo(void) -{ - unsigned long prev_cap = 0; - unsigned long cpu_cap = 0; - unsigned int cpu = 0; - int i = 0, insert_idx = 0, cls_nr = 0; - struct ux_sched_cluster sched_cls; - - /* reset prev cpu topo info */ - sched_init_ux_cputopo(); - - /* update new cpu topo info */ - for_each_possible_cpu(cpu) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - cpu_cap = arch_scale_cpu_capacity(cpu); -#else - cpu_cap = arch_scale_cpu_capacity(NULL, cpu); -#endif - - /* add cpu with same capacity into target sched_cls */ - if (cpu_cap == prev_cap) { - for (i = 0; i < ux_sched_cputopo.cls_nr; ++i) { - if (cpu_cap == ux_sched_cputopo.sched_cls[i].capacity) { - cpumask_set_cpu(cpu, &ux_sched_cputopo.sched_cls[i].cpus); - break; - } - } - - continue; - } - - cpumask_clear(&sched_cls.cpus); - cpumask_set_cpu(cpu, &sched_cls.cpus); - sched_cls.capacity = cpu_cap; - cls_nr = ux_sched_cputopo.cls_nr; - - if (!cls_nr) { - ux_sched_cputopo.sched_cls[cls_nr] = sched_cls; - } else { - for (i = 0; i <= ux_sched_cputopo.cls_nr; ++i) { - if (sched_cls.capacity < ux_sched_cputopo.sched_cls[i].capacity) { - insert_idx = i; - break; - } - } - if (insert_idx == ux_sched_cputopo.cls_nr) { - ux_sched_cputopo.sched_cls[insert_idx] = sched_cls; - } else { - for (; cls_nr > insert_idx; cls_nr--) { - ux_sched_cputopo.sched_cls[cls_nr] = ux_sched_cputopo.sched_cls[cls_nr-1]; - } - ux_sched_cputopo.sched_cls[insert_idx] = sched_cls; - } - } - ux_sched_cputopo.cls_nr++; - - prev_cap = cpu_cap; - } - - for (i = 0; i < ux_sched_cputopo.cls_nr; i++) - ux_debug("update ux sched cpu topology [cls_nr:%d cpus:%*pbl cap:%lu]", - i, cpumask_pr_args(&ux_sched_cputopo.sched_cls[i].cpus), ux_sched_cputopo.sched_cls[i].capacity); -} - -static inline struct task_struct *task_of(struct sched_entity *se) -{ - return container_of(se, struct task_struct, se); -} - -static int entity_before(struct sched_entity *a, struct sched_entity *b) -{ - return (s64)(a->vruntime - b->vruntime) < 0; -} - -static int entity_over(struct sched_entity *a, struct sched_entity *b) -{ - return (s64)(a->vruntime - b->vruntime) > (s64)ux_max_over_thresh * S2NS_T; -} - -extern const struct sched_class fair_sched_class; - -/* identify ux only opt in some case, but always keep it's id_type, and wont do inherit through test_task_ux() */ -bool test_task_identify_ux(struct task_struct *task, int id_type_ux) -{ - if (id_type_ux == SA_TYPE_ID_CAMERA_PROVIDER) { - struct task_struct *grp_leader = task->group_leader; - /* consider provider's HwBinder in configstream */ - if ((task->ux_state & SA_TYPE_LISTPICK) && (grp_leader->ux_state & SA_TYPE_ID_CAMERA_PROVIDER)) - return true; - return (task->ux_state & SA_TYPE_ID_CAMERA_PROVIDER) && (sysctl_sched_assist_scene & SA_CAMERA); - } else if (id_type_ux == SA_TYPE_ID_ALLOCATOR_SER) { - if (task && (task->ux_state & SA_TYPE_ID_ALLOCATOR_SER) && (sysctl_sched_assist_scene & SA_CAMERA)) - return true; - } - - return false; -} - -inline bool test_task_ux(struct task_struct *task) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - if (!task) - return false; - - if (task->sched_class != &fair_sched_class) - return false; -#ifdef CONFIG_KERNEL_LOCK_OPT - if (test_task_lock_ux(task)) - return true; -#endif - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - /* during gesture animation, top application should not be optimized except launcher */ - if (sched_assist_scene(SA_ANIM) && save_top_app_tgid && (task->tgid == save_top_app_tgid) && (top_app_type != 1)) - return false; -#endif - - if (task->ux_state & (SA_TYPE_HEAVY | SA_TYPE_LIGHT | SA_TYPE_ANIMATOR | SA_TYPE_LISTPICK)) - return true; - - return false; -} - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -static unsigned long task_util_mtk(struct task_struct *p, bool flag) -{ -#ifdef CONFIG_SCHED_WALT - if (likely(!walt_disabled && (sysctl_sched_use_walt_task_util || flag))) - return (p->ravg.demand / (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif - return READ_ONCE(p->se.avg.util_avg); -} -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_MTK */ - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -#define NR_IMBALANCE_THRESHOLD (24) -void update_rq_nr_imbalance(int cpu) -{ - int total_nr = 0; - int i = -1; - int threshold = NR_IMBALANCE_THRESHOLD; - - /* Note: check without holding rq lock */ - for_each_cpu(i, cpu_active_mask) { - total_nr += cpu_rq(i)->cfs.nr_running; - if (idle_cpu(i)) - cpumask_clear_cpu(i, &nr_mask); - } - - if (!idle_cpu(cpu) && (total_nr >= threshold)) { - cpumask_set_cpu(cpu, &nr_mask); - } else { - cpumask_clear_cpu(cpu, &nr_mask); - } -} - -bool should_force_spread_tasks(void) { - return !cpumask_empty(&nr_mask); -} - -#ifdef CONFIG_CGROUP_SCHED -static inline int task_cgroup_id(struct task_struct *task) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - struct cgroup_subsys_state *css = task_css(task, cpu_cgrp_id); -#else - struct cgroup_subsys_state *css = task_css(task, schedtune_cgrp_id); -#endif - - return css ? css->id : -1; -} -#else -static inline int task_cgroup_id(struct task_struct *task) -{ - return -1; -} -#endif - -int task_lb_sched_type(struct task_struct *tsk) -{ - int cgroup_type = task_cgroup_id(tsk); - - if (test_task_ux(tsk)) - return SA_UX; - else if (cgroup_type == SA_CGROUP_TOP_APP) - return SA_TOP; - else if (cgroup_type == SA_CGROUP_FOREGROUD || cgroup_type == SA_CGROUP_DEFAULT) - return SA_FG; - else if (cgroup_type == SA_CGROUP_BACKGROUD) - return SA_BG; - - return -1; -} - -#ifdef CONFIG_SCHED_WALT -bool task_high_load(struct task_struct *tsk) -{ - unsigned int cpu = 0; - unsigned long capacity = capacity_orig_of(cpu); - unsigned long max_capacity = cpu_rq(cpu)->rd->max_cpu_capacity.val; - unsigned int margin; - int sched_type = task_lb_sched_type(tsk); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - unsigned long load = tsk->wts.demand_scaled; -#else - unsigned long load = (tsk->ravg.demand / (walt_ravg_window >> SCHED_CAPACITY_SHIFT)); -#endif - - if (sched_type == SA_BG) - load = min(load, tsk->se.avg.util_avg); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - load = clamp(load, - uclamp_eff_value(tsk, UCLAMP_MIN), - uclamp_eff_value(tsk, UCLAMP_MAX)); -#endif - if (capacity == max_capacity) - return true; - - if (capacity_orig_of(task_cpu(tsk)) > capacity_orig_of(cpu)) - margin = sched_capacity_margin_down[cpu]; - else - margin = sched_capacity_margin_up[task_cpu(tsk)]; - - return capacity * 1024 < load * margin; -} -#endif -void dec_task_lb(struct task_struct *tsk, struct rq *rq, - int high_load, int task_type) -{ - int cpu = cpu_of(rq); - - if (high_load == SA_HIGH_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_high--; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_high--; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_high--; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_high--; - break; - } - } else if (high_load == SA_LOW_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_low--; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_low--; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_low--; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_low--; - break; - } - } -} - -void inc_task_lb(struct task_struct *tsk, struct rq *rq, - int high_load, int task_type) -{ - int cpu = cpu_of(rq); - - if (high_load == SA_HIGH_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_high++; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_high++; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_high++; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_high++; - break; - } - } else if (high_load == SA_LOW_LOAD) { - switch (task_type) { - case SA_UX: - per_cpu(task_lb_count, cpu).ux_low++; - break; - case SA_TOP: - per_cpu(task_lb_count, cpu).top_low++; - break; - case SA_FG: - per_cpu(task_lb_count, cpu).foreground_low++; - break; - case SA_BG: - per_cpu(task_lb_count, cpu).background_low++; - break; - } - } -} - -void update_load_flag(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = task_high_load(tsk); - int curr_task_type = task_lb_sched_type(tsk); - - if (tsk->lb_state != 0) { - int prev_high_load = tsk->lb_state & 0x1; - int prev_task_type = (tsk->lb_state >> 1) & 0x7; - - if (prev_high_load == curr_high_load && prev_task_type == curr_task_type) - return; - else - dec_task_lb(tsk, rq, prev_high_load, prev_task_type); - } - inc_task_lb(tsk, rq, curr_high_load, curr_task_type); - tsk->lb_state = (curr_task_type << 1) | curr_high_load; -} - -void inc_ld_stats(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = tsk->lb_state & 0x1; - int curr_task_type = (tsk->lb_state >> 1) & 0x7; - - inc_task_lb(tsk, rq, curr_high_load, curr_task_type); - tsk->ld_flag = 1; -} - -void dec_ld_stats(struct task_struct *tsk, struct rq *rq) -{ - int curr_high_load = tsk->lb_state & 0x1; - int curr_task_type = (tsk->lb_state >> 1) & 0x7; - - tsk->ld_flag = 0; - dec_task_lb(tsk, rq, curr_high_load, curr_task_type); -} - -#define MAX_ADJ_NICE (5) -#define MAX_ADJ_PRIO (DEFAULT_PRIO + MAX_ADJ_NICE - 1) -const int sched_prio_to_weight_bg[MAX_ADJ_NICE] = { 716, 601, 510, 438, 380, }; -const int sched_prio_to_wmult_bg[MAX_ADJ_NICE] = { 5998558, 7146368, 8421505, 9805861, 11302546, }; - -/* keep same as defined in sched/fair.c */ -#define OPLUS_WMULT_CONST (~0U) -#define OPLUS_WMULT_SHIFT 32 - -/* keep same as defined in sched/fair.c */ -static void __oplus_update_inv_weight(struct load_weight *lw) -{ - unsigned long w; - - if (likely(lw->inv_weight)) - return; - - w = scale_load_down(lw->weight); - - if (BITS_PER_LONG > 32 && unlikely(w >= OPLUS_WMULT_CONST)) - lw->inv_weight = 1; - else if (unlikely(!w)) - lw->inv_weight = OPLUS_WMULT_CONST; - else - lw->inv_weight = OPLUS_WMULT_CONST / w; -} - -static struct load_weight sa_new_weight(struct sched_entity *se) { - struct task_struct *task = NULL; - struct load_weight lw; - int sched_type = -1; - int idx = -1; - int i = 0; - - if ((sysctl_sched_assist_enabled < 2) || !entity_is_task(se) || sched_assist_scene(SA_CAMERA)) { - return se->load; - } - - task = container_of(se, struct task_struct, se); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if ((task->static_prio < DEFAULT_PRIO) || (task->static_prio > MAX_ADJ_PRIO) || (task_util(task) < 51)) -#else - if ((task->static_prio < DEFAULT_PRIO) || (task->static_prio > MAX_ADJ_PRIO) || (task_util_mtk(task, true) < 51)) -#endif - return se->load; - - /* skip important process such as audio proc */ - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] && (task->tgid == save_impt_tgid[i])) - return se->load; - } - - /* we only adjust background group's load weight */ - sched_type = task_lb_sched_type(task); - if (sched_type != SA_BG) - return se->load; - - idx = task->static_prio - DEFAULT_PRIO; - lw.weight = scale_load(sched_prio_to_weight_bg[idx]); - lw.inv_weight = sched_prio_to_wmult_bg[idx]; - - return lw; -} - -u64 sa_calc_delta(struct sched_entity *se, u64 delta_exec, unsigned long weight, struct load_weight *lw, bool calc_fair) -{ - u64 fact = 0; - u32 inv_weight = 0; - int shift = OPLUS_WMULT_SHIFT; - struct load_weight sa_lw = sa_new_weight(se); - - if (calc_fair && (sa_lw.weight == lw->weight) && (lw->weight == NICE_0_LOAD)) - return delta_exec; - - __oplus_update_inv_weight(lw); - - if (calc_fair) { /* __calc_delta(delta, NICE_0_LOAD, &se->load) */ - fact = scale_load_down(weight); - inv_weight = sa_lw.inv_weight; - } else { /* __calc_delta(slice, sa_lw.weight, load) */ - fact = scale_load_down(sa_lw.weight); - inv_weight = lw->inv_weight; - } - - if (unlikely(fact >> 32)) { - while (fact >> 32) { - fact >>= 1; - shift--; - } - } - - /* hint to use a 32x32->64 mul */ - fact = (u64)(u32)fact * inv_weight; - - while (fact >> 32) { - fact >>= 1; - shift--; - } - - return mul_u64_u32_shr(delta_exec, fact, shift); -} - -bool should_force_adjust_vruntime(struct sched_entity *se) -{ - struct task_struct *se_task = NULL; - - if (sysctl_sched_assist_enabled < 2 || sched_assist_scene(SA_CAMERA)) - return false; - - if (!entity_is_task(se)) - return false; - - se_task = task_of(se); - /* requeue runnable inherit ux task should be adjusted */ - if (se_task && (se_task->ux_state & SA_TYPE_INHERIT)) - return true; - - return false; -} -static void find_spread_lowest_nr_cpu(struct task_struct *p, cpumask_t *visit_cpus_t, int sched_type, int prev_cpu, int skip_cpu, - int *lowest_nr, int *lowest_nr_load, int *lowest_nr_cpu) -{ - int i = 0; - for_each_cpu(i, visit_cpus_t) { - int ux_nr = 0; - int top_nr = 0; - int fg_nr = 0; - int bg_nr = 0; - int rq_nr = 0; - int rq_nr_load = 0; - - if (!cpu_active(i) || cpu_isolated(i)) - continue; - if (is_reserved(i)) - continue; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (sched_cpu_high_irqload(i)) - continue; -#endif -#ifdef CONFIG_MTK_SCHED_INTEROP - if (cpu_rq(i)->rt.rt_nr_running && - likely(!is_rt_throttle(i))) - continue; -#endif - if (skip_cpu == i) - continue; - - ux_nr = per_cpu(task_lb_count, i).ux_high + per_cpu(task_lb_count, i).ux_low; - top_nr = per_cpu(task_lb_count, i).top_high + per_cpu(task_lb_count, i).top_low; - fg_nr = per_cpu(task_lb_count, i).foreground_high + per_cpu(task_lb_count, i).foreground_low; - bg_nr = per_cpu(task_lb_count, i).background_high + per_cpu(task_lb_count, i).background_low; - - if (sched_type == SA_UX) { - rq_nr = ux_nr; - } else if (sched_type == SA_TOP) { - rq_nr = ux_nr + top_nr; - } else if (sched_type == SA_FG) { - rq_nr = ux_nr + top_nr + fg_nr; - } else if (sched_type == SA_BG) { - rq_nr = ux_nr + top_nr + fg_nr + bg_nr; - } - - rq_nr_load = 1000 * ux_nr + 100 * top_nr + 10 * fg_nr + bg_nr; - - if (rq_nr > *lowest_nr) { - continue; - } - - if (rq_nr == *lowest_nr) { - if (rq_nr_load < *lowest_nr_load) - goto find; - if (rq_nr_load == *lowest_nr_load && i == prev_cpu) - goto find; - - continue; - } - -find: - *lowest_nr = rq_nr; - *lowest_nr_load = rq_nr_load; - *lowest_nr_cpu = i; - } -} -#if !defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) || (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int start_cpu, int skip_cpu, cpumask_t *cpus, bool strict) -{ - int sched_type = task_lb_sched_type(p); - int cluster; - cpumask_t visit_cpus; - int lowest_nr = INT_MAX; - int lowest_nr_load = INT_MAX; - int lowest_nr_cpu = -1; - int prev_cpu = task_cpu(p); - bool force_spread = false; - int tmp_idx = 0; - int order_index = 0; - int end_index = 0; - struct ux_sched_cputopo cputopo = ux_sched_cputopo; - - if (!is_spread_task_enabled()) - return; - if (cputopo.cls_nr <= 1 || sched_type == -1) - return; - for (cluster = 0; cluster < cputopo.cls_nr; cluster++) { - if (start_cpu == cpumask_first(&cputopo.sched_cls[cluster].cpus)) { - order_index = cluster; - break; - } - } - /* add for launch boost */ - if (sched_assist_scene(SA_LAUNCH) && is_heavy_ux_task(p)) { - strict = true; - order_index = cputopo.cls_nr - 1; - end_index = (p->pid == p->tgid) ? 0 : 1; - } - /* in launch or animation scene, force scheduler to spread tasks */ - if (should_force_spread_tasks()) - force_spread = true; - else - return; - tmp_idx = order_index; - for (cluster = 0; cluster < cputopo.cls_nr; cluster++) { - cpumask_and(&visit_cpus, &new_allowed_cpus, - &cputopo.sched_cls[tmp_idx].cpus); - find_spread_lowest_nr_cpu(p, &visit_cpus, sched_type, prev_cpu, skip_cpu, - &lowest_nr, &lowest_nr_load, &lowest_nr_cpu); - /* - * order_index <= 1, order is cluster(0-1-2 or 1-2-0) - * order_index > 1, order is cluster(2-1-0) - */ - if (order_index <= 1) { - tmp_idx++; - } else { - tmp_idx--; - } - if (tmp_idx >= cputopo.cls_nr) - tmp_idx = 0; - if (tmp_idx < 0) - tmp_idx = cputopo.cls_nr - 1; - /* should we visit next cluster? */ - if (strict && cluster >= end_index) { - break; - } - if (force_spread) - continue; - break; - } - if (lowest_nr_cpu != -1) { - cpumask_set_cpu(lowest_nr_cpu, cpus); - } -} -#else -void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int order_index, int end_index, int skip_cpu, cpumask_t *cpus, bool strict) -{ - int sched_type = task_lb_sched_type(p); - int cluster; - cpumask_t visit_cpus; - int lowest_nr = INT_MAX; - int lowest_nr_load = INT_MAX; - int lowest_nr_cpu = -1; - int prev_cpu = task_cpu(p); - bool force_spread = false; - - if (!is_spread_task_enabled()) - return; - if (num_sched_clusters <= 1 || sched_type == -1) - return; - /* add for launch boost */ - if (sched_assist_scene(SA_LAUNCH) && is_heavy_ux_task(p)) { - strict = true; - order_index = num_sched_clusters - 1; - end_index = (p->pid == p->tgid) ? 0 : 1; - } - /* in launch or animation scene, force scheduler to spread tasks */ - if (should_force_spread_tasks()) - force_spread = true; - else - return; - for (cluster = 0; cluster < num_sched_clusters; cluster++) { - cpumask_and(&visit_cpus, &new_allowed_cpus, - &cpu_array[order_index][cluster]); - find_spread_lowest_nr_cpu(p, &visit_cpus, sched_type, prev_cpu, skip_cpu, - &lowest_nr, &lowest_nr_load, &lowest_nr_cpu); - /* should we visit next cluster? */ - if (strict && cluster >= end_index) { - break; - } - if (force_spread) - continue; - break; - } - if (lowest_nr_cpu != -1) { - cpumask_set_cpu(lowest_nr_cpu, cpus); - } -} -#endif -#endif - -inline int get_ux_state_type(struct task_struct *task) -{ - if (!task) { - return UX_STATE_INVALID; - } - - if (task->sched_class != &fair_sched_class) - return UX_STATE_INVALID; - - if (task->ux_state & SA_TYPE_INHERIT) - return UX_STATE_INHERIT; - - if (task->ux_state & (SA_TYPE_HEAVY | SA_TYPE_LIGHT | SA_TYPE_ANIMATOR | SA_TYPE_LISTPICK)) - return UX_STATE_SCHED_ASSIST; - - return UX_STATE_NONE; -} - -inline bool test_list_pick_ux(struct task_struct *task) -{ - return (task->ux_state & SA_TYPE_LISTPICK) || (task->ux_state & SA_TYPE_ONCE_UX) || -#ifdef CONFIG_KERNEL_LOCK_OPT - test_task_identify_ux(task, SA_TYPE_ID_ALLOCATOR_SER) || test_task_lock_ux(task); -#else - test_task_identify_ux(task, SA_TYPE_ID_ALLOCATOR_SER); -#endif -} - -void enqueue_ux_thread(struct rq *rq, struct task_struct *p) -{ - struct list_head *pos, *n; - bool exist = false; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - if (!rq || !p || !list_empty(&p->ux_entry)) { - return; - } - - p->enqueue_time = rq->clock; - if (test_list_pick_ux(p)) { - list_for_each_safe(pos, n, &rq->ux_thread_list) { - if (pos == &p->ux_entry) { - exist = true; - break; - } - } - if (!exist) { - list_add_tail(&p->ux_entry, &rq->ux_thread_list); - get_task_struct(p); - } - } -} - -#define ux_max_dynamic_granularity ((u64)(64 * S2NS_T)) -void dequeue_ux_thread(struct rq *rq, struct task_struct *p) -{ - struct list_head *pos, *n; - - if (!rq || !p) { - return; - } - p->enqueue_time = 0; - if (!list_empty(&p->ux_entry)) { - u64 now = jiffies_to_nsecs(jiffies); - list_for_each_safe(pos, n, &rq->ux_thread_list) { - if (pos == &p->ux_entry) { - list_del_init(&p->ux_entry); - if (p->ux_state & SA_TYPE_ONCE_UX) { - p->ux_state &= ~SA_TYPE_ONCE_UX; - } - if (get_ux_state_type(p) == UX_STATE_INHERIT && - now - p->inherit_ux_start > ux_max_dynamic_granularity) { - p->ux_state &= ~SA_TYPE_LISTPICK; - } - put_task_struct(p); - return; - } - } - } -} - -static struct task_struct *pick_first_ux_thread(struct rq *rq) -{ - struct list_head *ux_thread_list = &rq->ux_thread_list; - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct task_struct *temp = NULL; - struct task_struct *leftmost_task = NULL; - list_for_each_safe(pos, n, ux_thread_list) { - temp = list_entry(pos, struct task_struct, ux_entry); - /*ensure ux task in current rq cpu otherwise delete it*/ - if (unlikely(task_cpu(temp) != rq->cpu)) { - list_del_init(&temp->ux_entry); - put_task_struct(temp); - continue; - } - if (unlikely(!test_list_pick_ux(temp))) { - list_del_init(&temp->ux_entry); - put_task_struct(temp); - continue; - } - - if (leftmost_task == NULL) { - leftmost_task = temp; - } else if (entity_before(&temp->se, &leftmost_task->se)) { - leftmost_task = temp; - } - } - - return leftmost_task; -} - -void pick_ux_thread(struct rq *rq, struct task_struct **p, struct sched_entity **se) -{ - struct task_struct *ori_p = *p; - struct task_struct *key_task; - struct sched_entity *key_se; - - if (!rq || !ori_p || !se) { - return; - } - -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if ((*p)->oplus_task_info.im_small) - return; -#endif - if ((ori_p->ux_state & SA_TYPE_ANIMATOR) || test_list_pick_ux(ori_p)) - return; - - if (!list_empty(&rq->ux_thread_list)) { - key_task = pick_first_ux_thread(rq); - /* in case that ux thread keep running too long */ - if (key_task && entity_over(&key_task->se, &ori_p->se)) - return; - - if (key_task) { - key_se = &key_task->se; - if (key_se && (rq->clock >= key_task->enqueue_time) && - rq->clock - key_task->enqueue_time >= ((u64)ux_min_sched_delay_granularity * S2NS_T)) { - *p = key_task; - *se = key_se; - } - } - } -} - -#define INHERIT_UX_SEC_WIDTH 8 -#define INHERIT_UX_MASK_BASE 0x00000000ff - -#define inherit_ux_offset_of(type) (type * INHERIT_UX_SEC_WIDTH) -#define inherit_ux_mask_of(type) ((u64)(INHERIT_UX_MASK_BASE) << (inherit_ux_offset_of(type))) -#define inherit_ux_get_bits(value, type) ((value & inherit_ux_mask_of(type)) >> inherit_ux_offset_of(type)) -#define inherit_ux_value(type, value) ((u64)value << inherit_ux_offset_of(type)) - - -bool test_inherit_ux(struct task_struct *task, int type) -{ - u64 inherit_ux; - if (!task) { - return false; - } - inherit_ux = atomic64_read(&task->inherit_ux); - return inherit_ux_get_bits(inherit_ux, type) > 0; -} - -static bool test_task_exist(struct task_struct *task, struct list_head *head) -{ - struct list_head *pos, *n; - list_for_each_safe(pos, n, head) { - if (pos == &task->ux_entry) { - return true; - } - } - return false; -} - -inline void inherit_ux_inc(struct task_struct *task, int type) -{ - atomic64_add(inherit_ux_value(type, 1), &task->inherit_ux); -} - -inline void inherit_ux_sub(struct task_struct *task, int type, int value) -{ - atomic64_sub(inherit_ux_value(type, value), &task->inherit_ux); -} - -static void __inherit_ux_dequeue(struct task_struct *task, int type, int value) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - bool exist = false; - struct rq *rq = NULL; - u64 inherit_ux = 0; - - rq = task_rq_lock(task, &flags); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux <= 0) { - task_rq_unlock(rq, task, &flags); - return; - } - inherit_ux_sub(task, type, value); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux > 0) { - task_rq_unlock(rq, task, &flags); - return; - } - task->ux_depth = 0; - - exist = test_task_exist(task, &rq->ux_thread_list); - if (exist) { - list_del_init(&task->ux_entry); - put_task_struct(task); - } - task_rq_unlock(rq, task, &flags); -} - -void inherit_ux_dequeue(struct task_struct *task, int type) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_dequeue(task, type, 1); -} -void inherit_ux_dequeue_refs(struct task_struct *task, int type, int value) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_dequeue(task, type, value); -} - -static void __inherit_ux_enqueue(struct task_struct *task, int type, int depth) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - bool exist = false; - struct rq *rq = NULL; - - rq = task_rq_lock(task, &flags); - - if (unlikely(!list_empty(&task->ux_entry))) { - task_rq_unlock(rq, task, &flags); - return; - } - - inherit_ux_inc(task, type); - task->inherit_ux_start = jiffies_to_nsecs(jiffies); - task->ux_depth = task->ux_depth > depth + 1 ? task->ux_depth : depth + 1; - if (task->state == TASK_RUNNING && task->sched_class == &fair_sched_class) { - exist = test_task_exist(task, &rq->ux_thread_list); - if (!exist) { - get_task_struct(task); - list_add_tail(&task->ux_entry, &rq->ux_thread_list); - } - } - task_rq_unlock(rq, task, &flags); -} - -void inherit_ux_enqueue(struct task_struct *task, int type, int depth) -{ - if (!task || type >= INHERIT_UX_MAX) { - return; - } - __inherit_ux_enqueue(task, type, depth); -} - -inline bool test_task_ux_depth(int ux_depth) -{ - return ux_depth < UX_DEPTH_MAX; -} - -inline bool test_set_inherit_ux(struct task_struct *tsk) -{ - return tsk && test_task_ux(tsk) && test_task_ux_depth(tsk->ux_depth); -} - -void ux_init_rq_data(struct rq *rq) -{ - if (!rq) { - return; - } - - INIT_LIST_HEAD(&rq->ux_thread_list); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - cpumask_clear(&nr_mask); - - per_cpu(task_lb_count, cpu_of(rq)).ux_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).ux_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).top_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).top_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).foreground_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).foreground_high = 0; - per_cpu(task_lb_count, cpu_of(rq)).background_low = 0; - per_cpu(task_lb_count, cpu_of(rq)).background_high = 0; -#endif -} - -int ux_prefer_cpu[NR_CPUS] = {0}; -void ux_init_cpu_data(void) { - int i = 0; - int min_cpu = 0, ux_cpu = 0; - - for (; i < nr_cpu_ids; ++i) { - ux_prefer_cpu[i] = -1; - } - - ux_cpu = cpumask_weight(topology_core_cpumask(min_cpu)); - if (ux_cpu == 0) { - ux_warn("failed to init ux cpu data\n"); - return; - } - - for (i = 0; i < nr_cpu_ids && ux_cpu < nr_cpu_ids; ++i) { - ux_prefer_cpu[i] = ux_cpu++; - } -} - -bool test_ux_task_cpu(int cpu) { - return (cpu >= ux_prefer_cpu[0]); -} - -bool test_ux_prefer_cpu(struct task_struct *tsk, int cpu) { - struct root_domain *rd = cpu_rq(smp_processor_id())->rd; - - if (cpu < 0) - return false; - - if (tsk->pid == tsk->tgid) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - return cpu >= rd->wrd.max_cap_orig_cpu; -#else - return cpu >= rd->max_cap_orig_cpu; -#endif -#else - return capacity_orig_of(cpu) >= rd->max_cpu_capacity.val; -#endif /*CONFIG_OPLUS_SYSTEM_KERNEL_QCOM*/ - } - - return (cpu >= ux_prefer_cpu[0]); -} - -void find_ux_task_cpu(struct task_struct *tsk, int *target_cpu) { - int i = 0; - int temp_cpu = 0; - struct rq *rq = NULL; - for (i = (nr_cpu_ids - 1); i >= 0; --i) { - temp_cpu = ux_prefer_cpu[i]; - if (temp_cpu <= 0 || temp_cpu >= nr_cpu_ids) - continue; - - rq = cpu_rq(temp_cpu); - if (!rq) - continue; - - if (rq->curr->prio <= MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!test_task_ux(rq->curr) && cpu_online(temp_cpu) && !cpu_isolated(temp_cpu) - && cpumask_test_cpu(temp_cpu, tsk->cpus_ptr)) { -#else - if (!test_task_ux(rq->curr) && cpu_online(temp_cpu) && !cpu_isolated(temp_cpu) - && cpumask_test_cpu(temp_cpu, &tsk->cpus_allowed)) { -#endif - *target_cpu = temp_cpu; - return; - } - } - return; -} - -static inline bool oplus_is_min_capacity_cpu(int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - - if (unlikely(cls_nr <= 0)) - return false; - - return capacity_orig_of(cpu) == ux_cputopo.sched_cls[0].capacity; -} - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -extern unsigned long capacity_curr_of(int cpu); -#endif -/* - * taget cpu is - * unboost: the one in all domain, with lowest prio running task - * boost: the one in power domain, with lowest prio running task which is not ux - * !!this func will ignore task's start cpu -*/ -int set_ux_task_cpu_common_by_prio(struct task_struct *task, int *target_cpu, bool boost, bool prefer_idle, unsigned int type) -{ - int i; - int lowest_prio = INT_MIN; - unsigned long lowest_prio_max_cap = 0; - int ret = -1; - - if (unlikely(!sysctl_sched_assist_enabled)) - return -1; - - if (!(task->ux_state & SA_TYPE_ANIMATOR) && !test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER)) - return -1; - - if ((*target_cpu < 0) || (*target_cpu >= NR_CPUS)) - return -1; - -#ifdef CONFIG_SCHED_WALT - if (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - boost = ((scale_demand(task->wts.sum) >= THRESHOLD_BOOST) || -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - (task_util(task) >= THRESHOLD_BOOST)) ? true : false; -#else - (task_util_mtk(task, true) >= THRESHOLD_BOOST)) ? true : false; -#endif -#else /* KERNEL-5-4 */ - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - boost = ((scale_demand(task->ravg.sum) >= THRESHOLD_BOOST) || - (task_util(task) >= THRESHOLD_BOOST)) ? true : false; -#else - boost = (scale_demand(task->ravg.sum) >= THRESHOLD_BOOST); -#endif - -#endif /* KERNEL-5-4 */ - } -#endif /* CONFIG_SCHED_WALT */ - - for_each_cpu(i, cpu_active_mask) { - unsigned long capacity_curr; - struct task_struct *curr; - bool curr_ux = false; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!cpumask_test_cpu(i, task->cpus_ptr) || cpu_isolated(i)) -#else - if (!cpumask_test_cpu(i, &task->cpus_allowed) || cpu_isolated(i)) -#endif - continue; - - /* avoid placing task into high power cpu and break it's idle state if !prefer_idle */ - if (prefer_idle && idle_cpu(i)) { - *target_cpu = i; - return 0; - } - - curr = cpu_rq(i)->curr; - /* avoid placing task into cpu with rt */ - if (!curr || !(curr->sched_class == &fair_sched_class)) - continue; - - curr_ux = test_task_ux(curr) || test_task_identify_ux(curr, SA_TYPE_ID_CAMERA_PROVIDER); - if (curr_ux) - continue; - - capacity_curr = capacity_curr_of(i); - if ((curr->prio > lowest_prio) || (boost && (capacity_curr > lowest_prio_max_cap))) { - lowest_prio = curr->prio; - lowest_prio_max_cap = capacity_curr; - *target_cpu = i; - ret = 0; - } - } - - return ret; -} - -bool is_sf(struct task_struct *p) -{ - return (task_index_of_sf_union(p) >= 0); -} - -void drop_ux_task_cpus(struct task_struct *p, struct cpumask *lowest_mask) -{ - unsigned int cpu = cpumask_first(lowest_mask); -#ifdef CONFIG_SCHED_WALT - bool sf = false; -#endif - - while (cpu < nr_cpu_ids) { - /* unlocked access */ - struct task_struct *task = READ_ONCE(cpu_rq(cpu)->curr); - - if ((sysctl_sched_assist_scene & SA_LAUNCH) && (task->ux_state & SA_TYPE_HEAVY)) - cpumask_clear_cpu(cpu, lowest_mask); - - if (test_task_ux(task) || !list_empty(&task->ux_entry) || - (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER) && oplus_is_min_capacity_cpu(cpu))) { - cpumask_clear_cpu(cpu, lowest_mask); - } - -#ifdef CONFIG_SCHED_WALT - if (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) { - sf = is_sf(p); - if (sf && is_task_util_over(p, sysctl_boost_task_threshold) && oplus_is_min_capacity_cpu(cpu)) - cpumask_clear_cpu(cpu, lowest_mask); - } -#endif - - cpu = cpumask_next(cpu, lowest_mask); - } -} - -static inline bool test_sched_assist_ux_type(struct task_struct *task, unsigned int sa_ux_type) -{ - return task->ux_state & sa_ux_type; -} - -static inline u64 max_vruntime(u64 max_vruntime, u64 vruntime) -{ - s64 delta = (s64)(vruntime - max_vruntime); - if (delta > 0) - max_vruntime = vruntime; - - return max_vruntime; -} - -#define MALI_THREAD_NAME "mali-cmar-backe" -#define LAUNCHER_THREAD_NAME "ndroid.launcher" -#define ALLOCATOR_THREAD_NAME "allocator-servi" -#define CAMERA_PROVIDER_NAME "provider@2.4-se" -#define CAMERA_HAL_SERVER_NAME "camerahalserver" - -#define CAMERA_MAINTHREAD_NAME "com.oppo.camera" -#define OPLUS_CAMERA_MAINTHREAD_NAME "om.oplus.camera" -#define CAMERA_PREMR_NAME "previewManagerR" -#define CAMERA_PREPT_NAME "PreviewProcessT" -#define CAMERA_HALCONT_NAME "Camera Hal Cont" -#define CAMERA_IMAGEPROC_NAME "ImageProcessThr" - -#define SURFACE_FLINGER_NAME "surfaceflinger" -#define SF_RENDER_ENGINE_NAME "RenderEngine" - -#define SF_RENDER_PID_NUM 3 -static pid_t sSF_union[SF_RENDER_PID_NUM] = {-1, -1, -1}; -static unsigned long sSF_union_util[SF_RENDER_PID_NUM] = {0, 0, 0}; -static unsigned long sSF_union_ux_load[SF_RENDER_PID_NUM] = {0, 0, 0}; - - -void sched_assist_target_comm(struct task_struct *task) -{ - struct task_struct *grp_leader; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - /* Surfaceflinger is rt */ - if (task->pid == task->tgid && (task_uid(task).val == 1000 /* SURFACE_FLINGER_UID */) && !strncmp(task->comm, SURFACE_FLINGER_NAME, TASK_COMM_LEN)) { - sSF_union[0] = task->pid; - /* If sf restart, reset union to -1; */ - sSF_union[1] = sSF_union[2] = -1; - /* sched_assist_systrace_pid(task->tgid, sSF_union[0], "sf_union %d", task->pid); */ - return; - } - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /* Actually there are two "RenderEngine", only match one by set_task_comm(); */ - if ((task_uid(task).val == 1000 /* SURFACE_FLINGER_UID */) && !strncmp(task->comm, SF_RENDER_ENGINE_NAME, TASK_COMM_LEN)) { - if (sSF_union[1] == -1) { - sSF_union[1] = task->pid; - /* sched_assist_systrace_pid(task->tgid, sSF_union[1], "sf_union %d", task->pid); */ - } else if (sSF_union[2] == -1) { - sSF_union[2] = task->pid; - /* sched_assist_systrace_pid(task->tgid, sSF_union[2], "sf_union %d", task->pid); */ - } - return; - } -#endif - - grp_leader = task->group_leader; - - if (!grp_leader || (get_ux_state_type(task) != UX_STATE_NONE)) - return; - -#ifndef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /* mali thread only exist in mtk platform */ - if (strstr(grp_leader->comm, LAUNCHER_THREAD_NAME) && strstr(task->comm, MALI_THREAD_NAME)) { - task->ux_state |= SA_TYPE_ANIMATOR; - return; - } - - if (!strncmp(grp_leader->comm, CAMERA_HAL_SERVER_NAME, TASK_COMM_LEN) && (task_uid(task).val == 1047 /* CAMERASERVER_UID */)) { - if (task->sched_class == &fair_sched_class) { - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - return; - } - } -#endif - - if (strstr(grp_leader->comm, CAMERA_PROVIDER_NAME) && strstr(task->comm, CAMERA_PROVIDER_NAME)) { - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - return; - } - - if ((strstr(grp_leader->comm, CAMERA_MAINTHREAD_NAME) || strstr(grp_leader->comm, OPLUS_CAMERA_MAINTHREAD_NAME)) && (strstr(task->comm, CAMERA_PREMR_NAME) - || strstr(task->comm, CAMERA_PREPT_NAME) - || strstr(task->comm, CAMERA_HALCONT_NAME) - || strstr(task->comm, CAMERA_IMAGEPROC_NAME))) { - task->ux_state |= SA_TYPE_LIGHT; - return; - } - - if (!strncmp(grp_leader->comm, ALLOCATOR_THREAD_NAME, TASK_COMM_LEN) || !strncmp(task->comm, ALLOCATOR_THREAD_NAME, TASK_COMM_LEN)) { - task->ux_state |= SA_TYPE_ID_ALLOCATOR_SER; - return; - } - - return; -} - -#ifdef CONFIG_FAIR_GROUP_SCHED -/* An entity is a task if it doesn't "own" a runqueue */ -#define oplus_entity_is_task(se) (!se->my_q) -#else -#define oplus_entity_is_task(se) (1) -#endif - -void place_entity_adjust_ux_task(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) -{ - u64 vruntime = cfs_rq->min_vruntime; - unsigned long thresh = sysctl_sched_latency; - unsigned long launch_adjust = 0; - struct task_struct *se_task = NULL; - - if (unlikely(!sysctl_sched_assist_enabled)) - return; - - if (!oplus_entity_is_task(se) || initial) - return; - - if (sysctl_sched_assist_scene & SA_LAUNCH) - launch_adjust = sysctl_sched_latency; - - se_task = task_of(se); - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - if (se_task->ux_once) { - vruntime -= 3 * thresh; - se->vruntime = vruntime; - se_task->ux_once = 0; - return; - } -#endif - - if (test_sched_assist_ux_type(se_task, SA_TYPE_ANIMATOR)) { - vruntime -= 3 * thresh + (thresh >> 1); - se->vruntime = vruntime - (launch_adjust >> 1); - return; - } - - if (test_sched_assist_ux_type(se_task, SA_TYPE_LIGHT | SA_TYPE_HEAVY)) { - vruntime -= 2 * thresh; - se->vruntime = vruntime - (launch_adjust >> 1); - return; - } -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - if (!sysctl_sched_impt_tgid && test_task_identify_ux(se_task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#else - if (test_task_identify_ux(se_task, SA_TYPE_ID_CAMERA_PROVIDER)) { -#endif -#ifdef CONFIG_MACH_MT6765 - vruntime -= 4 * thresh; - se->vruntime = vruntime; -#else - vruntime -= 2 * thresh + (thresh >> 1); - se->vruntime = vruntime - (launch_adjust >> 1); -#endif - return; - } - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - if (should_force_adjust_vruntime(se)) { - se->vruntime = vruntime - (thresh + (thresh >> 1)); - return; - } -#endif -} - -bool should_ux_preempt_wakeup(struct task_struct *wake_task, struct task_struct *curr_task) -{ - bool wake_ux = false; - bool curr_ux = false; - - if (!sysctl_sched_assist_enabled) - return false; - - wake_ux = test_task_ux(wake_task) || test_list_pick_ux(wake_task) || test_task_identify_ux(wake_task, SA_TYPE_ID_CAMERA_PROVIDER); - curr_ux = test_task_ux(curr_task) || test_list_pick_ux(curr_task) || test_task_identify_ux(curr_task, SA_TYPE_ID_CAMERA_PROVIDER); - - /* exit animation ux is set as highest ux which other ux can't preempt and can preempt other ux */ - if (!(sysctl_sched_assist_scene & SA_LAUNCH)) { - if (is_animation_ux(curr_task)) - return false; - else if (is_animation_ux(wake_task)) - return true; - } - - /* ux can preemt cfs */ - if (wake_ux && !curr_ux) - return true; - - /* animator ux can preemt un-animator */ - if ((wake_task->ux_state & SA_TYPE_ANIMATOR) && !(curr_task->ux_state & SA_TYPE_ANIMATOR)) - return true; - - /* heavy type can be preemt by other type */ - if (wake_ux && !(wake_task->ux_state & SA_TYPE_HEAVY) && (curr_task->ux_state & SA_TYPE_HEAVY)) - return true; - - return false; -} - -bool should_ux_task_skip_further_check(struct sched_entity *se) -{ - return oplus_entity_is_task(se) && test_sched_assist_ux_type(task_of(se), SA_TYPE_ANIMATOR); -} - -static inline bool is_ux_task_prefer_cpu(struct task_struct *task, int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - - if(cpu < 0) - return false; - - /* only one cluster or init failed */ - if (unlikely(cls_nr <= 0)) - return true; - - if (cpu_rq(cpu)->curr && test_sched_assist_ux_type(cpu_rq(cpu)->curr, SA_TYPE_HEAVY)) - return false; - - if (test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) { - return capacity_orig_of(cpu) >= ux_cputopo.sched_cls[cls_nr].capacity; - } - - return true; -} - -bool is_task_util_over(struct task_struct *task, int threshold) -{ - bool sum_over = false; - bool demand_over = false; - -#ifdef CONFIG_SCHED_WALT -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - sum_over = scale_demand(task->wts.sum) >= threshold; -#else - sum_over = scale_demand(task->ravg.sum) >= threshold; -#endif -#else /* !CONFIG_SCHED_WALT */ - sum_over = READ_ONCE(task->se.avg.util_avg) >= threshold; -#endif /* CONFIG_SCHED_WALT */ - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - demand_over = task_util(task) >= threshold; -#else - if (unlikely(task_index_of_sf_union(task) >= 0)) { - unsigned long util = sSF_union_util[0] + sSF_union_util[1] + sSF_union_util[2]; - demand_over = (util >= threshold); - } -#endif - - return sum_over || demand_over; -} - -static inline int get_task_cls_for_scene(struct task_struct *task) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_max = ux_cputopo.cls_nr - 1; - int cls_mid = cls_max - 1; - - /* only one cluster or init failed */ - if (unlikely(cls_max <= 0)) - return 0; - - /* for 2 clusters cpu, mid = max */ - if (cls_mid == 0) { - cls_mid = cls_max; - } - - /* just change cpu selection for heavy ux task */ - if (!test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) - return 0; - - /* for launch scene, heavy ux task move to max capacity cluster */ - if (sched_assist_scene(SA_LAUNCH)) { - return cls_max; - } - - if ((sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) && - is_task_util_over(task, sysctl_boost_task_threshold)) { - return cls_mid; - } - - return 0; -} - -static inline bool is_ux_task_prefer_cpu_for_scene(struct task_struct *task, unsigned int cpu) -{ - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_id = ux_cputopo.cls_nr - 1; - - /* only one cluster or init failed */ - if (unlikely(cls_id <= 0)) - return true; - - cls_id = get_task_cls_for_scene(task); - return capacity_orig_of(cpu) >= ux_cputopo.sched_cls[cls_id].capacity; -} - -#ifdef CONFIG_SCHED_WALT -/* 2ms default for 20ms window size scaled to 1024 */ -bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - /* for SA_TYPE_ID_CAMERA_PROVIDER */ - if (test_task_identify_ux(task, SA_TYPE_ID_CAMERA_PROVIDER) - && is_task_util_over(task, THRESHOLD_BOOST) && oplus_is_min_capacity_cpu(cpu)) { - return true; - } - - if(is_task_util_over(task, sysctl_boost_task_threshold) - && !is_ux_task_prefer_cpu_for_scene(task, cpu)) { - return true; - } - - return false; -} -#endif - -bool should_ux_task_skip_cpu(struct task_struct *task, unsigned int cpu) -{ - if (!sysctl_sched_assist_enabled || !test_task_ux(task)) - return false; - - if (!is_ux_task_prefer_cpu_for_scene(task, cpu)) - return true; - - if (!(sysctl_sched_assist_scene & SA_LAUNCH) || !test_sched_assist_ux_type(task, SA_TYPE_HEAVY)) { - if (cpu_rq(cpu)->rt.rt_nr_running) - return true; - - /* avoid placing turbo ux into cpu which has animator ux or list ux */ - if (cpu_rq(cpu)->curr && (test_sched_assist_ux_type(cpu_rq(cpu)->curr, SA_TYPE_ANIMATOR) - || !list_empty(&cpu_rq(cpu)->ux_thread_list))) - return true; - } - - return false; -} - -void set_ux_task_to_prefer_cpu_v1(struct task_struct *task, int *orig_target_cpu, bool *cond) { - struct rq *rq = NULL; - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - int cpu = 0; - - if (!sysctl_sched_assist_enabled || !(sysctl_sched_assist_scene & SA_LAUNCH)) - return; - - if (unlikely(cls_nr <= 0)) - return; - - if (is_ux_task_prefer_cpu(task, *orig_target_cpu)) - return; - *cond = true; -retry: - for_each_cpu(cpu, &ux_cputopo.sched_cls[cls_nr].cpus) { - rq = cpu_rq(cpu); - if (test_sched_assist_ux_type(rq->curr, SA_TYPE_HEAVY)) - continue; - - if (rq->curr->prio < MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, task->cpus_ptr)) { -#else - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, &task->cpus_allowed)) { -#endif - *orig_target_cpu = cpu; - return; - } - } - - cls_nr = cls_nr - 1; - if (cls_nr > 0) - goto retry; - - return; -} - -bool set_ux_task_to_prefer_cpu(struct task_struct *task, int *orig_target_cpu) { - struct rq *rq = NULL; - struct ux_sched_cputopo ux_cputopo = ux_sched_cputopo; - int cls_nr = ux_cputopo.cls_nr - 1; - int cpu = 0; - int direction = -1; - - if (!sysctl_sched_assist_enabled || !(sysctl_sched_assist_scene & SA_LAUNCH)) - return false; - - if (unlikely(cls_nr <= 0)) - return false; - - if (is_ux_task_prefer_cpu(task, *orig_target_cpu)) - return false; - - cls_nr = get_task_cls_for_scene(task); - if (cls_nr != ux_cputopo.cls_nr - 1) - direction = 1; -retry: - for_each_cpu(cpu, &ux_cputopo.sched_cls[cls_nr].cpus) { - rq = cpu_rq(cpu); - if (test_sched_assist_ux_type(rq->curr, SA_TYPE_HEAVY)) - continue; - - if (rq->curr->prio < MAX_RT_PRIO) - continue; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, task->cpus_ptr)) { -#else - if (cpu_online(cpu) && !cpu_isolated(cpu) && cpumask_test_cpu(cpu, &task->cpus_allowed)) { -#endif - *orig_target_cpu = cpu; - return true; - } - } - - cls_nr = cls_nr + direction; - if (cls_nr > 0 && cls_nr < ux_cputopo.cls_nr) - goto retry; - - return false; -} - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -static void requeue_runnable_task(struct task_struct *p) -{ - bool queued, running; - struct rq_flags rf; - struct rq *rq; - - rq = task_rq_lock(p, &rf); - queued = task_on_rq_queued(p); - running = task_current(rq, p); - - if (!queued || running) { - task_rq_unlock(rq, p, &rf); - return; - } - - update_rq_clock(rq); - deactivate_task(rq, p, DEQUEUE_NOCLOCK); - activate_task(rq, p, ENQUEUE_NOCLOCK); - resched_curr(rq); - - task_rq_unlock(rq, p, &rf); -} -#endif - -void set_inherit_ux(struct task_struct *task, int type, int depth, int inherit_val) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq = NULL; - int old_state = 0; - - if (!task || type >= INHERIT_UX_MAX) { - return; - } - - rq = task_rq_lock(task, &flags); - - if (task->sched_class != &fair_sched_class) { - task_rq_unlock(rq, task, &flags); - return; - } - - inherit_ux_inc(task, type); - task->ux_depth = depth + 1; - old_state = task->ux_state; - task->ux_state = (inherit_val & SCHED_ASSIST_UX_MASK) | SA_TYPE_INHERIT; - /* identify type like allocator ux, keep it, but can not inherit */ - if (old_state & SA_TYPE_ID_ALLOCATOR_SER) - task->ux_state |= SA_TYPE_ID_ALLOCATOR_SER; - if (old_state & SA_TYPE_ID_CAMERA_PROVIDER) - task->ux_state |= SA_TYPE_ID_CAMERA_PROVIDER; - task->inherit_ux_start = jiffies_to_nsecs(jiffies); - - if (task->on_rq && (!rq->curr || (!test_task_ux(rq->curr) && rq->curr->prio > 110))) { - set_once_ux(task); - enqueue_ux_thread(task_rq(task), task); - } - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - task_rq_unlock(rq, task, &flags); - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - /* requeue runnable task to ensure vruntime adjust */ - requeue_runnable_task(task); -#endif -} - -void reset_inherit_ux(struct task_struct *inherit_task, struct task_struct *ux_task, int reset_type) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - int reset_depth = 0; - int reset_inherit = 0; - - if (!inherit_task || !ux_task || reset_type >= INHERIT_UX_MAX) { - return; - } - - reset_inherit = ux_task->ux_state; - reset_depth = ux_task->ux_depth; - /* animator ux is important, so we just reset in this type */ - if (!test_inherit_ux(inherit_task, reset_type) || !test_sched_assist_ux_type(ux_task, SA_TYPE_ANIMATOR)) - return; - - rq = task_rq_lock(inherit_task, &flags); - - inherit_task->ux_depth = reset_depth + 1; - /* identify type like allocator ux, keep it, but can not inherit */ - if (reset_inherit & SA_TYPE_ID_ALLOCATOR_SER) - reset_inherit &= ~SA_TYPE_ID_ALLOCATOR_SER; - if (reset_inherit & SA_TYPE_ID_CAMERA_PROVIDER) - reset_inherit &= ~SA_TYPE_ID_CAMERA_PROVIDER; - inherit_task->ux_state = (inherit_task->ux_state & ~SCHED_ASSIST_UX_MASK) | reset_inherit; - - sched_assist_systrace_pid(inherit_task->tgid, inherit_task->ux_state, "ux_state %d", inherit_task->pid); - - task_rq_unlock(rq, inherit_task, &flags); -} - -void unset_inherit_ux_value(struct task_struct *task, int type, int value) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - s64 inherit_ux; - - if (!task || type >= INHERIT_UX_MAX) { - return; - } - - rq = task_rq_lock(task, &flags); - - inherit_ux_sub(task, type, value); - inherit_ux = atomic64_read(&task->inherit_ux); - if (inherit_ux > 0) { - task_rq_unlock(rq, task, &flags); - return; - } - if (inherit_ux < 0) { - atomic64_set(&(task->inherit_ux), 0); - } - task->ux_depth = 0; - /* identify type like allocator ux, keep it, but can not inherit */ - task->ux_state &= SA_TYPE_ID_ALLOCATOR_SER | SA_TYPE_ID_CAMERA_PROVIDER; - - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - task_rq_unlock(rq, task, &flags); -} - -void unset_inherit_ux(struct task_struct *task, int type) -{ - unset_inherit_ux_value(task, type, 1); -} - -void inc_inherit_ux_refs(struct task_struct *task, int type) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) - unsigned long flags; -#else - struct rq_flags flags; -#endif - struct rq *rq; - - rq = task_rq_lock(task, &flags); - inherit_ux_inc(task, type); - task_rq_unlock(rq, task, &flags); -} - -int task_index_of_sf_union(struct task_struct *p) -{ - int i; - for (i = 0; i < SF_RENDER_PID_NUM; i++) { - if (p->pid == sSF_union[i]) { - return i; - } - } - return -1; -} - -void sf_task_util_record(struct task_struct *p) -{ - int index = task_index_of_sf_union(p); - if (unlikely(index >= 0)) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - sSF_union_util[index] = task_util(p); -#else - sSF_union_util[index] = task_util_mtk(p, true); -#endif - } -} - -u64 sf_union_ux_load(struct task_struct *tsk, u64 timeline) { - int index = task_index_of_sf_union(tsk); - if (unlikely(index >= 0)) { - sSF_union_ux_load[index] = timeline; - /* sched_assist_systrace_pid(tsk->tgid, sSF_union_ux_load[0] + sSF_union_ux_load[1] + sSF_union_ux_load[2], "sf_union_ux_load %d", tsk->pid); */ - return sSF_union_ux_load[0] + sSF_union_ux_load[1] + sSF_union_ux_load[2]; - } - return timeline; -} - -bool oplus_task_misfit(struct task_struct *p, int cpu) { - int num_mincpu; - - int index = task_index_of_sf_union(p); - if (unlikely(index >= 0)) { - unsigned long util = sSF_union_util[0] + sSF_union_util[1] + sSF_union_util[2]; - /* sched_assist_systrace_pid(p->tgid, util, "sf_union_util %d", p->pid); */ - num_mincpu = cpumask_weight(topology_core_cpumask(0)); - if (util >= sysctl_boost_task_threshold && cpu < num_mincpu) { - return true; - } - } - -#ifdef CONFIG_SCHED_WALT -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - #ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - num_mincpu = cpumask_weight(topology_core_cpumask(0)); - if ((scale_demand(p->wts.sum) >= sysctl_boost_task_threshold || - task_util(p) >= sysctl_boost_task_threshold) && cpu < num_mincpu) - return true; - #endif -#else - num_mincpu = cpumask_weight(topology_core_cpumask(0)); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if ((scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold || - task_util(p) >= sysctl_boost_task_threshold) && cpu < num_mincpu) -#else - if ((scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold || - task_util_mtk(p, true) > sysctl_boost_task_threshold) && cpu < num_mincpu) -#endif - return true; -#endif -#endif - return false; -} - -void kick_min_cpu_from_mask(struct cpumask *lowest_mask) -{ - unsigned int cpu = cpumask_first(lowest_mask); - while(cpu < nr_cpu_ids) { - if (cpumask_test_cpu(cpu, &ux_sched_cputopo.sched_cls[0].cpus)) { - cpumask_clear_cpu(cpu, lowest_mask); - } - cpu = cpumask_next(cpu, lowest_mask); - } -} - -bool ux_skip_sync_wakeup(struct task_struct *task, int *sync) -{ - bool ret = false; - - if (test_sched_assist_ux_type(task, SA_TYPE_ANIMATOR)) { - *sync = 0; - ret = true; - } - - return ret; -} - -/* - * add for create proc node: proc/pid/task/pid/ux_state -*/ -bool is_special_entry(struct dentry *dentry, const char *special_proc) -{ - const unsigned char *name; - if (NULL == dentry || NULL == special_proc) - return false; - - name = dentry->d_name.name; - if (NULL != name && !strncmp(special_proc, name, 32)) - return true; - else - return false; -} - -static unsigned long __read_mostly mark_addr; - -static int _sched_assist_update_tracemark(void) -{ - if (mark_addr) - return 1; - - mark_addr = kallsyms_lookup_name("tracing_mark_write"); - - if (unlikely(!mark_addr)) - return 0; - - return 1; -} - -void sched_assist_systrace_pid(pid_t pid, int val, const char *fmt, ...) -{ - char log[256]; - va_list args; - int len; - - if (likely(!param_ux_debug)) - return; - - if (unlikely(!_sched_assist_update_tracemark())) - return; - - memset(log, ' ', sizeof(log)); - va_start(args, fmt); - len = vsnprintf(log, sizeof(log), fmt, args); - va_end(args); - - if (unlikely(len < 0)) - return; - else if (unlikely(len == 256)) - log[255] = '\0'; - - preempt_disable(); - event_trace_printk(mark_addr, "C|%d|%s|%d\n", pid, log, val); - preempt_enable(); -} - -static int proc_ux_state_show(struct seq_file *m, void *v) -{ - struct inode *inode = m->private; - struct task_struct *p; - p = get_proc_task(inode); - if (!p) { - return -ESRCH; - } - task_lock(p); - seq_printf(m, "%d\n", p->ux_state); - task_unlock(p); - put_task_struct(p); - return 0; -} - -static int proc_ux_state_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, proc_ux_state_show, inode); -} - -static ssize_t proc_ux_state_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - struct task_struct *task; - char buffer[PROC_NUMBUF]; - int err, ux_state; - - memset(buffer, 0, sizeof(buffer)); - - if (count > sizeof(buffer) - 1) - count = sizeof(buffer) - 1; - if (copy_from_user(buffer, buf, count)) { - return -EFAULT; - } - - err = kstrtoint(strstrip(buffer), 0, &ux_state); - if(err) { - return err; - } - task = get_proc_task(file_inode(file)); - if (!task) { - return -ESRCH; - } - - if (ux_state < 0) { - put_task_struct(task); - return -EINVAL; - } - - if (ux_state == SA_OPT_CLEAR) { /* clear all ux type but animator */ - task->ux_state &= ~(SA_TYPE_LISTPICK | SA_TYPE_HEAVY | SA_TYPE_LIGHT); - } else if (ux_state & SA_OPT_SET) { /* set target ux type and clear set opt */ - task->ux_state |= ux_state & (~SA_OPT_SET); - } else if (task->ux_state & ux_state) { /* reset target ux type */ - task->ux_state &= ~ux_state; - } - sched_assist_systrace_pid(task->tgid, task->ux_state, "ux_state %d", task->pid); - - put_task_struct(task); - - return count; -} - -static ssize_t proc_ux_state_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[256]; - struct task_struct *task = NULL; - int ux_state = -1; - size_t len = 0; - int cpuset_id = 0; - - task = get_proc_task(file_inode(file)); - - if (!task) - return -ESRCH; - -#ifdef CONFIG_CGROUP_SCHED - cpuset_id = task_css(task, cpuset_cgrp_id)->id; -#endif - ux_state = task->ux_state; - put_task_struct(task); - - len = snprintf(buffer, sizeof(buffer), "pid=%d ux_state=%d inherit=%llx(fu:%d mu:%d rw:%d bi:%d) cpuset_id=%d\n", - task->pid, ux_state, (u64)atomic64_read(&task->inherit_ux), - test_inherit_ux(task, INHERIT_UX_FUTEX), test_inherit_ux(task, INHERIT_UX_MUTEX), - test_inherit_ux(task, INHERIT_UX_RWSEM), test_inherit_ux(task, INHERIT_UX_BINDER), - cpuset_id); - - return simple_read_from_buffer(buf, count, ppos, buffer, len); -} - -const struct file_operations proc_ux_state_operations = { - .open = proc_ux_state_open, - .write = proc_ux_state_write, - .read = proc_ux_state_read, - .llseek = seq_lseek, - .release = single_release, -}; - -/* - * add for proc node: proc/sys/kernel/sched_assist_scene -*/ -int sysctl_sched_assist_scene_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int result, save_sa; - static DEFINE_MUTEX(sa_scene_mutex); - - mutex_lock(&sa_scene_mutex); - - save_sa = sysctl_sched_assist_scene; - result = proc_dointvec(table, write, buffer, lenp, ppos); - - if (!write) - goto out; - - if (sysctl_sched_assist_scene == SA_SCENE_OPT_CLEAR) { - goto out; - } - - if (sysctl_sched_assist_scene & SA_SCENE_OPT_SET) { - save_sa |= sysctl_sched_assist_scene & (~SA_SCENE_OPT_SET); - } else if (save_sa & sysctl_sched_assist_scene) { - save_sa &= ~sysctl_sched_assist_scene; - } - - sysctl_sched_assist_scene = save_sa; - sched_assist_systrace(sysctl_sched_assist_scene, "scene"); -out: - mutex_unlock(&sa_scene_mutex); - - return result; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) -static inline bool is_mmap_lock_opt_enabled(void) -{ - return sysctl_uxchain_v2 && !sched_assist_scene(SA_CAMERA); -} - -void uxchain_rwsem_wake(struct task_struct *tsk, struct rw_semaphore *sem) -{ - int set_ux_once; - - if (!is_mmap_lock_opt_enabled()) - return; - - if (current->mm) { - set_ux_once = (sem == &(current->mm->mmap_sem)); - if (set_ux_once) - tsk->ux_once = 1; - } -} -void uxchain_rwsem_down(struct rw_semaphore *sem) -{ - if (!is_mmap_lock_opt_enabled()) - return; - - if (current->mm && sem == &(current->mm->mmap_sem)) { - current->get_mmlock = 1; - current->get_mmlock_ts = sched_clock(); - } -} - -void uxchain_rwsem_up(struct rw_semaphore *sem) -{ - if (current->mm && sem == &(current->mm->mmap_sem) && - current->get_mmlock == 1) { - current->get_mmlock = 0; - } -} -#endif - -bool skip_check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) -{ - u64 wallclock = 0; - - wallclock = sched_clock(); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - if (!is_mmap_lock_opt_enabled()) - return false; - - if (wallclock - rq->curr->get_mmlock_ts < PREEMPT_DISABLE_RWSEM && - rq->curr->get_mmlock && - !(p->flags & PF_WQ_WORKER) && !task_has_rt_policy(p)) - return true; -#endif - - return false; -} - -#define TOP_APP_GROUP_ID 4 -bool im_mali(struct task_struct *p) -{ - return strstr(p->comm, "mali-cmar-backe"); -} -bool cgroup_check_set_sched_assist_boost(struct task_struct *p) -{ - return im_mali(p); -} -int get_st_group_id(struct task_struct *task) -{ -#if IS_ENABLED(CONFIG_SCHED_TUNE) - const int subsys_id = schedtune_cgrp_id; - struct cgroup *grp; - - rcu_read_lock(); - grp = task_cgroup(task, subsys_id); - rcu_read_unlock(); - return grp->id; -#else - return 0; -#endif -} -void cgroup_set_sched_assist_boost_task(struct task_struct *p) -{ - if(cgroup_check_set_sched_assist_boost(p)) { - if (get_st_group_id(p) == TOP_APP_GROUP_ID) { - p->ux_state |= SA_TYPE_HEAVY; - } else - p->ux_state &= ~SA_TYPE_HEAVY; - } else { - return; - } -} - - -#define DEFAULT_LIMIT_CORE_USE (4) -#define MAX_LIMIT_PROCESS (5) -#define ULIMIT_PROCESS_TYPE (3) - -bool is_limit_task(struct task_struct *task) -{ - return false; -} - -static inline bool should_limit_core_use(struct task_struct *task) -{ - return task && is_limit_task(task); -} - -bool should_limit_task_skip_cpu(struct task_struct *task, int cpu) -{ - return should_limit_core_use(task) && (cpu >= DEFAULT_LIMIT_CORE_USE); -} - -bool set_limit_task_target_cpu(struct task_struct *task, int *target_cpu) -{ - bool res = false; - - if (should_limit_core_use(task)) { - int i = 0; - int core_limit = DEFAULT_LIMIT_CORE_USE; - unsigned int best_nr = UINT_MAX; - struct cpumask allowed_mask; - cpumask_clear(&allowed_mask); - - if (core_limit <= 0 || core_limit >= NR_CPUS) - return false; - - for (i = 0; i < core_limit; ++i) - cpumask_set_cpu(i, &allowed_mask); - - if (cpumask_test_cpu(*target_cpu, &allowed_mask)) - return true; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - for_each_cpu_and(i, &allowed_mask, task->cpus_ptr) { -#else - for_each_cpu_and(i, &allowed_mask, &task->cpus_allowed) { -#endif - if (!cpu_online(i) || cpu_isolated(i)) - continue; - - if (cpu_rq(i)->nr_running < best_nr) { - best_nr = cpu_rq(i)->nr_running; - *target_cpu = i; - res = true; - } - } - } - - return res; -} - -static ssize_t proc_sched_impt_task_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - char temp_buf[32]; - char *temp_str, *token; - char in_str[2][16]; - int cnt, err, pid; - - static DEFINE_MUTEX(impt_thd_mutex); - static unsigned int save_idx = 0; - - mutex_lock(&impt_thd_mutex); - - memset(temp_buf, 0, sizeof(temp_buf)); - - if (count > sizeof(temp_buf) - 1) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - if (copy_from_user(temp_buf, buf, count)) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - cnt = 0; - temp_str = strstrip(temp_buf); - while ((token = strsep(&temp_str, " ")) && *token && (cnt < 2)) { - strncpy(in_str[cnt], token, sizeof(in_str[cnt])); - cnt += 1; - } - - if (cnt != 2) { - mutex_unlock(&impt_thd_mutex); - return -EFAULT; - } - - err = kstrtoint(strstrip(in_str[1]), 0, &pid); - if (err) { - mutex_unlock(&impt_thd_mutex); - return err; - } - - if (pid <= 0 || pid > PID_MAX_DEFAULT) { - mutex_unlock(&impt_thd_mutex); - return -EINVAL; - } - - /* set top app */ - if (!strncmp(in_str[0], "fg", 2)) { - save_top_app_tgid = pid; - top_app_type = 0; - if (!strncmp(in_str[0], "fgLauncher", 10)) - top_app_type = 1; /* 1 is launcher */ - goto out; - } - - /* set audio app */ - if (!strncmp(in_str[0], "addAu", 5)) { - int i = 0; - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] == pid) { - break; - } - } - - /* we can't found save_tgid, update it. */ - if (i >= MAX_IMPT_SAVE_PID) { - save_impt_tgid[save_idx++] = pid; - } - - if (save_idx >= MAX_IMPT_SAVE_PID) - save_idx = 0; - - goto out; - } else if (!strncmp(in_str[0], "remAu", 5)) { - int i = 0; - for (; i < MAX_IMPT_SAVE_PID; ++i) { - if (save_impt_tgid[i] == pid) { - save_impt_tgid[i] = 0; - save_idx = i; - break; - } - } - } - -out: - mutex_unlock(&impt_thd_mutex); - - return count; -} - -static ssize_t proc_sched_impt_task_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - char buffer[32]; - size_t len = 0; - - len = snprintf(buffer, sizeof(buffer), "top(%d %u) au(%d %d)\n", save_top_app_tgid, top_app_type, save_impt_tgid[0], save_impt_tgid[1]); - - return simple_read_from_buffer(buf, count, ppos, buffer, len); -} - -static const struct file_operations proc_sched_impt_task_fops = { - .write = proc_sched_impt_task_write, - .read = proc_sched_impt_task_read, -}; - -#define OPLUS_SCHEDULER_PROC_DIR "oplus_scheduler" -#define OPLUS_SCHEDASSIST_PROC_DIR "sched_assist" -struct proc_dir_entry *d_oplus_scheduler = NULL; -struct proc_dir_entry *d_sched_assist = NULL; -static int __init oplus_sched_assist_init(void) -{ - struct proc_dir_entry *proc_node; - - d_oplus_scheduler = proc_mkdir(OPLUS_SCHEDULER_PROC_DIR, NULL); - if(!d_oplus_scheduler) { - ux_err("failed to create proc dir oplus_scheduler\n"); - goto err_dir_scheduler; - } - - d_sched_assist = proc_mkdir(OPLUS_SCHEDASSIST_PROC_DIR, d_oplus_scheduler); - if(!d_sched_assist) { - ux_err("failed to create proc dir sched_assist\n"); - goto err_dir_sa; - } - - proc_node = proc_create("sched_impt_task", 0666, d_sched_assist, &proc_sched_impt_task_fops); - if(!proc_node) { - ux_err("failed to create proc node sched_impt_task\n"); - goto err_node_impt; - } - - return 0; - -err_node_impt: - remove_proc_entry(OPLUS_SCHEDASSIST_PROC_DIR, NULL); - -err_dir_sa: - remove_proc_entry(OPLUS_SCHEDULER_PROC_DIR, NULL); - -err_dir_scheduler: - return -ENOENT; -} -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -static inline bool is_sched_boost_group(struct task_struct *tsk) -{ - return (sysctl_sched_impt_tgid != 0 && tsk->tgid == sysctl_sched_impt_tgid); -} - -#define ANDROID_PRIORITY_URGENT_AUDIO 101 -#define ANDROID_PRIORITY_AUDIO 104 -#define FIT_SMALL_THREASH 3 -#define RUNNABLE_MIN_THREASH 20000000 -#define RUNNING_MIN_THREASH 3000000 - -inline bool is_small_task(struct task_struct *task) -{ - if (task->oplus_task_info.im_small) - return true; - else - return false; -} - -inline bool is_audio_task(struct task_struct *task) -{ - if (((task->prio == ANDROID_PRIORITY_URGENT_AUDIO) || (task->prio == ANDROID_PRIORITY_AUDIO))) - return true; - else - return false; -} -extern void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se); -bool sched_assist_pick_next_task(struct cfs_rq *cfs_rq, struct sched_entity *se) -{ - if (cfs_rq->next && oplus_entity_is_task(cfs_rq->next)) { - struct task_struct *tsk = task_of(cfs_rq->next); - if (tsk->oplus_task_info.im_small) { - sched_assist_im_systrace_c(tsk, -1); - se = cfs_rq->next; - clear_buddies(cfs_rq, se); - return true; - } - return false; - } else { - return false; - } -} - -bool sched_assist_pick_next_task_opt(struct cfs_rq *cfs_rq, struct sched_entity **se) -{ - if (cfs_rq->next && oplus_entity_is_task(cfs_rq->next)) { - struct task_struct *tsk = task_of(cfs_rq->next); - if (tsk->oplus_task_info.im_small) { - sched_assist_im_systrace_c(tsk, -1); - *se = cfs_rq->next; - clear_buddies(cfs_rq, *se); - return true; - } - return false; - } else { - return false; - } -} - -void update_task_sched_stat_common(struct task_struct *tsk, u64 delta_ns, int stats_type) -{ - int i = TASK_INFO_SAMPLE -1; - while (i > 0) { - tsk->oplus_task_info.sa_info[stats_type][i] = tsk->oplus_task_info.sa_info[stats_type][i-1]; - i--; - } - tsk->oplus_task_info.sa_info[stats_type][0] = delta_ns; -} - -enum { - TASK_SMALL, - TASK_TYPE_TOTAL, -}; - - -u64 task_info_sum(struct task_struct *task, int type) -{ - int i; - u64 sum = 0; - - for (i = 0; i < TASK_INFO_SAMPLE; i++) { - sum += task->oplus_task_info.sa_info[type][i]; - } - - return sum; -} - -void try_to_mark_task_type(struct task_struct *tsk, int type) -{ - int i = 0; - int fit_small = 0; - - switch (type) { - case TASK_SMALL: - if ((tsk->oplus_task_info.sa_info[TST_EXEC][TASK_INFO_SAMPLE-1] != 0) && (tsk->oplus_task_info.sa_info[TST_SLEEP][TASK_INFO_SAMPLE-1] != 0)) { - while (i < TASK_INFO_SAMPLE) { - if ((tsk->oplus_task_info.sa_info[TST_EXEC][i] < RUNNING_MIN_THREASH) && - ((tsk->oplus_task_info.sa_info[TST_EXEC][i] * 5) < tsk->oplus_task_info.sa_info[TST_SLEEP][i])) - fit_small++; - - if (fit_small >= FIT_SMALL_THREASH) { - tsk->oplus_task_info.im_small = true; - goto out; - } - i++; - } - } - tsk->oplus_task_info.im_small = false; - break; - default: - break; - } -out: - return; -} - -void update_sa_task_stats(struct task_struct *tsk, u64 delta_ns, int stats_type) -{ - if (!tsk) - return; - if (unlikely(!sysctl_sched_assist_enabled)) - return; - if (tsk->oplus_task_info.im_small && (!is_sched_boost_group(tsk) || !sched_assist_scene(SA_CAMERA))) { - memset(&tsk->oplus_task_info, 0, sizeof(struct task_info)); - return; - } - if (!sched_assist_scene(SA_CAMERA)) - return; - update_task_sched_stat_common(tsk, delta_ns, stats_type); - - try_to_mark_task_type(tsk, TASK_SMALL); -} - -void sched_assist_update_record(struct task_struct *p, u64 delta_ns, int stats_type) -{ - update_sa_task_stats(p, delta_ns, stats_type); - sched_assist_im_systrace_c(p, stats_type + 1); -} - -void sched_assist_im_systrace_c(struct task_struct *tsk, int tst_type) -{ - if (unlikely(!_sched_assist_update_tracemark())) - return; - - if (!is_sched_boost_group(tsk)) - return; - - if (likely(!param_ux_debug)) - return; - - preempt_disable(); - if (tst_type != -1) { - event_trace_printk(mark_addr, "C|10001|short_run_target_%d|%d\n", tsk->pid, tsk->oplus_task_info.im_small ? 1 : 0); - } else if (tst_type == -1) { - event_trace_printk(mark_addr, "C|10001|short_run_target_buddy_%d|%d\n", tsk->pid, 1); - event_trace_printk(mark_addr, "C|10001|short_run_target_buddy_%d|%d\n", tsk->pid, 0); - } - preempt_enable(); -} -#endif - -device_initcall(oplus_sched_assist_init); diff --git a/kernel/sched_assist/sched_assist_common.h b/kernel/sched_assist/sched_assist_common.h deleted file mode 100755 index 990a381cc6fc..000000000000 --- a/kernel/sched_assist/sched_assist_common.h +++ /dev/null @@ -1,310 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#ifndef _OPLUS_SCHED_COMMON_H_ -#define _OPLUS_SCHED_COMMON_H_ - -#include - -#define ux_err(fmt, ...) \ - printk_deferred(KERN_ERR "[SCHED_ASSIST_ERR][%s]"fmt, __func__, ##__VA_ARGS__) -#define ux_warn(fmt, ...) \ - printk_deferred(KERN_WARNING "[SCHED_ASSIST_WARN][%s]"fmt, __func__, ##__VA_ARGS__) -#define ux_debug(fmt, ...) \ - printk_deferred(KERN_INFO "[SCHED_ASSIST_INFO][%s]"fmt, __func__, ##__VA_ARGS__) - -#define UX_MSG_LEN 64 -#define UX_DEPTH_MAX 5 - -/* define for sched assist thread type, keep same as the define in java file */ -#define SA_OPT_CLEAR (0) -#define SA_TYPE_LIGHT (1 << 0) -#define SA_TYPE_HEAVY (1 << 1) -#define SA_TYPE_ANIMATOR (1 << 2) -#define SA_TYPE_LISTPICK (1 << 3) -#ifdef CONFIG_UCLAMP_TASK -#define SA_TYPE_TURBO (1 << 4) /* for high load rt boost, used in audio*/ -#endif -#ifdef CONFIG_KERNEL_LOCK_OPT -#define SA_TYPE_LISTPICK_LOCK (1 << 5) -#endif -#define SA_OPT_SET (1 << 7) -#define SA_TYPE_INHERIT (1 << 8) -#define SA_TYPE_ONCE_UX (1 << 9) -#define SA_TYPE_ID_CAMERA_PROVIDER (1 << 10) -#define SA_TYPE_ID_ALLOCATOR_SER (1 << 11) - - - -#define SCHED_ASSIST_UX_MASK (0xFF) - -/* define for sched assist scene type, keep same as the define in java file */ -#define SA_SCENE_OPT_CLEAR (0) -#define SA_LAUNCH (1 << 0) -#define SA_SLIDE (1 << 1) -#define SA_CAMERA (1 << 2) -#define SA_ANIM_START (1 << 3) /* we care about both launcher and top app */ -#define SA_ANIM (1 << 4) /* we only care about launcher */ -#define SA_INPUT (1 << 5) -#define SA_LAUNCHER_SI (1 << 6) -#define SA_SCENE_OPT_SET (1 << 7) - -#ifdef CONFIG_CGROUP_SCHED -#define SA_CGROUP_DEFAULT (1) -#define SA_CGROUP_FOREGROUD (2) -#define SA_CGROUP_BACKGROUD (3) -#define SA_CGROUP_TOP_APP (4) -#endif - -/* define for load balance task type */ -#define SA_HIGH_LOAD 1 -#define SA_LOW_LOAD 0 -#define SA_UX 1 -#define SA_TOP 2 -#define SA_FG 3 -#define SA_BG 4 - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -DECLARE_PER_CPU(struct task_count_rq, task_lb_count); -#endif - -enum UX_STATE_TYPE -{ - UX_STATE_INVALID = 0, - UX_STATE_NONE, - UX_STATE_SCHED_ASSIST, - UX_STATE_INHERIT, - MAX_UX_STATE_TYPE, -}; - -enum INHERIT_UX_TYPE -{ - INHERIT_UX_BINDER = 0, - INHERIT_UX_RWSEM, - INHERIT_UX_MUTEX, - INHERIT_UX_SEM, - INHERIT_UX_FUTEX, - INHERIT_UX_MAX, -}; - -struct ux_sched_cluster { - struct cpumask cpus; - unsigned long capacity; -}; - -struct ux_sched_cputopo { - int cls_nr; - struct ux_sched_cluster sched_cls[NR_CPUS]; -}; - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -extern unsigned int walt_scale_demand_divisor; -#else -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#endif -#define scale_demand(d) ((d)/walt_scale_demand_divisor) - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -struct task_count_rq{ - int ux_high; - int ux_low; - int top_high; - int top_low; - int foreground_high; - int foreground_low; - int background_high; - int background_low; -}; - -enum OPLUS_LB_TYPE -{ - OPLUS_LB_UX = 1, - OPLUS_LB_TOP, - OPLUS_LB_FG, - OPLUS_LB_BG, - OPLUS_LB_MAX, -}; -#endif - -enum ANMATION_TYPE -{ - ANNIMATION_END = 0, - APP_START_ANIMATION, - APP_EXIT_ANIMATION, - ULIMIT_PROCESS, - LAUNCHER_SI_START, - BACKUP, - SYSTEMUI_SPLIT_STARTM, -}; - -struct rq; -extern unsigned int ux_uclamp_value; -extern int sysctl_input_boost_enabled; -extern int sysctl_animation_type; -extern int sysctl_input_boost_enabled; -extern int sysctl_sched_assist_ib_duration_coedecay; -extern int sched_assist_ib_duration_coedecay; -extern u64 sched_assist_input_boost_duration; -extern int ux_prefer_cpu[]; -extern int sysctl_animation_type; - -extern void ux_init_rq_data(struct rq *rq); -extern void ux_init_cpu_data(void); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -extern void init_rq_cpu(int cpu); -#endif - -extern bool test_list_pick_ux(struct task_struct *task); -extern void enqueue_ux_thread(struct rq *rq, struct task_struct *p); -extern void dequeue_ux_thread(struct rq *rq, struct task_struct *p); -extern void pick_ux_thread(struct rq *rq, struct task_struct **p, struct sched_entity **se); -extern bool sched_assist_pick_next_task_opt(struct cfs_rq *cfs_rq, struct sched_entity **se); -extern void inherit_ux_dequeue(struct task_struct *task, int type); -extern void inherit_ux_dequeue_refs(struct task_struct *task, int type, int value); -extern void inherit_ux_enqueue(struct task_struct *task, int type, int depth); -extern void inherit_ux_inc(struct task_struct *task, int type); -extern void inherit_ux_sub(struct task_struct *task, int type, int value); - -extern void set_inherit_ux(struct task_struct *task, int type, int depth, int inherit_val); -extern void reset_inherit_ux(struct task_struct *inherit_task, struct task_struct *ux_task, int reset_type); -extern void unset_inherit_ux(struct task_struct *task, int type); -extern void unset_inherit_ux_value(struct task_struct *task, int type, int value); -extern void inc_inherit_ux_refs(struct task_struct *task, int type); - -extern bool test_task_ux(struct task_struct *task); -extern bool test_task_ux_depth(int ux_depth); -extern bool test_inherit_ux(struct task_struct *task, int type); -extern bool test_set_inherit_ux(struct task_struct *task); -extern int get_ux_state_type(struct task_struct *task); - -extern bool test_ux_task_cpu(int cpu); -extern bool test_ux_prefer_cpu(struct task_struct *task, int cpu); -extern void find_ux_task_cpu(struct task_struct *task, int *target_cpu); -static inline void find_slide_boost_task_cpu(struct task_struct *task, int *target_cpu) {} - -extern void sched_assist_systrace_pid(pid_t pid, int val, const char *fmt, ...); -#define SA_SYSTRACE_MAGIC 123 -#define sched_assist_systrace(...) sched_assist_systrace_pid(SA_SYSTRACE_MAGIC, __VA_ARGS__) - -extern void place_entity_adjust_ux_task(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial); -extern bool should_ux_task_skip_further_check(struct sched_entity *se); -extern bool should_ux_preempt_wakeup(struct task_struct *wake_task, struct task_struct *curr_task); -extern bool should_ux_task_skip_cpu(struct task_struct *task, unsigned int cpu); -extern bool set_ux_task_to_prefer_cpu(struct task_struct *task, int *orig_target_cpu); -extern int set_ux_task_cpu_common_by_prio(struct task_struct *task, int *target_cpu, bool boost, bool prefer_idle, unsigned int type); -extern bool ux_skip_sync_wakeup(struct task_struct *task, int *sync); -extern void set_ux_task_to_prefer_cpu_v1(struct task_struct *task, int *orig_target_cpu, bool *cond); -extern bool im_mali(struct task_struct *p); -extern bool cgroup_check_set_sched_assist_boost(struct task_struct *p); -extern int get_st_group_id(struct task_struct *task); -extern void cgroup_set_sched_assist_boost_task(struct task_struct *p); -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -extern void inc_ld_stats(struct task_struct *tsk, struct rq *rq); -extern void dec_ld_stats(struct task_struct *tsk, struct rq *rq); -extern void update_load_flag(struct task_struct *tsk, struct rq *rq); - -extern int task_lb_sched_type(struct task_struct *tsk); -extern unsigned long reweight_cgroup_task(u64 slice, struct sched_entity *se, unsigned long task_weight, struct load_weight *lw); -#if !defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) || (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) -extern void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int start_cpu, int skip_cpu, cpumask_t *cpus, bool strict); -#else -extern void sched_assist_spread_tasks(struct task_struct *p, cpumask_t new_allowed_cpus, - int order_index, int end_index, int skip_cpu, cpumask_t *cpus, bool strict); -#endif -extern bool should_force_spread_tasks(void); -extern bool should_force_adjust_vruntime(struct sched_entity *se); -extern u64 sa_calc_delta(struct sched_entity *se, u64 delta_exec, unsigned long weight, struct load_weight *lw, bool calc_fair); -extern void update_rq_nr_imbalance(int cpu); -#endif - -extern bool test_task_identify_ux(struct task_struct *task, int id_type_ux); -extern bool is_task_util_over(struct task_struct *task, int threshold); - -#ifdef CONFIG_SCHED_WALT -extern bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag); -extern bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock); -#else -static inline bool sched_assist_task_misfit(struct task_struct *task, int cpu, int flag) { return false; } -static inline bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock) { return false; } -#endif - -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern void update_sa_task_stats(struct task_struct *tsk, u64 delta_ns, int stats_type); -extern void sched_assist_im_systrace_c(struct task_struct *tsk, int tst_type); -extern void sched_assist_update_record(struct task_struct *p, u64 delta_ns, int stats_type); -extern bool sched_assist_pick_next_task(struct cfs_rq *cfs_rq, struct sched_entity *se); -#endif - -extern bool skip_check_preempt_curr(struct rq *rq, struct task_struct *p, int flags); - -static inline bool is_heavy_ux_task(struct task_struct *task) -{ - return task->ux_state & SA_TYPE_HEAVY; -} - -static inline bool is_animation_ux(struct task_struct *task) -{ - return task->ux_state & SA_TYPE_ANIMATOR; -} -static inline void set_once_ux(struct task_struct *task) -{ - task->ux_state |= SA_TYPE_ONCE_UX; -} - -static inline bool sched_assist_scene(unsigned int scene) -{ - if (unlikely(!sysctl_sched_assist_enabled)) - return false; - - switch (scene) { - case SA_LAUNCH: - return sysctl_sched_assist_scene & SA_LAUNCH; - case SA_SLIDE: - return sysctl_slide_boost_enabled; - case SA_INPUT: - return sysctl_input_boost_enabled; - case SA_CAMERA: - return sysctl_sched_assist_scene & SA_CAMERA; - case SA_LAUNCHER_SI: - return sysctl_animation_type == LAUNCHER_SI_START; - case SA_ANIM: - return sysctl_sched_assist_scene & SA_ANIM; - default: - return sysctl_sched_assist_scene & scene; - } -} - -static inline bool is_sched_assist_scene() { - return sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM); -} - -static inline bool should_skip_detach_tasks(struct task_struct *tsk) -{ - return (sysctl_sched_assist_enabled >= 2) && test_task_ux(tsk) && !sched_assist_scene(SA_CAMERA); -} - -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD -static inline bool is_spread_task_enabled(void) -{ - return (sysctl_sched_assist_enabled >= 2) && !sched_assist_scene(SA_CAMERA); -} -#endif - -static inline bool task_demand_ignore_wait_time(int event) -{ - return false; -} - -bool should_limit_task_skip_cpu(struct task_struct *p, int cpu); -bool set_limit_task_target_cpu(struct task_struct *p, int *cpu); -bool is_sf(struct task_struct *p); - -int task_index_of_sf_union(struct task_struct *p); -void sf_task_util_record(struct task_struct *p); -u64 sf_union_ux_load(struct task_struct *tsk, u64 timeline); - -#endif /* _OPLUS_SCHED_COMMON_H_ */ diff --git a/kernel/sched_assist/sched_assist_fork.h b/kernel/sched_assist/sched_assist_fork.h deleted file mode 100755 index 63f8e26cb992..000000000000 --- a/kernel/sched_assist/sched_assist_fork.h +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include - -#ifndef _OPLUS_SCHED_FORK_H_ -#define _OPLUS_SCHED_FORK_H_ - -static inline void init_task_ux_info(struct task_struct *p) -{ - p->ux_state = 0; - atomic64_set(&(p->inherit_ux), 0); - INIT_LIST_HEAD(&p->ux_entry); - p->ux_depth = 0; - p->enqueue_time = 0; - p->inherit_ux_start = 0; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || defined(CONFIG_MMAP_LOCK_OPT) - p->ux_once = 0; - p->get_mmlock = 0; - p->get_mmlock_ts = 0; -#endif -#ifdef CONFIG_KERNEL_LOCK_OPT - INIT_LIST_HEAD(&p->own_rwsem); - p->lock_waiting_start = 0; - p->mt_count = 0; - p->hold_rwsem = NULL; -#endif -#ifdef CONFIG_OPLUS_FEATURE_SCHED_SPREAD - p->lb_state = 0; - p->ld_flag = 0; -#endif -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - memset(&p->oplus_task_info, 0, sizeof(struct task_info)); -#endif -} -#endif /* _OPLUS_SCHED_FORK_H_ */ diff --git a/kernel/sched_assist/sched_assist_futex.c b/kernel/sched_assist/sched_assist_futex.c deleted file mode 100755 index f0798273dcde..000000000000 --- a/kernel/sched_assist/sched_assist_futex.c +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include "sched_assist_common.h" - -#define CREATE_TRACE_POINTS -#include "sched_assist_trace.h" - -struct task_struct* get_futex_owner_by_pid(u32 owner_tid) -{ - struct task_struct* futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { - rcu_read_lock(); - futex_owner = find_task_by_vpid(owner_tid); - rcu_read_unlock(); - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) -static inline struct task_struct *oplus_find_get_task_by_vpid(pid_t nr) -{ - struct task_struct *task; - - rcu_read_lock(); - task = find_task_by_vpid(nr); - if (task) - get_task_struct(task); - rcu_read_unlock(); - - return task; -} -#endif - -struct task_struct* get_futex_owner_by_pid_v2(u32 owner_tid) { - struct task_struct* futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) - futex_owner = find_get_task_by_vpid(owner_tid); -#else - futex_owner = oplus_find_get_task_by_vpid(owner_tid); -#endif - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -struct task_struct *get_futex_owner(u32 owner_tid) -{ - struct task_struct *futex_owner = NULL; - - if (owner_tid > 0 && owner_tid <= PID_MAX_DEFAULT) { - rcu_read_lock(); - futex_owner = find_task_by_vpid(owner_tid); - rcu_read_unlock(); - if (futex_owner == NULL) { - ux_warn("failed to find task by pid(curr:%-12s pid:%d)\n", current->comm, owner_tid); - } - } - - return futex_owner; -} - -void futex_set_inherit_ux(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = false; - is_ux = test_set_inherit_ux(task); - - if (is_ux && owner && !test_task_ux(owner)) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - } -} - -void futex_unset_inherit_ux(struct task_struct *task) -{ - if (test_inherit_ux(task, INHERIT_UX_FUTEX)) { - unset_inherit_ux(task, INHERIT_UX_FUTEX); - } -} - -void futex_set_inherit_ux_refs(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = test_set_inherit_ux(task); - - if (is_ux && owner) { - bool type = get_ux_state_type(owner); - if (UX_STATE_NONE == type) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - } else { - inherit_ux_inc(owner, INHERIT_UX_FUTEX); - } - } -} - -int futex_set_inherit_ux_refs_v2(struct task_struct *owner, struct task_struct *task) -{ - bool is_ux = test_set_inherit_ux(task); - - if (is_ux && owner) { - int type = get_ux_state_type(owner); - if (UX_STATE_NONE == type) { - set_inherit_ux(owner, INHERIT_UX_FUTEX, task->ux_depth, task->ux_state); - return 1; - } else if (UX_STATE_INHERIT == type) { - inc_inherit_ux_refs(owner, INHERIT_UX_FUTEX); - return 2; - } - } - - return 0; -} - -void futex_unset_inherit_ux_refs(struct task_struct *task, int value) -{ - if (test_inherit_ux(task, INHERIT_UX_FUTEX)) { - unset_inherit_ux_value(task, INHERIT_UX_FUTEX, value); - } -} diff --git a/kernel/sched_assist/sched_assist_futex.h b/kernel/sched_assist/sched_assist_futex.h deleted file mode 100755 index eba5f11740d3..000000000000 --- a/kernel/sched_assist/sched_assist_futex.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_FUTEX_H_ -#define _OPLUS_SCHED_FUTEX_H_ -extern bool test_task_ux(struct task_struct *task); -extern struct task_struct* get_futex_owner(u32 __user *uaddr2); -extern struct task_struct* get_futex_owner_by_pid(u32 owner_tid); -extern struct task_struct* get_futex_owner_by_pid_v2(u32 owner_tid); -extern void futex_set_inherit_ux(struct task_struct *owner, struct task_struct *task); -extern void futex_unset_inherit_ux(struct task_struct *task); -extern void futex_set_inherit_ux_refs(struct task_struct *owner, struct task_struct *task); -extern int futex_set_inherit_ux_refs_v2(struct task_struct *owner, struct task_struct *task); -extern void futex_unset_inherit_ux_refs(struct task_struct *task, int value); -#endif /* _OPLUS_SCHED_FUTEX_H_ */ diff --git a/kernel/sched_assist/sched_assist_mutex.c b/kernel/sched_assist/sched_assist_mutex.c deleted file mode 100755 index bf61a14b3254..000000000000 --- a/kernel/sched_assist/sched_assist_mutex.c +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include -#include "sched_assist_common.h" -#ifdef CONFIG_KERNEL_LOCK_OPT -#include -#endif -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) -#define MUTEX_FLAGS 0x07 -static inline struct task_struct *__mutex_owner(struct mutex *lock) -{ - return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS); -} -#endif - -static void mutex_list_add_ux(struct list_head *entry, struct list_head *head) -{ - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct mutex_waiter *waiter = NULL; - list_for_each_safe(pos, n, head) { - waiter = list_entry(pos, struct mutex_waiter, list); -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task)) { -#else - if (!test_task_ux(waiter->task)) { -#endif - list_add(entry, waiter->list.prev); - return; - } - } - if (pos == head) { - list_add_tail(entry, head); - } -} - -void mutex_list_add(struct task_struct *task, struct list_head *entry, struct list_head *head, struct mutex *lock) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(task); -#else - bool is_ux = test_task_ux(task); -#endif - if (!entry || !head || !lock) { - return; - } -#ifdef CONFIG_KERNEL_LOCK_OPT - if (is_ux) { -#else - if (is_ux && !lock->ux_dep_task) { -#endif - mutex_list_add_ux(entry, head); - } else { - list_add_tail(entry, head); - } -} - -void mutex_set_inherit_ux(struct mutex *lock, struct task_struct *task) -{ - bool is_ux = false; - struct task_struct *owner = NULL; - if (!lock) { - return; - } - is_ux = test_set_inherit_ux(task); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) - owner = __mutex_owner(lock); -#else - owner = lock->owner; -#endif - if (is_ux && !lock->ux_dep_task) { - int type = get_ux_state_type(owner); - if ((UX_STATE_NONE == type) || (UX_STATE_INHERIT == type)) { - set_inherit_ux(owner, INHERIT_UX_MUTEX, task->ux_depth, task->ux_state); - lock->ux_dep_task = owner; - } - } -} - -void mutex_unset_inherit_ux(struct mutex *lock, struct task_struct *task) -{ - if (lock && lock->ux_dep_task == task) { - unset_inherit_ux(task, INHERIT_UX_MUTEX); - lock->ux_dep_task = NULL; - } -} diff --git a/kernel/sched_assist/sched_assist_mutex.h b/kernel/sched_assist/sched_assist_mutex.h deleted file mode 100755 index a862aec004e6..000000000000 --- a/kernel/sched_assist/sched_assist_mutex.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_MUTEX_H_ -#define _OPLUS_SCHED_MUTEX_H_ - -extern void mutex_list_add(struct task_struct *task, struct list_head *entry, struct list_head *head, struct mutex *lock); -extern void mutex_set_inherit_ux(struct mutex *lock, struct task_struct *task); -extern void mutex_unset_inherit_ux(struct mutex *lock, struct task_struct *task); - -#endif /* _OPLUS_SCHED_MUTEX_H_ */ diff --git a/kernel/sched_assist/sched_assist_rt.c b/kernel/sched_assist/sched_assist_rt.c deleted file mode 100755 index ed832f8d5b3f..000000000000 --- a/kernel/sched_assist/sched_assist_rt.c +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include <../kernel/sched/sched.h> - -#define WALT_RT_PULL_THRESHOLD_NS 250000 -#define CPUSET_AUDIO_APP (7) - -static inline int has_pushable_tasks(struct rq *rq) -{ - return !plist_head_empty(&rq->rt.pushable_tasks); -} - -static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) -{ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (!task_running(rq, p) && cpumask_test_cpu(cpu, p->cpus_ptr)) - return 1; -#else - if (!task_running(rq, p) && cpumask_test_cpu(cpu, &p->cpus_allowed)) - return 1; -#endif - - return 0; -} - -static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu) -{ - struct plist_head *head = &rq->rt.pushable_tasks; - struct task_struct *p; - - if (!has_pushable_tasks(rq)) - return NULL; - - plist_for_each_entry(p, head, pushable_tasks) { - if (pick_rt_task(rq, p, cpu)) - return p; - } - - return NULL; -} - - -static inline bool is_audio_app_group(struct task_struct *p) -{ -#ifdef CONFIG_CGROUP_SCHED - return task_css(p, cpuset_cgrp_id)->id == CPUSET_AUDIO_APP; -#else - return false; -#endif -} - -#ifdef CONFIG_SCHED_WALT -bool oplus_rt_new_idle_balance(struct rq *this_rq, u64 wallclock) -{ - int i, this_cpu = this_rq->cpu, src_cpu = this_cpu; - struct rq *src_rq; - struct task_struct *p; - bool pulled = false; - - /* can't help if this has a runnable RT */ - if (this_rq->rt.rt_queued > 0) - return false; - - /* check if any CPU has a pushable RT task */ - for_each_possible_cpu(i) { - struct rq *rq = cpu_rq(i); - - if (!has_pushable_tasks(rq)) - continue; - src_cpu = i; - break; - } - - if (src_cpu == this_cpu) - return false; - - src_rq = cpu_rq(src_cpu); - double_lock_balance(this_rq, src_rq); - - /* lock is dropped, so check again */ - if (this_rq->rt.rt_queued > 0) - goto unlock; - - p = pick_highest_pushable_task(src_rq, this_cpu); - - if (!p) - goto unlock; - - /* we only allow audio-app group task doing this work */ - if (!is_audio_app_group(p)) - goto unlock; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (wallclock - p->wts.last_wake_ts < WALT_RT_PULL_THRESHOLD_NS) - goto unlock; -#else - if (wallclock - p->last_wake_ts < WALT_RT_PULL_THRESHOLD_NS) - goto unlock; -#endif - - pulled = true; - deactivate_task(src_rq, p, 0); - set_task_cpu(p, this_cpu); - activate_task(this_rq, p , 0); -unlock: - double_unlock_balance(this_rq, src_rq); - - return pulled; -} -#endif diff --git a/kernel/sched_assist/sched_assist_rwsem.c b/kernel/sched_assist/sched_assist_rwsem.c deleted file mode 100755 index c43618a0835a..000000000000 --- a/kernel/sched_assist/sched_assist_rwsem.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#include -#include -#include -#include "sched_assist_common.h" - -enum rwsem_waiter_type { - RWSEM_WAITING_FOR_WRITE, - RWSEM_WAITING_FOR_READ -}; - -struct rwsem_waiter { - struct list_head list; - struct task_struct *task; - enum rwsem_waiter_type type; -}; - -#define RWSEM_READER_OWNED ((struct task_struct *)1UL) - -static inline bool rwsem_owner_is_writer(struct task_struct *owner) -{ - return owner && owner != RWSEM_READER_OWNED; -} - -static void rwsem_list_add_ux(struct list_head *entry, struct list_head *head) -{ - struct list_head *pos = NULL; - struct list_head *n = NULL; - struct rwsem_waiter *waiter = NULL; - list_for_each_safe(pos, n, head) { - waiter = list_entry(pos, struct rwsem_waiter, list); -#ifdef CONFIG_RWSEM_PRIO_AWARE -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task) && waiter->task->prio > MAX_RT_PRIO) { -#else - if (!test_task_ux(waiter->task) && waiter->task->prio > MAX_RT_PRIO) { -#endif -#else -#ifdef CONFIG_KERNEL_LOCK_OPT - if (!lock_ux_target(waiter->task)) { -#else - if (!test_task_ux(waiter->task)) { -#endif -#endif - list_add(entry, waiter->list.prev); - return; - } - } - if (pos == head) { - list_add_tail(entry, head); - } -} - -#ifndef CONFIG_MTK_TASK_TURBO -#ifdef CONFIG_RWSEM_PRIO_AWARE -bool rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head, struct rw_semaphore *sem) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(tsk); -#else - bool is_ux = test_task_ux(tsk); -#endif - if (!entry || !head) { - return false; - } - if (is_ux) { - rwsem_list_add_ux(entry, head); - sem->m_count++; - return true; - } else { - return false; - } - return false; -} -#else /* CONFIG_RWSEM_PRIO_AWARE */ -void rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head) -{ -#ifdef CONFIG_KERNEL_LOCK_OPT - bool is_ux = lock_ux_target(tsk); -#else - bool is_ux = test_task_ux(tsk); -#endif - if (!entry || !head) { - return; - } - if (is_ux) { - rwsem_list_add_ux(entry, head); - } else { - list_add_tail(entry, head); - } -} -#endif /* CONFIG_RWSEM_PRIO_AWARE */ -#endif /* CONFIG_MTK_TASK_TURBO */ - -void rwsem_set_inherit_ux(struct task_struct *tsk, struct task_struct *waiter_task, struct task_struct *owner, struct rw_semaphore *sem) -{ - bool is_ux = test_set_inherit_ux(tsk); - if (waiter_task && is_ux) { - if (rwsem_owner_is_writer(owner) && sem && !sem->ux_dep_task) { - int type = get_ux_state_type(owner); - if ((UX_STATE_NONE == type) || (UX_STATE_INHERIT == type)) { - set_inherit_ux(owner, INHERIT_UX_RWSEM, tsk->ux_depth, tsk->ux_state); - sem->ux_dep_task = owner; - } - } - } -} - -void rwsem_unset_inherit_ux(struct rw_semaphore *sem, struct task_struct *tsk) -{ - if (tsk && sem && sem->ux_dep_task == tsk) { - unset_inherit_ux(tsk, INHERIT_UX_RWSEM); - sem->ux_dep_task = NULL; - } -} diff --git a/kernel/sched_assist/sched_assist_rwsem.h b/kernel/sched_assist/sched_assist_rwsem.h deleted file mode 100755 index f10a16658755..000000000000 --- a/kernel/sched_assist/sched_assist_rwsem.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_RWSEM_H_ -#define _OPLUS_SCHED_RWSEM_H_ - -#ifndef CONFIG_MTK_TASK_TURBO -#ifdef CONFIG_RWSEM_PRIO_AWARE -extern bool rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head, struct rw_semaphore *sem); -#else /* CONFIG_RWSEM_PRIO_AWARE */ -extern void rwsem_list_add(struct task_struct *tsk, struct list_head *entry, struct list_head *head); -#endif /* CONFIG_RWSEM_PRIO_AWARE */ -#endif /* CONFIG_MTK_TASK_TURBO */ - -extern void rwsem_set_inherit_ux(struct task_struct *tsk, struct task_struct *waiter_task, struct task_struct *owner, struct rw_semaphore *sem); -extern void rwsem_unset_inherit_ux(struct rw_semaphore *sem, struct task_struct *tsk); -#endif /* _OPLUS_SCHED_RWSEM_H_ */ diff --git a/kernel/sched_assist/sched_assist_slide.c b/kernel/sched_assist/sched_assist_slide.c deleted file mode 100755 index 790c8c166974..000000000000 --- a/kernel/sched_assist/sched_assist_slide.c +++ /dev/null @@ -1,237 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include <../kernel/sched/sched.h> - -#include "sched_assist_common.h" -#include "sched_assist_slide.h" - -#define UX_LOAD_WINDOW 8000000 -#define DEFAULT_INPUT_BOOST_DURATION 1000 -u64 ux_task_load[NR_CPUS] = {0}; -u64 ux_load_ts[NR_CPUS] = {0}; - -int sysctl_slide_boost_enabled = 0; -int sysctl_boost_task_threshold = 51; -int sysctl_frame_rate = 60; - -void sched_assist_adjust_slide_param(unsigned int *maxtime) { - /*give each scene with default boost value*/ - if (sched_assist_scene(SA_SLIDE)) { - if (sysctl_frame_rate <= 90) - *maxtime = 5; - else if (sysctl_frame_rate <= 120) - *maxtime = 4; - else - *maxtime = 3; - } else if (sched_assist_scene(SA_INPUT)) { - if (sysctl_frame_rate <= 90) - *maxtime = 8; - else if (sysctl_frame_rate <= 120) - *maxtime = 7; - else - *maxtime = 6; - } -} - -static u64 calc_freq_ux_load(struct task_struct *p, u64 wallclock) -{ - unsigned int maxtime = 5, factor = 0; - unsigned int window_size = sched_ravg_window / NSEC_PER_MSEC; - u64 timeline = 0, freq_exec_load = 0, freq_ravg_load = 0; - u64 wakeclock = p->wts.last_wake_ts; - - if (wallclock < wakeclock) - return 0; - - sched_assist_adjust_slide_param(&maxtime); - timeline = wallclock - wakeclock; - timeline = sf_union_ux_load(p, timeline); - factor = window_size / maxtime; - freq_exec_load = timeline * factor; - if (freq_exec_load > sched_ravg_window) - freq_exec_load = sched_ravg_window; - - freq_ravg_load = (p->wts.prev_window + p->wts.curr_window) << 1; - if (freq_ravg_load > sched_ravg_window) - freq_ravg_load = sched_ravg_window; - - return max(freq_exec_load, freq_ravg_load); -} - -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ - if (task_util(p) >= sysctl_boost_task_threshold || - scale_demand(p->wts.sum) >= sysctl_boost_task_threshold) { - *start_cpu = rd->wrd.mid_cap_orig_cpu == -1 ? - rd->wrd.max_cap_orig_cpu : rd->wrd.mid_cap_orig_cpu; - } -} - -bool _slide_task_misfit(struct task_struct *p, int cpu) -{ - int num_mincpu = cpumask_weight(topology_core_cpumask(0)); - return (is_task_util_over(p, sysctl_boost_task_threshold)&& cpu < num_mincpu); -} - -u64 _slide_get_boost_load(int cpu) { - u64 wallclock = sched_ktime_clock(); - u64 timeline = 0; - u64 ret_load = 0; - - if ((sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT)|| sched_assist_scene(SA_ANIM)) && ux_task_load[cpu]) { - timeline = wallclock - ux_load_ts[cpu]; - if (timeline >= UX_LOAD_WINDOW) - ux_task_load[cpu] = 0; - - ret_load = ux_task_load[cpu]; - } - - return ret_load; -} - -void adjust_sched_assist_input_ctrl(void) { - static int input_boost_old = 0; - - if (sysctl_input_boost_enabled) { - if(sysctl_slide_boost_enabled || jiffies_to_msecs(jiffies) >= sched_assist_input_boost_duration) { - sysctl_input_boost_enabled = 0; - sched_assist_input_boost_duration = 0; - } - } - if (input_boost_old != sysctl_input_boost_enabled) { - input_boost_old = sysctl_input_boost_enabled; - sched_assist_systrace(sysctl_input_boost_enabled, "ux input"); - } -} - -/* we may need to always keep slide-scene, use it! */ -bool __weak keep_slide_nolimit(struct task_struct *p) -{ - return false; -} - -void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu) { - u64 wallclock = sched_ktime_clock(); - adjust_sched_assist_input_ctrl(); - if (keep_slide_nolimit(rq->curr) || sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) { - if(rq->curr && (is_heavy_ux_task(rq->curr) || rq->curr->sched_class == &rt_sched_class) && !_slide_task_misfit(rq->curr, rq->cpu)) { - ux_task_load[cpu] = calc_freq_ux_load(rq->curr, wallclock); - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } - else if (ux_task_load[cpu] != 0) { - ux_task_load[cpu] = 0; - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_RESET); - } - } else { - ux_task_load[cpu] = 0; - ux_load_ts[cpu] = 0; - } - sched_assist_systrace(ux_task_load[cpu], "ux_load_%d", cpu); -} - -bool should_adjust_slide_task_placement(struct task_struct *p, int cpu) -{ - struct rq *rq = NULL; - - if (!check_slide_scene() && !keep_slide_nolimit(p)) - return false; - - if (!is_heavy_ux_task(p)) - return false; - - /* slide task running on silver core with util over threshold, boost it */ - if (oplus_task_misfit(p, cpu)) - return true; - - /* slide task should not share it's core with another slide task */ - rq = cpu_rq(cpu); - if (rq->curr && is_heavy_ux_task(rq->curr)) - return true; - - return false; -} - -int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_frame_rate, "ux frate"); - - return ret; -} - -int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table * table, int write, - void __user * buffer, size_t * lenp, loff_t * ppos) -{ - int result; - static DEFINE_MUTEX(sa_boost_mutex); - mutex_lock(&sa_boost_mutex); - result = proc_dointvec(table, write, buffer, lenp, ppos); - if (!write) - goto out; - /*orms write just write this proc to tell us update input window*/ - sched_assist_input_boost_duration = jiffies_to_msecs(jiffies) + DEFAULT_INPUT_BOOST_DURATION / sched_assist_ib_duration_coedecay; -out: - mutex_unlock(&sa_boost_mutex); - return result; -} - -int sysctl_sched_slide_boost_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_slide_boost_enabled, "ux slide"); - - return ret; -} - -int sysctl_sched_boost_task_threshold_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_boost_task_threshold, "ux threshold"); - - return ret; -} - -int sysctl_sched_animation_type_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - if (write) - sched_assist_systrace(sysctl_animation_type, "ux anima"); - - return ret; -} - - diff --git a/kernel/sched_assist/sched_assist_slide.h b/kernel/sched_assist/sched_assist_slide.h deleted file mode 100755 index 915daa5fb59a..000000000000 --- a/kernel/sched_assist/sched_assist_slide.h +++ /dev/null @@ -1,81 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_SLIDE_H_ -#define _OPLUS_SCHED_SLIDE_H_ - -#include -#include "sched_assist_common.h" - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) && defined(CONFIG_OPLUS_SYSTEM_KERNEL_QCOM) -extern unsigned int sched_ravg_window; -extern unsigned int walt_scale_demand_divisor; -#else -#ifdef CONFIG_HZ_300 -#define DEFAULT_SCHED_RAVG_WINDOW (3333333 * 6) -#else -#define DEFAULT_SCHED_RAVG_WINDOW 20000000 -#endif -#define sched_ravg_window DEFAULT_SCHED_RAVG_WINDOW -extern unsigned int walt_ravg_window; -#define walt_scale_demand_divisor (walt_ravg_window >> SCHED_CAPACITY_SHIFT) -#endif -#define scale_demand(d) ((d)/walt_scale_demand_divisor) - -extern int sysctl_slide_boost_enabled; -extern int sysctl_boost_task_threshold; -extern int sysctl_frame_rate; - -extern bool oplus_task_misfit(struct task_struct *p, int cpu); -extern bool _slide_task_misfit(struct task_struct *p, int cpu); -extern u64 _slide_get_boost_load(int cpu); -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu); - -extern void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu); -extern bool should_adjust_slide_task_placement(struct task_struct *p, int cpu); -extern int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_slide_boost_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_animation_type_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_boost_task_threshold_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -extern int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table * table, int write, void __user * buffer, size_t * lenp, loff_t * ppos); -extern bool keep_slide_nolimit(struct task_struct *p); - -static bool inline check_slide_scene(void) -{ - return sched_assist_scene(SA_SLIDE) - || sched_assist_scene(SA_LAUNCHER_SI) - || sched_assist_scene(SA_INPUT) - || sched_assist_scene(SA_ANIM); -} - -static bool inline slide_task_misfit(struct task_struct *p, int cpu) -{ - return check_slide_scene() && (is_heavy_ux_task(p) || is_sf(p)) && - oplus_task_misfit(p, cpu); -} - -static void inline slide_set_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ - if (check_slide_scene() && (is_heavy_ux_task(p) || is_sf(p))) - _slide_find_start_cpu(rd, p, start_cpu); -} - -static void inline slide_set_task_cpu(struct task_struct *p, int *best_energy_cpu) -{ - if (should_adjust_slide_task_placement(p, *best_energy_cpu)) - find_ux_task_cpu(p, best_energy_cpu); -} - -static void inline slide_set_boost_load(u64 *load, int cpu) -{ - u64 tmpload = *load; - - if (check_slide_scene()) { - tmpload = max_t(u64, tmpload, _slide_get_boost_load(cpu)); - *load = tmpload; - } -} -#endif /* _OPLUS_SCHED_SLIDE_H_ */ diff --git a/kernel/sched_assist/sched_assist_slide_v1.c b/kernel/sched_assist/sched_assist_slide_v1.c deleted file mode 100755 index 867764b37fa7..000000000000 --- a/kernel/sched_assist/sched_assist_slide_v1.c +++ /dev/null @@ -1,239 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ -#include -#include -#include -#include <../kernel/sched/sched.h> -#include <../kernel/sched/walt.h> -#include -#include "sched_assist_common.h" -#include "sched_assist_slide.h" - -#define UX_LOAD_WINDOW 8000000 -#define DEFAULT_INPUT_BOOST_DURATION 1000 -extern struct ux_sched_cputopo ux_sched_cputopo; -u64 ux_task_load[NR_CPUS] = {0}; -u64 ux_load_ts[NR_CPUS] = {0}; -int sysctl_slide_boost_enabled = 0; -int sysctl_boost_task_threshold = 51; -int sysctl_frame_rate = 60; - -void sched_assist_adjust_slide_param(unsigned int *maxtime) { -/* Give each scene with default boost value */ - if (sched_assist_scene(SA_SLIDE)) { - if (sysctl_frame_rate <= 90) - *maxtime = 5; - else if (sysctl_frame_rate <= 120) - *maxtime = 4; - else - *maxtime = 3; - } else if (sched_assist_scene(SA_INPUT)) { - if (sysctl_frame_rate <= 90) - *maxtime = 8; - else if (sysctl_frame_rate <= 120) - *maxtime = 7; - else - *maxtime = 6; - } -} - -static u64 calc_freq_ux_load(struct task_struct *p, u64 wallclock) -{ - unsigned int maxtime = 0, factor = 0; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - unsigned int window_size = sched_ravg_window / NSEC_PER_MSEC; -#else - unsigned int window_size = walt_ravg_window / NSEC_PER_MSEC; -#endif - u64 timeline = 0, freq_exec_load = 0, freq_ravg_load = 0; - u64 wakeclock = p->last_wake_ts; - - if (wallclock < wakeclock) - return 0; - - sched_assist_adjust_slide_param(&maxtime); - timeline = wallclock - wakeclock; - timeline = sf_union_ux_load(p, timeline); - factor = window_size / maxtime; - freq_exec_load = timeline * factor; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (freq_exec_load > sched_ravg_window) - freq_exec_load = sched_ravg_window; -#else - if (freq_exec_load > walt_ravg_window) - freq_exec_load = walt_ravg_window; -#endif - freq_ravg_load = (p->ravg.prev_window + p->ravg.curr_window) << 1; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (freq_ravg_load > sched_ravg_window) - freq_ravg_load = sched_ravg_window; -#else - if (freq_ravg_load > walt_ravg_window) - freq_ravg_load = walt_ravg_window; -#endif - return max(freq_exec_load, freq_ravg_load); -} - -void _slide_find_start_cpu(struct root_domain *rd, struct task_struct *p, int *start_cpu) -{ -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - if (task_util(p) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold) { -#else - if (READ_ONCE(p->se.avg.util_avg) >= sysctl_boost_task_threshold || - scale_demand(p->ravg.sum) >= sysctl_boost_task_threshold) { -#endif - if (ux_sched_cputopo.cls_nr > 2) { - *start_cpu = cpumask_first(&ux_sched_cputopo.sched_cls[1].cpus); - } else if (rd->max_cap_orig_cpu != -1) { - *start_cpu = rd->max_cap_orig_cpu; - } - } -} - -u64 _slide_get_boost_load(int cpu) { - u64 timeline = 0; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - u64 wallclock = sched_ktime_clock(); -#else - u64 wallclock = walt_ktime_clock(); -#endif - - if ((sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_INPUT) || - sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_ANIM)) - && ux_task_load[cpu]) { - timeline = wallclock - ux_load_ts[cpu]; - - if (timeline >= UX_LOAD_WINDOW) - ux_task_load[cpu] = 0; - - return ux_task_load[cpu]; - } else { - return 0; - } -} - -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -#define SCHED_CPUFREQ_RESET (1U << 7) -#define SCHED_CPUFREQ_BOOST (1U << 9) -#else -#define SCHED_CPUFREQ_WALT (1U << 4) -#define SCHED_CPUFREQ_RESET (1U << 7) -#define SCHED_CPUFREQ_BOOST (1U << 9) -#endif -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ - -void adjust_sched_assist_input_ctrl(void) { - if (!sysctl_input_boost_enabled) - return; - - if (sysctl_slide_boost_enabled) { - sysctl_input_boost_enabled = 0; - sched_assist_input_boost_duration = 0; - return; - } - - if (jiffies_to_msecs(jiffies) < sched_assist_input_boost_duration) { - return; - } else { - sched_assist_input_boost_duration = 0; - sysctl_input_boost_enabled = 0; - } -} - -void slide_calc_boost_load(struct rq *rq, unsigned int *flag, int cpu) { -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - u64 wallclock = sched_ktime_clock(); -#else - u64 wallclock = walt_ktime_clock(); -#endif - adjust_sched_assist_input_ctrl(); - if (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_LAUNCHER_SI) || sched_assist_scene(SA_INPUT)) { - if(rq->curr && (is_heavy_ux_task(rq->curr) || rq->curr->sched_class == &rt_sched_class) && !oplus_task_misfit(rq->curr, rq->cpu)) { - ux_task_load[cpu] = calc_freq_ux_load(rq->curr, wallclock); - ux_load_ts[cpu] = wallclock; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } else if (ux_task_load[cpu] && !test_task_ux(rq->curr)) { - ux_task_load[cpu] = 0; - *flag |= (SCHED_CPUFREQ_WALT | SCHED_CPUFREQ_BOOST); - } - } -} - -bool should_adjust_slide_task_placement(struct task_struct *p, int cpu) -{ - struct rq *rq = NULL; - - if (!check_slide_scene()) - return false; - - if (!is_heavy_ux_task(p)) - return false; - - /* slide task running on silver core with util over threshold, boost it */ - if (oplus_task_misfit(p, cpu)) - return true; - - /* slide task should not share it's core with another slide task */ - rq = cpu_rq(cpu); - if (rq->curr && is_heavy_ux_task(rq->curr)) - return true; - - return false; -} - -int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int ret; - - if (write && *ppos) - *ppos = 0; - - ret = proc_dointvec(table, write, buffer, lenp, ppos); - - return ret; -} - -int sysctl_sched_assist_input_boost_ctrl_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - int result; - static DEFINE_MUTEX(sa_boost_mutex); - - mutex_lock(&sa_boost_mutex); - result = proc_dointvec(table, write, buffer, lenp, ppos); - if (!write) - goto out; - - /* Orms write just write this proc to tell us update input window */ - sched_assist_input_boost_duration = jiffies_to_msecs(jiffies) + DEFAULT_INPUT_BOOST_DURATION / sysctl_sched_assist_ib_duration_coedecay; -#ifndef CONFIG_MACH_MT6877 - sysctl_boost_task_threshold = 102; -#endif -out: - mutex_unlock(&sa_boost_mutex); - return result; -} - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) -void oplus_get_cpu_util_mtk(int cpu, u64 *walt_cpu_util, int *boosted) -{ - if (sysctl_sched_assist_enabled && (sched_assist_scene(SA_SLIDE) || sched_assist_scene(SA_LAUNCHER_SI) || - sched_assist_scene(SA_INPUT) || sched_assist_scene(SA_ANIM)) && ux_task_load[cpu]) { - *boosted = true; - *walt_cpu_util = cpu_rq(cpu)->prev_runnable_sum; - slide_set_boost_load(walt_cpu_util, cpu); - *walt_cpu_util <<= SCHED_CAPACITY_SHIFT; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - do_div(*walt_cpu_util, sched_ravg_window); -#else - do_div(*walt_cpu_util, walt_ravg_window); -#endif - } else { - return; - } -} -#endif diff --git a/kernel/sched_assist/sched_assist_status.h b/kernel/sched_assist/sched_assist_status.h deleted file mode 100755 index b01f8c4d3f69..000000000000 --- a/kernel/sched_assist/sched_assist_status.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_SCHED_STATUS_H_ -#define _OPLUS_SCHED_STATUS_H_ -enum task_stats_type { - TST_SLEEP = 0, /* update sleeping time when enq-wakeup */ - TST_RUNNABLE, /* update runnable time when enq_deq */ - TST_EXEC, /* update exec time when deq-sleep */ - TST_SCHED_TYPE_TOTAL, /* total type*/ -}; - -#define TASK_INFO_SAMPLE 4 -struct task_info { - u64 sa_info[TST_SCHED_TYPE_TOTAL][TASK_INFO_SAMPLE]; - bool im_small; -}; - -extern int sysctl_sched_impt_tgid; -#endif /* _OPLUS_SCHED_STATUS_H_ */ diff --git a/kernel/sched_assist/sched_assist_trace.h b/kernel/sched_assist/sched_assist_trace.h deleted file mode 100755 index 98129a9aaf56..000000000000 --- a/kernel/sched_assist/sched_assist_trace.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#if !defined(_OPLUS_SCHED_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) -#define _OPLUS_SCHED_TRACE_H - -#include - -#undef TRACE_SYSTEM -#define TRACE_SYSTEM oplus_sched -#define TRACE_INCLUDE_FILE sched_assist_trace - -TRACE_EVENT(oplus_tp_sched_change_ux, - TP_PROTO(int chg_ux, int target_cpu), - TP_ARGS(chg_ux, target_cpu), - TP_STRUCT__entry( - __field(int, chg_ux) - __field(int, target_cpu)), - TP_fast_assign( - __entry->chg_ux = chg_ux; - __entry->target_cpu = target_cpu;), - TP_printk("chg_ux=%d target_cpu=%d", __entry->chg_ux, __entry->target_cpu) -); - -TRACE_EVENT(oplus_tp_sched_switch_ux, - TP_PROTO(int chg_ux, int target_cpu), - TP_ARGS(chg_ux, target_cpu), - TP_STRUCT__entry( - __field(int, chg_ux) - __field(int, target_cpu)), - TP_fast_assign( - __entry->chg_ux = chg_ux; - __entry->target_cpu = target_cpu;), - TP_printk("chg_ux=%d target_cpu=%d", __entry->chg_ux, __entry->target_cpu) -); - -#endif /* _OPLUS_SCHED_TRACE_H */ - -/* This part must be outside protection */ -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . -#include diff --git a/kernel/sched_assist/sched_assist_workqueue.c b/kernel/sched_assist/sched_assist_workqueue.c deleted file mode 100755 index dd542b607719..000000000000 --- a/kernel/sched_assist/sched_assist_workqueue.c +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - -#include -#include - -int is_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return 0; - - return work->ux_work; -} - -inline int set_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return false; - return work->ux_work = 1; -} - -inline int unset_uxwork(struct work_struct *work) -{ - if(!sysctl_sched_assist_enabled) - return false; - return work->ux_work = 0; -} - -inline void set_ux_worker_task(struct task_struct *task) -{ - task->ux_state = 1; -} - -inline void reset_ux_worker_task(struct task_struct *task) -{ - task->ux_state = 0; -} - -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ -#endif diff --git a/kernel/sched_assist/sched_assist_workqueue.h b/kernel/sched_assist/sched_assist_workqueue.h deleted file mode 100755 index c5156c36dcf1..000000000000 --- a/kernel/sched_assist/sched_assist_workqueue.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - - -#ifndef _OPLUS_WORKQUEUE_H_ -#define _OPLUS_WORKQUEUE_H_ - -struct worker; -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM -int is_uxwork(struct work_struct *work); -inline int set_uxwork(struct work_struct *work); -inline int unset_uxwork(struct work_struct *work); -inline void set_ux_worker_task(struct task_struct *task); -inline void reset_ux_worker_task(struct task_struct *task); -#else /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ -static inline int is_uxwork(struct work_struct *work) { return false; } -static inline int set_uxwork(struct work_struct *work) { return false; } -static inline int unset_uxwork(struct work_struct *work) { return false; } -static inline void set_ux_worker_task(struct task_struct *task) {} -static inline void reset_ux_worker_task(struct task_struct *task) {} -#endif /* CONFIG_OPLUS_SYSTEM_KERNEL_QCOM */ - -#endif /* _OPLUS_WORKQUEUE_H_ */ diff --git a/kernel/signal.c b/kernel/signal.c index 823d7603b6dd..38f3464bbf61 100755 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -52,15 +52,6 @@ #include #include #include "audit.h" /* audit_signal_info() */ -#ifdef OPLUS_FEATURE_HANS_FREEZE -// Kun.Zhou@AD.RESCONTROL, 2019/09/23, add for hans freeze manager -#include -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ - -#ifdef OPLUS_BUG_STABILITY -//Tian.Pan@ANDROID.STABILITY.NA.2020/07/22.add for dump android critical process log -#include -#endif /* * SLAB caches for signal bits. @@ -1073,16 +1064,6 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, result = TRACE_SIGNAL_IGNORED; -#ifdef OPLUS_BUG_STABILITY -//Haoran.Zhang@ANDROID.STABILITY.1052210, 2015/11/04, Modify for the sender who kill system_server - if(1) { - /*add the SIGKILL print log for some debug*/ - if((sig == SIGHUP || sig == 33 || sig == SIGKILL || sig == SIGSTOP || sig == SIGABRT || sig == SIGTERM || sig == SIGCONT) && is_key_process(t)) { - printk("Some other process %d:%s want to send sig:%d to pid:%d tgid:%d comm:%s\n", current->pid, current->comm,sig, t->pid, t->tgid, t->comm); - } - } -#endif - if (!prepare_signal(sig, t, from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == SEND_SIG_FORCED))) goto ret; @@ -1239,25 +1220,6 @@ int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, unsigned long flags; int ret = -ESRCH; -#ifdef OPLUS_FEATURE_HANS_FREEZE -//#Kun.Zhou@ANDROID.RESCONTROL, 2019/09/23, add for hans freeze manager - if (is_frozen_tg(p) /*signal receiver thread group is frozen?*/ - && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)) { - if (hans_report(SIGNAL, task_tgid_nr(current), task_uid(current).val, task_tgid_nr(p), task_uid(p).val, "signal", -1) == HANS_ERROR) { - printk(KERN_ERR "HANS: report signal-freeze failed, sig = %d, caller = %d, target_uid = %d\n", sig, task_tgid_nr(current), task_uid(p).val); - } - } -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ - -#if defined(CONFIG_CFS_BANDWIDTH) - if (is_belong_cpugrp(p) /*signal receiver thread group is cpuctl?*/ - && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)) { - if (hans_report(SIGNAL, task_tgid_nr(current), task_uid(current).val, task_tgid_nr(p), task_uid(p).val, "signal", -1) == HANS_ERROR) { - printk(KERN_ERR "HANS: report signal-cpuctl failed, sig = %d, caller = %d, target_uid = %d\n", sig, task_tgid_nr(current), task_uid(p).val); - } - } -#endif /*OPLUS_FEATURE_HANS_FREEZE*/ - if (lock_task_sighand(p, &flags)) { ret = send_signal(sig, info, p, group); unlock_task_sighand(p, &flags); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 5915eff1d2ee..e36c60dafa5b 100755 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -70,9 +70,6 @@ #include #include -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) -#include -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) */ #ifdef CONFIG_X86 #include @@ -99,18 +96,9 @@ #include #endif -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) -#include -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ #if defined(CONFIG_SYSCTL) -#if defined(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) && defined(CONFIG_OPLUS_FEATURE_DEATH_HEALER) -#include -#endif -#ifdef CONFIG_OPLUS_PREFER_SILVER -#include -#endif /* CONFIG_OPLUS_PREFER_SILVER */ /* External variables not in a header file. */ extern int suid_dumpable; @@ -134,22 +122,7 @@ extern int sysctl_nr_trim_pages; static int sixty = 60; #endif -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 -int sysctl_uxchain_v2 = 0; -u64 sysctl_mmapsem_uninterruptable_time; -#endif -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT -extern sysctl_sched_impt_tgid; -#endif -#ifdef CONFIG_OPLUS_BINDER_STRATEGY -#include -extern int sysctl_ob_control_enable; -extern int sysctl_binder_status_record; -extern int ob_pid; -extern int sysctl_ob_control_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -#endif static int __maybe_unused neg_one = -1; @@ -165,15 +138,7 @@ static int one_hundred = 100; static int two_hundred = 200; #endif -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -extern int direct_vm_swappiness; -static int two_hundred = 200; -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ -unsigned int sysctl_fg_io_opt = 1; -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ static int one_thousand = 1000; #ifdef CONFIG_PRINTK static int ten_thousand = 10000; @@ -345,22 +310,12 @@ static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1; #endif /* CONFIG_SCHED_DEBUG */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -int sysctl_sched_assist_enabled = 1; -int sysctl_sched_assist_scene = 0; -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ #ifdef CONFIG_COMPACTION static int min_extfrag_threshold; static int max_extfrag_threshold = 1000; #endif -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) -extern int sysctl_slide_boost_enabled; -extern int sysctl_boost_task_threshold; -extern int sysctl_frame_rate; -extern int sched_frame_rate_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); -#endif static struct ctl_table kern_table[] = { { @@ -370,16 +325,6 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, -#if defined(OPLUS_FEATURE_FG_IO_OPT) && defined(CONFIG_OPLUS_FG_IO_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-23,add foreground io opt*/ - { - .procname = "fg_io_opt", - .data = &sysctl_fg_io_opt, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, -#endif /*OPLUS_FEATURE_FG_IO_OPT*/ #ifdef CONFIG_SCHED_DEBUG { .procname = "sched_min_granularity_ns", @@ -1250,36 +1195,6 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = &neg_one, }, -#ifdef CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE - { - .procname = "hung_task_selective_monitoring", - .data = &sysctl_hung_task_selective_monitoring, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &zero, - .extra2 = &one, - }, -#endif -#if defined(CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE) && defined(CONFIG_OPLUS_FEATURE_DEATH_HEALER) -/* record the hung task killing */ - { - .procname = "hung_task_kill", - .data = &sysctl_hung_task_kill, - .maxlen = 128, - .mode = 0666, - .proc_handler = proc_dostring, - }, -/* Foreground background optimization,change max io count */ - { - .procname = "hung_task_maxiowait_count", - .data = &sysctl_hung_task_maxiowait_count, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &five, - }, -#endif #endif #ifdef CONFIG_RT_MUTEXES { @@ -1404,142 +1319,6 @@ static struct ctl_table kern_table[] = { .extra2 = &one, }, #endif -#ifdef CONFIG_OPLUS_PREFER_SILVER - { - .procname = "prefer_silver_enabled", - .data = &sysctl_prefer_silver, - .maxlen = sizeof(int), - .mode = 0660, - .proc_handler = proc_dointvec, - }, - { - .procname = "heavy_task_thresh", - .data = &sysctl_heavy_task_thresh, - .maxlen = sizeof(int), - .mode = 0444, - .proc_handler = proc_dointvec, - }, - { - .procname = "cpu_util_thresh", - .data = &sysctl_cpu_util_thresh, - .maxlen = sizeof(int), - .mode = 0444, - .proc_handler = proc_dointvec, - }, -#endif /* CONFIG_OPLUS_PREFER_SILVER */ -#ifdef CONFIG_OPLUS_BINDER_STRATEGY - { - .procname = "oplus_binder_control_enabled", - .data = &sysctl_ob_control_enable, - .maxlen = sizeof(int), - .mode = 0660, - .proc_handler = sysctl_ob_control_handler, - }, - { - .procname = "oplus_binder_status_enabled", - .data = &sysctl_binder_status_record, - .maxlen = sizeof(int), - .mode = 0660, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_bg_thread_pid", - .data = &ob_pid, - .maxlen = sizeof(int), - .mode = 0660, - .proc_handler = proc_dointvec, - }, -#endif -#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) - { - .procname = "task_cpustats_enable", - .data = &sysctl_task_cpustats_enable, - .maxlen = sizeof(unsigned int), - .mode = 0666, - .proc_handler = proc_dointvec_minmax, - .extra1 = &zero, - .extra2 = &one, - }, -#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_CTP) */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST - { - .procname = "sched_assist_enabled", - .data = &sysctl_sched_assist_enabled, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, - { - .procname = "sched_assist_scene", - .data = &sysctl_sched_assist_scene, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = sysctl_sched_assist_scene_handler, - }, -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_SCHED_WALT) - { - .procname = "slide_boost_enabled", - .data = &sysctl_slide_boost_enabled, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, - { - .procname = "boost_task_threshold", - .data = &sysctl_boost_task_threshold, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, - { - .procname = "animation_type", - .data = &sysctl_animation_type, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, - { - .procname = "frame_rate", - .data = &sysctl_frame_rate, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = sched_frame_rate_handler, - }, - { - .procname = "input_boost_enabled", - .data = &sysctl_input_boost_enabled, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = sysctl_sched_assist_input_boost_ctrl_handler, - }, -#endif /* OPLUS_FEATURE_SCHED_ASSIST */ -#ifdef OPLUS_FEATURE_SCHED_ASSIST -//#ifdef CONFIG_UXCHAIN_V2 - { - .procname = "uxchain_v2", - .data = &sysctl_uxchain_v2, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, - { - .procname = "mmapsem_uninterruptable_time", - .data = &sysctl_mmapsem_uninterruptable_time, - .maxlen = sizeof(u64), - .mode = 0666, - .proc_handler = proc_dointvec, - }, -#endif -#ifdef CONFIG_OPLUS_FEATURE_AUDIO_OPT - { - .procname = "sched_impt_tgid", - .data = &sysctl_sched_impt_tgid, - .maxlen = sizeof(int), - .mode = 0666, - .proc_handler = proc_dointvec, - }, -#endif { } }; @@ -1682,23 +1461,8 @@ static struct ctl_table vm_table[] = { #else .extra2 = &two_hundred, #endif -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) - .extra2 = &two_hundred, -#else .extra2 = &one_hundred, -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ }, -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) - { - .procname = "direct_swappiness", - .data = &direct_vm_swappiness, - .maxlen = sizeof(direct_vm_swappiness), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &zero, - .extra2 = &two_hundred, - }, -#endif #ifdef CONFIG_DYNAMIC_TUNNING_SWAPPINESS { .procname = "vm_swappiness_threshold1", @@ -1795,11 +1559,7 @@ static struct ctl_table vm_table[] = { .procname = "compact_memory", .data = &sysctl_compact_memory, .maxlen = sizeof(int), -#ifdef OPLUS_FEATURE_PERFORMANCE - .mode = 0222, -#else /*OPLUS_FEATURE_PERFORMANCE */ .mode = 0200, -#endif /* OPLUS_FEATURE_PERFORMANCE */ .proc_handler = sysctl_compaction_handler, }, { @@ -1830,17 +1590,6 @@ static struct ctl_table vm_table[] = { .proc_handler = min_free_kbytes_sysctl_handler, .extra1 = &zero, }, -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - { - .procname = "kswapd_threads", - .data = &kswapd_threads, - .maxlen = sizeof(kswapd_threads), - .mode = 0644, - .proc_handler = kswapd_threads_sysctl_handler, - .extra1 = &one, - .extra2 = &max_kswapd_threads, -}, -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ { .procname = "watermark_scale_factor", .data = &watermark_scale_factor, diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 5fa5bb1a07c2..eb26977776bf 100755 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -220,10 +220,6 @@ static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) if (alarm->function) { restart = alarm->function(alarm, base->gettime()); -#ifdef OPLUS_FEATURE_ALARMINFO_STANDBY - if (alarm->type == ALARM_REALTIME || alarm->type == ALARM_BOOTTIME) - pr_info("alarm_type=%d, alarm_owner=%s, alarm_func=%pf\n", alarm->type, alarm->comm, alarm->function); -#endif /* OPLUS_FEATURE_ALARMINFO_STANDBY */ } spin_lock_irqsave(&base->lock, flags); @@ -357,9 +353,6 @@ __alarm_init(struct alarm *alarm, enum alarmtimer_type type, alarm->function = function; alarm->type = type; alarm->state = ALARMTIMER_STATE_INACTIVE; -#ifdef OPLUS_FEATURE_ALARMINFO_STANDBY - memset(alarm->comm, 0, sizeof(alarm->comm)); -#endif /* OPLUS_FEATURE_ALARMINFO_STANDBY */ } /** @@ -392,9 +385,6 @@ void alarm_start(struct alarm *alarm, ktime_t start) alarmtimer_enqueue(base, alarm); hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS); spin_unlock_irqrestore(&base->lock, flags); -#ifdef OPLUS_FEATURE_ALARMINFO_STANDBY - memcpy(alarm->comm, current->comm, TASK_COMM_LEN); -#endif /* OPLUS_FEATURE_ALARMINFO_STANDBY */ trace_alarmtimer_start(alarm, base->gettime()); } diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 124c48c19d67..ca569372cada 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3019,38 +3019,10 @@ static bool rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) /* In case of error, head will be NULL */ if (unlikely(!head)) return true; - #ifndef OPLUS_BUG_STABILITY return reader->read == rb_page_commit(reader) && (commit == reader || (commit == head && head->read == rb_page_commit(commit))); - #else - - /* Reader should exhaust content in reader page */ - if (reader->read != rb_page_commit(reader)) - return false; - - /* - * If writers are committing on the reader page, knowing all - * committed content has been read, the ring buffer is empty. - */ - if (commit == reader) - return true; - - /* - * If writers are committing on a page other than reader page - * and head page, there should always be content to read. - */ - if (commit != head) - return false; - - /* - * Writers are committing on the head page, we just need - * to care about there're committed data, and the reader will - * swap reader page with head page when it is to read data. - */ - return rb_page_commit(commit) == 0; - #endif /*OPLUS_BUG_STABILITY*/ } diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index beb60c91a89c..37604a4b0086 100755 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -55,9 +55,7 @@ #include EXPORT_TRACEPOINT_SYMBOL(gpu_freq); #endif -/* #ifdef OPLUS_BUG_STABILITY */ -#include -/* #endif */ + /* * On boot up, the ring buffer is set to the minimum size, so that * we do not waste memory on systems that are not using tracing. @@ -2323,11 +2321,7 @@ trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, (entry = this_cpu_read(trace_buffered_event))) { /* Try to use the per cpu buffer first */ val = this_cpu_inc_return(trace_buffered_event_cnt); - #ifdef OPLUS_BUG_STABILITY - if ((len < (PAGE_SIZE - sizeof(*entry) - sizeof(entry->array[0]))) && val == 1) { - #else if ((len < (PAGE_SIZE - sizeof(*entry))) && val == 1) { - #endif /*OPLUS_BUG_STABILITY*/ trace_event_setup(entry, type, flags, pc); entry->array[0] = len; return entry; @@ -7933,14 +7927,6 @@ static int instance_rmdir(const char *name) static __init void create_trace_instances(struct dentry *d_tracer) { -/* #ifdef OPLUS_BUG_STABILITY */ -/* disable ftrace for aging test */ - if (get_eng_version() == AGING) { - pr_info("skip create_trace_instances for aging\n"); - return; - } -/* #endif */ - trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer, instance_mkdir, instance_rmdir); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index add886f4508f..19dba9f0b59d 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4428,45 +4428,6 @@ void print_worker_info(const char *log_lvl, struct task_struct *task) } } -#ifdef CONFIG_OPLUS_FEATURE_MIDAS -void get_worker_info(struct task_struct *task, char *buf) -{ - work_func_t *fn = NULL; - char name[WQ_NAME_LEN] = { }; - char fn_name[WQ_NAME_LEN] = { }; - char desc[WORKER_DESC_LEN] = { }; - struct pool_workqueue *pwq = NULL; - struct workqueue_struct *wq = NULL; - struct worker *worker; - - if (!(task->flags & PF_WQ_WORKER)) - return; - - /* - * This function is called without any synchronization and @task - * could be in any state. Be careful with dereferences. - */ - worker = kthread_probe_data(task); - - /* - * Carefully copy the associated workqueue's workfn and name. Keep - * the original last '\0' in case the original contains garbage. - */ - probe_kernel_read(&fn, &worker->current_func, sizeof(fn)); - probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq)); - probe_kernel_read(&wq, &pwq->wq, sizeof(wq)); - probe_kernel_read(name, wq->name, sizeof(name) - 1); - probe_kernel_read(desc, worker->desc, sizeof(desc) - 1); - - if (name[0]) { - strncpy(buf, name, sizeof(name)); - } else if (fn) { - snprintf(fn_name, sizeof(fn_name), "%pf", fn); - if (fn_name[0]) - strncpy(buf, fn_name, sizeof(fn_name)); - } -} -#endif static void pr_cont_pool_info(struct worker_pool *pool) { diff --git a/lib/Makefile b/lib/Makefile index 97edc93522f4..e16cd469e5f3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -264,10 +264,6 @@ UBSAN_SANITIZE_ubsan.o := n KASAN_SANITIZE_ubsan.o := n CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) -# ifdef OPLUS_FEATURE_MEMLEAK_DETECT -obj-$(CONFIG_VMALLOC_DEBUG) += memleak_debug_stackdepot.o -# endif - obj-$(CONFIG_SBITMAP) += sbitmap.o obj-$(CONFIG_PARMAN) += parman.o diff --git a/lib/memleak_debug_stackdepot.c b/lib/memleak_debug_stackdepot.c deleted file mode 100755 index 0194b67ad72a..000000000000 --- a/lib/memleak_debug_stackdepot.c +++ /dev/null @@ -1,334 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEPOT_STACK_BITS (sizeof(ml_depot_stack_handle_t) * 8) - -#define STACK_ALLOC_NULL_PROTECTION_BITS 1 -#define STACK_ALLOC_ORDER 0 /* 'Slab' size order for stack depot, 1 pages */ -#define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER)) -#define STACK_ALLOC_ALIGN 4 -#define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ - STACK_ALLOC_ALIGN) //9 -#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ - STACK_ALLOC_NULL_PROTECTION_BITS - STACK_ALLOC_OFFSET_BITS) //22 -#define STACK_ALLOC_SLABS_CAP 10240 -#define STACK_ALLOC_MAX_SLABS \ - (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ - (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP) - -/* The compact structure to store the reference to stacks. */ -union ml_handle_parts { - ml_depot_stack_handle_t handle; - struct { - u32 slabindex : STACK_ALLOC_INDEX_BITS; - u32 offset : STACK_ALLOC_OFFSET_BITS; - u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; - }; -}; - -struct ml_stack_record { - struct ml_stack_record *next; /* Link in the hashtable */ - u32 hash; /* Hash in the hastable */ - u32 size; /* Number of frames in the stack */ - union ml_handle_parts handle; - unsigned long entries[1]; /* Variable-sized array of entries. */ -}; - -static void **ml_stack_slabs = NULL; - -static int ml_depot_index; -static int ml_next_slab_inited; -static size_t ml_depot_offset; -static DEFINE_SPINLOCK(ml_depot_lock); -static DEFINE_MUTEX(ml_depot_init_mutex); -static atomic_t ml_stack_depot_inited = ATOMIC_INIT(0); - -static bool ml_init_stack_slab(void **prealloc) -{ - if (!*prealloc) - return false; - /* - * This smp_load_acquire() pairs with smp_store_release() to - * |ml_next_slab_inited| below and in ml_depot_alloc_stack(). - */ - if (smp_load_acquire(&ml_next_slab_inited)) - return true; - if (ml_stack_slabs[ml_depot_index] == NULL) { - ml_stack_slabs[ml_depot_index] = *prealloc; - } else { - ml_stack_slabs[ml_depot_index + 1] = *prealloc; - /* - * This smp_store_release pairs with smp_load_acquire() from - * |ml_next_slab_inited| above and in ml_depot_save_stack(). - */ - smp_store_release(&ml_next_slab_inited, 1); - } - *prealloc = NULL; - return true; -} - -/* Allocation of a new stack in raw storage */ -static struct ml_stack_record *ml_depot_alloc_stack(unsigned long *entries, int size, - u32 hash, void **prealloc, gfp_t alloc_flags) -{ - int required_size = offsetof(struct ml_stack_record, entries) + - sizeof(unsigned long) * size; - struct ml_stack_record *stack; - - required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); - - if (unlikely(ml_depot_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(ml_depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) { - WARN_ONCE(1, "Stack depot reached limit capacity"); - return NULL; - } - ml_depot_index++; - ml_depot_offset = 0; - /* - * smp_store_release() here pairs with smp_load_acquire() from - * |ml_next_slab_inited| in ml_depot_save_stack() and - * ml_init_stack_slab(). - */ - if (ml_depot_index + 1 < STACK_ALLOC_MAX_SLABS) - smp_store_release(&ml_next_slab_inited, 0); - } - ml_init_stack_slab(prealloc); - if (ml_stack_slabs[ml_depot_index] == NULL) - return NULL; - - stack = ml_stack_slabs[ml_depot_index] + ml_depot_offset; - - stack->hash = hash; - stack->size = size; - stack->handle.slabindex = ml_depot_index; - stack->handle.offset = ml_depot_offset >> STACK_ALLOC_ALIGN; - stack->handle.valid = 1; - memcpy(stack->entries, entries, size * sizeof(unsigned long)); - ml_depot_offset += required_size; - - return stack; -} - -#define STACK_HASH_SIZE (1L << 19) -#define STACK_HASH_MASK (STACK_HASH_SIZE - 1) -#define STACK_HASH_SEED 0x9747b28c - -static struct ml_stack_record **ml_stack_table = NULL; - -/* Calculate hash for a stack */ -static inline u32 ml_hash_stack(unsigned long *entries, unsigned int size) -{ - return jhash2((u32 *)entries, - size * sizeof(unsigned long) / sizeof(u32), - STACK_HASH_SEED); -} - -/* Use our own, non-instrumented version of memcmp(). - * - * We actually don't care about the order, just the equality. - */ -static inline -int ml_stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, - unsigned int n) -{ - for ( ; n-- ; u1++, u2++) { - if (*u1 != *u2) - return 1; - } - return 0; -} - -/* Find a stack that is equal to the one stored in entries in the hash */ -static inline struct ml_stack_record *ml_find_stack(struct ml_stack_record *bucket, - unsigned long *entries, int size, - u32 hash) -{ - struct ml_stack_record *found; - - for (found = bucket; found; found = found->next) { - if (found->hash == hash && - found->size == size && - !ml_stackdepot_memcmp(entries, found->entries, size)) - return found; - } - return NULL; -} - -void ml_depot_fetch_stack(ml_depot_stack_handle_t handle, struct stack_trace *trace) -{ - union ml_handle_parts parts = { .handle = handle }; - void *slab; - size_t offset; - struct ml_stack_record *stack; - - if (atomic_read(&ml_stack_depot_inited) == 0) { - pr_err("ml_stack_depot_inited is not inited\n"); - return; - } - - slab = ml_stack_slabs[parts.slabindex]; - offset = parts.offset << STACK_ALLOC_ALIGN; - stack = slab + offset; - trace->nr_entries = trace->max_entries = stack->size; - trace->entries = stack->entries; - trace->skip = 0; -} -EXPORT_SYMBOL_GPL(ml_depot_fetch_stack); - -/** - * ml_depot_save_stack - save stack in a stack depot. - * @trace - the stacktrace to save. - * @alloc_flags - flags for allocating additional memory if required. - * - * Returns the handle of the stack struct stored in depot. - */ -ml_depot_stack_handle_t ml_depot_save_stack(struct stack_trace *trace, - gfp_t alloc_flags) -{ - u32 hash; - ml_depot_stack_handle_t retval = 0; - struct ml_stack_record *found = NULL, **bucket; - unsigned long flags; - struct page *page = NULL; - void *prealloc = NULL; - - if (atomic_read(&ml_stack_depot_inited) == 0) { - pr_err("ml_stack_depot_inited is not inited\n"); - goto fast_exit; - } - - if (unlikely(trace->nr_entries == 0)) - goto fast_exit; - - hash = ml_hash_stack(trace->entries, trace->nr_entries); - bucket = &ml_stack_table[hash & STACK_HASH_MASK]; - - /* - * Fast path: look the stack trace up without locking. - * The smp_load_acquire() here pairs with smp_store_release() to - * |bucket| below. - */ - found = ml_find_stack(smp_load_acquire(bucket), trace->entries, - trace->nr_entries, hash); - if (found) - goto exit; - - /* - * Check if the current or the next stack slab need to be initialized. - * If so, allocate the memory - we won't be able to do that under the - * lock. - * - * The smp_load_acquire() here pairs with smp_store_release() to - * |ml_next_slab_inited| in ml_depot_alloc_stack() and ml_init_stack_slab(). - */ - if (unlikely(!smp_load_acquire(&ml_next_slab_inited))) { - /* - * Zero out zone modifiers, as we don't have specific zone - * requirements. Keep the flags related to allocation in atomic - * contexts and I/O. - */ - alloc_flags &= ~GFP_ZONEMASK; - alloc_flags &= (GFP_ATOMIC | GFP_KERNEL); - alloc_flags |= __GFP_NOWARN; - page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER); - if (page) - prealloc = page_address(page); - } - - spin_lock_irqsave(&ml_depot_lock, flags); - found = ml_find_stack(*bucket, trace->entries, trace->nr_entries, hash); - if (!found) { - struct ml_stack_record *new = - ml_depot_alloc_stack(trace->entries, trace->nr_entries, - hash, &prealloc, alloc_flags); - if (new) { - new->next = *bucket; - /* - * This smp_store_release() pairs with - * smp_load_acquire() from |bucket| above. - */ - smp_store_release(bucket, new); - found = new; - } - } else if (prealloc) { - /* - * We didn't need to store this stack trace, but let's keep - * the preallocated memory for the future. - */ - WARN_ON(!ml_init_stack_slab(&prealloc)); - } - spin_unlock_irqrestore(&ml_depot_lock, flags); - - if (prealloc) { - /* Nobody used this memory, ok to free it. */ - free_pages((unsigned long)prealloc, STACK_ALLOC_ORDER); - } - -exit: - if (found) - retval = found->handle.handle; -fast_exit: - return retval; -} -EXPORT_SYMBOL_GPL(ml_depot_save_stack); - -int ml_depot_init(void) -{ - int inited; - unsigned int size; - - mutex_lock(&ml_depot_init_mutex); - inited = atomic_read(&ml_stack_depot_inited); - if (inited != 0) { - mutex_unlock(&ml_depot_init_mutex); - pr_err("ml_stack_depot_inited is inited, val %d\n", inited); - return 0; - } - - size = sizeof(void *) * STACK_ALLOC_MAX_SLABS; - ml_stack_slabs = (void **)vmalloc(size); - if (!ml_stack_slabs) { - mutex_unlock(&ml_depot_init_mutex); - pr_err("vmalloc ml_stack_slabs %d failed.\n", size); - return -1; - } - memset(ml_stack_slabs, 0, size); - - size = sizeof(struct ml_stack_record *) * STACK_HASH_SIZE; - ml_stack_table = (struct ml_stack_record **)vmalloc(size); - if (!ml_stack_table) { - mutex_unlock(&ml_depot_init_mutex); - pr_err("vmalloc ml_stack_table %d failed.\n", size); - vfree(ml_stack_slabs); - ml_stack_slabs = NULL; - return -1; - } - memset(ml_stack_table, 0, size); - - atomic_set(&ml_stack_depot_inited, 1); - mutex_unlock(&ml_depot_init_mutex); - printk("ml_stack_depot_inited is inited.\n"); - return 0; -} -EXPORT_SYMBOL_GPL(ml_depot_init); - -int ml_get_depot_index(void) -{ - return ml_depot_index; -} -EXPORT_SYMBOL_GPL(ml_get_depot_index); diff --git a/lib/show_mem.c b/lib/show_mem.c index b50cea384de4..9eb372764a84 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c @@ -9,9 +9,6 @@ #include #include -#ifdef OPLUS_FEATURE_HEALTHINFO -#include -#endif /*OPLUS_FEATURE_HEALTHINFO*/ void show_mem(unsigned int filter, nodemask_t *nodemask) { @@ -53,7 +50,4 @@ void show_mem(unsigned int filter, nodemask_t *nodemask) #ifdef CONFIG_MEMORY_FAILURE printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) - printk("%lu pages ion total used\n", ion_total()>> PAGE_SHIFT); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ } diff --git a/mm/Kconfig b/mm/Kconfig index e4bd5705283c..adbaf769fb9c 100755 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -761,25 +761,6 @@ config ARCH_HAS_PTE_SPECIAL config ARCH_SUPPORTS_SPECULATIVE_PAGE_FAULT def_bool n -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) -#Support reclaim process inactive pages only -config PROCESS_RECLAIM_ENHANCE - bool "Enable process reclaim enchance" - depends on PROCESS_RECLAIM - default y - help - It allows to reclaim different type pages of the process by - /proc/process_reclaim. - - (echo inactive_file > /proc/PID/reclaim) reclaims inactive file-backed - pages only. - (echo inactive_anon > /proc/PID/reclaim) reclaims inactive anonymous - pages only. - (echo inactive > /proc/PID/reclaim) reclaims inactive file-backed and - anonymous pages only. - Any other vaule, please reference PROCESS_RECLAIM. -#endif - config SPECULATIVE_PAGE_FAULT bool "Speculative page faults" default n @@ -812,14 +793,6 @@ config PROCESS_RECLAIM Any other value is ignored. -#ifdef OPLUS_FEATURE_MULTI_FREEAREA -config PHYSICAL_ANTI_FRAGMENTATION - bool "Physical memory anti-fragmentation" - default y - help - Turn on the function of Physical memory anti-fragmentation. -#endif /* OPLUS_FEATURE_MULTI_FREEAREA */ - config FRAME_VECTOR bool @@ -841,17 +814,3 @@ config PERCPU_STATS This feature collects and exposes statistics via debugfs. The information includes global and per chunk statistics, which can be used to help understand percpu memory usage. - -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -#/* Kui.Zhang@TEC.Kernel.MM, 2020/06/12, memleak detect of kmalloc/vmalloc/ion */ -source "mm/malloc_track/Kconfig.compat" -source "mm/task_mem/Kconfig" -#endif - -#ifdef OPLUS_FEATURE_MULTI_KSWAPD -source "mm/multi_kswapd/Kconfig" -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ - -#ifdef OPLUS_FEATURE_HEALTHINFO -source "mm/healthinfo/Kconfig" -#endif /*OPLUS_FEATURE_HEALTHINFO*/ diff --git a/mm/Makefile b/mm/Makefile index 8a4cd7cd2e0d..f75903daaf0f 100755 --- a/mm/Makefile +++ b/mm/Makefile @@ -112,33 +112,4 @@ obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o obj-$(CONFIG_HMM) += hmm.o -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) -#/* Kui.Zhang@TEC.Kernel.Performance, 2019-03-13, add new interface for process memory reclaim*/ -#ifeq ($(OPLUS_FEATURE_PROCESS_RECLAIM), yes) -obj-$(CONFIG_PROCESS_RECLAIM_ENHANCE) += process_mm_reclaim.o -#else -#obj-$(CONFIG_PROCESS_RECLAIM_ENHANCE) += process_mm_reclaim_weak.o -#endif -#endif /*defined(OPLUS_FEATURE_PROCESS_RECLAIM) - -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) -#/* Kui.Zhang@TEC.Kernel.Performance, 2019-03-13, collect all tasks memory info */ -#ifeq ($(OPLUS_FEATURE_MEMLEAK_DETECT), yes) -obj-$(CONFIG_DUMP_TASKS_MEM) += task_mem/ -#endif -#endif /*defined(OPLUS_FEATURE_MEMLEAK_DETECT) - -#ifdef OPLUS_FEATURE_HEALTHINFO -#/* Jiheng.Xie@TECH.BSP.Kernel, 2019-12-11, add for slub debug*/ -obj-y += healthinfo/ -#endif /*OPLUS_FEATURE_HEALTHINFO*/ - -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) -obj-$(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) += multi_freearea.o -#endif - -#ifdef OPLUS_FEATURE_MULTI_KSWAPD -obj-$(CONFIG_OPLUS_MULTI_KSWAPD) += multi_kswapd/ -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ - obj-y += async_shrink_slabd.o diff --git a/mm/async_shrink_slabd.c b/mm/async_shrink_slabd.c index dfa510c9d3d7..bdf8ace0cd55 100644 --- a/mm/async_shrink_slabd.c +++ b/mm/async_shrink_slabd.c @@ -35,9 +35,6 @@ #include #include -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -#include -#endif #include "internal.h" diff --git a/mm/compaction.c b/mm/compaction.c index a2046890e23a..dfff531df61d 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -24,9 +24,6 @@ #include #include #include "internal.h" -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#include -#endif #ifdef CONFIG_COMPACTION static inline void count_compact_event(enum vm_event_item item) { @@ -1294,9 +1291,6 @@ static enum compact_result __compact_finished(struct zone *zone, { unsigned int order; const int migratetype = cc->migratetype; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc = 0; -#endif if (cc->contended || fatal_signal_pending(current)) return COMPACT_CONTENDED; @@ -1337,15 +1331,8 @@ static enum compact_result __compact_finished(struct zone *zone, /* Direct compactor: Is a suitable page free? */ -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { -#endif for (order = cc->order; order < MAX_ORDER; order++) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct free_area *area = &zone->free_area[flc][order]; -#else struct free_area *area = &zone->free_area[order]; -#endif bool can_steal; /* Job done if page is free of the right migratetype */ @@ -1387,9 +1374,6 @@ static enum compact_result __compact_finished(struct zone *zone, return COMPACT_CONTINUE; } } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif return COMPACT_NO_SUITABLE_PAGE; } diff --git a/mm/healthinfo/Kconfig b/mm/healthinfo/Kconfig deleted file mode 100644 index 01844c5d0ddd..000000000000 --- a/mm/healthinfo/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -config OPLUS_MEM_MONITOR - bool "memory monitor " - default n - help - memory monitor. -#endif /* OPLUS_FEATURE_HEALTHINFO */ diff --git a/mm/healthinfo/Makefile b/mm/healthinfo/Makefile deleted file mode 100644 index befedefa9d13..000000000000 --- a/mm/healthinfo/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -#ifdef OPLUS_FEATURE_HEALTHINFO -obj-$(CONFIG_OPLUS_MEM_MONITOR) += memory_monitor.o -#endif /* OPLUS_FEATURE_HEALTHINFO */ - diff --git a/mm/healthinfo/memory_monitor.c b/mm/healthinfo/memory_monitor.c deleted file mode 100755 index ed3f38d6566d..000000000000 --- a/mm/healthinfo/memory_monitor.c +++ /dev/null @@ -1,191 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include <../../mm/internal.h> -#include - -#ifdef CONFIG_OPLUS_HEALTHINFO -struct alloc_wait_para allocwait_para = { - .ux_alloc_wait.max_ms = 0, - .ux_alloc_wait.high_cnt = 0, - .ux_alloc_wait.low_cnt = 0, - .ux_alloc_wait.total_ms = 0, - .ux_alloc_wait.total_cnt = 0, - .fg_alloc_wait.max_ms = 0, - .fg_alloc_wait.high_cnt = 0, - .fg_alloc_wait.low_cnt = 0, - .fg_alloc_wait.total_ms = 0, - .fg_alloc_wait.total_cnt = 0, - .total_alloc_wait.max_ms = 0, - .total_alloc_wait.high_cnt = 0, - .total_alloc_wait.low_cnt = 0, - .total_alloc_wait.total_ms = 0, - .total_alloc_wait.total_cnt = 0 -}; - -struct ion_wait_para ionwait_para = { - .ux_ion_wait.max_ms = 0, - .ux_ion_wait.high_cnt = 0, - .ux_ion_wait.low_cnt = 0, - .ux_ion_wait.total_ms = 0, - .ux_ion_wait.total_cnt = 0, - .fg_ion_wait.max_ms = 0, - .fg_ion_wait.high_cnt = 0, - .fg_ion_wait.low_cnt = 0, - .fg_ion_wait.total_ms = 0, - .fg_ion_wait.total_cnt = 0, - .total_ion_wait.max_ms = 0, - .total_ion_wait.high_cnt = 0, - .total_ion_wait.low_cnt = 0, - .total_ion_wait.total_ms = 0, - .total_ion_wait.total_cnt = 0 -}; - -extern bool ohm_memmon_ctrl; -extern bool ohm_memmon_logon; -extern bool ohm_memmon_trig; -extern void ohm_action_trig(int type); - -extern bool ohm_ionmon_ctrl; -extern bool ohm_ionmon_logon; -extern bool ohm_ionmon_trig; - -#else -static bool ohm_memmon_ctrl = false; -static bool ohm_memmon_logon = false; -static bool ohm_memmon_trig = false; - -static bool ohm_ionmon_ctrl = false; -static bool ohm_ionmon_logon = false; -static bool ohm_ionmon_trig = false; - -void ohm_action_trig(int type) -{ - return; -} -#endif - -static int alloc_wait_h_ms = 500; -static int alloc_wait_l_ms = 100; -static int alloc_wait_log_ms = 1000; -static int alloc_wait_trig_ms = 10000; - -static int ion_wait_h_ms = 500; -static int ion_wait_l_ms = 100; -static int ion_wait_log_ms = 1000; -static int ion_wait_trig_ms = 10000; - -#ifdef OPLUS_FEATURE_SCHED_ASSIST -extern bool test_task_ux(struct task_struct *task); -#endif -void memory_alloc_monitor(gfp_t gfp_mask, unsigned int order, u64 wait_ms) -{ - int fg = 0; - int ux = 0; - if (unlikely(!ohm_memmon_ctrl)) - return; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - ux = test_task_ux(current); -#endif - fg = current_is_fg(); - if (ux) { - if (wait_ms > allocwait_para.ux_alloc_wait.max_ms) { - allocwait_para.ux_alloc_wait.max_ms = wait_ms; - allocwait_para.ux_alloc_wait_max_order = order; - } - if (wait_ms >= alloc_wait_h_ms) { - allocwait_para.ux_alloc_wait.high_cnt++; - } else if (wait_ms >= alloc_wait_l_ms) { - allocwait_para.ux_alloc_wait.low_cnt++; - } - } - if (fg) { - if (wait_ms > allocwait_para.fg_alloc_wait.max_ms) { - allocwait_para.fg_alloc_wait.max_ms = wait_ms; - allocwait_para.fg_alloc_wait_max_order = order; - } - if (wait_ms >= alloc_wait_h_ms) { - allocwait_para.fg_alloc_wait.high_cnt++; - } else if (wait_ms >= alloc_wait_l_ms) { - allocwait_para.fg_alloc_wait.low_cnt++; - } - } - if (wait_ms > allocwait_para.total_alloc_wait.max_ms) { - allocwait_para.total_alloc_wait.max_ms = wait_ms; - allocwait_para.total_alloc_wait_max_order = order; - } - if (wait_ms >= alloc_wait_h_ms) { - allocwait_para.total_alloc_wait.high_cnt++; - if (ohm_memmon_logon && (wait_ms >= alloc_wait_log_ms)) { - ohm_debug - ("[alloc_wait / %s] long, order %d, wait %lld ms!\n", - (fg ? "fg" : "bg"), order, wait_ms); - warn_alloc(gfp_mask, NULL, - "page allocation stalls for %lld ms, order: %d", - wait_ms, order); - } - if (ohm_memmon_trig && wait_ms >= alloc_wait_trig_ms) { - /* Trig Uevent */ - ohm_action_trig(OHM_MEM_MON); - } - } else if (wait_ms >= alloc_wait_l_ms) { - allocwait_para.total_alloc_wait.low_cnt++; - } -} - -void ionwait_monitor(u64 wait_ms) -{ - int fg = 0; - int ux = 0; - if (unlikely(!ohm_ionmon_ctrl)) - return; -#ifdef OPLUS_FEATURE_SCHED_ASSIST - ux = test_task_ux(current); -#endif - fg = current_is_fg(); - if (ux) { - if (wait_ms >= ion_wait_h_ms) { - ionwait_para.ux_ion_wait.high_cnt++; - } else if (wait_ms >= ion_wait_l_ms) { - ionwait_para.ux_ion_wait.low_cnt++; - } - } - if (fg) { - if (wait_ms >= ion_wait_h_ms) { - ionwait_para.fg_ion_wait.high_cnt++; - } else if (wait_ms >= ion_wait_l_ms) { - ionwait_para.fg_ion_wait.low_cnt++; - } - } - if (wait_ms > ionwait_para.total_ion_wait.max_ms) { - ionwait_para.total_ion_wait.max_ms = wait_ms; - } - if (wait_ms >= ion_wait_h_ms) { - ionwait_para.total_ion_wait.high_cnt++; - if (ohm_ionmon_logon && (wait_ms >= ion_wait_log_ms)) { - ohm_debug("[ion_wait / %s] long, wait %lld ms!\n", - (fg ? "fg" : "bg"), wait_ms); - } - if (ohm_ionmon_trig && wait_ms >= ion_wait_trig_ms) { - /* Trig Uevent */ - ohm_action_trig(OHM_ION_MON); - } - } else if (wait_ms >= ion_wait_l_ms) { - ionwait_para.total_ion_wait.low_cnt++; - } -} - -module_param_named(ion_wait_h_ms, ion_wait_h_ms, int, S_IRUGO | S_IWUSR); -module_param_named(ion_wait_l_ms, ion_wait_l_ms, int, S_IRUGO | S_IWUSR); -module_param_named(ion_wait_log_ms, ion_wait_log_ms, int, S_IRUGO | S_IWUSR); diff --git a/mm/madvise.c b/mm/madvise.c index 78af3ba3c711..a823608a5258 100755 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -192,13 +192,8 @@ out: } #ifdef CONFIG_SWAP -#if defined(CONFIG_NANDSWAP) || defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk) -#else static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, unsigned long end, struct mm_walk *walk) -#endif { pte_t *orig_pte; struct vm_area_struct *vma = walk->private; @@ -213,10 +208,6 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, struct page *page; spinlock_t *ptl; -#if defined(CONFIG_NANDSWAP) || defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - if (!list_empty(&vma->vm_mm->mmap_sem.wait_list)) - return -1; -#endif orig_pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl); pte = *(orig_pte + ((index - start) / PAGE_SIZE)); pte_unmap_unlock(orig_pte, ptl); diff --git a/mm/malloc_track/Kconfig b/mm/malloc_track/Kconfig deleted file mode 100644 index 79dd80fc73b7..000000000000 --- a/mm/malloc_track/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config OPLUS_MEMLEAK_DETECT - string - default "$(OPLUS_MEMLEAK_DETECT)" - -config KMALLOC_DEBUG - default n - bool "Enable Create kmalloc caches with debug flag" - depends on STACKTRACE && SLUB_DEBUG - help - If kmalloc-* slab has memleak, will replace the kmalloc cache - with a new kmalloc debug cache. The new kmalloc cache will enable - SLAB_STORE_USER. - -source "mm/malloc_track/Kconfig.in" diff --git a/mm/malloc_track/Kconfig.compat b/mm/malloc_track/Kconfig.compat deleted file mode 100644 index c52150503264..000000000000 --- a/mm/malloc_track/Kconfig.compat +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config OPLUS_MEMLEAK_DETECT - string - option env="OPLUS_MEMLEAK_DETECT" - -config KMALLOC_DEBUG - default n - bool "Enable Create kmalloc caches with debug flag" - depends on STACKTRACE - help - If kmalloc-* slab has memleak, will replace the kmalloc cache - with a new kmalloc debug cache. The new kmalloc cache will enable - SLAB_STORE_USER. - -source "mm/malloc_track/Kconfig.in" diff --git a/mm/malloc_track/Kconfig.in b/mm/malloc_track/Kconfig.in deleted file mode 100644 index cbb7ee68a01b..000000000000 --- a/mm/malloc_track/Kconfig.in +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config VMALLOC_DEBUG - bool "trace vmalloc called information with a stack" - default n - help - trace vmalloc called information with a stack. - -config MEMLEAK_DETECT_THREAD - bool "One kernel thread to detect memleak and dump infomation to log" - depends on (KMALLOC_DEBUG || VMALLOC_DEBUG) && SVELTE - default y if OPLUS_MEMLEAK_DETECT="true" - default n - help - a daemon to monitor kernel memory leak. diff --git a/mm/malloc_track/slub_track.c b/mm/malloc_track/slub_track.c deleted file mode 100755 index e0f1bc38a489..000000000000 --- a/mm/malloc_track/slub_track.c +++ /dev/null @@ -1,1207 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _SLUB_TRACK_ -#define _SLUB_TRACK_ -#include -#include -#include - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -extern void dump_meminfo_to_logger(const char *tag, char *msg, size_t len); -#endif - -/* - * sort the locations with count from more to less. - */ -#define LOCATIONS_TRACK_BUF_SIZE(s) ((s->object_size == 128) ? (PAGE_SIZE << 10) : (PAGE_SIZE * 128)) -#define KD_SLABTRACE_STACK_CNT TRACK_ADDRS_COUNT -#define KD_BUFF_LEN(total, len) (total - len - 101) -#define KD_BUFF_LEN_MAX(total) (total - 101 - 100) -#define KD_BUFF_LEN_EXT(total, len) (total - len - 55) - -struct kd_location { - unsigned long count; - unsigned long addr; - unsigned long addrs[KD_SLABTRACE_STACK_CNT]; /* caller address */ - u32 depth; - u32 hash; - long long sum_time; - long min_time; - long max_time; - long min_pid; - long max_pid; -}; - -struct kd_loc_track { - unsigned long max; - unsigned long count; - struct kd_location *loc; -}; - -/* - * kmalloc_debug_info add debug to slab name. - */ -const struct kmalloc_info_struct kmalloc_debug_info[] = { - {NULL, 0}, {"kmalloc-debug-96", 96}, - {"kmalloc-debug-192", 192}, {"kmalloc-debug-8", 8}, - {"kmalloc-debug-16", 16}, {"kmalloc-debug-32", 32}, - {"kmalloc-debug-64", 64}, {"kmalloc-debug-128", 128}, - {"kmalloc-debug-256", 256}, {"kmalloc-debug-512", 512}, - {"kmalloc-debug-1k", 1024}, {"kmalloc-debug-2k", 2048}, - {"kmalloc-debug-4k", 4096}, {"kmalloc-debug-8k", 8192}, - {"kmalloc-debug-16k", 16384}, {"kmalloc-debug-32k", 32768}, - {"kmalloc-debug-64k", 65536}, {"kmalloc-debug-128k", 131072}, - {"kmalloc-debug-256k", 262144}, {"kmalloc-debug-512k", 524288}, - {"kmalloc-debug-1M", 1048576}, {"kmalloc-debug-2M", 2097152}, - {"kmalloc-debug-4M", 4194304}, {"kmalloc-debug-8M", 8388608}, - {"kmalloc-debug-16M", 16777216}, {"kmalloc-debug-32M", 33554432}, - {"kmalloc-debug-64M", 67108864} -}; - -/* - * kmalloc_debug_caches store the kmalloc caches with debug flag. - */ -atomic64_t kmalloc_debug_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1] = {{ATOMIC64_INIT(0)}}; -EXPORT_SYMBOL(kmalloc_debug_caches); - -int kmalloc_debug_enable = 0; -EXPORT_SYMBOL(kmalloc_debug_enable); - -struct task_struct *memleak_detect_task = NULL; -static DEFINE_MUTEX(debug_mutex); - -extern unsigned long calculate_kmalloc_slab_size(struct kmem_cache *s); - -static int kd_location_cmp(const void *la, const void *lb) -{ - return ((struct kd_location *)lb)->count - ((struct kd_location *)la)->count; -} - -static void kd_location_swap(void *la, void *lb, int size) -{ - struct kd_location l_tmp; - - memcpy(&l_tmp, la, size); - memcpy(la, lb, size); - memcpy(lb, &l_tmp, size); -} - -static void kd_free_loc_track(struct kd_loc_track *t) -{ - if (t->max) - vfree(t->loc); -} - -static int kd_alloc_loc_track(struct kd_loc_track *t, int buff_size) -{ - struct kd_location *l; - - l = (void *)vmalloc(buff_size); - if (!l) { - buff_size >>= 1; - l = (void *)vmalloc(buff_size); - if (!l) - return -ENOMEM; - } - - t->count = 0; - t->max = buff_size / sizeof(struct kd_location); - t->loc = l; - return 0; -} - -static int kd_add_location(struct kd_loc_track *t, struct kmem_cache *s, - const struct track *track) -{ - long start, end, pos; - struct kd_location *l; - /* - * save the stack depth and hash. - */ - u32 hash; - unsigned long age; - - if (track->hash == 0) - return -EINVAL; - - age = jiffies - track->when; - start = -1; - end = t->count; - - for ( ; ; ) { - pos = start + (end - start + 1) / 2; - - /* - * There is nothing at "end". If we end up there - * we need to add something to before end. - */ - if (pos == end) - break; - - hash = t->loc[pos].hash; - if (track->hash == hash) { - l = &t->loc[pos]; - l->count++; - if (track->when) { - l->sum_time += age; - if (age < l->min_time) - l->min_time = age; - if (age > l->max_time) - l->max_time = age; - - if (track->pid < l->min_pid) - l->min_pid = track->pid; - if (track->pid > l->max_pid) - l->max_pid = track->pid; - } - return 0; - } - /* - * use hash value to record the stack. - */ - if (track->hash < hash) - end = pos; - else - start = pos; - } - - /* - * Not found. Insert new tracking element. - */ - if (t->count >= t->max) - return -ENOMEM; - - l = t->loc + pos; - if (pos < t->count) - memmove(l + 1, l, - (t->count - pos) * sizeof(struct kd_location)); - t->count++; - l->count = 1; - l->addr = track->addr; - l->sum_time = age; - l->min_time = age; - l->max_time = age; - l->min_pid = track->pid; - l->max_pid = track->pid; - l->depth = min_t(u32, (u32)(sizeof(l->addrs)/sizeof(l->addrs[0])), - track->depth); - l->hash = track->hash; -#ifdef COMPACT_OPLUS_SLUB_TRACK - { - int i; - for (i = 0; i < l->depth; i++) - l->addrs[i] = track->addrs[i] + MODULES_VADDR; - } -#else - memcpy(l->addrs, track->addrs, sizeof(l->addrs[0])*l->depth); -#endif - return 0; -} - -static int kd_process_slab(struct kd_loc_track *t, struct kmem_cache *s, - struct page *page, unsigned long *map) -{ - void *addr = page_address(page); - void *p; - unsigned int dropped = 0; - - bitmap_zero(map, page->objects); - get_map(s, page, map); - - for_each_object(p, s, addr, page->objects) - if (!test_bit(slab_index(p, s, addr), map)) - if (kd_add_location(t, s, get_track(s, p, TRACK_ALLOC))) - dropped++; - return dropped; -} - -static int kd_list_locations(struct kmem_cache *s, char *buf, int buff_len) -{ - int len = 0; - unsigned long i, j; - struct kd_loc_track t = { 0, 0, NULL }; - int node; - unsigned long *map = vmalloc(BITS_TO_LONGS(oo_objects(s->max)) * sizeof(unsigned long)); - struct kmem_cache_node *n; - int ret; - int dropped = 0; - - if (!map || kd_alloc_loc_track(&t, LOCATIONS_TRACK_BUF_SIZE(s))) { - vfree(map); - len = sprintf(buf, "Out of memory\n"); - return len; - } - - /* Push back cpu slabs */ - flush_all(s); - - for_each_kmem_cache_node(s, node, n) { - unsigned long flags; - struct page *page; - - if (!atomic_long_read(&n->nr_slabs)) - continue; - - spin_lock_irqsave(&n->list_lock, flags); - list_for_each_entry(page, &n->partial, lru) { - ret = kd_process_slab(&t, s, page, map); - if (ret) - dropped += ret; - } - list_for_each_entry(page, &n->full, lru) { - ret = kd_process_slab(&t, s, page, map); - if (ret) - dropped += ret; - } - spin_unlock_irqrestore(&n->list_lock, flags); - } - vfree(map); - - /* - * sort the locations with count from more to less. - */ - sort(&t.loc[0], t.count, sizeof(struct kd_location), kd_location_cmp, - kd_location_swap); - - for (i = 0; i < t.count; i++) { - struct kd_location *l = &t.loc[i]; - - if (len >= KD_BUFF_LEN_MAX(buff_len)) - break; - - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), "%7ld ", - l->count); - - if (l->addr) - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), "%pS", - (void *)l->addr); - else - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - ""); - - if (l->sum_time != l->min_time) - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - " age=%ld/%ld/%ld", - l->min_time, - (long)div_u64(l->sum_time, l->count), - l->max_time); - else - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - " age=%ld", l->min_time); - - if (l->min_pid != l->max_pid) - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - " pid=%ld-%ld", l->min_pid, l->max_pid); - else - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - " pid=%ld", l->min_pid); - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), "\n"); - - for (j = 0; j < l->depth; j++) - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), - "%pS\n", (void *)l->addrs[j]); - len += scnprintf(buf + len, KD_BUFF_LEN(buff_len, len), "\n"); - } - if (t.count && (buf[len -1] != '\n')) - buf[len++] = '\n'; - kd_free_loc_track(&t); - - if (!t.count) - len += scnprintf(buf + len, KD_BUFF_LEN_EXT(buff_len, len), - "%s no data\n", s->name); - if (dropped) - len += scnprintf(buf + len, KD_BUFF_LEN_EXT(buff_len, len), - "%s dropped %d %lu %lu\n", - s->name, dropped, t.count, t.max); - if (buf[len -1] != '\n') - buf[len++] = '\n'; - return len; -} - -int kbuf_dump_kmalloc_debug(struct kmem_cache *s, char *kbuf, int buff_len) -{ - memset(kbuf, 0, buff_len); - return kd_list_locations(s, kbuf, buff_len); -} - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#define KMALLOC_DEBUG_MIN_WATERMARK 100u -#define KMALLOC_DEBUG_DUMP_STEP 20u -#define BUFLEN(total, len) (total - len - 81) -#define BUFLEN_EXT(total, len) (total - len - 1) -#define KMALLOC_LOG_TAG "kmalloc_debug" - -static unsigned int kmalloc_debug_watermark[KMALLOC_SHIFT_HIGH + 1]; - -void kmalloc_debug_watermark_init(void) -{ - int i; - unsigned int water; - - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - if (kmalloc_debug_info[i].size <= 128) - water = KMALLOC_DEBUG_MIN_WATERMARK; - else - water = KMALLOC_DEBUG_MIN_WATERMARK >> 1; - kmalloc_debug_watermark[i] = water; - } -} - -static void dump_locations(struct kmem_cache *s, int slab_size, int index, - char *dump_buff, int len) -{ - unsigned long i, j; - struct kd_loc_track t = { 0, 0, NULL }; - unsigned long *map; - int node; - struct kmem_cache_node *n; - int ret, dropped = 0; - int dump_buff_len = 0; - - map = vmalloc(BITS_TO_LONGS(oo_objects(s->max)) * sizeof(unsigned long)); - if (!map || kd_alloc_loc_track(&t, LOCATIONS_TRACK_BUF_SIZE(s))) { - vfree(map); - pr_err("[kmalloc_debug] Out of memory\n"); - return; - } - - /* Push back cpu slabs */ - flush_all(s); - - for_each_kmem_cache_node(s, node, n) { - unsigned long flags; - struct page *page; - - if (!atomic_long_read(&n->nr_slabs)) - continue; - - spin_lock_irqsave(&n->list_lock, flags); - list_for_each_entry(page, &n->partial, lru) { - ret = kd_process_slab(&t, s, page, map); - if (ret) - dropped += ret; - } - list_for_each_entry(page, &n->full, lru) { - ret = kd_process_slab(&t, s, page, map); - if (ret) - dropped += ret; - } - spin_unlock_irqrestore(&n->list_lock, flags); - } - vfree(map); - - sort(&t.loc[0], t.count, sizeof(struct kd_location), kd_location_cmp, - kd_location_swap); - - dump_buff_len = scnprintf(dump_buff + dump_buff_len, - len - dump_buff_len - 2, - "%s used %u MB Water %u MB:\n", s->name, slab_size, - kmalloc_debug_watermark[index]); - - for (i = 0; i < t.count; i++) { - struct kd_location *l = &t.loc[i]; - - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%ld KB %pS age=%ld/%ld/%ld pid=%ld-%ld\n", - (l->count * s->object_size) >> 10, - (void *)l->addr, - l->min_time, - (long)div_u64(l->sum_time, l->count), - l->max_time, - l->min_pid, l->max_pid); - - for (j = 0; j < l->depth; j++) - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%pS\n", (void *)l->addrs[j]); - - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), "-\n"); - } - - kd_free_loc_track(&t); - if (!t.count) - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN_EXT(len, dump_buff_len), - "[kmalloc_debug]%s no data\n", s->name); - - if (dropped) - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN_EXT(len, dump_buff_len), - "%s dropped %d %lu %lu\n", - s->name, dropped, t.count, t.max); - dump_buff[dump_buff_len++] = '\n'; - dump_meminfo_to_logger(KMALLOC_LOG_TAG, dump_buff, dump_buff_len); -} - -void dump_kmalloc_debug_info(struct kmem_cache *s, int index, char *dump_buff, - int len) -{ - unsigned int slab_size; - - slab_size = calculate_kmalloc_slab_size(s) >> 20; - if (slab_size < kmalloc_debug_watermark[index]) { - pr_warn("[kmalloc_debug]slab %s size %uMB is not over %uMB, ignore it.\n", - s->name, slab_size, kmalloc_debug_watermark[index]); - return; - } - - if (!dump_buff) { - pr_err("[kmalloc_debug] dump_buff is NULL.\n"); - return; - } - - kmalloc_debug_watermark[index] += KMALLOC_DEBUG_DUMP_STEP; - dump_locations(s, slab_size, index, dump_buff, len); -} -#endif - -static inline const char * -kmalloc_debug_cache_name(const char *prefix, unsigned int size) -{ - static const char units[3] = "\0kM"; - int idx = 0; - - while (size >= 1024 && (size % 1024 == 0)) { - size /= 1024; - idx++; - } - - return kasprintf(GFP_NOWAIT, "%s-%u%c", prefix, size, units[idx]); -} - -static struct kmem_cache *create_kmalloc_debug_caches(size_t size, - unsigned long flags, enum kmalloc_cache_type kmalloc_type) -{ - unsigned int index = kmalloc_index(size); - struct kmem_cache *s; - const char *name; - - if ((!index) || (index < KMALLOC_SHIFT_LOW) || - (index > KMALLOC_SHIFT_HIGH)) { - pr_warn("kmalloc debug cache create failed size %lu index %d\n", - size, index); - return NULL; - } - - s = kmalloc_caches[kmalloc_type][index]; - if (!s) { - pr_warn("kmalloc-%lu slab is NULL, do not create debug one\n", - size); - return NULL; - } - - if (s->flags & SLAB_STORE_USER) { - pr_warn("%s slab is enable SLAB_STORE_USER, do not "\ - "create a new debug slab and size %lu.\n", - s->name, size); - return NULL; - } - - if (kmalloc_type == KMALLOC_RECLAIM) { - flags |= SLAB_RECLAIM_ACCOUNT; - name = kmalloc_debug_cache_name("kmalloc-debug-rcl", - kmalloc_debug_info[index].size); - if (!name) - return NULL; - } else - name = kmalloc_debug_info[index].name; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) - s = kmem_cache_create(name, kmalloc_debug_info[index].size, - ARCH_KMALLOC_MINALIGN, flags, NULL); -#else - s = kmem_cache_create_usercopy(name, kmalloc_debug_info[index].size, - ARCH_KMALLOC_MINALIGN, flags, 0, - kmalloc_debug_info[index].size, NULL); -#endif - if (kmalloc_type == KMALLOC_RECLAIM) - kfree(name); - - return s; -} - -#define KMALLOC_DEBUG_R_LEN 1024 - -static ssize_t kmalloc_debug_create_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char *kbuf; - struct kmem_cache *s; - int i, type; - int len = 0; - - kbuf = kzalloc(KMALLOC_DEBUG_R_LEN, GFP_KERNEL); - if (!kbuf) { - pr_warn("[kmalloc_debug] %s allo kbuf failed.\n", __func__); - return -ENOMEM; - } - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - s = (struct kmem_cache *)atomic64_read( - &kmalloc_debug_caches[type][i]); - if (s) - len += scnprintf(kbuf+len, KMALLOC_DEBUG_R_LEN - len - 1, - "%s\n", s->name); - } - } - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - s = kmalloc_caches[type][i]; - if (s && (s->flags & SLAB_STORE_USER)) - len += scnprintf(kbuf+len, KMALLOC_DEBUG_R_LEN - len - 1, - "%s\n", s->name); - } - } - - if ((len > 0) && (kbuf[len - 1] != '\n')) - kbuf[len++] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf, (len < count ? len : count))) { - kfree(kbuf); - return -EFAULT; - } - kfree(kbuf); - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static ssize_t kmalloc_debug_create_write(struct file *file, const char __user *buff, - size_t len, loff_t *ppos) -{ - char kbuf[64] = {'0'}; - long size; - int ret, type; - unsigned int index; - struct kmem_cache *s; - - if (!kmalloc_debug_enable) - return -EPERM; - - if (len > 63) - len = 63; - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - ret = kstrtol(kbuf, 10, &size); - if (ret) - return -EINVAL; - - index = kmalloc_index(size); - mutex_lock(&debug_mutex); - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[type][index]); - if (s) { - pr_warn("slab %s has been created, addr is %p, size %lu.\n", - kmalloc_debug_info[index].name, s, size); - mutex_unlock(&debug_mutex); - return -EEXIST; - } - } - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - s = create_kmalloc_debug_caches((size_t)size, SLAB_STORE_USER, type); - if (!s) { - mutex_unlock(&debug_mutex); - return -ENOMEM; - } - atomic64_set(&kmalloc_debug_caches[type][index], (unsigned long)s); - } - mutex_unlock(&debug_mutex); - - return len; -} - -static const struct file_operations kmalloc_debug_create_operations = { - .read = kmalloc_debug_create_read, - .write = kmalloc_debug_create_write, -}; - -#if (defined(CONFIG_KMALLOC_DEBUG) || defined(CONFIG_VMALLOC_DEBUG)) -#define MEMLEAK_DETECT_SLEEP_SEC (5400 * HZ) - -#ifdef CONFIG_VMALLOC_DEBUG -#ifdef CONFIG_MEMLEAK_DETECT_THREAD -extern void dump_vmalloc_debug(char *dump_buff, int len); -#endif -extern void enable_vmalloc_debug(void); -extern void disable_vmalloc_debug(void); -#endif - -#ifdef CONFIG_KMALLOC_DEBUG -#ifdef CONFIG_MEMLEAK_DETECT_THREAD -extern void kmalloc_debug_watermark_init(void); -extern void dump_kmalloc_debug_info(struct kmem_cache *s, int index, - char *dump_buff, int len); -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) -extern void dump_ion_info(char *dump_buff, int len); -#endif -#endif - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -static const struct file_operations memleak_detect_thread_operations; -#endif - -extern int kbuf_dump_kmalloc_debug(struct kmem_cache *s, char *kbuf, int buff_len); - -#define KD_VALUE_LEN (32) -#define DATA_LEN (PAGE_SIZE) -#define ALL_KMALLOC_HIGH (KMALLOC_SHIFT_HIGH * 2 + 1) -#define CACHE_INDEX(index) ((index) % (KMALLOC_SHIFT_HIGH + 1)) -#define CACHE_TYPE(index) ((index) / (KMALLOC_SHIFT_HIGH + 1)) - -static inline void -memleak_accumulate_slabinfo(struct kmem_cache *s, struct slabinfo *info) -{ - struct kmem_cache *c; - struct slabinfo sinfo; - - if (!is_root_cache(s)) - return; - - for_each_memcg_cache(c, s) { - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(c, &sinfo); - - info->active_slabs += sinfo.active_slabs; - info->num_slabs += sinfo.num_slabs; - info->shared_avail += sinfo.shared_avail; - info->active_objs += sinfo.active_objs; - info->num_objs += sinfo.num_objs; - } -} - -unsigned long calculate_kmalloc_slab_size(struct kmem_cache *s) -{ - struct slabinfo sinfo; - - memset(&sinfo, 0, sizeof(sinfo)); - get_slabinfo(s, &sinfo); - memleak_accumulate_slabinfo(s, &sinfo); - return sinfo.num_objs * s->object_size; -} - -static void *kmo_start(struct seq_file *m, loff_t *pos) -{ - struct kmem_cache *s = NULL; - - while (*pos <= ALL_KMALLOC_HIGH) { - s = kmalloc_caches[CACHE_TYPE(*pos)][CACHE_INDEX(*pos)]; - if (s && (s->flags & SLAB_STORE_USER)) - return (void *)s; - ++*pos; - } - - return NULL; -} - -static void *kmo_next(struct seq_file *m, void *p, loff_t *pos) -{ - struct kmem_cache *s = NULL; - - ++*pos; - while (*pos <= ALL_KMALLOC_HIGH) { - s = kmalloc_caches[CACHE_TYPE(*pos)][CACHE_INDEX(*pos)]; - if (s && (s->flags & SLAB_STORE_USER)) - return (void *)s; - ++*pos; - } - - return NULL; -} - -static void *kmd_start(struct seq_file *m, loff_t *pos) -{ - struct kmem_cache *s = NULL; - - while (*pos <= ALL_KMALLOC_HIGH) { - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[CACHE_TYPE(*pos)][CACHE_INDEX(*pos)]); - if (s && (s->flags & SLAB_STORE_USER)) - return (void *)s; - ++*pos; - } - - return NULL; -} - -static void *kmd_next(struct seq_file *m, void *p, loff_t *pos) -{ - struct kmem_cache *s = NULL; - - ++*pos; - while (*pos <= ALL_KMALLOC_HIGH) { - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[CACHE_TYPE(*pos)][CACHE_INDEX(*pos)]); - if (s && (s->flags & SLAB_STORE_USER)) - return (void *)s; - ++*pos; - } - - return NULL; -} - -static void kmd_stop(struct seq_file *m, void *p) -{ -} - -static int kmd_show(struct seq_file *m, void *p) -{ - struct kmem_cache *s = (struct kmem_cache *)p; - - (void)kbuf_dump_kmalloc_debug(s, (char *)m->private, DATA_LEN); - seq_printf(m, "=== slab %s debug info:\n", s->name); - seq_printf(m, "%s\n", (char *)m->private); - - return 0; -} - -static const struct seq_operations kmalloc_debug_op = { - .start = kmd_start, - .next = kmd_next, - .show = kmd_show, - .stop = kmd_stop -}; - -static const struct seq_operations kmalloc_origin_op = { - .start = kmo_start, - .next = kmo_next, - .show = kmd_show, - .stop = kmd_stop -}; - -static int kmalloc_debug_open(struct inode *inode, struct file *file) -{ - void *priv = __seq_open_private(file, &kmalloc_debug_op, DATA_LEN); - - if (!priv) - return -ENOMEM; - - return 0; -} - -static int kmalloc_origin_open(struct inode *inode, struct file *file) -{ - void *priv = __seq_open_private(file, &kmalloc_origin_op, DATA_LEN); - - if (!priv) - return -ENOMEM; - - return 0; -} - -static ssize_t kmalloc_debug_enable_write(struct file *file, - const char __user *buff, size_t len, loff_t *ppos) -{ - char kbuf[KD_VALUE_LEN] = {'0'}; - long val; - int ret; - - if (len > (KD_VALUE_LEN - 1)) - len = KD_VALUE_LEN - 1; - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - ret = kstrtol(kbuf, 10, &val); - if (ret) - return -EINVAL; - - kmalloc_debug_enable = val ? 1 : 0; - return len; -} - -static ssize_t kmalloc_debug_enable_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[KD_VALUE_LEN] = {'0'}; - int len; - - len = scnprintf(kbuf, KD_VALUE_LEN - 1, "%d\n", kmalloc_debug_enable); - if (kbuf[len - 1] != '\n') - kbuf[len++] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static ssize_t kmalloc_used_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[512] = {'\0'}; - int len = 0; - int i, type; - - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - unsigned long slab_size = 0; - - for(type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - struct kmem_cache *s; - - s = kmalloc_caches[type][i]; - if (!s) - continue; - slab_size += calculate_kmalloc_slab_size(s); - - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[type][i]); - if (!s) - continue; - slab_size += calculate_kmalloc_slab_size(s); - } - - if (slab_size == 0) - continue; - - len += scnprintf(&kbuf[len], 511 - len, "%-8u %lu\n", - kmalloc_debug_info[i].size, slab_size >> 10); - if (len >= 511) - break; - } - - if ((len > 0) && (kbuf[len - 1] != '\n')) - kbuf[len++] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static const struct file_operations kmalloc_used_ops = { - .read = kmalloc_used_read, -}; - -static const struct file_operations kmalloc_debug_enable_operations = { - .write = kmalloc_debug_enable_write, - .read = kmalloc_debug_enable_read, -}; - -static const struct file_operations kmalloc_debug_operations = { - .open = kmalloc_debug_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release_private, -}; - -static const struct file_operations kmalloc_origin_operations = { - .open = kmalloc_origin_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release_private, -}; - -int __init create_kmalloc_debug(struct proc_dir_entry *parent) -{ - struct proc_dir_entry *dpentry; - struct proc_dir_entry *opentry; - struct proc_dir_entry *cpentry; - struct proc_dir_entry *epentry; - struct proc_dir_entry *upentry; -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) - struct proc_dir_entry *mpentry; -#endif - - dpentry = proc_create("kmalloc_debug", S_IRUGO, parent, - &kmalloc_debug_operations); - if (!dpentry) { - pr_err("create kmalloc_debug proc failed.\n"); - return -ENOMEM; - } - - opentry = proc_create("kmalloc_origin", S_IRUGO, parent, - &kmalloc_origin_operations); - if (!opentry) { - pr_err("create kmalloc_origin proc failed.\n"); - proc_remove(dpentry); - return -ENOMEM; - } - - epentry = proc_create("kmalloc_debug_enable", - S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, - parent, &kmalloc_debug_enable_operations); - if (!epentry) { - pr_err("create kmalloc_debug_enable proc failed.\n"); - proc_remove(opentry); - proc_remove(dpentry); - return -ENOMEM; - } - - upentry = proc_create("kmalloc_used", S_IRUGO, parent, - &kmalloc_used_ops); - if (!upentry) { - pr_err("create kmalloc_used proc failed.\n"); - proc_remove(epentry); - proc_remove(opentry); - proc_remove(dpentry); - return -ENOMEM; - } - - /* add new proc interface for create kmalloc debug caches. */ - cpentry = proc_create("kmalloc_debug_create", S_IRUGO|S_IWUGO, parent, - &kmalloc_debug_create_operations); - if (!cpentry) { - pr_err("create kmalloc_debug_create proc failed.\n"); - proc_remove(upentry); - proc_remove(epentry); - proc_remove(opentry); - proc_remove(dpentry); - return -ENOMEM; - } - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) - mpentry = proc_create("memleak_detect_thread", S_IRUGO|S_IWUGO, parent, - &memleak_detect_thread_operations); - if (!cpentry) { - pr_err("create memleak_detect_thread_operations proc failed.\n"); - proc_remove(cpentry); - proc_remove(upentry); - proc_remove(epentry); - proc_remove(opentry); - proc_remove(dpentry); - return -ENOMEM; - } -#endif - return 0; -} -EXPORT_SYMBOL(create_kmalloc_debug); -#endif - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#define DUMP_BUFF_LEN (PAGE_SIZE << 1) - -static int memleak_detect_thread(void *arg) -{ - long ret = 0; - long sleep_jiffies = MEMLEAK_DETECT_SLEEP_SEC; - int i, type; - - do { - char *dump_buff = NULL; - - current->state = TASK_INTERRUPTIBLE; - ret = schedule_timeout(sleep_jiffies); - if (ret) { - sleep_jiffies = ret; - continue; - } - sleep_jiffies = MEMLEAK_DETECT_SLEEP_SEC; - - dump_buff = (char *)vmalloc(DUMP_BUFF_LEN); - if (!dump_buff) { - pr_err("[%s] vmalloc dump_buff failed.\n", __func__); - continue; - } - -#ifdef CONFIG_VMALLOC_DEBUG - dump_vmalloc_debug(dump_buff, DUMP_BUFF_LEN); -#endif - -#ifdef CONFIG_KMALLOC_DEBUG - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - struct kmem_cache *s = kmalloc_caches[type][i]; - - if (!s) - continue; - if (s->flags & SLAB_STORE_USER) - dump_kmalloc_debug_info(s, i, dump_buff, - DUMP_BUFF_LEN); - } - } - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - struct kmem_cache *s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[type][i]); - - if (!s) - continue; - if (s->flags & SLAB_STORE_USER) - dump_kmalloc_debug_info(s, i, dump_buff, - DUMP_BUFF_LEN); - } - } -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) - dump_ion_info(dump_buff, DUMP_BUFF_LEN); -#endif - vfree(dump_buff); - } while (!kthread_should_stop()); - - return 0; -} - -static inline void init_kmalloc_debug_caches(unsigned long flags) -{ - int i, type; - struct kmem_cache *s; - - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { - for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) { - if (atomic64_read(&kmalloc_debug_caches[type][i])) - continue; - - s = create_kmalloc_debug_caches(kmalloc_debug_info[i].size, - flags, type); - - /* - * Caches that are not of the two-to-the-power-of size. - * These have to be created immediately after the - * earlier power of two caches - */ - if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[type][1] && i == 6) - s = create_kmalloc_debug_caches(kmalloc_debug_info[i].size, - flags, type); - if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[type][2] && i == 7) - s = create_kmalloc_debug_caches(kmalloc_debug_info[i].size, - flags, type); - - if (!s) - break; - - atomic64_set(&kmalloc_debug_caches[type][i], (unsigned long)s); - } - } - kmalloc_debug_enable = 1; -} - -static ssize_t memleak_detect_thread_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[16] = {'0'}; - int len = 0; - - if (count > 15) - count = 15; - - len = scnprintf(kbuf, count, "%d\n", memleak_detect_task ? 1 : 0); - kbuf[len++] = '\0'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf, len)) - return -EFAULT; - - *off += len; - return len; -} - -static ssize_t memleak_detect_thread_write(struct file *file, const char __user *buff, - size_t len, loff_t *ppos) -{ - char kbuf[16] = {'0'}; - long val; - int ret; - - if (len > 15) - len = 15; - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - ret = kstrtol(kbuf, 10, &val); - if (ret) - return -EINVAL; - - mutex_lock(&debug_mutex); - if (val > 0) { - if (memleak_detect_task) - goto out; - -#ifdef CONFIG_VMALLOC_DEBUG - enable_vmalloc_debug(); -#endif -#ifdef CONFIG_KMALLOC_DEBUG - init_kmalloc_debug_caches(SLAB_STORE_USER); - kmalloc_debug_watermark_init(); -#endif - - memleak_detect_task = kthread_create(memleak_detect_thread, NULL, - "memleak_detect"); - if (IS_ERR(memleak_detect_task)) { - pr_warn("[kmalloc_debug][vmalloc_debug] memleak_detect_init failed.\n"); - memleak_detect_task = NULL; - } else - wake_up_process(memleak_detect_task); - } else if (memleak_detect_task) { -#ifdef CONFIG_VMALLOC_DEBUG - disable_vmalloc_debug(); -#endif -#ifdef CONFIG_KMALLOC_DEBUG - kmalloc_debug_enable = 0; -#endif - kthread_stop(memleak_detect_task); - memleak_detect_task = NULL; - } - -out: - mutex_unlock(&debug_mutex); - return len; -} - -static const struct file_operations memleak_detect_thread_operations = { - .read = memleak_detect_thread_read, - .write = memleak_detect_thread_write, -}; - -static int __init memleak_detect_init(void) -{ -#ifdef CONFIG_VMALLOC_DEBUG - enable_vmalloc_debug(); -#endif - -#ifdef CONFIG_KMALLOC_DEBUG - init_kmalloc_debug_caches(SLAB_STORE_USER); - kmalloc_debug_watermark_init(); -#endif - - memleak_detect_task = kthread_create(memleak_detect_thread, NULL, "memleak_detect"); - if (IS_ERR(memleak_detect_task)) { - pr_warn("[kmalloc_debug][vmalloc_debug] memleak_detect_init failed.\n"); - memleak_detect_task = NULL; - } else - wake_up_process(memleak_detect_task); - - return 0; -} -#else -static int __init memleak_detect_init(void) -{ - return 0; -} -#endif /* CONFIG_MEMLEAK_DETECT_THREAD */ -module_init(memleak_detect_init); -#endif /* CONFIG_KMALLOC_DEBUG || CONFIG_VMALLOC_DEBUG */ -#endif /* _SLUB_TRACK_ */ diff --git a/mm/malloc_track/vmalloc_track.c b/mm/malloc_track/vmalloc_track.c deleted file mode 100755 index 03b1705f3880..000000000000 --- a/mm/malloc_track/vmalloc_track.c +++ /dev/null @@ -1,605 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef _VMALLOC_DEBUG_ -#define _VMALLOC_DEBUG_ -#include -#include -#include -#include -#include -#include -#include -#include - -/* remember the vmalloc info. */ -static atomic_t vmalloc_count = ATOMIC_INIT(0); - -/* save vmalloc stack. */ -#ifdef CONFIG_MEMLEAK_DETECT_THREAD -#define VMALLOC_STACK_DEPTH 16 -#else -#define VMALLOC_STACK_DEPTH 10 -#endif -#define VD_VALUE_LEN 32 - -static int vmalloc_debug_enable = 0; -static atomic64_t hash_cal_sum_us = ATOMIC64_INIT(0); -static atomic64_t hash_cal_times = ATOMIC64_INIT(0); -static unsigned long hash_cal_max_us; - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#define LOGGER_PRELOAD_SIZE 4076 -extern void logger_kmsg_nwrite(const char *tag, const char *msg, size_t len); - -static inline int find_last_lf(char *buf, size_t len) -{ - int i = len - 1; - - for (; i >= 0; i--) { - if (buf[i] == '\n') - break; - } - - return (i < 0) ? -1 : i + 1; -} - -void dump_meminfo_to_logger(const char *tag, char *msg, size_t total_len) -{ - int len; - size_t tag_len = strlen(tag); - char *wr_msg = msg; - - while (total_len > 0) { - if ((total_len + tag_len + 3) <= LOGGER_PRELOAD_SIZE) { - logger_kmsg_nwrite(tag, (const char *)wr_msg, total_len); - return; - } - - len = LOGGER_PRELOAD_SIZE - 3 - tag_len; - len = find_last_lf(wr_msg, len); - if (len < 0) - return; - - logger_kmsg_nwrite(tag, (const char *)wr_msg, len); - - wr_msg += len; - total_len -= len; - } -} -EXPORT_SYMBOL(dump_meminfo_to_logger); -#endif - -static noinline ml_depot_stack_handle_t _save_vmalloc_stack(gfp_t flags) -{ - unsigned long entries[VMALLOC_STACK_DEPTH]; - struct stack_trace trace = { - .nr_entries = 0, - .entries = entries, - .max_entries = VMALLOC_STACK_DEPTH, -#ifdef CONFIG_64BIT - .skip = 4 -#else - .skip = 3 -#endif - }; - ml_depot_stack_handle_t handle; - unsigned long delay; - unsigned long start = sched_clock(); - - save_stack_trace(&trace); - if (trace.nr_entries != 0 && - trace.entries[trace.nr_entries-1] == ULONG_MAX) - trace.nr_entries--; - - handle = ml_depot_save_stack(&trace, flags); - if (handle) { - delay = (sched_clock() - start) / 1000; - if (delay > hash_cal_max_us) - hash_cal_max_us = delay; - atomic64_add(delay, &hash_cal_sum_us); - atomic64_inc(&hash_cal_times); - } - return handle; -} - -static unsigned int save_vmalloc_stack(unsigned long flags, struct vmap_area *va) -{ - if (flags & VM_ALLOC) { - atomic_inc(&vmalloc_count); - if (vmalloc_debug_enable) - return _save_vmalloc_stack(GFP_KERNEL); - } - - return 0; -} - -static void dec_vmalloc_stat(struct vmap_area *va) -{ - if (va->vm->flags & VM_ALLOC) - atomic_dec(&vmalloc_count); -} - -static ssize_t vmalloc_debug_enable_write(struct file *file, - const char __user *buff, size_t len, loff_t *ppos) -{ - char kbuf[VD_VALUE_LEN] = {'0'}; - long val; - int ret; - - if (len > (VD_VALUE_LEN - 1)) - len = VD_VALUE_LEN - 1; - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - ret = kstrtol(kbuf, 10, &val); - if (ret) - return -EINVAL; - - if (val) { - ret = ml_depot_init(); - if (ret) - return -ENOMEM; - vmalloc_debug_enable = 1; - } else - vmalloc_debug_enable = 0; - - return len; -} - -static ssize_t vmalloc_debug_enable_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[VD_VALUE_LEN] = {'0'}; - int len; - - len = scnprintf(kbuf, VD_VALUE_LEN - 1, "%d\n", vmalloc_debug_enable); - if (kbuf[len - 1] != '\n') - kbuf[len++] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static ssize_t hash_cal_time_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[128] = {'0'}; - int len; - unsigned long sum_us = atomic64_read(&hash_cal_sum_us); - unsigned long times = atomic64_read(&hash_cal_times); - - len = scnprintf(kbuf, 127, "%lu %lu %lu %lu\n", - sum_us, times, sum_us / times, hash_cal_max_us); - if (kbuf[len - 1] != '\n') - kbuf[len++] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -void enable_vmalloc_debug(void) -{ - int ret; - - ret = ml_depot_init(); - if (ret) { - pr_err("init depot failed, oom.\n"); - return; - } - vmalloc_debug_enable = 1; -} -EXPORT_SYMBOL(enable_vmalloc_debug); - -void disable_vmalloc_debug(void) -{ - vmalloc_debug_enable = 0; -} -EXPORT_SYMBOL(disable_vmalloc_debug); - -static const struct file_operations hash_cal_time_ops = { - .read = hash_cal_time_read, -}; - -static const struct file_operations proc_vmalloc_debug_enable_ops = { - .write = vmalloc_debug_enable_write, - .read = vmalloc_debug_enable_read, -}; - -typedef struct { - const void *caller; - unsigned int hash; - unsigned int nr_pages; -} vmalloc_debug_list; - -typedef struct { - unsigned long max; - unsigned long count; - vmalloc_debug_list *data; -} vmalloc_record_t; - -static int add_record(vmalloc_record_t *t, struct vm_struct *v) -{ - long start, end, pos; - vmalloc_debug_list *l; - unsigned int hash; - - start = -1; - end = t->count; - - for ( ; ; ) { - pos = start + (end - start + 1) / 2; - - /* - * There is nothing at "end". If we end up there - * we need to add something to before end. - */ - if (pos == end) - break; - - hash = t->data[pos].hash; - if (v->hash == hash) { - l = &t->data[pos]; - l->nr_pages += v->nr_pages; - return 1; - } - - if (v->hash < hash) - end = pos; - else - start = pos; - } - - /* - * Not found. Insert new tracking element. - */ - if (t->count >= t->max) - return 0; - - l = t->data + pos; - if (pos < t->count) - memmove(l + 1, l, (t->count - pos) * sizeof(vmalloc_record_t)); - t->count++; - l->caller = v->caller; - l->hash = v->hash; - l->nr_pages = v->nr_pages; - return 1; -} - -static int record_cmp(const void *la, const void *lb) -{ - return ((vmalloc_debug_list *)lb)->nr_pages - \ - ((vmalloc_debug_list *)la)->nr_pages; -} - -static void record_swap(void *la, void *lb, int size) -{ - vmalloc_debug_list l_tmp; - - memcpy(&l_tmp, la, size); - memcpy(la, lb, size); - memcpy(lb, &l_tmp, size); -} - -static inline char *dump_vmalloc_debug_info(unsigned int inlen, unsigned int *outlen) -{ - unsigned int vmalloc_entry_count = atomic_read(&vmalloc_count); - vmalloc_record_t record; - char *kbuf; - struct vmap_area *va; - struct vm_struct *v; - unsigned int i, j; - int ret; - unsigned int len = 0; - struct stack_trace trace; - unsigned int add_record_cnt = 0; - - record.data = vmalloc((sizeof(vmalloc_debug_list) * vmalloc_entry_count)); - if (!record.data) { - pr_err("vmalloc_debug : malloc record.data failed.\n"); - return NULL; - } - - kbuf = kmalloc(inlen, GFP_KERNEL); - if (!kbuf) { - pr_err("vmalloc_debug : malloc kbuf failed.\n"); - vfree(record.data); - return NULL; - } - - record.max = vmalloc_entry_count; - record.count = 0; - spin_lock(&vmap_area_lock); - list_for_each_entry(va, &vmap_area_list, list) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) - if (!(va->flags & VM_VM_AREA)) - continue; -#endif - v = va->vm; - if (!v) - continue; - - if (!(v->flags & VM_ALLOC) || (v->hash == 0)) - continue; - - ret = add_record(&record, v); - if (!ret) - break; - - add_record_cnt++; - } - spin_unlock(&vmap_area_lock); - - sort(record.data, record.count, sizeof(vmalloc_debug_list), - record_cmp, record_swap); - - /* reserve one byte for '\n' */ - inlen--; - for (i = 0; i < record.count; i++) { - len += scnprintf(kbuf+len, inlen-len, "- %u KB -\n", - record.data[i].nr_pages << 2); - - if (record.data[i].hash) { - memset(&trace, 0, sizeof(trace)); - ml_depot_fetch_stack(record.data[i].hash, &trace); - for (j = 0; j < trace.nr_entries; j++) { - len += scnprintf(kbuf+len, inlen-len, - "%pS\n", (void *)trace.entries[j]); - if (len == inlen) - break; - } - len += scnprintf(kbuf+len, inlen-len, "\n"); - } - - if (len == inlen) - break; - } - if ((len > 0) && (kbuf[len - 1] != '\n')) - kbuf[len++] = '\n'; - - vfree(record.data); - *outlen = len; - return kbuf; -} - -#if defined(CONFIG_MEMLEAK_DETECT_THREAD) && defined(CONFIG_SVELTE) -#define VMALLOC_DEBUG_STEP 30ll -#define VMALLOC_DUMP_WATER_MIN 180ll -#define BUFLEN(total, len) (total - len - 25) -#define BUFLEN_EXT(total, len) (total - len - 1) -#define VMALLOC_LOG_TAG "vmalloc_debug" - -static inline void dump_vmalloc_dmesg(unsigned long used_size, char *dump_buff, - int len) -{ - unsigned int vmalloc_entry_count = atomic_read(&vmalloc_count); - vmalloc_record_t record; - struct vmap_area *va; - struct vm_struct *v; - unsigned int i, j; - struct stack_trace trace; - int dump_buff_len = 0; - - record.data = vmalloc((sizeof(vmalloc_debug_list) * vmalloc_entry_count)); - if (!record.data) { - pr_err("[vmalloc_debug] : malloc record.data failed.\n"); - return; - } - record.max = vmalloc_entry_count; - record.count = 0; - - spin_lock(&vmap_area_lock); - list_for_each_entry(va, &vmap_area_list, list) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) - if (!(va->flags & VM_VM_AREA)) - continue; -#endif - v = va->vm; - if (!v) - continue; - - if (!(v->flags & VM_ALLOC) || (v->hash == 0)) - continue; - - if (!add_record(&record, v)) - break; - } - spin_unlock(&vmap_area_lock); - - sort(record.data, record.count, sizeof(vmalloc_debug_list), - record_cmp, record_swap); - - memset(dump_buff, 0, len); - dump_buff_len = scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "used %u MB depot_index %d:\n", used_size, - ml_get_depot_index()); - - for (i = 0; i < record.count; i++) { - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%pS %u KB\n", - record.data[i].caller, - record.data[i].nr_pages << 2); - - if (record.data[i].hash) { - memset(&trace, 0, sizeof(trace)); - ml_depot_fetch_stack(record.data[i].hash, &trace); - for (j = 0; j < trace.nr_entries; j++) - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "%pS\n", - (void *)trace.entries[j]); - } - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN(len, dump_buff_len), - "-\n"); - } - vfree(record.data); - if (!record.count) - dump_buff_len += scnprintf(dump_buff + dump_buff_len, - BUFLEN_EXT(len, dump_buff_len), - "No Data\n"); - - dump_buff[dump_buff_len++] = '\n'; - dump_meminfo_to_logger(VMALLOC_LOG_TAG, dump_buff, dump_buff_len); -} - -void dump_vmalloc_debug(char *dump_buff, int len) -{ - static long long debug_dump_watermark = VMALLOC_DUMP_WATER_MIN; - long long vmalloc_total_size = vmalloc_nr_pages() >> 8; - - if (vmalloc_total_size < debug_dump_watermark) { - pr_warn("[vmalloc_debug] vmalloc_total_size %lld do not over %lld, ignore it.\n", - vmalloc_total_size, debug_dump_watermark); - return; - } - - pr_warn("[vmalloc_debug] vmalloc_size %lld is over %lld.\n", - vmalloc_total_size, debug_dump_watermark); - if (!vmalloc_debug_enable) { - pr_err("[vmalloc_debug] vmalloc debug is disabled.\n"); - return; - } - - if (!dump_buff) { - pr_err("[vmalloc_debug] dump_buff is NULL.\n"); - return; - } - - debug_dump_watermark += VMALLOC_DEBUG_STEP; - dump_vmalloc_dmesg(vmalloc_total_size, dump_buff, len); -} -EXPORT_SYMBOL(dump_vmalloc_debug); -#endif - -static ssize_t vmalloc_debug_read(struct file *filp, - char __user *buff, size_t count, loff_t *off) -{ - unsigned int read_len = PAGE_SIZE; - char *kbuf; - unsigned int len; - - if (!vmalloc_debug_enable) { - pr_err("[vmalloc_debug] vmalloc debug is disabled.\n"); - return 0; - } - - kbuf = dump_vmalloc_debug_info(read_len, &len); - if (!kbuf) - return -ENOMEM; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buff, kbuf + *off, (len < count ? len : count))) { - pr_err("vmalloc_debug : copy to user failed.\n"); - kfree(kbuf); - return -EFAULT; - } - kfree(kbuf); - - *off += len < count ? len : count; - return (len < count ? len : count); -} - -static ssize_t vmalloc_used_read(struct file *filp, - char __user *buff, size_t count, loff_t *off) -{ - char kbuf[64] = {'\0'}; - unsigned int len; - - len = scnprintf(kbuf, 63, "%ld\n", vmalloc_nr_pages() << 2); - - if (kbuf[len - 1] != '\n') - kbuf[len++] = '\n'; - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buff, kbuf, (len < count ? len : count))) { - pr_err("vmalloc_debug : copy to user failed.\n"); - return -EFAULT; - } - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static const struct file_operations vmalloc_debug_fops = { - .read = vmalloc_debug_read, -}; - -static const struct file_operations vmalloc_used_fops = { - .read = vmalloc_used_read, -}; - -int __init create_vmalloc_debug(struct proc_dir_entry *parent) -{ - struct proc_dir_entry *vpentry; - struct proc_dir_entry *spentry; - struct proc_dir_entry *epentry; - struct proc_dir_entry *tpentry; - - vpentry = proc_create("vmalloc_debug", S_IRUGO, parent, - &vmalloc_debug_fops); - if (!vpentry) { - pr_err("create vmalloc_debug proc failed.\n"); - return -ENOMEM; - } - - spentry = proc_create("vmalloc_used", S_IRUGO, parent, - &vmalloc_used_fops); - if (!spentry) { - pr_err("create vmalloc_used proc failed.\n"); - proc_remove(vpentry); - return -ENOMEM; - } - - epentry = proc_create("vmalloc_debug_enable", - S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, - parent, &proc_vmalloc_debug_enable_ops); - if (!epentry) { - pr_err("create vmalloc_debug_enable proc failed.\n"); - proc_remove(spentry); - proc_remove(vpentry); - return -ENOMEM; - } - - tpentry = proc_create("vmalloc_hash_cal", S_IRUSR, parent, - &hash_cal_time_ops); - if (!tpentry) { - pr_err("create vmalloc_hash_cal proc failed.\n"); - proc_remove(epentry); - proc_remove(spentry); - proc_remove(vpentry); - return -ENOMEM; - } - return 0; -} -EXPORT_SYMBOL(create_vmalloc_debug); -#endif /* _VMALLOC_DEBUG_ */ diff --git a/mm/memory.c b/mm/memory.c index f2519aa28407..c5dbb926e7de 100755 --- a/mm/memory.c +++ b/mm/memory.c @@ -1105,10 +1105,6 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, int rss[NR_MM_COUNTERS]; swp_entry_t entry = (swp_entry_t){0}; -#ifdef OPLUS_BUG_STABILITY - unsigned long orig_addr = addr; -#endif - again: init_rss_vec(rss); @@ -1145,17 +1141,6 @@ again: } while (dst_pte++, src_pte++, addr += PAGE_SIZE, addr != end); arch_leave_lazy_mmu_mode(); - -#ifdef OPLUS_BUG_STABILITY - /* - * Prevent the page fault handler to copy the page while stale tlb entry - * are still not flushed. - */ - if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT) && - is_cow_mapping(vma->vm_flags)) - flush_tlb_range(vma, orig_addr, end); -#endif - spin_unlock(src_ptl); pte_unmap(orig_src_pte); add_mm_rss_vec(dst_mm, rss); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 597379a5055d..3236345e9cb4 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -41,9 +41,6 @@ #include "internal.h" -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#include "multi_freearea.h" -#endif /* * online_page_callback contains pointer to current page onlining function. @@ -424,9 +421,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, zone->spanned_pages = pfn - zone_start_pfn + 1; } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - ajust_zone_label(zone); -#endif /* * The section is not biggest or smallest mem_section in the zone, it * only creates a hole in the zone. So in this case, we need not @@ -453,9 +447,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, /* The zone has no valid section */ zone->zone_start_pfn = 0; zone->spanned_pages = 0; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - ajust_zone_label(zone); -#endif zone_span_writeunlock(zone); } @@ -763,9 +754,6 @@ static void __meminit resize_zone_range(struct zone *zone, unsigned long start_p zone->zone_start_pfn = start_pfn; zone->spanned_pages = max(start_pfn + nr_pages, old_end_pfn) - zone->zone_start_pfn; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - ajust_zone_label(zone); -#endif } static void __meminit resize_pgdat_range(struct pglist_data *pgdat, unsigned long start_pfn, diff --git a/mm/multi_freearea.c b/mm/multi_freearea.c deleted file mode 100644 index ce65537c4636..000000000000 --- a/mm/multi_freearea.c +++ /dev/null @@ -1,246 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "internal.h" -#include "multi_freearea.h" -#include "internal.h" - -static unsigned int show_order = 0; -#define SHOW_ALL (11) - -static char * const zone_names[MAX_NR_ZONES] = { -#ifdef CONFIG_ZONE_DMA - "DMA", -#endif -#ifdef CONFIG_ZONE_DMA32 - "DMA32", -#endif - "Normal", -#ifdef CONFIG_HIGHMEM - "HighMem", -#endif - "Movable", -#ifdef CONFIG_ZONE_DEVICE - "Device", -#endif -}; - -static int proc_free_area_show(struct seq_file *m, void *p) -{ - unsigned int order, t, flc; - pg_data_t *pgdat = NODE_DATA(0); - struct page *page; - int zone_type; - - /* - * The proc-node just for test so that close in release-version. - */ - return 0; - - for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) { - struct zone *zone = &pgdat->node_zones[zone_type]; - - if (!managed_zone(zone)) { - continue; - } - seq_printf(m, "---------------------------------------------------------------------------------------------------------------\n"); - seq_printf(m, "zone_name = %s, show_order = %u\n", zone_names[zone_type], show_order); - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) - seq_printf(m, "[%d]: label = %lu, segment = %lu\n", flc, zone->zone_label[flc].label, zone->zone_label[flc].segment); - seq_printf(m, "\n---------------------------------------------------------------------------------------------------------------\n"); - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - seq_printf(m, "flc = %u\n", flc); - for_each_migratetype_order(order, t) { - if (order == show_order || show_order == SHOW_ALL) { - seq_printf(m, "order = %u, mt = %u\n", order, t); - list_for_each_entry(page, &(zone->free_area[flc][order].free_list[t]), lru) { - seq_printf(m, "%lu\t", page_to_pfn(page)); - } - seq_printf(m, "\n"); - } - } - } - } - - return 0; -} - -static ssize_t proc_free_area_write(struct file *file, const char __user *buff, size_t len, loff_t *ppos) -{ - char write_data[16] = {0}; - int ret = 0; - - /* - * The proc-node just for test so that close in release-version. - */ - return len; - - if (len > 15) - len = 15; - if (copy_from_user(&write_data, buff, len)) { - return -EFAULT; - } - ret = kstrtouint(write_data, 10, &show_order); - - return len; -} - -static int proc_free_area_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_free_area_show, NULL); -} - -const struct file_operations proc_free_area_fops = { - .open = proc_free_area_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, - .write = proc_free_area_write, -}; - - -void list_sort_add(struct page *page, struct zone *zone, unsigned int order, int mt) -{ - struct list_head *list = &(zone->free_area[0][order].free_list[mt]); - unsigned long pfn = 0, segment = 0; - int i = 0; - - pfn = page_to_pfn(page); - - if (unlikely(pfn > zone->zone_label[FREE_AREA_COUNTS - 1].label)) { - list = &(zone->free_area[FREE_AREA_COUNTS - 1][order].free_list[mt]); - segment = zone->zone_label[FREE_AREA_COUNTS - 1].segment; - goto add_page; - } - - for (i = 0; i < FREE_AREA_COUNTS; i++) { - if (pfn <= zone->zone_label[i].label) { - list = &(zone->free_area[i][order].free_list[mt]); - segment = zone->zone_label[i].segment; - break; - } - } - -add_page: - if (pfn >= segment) - list_add_tail(&page->lru, list); - else - list_add(&page->lru, list); -} - -int page_to_flc(struct page *page) -{ - struct zone *zone = page_zone(page); - unsigned long pfn = page_to_pfn(page); - int flc = 0; - - if (unlikely(pfn > zone->zone_label[FREE_AREA_COUNTS - 1].label)) - return FREE_AREA_COUNTS - 1; - - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - if (pfn <= zone->zone_label[flc].label) - return flc; - } - - return flc; -} - -void ajust_zone_label(struct zone *zone) -{ - int i; - unsigned long prev_base; - - for (i = 0; i < FREE_AREA_COUNTS; i++) { - zone->zone_label[i].label = zone->zone_start_pfn + zone->spanned_pages * (i + 1) / FREE_AREA_COUNTS; - } - - for (i = 0; i < FREE_AREA_COUNTS; i++) { - if (i == 0) - prev_base = zone->zone_start_pfn; - else - prev_base = zone->zone_label[i - 1].label; - - zone->zone_label[i].segment = prev_base + - ((zone->zone_label[i].label - prev_base) >> 1); - } -} - -unsigned int ajust_flc(unsigned int current_flc, unsigned int order) -{ - /* when alloc_order >= HIGH_ORDER_TO_FLC, - * we like to alloc in free_area: 4->3->2->1 - */ - if (order >= HIGH_ORDER_TO_FLC) - return (FREE_AREA_COUNTS - 1 - current_flc); - - return current_flc; -} - - diff --git a/mm/multi_freearea.h b/mm/multi_freearea.h deleted file mode 100644 index 6709bf995c5f..000000000000 --- a/mm/multi_freearea.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#ifndef __MULTI_FREEAREA_H__ -#define __MULTI_FREEAREA_H__ - -#define HIGH_ORDER_TO_FLC 3 - -extern const struct file_operations proc_free_area_fops; - -extern void list_sort_add(struct page *page, struct zone *zone, unsigned int order, int mt); -extern int page_to_flc(struct page *page); -extern void ajust_zone_label(struct zone *zone); -extern unsigned int ajust_flc(unsigned int current_flc, unsigned int order); - -#endif //__MULTI_FREEAREA_H__ diff --git a/mm/multi_kswapd/Kconfig b/mm/multi_kswapd/Kconfig deleted file mode 100755 index ec8cfdf6a0ec..000000000000 --- a/mm/multi_kswapd/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -config OPLUS_MULTI_KSWAPD - bool "Enable multi kswapd" - default n - help - multi kswapd - -config KSWAPD_UNBIND_MAX_CPU - bool "kswapd unbind to max capacity cpu" - default n - depends on OPLUS_MULTI_KSWAPD - help - unbind to max capacity cpu diff --git a/mm/multi_kswapd/Makefile b/mm/multi_kswapd/Makefile deleted file mode 100755 index 73ad810c0c1f..000000000000 --- a/mm/multi_kswapd/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -obj-y += multi_kswapd.o diff --git a/mm/multi_kswapd/multi_kswapd.c b/mm/multi_kswapd/multi_kswapd.c deleted file mode 100755 index e6e68db508b3..000000000000 --- a/mm/multi_kswapd/multi_kswapd.c +++ /dev/null @@ -1,203 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* -* Number of active kswapd threads -*/ -#define DEF_KSWAPD_THREADS_PER_NODE 1 -int kswapd_threads = DEF_KSWAPD_THREADS_PER_NODE; -int kswapd_threads_current = DEF_KSWAPD_THREADS_PER_NODE; -int max_kswapd_threads = MAX_KSWAPD_THREADS; -#ifdef CONFIG_KSWAPD_UNBIND_MAX_CPU -int kswapd_unbind_cpu = -1; -#endif - -static void update_kswapd_threads_node(int nid) -{ - pg_data_t *pgdat; - int drop, increase; - int last_idx, start_idx, hid; - int nr_threads = kswapd_threads_current; - - pgdat = NODE_DATA(nid); - last_idx = nr_threads - 1; - if (kswapd_threads < nr_threads) { - drop = nr_threads - kswapd_threads; - for (hid = last_idx; hid > (last_idx - drop); hid--) { - if (pgdat->kswapd[hid]) { - kthread_stop(pgdat->kswapd[hid]); - pgdat->kswapd[hid] = NULL; - } - } - } else { -#ifdef CONFIG_KSWAPD_UNBIND_MAX_CPU - if (kswapd_unbind_cpu == -1) - upate_kswapd_unbind_cpu(); -#endif - increase = kswapd_threads - nr_threads; - start_idx = last_idx + 1; - for (hid = start_idx; hid < (start_idx + increase); hid++) { - pgdat->kswapd[hid] = kthread_run(kswapd, pgdat, - "kswapd%d:%d", nid, hid); - if (IS_ERR(pgdat->kswapd[hid])) { - pr_err("Failed to start kswapd%d on node %d\n", - hid, nid); - pgdat->kswapd[hid] = NULL; - /* - * We are out of resources. Do not start any - * more threads. - */ - break; - } - } - } -} - -void update_kswapd_threads(void) -{ - int nid; - - if (kswapd_threads_current == kswapd_threads) - return; - - /* - * Hold the memory hotplug lock to avoid racing with memory - * hotplug initiated updates - */ - mem_hotplug_begin(); - for_each_node_state(nid, N_MEMORY) - update_kswapd_threads_node(nid); - - pr_info("kswapd_thread count changed, old:%d new:%d\n", - kswapd_threads_current, kswapd_threads); - kswapd_threads_current = kswapd_threads; - mem_hotplug_done(); -} - -int kswapd_threads_sysctl_handler(struct ctl_table *table, int write, - void __user *buffer, size_t *length, loff_t *ppos) -{ - int rc; - - rc = proc_dointvec_minmax(table, write, buffer, length, ppos); - if (rc) - return rc; - - if (write) - update_kswapd_threads(); - - return 0; -} - -/* It's optimal to keep kswapds on the same CPUs as their memory, but - not required for correctness. So if the last cpu in a node goes - away, we get changed to run anywhere: as the first one comes back, - restore their cpu bindings. */ -#if(LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)) -int kswapd_cpu_online_ext(unsigned int cpu) -{ - int nid, hid; - int nr_threads = kswapd_threads_current; - - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat = NODE_DATA(nid); - const struct cpumask *mask; - - mask = cpumask_of_node(pgdat->node_id); - - if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) - for (hid = 0; hid < nr_threads; hid++) { - /* One of our CPUs online: restore mask */ - set_cpus_allowed_ptr(pgdat->kswapd[hid], mask); - } - } - return 0; -} - - -#else -int cpu_callback_ext(struct notifier_block *nfb, unsigned long action, - void *hcpu) -{ - int nid, hid; - int nr_threads = kswapd_threads_current; - - if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN) { - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat = NODE_DATA(nid); - const struct cpumask *mask; - - mask = cpumask_of_node(pgdat->node_id); - - if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) { - for (hid = 0; hid < nr_threads; hid++) { - /* One of our CPUs online: restore mask */ - set_cpus_allowed_ptr(pgdat->kswapd[hid], mask); - } - } - } - } - return NOTIFY_OK; -} -#endif /*LINUX_VERSION_CODE*/ - -int kswapd_run_ext(int nid) -{ - pg_data_t *pgdat = NODE_DATA(nid); - int ret = 0; - int hid, nr_threads; - - if (pgdat->kswapd[0]) - return 0; - -#ifdef CONFIG_KSWAPD_UNBIND_MAX_CPU - if (kswapd_unbind_cpu == -1) - upate_kswapd_unbind_cpu(); -#endif - nr_threads = kswapd_threads; - for (hid = 0; hid < nr_threads; hid++) { - pgdat->kswapd[hid] = kthread_run(kswapd, pgdat, "kswapd%d:%d", nid, hid); - if (IS_ERR(pgdat->kswapd[hid])) { - /* failure at boot is fatal */ - BUG_ON(system_state < SYSTEM_RUNNING); - pr_err("Failed to start kswapd%d on node %d\n", - hid, nid); - ret = PTR_ERR(pgdat->kswapd[hid]); - pgdat->kswapd[hid] = NULL; - } - } - kswapd_threads_current = nr_threads; - - return ret; -} - -void kswapd_stop_ext(int nid) -{ - struct task_struct *kswapd; - int hid; - int nr_threads = kswapd_threads_current; - - for (hid = 0; hid < nr_threads; hid++) { - kswapd = NODE_DATA(nid)->kswapd[hid]; - if (kswapd) { - kthread_stop(kswapd); - NODE_DATA(nid)->kswapd[hid] = NULL; - } - } -} - diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b5d341ee2b67..b982b4403b83 100755 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -75,17 +75,11 @@ #include #include "internal.h" -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_MEM_MONITOR) -#include -#endif /*OPLUS_FEATURE_HEALTHINFO*/ #if defined(CONFIG_DMAUSER_PAGES) #include #endif -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#include "multi_freearea.h" -#endif /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */ static DEFINE_MUTEX(pcp_batch_high_lock); @@ -912,9 +906,6 @@ static inline void __free_one_page(struct page *page, unsigned long uninitialized_var(buddy_pfn); struct page *buddy; unsigned int max_order; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc; -#endif max_order = min_t(unsigned int, MAX_ORDER, pageblock_order + 1); @@ -945,12 +936,7 @@ continue_merging: clear_page_guard(zone, buddy, order, migratetype); } else { list_del(&buddy->lru); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - flc = page_to_flc(buddy); - zone->free_area[flc][order].nr_free--; -#else zone->free_area[order].nr_free--; -#endif rmv_page_order(buddy); } combined_pfn = buddy_pfn & pfn; @@ -1002,28 +988,15 @@ done_merging: higher_buddy = higher_page + (buddy_pfn - combined_pfn); if (pfn_valid_within(buddy_pfn) && page_is_buddy(higher_page, higher_buddy, order + 1)) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - flc = page_to_flc(page); - list_add_tail(&page->lru, - &zone->free_area[flc][order].free_list[migratetype]); -#else list_add_tail(&page->lru, &zone->free_area[order].free_list[migratetype]); -#endif goto out; } } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - list_sort_add(page, zone, order, migratetype); -out: - flc = page_to_flc(page); - zone->free_area[flc][order].nr_free++; -#else list_add(&page->lru, &zone->free_area[order].free_list[migratetype]); out: zone->free_area[order].nr_free++; -#endif } /* @@ -1785,9 +1758,6 @@ static inline void expand(struct zone *zone, struct page *page, int migratetype) { unsigned long size = 1 << high; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc = 0; -#endif while (high > low) { area--; @@ -1804,14 +1774,8 @@ static inline void expand(struct zone *zone, struct page *page, if (set_page_guard(zone, &page[size], high, migratetype)) continue; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - list_sort_add(&page[size], zone, high, migratetype); - flc = page_to_flc(&page[size]); - zone->free_area[flc][high].nr_free++; -#else list_add(&page[size].lru, &area->free_list[migratetype]); area->nr_free++; -#endif set_page_order(&page[size], high); } } @@ -1945,46 +1909,27 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, unsigned int current_order; struct free_area *area; struct page *page; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc = 0, flc_tmp = 0, flc_last = 0; -#endif #ifdef CONFIG_ZONE_MOVABLE_CMA if (IS_ZONE_MOVABLE_CMA_ZONE(zone) && migratetype == MIGRATE_MOVABLE) migratetype = MIGRATE_CMA; #endif -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - flc_tmp = ajust_flc(flc, order); -#endif /* Find a page of the appropriate size in the preferred list */ for (current_order = order; current_order < MAX_ORDER; ++current_order) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - area = &(zone->free_area[flc_tmp][current_order]); -#else area = &(zone->free_area[current_order]); -#endif page = list_first_entry_or_null(&area->free_list[migratetype], struct page, lru); if (!page) continue; list_del(&page->lru); rmv_page_order(page); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - flc_last = page_to_flc(page); - zone->free_area[flc_last][current_order].nr_free--; -#else area->nr_free--; -#endif expand(zone, page, order, current_order, area, migratetype); set_pcppage_migratetype(page, migratetype); return page; } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif return NULL; } @@ -2067,13 +2012,8 @@ static int move_freepages(struct zone *zone, } order = page_order(page); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - __list_del_entry(&page->lru); - list_sort_add(page, zone, order, migratetype); -#else list_move(&page->lru, &zone->free_area[order].free_list[migratetype]); -#endif page += 1 << order; pages_moved += 1 << order; } @@ -2159,10 +2099,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, int start_type, bool whole_block) { unsigned int current_order = page_order(page); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#else struct free_area *area; -#endif int free_pages, movable_pages, alike_pages; int old_block_type; @@ -2224,13 +2161,8 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, return; single_page: -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - __list_del_entry(&page->lru); - list_sort_add(page, zone, current_order, start_type); -#else area = &zone->free_area[current_order]; list_move(&page->lru, &area->free_list[start_type]); -#endif } /* @@ -2326,9 +2258,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, struct page *page; int order; bool ret; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc; -#endif for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->high_zoneidx, ac->nodemask) { @@ -2341,15 +2270,8 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, continue; spin_lock_irqsave(&zone->lock, flags); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { -#endif for (order = 0; order < MAX_ORDER; order++) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct free_area *area = &(zone->free_area[flc][order]); -#else struct free_area *area = &(zone->free_area[order]); -#endif page = list_first_entry_or_null( &area->free_list[MIGRATE_HIGHATOMIC], @@ -2394,9 +2316,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, return ret; } } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif spin_unlock_irqrestore(&zone->lock, flags); } @@ -2421,26 +2340,15 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype) struct page *page; int fallback_mt; bool can_steal; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc = 0, flc_tmp = 0; -#endif /* * Find the largest available free page in the other list. This roughly * approximates finding the pageblock with the most free pages, which * would be too costly to do exactly. */ -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - flc_tmp = ajust_flc(flc, order); -#endif for (current_order = MAX_ORDER - 1; current_order >= order; --current_order) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - area = &(zone->free_area[flc_tmp][current_order]); -#else area = &(zone->free_area[current_order]); -#endif fallback_mt = find_suitable_fallback(area, current_order, start_migratetype, false, &can_steal); if (fallback_mt == -1) @@ -2460,35 +2368,17 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype) goto do_steal; } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif return false; find_smallest: -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - flc_tmp = ajust_flc(flc, order); -#endif for (current_order = order; current_order < MAX_ORDER; current_order++) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - area = &(zone->free_area[flc_tmp][current_order]); -#else area = &(zone->free_area[current_order]); -#endif fallback_mt = find_suitable_fallback(area, current_order, start_migratetype, false, &can_steal); if (fallback_mt != -1) -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - goto do_steal; -#else break; -#endif } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif /* * This should not happen - we already found a suitable fallback @@ -2768,9 +2658,6 @@ void mark_free_pages(struct zone *zone) unsigned long flags; unsigned int order, t; struct page *page; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc; -#endif if (zone_is_empty(zone)) return; @@ -2795,14 +2682,8 @@ void mark_free_pages(struct zone *zone) } for_each_migratetype_order(order, t) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - list_for_each_entry(page, - &zone->free_areai[flc][order].free_list[t], lru) { -#else list_for_each_entry(page, &zone->free_area[order].free_list[t], lru) { -#endif unsigned long i; pfn = page_to_pfn(page); @@ -2814,9 +2695,6 @@ void mark_free_pages(struct zone *zone) swsusp_set_page_free(pfn_to_page(pfn + i)); } } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif } spin_unlock_irqrestore(&zone->lock, flags); } @@ -2912,9 +2790,6 @@ int __isolate_free_page(struct page *page, unsigned int order) unsigned long watermark; struct zone *zone; int mt; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc; -#endif BUG_ON(!PageBuddy(page)); @@ -2937,12 +2812,7 @@ int __isolate_free_page(struct page *page, unsigned int order) /* Remove page from free list */ list_del(&page->lru); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - flc = page_to_flc(page); - zone->free_area[flc][order].nr_free--; -#else zone->free_area[order].nr_free--; -#endif rmv_page_order(page); /* @@ -3185,9 +3055,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, long min = mark; int o; const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc; -#endif #ifdef CONFIG_CMA long free_cma = 0; #endif @@ -3244,15 +3111,8 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, return true; /* For a high-order request, check at least one suitable page is free */ -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { -#endif for (o = order; o < MAX_ORDER; o++) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct free_area *area = &z->free_area[flc][o]; -#else struct free_area *area = &z->free_area[o]; -#endif int mt; if (!area->nr_free) @@ -3273,9 +3133,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, !list_empty(&area->free_list[MIGRATE_HIGHATOMIC])) return true; } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif return false; } @@ -3888,10 +3745,7 @@ retry: */ if (!page && !drained) { unreserve_highatomic_pageblock(ac, false); -#ifdef OPLUS_FEATURE_PERFORMANCE -#else drain_all_pages(NULL); -#endif drained = true; goto retry; } @@ -4142,20 +3996,12 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, int no_progress_loops; unsigned int cpuset_mems_cookie; int reserve_flags; -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_MEM_MONITOR) - unsigned long alloc_start = jiffies; -#endif /*OPLUS_FEATURE_HEALTHINFO*/ /* * We also sanity check to catch abuse of atomic reserves being used by * callers that are not in atomic context. */ if (WARN_ON_ONCE((gfp_mask & (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)) == -#ifdef OPLUS_FEATURE_PERFORMANCE - (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)) && - !(gfp_mask & ___GFP_HIGH_ATOMIC_ZRAM)) -#else (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM))) -#endif gfp_mask &= ~__GFP_ATOMIC; retry_cpuset: @@ -4380,9 +4226,6 @@ fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_MEM_MONITOR) - memory_alloc_monitor(gfp_mask, order, jiffies_to_msecs(jiffies - alloc_start)); -#endif /*OPLUS_FEATURE_HEALTHINFO*/ return page; } @@ -4977,9 +4820,6 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) int cpu; struct zone *zone; pg_data_t *pgdat; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc = 0; -#endif for_each_populated_zone(zone) { if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask)) @@ -5131,11 +4971,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) for_each_populated_zone(zone) { unsigned int order; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned long nr[FREE_AREA_COUNTS][MAX_ORDER], flags, total = 0; -#else unsigned long nr[MAX_ORDER], flags, total = 0; -#endif unsigned char types[MAX_ORDER]; if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask)) @@ -5144,24 +4980,12 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) printk(KERN_CONT "%s: ", zone->name); spin_lock_irqsave(&zone->lock, flags); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0 ; flc < FREE_AREA_COUNTS; flc++) { -#endif for (order = 0; order < MAX_ORDER; order++) { -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct free_area *area = &zone->free_area[flc][order]; -#else struct free_area *area = &zone->free_area[order]; -#endif int type; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - nr[flc][order] = area->nr_free; - total += nr[flc][order] << order; -#else nr[order] = area->nr_free; total += nr[order] << order; -#endif types[order] = 0; for (type = 0; type < MIGRATE_TYPES; type++) { @@ -5169,27 +4993,13 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) types[order] |= 1 << type; } } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif spin_unlock_irqrestore(&zone->lock, flags); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0 ; flc < FREE_AREA_COUNTS; flc++) { -#endif for (order = 0; order < MAX_ORDER; order++) { printk(KERN_CONT "%lu*%lukB ", -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - nr[flc][order], K(1UL) << order); - if (nr[flc][order]) -#else nr[order], K(1UL) << order); if (nr[order]) -#endif show_migration_types(types[order]); } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif printk(KERN_CONT "= %lukB\n", K(total)); } @@ -5701,21 +5511,10 @@ not_early: static void __meminit zone_init_free_lists(struct zone *zone) { unsigned int order, t; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc; - - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - for_each_migratetype_order(order, t) { - INIT_LIST_HEAD(&zone->free_area[flc][order].free_list[t]); - zone->free_area[flc][order].nr_free = 0; - } - } -#else for_each_migratetype_order(order, t) { INIT_LIST_HEAD(&zone->free_area[order].free_list[t]); zone->free_area[order].nr_free = 0; } -#endif } #ifndef __HAVE_ARCH_MEMMAP_INIT @@ -6464,9 +6263,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) set_pageblock_order(); setup_usemap(pgdat, zone, zone_start_pfn, size); init_currently_empty_zone(zone, zone_start_pfn, size); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - ajust_zone_label(zone); -#endif memmap_init(size, nid, j, zone_start_pfn); } } @@ -8088,9 +7884,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) unsigned int order, i; unsigned long pfn; unsigned long flags; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - unsigned int flc; -#endif /* find the first valid pfn */ for (pfn = start_pfn; pfn < end_pfn; pfn++) @@ -8127,12 +7920,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) #endif list_del(&page->lru); rmv_page_order(page); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - flc = page_to_flc(page); - zone->free_area[flc][order].nr_free--; -#else zone->free_area[order].nr_free--; -#endif for (i = 0; i < (1 << order); i++) SetPageReserved((page+i)); pfn += (1 << order); diff --git a/mm/page_io.c b/mm/page_io.c index a8741897b472..a3b701f330ea 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -375,12 +375,7 @@ int swap_readpage(struct page *page, bool do_poll) * or the submitting cgroup IO-throttled, submission can be a * significant part of overall IO time. */ -#ifdef CONFIG_NANDSWAP - if (!(sis->flags & SWP_NANDSWAP)) - psi_memstall_enter(&pflags); -#else psi_memstall_enter(&pflags); -#endif if (frontswap_load(page) == 0) { SetPageUptodate(page); @@ -448,12 +443,7 @@ int swap_readpage(struct page *page, bool do_poll) bio_put(bio); out: -#ifdef CONFIG_NANDSWAP - if (!(sis->flags & SWP_NANDSWAP)) - psi_memstall_leave(&pflags); -#else psi_memstall_leave(&pflags); -#endif return ret; } diff --git a/mm/process_mm_reclaim.c b/mm/process_mm_reclaim.c deleted file mode 100755 index 51aac5473fec..000000000000 --- a/mm/process_mm_reclaim.c +++ /dev/null @@ -1,604 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ -#define pr_fmt(fmt) "process_reclaim: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -extern bool is_fg(int uid); -static inline int task_is_fg(struct task_struct *tsk) -{ int cur_uid; - cur_uid = task_uid(tsk).val; - if (is_fg(cur_uid)) - return 1; - return 0; -} - -extern int __weak swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk); -int __weak swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, - unsigned long end, struct mm_walk *walk) -{ - return 0; -} - -/* check current need cancel reclaim or not, please check task not NULL first. - * If the reclaimed task has goto foreground, cancel reclaim immediately - */ -#define RECLAIM_SCAN_REGION_LEN (400ul<<20) - -enum reclaim_type { - RECLAIM_FILE, - RECLAIM_ANON, - RECLAIM_ALL, - RECLAIM_RANGE, - /* - * add three reclaim_type that only reclaim inactive pages - */ - RECLAIM_INACTIVE_FILE, - RECLAIM_INACTIVE_ANON, - RECLAIM_INACTIVE, - RECLAIM_SWAPIN, -}; - -static int mm_reclaim_pte_range(pmd_t *pmd, unsigned long addr, - unsigned long end, struct mm_walk *walk) -{ - struct reclaim_param *rp = walk->private; - struct vm_area_struct *vma = rp->vma; - pte_t *pte, ptent; - spinlock_t *ptl; - struct page *page; - LIST_HEAD(page_list); - int isolated; - int reclaimed; - int ret = 0; - -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - split_huge_pmd(vma, addr, pmd); -#else - split_huge_pmd(vma, pmd, addr); -#endif - if (pmd_trans_unstable(pmd) || !rp->nr_to_reclaim) - return 0; -cont: - isolated = 0; - pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); - for (; addr != end; pte++, addr += PAGE_SIZE) { - /* - * check whether the reclaim process should cancel - */ - if (rp->reclaimed_task && - (ret = is_reclaim_addr_over(walk, addr))) { - ret = -ret; - break; - } - ptent = *pte; - if (!pte_present(ptent)) - continue; - - page = vm_normal_page(vma, addr, ptent); - if (!page) - continue; - - /* - * do not reclaim page in active lru list - */ - if (rp->inactive_lru && (PageActive(page) || - PageUnevictable(page))) - continue; - - if (isolate_lru_page(page)) - continue; - - /* - * MADV_FREE clears pte dirty bit and then marks the page - * lazyfree (clear SwapBacked). Inbetween if this lazyfreed page - * is touched by user then it becomes dirty. PPR in - * shrink_page_list in try_to_unmap finds the page dirty, marks - * it back as PageSwapBacked and skips reclaim. This can cause - * isolated count mismatch. - */ - if (PageAnon(page) && !PageSwapBacked(page)) { - putback_lru_page(page); - continue; - } - - list_add(&page->lru, &page_list); -#ifdef CONFIG_OPLUS_SYSTEM_KERNEL_QCOM - /* - * only qualcomm need inc isolate count; mtk do it itself. - */ - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); -#endif - isolated++; - rp->nr_scanned++; - if ((isolated >= SWAP_CLUSTER_MAX) || !rp->nr_to_reclaim) - break; - } - pte_unmap_unlock(pte - 1, ptl); - - /* - * check whether the reclaim process should cancel - */ - reclaimed = reclaim_pages_from_list(&page_list, vma, walk); - - rp->nr_reclaimed += reclaimed; - rp->nr_to_reclaim -= reclaimed; - if (rp->nr_to_reclaim < 0) - rp->nr_to_reclaim = 0; - - /* - * if want to cancel, if ret <0 means need jump out of the loop immediately - */ - if (ret < 0) - return ret; - if (!rp->nr_to_reclaim) - return -PR_FULL; - if (addr != end) - goto cont; - return 0; -} - -static noinline ssize_t reclaim_task_write(struct task_struct* task, char *buffer) -{ - struct mm_struct *mm; - struct vm_area_struct *vma; - enum reclaim_type type; - char *type_buf; - struct mm_walk reclaim_walk = {}; - unsigned long start = 0; - unsigned long end = 0; - struct reclaim_param rp; - int err = 0; - - if (task == current->group_leader) - goto out_err; - - type_buf = strstrip(buffer); - if (!strcmp(type_buf, "file")) - type = RECLAIM_FILE; - else if (!strcmp(type_buf, "anon")) - type = RECLAIM_ANON; - else if (!strcmp(type_buf, "all")) - type = RECLAIM_ALL; - else if (!strcmp(type_buf, "inactive")) - type = RECLAIM_INACTIVE; - else if (!strcmp(type_buf, "inactive_file")) - type = RECLAIM_INACTIVE_FILE; - else if (!strcmp(type_buf, "inactive_anon")) - type = RECLAIM_INACTIVE_ANON; - else if (!strcmp(type_buf, "swapin")) - type = RECLAIM_SWAPIN; - else if (isdigit(*type_buf)) - type = RECLAIM_RANGE; - else - goto out_err; - - if (type == RECLAIM_RANGE) { - char *token; - unsigned long long len, len_in, tmp; - token = strsep(&type_buf, " "); - if (!token) - goto out_err; - tmp = memparse(token, &token); - if (tmp & ~PAGE_MASK || tmp > ULONG_MAX) - goto out_err; - start = tmp; - - token = strsep(&type_buf, " "); - if (!token) - goto out_err; - len_in = memparse(token, &token); - len = (len_in + ~PAGE_MASK) & PAGE_MASK; - if (len > ULONG_MAX) - goto out_err; - /* - * Check to see whether len was rounded up from small -ve - * to zero. - */ - if (len_in && !len) - goto out_err; - - end = start + len; - if (end < start) - goto out_err; - } - - mm = get_task_mm(task); - if (!mm) - goto out; - - /* - * Flag that relcaim inactive pages only in mm_reclaim_pte_range - */ - if ((type == RECLAIM_INACTIVE) || - (type == RECLAIM_INACTIVE_FILE) || - (type == RECLAIM_INACTIVE_ANON)) - rp.inactive_lru = true; - else - rp.inactive_lru = false; - - reclaim_walk.mm = mm; - reclaim_walk.pmd_entry = mm_reclaim_pte_range; - reclaim_walk.private = &rp; - - current->flags |= PF_RECLAIM_SHRINK; - rp.reclaimed_task = task; - current->reclaim.stop_jiffies = jiffies + RECLAIM_TIMEOUT_JIFFIES; - -cont: - rp.nr_to_reclaim = RECLAIM_PAGE_NUM; - rp.nr_reclaimed = 0; - rp.nr_scanned = 0; - - down_read(&mm->mmap_sem); - if (type == RECLAIM_RANGE) { - vma = find_vma(mm, start); - while (vma) { - if (vma->vm_start > end) - break; - if (is_vm_hugetlb_page(vma)) - continue; - - rp.vma = vma; - walk_page_range(max(vma->vm_start, start), - min(vma->vm_end, end), - &reclaim_walk); - vma = vma->vm_next; - } - } else if (type == RECLAIM_SWAPIN) { - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (is_vm_hugetlb_page(vma)) - continue; - - if (!vma_is_anonymous(vma)) - continue; - - /* if mlocked, don't reclaim it */ - if (vma->vm_flags & VM_LOCKED) - continue; - - reclaim_walk.mm = mm; - reclaim_walk.pmd_entry = swapin_walk_pmd_entry; - reclaim_walk.private = vma; - walk_page_range(max(vma->vm_start, start), - min(vma->vm_end, end), - &reclaim_walk); - } - } else { - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (vma->vm_end <= task->reclaim.stop_scan_addr) - continue; - - if (is_vm_hugetlb_page(vma)) - continue; - - /* - * Jump out of the reclaim flow immediately - */ - err = is_reclaim_addr_over(&reclaim_walk, vma->vm_start); - if (err) { - err = -err; - break; - } - - /* - * filter only reclaim anon pages - */ - if ((type == RECLAIM_ANON || - type == RECLAIM_INACTIVE_ANON) && vma->vm_file) - continue; - - /* - * filter only reclaim file-backed pages - */ - if ((type == RECLAIM_FILE || - type == RECLAIM_INACTIVE_FILE) && !vma->vm_file) - continue; - - rp.vma = vma; - if (vma->vm_start < task->reclaim.stop_scan_addr) - err = walk_page_range( - task->reclaim.stop_scan_addr, - vma->vm_end, &reclaim_walk); - else - err = walk_page_range(vma->vm_start, - vma->vm_end, &reclaim_walk); - - if (err < 0) - break; - } - - if (err != -PR_ADDR_OVER) - task->reclaim.stop_scan_addr = vma ? vma->vm_start : 0; - } - - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); - - if (type != RECLAIM_SWAPIN) { - /* - * If not reach the mmap end, continue - */ - if (((err == -PR_TIME_OUT) || (err == PR_PASS) || - (err == -PR_ADDR_OVER) || (err == -PR_FULL)) && vma) { - if (err == -PR_TIME_OUT) - current->reclaim.stop_jiffies = - jiffies + RECLAIM_TIMEOUT_JIFFIES; - goto cont; - } - task->reclaim.stop_scan_addr = 0; - } - - current->flags &= ~PF_RECLAIM_SHRINK; - mmput(mm); -out: - return 0; - -out_err: - return -EINVAL; -} - -/* - * If count < 0 means write sem locked - */ -static inline int rwsem_is_wlocked(struct rw_semaphore *sem) -{ - return atomic_long_read(&sem->count) < 0; -} - -static inline int _is_reclaim_should_cancel(struct mm_walk *walk) -{ - struct mm_struct *mm = walk->mm; - struct task_struct *task; - - if (!mm) - return 0; - - task = ((struct reclaim_param *)(walk->private))->reclaimed_task; - if (!task) - return 0; - - if (mm != task->mm) - return PR_TASK_DIE; - if (rwsem_is_wlocked(&mm->mmap_sem)) - return PR_SEM_OUT; -#ifdef CONFIG_FG_TASK_UID - if (task_is_fg(task)) - return PR_TASK_FG; -#endif - if (task->state == TASK_RUNNING) - return PR_TASK_RUN; - if (time_is_before_eq_jiffies(current->reclaim.stop_jiffies)) - return PR_TIME_OUT; - - return 0; -} - -int is_reclaim_should_cancel(struct mm_walk *walk) -{ - struct task_struct *task; - - if (!current_is_reclaimer() || !walk->private) - return 0; - - task = ((struct reclaim_param *)(walk->private))->reclaimed_task; - if (!task) - return 0; - - return _is_reclaim_should_cancel(walk); -} - -int is_reclaim_addr_over(struct mm_walk *walk, unsigned long addr) -{ - struct task_struct *task; - - if (!current_is_reclaimer() || !walk->private) - return 0; - - task = ((struct reclaim_param *)(walk->private))->reclaimed_task; - if (!task) - return 0; - - if (task->reclaim.stop_scan_addr + RECLAIM_SCAN_REGION_LEN <= addr) { - task->reclaim.stop_scan_addr = addr; - return PR_ADDR_OVER; - } - - return _is_reclaim_should_cancel(walk); -} - -/* - * Create /proc/process_reclaim interface for process reclaim. - * Because /proc/$pid/reclaim has deifferent permissiones of different processes, - * and can not set to 0444 because that have security risk. - * Use /proc/process_reclaim and setting with selinux - */ -#ifdef CONFIG_PROC_FS -#define PROCESS_RECLAIM_CMD_LEN 64 -static int process_reclaim_enable = 1; -module_param_named(process_reclaim_enable, process_reclaim_enable, int, 0644); - -static ssize_t proc_reclaim_write(struct file *file, const char __user *buffer, - size_t count, loff_t *ppos) -{ - char kbuf[PROCESS_RECLAIM_CMD_LEN]; - char *act_str; - char *end; - long value; - pid_t tsk_pid; - struct task_struct* tsk; - ssize_t ret = 0; - - if (!process_reclaim_enable) { - pr_warn("Process memory reclaim is disabled!\n"); - return -EFAULT; - } - - if (count > PROCESS_RECLAIM_CMD_LEN) { - pr_warn("count %ld is over %d\n", - count, PROCESS_RECLAIM_CMD_LEN); - return -EINVAL; - } - - memset(kbuf, 0, PROCESS_RECLAIM_CMD_LEN); - if (copy_from_user(&kbuf, buffer, count)) - return -EFAULT; - kbuf[PROCESS_RECLAIM_CMD_LEN - 1] = '\0'; - - act_str = strstrip(kbuf); - if (*act_str <= '0' || *act_str > '9') { - pr_err("process_reclaim write [%s] pid format is invalid.\n", - kbuf); - return -EINVAL; - } - - value = simple_strtol(act_str, &end, 10); - if (value < 0 || value > INT_MAX) { - pr_err("process_reclaim write [%s] is invalid.\n", kbuf); - return -EINVAL; - } - - tsk_pid = (pid_t)value; - - if (end == (act_str + strlen(act_str))) { - pr_err("process_reclaim write [%s] do not set reclaim type.\n", kbuf); - return -EINVAL; - } - - if (*end != ' ' && *end != ' ') { - pr_err("process_reclaim write [%s] format is wrong.\n", kbuf); - return -EINVAL; - } - - end = strstrip(end); - rcu_read_lock(); - tsk = find_task_by_vpid(tsk_pid); - if (!tsk) { - rcu_read_unlock(); - pr_err("process_reclaim can not find task of pid:%d\n", tsk_pid); - return -ESRCH; - } - - if (tsk != tsk->group_leader) - tsk = tsk->group_leader; - get_task_struct(tsk); - rcu_read_unlock(); - - ret = reclaim_task_write(tsk, end); - - put_task_struct(tsk); - if (ret < 0) { - pr_err("process_reclaim failed, command [%s]\n", kbuf); - return ret; - } - - return count; -} - -static ssize_t process_reclaim_enable_write(struct file *file, - const char __user *buff, size_t len, loff_t *ppos) -{ - char kbuf[12] = {'0'}; - long val; - int ret; - - if (len > 11) - len = 11; - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - ret = kstrtol(kbuf, 10, &val); - if (ret) - return -EINVAL; - - process_reclaim_enable = val ? 1 : 0; - return len; -} - -static ssize_t process_reclaim_enable_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[12] = {'0'}; - int len; - - len = snprintf(kbuf, 12, "%d\n", process_reclaim_enable); - if (kbuf[len] != '\n') - kbuf[len] = '\n'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static const struct file_operations proc_process_reclaim_enable_ops = { - .write = process_reclaim_enable_write, - .read = process_reclaim_enable_read, -}; - -int create_process_reclaim_enable_proc(struct proc_dir_entry *parent) -{ - if (parent && proc_create("process_reclaim_enable", - S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, - parent, &proc_process_reclaim_enable_ops)) { - printk("Register process_reclaim_enable interface passed.\n"); - return 0; - } - pr_err("Register process_reclaim_enable interface failed.\n"); - return -ENOMEM; -} - -static struct file_operations process_reclaim_w_fops = { - .write = proc_reclaim_write, - .llseek = noop_llseek, -}; - -static inline void process_mm_reclaim_init_procfs(void) -{ - if (!proc_create("process_reclaim", 0222, NULL, &process_reclaim_w_fops)) - pr_err("Failed to register proc interface\n"); -} -#else /* CONFIG_PROC_FS */ -static inline void process_mm_reclaim_init_procfs(void) -{ -} -#endif - -static int __init process_reclaim_proc_init(void) -{ - process_mm_reclaim_init_procfs(); - return 0; -} - -late_initcall(process_reclaim_proc_init); -MODULE_LICENSE("GPL"); diff --git a/mm/process_mm_reclaim_weak.c b/mm/process_mm_reclaim_weak.c deleted file mode 100644 index e072c5c65a44..000000000000 --- a/mm/process_mm_reclaim_weak.c +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -#include - -int __weak create_process_reclaim_enable_proc(struct proc_dir_entry *parent) -{ - return 0; -} diff --git a/mm/rmap.c b/mm/rmap.c index 6c60a29d083e..249be536943c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -346,76 +346,6 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) return -ENOMEM; } -#ifdef OPLUS_BUG_STABILITY -#define RECURSIVE_MAX_FORK_TIME 30 -int happend_times = 0; //total recursive fork times -pid_t fork_pid_child = 0; //last time recursive fork pid -pid_t fork_pid_father = 0; //last time recursive fork ppid - -/* - * Attach the anon_vmas from src to dst. - * Returns length of anon_vma_chain on success, -ENOMEM on failure. - * - * If dst->anon_vma is NULL this function tries to find and reuse existing - * anon_vma which has no vmas and only one child anon_vma. This prevents - * degradation of anon_vma hierarchy to endless linear chain in case of - * constantly forking task. On the other hand, an anon_vma with more than one - * child isn't reused even if there was no alive vma, thus rmap walker has a - * good chance of avoiding scanning the whole hierarchy when it searches where - * page is mapped. - */ -int anon_vma_clone_oppo(struct vm_area_struct *dst, struct vm_area_struct *src) -{ - struct anon_vma_chain *avc, *pavc; - struct anon_vma *root = NULL; - int length = 0; - - list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) { - struct anon_vma *anon_vma; - - avc = anon_vma_chain_alloc(GFP_NOWAIT | __GFP_NOWARN); - if (unlikely(!avc)) { - unlock_anon_vma_root(root); - root = NULL; - avc = anon_vma_chain_alloc(GFP_KERNEL); - if (!avc) - goto enomem_failure; - } - anon_vma = pavc->anon_vma; - root = lock_anon_vma_root(root, anon_vma); - anon_vma_chain_link(dst, avc, anon_vma); - length++; - - /* - * Reuse existing anon_vma if its degree lower than two, - * that means it has no vma and only one anon_vma child. - * - * Do not chose parent anon_vma, otherwise first child - * will always reuse it. Root anon_vma is never reused: - * it has self-parent reference and at least one child. - */ - if (!dst->anon_vma && anon_vma != src->anon_vma && - anon_vma->degree < 2) - dst->anon_vma = anon_vma; - } - if (dst->anon_vma) - dst->anon_vma->degree++; - unlock_anon_vma_root(root); - return length; - - enomem_failure: - /* - * dst->anon_vma is dropped here otherwise its degree can be incorrectly - * decremented in unlink_anon_vmas(). - * We can safely do this because callers of anon_vma_clone() don't care - * about dst->anon_vma if anon_vma_clone() failed. - */ - dst->anon_vma = NULL; - unlink_anon_vmas(dst); - return -ENOMEM; -} -#endif - /* * Attach vma to its own anon_vma, as well as to the anon_vmas that * the corresponding VMA in the parent process is attached to. @@ -438,22 +368,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) * First, attach the new VMA to the parent VMA's anon_vmas, * so rmap can find non-COWed pages in child processes. */ - #ifdef OPLUS_BUG_STABILITY - error = anon_vma_clone_oppo(vma, pvma); - if (error < 0) - return error; - else if (error > RECURSIVE_MAX_FORK_TIME) { - pr_err("[anon_vma_fork]%d: recursive fork more then 30 timges, pid is %d[%s]\n", __LINE__, get_current()->pid, get_current()->comm); - happend_times++; - fork_pid_child = get_current()->pid; - fork_pid_father = get_current()->parent->pid; - return -ENOMEM; - } - #else error = anon_vma_clone(vma, pvma); if (error) return error; - #endif /* An existing anon_vma has been reused, all done then. */ if (vma->anon_vma) diff --git a/mm/slab.h b/mm/slab.h index ce009772cf23..a90653214c64 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -134,10 +134,6 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size, #elif defined(CONFIG_SLUB_DEBUG) #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_CONSISTENCY_CHECKS) -#elif defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) -/* Kui.Zhang@tech.kernel.mm, 2020-02-12, create kmalloc cache with sotre user. -*/ -#define SLAB_DEBUG_FLAGS (SLAB_STORE_USER) #else #define SLAB_DEBUG_FLAGS (0) #endif @@ -474,7 +470,7 @@ struct kmem_cache_node { #ifdef CONFIG_SLUB unsigned long nr_partial; struct list_head partial; -#if defined(CONFIG_SLUB_DEBUG) || (defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG)) +#if defined(CONFIG_SLUB_DEBUG) atomic_long_t nr_slabs; atomic_long_t total_objects; struct list_head full; diff --git a/mm/slab_common.c b/mm/slab_common.c index 78bb3460e3f3..20da89561fd2 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -980,18 +980,6 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) index = fls(size - 1); } -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) - /* Kui.Zhang@tech.kernel.mm, 2020-02-13, try to kmalloc from kmalloc_debug - * caches fisrt. - */ - if (unlikely(kmalloc_debug_enable)) { - struct kmem_cache *s; - - s = (struct kmem_cache *)atomic64_read(&kmalloc_debug_caches[kmalloc_type(flags)][index]); - if (unlikely(s)) - return s; - } -#endif return kmalloc_caches[kmalloc_type(flags)][index]; } @@ -1246,10 +1234,6 @@ static void print_slabinfo_header(struct seq_file *m) #ifdef CONFIG_DEBUG_SLAB seq_puts(m, " : globalstat "); seq_puts(m, " : cpustat "); -#endif -#ifdef OPLUS_FEATURE_HEALTHINFO - seq_puts(m, " "); - #endif seq_putc(m, '\n'); } @@ -1306,14 +1290,8 @@ static void cache_show(struct kmem_cache *s, struct seq_file *m) seq_printf(m, " : tunables %4u %4u %4u", sinfo.limit, sinfo.batchcount, sinfo.shared); -#ifdef OPLUS_FEATURE_HEALTHINFO - seq_printf(m, " : slabdata %6lu %6lu %6lu %1d", - sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail, - ((s->flags & SLAB_RECLAIM_ACCOUNT) == SLAB_RECLAIM_ACCOUNT) ? 1: 0); -#else seq_printf(m, " : slabdata %6lu %6lu %6lu", sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail); -#endif /* OPLUS_FEATURE_HEALTHINFO */ slabinfo_show_stats(m, s); seq_putc(m, '\n'); } diff --git a/mm/slub.c b/mm/slub.c index b7b70e49ec13..de4c3d2f8264 100755 --- a/mm/slub.c +++ b/mm/slub.c @@ -35,10 +35,6 @@ #include #include #include -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) -/* calc the stack hash */ -#include -#endif #include @@ -122,20 +118,11 @@ static inline int kmem_cache_debug(struct kmem_cache *s) { -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT - /* add more check the slab is debug while enable CONFIG_KMALLOC_DEBUG.*/ -#if defined(CONFIG_KMALLOC_DEBUG) || defined(CONFIG_SLUB_DEBUG) - return unlikely(s->flags & SLAB_DEBUG_FLAGS); -#else - return 0; -#endif -#else #ifdef CONFIG_SLUB_DEBUG return unlikely(s->flags & SLAB_DEBUG_FLAGS); #else return 0; #endif -#endif } void *fixup_red_left(struct kmem_cache *s, void *p) @@ -211,21 +198,11 @@ static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s) /* * Tracking user of a slab. */ -#if !defined(OPLUS_FEATURE_MEMLEAK_DETECT) || !defined(CONFIG_KMALLOC_DEBUG) || !defined(CONFIG_MEMLEAK_DETECT_THREAD) #define TRACK_ADDRS_COUNT 8 -#else -/* set kmalloc_debug tack stack depth. */ -#define TRACK_ADDRS_COUNT 12 -#endif struct track { unsigned long addr; /* Called from address */ #ifdef CONFIG_STACKTRACE unsigned long addrs[TRACK_ADDRS_COUNT]; /* Called from address */ -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) - /* save the stack depth and hash. */ - u32 depth; - u32 hash; -#endif #endif int cpu; /* Was running on cpu */ int pid; /* Pid context */ @@ -476,8 +453,7 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page, return false; } -#if defined(CONFIG_SLUB_DEBUG) || (defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG)) -/* dump kmalloc debug info need this funciton. */ +#ifdef CONFIG_SLUB_DEBUG /* * Determine a map of object in use on a page. * @@ -608,13 +584,6 @@ static void set_track(struct kmem_cache *s, void *object, for (i = trace.nr_entries; i < TRACK_ADDRS_COUNT; i++) p->addrs[i] = 0; -#endif -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) - /* save the stack depth and hash. */ - p->depth = trace.nr_entries; - p->hash = jhash2((u32 *)p->addrs, - sizeof(p->addrs[0])/sizeof(u32)*trace.nr_entries, - 0xabcd); #endif p->addr = addr; p->cpu = smp_processor_id(); @@ -629,10 +598,7 @@ static void init_tracking(struct kmem_cache *s, void *object) if (!(s->flags & SLAB_STORE_USER)) return; -#ifdef CONFIG_SLUB_DEBUG - /* only record alloc stack. */ set_track(s, object, TRACK_FREE, 0UL); -#endif set_track(s, object, TRACK_ALLOC, 0UL); } @@ -661,10 +627,7 @@ static void print_tracking(struct kmem_cache *s, void *object) return; print_track("Allocated", get_track(s, object, TRACK_ALLOC)); -#ifdef CONFIG_SLUB_DEBUG - /* only record alloc stack. */ print_track("Freed", get_track(s, object, TRACK_FREE)); -#endif } static void print_page_info(struct page *page) @@ -731,14 +694,8 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p) else off = s->inuse; -#ifdef CONFIG_SLUB_DEBUG if (s->flags & SLAB_STORE_USER) off += 2 * sizeof(struct track); -#else - /* only save call stack to save memory. */ - if (s->flags & SLAB_STORE_USER) - off += sizeof(struct track); -#endif off += kasan_metadata_size(s); @@ -868,16 +825,9 @@ static int check_pad_bytes(struct kmem_cache *s, struct page *page, u8 *p) /* Freepointer is placed after the object. */ off += sizeof(void *); -#ifdef CONFIG_SLUB_DEBUG if (s->flags & SLAB_STORE_USER) /* We also have user information there */ off += 2 * sizeof(struct track); -#else - /* only save call stack to save memory. */ - if (s->flags & SLAB_STORE_USER) - /* We also have user information there */ - off += sizeof(struct track); -#endif off += kasan_metadata_size(s); @@ -1264,11 +1214,8 @@ next_object: goto out; } -#ifdef CONFIG_SLUB_DEBUG - /* only record alloc stack. */ if (s->flags & SLAB_STORE_USER) set_track(s, object, TRACK_FREE, addr); -#endif trace(s, page, object, 0); /* Freepointer not overwritten by init_object(), SLAB_POISON moved it */ init_object(s, object, SLUB_RED_INACTIVE); @@ -1364,10 +1311,6 @@ out: __setup("slub_debug", setup_slub_debug); -#ifdef CONFIG_SLUB_DEBUG -/* only open debug options while - * CONFIG_SLUB_DEBUG is enabled. - */ unsigned long kmem_cache_flags(unsigned long object_size, unsigned long flags, const char *name, void (*ctor)(void *)) @@ -1381,20 +1324,7 @@ unsigned long kmem_cache_flags(unsigned long object_size, return flags; } -#elif defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) -unsigned long kmem_cache_flags(unsigned long object_size, - unsigned long flags, const char *name, - void (*ctor)(void *)) -{ - return flags; -} -#endif #else /* !CONFIG_SLUB_DEBUG */ -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -/* implement the functions - * while CONFIG_KMALLOC_DEBUG enabled. - */ -#ifndef CONFIG_KMALLOC_DEBUG static inline void setup_object_debug(struct kmem_cache *s, struct page *page, void *object) {} static inline void setup_page_debug(struct kmem_cache *s, @@ -1407,38 +1337,15 @@ static inline int free_debug_processing( struct kmem_cache *s, struct page *page, void *head, void *tail, int bulk_cnt, unsigned long addr) { return 0; } -#endif -#else -static inline void setup_object_debug(struct kmem_cache *s, - struct page *page, void *object) {} - -static inline int alloc_debug_processing(struct kmem_cache *s, - struct page *page, void *object, unsigned long addr) { return 0; } - -static inline int free_debug_processing( - struct kmem_cache *s, struct page *page, - void *head, void *tail, int bulk_cnt, - unsigned long addr) { return 0; } -#endif static inline int slab_pad_check(struct kmem_cache *s, struct page *page) { return 1; } static inline int check_object(struct kmem_cache *s, struct page *page, void *object, u8 val) { return 1; } -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -/* implement the functions while CONFIG_KMALLOC_DEBUG enabled. */ -#ifndef CONFIG_KMALLOC_DEBUG static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page) {} static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page) {} -#endif -#else -static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n, - struct page *page) {} -static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, - struct page *page) {} -#endif unsigned long kmem_cache_flags(unsigned long object_size, unsigned long flags, const char *name, void (*ctor)(void *)) @@ -2489,8 +2396,7 @@ static inline int node_match(struct page *page, int node) return 1; } -#if defined(CONFIG_SLUB_DEBUG) || (defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG)) -/* open slabinfo need these apis. */ +#ifdef CONFIG_SLUB_DEBUG static int count_free(struct page *page) { return page->objects - page->inuse; @@ -3459,7 +3365,7 @@ init_kmem_cache_node(struct kmem_cache_node *n) n->nr_partial = 0; spin_lock_init(&n->list_lock); INIT_LIST_HEAD(&n->partial); -#if defined(CONFIG_SLUB_DEBUG) || (defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG)) +#ifdef CONFIG_SLUB_DEBUG atomic_long_set(&n->nr_slabs, 0); atomic_long_set(&n->total_objects, 0); INIT_LIST_HEAD(&n->full); @@ -3685,9 +3591,6 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) * the object. */ size += 2 * sizeof(struct track); -#elif defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_KMALLOC_DEBUG) - if (flags & SLAB_STORE_USER) - size += sizeof(struct track); #endif kasan_cache_create(s, &size, &s->flags); @@ -5414,13 +5317,7 @@ static ssize_t free_calls_show(struct kmem_cache *s, char *buf) { if (!(s->flags & SLAB_STORE_USER)) return -ENOSYS; - -#if !defined(OPLUS_FEATURE_MEMLEAK_DETECT) || !defined(CONFIG_KMALLOC_DEBUG) || defined(CONFIG_SLUB_DEBUG) - /* only record alloc stack. */ return list_locations(s, buf, TRACK_FREE); -#else - return -ENOSYS; -#endif } SLAB_ATTR_RO(free_calls); #endif /* CONFIG_SLUB_DEBUG */ @@ -6074,17 +5971,3 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer, } #endif /* CONFIG_SLABINFO */ - -#ifdef CONFIG_KMALLOC_DEBUG -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -/* calc the stack hash */ -#include "malloc_track/slub_track.c" -#else -int __init __weak create_kmalloc_debug(struct proc_dir_entry *parent) -{ - pr_warn("OPLUS_FEATURE_MEMLEAK_DETECT is off.\n"); - return 0; -} -EXPORT_SYMBOL(create_kmalloc_debug); -#endif -#endif diff --git a/mm/swap.c b/mm/swap.c index eab9b36b97eb..d1044a363421 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -1021,8 +1021,4 @@ void __init swap_setup(void) * Right now other parts of the system means that we * _really_ don't want to cluster much more */ -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-25, add oplus zram opt support*/ - page_cluster = 0; -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ } diff --git a/mm/swap_slots.c b/mm/swap_slots.c index 5ba74bd3beee..d81cfc5a43d5 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -326,12 +326,7 @@ swp_entry_t get_swap_page(struct page *page) */ cache = raw_cpu_ptr(&swp_slots); -#if defined(CONFIG_NANDSWAP) - if (check_cache_active() && - !current_is_nswapoutd()) { -#else if (check_cache_active()) { -#endif mutex_lock(&cache->alloc_lock); if (cache->slots) { repeat: diff --git a/mm/swap_state.c b/mm/swap_state.c index b74f494823b2..372c91d7f5dd 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -98,10 +98,6 @@ static atomic_t swapin_readahead_hits = ATOMIC_INIT(4); void show_swap_cache_info(void) { unsigned long totalswap = total_swap_pages; -#if defined(CONFIG_NANDSWAP) - if (nandswap_si) - totalswap -= nandswap_si->pages; -#endif printk("%lu pages in swap cache\n", total_swapcache_pages()); printk("Swap cache stats: add %lu, delete %lu, find %lu/%lu\n", swap_cache_info.add_total, swap_cache_info.del_total, diff --git a/mm/swapfile.c b/mm/swapfile.c index 99780d8426fa..5a9578cc3f84 100755 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -90,9 +90,6 @@ static DEFINE_SPINLOCK(swap_avail_lock); struct swap_info_struct *swap_info[MAX_SWAPFILES]; -#if defined(CONFIG_NANDSWAP) -struct swap_info_struct *nandswap_si; -#endif static DEFINE_MUTEX(swapon_mutex); @@ -936,19 +933,10 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) int n_ret = 0; int node; -#if defined(CONFIG_NANDSWAP) - long nandswap_avail_pgs = 0; -#endif /* Only single cluster request supported */ WARN_ON_ONCE(n_goal > 1 && cluster); -#if defined(CONFIG_NANDSWAP) - if (nandswap_si) - nandswap_avail_pgs = nandswap_si->pages - nandswap_si->inuse_pages; - avail_pgs = (atomic_long_read(&nr_swap_pages) - nandswap_avail_pgs) / nr_pages; -#else avail_pgs = atomic_long_read(&nr_swap_pages) / nr_pages; -#endif if (avail_pgs <= 0) goto noswap; @@ -969,14 +957,6 @@ start_over: plist_requeue(&si->avail_lists[node], &swap_avail_heads[node]); spin_unlock(&swap_avail_lock); spin_lock(&si->lock); -#if defined(CONFIG_NANDSWAP) - if ((current_is_nswapoutd() && !(si->flags & SWP_NANDSWAP)) || - (!current_is_nswapoutd() && (si->flags & SWP_NANDSWAP))) { - spin_lock(&swap_avail_lock); - spin_unlock(&si->lock); - goto nextsi; - } -#endif if (!si->highest_bit || !(si->flags & SWP_WRITEOK)) { spin_lock(&swap_avail_lock); if (plist_node_empty(&si->avail_lists[node])) { @@ -2497,12 +2477,6 @@ static void _enable_swap_info(struct swap_info_struct *p, int prio, atomic_long_add(p->pages, &nr_swap_pages); total_swap_pages += p->pages; -#if defined(CONFIG_NANDSWAP) - if (p->prio == SWAP_NANDSWAP_PRIO) { - p->flags |= SWP_NANDSWAP; - nandswap_si = p; - } -#endif assert_spin_locked(&swap_lock); /* @@ -2621,10 +2595,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) atomic_long_sub(p->pages, &nr_swap_pages); total_swap_pages -= p->pages; p->flags &= ~SWP_WRITEOK; -#if defined(CONFIG_NANDSWAP) - if (p->flags & SWP_NANDSWAP) - nandswap_si = NULL; -#endif spin_unlock(&p->lock); spin_unlock(&swap_lock); @@ -3324,10 +3294,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT; enable_swap_info(p, prio, swap_map, cluster_info, frontswap_map); -#if defined(CONFIG_NANDSWAP) - if (p->prio == SWAP_NANDSWAP_PRIO) - p->flags |= SWP_NANDSWAP; -#endif pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s%s\n", p->pages<<(PAGE_SHIFT-10), name->name, p->prio, @@ -3383,32 +3349,15 @@ void si_swapinfo(struct sysinfo *val) { unsigned int type; unsigned long nr_to_be_unused = 0; -#if defined(CONFIG_NANDSWAP) - unsigned long nandswap_free = 0; - unsigned long nandswap_total = 0; -#endif spin_lock(&swap_lock); for (type = 0; type < nr_swapfiles; type++) { struct swap_info_struct *si = swap_info[type]; if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK)) nr_to_be_unused += si->inuse_pages; -#if defined(CONFIG_NANDSWAP) - if (si->flags & SWP_NANDSWAP) { - if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK)) - nandswap_free = si->pages; - else - nandswap_free = si->pages - si->inuse_pages; - nandswap_total = si->pages; - } -#endif } val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused; val->totalswap = total_swap_pages + nr_to_be_unused; -#if defined(CONFIG_NANDSWAP) - val->freeswap -= nandswap_free; - val->totalswap -= nandswap_total; -#endif spin_unlock(&swap_lock); } diff --git a/mm/util.c b/mm/util.c index 6d92b2c04b84..5bb7932dcbb6 100644 --- a/mm/util.c +++ b/mm/util.c @@ -384,11 +384,6 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) if ((flags & GFP_KERNEL) != GFP_KERNEL) return kmalloc_node(size, flags, node); -#ifdef OPLUS_FEATURE_PERFORMANCE - /*do not attempt kmalloc if we need more than KMALLOC_MAX_PAGES pages at once*/ - if (size >= KMALLOC_MAX_PAGES * PAGE_SIZE) - goto use_vmalloc; -#endif /*OPLUS_FEATURE_PERFORMANCE*/ /* * We want to attempt a large physically contiguous block first because @@ -412,7 +407,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) */ if (ret || size <= PAGE_SIZE) return ret; -use_vmalloc: + return __vmalloc_node_flags_caller(size, node, flags, __builtin_return_address(0)); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 615ceab50b09..aea9baa811af 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -38,10 +38,6 @@ #include #include "internal.h" -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_VMALLOC_DEBUG) -static unsigned int save_vmalloc_stack(unsigned long flags, struct vmap_area *va); -static void dec_vmalloc_stat(struct vmap_area *va); -#endif struct vfree_deferred { struct llist_head list; @@ -1378,17 +1374,11 @@ EXPORT_SYMBOL_GPL(map_vm_area); static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va, unsigned long flags, const void *caller) { -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_VMALLOC_DEBUG) - unsigned int handle = save_vmalloc_stack(flags, va); -#endif spin_lock(&vmap_area_lock); vm->flags = flags; vm->addr = (void *)va->va_start; vm->size = va->va_end - va->va_start; vm->caller = caller; -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_VMALLOC_DEBUG) - vm->hash = handle; -#endif va->vm = vm; va->flags |= VM_VM_AREA; spin_unlock(&vmap_area_lock); @@ -1515,10 +1505,6 @@ struct vm_struct *remove_vm_area(const void *addr) if (va && va->flags & VM_VM_AREA) { struct vm_struct *vm = va->vm; -#if defined(OPLUS_FEATURE_MEMLEAK_DETECT) && defined(CONFIG_VMALLOC_DEBUG) - /* update the count while vfree. */ - dec_vmalloc_stat(va); -#endif spin_lock(&vmap_area_lock); va->vm = NULL; va->flags &= ~VM_VM_AREA; @@ -2767,12 +2753,8 @@ static int s_show(struct seq_file *m, void *p) seq_printf(m, "0x%pK-0x%pK %7ld", v->addr, v->addr + v->size, v->size); -#ifdef OPLUS_BUG_STABILITY - if (v->caller && (strcmp(current->comm, "android.bg") != 0)) -#else - if (v->caller) -#endif //OPLUS_BUG_STABILITY - + + if (v->caller) seq_printf(m, " %pS", v->caller); if (v->nr_pages) @@ -2832,16 +2814,3 @@ static int __init proc_vmalloc_init(void) module_init(proc_vmalloc_init); #endif - -#ifdef CONFIG_VMALLOC_DEBUG -#ifdef OPLUS_FEATURE_MEMLEAK_DETECT -#include "malloc_track/vmalloc_track.c" -#else -int __init __weak create_vmalloc_debug(struct proc_dir_entry *parent) -{ - pr_warn("OPLUS_FEATURE_MEMLEAK_DETECT is off.\n"); - return 0; -} -EXPORT_SYMBOL(create_vmalloc_debug); -#endif -#endif diff --git a/mm/vmscan.c b/mm/vmscan.c index f8be5ea95034..991afedc8e98 100755 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -56,22 +56,13 @@ #include #include -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -#include -#endif #include "internal.h" #define CREATE_TRACE_POINTS #include -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) -#include -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_FG_TASK_UID) -#include -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ #include @@ -138,9 +129,6 @@ struct scan_control { */ struct vm_area_struct *target_vma; -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - struct mm_walk *walk; -#endif }; #ifdef ARCH_HAS_PREFETCH @@ -175,12 +163,6 @@ struct scan_control { * From 0 .. 100. Higher means more swappy. */ int vm_swappiness = 60; -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -/* - * Direct reclaim swappiness, exptct 0 - 60. Higher means more swappy and slower. - */ -int direct_vm_swappiness = 60; -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ #ifdef CONFIG_DYNAMIC_TUNNING_SWAPPINESS int vm_swappiness_threshold1 = 0; @@ -189,9 +171,6 @@ int swappiness_threshold1_size = 0; int swappiness_threshold2_size = 0; #endif -#ifdef CONFIG_HYBRIDSWAP_SWAPD -static int hybridswapd_swappiness = 200; -#endif /* * The total number of pages which are beyond the high watermark within all * zones. @@ -1036,10 +1015,6 @@ static unsigned long shrink_page_list(struct list_head *page_list, enum page_references references = PAGEREF_RECLAIM; bool dirty, writeback; -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - if (sc->walk && is_reclaim_should_cancel(sc->walk)) - break; -#endif cond_resched(); page = lru_to_page(page_list); @@ -1454,68 +1429,10 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, return ret; } -#if defined(CONFIG_NANDSWAP) -unsigned long nswap_reclaim_page_list(struct list_head *page_list, - struct vm_area_struct *vma, bool scan) -{ - unsigned long nr_isolated[2] = {0, }; - struct pglist_data *pgdat = NULL; - unsigned long nr_reclaimed; - unsigned long nr_scan = 0; - struct page *page; - struct scan_control sc = { - .gfp_mask = GFP_KERNEL, - .priority = DEF_PRIORITY, - .may_writepage = 1, - .may_unmap = 1, - .may_swap = 1, - .target_vma = vma, - }; - - if (list_empty(page_list)) - return 0; - - list_for_each_entry(page, page_list, lru) { - ClearPageActive(page); - if (pgdat == NULL) - pgdat = page_pgdat(page); - /* XXX: It could be multiple node in other config */ - WARN_ON_ONCE(pgdat != page_pgdat(page)); - if (!page_is_file_cache(page)) - nr_isolated[0]++; - else - nr_isolated[1]++; - } - - mod_node_page_state(pgdat, NR_ISOLATED_ANON, nr_isolated[0]); - mod_node_page_state(pgdat, NR_ISOLATED_FILE, nr_isolated[1]); - - nr_reclaimed = shrink_page_list(page_list, NULL, &sc, - TTU_IGNORE_ACCESS, NULL, true); - - while (!list_empty(page_list)) { - page = lru_to_page(page_list); - if (PageSwapCache(page) && !PageDirty(page)) - nr_scan++; - list_del(&page->lru); - putback_lru_page(page); - } - - mod_node_page_state(pgdat, NR_ISOLATED_ANON, -nr_isolated[0]); - mod_node_page_state(pgdat, NR_ISOLATED_FILE, -nr_isolated[1]); - - return scan ? nr_scan : nr_reclaimed; -} -#endif #ifdef CONFIG_PROCESS_RECLAIM -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) -unsigned long reclaim_pages_from_list(struct list_head *page_list, - struct vm_area_struct *vma, struct mm_walk *walk) -#else unsigned long reclaim_pages_from_list(struct list_head *page_list, struct vm_area_struct *vma) -#endif { unsigned long nr_isolated[2] = {0, }; struct pglist_data *pgdat = NULL; @@ -1526,9 +1443,6 @@ unsigned long reclaim_pages_from_list(struct list_head *page_list, .may_unmap = 1, .may_swap = 1, .target_vma = vma, -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - .walk = walk, -#endif }; unsigned long nr_reclaimed; @@ -1798,11 +1712,7 @@ int isolate_lru_page(struct page *page) int ret = -EBUSY; VM_BUG_ON_PAGE(!page_count(page), page); -#if defined(OPLUS_FEATURE_PROCESS_RECLAIM) && defined(CONFIG_PROCESS_RECLAIM_ENHANCE) - WARN_RATELIMIT((!current_is_reclaimer() && PageTail(page)), "trying to isolate tail page"); -#else WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"); -#endif if (PageLRU(page)) { struct zone *zone = page_zone(page); @@ -1922,14 +1832,6 @@ putback_inactive_pages(struct lruvec *lruvec, struct list_head *page_list) */ static int current_may_throttle(void) { -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) - if ((current->signal->oom_score_adj < 0) -#ifdef CONFIG_FG_TASK_UID - || is_fg(current_uid().val) -#endif - ) - return 0; -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ return !(current->flags & PF_LESS_THROTTLE) || current->backing_dev_info == NULL || bdi_write_congested(current->backing_dev_info); @@ -2328,14 +2230,8 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file, inactive_ratio = 0; } else { gb = (inactive + active) >> (30 - PAGE_SHIFT); -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -/*Huacai.Zhou@Tech.Kernel.MM, 2020-03-25, keep more file pages*/ - if (file && gb) - inactive_ratio = min(2UL, int_sqrt(10 * gb)); -#else if (gb) inactive_ratio = int_sqrt(10 * gb); -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ else inactive_ratio = 1; } @@ -2416,13 +2312,6 @@ enum scan_balance { SCAN_FILE, }; -#ifdef CONFIG_HYBRIDSWAP_SWAPD -extern bool free_swap_is_low(void); -bool __weak free_swap_is_low(void) -{ - return false; -} -#endif /* * Determine how aggressively the anon and file LRU lists should be @@ -2447,11 +2336,6 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, unsigned long anon, file; unsigned long ap, fp; enum lru_list lru; - unsigned long totalswap = total_swap_pages; -#if defined(CONFIG_NANDSWAP) - if (nandswap_si) - totalswap -= nandswap_si->pages; -#endif /* use vm_swappiness defaultly */ swappiness = vm_swappiness; @@ -2473,22 +2357,8 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, } #endif -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) - if (!current_is_kswapd()) { -#ifdef CONFIG_HYBRIDSWAP_SWAPD - if (strncmp(current->comm, "hybridswapd:", sizeof("hybridswapd:") - 1) == 0) { - swappiness = hybridswapd_swappiness; - if (free_swap_is_low()) - swappiness = 0; - } else -#endif - swappiness = direct_vm_swappiness; - } - if (!sc->may_swap || (mem_cgroup_get_nr_swap_pages(memcg) <= totalswap>>6)) { -#else /* If we have no swap space, do not bother scanning anon pages. */ if (!sc->may_swap || mem_cgroup_get_nr_swap_pages(memcg) <= 0) { -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ scan_balance = SCAN_FILE; goto out; } @@ -3921,11 +3791,7 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o * If there are applications that are active memory-allocators * (most normal use), this basically shouldn't matter. */ -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - int kswapd(void *p) - #else static int kswapd(void *p) -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ { unsigned int alloc_order, reclaim_order; unsigned int classzone_idx = MAX_NR_ZONES - 1; @@ -4090,9 +3956,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) restore their cpu bindings. */ static int kswapd_cpu_online(unsigned int cpu) { -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - return kswapd_cpu_online_ext(cpu); -#else int nid; for_each_node_state(nid, N_MEMORY) { @@ -4106,7 +3969,6 @@ static int kswapd_cpu_online(unsigned int cpu) set_cpus_allowed_ptr(pgdat->kswapd, mask); } return 0; -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ } /* @@ -4115,9 +3977,6 @@ static int kswapd_cpu_online(unsigned int cpu) */ int kswapd_run(int nid) { -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - return kswapd_run_ext(nid); -#else pg_data_t *pgdat = NODE_DATA(nid); int ret = 0; @@ -4133,7 +3992,6 @@ int kswapd_run(int nid) pgdat->kswapd = NULL; } return ret; -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ } /* @@ -4142,16 +4000,12 @@ int kswapd_run(int nid) */ void kswapd_stop(int nid) { -#if defined(OPLUS_FEATURE_MULTI_KSWAPD) && defined(CONFIG_OPLUS_MULTI_KSWAPD) - return kswapd_stop_ext(nid); -#else struct task_struct *kswapd = NODE_DATA(nid)->kswapd; if (kswapd) { kthread_stop(kswapd); NODE_DATA(nid)->kswapd = NULL; } -#endif /*OPLUS_FEATURE_MULTI_KSWAPD*/ } @@ -4418,114 +4272,3 @@ void check_move_unevictable_pages(struct page **pages, int nr_pages) } #endif /* CONFIG_SHMEM */ -#ifdef CONFIG_HYBRIDSWAP_SWAPD -#define PARA_BUF_LEN 128 - -static inline bool debug_get_val(char *buf, char *token, unsigned long *val) -{ - int ret = -EINVAL; - char *str = strstr(buf, token); - - if (!str) - return ret; - - ret = kstrtoul(str + strlen(token), 0, val); - if (ret) - return -EINVAL; - - if (*val > 200) { - pr_err("%lu is invalid\n", *val); - return -EINVAL; - } - - return 0; -} - -static ssize_t swappiness_para_write(struct file *file, - const char __user *buff, size_t len, loff_t *ppos) -{ - char kbuf[PARA_BUF_LEN] = {'0'}; - char *str; - long val; - - if (len > PARA_BUF_LEN - 1) { - pr_err("len %d is too long\n", len); - return -EINVAL; - } - - if (copy_from_user(&kbuf, buff, len)) - return -EFAULT; - kbuf[len] = '\0'; - - str = strstrip(kbuf); - if (!str) { - pr_err("buff %s is invalid\n", kbuf); - return -EINVAL; - } - - if (!debug_get_val(str, "vm_swappiness=", &val)) { - vm_swappiness = val; - return len; - } - - if (!debug_get_val(str, "direct_swappiness=", &val)) { - direct_vm_swappiness = val; - return len; - } - - if (!debug_get_val(str, "swapd_swappiness=", &val)) { - hybridswapd_swappiness = val; - return len; - } - - return -EINVAL; -} - -static ssize_t swappiness_para_read(struct file *file, - char __user *buffer, size_t count, loff_t *off) -{ - char kbuf[PARA_BUF_LEN] = {'0'}; - int len; - - len = snprintf(kbuf, PARA_BUF_LEN, "vm_swappiness: %d\n", vm_swappiness); - len += snprintf(kbuf + len, PARA_BUF_LEN - len, - "direct_swappiness: %d\n", direct_vm_swappiness); - len += snprintf(kbuf + len, PARA_BUF_LEN - len, - "swapd_swappiness: %d\n", hybridswapd_swappiness); - - if (len == PARA_BUF_LEN) - kbuf[len - 1] = '\0'; - - if (len > *off) - len -= *off; - else - len = 0; - - if (copy_to_user(buffer, kbuf + *off, (len < count ? len : count))) - return -EFAULT; - - *off += (len < count ? len : count); - return (len < count ? len : count); -} - -static const struct file_operations proc_swappiness_para_ops = { - .write = swappiness_para_write, - .read = swappiness_para_read, -}; - -int create_swappiness_para_proc(void) -{ - struct proc_dir_entry * para_entry = - proc_create("oplus_healthinfo/swappiness_para", - S_IRUSR|S_IWUSR, NULL, &proc_swappiness_para_ops); - - if (para_entry) { - printk("Register swappiness_para interface passed.\n"); - return 0; - } - - pr_err("Register swappiness_para interface failed.\n"); - return -ENOMEM; -} -EXPORT_SYMBOL(create_swappiness_para_proc); -#endif diff --git a/mm/vmstat.c b/mm/vmstat.c index e7b5077b49f3..5f089fec82e3 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -29,9 +29,6 @@ #include #include "internal.h" -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) -#include "multi_freearea.h" -#endif #define NUMA_STATS_THRESHOLD (U16_MAX - 2) @@ -953,26 +950,16 @@ static void fill_contig_page_info(struct zone *zone, struct contig_page_info *info) { unsigned int order; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc; -#endif info->free_pages = 0; info->free_blocks_total = 0; info->free_blocks_suitable = 0; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { -#endif for (order = 0; order < MAX_ORDER; order++) { unsigned long blocks; /* Count number of free blocks */ -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - blocks = zone->free_area[flc][order].nr_free; -#else blocks = zone->free_area[order].nr_free; -#endif info->free_blocks_total += blocks; /* Count free base pages */ @@ -983,9 +970,6 @@ static void fill_contig_page_info(struct zone *zone, info->free_blocks_suitable += blocks << (order - suitable_order); } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif } /* @@ -1070,9 +1054,6 @@ const char * const vmstat_text[] = { "nr_zspages", #endif "nr_free_cma", -#if defined(OPLUS_FEATURE_HEALTHINFO) && defined(CONFIG_OPLUS_HEALTHINFO) - "nr_ioncache_pages", -#endif /*OPLUS_FEATURE_HEALTHINFO*/ /* enum numa_stat_item counters */ #ifdef CONFIG_NUMA "numa_hit", @@ -1308,20 +1289,10 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat, struct zone *zone) { int order; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc = 0; -#endif seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { - for (order = 0; order < MAX_ORDER; ++order) - seq_printf(m, "%6lu ", zone->free_area[flc][order].nr_free); - } -#else for (order = 0; order < MAX_ORDER; ++order) seq_printf(m, "%6lu ", zone->free_area[order].nr_free); -#endif seq_putc(m, '\n'); } @@ -1340,11 +1311,6 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, { int order, mtype; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - int flc; - - for (flc = 0; flc < FREE_AREA_COUNTS; flc++) { -#endif for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) { seq_printf(m, "Node %4d, zone %8s, type %12s ", pgdat->node_id, @@ -1355,11 +1321,7 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, struct free_area *area; struct list_head *curr; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - area = &(zone->free_area[flc][order]); -#else area = &(zone->free_area[order]); -#endif list_for_each(curr, &area->free_list[mtype]) freecount++; @@ -1367,9 +1329,6 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, } seq_putc(m, '\n'); } -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - } -#endif } /* Print out the free pages at each order for each migatetype */ @@ -1979,9 +1938,6 @@ struct workqueue_struct *mm_percpu_wq; void __init init_mm_internals(void) { int ret __maybe_unused; -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - struct proc_dir_entry *pentry; -#endif mm_percpu_wq = alloc_workqueue("mm_percpu_wq", WQ_MEM_RECLAIM, 0); @@ -2008,13 +1964,6 @@ void __init init_mm_internals(void) proc_create("pagetypeinfo", 0400, NULL, &pagetypeinfo_file_operations); proc_create("vmstat", 0444, NULL, &vmstat_file_operations); proc_create("zoneinfo", 0444, NULL, &zoneinfo_file_operations); -#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION) - pentry = proc_create("free_area_list_show", S_IRWXUGO, NULL, &proc_free_area_fops); - if (!pentry) { - pr_err("vmstat: failed to create '/proc/free_area_list_show'\n"); - return; - } -#endif #endif } diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index f944d0d0349b..801afc0b8c36 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -69,11 +69,7 @@ * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single) * pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N. */ -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -#define ZS_MAX_ZSPAGE_ORDER 3 -#else #define ZS_MAX_ZSPAGE_ORDER 2 -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ #define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER) #define ZS_HANDLE_SIZE (sizeof(unsigned long)) @@ -123,11 +119,7 @@ #define FULLNESS_BITS 2 #define CLASS_BITS 8 -#if defined(OPLUS_FEATURE_ZRAM_OPT) && defined(CONFIG_OPLUS_ZRAM_OPT) -#define ISOLATED_BITS (ZS_MAX_ZSPAGE_ORDER+1) -#else #define ISOLATED_BITS 3 -#endif /*OPLUS_FEATURE_ZRAM_OPT*/ #define MAGIC_VAL_BITS 8 #define MAX(a, b) ((a) >= (b) ? (a) : (b)) diff --git a/nativefeatures.mk b/nativefeatures.mk index 3dfd6aab186e..f389666207b4 100644 --- a/nativefeatures.mk +++ b/nativefeatures.mk @@ -17,7 +17,6 @@ OPLUS_FEATURE_DEXOPT_SPEED=true OPLUS_FEATURE_APP_ACCESS_FILES=true OPLUS_FEATURE_OTA_DATA_UPDATE=true OPLUS_FEATURE_CUSTOM_GIDS=true -OPLUS_FEATURE_PHOENIX_RECOVERY=yes OPLUS_FEATURE_ALLFILEACCESS=yes OPLUS_FEATURE_CTS_FINGERPRINT=yes OPLUS_FEATURE_STORAGE=yes @@ -52,8 +51,6 @@ OPLUS_FEATURE_BATTERY_MANAGER=yes OPLUS_FEATURE_PMS_EXCEPTION_FIX=true OPLUS_FEATURE_PMS_BOOT_TIME_OPT=true OPLUS_FEATURE_SHUTDOWN_DETECT=yes -OPLUS_FEATURE_PHOENIX=yes -OPLUS_FEATURE_AGINGTEST=yes OPLUS_FEATURE_FINGERPRINT=yes OPLUS_FEATURE_FINGERPRINTPAY=yes FP_DCS_ENABLE=y @@ -74,18 +71,9 @@ FACE_TEE_RUNTIME=TBASE FACE_CONFIG_CPU_VERSION=1 LOW_ST_BUFFER_SIZE=1 FACE_DCS_ENABLE=y -OPLUS_FEATURE_HEALTHINFO=yes -OPLUS_FEATURE_SCHED_ASSIST=yes -OPLUS_FEATURE_PROCESS_RECLAIM=yes -OPLUS_FEATURE_FG_IO_OPT=yes OPLUS_FEATURE_TP_BASIC=yes -OPLUS_FEATURE_MULTI_KSWAPD=yes -OPLUS_FEATURE_ZRAM_OPT=yes -OPLUS_FEATURE_MULTI_FREEAREA=yes -OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY=yes OPLUS_FEATURE_SENSOR=yes OPLUS_FEATURE_SENSOR_ALGORITHM=yes -OPLUS_FEATURE_STORAGE_TOOL=yes OPLUS_FEATURE_CHG_BASIC=yes OPLUS_FEATURE_NEW_FTMFLASHLIGHT_NODE=yes OPLUS_ARCH_EXTENDS_CAM_TUNING_LIB=yes @@ -102,14 +90,12 @@ OPLUS_FEATURE_CAMERA_SMVR=yes OPLUS_FEATURE_CAMERA_MSNR=yes OPLUS_FEATURE_WIFI_DATASTALL=yes OPLUS_FEATURE_WIFI_MTUDETECT=yes -OPLUS_FEATURE_WIFI_SLA=yes OPLUS_FEATURE_WIFI_GBK=yes OPLUS_FEATURE_WIFI_DUALSTA=yes OPLUS_FEATURE_WIFI_OSHARE=yes OPLUS_FEATURE_WIFI_SUPPLICANTHIDL=yes OPLUS_FEATURE_WIFI_LIMMITBGSPEED=yes OPLUS_FEATURE_BT_INTEROPLIST=yes -OPLUS_FEATURE_DATA_EVAL=yes OPLUS_FEATURE_FONT_FLIP=yes OPLUS_FEATURE_MOTION_INTERCEPT=yes OPLUS_FEATURE_LINKERCONFIG_CUSTOM=yes diff --git a/net/Kconfig b/net/Kconfig index 2615c219090e..1194851d91c7 100755 --- a/net/Kconfig +++ b/net/Kconfig @@ -454,21 +454,7 @@ config HAVE_CBPF_JIT config HAVE_EBPF_JIT bool -# HuangJunyuan@CONNECTIVITY.WIFI.INTERNET.1197891, 2018/04/10,Add code for oplus sla function -source "net/oplus_connectivity_sla/Kconfig" - config MTK_NET_LOGGING bool "Enable MTK Network debug log" ---help--- This config helps to enable/disable Network debug log - -#ifdef OPLUS_FEATURE_WIFI_CAPCENTER -#XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453, OPLUS_FEATURE_WIFI_CAPCENTER, 2021/5/31 -source "net/oplus_wificapcenter/Kconfig" -#endif /* OPLUS_FEATURE_WIFI_CAPCENTER */ - -# PengHao@NETWORK.DATA.EVAL, 2020/05/09, Add for data eval -source "net/oplus_score/Kconfig" - -# ShiQianhua@NETWORK.DATA.2341538 2021/10/18 add for network modules -source "net/oplus_modules/Kconfig" diff --git a/net/Makefile b/net/Makefile index bb98c598868a..d05dc7199663 100755 --- a/net/Makefile +++ b/net/Makefile @@ -86,26 +86,3 @@ obj-y += l3mdev/ endif obj-$(CONFIG_QRTR) += qrtr/ obj-$(CONFIG_NET_NCSI) += ncsi/ - - -#ifdef OPLUS_FEATURE_WIFI_SLA -#HuangJunyuan@CONNECTIVITY.WIFI.INTERNET.1197891, 2018/04/10,Add code for oplus sla function -obj-$(CONFIG_OPLUS_FEATURE_WIFI_SLA) += oplus_connectivity_sla/ -#endif /* OPLUS_FEATURE_WIFI_SLA */ - -#ifdef OPLUS_FEATURE_DATA_EVAL -#PengHao@NETWORK.DATA.8124, 2020/05/08, Add for network quality evaluation. -obj-$(CONFIG_OPLUS_FEATURE_DATA_EVAL) += oplus_score/ -#endif /* OPLUS_FEATURE_DATA_EVAL */ - -#ifdef OPLUS_FEATURE_WIFI_CAPCENTER -#XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453, 2020/7/6, Add for Oplus Wifi capability center -obj-$(CONFIG_OPLUS_FEATURE_WIFI_CAPCENTER) += oplus_wificapcenter/ -#endif /* OPLUS_FEATURE_WIFI_CAPCENTER */ - -# ShiQianhua@NETWORK.DATA.2341538 2021/10/18 add for network modules -obj-y += oplus_modules/ - -#ifdef OPLUS_FEATURE_NWPOWER -obj-y += oplus_nwpower/ -#endif /* OPLUS_FEATURE_NWPOWER */ diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index beb73ecf9fc6..7826fba34b14 100755 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1110,16 +1110,6 @@ struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu) } dst->ops->update_pmtu(dst, sk, NULL, mtu, true); -// #ifdef OPLUS_FEATURE_WIFI_MTUDETECT - //TangRongzheng@CONNECTIVITY.WIFI.NETWORK.1066205, 2016/11/03. - //Add for [1066205] when receives ICMP_FRAG_NEEDED, reduces the mtu of net_device. - pr_err("%s: current_mtu = %d , frag_mtu = %d mtu = %d\n", __func__, dst->dev->mtu, dst_mtu(dst),mtu); - //do not use dst_mtu here, because dst_mtu should be changed by update_pmtu after inet_csk_rebuild_route - if (dst->dev->mtu > mtu && mtu > IPV6_MIN_MTU) { - dst->dev->mtu = mtu; - } -// #endif /* OPLUS_FEATURE_WIFI_MTUDETECT */ - dst = __sk_dst_check(sk, 0); if (!dst) dst = inet_csk_rebuild_route(sk, &inet->cork.fl); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 71b2ffae8e06..96bea44b8c17 100755 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -78,9 +78,6 @@ #include #include -//#ifdef OPLUS_FEATURE_NWPOWER -#include -//#endif /* OPLUS_FEATURE_NWPOWER */ int sysctl_tcp_fack __read_mostly; int sysctl_tcp_max_reordering __read_mostly = 300; @@ -4734,11 +4731,6 @@ queue_and_out: if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { /* A retransmit, 2nd most common case. Force an immediate ack. */ - - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_tcp_input_retrans(sk); - //#endif /* OPLUS_FEATURE_NWPOWER */ - NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOST); tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a0b0be95e389..f4da903d5eea 100755 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -85,10 +85,6 @@ #include #include -//#ifdef OPLUS_FEATURE_NWPOWER -#include -//#endif /* OPLUS_FEATURE_NWPOWER */ - #ifdef CONFIG_TCP_MD5SIG static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, __be32 daddr, __be32 saddr, const struct tcphdr *th); @@ -1629,10 +1625,6 @@ int tcp_v4_rcv(struct sk_buff *skb) struct sock *sk; int ret; - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_ipa_ip_wakeup(OPLUS_TCP_TYPE_V4, skb); - //#endif /* OPLUS_FEATURE_NWPOWER */ - if (skb->pkt_type != PACKET_HOST) goto discard_it; @@ -1665,10 +1657,6 @@ lookup: if (!sk) goto no_tcp_socket; - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_ipa_tcp_wakeup(OPLUS_TCP_TYPE_V4, sk); - //#endif /* OPLUS_FEATURE_NWPOWER */ - process: if (sk->sk_state == TCP_TIME_WAIT) goto do_time_wait; @@ -1778,9 +1766,6 @@ bad_packet: } discard_it: - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_ipa_schedule_work(); - //#endif /* OPLUS_FEATURE_NWPOWER */ /* Discard frame. */ kfree_skb(skb); return 0; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index ad650c5d244a..d79af0e5ad65 100755 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -62,10 +62,6 @@ int sysctl_tcp_tso_win_divisor __read_mostly = 3; /* By default, RFC2861 behavior. */ int sysctl_tcp_slow_start_after_idle __read_mostly = 1; -//#ifdef OPLUS_FEATURE_NWPOWER -#include -//#endif /* OPLUS_FEATURE_NWPOWER */ - static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, int push_one, gfp_t gfp); @@ -1134,10 +1130,6 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, err = icsk->icsk_af_ops->queue_xmit(sk, skb, &inet->cork.fl); - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_tcp_output(sk); - //#endif /* OPLUS_FEATURE_NWPOWER */ - if (unlikely(err > 0)) { tcp_enter_cwr(sk); err = net_xmit_eval(err); @@ -2030,13 +2022,6 @@ static bool tcp_can_coalesce_send_queue_head(struct sock *sk, int len) struct sk_buff *skb, *next; skb = tcp_send_head(sk); - //#ifdef OPLUS_BUG_STABILITY - //#KangYi@CN.WiFi.Network., 2021/06/02, add for stability bug - if ( !skb ) - { - return false; - } - //endif OPLUS_BUG_STABILITY tcp_for_write_queue_from_safe(skb, next, sk) { if (len <= skb->len) break; diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 28f617ee991f..1b235c12dc4c 100755 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1498,13 +1498,6 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk, if (confirm_neigh) dst_confirm_neigh(dst, daddr); -#ifdef OPLUS_BUG_STABILITY - //ipv6 RFC8201 test - if (mtu < IPV6_MIN_MTU) { - return; - } -#endif /* OPLUS_BUG_STABILITY */ - mtu = max_t(u32, mtu, IPV6_MIN_MTU); if (mtu >= dst_mtu(dst)) return; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 689ff05c8459..a516490de3db 100755 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -69,10 +69,6 @@ #include #include -//#ifdef OPLUS_FEATURE_NWPOWER -#include -//#endif /* OPLUS_FEATURE_NWPOWER */ - static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb); static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, struct request_sock *req); @@ -1413,10 +1409,6 @@ static int tcp_v6_rcv(struct sk_buff *skb) int ret; struct net *net = dev_net(skb->dev); - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_ipa_ip_wakeup(OPLUS_TCP_TYPE_V6, skb); - //#endif /* OPLUS_FEATURE_NWPOWER */ - if (skb->pkt_type != PACKET_HOST) goto discard_it; @@ -1448,10 +1440,6 @@ lookup: if (!sk) goto no_tcp_socket; - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_match_ipa_tcp_wakeup(OPLUS_TCP_TYPE_V6, sk); - //#endif /* OPLUS_FEATURE_NWPOWER */ - process: if (sk->sk_state == TCP_TIME_WAIT) goto do_time_wait; @@ -1555,9 +1543,6 @@ bad_packet: } discard_it: - //#ifdef OPLUS_FEATURE_NWPOWER - oplus_ipa_schedule_work(); - //#endif /* OPLUS_FEATURE_NWPOWER */ kfree_skb(skb); return 0; diff --git a/net/oplus_connectivity_sla/Kconfig b/net/oplus_connectivity_sla/Kconfig deleted file mode 100755 index e4f3d4749684..000000000000 --- a/net/oplus_connectivity_sla/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. - -config OPLUS_FEATURE_WIFI_SLA - tristate "Add for oplus sla function" - help - Add for oplus sla function. diff --git a/net/oplus_connectivity_sla/Makefile b/net/oplus_connectivity_sla/Makefile deleted file mode 100755 index df1ba9ca04f7..000000000000 --- a/net/oplus_connectivity_sla/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -#/************************************************************************************ -#** File: - Makefile -#** Copyright (C), 2008-2020, OPLUS Mobile Comm Corp., Ltd -#** -#** Description: -#** 1. Add for sla -#** -#** Version: 1.0 -#** Date : 2021-7-17 -#** Author: LianGenglin@CONNECTIVITY.WIFI.INTERNET -#** TAG : OPLUS_FEATURE_WIFI_SLA -#** -#** ---------------------Revision History: --------------------- -#** -#** --------------------------------------------------------------- -#** LianGenglin@CONNECTIVITY.WIFI.INTERNET 2020/05/09 1.0 build this module -#** -#************************************************************************************/ - -# -# Makefile for the netfilter modules on top of IPv4. -# -obj-$(CONFIG_OPLUS_FEATURE_WIFI_SLA) += oplus_connectivity_sla.o diff --git a/net/oplus_connectivity_sla/oplus_connectivity_sla.c b/net/oplus_connectivity_sla/oplus_connectivity_sla.c deleted file mode 100755 index a0c9c31dd9fb..000000000000 --- a/net/oplus_connectivity_sla/oplus_connectivity_sla.c +++ /dev/null @@ -1,1613 +0,0 @@ -/************************************************************************************ -** File: - oplus_connectivity_sla.c -** Copyright (C), 2008-2020, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** 1. Add for SLA GKI -** -** Version: 1.0 -** Date : 2021-04-19 -** Author: LianGenglin@CONNECTIVITY.WIFI.INTERNET -** TAG : OPLUS_FEATURE_WIFI_CONNECTIVITY_SLA -** -** ---------------------Revision History: --------------------- -** -** --------------------------------------------------------------- -** Junyuan.Huang@CONNECTIVITY.WIFI.INTERNET 2018/04/03 1.0 OPLUS_FEATURE_WIFI_SLA -** LianGenglin@CONNECTIVITY.WIFI.INTERNET 2021/04/19 1.0 rebuild this module -** -************************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#define LOG_TAG "[oplus_connectivity_sla] %s line:%d " -#define debug(fmt,args...) printk(LOG_TAG fmt,__FUNCTION__,__LINE__,##args) - -#define IFACE_NUM 3 -#define WLAN_NUM 2 -#define WLAN0_INDEX 0 -#define WLAN1_INDEX 1 -#define CELL_INDEX 2 - -#define MARK_MASK 0x0fff -#define GAME_UNSPEC_MASK 0x8000 -#define CT_MARK_APP_TYPE_MASK 0xfff00000 //mark for detect white list -#define CT_MARK_APP_TYPE_OFFSET 20 - -#define GAME_NUM 7 -#define IFACE_LEN 16 -#define WHITE_APP_BASE 100 -#define DUAL_STA_APP_BASE 200 -#define WHITE_APP_NUM 64 -#define DUAL_STA_APP_NUM 256 - -//#define DNS_TIME 10 - -#define UID_MASK 100000 -#define INIT_APP_TYPE 0 -#define UNKNOW_APP_TYPE 0xfff /*for distinguish dual sta app*/ - -#define OPLUS_SLA_CMD_MAX (__OPLUS_SLA_CMD_MAX - 1) -#define OPLUS_SLA_FAMILY_VERSION 1 -#define OPLUS_SLA_FAMILY "oplus_sla" -#define NLA_DATA(na) ((char *)((char*)(na) + NLA_HDRLEN)) -#define GENL_ID_GENERATE 0 - -enum { - OPLUS_SLA_CMD_UNSPEC = 1, - OPLUS_SLA_CMD_SET_ANDROID_PID = 2, - OPLUS_SLA_CMD_ENABLE = 3, - OPLUS_SLA_CMD_DISABLE = 4, - OPLUS_SLA_CMD_IFACE_CHANGED = 5, - OPLUS_SLA_CMD_SET_WHITE_LIST_APP = 6, - OPLUS_SLA_CMD_SET_DUAL_STA_LIST_APP = 7, - OPLUS_SLA_CMD_SET_GAME_LIST_APP = 8, - OPLUS_SLA_CMD_SET_VIDEO_LIST_APP = 9, - OPLUS_SLA_CMD_CHANGE_GAME_NETWORK = 10, - OPLUS_SLA_CMD_CHANGE_VIDEO_APP_NETWORK = 11, - OPLUS_SLA_CMD_CHANGE_DNS_NETWORK = 12, - OPLUS_SLA_CMD_UPDATE_WEIGHT = 13, - OPLUS_SLA_CMD_SET_KERNEL_DEBUG = 14, - OPLUS_SLA_CMD_CHANGE_VPN_STATE = 15, - OPLUS_SLA_CMD_CHANGE_DEFAULT_NETWORK = 16, - OPLUS_SLA_ENABLED_EVENT = 18, - OPLUS_SLA_DISABLED_EVENT = 19, - OPLUS_SLA_GAME_NETWORK_CHANGED_EVENT = 20, - __SLA_MSG_MAX, -}; - -enum { - OPLUS_SLA_UNSPEC, - OPLUS_SLA_CMD_DOWNLINK, - OPLUS_SLA_CMD_UPLINK, - __OPLUS_SLA_CMD_MAX -}; - - -#define OPLUS_SLA_MSG_MAX (__SLA_MSG_MAX - 1) - - -/* dev info struct - * if we need to consider wifi RSSI ?if we need consider screen state? -*/ -struct oplus_dev_info { - int if_up; - int weight; - //int weight_state; - u32 mark; - char dev_name[IFACE_LEN]; -}; - -struct oplus_white_app_info { - u32 count; - u32 uid[WHITE_APP_NUM]; - u64 cell_bytes[WHITE_APP_NUM]; - u64 cell_bytes_normal[WHITE_APP_NUM]; -}; - -struct oplus_dual_sta_info { - u32 count; - u32 uid[DUAL_STA_APP_NUM]; -}; - -struct oplus_sla_game_info { - u32 game_type; - u32 uid; - u32 mark; -}; - -enum { - SLA_SKB_ACCEPT, - SLA_SKB_CONTINUE, - SLA_SKB_MARKED, - SLA_SKB_REMARK, - SLA_SKB_DROP, -}; - -enum { - GAME_UNSPEC = 0, - GAME_WZRY = 1, - GAME_CJZC, - GAME_QJCJ, - GAME_HYXD_NM, - GAME_HYXD, - GAME_HYXD_ALI, -}; - -enum { - - WLAN0_MARK_BIT = 8, //WLAN mark value,mask 0x0fff - WLAN0_MARK = (1 << WLAN0_MARK_BIT), - - WLAN1_MARK_BIT = 9, //WLAN mark value,mask 0x0fff - WLAN1_MARK = (1 << WLAN1_MARK_BIT), - - CELL_MARK_BIT = 10, //cellular mark value mask 0x0fff - CELL_MARK = (1 << CELL_MARK_BIT), - - RETRAN_BIT = 12, //first retran mark value, mask 0xf000 - RETRAN_MARK = (1 << RETRAN_BIT), - - RETRAN_SECOND_BIT = 13, //second retran mark value, mask 0xf000 - RETRAN_SECOND_MARK = (1 << RETRAN_SECOND_BIT), - - RTT_MARK_BIT = 14, //one ct only statitisc once rtt,mask 0xf000 - RTT_MARK = (1 << RTT_MARK_BIT), - - GAME_UNSPEC_MARK_BIT = 15, //mark game skb when game not start - GAME_UNSPEC_MARK = (1 << GAME_UNSPEC_MARK_BIT), -}; - -enum { - SLA_MODE_INIT = 0, - SLA_MODE_DUAL_WIFI = 1, - /*if the dual wifi is enable,please do not send - disable msg to kernel when rcv SLA_MODE_WIFI_CELL msg*/ - SLA_MODE_WIFI_CELL = 2, - SLA_MODE_DUAL_WIFI_CELL = 3, - SLA_MODE_RESERVER = 4, -}; - -static volatile u32 oplus_sla_netlink_pid; -static int MAIN_WLAN = WLAN0_INDEX; -static int SECOND_WLAN = WLAN1_INDEX; - -static int oplus_sla_enable_status; -static int oplus_sla_screen_on; -static int oplus_sla_debug = 0; -static int oplus_sla_def_net = 0; //WLAN0->0 WLAN1->1 CELL->2 -static int sla_work_mode = SLA_MODE_INIT; -static int dns_network = WLAN0_INDEX; -static int video_app_network = WLAN0_INDEX; //init - -static struct oplus_white_app_info white_app_list; -static struct oplus_dual_sta_info dual_wifi_app_list; -static struct oplus_dual_sta_info video_app_list; -static struct oplus_sla_game_info game_info[GAME_NUM]; -static int game_mark = 0; //for proc debug -static int oplus_sla_vpn_connected = 0; -static struct ctl_table_header *oplus_sla_table_hrd; - -static rwlock_t sla_lock; -static rwlock_t sla_game_lock; - -static int MAIN_WLAN_MARK = WLAN0_MARK; -static int SECOND_WLAN_MARK = WLAN1_MARK; -static struct oplus_dev_info oplus_sla_info[IFACE_NUM]; - -#define sla_read_lock() read_lock_bh(&sla_lock); -#define sla_read_unlock() read_unlock_bh(&sla_lock); -#define sla_write_lock() write_lock_bh(&sla_lock); -#define sla_write_unlock() write_unlock_bh(&sla_lock); - -#define sla_game_write_lock() write_lock_bh(&sla_game_lock); -#define sla_game_write_unlock() write_unlock_bh(&sla_game_lock); - - - -static u32 get_app_type(struct nf_conn *ct) -{ - if (ct != NULL) { - return (ct->mark & CT_MARK_APP_TYPE_MASK) >> CT_MARK_APP_TYPE_OFFSET; - } - - return 0; -} - -static void set_app_type(struct nf_conn *ct, int type) -{ - if (ct != NULL) { - ct->mark = (ct->mark & ~CT_MARK_APP_TYPE_MASK) | ((type << - CT_MARK_APP_TYPE_OFFSET) & CT_MARK_APP_TYPE_MASK); - } -} - -static bool is_same_app(u32 source_app_uid, u32 target_app_uid) -{ - return (source_app_uid % UID_MASK) == (target_app_uid % UID_MASK); -} - -static u32 get_ct_mark(struct nf_conn *ct) -{ - if (ct != NULL) { - return (ct->mark & ~CT_MARK_APP_TYPE_MASK); - } - return 0; -} - -static void set_ct_mark(struct nf_conn *ct, int mark) -{ - if (ct != NULL) { - ct->mark = (ct->mark & ~MARK_MASK) | mark; - } -} - -static void print_stream_info(struct sk_buff *skb) -{ - u32 uid = 0; - int srcport = 0; - int dstport = 0; - unsigned char *dstip; - - struct sock *sk = NULL; - struct iphdr *iph = NULL; - struct nf_conn *ct = NULL; - struct net_device *dev = NULL; - enum ip_conntrack_info ctinfo; - const struct file *filp = NULL; - - if (oplus_sla_debug) { - ct = nf_ct_get(skb, &ctinfo); - - if (NULL == ct) { - return; - } - - if (ctinfo == IP_CT_NEW) { - sk = skb_to_full_sk(skb); - - if (sk && sk_fullsock(sk)) { - if (NULL == sk->sk_socket) { - return; - } - - filp = sk->sk_socket->file; - - if (NULL == filp) { - return; - } - - iph = ip_hdr(skb); - - if (NULL != iph && - (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP)) { - - dev = skb_dst(skb)->dev; - uid = filp->f_cred->fsuid.val; - dstport = ntohs(udp_hdr(skb)->dest); - srcport = ntohs(udp_hdr(skb)->source); - dstip = (unsigned char *)&iph->daddr; - - debug("screen_on[%d] uid[%u] proto[%d] srcport[%d] dstport[%d]" - " dstip[%d.%d.%d.%d] dev[%s] mark[%x] ct_mark[%x] app_type[%d]\n", - oplus_sla_screen_on, uid, iph->protocol, srcport, dstport, - dstip[0], dstip[1], dstip[2], dstip[3], dev ? dev->name : "null", skb->mark, - get_ct_mark(ct), get_app_type(ct)); - } - } - } - } - - return; -} - -static bool is_skb_pre_bound(struct sk_buff *skb) -{ - u32 pre_mark = skb->mark & 0x10000; - - if (0x10000 == pre_mark) { - return true; - } - - return false; -} - -static bool is_sla_white_or_game_app(struct nf_conn *ct, struct sk_buff *skb) -{ - u32 oplus_app_type = get_app_type(ct); - //debug("type : %u \n", get_app_type(ct)); - if (oplus_app_type > 0 && - oplus_app_type < DUAL_STA_APP_BASE) { /* game app skb */ - return true; - } - - return false; -} - -static bool is_dual_sta_white_app(struct nf_conn *ct, struct sk_buff *skb, - kuid_t *app_uid) -{ - int i = 0; - int last_type = UNKNOW_APP_TYPE; - kuid_t uid; - struct sock *sk = NULL; - const struct file *filp = NULL; - - //debug("type : %u \n", get_app_type(ct)); - - if (get_app_type(ct) >= DUAL_STA_APP_BASE) { - return true; - } - - if (UNKNOW_APP_TYPE != get_app_type(ct)) { - - last_type = get_app_type(ct); - - sk = skb_to_full_sk(skb); - - if (NULL == sk || NULL == sk->sk_socket) { - return false; - } - - filp = sk->sk_socket->file; - - if (NULL == filp) { - return false; - } - - *app_uid = filp->f_cred->fsuid; - uid = filp->f_cred->fsuid; - - for (i = 0; i < dual_wifi_app_list.count; i++) { - if (dual_wifi_app_list.uid[i]) { - if (is_same_app(uid.val, dual_wifi_app_list.uid[i])) { - set_app_type(ct, i + DUAL_STA_APP_BASE); - return true; - } - } - } - - set_app_type(ct, last_type); - } - - return false; -} - - -static bool is_video_app(kuid_t app_uid) -{ - int i = 0; - kuid_t uid; - - for (i = 0; i < video_app_list.count; i++) { - if (video_app_list.uid[i]) { - uid = make_kuid(&init_user_ns, video_app_list.uid[i]); - - if (is_same_app(uid.val, app_uid.val)) { - debug("oplus_sla video app, the uid = %d", app_uid.val); - return true; - } - } - } - - return false; -} - -static int mark_video_app(struct sock *sk, - kuid_t app_uid, - struct nf_conn *ct, - struct sk_buff *skb) -{ - int choose_mark = 0; - int ret = SLA_SKB_CONTINUE; - - if (SLA_MODE_DUAL_WIFI == sla_work_mode && - is_video_app(app_uid)) { - if (video_app_network == MAIN_WLAN) { - choose_mark = MAIN_WLAN_MARK; - - } else if (video_app_network == SECOND_WLAN) { - choose_mark = SECOND_WLAN_MARK; - } - } - - if (choose_mark) { - skb->mark = choose_mark; - set_ct_mark(ct, skb->mark); - return SLA_SKB_MARKED; - } - - return ret; -} - -/* -LAN IP: -A:10.0.0.0-10.255.255.255 -B:172.16.0.0-172.31.255.255 -C:192.168.0.0-192.168.255.255 -*/ -static bool dst_is_lan_ip(struct sk_buff *skb) -{ - struct iphdr *iph = NULL; - unsigned char *dstip = NULL; - - iph = ip_hdr(skb); - - if (NULL != iph) { - dstip = (unsigned char *)&iph->daddr; - - if ((10 == dstip[0]) || - (192 == dstip[0] && 168 == dstip[1]) || - (172 == dstip[0] && dstip[1] >= 16 && dstip[1] <= 31)) { - return true; - } - } - - return false; -} - -static int sla_skb_reroute(struct sk_buff *skb, struct nf_conn *ct, - const struct nf_hook_state *state) -{ - int err; - - //err = ip_route_me_harder(state->net, state->sk, skb, RTN_UNSPEC); - err = ip_route_me_harder(state->net, skb, RTN_UNSPEC); - - if (err < 0) { - return NF_DROP_ERR(err); - } - - return NF_ACCEPT; -} - - -static u32 get_skb_mark_by_weight(void) -{ - int i = 0; - u32 sla_random = prandom_u32() & 0x7FFFFFFF; - - /*0x147AE15 = 0x7FFFFFFF /100 + 1; for we let the weight * 100 to void - *decimal point operation at linux kernel - */ - for (i = 0; i < IFACE_NUM; i++) { - if (oplus_sla_info[i].if_up && - oplus_sla_info[i].weight) { - if (sla_random < (0x147AE15 * oplus_sla_info[i].weight)) { - return oplus_sla_info[i].mark; - } - } - } - - return oplus_sla_info[MAIN_WLAN].mark; -} - -static bool is_need_change_dns_network(int index) -{ - if (dns_network != 0) { - return true; - - } else { - return false; - } - -} - -static int dns_skb_need_sla(struct nf_conn *ct, struct sk_buff *skb) -{ - int ret = SLA_SKB_CONTINUE; - struct iphdr *iph = NULL; - u_int32_t dns_ct_mark = MAIN_WLAN_MARK; - - iph = ip_hdr(skb); - - if (NULL != iph && - (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) && - 53 == ntohs(udp_hdr(skb)->dest)) { - - ret = SLA_SKB_ACCEPT; - - if (SLA_MODE_DUAL_WIFI == sla_work_mode) { - if (is_need_change_dns_network(SECOND_WLAN)) { - //for the dns packet will do DNAT at iptables,if do DNAT,the packet - //will be reroute,so here just mark and accept it - dns_ct_mark = SECOND_WLAN_MARK; - skb->mark = SECOND_WLAN_MARK; - //todo: same dst ip should do this ,differ dst ip just let it go and reroute by DNAT - //debug("dual sta reroute skb->mark = %x\n", skb->mark); - ret = SLA_SKB_MARKED; - } - - } else if (SLA_MODE_WIFI_CELL == sla_work_mode) { - if (is_need_change_dns_network(CELL_INDEX)) { - dns_ct_mark = CELL_MARK; - skb->mark = CELL_MARK; - //todo: same dst ip should do this - //ret = SLA_SKB_MARKED; - } - } - - //debug("dns mark = %x\n", skb->mark); - ct->mark = dns_ct_mark; - } - - return ret; -} - -static bool is_game_app_skb(struct nf_conn *ct, struct sk_buff *skb, - enum ip_conntrack_info ctinfo) -{ - int i = 0; - kuid_t uid; - struct sock *sk = NULL; - struct iphdr *iph = NULL; - const struct file *filp = NULL; - - if (INIT_APP_TYPE == get_app_type(ct)) { - - sk = skb_to_full_sk(skb); - - if (NULL == sk || NULL == sk->sk_socket) { - return false; - } - - filp = sk->sk_socket->file; - - if (NULL == filp) { - return false; - } - - iph = ip_hdr(skb); - - uid = filp->f_cred->fsuid; - - for (i = 1; i < GAME_NUM; i++) { - if (game_info[i].uid) { - if (is_same_app(uid.val, game_info[i].uid)) { - set_app_type(ct, i); - - if (game_mark) { - set_ct_mark(ct, game_mark); - - } else { - set_ct_mark(ct, game_info[i].mark); - } - - return true; - } - } - } - - } else if (get_app_type(ct) > 0 && get_app_type(ct) < GAME_NUM) { - i = get_app_type(ct); - return true; - } - - return false; - -} - -static int detect_game_skb(struct sk_buff *skb) -{ - //struct iphdr *iph = NULL; - struct nf_conn *ct = NULL; - int ret = SLA_SKB_ACCEPT; - enum ip_conntrack_info ctinfo; - - if (oplus_sla_vpn_connected) { - return SLA_SKB_CONTINUE; - } - - ct = nf_ct_get(skb, &ctinfo); - - if (NULL == ct) { - return SLA_SKB_ACCEPT; - } - - if (!is_game_app_skb(ct, skb, ctinfo)) { - return SLA_SKB_CONTINUE; - } - - //TCP and udp need to switch network - ret = SLA_SKB_CONTINUE; - return ret; -} - - -static void detect_white_list_app_skb(struct sk_buff *skb) -{ - int i = 0; - int index = -1; - kuid_t uid; - struct nf_conn *ct = NULL; - enum ip_conntrack_info ctinfo; - struct sock *sk = NULL; - const struct file *filp = NULL; - - ct = nf_ct_get(skb, &ctinfo); - - if (NULL == ct) { - return; - } - - /*when the app type is dual sta app,but the work mode is not - SLA_MODE_DUAL_WIFI, we should detect it is WIFI+CELL white - list app again - */ - if (SLA_MODE_DUAL_WIFI != sla_work_mode && - get_app_type(ct) >= DUAL_STA_APP_BASE) { - set_app_type(ct, INIT_APP_TYPE); - } - - if (INIT_APP_TYPE == get_app_type(ct)) { - sk = skb_to_full_sk(skb); - - if (NULL == sk || NULL == sk->sk_socket) { - return; - } - - filp = sk->sk_socket->file; - - if (NULL == filp) { - return; - } - - uid = filp->f_cred->fsuid; - - for (i = 0; i < white_app_list.count; i++) { - if (white_app_list.uid[i]) { - if (is_same_app(uid.val, white_app_list.uid[i])) { - set_app_type(ct, i + WHITE_APP_BASE); - return; - } - } - } - - /* we need to detect the whether it is dual sta white list app */ - if (SLA_MODE_DUAL_WIFI != sla_work_mode) { - set_app_type(ct, UNKNOW_APP_TYPE); - } - - } else if (get_app_type(ct) >= WHITE_APP_BASE && - get_app_type(ct) < DUAL_STA_APP_BASE) { - /*calc white app cell bytes when sla is not enable, - when the default network is change to cell,we should - disable dual sta from framework - */ - if (oplus_sla_info[CELL_INDEX].if_up) { - if (!oplus_sla_info[MAIN_WLAN].if_up || - oplus_sla_def_net == CELL_INDEX) { - index = get_app_type(ct) - WHITE_APP_BASE; - - if (index < WHITE_APP_NUM) { - white_app_list.cell_bytes_normal[index] += skb->len; - } - } - } - } - - return; -} - -static int mark_game_app_skb(struct nf_conn *ct, struct sk_buff *skb, - enum ip_conntrack_info ctinfo) -{ - int game_index = -1; - struct iphdr *iph = NULL; - u32 ct_mark = 0; - int ret = SLA_SKB_CONTINUE; - int oplus_app_type = get_app_type(ct); - - if (oplus_app_type > 0 && oplus_app_type < GAME_NUM) { - ret = SLA_SKB_ACCEPT; - game_index = oplus_app_type; - - if (GAME_WZRY != game_index && - GAME_CJZC != game_index) { - return ret; - } - - iph = ip_hdr(skb); - - if (iph && - (IPPROTO_UDP == iph->protocol || - IPPROTO_TCP == iph->protocol)) { - - //WZRY can not switch tcp packets - if (GAME_WZRY == game_index && - IPPROTO_TCP == iph->protocol) { - return SLA_SKB_ACCEPT; - } - - ct_mark = get_ct_mark(ct) & MARK_MASK; - - if (GAME_CJZC == game_index && - IPPROTO_TCP == iph->protocol && - ((XT_STATE_BIT(ctinfo) & XT_STATE_BIT(IP_CT_ESTABLISHED)) || - (XT_STATE_BIT(ctinfo) & XT_STATE_BIT(IP_CT_RELATED)))) { - if (MAIN_WLAN_MARK == ct_mark) { - return SLA_SKB_ACCEPT; - - } else if (CELL_MARK == ct_mark) { - skb->mark = CELL_MARK; - return SLA_SKB_MARKED; - } - } - - if (game_mark) { - skb->mark = game_mark; - - } else { - skb->mark = game_info[game_index].mark; - } - - if (ct_mark && skb->mark && - ct_mark != skb->mark) { - - debug("oplus_sla_game:reset game ct proto= %u,srcport = %d," - "ct dying = %d,ct confirmed = %d,game type = %d,ct mark = %x,skb mark = %x\n", - iph->protocol, ntohs(udp_hdr(skb)->source), - nf_ct_is_dying(ct), nf_ct_is_confirmed(ct), game_index, ct_mark, skb->mark); - - if (!nf_ct_is_dying(ct) && - nf_ct_is_confirmed(ct)) { - nf_ct_kill(ct); - return SLA_SKB_DROP; - - } else { - skb->mark = ct_mark; - ret = SLA_SKB_MARKED; - } - } - - if (!ct_mark) { - //set_ct_mark(ct, game_info[game_index].mark); - set_ct_mark(ct, skb->mark); - } - - ret = SLA_SKB_MARKED; - } - } - - return ret; -} - - -static int sla_mark_skb(struct sk_buff *skb, const struct nf_hook_state *state) -{ - int ret = SLA_SKB_CONTINUE; - //int index = 0; - kuid_t app_uid = {0}; - //u32 ct_mark = 0x0; - struct sock *sk = NULL; - struct nf_conn *ct = NULL; - enum ip_conntrack_info ctinfo; - - //if wlan assistant has change network to cell,do not mark SKB - if (oplus_sla_def_net == CELL_INDEX) { - return NF_ACCEPT; - } - - ct = nf_ct_get(skb, &ctinfo); - - if (NULL == ct) { - return NF_ACCEPT; - } - - /* - * when the wifi is poor,the dns request allways can not rcv respones, - * so please let the dns packet with the cell network mark. - */ - ret = dns_skb_need_sla(ct, skb); - - if (SLA_SKB_ACCEPT == ret) { - return NF_ACCEPT; - - } else if (SLA_SKB_MARKED == ret) { - goto sla_reroute; - } - - if (is_skb_pre_bound(skb) || dst_is_lan_ip(skb)) { - return NF_ACCEPT; - } - - if (SLA_MODE_WIFI_CELL == sla_work_mode && - !is_sla_white_or_game_app(ct, skb)) { - return NF_ACCEPT; - } - - if (SLA_MODE_DUAL_WIFI == sla_work_mode && - !is_dual_sta_white_app(ct, skb, &app_uid)) { - return NF_ACCEPT; - } - - ret = mark_game_app_skb(ct, skb, ctinfo); - - if (SLA_SKB_MARKED == ret) { - goto sla_reroute; - - } else if (SLA_SKB_ACCEPT == ret) { - return NF_ACCEPT; - - } else if (SLA_SKB_DROP == ret) { - return NF_DROP; - } - - if (ctinfo == IP_CT_NEW) { - sk = skb_to_full_sk(skb); - - if (NULL != sk) { -#if 0 - // add for download app stream - ret = mark_download_app(sk, app_uid, ct, skb); - - if (SLA_SKB_MARKED == ret) { - goto sla_reroute; - } - -#endif - // add for video app stream - ret = mark_video_app(sk, app_uid, ct, skb); - - if (SLA_SKB_MARKED == ret) { - goto sla_reroute; - } - - sla_read_lock(); - skb->mark = get_skb_mark_by_weight(); - sla_read_unlock(); - set_ct_mark(ct, skb->mark); - if (oplus_sla_debug) { - debug("skb->mark = %x ct->mark = %x get_ct_mark = %x\n", skb->mark, ct->mark, - get_ct_mark(ct)); - } - } - - } else if ((XT_STATE_BIT(ctinfo) & XT_STATE_BIT(IP_CT_ESTABLISHED)) || - (XT_STATE_BIT(ctinfo) & XT_STATE_BIT(IP_CT_RELATED))) { - - skb->mark = get_ct_mark(ct) & MARK_MASK; - /* - if (oplus_sla_debug) { - debug("skb->mark = %x ct->mark = %x get_ct_mark = %x\n", skb->mark, ct->mark, - get_ct_mark(ct)); - } - */ - } - -//If the mark value of the packet is equal to WLAN0_MARK, no re routing is required - if (MAIN_WLAN_MARK == skb->mark) { - return NF_ACCEPT; - } - -#if 0 - -//calc white list app cell bytes - if (ct->oppo_app_type >= WHITE_APP_BASE && - ct->oppo_app_type < DUAL_STA_APP_BASE) { - ct_mark = ct->mark & MARK_MASK; - - if (CELL_MARK == ct_mark) { - index = ct->oppo_app_type - WHITE_APP_BASE; - - if (index < WHITE_APP_NUM) { - white_app_list.cell_bytes[index] += skb->len; - } - } - } - -#endif - -sla_reroute: - ret = sla_skb_reroute(skb, ct, state); - return ret; - -} -/* -oplus sla hook function, mark skb and rerout skb -*/ -static unsigned int oplus_sla_output_hook(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - int ret = NF_ACCEPT; - int game_ret = NF_ACCEPT; - - game_ret = detect_game_skb(skb); - - if (SLA_SKB_ACCEPT == game_ret) { - goto end_sla_output; - } - - //we need to calc white list app cell bytes when sla not enabled - detect_white_list_app_skb(skb); - - if (oplus_sla_enable_status) { - - ret = sla_mark_skb(skb, state); - - }/* else { - - if (!oplus_sla_screen_on) { - goto end_sla_output; - } - }*/ - -end_sla_output: - //add for android Q statictis tcp tx and tx - //statistics_wlan_tcp_tx_rx(state, skb); - print_stream_info(skb); - return ret; -} - -static int TIMESTAMP_ERROR_THRESHOLD = 10; -static int ts_error_count = 0; -static void handle_timestamp_error_case(struct sk_buff *skb, const struct nf_hook_state *state) -{ - struct sock *sk = NULL; - struct iphdr *iph; - struct tcp_options_received tcp_opt; - const __be32 *ptr; - - if ((iph = ip_hdr(skb)) != NULL && iph->protocol == IPPROTO_TCP) { - sk = skb_to_full_sk(skb); - - if (sk && (!sk_fullsock(sk) || sk->sk_state == TCP_TIME_WAIT || sk->sk_state == TCP_NEW_SYN_RECV)) { - return; - } - - if (NULL != sk) { - struct tcp_sock *tp = tcp_sk(sk); - struct tcphdr *th = tcp_hdr(skb); - - //handle syn + ack - if (NULL != tp && NULL != th && th->ack && th->syn) { - //fast path - memset(&tcp_opt, 0, sizeof(tcp_opt)); - ptr = (const __be32 *)(th + 1); - - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) { - ptr += 2; - - if (*ptr) { - tcp_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset; - tcp_opt.saw_tstamp = 1; - //debug("fast path rcv_tsecr = %u\n", tcp_opt.rcv_tsecr); - } - - }/*else { - //fall back slow path - tcp_parse_options(sock_net(sk), skb, &tcp_opt, 0, NULL); - tcp_opt.rcv_tsecr -= tp->tsoffset; - }*/ - /* - if (tcp_opt.saw_tstamp && tcp_opt.rcv_tsecr) { - debug("rcv_tsecr = %u retrans_stamp = %u tcp_time_stamp(tp) = %u ipid = %x\n", - tcp_opt.rcv_tsecr, - tp->retrans_stamp, tcp_time_stamp(tp), ntohs(iph->id)); - } - */ - if (tcp_opt.saw_tstamp && tcp_opt.rcv_tsecr && - !between(tcp_opt.rcv_tsecr, tp->retrans_stamp, tcp_time_stamp(tp))) { - debug("timestamp error count : %d\n", ts_error_count); - ts_error_count ++; - - if (ts_error_count >= TIMESTAMP_ERROR_THRESHOLD) { - debug("TimeStamp error:disable tcp timestamp\n"); - (state->net)->ipv4.sysctl_tcp_timestamps = 0; - ts_error_count = 0; - } - - } else { - if (ts_error_count > 0) { - ts_error_count --; - } - } - } - } - } -} - - -static int oplus_sla_genl_nlmsg_handle(struct sk_buff *skb, - struct genl_info *info); -static const struct genl_ops oplus_sla_genl_ops[] = { - { - .cmd = OPLUS_SLA_CMD_DOWNLINK, - .flags = 0, - .doit = oplus_sla_genl_nlmsg_handle, - .dumpit = NULL, - }, -}; - - -static struct genl_family oplus_sla_genl_family = { - .id = 0, - .hdrsize = 0, - .name = OPLUS_SLA_FAMILY, - .version = OPLUS_SLA_FAMILY_VERSION, - .maxattr = OPLUS_SLA_MSG_MAX, - .ops = oplus_sla_genl_ops, - .n_ops = ARRAY_SIZE(oplus_sla_genl_ops), -}; - -static inline int genl_msg_prepare_usr_msg(u8 cmd, size_t size, pid_t pid, - struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_ATOMIC); - - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_sla_genl_family, 0, cmd); - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, - int len) -{ - int ret; - - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - -/* send to user space */ -static int oplus_sla_send_to_user(int msg_type, char *payload, int payload_len) -{ - int ret = 0; - void *head; - struct sk_buff *skbuff; - size_t size; - - if (!oplus_sla_netlink_pid) { - debug("oplus_sla_netlink_pid == 0!!\n"); - return -1; - } - - /*allocate new buffer cache */ - size = nla_total_size(payload_len); - ret = genl_msg_prepare_usr_msg(OPLUS_SLA_CMD_UPLINK, size, - oplus_sla_netlink_pid, &skbuff); - - if (ret) { - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, msg_type, payload, payload_len); - - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - /* send data */ - ret = genlmsg_unicast(&init_net, skbuff, oplus_sla_netlink_pid); - - if (ret < 0) { - printk(KERN_ERR - "oplus_connectivity_sla: oplus_sla_send_to_user, can not unicast skbuff, ret = %d\n", ret); - return -1; - } - - return 0; -} - -static int oplus_sla_set_android_pid(struct sk_buff *skb) -{ - /*apps_monitor_netlink_pid = NETLINK_CB(skb).portid;*/ - struct nlmsghdr *nlhdr = nlmsg_hdr(skb); - oplus_sla_netlink_pid = nlhdr->nlmsg_pid; - debug("oplus_sla_set_android_pid oplus_sla_netlink_pid=%d\n", - oplus_sla_netlink_pid); - return 0; -} - -static int oplus_sla_iface_changed(struct nlattr *nla) -{ - int index = -1; - int up = 0; - char *p; - struct oplus_dev_info *node = NULL; - u32 mark = 0x0; - - int *data = (int *)NLA_DATA(nla); - index = data[0]; - up = data[1]; - p = (char *)(data + 2); - debug("oplus_sla_iface_changed index:%d, up:%d, ifname:%s\n", - index, up, p); - - if (index >= 0 && index < IFACE_NUM) { - if (up) { - sla_write_lock(); - oplus_sla_info[index].if_up = 0; - - if (index == MAIN_WLAN) { - mark = MAIN_WLAN_MARK; - oplus_sla_info[MAIN_WLAN].if_up = 1; - - } else if (index == SECOND_WLAN) { - mark = SECOND_WLAN_MARK; - oplus_sla_info[SECOND_WLAN].if_up = 1; - - } else if (index == CELL_INDEX) { - mark = CELL_MARK; - oplus_sla_info[CELL_INDEX].if_up = 1; - } - - if (p) { - node = &oplus_sla_info[index]; - node->mark = mark; - memcpy(node->dev_name, p, IFACE_LEN); - debug("ifname = %s,ifup = %d\n", node->dev_name, node->if_up); - } - - sla_write_unlock(); - - } else { - sla_write_lock(); - memset(&oplus_sla_info[index], 0x0, sizeof(struct oplus_dev_info)); - sla_write_unlock(); - } - } - - return 0; -} - -static int oplus_sla_set_white_list_app_uid(struct nlattr *nla) -{ - u32 *info = (u32 *)NLA_DATA(nla); - memset(&white_app_list, 0x0, sizeof(struct oplus_white_app_info)); - white_app_list.count = info[0]; - - if (white_app_list.count > 0 && white_app_list.count < WHITE_APP_NUM) { - int i; - - for (i = 0; i < white_app_list.count; i++) { - white_app_list.uid[i] = info[i + 1]; - debug("oplus_sla_set_white_list_app_uid count=%d, uid[%d]=%d\n", - white_app_list.count, i, white_app_list.uid[i]); - } - } - - return 0; -} - -static int oplus_sla_set_dual_wifi_app_uid(struct nlattr *nla) -{ - u32 *info = (u32 *)NLA_DATA(nla); - memset(&dual_wifi_app_list, 0x0, sizeof(struct oplus_dual_sta_info)); - dual_wifi_app_list.count = info[0]; - - if (dual_wifi_app_list.count > 0 - && dual_wifi_app_list.count < DUAL_STA_APP_NUM) { - int i; - - for (i = 0; i < dual_wifi_app_list.count; i++) { - dual_wifi_app_list.uid[i] = info[i + 1]; - debug("set_dual_wifi_app_uid count=%d, uid[%d]=%d\n", - dual_wifi_app_list.count, i, dual_wifi_app_list.uid[i]); - } - } - - return 0; -} - -static int oplus_sla_set_game_app_uid(struct nlattr *nla) -{ - u32 *uidInfo = (u32 *)NLA_DATA(nla); - u32 index = uidInfo[0]; - u32 uid = uidInfo[1]; - - sla_game_write_lock(); - if (index < GAME_NUM) { - game_info[index].uid = uid; - game_info[index].game_type = index; - game_info[index].mark = MAIN_WLAN_MARK; - debug("oplus_sla_set_game_app_uid:index=%d uid=%d\n", index, uid); - } - sla_game_write_unlock(); - - return 0; -} - -static void init_game_info(void) -{ - int i = 0; - - sla_game_write_lock(); - for(i = 1; i < GAME_NUM; i++){ - game_info[i].mark = MAIN_WLAN_MARK; - } - sla_game_write_unlock(); - if(oplus_sla_debug){ - debug("oplus_sla:init_game_online_info\n"); - } -} - -static int oplus_sla_change_game_network(struct nlattr *nla) -{ - u32 *data = (u32 *)NLA_DATA(nla); - u32 game_index = data[0]; - u32 network_index = data[1]; - int game_feed_back[2]; - - sla_game_write_lock(); - if (CELL_INDEX == network_index) { - game_info[game_index].mark = CELL_MARK; - - } else if (WLAN0_INDEX == network_index) { - game_info[game_index].mark = MAIN_WLAN_MARK; - } - sla_game_write_unlock(); - - game_feed_back[0] = game_index; - game_feed_back[1] = network_index; - oplus_sla_send_to_user(OPLUS_SLA_GAME_NETWORK_CHANGED_EVENT, - (char *)game_feed_back, sizeof(game_feed_back)); - debug("game_index = %d network_index = %d \n", game_index, network_index); - return 0; -} - -static int oplus_sla_set_video_app_uid(struct nlattr *nla) -{ - u32 *info = (u32 *)NLA_DATA(nla); - memset(&video_app_list, 0x0, sizeof(struct oplus_dual_sta_info)); - video_app_list.count = info[0]; - - if (video_app_list.count > 0 && video_app_list.count < DUAL_STA_APP_NUM) { - int i; - - for (i = 0; i < video_app_list.count; i++) { - video_app_list.uid[i] = info[i + 1]; - debug("video_app_list count=%d, uid[%d]=%d\n", - video_app_list.count, i, video_app_list.uid[i]); - } - } - - return 0; -} - -static int oplus_sla_enable(struct nlattr *nla) -{ - int *data = (int *)NLA_DATA(nla); - int enable_type = data[0]; - - sla_write_lock(); - - oplus_sla_enable_status = 1; - sla_work_mode = enable_type; - - debug("oplus_sla_enable: enable type = %d\n", enable_type); - oplus_sla_send_to_user(OPLUS_SLA_ENABLED_EVENT, (char *)&enable_type, - sizeof(int)); - - sla_write_unlock(); - return 0; -} - -static int oplus_sla_disable(struct nlattr *nla) -{ - int disable_type = 0; - - int *data = (int *)NLA_DATA(nla); - disable_type = data[0]; - - debug("type[%d] disable,oplus_sla_enable_status[%d],work_mode[%d]\n", - disable_type, oplus_sla_enable_status, sla_work_mode); - - init_game_info(); - sla_write_lock(); - - if (oplus_sla_enable_status && disable_type) { - if (disable_type == sla_work_mode) { - oplus_sla_enable_status = 0; - sla_work_mode = SLA_MODE_INIT; - debug("type[%d] disabled\n", disable_type); - } - - dns_network = 0; - video_app_network = 0; - oplus_sla_send_to_user(OPLUS_SLA_DISABLED_EVENT, (char *)&disable_type, - sizeof(int)); - } - sla_write_unlock(); - return 0; -} - -static int oplus_sla_update_weight(struct nlattr *nla) -{ - int *weight = (int *)NLA_DATA(nla); - sla_write_lock(); - oplus_sla_info[0].weight = weight[0]; - oplus_sla_info[1].weight = weight[1]; - oplus_sla_info[2].weight = weight[2]; - debug("weight: %u:%u:%u\n", oplus_sla_info[0].weight, oplus_sla_info[1].weight, - oplus_sla_info[2].weight); - sla_write_unlock(); - return 0; -} - -static int oplus_sla_change_default_network(struct nlattr *nla) -{ - oplus_sla_def_net = *(u32 *)NLA_DATA(nla); - debug("oplus_sla_change_default_network = %d\n", oplus_sla_def_net); - return 0; -} - -static int oplus_sla_set_kernel_debug(struct nlattr *nla) -{ - oplus_sla_debug = *(u32 *)NLA_DATA(nla); - debug("oplus_sla_set_kernel_debug = %d\n", oplus_sla_debug); - return 0; -} - -static int oplus_sla_change_vpn_state(struct nlattr *nla) -{ - oplus_sla_vpn_connected = *(u32 *)NLA_DATA(nla); - debug("oplus_sla_vpn_connected = %d\n", oplus_sla_vpn_connected); - return 0; -} - -static int oplus_sla_change_video_app_network(struct nlattr *nla) -{ - video_app_network = *(u32 *)NLA_DATA(nla); - debug("video_app_network = %d\n", video_app_network); - return 0; -} - -static int oplus_sla_change_dns_network(struct nlattr *nla) -{ - dns_network = *(u32 *)NLA_DATA(nla); - debug("dns_network = %d\n", dns_network); - return 0; -} - -static int oplus_sla_genl_nlmsg_handle(struct sk_buff *skb, - struct genl_info *info) -{ - int ret = 0; - struct nlmsghdr *nlhdr; - struct genlmsghdr *genlhdr; - struct nlattr *nla; - - nlhdr = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlhdr); - nla = genlmsg_data(genlhdr); - - if (oplus_sla_debug) { - debug("oplus_sla_genl_nlmsg_handle, the nla->nla_type = %u, len = %u\n", - nla->nla_type, nla->nla_len); - } - - switch (nla->nla_type) { - case OPLUS_SLA_CMD_SET_ANDROID_PID: - ret = oplus_sla_set_android_pid(skb); - break; - - case OPLUS_SLA_CMD_IFACE_CHANGED: - ret = oplus_sla_iface_changed(nla); - break; - - case OPLUS_SLA_CMD_ENABLE: - ret = oplus_sla_enable(nla); - break; - - case OPLUS_SLA_CMD_DISABLE: - ret = oplus_sla_disable(nla); - break; - - case OPLUS_SLA_CMD_SET_WHITE_LIST_APP: - ret = oplus_sla_set_white_list_app_uid(nla); - break; - - case OPLUS_SLA_CMD_SET_DUAL_STA_LIST_APP: - ret = oplus_sla_set_dual_wifi_app_uid(nla); - break; - - case OPLUS_SLA_CMD_SET_VIDEO_LIST_APP: - ret = oplus_sla_set_video_app_uid(nla); - break; - - case OPLUS_SLA_CMD_SET_GAME_LIST_APP: - ret = oplus_sla_set_game_app_uid(nla); - break; - - case OPLUS_SLA_CMD_CHANGE_GAME_NETWORK: - ret = oplus_sla_change_game_network(nla); - break; - - case OPLUS_SLA_CMD_UPDATE_WEIGHT: - ret = oplus_sla_update_weight(nla); - break; - - case OPLUS_SLA_CMD_CHANGE_DEFAULT_NETWORK: - ret = oplus_sla_change_default_network(nla); - break; - - case OPLUS_SLA_CMD_SET_KERNEL_DEBUG: - ret = oplus_sla_set_kernel_debug(nla); - break; - - case OPLUS_SLA_CMD_CHANGE_VPN_STATE: - ret = oplus_sla_change_vpn_state(nla); - break; - - case OPLUS_SLA_CMD_CHANGE_VIDEO_APP_NETWORK: - ret = oplus_sla_change_video_app_network(nla); - break; - - case OPLUS_SLA_CMD_CHANGE_DNS_NETWORK: - ret = oplus_sla_change_dns_network(nla); - break; - - default: - break; - } - - return ret; -} - -static unsigned int oplus_sla_input_hook(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - handle_timestamp_error_case(skb, state); - return NF_ACCEPT; -} - -static struct nf_hook_ops oplus_sla_ops[] __read_mostly = { - { - .hook = oplus_sla_output_hook, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_OUT, - //must be here,for dns packet will do DNAT at mangle table with skb->mark - .priority = NF_IP_PRI_CONNTRACK + 1, - }, - { - .hook = oplus_sla_input_hook, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER + 1, - }, -}; - -static struct ctl_table oplus_sla_sysctl_table[] = { - { - .procname = "oplus_sla_enable", - .data = &oplus_sla_enable_status, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_sla_debug", - .data = &oplus_sla_debug, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_sla_vpn_connected", - .data = &oplus_sla_vpn_connected, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "game_mark", - .data = &game_mark, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { } -}; - -static int oplus_sla_sysctl_init(void) -{ - oplus_sla_table_hrd = register_net_sysctl(&init_net, "net/oplus_sla", - oplus_sla_sysctl_table); - return oplus_sla_table_hrd == NULL ? -ENOMEM : 0; -} - - -static int oplus_sla_genl_init(void) -{ - int ret; - ret = genl_register_family(&oplus_sla_genl_family); - - if (ret) { - debug("genl_register_family:%s error,ret = %d\n", OPLUS_SLA_FAMILY, ret); - return ret; - - } else { - debug("genl_register_family complete, id = %d!\n", oplus_sla_genl_family.id); - } - - return 0; -} - -static void oplus_sla_genl_fini(void) -{ - - genl_unregister_family(&oplus_sla_genl_family); -} - -static int __init oplus_sla_init(void) -{ - int ret = 0; - rwlock_init(&sla_lock); - rwlock_init(&sla_game_lock); - - ret = oplus_sla_genl_init(); - - if (ret < 0) { - debug(" module can not init sla netlink.\n"); - } - - ret |= oplus_sla_sysctl_init(); - ret |= nf_register_net_hooks(&init_net, oplus_sla_ops, - ARRAY_SIZE(oplus_sla_ops)); - - debug(" enter.\n"); - return ret; -} - -static void __exit oplus_sla_exit(void) -{ - debug(" exit.\n"); - oplus_sla_genl_fini(); - - if (oplus_sla_table_hrd) { - unregister_net_sysctl_table(oplus_sla_table_hrd); - } - - nf_unregister_net_hooks(&init_net, oplus_sla_ops, ARRAY_SIZE(oplus_sla_ops)); -} - -module_init(oplus_sla_init); -module_exit(oplus_sla_exit); -MODULE_LICENSE("GPL v2"); diff --git a/net/oplus_modules/Kconfig b/net/oplus_modules/Kconfig deleted file mode 100755 index 3f633af2b745..000000000000 --- a/net/oplus_modules/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ShiQianhua@NETWORK.DATA.1816043, 2021/08/09, add for dns hook. -source "net/oplus_modules/oplus_dns_hook/Kconfig" - -#ShiQianhua@NETWORK.DATA.2360276, 2021/11/02 add for kernel stats -source "net/oplus_modules/oplus_stats_calc/Kconfig" - -#yangzhaoji@NETWORK.DATA.2534809, 2022/01/19, Add for qr scan scene -source "net/oplus_modules/oplus_qr_scan/Kconfig" diff --git a/net/oplus_modules/Makefile b/net/oplus_modules/Makefile deleted file mode 100755 index c036c3f84c7d..000000000000 --- a/net/oplus_modules/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -#ifdef OPLUS_FEATURE_DNS_HOOK -#ShiQianhua@NETWORK.DATA.1816043, 2021/08/09, add for dns hook. -obj-$(CONFIG_OPLUS_FEATURE_DNS_HOOK) += oplus_dns_hook/ -#endif /* OPLUS_FEATURE_DNS_HOOK */ - -#ifdef OPLUS_FEATURE_STATS_CALC -#ShiQianhua@NETWORK.DATA.2360276, 2021/11/02 add for kernel stats -obj-$(CONFIG_OPLUS_FEATURE_STATS_CALC) += oplus_stats_calc/ -#endif /* OPLUS_FEATURE_STATS_CALC */ - -#ifdef OPLUS_FEATURE_QR_SCAN -#yangzhaoji@NETWORK.DATA.2534809, 2022/01/19, Add for qr scan scene -obj-$(CONFIG_OPLUS_FEATURE_QR_SCAN) += oplus_qr_scan/ -#endif /* OPLUS_FEATURE_QR_SCAN */ diff --git a/net/oplus_modules/oplus_dns_hook/Kconfig b/net/oplus_modules/oplus_dns_hook/Kconfig deleted file mode 100644 index 3b4a8609fdd2..000000000000 --- a/net/oplus_modules/oplus_dns_hook/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# PDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. - -config OPLUS_FEATURE_DNS_HOOK - tristate "Add for quick app support dns hook" - help - Add for quick app support dns hook diff --git a/net/oplus_modules/oplus_dns_hook/Makefile b/net/oplus_modules/oplus_dns_hook/Makefile deleted file mode 100644 index a144d04825d5..000000000000 --- a/net/oplus_modules/oplus_dns_hook/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# -# Add for kernel data info send to user space. -# -obj-$(CONFIG_OPLUS_FEATURE_DNS_HOOK) += oplus_dns_hook.o diff --git a/net/oplus_modules/oplus_dns_hook/oplus_dns_hook.c b/net/oplus_modules/oplus_dns_hook/oplus_dns_hook.c deleted file mode 100755 index e570782d3346..000000000000 --- a/net/oplus_modules/oplus_dns_hook/oplus_dns_hook.c +++ /dev/null @@ -1,834 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2021, oplus Mobile Comm Corp., Ltd. -** File: oplus_dns_hook.c -** Description: Add dns hook for quick app. -** -** Version: 1.0 -** Date : 2021/8/13 -** Author: ShiQianhua -** -** ------------------ Revision History:------------------------ -** -** shiqianhua 2021/8/13 1.0 build this module -****************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define LOG_TAG "oplus_dns_hook" - -#define DNS_DST_PORT 53 - -#define MAX_DNS_HOOK_SIZE 20 -#define MAX_QUERY_SIZE 10 -#define MAX_ANSWER_SIZE 20 - -#define MAX_URL_LEN 127 - -#define DNS_TYPE_CNAME 5 -#define DNS_TYPE_A 1 - -#define DNS_IPV4_LEN 4 -#define QUERY_MATCH_EXTEND 5 - -#pragma pack(1) -typedef struct { - uint32_t inuse; - char url[MAX_URL_LEN + 1]; - uint32_t addr; -} dns_hook_data_t; - -static int s_debug = 0; -static uint32_t s_dns_hook_enable = 1; -static uint32_t s_user_pid = 0; -static spinlock_t s_dns_hook_lock; - -static uint32_t s_dns_hook_count = 0; -static dns_hook_data_t s_hook_addrs[MAX_DNS_HOOK_SIZE]; - -static int s_first_notify = 0; - -typedef struct { - uint16_t id; - uint16_t flag; - uint16_t queryCount; - uint16_t ansCount; - uint16_t nsCount; - uint16_t arCount; -} dnshdr_t; - -typedef struct { - uint16_t offset; - uint16_t pad; - uint32_t addr; -} query_info_t; - -typedef struct { - uint16_t name; - uint16_t type; - uint16_t class; - uint32_t ttl; - uint16_t dataLen; -} ans_item_hdr_t; - -#define IPV4_ANSWER_ITEM_LEN (sizeof(ans_item_hdr_t) + sizeof(uint32_t)) - -#define DNS_RSP_FLAG 0x8000 -#define DNS_RD_FLAG 0x0100 -#define DNS_RA_FLAG 0x0080 - -static struct ctl_table_header *oplus_dns_hook_table_hdr = NULL; - -#define LOGK(flag, fmt, args...) \ - do { \ - if (flag || s_debug) { \ - printk("[%s]:" fmt "\n", LOG_TAG, ##args);\ - } \ - } while (0) - -static int send_first_dns_event(char *hostname); - -static int check_dns_package(struct sk_buff *skb, int is_ingress) -{ - struct iphdr *iph = NULL; - struct ipv6hdr *ipv6h = NULL; - struct udphdr *udph = NULL; - - if (skb->protocol == htons(ETH_P_IP)) { - iph = ip_hdr(skb); - if (!iph) { - return -1; - } - if (iph->protocol != IPPROTO_UDP) { - return -1; - } - } else if (skb->protocol == htons(ETH_P_IPV6)) { - ipv6h = ipv6_hdr(skb); - if (!ipv6h) { - return -1; - } - if (ipv6h->nexthdr != IPPROTO_UDP) { - return -1; - } - } else { - return -1; - } - - udph = udp_hdr(skb); - if (!udph) { - return -1; - } - if (is_ingress) { - if (udph->source != htons(DNS_DST_PORT)) { - return -1; - } - } else { - if (udph->dest != htons(DNS_DST_PORT)) { - return -1; - } - } - - return 0; -} - -static int parse_querys(char *start, int *querys_len, query_info_t *queryList, uint16_t query_size, int *match_count, int hook) -{ - int matchSize = 0; - int offset = 0; - int i = 0; - int j = 0; - int notify_flag = 0; - char notify_url[MAX_URL_LEN + 1] = {0}; - - spin_lock(&s_dns_hook_lock); - for (i = 0; i < query_size; i++) { - char tmpurl[MAX_URL_LEN + 1] = {0}; - uint8_t len = 0; - uint8_t tmpLen = 0; - size_t urlLen = strlen(start + offset + 1); - if (urlLen > MAX_URL_LEN) { - LOGK(1, "url %s len %lu over %d\n", start + offset + 1, urlLen, MAX_URL_LEN); - offset += (urlLen + 2 + 4); - continue; - } - strcpy(tmpurl, start + offset + 1); - - tmpLen = *(start + offset); - // LOGK(1, "tmpurl %s strlen:%u, tmpLen:%d", tmpurl, strlen(tmpurl), tmpLen); - do { - if (tmpLen > (urlLen - len)) { - LOGK(1, "len invalid! %d-%lu-%d", tmpLen, urlLen, len); - spin_unlock(&s_dns_hook_lock); - return -1; - } - len += tmpLen; - tmpLen = *(tmpurl + len); - if (*(tmpurl + len) != 0) { - *(tmpurl + len) = '.'; - } - len += 1; - // LOGK(1, "tmlen:%d, len:%d", tmpLen, len); - } while (tmpLen != 0); - LOGK(0, "tmpurl %s len:%d", tmpurl, len); - for (j = 0; j < MAX_DNS_HOOK_SIZE; j++) { - if (s_hook_addrs[j].inuse) { - if (strcmp(tmpurl, s_hook_addrs[j].url) == 0) { - queryList->offset = offset + sizeof(dnshdr_t); - queryList->addr = s_hook_addrs[j].addr; - LOGK(1, "hook %d parse_querys match %d-%d-%s-%u", hook, i, j, tmpurl, queryList->addr); - queryList += 1; - matchSize++; - if (s_first_notify == 0) { - notify_flag = 1; - strncpy(notify_url, tmpurl, MAX_URL_LEN); - s_first_notify = 1; - } - } - } - } - offset += urlLen + 2 + 4; - } - spin_unlock(&s_dns_hook_lock); - - if (notify_flag) { - send_first_dns_event(notify_url); - } - - *match_count = matchSize; - *querys_len = offset; - return 0; -} - -static struct sk_buff *gen_dns_rsp(struct sk_buff *skb, int query_len, query_info_t *query, int match_count) -{ - struct iphdr *iph = NULL; - struct ipv6hdr *ipv6h = NULL; - struct sk_buff *skb_rsp = NULL; - struct udphdr *udph_rsp = NULL; - dnshdr_t *dnshdr = NULL; - int leftpayload = 0; - int i = 0; - int answer_len = 0; - char *ans_buf = NULL; - int ret = 0; - - answer_len = match_count * IPV4_ANSWER_ITEM_LEN; - ans_buf = kmalloc(answer_len, GFP_ATOMIC); - if (ans_buf == NULL) { - LOGK(1, "1 malloc len %d failed", answer_len); - return NULL; - } - - for (i = 0; i < match_count; i++) { - ans_item_hdr_t *hdr = (ans_item_hdr_t *)(ans_buf + IPV4_ANSWER_ITEM_LEN * i); - hdr->name = ntohs(0xC000 | query[i].offset); - hdr->type = ntohs(0x1); - hdr->class = ntohs(0x1); - hdr->ttl = ntohl(0xff); - hdr->dataLen = ntohs(sizeof(uint32_t)); - memcpy((char *)(hdr + 1), &query[i].addr, sizeof(uint32_t)); - LOGK(0, "set url add to buf %u", query[i].addr); - } - skb_rsp = skb_copy_expand(skb, skb_headroom(skb), skb_tailroom(skb) + answer_len, GFP_ATOMIC); - if (skb_rsp == NULL) { - kfree(ans_buf); - LOGK(1, "skb_copy_expand failed! size: %u", answer_len); - return NULL; - } - __skb_put_data(skb_rsp, ans_buf, answer_len); - - // update ip - skb_set_mac_header(skb_rsp, 0); - if (skb_rsp->protocol == htons(ETH_P_IP)) { - __be32 tmp = 0; - iph = ip_hdr(skb_rsp); - tmp = iph->saddr; - iph->saddr = iph->daddr; - iph->daddr = tmp; - iph->tot_len = htons(ntohs(iph->tot_len) + answer_len); - ip_send_check(iph); - } else { - struct in6_addr tmp; - ipv6h = ipv6_hdr(skb_rsp); - tmp = ipv6h->saddr; - ipv6h->saddr = ipv6h->daddr; - ipv6h->daddr = tmp; - ipv6h->payload_len = htons(ntohs(ipv6h->payload_len) + answer_len); - } - // update udp - udph_rsp = udp_hdr(skb_rsp); - udph_rsp->dest = udph_rsp->source; - udph_rsp->source = htons(DNS_DST_PORT); - udph_rsp->len = htons(ntohs(udph_rsp->len) + answer_len); - udph_rsp->check = 0; - leftpayload = ntohs(udph_rsp->len) - sizeof(struct udphdr) - sizeof(dnshdr_t) - query_len - answer_len; - LOGK(0, "udplen: %d, leftpayload value %d, queryLen:%d", ntohs(udph_rsp->len), leftpayload, query_len); - // update answer - dnshdr = (dnshdr_t *)(skb_transport_header(skb_rsp) + sizeof(struct udphdr)); - dnshdr->flag = htons(DNS_RSP_FLAG | DNS_RD_FLAG | DNS_RA_FLAG); - dnshdr->ansCount = htons(match_count); - dnshdr->nsCount = 0; - dnshdr->arCount = 0; - - if (leftpayload != 0) { - char *left_buf = NULL; - left_buf = kmalloc(leftpayload, GFP_ATOMIC); - if (left_buf == NULL) { - LOGK(1, "malloc len %d failed", leftpayload); - kfree_skb(skb_rsp); - kfree(ans_buf); - return NULL; - } - ret = skb_copy_bits(skb_rsp, skb_transport_offset(skb_rsp) + sizeof(struct udphdr) + sizeof(dnshdr_t) + query_len, left_buf, leftpayload); - if (ret) { - LOGK(1, "skb_copy_bits failed! %d", ret); - kfree_skb(skb_rsp); - kfree(left_buf); - kfree(ans_buf); - return NULL; - } - ret = skb_store_bits(skb_rsp, skb_transport_offset(skb_rsp) + sizeof(struct udphdr) + sizeof(dnshdr_t) + query_len, ans_buf, answer_len); - if (ret) { - LOGK(1, "skb_store_bits 1 failed! %d", ret); - kfree_skb(skb_rsp); - kfree(left_buf); - kfree(ans_buf); - return NULL; - } - ret = skb_store_bits(skb_rsp, skb_transport_offset(skb_rsp) + sizeof(struct udphdr) + sizeof(dnshdr_t) + query_len + answer_len, left_buf, - leftpayload); - if (ret) { - LOGK(1, "skb_store_bits 2 failed! %d", ret); - kfree_skb(skb_rsp); - kfree(left_buf); - kfree(ans_buf); - return NULL; - } - kfree(left_buf); - } - kfree(ans_buf); - if (skb_rsp->protocol == htons(ETH_P_IP)) { - skb_rsp->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr, skb_rsp->len - ip_hdrlen(skb), IPPROTO_UDP, 0); - udph_rsp->check = __skb_checksum_complete(skb_rsp); - } else { - // uint16_t frag_off = 0; - // int hdrlen = 0; - // u8 nexthdr = 0; - // hdrlen = ipv6_skip_exthdr(skb_rsp, sizeof(struct ipv6hdr), &nexthdr, &frag_off); - // skb_rsp->csum = ~csum_unfold(csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb_rsp->len - hdrlen, - // IPPROTO_UDP, csum_sub(0, skb_checksum(skb, 0, hdrlen, 0)))); udph_rsp->check = - // __skb_checksum_complete(skb_rsp); - } - //skb_dump(KERN_WARNING, skb, false); - //skb_dump(KERN_WARNING, skb_rsp, false); - - return skb_rsp; -} - -static int dns_hook_process_postrouting(struct sk_buff *skb, int hook, const struct nf_hook_state *state) -{ - dnshdr_t *dnshdr = NULL; - query_info_t *query_list = NULL; - struct sk_buff *rsp_skb = NULL; - uint16_t query_count = 0; - int query_len = 0; - int match_count = 0; - int ret = 0; - - if (!s_dns_hook_enable) { - return -1; - } - if (check_dns_package(skb, 0)) { - return -1; - } - - dnshdr = (dnshdr_t *)(skb_transport_header(skb) + sizeof(struct udphdr)); - query_count = ntohs(dnshdr->queryCount); - LOGK(0, "output query_count: %u", query_count); - if (query_count == 0 || query_count > MAX_QUERY_SIZE) { - return -1; - } - LOGK(0, "output malloc size %lu", sizeof(query_info_t) * query_count); - query_list = kmalloc(sizeof(query_info_t) * query_count, GFP_ATOMIC); - if (query_list == NULL) { - return -1; - } - ret = parse_querys((char *)(dnshdr + 1), &query_len, query_list, query_count, &match_count, hook); - if (ret) { - kfree(query_list); - return -1; - } - - if (match_count == 0) { - kfree(query_list); - return -1; - } - LOGK(0, "skb_output return package! match_count %d", match_count); - rsp_skb = gen_dns_rsp(skb, query_len, query_list, match_count); - kfree(query_list); - if (!rsp_skb) { - return -1; - } - - nf_ct_attach(rsp_skb, skb); - if (skb->protocol == htons(ETH_P_IP)) { - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (ip_route_me_harder(state->net, state->sk, rsp_skb, RTN_UNSPEC)) { - #else - if (ip_route_me_harder(state->net, rsp_skb, RTN_UNSPEC)) { - #endif - LOGK(1, "ip_route_me_harder error"); - kfree_skb(rsp_skb); - return -1; - } - ret = ip_local_out(state->net, state->sk, rsp_skb); - LOGK(0, "ip_local_out return %d", ret); - } else if(skb->protocol == htons(ETH_P_IPV6)) { - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)) - if (ip6_route_me_harder(state->net, state->sk, rsp_skb)) { - #else - if (ip6_route_me_harder(state->net, rsp_skb)) { - #endif - LOGK(1, "ip6_route_me_harder error"); - kfree_skb(rsp_skb); - return -1; - } - ret = ip6_local_out(state->net, state->sk, rsp_skb); - LOGK(0, "ip6_local_out return %d", ret); - } - - return 0; -} - -static unsigned int oplus_dns_hook_output_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - if (dns_hook_process_postrouting(skb, state->hook, state) == 0) { - kfree_skb(skb); - return NF_STOLEN; - } - return NF_ACCEPT; -} - -static struct nf_hook_ops oplus_dns_hook_netfilter_ops[] __read_mostly = { - { - .hook = oplus_dns_hook_output_hook, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_OUT, - .priority = NF_IP_PRI_FILTER + 1, - }, - { - .hook = oplus_dns_hook_output_hook, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_OUT, - .priority = NF_IP_PRI_FILTER + 1, - }, -}; - -enum oplus_dns_hook_msg_type_e { - OPLUS_DNS_HOOK_MSG_UNSPEC, - OPLUS_DNS_HOOK_MSG_ENABLE, - OPLUS_DNS_HOOK_MSG_ADD_URL, - OPLUS_DNS_HOOK_MSG_DEL_URL, - OPLUS_DNS_HOOK_MSG_CLEAR_URL, - OPLUS_DNS_HOOK_MSG_FIRST_NOTIFY, - __OPLUS_DNS_HOOK_MSG_MAX, -}; -#define OPLUS_DNS_HOOK_MSG_MAX (__OPLUS_DNS_HOOK_MSG_MAX - 1) - -enum oplus_dns_hook_cmd_type_e { - OPLUS_DNS_HOOK_CMD_UNSPEC, - OPLUS_DNS_HOOK_CMD_SET, - OPLUS_DNS_HOOK_CMD_NOTIFY, - OPLUS_DNS_HOOK_CMD_MAX, -}; - -#define OPLUS_DNS_HOOK_CMD_MAX (OPLUS_DNS_HOOK_CMD_MAX - 1) - -#define OPLUS_DNS_HOOK_FAMILY_NAME "dns_hook" -#define OPLUS_DNS_HOOK_FAMILY_VERSION 1 - -#define OPLUS_NLA_DATA(na) ((char *)((char *)(na) + NLA_HDRLEN)) - - - -static int dns_hook_set_enable(struct nlattr *nla) -{ - uint32_t *data = (uint32_t *)OPLUS_NLA_DATA(nla); - if (s_dns_hook_enable != data[0]) { - s_dns_hook_enable = data[0]; - LOGK(1, "set enable value %d", s_dns_hook_enable); - } - return 0; -} - -static int add_dns_hook_url(struct nlattr *nla) -{ - uint32_t *addr = NULL; - uint8_t *data = (uint8_t *)OPLUS_NLA_DATA(nla); - uint8_t len = data[0]; - int i = 0; - int firstNotSetIndex = -1; - int is_modify = 0; - int ret = 0; - - if (len > MAX_URL_LEN || ntohs(nla->nla_len) < (5 + len)) { - return -EINVAL; - } - - addr = (uint32_t *)(data + len + 1); - spin_lock(&s_dns_hook_lock); - for (i = 0; i < MAX_DNS_HOOK_SIZE; i++) { - if (s_hook_addrs[i].inuse) { - if (strncmp(data + 1, s_hook_addrs[i].url, len) == 0) { - s_hook_addrs[i].addr = ntohl(*addr); - LOGK(1, "update url %s %u", s_hook_addrs[i].url, s_hook_addrs[i].addr); - is_modify = 1; - break; - } - } else { - if (firstNotSetIndex == -1) { - firstNotSetIndex = i; - } - } - } - - if (!is_modify) { - if (firstNotSetIndex != -1) { - strncpy(s_hook_addrs[firstNotSetIndex].url, (data + 1), len); - s_hook_addrs[firstNotSetIndex].addr = ntohl(*addr); - s_hook_addrs[firstNotSetIndex].inuse = 1; - s_dns_hook_count++; - LOGK(1, "add url %s %u", s_hook_addrs[firstNotSetIndex].url, s_hook_addrs[firstNotSetIndex].addr); - } else { - char tmp_url[MAX_URL_LEN + 1] = {0}; - strncpy(tmp_url, (data + 1), len); - LOGK(1, "no more place to set url %s", tmp_url); - ret = -EOVERFLOW; - } - } - spin_unlock(&s_dns_hook_lock); - - return ret; -} - -static int del_dns_hook_url(struct nlattr *nla) -{ - uint8_t *data = (uint8_t *)OPLUS_NLA_DATA(nla); - uint8_t len = data[0]; - int i = 0; - int del = 0; - - if (len > MAX_URL_LEN || ntohs(nla->nla_len) < len) { - return -EINVAL; - } - - spin_lock(&s_dns_hook_lock); - for (i = 0; i < MAX_DNS_HOOK_SIZE; i++) { - if (s_hook_addrs[i].inuse) { - if (strncmp(data + 1, s_hook_addrs[i].url, len) == 0) { - LOGK(1, "del url %s %u", s_hook_addrs[i].url, s_hook_addrs[i].addr); - memset(&s_hook_addrs[i], 0, sizeof(dns_hook_data_t)); - s_hook_addrs[i].inuse = 0; - s_dns_hook_count--; - del = 1; - } - } - } - spin_unlock(&s_dns_hook_lock); - - if (del == 0) { - return ENOENT; - } - return 0; -} - -static int clear_dns_hook_url(struct nlattr *nla) -{ - int i = 0; - - spin_lock(&s_dns_hook_lock); - for (i = 0; i < MAX_DNS_HOOK_SIZE; i++) { - if (s_hook_addrs[i].inuse) { - LOGK(1, "clear url %s %u", s_hook_addrs[i].url, s_hook_addrs[i].addr); - memset(&s_hook_addrs[i], 0, sizeof(dns_hook_data_t)); - s_hook_addrs[i].inuse = 0; - } - } - s_dns_hook_count = 0; - spin_unlock(&s_dns_hook_lock); - return 0; -} - -static int oplus_dns_hook_netlink_rcv_msg(struct sk_buff *skb, struct genl_info *info) -{ - int ret = 0; - struct nlmsghdr *nlhdr; - struct genlmsghdr *genlhdr; - struct nlattr *nla; - - nlhdr = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlhdr); - nla = genlmsg_data(genlhdr); - - LOGK(0, "set s_user_pid=%u type=%u len=%u.", nlhdr->nlmsg_pid, nla->nla_type, nla->nla_len); - if (s_user_pid == 0) { - s_user_pid = nlhdr->nlmsg_pid; - } else if (s_user_pid != nlhdr->nlmsg_pid) { - LOGK(1, "user pid changed!! %u - %u", s_user_pid, nlhdr->nlmsg_pid); - s_user_pid = nlhdr->nlmsg_pid; - } - - switch (nla->nla_type) { - case OPLUS_DNS_HOOK_MSG_ENABLE: - ret = dns_hook_set_enable(nla); - break; - case OPLUS_DNS_HOOK_MSG_ADD_URL: - ret = add_dns_hook_url(nla); - break; - case OPLUS_DNS_HOOK_MSG_DEL_URL: - ret = del_dns_hook_url(nla); - break; - case OPLUS_DNS_HOOK_MSG_CLEAR_URL: - ret = clear_dns_hook_url(nla); - break; - default: - return -EINVAL; - } - return ret; -} - -static const struct genl_ops oplus_dns_hook_genl_ops[] = { - { - .cmd = OPLUS_DNS_HOOK_CMD_SET, - .flags = 0, - .doit = oplus_dns_hook_netlink_rcv_msg, - .dumpit = NULL, - }, -}; - -static struct genl_family oplus_dns_hook_genl_family = { - .id = 0, - .hdrsize = 0, - .name = OPLUS_DNS_HOOK_FAMILY_NAME, - .version = OPLUS_DNS_HOOK_FAMILY_VERSION, - .maxattr = OPLUS_DNS_HOOK_MSG_MAX, - .ops = oplus_dns_hook_genl_ops, - .n_ops = ARRAY_SIZE(oplus_dns_hook_genl_ops), -}; - -static inline int genl_msg_prepare_usr_msg(u8 cmd, size_t size, pid_t pid, - struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_ATOMIC); - - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_dns_hook_genl_family, 0, cmd); - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, int len) -{ - int ret; - - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - - -static int send_netlink_data(int type, char *data, int len) -{ - int ret = 0; - void * head; - struct sk_buff *skbuff; - size_t size; - - if (!s_user_pid) { - LOGK(1, "send_netlink_data,oplus_score_user_pid=0\n"); - return -1; - } - - /* allocate new buffer cache */ - size = nla_total_size(len); - ret = genl_msg_prepare_usr_msg(OPLUS_DNS_HOOK_CMD_NOTIFY, size, s_user_pid, &skbuff); - if (ret) { - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, type, data, len); - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - /* send data */ - ret = genlmsg_unicast(&init_net, skbuff, s_user_pid); - if (ret < 0) { - LOGK(1, "genlmsg_unicast return error, ret = %d\n", ret); - return -1; - } - return 0; -} - - -static int send_first_dns_event(char *hostname) -{ - uint32_t len = 0; - char *data = NULL; - int ret = 0; - uint32_t nameLen = 0; - - LOGK(1, "send_first_dns_event %s", hostname); - len = sizeof(uint32_t) + strlen(hostname) + 1; - data = kmalloc(len, GFP_ATOMIC); - if (data == NULL) { - LOGK(1, "malloc failed %u", len); - return -1; - } - - memset(data, 0, len); - nameLen = strlen(hostname); - memcpy(data, &nameLen, sizeof(uint32_t)); - strcpy(data + sizeof(uint32_t), hostname); - ret = send_netlink_data(OPLUS_DNS_HOOK_MSG_FIRST_NOTIFY, data, len - 1); - kfree(data); - LOGK(1, "send_netlink_data return %d", ret); - - return ret; -} - - -static int oplus_dns_hook_netlink_init(void) -{ - int ret; - ret = genl_register_family(&oplus_dns_hook_genl_family); - if (ret) { - LOGK(1, "genl_register_family:%s failed,ret = %d\n", OPLUS_DNS_HOOK_FAMILY_NAME, ret); - return ret; - } else { - LOGK(1, "genl_register_family complete, id = %d!\n", oplus_dns_hook_genl_family.id); - } - - return 0; -} - -static void oplus_dns_hook_netlink_exit(void) { genl_unregister_family(&oplus_dns_hook_genl_family); } - -static struct ctl_table oplus_net_hook_sysctl_table[] = { - { - .procname = "debug", - .data = &s_debug, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "enable", - .data = &s_dns_hook_enable, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "hook_count", - .data = &s_dns_hook_count, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "first_notify", - .data = &s_first_notify, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - {} -}; - -static int oplus_dns_hook_sysctl_init(void) -{ - oplus_dns_hook_table_hdr = register_net_sysctl(&init_net, "net/oplus_dns_hook", oplus_net_hook_sysctl_table); - return oplus_dns_hook_table_hdr == NULL ? -ENOMEM : 0; -} - -static int __init oplus_dns_hook_init(void) -{ - int ret = 0; - - memset(s_hook_addrs, 0, sizeof(s_hook_addrs)); - spin_lock_init(&s_dns_hook_lock); - - ret = oplus_dns_hook_netlink_init(); - if (ret < 0) { - LOGK(1, "init module failed to init netlink, ret =%d", ret); - return ret; - } else { - LOGK(1, "init module init netlink successfully."); - } - - ret = nf_register_net_hooks(&init_net, oplus_dns_hook_netfilter_ops, ARRAY_SIZE(oplus_dns_hook_netfilter_ops)); - if (ret < 0) { - LOGK(1, "oplus_dns_hook_init netfilter register failed, ret=%d", ret); - oplus_dns_hook_netlink_exit(); - return ret; - } else { - LOGK(1, "oplus_dns_hook_init netfilter register successfully."); - } - - oplus_dns_hook_sysctl_init(); - return ret; -} - -static void __exit oplus_dns_hook_fini(void) -{ - LOGK(1, "oplus_dns_hook_fini."); - oplus_dns_hook_netlink_exit(); - nf_unregister_net_hooks(&init_net, oplus_dns_hook_netfilter_ops, ARRAY_SIZE(oplus_dns_hook_netfilter_ops)); - if (oplus_dns_hook_table_hdr) { - unregister_net_sysctl_table(oplus_dns_hook_table_hdr); - } -} - -MODULE_LICENSE("GPL"); -module_init(oplus_dns_hook_init); -module_exit(oplus_dns_hook_fini); - diff --git a/net/oplus_modules/oplus_qr_scan/Kconfig b/net/oplus_modules/oplus_qr_scan/Kconfig deleted file mode 100755 index a324b4dc83cd..000000000000 --- a/net/oplus_modules/oplus_qr_scan/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. - -config OPLUS_FEATURE_QR_SCAN - tristate "Add for qr scan" - help - Add for Add for tqr scan. diff --git a/net/oplus_modules/oplus_qr_scan/Makefile b/net/oplus_modules/oplus_qr_scan/Makefile deleted file mode 100755 index 83fdb89df85e..000000000000 --- a/net/oplus_modules/oplus_qr_scan/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# -# Add for kernel data info send to user space. -# -obj-$(CONFIG_OPLUS_FEATURE_QR_SCAN) += oplus_qr_scan.o - diff --git a/net/oplus_modules/oplus_qr_scan/oplus_qr_scan.c b/net/oplus_modules/oplus_qr_scan/oplus_qr_scan.c deleted file mode 100755 index e5c3bbdc4654..000000000000 --- a/net/oplus_modules/oplus_qr_scan/oplus_qr_scan.c +++ /dev/null @@ -1,657 +0,0 @@ -/************************************************************************************ -** File: - oplus_qr.c -** Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd -** -** Description: -** 1. Add for QR scan -** -** Version: 1.0 -** Date : 2022-01-19 -** Author: yangzhaoji@NETWORK.DATA -** TAG : OPLUS_FEATURE_QR_SCAN -** -** ---------------------Revision History: --------------------- -** -** --------------------------------------------------------------- -** -************************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define LOG_TAG "OPLUS_FEATURE_QR_SCAN" -#define _FAMILY_VERSION 1 -#define OPLUS_QR_FAMILY_NAME "qr_scan" -#define NETLINK_OPLUS_QR_CMD_MAX (__NETLINK_OPLUS_QR_CMD_MAX - 1) -#define QR_MONITOR_FAMILY_VERSION 1 -#define QR_MONITOR_FAMILY "qr_monitor" -#define NLA_DATA(na) ((char *)((char*)(na) + NLA_HDRLEN)) -#define GENL_ID_GENERATE 0 -#define QR_SCAN_MSG_MAX (__QR_SCAN_MSG_MAX - 1) - -enum { - QR_SCAN_MSG_UNDEFINE, - QR_SET_ANDROID_PID, - QR_SCAN_SET_PARAM, - QR_SCAN_DETECTED, - QR_SCAN_NO_CONTENT, - QR_SCAN_NO_FOUND, - QR_SCAN_POST_SUCCESS, - QR_SCAN_BAD_GATEWAY, - __QR_SCAN_MSG_MAX, -}; - -/*tcp dst and source*/ -struct qr_ipv4_package_info { - int ipv4_source; - int ipv4_dst; - int ipv4_saddr; - int ipv4_daddr; -}; - -struct qr_ipv6_package_info { - int ipv6_source; - int ipv6_dst; - struct in6_addr ipv6_saddr; - struct in6_addr ipv6_daddr; -}; - -/*AP pass qr uid*/ -static u32 qr_uid = 0; -/*qr package info,such as port and address*/ -static struct qr_ipv4_package_info qr_ipv4_infos; -static struct qr_ipv6_package_info qr_ipv6_infos; -/*AP control if need to check tcp*/ -static bool ap_control_need_check = false; -/*portid of android netlink socket*/ -static u32 oplus_qr_netlink_pid; - -enum { - NETLINK_OPLUS_QR_CMD_UNSPEC, - NETLINK_OPLUS_QR_HOOKS, - __NETLINK_OPLUS_QR_CMD_MAX -}; - -static int qr_monitor_netlink_nlmsg_handle(struct sk_buff *skb, struct genl_info *info); -static const struct genl_ops qr_monitor_genl_ops[] = { - { - .cmd = NETLINK_OPLUS_QR_HOOKS, - .flags = 0, - .doit = qr_monitor_netlink_nlmsg_handle, - .dumpit = NULL, - }, -}; - -static struct genl_family qr_monitor_genl_family = { - .id = 0, - .hdrsize = 0, - .name = QR_MONITOR_FAMILY, - .version = QR_MONITOR_FAMILY_VERSION, - .maxattr = QR_SCAN_MSG_MAX, - .ops = qr_monitor_genl_ops, - .n_ops = ARRAY_SIZE(qr_monitor_genl_ops), -}; - -static inline int qr_genl_msg_prepare_usr_msg(u8 cmd, size_t size, pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_KERNEL); - if (skb == NULL) { - return -ENOMEM; - } - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &qr_monitor_genl_family, 0, cmd); - *skbp = skb; - return 0; -} - -static inline int qr_genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, int len) -{ - int ret; - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - return 0; -} - -/* send to user space */ -static int oplus_qr_hooks_send_to_user(int msg_type, char *payload, int payload_len) -{ - int ret = 0; - void * head; - struct sk_buff *skbuff; - size_t size; - - if (!oplus_qr_netlink_pid) { - printk("oplus_qr_monitor: qr_monitor_netlink_send_to_user, can not unicast skbuff, oplus_qr_netlink_pid=0\n"); - return -1; - } - - /*allocate new buffer cache */ - size = nla_total_size(payload_len); - ret = qr_genl_msg_prepare_usr_msg(NETLINK_OPLUS_QR_HOOKS, size, oplus_qr_netlink_pid, &skbuff); - if (ret) { - return ret; - } - - ret = qr_genl_msg_mk_usr_msg(skbuff, msg_type, payload, payload_len); - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - /* send data */ - ret = genlmsg_unicast(&init_net, skbuff, oplus_qr_netlink_pid); - if (ret < 0) { - printk(KERN_ERR "oplus_qr_monitor: qr_monitor_netlink_send_to_user, can not unicast skbuff, ret = %d,android_pid pid=%d\n", ret, oplus_qr_netlink_pid); - return -1; - } - - printk(" qr_monitor_netlink_send_to_user, skb_len=%u,android_pid pid=%d", skbuff->len, oplus_qr_netlink_pid); - - return 0; -} - -/*to check if tcp uid is the qr sk*/ -static bool oplus_match_qr_uid_skb(struct sock *sk) -{ - kuid_t check_uid; - kuid_t sk_uid; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - const struct file *filp = NULL; -#endif - - if (NULL == sk || !sk_fullsock(sk) || NULL == sk->sk_socket) { - return false; - } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - filp = sk->sk_socket->file; - if (NULL == filp) { - return false; - } - sk_uid = filp->f_cred->fsuid; -#else - sk_uid = sk->sk_uid; -#endif - check_uid = make_kuid(&init_user_ns, qr_uid); - if (uid_eq(sk_uid, check_uid)) { - return true; - } - - return false; -} - -/*to record qr tcp info*/ -static void oplus_record_qr_ipv4_skb_info(int source, int dst, int saddr, int daddr) -{ - if ((qr_ipv4_infos.ipv4_source) || (qr_ipv4_infos.ipv4_dst) || (qr_ipv4_infos.ipv4_saddr) || (qr_ipv4_infos.ipv4_daddr)) { - return; - } - - qr_ipv4_infos.ipv4_source = source; - qr_ipv4_infos.ipv4_dst = dst; - qr_ipv4_infos.ipv4_saddr = saddr; - qr_ipv4_infos.ipv4_daddr = daddr; -} - -static void oplus_record_qr_ipv6_skb_info(int source, int dst, struct in6_addr saddr, struct in6_addr daddr) -{ - if ((qr_ipv6_infos.ipv6_source) || (qr_ipv6_infos.ipv6_dst)) { - return; - } - - if ((!ipv6_addr_any(&(qr_ipv6_infos.ipv6_saddr))) && (!ipv6_addr_any(&(qr_ipv6_infos.ipv6_daddr)))) { - return; - } - - qr_ipv6_infos.ipv6_source = source; - qr_ipv6_infos.ipv6_dst = dst; - qr_ipv6_infos.ipv6_saddr = saddr; - qr_ipv6_infos.ipv6_daddr = daddr; -} - -/*to check qr tcp info*/ -static bool oplus_check_qr_ipv4_skb_info(int source, int dst, int saddr, int daddr) -{ - if ((!qr_ipv4_infos.ipv4_source) || (!qr_ipv4_infos.ipv4_dst) || (!qr_ipv4_infos.ipv4_saddr) || (!qr_ipv4_infos.ipv4_daddr)) { - return false; - } - if ((source == qr_ipv4_infos.ipv4_source) && (dst == qr_ipv4_infos.ipv4_dst) && (saddr = qr_ipv4_infos.ipv4_saddr) && (daddr = qr_ipv4_infos.ipv4_daddr)) { - return true; - } - - return false; -} - -static bool oplus_check_qr_ipv6_skb_info(int source, int dst, struct in6_addr saddr, struct in6_addr daddr) -{ - if ((!qr_ipv6_infos.ipv6_source) || (!qr_ipv6_infos.ipv6_dst)) { - return false; - } - - if ((ipv6_addr_any(&(qr_ipv6_infos.ipv6_saddr))) || (ipv6_addr_any(&(qr_ipv6_infos.ipv6_daddr)))) { - return false; - } - - if ((source == qr_ipv6_infos.ipv6_source) && (dst == qr_ipv6_infos.ipv6_dst) - && (ipv6_addr_equal(&(qr_ipv6_infos.ipv6_saddr), &saddr)) && (ipv6_addr_equal(&(qr_ipv6_infos.ipv6_daddr), &daddr))) { - return true; - } - - return false; -} - -/*filter the skb about qr send*/ -static unsigned int oplus_filter_qr_v4_send_skb(void *p, struct sk_buff *skb, const struct nf_hook_state *s) -{ - struct iphdr *iph = NULL; - struct tcphdr *tcph = NULL; - u32 header_len; - char *userdata = NULL; - u16 tot_len; - int length = 0; - int ipv4_qr_source = 0; - int ipv4_qr_dst = 0; - int ipv4_qr_saddr = 0; - int ipv4_qr_daddr = 0; - - struct sock *sk = skb_to_full_sk(skb); - - if (sk == NULL) { - return NF_ACCEPT; - } - - /*confirm qr doing scan now and this skb is the qr uid*/ - if ((!oplus_match_qr_uid_skb(sk)) || (!ap_control_need_check)) { - return NF_ACCEPT; - } - - /*get the skb userdata*/ - if ((iph = ip_hdr(skb)) != NULL && iph->protocol == IPPROTO_TCP) { - tot_len = ntohs(iph->tot_len); - - if (unlikely(skb_linearize(skb))) { - return NF_ACCEPT; - } - iph = ip_hdr(skb); - tcph = tcp_hdr(skb); - header_len = iph->ihl * 4 + tcph->doff * 4; - userdata = (char *)(skb->data + header_len); - length = skb->len-iph->ihl*4-tcph->doff*4; - ipv4_qr_source = ntohs(tcph->source); - ipv4_qr_dst = ntohs(tcph->dest); - ipv4_qr_saddr = ntohs(iph->saddr); - ipv4_qr_daddr = ntohs(iph->daddr); - } - - if (userdata == NULL) { - return NF_ACCEPT; - } - - /*qr has send tcpv4 scan package*/ - if (strstr(userdata, "POST /mmtls/") != NULL) { - oplus_record_qr_ipv4_skb_info(ipv4_qr_source, ipv4_qr_dst, ipv4_qr_saddr, ipv4_qr_daddr); - oplus_qr_hooks_send_to_user(QR_SCAN_POST_SUCCESS, NULL, 0); - } - - return NF_ACCEPT; -} - -/*filter the skb about qr receive*/ -static unsigned int oplus_filter_qr_v4_receive_skb(void *p, struct sk_buff *skb, const struct nf_hook_state *s) -{ - struct iphdr *iph = NULL; - struct tcphdr *tcph = NULL; - u32 header_len; - char *userdata = NULL; - u16 tot_len; - int length = 0; - int ipv4_qr_source = 0; - int ipv4_qr_dst = 0; - int ipv4_qr_saddr = 0; - int ipv4_qr_daddr = 0; - struct sock *sk = skb_to_full_sk(skb); - if (sk == NULL) { - return NF_ACCEPT; - } - - if ((!oplus_match_qr_uid_skb(sk)) || (!ap_control_need_check)) { - return NF_ACCEPT; - } - - if ((iph = ip_hdr(skb)) != NULL && iph->protocol == IPPROTO_TCP) { - tot_len = ntohs(iph->tot_len); - - if (unlikely(skb_linearize(skb))) { - return NF_ACCEPT; - } - iph = ip_hdr(skb); - tcph = tcp_hdr(skb); - header_len = iph->ihl * 4 + tcph->doff * 4; - userdata = (char *)(skb->data + header_len); - length = skb->len-iph->ihl*4-tcph->doff*4; - ipv4_qr_source = ntohs(tcph->source); - ipv4_qr_dst = ntohs(tcph->dest); - ipv4_qr_saddr = ntohs(iph->saddr); - ipv4_qr_daddr = ntohs(iph->daddr); - } - - if (userdata == NULL) { - return NF_ACCEPT; - } - - if (strstr(userdata, "204 No Content") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_NO_CONTENT, NULL, 0); - printk("qr 204 No Content"); - return NF_ACCEPT; - } - - if (strstr(userdata, "Bad Gateway") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_BAD_GATEWAY, NULL, 0); - printk("qr Bad Gateway"); - return NF_ACCEPT; - } - - if (strstr(userdata, "Not Found") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_NO_FOUND, NULL, 0); - printk("qr Not Found"); - return NF_ACCEPT; - } - - if (!oplus_check_qr_ipv4_skb_info(ipv4_qr_dst, ipv4_qr_source, ipv4_qr_daddr, ipv4_qr_saddr)) { - return NF_ACCEPT; - } - - /*qr has received tcpv4 scan success package*/ - if (strstr(userdata, "200 OK")!= NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_DETECTED, NULL, 0); - } - - return NF_ACCEPT; -} - - -static unsigned int oplus_filter_qr_v6_send_skb(void *p, struct sk_buff *skb, const struct nf_hook_state *s) -{ - struct ipv6hdr *ipv6h = NULL; - struct tcphdr *tcph = NULL; - - u32 header_len; - __be16 fo = 0; - u8 ip_proto; - int ihl = 0; - char *userdata = NULL; - u16 tot_len; - int ipv6_qr_source = 0; - int ipv6_qr_dst = 0; - struct sock *sk = skb_to_full_sk(skb); - if (sk == NULL) { - return NF_ACCEPT; - } - if ((!oplus_match_qr_uid_skb(sk)) || (!ap_control_need_check)) { - return NF_ACCEPT; - } - - if (skb->protocol == htons(ETH_P_IPV6) && (ipv6h = ipv6_hdr(skb)) != NULL - && ipv6h->nexthdr == NEXTHDR_TCP) { - tot_len = ntohs(ipv6h->payload_len); - ip_proto = ipv6h->nexthdr; - if (unlikely(skb_linearize(skb))) { - return NF_ACCEPT; - } - ihl = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &ip_proto, &fo); /*ipv6 header length*/ - tcph = tcp_hdr(skb); - if (NULL == tcph) { - return NF_ACCEPT; - } - ipv6h = ipv6_hdr(skb); - header_len = ihl + tcph->doff * 4; /*total length of ipv6 header and tcp header*/ - userdata = (unsigned char *)(skb->data + header_len); /*tcp payload buffer*/ - ipv6_qr_source = ntohs(tcph->source); - ipv6_qr_dst = ntohs(tcph->dest); - } - - if (userdata == NULL) { - return NF_ACCEPT; - } - - /*QR has send tcpv6 scan package*/ - if (strstr(userdata, "POST /mmtls/") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_POST_SUCCESS, NULL, 0); - oplus_record_qr_ipv6_skb_info(ipv6_qr_source, ipv6_qr_dst, ipv6h->saddr, ipv6h->daddr); - } - - return NF_ACCEPT; -} - -static unsigned int oplus_filter_qr_v6_receive_skb(void *p, struct sk_buff *skb, const struct nf_hook_state *s) -{ - struct ipv6hdr *ipv6h = NULL; - struct tcphdr *tcph = NULL; - u32 header_len; - __be16 fo = 0; - u8 ip_proto; - int ihl = 0; - int ipv6_qr_source = 0; - int ipv6_qr_dst = 0; - char *userdata = NULL; - u16 tot_len; - struct sock *sk = skb_to_full_sk(skb); - if (sk == NULL) { - return NF_ACCEPT; - } - - if ((!oplus_match_qr_uid_skb(sk)) || (!ap_control_need_check)) { - return NF_ACCEPT; - } - - if (skb->protocol == htons(ETH_P_IPV6) && (ipv6h = ipv6_hdr(skb)) != NULL - && ipv6h->nexthdr == NEXTHDR_TCP) { - tot_len = ntohs(ipv6h->payload_len); - ip_proto = ipv6h->nexthdr; - if (unlikely(skb_linearize(skb))) { - return NF_ACCEPT; - } - ihl = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &ip_proto, &fo); /*ipv6 header length*/ - tcph = tcp_hdr(skb); - if (NULL == tcph) { - return NF_ACCEPT; - } - ipv6h = ipv6_hdr(skb); - header_len = ihl + tcph->doff * 4; /*total length of ipv6 header and tcp header*/ - userdata = (unsigned char *)(skb->data + header_len); /*tcp payload buffer*/ - ipv6_qr_source = ntohs(tcph->source); - ipv6_qr_dst = ntohs(tcph->dest); - } - - if (userdata == NULL) { - return NF_ACCEPT; - } - - if (strstr(userdata, "204 No Content") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_NO_CONTENT, NULL, 0); - printk("qr 204 No Content"); - return NF_ACCEPT; - } - - if (strstr(userdata, "Bad Gateway") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_BAD_GATEWAY, NULL, 0); - printk("qr Bad Gateway"); - return NF_ACCEPT; - } - - if (strstr(userdata, "Not Found") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_NO_FOUND, NULL, 0); - printk("qr Not Found"); - return NF_ACCEPT; - } - - if (!oplus_check_qr_ipv6_skb_info(ipv6_qr_dst, ipv6_qr_source, ipv6h->daddr, ipv6h->saddr)) { - printk("oplus_filter_qr_v6_receive_skb info not match"); - return NF_ACCEPT; - } - - if(strstr(userdata, "200 OK") != NULL) { - oplus_qr_hooks_send_to_user(QR_SCAN_DETECTED, NULL, 0); - } - - return NF_ACCEPT; -} - -/*regist a hook function*/ -static struct nf_hook_ops filter_qr_skb[] __read_mostly = { - { - .hook = oplus_filter_qr_v4_send_skb, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_OUT, - .priority = NF_IP_PRI_FILTER+2, - }, - - { - .hook = oplus_filter_qr_v6_send_skb, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_OUT, - .priority = NF_IP_PRI_FILTER+2, - }, - - { - .hook = oplus_filter_qr_v4_receive_skb, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER+2, - }, - - { - .hook = oplus_filter_qr_v6_receive_skb, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER+2, - }, -}; - -static void oplus_qr_hooks_set_qr_param(struct nlattr *nla) -{ - u32 *data = (u32 *)NLA_DATA(nla); - qr_uid = data[0]; - ap_control_need_check = data[1]; - if (!ap_control_need_check) { - qr_ipv6_infos.ipv6_source = 0; - qr_ipv6_infos.ipv6_dst = 0; - qr_ipv4_infos.ipv4_source = 0; - qr_ipv4_infos.ipv4_dst = 0; - ipv6_addr_set(&(qr_ipv6_infos.ipv6_saddr), 0, 0, 0, 0); - ipv6_addr_set(&(qr_ipv6_infos.ipv6_daddr), 0, 0, 0, 0); - qr_ipv4_infos.ipv4_saddr = 0; - qr_ipv4_infos.ipv4_daddr = 0; - } -} - -static int oplus_qr_hooks_set_android_pid(struct sk_buff *skb) -{ - struct nlmsghdr *nlhdr = nlmsg_hdr(skb); - oplus_qr_netlink_pid = nlhdr->nlmsg_pid; - printk("oplus_qr_hooks_set_android_pid pid=%d\n", oplus_qr_netlink_pid); - return 0; -} - -/*receive ap data*/ -static int qr_monitor_netlink_nlmsg_handle(struct sk_buff *skb, struct genl_info *info) -{ - int ret = 0; - struct nlmsghdr *nlhdr; - struct genlmsghdr *genlhdr; - struct nlattr *nla; - - nlhdr = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlhdr); - nla = genlmsg_data(genlhdr); - - switch (nla->nla_type) { - case QR_SET_ANDROID_PID: - ret = oplus_qr_hooks_set_android_pid(skb); - break; - case QR_SCAN_SET_PARAM: - oplus_qr_hooks_set_qr_param(nla); - break; - default: - return -EINVAL; - } - - return ret; -} - -static int oplus_qr_hooks_netlink_init(void) -{ - int ret; - ret = genl_register_family(&qr_monitor_genl_family); - if (ret) { - printk("[QR_MONITOR]:genl_register_family:%s error,ret = %d\n", OPLUS_QR_FAMILY_NAME, ret); - return ret; - } else { - printk("[QR_MONITOR]:genl_register_family complete, id = %d!\n", qr_monitor_genl_family.id); - } - - return 0; -} - -static void oplus_qr_hooks_netlink_exit(void) -{ - genl_unregister_family(&qr_monitor_genl_family); -} - -static int __init oplus_qr_hook_init(void) -{ - int ret = 0; - printk("oplus qr hook init"); - ret = oplus_qr_hooks_netlink_init(); - if (ret < 0) { - printk("qr init netlink fail"); - return ret; - } else { - printk("qr module register netfilter ops successfully.\n"); - } - ret = nf_register_net_hooks(&init_net, filter_qr_skb, ARRAY_SIZE(filter_qr_skb)); - if (ret < 0) { - printk("oplus_qr_init netfilter register failed, ret=%d\n", ret); - oplus_qr_hooks_netlink_exit(); - return ret; - } else { - printk("oplus_qr_init netfilter register successfully.\n"); - } - return 0; -} - -static void __exit oplus_qr_hook_fini(void) -{ - oplus_qr_hooks_netlink_exit(); - nf_unregister_net_hooks(&init_net, filter_qr_skb, ARRAY_SIZE(filter_qr_skb)); - printk("nf_hook_fini."); -} - -MODULE_LICENSE("GPL"); -module_init(oplus_qr_hook_init); -module_exit(oplus_qr_hook_fini); diff --git a/net/oplus_modules/oplus_stats_calc/Kconfig b/net/oplus_modules/oplus_stats_calc/Kconfig deleted file mode 100644 index d6b331577adb..000000000000 --- a/net/oplus_modules/oplus_stats_calc/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. - -config OPLUS_FEATURE_STATS_CALC - tristate "Add for iface uid stats" - help - Add for iface uid stats. diff --git a/net/oplus_modules/oplus_stats_calc/Makefile b/net/oplus_modules/oplus_stats_calc/Makefile deleted file mode 100644 index 054796d88623..000000000000 --- a/net/oplus_modules/oplus_stats_calc/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# -# Add for kernel data info send to user space. -# -obj-$(CONFIG_OPLUS_FEATURE_STATS_CALC) += oplus_stats_calc.o diff --git a/net/oplus_modules/oplus_stats_calc/oplus_stats_calc.c b/net/oplus_modules/oplus_stats_calc/oplus_stats_calc.c deleted file mode 100755 index 0a2188c920fb..000000000000 --- a/net/oplus_modules/oplus_stats_calc/oplus_stats_calc.c +++ /dev/null @@ -1,442 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG_TAG "oplus_stats_calc" - -static int s_debug = 1; - -#define LOGK(flag, fmt, args...) \ - do { \ - if (flag || s_debug) { \ - printk("[%s]:" fmt "\n", LOG_TAG, ##args);\ - } \ - } while (0) - -static spinlock_t s_stats_calc_lock; -static DEFINE_HASHTABLE(s_iface_uid_stats_map, 8); - -static u32 s_user_pid = 0; -static u32 s_stats_count = 0; - -static struct genl_family oplus_stats_calc_genl_family; - -enum stats_calc_type_et { - OPLUS_STATS_CALC_MSG_UNSPEC, - OPLUS_STATS_CALC_MSG_GET_ALL, - __OPLUS_STATS_CALC_MSG_MAX, -}; - -#define OPLUS_STATS_CALC_MSG_MAX (__OPLUS_STATS_CALC_MSG_MAX - 1) - -enum stats_calc_cmd_type_et { - OPLUS_STATS_CALC_CMD_UNSPEC, - OPLUS_STATS_CALC_CMD_DOWN, - OPLUS_STATS_CALC_CMD_UP, - __OPLUS_STATS_CALC_CMD_MAX, -}; - -#define OPLUS_STATS_CALC_CMD_MAX (__OPLUS_STATS_CALC_CMD_MAX - 1) - - -#define OPLUS_STATS_CALC_FAMILY_NAME "oplus_stats" -#define OPLUS_STATS_CALC_FAMILY_VERSION 1 - -#pragma pack (4) -struct iface_uid_stats_value { - char iface[IFNAMSIZ]; - u32 uid; - u64 rxBytes; - u64 txBytes; - u64 rxPackets; - u64 txPackets; -}; -#pragma pack () - -struct iface_uid_stats { - struct hlist_node node; - struct iface_uid_stats_value value; -}; - -static u64 getHashKey(char *iface, u32 uid) { - u32 crc = crc32(0, iface, strlen(iface)); - u64 result = ((u64)crc) << 32 | uid; - return result; -} - -static struct iface_uid_stats * get_stats_from_map(char *iface, u32 uid, u64 key) { - struct hlist_node *pos = NULL; - struct hlist_node *next = NULL; - struct iface_uid_stats *stats = NULL; - - struct hlist_head *t = &(s_iface_uid_stats_map[hash_min(key, HASH_BITS(s_iface_uid_stats_map))]); - hlist_for_each_safe(pos, next, t) { - stats = container_of(pos, struct iface_uid_stats, node); - if(strcmp(stats->value.iface, iface) == 0 && uid == stats->value.uid) { - return stats; - } - } - return NULL; -} - -static int add_iface_uid_stats(char *iface, u32 uid, u32 len, int dir) { - u64 key = 0; - struct iface_uid_stats *stats = NULL; - - key = getHashKey(iface, uid); - spin_lock_bh(&s_stats_calc_lock); - stats = get_stats_from_map(iface, uid, key); - - if (stats == NULL) { - stats = kmalloc(sizeof(struct iface_uid_stats), GFP_ATOMIC); - if (stats == NULL) { - spin_unlock_bh(&s_stats_calc_lock); - return -1; - } - memset(stats, 0, sizeof(struct iface_uid_stats)); - INIT_HLIST_NODE(&(stats->node)); - strcpy(stats->value.iface, iface); - stats->value.uid = uid; - if(dir == 1) { - stats->value.rxBytes = len; - stats->value.rxPackets = 1; - }else{ - stats->value.txBytes = len; - stats->value.txPackets = 1; - } - hash_add(s_iface_uid_stats_map, &(stats->node), key); - s_stats_count++; - LOGK(1, "add_iface_uid_stats add iface %s", iface); - }else{ - if(dir == 1) { - stats->value.rxBytes += len; - stats->value.rxPackets += 1; - }else{ - stats->value.txBytes += len; - stats->value.txPackets += 1; - } - } - spin_unlock_bh(&s_stats_calc_lock); - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, int len) -{ - int ret; - - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - -static inline int genl_msg_prepare_usr_msg(u8 cmd, size_t size, pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_ATOMIC); - - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_stats_calc_genl_family, 0, cmd); - LOGK(1, "genl_msg_prepare_usr_msg_1,skb_len=%u,pid=%u,cmd=%u,id=%u\n", - skb->len, (unsigned int)pid, cmd, oplus_stats_calc_genl_family.id); - *skbp = skb; - return 0; -} - -static int send_netlink_data(int type, char *data, int len) { - int ret = 0; - void * head; - struct sk_buff *skbuff; - size_t size; - - if (!s_user_pid) { - LOGK(1, "send_netlink_data,oplus_score_user_pid=0\n"); - return -1; - } - - /* allocate new buffer cache */ - size = nla_total_size(len); - ret = genl_msg_prepare_usr_msg(OPLUS_STATS_CALC_CMD_UP, size, s_user_pid, &skbuff); - if (ret) { - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, type, data, len); - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - /* send data */ - ret = genlmsg_unicast(&init_net, skbuff, s_user_pid); - if(ret < 0) { - LOGK(1,"genlmsg_unicast return error, ret = %d\n", ret); - return -1; - } - return 0; -} - -static int send_all_stats(struct nlattr *nla) { - char *data = NULL; - int total_len = 0; - struct iface_uid_stats_value *pvalue = NULL; - struct iface_uid_stats *pos = NULL; - struct hlist_node *next = NULL; - int count = 0; - int pkt = 0; - int ret = 0; - - LOGK(1, "send_stats_to_user %u", s_stats_count); - spin_lock_bh(&s_stats_calc_lock); - total_len = sizeof(s_stats_count) + sizeof(struct iface_uid_stats_value) * s_stats_count; - data = kmalloc(total_len, GFP_ATOMIC); - if (data == NULL) { - spin_unlock_bh(&s_stats_calc_lock); - return -1; - } - memset(data, 0, total_len); - if (s_stats_count != 0) { - pvalue = (struct iface_uid_stats_value *)(data + sizeof(u32)); - hash_for_each_safe(s_iface_uid_stats_map, pkt, next, pos, node) { - if (count < s_stats_count) { - memcpy(pvalue, &pos->value, sizeof(struct iface_uid_stats_value)); - pvalue++; - count++; - } - } - } - LOGK(1, "get data count %d %u", count, s_stats_count); - memcpy(data, &count, sizeof(count)); - spin_unlock_bh(&s_stats_calc_lock); - ret = send_netlink_data(OPLUS_STATS_CALC_MSG_GET_ALL, data, total_len); - LOGK(1, "send_netlink_data return %d", ret); - if (data) { - kfree(data); - } - return 0; -} - -static int get_sock_uid(struct sk_buff *skb) { - struct sock *sk = sk_to_full_sk(skb->sk); - kuid_t kuid; - - if (!sk || !sk_fullsock(sk)) - return overflowuid; - kuid = sock_net_uid(sock_net(sk), sk); - return from_kuid_munged(sock_net(sk)->user_ns, kuid); -} - -static unsigned int oplus_stats_calc_input_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - u32 uid = 0; - - if (skb->dev == NULL) { - LOGK(0, "dev is null %d", skb->skb_iif); - return NF_ACCEPT; - } - uid = get_sock_uid(skb); - add_iface_uid_stats(skb->dev->name, uid, skb->len, 1); - return NF_ACCEPT; -} - -static unsigned int oplus_stats_calc_output_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - u32 uid = 0; - - if (skb->dev == NULL) { - LOGK(0, "dev is null %d", skb->skb_iif); - return NF_ACCEPT; - } - uid = get_sock_uid(skb); - add_iface_uid_stats(skb->dev->name, uid, skb->len, 0); - return NF_ACCEPT; -} - -static struct nf_hook_ops oplus_stats_calc_netfilter_ops[] __read_mostly = { - { - .hook = oplus_stats_calc_input_hook, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER + 1, - }, - { - .hook = oplus_stats_calc_output_hook, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP_PRI_FILTER + 1, - }, -}; - -static int oplus_stats_calc_netlink_rcv_msg(struct sk_buff *skb, struct genl_info *info) -{ - int ret = 0; - struct nlmsghdr *nlhdr; - struct genlmsghdr *genlhdr; - struct nlattr *nla; - - nlhdr = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlhdr); - nla = genlmsg_data(genlhdr); - - LOGK(0, "set s_user_pid=%u type=%u len=%u.", nlhdr->nlmsg_pid, nla->nla_type, nla->nla_len); - if (s_user_pid == 0) { - s_user_pid = nlhdr->nlmsg_pid; - } else if (s_user_pid != nlhdr->nlmsg_pid) { - LOGK(1, "user pid changed!! %u - %u", s_user_pid, nlhdr->nlmsg_pid); - s_user_pid = nlhdr->nlmsg_pid; - } - LOGK(1, "nla->nla_type %d", nla->nla_type); - - switch (nla->nla_type) { - case OPLUS_STATS_CALC_MSG_GET_ALL: - ret = send_all_stats(nla); - LOGK(0, "send_all_stats return %d", ret); - break; - default: - return -EINVAL; - } - return ret; -} - -static const struct genl_ops oplus_stats_calc_genl_ops[] = { - { - .cmd = OPLUS_STATS_CALC_CMD_DOWN, - .flags = 0, - .doit = oplus_stats_calc_netlink_rcv_msg, - .dumpit = NULL, - }, -}; - -static struct genl_family oplus_stats_calc_genl_family = { - .id = 0, - .hdrsize = 0, - .name = OPLUS_STATS_CALC_FAMILY_NAME, - .version = OPLUS_STATS_CALC_FAMILY_VERSION, - .maxattr = OPLUS_STATS_CALC_CMD_UP + 1, - .ops = oplus_stats_calc_genl_ops, - .n_ops = ARRAY_SIZE(oplus_stats_calc_genl_ops), -}; - -static int oplus_stats_calc_netlink_init(void) -{ - int ret; - ret = genl_register_family(&oplus_stats_calc_genl_family); - if (ret) { - LOGK(1, "genl_register_family:%s failed,ret = %d\n", OPLUS_STATS_CALC_FAMILY_NAME, ret); - return ret; - } else { - LOGK(1, "genl_register_family complete, id = %d!\n", oplus_stats_calc_genl_family.id); - } - - return 0; -} - - -static void oplus_stats_calc_netlink_exit(void) -{ - genl_unregister_family(&oplus_stats_calc_genl_family); -} - -static struct ctl_table oplus_net_hook_sysctl_table[] = { - { - .procname = "debug", - .data = &s_debug, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "count", - .data = &s_stats_count, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - {} -}; - - -static struct ctl_table_header *oplus_stats_calc_table_hdr = NULL; - -static int oplus_stats_calc_sysctl_init(void) -{ - oplus_stats_calc_table_hdr = register_net_sysctl(&init_net, "net/oplus_stats_calc", oplus_net_hook_sysctl_table); - return oplus_stats_calc_table_hdr == NULL ? -ENOMEM : 0; -} - -static int __init oplus_stats_calc_init(void) -{ - int ret = 0; - - spin_lock_init(&s_stats_calc_lock); - - ret = oplus_stats_calc_netlink_init(); - if (ret < 0) { - LOGK(1, "init module failed to init netlink, ret =%d", ret); - return ret; - } else { - LOGK(1, "init module init netlink successfully."); - } - - ret = nf_register_net_hooks(&init_net, oplus_stats_calc_netfilter_ops, ARRAY_SIZE(oplus_stats_calc_netfilter_ops)); - if (ret < 0) { - LOGK(1, "oplus_stats_calc_init netfilter register failed, ret=%d", ret); - oplus_stats_calc_netlink_exit(); - return ret; - } else { - LOGK(1, "oplus_stats_calc_init netfilter register successfully."); - } - - oplus_stats_calc_sysctl_init(); - return ret; -} - -static void __exit oplus_stats_calc_fini(void) -{ - LOGK(1, "oplus_stats_fini."); - oplus_stats_calc_netlink_exit(); - nf_unregister_net_hooks(&init_net, oplus_stats_calc_netfilter_ops, ARRAY_SIZE(oplus_stats_calc_netfilter_ops)); - if (oplus_stats_calc_table_hdr) { - unregister_net_sysctl_table(oplus_stats_calc_table_hdr); - } -} - -MODULE_LICENSE("GPL"); -module_init(oplus_stats_calc_init); -module_exit(oplus_stats_calc_fini); - diff --git a/net/oplus_nwpower/Makefile b/net/oplus_nwpower/Makefile deleted file mode 100755 index 308a7bcfb063..000000000000 --- a/net/oplus_nwpower/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2018-2020 Oplus. All rights reserved. - -obj-y += oplus_nwpower.o diff --git a/net/oplus_nwpower/oplus_nwpower.c b/net/oplus_nwpower/oplus_nwpower.c deleted file mode 100755 index 4f11dd50d139..000000000000 --- a/net/oplus_nwpower/oplus_nwpower.c +++ /dev/null @@ -1,960 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2018-2020 Oplus. All rights reserved. - */ - -/**************************************************************** -** ------------------ Revision History:------------------------ -** -** Asiga 2019/07/31 1.0 build this module -****************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void tcp_output_hook_work_callback(struct work_struct *work); -static void tcp_input_hook_work_callback(struct work_struct *work); -static void tcp_output_tcpsynretrans_hook_work_callback(struct work_struct *work); -static void tcp_input_tcpsynretrans_hook_work_callback(struct work_struct *work); - -static int nwpower_send_to_user(int msg_type, char *msg_data, int msg_len); - -/*Add for feature switch*/ -static atomic_t qrtr_wakeup_hook_boot = ATOMIC_INIT(0); -static atomic_t ipa_wakeup_hook_boot = ATOMIC_INIT(0); -static atomic_t tcpsynretrans_hook_boot = ATOMIC_INIT(0); - -/*Add for qmi wakeup msg*/ -#define GLINK_MODEM_NODE_ID 0x3 -#define GLINK_ADSP_NODE_ID 0x5 -#define GLINK_CDSP_NODE_ID 0xa -#define GLINK_SLPI_NODE_ID 0x9 -#define GLINK_NPU_NODE_ID 0xb - -#define OPLUS_MAX_QRTR_SERVICE_LEN 120 - -atomic_t qrtr_first_msg = ATOMIC_INIT(0); -u64 oplus_nw_wakeup[OPLUS_NW_WAKEUP_SUM] = {0}; -static u64 service_wakeup_times[OPLUS_MAX_QRTR_SERVICE_LEN][4] = {{0}}; - -/*Add for ipa wakeup msg*/ -#define OPLUS_MAX_RECORD_IP_LEN 60 -#define OPLUS_TRANSMISSION_INTERVAL 3 * 1000 -#define OPLUS_TCP_RETRANSMISSION_INTERVAL 1 * 1000 -#define OPLUS_MAX_RECORD_APP_WAKEUP_LEN 100 - -struct tcp_hook_struct { - u32 uid; - u32 pid; - bool is_ipv6; - u32 ipv4_addr; - u64 ipv6_addr1; - u64 ipv6_addr2; - u64 set[OPLUS_MAX_RECORD_IP_LEN*3]; -}; - -struct tcp_hook_simple_struct { - u32 count; - u64 set[OPLUS_MAX_RECORD_APP_WAKEUP_LEN*3+1]; -}; -static struct tcp_hook_simple_struct app_wakeup_monitor_list = { - .set = {0}, -}; - -static bool tcp_input_sch_work = false; -static atomic_t tcp_is_input = ATOMIC_INIT(0);/*1=v4_input,2=v6_input,3=output,0=default*/ -static struct timespec tcp_last_transmission_stamp; -static struct tcp_hook_struct tcp_output_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct tcp_input_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct tcp_output_retrans_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct tcp_input_retrans_list = { - .is_ipv6 = false, - .set = {0}, -}; -DECLARE_WORK(tcp_output_hook_work, tcp_output_hook_work_callback); -DECLARE_WORK(tcp_input_hook_work, tcp_input_hook_work_callback); -DECLARE_WORK(tcp_output_tcpsynretrans_hook_work, tcp_output_tcpsynretrans_hook_work_callback); -DECLARE_WORK(tcp_input_tcpsynretrans_hook_work, tcp_input_tcpsynretrans_hook_work_callback); - -/*Add for modem eap buffer*/ -u64 oplus_mdaci_nw_wakeup[OPLUS_NW_WAKEUP_SUM] = {0}; -static u64 mdaci_service_wakeup_times[OPLUS_MAX_QRTR_SERVICE_LEN][4] = {{0}}; -static struct tcp_hook_struct mdaci_tcp_output_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct mdaci_tcp_input_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct mdaci_tcp_output_retrans_list = { - .is_ipv6 = false, - .set = {0}, -}; -static struct tcp_hook_struct mdaci_tcp_input_retrans_list = { - .is_ipv6 = false, - .set = {0}, -}; - -/*Add for Netlink*/ -enum{ - NW_POWER_ANDROID_PID = 0x11, - NW_POWER_BOOT_MONITOR = 0x12, - NW_POWER_STOP_MONITOR = 0x13, - NW_POWER_STOP_MONITOR_UNSL = 0x14, - NW_POWER_UNSL_MONITOR = 0x15, - NW_POWER_REQUEST_MDACI = 0x16, - NW_POWER_REPORT_MDACI = 0x17, - NW_POWER_BLACK_LIST = 0x18, - NW_POWER_REQUEST_BLACK_REJECT = 0x19, - NW_POWER_REPORT_BLACK_REJECT = 0x1A, - NW_POWER_REQUEST_APP_WAKEUP = 0x1D, - NW_POWER_REPORT_APP_WAKEUP = 0x1E, - NW_POWER_REPORT_MDACI_APP_WAKEUP = 0x1F, -}; -static DEFINE_MUTEX(netlink_mutex); -static u32 oplus_nwpower_pid = 0; -static struct sock *oplus_nwpower_sock; - -/*Add for unsl wakeup msg*/ -#define KERNEL_UNSL_MONITOR_LEN 7 -static u64 wakeup_unsl_msg[KERNEL_UNSL_MONITOR_LEN] = {0}; - -#define KERNEL_UNSL_APP_WAKEUP_LEN 300 -static u32 blacklist_len = 0; -static u32 blacklist_uid[KERNEL_UNSL_APP_WAKEUP_LEN] = {0}; - -#define OPLUS_MAX_RECORD_BLACK_REJECT_LEN 100 -#define KERNEL_UNSL_BLACK_REJECT_LEN 201 -static u32 record_blacklist_reject_index = 0; -static u64 blacklist_reject_uid[KERNEL_UNSL_BLACK_REJECT_LEN] = {0}; - -/*Add for mdaci wakeup apps*/ -static struct tcp_hook_simple_struct mdaci_app_wakeup_monitor_list = { - .set = {0}, -}; - -static uid_t get_uid_from_sock(const struct sock *sk) -{ - uid_t sk_uid; - #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - const struct file *filp = NULL; - #endif - if(NULL == sk || !sk_fullsock(sk) || NULL == sk->sk_socket) { - return 0; - } - #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - filp = sk->sk_socket->file; - if(NULL == filp) { - return 0; - } - sk_uid = __kuid_val(filp->f_cred->fsuid); - #else - sk_uid = __kuid_val(sk->sk_uid); - #endif - return sk_uid; -} - -static void nwpower_unsl_blacklist_reject() { - if (record_blacklist_reject_index > 0) { - blacklist_reject_uid[0] = record_blacklist_reject_index; - nwpower_send_to_user(NW_POWER_REPORT_BLACK_REJECT, (char*)blacklist_reject_uid, sizeof(blacklist_reject_uid)); - memset(blacklist_reject_uid, 0x0, OPLUS_MAX_RECORD_BLACK_REJECT_LEN * sizeof(u32)); - record_blacklist_reject_index = 0; - } -} - -extern bool oplus_check_socket_in_blacklist(int is_input, struct socket *sock) { - int i = 0; - uid_t uid = 0; - struct timespec now_ts; - if (blacklist_len > 0 && sock && sock->sk && (sock->sk->sk_family == 2 || sock->sk->sk_family == 10)) { - uid = get_uid_from_sock(sock->sk); - if(uid == 0) { - return false; - } - now_ts = current_kernel_time(); - for (i = 0; i < blacklist_len; i++) { - if(blacklist_uid[i] == uid) { - if (is_input != 1) { - if (record_blacklist_reject_index >= OPLUS_MAX_RECORD_BLACK_REJECT_LEN) { - nwpower_unsl_blacklist_reject(); - } - if (record_blacklist_reject_index < OPLUS_MAX_RECORD_BLACK_REJECT_LEN) { - blacklist_reject_uid[record_blacklist_reject_index*2+1] = now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000; - blacklist_reject_uid[record_blacklist_reject_index*2+2] = (u64)uid << 32 | is_input; - record_blacklist_reject_index++; - } - } - printk("[oplus_netcontroller] blacklist reject, stamp=%ld, is_input=%d, uid=%u", - now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000, is_input, uid); - return true; - } - } - return false; - } - return false; -} - -static int nwpower_set_blacklist_uids(struct nlmsghdr *nlh) { - u32 *data; - int i = 0; - data = (u32 *)NLMSG_DATA(nlh); - memset(blacklist_uid, 0x0, KERNEL_UNSL_APP_WAKEUP_LEN * sizeof(u32)); - blacklist_len = *data; - for (i = 0; i < blacklist_len; i++) { - if (i >= KERNEL_UNSL_APP_WAKEUP_LEN) { - printk("[oplus_netcontroller] uids length exceed the limit!"); - break; - } else { - blacklist_uid[i] = *(data + i + 1); - } - } - return 0; -} - -extern void oplus_match_modem_wakeup() { - atomic_set(&qrtr_first_msg, 1); - oplus_nw_wakeup[OPLUS_NW_MPSS]++; - oplus_mdaci_nw_wakeup[OPLUS_NW_MPSS]++; -} - -extern void oplus_match_wlan_wakeup() { - oplus_nw_wakeup[OPLUS_NW_WIFI]++; - oplus_mdaci_nw_wakeup[OPLUS_NW_WIFI]++; -} - -static void match_qrtr_new_service_port(int id, int port, u64 qrtr[][4]) { - int i; - for (i = 0; i < OPLUS_MAX_QRTR_SERVICE_LEN; ++i) { - if (qrtr[i][0] == 0) { - qrtr[i][0] = 1; - qrtr[i][1] = id; - qrtr[i][2] = port; - break; - } else { - if (qrtr[i][1] == id && qrtr[i][2] == port) { - break; - } - } - } -} - -static void match_qrtr_del_service_port(int id, u64 qrtr[][4]) { - int i; - for (i = 0; i < OPLUS_MAX_QRTR_SERVICE_LEN; ++i) { - if (qrtr[i][0] == 1 && qrtr[i][1] == id) { - qrtr[i][0] = 0; - break; - } - } -} - -extern void oplus_match_qrtr_service_port(int type, int id, int port) { - /* - if (type == QRTR_TYPE_NEW_SERVER) { - match_qrtr_new_service_port(id, port, service_wakeup_times); - match_qrtr_new_service_port(id, port, mdaci_service_wakeup_times); - } else if (type == QRTR_TYPE_DEL_SERVER) { - match_qrtr_del_service_port(id, service_wakeup_times); - match_qrtr_del_service_port(id, mdaci_service_wakeup_times); - } - */ -} - -static void __oplus_match_qrtr_wakeup(int src_node, int src_port, int dst_port, - unsigned int arg1, unsigned int arg2, u64 qrtr[][4], u64 wakeup[OPLUS_NW_WAKEUP_SUM], bool prt) { - int i; - int repeat[4] = {0}; - int repeat_index = 0; - if (atomic_read(&qrtr_wakeup_hook_boot) == 1 && atomic_read(&qrtr_first_msg) == 1) { - for (i = 0; i < OPLUS_MAX_QRTR_SERVICE_LEN; ++i) { - if (qrtr[i][0] == 1 && (qrtr[i][2] == src_port || qrtr[i][2] == dst_port)) { - if (repeat_index < 4) repeat[repeat_index++] = i; - } - } - if (repeat_index == 1) { - qrtr[repeat[0]][3]++; - if (prt) - printk("[oplus_nwpower] QrtrWakeup: ServiceID: %d, NodeID: %d, PortID: %d, Msg: [%08x %08x], Count: %d", - qrtr[repeat[0]][1], src_node, qrtr[repeat[0]][2], arg1, arg2, qrtr[repeat[0]][3]); - } else if (repeat_index > 1) { - qrtr[repeat[repeat_index-1]][3]++; - if (prt) - printk("[oplus_nwpower] QrtrWakeup: ServiceID: [%d/%d/%d/%d], NodeID: %d, PortID: %d, Msg: [%08x %08x], Count: %d", - qrtr[repeat[0]][1], qrtr[repeat[1]][1], - repeat_index > 2 ? qrtr[repeat[2]][1]:-1, - repeat_index > 3 ? qrtr[repeat[3]][1]:-1, - src_node, qrtr[repeat[repeat_index-1]][2], arg1, arg2, qrtr[repeat[repeat_index-1]][3]); - } else { - if (prt) - printk("[oplus_nwpower] QrtrWakeup: ServiceID: %d, NodeID: %d, PortID: %d, Msg: [%08x %08x], Count: %d", - -1, src_node, -1, arg1, arg2, -1); - } - wakeup[OPLUS_NW_QRTR]++; - if (src_node == GLINK_MODEM_NODE_ID) { - wakeup[OPLUS_NW_MD]++; - } else if (src_node == GLINK_ADSP_NODE_ID) { - } else if (src_node == GLINK_CDSP_NODE_ID) { - } else if (src_node == GLINK_SLPI_NODE_ID) { - } else if (src_node == GLINK_NPU_NODE_ID) { - } - } -} - -extern void oplus_match_qrtr_wakeup(int src_node, int src_port, int dst_port, unsigned int arg1, unsigned int arg2) { - __oplus_match_qrtr_wakeup(src_node, src_port, dst_port, arg1, arg2, service_wakeup_times, oplus_nw_wakeup, true); - __oplus_match_qrtr_wakeup(src_node, src_port, dst_port, arg1, arg2, mdaci_service_wakeup_times, oplus_mdaci_nw_wakeup, false); - atomic_set(&qrtr_first_msg, 0); -} - -extern void oplus_update_qrtr_flag(int flag) { - if (atomic_read(&qrtr_wakeup_hook_boot) == 1) { - atomic_set(&qrtr_first_msg, flag); - } -} - -static void print_qrtr_wakeup(bool unsl, u64 qrtr[][4], u64 wakeup[OPLUS_NW_WAKEUP_SUM], bool prt) { - u64 temp[5][4] = {{0}}; - u64 max_count = 0; - u64 max_count_id = 0; - int j; - int i; - int k; - for (j = 0; j < 5; ++j) { - for (i = 0; i < OPLUS_MAX_QRTR_SERVICE_LEN; ++i) { - if (qrtr[i][0] == 1 && qrtr[i][3] > max_count) { - max_count = qrtr[i][3]; - max_count_id = i; - } - } - for (k = 0;k < 4; ++k) { - temp[j][k] = qrtr[max_count_id][k]; - } - max_count = 0; - qrtr[max_count_id][3] = 0; - if (unsl) { - if (temp[j][3] > 0) wakeup_unsl_msg[j] = temp[j][2] << 32 | ((u32)temp[j][1] << 16 | (u16)temp[j][3]); - } - if (temp[j][3] > 0) printk("[oplus_nwpower] QrtrWakeupMax[%d]: ServiceID: %d, PortID: %d, Count: %d", - j, temp[j][1], temp[j][2], temp[j][3]); - } - if (unsl) { - wakeup_unsl_msg[5] = (wakeup[OPLUS_NW_MD] << 48) | - ((wakeup[OPLUS_NW_QRTR] & 0xFFFF) << 32) | - ((wakeup[OPLUS_NW_WIFI] & 0xFFFF) << 16) | - (wakeup[OPLUS_NW_MPSS] & 0xFFFF); - } - if (prt) - printk("[oplus_nwpower] AllWakeups: Mpss: %d, Qrtr: %d, Modem: %d, WiFi: %d", - wakeup[OPLUS_NW_MPSS], wakeup[OPLUS_NW_QRTR], wakeup[OPLUS_NW_MD], wakeup[OPLUS_NW_WIFI]); -} - -extern void oplus_match_ipa_ip_wakeup(int type, struct sk_buff *skb) { - struct timespec now_ts; - struct iphdr *tmp_v4iph; - struct ipv6hdr *tmp_v6iph; - tcp_input_sch_work = false; - if (atomic_read(&ipa_wakeup_hook_boot) == 1) { - if (atomic_read(&tcp_is_input) == 0) { - now_ts = current_kernel_time(); - if (((now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000) - (tcp_last_transmission_stamp.tv_sec * 1000 + tcp_last_transmission_stamp.tv_nsec / 1000000)) - > OPLUS_TRANSMISSION_INTERVAL) { - if (type == OPLUS_TCP_TYPE_V4) { - tmp_v4iph = ip_hdr(skb); - atomic_set(&tcp_is_input, OPLUS_TCP_TYPE_V4); - tcp_input_list.ipv4_addr = tmp_v4iph->saddr; - tcp_input_list.is_ipv6 = false; - mdaci_tcp_input_list.ipv4_addr = tcp_input_list.ipv4_addr; - mdaci_tcp_input_list.is_ipv6 = false; - } else { - tmp_v6iph = ipv6_hdr(skb); - atomic_set(&tcp_is_input, OPLUS_TCP_TYPE_V6); - tcp_input_list.ipv6_addr1 = (u64)ntohl(tmp_v6iph->saddr.s6_addr32[0]) << 32 | ntohl(tmp_v6iph->saddr.s6_addr32[1]); - tcp_input_list.ipv6_addr2 = (u64)ntohl(tmp_v6iph->saddr.s6_addr32[2]) << 32 | ntohl(tmp_v6iph->saddr.s6_addr32[3]); - tcp_input_list.is_ipv6 = true; - mdaci_tcp_input_list.ipv6_addr1 = tcp_input_list.ipv6_addr1; - mdaci_tcp_input_list.ipv6_addr2 = tcp_input_list.ipv6_addr2; - mdaci_tcp_input_list.is_ipv6 = true; - } - tcp_input_list.uid = 0; - tcp_input_list.pid = 0; - mdaci_tcp_input_list.uid = 0; - mdaci_tcp_input_list.pid = 0; - } - } - tcp_last_transmission_stamp = current_kernel_time(); - } -} - -extern void oplus_match_ipa_tcp_wakeup(int type, struct sock *sk) { - if (atomic_read(&ipa_wakeup_hook_boot) == 1) { - if (atomic_read(&tcp_is_input) == type && !tcp_input_sch_work) { - if (sk->sk_state != TCP_TIME_WAIT) { - tcp_input_list.uid = get_uid_from_sock(sk); - tcp_input_list.pid = sk->sk_oplus_pid; - mdaci_tcp_input_list.uid = tcp_input_list.uid; - mdaci_tcp_input_list.pid = tcp_input_list.pid; - } - schedule_work(&tcp_input_hook_work); - tcp_input_sch_work = true; - } - sk->oplus_last_rcv_stamp[0] = sk->oplus_last_rcv_stamp[1]; - sk->oplus_last_rcv_stamp[1] = tcp_last_transmission_stamp.tv_sec * 1000 + tcp_last_transmission_stamp.tv_nsec / 1000000; - } -} - -extern void oplus_ipa_schedule_work() { - if (atomic_read(&ipa_wakeup_hook_boot) == 1 && atomic_read(&tcp_is_input) == 1 && !tcp_input_sch_work) { - schedule_work(&tcp_input_hook_work); - tcp_input_sch_work = true; - } -} - -extern void oplus_match_tcp_output(struct sock *sk) { - struct timespec now_ts; - if (atomic_read(&ipa_wakeup_hook_boot) == 1) { - if (atomic_read(&tcp_is_input) == 0) { - now_ts = current_kernel_time(); - if (((now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000) - (tcp_last_transmission_stamp.tv_sec * 1000 + tcp_last_transmission_stamp.tv_nsec / 1000000)) - > OPLUS_TRANSMISSION_INTERVAL) { - atomic_set(&tcp_is_input, 3); - if (sk->sk_v6_daddr.s6_addr32[0] == 0 && sk->sk_v6_daddr.s6_addr32[1] == 0) { - tcp_output_list.ipv4_addr = sk->sk_daddr; - tcp_output_list.is_ipv6 = false; - mdaci_tcp_output_list.ipv4_addr = tcp_output_list.ipv4_addr; - mdaci_tcp_output_list.is_ipv6 = false; - } else { - tcp_output_list.ipv6_addr1 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[0]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[1]); - tcp_output_list.ipv6_addr2 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[2]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[3]); - tcp_output_list.is_ipv6 = true; - mdaci_tcp_output_list.ipv6_addr1 = tcp_output_list.ipv6_addr1; - mdaci_tcp_output_list.ipv6_addr2 = tcp_output_list.ipv6_addr2; - mdaci_tcp_output_list.is_ipv6 = true; - } - tcp_output_list.uid = get_uid_from_sock(sk); - tcp_output_list.pid = sk->sk_oplus_pid; - mdaci_tcp_output_list.uid = tcp_output_list.uid; - mdaci_tcp_output_list.pid = tcp_output_list.pid; - schedule_work(&tcp_output_hook_work); - } - } - tcp_last_transmission_stamp = current_kernel_time(); - sk->oplus_last_send_stamp[0] = sk->oplus_last_send_stamp[1]; - sk->oplus_last_send_stamp[1] = tcp_last_transmission_stamp.tv_sec * 1000 + tcp_last_transmission_stamp.tv_nsec / 1000000; - } -} - -extern void oplus_match_tcp_input_retrans(struct sock *sk) { - struct timespec now_ts; - if (atomic_read(&tcpsynretrans_hook_boot) == 1) { - now_ts = current_kernel_time(); - if (((now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000) - sk->oplus_last_rcv_stamp[0]) > OPLUS_TCP_RETRANSMISSION_INTERVAL) { - if (sk->sk_v6_daddr.s6_addr32[0] == 0 && sk->sk_v6_daddr.s6_addr32[1] == 0) { - tcp_input_retrans_list.ipv4_addr = sk->sk_daddr; - tcp_input_retrans_list.is_ipv6 = false; - mdaci_tcp_input_retrans_list.ipv4_addr = tcp_input_retrans_list.ipv4_addr; - mdaci_tcp_input_retrans_list.is_ipv6 = false; - } else { - tcp_input_retrans_list.ipv6_addr1 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[0]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[1]); - tcp_input_retrans_list.ipv6_addr2 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[2]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[3]); - tcp_input_retrans_list.is_ipv6 = true; - mdaci_tcp_input_retrans_list.ipv6_addr1 = tcp_input_retrans_list.ipv6_addr1; - mdaci_tcp_input_retrans_list.ipv6_addr2 = tcp_input_retrans_list.ipv6_addr2; - mdaci_tcp_input_retrans_list.is_ipv6 = true; - } - tcp_input_retrans_list.uid = get_uid_from_sock(sk); - tcp_input_retrans_list.pid = sk->sk_oplus_pid; - mdaci_tcp_input_retrans_list.uid = tcp_input_retrans_list.uid; - mdaci_tcp_input_retrans_list.pid = tcp_input_retrans_list.pid; - schedule_work(&tcp_input_tcpsynretrans_hook_work); - } - } -} - -extern void oplus_match_tcp_output_retrans(struct sock *sk) { - struct timespec now_ts; - if (atomic_read(&tcpsynretrans_hook_boot) == 1) { - now_ts = current_kernel_time(); - if (((now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000) - sk->oplus_last_send_stamp[0]) > OPLUS_TCP_RETRANSMISSION_INTERVAL) { - if (sk->sk_v6_daddr.s6_addr32[0] == 0 && sk->sk_v6_daddr.s6_addr32[1] == 0) { - tcp_output_retrans_list.ipv4_addr = sk->sk_daddr; - tcp_output_retrans_list.is_ipv6 = false; - mdaci_tcp_output_retrans_list.ipv4_addr = tcp_output_retrans_list.ipv4_addr; - mdaci_tcp_output_retrans_list.is_ipv6 = false; - } else { - tcp_output_retrans_list.ipv6_addr1 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[0]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[1]); - tcp_output_retrans_list.ipv6_addr2 = (u64)ntohl(sk->sk_v6_daddr.s6_addr32[2]) << 32 | ntohl(sk->sk_v6_daddr.s6_addr32[3]); - tcp_output_retrans_list.is_ipv6 = true; - mdaci_tcp_output_retrans_list.ipv6_addr1 = tcp_output_retrans_list.ipv6_addr1; - mdaci_tcp_output_retrans_list.ipv6_addr2 = tcp_output_retrans_list.ipv6_addr2; - mdaci_tcp_output_retrans_list.is_ipv6 = true; - } - tcp_output_retrans_list.uid = get_uid_from_sock(sk); - tcp_output_retrans_list.pid = sk->sk_oplus_pid; - mdaci_tcp_output_retrans_list.uid = tcp_output_retrans_list.uid; - mdaci_tcp_output_retrans_list.pid = tcp_output_retrans_list.pid; - schedule_work(&tcp_output_tcpsynretrans_hook_work); - } - } -} - -static void tcp_hook_insert_sort(struct tcp_hook_struct *pval) { - int i; - int j; - u64 count = 0; - u64 temp_sort[3] = {0}; - for (i = 1; i < OPLUS_MAX_RECORD_IP_LEN; ++i) { - temp_sort[0] = pval->set[3*i]; - temp_sort[1] = pval->set[3*i+1]; - temp_sort[2] = pval->set[3*i+2]; - if (temp_sort[0] == 0 && temp_sort[1] == 0 && temp_sort[2] != 0) { - count = (temp_sort[2] & 0xFFFC000000000000) >> 50; - } else { - count = temp_sort[2] & 0xFFFFFFFF; - } - j = i - 1; - while (j >= 0) { - if ((pval->set[3*j] == 0) && (pval->set[3*j+1] == 0) && (pval->set[3*j+2] != 0)) { - if (count > (pval->set[3*j+2] & 0xFFFC000000000000) >> 50) { - pval->set[3*(j+1)] = pval->set[3*j]; - pval->set[3*(j+1)+1] = pval->set[3*j+1]; - pval->set[3*(j+1)+2] = pval->set[3*j+2]; - --j; - } else { - break; - } - } else { - if (count > (pval->set[3*j+2] & 0xFFFFFFFF)) { - pval->set[3*(j+1)] = pval->set[3*j]; - pval->set[3*(j+1)+1] = pval->set[3*j+1]; - pval->set[3*(j+1)+2] = pval->set[3*j+2]; - --j; - } else { - break; - } - } - } - pval->set[3*(j+1)] = temp_sort[0]; - pval->set[3*(j+1)+1] = temp_sort[1]; - pval->set[3*(j+1)+2] = temp_sort[2]; - } -} - -static int match_tcp_hook(struct tcp_hook_struct *pval) { - int i; - u32 uid = 0; - u64 count = 0; - bool handle = false; - - for (i = 0; i < OPLUS_MAX_RECORD_IP_LEN; ++i) { - if (pval->is_ipv6) { - if (pval->ipv6_addr1 == pval->set[3*i] && pval->ipv6_addr2 == pval->set[3*i+1]) { - count = pval->set[3*i+2] & 0xFFFFFFFF; - uid = (pval->set[3*i+2] & 0xFFFFFFFF00000000) >> 32; - if (uid == 0) { - pval->set[3*i+2] = (u64)(pval->uid) << 32 | (u32)(++count); - } else { - pval->set[3*i+2] = (pval->set[3*i+2] & 0xFFFFFFFF00000000) | (u32)(++count); - } - handle = true; - break; - } else if (pval->set[3*i+2] == 0) { - pval->set[3*i] = pval->ipv6_addr1; - pval->set[3*i+1] = pval->ipv6_addr2; - count = 1; - pval->set[3*i+2] = (u64)(pval->uid) << 32 | (u32)(count); - handle = true; - break; - } - } else { - if (pval->ipv4_addr == (pval->set[3*i+2] & 0xFFFFFFFF)) { - count = (pval->set[3*i+2] & 0xFFFC000000000000) >> 50; - uid = (pval->set[3*i+2] & 0x3FFFF00000000) >> 32; - if (uid == 0) { - count++; - count = count << 18 | (pval->uid & 0x3FFFF); - pval->set[3*i+2] = count << 32 | (pval->set[3*i+2] & 0xFFFFFFFF); - } else { - pval->set[3*i+2] = (++count) << 50 | (pval->set[3*i+2] & 0x3FFFFFFFFFFFF); - } - handle = true; - break; - } else if (pval->set[3*i+2] == 0) { - count = 1 << 18 | (pval->uid & 0x3FFFF); - pval->set[3*i+2] = count << 32 | pval->ipv4_addr; - handle = true; - break; - } - } - } - if (!handle) { - tcp_hook_insert_sort(pval); - i = OPLUS_MAX_RECORD_IP_LEN - 1; - if (pval->is_ipv6) { - pval->set[3*i] = pval->ipv6_addr1; - pval->set[3*i+1] = pval->ipv6_addr2; - count = 1; - pval->set[3*i+2] = (u64)(pval->uid) << 32 | (u32)(count); - } else { - pval->set[3*i] = 0; - pval->set[3*i+1] = 0; - count = 1 << 18 | (pval->uid & 0x3FFFF); - pval->set[3*i+2] = (u64)count << 32 | pval->ipv4_addr; - } - } - - return i; -} - -static bool tcp_monitor_check_uid_in_whitelist(int uid) { - int i = 0; - if (blacklist_len > 0) { - for (i = 0; i < blacklist_len; i++) { - if (i >= KERNEL_UNSL_APP_WAKEUP_LEN) { - printk("[oplus_netcontroller] uids length exceed the limit!"); - return true; - } - if(blacklist_uid[i] == uid) { - return false; - } - } - } - return true; -} - -static void nwpower_unsl_app_wakeup() -{ - nwpower_send_to_user(NW_POWER_REPORT_APP_WAKEUP, (char*)app_wakeup_monitor_list.set, sizeof(app_wakeup_monitor_list.set)); - app_wakeup_monitor_list.count = 0; - memset(app_wakeup_monitor_list.set, 0x0, sizeof(app_wakeup_monitor_list.set)); -} - -static void app_wakeup_monitor(struct tcp_hook_simple_struct *pval, bool is_block, bool is_input, int pid, int uid) { - struct timespec now_ts = current_kernel_time(); - int block = is_block ? 1:0; - int input = is_input ? 1:0; - int whitelist = tcp_monitor_check_uid_in_whitelist(uid) ? 1:0; - if (pval->count < OPLUS_MAX_RECORD_APP_WAKEUP_LEN) { - pval->set[1+pval->count*3] = (u64)pid << 32 | uid; - pval->set[1+pval->count*3+1] = - ((u64)block << 48) | - ((u64)(input & 0xFFFF) << 32) | - ((u64)(whitelist & 0xFFFF) << 16) | - (0xFFFF); - pval->set[1+pval->count*3+2] = now_ts.tv_sec * 1000 + now_ts.tv_nsec / 1000000; - /* - printk("[oplus_nwpower] count:%d, block:%d, input:%d, pid:%d, uid:%d, stamp:%ld", - pval->set[0], block, input, pid, uid, pval->set[1+pval->count*3+2]); - */ - pval->set[0] = (++pval->count); - } else { - printk("[oplus_nwpower] warning! OPLUS_MAX_RECORD_APP_WAKEUP_LEN reached"); - } -} - -static void tcp_output_hook_work_callback(struct work_struct *work) { - int i = match_tcp_hook(&tcp_output_list); - match_tcp_hook(&mdaci_tcp_output_list); - app_wakeup_monitor(&app_wakeup_monitor_list, false, false, tcp_output_list.pid, tcp_output_list.uid); - app_wakeup_monitor(&mdaci_app_wakeup_monitor_list, false, false, tcp_output_list.pid, tcp_output_list.uid); - if (tcp_output_list.is_ipv6) { - printk("[oplus_nwpower] IPAOutputWakeup: [%ld,****], %d, %d, %d", - tcp_output_list.ipv6_addr1, - tcp_output_list.pid, tcp_output_list.uid, tcp_output_list.set[3*i+2] & 0xFFFFFFFF); - } else { - printk("[oplus_nwpower] IPAOutputWakeup: %#X, %d, %d, %d", - tcp_output_list.ipv4_addr & 0xFFFFFF, tcp_output_list.pid, tcp_output_list.uid, - (tcp_output_list.set[3*i+2] & 0xFFFC000000000000) >> 50); - } - atomic_set(&tcp_is_input, 0); -} - -static void tcp_input_hook_work_callback(struct work_struct *work) { - int i = match_tcp_hook(&tcp_input_list); - match_tcp_hook(&mdaci_tcp_input_list); - app_wakeup_monitor(&app_wakeup_monitor_list, false, true, tcp_input_list.pid, tcp_input_list.uid); - app_wakeup_monitor(&mdaci_app_wakeup_monitor_list, false, true, tcp_input_list.pid, tcp_input_list.uid); - if (tcp_input_list.is_ipv6) { - printk("[oplus_nwpower] IPAInputWakeup: [%ld,****], %d, %d, %d", - tcp_input_list.ipv6_addr1, - tcp_input_list.pid, tcp_input_list.uid, tcp_input_list.set[3*i+2] & 0xFFFFFFFF); - } else { - printk("[oplus_nwpower] IPAInputWakeup: %#X, %d, %d, %d", - tcp_input_list.ipv4_addr & 0xFFFFFF, tcp_input_list.pid, tcp_input_list.uid, - (tcp_input_list.set[3*i+2] & 0xFFFC000000000000) >> 50); - } - atomic_set(&tcp_is_input, 0); -} - -static void tcp_output_tcpsynretrans_hook_work_callback(struct work_struct *work) { - int i = match_tcp_hook(&tcp_output_retrans_list); - match_tcp_hook(&mdaci_tcp_output_retrans_list); - if (tcp_output_retrans_list.is_ipv6) { - if (tcp_output_retrans_list.ipv6_addr1 == 0 && tcp_output_retrans_list.ipv6_addr2 == 0) - return; - printk("[oplus_nwpower] TCPOutputRetrans: [%ld,****], %d, %d, %d", - tcp_output_retrans_list.ipv6_addr1, - tcp_output_retrans_list.pid, tcp_output_retrans_list.uid, tcp_output_retrans_list.set[3*i+2] & 0xFFFFFFFF); - } else { - if (tcp_output_retrans_list.ipv4_addr == 0) - return; - printk("[oplus_nwpower] TCPOutputRetrans: %#X, %d, %d, %d", - tcp_output_retrans_list.ipv4_addr & 0xFFFFFF, tcp_output_retrans_list.pid, tcp_output_retrans_list.uid, - (tcp_output_retrans_list.set[3*i+2] & 0xFFFC000000000000) >> 50); - } -} - -static void tcp_input_tcpsynretrans_hook_work_callback(struct work_struct *work) { - int i = match_tcp_hook(&tcp_input_retrans_list); - match_tcp_hook(&mdaci_tcp_input_retrans_list); - if (tcp_input_retrans_list.is_ipv6) { - if (tcp_input_retrans_list.ipv6_addr1 == 0 && tcp_input_retrans_list.ipv6_addr2 == 0) - return; - printk("[oplus_nwpower] TCPInputRetrans: [%ld,****], %d, %d, %d", - tcp_input_retrans_list.ipv6_addr1, - tcp_input_retrans_list.pid, tcp_input_retrans_list.uid, tcp_input_retrans_list.set[3*i+2] & 0xFFFFFFFF); - } else { - if (tcp_input_retrans_list.ipv4_addr == 0) - return; - printk("[oplus_nwpower] TCPInputRetrans: %#X, %d, %d, %d", - tcp_input_retrans_list.ipv4_addr & 0xFFFFFF, tcp_input_retrans_list.pid, tcp_input_retrans_list.uid, - (tcp_input_retrans_list.set[3*i+2] & 0xFFFC000000000000) >> 50); - } -} - -static int print_tcp_wakeup(const char *type, struct tcp_hook_struct *pval, bool prt) { - int i; - u32 count; - u32 tcp_wakeup_times = 0; - tcp_hook_insert_sort(pval); - for (i = 0; i < 5;++i) { - if ((pval->set[3*i] == 0) && (pval->set[3*i+1] == 0) && (pval->set[3*i+2] != 0)) { - count = (pval->set[3*i+2] & 0xFFFC000000000000) >> 50; - if (prt && count > 0) { - printk("[oplus_nwpower] IPA%sMAX[%d]: %#X, %d, %d", - type, i, (pval->set[3*i+2] & 0xFFFFFFFF) & 0xFFFFFF, - (pval->set[3*i+2] & 0x3FFFF00000000) >> 32, count); - } - } else { - count = pval->set[3*i+2] & 0xFFFFFFFF; - if (prt && count > 0) { - printk("[oplus_nwpower] IPA%sMAX[%d]: [%ld,****], %d, %d", - type, i, pval->set[3*i], - pval->set[3*i+2] >> 32, count); - } - } - } - for (i = 0; i < OPLUS_MAX_RECORD_IP_LEN;++i) { - if ((pval->set[3*i] == 0) && (pval->set[3*i+1] == 0) && (pval->set[3*i+2] != 0)) { - count = (pval->set[3*i+2] & 0xFFFC000000000000) >> 50; - } else { - count = pval->set[3*i+2] & 0xFFFFFFFF; - } - if (count > 0) { - tcp_wakeup_times += count; - } - } - return tcp_wakeup_times; -} - -static void print_ipa_wakeup(bool unsl, struct tcp_hook_struct *ptcp_in, struct tcp_hook_struct *ptcp_out, - struct tcp_hook_struct *ptcp_re_in, struct tcp_hook_struct *ptcp_re_out, u64 wakeup[OPLUS_NW_WAKEUP_SUM], bool prt) { - wakeup[OPLUS_NW_TCP_IN] = print_tcp_wakeup("Input", ptcp_in, prt); - wakeup[OPLUS_NW_TCP_OUT] = print_tcp_wakeup("Output", ptcp_out, prt); - wakeup[OPLUS_NW_TCP_RE_IN] = print_tcp_wakeup("InputRetrans", ptcp_re_in, prt); - wakeup[OPLUS_NW_TCP_RE_OUT] = print_tcp_wakeup("OutputRetrans", ptcp_re_out, prt); - if (prt) - printk("[oplus_nwpower] IPAAllWakeups: TCPInput: %d, TCPOutput: %d, TCPInputRetrans: %d, TCPOutputRetrans: %d", - wakeup[OPLUS_NW_TCP_IN], wakeup[OPLUS_NW_TCP_OUT], wakeup[OPLUS_NW_TCP_RE_IN], wakeup[OPLUS_NW_TCP_RE_OUT]); - if (unsl) { - wakeup_unsl_msg[6] = (wakeup[OPLUS_NW_TCP_IN] << 48) | - ((wakeup[OPLUS_NW_TCP_OUT] & 0xFFFF) << 32) | - ((wakeup[OPLUS_NW_TCP_RE_IN] & 0xFFFF) << 16) | - (wakeup[OPLUS_NW_TCP_RE_OUT] & 0xFFFF); - } -} - -static void reset_count(u64 qrtr[][4], struct tcp_hook_struct *ptcp_in, struct tcp_hook_struct *ptcp_out, - struct tcp_hook_struct *ptcp_re_in, struct tcp_hook_struct *ptcp_re_out, u64 wakeup[OPLUS_NW_WAKEUP_SUM]) { - int i; - int j; - for (i = 0; i < OPLUS_MAX_QRTR_SERVICE_LEN; ++i) { - if (qrtr[i][0] == 1) { - qrtr[i][3] = 0; - } - } - for (i = 0; i < OPLUS_MAX_RECORD_IP_LEN; ++i) { - for (j = 0; j < 3; ++j) { - ptcp_in->set[i+j] = 0; - ptcp_out->set[i+j] = 0; - ptcp_re_in->set[i+j] = 0; - ptcp_re_out->set[i+j] = 0; - } - } - for (i = 0; i < OPLUS_NW_WAKEUP_SUM; ++i) { - wakeup[i] = 0; - } -} - -static void nwpower_hook_on() { - atomic_set(&qrtr_wakeup_hook_boot, 1); - atomic_set(&ipa_wakeup_hook_boot, 1); - atomic_set(&tcpsynretrans_hook_boot, 1); -} - -static void nwpower_hook_off(bool unsl) { - atomic_set(&qrtr_wakeup_hook_boot, 0); - atomic_set(&ipa_wakeup_hook_boot, 0); - atomic_set(&tcpsynretrans_hook_boot, 0); - print_qrtr_wakeup(unsl, service_wakeup_times, oplus_nw_wakeup, true); - print_ipa_wakeup(unsl, &tcp_input_list, &tcp_output_list, &tcp_input_retrans_list, &tcp_output_retrans_list, oplus_nw_wakeup, true); - reset_count(service_wakeup_times, &tcp_input_list, &tcp_output_list, &tcp_input_retrans_list, &tcp_output_retrans_list, oplus_nw_wakeup); - app_wakeup_monitor_list.count = 0; - memset(app_wakeup_monitor_list.set, 0x0, sizeof(app_wakeup_monitor_list.set)); - if (unsl) { - nwpower_send_to_user(NW_POWER_UNSL_MONITOR, (char*)wakeup_unsl_msg, sizeof(wakeup_unsl_msg)); - memset(wakeup_unsl_msg, 0x0, sizeof(wakeup_unsl_msg)); - } -} - -static void nwpower_unsl_mdaci() { - print_qrtr_wakeup(true, mdaci_service_wakeup_times, oplus_mdaci_nw_wakeup, true); - print_ipa_wakeup(true, &mdaci_tcp_input_list, &mdaci_tcp_output_list, - &mdaci_tcp_input_retrans_list, &mdaci_tcp_output_retrans_list, oplus_mdaci_nw_wakeup, true); - reset_count(mdaci_service_wakeup_times, &mdaci_tcp_input_list, &mdaci_tcp_output_list, - &mdaci_tcp_input_retrans_list, &mdaci_tcp_output_retrans_list, oplus_mdaci_nw_wakeup); - nwpower_send_to_user(NW_POWER_REPORT_MDACI, (char*)wakeup_unsl_msg, sizeof(wakeup_unsl_msg)); - memset(wakeup_unsl_msg, 0x0, sizeof(wakeup_unsl_msg)); - nwpower_send_to_user(NW_POWER_REPORT_MDACI_APP_WAKEUP, (char*)mdaci_app_wakeup_monitor_list.set, sizeof(mdaci_app_wakeup_monitor_list.set)); - mdaci_app_wakeup_monitor_list.count = 0; - memset(mdaci_app_wakeup_monitor_list.set, 0x0, sizeof(mdaci_app_wakeup_monitor_list.set)); -} - -static int nwpower_send_to_user(int msg_type, char *msg_data, int msg_len) { - int ret = 0; - struct sk_buff *skb; - struct nlmsghdr *nlh; - if (oplus_nwpower_pid == 0) { - printk("[oplus_nwpower] netlink: oplus_nwpower_pid = 0.\n"); - return -1; - } - skb = alloc_skb(NLMSG_SPACE(msg_len), GFP_ATOMIC); - if (skb == NULL) { - printk("[oplus_nwpower] netlink: alloc_skb failed.\n"); - return -2; - } - nlh = nlmsg_put(skb, 0, 0, msg_type, NLMSG_ALIGN(msg_len), 0); - if (nlh == NULL) { - printk("[oplus_nwpower] netlink: nlmsg_put failed.\n"); - nlmsg_free(skb); - return -3; - } - nlh->nlmsg_len = NLMSG_HDRLEN + NLMSG_ALIGN(msg_len); - if(msg_data != NULL) { - memcpy((char*)NLMSG_DATA(nlh), msg_data, msg_len); - } - NETLINK_CB(skb).portid = 0; - NETLINK_CB(skb).dst_group = 0; - ret = netlink_unicast(oplus_nwpower_sock, skb, oplus_nwpower_pid, MSG_DONTWAIT); - if(ret < 0) { - printk(KERN_ERR "[oplus_nwpower] netlink: netlink_unicast failed, ret = %d.\n", ret); - return -4; - } - return 0; -} - -static int nwpower_netlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { - int ret = 0; - switch (nlh->nlmsg_type) { - case NW_POWER_ANDROID_PID: - oplus_nwpower_pid = NETLINK_CB(skb).portid; - printk("[oplus_nwpower] netlink: oplus_nwpower_pid = %d", oplus_nwpower_pid); - break; - case NW_POWER_BOOT_MONITOR: - nwpower_hook_on(); - printk("[oplus_nwpower] netlink: hook_on"); - break; - case NW_POWER_STOP_MONITOR: - nwpower_hook_off(false); - printk("[oplus_nwpower] netlink: hook_off"); - break; - case NW_POWER_STOP_MONITOR_UNSL: - nwpower_hook_off(true); - printk("[oplus_nwpower] netlink: hook_off_unsl"); - break; - case NW_POWER_BLACK_LIST: - ret = nwpower_set_blacklist_uids(nlh); - break; - case NW_POWER_REQUEST_BLACK_REJECT: - nwpower_unsl_blacklist_reject(); - printk("[oplus_nwpower] netlink: unsl_blacklist_reject"); - break; - case NW_POWER_REQUEST_APP_WAKEUP: - nwpower_unsl_app_wakeup(); - printk("[oplus_nwpower] netlink: unsl_app_wakeup"); - break; - case NW_POWER_REQUEST_MDACI: - nwpower_unsl_mdaci(); - printk("[oplus_nwpower] netlink: unsl_mdaci"); - break; - default: - return -EINVAL; - } - return ret; -} - -static void nwpower_netlink_rcv(struct sk_buff *skb) { - mutex_lock(&netlink_mutex); - netlink_rcv_skb(skb, &nwpower_netlink_rcv_msg); - mutex_unlock(&netlink_mutex); -} - -static int nwpower_netlink_init(void) { - struct netlink_kernel_cfg cfg = { - .input = nwpower_netlink_rcv, - }; - oplus_nwpower_sock = netlink_kernel_create(&init_net, NETLINK_OPLUS_NWPOWERSTATE, &cfg); - return oplus_nwpower_sock == NULL ? -ENOMEM : 0; -} - -static void nwpower_netlink_exit(void) { - netlink_kernel_release(oplus_nwpower_sock); - oplus_nwpower_sock = NULL; -} - -static int __init nwpower_init(void) { - int ret = 0; - ret = nwpower_netlink_init(); - if (ret < 0) { - printk("[oplus_nwpower] netlink: failed to init netlink.\n"); - } else { - printk("[oplus_nwpower] netlink: init netlink successfully.\n"); - } - return ret; -} - -static void __exit nwpower_fini(void) { - nwpower_netlink_exit(); -} - -module_init(nwpower_init); -module_exit(nwpower_fini); diff --git a/net/oplus_score/Kconfig b/net/oplus_score/Kconfig deleted file mode 100755 index 60481e8916b9..000000000000 --- a/net/oplus_score/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. - -config OPLUS_FEATURE_DATA_EVAL - tristate "Add for network score" - help - Add for Add for network score. diff --git a/net/oplus_score/Makefile b/net/oplus_score/Makefile deleted file mode 100755 index a13fad1b44f4..000000000000 --- a/net/oplus_score/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# -# Add for kernel data info send to user space. -# -obj-$(CONFIG_OPLUS_FEATURE_DATA_EVAL) += oplus_score.o - diff --git a/net/oplus_score/oplus_score.c b/net/oplus_score/oplus_score.c deleted file mode 100755 index 456701d01b87..000000000000 --- a/net/oplus_score/oplus_score.c +++ /dev/null @@ -1,1437 +0,0 @@ -/*********************************************************** -** Copyright (C), 2008-2019, oplus Mobile Comm Corp., Ltd. -** File: oplus_score.c -** Description: Add for kernel data info send to user space. -** -** Version: 1.0 -** Date : 2019/10/02 -** Author: Hao.Peng@TECH.CN.WiFi.Network.2527098,2019/10/02 -** -** ------------------ Revision History:------------------------ -** -** penghao 2019/10/02 1.0 build this module -****************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define IFNAME_LEN 16 -#define IPV4ADDRTOSTR(addr) \ -((unsigned char *)&addr)[0], \ -((unsigned char *)&addr)[1], \ -((unsigned char *)&addr)[2], \ -((unsigned char *)&addr)[3] - -#define OPLUS_TRUE 1 -#define OPLUS_FALSE 0 -#define REPORT_PERIOD 1 -#define SCORE_WINDOW 3 -#define OPLUS_UPLINK 1 -#define OPLUS_DOWNLINK 0 - -struct link_score_msg_st -{ - u32 link_index; - s32 uplink_score; - s32 downlink_score; -}; - -struct score_param_st -{ - u32 score_debug; - u32 threshold_retansmit; - u32 threshold_normal; - u32 smooth_factor; - u32 protect_score; - u32 threshold_gap; -}; - -struct uplink_score_info_st{ - u32 link_index; - u32 uplink_rtt_stamp; - u32 uplink_retrans_packets; - u32 uplink_packets; - s32 uplink_score_save[SCORE_WINDOW]; - u32 uplink_score_index; - u32 uplink_srtt; - u32 uplink_rtt_num; - u32 seq; - s32 uplink_score_count; - u32 uplink_nodata_count; - char ifname[IFNAME_LEN]; -}; - -struct downlink_score_info_st{ - u32 link_index; - u32 downlink_update_stamp; - u32 downlink_retrans_packets; - u32 downlink_packets; - s32 downlink_score_save[SCORE_WINDOW]; - u32 downlink_score_index; - u32 downlink_srtt; - u32 downlink_rtt_num; - u32 seq; - s32 downlink_score_count; - u32 downlink_nodata_count; - char ifname[IFNAME_LEN]; -}; - -#define MAX_LINK_SCORE 100 -#define MAX_LINK_NUM 4 -#define FOREGROUND_UID_MAX_NUM 10 - -static int oplus_score_uplink_num = 0; -static int oplus_score_downlink_num = 0; -static int oplus_score_enable_flag = 1; -static u32 oplus_score_foreground_uid[FOREGROUND_UID_MAX_NUM]; -static u32 oplus_score_user_pid = 0; -static spinlock_t uplink_score_lock; -static struct uplink_score_info_st uplink_score_info[MAX_LINK_NUM]; -static spinlock_t downlink_score_lock; -static struct downlink_score_info_st downlink_score_info[MAX_LINK_NUM]; -static struct score_param_st oplus_score_param_info; -static struct ctl_table_header *oplus_score_table_hrd = NULL; -//static u32 time_gap = 5; /* sec */ -/* static u32 last_report_time = 0; */ -static struct timer_list oplus_score_report_timer; -static int oplus_score_debug = 0; -static u32 para_rtt = 8; -static u32 para_rate = 8; -static u32 para_loss = 16; - -#define WORST_VIDEO_RTT_THRESH 1000 -#define WORST_RTT_THRESH 400 -#define WORSE_RTT_THRESH 300 -#define NORMAL_RTT_THRESH 200 -#define BAD_GAME_RTT_THREAD 170 -#define WORST_BASE_SCORE 59 -#define WORSE_BASE_SCORE 70 -#define NORMAL_BASE_SCORE 80 -#define GOOD_BASE_SCORE 100 - -/*for test*/ -static u32 test_foreground_uid = 0; -static u32 test_link_index = 0; -#define PACKET_PER_SEC 240 -#define VIDEO_GOOD_RATE 400 -#define LOWER_RATE_PACKET 20 -#define LOWEST_RATE_PACKET 10 -#define SCORE_KEEP 3 -#define VALID_RTT_THRESH 10 - - -enum score_msg_type_et{ - OPLUS_SCORE_MSG_UNSPEC, - OPLUS_SCORE_MSG_ENABLE, - OPLUS_SCORE_MSG_FOREGROUND_ANDROID_UID, - OPLUS_SCORE_MSG_REQUEST_SCORE, - OPLUS_SCORE_MSG_ADD_LINK, - OPLUS_SCORE_MSG_DEL_LINK, - OPLUS_SCORE_MSG_CLEAR_LINK, - OPLUS_SCORE_MSG_CONFIG, - OPLUS_SCORE_MSG_REPORT_NETWORK_SCORE, - __OPLUS_SCORE_MSG_MAX, -}; -#define OPLUS_SCORE_MSG_MAX (__OPLUS_SCORE_MSG_MAX - 1) - -enum score_cmd_type_et{ - OPLUS_SCORE_CMD_UNSPEC, - OPLUS_SCORE_CMD_DOWNLINK, - __OPLUS_SCORE_CMD_MAX, -}; -#define OPLUS_SCORE_CMD_MAX (__OPLUS_SCORE_CMD_MAX - 1) - -#define OPLUS_SCORE_FAMILY_VERSION 1 -#define OPLUS_SCORE_FAMILY_NAME "net_score" -#define NLA_DATA(na) ((char *)((char*)(na) + NLA_HDRLEN)) -#define GENL_ID_GENERATE 0 -static int oplus_score_netlink_rcv_msg(struct sk_buff *skb, struct genl_info *info); -static const struct genl_ops oplus_score_genl_ops[] = -{ - { - .cmd = OPLUS_SCORE_CMD_DOWNLINK, - .flags = 0, - .doit = oplus_score_netlink_rcv_msg, - .dumpit = NULL, - }, -}; - -static struct genl_family oplus_score_genl_family = -{ - .id = 0, - .hdrsize = 0, - .name = OPLUS_SCORE_FAMILY_NAME, - .version = OPLUS_SCORE_FAMILY_VERSION, - .maxattr = OPLUS_SCORE_MSG_MAX, - .ops = oplus_score_genl_ops, - .n_ops = ARRAY_SIZE(oplus_score_genl_ops), -}; - -static int oplus_score_send_netlink_msg(int msg_type, char *payload, int payload_len); -/* score = 100 - rtt * 10 / 500 - 100 * loss_rate * 8*/ - -static s32 oplus_get_smooth_score(int link, int flag) -{ - int i; - int j = 0; - u32 score_sum = 0; - if (flag) { - for (i = 0; i < SCORE_WINDOW; i++) { - if (uplink_score_info[link].uplink_score_save[i] > 0) { - score_sum += uplink_score_info[link].uplink_score_save[i]; - j++; - } - } - } else { - for (i = 0; i < SCORE_WINDOW; i++) { - if (downlink_score_info[link].downlink_score_save[i] > 0) { - score_sum += downlink_score_info[link].downlink_score_save[i]; - j++; - } - } - } - - if (j == 0) { - return -1; - } else { - return score_sum / j; - } -} - -static int oplus_update_score_count(int link, int score, int flag) -{ - int ret = OPLUS_FALSE; - if (score == -1) { - return OPLUS_TRUE; - } - - if (flag) { - if(score > WORSE_BASE_SCORE) { - uplink_score_info[link].uplink_score_count++; - if (uplink_score_info[link].uplink_score_count > SCORE_KEEP) { - uplink_score_info[link].uplink_score_count = SCORE_KEEP; - } - } - else if (score <= WORST_BASE_SCORE && score >= 0) { - uplink_score_info[link].uplink_score_count--; - if (uplink_score_info[link].uplink_score_count < -SCORE_KEEP) { - uplink_score_info[link].uplink_score_count = -SCORE_KEEP; - } - } - - if (((score > WORST_BASE_SCORE) && (uplink_score_info[link].uplink_score_count >= 0)) || - ((score <= WORST_BASE_SCORE) && (uplink_score_info[link].uplink_score_count <= 0))) { - ret = OPLUS_TRUE; - } - - if (oplus_score_debug) { - printk("[oplus_score]:uplink_report=%d,score=%d,score_count=%d\n", - ret, score, uplink_score_info[link].uplink_score_count); - } - } else { - if(score > WORSE_BASE_SCORE) { - downlink_score_info[link].downlink_score_count++; - if (downlink_score_info[link].downlink_score_count > SCORE_KEEP) { - downlink_score_info[link].downlink_score_count = SCORE_KEEP; - } - } - else if (score <= WORST_BASE_SCORE && score >= 0) { - downlink_score_info[link].downlink_score_count--; - if (downlink_score_info[link].downlink_score_count < -SCORE_KEEP) { - downlink_score_info[link].downlink_score_count = -SCORE_KEEP; - } - } - - if (((score <= WORST_BASE_SCORE) && (downlink_score_info[link].downlink_score_count <= 0)) || - ((score > WORST_BASE_SCORE) && (downlink_score_info[link].downlink_score_count >= 0))) { - ret = OPLUS_TRUE; - } - - if (oplus_score_debug) { - printk("[oplus_score]:downlink_report=%d,score=%d,score_count=%d\n", - ret, score, downlink_score_info[link].downlink_score_count); - } - } - - return ret; -} - -void oplus_score_calc_and_report(void) -{ - struct link_score_msg_st link_score_msg; - int i; - u32 uplink_index, downlink_index; - u32 uplink_packets, uplink_retrans_packets, uplink_srtt; - u32 downlink_packets, downlink_retrans_packets, downlink_srtt; - s32 uplink_score, downlink_score; - u32 uplink_seq, downlink_seq; - u32 retrans_rate = 0; - s32 uplink_smooth_score, downlink_smooth_score; - u32 index = 0; - int uplink_report, downlink_report; - char ifname[IFNAME_LEN]; - u32 uplink_nodata_count; - u32 downlink_nodata_count; - int downlink_rate = 0; - u32 uplink_total_packets = 0; - u32 downlink_total_packets = 0; - - /* printk("[oplus_score]:enter oplus_score_calc_and_report,jiffies=%llu\n", jiffies);*/ - for (i = 0; i < MAX_LINK_NUM; i++) { - uplink_smooth_score = -1; - downlink_smooth_score = -1; - uplink_report = 0; - downlink_report = 0; - spin_lock_bh(&downlink_score_lock); - if (downlink_score_info[i].link_index == 0) { - spin_unlock_bh(&downlink_score_lock); - continue; - } - downlink_index = downlink_score_info[i].link_index; - downlink_packets = downlink_score_info[i].downlink_packets; - downlink_retrans_packets = downlink_score_info[i].downlink_retrans_packets; - downlink_total_packets = downlink_packets + downlink_retrans_packets; - downlink_srtt = downlink_score_info[i].downlink_srtt; - downlink_seq = downlink_score_info[i].seq; - downlink_score_info[i].downlink_packets = 0; - downlink_score_info[i].downlink_retrans_packets = 0; - /*downlink_score_info[i].downlink_srtt = 0;*/ - downlink_score_info[i].downlink_rtt_num = 1; - downlink_nodata_count = downlink_score_info[i].downlink_nodata_count; - spin_unlock_bh(&downlink_score_lock); - - spin_lock_bh(&uplink_score_lock); - if (uplink_score_info[i].link_index == 0) { - spin_unlock_bh(&uplink_score_lock); - continue; - } - uplink_index = uplink_score_info[i].link_index; - if (uplink_index != downlink_index) { - printk("[oplus_score]:link error:uplink_index=%u,downlink_index=%u\n", - uplink_index, downlink_index); - spin_unlock_bh(&uplink_score_lock); - continue; - } - memcpy((void*)ifname, (void*)uplink_score_info[i].ifname, IFNAME_LEN); - uplink_packets = uplink_score_info[i].uplink_packets; - uplink_retrans_packets = uplink_score_info[i].uplink_retrans_packets; - uplink_total_packets = uplink_packets + uplink_retrans_packets; - uplink_srtt = uplink_score_info[i].uplink_srtt; - uplink_seq = uplink_score_info[i].seq; - uplink_nodata_count = uplink_score_info[i].uplink_nodata_count; - uplink_score_info[i].uplink_packets = 0; - uplink_score_info[i].uplink_retrans_packets = 0; - /*uplink_score_info[i].uplink_srtt = 0;*/ - if (uplink_score_info[i].uplink_rtt_num) { - uplink_score_info[i].uplink_rtt_num = 1; - } - - if (uplink_total_packets == 0) { - if (oplus_score_debug) { - printk("[oplus_score]:uplink no_data\n"); - } - uplink_score = -1; - uplink_score_info[i].uplink_nodata_count++; - } else { - uplink_score_info[i].uplink_nodata_count = 0; - retrans_rate = 100 * uplink_retrans_packets / uplink_total_packets; - if (uplink_packets > ((para_rate * PACKET_PER_SEC) >> 3)) { - uplink_score = (s32)(GOOD_BASE_SCORE - (retrans_rate * para_loss) / 8); - } /*else if (uplink_srtt > BAD_GAME_RTT_THREAD && (uplink_total_packets < 10) && (downlink_total_packets < 10)) { - uplink_score = (s32)(WORST_BASE_SCORE - (WORST_BASE_SCORE * retrans_rate * para_loss) / 800); - } */else { - if (uplink_srtt > WORST_VIDEO_RTT_THRESH) { - uplink_score = (s32)(WORST_BASE_SCORE - (WORST_BASE_SCORE * retrans_rate * para_loss) / 800); - } else if (uplink_srtt > WORST_RTT_THRESH) { - downlink_rate = downlink_packets * 1000 / uplink_srtt; - if (downlink_rate == 0) { - uplink_score = -1; - } else if (downlink_rate > VIDEO_GOOD_RATE) { - uplink_score = (s32)(GOOD_BASE_SCORE - (GOOD_BASE_SCORE * retrans_rate * para_loss) / 800); - } else if (downlink_rate > PACKET_PER_SEC) { - uplink_score = (s32)(NORMAL_BASE_SCORE - (NORMAL_BASE_SCORE * retrans_rate * para_loss) / 800); - } else { - uplink_score = (s32)(WORST_BASE_SCORE - (WORST_BASE_SCORE * retrans_rate * para_loss) / 800); - } - } else if (uplink_srtt > WORSE_RTT_THRESH) { - uplink_score = (s32)(WORSE_BASE_SCORE - (WORSE_BASE_SCORE * retrans_rate * para_loss) / 800); - } else if (uplink_srtt > NORMAL_RTT_THRESH) { - uplink_score = (s32)(NORMAL_BASE_SCORE - (NORMAL_BASE_SCORE * retrans_rate * para_loss) / 800); - } else { - uplink_score = (s32)(GOOD_BASE_SCORE - (retrans_rate * para_loss) / 8); - } - } - if (uplink_score <= 0) { - uplink_score = 1; - } - } - - uplink_report = oplus_update_score_count(i, uplink_score, OPLUS_UPLINK); - if (uplink_report) { - index = uplink_score_info[i].uplink_score_index++ % SCORE_WINDOW; - uplink_score_info[i].uplink_score_save[index] = uplink_score; - } - uplink_smooth_score = oplus_get_smooth_score(i, OPLUS_UPLINK); - if (uplink_smooth_score == -1) { - uplink_report = 0; - } - spin_unlock_bh(&uplink_score_lock); - - if (oplus_score_debug || (uplink_smooth_score > 0 && uplink_smooth_score <= WORST_BASE_SCORE)) { - if (net_ratelimit()) - printk("[oplus_score]:up_score:link=%u,if=%s,up_pack=%u,up_retran=%u,up_rtt=%u,score=%d,s_score=%d,seq=%u,uid=%u,retrans_rate=%u,index=%u,nodata=%u\n", - uplink_index, ifname, uplink_packets, uplink_retrans_packets, uplink_srtt, uplink_score, - uplink_smooth_score, uplink_seq, oplus_score_foreground_uid[0], retrans_rate, index, uplink_nodata_count); - } - - /*start downlink score calc*/ - if (downlink_total_packets == 0) { - if (oplus_score_debug) { - printk("[oplus_score]:downlink no_data,if=%s\n", ifname); - } - downlink_score = -1; - downlink_score_info[i].downlink_nodata_count++; - } else { - downlink_score_info[i].downlink_nodata_count = 0; - retrans_rate = 100 * downlink_retrans_packets / downlink_total_packets; - if (downlink_packets > ((para_rate * PACKET_PER_SEC) >> 3)) { - downlink_score = (s32)(GOOD_BASE_SCORE - retrans_rate * para_loss / 4); - } else { - if (uplink_srtt > WORST_RTT_THRESH) { - downlink_score = (s32)(WORST_BASE_SCORE - (WORST_BASE_SCORE * retrans_rate * para_loss) / 800); - } else { - downlink_score = (s32)(100 - (2 * downlink_retrans_packets * uplink_srtt) / 10); - } - } - - if (downlink_score < 0) { - downlink_score = 1; - } - } - - if ((downlink_total_packets < 15) && (downlink_score > WORST_BASE_SCORE)) { - downlink_score = -1; - } - - spin_lock_bh(&downlink_score_lock); - downlink_report = oplus_update_score_count(i, downlink_score, OPLUS_DOWNLINK); - if (downlink_report) { - index = downlink_score_info[i].downlink_score_index++ % SCORE_WINDOW; - downlink_score_info[i].downlink_score_save[index] = downlink_score; - } - downlink_smooth_score = oplus_get_smooth_score(i, OPLUS_DOWNLINK); - if (downlink_smooth_score == -1) { - downlink_report = 0; - } - spin_unlock_bh(&downlink_score_lock); - - if (oplus_score_debug || (downlink_smooth_score > 0 && downlink_smooth_score <= WORST_BASE_SCORE)) { - if (net_ratelimit()) - printk("[oplus_score]:down_score:link=%u,if=%s,down_pack=%u,down_retran=%u,rtt=%u,score=%d,s_score=%d,seq=%u,uid=%u,retrans_rate=%u,index=%u,nodata=%u\n", - downlink_index, ifname, downlink_packets, downlink_retrans_packets, uplink_srtt, downlink_score, - downlink_smooth_score, downlink_seq, oplus_score_foreground_uid[0], retrans_rate, index, downlink_nodata_count); - } - - if (uplink_report || downlink_report) { - link_score_msg.link_index = uplink_index; - if (uplink_smooth_score == -1) { - link_score_msg.uplink_score = downlink_smooth_score; - } else { - link_score_msg.uplink_score = uplink_smooth_score; - } - - if (downlink_smooth_score == -1) { - link_score_msg.downlink_score = uplink_smooth_score; - } else { - link_score_msg.downlink_score = downlink_smooth_score; - } - - oplus_score_send_netlink_msg(OPLUS_SCORE_MSG_REPORT_NETWORK_SCORE, (char *)&link_score_msg, sizeof(link_score_msg)); - if (oplus_score_debug || (downlink_smooth_score <= WORST_BASE_SCORE) || (uplink_smooth_score <= WORST_BASE_SCORE)) { - if (net_ratelimit()) - printk("[oplus_score]:report_score1:link=%u,if=%s,up_score=%d,down_score=%d,uid=%u,ul_p=%d,dl_p=%d\n", - uplink_index, ifname, link_score_msg.uplink_score, link_score_msg.downlink_score, - oplus_score_foreground_uid[0], uplink_report, downlink_report); - } - } - - if (oplus_score_debug) { - printk("[oplus_score]:report_score_all:link=%u,uplink_score=%d,us_score=%d,downlink_score=%d,ds_score=%d,uid=%u,ul_p=%d,dl_p=%d\n", - uplink_index, uplink_score, uplink_smooth_score, downlink_score, - downlink_smooth_score, oplus_score_foreground_uid[0], uplink_report, downlink_report); - } - } - - return; -} - -static void oplus_score_report_timer_function(struct timer_list *t) -{ - oplus_score_calc_and_report(); - mod_timer(&oplus_score_report_timer, jiffies + REPORT_PERIOD * HZ); -} - -static void oplus_score_report_timer_init(void) -{ - printk("[oplus_score]:report_timer_init\n"); - timer_setup(&oplus_score_report_timer, oplus_score_report_timer_function, 0); -} - -static void oplus_score_report_timer_start(void) -{ - printk("[oplus_score]:report_timer_start\n"); - /*oplus_score_report_timer.function = (void *)oplus_score_report_timer_function;*/ - oplus_score_report_timer.expires = jiffies + REPORT_PERIOD * HZ; - mod_timer(&oplus_score_report_timer, oplus_score_report_timer.expires); -} - -static void oplus_score_report_timer_del(void) -{ - printk("[oplus_score]:report_timer_del\n"); - del_timer_sync(&oplus_score_report_timer); -} - -static inline int genl_msg_prepare_usr_msg(u8 cmd, size_t size, pid_t pid, struct sk_buff **skbp) -{ - struct sk_buff *skb; - /* create a new netlink msg */ - skb = genlmsg_new(size, GFP_ATOMIC); - if (skb == NULL) { - return -ENOMEM; - } - - /* Add a new netlink message to an skb */ - genlmsg_put(skb, pid, 0, &oplus_score_genl_family, 0, cmd); - *skbp = skb; - return 0; -} - -static inline int genl_msg_mk_usr_msg(struct sk_buff *skb, int type, void *data, int len) -{ - int ret; - /* add a netlink attribute to a socket buffer */ - if ((ret = nla_put(skb, type, len, data)) != 0) { - return ret; - } - - return 0; -} - -static inline int uplink_get_array_index_by_link_index(int link_index) -{ - int array_index = -1; - int i; - - for (i = 0; i < MAX_LINK_NUM; i++) { - if (uplink_score_info[i].link_index == link_index) { - return i; - } - } - - return array_index; -} - -static inline int downlink_get_array_index_by_link_index(int link_index) -{ - int array_index = -1; - int i; - - for (i = 0; i < MAX_LINK_NUM; i++) { - if (downlink_score_info[i].link_index == link_index) { - return i; - } - } - - return array_index; -} - -static inline int is_foreground_uid(int uid) -{ - int i; - for (i = 0; i < FOREGROUND_UID_MAX_NUM; i++) { - if (uid == oplus_score_foreground_uid[i]) { - return OPLUS_TRUE; - } - } - - return OPLUS_FALSE; -} - -/* send to user space */ -static int oplus_score_send_netlink_msg(int msg_type, char *payload, int payload_len) -{ - int ret = 0; - void * head; - struct sk_buff *skbuff; - size_t size; - - if (!oplus_score_user_pid) { - printk("[oplus_score]: oplus_score_send_netlink_msg,oplus_score_user_pid=0\n"); - return -1; - } - - /* allocate new buffer cache */ - size = nla_total_size(payload_len); - ret = genl_msg_prepare_usr_msg(OPLUS_SCORE_CMD_DOWNLINK, size, oplus_score_user_pid, &skbuff); - if (ret) { - return ret; - } - - ret = genl_msg_mk_usr_msg(skbuff, msg_type, payload, payload_len); - if (ret) { - kfree_skb(skbuff); - return ret; - } - - head = genlmsg_data(nlmsg_data(nlmsg_hdr(skbuff))); - genlmsg_end(skbuff, head); - - /* send data */ - ret = genlmsg_unicast(&init_net, skbuff, oplus_score_user_pid); - if(ret < 0) { - printk("[oplus_score]:oplus_score_send_netlink_msg error, ret = %d\n", ret); - return -1; - } - - return 0; -} - -static void oplus_score_uplink_stat(struct sk_buff *skb) -{ - int link_index; - int i; - struct sock *sk; - struct tcp_sock *tp; - struct tcphdr *tcph = tcp_hdr(skb); - struct inet_connection_sock *icsk; - u32 srtt; - - sk = skb_to_full_sk(skb); - tp = tcp_sk(sk); - icsk = inet_csk(sk); - link_index = skb->dev->ifindex; - - spin_lock_bh(&uplink_score_lock); - i = uplink_get_array_index_by_link_index(link_index); - if (i < 0) { - if (oplus_score_debug) { - printk("[oplus_score]:upskb_linkerr,link=%d,if=%s,seq=%u,ack=%u,sport=%u,dport=%u,uid=%u\n", - link_index, skb->dev->name, ntohl(tcph->seq), ntohl(tcph->ack_seq), ntohs(tcph->source), - ntohs(tcph->dest), (u32)(sk->sk_uid.val)); - } - spin_unlock_bh(&uplink_score_lock); - return; - } - - if (icsk->icsk_ca_state >= TCP_CA_Recovery && tp->high_seq !=0 && before(ntohl(tcph->seq), tp->high_seq)) { - uplink_score_info[i].uplink_retrans_packets++; - } else { - uplink_score_info[i].uplink_packets++; - } - if (oplus_score_debug) { - printk("[oplus_score]:uplink=%d,if=%s,seq=%u,high_seq=%u,uplink_retran=%u,npacket=%u,uid=%u,sport=%u,dport=%u,state=%d,len=%u\n", - link_index, skb->dev->name, ntohl(tcph->seq), tp->high_seq, uplink_score_info[i].uplink_retrans_packets, - uplink_score_info[i].uplink_packets, (u32)(sk->sk_uid.val), ntohs(tcph->source), - ntohs(tcph->dest), sk->sk_state, skb->len); - } - - uplink_score_info[i].seq = ntohl(tcph->seq); - srtt = (tp->srtt_us >> 3) / 1000; - if (oplus_score_debug) { - printk("[oplus_score]:rtt_sample_up:rtt=%u,rtt_num=%u,uid=%u\n", - srtt, uplink_score_info[i].uplink_rtt_num, (u32)(sk->sk_uid.val)); - } - - if (srtt > VALID_RTT_THRESH) { - uplink_score_info[i].uplink_rtt_num++; - if (uplink_score_info[i].uplink_rtt_num != 0) { - uplink_score_info[i].uplink_srtt = - (uplink_score_info[i].uplink_srtt * (uplink_score_info[i].uplink_rtt_num -1) + srtt) / uplink_score_info[i].uplink_rtt_num; - uplink_score_info[i].uplink_rtt_stamp = (u32)jiffies; - } - } - spin_unlock_bh(&uplink_score_lock); - - return; -} - - -static int is_downlink_retrans_pack(u32 skb_seq, struct sock *sk) -{ - struct tcp_sock *tp = (struct tcp_sock*)sk; - struct inet_connection_sock *icsk = inet_csk(sk); - u32 now = (u32)jiffies; - - if((skb_seq == tp->rcv_nxt) && (!RB_EMPTY_ROOT(&tp->out_of_order_queue))) { - int m = (int)(now - icsk->icsk_ack.lrcvtime) * 1000 / HZ; - int half_rtt = (tp->srtt_us / 8000) >> 1; - if ((tp->srtt_us != 0) && (m > 50)) { - if (oplus_score_debug) { - printk("[oplus_score]:now=%u,lrcttime=%u,half_rtt=%d,m=%d,Hz=%u,rtt=%u,seq=%u\n", - now, icsk->icsk_ack.lrcvtime, half_rtt, m, HZ, tp->srtt_us, skb_seq); - } - return OPLUS_TRUE; - } - } - - return OPLUS_FALSE; -} - -static void oplus_score_downlink_stat(struct sk_buff *skb) -{ - int link_index; - int i; - struct sock *sk; - struct tcp_sock *tp; - struct tcphdr *tcph = tcp_hdr(skb); - struct inet_connection_sock *icsk; - u32 srtt; - - sk = skb_to_full_sk(skb); - tp = tcp_sk(sk); - icsk = inet_csk(sk); - link_index = skb->dev->ifindex; - - spin_lock_bh(&downlink_score_lock); - i = downlink_get_array_index_by_link_index(link_index); - if (i < 0) { - if (oplus_score_debug) { - printk("[oplus_score]:downskb_linkerr,link=%d,if=%s,seq=%u,ack=%u,sport=%u,dport=%u,uid=%u\n", - link_index, skb->dev->name, ntohl(tcph->seq), ntohl(tcph->ack_seq), ntohs(tcph->source), - ntohs(tcph->dest), (u32)(sk->sk_uid.val)); - } - spin_unlock_bh(&downlink_score_lock); - return; - } - - if ((sk->sk_state != TCP_SYN_SENT) && (is_downlink_retrans_pack(ntohl(tcph->seq), sk))) { - downlink_score_info[i].downlink_retrans_packets++; - } else { - downlink_score_info[i].downlink_packets++; - } - if (oplus_score_debug) { - printk("[oplus_score]:downlink=%d,if=%s,seq=%u,rcv_nxt=%u,downlink_retran=%u,npacket=%u,uid=%u,sport=%u,dport=%u,state=%d,len=%u\n", - link_index, skb->dev->name, ntohl(tcph->seq), tp->rcv_nxt, downlink_score_info[i].downlink_retrans_packets, - downlink_score_info[i].downlink_packets, (u32)(sk->sk_uid.val), ntohs(tcph->source), - ntohs(tcph->dest), sk->sk_state, skb->len); - } - - downlink_score_info[i].seq = ntohl(tcph->seq); - srtt = (tp->rcv_rtt_est.rtt_us >> 3) / 1000; - if (oplus_score_debug) { - printk("[oplus_score]:rtt_sample_down:rtt=%u,rtt_num=%u,uid=%u\n", - srtt, downlink_score_info[i].downlink_rtt_num, (u32)(sk->sk_uid.val)); - } - - if (srtt) { - downlink_score_info[i].downlink_rtt_num++; - if (downlink_score_info[i].downlink_rtt_num != 0) { - downlink_score_info[i].downlink_srtt = - (downlink_score_info[i].downlink_srtt * (downlink_score_info[i].downlink_rtt_num -1) + srtt) / downlink_score_info[i].downlink_rtt_num; - } - downlink_score_info[i].downlink_update_stamp = (u32)jiffies; - } - spin_unlock_bh(&downlink_score_lock); - - return; -} - -uid_t get_uid_from_sock(const struct sock *sk) -{ - uid_t sk_uid; - #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - const struct file *filp = NULL; - #endif - if (NULL == sk || !sk_fullsock(sk) || NULL == sk->sk_socket) { - return 0; - } - #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)) - filp = sk->sk_socket->file; - if (NULL == filp) { - return 0; - } - sk_uid = __kuid_val(filp->f_cred->fsuid); - #else - sk_uid = __kuid_val(sk->sk_uid); - #endif - return sk_uid; -} - -static inline int skb_v4_check(struct sk_buff *skb) -{ - uid_t sk_uid; - struct sock *sk; - struct iphdr *iph = NULL; - struct tcphdr *tcph = NULL; - struct net_device *dev; - - iph = ip_hdr(skb); - tcph = tcp_hdr(skb); - if (skb->protocol != htons(ETH_P_IP) || (!iph)) - return OPLUS_FALSE; - - if (iph->protocol != IPPROTO_TCP || !tcph) - return OPLUS_FALSE; - - sk = skb_to_full_sk(skb); - if (!sk) { - return OPLUS_FALSE; - } - - if (sk->sk_state > TCP_SYN_SENT) { - return OPLUS_FALSE; - } - - /* skb is pure ack*/ - if ((ntohs(iph ->tot_len) == (iph->ihl + tcph->doff) * 4) && (!tcph->syn || !tcph->fin)) - return OPLUS_FALSE; - - sk_uid = get_uid_from_sock(sk); - if(sk_uid == 0) { - return OPLUS_FALSE; - } - - /* check uid is foreground*/ - if (!is_foreground_uid(sk_uid)) - return OPLUS_FALSE; - - dev = skb->dev; - if (!dev) { - return OPLUS_FALSE; - } - - return OPLUS_TRUE; -} - -static inline int skb_v6_check(struct sk_buff *skb) -{ - uid_t sk_uid; - struct sock *sk; - struct tcphdr *tcph = NULL; - struct ipv6hdr *ipv6h = NULL; - struct net_device *dev; - - ipv6h = ipv6_hdr(skb); - tcph = tcp_hdr(skb); - if (skb->protocol != htons(ETH_P_IPV6) || (!ipv6h)) - return OPLUS_FALSE; - - if ((ipv6h->nexthdr != NEXTHDR_TCP) || (!tcph)) - return OPLUS_FALSE; - - sk = skb_to_full_sk(skb); - if (!sk) { - return OPLUS_FALSE; - } - - if (sk->sk_state > TCP_SYN_SENT) { - return OPLUS_FALSE; - } - - /* skb is pure ack*/ - if ((ntohs(ipv6h ->payload_len) == tcph->doff * 4) && (!tcph->syn || !tcph->fin)) - return OPLUS_FALSE; - - /* check uid is foreground*/ - sk_uid = get_uid_from_sock(sk); - if (!is_foreground_uid(sk_uid)) - return OPLUS_FALSE; - - dev = skb->dev; - if (!dev) { - return OPLUS_FALSE; - } - - return OPLUS_TRUE; -} - -static unsigned int oplus_score_postrouting_hook4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - if (!oplus_score_enable_flag) - return NF_ACCEPT; - - if (skb_v4_check(skb) == OPLUS_FALSE) { - return NF_ACCEPT; - } - - oplus_score_uplink_stat(skb); - - return NF_ACCEPT; -} - -static unsigned int oplus_score_postrouting_hook6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - if (!oplus_score_enable_flag) - return NF_ACCEPT; - - if (skb_v6_check(skb) == OPLUS_FALSE) { - return NF_ACCEPT; - } - - oplus_score_uplink_stat(skb); - - return NF_ACCEPT; -} - -static unsigned int oplus_score_input_hook4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - if (!oplus_score_enable_flag) { - return NF_ACCEPT; - } - - if (skb_v4_check(skb) == OPLUS_FALSE) { - return NF_ACCEPT; - } - - oplus_score_downlink_stat(skb); - - return NF_ACCEPT; -} - -static unsigned int oplus_score_input_hook6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) -{ - if (!oplus_score_enable_flag) - return NF_ACCEPT; - - if (skb_v6_check(skb) == OPLUS_FALSE) - return NF_ACCEPT; - - oplus_score_downlink_stat(skb); - - return NF_ACCEPT; -} - -static struct nf_hook_ops oplus_score_netfilter_ops[] __read_mostly = -{ - { - .hook = oplus_score_postrouting_hook4, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP_PRI_FILTER + 1, - }, - { - .hook = oplus_score_input_hook4, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER + 1, - }, - { - .hook = oplus_score_postrouting_hook6, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP_PRI_FILTER + 1, - }, - { - .hook = oplus_score_input_hook6, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_FILTER + 1, - }, -}; - -static void oplus_score_enable(struct nlattr *nla) -{ - u32 *data = (u32*)NLA_DATA(nla); - oplus_score_enable_flag = data[0]; - printk("[oplus_score]:oplus_score_enable_flag = %u", oplus_score_enable_flag); - return; -} - -static void oplus_score_set_foreground_uid(struct nlattr *nla) -{ - u32 *data; - int i, num; - - data = (u32 *)NLA_DATA(nla); - num = data[0]; - if (num <= 0 || num > FOREGROUND_UID_MAX_NUM) { - printk("[oplus_score]: foreground uid num out of range, num = %d", num); - return; - } - - memset(oplus_score_foreground_uid, 0, sizeof(oplus_score_foreground_uid)); - for (i = 0; i < num; i++) { - oplus_score_foreground_uid[i] = data[i + 1]; - printk("[oplus_score]: add uid, num = %d, index = %d, uid=%u\n", num, i, data[i + 1]); - } - - /* forground uid change, so reset score static */ - spin_lock_bh(&uplink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - uplink_score_info[i].uplink_retrans_packets = 0; - uplink_score_info[i].uplink_packets = 0; - uplink_score_info[i].uplink_nodata_count = 0; - /*uplink_score_info[i].uplink_score = MAX_LINK_SCORE;*/ - if (uplink_score_info[i].uplink_rtt_num) { - uplink_score_info[i].uplink_rtt_num = 1; - } - } - spin_unlock_bh(&uplink_score_lock); - - spin_lock_bh(&downlink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - downlink_score_info[i].downlink_retrans_packets = 0; - downlink_score_info[i].downlink_packets = 0; - downlink_score_info[i].downlink_nodata_count = 0; - /*downlink_score_info[i].downlink_score = MAX_LINK_SCORE;*/ - } - spin_unlock_bh(&downlink_score_lock); - - return; -} - -static void oplus_score_request_score(struct nlattr *nla) -{ - u32 *data; - u32 link_index; - int i; - - struct link_score_msg_st link_score_msg; - data = (u32 *)NLA_DATA(nla); - link_index = data[0]; - - spin_lock_bh(&uplink_score_lock); - i = uplink_get_array_index_by_link_index(link_index); - if (i < 0) { - /* printk("[oplus_score]:uplink get index falure!\n"); */ - spin_unlock_bh(&uplink_score_lock); - return; - } - link_score_msg.uplink_score = oplus_get_smooth_score(link_index, OPLUS_UPLINK); - spin_unlock_bh(&uplink_score_lock); - - spin_lock_bh(&downlink_score_lock); - i = downlink_get_array_index_by_link_index(link_index); - if (i < 0) { - /* printk("[oplus_score]:downlink get index falure!\n");*/ - spin_unlock_bh(&downlink_score_lock); - return; - } - link_score_msg.downlink_score = oplus_get_smooth_score(link_index, OPLUS_DOWNLINK); - spin_unlock_bh(&downlink_score_lock); - - link_score_msg.link_index = link_index; - printk("[oplus_score]:request_report:link=%d,uscore=%d,dscore=%d\n", link_index, link_score_msg.uplink_score, link_score_msg.downlink_score); - oplus_score_send_netlink_msg(OPLUS_SCORE_MSG_REPORT_NETWORK_SCORE, (char *)&link_score_msg, sizeof(link_score_msg)); - return; -} - -static void oplus_score_add_uplink(u32 link_index, struct net_device *dev) -{ - int i, j; - if (oplus_score_uplink_num == MAX_LINK_NUM) { - printk("[oplus_score]:error, uplink num reach max.\n"); - return; - } - - for (i = 0; i < MAX_LINK_NUM; i++) { - if (uplink_score_info[i].link_index == link_index) { - printk("[oplus_score]:warning,uplink already exist,index = %u.\n", link_index); - return; - } - } - - for (i =0; i < MAX_LINK_NUM; i++) { - if (uplink_score_info[i].link_index != 0) - continue; - - memset(&uplink_score_info[i], 0, sizeof(struct uplink_score_info_st)); - uplink_score_info[i].link_index = link_index; - memcpy((void*)uplink_score_info[i].ifname, (void*)dev->name, IFNAME_LEN); - for (j = 0; j < SCORE_WINDOW; j++) { - uplink_score_info[i].uplink_score_save[j] = -1; - } - oplus_score_uplink_num++; - printk("[oplus_score]:up:add_link finish,link_index=%u,i=%d,link_num=%u", link_index, i, oplus_score_uplink_num); - break; - } - - return; -} - -static void oplus_score_add_downlink(u32 link_index, struct net_device *dev) -{ - int i, j; - if (oplus_score_downlink_num == MAX_LINK_NUM) { - printk("[oplus_score]:error, downlink num reach max.\n"); - return; - } - - for (i = 0; i < MAX_LINK_NUM; i++) { - if (downlink_score_info[i].link_index == link_index) { - printk("[oplus_score]:warning,downlink already exist,index = %u.\n", link_index); - return; - } - } - - for (i =0; i < MAX_LINK_NUM; i++) { - if (downlink_score_info[i].link_index != 0) - continue; - - memset(&downlink_score_info[i], 0, sizeof(struct downlink_score_info_st)); - downlink_score_info[i].link_index = link_index; - memcpy((void*)uplink_score_info[i].ifname, (void*)dev->name, IFNAME_LEN); - for (j = 0; j < SCORE_WINDOW; j++) { - downlink_score_info[i].downlink_score_save[j] = -1; - } - oplus_score_downlink_num++; - printk("[oplus_score]:down:add_link finish,link_index=%u,i=%d,link_num=%u", link_index, i, oplus_score_downlink_num); - break; - } -} - -static void oplus_score_add_link(struct nlattr *nla) -{ - u32 *data; - u32 link_index; - struct net_device *dev; - - data = (u32 *)NLA_DATA(nla); - link_index = data[0]; - - if (link_index == 0) { - printk("[oplus_score]:error, link index is 0!\n"); - return; - } - - dev = dev_get_by_index(&init_net, link_index); - if(!dev) { - printk("[oplus_score]:dev is null,index=%d\n", link_index); - return; - } - - printk("[oplus_score]:to add_link index=%u,dev_name=%s, uplink_num=%d,downlink_num=%d!\n", - link_index, dev->name, oplus_score_uplink_num, oplus_score_downlink_num); - - spin_lock_bh(&uplink_score_lock); - oplus_score_add_uplink(link_index, dev); - spin_unlock_bh(&uplink_score_lock); - - spin_lock_bh(&downlink_score_lock); - oplus_score_add_downlink(link_index, dev); - spin_unlock_bh(&downlink_score_lock); - - dev_put(dev); - - return; -} - -static void oplus_score_del_link(struct nlattr *nla) -{ - u32 *data; - u32 i, j, link_index; - - data = (u32 *)NLA_DATA(nla); - link_index = data[0]; - - printk("[oplus_score]:to del_link index=%u,uplink_num=%d,downlink_num=%d!\n", - link_index, oplus_score_uplink_num, oplus_score_downlink_num); - - if (link_index == 0) { - printk("[oplus_score]:error, link index is 0!\n"); - return; - } - - spin_lock_bh(&uplink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - if (uplink_score_info[i].link_index == link_index) { - memset(&uplink_score_info[i], 0, sizeof(struct uplink_score_info_st)); - oplus_score_uplink_num--; - } - } - spin_unlock_bh(&uplink_score_lock); - - spin_lock_bh(&downlink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - if (downlink_score_info[i].link_index == link_index) { - memset(&downlink_score_info[i], 0, sizeof(struct downlink_score_info_st)); - oplus_score_downlink_num--; - } - } - spin_unlock_bh(&downlink_score_lock); - - return; -} - -static void oplus_score_clear_link(struct nlattr *nla) -{ - int i, j; - - spin_lock_bh(&uplink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - memset(&uplink_score_info[i], 0, sizeof(struct uplink_score_info_st)); - } - oplus_score_uplink_num = 0; - spin_unlock_bh(&uplink_score_lock); - - spin_lock_bh(&downlink_score_lock); - for (i = 0; i < MAX_LINK_NUM; i++) { - memset(&downlink_score_info[i], 0, sizeof(struct downlink_score_info_st)); - } - oplus_score_downlink_num = 0; - spin_unlock_bh(&downlink_score_lock); - - return; -} - -static void oplus_score_config(struct nlattr *nla) -{ - struct score_param_st *config; - config = (struct score_param_st*)NLA_DATA(nla); - oplus_score_param_info = *config; - oplus_score_debug = oplus_score_param_info.score_debug; - return; -} - -static int oplus_score_netlink_rcv_msg(struct sk_buff *skb, struct genl_info *info) -{ - int ret = 0; - struct nlmsghdr *nlhdr; - struct genlmsghdr *genlhdr; - struct nlattr *nla; - - nlhdr = nlmsg_hdr(skb); - genlhdr = nlmsg_data(nlhdr); - nla = genlmsg_data(genlhdr); - - if (oplus_score_user_pid == 0) { - oplus_score_user_pid = nlhdr->nlmsg_pid; - if (oplus_score_debug) { - printk("[oplus_score]:set oplus_score_user_pid=%u.\n", oplus_score_user_pid); - } - } - - /* to do: may need to some head check here*/ - if (oplus_score_debug) { - printk("[oplus_score]:score_netlink_rcv_msg type=%u.\n", nla->nla_type); - } - switch (nla->nla_type) { - case OPLUS_SCORE_MSG_ENABLE: - oplus_score_enable(nla); - break; - case OPLUS_SCORE_MSG_FOREGROUND_ANDROID_UID: - oplus_score_set_foreground_uid(nla); - break; - case OPLUS_SCORE_MSG_REQUEST_SCORE: - oplus_score_request_score(nla); - break; - case OPLUS_SCORE_MSG_ADD_LINK: - oplus_score_add_link(nla); - break; - case OPLUS_SCORE_MSG_DEL_LINK: - oplus_score_del_link(nla); - break; - case OPLUS_SCORE_MSG_CLEAR_LINK: - oplus_score_clear_link(nla); - break; - case OPLUS_SCORE_MSG_CONFIG: - oplus_score_config(nla); - break; - default: - return -EINVAL; - } - - return ret; -} - -static int oplus_score_netlink_init(void) -{ - int ret; - ret = genl_register_family(&oplus_score_genl_family); - if (ret) { - printk("[oplus_score]:genl_register_family:%s failed,ret = %d\n", OPLUS_SCORE_FAMILY_NAME, ret); - return ret; - } else { - printk("[oplus_score]:genl_register_family complete, id = %d!\n", oplus_score_genl_family.id); - } - - return 0; -} - -static void oplus_score_netlink_exit(void) -{ - genl_unregister_family(&oplus_score_genl_family); -} - -static int proc_set_test_foreground_uid(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp,loff_t *ppos) -{ - int ret; - u32 data[3]; - struct nlattr *nla = (struct nlattr*)data; - - ret = proc_dointvec(ctl, write, buffer, lenp, ppos); - printk("[oplus_score]:proc_set_test_foreground_uid,write=%d,ret=%d\n", write, ret); - if (ret == 0) { - data[1] = 1; - data[2] = test_foreground_uid; - if (test_foreground_uid) { - oplus_score_set_foreground_uid(nla); - } - } - - return ret; -} - -static int proc_set_test_link_index(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp,loff_t *ppos) -{ - int ret; - u32 data[2]; - struct nlattr *nla = (struct nlattr*)data; - u32 old_link_index = test_link_index; - - ret = proc_dointvec(ctl, write, buffer, lenp, ppos); - if (oplus_score_debug) { - printk("[oplus_score]:proc_set_test_link,write=%d,ret=%d\n", write, ret); - } - if (ret == 0) { - if (test_link_index) { - data[1] = test_link_index; - oplus_score_add_link(nla); - } - else{ - data[1] = old_link_index; - oplus_score_del_link(nla); - } - } - - return ret; -} - -static struct ctl_table oplus_score_sysctl_table[] = -{ - { - .procname = "oplus_score_debug", - .data = &oplus_score_debug, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_para_rtt", - .data = ¶_rtt, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_score_para_rate", - .data = ¶_rate, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "oplus_score_para_loss", - .data = ¶_loss, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "test_foreground_uid", - .data = &test_foreground_uid, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_set_test_foreground_uid, - }, - { - .procname = "test_link_index", - .data = &test_link_index, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_set_test_link_index, - }, - { } -}; - -static int oplus_score_sysctl_init(void) -{ - oplus_score_table_hrd = register_net_sysctl(&init_net, "net/oplus_score", oplus_score_sysctl_table); - return oplus_score_table_hrd == NULL ? -ENOMEM : 0; -} - -static void oplus_score_param_init(void) -{ - oplus_score_uplink_num = 0; - oplus_score_uplink_num = 0; - oplus_score_enable_flag = 1; - oplus_score_user_pid = 0; - memset(oplus_score_foreground_uid, 0, sizeof(oplus_score_foreground_uid)); - memset(&uplink_score_info, 0, sizeof(uplink_score_info)); - memset(&downlink_score_info, 0, sizeof(downlink_score_info)); - oplus_score_param_info.score_debug = 0; - oplus_score_param_info.threshold_retansmit = 10; - oplus_score_param_info.threshold_normal = 100; - oplus_score_param_info.smooth_factor = 20; - oplus_score_param_info.protect_score = 60; - oplus_score_param_info.threshold_gap = 5; -} - -static int __init oplus_score_init(void) -{ - int ret = 0; - - ret = oplus_score_netlink_init(); - if (ret < 0) { - printk("[oplus_score]:init module failed to init netlink, ret =% d\n", ret); - return ret; - } else { - printk("[oplus_score]:init module init netlink successfully.\n"); - } - - oplus_score_param_init(); - spin_lock_init(&uplink_score_lock); - spin_lock_init(&downlink_score_lock); - ret = nf_register_net_hooks(&init_net, oplus_score_netfilter_ops, ARRAY_SIZE(oplus_score_netfilter_ops)); - if (ret < 0) { - printk("oplus_score_init netfilter register failed, ret=%d\n", ret); - oplus_score_netlink_exit(); - return ret; - } else { - printk("oplus_score_init netfilter register successfully.\n"); - } - - oplus_score_sysctl_init(); - oplus_score_report_timer_init(); - oplus_score_report_timer_start(); - return ret; -} - -static void __exit oplus_score_fini(void) -{ - oplus_score_netlink_exit(); - nf_unregister_net_hooks(&init_net, oplus_score_netfilter_ops, ARRAY_SIZE(oplus_score_netfilter_ops)); - if (oplus_score_table_hrd) { - unregister_net_sysctl_table(oplus_score_table_hrd); - } - oplus_score_report_timer_del(); -} - -module_init(oplus_score_init); -module_exit(oplus_score_fini); -MODULE_LICENSE("GPL v2"); -MODULE_DESCRIPTION("oplus_score"); diff --git a/net/oplus_wificapcenter/Kconfig b/net/oplus_wificapcenter/Kconfig deleted file mode 100755 index 6857a2a573bd..000000000000 --- a/net/oplus_wificapcenter/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) 2020-2022 Oplus. All rights reserved. -# XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453, OPLUS_FEATURE_WIFI_CAPCENTER -# XiaZijian@CONNECTIVITY.WIFI.P2P.26106,20210528, OPLUS_FEATURE_WIFI_OPLUSWFD - -config OPLUS_FEATURE_WIFI_CAPCENTER - bool "Add for Oplus Wifi capability center" - help - Add for Oplus Wifi capability center. - -config OPLUS_FEATURE_WIFI_OPLUSWFD - bool "Add for OplusWFD" - help - Add for Add for OplusWFD. diff --git a/net/oplus_wificapcenter/Makefile b/net/oplus_wificapcenter/Makefile deleted file mode 100755 index 79fc4277ed33..000000000000 --- a/net/oplus_wificapcenter/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# -# Makefile for the wifi cap center. -# XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453, OPLUS_FEATURE_WIFI_CAPCENTER -# -KBUILD_CFLAGS += -Wno-unused-variable -Wno-unused-function -obj-$(CONFIG_OPLUS_FEATURE_WIFI_CAPCENTER) += oplus_wificapcenter.o diff --git a/net/oplus_wificapcenter/oplus_wificapcenter.c b/net/oplus_wificapcenter/oplus_wificapcenter.c deleted file mode 100755 index 712a14423ee6..000000000000 --- a/net/oplus_wificapcenter/oplus_wificapcenter.c +++ /dev/null @@ -1,548 +0,0 @@ -/****************************************************************************** -** Copyright (C), 2019-2029, OPPO Mobile Comm Corp., Ltd -** OPLUS_EDIT, All rights reserved. -** File: - opluswificap center.c -** Description: wificapcenter (wcc) -** -** Version: 1.0 -** Date : 2020/07/05 -** Author: XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453 -** TAG: OPLUS_FEATURE_WIFI_CAPCENTER -** ------------------------------- Revision History: ---------------------------- -** -** ------------------------------------------------------------------------------ -**XuFenghua@CONNECTIVITY.WIFI.BASIC.CAPCENTER.190453 2020/07/05 1.0 OPLUS_FEATURE_WIFI_CAPCENTER - *******************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define LOG_TAG "[oplus_wificapcenter] %s line:%d " -#define debug(fmt, args...) printk(LOG_TAG fmt, __FUNCTION__, __LINE__, ##args) - -/*NLMSG_MIN_TYPE is 0x10,so we start at 0x11*/ -/*If response event is close contact with request,*/ -/*response can be same with req to reduce msg*/ -enum{ - /*common msg for sync and async from 0x11-0x29*/ - OPLUS_COMMON_MSG_BASE = 0x11, - OPLUS_WIFI_CAP_CENTER_NOTIFY_PID = OPLUS_COMMON_MSG_BASE, - - /*sync msg from 0x30-0x79;*/ - OPLUS_SYNC_MSG_BASE = 0x30, - OPLUS_SAMPLE_SYNC_GET = OPLUS_SYNC_MSG_BASE, - OPLUS_SAMPLE_SYNC_GET_NO_RESP = OPLUS_SYNC_MSG_BASE + 1, - - OPLUS_SYNC_REMOVE_HE_IE_FROM_PROBE_REQUEST = OPLUS_SYNC_MSG_BASE + 2, - OPLUS_SYNC_DBS_CAPACITY_GET = OPLUS_SYNC_MSG_BASE + 3, - OPLUS_SYNC_PHY_CAPACITY_GET = OPLUS_SYNC_MSG_BASE + 4, - OPLUS_SYNC_SUPPORTED_CHANNELS_GET = OPLUS_SYNC_MSG_BASE + 5, - OPLUS_SYNC_AVOID_CHANNELS_GET = OPLUS_SYNC_MSG_BASE + 6, - - /*async msg from 0x80-(max-1)*/ - OPLUS_ASYNC_MSG_BASE = 0x80, - OPLUS_SAMPLE_ASYNC_GET = OPLUS_ASYNC_MSG_BASE, - - OPLUS_WIFI_CAP_CENTER_MAX = 0x100, -}; - -static DEFINE_MUTEX(oplus_wcc_sync_nl_mutex); -static DEFINE_MUTEX(oplus_wcc_async_nl_mutex); -static struct ctl_table_header *oplus_table_hrd; -static rwlock_t oplus_sync_nl_lock; -static rwlock_t oplus_async_nl_lock; -static u32 oplus_wcc_debug = 1; -/*user space pid*/ -static u32 oplus_sync_nl_pid = 0; -static u32 oplus_async_nl_pid = 0; -/*kernel sock*/ -static struct sock *oplus_sync_nl_sock; -static struct sock *oplus_async_nl_sock; -static struct timer_list oplus_timer; -static int async_msg_type = 0; - -/*check msg_type in range of sync & async, 1 stands in range, 0 not in range*/ -static int check_msg_in_range(struct sock *nl_sock, int msg_type) -{ - debug("nl_sock: %p, msg_type:%d", nl_sock, msg_type); - if (msg_type >= OPLUS_COMMON_MSG_BASE && msg_type < OPLUS_SYNC_MSG_BASE) { - return 1; - } - - /*not in common part*/ - if (nl_sock == oplus_sync_nl_sock) { - if (msg_type >= OPLUS_SYNC_MSG_BASE && msg_type< OPLUS_ASYNC_MSG_BASE) { - return 1; - } else { - return 0; - } - } else if (nl_sock == oplus_async_nl_sock) { - if (msg_type >= OPLUS_ASYNC_MSG_BASE && msg_type < OPLUS_WIFI_CAP_CENTER_MAX) { - return 1; - } else { - return 0; - } - } else { - return 0; - } -} - -/* send to user space */ -static int oplus_wcc_send_to_user(struct sock *oplus_sock, - u32 oplus_pid, int msg_type, char *payload, int payload_len) -{ - int ret = 0; - struct sk_buff *skbuff; - struct nlmsghdr *nlh = NULL; - - if (!check_msg_in_range(oplus_sock, msg_type)) { - debug("msg_type:%d not in range\n", msg_type); - return -1; - } - - /*allocate new buffer cache */ - skbuff = alloc_skb(NLMSG_SPACE(payload_len), GFP_ATOMIC); - if (skbuff == NULL) { - printk("oplus_wcc_netlink: skbuff alloc_skb failed\n"); - return -1; - } - - /* fill in the data structure */ - nlh = nlmsg_put(skbuff, 0, 0, msg_type, NLMSG_ALIGN(payload_len), 0); - if (nlh == NULL) { - printk("oplus_wcc_netlink:nlmsg_put failaure\n"); - nlmsg_free(skbuff); - return -1; - } - - /*compute nlmsg length*/ - nlh->nlmsg_len = NLMSG_HDRLEN + NLMSG_ALIGN(payload_len); - - if(NULL != payload) { - memcpy((char *)NLMSG_DATA(nlh), payload, payload_len); - } - - /* set control field,sender's pid */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)) - NETLINK_CB(skbuff).pid = 0; -#else - NETLINK_CB(skbuff).portid = 0; -#endif - - NETLINK_CB(skbuff).dst_group = 0; - - /* send data */ - if(oplus_pid) { - ret = netlink_unicast(oplus_sock, skbuff, oplus_pid, MSG_DONTWAIT); - } else { - printk(KERN_ERR "oplus_wcc_netlink: can not unicast skbuff, oplus_pid=0\n"); - kfree_skb(skbuff); - } - if(ret < 0) { - printk(KERN_ERR "oplus_wcc_netlink: can not unicast skbuff,ret = %d\n", ret); - return 1; - } - - return 0; -} - -static void oplus_wcc_sample_resp(struct sock *oplus_sock, u32 oplus_pid, int msg_type) -{ - int payload[4]; - payload[0] = 5; - payload[1] = 6; - payload[2] = 7; - payload[3] = 8; - - oplus_wcc_send_to_user(oplus_sock, oplus_pid, msg_type, (char *)payload, sizeof(payload)); - if (oplus_wcc_debug) { - debug("msg_type = %d, sample_resp =%d%d%d%d\n", msg_type, payload[0], payload[1], payload[2], payload[3]); - } - - return; -} - -static int oplus_wcc_sample_sync_get(struct nlmsghdr *nlh) -{ - u32 *data = (u32 *)NLMSG_DATA(nlh); - - debug("sample_sync_get: %u%u%u%u\n", data[0], data[1], data[2], data[3]); - oplus_wcc_sample_resp(oplus_sync_nl_sock, oplus_sync_nl_pid, OPLUS_SAMPLE_SYNC_GET); - return 0; -} - -static int oplus_wcc_sample_sync_get_no_resp(struct nlmsghdr *nlh) -{ - u32 *data = (u32 *)NLMSG_DATA(nlh); - - debug("sample_sync_get_no_resp: %u%u%u%u\n", data[0], data[1], data[2], data[3]); - return 0; -} - -/*#ifdef OPLUS_FEATURE_WIFI_OPLUSWFD*/ -/*XiaZijian@CONNECTIVITY.WIFI.P2P.26106,20200703*/ -#define OPLUS_WFD_FREQS_NUM_MAX 100 -/*the first one for length*/ -static int s_oplus_wfd_freqs[OPLUS_WFD_FREQS_NUM_MAX + 1]; -enum oplus_wfd_band -{ - oplus_wfd_band_2g = 0, - oplus_wfd_band_5g, - oplus_wfd_band_6g, - oplus_wfd_band_max -}; - -static void remove_he_ie_from_probe_request_stub(int remove) { - debug("remove_he_ie_from_probe_request_stub"); -} - -static int get_dbs_capacity_stub() { - debug("get_dbs_capacity_stub"); - return 0; -} - -static int get_phy_capacity_stub(int band) -{ - debug("get_phy_capacity_stub"); - return 0; -} - -static void get_supported_channels_stub(int band, int *len, int *freqs, int max_num) -{ - debug("get_supported_channels_stub"); - *len = 0; -} -static void get_avoid_channels_stub(int *len, int *freqs, int max_num) -{ - debug("get_avoid_channels_stub"); - *len = 0; -} - -struct oplus_wfd_wlan_ops_t oplus_wfd_wlan_ops = { - .remove_he_ie_from_probe_request = remove_he_ie_from_probe_request_stub, - .get_dbs_capacity = get_dbs_capacity_stub, - .get_phy_capacity = get_phy_capacity_stub, - .get_supported_channels = get_supported_channels_stub, - .get_avoid_channels = get_avoid_channels_stub -}; - -void register_oplus_wfd_wlan_ops(struct oplus_wfd_wlan_ops_t *ops) { - if (ops == NULL) - return; - if (ops->remove_he_ie_from_probe_request) - oplus_wfd_wlan_ops.remove_he_ie_from_probe_request = ops->remove_he_ie_from_probe_request; - if (ops->get_dbs_capacity) - oplus_wfd_wlan_ops.get_dbs_capacity = ops->get_dbs_capacity; - if (ops->get_phy_capacity) - oplus_wfd_wlan_ops.get_phy_capacity = ops->get_phy_capacity; - if (ops->get_supported_channels) - oplus_wfd_wlan_ops.get_supported_channels = ops->get_supported_channels; - if (ops->get_avoid_channels) - oplus_wfd_wlan_ops.get_avoid_channels = ops->get_avoid_channels; -} - -static void oplus_wcc_remove_He_IE_from_probe_request(struct nlmsghdr *nlh) -{ - if (nlmsg_len(nlh) > 0) { - u32 *data = (u32 *)NLMSG_DATA(nlh); - debug("remove he from probe rquest: %d", *data); - oplus_wfd_wlan_ops.remove_he_ie_from_probe_request(*data); - } -} - -static void oplus_wcc_get_dbs_capacity(struct nlmsghdr *nlh) -{ - s32 cap = oplus_wfd_wlan_ops.get_dbs_capacity(); - oplus_wcc_send_to_user(oplus_sync_nl_sock, oplus_sync_nl_pid, OPLUS_SYNC_DBS_CAPACITY_GET, (char*)&cap, sizeof(cap)); -} -static void oplus_wcc_get_phy_capacity(struct nlmsghdr *nlh) -{ - u32 band = 0; - u32 cap = 0; - if (nlmsg_len(nlh) > 0) { - u32* data = (u32 *)NLMSG_DATA(nlh); - band = *data; - if (band < oplus_wfd_band_max) { - cap = oplus_wfd_wlan_ops.get_phy_capacity(band); - debug("oplus_wcc_get_phy_capacity, cap= %d", cap); - } - } - oplus_wcc_send_to_user(oplus_sync_nl_sock, oplus_sync_nl_pid, OPLUS_SYNC_PHY_CAPACITY_GET, (char*)&cap, sizeof(cap)); -} - -static void oplus_wcc_get_supported_channels(struct nlmsghdr *nlh) -{ - u32 band = 0; - u32 len = 0; - - memset(s_oplus_wfd_freqs, 0, sizeof(s_oplus_wfd_freqs)); - if (nlmsg_len(nlh) > 0) { - u32* data = (u32 *)NLMSG_DATA(nlh); - band = *data; - if (band < oplus_wfd_band_max) { - oplus_wfd_wlan_ops.get_supported_channels(band, &len, s_oplus_wfd_freqs + 1, OPLUS_WFD_FREQS_NUM_MAX); - s_oplus_wfd_freqs[0] = len; - debug("get supported channels, num = %d", len); - } - } - oplus_wcc_send_to_user(oplus_sync_nl_sock, oplus_sync_nl_pid, OPLUS_SYNC_SUPPORTED_CHANNELS_GET, (char*)s_oplus_wfd_freqs, (len + 1)*sizeof(u32)); -} - -static void oplus_wcc_get_avoid_channels(struct nlmsghdr *nlh) -{ - u32 len = 0; - - memset(s_oplus_wfd_freqs, 0, sizeof(s_oplus_wfd_freqs)); - - oplus_wfd_wlan_ops.get_avoid_channels(&len, s_oplus_wfd_freqs + 1, OPLUS_WFD_FREQS_NUM_MAX); - s_oplus_wfd_freqs[0] = len; - debug("get avoid channels, num = %d", len); - - oplus_wcc_send_to_user(oplus_sync_nl_sock, oplus_sync_nl_pid, OPLUS_SYNC_AVOID_CHANNELS_GET, (char*)s_oplus_wfd_freqs, (len + 1)*sizeof(u32)); -} - -EXPORT_SYMBOL(register_oplus_wfd_wlan_ops); - -/*#endif OPLUS_FEATURE_WIFI_OPLUSWFD*/ -static int oplus_wcc_sample_async_get(struct nlmsghdr *nlh) -{ - u32 *data = (u32 *)NLMSG_DATA(nlh); - - async_msg_type = OPLUS_SAMPLE_ASYNC_GET; - oplus_timer.expires = jiffies + HZ;/* timer expires in ~1s*/ - add_timer(&oplus_timer); - - debug("sample_async_set: %u%u%u%u\n", data[0], data[1], data[2], data[3]); - - return 0; -} - -static void oplus_wcc_timer_function(void) -{ - if (async_msg_type == OPLUS_SAMPLE_ASYNC_GET) { - oplus_wcc_sample_resp(oplus_async_nl_sock, oplus_async_nl_pid, OPLUS_SAMPLE_ASYNC_GET); - async_msg_type = 0; - } -} - -static void oplus_wcc_timer_init(void) -{ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) - init_timer(&oplus_timer); - oplus_timer.function = (void*)oplus_wcc_timer_function; -#else - timer_setup(&oplus_timer, (void*)oplus_wcc_timer_function, 0); -#endif -} - -static void oplus_wcc_timer_fini(void) -{ - del_timer(&oplus_timer); -} - -static int oplus_wcc_sync_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) -{ - u32 portid = NETLINK_CB(skb).portid; - - if (nlh->nlmsg_type == OPLUS_WIFI_CAP_CENTER_NOTIFY_PID) { - oplus_sync_nl_pid = portid; - debug("oplus_sync_nl_pid pid=%d\n", oplus_sync_nl_pid); - } - /* only recv msg from target pid*/ - if (portid != oplus_sync_nl_pid) { - return -1; - } - if (!check_msg_in_range(oplus_sync_nl_sock, nlh->nlmsg_type)) { - debug("msg_type:%d not in range\n", nlh->nlmsg_type); - return -1; - } - - switch (nlh->nlmsg_type) { - case OPLUS_SAMPLE_SYNC_GET: - oplus_wcc_sample_sync_get(nlh); - break; - case OPLUS_SAMPLE_SYNC_GET_NO_RESP: - oplus_wcc_sample_sync_get_no_resp(nlh); - break; - case OPLUS_SYNC_REMOVE_HE_IE_FROM_PROBE_REQUEST: - oplus_wcc_remove_He_IE_from_probe_request(nlh); - break; - case OPLUS_SYNC_DBS_CAPACITY_GET: - oplus_wcc_get_dbs_capacity(nlh); - break; - case OPLUS_SYNC_PHY_CAPACITY_GET: - oplus_wcc_get_phy_capacity(nlh); - break; - case OPLUS_SYNC_SUPPORTED_CHANNELS_GET: - oplus_wcc_get_supported_channels(nlh); - break; - case OPLUS_SYNC_AVOID_CHANNELS_GET: - oplus_wcc_get_avoid_channels(nlh); - break; - default: - return -EINVAL; - } - - return 0; -} - -static int oplus_wcc_async_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) -{ - u32 portid = NETLINK_CB(skb).portid; - - if (nlh->nlmsg_type == OPLUS_WIFI_CAP_CENTER_NOTIFY_PID) { - oplus_async_nl_pid = portid; - debug("oplus_async_nl_pid pid=%d\n", oplus_async_nl_pid); - } - /* only recv msg from target pid*/ - if (portid != oplus_async_nl_pid) { - return -1; - } - if (!check_msg_in_range(oplus_async_nl_sock, nlh->nlmsg_type)) { - debug("msg_type:%d not in range\n", nlh->nlmsg_type); - return -1; - } - - switch (nlh->nlmsg_type) { - case OPLUS_SAMPLE_ASYNC_GET: - oplus_wcc_sample_async_get(nlh); - break; - default: - return -EINVAL; - } - - return 0; -} - -static void oplus_wcc_sync_nl_rcv(struct sk_buff *skb) -{ - mutex_lock(&oplus_wcc_sync_nl_mutex); - netlink_rcv_skb(skb, &oplus_wcc_sync_nl_rcv_msg); - mutex_unlock(&oplus_wcc_sync_nl_mutex); -} - -static void oplus_wcc_async_nl_rcv(struct sk_buff *skb) -{ - mutex_lock(&oplus_wcc_async_nl_mutex); - netlink_rcv_skb(skb, &oplus_wcc_async_nl_rcv_msg); - mutex_unlock(&oplus_wcc_async_nl_mutex); -} - -static int oplus_wcc_netlink_init(void) -{ - struct netlink_kernel_cfg cfg1 = { - .input = oplus_wcc_sync_nl_rcv, - }; - struct netlink_kernel_cfg cfg2 = { - .input = oplus_wcc_async_nl_rcv, - }; - - oplus_sync_nl_sock = netlink_kernel_create(&init_net, NETLINK_OPLUS_WIFI_CAP_CENTER_SYNC, &cfg1); - oplus_async_nl_sock = netlink_kernel_create(&init_net, NETLINK_OPLUS_WIFI_CAP_CENTER_ASYNC, &cfg2); - debug("oplus_sync_nl_sock = %p, oplus_async_nl_sock = %p\n", oplus_sync_nl_sock, oplus_async_nl_sock); - - if (oplus_sync_nl_sock == NULL || oplus_async_nl_sock == NULL) { - return -ENOMEM; - } else { - return 0; - } -} - -static void oplus_wcc_netlink_exit(void) -{ - netlink_kernel_release(oplus_sync_nl_sock); - oplus_sync_nl_sock = NULL; - - netlink_kernel_release(oplus_async_nl_sock); - oplus_async_nl_sock = NULL; -} - -static struct ctl_table oplus_wcc_sysctl_table[] = { - { - .procname = "oplus_wcc_debug", - .data = &oplus_wcc_debug, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { } -}; - -static int oplus_wcc_sysctl_init(void) -{ - oplus_table_hrd = register_net_sysctl - (&init_net, "net/oplus_wcc", oplus_wcc_sysctl_table); - return oplus_table_hrd == NULL ? -ENOMEM : 0; -} - -static void oplus_wcc_sysctl_fini(void) -{ - if(oplus_table_hrd) { - unregister_net_sysctl_table(oplus_table_hrd); - oplus_table_hrd = NULL; - } -} - -static int __init oplus_wcc_init(void) -{ - int ret = 0; - rwlock_init(&oplus_sync_nl_lock); - rwlock_init(&oplus_async_nl_lock); - - ret = oplus_wcc_netlink_init(); - if (ret < 0) { - debug("oplus_wcc_init module failed to init netlink.\n"); - } else { - debug("oplus_wcc_init module init netlink successfully.\n"); - } - - ret = oplus_wcc_sysctl_init(); - if (ret < 0) { - debug("oplus_wcc_init module failed to init sysctl.\n"); - } - else { - debug("oplus_wcc_init module init sysctl successfully.\n"); - } - - oplus_wcc_timer_init(); - - return ret; -} - -static void __exit oplus_wcc_fini(void) -{ - oplus_wcc_sysctl_fini(); - oplus_wcc_netlink_exit(); - oplus_wcc_timer_fini(); -} - -module_init(oplus_wcc_init); -module_exit(oplus_wcc_fini); - diff --git a/net/socket.c b/net/socket.c index bbc728cae628..02207a294056 100755 --- a/net/socket.c +++ b/net/socket.c @@ -108,10 +108,6 @@ #include #include #include -//#ifdef OPLUS_FEATURE_NWPOWER_NETCONTROLLER -//PengHao@NETWORK.POWER.26376, 2020/04/27, add for oplus net controller -#include -//#endif /* OPLUS_FEATURE_NWPOWER_NETCONTROLLER */ #ifdef CONFIG_NET_RX_BUSY_POLL unsigned int sysctl_net_busy_read __read_mostly; @@ -430,12 +426,6 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) file->f_flags = O_RDWR | (flags & O_NONBLOCK); file->private_data = sock; - //#ifdef OPLUS_FEATURE_NWPOWER - if (sock->sk) { - sock->sk->sk_oplus_pid = current->tgid; - } - //#endif /* OPLUS_FEATURE_NWPOWER */ - return file; } EXPORT_SYMBOL(sock_alloc_file); diff --git a/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.c b/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.c index 39724f69f0d0..93bbd651e26a 100755 --- a/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.c +++ b/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.c @@ -41,10 +41,6 @@ static int s_speaker_reboot = 0; #include "aw_bin_parse.h" #include "aw_spin.h" -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#include -#endif - #define AW882XX_DRIVER_VERSION "v1.10.0" #define AW882XX_I2C_NAME "aw882xx_smartpa" @@ -272,13 +268,13 @@ static int aw882xx_startup(struct snd_pcm_substream *substream, aw_snd_soc_codec_t *codec = aw_get_codec(dai); struct aw882xx *aw882xx = aw_componet_codec_ops.codec_get_drvdata(codec); - -#ifdef OPLUS_ARCH_EXTENDS - if (aw882xx->speaker_force_mute) { - aw882xx->allow_pw = false; - } -#endif - + +#ifdef OPLUS_ARCH_EXTENDS + if (aw882xx->speaker_force_mute) { + aw882xx->allow_pw = false; + } +#endif + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { aw_dev_info(aw882xx->dev, "playback enter"); /*load cali re*/ @@ -411,236 +407,6 @@ static void aw882xx_start_pa(struct aw882xx *aw882xx) } -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#define AW882XX_CHECK_WORK_DELAY (6*HZ) -#define OPLUS_AUDIO_EVENTID_SMARTPA_ERR 10041 -#define OPLUS_AUDIO_EVENTID_SPK_ERR 10042 -#define ERROR_INFO_MAX_LEN 20 -#define AW882XX_STATUS_REG 0x01 -#define AW882XX_STATUS_NORMAL_VALUE 0x311 -/* 0xCFBB = 1100101110111011b, mask bit0/1/3/4/5/7/8/9/11/14/15 */ -#define AW882XX_STATUS_CHECK_MASK 0xCBBB - -enum { - RE_ERR_IV_OR_MEC_DISABLE = -99000, - RE_ERR_NOT_WORK = -2000, - RE_ERR_IV_ERR = -1000, - RE_ERR_SHORT_MIN = -500, - RE_ERR_SHORT_MAX = 500, - RE_NORMAL_MIN = 4500, - RE_NORMAL_MAX = 8500, - RE_ERR_OPEN = 99000, -}; - -struct check_status_err { - int bit; - uint32_t err_val; - char info[ERROR_INFO_MAX_LEN]; -}; -static const struct check_status_err check_err[] = { - {0, 0, "PllUnlock"}, - {1, 1, "OverTemperature"}, - {3, 1, "BoostOverCurrent"}, - {4, 0, "UnstableClk"}, - {5, 1, "NoClock"}, - {7, 1, "Clipping"}, - {8, 0, "NotSwitch"}, - {9, 0, "NoBoost"}, - {11, 1, "CurrentHigh"}, - {14, 1, "VbatLow"}, - {15, 1, "BoostOVP"}, -}; - -const unsigned char fb_regs_aw88264[] = {0x02, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10, 0x12, 0x13, 0x14, 0x60, 0x61}; -const unsigned char fb_regs_aw88265[] = {0x02, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x20, 0x21, 0x22, 0x23, 0x60, 0x61}; - -static bool g_chk_err = false; - -static int aw882xx_check_status_reg(struct aw882xx *aw882xx) -{ - unsigned int reg_val = 0; - char fd_buf[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; - char info[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; - int offset = 0; - int i = 0; - int ret = 0; - - if ((aw882xx->last_fb !=0) && ktime_before(ktime_get(), ktime_add_ms(aw882xx->last_fb, MM_FB_KEY_RATELIMIT_1MIN))) { - return 0; - } - - ret = aw882xx_i2c_read(aw882xx, AW882XX_STATUS_REG, ®_val); - if (ret < 0) { - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, \ - "AW882xx SPK%u:failed to read regs 0x%x, ret=%d,", \ - aw882xx->index + 1, AW882XX_STATUS_REG, ret); - aw_dev_info(aw882xx->dev, "i2c read error, ret=%d", ret); - } else { - aw_dev_info(aw882xx->dev, "read reg[0x%x]=0x%x", AW882XX_STATUS_REG, reg_val); - if ((AW882XX_STATUS_NORMAL_VALUE & AW882XX_STATUS_CHECK_MASK) != (reg_val & AW882XX_STATUS_CHECK_MASK)) { - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, \ - "AW882xx SPK%u:reg[0x%x]=0x%x,", \ - aw882xx->index + 1, AW882XX_STATUS_REG, reg_val); - for (i = 0; i < ARRAY_SIZE(check_err); i++) { - if (check_err[i].err_val == (1 & (reg_val>>check_err[i].bit))) { - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, "%s,", check_err[i].info); - } - } - - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, "regs:("); - if (aw882xx->aw_pa && (PID_1852_ID == aw882xx->aw_pa->chip_id)) { - for (i = 0; i < sizeof(fb_regs_aw88264); i++) { - ret = aw882xx_i2c_read(aw882xx, fb_regs_aw88264[i], ®_val); - if (ret < 0) { - break; - } else { - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, "%x,", reg_val); - } - } - } else { - for (i = 0; i < sizeof(fb_regs_aw88265); i++) { - ret = aw882xx_i2c_read(aw882xx, fb_regs_aw88265[i], ®_val); - if (ret < 0) { - break; - } else { - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, "%x,", reg_val); - } - } - } - offset = strlen(info); - scnprintf(info + offset, sizeof(info) - offset - 1, ")"); - } - } - - /* feedback the check error */ - offset = strlen(info); - if ((offset > 0) && (offset < MM_KEVENT_MAX_PAYLOAD_SIZE)) { - scnprintf(fd_buf, sizeof(fd_buf) - 1, "payload@@%s", info); - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_SMARTPA_ERR, - MM_FB_KEY_RATELIMIT_5MIN, fd_buf); - aw882xx->last_fb = ktime_get(); - aw_dev_info(aw882xx->dev, "fd_buf=%s", fd_buf); - } - - return 1; -} - -static int aw882xx_check_speaker_status(struct aw882xx *aw882xx) -{ - char fd_buf[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; - int32_t re = 0; - int32_t te = 0; - int32_t ret = 0; - - if ((aw882xx->last_fb !=0) && ktime_before(ktime_get(), ktime_add_ms(aw882xx->last_fb, MM_FB_KEY_RATELIMIT_1MIN))) { - return 0; - } - - ret = aw_dsp_read_st(aw882xx->aw_pa, &re, &te); - if (ret) { - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:read data from adsp error, ret=%d,", \ - aw882xx->index + 1, ret); - } else { - switch (re) { - case RE_ERR_IV_OR_MEC_DISABLE: - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:IV or MEC channel disable, re=%d, te=%d", \ - aw882xx->index + 1, re, te); - break; - case RE_ERR_NOT_WORK: - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:equivalent chip not working, re=%d, te=%d", \ - aw882xx->index + 1, re, te); - break; - case RE_ERR_IV_ERR: - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:IV data error(no tx or MEC not open), re=%d, te=%d", \ - aw882xx->index + 1, re, te); - break; - case RE_ERR_OPEN: - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:speaker open circuit, re=%d, te=%d", \ - aw882xx->index + 1, re, te); - break; - default: - if ((re > RE_ERR_SHORT_MIN) && (re < RE_ERR_SHORT_MAX)) { - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:speaker short circuit, re=%d, te=%d", \ - aw882xx->index + 1, re, te); - } else if ((re < RE_NORMAL_MIN) || (re > RE_NORMAL_MAX)) { - scnprintf(fd_buf, sizeof(fd_buf) - 1, \ - "payload@@AW882xx SPK%u:speaker R0 out of range(%d, %d), re=%d, te=%d", \ - aw882xx->index + 1, RE_NORMAL_MIN, RE_NORMAL_MAX, re, te); - } - aw_dev_info(aw882xx->dev, "AW882xx SPK%u: re=%d, te=%d", \ - aw882xx->index + 1, re, te); - break; - } - } - - if (strlen(fd_buf) > 0) { - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_SPK_ERR, MM_FB_KEY_RATELIMIT_5MIN, fd_buf); - aw882xx->last_fb = ktime_get(); - aw_dev_info(aw882xx->dev, "%s", fd_buf); - } - - return ret; -} - -static void aw882xx_check_work(struct work_struct *work) -{ - struct aw882xx *aw882xx = container_of(work, struct aw882xx, check_work.work); - - aw_dev_info(aw882xx->dev, "enter"); - if (g_chk_err) { - aw882xx_check_speaker_status(aw882xx); - } -} - -static int aw882xx_set_check_feedback(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - aw_snd_soc_codec_t *codec = - aw_componet_codec_ops.kcontrol_codec(kcontrol); - struct aw882xx *aw882xx = - aw_componet_codec_ops.codec_get_drvdata(codec); - int need_chk = ucontrol->value.integer.value[0]; - - aw_pr_info("%d", need_chk); - g_chk_err = need_chk; - if (!g_chk_err) { - cancel_delayed_work_sync(&aw882xx->check_work); - } - - return 0; -} - -static int aw882xx_get_check_feedback(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - ucontrol->value.integer.value[0] = g_chk_err; - aw_pr_info("%d", g_chk_err); - - return 0; -} - -static char const *aw882xx_check_feedback_text[] = {"Off", "On"}; -static const struct soc_enum aw882xx_check_feedback_enum = - SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aw882xx_check_feedback_text), aw882xx_check_feedback_text); - -static const struct snd_kcontrol_new aw882xx_check_feedback[] = { - SOC_ENUM_EXT("AW_CHECK_FEEDBACK", aw882xx_check_feedback_enum, - aw882xx_get_check_feedback, aw882xx_set_check_feedback), -}; -#endif /*OPLUS_FEATURE_MM_FEEDBACK*/ - static int aw882xx_mute(struct snd_soc_dai *dai, int mute, int stream) { int ret = 0; @@ -650,16 +416,6 @@ static int aw882xx_mute(struct snd_soc_dai *dai, int mute, int stream) aw_dev_info(aw882xx->dev, "mute state=%d", mute); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - if (mute) { - if (g_chk_err) { - aw882xx_check_status_reg(aw882xx); - g_chk_err = false; - } - cancel_delayed_work_sync(&aw882xx->check_work); - } -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - if (stream != SNDRV_PCM_STREAM_PLAYBACK) { aw_dev_info(aw882xx->dev, "capture"); return 0; @@ -687,13 +443,6 @@ static int aw882xx_mute(struct snd_soc_dai *dai, int mute, int stream) aw882xx_start_pa(aw882xx); #endif /* OPLUS_ARCH_EXTENDS */ -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - if (g_chk_err) { - queue_delayed_work(aw882xx->work_queue, - &aw882xx->check_work, AW882XX_CHECK_WORK_DELAY); - } -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - #ifndef OPLUS_ARCH_EXTENDS if (aw882xx->index == 0) { #else /* OPLUS_ARCH_EXTENDS */ @@ -858,14 +607,6 @@ static int aw882xx_switch_set(struct snd_kcontrol *kcontrol, if (aw882xx->pstream) { if (ucontrol->value.integer.value[0] == 0) { -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -/*MTK platform set aw_dev_0_switch before pcm close, so check reg here rather than aw882xx_mute */ - if (g_chk_err) { - aw882xx_check_status_reg(aw882xx); - g_chk_err = false; - } - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->dc_work); cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); @@ -874,9 +615,6 @@ static int aw882xx_switch_set(struct snd_kcontrol *kcontrol, mutex_unlock(&aw882xx->lock); aw_dev_info(aw882xx->dev, "stop pa"); } else { -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); aw882xx->allow_pw = true; @@ -1110,10 +848,6 @@ static void aw882xx_dc_prot_work(struct work_struct *work) if (dev_status) { dc_status = aw_dev_dc_status(aw882xx->aw_pa); if (dc_status > 0) { -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - g_chk_err = false; - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); aw_device_stop(aw882xx->aw_pa); @@ -1538,14 +1272,14 @@ static const struct soc_enum spk_r_reboot_ctrl_enum = static int aw882xx_spk_l_mute_ctrl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) -{ - aw_snd_soc_codec_t *codec = - aw_componet_codec_ops.kcontrol_codec(kcontrol); - struct aw882xx *aw882xx = - aw_componet_codec_ops.codec_get_drvdata(codec); - - ucontrol->value.integer.value[0] = aw882xx->speaker_force_mute; - return 0; +{ + aw_snd_soc_codec_t *codec = + aw_componet_codec_ops.kcontrol_codec(kcontrol); + struct aw882xx *aw882xx = + aw_componet_codec_ops.codec_get_drvdata(codec); + + ucontrol->value.integer.value[0] = aw882xx->speaker_force_mute; + return 0; } static int aw882xx_spk_l_mute_ctrl_put(struct snd_kcontrol *kcontrol, @@ -1555,34 +1289,30 @@ static int aw882xx_spk_l_mute_ctrl_put(struct snd_kcontrol *kcontrol, aw_componet_codec_ops.kcontrol_codec(kcontrol); struct aw882xx *aw882xx = aw_componet_codec_ops.codec_get_drvdata(codec); - - char name[32]; - uint32_t ctrl_value = 0; + + char name[32]; + uint32_t ctrl_value = 0; ctrl_value = ucontrol->value.integer.value[0]; aw_dev_info(aw882xx->dev, "AW_L operating, set spk_l_mute ctrl is %d", ctrl_value); - - if (ctrl_value == aw882xx->speaker_force_mute) { - aw_dev_info(aw882xx->dev, "AW_L operating, Speaker_L mute is already %d", ctrl_value); + + if (ctrl_value == aw882xx->speaker_force_mute) { + aw_dev_info(aw882xx->dev, "AW_L operating, Speaker_L mute is already %d", ctrl_value); return 1; - } - - if (aw_dev_get_profile_name(aw882xx->aw_pa, name, aw_dev_get_profile_index(aw882xx->aw_pa)) == 0) { - if (strcmp(name, "Receiver") == 0) { - aw_dev_info(aw882xx->dev, "Speaker_L is a receiver, no need to mute"); - return 1; - } - } - - aw_dev_info(aw882xx->dev, "AW_L operating, Speaker_L mute set to %d", ctrl_value); - aw882xx->speaker_force_mute = ctrl_value; - + } + + if (aw_dev_get_profile_name(aw882xx->aw_pa, name, aw_dev_get_profile_index(aw882xx->aw_pa)) == 0) { + if (strcmp(name, "Receiver") == 0) { + aw_dev_info(aw882xx->dev, "Speaker_L is a receiver, no need to mute"); + return 1; + } + } + + aw_dev_info(aw882xx->dev, "AW_L operating, Speaker_L mute set to %d", ctrl_value); + aw882xx->speaker_force_mute = ctrl_value; + if (aw882xx->pstream) { if (ucontrol->value.integer.value[0] == 1) { aw_dev_info(aw882xx->dev, "AW_L operating, setting mute state..."); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - g_chk_err = false; - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->dc_work); cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); @@ -1615,14 +1345,14 @@ static int aw882xx_spk_l_mute_ctrl_put(struct snd_kcontrol *kcontrol, static int aw882xx_spk_r_mute_ctrl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) -{ - aw_snd_soc_codec_t *codec = - aw_componet_codec_ops.kcontrol_codec(kcontrol); - struct aw882xx *aw882xx = - aw_componet_codec_ops.codec_get_drvdata(codec); - - ucontrol->value.integer.value[0] = aw882xx->speaker_force_mute; - return 0; +{ + aw_snd_soc_codec_t *codec = + aw_componet_codec_ops.kcontrol_codec(kcontrol); + struct aw882xx *aw882xx = + aw_componet_codec_ops.codec_get_drvdata(codec); + + ucontrol->value.integer.value[0] = aw882xx->speaker_force_mute; + return 0; } static int aw882xx_spk_r_mute_ctrl_put(struct snd_kcontrol *kcontrol, @@ -1636,22 +1366,18 @@ static int aw882xx_spk_r_mute_ctrl_put(struct snd_kcontrol *kcontrol, uint32_t ctrl_value = 0; ctrl_value = ucontrol->value.integer.value[0]; aw_dev_info(aw882xx->dev, "sAW_R operating, et spk_l_mute ctrl is %d", ctrl_value); - - if (ctrl_value == aw882xx->speaker_force_mute) { - aw_dev_info(aw882xx->dev, "AW_R operating, Speaker_R mute is already %d", ctrl_value); - return 1; - } - - aw_dev_info(aw882xx->dev, "AW_R operating, Speaker_R mute set to %d", ctrl_value); - aw882xx->speaker_force_mute = ctrl_value; - + + if (ctrl_value == aw882xx->speaker_force_mute) { + aw_dev_info(aw882xx->dev, "AW_R operating, Speaker_R mute is already %d", ctrl_value); + return 1; + } + + aw_dev_info(aw882xx->dev, "AW_R operating, Speaker_R mute set to %d", ctrl_value); + aw882xx->speaker_force_mute = ctrl_value; + if (aw882xx->pstream) { if (ucontrol->value.integer.value[0] == 1) { aw_dev_info(aw882xx->dev, "AW_R operating, setting mute state..."); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - g_chk_err = false; - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->dc_work); cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); @@ -1706,10 +1432,6 @@ static int aw882xx_spk_reboot_ctrl_put(struct snd_kcontrol *kcontrol, if (aw882xx->pstream) { if (ucontrol->value.integer.value[0] == 1) { aw_dev_info(aw882xx->dev, "AW rebooting, setting mute state..."); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - g_chk_err = false; - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ cancel_delayed_work_sync(&aw882xx->dc_work); cancel_delayed_work_sync(&aw882xx->start_work); mutex_lock(&aw882xx->lock); @@ -1775,35 +1497,30 @@ static void aw882xx_add_codec_controls(struct aw882xx *aw882xx) if (aw882xx->aw_pa->spin_desc.aw_spin_kcontrol_st == AW_SPIN_KCONTROL_ENABLE) aw_componet_codec_ops.add_codec_controls(aw882xx->codec, - aw882xx_spin_control, ARRAY_SIZE(aw882xx_spin_control)); - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - aw_componet_codec_ops.add_codec_controls(aw882xx->codec, - &aw882xx_check_feedback[0], ARRAY_SIZE(aw882xx_check_feedback)); + aw882xx_spin_control, ARRAY_SIZE(aw882xx_spin_control)); +} + +#ifdef OPLUS_ARCH_EXTENDS +static void aw882xx_add_codec_mute_controls(struct aw882xx *aw882xx) +{ + if (aw882xx->aw_pa->channel == 0x00) { + snd_soc_add_codec_controls(aw882xx->codec, + aw882xx_snd_control_spk_l_mute, + ARRAY_SIZE(aw882xx_snd_control_spk_l_mute)); + snd_soc_add_codec_controls(aw882xx->codec, + aw882xx_snd_control_spk_l_reboot, + ARRAY_SIZE(aw882xx_snd_control_spk_l_reboot)); + } else if ((aw882xx->aw_pa->channel == 0x01)||(aw882xx->aw_pa->channel == 0xff)) { + snd_soc_add_codec_controls(aw882xx->codec, + aw882xx_snd_control_spk_r_mute, + ARRAY_SIZE(aw882xx_snd_control_spk_r_mute)); + snd_soc_add_codec_controls(aw882xx->codec, + aw882xx_snd_control_spk_r_reboot, + ARRAY_SIZE(aw882xx_snd_control_spk_r_reboot)); + } +} #endif -} - -#ifdef OPLUS_ARCH_EXTENDS -static void aw882xx_add_codec_mute_controls(struct aw882xx *aw882xx) -{ - if (aw882xx->aw_pa->channel == 0x00) { - snd_soc_add_codec_controls(aw882xx->codec, - aw882xx_snd_control_spk_l_mute, - ARRAY_SIZE(aw882xx_snd_control_spk_l_mute)); - snd_soc_add_codec_controls(aw882xx->codec, - aw882xx_snd_control_spk_l_reboot, - ARRAY_SIZE(aw882xx_snd_control_spk_l_reboot)); - } else if ((aw882xx->aw_pa->channel == 0x01)||(aw882xx->aw_pa->channel == 0xff)) { - snd_soc_add_codec_controls(aw882xx->codec, - aw882xx_snd_control_spk_r_mute, - ARRAY_SIZE(aw882xx_snd_control_spk_r_mute)); - snd_soc_add_codec_controls(aw882xx->codec, - aw882xx_snd_control_spk_r_reboot, - ARRAY_SIZE(aw882xx_snd_control_spk_r_reboot)); - } -} -#endif - + #ifdef AW_MTK_PLATFORM_WITH_DSP static int aw882xx_name_append_suffix(struct aw882xx *aw882xx, const char **name) { @@ -1947,20 +1664,15 @@ static int aw882xx_codec_probe(aw_snd_soc_codec_t *aw_codec) INIT_DELAYED_WORK(&aw882xx->dc_work, aw882xx_dc_prot_work); INIT_DELAYED_WORK(&aw882xx->fw_work, aw882xx_request_firmware); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - aw882xx->last_fb = 0; - INIT_DELAYED_WORK(&aw882xx->check_work, aw882xx_check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ + aw882xx->codec = aw_codec; + + if (aw882xx->index == 0) + aw882xx_add_codec_controls(aw882xx); + +#ifdef OPLUS_ARCH_EXTENDS + aw882xx_add_codec_mute_controls(aw882xx); +#endif /* OPLUS_ARCH_EXTENDS */ - aw882xx->codec = aw_codec; - - if (aw882xx->index == 0) - aw882xx_add_codec_controls(aw882xx); - -#ifdef OPLUS_ARCH_EXTENDS - aw882xx_add_codec_mute_controls(aw882xx); -#endif /* OPLUS_ARCH_EXTENDS */ - aw882xx_add_widgets(aw882xx); /*load fw bin*/ @@ -2142,13 +1854,13 @@ static struct aw882xx *aw882xx_malloc_init(struct i2c_client *i2c) aw882xx->fw_status = AW_DEV_FW_FAILED; aw882xx->fw_retry_cnt = 0; aw882xx->dbg_en_prof = true; - aw882xx->allow_pw = true; - aw882xx->work_queue = NULL; -#ifdef OPLUS_ARCH_EXTENDS - aw882xx->speaker_force_mute = false; -#endif - - mutex_init(&aw882xx->lock); + aw882xx->allow_pw = true; + aw882xx->work_queue = NULL; +#ifdef OPLUS_ARCH_EXTENDS + aw882xx->speaker_force_mute = false; +#endif + + mutex_init(&aw882xx->lock); return aw882xx; } @@ -3057,10 +2769,6 @@ static void aw882xx_i2c_shutdown(struct i2c_client *i2c) { struct aw882xx *aw882xx = i2c_get_clientdata(i2c); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - g_chk_err = false; - cancel_delayed_work_sync(&aw882xx->check_work); -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ aw_dev_info(aw882xx->dev, "enter"); mutex_lock(&aw882xx->lock); aw_device_stop(aw882xx->aw_pa); diff --git a/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.h b/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.h index dbb8f6c01da3..9eecc5e5bace 100755 --- a/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.h +++ b/sound/soc/codecs/audio/aw882xx_v1.10.0/aw882xx.h @@ -150,10 +150,10 @@ struct aw882xx { unsigned char dc_flag; unsigned char dbg_en_prof; /* debug enable/disable profile function */ unsigned char allow_pw; /* allow power */ -#ifdef OPLUS_ARCH_EXTENDS - unsigned char spin_flag; - unsigned char speaker_force_mute; /* government force mute pa */ -#endif +#ifdef OPLUS_ARCH_EXTENDS + unsigned char spin_flag; + unsigned char speaker_force_mute; /* government force mute pa */ +#endif int reset_gpio; int irq_gpio; unsigned char fw_status; @@ -173,10 +173,6 @@ struct aw882xx { struct delayed_work interrupt_work; struct delayed_work dc_work; struct delayed_work fw_work; -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - struct delayed_work check_work; - ktime_t last_fb; -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ #ifdef OPLUS_ARCH_EXTENDS struct proc_dir_entry *dbg_dir; diff --git a/sound/soc/codecs/audio/driver/Makefile b/sound/soc/codecs/audio/driver/Makefile index be59b94cc52f..330a256429cb 100755 --- a/sound/soc/codecs/audio/driver/Makefile +++ b/sound/soc/codecs/audio/driver/Makefile @@ -14,4 +14,3 @@ snd-audio-extend-objs := audio_extend_drv.o obj-y += snd-audio-extend.o snd-hal-feedback-objs := hal_feedback.o -obj-$(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) += snd-hal-feedback.o diff --git a/sound/soc/codecs/audio/driver/hal_feedback.c b/sound/soc/codecs/audio/driver/hal_feedback.c deleted file mode 100755 index 168f84140ee0..000000000000 --- a/sound/soc/codecs/audio/driver/hal_feedback.c +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************************ -** File: - -** Copyright (C), 2020-2025, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** add hal feedback -** Version: 1.0 -** --------------------------- Revision History: -------------------------------- -** -** -************************************************************************************/ -#include -#include -#include -#include - -#define HAL_FEEDBACK_MAX_BYTES (256) -#define AUDIO_EVENTID_HAL_ERR (10008) -#define OPLUS_FB_HAL_ERR_RATELIMIT (60*1000) - -int hal_feedback_config_get(struct snd_kcontrol *kcontrol, - unsigned int __user *bytes, - unsigned int size) -{ - return 0; -} -EXPORT_SYMBOL(hal_feedback_config_get); - -int hal_feedback_config_set(struct snd_kcontrol *kcontrol, - const unsigned int __user *bytes, - unsigned int size) -{ - int ret = 0; - char info[HAL_FEEDBACK_MAX_BYTES + 1] = {0}; - unsigned int len = size; - - if (len > HAL_FEEDBACK_MAX_BYTES) { - len = HAL_FEEDBACK_MAX_BYTES; - pr_info("%s(), size(%d) > Max bytes(%d)", - __func__, size, HAL_FEEDBACK_MAX_BYTES); - } - - if (copy_from_user(info, bytes, len)) { - pr_err("%s(), Fail copy to user Ptr:(%p),len:%d", - __func__, bytes, len); - ret = -EFAULT; - } else { - info[len] = '\0'; - ret = upload_mm_fb_kevent_to_atlas_limit(AUDIO_EVENTID_HAL_ERR, info, - OPLUS_FB_HAL_ERR_RATELIMIT); - } - - return ret; -} -EXPORT_SYMBOL(hal_feedback_config_set); - -MODULE_LICENSE("GPL v2"); - - diff --git a/sound/soc/codecs/audio/fsa44xx/fsa4480-i2c.c b/sound/soc/codecs/audio/fsa44xx/fsa4480-i2c.c index ae8487318013..beede7c36780 100755 --- a/sound/soc/codecs/audio/fsa44xx/fsa4480-i2c.c +++ b/sound/soc/codecs/audio/fsa44xx/fsa4480-i2c.c @@ -14,8 +14,6 @@ #include //#endif /*OPLUS_ARCH_EXTENDS*/ -#include - #include "fsa4480-i2c.h" #include "../../../../drivers/misc/mediatek/typec/tcpc/inc/tcpm.h" @@ -111,7 +109,6 @@ static void fsa4480_usbc_digit_work_fn(struct work_struct *work) struct fsa4480_priv *fsa_priv = container_of(work, struct fsa4480_priv, usbc_digit_work); unsigned int reg04,reg05,reg06,reg07; - char buf[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; struct device *dev; if (!fsa_priv) { @@ -132,11 +129,6 @@ static void fsa4480_usbc_digit_work_fn(struct work_struct *work) dev_info(dev, "%s: is not audio jack,reg04:%02x,reg05:%02x,reg06:%02x,reg07:%02x\n", __func__, reg04, reg05, reg06, reg07); if ((reg04 != 0x98) || (reg05 != 0x18) || (reg06 != 0x05) || (reg07 != 0x00)) { - dev_info(dev, "%s: error status\n",__func__); - scnprintf(buf, sizeof(buf) - 1, "func@@%s$$typec_mode@@%d,%d$$regs@@%02x,%02x,%02x,%02x", \ - __func__, fsa_priv->old_state, fsa_priv->new_state,reg04,reg05,reg06,reg07); - upload_mm_fb_kevent_to_atlas_limit(OPLUS_AUDIO_EVENTID_HEADSET_DET, buf, MM_FB_KEY_RATELIMIT_1MIN); - if (fsa_priv->new_state == TYPEC_UNATTACHED) { regmap_write(fsa_priv->regmap, FSA4480_RESET, 0x01); usleep_range(1000, 1005); diff --git a/sound/soc/mediatek/audio_dsp/mtk-base-dsp.h b/sound/soc/mediatek/audio_dsp/mtk-base-dsp.h index 5f2b4ecf78d5..f88817bf2a9f 100755 --- a/sound/soc/mediatek/audio_dsp/mtk-base-dsp.h +++ b/sound/soc/mediatek/audio_dsp/mtk-base-dsp.h @@ -48,9 +48,6 @@ struct mtk_base_dsp_mem { unsigned int dsp_feature_counter; int adsp_xrun_flag; spinlock_t ringbuf_lock; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - int underflow_cnt; -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ }; struct audio_core_flag { diff --git a/sound/soc/mediatek/audio_dsp/mtk-dsp-common.c b/sound/soc/mediatek/audio_dsp/mtk-dsp-common.c index 0120b6c8d567..3126dd462d3c 100755 --- a/sound/soc/mediatek/audio_dsp/mtk-dsp-common.c +++ b/sound/soc/mediatek/audio_dsp/mtk-dsp-common.c @@ -19,10 +19,6 @@ #include #include -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#include "../feedback/oplus_audio_kernel_fb.h" -#endif - #ifdef CONFIG_MTK_AUDIODSP_SUPPORT #include #else @@ -126,13 +122,6 @@ int mtk_scp_ipi_send(int task_scene, int data_type, int ack_type, pr_info("%s(),scp_ipi send fail\n", __func__); -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) - if (send_result) { - ratelimited_fb("payload@@scp_ipi send fail,ret=%d,task_scene=%d,msg_id=%d", \ - send_result, get_dspdaiid_by_dspscene(task_scene), msg_id); - } -#endif - return send_result; } diff --git a/sound/soc/mediatek/audio_dsp/mtk-dsp-common.h b/sound/soc/mediatek/audio_dsp/mtk-dsp-common.h index 07669ef4c109..23fcaac27fbe 100755 --- a/sound/soc/mediatek/audio_dsp/mtk-dsp-common.h +++ b/sound/soc/mediatek/audio_dsp/mtk-dsp-common.h @@ -28,22 +28,8 @@ #include #endif -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#include "../feedback/oplus_audio_kernel_fb.h" -#endif - #ifdef CONFIG_MTK_AEE_FEATURE -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#define AUD_ASSERT(exp) \ -do { \ - if (!(exp)) { \ - ratelimited_fb("payload@@AUD_ASSERT:("#exp") fail"); \ - aee_kernel_exception_api(__FILE__, __LINE__, DB_OPT_DEFAULT, \ - "[Audio]", "ASSERT("#exp") fail!!"); \ - } \ -} while (0) -#else /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ #define AUD_ASSERT(exp) \ do { \ if (!(exp)) { \ @@ -51,21 +37,7 @@ do { \ "[Audio]", "ASSERT("#exp") fail!!"); \ } \ } while (0) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - #else - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#define AUD_ASSERT(exp) \ -do { \ - if (!(exp)) { \ - ratelimited_fb("payload@@AUD_ASSERT:("#exp") fail"); \ - pr_notice("ASSERT("#exp") fail: \"" __FILE__ "\", %uL\n", \ - __LINE__); \ - } \ -} while (0) -#else /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - #define AUD_ASSERT(exp) \ do { \ if (!(exp)) { \ @@ -73,8 +45,6 @@ do { \ __LINE__); \ } \ } while (0) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - #endif /* wake lock relate*/ diff --git a/sound/soc/mediatek/audio_dsp/mtk-dsp-platform-driver.c b/sound/soc/mediatek/audio_dsp/mtk-dsp-platform-driver.c index 43c51d489f50..b84366f1d1a4 100755 --- a/sound/soc/mediatek/audio_dsp/mtk-dsp-platform-driver.c +++ b/sound/soc/mediatek/audio_dsp/mtk-dsp-platform-driver.c @@ -26,11 +26,6 @@ #include "mtk-dsp-platform-driver.h" #include "mtk-base-afe.h" -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#include -#define OPLUS_AUDIO_EVENTID_MTK_UNDERRUN_ERR 10043 -#define OPLUS_MTK_UNDERRUN_FEEDBACK_CNT (20) -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ static DEFINE_MUTEX(adsp_wakelock_lock); #define IPIMSG_SHARE_MEM (1024) @@ -986,9 +981,6 @@ static bool mtk_dsp_dl_consume_check_exception(struct mtk_base_dsp *dsp, pr_info("%s adsp reset id = %d\n", __func__, id); RingBuf_Reset(&dsp->dsp_mem[id].ring_buf); dsp->dsp_mem[id].adsp_xrun_flag = true; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - dsp->dsp_mem[id].underflow_cnt++; -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ snd_pcm_period_elapsed(dsp->dsp_mem[id].substream); return true; } @@ -997,9 +989,6 @@ static bool mtk_dsp_dl_consume_check_exception(struct mtk_base_dsp *dsp, if (ipi_msg && ipi_msg->param2 == ADSP_DL_CONSUME_UNDERFLOW) { pr_info("%s adsp underflowed id = %d\n", __func__, id); dsp->dsp_mem[id].adsp_xrun_flag = true; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - dsp->dsp_mem[id].underflow_cnt++; -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ snd_pcm_period_elapsed(dsp->dsp_mem[id].substream); return true; } @@ -1211,26 +1200,6 @@ static int mtk_dsp_pcm_close(struct snd_pcm_substream *substream) pr_info("%s(), task_id: %d\n", __func__, id); -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - if (dsp->dsp_mem[id].underflow_cnt > OPLUS_MTK_UNDERRUN_FEEDBACK_CNT) { - if (substream->pcm && substream->runtime) { - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_MTK_UNDERRUN_ERR, \ - MM_FB_KEY_RATELIMIT_5MIN, "payload@@MTK adsp underflow,task_scene=%d,underrun=%d,pcm=%d,sample_rate=%d", \ - get_dspscene_by_dspdaiid(id), \ - dsp->dsp_mem[id].underflow_cnt, \ - substream->pcm->device, \ - substream->runtime->rate); - } else { - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_MTK_UNDERRUN_ERR, \ - MM_FB_KEY_RATELIMIT_5MIN, "payload@@MTK adsp underflow,task_scene=%d,underrun=%d", \ - get_dspscene_by_dspdaiid(id), \ - dsp->dsp_mem[id].underflow_cnt); - } - } - pr_info("%s(), task_scene = %d, underflow_cnt = %d\n", __func__, - get_dspscene_by_dspdaiid(id), dsp->dsp_mem[id].underflow_cnt); - dsp->dsp_mem[id].underflow_cnt = 0; -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ /* send to task with close information */ ret = mtk_scp_ipi_send(get_dspscene_by_dspdaiid(id), AUDIO_IPI_MSG_ONLY, diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c index c7b0348f918c..ceaa45446d6b 100755 --- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c +++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c @@ -58,7 +58,6 @@ //#ifdef OPLUS_ARCH_EXTENDS /*Jianqing.Liao@AudioDriver, 2021/07/28, add for memif reg access error address */ -#include #define OPLUS_AUDIO_EVENTID_AFE_ERROR (10026) //#endif @@ -803,7 +802,6 @@ int mtk_memif_set_addr(struct mtk_base_afe *afe, int id, //#ifdef OPLUS_ARCH_EXTENDS /*Jianqing.Liao@AudioDriver, 2021/07/28, add for memif reg access error address */ unsigned int value = 0; - char buf[MM_KEVENT_MAX_PAYLOAD_SIZE] = {0}; /* check the memif already disable */ regmap_read(afe->regmap, memif->data->enable_reg, &value); @@ -811,9 +809,6 @@ int mtk_memif_set_addr(struct mtk_base_afe *afe, int id, mtk_memif_set_disable(afe, id); pr_info("%s memif[%d] is enabled before set_addr, en:0x%x\n", __func__, id, value); - scnprintf(buf, sizeof(buf) - 1, "$$memif_id@@%d$regs@@%x", \ - id, value); - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_AFE_ERROR, MM_FB_KEY_RATELIMIT_1MIN, buf); } //#endif diff --git a/sound/soc/mediatek/common/mtk-sp-common.h b/sound/soc/mediatek/common/mtk-sp-common.h index 1c406c4bb12d..a600c7b254c0 100755 --- a/sound/soc/mediatek/common/mtk-sp-common.h +++ b/sound/soc/mediatek/common/mtk-sp-common.h @@ -9,40 +9,16 @@ #ifndef _MTK_SP_COMMON_H_ #define _MTK_SP_COMMON_H_ -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#include "../feedback/oplus_audio_kernel_fb.h" -#endif - #if defined(CONFIG_MTK_AEE_FEATURE) #include -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#define AUDIO_AEE(message) \ - do { \ - ratelimited_fb("payload@@AUDIO_AEE:"message); \ - (aee_kernel_exception_api(__FILE__, \ - __LINE__, \ - DB_OPT_FTRACE, message, \ - "audio assert")); \ - } while (0) -#else /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ - #define AUDIO_AEE(message) \ (aee_kernel_exception_api(__FILE__, \ __LINE__, \ DB_OPT_FTRACE, message, \ "audio assert")) -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #else -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#define AUDIO_AEE(message) \ - do { \ - ratelimited_fb("payload@@AUDIO_AEE:"message); \ - WARN_ON(true); \ - } while (0) -#else /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #define AUDIO_AEE(message) WARN_ON(true) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ #endif /* Declare weak function due to not all platform has definition */ diff --git a/sound/soc/mediatek/feedback/oplus_audio_kernel_fb.h b/sound/soc/mediatek/feedback/oplus_audio_kernel_fb.h deleted file mode 100755 index 7e60e5ead6a4..000000000000 --- a/sound/soc/mediatek/feedback/oplus_audio_kernel_fb.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************************ -** File: - vendor\oplus\kernel\audio\include\oplus_audio_kernel_fb.h -** CONFIG_OPLUS_FEATURE_MM_FEEDBACK -** Copyright (C), 2022-2024, OPLUS Mobile Comm Corp., Ltd -** -** Description: -** add oplus audio kernel feedback -** Version: 1.0 -** --------------------------- Revision History: -------------------------------- -** -************************************************************************************/ -#ifndef OPLUS_AUDIO_KERNEL_FB_H -#define OPLUS_AUDIO_KERNEL_FB_H - -#include -#include - -#define OPLUS_AUDIO_EVENTID_AUDIO_KERNEL_ERR (10047) -#define FEEDBACK_RATELIMIT_INTERVAL (300 * HZ) -#define FEEDBACK_RATELIMIT_BURST 1 - -#define ratelimited_fb(fmt, ...) \ - do { \ - static DEFINE_RATELIMIT_STATE(_rs, \ - FEEDBACK_RATELIMIT_INTERVAL, \ - FEEDBACK_RATELIMIT_BURST); \ - if (__ratelimit(&_rs)) \ - mm_fb_audio_kevent_named(OPLUS_AUDIO_EVENTID_AUDIO_KERNEL_ERR, \ - MM_FB_KEY_RATELIMIT_30MIN, fmt, ##__VA_ARGS__); \ - } while (0) - -/* print error log and feedback */ -#define pr_err_fb(fmt, ...) \ - do { \ - printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__); \ - ratelimited_fb("payload@@"fmt, ##__VA_ARGS__); \ - } while (0) - -#endif /* OPLUS_AUDIO_KERNEL_FB_H */ - diff --git a/sound/soc/mediatek/mt6833/mt6833-mt6359.c b/sound/soc/mediatek/mt6833/mt6833-mt6359.c index f5eebfd63a69..2b3349df84eb 100755 --- a/sound/soc/mediatek/mt6833/mt6833-mt6359.c +++ b/sound/soc/mediatek/mt6833/mt6833-mt6359.c @@ -373,15 +373,6 @@ static const struct snd_soc_dapm_route mt6833_mt6359_routes[] = { #endif /*OPLUS_BUG_COMPATIBILITY*/ }; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#define HAL_FEEDBACK_MAX_BYTES (256) -extern int hal_feedback_config_get(struct snd_kcontrol *kcontrol, - unsigned int __user *bytes, - unsigned int size); -extern int hal_feedback_config_set(struct snd_kcontrol *kcontrol, - const unsigned int __user *bytes, - unsigned int size); -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ static const struct snd_kcontrol_new mt6833_mt6359_controls[] = { SOC_DAPM_PIN_SWITCH(EXT_SPK_AMP_W_NAME), @@ -408,11 +399,6 @@ static const struct snd_kcontrol_new mt6833_mt6359_controls[] = { .get = mt6853_audio_extern_config_get }, #endif //OPLUS_BUG_COMPATIBILITY - #ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - SND_SOC_BYTES_TLV("HAL FEEDBACK", - HAL_FEEDBACK_MAX_BYTES, - hal_feedback_config_get, hal_feedback_config_set), - #endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK }; /* diff --git a/sound/soc/mediatek/mt6853/mt6853-mt6359.c b/sound/soc/mediatek/mt6853/mt6853-mt6359.c index be3dbdcb043c..4e518e37376d 100755 --- a/sound/soc/mediatek/mt6853/mt6853-mt6359.c +++ b/sound/soc/mediatek/mt6853/mt6853-mt6359.c @@ -275,15 +275,6 @@ static const struct snd_soc_dapm_route mt6853_mt6359_routes[] = { {EXT_SPK_AMP_W_NAME, NULL, "Headphone R Ext Spk Amp"}, }; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#define HAL_FEEDBACK_MAX_BYTES (256) -extern int hal_feedback_config_get(struct snd_kcontrol *kcontrol, - unsigned int __user *bytes, - unsigned int size); -extern int hal_feedback_config_set(struct snd_kcontrol *kcontrol, - const unsigned int __user *bytes, - unsigned int size); -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ static const struct snd_kcontrol_new mt6853_mt6359_controls[] = { @@ -294,11 +285,6 @@ static const struct snd_kcontrol_new mt6853_mt6359_controls[] = { mt6853_spk_i2s_out_type_get, NULL), SOC_ENUM_EXT("MTK_SPK_I2S_IN_TYPE_GET", mt6853_spk_type_enum[1], mt6853_spk_i2s_in_type_get, NULL), - #ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - SND_SOC_BYTES_TLV("HAL FEEDBACK", - HAL_FEEDBACK_MAX_BYTES, - hal_feedback_config_get, hal_feedback_config_set), - #endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK #ifdef OPLUS_BUG_COMPATIBILITY #ifdef OPLUS_FEATURE_SPEAKER_MUTE SOC_ENUM_EXT("Speaker_Mute_Switch", spkmute_snd_enum[0], speaker_mute_get_status, speaker_mute_put_status), diff --git a/sound/soc/mediatek/mt6877/mt6877-mt6359.c b/sound/soc/mediatek/mt6877/mt6877-mt6359.c index ef1be7a09e9e..8af07bbd3ca2 100755 --- a/sound/soc/mediatek/mt6877/mt6877-mt6359.c +++ b/sound/soc/mediatek/mt6877/mt6877-mt6359.c @@ -163,15 +163,6 @@ static const struct snd_soc_dapm_route mt6877_mt6359_routes[] = { {EXT_SPK_AMP_W_NAME, NULL, "Headphone R Ext Spk Amp"}, }; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#define HAL_FEEDBACK_MAX_BYTES (256) -extern int hal_feedback_config_get(struct snd_kcontrol *kcontrol, - unsigned int __user *bytes, - unsigned int size); -extern int hal_feedback_config_set(struct snd_kcontrol *kcontrol, - const unsigned int __user *bytes, - unsigned int size); -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ static const struct snd_kcontrol_new mt6877_mt6359_controls[] = { SOC_DAPM_PIN_SWITCH(EXT_SPK_AMP_W_NAME), SOC_ENUM_EXT("MTK_SPK_TYPE_GET", mt6877_spk_type_enum[0], @@ -184,11 +175,6 @@ static const struct snd_kcontrol_new mt6877_mt6359_controls[] = { SOC_ENUM_EXT("TFA_HAPTIC_RING_SYNC", tfa_haptic_type_enum[0], tfa_haptic_ring_sync_get, tfa_haptic_ring_sync_set), #endif /*CONFIG_SND_SOC_TFA_HAPTIC*/ -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - SND_SOC_BYTES_TLV("HAL FEEDBACK", - HAL_FEEDBACK_MAX_BYTES, - hal_feedback_config_get, hal_feedback_config_set), -#endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK }; /* diff --git a/sound/soc/mediatek/mt6885/mt6885-mt6359.c b/sound/soc/mediatek/mt6885/mt6885-mt6359.c index ac35acfb5436..5e73c082ac71 100755 --- a/sound/soc/mediatek/mt6885/mt6885-mt6359.c +++ b/sound/soc/mediatek/mt6885/mt6885-mt6359.c @@ -156,15 +156,6 @@ static const struct snd_soc_dapm_route mt6885_mt6359_routes[] = { {EXT_SPK_AMP_W_NAME, NULL, "Headphone R Ext Spk Amp"}, }; -#ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK -#define HAL_FEEDBACK_MAX_BYTES (256) -extern int hal_feedback_config_get(struct snd_kcontrol *kcontrol, - unsigned int __user *bytes, - unsigned int size); -extern int hal_feedback_config_set(struct snd_kcontrol *kcontrol, - const unsigned int __user *bytes, - unsigned int size); -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ static const struct snd_kcontrol_new mt6885_mt6359_controls[] = { SOC_DAPM_PIN_SWITCH(EXT_SPK_AMP_W_NAME), @@ -174,11 +165,6 @@ static const struct snd_kcontrol_new mt6885_mt6359_controls[] = { mt6885_spk_i2s_out_type_get, NULL), SOC_ENUM_EXT("MTK_SPK_I2S_IN_TYPE_GET", mt6885_spk_type_enum[1], mt6885_spk_i2s_in_type_get, NULL), - #ifdef CONFIG_OPLUS_FEATURE_MM_FEEDBACK - SND_SOC_BYTES_TLV("HAL FEEDBACK", - HAL_FEEDBACK_MAX_BYTES, - hal_feedback_config_get, hal_feedback_config_set), - #endif //CONFIG_OPLUS_FEATURE_MM_FEEDBACK #ifdef OPLUS_ARCH_EXTENDS #ifdef CONFIG_SND_SOC_TFA_HAPTIC SOC_ENUM_EXT("TFA_HAPTIC_RING_SYNC", tfa_haptic_type_enum[0], diff --git a/sound/soc/mediatek/scp_ultra/mtk-scp-ultra-common.h b/sound/soc/mediatek/scp_ultra/mtk-scp-ultra-common.h index f72d4c066da7..ffd0f4a54d2f 100755 --- a/sound/soc/mediatek/scp_ultra/mtk-scp-ultra-common.h +++ b/sound/soc/mediatek/scp_ultra/mtk-scp-ultra-common.h @@ -7,9 +7,6 @@ #define _MTK_SCP_ULTRA_COMMON_H #include -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#include "../feedback/oplus_audio_kernel_fb.h" -#endif #ifdef scp_ultra_debug #undef scp_ultra_debug @@ -22,39 +19,14 @@ #if defined(CONFIG_MTK_AEE_FEATURE) #include -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) -#ifndef AUDIO_AEE -#define AUDIO_AEE(message) \ - do { \ - ratelimited_fb("payload@@AUDIO_AEE:"message); \ - (aee_kernel_exception_api(__FILE__, \ - __LINE__, \ - DB_OPT_FTRACE, message, \ - "audio assert")); \ - } while (0) -#endif -#else /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #define AUDIO_AEE(message) \ (aee_kernel_exception_api(__FILE__, \ __LINE__, \ DB_OPT_FTRACE, message, \ "audio assert")) -#endif /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ - #else - -#if IS_ENABLED(CONFIG_OPLUS_FEATURE_MM_FEEDBACK) #ifndef AUDIO_AEE -#define AUDIO_AEE(message) \ - do { \ - ratelimited_fb("payload@@AUDIO_AEE:"message); \ - WARN_ON(true); \ - } while (0) -#endif -#else /* CONFIG_OPLUS_FEATURE_MM_FEEDBACK */ #define AUDIO_AEE(message) WARN_ON(true) -#endif /*CONFIG_OPLUS_FEATURE_MM_FEEDBACK*/ - #endif /* wake lock relate*/