copy / v86

x86 PC emulator and x86-to-wasm JIT, running in the browser
https://copy.sh/v86/
BSD 2-Clause "Simplified" License
19.86k stars 1.4k forks source link

CPU frequency is reported as 0 when measured using RDTSC #30

Closed yogev1978 closed 9 years ago

yogev1978 commented 9 years ago

KolibriOS uses RDTSC to calculate CPU frequency. In your emulator, the CPU frequency is reported as 0 (0000 MHz - see attached screenshot). On real machines, the actual CPU frequency is reported. In other emulators (VMware, Oracle VirtualBox, QEMU, BOCHS) the frequency reported might be wrong (since the emulator is not running at the same speed as the host machine), but it's still not 0.

It's very much preferred not to report 0 since it affects some KolibriOS programs (Process Manager reports wrong CPU usage, Ghost Monitor thinks that CPU usage is always 100%, CPUID reports CPU speed as 0 MHz etc.)

screenshot342

copy commented 9 years ago

Thanks, I will look into it. This is supposed to work (RDTSC is supported).

Do you know what hardware is used to measure the time (PIT, RTC, ...)?

yogev1978 commented 9 years ago

I am not a developer myself (volunteering as a PR guy for KolibriOS), so my answer might be not so technical. But as far as I understood, we use PC Speaker port 0x61 via PIT, and count 250ms to calculate the CPU frequency: http://wiki.osdev.org/PC_Speaker

yogev1978 commented 9 years ago

Thanks a lot - I have tested it on your website now, and it displays a value greater than 0. Although that value is pretty small (8 MHz), it's good enough for KolibriOS to display the CPU usage correctly.

copy commented 9 years ago

Yeah, it's just a constant defined here (it has to run at constant speed and the speed at which instructions are executed is not usable for that).

This was very useful because it also fixed many small problems in other operating systems, for example clock.com in Freedos.