Page 1 of 1

Why is GRUB taking so long to load my kernel

Posted: Wed Nov 13, 2013 5:51 pm
by justin
It takes 1 min 4 sec in bochs and 11 sec in qemu. Time in bochs is going about 10% faster than real time.

My kernel is about 250k and is being loaded from a hard disk. No surprises in grub.cfg:

Code: Select all

   multiboot /boot/kernel.elf
   boot
Any ideas?

Thanks.

Re: Why is GRUB taking so long to load my kernel

Posted: Thu Nov 14, 2013 12:48 am
by sortie
Perhaps try enable kvm using -enable-kvm if you have it available?

Re: Why is GRUB taking so long to load my kernel

Posted: Thu Nov 14, 2013 5:42 am
by Combuster
I wouldn't just blame bochs/qemu or grub, I have seen them both boot OSes over an MB in size in less than 5 seconds. That basically leaves two options:

- You're using your tools wrong (and I don't think KVM is the fix since I've done without it for long enough)
- You're not measuring properly. In other words you're not actually measuring from the time you hit enter in grub until the first instruction in your kernel is executed. Since GRUB doesn't visibly show you exactly that moment, your kernel has to do it, and your kernel might decide to do a ton of other stuff first.


Also, 250k for a starter(?) kernel sounds like a lot. Mine is a mere 15k in comparison and runs an entire userspace just fine. That may also be a hint to your problem

Re: Why is GRUB taking so long to load my kernel

Posted: Thu Nov 14, 2013 8:00 am
by justin
sortie wrote:Perhaps try enable kvm using -enable-kvm if you have it available?
Thanks. Will give it a shot.
Combuster wrote:I wouldn't just blame bochs/qemu or grub, I have seen them both boot OSes over an MB in size in less than 5 seconds. That basically leaves two options:

- You're using your tools wrong (and I don't think KVM is the fix since I've done without it for long enough)
- You're not measuring properly. In other words you're not actually measuring from the time you hit enter in grub until the first instruction in your kernel is executed. Since GRUB doesn't visibly show you exactly that moment, your kernel has to do it, and your kernel might decide to do a ton of other stuff first.


Also, 250k for a starter(?) kernel sounds like a lot. Mine is a mere 15k in comparison and runs an entire userspace just fine. That may also be a hint to your problem
-Could you elaborate on what you mean by using my tools wrong?

-I have tried making the timeout nonzero and have discovered that the lag is entirely prior to the GRUB menu coming, so I'm confident it is something that GRUB is doing, not the kernel.


I have since found that other people are having this problem as well on real hardware with GRUB2:
http://lists.debian.org/debian-user/201 ... 00737.html

I tried setting translation=lba for my disk in bochsrc but that didn't help.

Re: Why is GRUB taking so long to load my kernel

Posted: Thu Nov 14, 2013 10:08 am
by justin
Combuster wrote:Also, 250k for a starter(?) kernel sounds like a lot. Mine is a mere 15k in comparison and runs an entire userspace just fine. That may also be a hint to your problem
I investigated your advice, but I don't think size is the problem. I ran strip on my kernel and it's down to 88k (still large, but ~1/3 the prior size) and GRUB took 1 min 7 sec in bochs. Compare to 1 min 4 sec with the old file.

Of course, the discarded parts aren't loaded anyways, but I don't think 88k should take 1 minute to read off the disk.

Re: Why is GRUB taking so long to load my kernel

Posted: Thu Nov 14, 2013 1:02 pm
by sortie
Mind you that bochs is significantly slower than real hardware. You will need to adjust the instructions-per-seconds accordingly to how fast it runs on your computer. But, it's probably not worth thinking too much about how fast bochs runs, just whether it runs correctly.