blob: 890c71a475c52f90d63bde0ac25e098ca54acba6 [file] [log] [blame]
ReStranger1b85f702025-09-30 04:05:06 +03001# Copyright (c) 2020-2022 Qualcomm Technologies, Inc.
2# All Rights Reserved.
3# Confidential and Proprietary - Qualcomm Technologies, Inc.
4#
5# Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# * Neither the name of The Linux Foundation nor
15# the names of its contributors may be used to endorse or promote
16# products derived from this software without specific prior written
17# permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#
31
32KernelVersionStr=`cat /proc/sys/kernel/osrelease`
33KernelVersionS=${KernelVersionStr:2:2}
34KernelVersionA=${KernelVersionStr:0:1}
35KernelVersionB=${KernelVersionS%.*}
36
37function configure_zram_parameters() {
38 MemTotalStr=`cat /proc/meminfo | grep MemTotal`
39 MemTotal=${MemTotalStr:16:8}
40
41 low_ram=`getprop ro.config.low_ram`
42
43 # Zram disk - 75% for Go devices.
44 # For 512MB Go device, size = 384MB, set same for Non-Go.
45 # For 1GB Go device, size = 768MB, set same for Non-Go.
46 # For 2GB Go device, size = 1536MB, set same for Non-Go.
47 # For >2GB Non-Go devices, size = 50% of RAM size. Limit the size to 4GB.
48 # And enable lz4 zram compression for Go targets.
49
50 let RamSizeGB="( $MemTotal / 1048576 ) + 1"
51 diskSizeUnit=M
52 if [ $RamSizeGB -le 2 ]; then
53 let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4"
54 else
55 let zRamSizeMB="( $RamSizeGB * 1024 ) / 2"
56 fi
57
58 # use MB avoid 32 bit overflow
59 if [ $zRamSizeMB -gt 4096 ]; then
60 let zRamSizeMB=4096
61 fi
62
63 if [ "$low_ram" == "true" ]; then
64 echo lz4 > /sys/block/zram0/comp_algorithm
65 fi
66
67 if [ -f /sys/block/zram0/disksize ]; then
68 if [ -f /sys/block/zram0/use_dedup ]; then
69 echo 1 > /sys/block/zram0/use_dedup
70 fi
71 echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize
72
73 # ZRAM may use more memory than it saves if SLAB_STORE_USER
74 # debug option is enabled.
75 if [ -e /sys/kernel/slab/zs_handle ]; then
76 echo 0 > /sys/kernel/slab/zs_handle/store_user
77 fi
78 if [ -e /sys/kernel/slab/zspage ]; then
79 echo 0 > /sys/kernel/slab/zspage/store_user
80 fi
81
82 mkswap /dev/block/zram0
83 swapon /dev/block/zram0 -p 32758
84 fi
85}
86
87function configure_read_ahead_kb_values() {
88 MemTotalStr=`cat /proc/meminfo | grep MemTotal`
89 MemTotal=${MemTotalStr:16:8}
90
91 dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc -e sd)
92 # dmpts holds below read_ahead_kb nodes if exists:
93 # /sys/block/dm-0/queue/read_ahead_kb to /sys/block/dm-10/queue/read_ahead_kb
94 # /sys/block/sda/queue/read_ahead_kb to /sys/block/sdh/queue/read_ahead_kb
95
96 # Set 128 for <= 3GB &
97 # set 512 for >= 4GB targets.
98 if [ $MemTotal -le 3145728 ]; then
99 ra_kb=128
100 else
101 ra_kb=512
102 fi
103 if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then
104 echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb
105 fi
106 if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then
107 echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
108 fi
109 for dm in $dmpts; do
110 echo $ra_kb > $dm
111 done
112}
113
114function disable_core_ctl() {
115 if [ -f /sys/devices/system/cpu/cpu0/core_ctl/enable ]; then
116 echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable
117 else
118 echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/disable
119 fi
120}
121
122function configure_memory_parameters() {
123 # Set Memory parameters.
124 #
125 # Set per_process_reclaim tuning parameters
126 # All targets will use vmpressure range 50-70,
127 # All targets will use 512 pages swap size.
128 #
129 # Set Low memory killer minfree parameters
130 # 32 bit Non-Go, all memory configurations will use 15K series
131 # 32 bit Go, all memory configurations will use uLMK + Memcg
132 # 64 bit will use Google default LMK series.
133 #
134 # Set ALMK parameters (usually above the highest minfree values)
135 # vmpressure_file_min threshold is always set slightly higher
136 # than LMK minfree's last bin value for all targets. It is calculated as
137 # vmpressure_file_min = (last bin - second last bin ) + last bin
138 #
139 # Set allocstall_threshold to 0 for all targets.
140 #
141
142 # Set swappiness to 100 for all targets
143 echo 100 > /proc/sys/vm/swappiness
144
145 # Disable wsf for all targets beacause we are using efk.
146 # wsf Range : 1..1000 So set to bare minimum value 1.
147
148 #Set per-app max kgsl reclaim limit and per shrinker call limit
149 if [ -f /sys/class/kgsl/kgsl/page_reclaim_per_call ]; then
150 echo 38400 > /sys/class/kgsl/kgsl/page_reclaim_per_call
151 fi
152
153 if [ -f /sys/class/kgsl/kgsl/max_reclaim_limit ]; then
154 echo 25600 > /sys/class/kgsl/kgsl/max_reclaim_limit
155 fi
156
157 configure_zram_parameters
158
159 configure_read_ahead_kb_values
160
161 # Disable periodic kcompactd wakeups. We do not use THP, so having many
162 # huge pages is not as necessary.
163 echo 0 > /proc/sys/vm/compaction_proactiveness
164
165 # With THP enabled, the kernel greatly increases min_free_kbytes over its
166 # default value. Disable THP to prevent resetting of min_free_kbytes
167 # value during online/offline pages.
168
169 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
170 echo never > /sys/kernel/mm/transparent_hugepage/enabled
171 fi
172
173 MemTotalStr=`cat /proc/meminfo | grep MemTotal`
174 MemTotal=${MemTotalStr:16:8}
175 let RamSizeGB="( $MemTotal / 1048576 ) + 1"
176
177 # Set the min_free_kbytes to standard kernel value
178 if [ $RamSizeGB -ge 8 ]; then
179 echo 11584 > /proc/sys/vm/min_free_kbytes
180 elif [ $RamSizeGB -ge 4 ]; then
181 echo 8192 > /proc/sys/vm/min_free_kbytes
182 elif [ $RamSizeGB -ge 2 ]; then
183 echo 5792 > /proc/sys/vm/min_free_kbytes
184 else
185 echo 4096 > /proc/sys/vm/min_free_kbytes
186 fi
187 extra_free_kbytes_backup_enable=`getprop persist.vendor.spc.mi_extra_free_enable`
188 MIN_PERCPU_PAGELIST_HIGH_FRACTION=8
189
190 if [ "true" = ${extra_free_kbytes_backup_enable} ]; then
191 echo `cat /proc/sys/vm/min_free_kbytes` " " `cat /proc/sys/vm/watermark_scale_factor` " -1" > /sys/kernel/mi_wmark/extra_free_kbytes
192 cat /proc/sys/vm/lowmem_reserve_ratio > /proc/sys/vm/lowmem_reserve_ratio
193
194 percpu_pagelist_high_fraction=`cat /proc/sys/vm/percpu_pagelist_high_fraction`
195 new_percpu_pagelist_high_fraction=${percpu_pagelist_high_fraction}
196 [ ${percpu_pagelist_high_fraction} -lt ${MIN_PERCPU_PAGELIST_HIGH_FRACTION} ] && new_percpu_pagelist_high_fraction=${MIN_PERCPU_PAGELIST_HIGH_FRACTION}
197 let new_percpu_pagelist_high_fraction++
198 echo ${new_percpu_pagelist_high_fraction} > /proc/sys/vm/percpu_pagelist_high_fraction
199 echo ${percpu_pagelist_high_fraction} > /proc/sys/vm/percpu_pagelist_high_fraction
200
201 fi
202}
203
204function start_hbtp()
205{
206 # Start the Host based Touch processing but not in the power off mode.
207 bootmode=`getprop ro.bootmode`
208 if [ "charger" != $bootmode ]; then
209 start vendor.hbtp
210 fi
211}
212
213if [ -f /sys/devices/soc0/soc_id ]; then
214 soc_id=`cat /sys/devices/soc0/soc_id`
215else
216 soc_id=`cat /sys/devices/system/soc/soc0/id`
217fi
218
219configure_memory_parameters
220
221# Configure RT parameters:
222# Long running RT task detection is confined to consolidated builds.
223# Set RT throttle runtime to 50ms more than long running RT
224# task detection time.
225# Set RT throttle period to 100ms more than RT throttle runtime.
226long_running_rt_task_ms=1200
227sched_rt_runtime_ms=`expr $long_running_rt_task_ms + 50`
228sched_rt_runtime_us=`expr $sched_rt_runtime_ms \* 1000`
229sched_rt_period_ms=`expr $sched_rt_runtime_ms + 100`
230sched_rt_period_us=`expr $sched_rt_period_ms \* 1000`
231if [ -d /sys/module/sched_walt_debug ]; then
232 echo $long_running_rt_task_ms > /proc/sys/walt/sched_long_running_rt_task_ms
233fi
234echo $sched_rt_period_us > /proc/sys/kernel/sched_rt_period_us
235echo $sched_rt_runtime_us > /proc/sys/kernel/sched_rt_runtime_us
236
237# Disable Core control on silver
238echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable
239# Core control parameters for gold
240echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus
241echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres
242echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres
243echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms
244echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres
245
246# Controls how many more tasks should be eligible to run on gold CPUs
247# w.r.t number of gold CPUs available to trigger assist (max number of
248# tasks eligible to run on previous cluster minus number of CPUs in
249# the previous cluster).
250#
251# Setting to 1 by default which means there should be at least
252# 5 tasks eligible to run on gold cluster (tasks running on gold cores
253# plus misfit tasks on silver cores) to trigger assitance from gold+.
254#echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/nr_prev_assist_thresh
255
256# Setting b.L scheduler parameters
257echo 65 > /proc/sys/walt/sched_downmigrate
258echo 71 > /proc/sys/walt/sched_upmigrate
259echo 100 > /proc/sys/walt/sched_group_upmigrate
260echo 85 > /proc/sys/walt/sched_group_downmigrate
261echo 1 > /proc/sys/walt/sched_walt_rotate_big_tasks
262echo 400000000 > /proc/sys/walt/sched_coloc_downmigrate_ns
263echo 39000000 39000000 39000000 39000000 39000000 39000000 39000000 39000000 > /proc/sys/walt/sched_coloc_busy_hyst_cpu_ns
264echo 248 > /proc/sys/walt/sched_coloc_busy_hysteresis_enable_cpus
265echo 10 10 10 10 10 10 10 10 > /proc/sys/walt/sched_coloc_busy_hyst_cpu_busy_pct
266echo 8500000 8500000 8500000 8500000 8500000 8500000 8500000 8500000 > /proc/sys/walt/sched_util_busy_hyst_cpu_ns
267echo 255 > /proc/sys/walt/sched_util_busy_hysteresis_enable_cpus
268echo 1 1 1 1 1 1 1 1 > /proc/sys/walt/sched_util_busy_hyst_cpu_util
269echo 40 > /proc/sys/walt/sched_cluster_util_thres_pct
270echo 0 > /proc/sys/walt/sched_idle_enough
271
272#Set early upmigrate tunables
273freq_to_migrate=1228800
274silver_fmax=`cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq`
275silver_early_upmigrate="$((1024 * $silver_fmax / $freq_to_migrate))"
276silver_early_downmigrate="$((((1024 * $silver_fmax) / (((10*$freq_to_migrate) - $silver_fmax) / 10))))"
277sched_upmigrate=`cat /proc/sys/walt/sched_upmigrate`
278sched_downmigrate=`cat /proc/sys/walt/sched_downmigrate`
279sched_upmigrate=${sched_upmigrate:0:2}
280sched_downmigrate=${sched_downmigrate:0:2}
281gold_early_upmigrate="$((1024 * 100 / $sched_upmigrate))"
282gold_early_downmigrate="$((1024 * 100 / $sched_downmigrate))"
283echo $silver_early_downmigrate $gold_early_downmigrate > /proc/sys/walt/sched_early_downmigrate
284echo $silver_early_upmigrate $gold_early_upmigrate > /proc/sys/walt/sched_early_upmigrate
285
286# set the threshold for low latency task boost feature which prioritize
287# binder activity tasks
288echo 325 > /proc/sys/walt/walt_low_latency_task_threshold
289
290# cpuset parameters
291echo 0-3 > /dev/cpuset/background/cpus
292echo 0-3 > /dev/cpuset/system-background/cpus
293
294# Turn off scheduler boost at the end
295echo 0 > /proc/sys/walt/sched_boost
296
297# Reset the RT boost, which is 1024 (max) by default.
298echo 0 > /proc/sys/kernel/sched_util_clamp_min_rt_default
299
300# configure governor settings for silver cluster
301echo "walt" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
302echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/down_rate_limit_us
303echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/up_rate_limit_us
304echo 1516800 > /sys/devices/system/cpu/cpufreq/policy0/walt/hispeed_freq
305echo 691200 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq
306echo 1 > /sys/devices/system/cpu/cpufreq/policy0/walt/pl
307echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/rtg_boost_freq
308
309# configure input boost settings
310echo 1190000 0 0 0 0 0 0 0 > /proc/sys/walt/input_boost/input_boost_freq
311echo 120 > /proc/sys/walt/input_boost/input_boost_ms
312
313echo 1516800 0 0 0 2208000 0 0 0 > /proc/sys/walt/input_boost/powerkey_input_boost_freq
314echo 400 > /proc/sys/walt/input_boost/powerkey_input_boost_ms
315
316# configure governor settings for gold cluster
317echo "walt" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
318echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/down_rate_limit_us
319echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/up_rate_limit_us
320echo 1344000 > /sys/devices/system/cpu/cpufreq/policy4/walt/hispeed_freq
321echo 1056000 > /sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq
322echo 1 > /sys/devices/system/cpu/cpufreq/policy4/walt/pl
323echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/rtg_boost_freq
324
325# cpuset parameters
326echo 0-2 > /dev/cpuset/background/cpus
327echo 0-3 > /dev/cpuset/system-background/cpus
328echo 4-7 > /dev/cpuset/foreground/boost/cpus
329echo 0-2,4-7 > /dev/cpuset/foreground/cpus
330echo 0-7 > /dev/cpuset/top-app/cpus
331
332# configure bus-dcvs
333bus_dcvs="/sys/devices/system/cpu/bus_dcvs"
334
335for device in $bus_dcvs/*
336do
337 cat $device/hw_min_freq > $device/boost_freq
338done
339
340for ddrbw in $bus_dcvs/DDR/*bwmon-ddr
341do
342 echo "762 2086 2929 3879 5931 6881 7980" > $ddrbw/mbps_zones
343 echo 4 > $ddrbw/sample_ms
344 echo 85 > $ddrbw/io_percent
345 echo 20 > $ddrbw/hist_memory
346 echo 0 > $ddrbw/hyst_length
347 echo 80 > $ddrbw/down_thres
348 echo 0 > $ddrbw/guard_band_mbps
349 echo 250 > $ddrbw/up_scale
350 echo 1600 > $ddrbw/idle_mbps
351 echo 2092000 > $ddrbw/max_freq
352done
353
354echo s2idle > /sys/power/mem_sleep
355echo N > /sys/devices/system/cpu/qcom_lpm/parameters/sleep_disabled
356
357# Let kernel know our image version/variant/crm_version
358if [ -f /sys/devices/soc0/select_image ]; then
359 image_version="10:"
360 image_version+=`getprop ro.build.id`
361 image_version+=":"
362 image_version+=`getprop ro.build.version.incremental`
363 image_variant=`getprop ro.product.name`
364 image_variant+="-"
365 image_variant+=`getprop ro.build.type`
366 oem_version=`getprop ro.build.version.codename`
367 echo 10 > /sys/devices/soc0/select_image
368 echo $image_version > /sys/devices/soc0/image_version
369 echo $image_variant > /sys/devices/soc0/image_variant
370 echo $oem_version > /sys/devices/soc0/image_crm_version
371fi
372
373echo 4 > /proc/sys/kernel/printk
374
375# Change console log level as per console config property
376console_config=`getprop persist.vendor.console.silent.config`
377case "$console_config" in
378 "1")
379 echo "Enable console config to $console_config"
380 echo 0 > /proc/sys/kernel/printk
381 ;;
382 *)
383 echo "Enable console config to $console_config"
384 ;;
385esac
386
387# Post-setup services
388setprop vendor.post_boot.parsed 1