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;


Leave a Reply

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

You are commenting using your 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