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

diff --git a/pi.c b/pi.c
index 9c7b148..a8c6051 100644
--- a/pi.c
+++ b/pi.c
@@ -61,6 +61,20 @@ static void pi_destroy(struct servo *servo)
        free(s);
 }
 
+static int pi_weight_samples(struct servo *servo)
+{
+       struct pi_servo *s = container_of(servo, struct pi_servo, servo);
+
+       if (s->count < 2)
+               return 0;
+
+       /*
+        * Enable weights approximately at half way between default ki
+        * values for HW and SW time stamping.
+        */
+       return s->ki <= 0.01;
+}
+
 static double pi_sample(struct servo *servo,
                        int64_t offset,
                        uint64_t local_ts,
@@ -137,8 +151,8 @@ static double pi_sample(struct servo *servo,
                        break;
                }
 
-               ki_term = s->ki * offset;
-               ppb = s->kp * offset + s->drift + ki_term;
+               ki_term = s->ki * offset * weight;
+               ppb = s->kp * offset * weight + s->drift + ki_term;
                if (ppb < -servo->max_frequency) {
                        ppb = -servo->max_frequency;
                } else if (ppb > servo->max_frequency) {
@@ -186,6 +200,7 @@ struct servo *pi_servo_create(int fadj, int sw_ts)
                return NULL;
 
        s->servo.destroy = pi_destroy;
+       s->servo.weight_samples = pi_weight_samples;
        s->servo.sample  = pi_sample;
        s->servo.sync_interval = pi_sync_interval;
        s->servo.reset   = pi_reset;
-- 
2.1.0


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to