Improve boot performance
Sortix installations boot fast in about two seconds in my VirtualBox VM but the boot performance can be improved considerably. I did a trace to get some data: https://pub.sortix.org/sortix/screenshots/sortix-tracing-boot-performance.png.
Here's some ideas:
- The AHCI initialization is the biggest bottleneck. I suppose there's some long timeouts in there and lot of the work could be parallelized. Likewise for ATA.
- The PS/2 initialization is a bit slow. It seems to use a 50 ms timeout but a comment says grub uses a 20 ms timeout so it could be optimized.
- The init mounting uses a 50 ms polling loop which is a long time, it should be a 1 ms and then increasing up to 50 ms maybe.
- Otherwise the init stuff seems to be a bit slower than expected even with a 1 ms polling loop but maybe that's due to IO.
- A more powerful design is to parallelize all the driver initialization in the kernel which should speed things up.
- The AHCI driver has some 600 ms timeouts that are probably due to the spec and while they can be parallelized, they likely can't be eliminated. However real ports will probably detect a lot quicker so in practice it is wasteful. If the block devices instead appeared as they were detected, and init was notified when a new block device is detected and when no more block devices will become available, then that 600 ms timeout can be avoided in practice.
I have a feeling this can definitely get to subsecond. I got it down to some 560 ms with some prototyping of lowering timeouts and polling intervals.