From 917eff8c30895e85943ec0a8c735e91088dbda85 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Fri, 20 Nov 2020 19:25:12 -0800 Subject: [PATCH] New settings for governors, +30% memory bandwidth (#2590) * new settings for governors, +30% memory bandwidth * CPU waste is better * warm up frame_drop * optional CORE arg for rtshield * back off priorities of processes not critical to driving * if it doesn't drive, it's not realtime * err, resource. this should have been included * reverse order to not spike Co-authored-by: Comma Device --- launch_chffrplus.sh | 13 +++++++++++++ scripts/waste | Bin 8568 -> 8608 bytes scripts/waste.c | 19 +++++++++++++++++-- selfdrive/loggerd/loggerd.cc | 2 +- selfdrive/modeld/dmonitoringmodeld.cc | 3 ++- selfdrive/modeld/modeld.cc | 4 ++++ selfdrive/rtshield.py | 8 ++++++-- selfdrive/thermald/thermald.py | 2 -- 8 files changed, 43 insertions(+), 8 deletions(-) mode change 100644 => 100755 selfdrive/rtshield.py diff --git a/launch_chffrplus.sh b/launch_chffrplus.sh index e7fd3a257b..c20608862b 100755 --- a/launch_chffrplus.sh +++ b/launch_chffrplus.sh @@ -19,6 +19,19 @@ function two_init { # openpilot gets all the cores echo 0-3 > /dev/cpuset/app/cpus + # set up governors + # +50mW offroad, +500mW onroad for 30% more RAM bandwidth + echo "performance" > /sys/class/devfreq/soc:qcom,cpubw/governor + echo 1056000 > /sys/class/devfreq/soc:qcom,m4m/max_freq + echo "performance" > /sys/class/devfreq/soc:qcom,m4m/governor + + # unclear if these help, but they don't seem to hurt + echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu0/governor + echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu2/governor + + # /sys/class/devfreq/soc:qcom,mincpubw is the only one left at "powersave" + # it seems to gain nothing but a wasted 500mW + # Collect RIL and other possibly long-running I/O interrupts onto CPU 1 echo 1 > /proc/irq/78/smp_affinity_list # qcom,smd-modem (LTE radio) echo 1 > /proc/irq/33/smp_affinity_list # ufshcd (flash storage) diff --git a/scripts/waste b/sc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*4{(bHgPGOC zh`qLasqZ1#f`z1vaKm1UAFs^eD+{W1;nokzOfjY#aX9HN45n6r(UCE8{)P_1>|@OWR^K2 zFEA|)wt`1CLip-Sh|9iITv;Wgm+i+G3@Xl-6Ecp4UgCX-c_~Y)TGdOmj9&*CQH56hwxEj5DkGzDiW>P 1 && strcmp(argv[1], "--bootlog") == 0) { diff --git a/selfdrive/modeld/dmonitoringmodeld.cc b/selfdrive/modeld/dmonitoringmodeld.cc index a3ddfea04c..3a9b134eff 100644 --- a/selfdrive/modeld/dmonitoringmodeld.cc +++ b/selfdrive/modeld/dmonitoringmodeld.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "common/visionbuf.h" #include "common/visionipc.h" @@ -23,7 +24,7 @@ static void set_do_exit(int sig) { int main(int argc, char **argv) { int err; - set_realtime_priority(51); + setpriority(PRIO_PROCESS, 0, -15); #ifdef QCOM2 set_core_affinity(5); diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index c528ba98d0..9b956e8559 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -157,6 +157,7 @@ int main(int argc, char **argv) { uint32_t frame_id = 0, last_vipc_frame_id = 0; double last = 0; int desire = -1; + uint32_t run_count = 0; while (!do_exit) { VIPCBuf *buf; VIPCBufExtra extra; @@ -179,6 +180,8 @@ int main(int argc, char **argv) { double mt1 = 0, mt2 = 0; if (run_model_this_iter) { + run_count++; + float vec_desire[DESIRE_LEN] = {0}; if (desire >= 0 && desire < DESIRE_LEN) { vec_desire[desire] = 1.0; @@ -198,6 +201,7 @@ int main(int argc, char **argv) { // tracked dropped frames uint32_t vipc_dropped_frames = extra.frame_id - last_vipc_frame_id - 1; frames_dropped = (1. - frame_filter_k) * frames_dropped + frame_filter_k * (float)std::min(vipc_dropped_frames, 10U); + if (run_count < 10) frames_dropped = 0; // let frame drops warm up float frame_drop_ratio = frames_dropped / (1 + frames_dropped); model_publish(pm, extra.frame_id, frame_id, vipc_dropped_frames, frame_drop_ratio, model_buf, extra.timestamp_eof, model_execution_time); diff --git a/selfdrive/rtshield.py b/selfdrive/rtshield.py old mode 100644 new mode 100755 index e76022501b..9a638c9169 --- a/selfdrive/rtshield.py +++ b/selfdrive/rtshield.py @@ -1,16 +1,20 @@ #!/usr/bin/env python3 +import os import time from common.realtime import set_core_affinity, set_realtime_priority - # RT shield - ensure CPU 3 always remains available for RT processes # runs as SCHED_FIFO with minimum priority to ensure kthreads don't # get scheduled onto CPU 3, but it's always preemptible by realtime # openpilot processes def main(): - set_core_affinity(3) + set_core_affinity(int(os.getenv("CORE", "3"))) set_realtime_priority(1) while True: time.sleep(0.000001) + +if __name__ == "__main__": + main() + diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index df606f8b0b..c36e9cdbe0 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -377,7 +377,6 @@ def thermald_thread(): if started_ts is None: started_ts = sec_since_boot() started_seen = True - os.system('echo performance > /sys/class/devfreq/soc:qcom,cpubw/governor') else: if startup_conditions["ignition"] and (startup_conditions != startup_conditions_prev): cloudlog.event("Startup blocked", startup_conditions=startup_conditions) @@ -387,7 +386,6 @@ def thermald_thread(): started_ts = None if off_ts is None: off_ts = sec_since_boot() - os.system('echo powersave > /sys/class/devfreq/soc:qcom,cpubw/governor') # Offroad power monitoring pm.calculate(health)