blob: de538ae9fad7d0d6977eb74c4cdf411dd3def087 [file] [log] [blame]
ReStranger1b85f702025-09-30 04:05:06 +03001# Copyright (c) 2020-2023 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 echo 1 > /proc/sys/vm/watermark_scale_factor
148
149 configure_zram_parameters
150
151 configure_read_ahead_kb_values
152
153 # Disable periodic kcompactd wakeups. We do not use THP, so having many
154 # huge pages is not as necessary.
155 echo 0 > /proc/sys/vm/compaction_proactiveness
156
157 # With THP enabled, the kernel greatly increases min_free_kbytes over its
158 # default value. Disable THP to prevent resetting of min_free_kbytes
159 # value during online/offline pages.
160
161 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
162 echo never > /sys/kernel/mm/transparent_hugepage/enabled
163 fi
164
165 MemTotalStr=`cat /proc/meminfo | grep MemTotal`
166 MemTotal=${MemTotalStr:16:8}
167 let RamSizeGB="( $MemTotal / 1048576 ) + 1"
168
169 # Set the min_free_kbytes to standard kernel value
170 if [ $RamSizeGB -ge 8 ]; then
171 echo 11584 > /proc/sys/vm/min_free_kbytes
172 elif [ $RamSizeGB -ge 4 ]; then
173 echo 8192 > /proc/sys/vm/min_free_kbytes
174 elif [ $RamSizeGB -ge 2 ]; then
175 echo 5792 > /proc/sys/vm/min_free_kbytes
176 else
177 echo 4096 > /proc/sys/vm/min_free_kbytes
178 fi
179}
180
181function start_hbtp()
182{
183 # Start the Host based Touch processing but not in the power off mode.
184 bootmode=`getprop ro.bootmode`
185 if [ "charger" != $bootmode ]; then
186 start vendor.hbtp
187 fi
188}
189
190if [ -f /sys/devices/soc0/soc_id ]; then
191 soc_id=`cat /sys/devices/soc0/soc_id`
192else
193 soc_id=`cat /sys/devices/system/soc/soc0/id`
194fi
195
196configure_memory_parameters
197
198# Configure RT parameters:
199# Long running RT task detection is confined to consolidated builds.
200# Set RT throttle runtime to 50ms more than long running RT
201# task detection time.
202# Set RT throttle period to 100ms more than RT throttle runtime.
203long_running_rt_task_ms=1200
204sched_rt_runtime_ms=`expr $long_running_rt_task_ms + 50`
205sched_rt_runtime_us=`expr $sched_rt_runtime_ms \* 1000`
206sched_rt_period_ms=`expr $sched_rt_runtime_ms + 100`
207sched_rt_period_us=`expr $sched_rt_period_ms \* 1000`
208if [ -d /sys/module/sched_walt_debug ]; then
209 echo $long_running_rt_task_ms > /proc/sys/walt/sched_long_running_rt_task_ms
210fi
211echo $sched_rt_period_us > /proc/sys/kernel/sched_rt_period_us
212echo $sched_rt_runtime_us > /proc/sys/kernel/sched_rt_runtime_us
213
214# Disable Core control on silver
215echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable
216
217# Core control parameters for gold
218if [ -d "/sys/devices/system/cpu/cpu4/" ]; then
219echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres
220echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres
221echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms
222echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres
223if [ -d "/sys/devices/system/cpu/cpu7/" ]; then
224echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus
225echo 1 0 0 0 > /sys/devices/system/cpu/cpu4/core_ctl/not_preferred
226else
227echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus
228echo 1 0 > /sys/devices/system/cpu/cpu4/core_ctl/not_preferred
229fi
230
231elif [ -d "/sys/devices/system/cpu/cpu5/" ]; then
232echo 1 > /sys/devices/system/cpu/cpu5/core_ctl/min_cpus
233echo 60 > /sys/devices/system/cpu/cpu5/core_ctl/busy_up_thres
234echo 40 > /sys/devices/system/cpu/cpu5/core_ctl/busy_down_thres
235echo 100 > /sys/devices/system/cpu/cpu5/core_ctl/offline_delay_ms
236echo 4 > /sys/devices/system/cpu/cpu5/core_ctl/task_thres
237echo 1 0 > /sys/devices/system/cpu/cpu5/core_ctl/not_preferred
238
239elif [ -d "/sys/devices/system/cpu/cpu6/" ]; then
240echo 1 > /sys/devices/system/cpu/cpu6/core_ctl/min_cpus
241echo 60 > /sys/devices/system/cpu/cpu6/core_ctl/busy_up_thres
242echo 40 > /sys/devices/system/cpu/cpu6/core_ctl/busy_down_thres
243echo 100 > /sys/devices/system/cpu/cpu6/core_ctl/offline_delay_ms
244echo 4 > /sys/devices/system/cpu/cpu6/core_ctl/task_thres
245echo 1 0 > /sys/devices/system/cpu/cpu6/core_ctl/not_preferred
246fi
247
248# Controls how many more tasks should be eligible to run on gold CPUs
249# w.r.t number of gold CPUs available to trigger assist (max number of
250# tasks eligible to run on previous cluster minus number of CPUs in
251# the previous cluster).
252#
253# Setting to 1 by default which means there should be at least
254# 5 tasks eligible to run on gold cluster (tasks running on gold cores
255# plus misfit tasks on silver cores) to trigger assitance from gold+.
256#echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/nr_prev_assist_thresh
257
258# Setting b.L scheduler parameters
259echo 65 > /proc/sys/walt/sched_downmigrate
260echo 71 > /proc/sys/walt/sched_upmigrate
261echo 100 > /proc/sys/walt/sched_group_upmigrate
262echo 85 > /proc/sys/walt/sched_group_downmigrate
263echo 1 > /proc/sys/walt/sched_walt_rotate_big_tasks
264echo 400000000 > /proc/sys/walt/sched_coloc_downmigrate_ns
265echo 39000000 39000000 39000000 39000000 39000000 39000000 39000000 39000000 > /proc/sys/walt/sched_coloc_busy_hyst_cpu_ns
266echo 248 > /proc/sys/walt/sched_coloc_busy_hysteresis_enable_cpus
267echo 10 10 10 10 10 10 10 10 > /proc/sys/walt/sched_coloc_busy_hyst_cpu_busy_pct
268echo 8500000 8500000 8500000 8500000 8500000 8500000 8500000 8500000 > /proc/sys/walt/sched_util_busy_hyst_cpu_ns
269echo 255 > /proc/sys/walt/sched_util_busy_hysteresis_enable_cpus
270echo 1 1 1 1 1 1 1 1 > /proc/sys/walt/sched_util_busy_hyst_cpu_util
271echo 40 > /proc/sys/walt/sched_cluster_util_thres_pct
272echo 0 > /proc/sys/walt/sched_idle_enough
273
274#Set early upmigrate tunables
275nr_cpus=`grep -c processor /proc/cpuinfo`
276if [ $nr_cpus -gt 4 ]; then
277freq_to_migrate=1228800
278silver_fmax=`cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq`
279silver_early_upmigrate="$((1024 * $silver_fmax / $freq_to_migrate))"
280silver_early_downmigrate="$((((1024 * $silver_fmax) / (((10*$freq_to_migrate) - $silver_fmax) / 10))))"
281sched_upmigrate=`cat /proc/sys/walt/sched_upmigrate`
282sched_downmigrate=`cat /proc/sys/walt/sched_downmigrate`
283sched_upmigrate=${sched_upmigrate:0:2}
284sched_downmigrate=${sched_downmigrate:0:2}
285gold_early_upmigrate="$((1024 * 100 / $sched_upmigrate))"
286gold_early_downmigrate="$((1024 * 100 / $sched_downmigrate))"
287echo $silver_early_downmigrate $gold_early_downmigrate > /proc/sys/walt/sched_early_downmigrate
288echo $silver_early_upmigrate $gold_early_upmigrate > /proc/sys/walt/sched_early_upmigrate
289fi
290
291# set the threshold for low latency task boost feature which prioritize
292# binder activity tasks
293echo 325 > /proc/sys/walt/walt_low_latency_task_threshold
294
295# cpuset parameters
296echo 0-3 > /dev/cpuset/background/cpus
297echo 0-3 > /dev/cpuset/system-background/cpus
298
299# Turn off scheduler boost at the end
300echo 0 > /proc/sys/walt/sched_boost
301
302# Reset the RT boost, which is 1024 (max) by default.
303echo 0 > /proc/sys/kernel/sched_util_clamp_min_rt_default
304
305# configure governor settings for silver cluster
306echo "walt" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
307echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/down_rate_limit_us
308echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/up_rate_limit_us
309echo 1516800 > /sys/devices/system/cpu/cpufreq/policy0/walt/hispeed_freq
310echo 691200 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq
311echo 1 > /sys/devices/system/cpu/cpufreq/policy0/walt/pl
312echo 0 > /sys/devices/system/cpu/cpufreq/policy0/walt/rtg_boost_freq
313
314# configure input boost settings
315echo 1190000 0 0 0 0 0 0 0 > /proc/sys/walt/input_boost/input_boost_freq
316echo 80 > /proc/sys/walt/input_boost/input_boost_ms
317
318# configure governor settings for gold cluster
319if [ -d "/sys/devices/system/cpu/cpufreq/policy4/" ]; then
320echo "walt" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
321echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/down_rate_limit_us
322echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/up_rate_limit_us
323echo 1344000 > /sys/devices/system/cpu/cpufreq/policy4/walt/hispeed_freq
324echo 1056000 > /sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq
325echo 1 > /sys/devices/system/cpu/cpufreq/policy4/walt/pl
326echo 0 > /sys/devices/system/cpu/cpufreq/policy4/walt/rtg_boost_freq
327
328elif [ -d "/sys/devices/system/cpu/cpufreq/policy5/" ]; then
329echo "walt" > /sys/devices/system/cpu/cpufreq/policy5/scaling_governor
330echo 0 > /sys/devices/system/cpu/cpufreq/policy5/walt/down_rate_limit_us
331echo 0 > /sys/devices/system/cpu/cpufreq/policy5/walt/up_rate_limit_us
332echo 1344000 > /sys/devices/system/cpu/cpufreq/policy5/walt/hispeed_freq
333echo 1056000 > /sys/devices/system/cpu/cpufreq/policy5/scaling_min_freq
334echo 1 > /sys/devices/system/cpu/cpufreq/policy5/walt/pl
335echo 0 > /sys/devices/system/cpu/cpufreq/policy5/walt/rtg_boost_freq
336
337elif [ -d "/sys/devices/system/cpu/cpufreq/policy6/" ]; then
338echo "walt" > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
339echo 0 > /sys/devices/system/cpu/cpufreq/policy6/walt/down_rate_limit_us
340echo 0 > /sys/devices/system/cpu/cpufreq/policy6/walt/up_rate_limit_us
341echo 1344000 > /sys/devices/system/cpu/cpufreq/policy6/walt/hispeed_freq
342echo 1056000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq
343echo 1 > /sys/devices/system/cpu/cpufreq/policy6/walt/pl
344echo 0 > /sys/devices/system/cpu/cpufreq/policy6/walt/rtg_boost_freq
345fi
346
347# configure bus-dcvs
348bus_dcvs="/sys/devices/system/cpu/bus_dcvs"
349
350for device in $bus_dcvs/*
351do
352 cat $device/hw_min_freq > $device/boost_freq
353done
354
355for ddrbw in $bus_dcvs/DDR/*bwmon-ddr
356do
357 echo "762 2086 2929 3879 5931 6881 7980" > $ddrbw/mbps_zones
358 echo 4 > $ddrbw/sample_ms
359 echo 85 > $ddrbw/io_percent
360 echo 20 > $ddrbw/hist_memory
361 echo 0 > $ddrbw/hyst_length
362 echo 80 > $ddrbw/down_thres
363 echo 0 > $ddrbw/guard_band_mbps
364 echo 250 > $ddrbw/up_scale
365 echo 1600 > $ddrbw/idle_mbps
366 echo 2092000 > $ddrbw/max_freq
367done
368
369echo s2idle > /sys/power/mem_sleep
370echo N > /sys/devices/system/cpu/qcom_lpm/parameters/sleep_disabled
371
372# Let kernel know our image version/variant/crm_version
373if [ -f /sys/devices/soc0/select_image ]; then
374 image_version="10:"
375 image_version+=`getprop ro.build.id`
376 image_version+=":"
377 image_version+=`getprop ro.build.version.incremental`
378 image_variant=`getprop ro.product.name`
379 image_variant+="-"
380 image_variant+=`getprop ro.build.type`
381 oem_version=`getprop ro.build.version.codename`
382 echo 10 > /sys/devices/soc0/select_image
383 echo $image_version > /sys/devices/soc0/image_version
384 echo $image_variant > /sys/devices/soc0/image_variant
385 echo $oem_version > /sys/devices/soc0/image_crm_version
386fi
387
388echo 4 > /proc/sys/kernel/printk
389
390# Change console log level as per console config property
391console_config=`getprop persist.vendor.console.silent.config`
392case "$console_config" in
393 "1")
394 echo "Enable console config to $console_config"
395 echo 0 > /proc/sys/kernel/printk
396 ;;
397 *)
398 echo "Enable console config to $console_config"
399 ;;
400esac
401
402# Post-setup services
403setprop vendor.post_boot.parsed 1