Day: November 7, 2013

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();

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

  return 0;