0

I needed a high resolution timer (at least having micro-second level resolution) and i found setitimer() can be set in micro-seconds level.

struct itimerval t;
t.it_interval.tv_sec = 0;
t.it_interval.tv_usec = 2;
t.it_value.tv_sec = 0;
t.it_value.tv_usec = 3;
setitimer (ITIMER_REAL , &t, NULL);

What i needed to know is setitimer() actual resolution in linux?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
DarRay
  • 2,550
  • 6
  • 27
  • 39

2 Answers2

1

Lower, actually, but how low is not specified. The manpage states:

may expire some (short) time afterward, which depends on the system timer resolution and on the system load; see time(7).

If you require microsecond-level resolution and precision, you are in the real-time domain.

thiton
  • 35,651
  • 4
  • 70
  • 100
  • Do u know how to implement this in real-time domain – DarRay Oct 04 '11 at 10:11
  • @DarRay: Sorry, but this is a topic too wide for a post or comment. Better get a good book and start reading. – thiton Oct 04 '11 at 10:12
  • 2
    real time has nothing to do with precision but with deadlines being met within a given time frame. – RedX Oct 04 '11 at 10:14
  • @RedX: Yes, I agree. But why would you need a high timer precision if not to meet a deadline within microseconds? If the OP could suffer a few microseconds of delay, he wouldn't need the precision in setitimer. – thiton Oct 04 '11 at 10:17
1

The API is in micro-second, the actual resolutions depends on both the kernel configuration and hardware resources.

If your kernel configuration does not have the Hi res timers option set, then the resolution is the OS tick resolution - which is itself set in the kernel config (CONFIG_HZ) and is usualy between 100 to 1000 hz.

If the hi res timer option is on then the timer resolution is determined by your specific timer hardware abilities and limitations.

You can find out the actual timer source on the system using the commands:

$ ls /sys/devices/system/clocksource/clocksource0/

$ cat /sys/devices/system/clocksource/clocksource0/*

gby
  • 14,900
  • 40
  • 57
  • @jby: For the first command the result is `available_clocksource current_clocksource` and second command displays `acpi_pm jiffies tsc acpi_pm`. I have no idea what these means. Can you please help – DarRay Oct 04 '11 at 10:44
  • Basically, it means that acpi_pm (ACPI Power management timer) is the active clock source in your machine. The ACPI PM timer resolution is roughly 280 nanoseconds, so you're OK from that perspective. Note however that there is both interrupt and scheduling latency involved which needs to be taken into account. You will probably need to a PREEMPT-RT kernel installed to get to the resolution you want. – gby Oct 04 '11 at 11:27
  • There is a lot of relevant material available on the subject here: http://elinux.org/Real_Time – gby Oct 04 '11 at 11:29