Time and timers

Time resolution

Time is measured in nano-seconds. Two different data structures are used to measure time: POSIX structure:


struct timespec {
   time_t tv_sec; /* seconds */
   long tv_nsec; /* nanoseconds */
};
	      
and RTLinux specific:
typedef long long hrtime_t; /* Nano seconds */

RTLinux use the highest resolution that the underlying hardware provides.

Currently supported clocks are:

  • CLOCK_MONOTONIC: This POSIX clock runs at a steady rate, and is never adjusted or reset.

  • CLOCK_REALTIME: This is the standard POSIX realtime clock. Currently, it is the same as CLOCK_MONOTONIC.

  • CLOCK_RTL_SCHED: The clock that the scheduler uses for task scheduling, it is the best hardware clock.

The following clocks are architecture-dependent. They are not normally found in user programs.

  • CLOCK_8254: Used on non-APIC x86 machines for scheduling. Its frequency is 1193180Hz.

  • CLOCK_APIC: Used on SMP x86 machines and single processor equipped with local APIC. This clock ticks at the same frequency than the internal processor clock. If the processor is clocked at 1GHz or higher, then the this clock has a resolution smaller than 1 nano-second.

User timers

There is no user timers. There is only one timer handler per hardware timer, which is the associated with the interrupt handler. When the scheduler module is loaded, the scheduler takes the control of the timer and no other thread can use the timer.

The only timing facility that a thread can use being a periodic thread.

Facilities to add new hardware timers

The internal structure of the source code is prepared to add new timer drivers easily. There is a struct rtl_clock similar to the device driver structure used to register UNIX device drivers.