From: Raz <raziebe@gmail.com>
To: "Linux Kernel" <linux-kernel@vger.kernel.org>
Subject: mmap over HPET - 32 bit wrap arround
Date: Thu, 29 May 2008 01:19:14 +0300 [thread overview]
Message-ID: <5d96567b0805281519v7ee18eb0l27f2e4edc18af01c@mail.gmail.com> (raw)
In-Reply-To: <83CA05F64804AF43B8F733C4ABDFAA5101384FA4@mail1.bitband.com>
I am wondering wether someone can explain how hpet behaves. The bellow
is a short program that reads from a mmaped /dev/hpet the time. I am
running it and it looks that afer ~296 seconds the counter resets . I
AM RUNNING 64bi KERNEL(2.6.18-8.el5) and reading a 64BIT VARIABLE.
my hpet is 14MHZ, so I am guessing a 32bit wraparound ( ~296 * 14Mhz
) = MAX_INT . but why ?
thank you
raz
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>ing 6
#include <sys/mman.h>
#include <stdio.h>
struct hpet {
uint64_t hpet_cap; /* capabilities */
uint64_t res0; /* reserved */
uint64_t hpet_config; /* configuration */
uint64_t res1; /* reserved */
uint64_t hpet_isr; /* interrupt status reg */
uint64_t res2[25]; /* reserved */
union { /* main counter */
uint64_t _hpet_mc64;
uint32_t _hpet_mc32;
unsigned long _hpet_mc;
} _u0;
uint64_t res3; /* reserved */
struct hpet_timer {
uint64_t hpet_config; /* configuration/cap */
union { /* timer compare register */
uint64_t _hpet_hc64;
uint32_t _hpet_hc32;
unsigned long _hpet_compare;
} _u1;
uint64_t hpet_fsb[2]; /* FSB route */
} hpet_timers[1];
};
struct hpet* timer;
int hpet_fd;
uint64_t resHZ;
uint64_t divisor;
#define NSEC_PER_SEC 1000000000LL
#define USEC_PER_SEC 1000000LL
int hpet_init()
{
hpet_fd = open("/dev/hpet", O_RDONLY);
if (hpet_fd < 0) {
puts("This system has no accessible HPET device");
return -1;
}
timer = ( struct hpet* )mmap(NULL, 1024 ,PROT_READ,
MAP_SHARED, hpet_fd, 0);
if ((long)timer == (-1) ) {
puts("This system has no mappable HPET device");
close(hpet_fd);
return -1;
}
return 0;
}
void discover_hpet_resulotion(void)
{
uint64_t d1,d2;
d1 = timer->_u0._hpet_mc64;
sleep(1);
d2 = timer->_u0._hpet_mc64;
resHZ = d2 - d1;
printf("HPET clock resolution %lldHZ\n",
resHZ);
}
void calibrate_hpet(void)
{
divisor = NSEC_PER_SEC / resHZ;
printf("divisor=%lld ns/hpet\n", divisor);
}
uint64_t __get_cur_ns(void)
{
return (timer->_u0._hpet_mc64*divisor);
}
uint64_t __get_cur_us(void)
{
return __get_cur_ns()/1000;
}
int main()
{
uint64_t d1,d2;
if ( hpet_init() < 0 ){
return (0);
}
discover_hpet_resulotion();
calibrate_hpet();
while(1){
d1 = __get_cur_us();
sleep(1);
d2 = __get_cur_us();
printf("cur %lldus delta=%lldus\n",
d2,d2-d1);
}
}
--
Raz
next parent reply other threads:[~2008-05-28 22:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <83CA05F64804AF43B8F733C4ABDFAA5101384F73@mail1.bitband.com>
[not found] ` <83CA05F64804AF43B8F733C4ABDFAA5101384FA4@mail1.bitband.com>
2008-05-28 22:19 ` Raz [this message]
2008-05-28 23:57 ` Lee Revell
2008-05-31 18:20 ` Raz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d96567b0805281519v7ee18eb0l27f2e4edc18af01c@mail.gmail.com \
--to=raziebe@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®