From 644faa3d6ce717ec24b542405bd73972c7ccb2f5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 8 Jan 2011 20:18:04 +0000 Subject: [PATCH] realtime: add debugging output for retransmit.c --- hostside/realtime.c | 1 + hostside/retransmit.c | 73 ++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/hostside/realtime.c b/hostside/realtime.c index 0ec0479..131d377 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -336,6 +336,7 @@ void debug_count_event(const char *what) { #define DEFDFLAGS_safety ~(DBIT_safety_predictplan|DBIT_safety_predictseg) #define DEFDFLAGS_movpos ~(DBIT_movpos_eval|DBIT_movpos_changeneeded) #define DEFDFLAGS_speed ~(DBIT_speed_query) +#define DEFDFLAGS_retransmit ~(DBIT_retransmit_message) #define DEBUG_FLAGS_H_DEFINE #include "realtime+dflags.h" diff --git a/hostside/retransmit.c b/hostside/retransmit.c index 2e0d201..1c882df 100644 --- a/hostside/retransmit.c +++ b/hostside/retransmit.c @@ -54,7 +54,19 @@ static int last_relaxed_qn; static Retransmit__Time elapsed; static PerSpeedyTrans speedies[] = SPEEDIESINIT; +static void debug_hex(const Byte *d, int l) { + int i; + for (i=0; id, pi->l); + if (n) { DPRINTFA(" <="); debug_hex(n->d, n->l); } + DPRINTFA(".\n"); +} + static void retransmit_this(const PicInsn *pi) { + if (DEBUGP(retransmit,message)) debug_message(pi, 0); serial_transmit(pi); elapsed++; } @@ -75,23 +87,30 @@ void retransmit_something(void) { PerSpeedyTrans *spd; RetransmitUrgentNode *urg; RetransmitRelaxedNode *rlx; - int ix; - + int ix, DP; + + DPRINTF1(retransmit,message,"xmit "); + for (ix=0, spd=speedies; ix < SPEEDYCOUNT; ix++, spd++) { urg= spd->queue.head; - if (!urg) continue; - if (elapsed - urg->u.when > RETRANSMIT_TIME_SIGNED_MAX) continue; + if (!urg) { DPRINTF2("-"); continue; } + if (elapsed - urg->u.when > RETRANSMIT_TIME_SIGNED_MAX) + { DPRINTF2("<"); continue; } + + DPRINTF2("%*s spd%-2d", SPEEDYCOUNT-ix,"", ix); /* found one to transmit: */ DLIST2_REMOVE(spd->queue,urg,u.queue); if (++ix < SPEEDYCOUNT) { + DPRINTF2(" ->spd%-2d =%p",ix, urg); urg->u.ix= ix; urg->u.when= elapsed + spd->interval; spd++; DLIST2_APPEND(spd->queue,urg,u.queue); } else { + DPRINTF2(" ->rlx =%p", urg); urg->u.ix= -1; } retransmit_this(&urg->pi); @@ -101,52 +120,70 @@ void retransmit_something(void) { for (ix=0; ix<2; ix++) { int qn= last_relaxed_qn ^ ix ^ 1; rlx= relaxed[qn].head; - if (!rlx) continue; + if (!rlx) { DPRINTF2("%d",qn); continue; } + DPRINTF2("%-*s rlx%d =%p", 2-ix,"", qn, rlx); + DLIST2_REMOVE(relaxed[qn],rlx,rr); DLIST2_APPEND(relaxed[qn],rlx,rr); - retransmit_this(&rlx->pi); + last_relaxed_qn= qn; + retransmit_this(&rlx->pi); return; } serial_transmit(&linefill); } -static void relaxed_queue(int qn, RetransmitRelaxedNode *rn, Nmra *n) { +static void relaxed_queue(int qn, RetransmitRelaxedNode *rn, Nmra *n, + const char *debugwhat) { + int DP; if (n) { nmra_addchecksum(n); nmra_encodeforpic(n, &rn->pi); } + DPRINTF1(retransmit,queue, "%s %p", debugwhat, rn); + if (DP) debug_message(&rn->pi, n); DLIST2_PREPEND(relaxed[qn],rn,rr); } -static void relaxed_cancel(int qn, RetransmitRelaxedNode *rlx) { +static void relaxed_cancel(int qn, RetransmitRelaxedNode *rlx, + const char *debugwhat) { + if (debugwhat) DPRINTF(retransmit,queue, "%s %p\n", debugwhat, &rlx->pi); DLIST2_REMOVE(relaxed[qn],rlx,rr); } void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n) { - relaxed_queue(1,rn,n); + relaxed_queue(1,rn,n, "retransmit_relaxed_queue"); } void retransmit_relaxed_cancel(RetransmitRelaxedNode *rlx) { - relaxed_cancel(1,rlx); + relaxed_cancel(1,rlx, "retransmit_relaxed_cancel"); } -void retransmit_urgent_queue(RetransmitUrgentNode *urg, Nmra *n) { - relaxed_queue(0, &urg->u.relaxed, n); +static void urgent_queue(RetransmitUrgentNode *urg, Nmra *n, + const char *debugwhat) { + relaxed_queue(0, &urg->u.relaxed, n, debugwhat); urg->u.ix= 0; urg->u.when= elapsed; DLIST2_APPEND(speedies[0].queue,urg,u.queue); } +static void urgent_cancel(RetransmitUrgentNode *urg, + const char *debugwhat) { + if (urg->u.ix >= 0) + DLIST2_REMOVE(speedies[urg->u.ix].queue,urg,u.queue); + relaxed_cancel(0, &urg->u.relaxed, debugwhat); +} + +void retransmit_urgent_queue(RetransmitUrgentNode *urg, Nmra *n) { + urgent_queue(urg,n, "retransmit_urgent_queue"); +} void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n){ - relaxed_queue(0, &urg->u.relaxed, n); + relaxed_queue(0, &urg->u.relaxed, n, "retransmit_urgent_queue_relaxed"); urg->u.ix= -1; urg->u.when= elapsed; } void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n) { - retransmit_urgent_cancel(rn); - retransmit_urgent_queue(rn, n); + urgent_cancel(rn, 0); + urgent_queue(rn, n, "retransmit_urgent_requeue"); } void retransmit_urgent_cancel(RetransmitUrgentNode *urg) { - if (urg->u.ix >= 0) - DLIST2_REMOVE(speedies[urg->u.ix].queue,urg,u.queue); - relaxed_cancel(0, &urg->u.relaxed); + urgent_cancel(urg, "retransmit_urgent_cancel"); } -- 2.30.2