Revert "Improve stability of PHC reading in phc2sys."
This reverts commit f08d264e1d
.
Will apply this patch again, with the correct author info.
master
parent
f08d264e1d
commit
0a5caa8476
29
phc2sys.c
29
phc2sys.c
|
@ -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,34 +87,25 @@ 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++) {
|
|
||||||
if (clock_gettime(sysclk, &tdst1) ||
|
|
||||||
clock_gettime(clkid, &tsrc) ||
|
|
||||||
clock_gettime(sysclk, &tdst2)) {
|
|
||||||
perror("clock_gettime");
|
perror("clock_gettime");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
interval = (tdst2.tv_sec - tdst1.tv_sec) * NS_PER_SEC +
|
if (clock_gettime(sysclk, &tdst)) {
|
||||||
tdst2.tv_nsec - tdst1.tv_nsec;
|
perror("clock_gettime");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (best_interval > interval) {
|
*offset = tdst.tv_sec * NS_PER_SEC - tsrc.tv_sec * NS_PER_SEC +
|
||||||
best_interval = interval;
|
tdst.tv_nsec - tsrc.tv_nsec - rdelay;
|
||||||
*offset = (tdst1.tv_sec - tsrc.tv_sec) * NS_PER_SEC +
|
*ts = tdst.tv_sec * NS_PER_SEC + tdst.tv_nsec;
|
||||||
tdst1.tv_nsec - tsrc.tv_nsec +
|
|
||||||
interval / 2 - rdelay;
|
|
||||||
*ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue