Commit 52df1a37 authored by Alessandro Rubini's avatar Alessandro Rubini

servo: fix correction factor and remove duplicate fields

"delay_ms" and "m_to_s_delay" were duplicates. This removes one of them
(and the same for s_to_m) and a long-standing "TODO check".

The original code was unclear about correction factor, that sometimes
was removed and sometimes not. Since the value is an overhead figure
added by any transparent clocks in the path, this commit counts it
immediately, to forget about it as soon as possible.  This also makes
the code more symmetric (t1,t2 code is similar to t3,t4 code).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ac5c8b72
......@@ -91,16 +91,8 @@ struct pp_owd_fltr {
};
struct pp_servo {
/* TODO check. Which is the difference between m_to_s_dly (which
* comes from ptpd's master_to_slave_delay) and delay_ms (which comes
* from ptpd's delay_MS? Seems like ptpd actually uses only delay_MS.
* The same of course must be checked for their equivalents,
* s_to_m_dly and delay_sm
*/
TimeInternal m_to_s_dly;
TimeInternal s_to_m_dly;
TimeInternal delay_ms;
TimeInternal delay_sm;
Integer32 obs_drift;
struct pp_owd_fltr owd_fltr;
struct pp_ofm_fltr ofm_fltr;
......
......@@ -39,14 +39,17 @@ static void format_TimeInternal(char *s, TimeInternal *t)
*/
static int __pp_servo_got_sync(struct pp_instance *ppi)
{
TimeInternal *correction_field = &ppi->cField;
TimeInternal m_to_s_dly;
TimeInternal time_tmp;
struct pp_ofm_fltr *ofm_fltr = &SRV(ppi)->ofm_fltr;
Integer32 adj;
/* calc 'master_to_slave_delay' */
/*
* calc 'master_to_slave_delay', removing the correction field
* added by transparent clocks in the path.
*/
sub_TimeInternal(&m_to_s_dly, &ppi->t2, &ppi->t1);
sub_TimeInternal(&m_to_s_dly, &m_to_s_dly, &ppi->cField);
if (OPTS(ppi)->max_dly) { /* If maxDelay is 0 then it's OFF */
if (m_to_s_dly.seconds) {
......@@ -66,12 +69,6 @@ static int __pp_servo_got_sync(struct pp_instance *ppi)
SRV(ppi)->m_to_s_dly = m_to_s_dly;
sub_TimeInternal(&SRV(ppi)->delay_ms, &ppi->t2, &ppi->t1);
/* Take care about correctionField */
sub_TimeInternal(&SRV(ppi)->m_to_s_dly,
&SRV(ppi)->m_to_s_dly, correction_field);
/* update 'offsetFromMaster', (End to End mode) */
sub_TimeInternal(&DSCUR(ppi)->offsetFromMaster,
&SRV(ppi)->m_to_s_dly,
......@@ -179,10 +176,8 @@ void pp_servo_got_sync(struct pp_instance *ppi)
(int)SRV(ppi)->obs_drift);
}
/* called by slave states when delay_resp is received (all t1..t4 are valid) */
static void pp_update_delay(struct pp_instance *ppi,
TimeInternal *correction_field)
void pp_servo_got_resp(struct pp_instance *ppi)
{
TimeInternal s_to_m_dly;
TimeInternal *mpd = &DSCUR(ppi)->meanPathDelay;
......@@ -192,8 +187,12 @@ static void pp_update_delay(struct pp_instance *ppi,
if (!SRV(ppi)->t1_t2_valid)
return;
/* calc 'slave to master' delay */
/*
* calc 'slave_to_master_delay', removing the correction field
* added by transparent clocks in the path.
*/
sub_TimeInternal(&s_to_m_dly, &ppi->t4, &ppi->t3);
sub_TimeInternal(&s_to_m_dly, &s_to_m_dly, &ppi->cField);
if (OPTS(ppi)->max_dly) { /* If max_delay is 0 then it's OFF */
if (s_to_m_dly.seconds) {
......@@ -212,21 +211,14 @@ static void pp_update_delay(struct pp_instance *ppi,
return;
}
/* calc 'slave to_master' delay (master to slave delay is
* already computed in pp_update_offset)
*/
sub_TimeInternal(&SRV(ppi)->delay_sm, &ppi->t4, &ppi->t3);
SRV(ppi)->s_to_m_dly = s_to_m_dly;
/* update 'one_way_delay' */
add_TimeInternal(mpd, &SRV(ppi)->delay_sm, &SRV(ppi)->delay_ms);
/* Subtract correction_field */
sub_TimeInternal(mpd, mpd, correction_field);
add_TimeInternal(mpd, &SRV(ppi)->m_to_s_dly, &SRV(ppi)->s_to_m_dly);
/* Compute one-way delay */
div2_TimeInternal(mpd);
if (mpd->seconds) {
/* cannot filter with secs, clear filter */
owd_fltr->s_exp = 0;
......@@ -260,8 +252,3 @@ static void pp_update_delay(struct pp_instance *ppi,
pp_diag(ppi, servo, 1, "delay filter %d, %d\n",
(int)owd_fltr->y, (int)owd_fltr->s_exp);
}
void pp_servo_got_resp(struct pp_instance *ppi)
{
pp_update_delay(ppi, &ppi->cField);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment