Commit a040e8d1 authored by Cesar Prados's avatar Cesar Prados Committed by Alessandro Rubini

pdelay/wrservo: wr_servo calculates link delay and offset to master using P2P

the calculation of the link delay and offset to master is moved from
the fat wr_servo_update to tree functions which will be called
according to the delay mech. In the case of pdelay, the link delay
calculated and then the offset.
Signed-off-by: Cesar Prados's avatarC.Prados <c.prados@gsi.de>

Conflicts:
	include/ppsi/pp-instance.h
	include/ppsi/ppsi.h
	proto-ext-whiterabbit/wr-api.h
	proto-ext-whiterabbit/wr-servo.c
parent c86b48d6
......@@ -155,6 +155,7 @@ struct pp_instance {
/* Times, for the various offset computations */
TimeInternal t1, t2, t3, t4, t5, t6; /* *the* stamps */
Integer32 t4_cf, t6_cf; /* peer delay */
TimeInternal cField; /* transp. clocks */
TimeInternal last_rcv_time, last_snt_time; /* two temporaries */
......
......@@ -136,6 +136,8 @@ struct pp_ext_hooks {
void (*handle_announce)(struct pp_instance *ppi);
int (*handle_followup)(struct pp_instance *ppi, TimeInternal *orig,
TimeInternal *correction_field);
int (*handle_preq) (struct pp_instance * ppi);
int (*handle_presp) (struct pp_instance * ppi);
int (*pack_announce)(struct pp_instance *ppi);
void (*unpack_announce)(void *buf, MsgAnnounce *ann);
};
......
......@@ -156,7 +156,7 @@ struct wr_servo_state {
int32_t clock_period_ps;
/* These fields are used by servo code, across iterations */
TimeInternal t1, t2, t3, t4;
TimeInternal t1, t2, t3, t4, t5, t6;
int64_t delta_ms_prev;
int missed_iters;
......@@ -179,6 +179,13 @@ struct wr_servo_state {
TimeInternal update_time;
};
int wr_p2p_delay(struct pp_instance *ppi, struct wr_servo_state *s);
int wr_e2e_offset(struct pp_instance *ppi,
struct wr_servo_state *s, TimeInternal *ts_offset_hw);
int wr_p2p_offset(struct pp_instance *ppi,
struct wr_servo_state *s, TimeInternal *ts_offset_hw);
/* All data used as extension ppsi-wr must be put here */
struct wr_data {
struct wr_servo_state servo_state;
......
......@@ -239,31 +239,109 @@ int wr_servo_got_delay(struct pp_instance *ppi, Integer32 cf)
struct wr_servo_state *s =
&((struct wr_data *)ppi->ext_data)->servo_state;
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
s->t3 = ppi->t3;
/* s->t3.phase = 0; */
s->t4 = ppi->t4;
s->t4.correct = 1; /* clock->delay_req_receive_time.correct; */
s->t4.phase = (int64_t) cf * 1000LL / 65536LL;
if (GLBS(ppi)->delay_mech == PP_P2P_MECH) {
s->t5 = ppi->t5;
s->t5.correct = 1;
s->t5.phase = 0;
s->t6 = ppi->t6;
s->t6.phase = (int64_t) ppi->t6_cf * 1000LL / 65536LL;
wr_p2p_delay(ppi, s);
}
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END);
return 0;
}
int wr_p2p_delay(struct pp_instance *ppi, struct wr_servo_state *s)
{
uint64_t big_delta_fix;
static int errcount;
int wr_servo_update(struct pp_instance *ppi)
if (!s->t3.correct || !s->t4.correct ||
!s->t5.correct || !s->t6.correct) {
errcount++;
if (errcount > 5) /* a 2-3 in a row are expected */
pp_error("%s: TimestampsIncorrect: %d %d %d %d\n",
__func__, s->t3.correct, s->t4.correct,
s->t5.correct, s->t6.correct);
return 0;
}
errcount = 0;
s->update_count++;
s->mu = ts_sub(ts_sub(s->t6, s->t3), ts_sub(s->t5, s->t4));
if (__PP_DIAG_ALLOW(ppi, pp_dt_servo, 1)) {
dump_timestamp(ppi, "servo:t1", s->t1);
dump_timestamp(ppi, "servo:t2", s->t2);
dump_timestamp(ppi, "servo:t3", s->t3);
dump_timestamp(ppi, "servo:t4", s->t4);
dump_timestamp(ppi, "servo:t5", s->t5);
dump_timestamp(ppi, "servo:t6", s->t6);
dump_timestamp(ppi, "->mdelay", s->mu);
}
big_delta_fix = s->delta_tx_m + s->delta_tx_s
+ s->delta_rx_m + s->delta_rx_s;
s->delta_ms =
(((int64_t) (ts_to_picos(s->mu) - big_delta_fix) *
(int64_t) s->fiber_fix_alpha) >> FIX_ALPHA_FRACBITS)
+ ((ts_to_picos(s->mu) - big_delta_fix) >> 1)
+ s->delta_tx_m + s->delta_rx_s;
return 1;
}
int wr_p2p_offset(struct pp_instance *ppi,
struct wr_servo_state *s, TimeInternal *ts_offset_hw)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
struct wr_servo_state *s =
&((struct wr_data *)ppi->ext_data)->servo_state;
TimeInternal ts_offset;
static int errcount;
if (!s->t1.correct || !s->t2.correct) {
errcount++;
if (errcount > 5) /* a 2-3 in a row are expected */
pp_error("%s: TimestampsIncorrect: %d %d \n",
__func__, s->t1.correct, s->t2.correct);
return 0;
}
errcount = 0;
got_sync = 0;
s->update_count++;
ts_offset = ts_add(ts_sub(s->t1, s->t2), picos_to_ts(s->delta_ms));
*ts_offset_hw = ts_hardwarize(ts_offset, s->clock_period_ps);
/* is it possible to calculate it in client,
* but then t1 and t2 require shmem locks */
s->offset = ts_to_picos(ts_offset);
s->tracking_enabled = tracking_enabled;
return 1;
}
int wr_e2e_offset(struct pp_instance *ppi,
struct wr_servo_state *s, TimeInternal *ts_offset_hw)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
uint64_t big_delta_fix;
uint64_t delay_ms_fix;
TimeInternal ts_offset;
static int errcount;
int remaining_offset;
int64_t picos_mu_prev = 0;
TimeInternal ts_offset, ts_offset_hw /*, ts_phase_adjust */;
if(!got_sync)
return 0;
if(!s->t1.correct || !s->t2.correct ||
!s->t3.correct || !s->t4.correct) {
......@@ -312,7 +390,7 @@ int wr_servo_update(struct pp_instance *ppi)
+ s->delta_tx_m + s->delta_rx_s;
ts_offset = ts_add(ts_sub(s->t1, s->t2), picos_to_ts(delay_ms_fix));
ts_offset_hw = ts_hardwarize(ts_offset, s->clock_period_ps);
*ts_offset_hw = ts_hardwarize(ts_offset, s->clock_period_ps);
/* is it possible to calculate it in client,
* but then t1 and t2 require shmem locks */
......@@ -322,6 +400,33 @@ int wr_servo_update(struct pp_instance *ppi)
s->delta_ms = delay_ms_fix;
return 1;
}
int wr_servo_update(struct pp_instance *ppi)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
struct wr_servo_state *s =
&((struct wr_data *)ppi->ext_data)->servo_state;
int remaining_offset;
int64_t picos_mu_prev = 0;
TimeInternal ts_offset_hw /*, ts_phase_adjust */ ;
if (!got_sync)
return 0;
/* shmem lock */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
if (GLBS(ppi)->delay_mech == PP_P2P_MECH) {
if (!wr_p2p_offset(ppi, s, &ts_offset_hw))
goto out;
} else {
if (!wr_e2e_offset(ppi, s, &ts_offset_hw))
goto out;
}
if (wrp->ops->locking_poll(ppi, 0) != WR_SPLL_READY) {
pp_diag(ppi, servo, 1, "PLL OutOfLock, should restart sync\n");
wrp->ops->enable_timing_output(ppi, 0);
......
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