On 11/04/2011 12:52 AM, Victor Alvidrez wrote: > I have been doing a lot of research regarding time and how it is > measured in Linux. > > The book "Understanding the Linux Kernel" by Bovet and Cesati was > essential in figuring out how time is handled at the kernel level. > > Here is what I gather so far (that is relevant to my question): > > The RTC is used by the system to initialize the 'struct timeval xtime' > variable with a UTC time. After this occurs the PIT is programmed so > that it issues timer interrupts at a fixed frequency. The book states > that this defines a 'tick'. At each tick occurrence, a interrupt is > triggered and is handled by the TIMER_BH handler. This handler adds > 1/HZ microseconds to the 'xtime.tv_usec' value (where HZ is the kernel > configuration value). If NTP is being used, the adjtimex() function > adjusts the 1/HZ value to slowly synchronize the time with a reference > time.
This understanding is outdated. Search for "high resolution timers" and "dynamic ticks" for a more current understanding. > > My issue is in understanding how the TSC (timer stamp counter register) > is used. I know that this register counts the number of clock ticks. I > am pretty sure that clock ticks refer to ticks produced by the CPU > clock, which runs at completely different frequency than HZ. > > This is where my confusion with Xenomai comes in. The native skin lets > me set the timer mode to be oneshot using TM_ONESHOT so that timer ticks > are in nanoseconds and so that the timer is rescheduled every tick (not > sure if rescheduled is the right word here). This explanation makes me > think that 'timer' refers to the PIT? the timer (usually the APIC, but it can be the PIT on very old processors) is programmed to tick at the next timer event. The TSC is used as a clock source, all the time keeping is done using the TSC unit, durations are converted to the timer frequency when programming the timer. > > However, the native skin lets me set intervals (for alarms/timers) down > to nanoseconds. How can this be accomplished if the HZ value only goes > up to 1000 in the kernel configuration? Somehow I think the TSC must be > used separately, independent of the PIT? > > I realize this isn't really a Xenomai programming issue, but I thought I > would go ahead and ask to see if you could provide some help. Xenomai does not use HZ, it uses a timer (either APIC, or PIT) in one-shot mode, it means programming it to tick only for the next event. Using the TSC as clock source is a completely different issue and has nothing to do with the timer chosen. The difference in frequencies only cause a conversion between the two. > > Thanks > > _______________________________________________ > Xenomai-help mailing list > Xenomai-help@gna.org > https://mail.gna.org/listinfo/xenomai-help > -- Gilles. _______________________________________________ Xenomai-help mailing list Xenomai-help@gna.org https://mail.gna.org/listinfo/xenomai-help