Commit 45461041 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Federico Vaga

wrtd/rt: protect against timestamps far in the future & report to debug queue


NOTE
This commit has been created by `git subtree` on the Mock Turtle repository
on tag mock-turtle-2.0

This commit will not compile
parent a31de72f
...@@ -169,6 +169,8 @@ extern int wrtd_load_application(struct wrtd_node *dev, char *rt_tdc, ...@@ -169,6 +169,8 @@ extern int wrtd_load_application(struct wrtd_node *dev, char *rt_tdc,
extern int wrtd_white_rabbit_sync(struct wrtd_node *dev, extern int wrtd_white_rabbit_sync(struct wrtd_node *dev,
unsigned long timeout_s); unsigned long timeout_s);
extern int wrtd_cpu_restart(struct wrtd_node *dev); extern int wrtd_cpu_restart(struct wrtd_node *dev);
extern int wrtd_time_get(struct wrtd_node *dev, unsigned int input,
struct wr_timestamp *current_time);
/**@}*/ /**@}*/
/** /**
...@@ -254,6 +256,8 @@ extern int wrtd_in_dead_time_get(struct wrtd_node *dev, unsigned int input, ...@@ -254,6 +256,8 @@ extern int wrtd_in_dead_time_get(struct wrtd_node *dev, unsigned int input,
uint64_t *dead_time_ps); uint64_t *dead_time_ps);
extern int wrtd_in_delay_get(struct wrtd_node *dev, unsigned int input, extern int wrtd_in_delay_get(struct wrtd_node *dev, unsigned int input,
uint64_t *delay_ps); uint64_t *delay_ps);
/**@}*/ /**@}*/
/** /**
......
include Makefile.specific
OBJS := wrtd-rt-fd.o OBJS := wrtd-rt-fd.o
OBJS += ../common/loop-queue.o OBJS += ../common/loop-queue.o
OUTPUT = wrtd-rt-fd OUTPUT = wrtd-rt-fd
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#define OUT_ST_TEST_PENDING 2 #define OUT_ST_TEST_PENDING 2
#define OUT_ST_CONDITION_HIT 3 #define OUT_ST_CONDITION_HIT 3
#define OUT_TIMEOUT 10
static const uint32_t version = GIT_VERSION; static const uint32_t version = GIT_VERSION;
static uint32_t promiscuous_mode = 0; static uint32_t promiscuous_mode = 0;
...@@ -541,6 +544,14 @@ static int check_output_timeout (struct lrt_output *out) ...@@ -541,6 +544,14 @@ static int check_output_timeout (struct lrt_output *out)
tc.seconds = lr_readl(WRN_CPU_LR_REG_TAI_SEC); tc.seconds = lr_readl(WRN_CPU_LR_REG_TAI_SEC);
tc.ticks = lr_readl(WRN_CPU_LR_REG_TAI_CYCLES); tc.ticks = lr_readl(WRN_CPU_LR_REG_TAI_CYCLES);
if( out->last_programmed.seconds > tc.seconds + OUT_TIMEOUT )
{
struct lrt_pulse_queue *q = &out->queue;
struct pulse_queue_entry *pq_ent = pulse_queue_front(q);
pp_printf("Enqueued timestamp very far in the future [id %x:%x:%x]. Dropping.", pq_ent->trig.id.system, pq_ent->trig.id.source_port, pq_ent->trig.id.trigger);
pp_printf("Offending TS: %d:%d", out->last_programmed.seconds, out->last_programmed.ticks);
}
int delta = tc.seconds - out->last_programmed.seconds; int delta = tc.seconds - out->last_programmed.seconds;
delta *= 125 * 1000 * 1000; delta *= 125 * 1000 * 1000;
delta += tc.ticks - out->last_programmed.ticks; delta += tc.ticks - out->last_programmed.ticks;
...@@ -1264,6 +1275,8 @@ static inline void ctl_software_trigger (uint32_t seq, struct wrnc_msg *ibuf) ...@@ -1264,6 +1275,8 @@ static inline void ctl_software_trigger (uint32_t seq, struct wrnc_msg *ibuf)
wrtd_msg_timestamp(ibuf, &tc); wrtd_msg_timestamp(ibuf, &tc);
} }
// pp_printf("SoftwareTrig: %d %d\n", tc.seconds, tc.ticks);
struct wrnc_msg obuf = ctl_claim_out_buf(); struct wrnc_msg obuf = ctl_claim_out_buf();
uint32_t id_timestamp = WRTD_REP_TIMESTAMP; uint32_t id_timestamp = WRTD_REP_TIMESTAMP;
...@@ -1369,6 +1382,7 @@ static inline void ctl_chan_set_log_level (uint32_t seq, struct wrnc_msg *ibuf) ...@@ -1369,6 +1382,7 @@ static inline void ctl_chan_set_log_level (uint32_t seq, struct wrnc_msg *ibuf)
for (i = 0; i < FD_NUM_CHANNELS; i++) for (i = 0; i < FD_NUM_CHANNELS; i++)
promiscuous_mode |= (outputs[i].log_level & WRTD_LOG_PROMISC); promiscuous_mode |= (outputs[i].log_level & WRTD_LOG_PROMISC);
} }
/* Receives command messages and call matching command handlers */ /* Receives command messages and call matching command handlers */
static inline void do_control() static inline void do_control()
{ {
...@@ -1413,6 +1427,7 @@ static inline void do_control() ...@@ -1413,6 +1427,7 @@ static inline void do_control()
_CMD(WRTD_CMD_FD_PING, ctl_ping) _CMD(WRTD_CMD_FD_PING, ctl_ping)
_CMD(WRTD_CMD_FD_CHAN_DEAD_TIME, ctl_chan_set_dead_time) _CMD(WRTD_CMD_FD_CHAN_DEAD_TIME, ctl_chan_set_dead_time)
_CMD(WRTD_CMD_FD_VERSION, ctl_version) _CMD(WRTD_CMD_FD_VERSION, ctl_version)
default: default:
break; break;
} }
......
include Makefile.specific
OBJS := wrtd-rt-tdc.o OBJS := wrtd-rt-tdc.o
OBJS += ../common/loop-queue.o OBJS += ../common/loop-queue.o
OUTPUT = wrtd-rt-tdc OUTPUT = wrtd-rt-tdc
......
...@@ -275,11 +275,23 @@ static int wrtd_in_trigger_sw(struct wrnc_proto_header *hin, void *pin, ...@@ -275,11 +275,23 @@ static int wrtd_in_trigger_sw(struct wrnc_proto_header *hin, void *pin,
/* trigger entity ts from the host contains the delay. /* trigger entity ts from the host contains the delay.
So add to it the current time */ So add to it the current time */
struct wr_timestamp ts_orig;
ts_orig.seconds = lr_readl(WRN_CPU_LR_REG_TAI_SEC);
ts_orig.ticks = lr_readl(WRN_CPU_LR_REG_TAI_CYCLES);
ts.seconds = lr_readl(WRN_CPU_LR_REG_TAI_SEC); ts.seconds = lr_readl(WRN_CPU_LR_REG_TAI_SEC);
ts.ticks = lr_readl(WRN_CPU_LR_REG_TAI_CYCLES); ts.ticks = lr_readl(WRN_CPU_LR_REG_TAI_CYCLES);
ts.frac = 0; ts.frac = 0;
ts_add(&ent.ts, &ts); ts_add(&ent.ts, &ts);
if( ent.ts.seconds > ts_orig.seconds + 1000 )
{
pp_printf("Warning: suspiciously long software trigger delay %d tai-secs %d", (int)ent.ts.seconds, (int)ts_orig.seconds);
}
/* Send trigger */ /* Send trigger */
send_trigger(&ent); send_trigger(&ent);
......
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