[riot-devel] Odd problems with xtimer

Michael Andersen michael at steelcode.com
Wed Feb 24 21:02:02 CET 2016


>
>
>
> Would you be willing to share this hack with us? Maybe it gives us more
> insights.
>
>
Sure! Here is what I did:

This is the "lightweight" remove
+int _xtimer_ensure_remove(xtimer_t *timer)
+{
+  int res = 0;
+  if (timer_list_head == timer) {
+      uint32_t next;
+      timer_list_head = timer->next;
+      if (timer_list_head) {
+          next = timer_list_head->target - XTIMER_OVERHEAD;
+      }
+      else {
+          next = _lltimer_mask(0xFFFFFFFF);
+      }
+      _lltimer_set(next);
+  }
+  else {
+      res = _remove_timer_from_list(&timer_list_head, timer) ||
+          _remove_timer_from_list(&overflow_list_head, timer) ||
+          _remove_timer_from_list(&long_list_head, timer);
+  }
+
+  return res;
+}

And then I call it from these two places inside the existing critical
sections:

@@ -104,6 +106,7 @@ void _xtimer_set64(xtimer_t *timer, uint32_t offset,
uint32_t long_offset)
         }

         int state = disableIRQ();
+        _xtimer_ensure_remove(timer);
         _add_timer_to_long_list(&long_list_head, timer);
         restoreIRQ(state);
         DEBUG("xtimer_set64(): added longterm timer (long_target=%" PRIu32
" target=%" PRIu32 ")\n",
@@ -179,6 +182,7 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t
target)
     }

     unsigned state = disableIRQ();
+    _xtimer_ensure_remove(timer);
     if ( !_this_high_period(target) ) {
         DEBUG("xtimer_set_absolute(): the timer doesn't fit into the
low-level timer's mask.\n");
         _add_timer_to_long_list(&long_list_head, timer);

I then ran it for a week without problems (previously it would definitely
crash within two hours). It's a bad hack though because we spend the effort
to remove the timer earlier in the call chain so I really don't want to
duplicate that work. Also, from my understanding, the timer should never
actually be there so I don't like hiding the fact that somewhere else
someone is doing something ugly.


> Cheers,
> Oleg
> --
> panic("This never returns");
>         linux-2.6.6/kernel/power/swsusp.c
>
> _______________________________________________
> devel mailing list
> devel at riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/devel/attachments/20160224/24ed03bd/attachment-0001.html>


More information about the devel mailing list