mirror of
https://github.com/commaai/agnos-builder.git
synced 2026-06-08 11:04:51 +08:00
another boot time speedup pass (#598)
* magic speedup * lil more * put that back * tmpfiles
This commit is contained in:
@@ -33,11 +33,6 @@ COPY ./userspace/compile-modemmanager.sh /tmp/agnos/
|
||||
RUN --mount=type=cache,target=/root/.ccache,id=modemmanager,sharing=shared \
|
||||
/tmp/agnos/compile-modemmanager.sh
|
||||
|
||||
# power_burn_max
|
||||
FROM agnos-compiler AS agnos-compiler-power-burn
|
||||
COPY ./userspace/power_burn_max.c /tmp/agnos/
|
||||
RUN gcc -O2 -o /tmp/power_burn_max /tmp/agnos/power_burn_max.c -lpthread
|
||||
|
||||
# ################## #
|
||||
# ###### Base ###### #
|
||||
# ################## #
|
||||
@@ -120,10 +115,9 @@ RUN rm -f /etc/fstab
|
||||
# Install kernel headers
|
||||
COPY ./output/linux-headers/include/ /usr/include/
|
||||
|
||||
COPY --from=agnos-compiler-power-burn /tmp/power_burn_max /home/$USERNAME/power_burn_max
|
||||
RUN chown $USERNAME: /home/$USERNAME/power_burn_max
|
||||
|
||||
COPY ./userspace/irsc_util.c /tmp/agnos/
|
||||
# builds
|
||||
COPY ./userspace/power_burn_max.c ./userspace/irsc_util.c /tmp/agnos/
|
||||
RUN gcc -O2 -o /usr/comma/power_burn_max /tmp/agnos/power_burn_max.c -lpthread
|
||||
RUN gcc -O2 -Wall -Wextra -o /usr/bin/irsc_util /tmp/agnos/irsc_util.c
|
||||
|
||||
# Setup systemd services
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=tmpfiles setup handled by comma-init
|
||||
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
|
||||
DefaultDependencies=no
|
||||
After=comma-init.service
|
||||
Before=sysinit.target shutdown.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
# Preserve ordering for units with After=systemd-tmpfiles-setup.service.
|
||||
ExecStart=/bin/true
|
||||
@@ -122,6 +122,7 @@ function init_filesystems (
|
||||
|
||||
# *** setup RW areas ***
|
||||
|
||||
systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev
|
||||
systemd-tmpfiles --create /usr/comma/tmpfiles.conf
|
||||
|
||||
# setup /var and /home overlays
|
||||
@@ -144,7 +145,8 @@ function init_filesystems (
|
||||
fi
|
||||
|
||||
# /cache
|
||||
chown -R comma:comma /cache/
|
||||
mkdir -p /cache/debug
|
||||
chown comma:comma /cache /cache/debug
|
||||
)
|
||||
|
||||
function init_qcom (
|
||||
@@ -172,6 +174,15 @@ function init_qcom (
|
||||
echo 1 > /dev/ipa
|
||||
)
|
||||
|
||||
function init_power_burn (
|
||||
# blip power to ~10W to see if the PSU is stable
|
||||
chrt -i 0 timeout --kill-after=1 1 /usr/comma/power_burn_max 0.5 8
|
||||
|
||||
# limit after burn
|
||||
echo 1689600 > /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq
|
||||
echo 1689600 > /sys/devices/system/cpu/cpufreq/policy4/scaling_max_freq
|
||||
)
|
||||
|
||||
function init_gpio (
|
||||
pins=(
|
||||
49 # SOM_ST_IO
|
||||
@@ -192,7 +203,8 @@ function init_gpio (
|
||||
done
|
||||
|
||||
# set permissions
|
||||
find -L /sys/class/gpio/ -maxdepth 2 -exec chown root:gpio {} + -exec chmod 770 {} +
|
||||
find -H /sys/class/gpio/export /sys/class/gpio/unexport /sys/class/gpio/gpio* \
|
||||
-maxdepth 1 -exec chown root:gpio {} + -exec chmod 770 {} +
|
||||
)
|
||||
|
||||
function init_sound (
|
||||
@@ -232,6 +244,7 @@ function init_debug (
|
||||
run_init init_permissions &
|
||||
run_init init_filesystems &
|
||||
run_init init_qcom &
|
||||
run_init init_power_burn &
|
||||
run_init init_gpio &
|
||||
run_init init_sound &
|
||||
run_init init_screen_calibration &
|
||||
|
||||
@@ -8,15 +8,6 @@ CONTINUE="/data/continue.sh"
|
||||
INSTALLER="/tmp/installer"
|
||||
RESET_TRIGGER="/data/__system_reset__"
|
||||
|
||||
# blip power to ~10W to see if the PSU is stable
|
||||
function power_burn {
|
||||
sudo chrt -i 0 timeout --kill-after=1 1 /home/comma/power_burn_max 0.5 8
|
||||
# limit after burn
|
||||
echo 1689600 | sudo tee /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq
|
||||
echo 1689600 | sudo tee /sys/devices/system/cpu/cpufreq/policy4/scaling_max_freq
|
||||
}
|
||||
power_burn &
|
||||
|
||||
echo "waiting for magic"
|
||||
for i in {1..200}; do
|
||||
if [ -S /tmp/drmfd.sock ]; then
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
import os, socket, threading, time
|
||||
from array import array
|
||||
|
||||
import pyray as rl
|
||||
|
||||
SOCK_PATH = "/tmp/drmfd.sock"
|
||||
DRM_DEVICE = "/dev/dri/card0"
|
||||
BACKLIGHT_POWER = "/sys/class/backlight/panel0-backlight/bl_power"
|
||||
BACKGROUND = "/usr/comma/bg.jpg"
|
||||
rl = None
|
||||
|
||||
def power_screen():
|
||||
try:
|
||||
@@ -41,6 +40,8 @@ def handle_client(client, drm_master):
|
||||
pass
|
||||
|
||||
def main():
|
||||
global rl
|
||||
|
||||
while True:
|
||||
try:
|
||||
drm_master = os.open(DRM_DEVICE, os.O_RDWR | os.O_CLOEXEC)
|
||||
@@ -50,18 +51,6 @@ def main():
|
||||
time.sleep(0.1)
|
||||
|
||||
os.environ['DRM_FD'] = str(drm_master)
|
||||
while not os.access(BACKLIGHT_POWER, os.W_OK):
|
||||
time.sleep(0.1)
|
||||
|
||||
rl.init_window(0, 0, "not weston")
|
||||
img = rl.load_image(BACKGROUND)
|
||||
rl.image_resize(img, rl.get_screen_width(), rl.get_screen_width()//2)
|
||||
tex = rl.load_texture_from_image(img)
|
||||
rl.set_texture_filter(tex, rl.TextureFilter.TEXTURE_FILTER_BILINEAR)
|
||||
pos = rl.Vector2((rl.get_screen_width() - tex.width)/2.0, (rl.get_screen_height() - tex.height)/2.0)
|
||||
rl.unload_image(img)
|
||||
show_background(tex, pos)
|
||||
|
||||
try:
|
||||
os.unlink(SOCK_PATH)
|
||||
except FileNotFoundError:
|
||||
@@ -71,9 +60,11 @@ def main():
|
||||
server.bind(SOCK_PATH)
|
||||
server.settimeout(0.1)
|
||||
server.listen(1)
|
||||
print("magic: socket listening", flush=True)
|
||||
|
||||
clients = set()
|
||||
need_background = False
|
||||
tex = pos = None
|
||||
|
||||
while True:
|
||||
dead = [t for t in list(clients) if not t.is_alive()]
|
||||
@@ -82,6 +73,17 @@ def main():
|
||||
clients.discard(t)
|
||||
if not clients and need_background:
|
||||
need_background = False
|
||||
if rl is None:
|
||||
import pyray as rl
|
||||
while not os.access(BACKLIGHT_POWER, os.W_OK):
|
||||
time.sleep(0.1)
|
||||
rl.init_window(0, 0, "not weston")
|
||||
img = rl.load_image(BACKGROUND)
|
||||
rl.image_resize(img, rl.get_screen_width(), rl.get_screen_width()//2)
|
||||
tex = rl.load_texture_from_image(img)
|
||||
rl.set_texture_filter(tex, rl.TextureFilter.TEXTURE_FILTER_BILINEAR)
|
||||
pos = rl.Vector2((rl.get_screen_width() - tex.width)/2.0, (rl.get_screen_height() - tex.height)/2.0)
|
||||
rl.unload_image(img)
|
||||
show_background(tex, pos)
|
||||
|
||||
try:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
DefaultDependencies=no
|
||||
Requires=comma-init.service
|
||||
Wants=magic.service
|
||||
After=comma-init.service magic.service
|
||||
After=comma-init.service
|
||||
Before=basic.target shutdown.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
@@ -10,9 +10,9 @@ Conflicts=shutdown.target
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
User=comma
|
||||
ExecStart=/bin/bash -c "/usr/bin/tmux new-session -s comma -d /usr/comma/comma.sh"
|
||||
ExecStart=/usr/bin/tmux new-session -d -s comma /usr/comma/comma.sh
|
||||
# TODO: send SIGTERM first, then kill after a timeout
|
||||
ExecStop=/bin/bash -c "/usr/bin/tmux kill-session -t comma"
|
||||
ExecStop=/usr/bin/tmux kill-session -t comma
|
||||
TimeoutStopSec=1
|
||||
LimitRTPRIO=100
|
||||
LimitNICE=-10
|
||||
|
||||
@@ -10,12 +10,9 @@ Conflicts=shutdown.target
|
||||
Type=simple
|
||||
User=comma
|
||||
PermissionsStartOnly=true
|
||||
ExecStartPre=/bin/bash -c "mkdir -p /data/misc/display && printf '0\n' > /data/misc/display/sdm_dbg_cfg.txt && printf '0\n' > /data/misc/display/gbm_dbg_cfg.txt"
|
||||
|
||||
ExecStartPre=/bin/bash -c "mkdir -p /data/misc/display || true"
|
||||
ExecStartPre=/bin/bash -c "echo 0 > /data/misc/display/sdm_dbg_cfg.txt || true"
|
||||
ExecStartPre=/bin/bash -c "echo 0 > /data/misc/display/gbm_dbg_cfg.txt || true"
|
||||
|
||||
ExecStart=/bin/bash -c "source /etc/profile && /usr/local/venv/bin/python -u /usr/comma/magic.py"
|
||||
ExecStart=/usr/local/venv/bin/python -u /usr/comma/magic.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Reference in New Issue
Block a user