-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnitrond
executable file
·494 lines (453 loc) · 17.8 KB
/
nitrond
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
#!/usr/bin/env bash
# shellcheck disable=SC2034
# shellcheck disable=SC2059
# shellcheck disable=SC1091
# shellcheck disable=SC2015
# shellcheck disable=SC1087
# shellcheck disable=SC2181
# shellcheck disable=SC2261
#
# Copyright (C) 2022~2023 UsiFX <[email protected]>
# Kartik728 <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License
#
# 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.
#
### Local Variables
# \e colors
BLUE='\e[1;34m'
GREEN='\e[1;32m'
PURPLE='\e[1;35m'
CYAN='\e[1;36m'
RED='\e[1;31m'
WHITE='\e[1;37m'
YELLOW='\e[01;33m'
STOCK='\e[1;0m'
NITRON_VERSION='1.3.1'
PROMPT_COMMAND='sync'
# Disable Shell's Monitor Mode
set +o monitor
# Environment variables
if grep -q "androidboot" /proc/cmdline; then
HEADER_SOURCE="/system/etc"
NITRON_RELAX_DIR='/sdcard'
NITRON_LOG_DIR='/cache'
else
if command -v "resetprop" >/dev/null; then
HEADER_SOURCE="/system/etc"
NITRON_RELAX_DIR='/sdcard'
NITRON_LOG_DIR='/cache'
else
HEADER_SOURCE="${PREFIX/\/usr}/usr/include"
NITRON_RELAX_DIR='/etc'
NITRON_LOG_DIR='/tmp'
fi
fi
# Include headers
if [[ ! -f $HEADER_SOURCE/nitronapi.sh ]]; then
echo "missing header, $HEADER_SOURCE/nitronapi.sh"
exit 1
else
source "$HEADER_SOURCE"/nitronapi.sh
LOCKFILE="${NITRON_LOG_DIR}/nitrond-frontend.lock"
fi
# Initialise OS Compatibility check
oschk
# Initialise Mode set
modelockn
# Initialise Android Magisk Module status set-er
apin -as
# Check locker
[[ -f $LOCKFILE ]] && printn -e "nitrond_broadcast(): tool is held by a process and it is still running, cannot continue this instance." || echo $$ > $LOCKFILE
trap 'rm -f $LOCKFILE' EXIT TERM INT
trap 'rm -f $LOCKFILE; trapper; wait' SIGINT SIGTERM SIGHUP INT TERM KILL
# magicn <argument>
magicn() {
PR_PREFIX="magicn"
set_battery_mode() {
[[ "$SOURCE" == "api-auto" ]] && setmoden "Automatic green" || setmoden "Battery"
(
writen "/proc/sys/kernel/perf_cpu_time_max_percent" "2"
writen "/proc/sys/kernel/sched_autogroup_enabled" "1"
writen "/proc/sys/kernel/sched_child_runs_first" "0"
writen "/proc/sys/kernel/sched_tunable_scaling" "0"
writen "/proc/sys/kernel/sched_migration_cost_ns" "5000000"
writen "/proc/sys/kernel/sched_nr_migrate" "256"
writen "/proc/sys/kernel/sched_schedstats" "0"
writen "/proc/sys/kernel/sched_min_task_util_for_colocation" "0"
sleep 1.5
) & spin "applying scheduler tunables..."
writen "/proc/sys/kernel/printk_devkmsg" "off" & spin "disabling printk logging..."
(
writen "/proc/sys/vm/dirty_background_ratio" "2"
writen "/proc/sys/vm/dirty_ratio" "5"
writen "/proc/sys/vm/dirty_expire_centisecs" "500"
writen "/proc/sys/vm/dirty_writeback_centisecs" "500"
writen "/proc/sys/vm/page-cluster" "0"
writen "/proc/sys/vm/stat_interval" "10"
writen "/proc/sys/vm/swappiness" "100"
writen "/proc/sys/vm/vfs_cache_pressure" "100"
sleep 1.5
) & spin "enhancning kernel's VM management..."
(
writen "/proc/sys/net/ipv4/tcp_ecn" "1"
writen "/proc/sys/net/ipv4/tcp_fastopen" "3"
writen "/proc/sys/net/ipv4/tcp_syncookies" "0"
sleep 1.5
) & spin "applying TCP tunables..."
(
writen "/dev/stune/background/schedtune.util.max.effective" "0"
writen "/dev/stune/background/schedtune.util.min.effective" "0"
writen "/dev/stune/background/schedtune.util.max" "0"
writen "/dev/stune/background/schedtune.util.min" "0"
writen "/dev/stune/background/schedtune.boost" "0"
writen "/dev/stune/background/schedtune.prefer_idle" "1"
writen "/dev/stune/foreground/schedtune.util.max.effective" "1"
writen "/dev/stune/foreground/schedtune.util.min.effective" "0"
writen "/dev/stune/foreground/schedtune.util.max" "1"
writen "/dev/stune/foreground/schedtune.util.min" "0"
writen "/dev/stune/foreground/schedtune.boost" "0"
writen "/dev/stune/foreground/schedtune.prefer_idle" "1"
writen "/dev/stune/top-app/schedtune.util.max.effective" "1024"
writen "/dev/stune/top-app/schedtune.util.min.effective" "0"
writen "/dev/stune/top-app/schedtune.util.max" "1024"
writen "/dev/stune/top-app/schedtune.util.min" "0"
writen "/dev/stune/top-app/schedtune.boost" "0"
writen "/dev/stune/top-app/schedtune.prefer_idle" "0"
writen "/dev/stune/schedtune.util.min" "0"
writen "/dev/stune/schedtune.util.max" "512"
writen "/dev/stune/schedtune.util.max.effective" "512"
writen "/dev/stune/schedtune.util.min.effective" "0"
writen "/dev/stune/schedtune.boost" "0"
writen "/dev/stune/schedtune.prefer_idle" "1"
sleep 1.5
) & spin "enhancing SchedTune..."
(
writen "/sys/block/mmcblk0/queue/scheduler" "noop"
writen "/sys/block/mmcblk1/queue/scheduler" "noop"
writen "/sys/block/sda/queue/scheduler" "noop"
writen "/sys/block/sdb/queue/scheduler" "noop"
writen "/proc/cpufreq/cpufreq_power_mode" "1"
writen "/proc/cpufreq/cpufreq_cci_mode" "0"
writen "/sys/devices/system/cpu/eas/enable" "1"
writen "/sys/devices/system/cpu/perf/enable" "0"
writen "/proc/gpufreq/gpufreq_opp_freq" "99000"
writen "/proc/ppm/enabled" "0"
writen "/proc/ppm/policy_status" "1"
writen "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor" "schedutil"
writen "/sys/devices/system/cpu/cpufreq/policy4/scaling_governor" "schedutil"
writen "/sys/devices/system/cpu/cpufreq/policy6/scaling_governor" "schedutil"
writen "/proc/ppm/policy/hard_userlimit_max_cpu_freq" "0 $cpu_max_freq"
writen "/proc/ppm/policy/hard_userlimit_max_cpu_freq" "1 $cpu_max_freq"
writen "/dev/cpuset/foreground/cpus" "0-5"
writen "/dev/cpuset/background/cpus" "0-7"
writen "/dev/cpuset/system-background/cpus" "0-7"
writen "/dev/cpuset/top-app/cpus" "0-7"
writen "/dev/cpuset/restricted/cpus" "0"
writen "/sys/kernel/debug/sched_features" "NEXT_BUDDY"
writen "/sys/kernel/debug/sched_features" "NO_TTWU_QUEUE"
sleep 1.5
) & spin "applying misc changes..."
}
set_balanced_mode() {
[[ "$SOURCE" == "api-auto" ]] && setmoden "Automatic yellow" || setmoden "Balanced"
(
writen "/proc/sys/kernel/perf_cpu_time_max_percent" "5"
writen "/proc/sys/kernel/sched_autogroup_enabled" "1"
writen "/proc/sys/kernel/sched_child_runs_first" "1"
writen "/proc/sys/kernel/sched_tunable_scaling" "0"
writen "/proc/sys/kernel/sched_migration_cost_ns" "5000000"
writen "/proc/sys/kernel/sched_nr_migrate" "32"
writen "/proc/sys/kernel/sched_schedstats" "0"
writen "/proc/sys/kernel/sched_min_task_util_for_colocation" "0"
sleep 1.5
) & spin "applying scheduler tunables..."
writen "/proc/sys/kernel/printk_devkmsg" "off" & spin "disabling printk logging..."
(
writen "/proc/sys/vm/dirty_background_ratio" "10"
writen "/proc/sys/vm/dirty_ratio" "30"
writen "/proc/sys/vm/dirty_expire_centisecs" "3000"
writen "/proc/sys/vm/dirty_writeback_centisecs" "3000"
writen "/proc/sys/vm/page-cluster" "0"
writen "/proc/sys/vm/stat_interval" "10"
writen "/proc/sys/vm/swappiness" "100"
writen "/proc/sys/vm/vfs_cache_pressure" "100"
sleep 1.5
) & spin "enhancning kernel's VM management..."
(
writen "/proc/sys/net/ipv4/tcp_ecn" "1"
writen "/proc/sys/net/ipv4/tcp_fastopen" "3"
writen "/proc/sys/net/ipv4/tcp_syncookies" "0"
sleep 1.5
) & spin "applying TCP tunables..."
(
writen "/dev/stune/background/schedtune.util.max.effective" "0"
writen "/dev/stune/background/schedtune.util.min.effective" "0"
writen "/dev/stune/background/schedtune.util.max" "0"
writen "/dev/stune/background/schedtune.util.min" "0"
writen "/dev/stune/background/schedtune.boost" "0"
writen "/dev/stune/foreground/schedtune.util.max.effective" "1024"
writen "/dev/stune/foreground/schedtune.util.min.effective" "1024"
writen "/dev/stune/foreground/schedtune.util.max" "1024"
writen "/dev/stune/foreground/schedtune.util.min" "0"
writen "/dev/stune/foreground/schedtune.boost" "0"
writen "/dev/stune/top-app/schedtune.util.max.effective" "1024"
writen "/dev/stune/top-app/schedtune.util.min.effective" "0"
writen "/dev/stune/top-app/schedtune.util.max" "1024"
writen "/dev/stune/top-app/schedtune.util.min" "0"
writen "/dev/stune/top-app/schedtune.prefer_idle" "0"
writen "/dev/stune/top-app/schedtune.boost" "1"
writen "/dev/stune/schedtune.util.min" "0"
writen "/dev/stune/schedtune.util.max" "0"
writen "/dev/stune/schedtune.util.max.effective" "1024"
writen "/dev/stune/schedtune.util.min.effective" "0"
writen "/dev/stune/schedtune.boost" "0"
sleep 1.5
) & spin "enhancing SchedTune..."
(
writen "/proc/cpufreq/cpufreq_power_mode" "0"
writen "/proc/cpufreq/cpufreq_cci_mode" "0"
writen "/sys/devices/system/cpu/eas/enable" "2"
writen "/sys/devices/system/cpu/perf/enable" "0"
writen "/proc/gpufreq/gpufreq_opp_freq" "0"
writen "/sys/block/mmcblk0/queue/scheduler" "cfq"
writen "/sys/block/mmcblk1/queue/scheduler" "cfq"
writen "/sys/block/sda/queue/scheduler" "cfq"
writen "/sys/block/sdb/queue/scheduler" "cfq"
writen "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor" "schedutil"
writen "/sys/devices/system/cpu/cpufreq/policy4/scaling_governor" "schedutil"
writen "/sys/devices/system/cpu/cpufreq/policy6/scaling_governor" "schedutil"
writen "/proc/ppm/policy/hard_userlimit_max_cpu_freq" "0 $cpu_max_freq"
writen "/proc/ppm/policy/hard_userlimit_min_cpu_freq" "1 $cpu_max_freq"
writen "/dev/cpuset/foreground/cpus" "0-7"
writen "/dev/cpuset/background/cpus" "0-6"
writen "/dev/cpuset/system-background/cpus" "0-4"
writen "/dev/cpuset/top-app/cpus" "0-7"
writen "/dev/cpuset/restricted/cpus" "0"
writen "/sys/kernel/debug/sched_features" "NEXT_BUDDY"
writen "/sys/kernel/debug/sched_features" "NO_TTWU_QUEUE"
sleep 1.5
) & spin "applying misc changes..."
}
set_gaming_mode() {
[[ "$SOURCE" == "api-auto" ]] && setmoden "Automatic red" || setmoden "Gaming"
(
writen "/proc/sys/kernel/perf_cpu_time_max_percent" "25"
writen "/proc/sys/kernel/sched_autogroup_enabled" "0"
writen "/proc/sys/kernel/sched_child_runs_first" "0"
writen "/proc/sys/kernel/sched_tunable_scaling" "0"
writen "/proc/sys/kernel/sched_migration_cost_ns" "5000000"
writen "/proc/sys/kernel/sched_nr_migrate" "128"
writen "/proc/sys/kernel/sched_schedstats" "0"
sleep 1.5
) & spin "applying scheduler tunables..."
writen "/proc/sys/kernel/printk_devkmsg" "off" & spin "disabling printk logging..."
(
writen "/proc/sys/vm/dirty_background_ratio" "15"
writen "/proc/sys/vm/dirty_ratio" "30"
writen "/proc/sys/vm/dirty_expire_centisecs" "3000"
writen "/proc/sys/vm/dirty_writeback_centisecs" "3000"
writen "/proc/sys/vm/page-cluster" "0"
writen "/proc/sys/vm/stat_interval" "10"
writen "/proc/sys/vm/swappiness" "100"
writen "/proc/sys/vm/vfs_cache_pressure" "80"
sleep 1.5
) & spin "enhancning kernel's VM management..."
(
writen "/proc/sys/net/ipv4/tcp_ecn" "1"
writen "/proc/sys/net/ipv4/tcp_fastopen" "3"
writen "/proc/sys/net/ipv4/tcp_syncookies" "0"
sleep 1.5
) & spin "applying TCP tunables..."
(
writen "/dev/stune/background/schedtune.util.max" "1"
writen "/dev/stune/background/schedtune.util.min" "1"
writen "/dev/stune/background/schedtune.boost" "1"
writen "/dev/stune/background/schedtune.prefer_idle" "0"
writen "/dev/stune/foreground/schedtune.util.max.effective" "1"
writen "/dev/stune/foreground/schedtune.util.min.effective" "0"
writen "/dev/stune/foreground/schedtune.util.max" "1024"
writen "/dev/stune/foreground/schedtune.util.min" "0"
writen "/dev/stune/foreground/schedtune.boost" "13"
writen "/dev/stune/foreground/schedtune.prefer_idle" "0"
writen "/dev/stune/top-app/schedtune.util.max.effective" "1024"
writen "/dev/stune/top-app/schedtune.util.min.effective" "0"
writen "/dev/stune/top-app/schedtune.util.max" "1024"
writen "/dev/stune/top-app/schedtune.util.min" "0"
writen "/dev/stune/top-app/schedtune.boost" "1"
writen "/dev/stune/top-app/schedtune.prefer_idle" "0"
writen "/dev/stune/schedtune.util.min" "1024"
writen "/dev/stune/schedtune.util.max" "1024"
writen "/dev/stune/schedtune.util.max.effective" "1024"
writen "/dev/stune/schedtune.util.min.effective" "0"
writen "/dev/stune/schedtune.boost" "1"
writen "/dev/stune/schedtune.prefer_idle" "0"
sleep 1.5
) & spin "enhancing SchedTune..."
(
writen "/sys/module/pm_hotplug/parameters/loadl" "40"
writen "/sys/module/pm_hotplug/parameters/loadh" "90"
writen "/sys/module/pm_hotplug/parameters/loadl_scroff" "50"
writen "/sys/module/pm_hotplug/parameters/loadh_scroff" "100"
writen "/sys/module/pm_hotplug/parameters/rate" "100"
writen "/sys/module/pm_hotplug/parameters/rate_cpuon" "400"
writen "/sys/module/pm_hotplug/parameters/rate_scroff" "400"
writen "/sys/module/pm_hotplug/parameters/freq_cpu1on" "500000"
sleep 1.5
) & spin "adapting pm_hotplug limitations..."
(
writen "/sys/devices/system/cpu/cpu0/cpufreq/smooth_target" "1"
writen "/sys/devices/system/cpu/cpu0/cpufreq/smooth_offset" "1"
writen "/sys/devices/system/cpu/cpu0/cpufreq/smooth_step" "1"
sleep 1.5
) & spin "enhancing cpufreq smoothness sets..."
(
writen "/proc/cpufreq/cpufreq_power_mode" "3"
writen "/proc/cpufreq/cpufreq_cci_mode" "1"
writen "/sys/devices/system/cpu/eas/enable" "0"
writen "/sys/devices/system/cpu/perf/enable" "1"
writen "/proc/ppm/enabled" "1"
writen "/proc/ppm/policy_status" "1"
writen "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor" "performance"
writen "/sys/devices/system/cpu/cpufreq/policy4/scaling_governor" "performance"
writen "/sys/devices/system/cpu/cpufreq/policy6/scaling_governor" "performance"
writen "/sys/block/mmcblk0/queue/scheduler" "deadline"
writen "/sys/block/mmcblk1/queue/scheduler" "deadline"
writen "/sys/block/sda/queue/scheduler" "deadline"
writen "/sys/block/sdb/queue/scheduler" "deadline"
writen "/sys/block/sdc/queue/scheduler" "deadline"
writen "/proc/ppm/policy/hard_userlimit_max_cpu_freq" "0 $cpu_max_freq"
writen "/proc/ppm/policy/hard_userlimit_min_cpu_freq" "1 $cpu_max_freq"
writen "/dev/cpuset/foreground/cpus" "0-7"
writen "/dev/cpuset/background/cpus" "0-7"
writen "/dev/cpuset/system-background/cpus" "0-7"
writen "/dev/cpuset/top-app/cpus" "0-7"
writen "/dev/cpuset/restricted/cpus" "0"
writen "/sys/kernel/debug/sched_features" "NEXT_BUDDY"
writen "/sys/kernel/debug/sched_features" "NO_TTWU_QUEUE"
sleep 1.5
) & spin "applying misc changes..."
}
case $* in
"-g" | "--green")
printn -l "--- started"
set_battery_mode
printn -l "--- finished"
return 0
;;
"-y" | "--yellow")
printn -l "--- started"
set_balanced_mode
printn -l "--- finished"
return 0
;;
"-r" | "--red")
printn -l "--- started"
set_gaming_mode
printn -l "--- finished"
return 0
;;
esac
}
# Bail out if we aren't running as SU
[[ "$(id -u)" -ne "0" ]] && {
printn -e "please run this tool as SU"
exit 1
}
__nitron_help() {
echo "
Usage: nitrond [OPTION] (e.g. nitrond --update)
Commands:
auto automatically change mode up on some scenarios
cli sort options into friendly-like TUI
deviceinfo shows device resource information
clean wipe stored nitron data
Options:
-sg, --set-green applies ultra power saving scenario
-sr, --set-red applies performance scenario
-sy, --set-yellow applies balance scenario
-v, --version prints license and version
-h, --help shows this help menu
-m, --mode prints current mode
-d, --debug saves shell debug instructions
"
}
if [[ $# -eq "0" ]]; then
tty -s
__nitron_help
else
for arg in "$@"
do
case "${arg}" in
"deviceinfo")
apin -rc
;;
"clean")
apin -c
;;
"auto")
setmoden "Automatic"
apin -as
rm -rf "$NITRON_RELAX_DIR"/nitron.log
apin -rc >> "$NITRON_RELAX_DIR"/nitron.log
printn -ll "started modifying modes up on resource usage"
printn -w "nitrond: auto session started"
printn -i "^C to force stop the daemon, death of this process means end of this auto session."
while true; do apin -ad; done
;;
"cli")
printn -l "starting console_legacy()..."
console_legacy
;;
"-sg" | "--set-green") # Battery mode
# Apply mode
magicn -g
# Display mode set
printn -n "nitrond: current mode: \e[2;42m$(apin -mc)${STOCK}"
# Reload magisk's module prop
apin -as
;;
"-sr" | "--set-red") # Extreme mode
# Apply mode
magicn -r
# Display mode set
printn -n "nitrond: current mode: \e[1;41m$(apin -mc)${STOCK}"
# Reloae magis's module prop
apin -as
;;
"-sy" | "--set-yellow") # Balance mode
# Apply mode
magicn -y
# Display mode set
printn -n "nitrond: current mode: \e[2;43m$(apin -mc)${STOCK}"
# Reload magisk's module prop
apin -as
;;
"-m" | "--mode")
echo -e "nitrond: mode: $(apin -mc)"
return 0
;;
"-v" | "--version")
echo -e "NitronD $(apin -dv), API: $(apin -hv)
Copyright (C) 2022-2023 UsiFX <[email protected]>
Copyright (C) 2022-2023 Kartik728 <[email protected]>
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.."
;;
*"?"* | "h"* | "-h" | "--help") __nitron_help ;;
"-d" | "--debug")
printn -w "execution under debug, please provide arguments to debug"
printn -w "verbose is saved at: $NITRON_LOG_DIR/nitron.verbose.log"
set -x 2>"$NITRON_LOG_DIR"/nitron.verbose.log >/dev/null
;;
*) printn -e "unknown option $*, check 'nitrond --help'." ;;
esac
done
fi