When the drift value is adjusted by the newly measured frequency offset,
multiply the frequencies instead of adding the measured offset to the
old value to get accurate result even when updating a large drift.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 pi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pi.c b/pi.c
index bd78e40..ccad98e 100644
--- a/pi.c
+++ b/pi.c
@@ -107,8 +107,10 @@ static double pi_sample(struct servo *servo,
                        break;
                }
 
-               s->drift += (s->offset[1] - s->offset[0]) * 1e9 /
-                       (s->local[1] - s->local[0]);
+               /* Adjust drift by the measured frequency offset. */
+               s->drift = 1e9 - (1e9 - s->drift) *
+                                (1.0 - (double)(s->offset[1] - s->offset[0]) /
+                                       (s->local[1] - s->local[0]));
                if (s->drift < -s->maxppb)
                        s->drift = -s->maxppb;
                else if (s->drift > s->maxppb)
-- 
1.8.3.1


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to