chiark / gitweb /
realtime: add debugging output for retransmit.c
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 Jan 2011 20:18:04 +0000 (20:18 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 Jan 2011 20:18:04 +0000 (20:18 +0000)
hostside/realtime.c
hostside/retransmit.c

index 0ec047991e77570858bb9f52fb8c8c3bde707990..131d377a6386118a6e35f86dafc32216dd04c2ec 100644 (file)
@@ -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"
index 2e0d20166df43fe15ee88dfca6fbbf64f2b8e014..1c882dfb7874c8e7e40f8f5941ee16b71b74efb3 100644 (file)
@@ -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; i<l; i++) DPRINTFA(" %02x", d[i]);
+}
+
+static void debug_message(const PicInsn *pi, const Nmra *n) {
+  DPRINTFA(" :"); debug_hex(pi->d, 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");
 }