librecore-org / librecore

GNU General Public License v2.0
88 stars 10 forks source link

[ich7] GRUB is very slow accessing IDE disks #3

Open ghost opened 7 years ago

ghost commented 7 years ago

For reasons unknown, the GRUB payload is very laggy.

Keypresses are not always registered, and there is a lot of input lag within GRUB.

The main cause of slowdowns seems to be the loading of the kernel and initramfs after the OS grub.cfg is loaded. There is no serial console output at this point.

The average boot time (from pressing the power button to the GDM login screen) is ~55 seconds. The actual kernel boot time is usually ~6 seconds according to dmesg. It takes coreboot+GRUB ~49 seconds to get to the point of booting a kernel.

ghost commented 7 years ago

According to @ArthurHeymans, this slowness also occurs with the SeaBIOS payload.

Within GRUB, this problem is limited to booting from ATA devices. It does not happen when you boot from USB. USB boots immediately. I'm unsure about SeaBIOS.

zamaudio commented 7 years ago

I have always seen this issue on this board since conception. I suspect the issue is IRQ related or CPU multiple-core related.

ArthurHeymans commented 7 years ago

I looks like the slowness on grub and SeaBIOS is gone with latest upstream! grub is still a bit slow to load stuff from sata disks but its already a lot more bearable.

ghost commented 7 years ago

Maybe we can try to fix #5 and test if GRUB is also slow on the GA-945GCM-S2L. If so, there is probably some bug with IDE mode on ICH7. Likely in GRUB and not in coreboot.

zamaudio commented 7 years ago

I flashed master and recent SIO EC fixes, I installed grub2 payload as usual and noticed no difference with speed loading from SATA in IDE mode.

ghost commented 7 years ago

I think we should differentiate between the input lag, which may be chipset-specific and the slowness in loading the kernel and initrd, which happens on both 945GC and G41, and is tracked in issue #5.

I'll try mainline GRUB on x4x as soon as possible, which might have solved the input lag problem.

In general, I just want to know why everything works so well on gm45 and what we're doing wrong on i945 and x4x.

ghost commented 7 years ago

The input lag can be solved on at least the ga-945gcm-s2l by adding rmmod at_keyboard at the top of grub.cfg and removing the terminal_input --append at_keyboard line.

ghost commented 7 years ago

I can also confirm now that rmmod at_keyboard fixes the slow keypresses on the ga-g41m-es2l as well, even with a much older grub.elf.

The only problem both boards still have, is slowness in accessing disks. Especially when doing regular expression searches, or loading kernels and initramfs'es. GRUB doesn't show any errors whatsoever, it just prints debug output like Opening (ata4) with long pauses in between.

My guess is that there is a problem with IDE mode on the ICH7 southbridge, as the exact same problem occurs both on i945 and x4x.

ghost commented 7 years ago

The slowness may be USB-related. Both on i945 and x4x, running debug=all from a GRUB console results in the screen being flooded by these messages:

bus/usb/uhci.c:809: detect=0x80 port=0
bus/usb/uhci.c:798: detect_dev, iobase:00002060
bus/usb/uhci.c:809: detect=0x80 port=1
bus/usb/uhci.c:612: >t status=0x188807ff data=0xcf5ab480 td=0xcf5d8120,
cf5d8120
bus/usb/uhci.c:672: transaction fallthrough
bus/usb/uhci.c:798: detect_dev, iobase:00002000
bus/usb/uhci.c:809: detect=0x80 port=0
bus/usb/uhci.c:798: detect_dev, iobase:00002000
--MORE--bus/usb/uhci.c:798: detect_dev, iobase:00002000

Eventually both boards crash and reboot.

ghost commented 7 years ago

The exact same thing happens on a Lenovo X200, even though that doesn't exhibit any slowness. So it's probably not USB-related.

ghost commented 7 years ago

Using GRUB's testspeed, we can see that the performance is rather abysmal when loading a kernel from an ata disk.

grub> testspeed (ata4,gpt2)/vmlinuz 
File size: 3.95MiB
Elapsed time: 8.316 s 
Speed: 486.78KiB/s

(Trying the same thing on a Lenovo X200 results in 100MB/s+)

USB, on the other hand, seems all right.

grub> testspeed (usb0,msdos1)/install/vmlinuz 
File size: 2.98MiB
Elapsed time: 0.163 s 
Speed: 18.29MiB/s 

When the SeaBIOS payload loads GRUB from disk, loading the kernel is only slightly faster.

grub> testspeed (hd0,2)/vmlinuz 
File size: 3.95MiB
Elapsed time: 1.914 s 
Speed: 2.07MiB/s 

Once Debian is booted, the disk seems fine..

kevin@test-machine:~$ sudo hdparm -t /dev/sda
  Timing buffered disk reads: 378 MB in  3.01 seconds = 125.74 MB/sec
ghost commented 7 years ago

Tested with vendor BIOS:

grub> testspeed (hd0,gpt2)/vmlinuz
File size: 3.95MiB
Elapsed itme: 0.066 s
Speed: 59.90MiB/s
ghost commented 7 years ago

Booting the Linux kernel with libata.dma=0 results in the same behaviour in the OS. This problem is likely caused by PIO mode being used by the payload.

zamaudio commented 7 years ago

This could be a bug with the ICH7 ata init code in coreboot, I don't know yet.

ArthurHeymans commented 7 years ago

If you configure SeaBIOS to select CONFIG_ATA_DMA grub itself is fast. So the remaining problem is why grub as a payload is that slow...

zamaudio commented 7 years ago

Okay, this is a bug with grub2. It currently does not use DMA mode for ATA transfers. The reason it works faster when chainloaded from SeaBIOS is because SeaBIOS exposes a BIOS emulation that uses DMA underneath, and grub2 uses that instead of raw PIO.

ghost commented 7 years ago

I can confirm that setting CONFIG_ATA_DMA=y for SeaBIOS indeed fixes the problem on both the ga-g41m-es2l and the ga-945gcm-s2l when GRUB is loaded from disk. I will test the d945gclf later.

ghost commented 7 years ago

Also tested on two d945gclf boards. The problem is fixed with CONFIG_ATA_DMA=y there as well.

So with SeaBIOS, this bug can be avoided on all ICH7 boards, it seems.