chiark / gitweb /
wip new debugging for movpos; before change type of MovPosComb
authorian <ian>
Thu, 24 Apr 2008 17:52:10 +0000 (17:52 +0000)
committerian <ian>
Thu, 24 Apr 2008 17:52:10 +0000 (17:52 +0000)
hostside/movpos.c

index 512610a81ce9b2e41ded04b2828eb2b0247622a7..32b3015bcae574214f3f985be513ce8a17ca3611 100644 (file)
@@ -50,6 +50,7 @@ typedef struct MovPosChange {      /* valid in:   filled in by and when:     */
    * proper transition.  */
 
 struct KindInfo {
+  const char *pname;
   Change *(*allocate)(int alloc_motions); /* U->A (always succeeds) */
   ErrorCode (*reserve)(Change*, Segment*, int ms); /* A->R; error: A->E */
   ErrorCode (*confirm)(Change*, Segment*, int n_motions,
@@ -73,18 +74,14 @@ static void ouposn_moving(Change *chg) {
          move->i->pname, posnpname(move, chg->actual));
 }
 
-static void motion_done(Segment *move) {
+static void motion_done(Segment *move, MovPosComb actual) {
   move->moving= 0;
   move->motion= 0;
-  move->movposcomb= r->h.actual;
+  move->movposcomb= actual;
   oprintf(UPO, "movpos %s position %s stable\n",
          move->i->pname, posnpname(move, move->movposcomb));
 }
 
-#define PRPOSN_CHG(chg)                                                        \
-  (chg)->move->i->pname,                                               \
-  (chg)->actual<0 ? "?" : (chg)->move->i->poscombs[(chg)->actual].pname
-
 /*========== points ==========*/
 
 /*
@@ -326,7 +323,7 @@ static ErrorCode point_confirm(Change *chg, Segment *move,
   int allow_failure;
   ErrorCode ec;
 
-  oprintf(DUPO("point") "confirm %s n=%d maxdelay=%d"
+  oprintf(DUPO("movpos/point") "confirm %s n=%d maxdelay=%d"
          " (res: n=%d deadline=[t+]%d)\n",
          move->i->pname, n_motions, maxdelay_ms,
          r->n_motions, r->deadline);
@@ -346,7 +343,7 @@ static ErrorCode point_confirm(Change *chg, Segment *move,
     newdeadline= pt_maxdelay_reldeadline(maxdelay_ms);
   }
   allow_failure= newdeadline < r->deadline;
-  oprintf(DUPO("point") " newdeadline=t+%d allow_failure=%d\n",
+  oprintf(DUPO("movpos/point") " newdeadline=t+%d allow_failure=%d\n",
          newdeadline, allow_failure);
   newdeadline += pt_cslot;
 
@@ -356,11 +353,11 @@ static ErrorCode point_confirm(Change *chg, Segment *move,
   PointReq *existing=
     move->moving ? (PointReq*)move->motion : 0;   /* U or C */
   if (existing) {
-    oprintf(DUPO("point")
+    oprintf(DUPO("movpos/point")
            " existing %s n=%d deadline=t+%d\n",
            existing->h.move->i->pname,
            existing->n_motions,
-           existing->deadline - pt_slot);
+           existing->deadline - pt_cslot);
     pt_dequeue(existing);                         /* U or CA */
   }
 
@@ -379,7 +376,7 @@ static ErrorCode point_confirm(Change *chg, Segment *move,
 
   /* state CA */
   ec= pt_enqueue(&pt_confirmed, r);
-  oprintf(DUPO("point") " pt_enqueue=%s\n", ecstr(ec));
+  oprintf(DUPO("movpos/point") " pt_enqueue=%s\n", ec2str(ec));
   assert(allow_failure || !ec);
 
   if (existing) {                                  /* CA */
@@ -397,7 +394,7 @@ static ErrorCode point_confirm(Change *chg, Segment *move,
    *     or  ec!=0  state C but bad                    C
    */
 
-  if (ec) return;
+  if (ec) return ec;
 
   move->moving= 1;
   move->motion= chg;
@@ -418,8 +415,6 @@ static void point_destroy(Change *chg) { /* X->XA and then free it */
 static void pt_check_action(void) {
   PicInsn piob;
 
-fixme add more oprintf DUPO from about here onwards
-
   if (!pt_confirmed.n) {
     if (sta_state == Sta_Finalising) resolve_motioncheck();
     return;
@@ -433,7 +428,7 @@ fixme add more oprintf DUPO from about here onwards
     assert(m->posn < m->i->posns);
     enco_pic_point(&piob, m->i->boob[m->posn]);
     serial_transmit(&piob);
-    oprintf(UPO, "movpos %s point %s%d\n", r->move->i->pname,
+    oprintf(UPO, "movpos %s point %s%d\n", r->h.move->i->pname,
            m->i->pname, m->posn);
     pt_cdu_charged= 0;
 
@@ -455,7 +450,7 @@ fixme add more oprintf DUPO from about here onwards
     assert(move->moving && move->motion == (Change*)r);
     pt_queue_remove_index(&pt_confirmed,0);
     pt_mark_as_allocated(r); /* now state A aka Done */
-    motion_done(move);
+    motion_done(move,r->h.actual);
     free(r);
     pt_check_action();
   }
@@ -472,7 +467,7 @@ void points_all_abandon(void) {
     PointReq *r= pt_confirmed.l[i];
     Segment *move= r->h.move;
     assert(move->motion == (Change*)r);
-    motion_done(move);
+    motion_done(move,r->h.actual);
     free(r);
   }
   pt_confirmed.n= 0;
@@ -513,9 +508,9 @@ static ErrorCode nomove_confirm(Change *chg, Segment *move, int n_motions,
 /*========== method-independent machinery ==========*/
 
 static const KindInfo methodinfos[]= {
 { nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy },
 { point_allocate,  point_reserve,  point_confirm,  point_destroy  },
 { 0 }
{ "nomove", nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy },
{ "point",  point_allocate,  point_reserve,  point_confirm,  point_destroy  },
+ { 0 }
 };
 
 static Change *mp_allocate(const KindInfo *ki, Segment *move,
@@ -530,9 +525,14 @@ static Change *mp_allocate(const KindInfo *ki, Segment *move,
 
 static int change_needed(const MovFeatInfo *feati, MovPosComb target,
                        MovPosComb startpoint) {
-  return
-    startpoint<0 ||
+  int r;
+  r= startpoint<0 ||
     (target - startpoint) / feati->weight % feati->posns;
+  oprintf(DUPO("movpos/change-needed") "%s:%s(%d*%d) %d<-%d => %d",
+         methodinfos[feati->kind].pname, feati->pname,
+         feati->posns, feati->weight,
+         target, startpoint, r);
+  return r;
 }  
 
 static int evaluate_target(Segment *move, MovPosComb target,
@@ -544,7 +544,14 @@ static int evaluate_target(Segment *move, MovPosComb target,
   const MovFeatInfo *feati;
   MovFeatKind kind;
 
-  if (startpoint<0) startpoint= movpos_poscomb_actual(move);
+  oprintf(DUPO("movpos/eval") "%s/%s <-%s\n",
+         move->i->pname, posnpname(move,target), posnpname(move,startpoint));
+
+  if (startpoint<0) {
+    startpoint= movpos_poscomb_actual(move);
+    oprintf(DUPO("movpos/eval") "  actual <-%s\n",
+           posnpname(move,startpoint));
+  }
 
   for (feat=0, feati=movei->movfeats, tchanges=0, kind= mfk_none;
        feat<movei->n_movfeats;
@@ -556,6 +563,8 @@ static int evaluate_target(Segment *move, MovPosComb target,
   }
 
   if (kind_r) *kind_r= kind;
+  oprintf(DUPO("movpos/eval") "changes=%d kind=%s\n",
+         tchanges, methodinfos[kind].pname);
   return tchanges;
 }
 
@@ -575,7 +584,6 @@ ErrorCode movpos_findcomb_bysegs(Segment *back, Segment *move, Segment *fwd,
     if (fwd  && !(fwd ==tback || fwd ==tfwd)) continue;
 
     if (movei->n_movfeats>1) {
-      //fprintf(stderr,"  several feats\n");
       /* we have to search for the one which is least effort, then */
       tchanges= evaluate_target(move,tcomb,startpoint,0);
       if (tchanges >= bestchanges) /* prefer low-numbered movposcombs */
@@ -614,21 +622,23 @@ ErrorCode movpos_change(Segment *move, MovPosComb target,
     actual= move->motion->actual;
   }
 
-  {
+  oprintf(DUPO("movpos/change") "%s/%s maxdelay_ms=%d actual=%s\n",
+         move->i->pname, posnpname(move,target),
+         maxdelay_ms, prposn(move, actual));
+  if (chg) oprintf(DUPO("movpos/change") " chg=%s:%s/%s\n",
+                  chg->ki->pname, chg->move->i->pname,
+                  posnpname(chg->move, chg->move->intent));
+
+  { /* provide horizon for visibility of motions[] */
     int n_motions=0;
     Motion motions[movei->n_movfeats];
 
-fixme make these debug
-fprintf(stderr," motions...  best=%lu actual=%ld\n",target,actual);
     for (feat=0, feati=movei->movfeats;
         feat<movei->n_movfeats;
         feat++, feati++) {
-fprintf(stderr,"  checking %s w=%lu posns=%d\n",
-       feati->pname,feati->weight,(int)feati->posns);
       if (!change_needed(feati,actual,target))
        continue;
       MovPosComb posn= target / feati->weight % feati->posns;
-fprintf(stderr,"    motion %s %lu kind=%d\n",feati->pname,posn,kind);
       if (kind) {
        if (feati->kind != kind) { ec= EC_MovFeatKindsCombination; goto x; }
       } else {
@@ -651,9 +661,9 @@ fprintf(stderr,"    motion %s %lu kind=%d\n",feati->pname,posn,kind);
     }
     chg->actual= actual;
 
-fprintf(stderr," confirming %d motions...\n",n_motions);
+    oprintf(DUPO("movpos/change") "confirm %s:%d...\n", ki->pname, n_motions);
     ec= ki->confirm(chg, move, n_motions, motions, maxdelay_ms);
-fprintf(stderr," confirming gave %s\n",errorcodelist[ec]);
+    oprintf(DUPO("movpos/change") "confirm => %s\n",errorcodelist[ec]);
     if (ec) goto x;
   }
   return 0;
@@ -670,12 +680,18 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r,
   ErrorCode ec;
   int nchanges;
 
+  oprintf(DUPO("movpos/reserve") "%s/%s maxdelay_ms=%d startpoint=%s\n",
+         move->i->pname, posnpname(move,target),
+         maxdelay_ms, prposn(move, startpoint));
+
   nchanges= evaluate_target(move,target,startpoint,&kind);
   if (nchanges==-1) return EC_MovFeatKindsCombination;
 
   const KindInfo *ki= &methodinfos[kind];
-  Change *chg= mp_allocate(ki, move, move->i->n_movfeats, target);
+  oprintf(DUPO("movpos/reserve") "allocate %s:%d...\n", ki->pname, nchanges);
+  Change *chg= mp_allocate(ki, move, nchanges, target);
   ec= ki->reserve(chg, move, maxdelay_ms);
+  oprintf(DUPO("movpos/reserve") "reserve => %s\n",errorcodelist[ec]);
   if (ec) goto x;
 
   *res_r= chg;
@@ -688,6 +704,9 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r,
 
 void movpos_unreserve(MovPosChange *res) {
   if (!res) return;
+  oprintf(DUPO("movpos/unreserve") "%s:%s/%s\n",
+         res->ki->pname, res->move->i->pname,
+         posnpname(chg->move, chg->move->intent));
   res->ki->destroy(res);
 }