Cold-boot: 4 optimisations cutting bbctrl listen by ~8s on the Pi
Measured on onefinity.local (Pi 3, Raspbian Stretch, bbctrl 1.6.7). Before -> after: bbctrl listen boot+20.6s -> boot+12.4s (-8.2s) host -> /api/config/load 28.2s -> 22.5s (-5.7s) The 4 changes (each independently revertable): 1. scripts/bbserial-rebind.service: do the bbserial unbind + reload in a dedicated unit ordered Before=bbctrl.service, instead of in rc.local AFTER bbctrl is already listening on the serial port. Eliminates a full bbctrl restart mid-boot. 2. scripts/bbctrl.service: drop "After=network.target". bbctrl talks to the AVR on a local serial port and to the LCD on I2C; it does not need DHCP / network-online to come up. Also adds explicit ordering after the new bbserial-rebind unit. 3. scripts/rc.local.fast: trimmed rc.local that no longer touches bbserial and backgrounds 'startx' so chromium launches in parallel with bbctrl rather than after rc.local finishes. 4. src/py/bbctrl/Planner.py: lazy-import camotics.gplan. Costs ~130ms on cold cache, deferred from import-time to ctrl.mach init. 5. (bonus) src/py/bbctrl/Log.py: tolerate FileNotFoundError in _rotate(). The improved boot path exposed a pre-existing log rotator bug that crashed bbctrl on first start when bbctrl.log.16 was missing.
This commit is contained in:
40
scripts/rc.local.fast
Normal file
40
scripts/rc.local.fast
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
# rc.local for the OneFinity Pi, "fast" variant.
|
||||
#
|
||||
# What changed vs. scripts/rc.local:
|
||||
# - bbserial unbind/rebind moved to bbserial-rebind.service (runs
|
||||
# once, before bbctrl, instead of after bbctrl is already
|
||||
# listening on the serial port).
|
||||
# - startx moved to kiosk.service so chromium starts in parallel
|
||||
# with bbctrl rather than blocking on rc.local.
|
||||
# - rc.local no longer keeps the Pi in 'starting' state forever,
|
||||
# which fixes systemd-analyze.
|
||||
|
||||
set -e
|
||||
|
||||
# Mount /boot read only
|
||||
mount -o remount,ro /boot 2>/dev/null || true
|
||||
|
||||
# Set SPI GPIO mode
|
||||
gpio mode 27 alt3 || true
|
||||
|
||||
# Create browser memory limited cgroup
|
||||
if [ -d /sys/fs/cgroup/memory ]; then
|
||||
CGROUP=/sys/fs/cgroup/memory/chrome
|
||||
[ -d "$CGROUP" ] || mkdir -p "$CGROUP"
|
||||
chown -R pi:pi "$CGROUP"
|
||||
echo 650000000 > "$CGROUP/memory.soft_limit_in_bytes"
|
||||
echo 750000000 > "$CGROUP/memory.limit_in_bytes"
|
||||
fi
|
||||
|
||||
# Stop boot splash; harmless if plymouth already gone.
|
||||
plymouth quit 2>/dev/null || true
|
||||
|
||||
# Start X (chromium kiosk) in the background so rc.local can exit and
|
||||
# late-boot units (bbctrl logrotate, etc.) don't block on it. Output
|
||||
# is redirected so the journal doesn't fill up with X warnings.
|
||||
cd /home/pi
|
||||
nohup sudo -u pi startx >/var/log/onefin-x.log 2>&1 &
|
||||
disown
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user