How to detect if your system has high resolution timer?

High Resolution timer is a necessary resource for realtime applications, fortunately the software support is already integrated on Linux kernel, but your hardware need to have internal support. Also fortunately all “modern” computer has this internal support.

Case you’re in doubt if your computer has it, then just execute this C code to test:

#include <stdio.h>
#include <linux/time.h>

static int check_timer(void)
{
  struct timespec ts;

  if (clock_getres(CLOCK_MONOTONIC, &ts))
    return 1;

  return (ts.tv_sec != 0 || ts.tv_nsec != 1);
}

int main()
{

  int missing_hires;

  missing_hires = check_timer();

  if(!missing_hires)
    printf("Your system has High Resolution timer!\n");
  else
    printf("Sorry, your system doesn't have High Resolution timer!\n");

  return 0;
}

Source: http://www.spinics.net/lists/linux-rt-users/msg09160.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s