Revert "Improve stability of PHC reading in phc2sys."

This reverts commit f08d264e1d.
Will apply this patch again, with the correct author info.
master
Richard Cochran 2012-08-30 14:44:46 +02:00
parent f08d264e1d
commit 0a5caa8476
1 changed files with 13 additions and 24 deletions

View File

@ -41,8 +41,6 @@
#define max_ppb 512000 #define max_ppb 512000
#define min_ppb -512000 #define min_ppb -512000
#define PHC_READINGS 5
static clockid_t clock_open(char *device) static clockid_t clock_open(char *device)
{ {
int fd = open(device, O_RDWR); int fd = open(device, O_RDWR);
@ -89,35 +87,26 @@ static void clock_step(clockid_t clkid, int64_t ns)
static int read_phc(clockid_t clkid, clockid_t sysclk, int rdelay, int64_t *offset, uint64_t *ts) static int read_phc(clockid_t clkid, clockid_t sysclk, int rdelay, int64_t *offset, uint64_t *ts)
{ {
struct timespec tdst1, tdst2, tsrc; struct timespec tsrc, tdst;
int i;
int64_t interval, best_interval = INT64_MAX;
if (clkid == CLOCK_INVALID) { if (clkid == CLOCK_INVALID) {
return 0; return 0;
} }
/* Pick the quickest clkid reading. */ if (clock_gettime(clkid, &tsrc)) {
for (i = 0; i < PHC_READINGS; i++) { perror("clock_gettime");
if (clock_gettime(sysclk, &tdst1) || return 0;
clock_gettime(clkid, &tsrc) ||
clock_gettime(sysclk, &tdst2)) {
perror("clock_gettime");
return 0;
}
interval = (tdst2.tv_sec - tdst1.tv_sec) * NS_PER_SEC +
tdst2.tv_nsec - tdst1.tv_nsec;
if (best_interval > interval) {
best_interval = interval;
*offset = (tdst1.tv_sec - tsrc.tv_sec) * NS_PER_SEC +
tdst1.tv_nsec - tsrc.tv_nsec +
interval / 2 - rdelay;
*ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec;
}
} }
if (clock_gettime(sysclk, &tdst)) {
perror("clock_gettime");
return 0;
}
*offset = tdst.tv_sec * NS_PER_SEC - tsrc.tv_sec * NS_PER_SEC +
tdst.tv_nsec - tsrc.tv_nsec - rdelay;
*ts = tdst.tv_sec * NS_PER_SEC + tdst.tv_nsec;
return 1; return 1;
} }