#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))) {
}
}
}
int main (int argc, char **argv)
{
struct sigaction sa;
struct itimerval timer;
sa.sa_handler = &event_handler;
sigaction (SIGALRM, &sa, NULL);
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = USECREQ;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = USECREQ;
setitimer (ITIMER_REAL, &timer, NULL);
while (1);
}
I2luY2x1ZGUgPHNpZ25hbC5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzeXMvdGltZS5oPgoKCiNkZWZpbmUgVVNFQ1JFUSAyNTAKI2RlZmluZSBMT09QUyAgIDEwMDAKCnZvaWQgZXZlbnRfaGFuZGxlciAoaW50IHNpZ251bSkKewogc3RhdGljIHVuc2lnbmVkIGxvbmcgY250ID0gMDsKIHN0YXRpYyBzdHJ1Y3QgdGltZXZhbCB0c0ZpcnN0OwogaWYgKGNudCA9PSAwKSB7CiAgIGdldHRpbWVvZmRheSAoJnRzRmlyc3QsIDApOwogfSAKIGNudCArKzsKIGlmIChjbnQgPj0gTE9PUFMpIHsKICAgc3RydWN0IHRpbWV2YWwgdHNOb3c7CiAgIHN0cn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