I needed a high resolution timer (at least having micro-second level resolution) and i found setitimer()
can be set in 开发者_StackOverflowmicro-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?
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.
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/*
精彩评论