Hacker News new | ask | show | jobs
by avian 1458 days ago
> Linux kernel also has (or had?) code to check for and also avoid a HLT instruction that doesn't work

I wonder how this works. How do you safely check for an instruction that "locks ups unrecoverably" on some hardware? Will Linux hang on boot on such systems? That is still better than hanging randomly later, but I can see why Microsoft didn't want to go for that approach.

EDIT:

The check in Linux literally just called hlt a bunch of times and hoped it didn't crash. There was no recovery in case it failed (note how there's no code path to print anything else than "ok"). Searching for "checking hlt instruction" you can actually find people asking on forums why their boot stoped at that point. The check has been removed in recent kernels, so I had to go back in history a bit to find it.

https://github.com/torvalds/linux/blob/521cb40b0c44418a4fd36...

2 comments

but I can see why Microsoft didn't want to go for that approach.

Yet Windows 95 has a message in its hardware detection dialog which tells you to restart the computer if it stops responding for a long time while it's detecting hardware --- and I believe it writes to the disk its progress, so it'll remember where it was and skip it the next time.

One wonders why neither MS nor Linux did that for HLT. Linux has a no-hlt boot parameter to disable its use.

I like the comment in the following function:

> If this fails, it means that any user program may lock the CPU hard. Too bad.