I'm writing an OS from scratch to run under qemu and I set up HPET timer. To tick every 1 millisecond, I set up:
frequency = 10^15 / counter_clock_period;
ticks = frequency / 1000;
Ticks are every 1 millisecond. frequency
is 100000000 (printed to the console).
I now want to tick every 1 nanosecond. If the frequency is frequency = 100000000
I thought they were 10 ns and I could divide by 10 to get 1ns, however this does not work and time goes very slow. I tried to divide by 1000000 but it still does not count time fine. How to I get the correct ticks
value given frequency
so that ticks are every 1 nanosecond?