by hackits · 10y ago · 0 comments
They must use pre-allocated string buffers for some of the task's. Though I figured if you're doing a flight controller for a jet fighter or sate-light you don't need a lot of string parsing.
Everything should be static and deterministic at all times. This is the easiest/only way to ensure you have no resource issues.
You should always (statically) allocate for maximum/worst case.. because you have analysed your worst-case, haven't you?
Another analogy: I would rather have a program with a 100% chance of hitting a bug under a well understood circumstance rather than a program with a 0.00001% chance of hitting a bug under an unpredictable/unknown circumstance.
In an embedded environment, you have complete control over the system and all aspects of it (or at least you should).
You often need to understand the behavior of your system under all circumstances, and that becomes _much_ easier to do when you operate with fixed size data structures because you now know exactly when you will run out of memory.
Consider a hypothetical embedded system where you’re creating a sub-module which must handle external events by means of a message queue. If you know that you can only have three possible events, you can statically allocate your message queue to be 3 deep to ensure that you will never drop an event. If you were to use dynamic memory allocation, you can’t make that guarantee because you don’t know what the other components of the system are doing (and how much memory they’re allocating). Even if there are no other allocations taking place, you still can’t guarantee that yours will succeed due to the possibility of fragmentation.
Statically allocating your buffers ensures that if the program can be loaded in the first place, you can predict with 100% certainty your program will be able to handle those 3 events.
Embedded systems typically are not 'manned', they have to handle all issues themselves and continue providing service. Note that this does not mean "no resets".
Resets should be designed for because they will happen.
All effort should be made to make errors deterministic as (like you say) they will become a real time-suck.
IMO, servers should also be considered embedded systems and designed like this, but unfortunately the culture around server software is for very dynamic, very resource heavy and very inefficient, non-deterministic s/w.
i.e. "You shall handle x messages in y milliseconds."
from that, you derive your worst case buffer size given that you can service that buffer every 'z' milliseconds at most (Note, that involves a hard-real-time requirement as it is a bounded maximum time).
As for the stack usage requirements, it seems like this could be determined statically by some parametric process, but I’m no expert on this.
Does anyone see a reason why there couldn’t be some algorithm to statically analyze some code to derive the worst case stack usage?
For example, take every function and assume that every variable declaration will be required. Add them up. Then, follow every path down the call tree while adding up the required stack for each call.
(tho that takes a bit of analysis, there are tools around that can automate this).
I imagine unmanned space software is similar; there is little need for a text UI on the spacecraft itself.
(Seriously? downvoted because I gave a direct, true answer to a question?)