Get Numer Of Timer Ticks
Posted: Wed Jan 23, 2008 6:35 pm
I need to get the number of timer ticks total since the system has booted. Is it possible to do this in assembly? If so, how?
Thanks,
Joseph
Thanks,
Joseph
The Place to Start for Operating System Developers
http://f.osdev.org/
Using a 1 Hz timer frequency would be more efficient, however it lacks precision (for e.g. "1.999 seconds" would look the same as "1.000 seconds").01000101 wrote:I have the PIT 18.2 Hz rollover installed on IRQ 0, but I've been thinking, would it not be more efficient to just use the 1second timersto free up some processor time? instaed of it responding to an IRQ every 1/18th of a second, wouldn't it be better to have it respond only once a second? Also, I don't even use the timer_wait functions or anything similar anywhere in my OS and the only thing I can think of to use the timer for would be too... display the time active in the OS.
NOOOOObewing wrote: Brendan is right about precision -- however, you do not have to use interrupts to achieve what he is saying. In a singletasking system, you can always use the "microsecond" PIT countdown timer. If you are willing to use interrupts, you can use one-shots to measure short periods of time, also.
I'd really like some more info on this, please.rv6502 wrote: 1) some chipsets cannot latch the MSB/LSB counters properly and you will get erroneous readings.
There's 2 different problems that I'm aware of.bewing wrote:I'd really like some more info on this, please.rv6502 wrote: 1) some chipsets cannot latch the MSB/LSB counters properly and you will get erroneous readings.
Code: Select all
5-4 counter access
00 counter latch command
BUG: Intel Neptune/Mercury Chipset 8237IB (SIO) needs a
short delay after issueing this command, else the
MSB may be outdated concerning the LSB, resulting
in large measuring errors.
Workaround: Check for this condition by comparing
results with last results and don't use errornous
results.
Code: Select all
disable_IRQs();
second_count = get_PIT_count();
do {
first_count = second_count;
second_count = get_PIT_count();
} while (first_count < second_count);
restore_IRQs();
No...bewing wrote:But if you are only reading the MSB *or* LSB (not both), then you don't need to latch the value of the PIT register, right?
You'd need to set the channel to "lobyte only" or "hibyte only" and then issue the latch command to get a reliable 8-bit count (e.g. without needing to worry about the "ripple through" or the stale MSB problem on the Neptune chipset, but still needing to worry about lost ticks).pctim003.txt wrote:{JAM} Some CTC hardware implementations do not buffer the counter properly, so
if the Counting register is read at the instant it is changing value, you may
read the counter part-way through the 'ripple-through', i.e. some low-order bits
may have decremented but high-order bits may not have decremented yet.
Therefore, even in lobyte-only or hibyte-only mode, the Counting register cannot
be read reliably in this way.
are you serious ?Brendan wrote:
Also note that for some CPUs there's a similar problem with RDTSC, where the high 32-bits may be "stale" (e.g. you could read the values 0x01234567FFFFFFFE then 0x0123456700000002 then 0x0123456800000004).