Hi, I have written a simple program that uses some of the same code from the ptplinux to check the /dev/ptp0 clock with the system time: #include <stdio.h> #include <sys/ioctl.h> #include <linux/ptp_clock.h> #include <stdlib.h> #include <time.h> #define NS_PER_SEC 1000000000LL #define FD_TO_CLOCKID(fd) ((clockid_t) ((((unsigned int) ~fd) << 3) | CLOCKFD))
static int64_t pctns(struct ptp_clock_time *t) { return t->sec * NS_PER_SEC + t->nsec; } static int64_t sysoff_estimate(struct ptp_clock_time *pct, int n_samples ) { int64_t t1, t2, tp; static int64_t pt1, pt2, ptp; int64_t interval, offset; int i; for (i = 0; i < n_samples; i++) { t1 = pctns(&pct[2*i]); tp = pctns(&pct[2*i+1]); t2 = pctns(&pct[2*i+2]); interval = t2 - t1; offset = (t2 + t1) / 2 - tp; //insertion_sort(i, interval, offset, (t2 + t1) / 2); if(i == 0) { printf("t1:%ld t2:%ld tp:%ld offset:%ld \n", t1 - pt1, t2 - pt2, tp - ptp, offset); pt1 = t1; ptp = t2; pt2 = tp; } } return 1; } int main(){ struct ptp_sys_offset pso; pso.n_samples = 5; int idx = -1; int clkid = 0; int fd = open("/dev/ptp0", O_RDWR); while(1){ sleep(1); if (ioctl(fd, PTP_SYS_OFFSET, &pso)) { perror("ioctl PTP_SYS_OFFSET"); } sysoff_estimate( pso.ts, pso.n_samples ); } } While running the above program without phc2sys the output from the program is: t1:1000252167 t2:5282945269 tp:-3171301000 offset:4171547723 t1:1000181952 t2:5171731144 tp:-3060242997 offset:4060418037 t1:1000201593 t2:5060624469 tp:-2949084760 offset:3949283848 t1:1000292372 t2:4949575672 tp:-2837855845 offset:3838141851 t1:1000190880 t2:4838334143 tp:-2726820632 offset:3727009583 t1:1000144080 t2:4727155679 tp:-2615739887 offset:3615882599 t1:1000187625 t2:4616072139 tp:-2504564783 offset:3504750665 t1:1000163203 t2:4504920853 tp:-2393458715 offset:3393622624 t1:1000152058 t2:4393778757 tp:-2282344421 offset:3282491885 t1:1000235491 t2:4282730818 tp:-2171124309 offset:3171355149 t1:1000205914 t2:4171564965 tp:-2060019474 offset:3060221571 t1:1000253059 t2:4060478965 tp:-1948832885 offset:2949082301 t1:1000219421 t2:3949309253 tp:-1837731221 offset:2837948251 t1:1000254931 t2:3838205602 tp:-1726560037 offset:2726807451 t1:1000187309 t2:3726998101 tp:-1615493026 offset:2615675827 t1:1000163261 t2:3615845525 tp:-1504386581 offset:2504547466 t1:1000282032 t2:3504831442 tp:-1393129253 offset:2393404632 t1:1000166054 t2:3393575611 tp:-1282111346 offset:2282274592 t1:1000255795 t2:3282537803 tp:-1170883947 offset:2171137121 t1:4573582696 t2:6744721689 tp:-1059332203 offset:5632907108 <- jump t1:1000192809 t2:6633104166 tp:-4521585113 offset:5521774279 t1:1000223424 t2:6522001117 tp:-4410419590 offset:5410638651 t1:1000188634 t2:6410831302 tp:-4299321629 offset:5299506676 t1:1000149466 t2:6299660160 tp:-4188233430 offset:5188379094 t1:1000186876 t2:6188570493 tp:-4077063440 offset:5077246659 t1:1000162224 t2:6077414038 tp:-3965960477 offset:4966118927 t1:1000155168 t2:5966277033 tp:-3854841078 offset:4854990673 t1:1000200874 t2:5855195997 tp:-3743658729 offset:4743856104 t1:1000136362 t2:5743996368 tp:-3632597997 offset:4632730110 t1:1000180137 t2:5632915533 tp:-3521422400 offset:4521599153 t1:1000192119 t2:5521794627 tp:-3410279821 offset:4410466640 t1:1000152028 t2:5410623133 tp:-3299191667 offset:4299339923 t1:1000169108 t2:5299512717 tp:-3188044509 offset:4188209109 t1:1000138204 t2:5188352281 tp:-3076947469 offset:4077082217 t1:1000156320 t2:5077242339 tp:-2965803113 offset:3965954638 t1:1000252253 t2:4966210189 tp:-2854567731 offset:3854815433 t1:1000188087 t2:4855007005 tp:-2743499501 offset:3743683757 t1:1000164441 t2:4743856982 tp:-2632392669 offset:3632556102 t1:1000214496 t2:4632772211 tp:-2521213398 offset:3521419412 t1:1000214352 t2:4521637811 tp:-2410073811 offset:3410284332 does it means that someone else is controlling the clock ? Thanks, Wen Bin Leong -----Original Message----- From: Richard Cochran <richardcoch...@gmail.com> Sent: Monday, 10 February 2020 10:34 pm To: Wen Bin Leong <wenbin.le...@rapsodo.com> Cc: linuxptp-users@lists.sourceforge.net Subject: Re: [Linuxptp-users] hpc2sys sync issue On Mon, Feb 10, 2020 at 09:36:39AM +0000, Wen Bin Leong wrote: > However the phc2sys is giving me the following error on the slave side, where > the phc clock took a big jump: > $ sudo ./phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -w -m > phc2sys[251211.780]: CLOCK_REALTIME phc offset 39434682283 s0 freq -801 > delay 7410 > phc2sys[251212.781]: CLOCK_REALTIME phc offset 39434724040 s1 freq +40945 > delay 7410 > phc2sys[251213.781]: CLOCK_REALTIME phc offset 39432354542 s2 freq +100000000 > delay 7420 ... > phc2sys[251244.787]: CLOCK_REALTIME phc offset 35988703421 s2 freq +100000000 > delay 6678 > phc2sys[251245.788]: clockcheck: clock jumped forward or running faster than > expected! <-- the error > phc2sys[251245.788]: CLOCK_REALTIME phc offset 39378909599 s0 freq +100000000 > delay 6678 It looks like someone else is controlling CLOCK_REALTIME. Is the PC running ntpd or chrony or timesyncd or ... Thanks, Richard _______________________________________________ Linuxptp-users mailing list Linuxptp-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-users