Commit a438acc9 authored by Alessandro Rubini's avatar Alessandro Rubini

general fix: implement SYNCHRONIZATION_FAULT

If we stopped sending to the master or the peer (for traffic or
whatever; in my case with "fault drop"), we wouldn't notice the
problem.

This looks like SYNCHRONIZATION_FAULT (9.2.6.12), so this reuses the
almost-unused TO_FAULTY, renaming it to a more generic TO_FAULT.

9.2.6.12 says we should reach uncalibrated, but since uncalibrated doesn't
exits (it is never entered, it's dead and untested code at this point),
I handle the problem just like the timeout receiving announce messages.

For wr, I reset the servo, so the problem can be seen.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 0bdf155f
......@@ -51,7 +51,7 @@ enum pp_timeouts {
PP_TO_SYNC_SEND,
PP_TO_ANN_RECEIPT,
PP_TO_ANN_SEND,
PP_TO_FAULTY,
PP_TO_FAULT,
PP_TO_QUALIFICATION,
/* Two timeouts for the protocol extension */
PP_TO_EXT_0,
......
......@@ -167,9 +167,13 @@ static void wr_s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
static int wr_execute_slave(struct pp_instance *ppi)
{
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if (pp_timeout(ppi, PP_TO_FAULT))
wr_servo_reset(ppi); /* the caller handles ptp state machine */
/* The doRestart thing is not used, it seems */
if (!WR_DSPOR(ppi)->doRestart)
return 0;
ppi->next_state = PPS_INITIALIZING;
WR_DSPOR(ppi)->doRestart = FALSE;
return 1; /* the caller returns too */
......
......@@ -83,7 +83,12 @@ int st_com_execute_slave(struct pp_instance *ppi)
if (ret < 0)
return ret;
if (pp_timeout(ppi, PP_TO_ANN_RECEIPT)) {
if (pp_timeout(ppi, PP_TO_ANN_RECEIPT)
|| pp_timeout(ppi, PP_TO_FAULT)) {
/*
* Note: TO_FAULTY == SYNCHRONIZATION_FAULT
* should move us to UNCALIBRATED (not implemented)
*/
ppi->frgn_rec_num = 0;
if (DSDEF(ppi)->clockQuality.clockClass != PP_CLASS_SLAVE_ONLY
&& (ppi->role != PPSI_ROLE_SLAVE)) {
......@@ -164,6 +169,7 @@ int st_com_peer_handle_pres(struct pp_instance *ppi, unsigned char *buf,
}
if (!(hdr->flagField[0] & PP_TWO_STEP_FLAG)) {
pp_timeout_set(ppi, PP_TO_FAULT);
if (pp_hooks.handle_presp)
e = pp_hooks.handle_presp(ppi);
else
......@@ -198,6 +204,7 @@ int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
ppi->t5 = respFllw.responseOriginTimestamp;
pp_time_add(&ppi->t5, &hdr->cField);
pp_timeout_set(ppi, PP_TO_FAULT);
if (pp_hooks.handle_presp)
e = pp_hooks.handle_presp(ppi);
else
......
......@@ -38,6 +38,7 @@ void pp_servo_init(struct pp_instance *ppi)
SRV(ppi)->obs_drift = 0;
}
pp_timeout_set(ppi, PP_TO_FAULT);
pp_diag(ppi, servo, 1, "Initialized: obs_drift %lli\n",
SRV(ppi)->obs_drift);
}
......
......@@ -9,16 +9,16 @@
#include <ppsi/ppsi.h>
/*
* Fault troubleshooting. Now only prints an error messages and comes back to
* PTP_INITIALIZING state after a 4-seconds grace period
* Fault troubleshooting. Now only comes back to
* PTP_INITIALIZING state after a grace period.
*/
int pp_faulty(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
if (pp_timeout(ppi, PP_TO_FAULTY)) {
if (pp_timeout(ppi, PP_TO_FAULT)) {
ppi->next_state = PPS_INITIALIZING;
return 0;
}
ppi->next_delay = pp_next_delay_1(ppi, PP_TO_FAULTY);
ppi->next_delay = pp_next_delay_1(ppi, PP_TO_FAULT);
return 0;
}
......@@ -13,6 +13,7 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
pp_timeout_set(ppi, PP_TO_FAULT); /* no fault as long as we listen */
if (pp_hooks.listening)
e = pp_hooks.listening(ppi, pkt, plen);
if (e)
......
......@@ -55,6 +55,7 @@ static int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
pp_time_add(&ppi->t4, &hdr->cField);
/* WARNING: should be "sub" (see README-cfield::BUG) */
pp_timeout_set(ppi, PP_TO_FAULT);
if (pp_hooks.handle_resp)
e = pp_hooks.handle_resp(ppi);
else
......
......@@ -24,7 +24,7 @@ static struct timeout_config to_configs[__PP_TO_ARRAY_SIZE] = {
[PP_TO_SYNC_SEND] = {"SYNC_SEND", RAND_70_130,},
[PP_TO_ANN_RECEIPT] = {"ANN_RECEIPT", RAND_NONE,},
[PP_TO_ANN_SEND] = {"ANN_SEND", RAND_70_130,},
[PP_TO_FAULTY] = {"FAULTY", RAND_NONE, 4000},
[PP_TO_FAULT] = {"FAULT", RAND_NONE, 4000},
[PP_TO_QUALIFICATION] = {"QUAL", RAND_NONE,}
/* extension timeouts are explicitly set to a value */
};
......@@ -36,8 +36,10 @@ void pp_timeout_init(struct pp_instance *ppi)
to_configs[PP_TO_REQUEST].value =
port->logMinDelayReqInterval;
to_configs[PP_TO_SYNC_SEND].value =
port->logSyncInterval;
/* fault timeout is 4 avg request intervals, not randomized */
to_configs[PP_TO_FAULT].value =
1 << (port->logMinDelayReqInterval + 12); /* 0 -> 4096ms */
to_configs[PP_TO_SYNC_SEND].value = port->logSyncInterval;
to_configs[PP_TO_ANN_RECEIPT].value = 1000 * (
port->announceReceiptTimeout << port->logAnnounceInterval);
to_configs[PP_TO_ANN_SEND].value = port->logAnnounceInterval;
......
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