-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bogoMips 0 causes a halt/freeze #74
Comments
Hi, nice to meet you! Now, back to technical stuff. I've took a look at the conversation on vogons.org (great place, btw). Still, even if that bit was set, having
Now, given that, in order to
In my understanding of the comments on vogons.org, you do see the Now, given your EDIT comment, it looks like you've been able to reach
And So, it looks like the slowdown of the emulator (compared to physical hardware) is more than 3,000x. That's a lot, but it's not surprising. Are you compiling with it -O3? (Btw, what bogoMIPS value Tilck shows when it's run on QEMU with KVM ?) Anyway, a fix could be to set:
In the |
An alternative solution might be to:
With such a solution, you should see something like:
When running Tilck on the emulator. |
OK thx, I'll check those. The emulation speed may be partly because of my lack of understanding with UniPCemu configuration. |
Ah yeah, you're right. My first suggestion won't work with 1, and 10 is bad because depends on TIMER_HZ and related.
But that's pretty ugly, I know. The problem with using MAX on just
Anyway, I won't insist at all for you to make a pull-request, as it's super easy to fix it myself. Just, it seemed to me that you spent a considerable amount of time playing with this project & debugging it, so I thought you would be happy to put your name on the commit with the fix :-) |
The one in your second post did the trick. Here it is in patch form: That's a good point about attribution, and for bigger patches it's a good idea for maintenance's sake. Especially with larger projects with many contributors... |
As discovered from #74, it is possible on some emulators to have a vCPU be able to do less than 1 million iterations. When that happens `loops_per_us` is 0 and delay_us() appears to hang because it starts counting back from 2^31 - 1. The fix -------- Since in such cases the vCPU does < 1 million iters / second, we should not do ANY work in delay_us(u32 us), when us <= 1. But when `us` is big enough we certainly are expected to burn some cycles in order to time to pass. In order to avoid loosing precision, in delay_us() we're going to spin for `us * loops_per_us` only when loops_per_us >= 10, otherwise we're going to spin for `(us * loops_per_ms) / 1000`. For example: loops_per_ms = 800 loops_per_us = 0 If us <= 1, we'll return immediately. But if us == 5, we'll spin: (5 * 800) / 1000 = 4 times The same logic is used when loops_per_us is too small (e.g. 5): loops_per_ms = 5923 loops_per_us = 5 With the basic formula `us * loops_per_us`, with `us` == 4, we'll have to spin for 4 * 5 = 20 iterations, while with the more precise one: (4 * 5923) / 1000 = 23 We'll have to spin a bit more.
Thanks for the patch! |
As discovered from #74, it is possible on some emulators to have a vCPU able to do less than 1 million iterations per second. When that happens, `loops_per_us` is 0 and delay_us() appears to hang because it starts counting back from 2^31 - 1. The fix -------- Since in such cases the vCPU does < 1 million iters / second, we should not do ANY work in delay_us(u32 us), when us <= 1. But when `us` is big enough we certainly are expected to burn some cycles in order to time to pass. In order to avoid loosing precision, in delay_us() we're going to spin for `us * loops_per_us` only when loops_per_us >= 10, otherwise we're going to spin for `(us * loops_per_ms) / 1000`. For example: loops_per_ms = 800 loops_per_us = 0 If us <= 1, we'll return immediately. But if us == 5, we'll spin: (5 * 800) / 1000 = 4 times The same logic is used when loops_per_us is too small (e.g. 5): loops_per_ms = 5923 loops_per_us = 5 With the basic formula `us * loops_per_us`, with `us` == 4, we'll have to spin for 4 * 5 = 20 iterations, while with the more precise one: (4 * 5923) / 1000 = 23 We'll have to spin a bit more.
I've merged the patch. Let me know if something still doesn't work. |
Hi!
Oh man what an awesome project. Your blog posts were nice too :D
Quite a lot of questions spinning around in my head now, but mainly just wanted to drop in to say "hi, saw what you did there, i approve" :D
I do have a small bug to report though. I did some testing in UniPCemu and found out that bogoMips goes to zero for some reason
(EDIT: looks like it's caused by emulation slowness...__bogo_loops reaches value of 8, so that would do it).
This causes Tilck to freeze at kb8042 kernel module init, because the nop loop counter (ecx) will flip over to max value.
Forcing loops_per_us value to 1 enables Tilck to boot all the way to the shell prompt.
The text was updated successfully, but these errors were encountered: