|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Written by Draco (tytydraco @ GitHub)
|
|
|
|
|
|
|
|
|
|
# The name of the current branch for logging purposes
|
|
|
|
|
BRANCH="latency"
|
|
|
|
|
|
|
|
|
|
# Maximum unsigned integer size in C
|
|
|
|
|
UINT_MAX="4294967295"
|
|
|
|
|
|
|
|
|
@ -8,7 +11,7 @@ UINT_MAX="4294967295"
|
|
|
|
|
SCHED_PERIOD="$((1 * 1000 * 1000))"
|
|
|
|
|
|
|
|
|
|
# How many tasks should we have at a maximum in one scheduling period
|
|
|
|
|
SCHED_TASKS="8"
|
|
|
|
|
SCHED_TASKS="10"
|
|
|
|
|
|
|
|
|
|
write() {
|
|
|
|
|
# Bail out if file does not exist
|
|
|
|
@ -40,13 +43,13 @@ grep -q android /proc/cmdline && ANDROID=true
|
|
|
|
|
|
|
|
|
|
# Log the date and time for records sake
|
|
|
|
|
echo "Time of execution: $(date)"
|
|
|
|
|
echo "Branch: master"
|
|
|
|
|
echo "Branch: $BRANCH"
|
|
|
|
|
|
|
|
|
|
# Sync to data in the rare case a device crashes
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
|
|
# Limit max perf event processing time to this much CPU usage
|
|
|
|
|
write /proc/sys/kernel/perf_cpu_time_max_percent 5
|
|
|
|
|
write /proc/sys/kernel/perf_cpu_time_max_percent 3
|
|
|
|
|
|
|
|
|
|
# Group tasks for less stutter but less throughput
|
|
|
|
|
write /proc/sys/kernel/sched_autogroup_enabled 1
|
|
|
|
@ -73,7 +76,7 @@ write /proc/sys/kernel/sched_migration_cost_ns 5000000
|
|
|
|
|
[[ "$ANDROID" == true ]] && write /proc/sys/kernel/sched_min_task_util_for_colocation 0
|
|
|
|
|
|
|
|
|
|
# Improve real time latencies by reducing the scheduler migration time
|
|
|
|
|
write /proc/sys/kernel/sched_nr_migrate 8
|
|
|
|
|
write /proc/sys/kernel/sched_nr_migrate 4
|
|
|
|
|
|
|
|
|
|
# Disable scheduler statistics to reduce overhead
|
|
|
|
|
write /proc/sys/kernel/sched_schedstats 0
|
|
|
|
@ -82,7 +85,7 @@ write /proc/sys/kernel/sched_schedstats 0
|
|
|
|
|
write /proc/sys/kernel/printk_devkmsg off
|
|
|
|
|
|
|
|
|
|
# Start non-blocking writeback later
|
|
|
|
|
write /proc/sys/vm/dirty_background_ratio 10
|
|
|
|
|
write /proc/sys/vm/dirty_background_ratio 3
|
|
|
|
|
|
|
|
|
|
# Start blocking writeback later
|
|
|
|
|
write /proc/sys/vm/dirty_ratio 30
|
|
|
|
@ -119,8 +122,8 @@ then
|
|
|
|
|
# Consider scheduling tasks that are eager to run
|
|
|
|
|
write /sys/kernel/debug/sched_features NEXT_BUDDY
|
|
|
|
|
|
|
|
|
|
# Schedule tasks on their origin CPU if possible
|
|
|
|
|
write /sys/kernel/debug/sched_features TTWU_QUEUE
|
|
|
|
|
# Some sources report large latency spikes during large migrations
|
|
|
|
|
write /sys/kernel/debug/sched_features NO_TTWU_QUEUE
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[[ "$ANDROID" == true ]] && if [[ -d "/dev/stune/" ]]
|
|
|
|
@ -154,12 +157,12 @@ done
|
|
|
|
|
find /sys/devices/system/cpu/ -name schedutil -type d | while IFS= read -r governor
|
|
|
|
|
do
|
|
|
|
|
# Consider changing frequencies once per scheduling period
|
|
|
|
|
write "$governor/up_rate_limit_us" "$((SCHED_PERIOD / 1000))"
|
|
|
|
|
write "$governor/down_rate_limit_us" "$((4 * SCHED_PERIOD / 1000))"
|
|
|
|
|
write "$governor/rate_limit_us" "$((SCHED_PERIOD / 1000))"
|
|
|
|
|
write "$governor/up_rate_limit_us" 0
|
|
|
|
|
write "$governor/down_rate_limit_us" 0
|
|
|
|
|
write "$governor/rate_limit_us" 0
|
|
|
|
|
|
|
|
|
|
# Jump to hispeed frequency at this load percentage
|
|
|
|
|
write "$governor/hispeed_load" 90
|
|
|
|
|
write "$governor/hispeed_load" 85
|
|
|
|
|
write "$governor/hispeed_freq" "$UINT_MAX"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
@ -167,11 +170,11 @@ done
|
|
|
|
|
find /sys/devices/system/cpu/ -name interactive -type d | while IFS= read -r governor
|
|
|
|
|
do
|
|
|
|
|
# Consider changing frequencies once per scheduling period
|
|
|
|
|
write "$governor/timer_rate" "$((SCHED_PERIOD / 1000))"
|
|
|
|
|
write "$governor/min_sample_time" "$((SCHED_PERIOD / 1000))"
|
|
|
|
|
write "$governor/timer_rate" 0
|
|
|
|
|
write "$governor/min_sample_time" 0
|
|
|
|
|
|
|
|
|
|
# Jump to hispeed frequency at this load percentage
|
|
|
|
|
write "$governor/go_hispeed_load" 90
|
|
|
|
|
write "$governor/go_hispeed_load" 85
|
|
|
|
|
write "$governor/hispeed_freq" "$UINT_MAX"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
@ -195,10 +198,10 @@ do
|
|
|
|
|
write "$queue/iostats" 0
|
|
|
|
|
|
|
|
|
|
# Reduce heuristic read-ahead in exchange for I/O latency
|
|
|
|
|
write "$queue/read_ahead_kb" 128
|
|
|
|
|
write "$queue/read_ahead_kb" 32
|
|
|
|
|
|
|
|
|
|
# Reduce the maximum number of I/O requests in exchange for latency
|
|
|
|
|
write "$queue/nr_requests" 64
|
|
|
|
|
write "$queue/nr_requests" 32
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Always return success, even if the last write fails
|
|
|
|
|