cubesatlab / cubedos

A flight software framework in SPARK/Ada

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sort CubedOS mailboxes by message priority

pchapin opened this issue · comments

We should keep the CubedOS Mailboxes sorted by message priority so that the highest priority message is the first to be taken from the mailbox. Using Insertion_Sort will allow us to insert a new item into an already sorted mailbox in O(N) time. We might want to consider going to a binary heap structure at some point to get O(log(N)) time insertion and removal, but that might be unnecessarily complicated for our current needs.

Currently the mailboxes are circular buffers. However, to apply Insertion_Sort (or any simple sorting procedure), we'll need to make them simple arrays. The effect of that would be to force either one of (Send, Receive) to be O(N) time. Note that Insertion_Sort is already O(N) so perhaps that is not a big deal. Before moving forward with this, though, we might want to be sure we really need to support sorting mailboxes by message priority. If we do, taking the time to implement a priority queue using a heap might be worth it. If we don't, ignoring the whole issue might be the most appropriate choice.

Would merging the priorities branch in its current state be enough to close this issue?

The priorities branch can't really be merged, unfortunately, because using dynamic priorities causes the system to not compile. Specifically, dynamic priorities are incompatible with the Ravenscar (or Jorvik) profiles that SPARK requires. I had originally thought we could include a justification to satisfy SPARK, but the problem is that the compiler rejects the dynamic priorities and refuses to generate an executable. It's not really a SPARK issue, at least not directly. I see no way around this right now.

We could still sort mailboxes by priority, but without dynamic priorities there is no priority inheritance, and I'm not sure just sorting the mailboxes is worth the trouble. It might be. I'll leave this open for now for future discussion.