Created
October 28, 2010 06:45
-
-
Save kylegibson/650786 to your computer and use it in GitHub Desktop.
Print Linux Kernel Frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/time.h> | |
#define USECREQ 250 | |
#define LOOPS 1000 | |
void event_handler (int signum) | |
{ | |
static unsigned long cnt = 0; | |
static struct timeval tsFirst; | |
if (cnt == 0) { | |
gettimeofday (&tsFirst, 0); | |
} | |
cnt ++; | |
if (cnt >= LOOPS) { | |
struct timeval tsNow; | |
struct timeval diff; | |
setitimer (ITIMER_REAL, NULL, NULL); | |
gettimeofday (&tsNow, 0); | |
timersub(&tsNow, &tsFirst, &diff); | |
unsigned long long udiff = (diff.tv_sec * 1000000) + diff.tv_usec; | |
double delta = (double)(udiff/cnt)/1000000; | |
int hz = (unsigned)(1.0/delta); | |
printf ("kernel timer interrupt frequency is approx. %d Hz", hz); | |
if (hz >= (int) (1.0/((double)(USECREQ)/1000000))) { | |
printf (" or higher"); | |
} | |
printf ("\n"); | |
exit (0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment