Re: Stack size calculation - tool support?
- From: "robertwessel2@xxxxxxxxx" <robertwessel2@xxxxxxxxx>
- Date: Mon, 16 Nov 2009 20:11:13 -0800 (PST)
On Nov 16, 6:23 pm, Tim Wescott <t...@xxxxxxxxxxxxxxxx> wrote:
On Mon, 16 Nov 2009 16:37:47 -0600, Vladimir Vassilevsky wrote:
Gerd wrote:
I need to allocate the stack for my system with a proper size. I don't
want do a vage estimation, so I would like to know: Is there a tool
that scans C source code, and calculates the required tack size, based
on the call graph? Only plain C, no recursion.
It is impossible to estimate stack depth from the source code only.
Proof? Reference to proof?
Absent recursion this should be a pretty direct calculation, if
exceedingly tedious. With recursion the answer is easy: "go back to
school where you belong, buddy".
Granted, an RTOS makes life difficult, but even there the stack usage of
any one task should be as easy (or impossible) to calculate as for a
traditional single thread of execution.
Assuming no function pointers, you can compute a maximum based on the
call tree simply enough, but that may be a substantial overestimate
based on what sequences of calls are actually possible. Consider:
void a() {... c(0); ...}
void b() {... c(1); ...}
void c(int p)
{
....
if (p)
d();
else
e();
....
}
void d() {...}
void e() {...}
Assume that a() and d() have large stack allocations, the
straightforward analysis will determine that a()->c()->d() results in
the worst case stack usage, when that's not actually possible because
of the control coupled call to d() or e() from c().
Also, function pointers make the analysis much harder. Even if you
assume that no recursion will occur, the straight-forward approach
requires you to assume that you can call *any* routine that has its
address taken from *any* use of a function pointer to execute a call,
which will again likely result in a substantial overestimate.
Of course having a maximum is often a nice place to start.
.
- Follow-Ups:
- Re: Stack size calculation - tool support?
- From: Vladimir Vassilevsky
- Re: Stack size calculation - tool support?
- References:
- Stack size calculation - tool support?
- From: Gerd
- Re: Stack size calculation - tool support?
- From: Vladimir Vassilevsky
- Re: Stack size calculation - tool support?
- From: Tim Wescott
- Stack size calculation - tool support?
- Prev by Date: Re: Bootloading from SD card
- Next by Date: Re: Stack size calculation - tool support?
- Previous by thread: Re: Stack size calculation - tool support?
- Next by thread: Re: Stack size calculation - tool support?
- Index(es):
Relevant Pages
|