The Problem: When I plug in my piZero to my MacOSX, it takes 28 seconds: from plugin, to MIDI device recognized. I'd like to be faster, in 5-10sec range. To support a nice consumer experience.
- Running Buster Lite (2019-09-26-raspbian-buster-lite.img)
- I have a readonly FS so power can be cut without filesystem corruption (easily switched back to readwrite when I want to make a change)
- Service which creates the USB Gadget MIDI definition (and Ethernet for SSH over USB)
....- Registered to run ~ #5 at top of the systemd list, right under the display service (sudo systemctl list-dependencies to see all)
....- in the service I modprobe dwc2 and libcomposite, then create 2 USB device definitions in the /sys/kernel/config/usb_gadget/ directory - one for MIDI and one for Ethernet (so I can also SSH in).
What I've tried:
- I tried a faster microsd card, same boot up speed, no change, I figure we're CPU bound (or stuck on some hardware or network init) here... maybe piZero is slow.
- I originally was running my service from /etc/rc.local, which gave me 58second "time till MIDI". Moving my service to systemd, high up in the order, got me down to 28seconds "time till MIDI".
Ideas for next steps:
- initrd apparently can boot the pi much faster from a RAM disk (you create a disk image on your microsd card, and i’m not sure, but sounds like it slams that into memory as a filesystem for (magic) faster boot times). Pipedream? idk... haven't found a good guide on doing this.
- maybe there is still something to reduce. systemd-analyze blame gives a list of the services and orders by slowest to fastest, so you can find the worst and perhaps optimize them. e.g. Keyboard service seems to be taking ~4seconds.
- maybe I could init the MIDI USB Gadget before systemd initializes services? Maybe using the init.d/rc.d system? IDK. information here is murky. I tried to run my service there but it killed the device and that was the last thing i tried. I could spend more time here. I haven't fully explored yet.
- I dont have a clear understanding what happens before my service runs - nor whether I can move my service earlier. Can you help me think of ways to diagnose / troubleshoot this?
measurements from 2 separate boots, returned by systemd-analyze blame (this list is ordered by slowest to fastest systemd service):
Code: Select all
9.011s dev-mmcblk0p2.device 3.858s keyboard-setup.service 3.204s systemd-udev-trigger.service 2.995s busybox-syslogd.service 2.436s [[[[---this is my controller---]]].service <------- 2.368s systemd-logind.service 2.273s dhcpcd.service 2.219s systemd-journald.service 2.027s avahi-daemon.service 1.916s networking.service 1.856s ssh.service 1.835s rpi-eeprom-update.service 1.798s systemd-modules-load.service 1.734s triggerhappy.service 1.496s systemd-remount-fs.service 1.434s rng-tools.service 1.164s wpa_supplicant.service 1.156s systemd-user-sessions.service 1.113s systemd-tmpfiles-setup.service 1.052s ntp.service 947ms rc-local.service 917ms kmod-static-nodes.service 900ms raspi-config.service 865ms fake-hwclock.service 851ms run-rpc_pipefs.mount 849ms sys-kernel-debug.mount 823ms dev-mqueue.mount 813ms systemd-sysctl.service 802ms systemd-tmpfiles-setup-dev.service 718ms [email protected] 689ms systemd-udevd.service 678ms systemd-random-seed.service 671ms systemd-fsck-root.service 597ms alsa-restore.service 491ms systemd-update-utmp.service 415ms var-tmp.mount 414ms tmp.mount 368ms systemd-journal-flush.service 357ms sys-kernel-config.mount 330ms var-lib-dhcpcd5.mount 298ms [email protected]\x2dpartuuid-6c586e13\x2d01.service 280ms console-setup.service 276ms nfs-config.service
Code: Select all
13.987s dhcpcd.service 9.364s dev-mmcblk0p2.device 4.289s networking.service 3.678s keyboard-setup.service 3.597s systemd-logind.service 3.294s systemd-udev-trigger.service 2.827s [[[[---this is my controller---]]].service <------- 2.607s wpa_supplicant.service 2.385s systemd-journald.service 2.089s rng-tools.service 1.958s systemd-modules-load.service 1.827s avahi-daemon.service 1.644s busybox-syslogd.service 1.471s systemd-remount-fs.service 1.391s rpi-eeprom-update.service 1.064s systemd-tmpfiles-setup.service 1.056s fake-hwclock.service 950ms kmod-static-nodes.service 932ms triggerhappy.service 930ms run-rpc_pipefs.mount 842ms dev-mqueue.mount 838ms alsa-restore.service 820ms raspi-config.service 775ms ssh.service 722ms systemd-fsck-root.service
I was also thinking to try OTG mode on Raspberry PI 4 - it should boot a lot faster... maybe.
Otherwise, i might move over to Teensy 4.0, arduinos boot very fast. I'd like to stay with raspberry pi if possible...
Can you think of ways to troubleshoot or diagnose this?