-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjitter-reducer-functions.shlib
2092 lines (1918 loc) · 79.8 KB
/
jitter-reducer-functions.shlib
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/system/bin/sh
function forceOnlineCPUs()
{
local i st en
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
for i in `seq $st $en`; do
if [ -e "/sys/devices/system/cpu/cpu$i/online" ]; then
chmod 644 "/sys/devices/system/cpu/cpu$i/online"
echo '1' >"/sys/devices/system/cpu/cpu$i/online"
fi
done
fi
}
function searchDefaultCpuGovernor()
{
# Search default CPU governor
local gov=""
local i
for i in `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors`; do
if [ "$i" = "walt" -o "$i" = "sched_pixel" -o "$i" = "schedutil" ]; then
gov="$i"
break;
elif [ ! "$gov" = "schedplus" ]; then
if [ "$i" = "schedplus" ]; then
gov="$i"
elif [ ! "$gov" = "interactive" ]; then
gov="$i"
fi
fi
done
if [ -z "$gov" ]; then
gov="performance"
fi
echo "$gov"
}
function reduceSelinuxJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
setenforce 0
elif [ $flag -lt 0 ]; then
if [ "`getprop ro.build.product`" = "jfltexx" -a "`getprop ro.system.build.version.release`" -ge "12" ]; then
echo "Warning: ignored trying to change Selinux mode" 1>&2
else
setenforce 1
fi
fi
if [ $printStatus -gt 0 ]; then
echo " Selinux mode: `getenforce`"
fi
else
return 1
fi
}
function reduceThermalJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
# Stop thermal core control
if [ -w "/sys/module/msm_thermal/core_control/enabled" ]; then
echo '0' > "/sys/module/msm_thermal/core_control/enabled"
fi
if [ -r "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
local i st en
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
if [ -w "/sys/devices/system/cpu/cpu7/core_ctl/enable" ]; then
# SD850 or higher type core control
echo '1' > "/sys/devices/system/cpu/cpu7/core_ctl/enable"
echo '1' > "/sys/devices/system/cpu/cpu7/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu7/core_ctl/enable"
if [ -w "/sys/devices/system/cpu/cpu4/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
echo '3' > "/sys/devices/system/cpu/cpu4/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
fi
if [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '4' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
fi
elif [ -w "/sys/devices/system/cpu/cpu4/core_ctl/enable" ]; then
# SD840 or lower type core control
echo '1' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
echo '4' > "/sys/devices/system/cpu/cpu4/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
if [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '4' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
fi
elif [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
# unknown type core control
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '4' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
fi
fi
fi
# Stop the MPDecision (CPU hotplug)
if [ "`getprop init.svc.mpdecision`" = "running" ]; then
setprop ctl.stop mpdecision
forceOnlineCPUs
elif [ "`getprop init.svc.mpdecision`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.mpdecision`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
forceOnlineCPUs
fi
elif [ "`getprop init.svc.vendor.mpdecision`" = "running" ]; then
setprop ctl.stop vendor.mpdecision
forceOnlineCPUs
elif [ "`getprop init.svc.vendor.mpdecision`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.vendor.mpdecision`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
forceOnlineCPUs
fi
fi
# Stop the thermal server
if [ "`getprop init.svc.thermal`" = "running" ]; then
setprop ctl.stop thermal
elif [ "`getprop init.svc.thermal`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.thermal`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
elif [ "`getprop init.svc.vendor.thermal`" = "running" ]; then
setprop ctl.stop vendor.thermal
elif [ "`getprop init.svc.vendor.thermal`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.vendor.thermal`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
# Stop the mi_thermald server
if [ "`getprop init.svc.mi_thermald`" = "running" ]; then
setprop ctl.stop mi_thermald
elif [ "`getprop init.svc.mi_thermald`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.mi_thermald`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
elif [ "`getprop init.svc.vendor.mi_thermald`" = "running" ]; then
setprop ctl.stop vendor.mi_thermald
elif [ "`getprop init.svc.vendor.mi_thermald`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.vendor.mi_thermald`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
# Stop the thermal-engine server
if [ "`getprop init.svc.thermal-engine`" = "running" ]; then
setprop ctl.stop thermal-engine
elif [ "`getprop init.svc.thermal-engine`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.thermal-engine`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
elif [ "`getprop init.svc.vendor.thermal-engine`" = "running" ]; then
setprop ctl.stop vendor.thermal-engine
elif [ "`getprop init.svc.vendor.thermal-engine`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.vendor.thermal-engine`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
# For MediaTek CPU's
if [ -w "/proc/cpufreq/cpufreq_sched_disable" ]; then
echo '1' > "/proc/cpufreq/cpufreq_sched_disable"
forceOnlineCPUs
fi
elif [ $flag -lt 0 ]; then
# Start thermal core control
if [ -w "/sys/module/msm_thermal/core_control/enabled" ]; then
echo '1' > "/sys/module/msm_thermal/core_control/enabled"
fi
if [ -r "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
local st en
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
if [ -w "/sys/devices/system/cpu/cpu7/core_ctl/enable" ]; then
# SD850 or higher type core control
echo '1' > "/sys/devices/system/cpu/cpu7/core_ctl/enable"
echo '0' > "/sys/devices/system/cpu/cpu7/core_ctl/min_cpus"
if [ -w "/sys/devices/system/cpu/cpu4/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
echo '2' > "/sys/devices/system/cpu/cpu4/core_ctl/min_cpus"
fi
if [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '4' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
echo '0' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
fi
elif [ -w "/sys/devices/system/cpu/cpu4/core_ctl/enable" ]; then
# SD840 or lower type core control
echo '1' > "/sys/devices/system/cpu/cpu4/core_ctl/enable"
echo '1' > "/sys/devices/system/cpu/cpu4/core_ctl/min_cpus"
if [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
fi
elif [ -w "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
# unknown type core control
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/enable"
echo '1' > "/sys/devices/system/cpu/cpu0/core_ctl/min_cpus"
fi
fi
fi
# Start the MPDecision (CPU hotplug)
if [ "`getprop init.svc.mpdecision`" = "stopped" ]; then
setprop ctl.start mpdecision
forceOnlineCPUs
elif [ "`getprop init.svc.vendor.mpdecision`" = "stopped" ]; then
setprop ctl.start vendor.mpdecision
forceOnlineCPUs
fi
# Start the thermal server
if [ "`getprop init.svc.thermal`" = "stopped" ]; then
setprop ctl.start thermal
elif [ "`getprop init.svc.vendor.thermal`" = "stopped" ]; then
setprop ctl.start vendor.thermal
fi
# Start the mi_thermald server
if [ "`getprop init.svc.mi_thermald`" = "stopped" ]; then
setprop ctl.start mi_thermald
elif [ "`getprop init.svc.vendor.mi_thermald`" = "stopped" ]; then
setprop ctl.start vendor.mi_thermald
fi
# Start the thermal-engine server
if [ "`getprop init.svc.thermal-engine`" = "stopped" ]; then
setprop ctl.start thermal-engine
elif [ "`getprop init.svc.vendor.thermal-engine`" = "stopped" ]; then
setprop ctl.start vendor.thermal-engine
fi
# For MediaTek CPU's
if [ -w "/proc/cpufreq/cpufreq_sched_disable" ]; then
val="`searchDefaultCpuGovernor`"
if [ "$val" = "schedutil" -a "`getprop ro.vendor.build.version.release`" -lt "11" ]; then
echo " Notice: EAS hasn't been enabled, so skipping thermal MTK EAS+ enabling" 1>&2
else
echo '0' > "/proc/cpufreq/cpufreq_sched_disable"
fi
fi
fi
if [ $printStatus -gt 0 ]; then
local found=0
# Qualcomm Core control
if [ -w "/sys/module/msm_thermal/core_control/enabled" ]; then
if [ "`cat /sys/module/msm_thermal/core_control/enabled`" -eq 0 ]; then
echo " Thermal msm_thermal: disabled"
else
echo " Thermal msm_thermal: enabled"
fi
found=1
fi
if [ -r "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
local i st en ctl_enabled=0
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
if [ -r "/sys/devices/system/cpu/cpu7/core_ctl/enable" ]; then
read ctl_enabled <"/sys/devices/system/cpu/cpu7/core_ctl/enable"
elif [ -r "/sys/devices/system/cpu/cpu4/core_ctl/enable" ]; then
read ctl_enabled <"/sys/devices/system/cpu/cpu4/core_ctl/enable"
elif [ -r "/sys/devices/system/cpu/cpu0/core_ctl/enable" ]; then
read ctl_enabled <"/sys/devices/system/cpu/cpu0/core_ctl/enable"
fi
if [ "$ctl_enabled" -gt 0 ]; then
echo " Thermal core_ctl: enabled"
else
echo " Thermal core_ctl: disabled"
fi
found=1
fi
fi
if [ -n "`getprop init.svc.thermal`" ]; then
echo " Thermal server: `getprop init.svc.thermal`"
found=1
elif [ -n "`getprop init.svc.vendor.thermal`" ]; then
echo " Thermal server: `getprop init.svc.vendor.thermal`"
found=1
fi
if [ -n "`getprop init.svc.mi_thermald`" ]; then
echo " Thermal mi_thermald: `getprop init.svc.mi_thermald`"
found=1
elif [ -n "`getprop init.svc.vendor.mi_thermald`" ]; then
echo " Thermal mi_thermald: `getprop init.svc.vendor.mi_thermald`"
found=1
fi
if [ -n "`getprop init.svc.thermal-engine`" ]; then
echo " Thermal thermal-engine: `getprop init.svc.thermal-engine`"
found=1
elif [ -n "`getprop init.svc.vendor.thermal-engine`" ]; then
echo " Thermal thermal-engine: `getprop init.svc.vendor.thermal-engine`"
found=1
fi
# MPDecision
if [ -n "`getprop init.svc.mpdecision`" ]; then
echo " Thermal MPDecision: `getprop init.svc.mpdecision`"
found=1
elif [ -n "`getprop init.svc.vendor.mpdecision`" ]; then
echo " Thermal MPDecision: `getprop init.svc.vendor.mpdecision`"
found=1
fi
# MediaTek EAS+ scheduling
if [ -r "/proc/cpufreq/cpufreq_sched_disable" ]; then
set `cat /proc/cpufreq/cpufreq_sched_disable`
val=$3
if [ "$val" -eq '1' ]; then
echo " Thermal MTK EAS+: stopped"
else
echo " Thermal MTK EAS+: running"
fi
found=1
fi
if [ $found -eq 0 ]; then
echo " Thermal control: N/A"
fi
# End of status print section
fi
else
return 1
fi
}
function reduceDozeJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
# Disable Doze of the device
dumpsys deviceidle disable all 1>"/dev/null" 2>&1
elif [ $flag -lt 0 ]; then
# Enable Doze of the device
dumpsys deviceidle enable all 1>"/dev/null" 2>&1
fi
if [ $printStatus -gt 0 ]; then
if [ "`dumpsys deviceidle enabled all`" -gt 0 ]; then
echo " Doze battery saver: enabled"
else
echo " Doze battery saver: disabled"
fi
fi
else
return 1
fi
}
function getQcomGpuFreq()
{
local isMax="0"
if [ $# -eq 1 -a "$1" = "max" ]; then
isMax="1"
fi
if [ -r "/sys/class/kgsl/kgsl-3d0/gpu_available_frequencies" -a -r "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
local tab x y freq=""
read tab <"/sys/class/kgsl/kgsl-3d0/gpu_available_frequencies"
if [ -z "$tab" ]; then
return 1
fi
set $tab 1>"/dev/null" 2>&1
if [ "$isMax" -eq 1 ]; then
freq="$1"
elif [ -r "/sys/class/kgsl/kgsl-3d0/default_pwrlevel" ]; then
read x <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
read y <"/sys/class/kgsl/kgsl-3d0/default_pwrlevel"
if [ "$y" -lt "$x" ]; then
x="$y"
fi
if [ "$x" -lt $# ]; then
shift $x
fi
freq="$1"
else
# no estimation possible, so check the current real GPU clock
read freq <"/sys/class/kgsl/kgsl-3d0/gpuclk"
fi
if [ -n "$freq" ]; then
echo "$freq"
return 0
else
return 1
fi
else
return 1
fi
}
function getMtkGpuFreqKhz()
{
local isMax="0"
if [ $# -eq 1 -a "$1" = "max" ]; then
isMax="1"
fi
if [ -r "/proc/gpufreq/gpufreq_opp_dump" ]; then
local x1 x2 x3 x4 x5 freq="" IFS=" ,"
if [ "$isMax" -eq 1 ]; then
read x1 x2 x3 x4 x5 <"/proc/gpufreq/gpufreq_opp_dump"
freq="$x4"
else
while read x1 x2 x3 x4 x5; do
freq="$x4"
done <"/proc/gpufreq/gpufreq_opp_dump"
fi
if [ -n "$freq" ]; then
echo "$freq"
return 0
else
return 1
fi
else
return 1
fi
}
function getTensorGpuFreqKhz()
{
local isMax="0"
if [ $# -eq 1 -a "$1" = "max" ]; then
isMax="1"
elif [ $# -eq 1 -a "$1" = "min" ]; then
isMax="-1"
fi
if [ -r "/sys/devices/platform/1c500000.mali/available_frequencies" ]; then
local tab x freq=""
read tab <"/sys/devices/platform/1c500000.mali/available_frequencies"
if [ -z "$tab" ]; then
return 1
fi
set $tab 1>"/dev/null" 2>&1
if [ "$isMax" -eq 1 ]; then
freq="$1"
elif [ "$isMax" -eq -1 ]; then
freq="$(eval echo '$'{$#})"
else
# return the current GPU clock
read freq <"/sys/devices/platform/1c500000.mali/cur_freq"
fi
if [ -n "$freq" ]; then
echo "$freq"
return 0
else
return 1
fi
else
return 1
fi
}
function isMtkGpuFreqFixed()
{
if [ -r "/proc/gpufreq/gpufreq_opp_freq" ]; then
local x1 x2 x3 x4 x5
read x1 x2 x3 x4 x5 <"/proc/gpufreq/gpufreq_opp_freq"
if [ "$x5" = "enabled" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
function validGpuGovernor()
{
if [ $# -eq 2 -a -r "$1" ]; then
local lst
local gov="$2"
local i
lst="`cat <\"$1\"`"
for i in $lst; do
if [ "$i" = "$gov" ]; then
return 0
fi
done
return 1
else
return 1
fi
}
function reduceGovernorJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
# CPU governor
# prevent CPU offline stuck by forcing online between double governor writing
local i st en x
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
for i in `seq $st $en`; do
if [ -e "/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor" ]; then
chmod 644 "/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
echo 'performance' >"/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
chmod 644 "/sys/devices/system/cpu/cpu$i/online"
echo '1' >"/sys/devices/system/cpu/cpu$i/online"
# Set the cpu max freq to the scaling_max_freq because some devices sometimes set it to be lower
read x <"/sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_max_freq"
chmod 644 "/sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
echo "$x" >"/sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
echo 'performance' >"/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
fi
done
fi
# Support for the Nyx kernel and others; Disable a workqueue power efficient featute
if [ -e "/sys/module/workqueue/parameters/power_efficient" ]; then
chmod 644 "/sys/module/workqueue/parameters/power_efficient"
echo 'N' >"/sys/module/workqueue/parameters/power_efficient"
fi
# GPU's
if [ -w "/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor" ]; then
# For old Qcomm GPU's
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor"
if [ -w "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
# Set the min power level to be maximum
read x <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
if [ "$x" -ne 0 ]; then
echo "0" >"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
fi
fi
elif [ -w "/sys/class/kgsl/kgsl-3d0/devfreq/governor" ]; then
# For Qcomm GPU's
if validGpuGovernor "/sys/class/kgsl/kgsl-3d0/devfreq/available_governors" "performance"; then
# Check whether "performance" governor exists or not because some Qcomm recent GPU's don't have the governor
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
sleep 0.1
fi
if [ -w "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
# Set the min power level to be maximum
read x <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
if [ "$x" -ne 0 ]; then
echo "0" >"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
fi
fi
# For some Qcomm GPU's, because they revert the governor after setting min_pwrlevel several times
if validGpuGovernor "/sys/class/kgsl/kgsl-3d0/devfreq/available_governors" "performance"; then
for i in `seq 1 9`; do
x="`echo \"scale=1;${i}/10\" | bc`"
sleep $x
read x <"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
if [ "$x" = "performance" ]; then
break
fi
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
done
fi
elif [ -w "/proc/gpufreq/gpufreq_opp_freq" ]; then
# Maximum fixed frequency setting for MediaTek GPU's
local freq="`getMtkGpuFreqKhz \"max\"`"
if [ -n "$freq" ]; then
echo "$freq" >"/proc/gpufreq/gpufreq_opp_freq"
fi
elif [ -w "/sys/devices/platform/1c500000.mali/scaling_min_freq" ]; then
# Maximum fixed frequency setting for Tensor GPU's
local freq="`getTensorGpuFreqKhz \"max\"`"
if [ -n "$freq" ]; then
echo "$freq" >"/sys/devices/platform/1c500000.mali/scaling_min_freq"
fi
fi
elif [ $flag -lt 0 ]; then
# CPU's governor
local gov="`searchDefaultCpuGovernor`"
# prevent CPU offline stuck by forcing online between double governor writing
local i st en
IFS="-" read st en <"/sys/devices/system/cpu/present"
if [ -n "$st" -a -n "$en" -a "$st" -ge 0 -a "$en" -ge 0 ]; then
for i in `seq $st $en`; do
if [ -e "/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor" ]; then
chmod 644 "/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
echo "$gov" >"/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
chmod 644 "/sys/devices/system/cpu/cpu$i/online"
echo '1' >"/sys/devices/system/cpu/cpu$i/online"
echo "$gov" >"/sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
fi
done
fi
# Support for the Nyx kernel and others; Revert a workqueue power efficient featute
if [ -e "/sys/module/workqueue/parameters/power_efficient" ]; then
chmod 644 "/sys/module/workqueue/parameters/power_efficient"
echo 'Y' >"/sys/module/workqueue/parameters/power_efficient"
fi
# GPU's
if [ -w "/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor" ]; then
# Default GPU governor for old Qcomm GPU's
if [ "`getprop ro.build.product`" = "jfltexx" -a "`getprop ro.system.build.version.release`" -ge "12" ]; then
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor"
else
echo 'ondemand' >"/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor"
fi
if [ -r "/sys/class/kgsl/kgsl-3d0/num_pwrlevels" -a -w "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
# Set the min power level to be minimum
local x="4"
local tmp
read x <"/sys/class/kgsl/kgsl-3d0/num_pwrlevels"
x="`expr $x - 1`"
if [ -n "$x" ]; then
read tmp <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
if [ "$tmp" -ne "$x" ]; then
echo "$x" >"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
fi
fi
fi
elif [ -w "/sys/class/kgsl/kgsl-3d0/devfreq/governor" ]; then
# Default GPU governor for Qcomm GPU's
echo 'msm-adreno-tz' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
sleep 0.1
if [ -r "/sys/class/kgsl/kgsl-3d0/num_pwrlevels" -a -w "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
# Set the min power level to be minimum
local x="6"
local tmp
read x <"/sys/class/kgsl/kgsl-3d0/num_pwrlevels"
x="`expr $x - 1`"
if [ -n "$x" ]; then
read tmp <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
if [ "$tmp" -ne "$x" ]; then
echo "$x" >"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
fi
fi
fi
# For some Qcomm GPU's, because they revert the governor after setting min_pwrlevel several times
for i in `seq 1 9`; do
x="`echo \"scale=1;${i}/10\" | bc`"
sleep $x
read x <"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
if [ "$x" = "msm-adreno-tz" ]; then
break
fi
echo 'msm-adreno-tz' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
done
elif [ -w "/proc/gpufreq/gpufreq_opp_freq" ]; then
# Variable frequency setting for MediaTek GPU's
echo '0' >"/proc/gpufreq/gpufreq_opp_freq"
elif [ -w "/sys/devices/platform/1c500000.mali/scaling_min_freq" ]; then
# Minimum fixed frequency setting for Tensor GPU's
local freq="`getTensorGpuFreqKhz \"min\"`"
if [ -n "$freq" ]; then
echo "$freq" >"/sys/devices/platform/1c500000.mali/scaling_min_freq"
fi
fi
fi
if [ $printStatus -gt 0 ]; then
#CPU Governor
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" ]; then
# Support for the Nyx kernel and others; Print the status of a workqueue power efficient featute
if [ -r "/sys/module/workqueue/parameters/power_efficient" ]; then
local pf
read pf <"/sys/module/workqueue/parameters/power_efficient"
if [ "$pf" = "Y" ]; then
pf="yes"
else
pf="no"
fi
echo " Governor CPU: `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor` (wq psave: $pf)"
else
echo " Governor CPU: `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`"
fi
fi
if [ -r "/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor" ]; then
# For old Qcomm GPU Governor
local freq gov
read gov <"/sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor"
if [ "$gov" = "performance" ]; then
freq="`getQcomGpuFreq \"max\"`"
freq="`expr $freq / 1000000`MHz"
echo " Governor GPU: performance (fixed: $freq)"
else
freq="`getQcomGpuFreq \"typical\"`"
freq="`expr $freq / 1000000`Mhz"
echo " Governor GPU: $gov (typical: $freq)"
fi
elif [ -w "/sys/class/kgsl/kgsl-3d0/devfreq/governor" ]; then
# For Qcomm GPU Governor
local freq gov
read gov <"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
if [ "$gov" = "performance" ]; then
freq="`getQcomGpuFreq \"max\"`"
freq="`expr $freq / 1000000`MHz"
echo " Governor GPU: performance (fixed: $freq)"
else
freq="`getQcomGpuFreq \"typical\"`"
freq="`expr $freq / 1000000`MHz"
echo " Governor GPU: $gov (typical: $freq)"
fi
elif [ -r "/proc/gpufreq/gpufreq_opp_freq" ]; then
# For getting MediaTek GPU settings
local freq
if isMtkGpuFreqFixed; then
freq="`getMtkGpuFreqKhz \"max\"`"
freq="`expr $freq / 1000`MHz"
echo " Governor GPU: max freq (fixed: $freq)"
else
freq="`getMtkGpuFreqKhz \"typical\"`"
freq="`expr $freq / 1000`MHz"
echo " Governor GPU: variable freq (typical: $freq)"
fi
elif [ -r "/sys/devices/platform/1c500000.mali/cur_freq" ]; then
# Get the current Tensor GPU frequency
local freq="`getTensorGpuFreqKhz`"
if [ "$freq" = "`getTensorGpuFreqKhz \"max\"`" ]; then
freq="`expr $freq / 1000`MHz"
echo " Governor GPU: max freq (fixed: $freq)"
else
freq="`expr $freq / 1000`MHz"
echo " Governor GPU: variable freq (typical: $freq)"
fi
fi
fi
else
return 1
fi
}
function reduceLogdJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
# Stop the Logd servers
if [ "`getprop init.svc.logd`" = "running" ]; then
setprop ctl.stop logd
elif [ "`getprop init.svc.logd`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.logd`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.traced`" = "running" ]; then
setprop ctl.stop traced
elif [ "`getprop init.svc.traced`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.traced`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.traced_probes`" = "running" ]; then
setprop ctl.stop traced_probes
elif [ "`getprop init.svc.traced_probes`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.traced_probes`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
elif [ $flag -lt 0 ]; then
# Start the Logd servers
if [ "`getprop init.svc.traced_probes`" = "stopped" ]; then
setprop ctl.start traced_probes
elif [ "`getprop init.svc.traced_probes`" = "stopping" ]; then
setprop ctl.restart traced_probes
fi
if [ "`getprop init.svc.traced`" = "stopped" ]; then
setprop ctl.start traced
elif [ "`getprop init.svc.traced`" = "stopping" ]; then
setprop ctl.restart traced
fi
if [ "`getprop init.svc.logd`" = "stopped" ]; then
setprop ctl.start logd
elif [ "`getprop init.svc.logd`" = "stopping" ]; then
setprop ctl.restart logd
fi
fi
if [ $printStatus -gt 0 ]; then
local val="`getprop init.svc.logd`"
if [ -n "$val" ]; then
echo " Logd main server: $val"
fi
val="`getprop init.svc.traced`"
if [ -n "$val" ]; then
echo " Logd traced server: $val"
fi
val="`getprop init.svc.traced_probes`"
if [ -n "$val" ]; then
echo " Logd traced_probes server: $val"
fi
fi
else
return 1
fi
}
function reduceCameraJitter()
{
if [ $# -eq 2 ]; then
local flag="$1"
local printStatus="$2"
if [ $flag -gt 0 ]; then
# Stop the camera servers
if [ "`getprop init.svc.qcamerasvr`" = "running" ]; then
setprop ctl.stop qcamerasvr
elif [ "`getprop init.svc.qcamerasvr`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.qcamerasvr`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.vendor.qcamerasvr`" = "running" ]; then
setprop ctl.stop vendor.qcamerasvr
elif [ "`getprop init.svc.vendor.qcamerasvr`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.vendor.qcamerasvr`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.cameraserver`" = "running" ]; then
setprop ctl.stop cameraserver
elif [ "`getprop init.svc.cameraserver`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.cameraserver`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.camerasloganserver`" = "running" ]; then
setprop ctl.stop camerasloganserver
elif [ "`getprop init.svc.camerasloganserver`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.camerasloganserver`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
if [ "`getprop init.svc.camerahalserver`" = "running" ]; then
setprop ctl.stop camerahalserver
elif [ "`getprop init.svc.camerahalserver`" = "stopping" ]; then
local pid="`getprop init.svc_debug_pid.camerahalserver`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
elif [ $flag -lt 0 ]; then
# Start the camera servers
if [ "`getprop init.svc.qcamerasvr`" = "stopped" ]; then
setprop ctl.start qcamerasvr
elif [ "`getprop init.svc.qcamerasvr`" = "stopping" ]; then
setprop ctl.restart qcamerasvr
fi
if [ "`getprop init.svc.vendor.qcamerasvr`" = "stopped" ]; then
setprop ctl.start vendor.qcamerasvr
elif [ "`getprop init.svc.vendor.qcamerasvr`" = "stopping" ]; then
setprop ctl.restart vendor.qcamerasvr
fi
if [ "`getprop init.svc.cameraserver`" = "stopped" ]; then
setprop ctl.start cameraserver
fi
if [ "`getprop init.svc.camerasloganserver`" = "stopped" ]; then
setprop ctl.start camerasloganserver
fi
if [ "`getprop init.svc.camerahalserver`" = "stopped" ]; then
setprop ctl.start camerahalserver
fi
fi
if [ $printStatus -gt 0 ]; then
local val="`getprop init.svc.qcamerasvr`"
if [ -n "$val" ]; then
echo " Qcom camera server: $val"
return 0
fi
val="`getprop init.svc.vendor.qcamerasvr`"
if [ -n "$val" ]; then
echo " Qcom camera server: $val"
return 0
fi
val="`getprop init.svc.cameraserver`"
if [ -n "$val" ]; then
echo " Camera server: $val"
return 0
fi
fi
else
return 1
fi
}
# choose the best I/O scheduler for very Hifi audio outputs, and output it into the standard output
function chooseBestIOScheduler()
{
if [ $# -eq 1 -a -r "$1" ]; then
local x scheds ret_val=""
scheds="`tr -d '[]' <\"$1\"`"
for x in $scheds; do
case "$x" in
"deadline" ) ret_val="deadline"; break ;;
"mq-deadline" ) ret_val="mq-deadline"; break ;;
"kyber" ) ret_val="kyber" ;;
"cfq" ) if [ "$ret_val" != "kyber" ]; then ret_val="cfq"; fi ;;
"noop" | "none" ) if [ "$ret_val" != "cfq" -o "$ret_val" != "kyber" ]; then ret_val="$x"; fi ;;
* ) ;;
esac
done
echo "$ret_val"
return 0
else
return 1
fi
}
function selectedScheduler()
{
if [ $# -eq 1 -a -r "$1" ]; then
local sched="`cat \"$1\"`"
if [ -n "$sched" ]; then
local val
val=`expr "$sched" : '[^[]*\[\([^]]*\)\]'`
echo "$val"
return 0
else
return 1
fi
else
return 1
fi
}
function validScheduler()
{
if [ $# -eq 2 -a -r "$1" ]; then
local lst
local sched="$2"
local i
lst="`tr -d '[]' <\"$1\"`"
for i in $lst; do
if [ "$i" = "$sched" ]; then
return 0
fi
done
return 1
else