Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #30744 > unrolled thread
| Started by | pozz <pozzugno@gmail.com> |
|---|---|
| First post | 2021-07-29 18:22 +0200 |
| Last post | 2021-08-05 04:59 -0700 |
| Articles | 20 on this page of 43 — 5 participants |
Back to article view | Back to comp.arch.embedded
Stack analysis tool that really work? pozz <pozzugno@gmail.com> - 2021-07-29 18:22 +0200
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-07-29 19:36 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-02 17:56 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-03 11:43 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-03 02:28 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-04 22:14 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-04 15:43 -0700
Re: Stack analysis tool that really work? pozz <pozzugno@gmail.com> - 2021-08-03 11:49 +0200
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-03 20:17 -0700
Re: Stack analysis tool that really work? pozz <pozzugno@gmail.com> - 2021-08-04 16:43 +0200
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-04 11:06 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-05 12:00 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-05 04:54 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-04 20:00 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-04 10:50 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-04 21:50 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-04 15:46 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-05 13:43 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-05 06:16 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-05 18:39 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-06 01:09 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-06 22:58 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-06 16:04 -0700
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-06 16:06 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 14:20 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-07 10:26 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 20:46 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-07 15:14 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 14:09 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-07 08:09 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 19:50 +0300
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 20:02 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-07 10:34 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 21:10 +0300
Re: Stack analysis tool that really work? George Neuner <gneuner2@comcast.net> - 2021-08-06 22:55 -0400
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-07 13:40 +0300
Re: Stack analysis tool that really work? George Neuner <gneuner2@comcast.net> - 2021-08-08 18:34 -0400
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-09 10:50 +0300
Re: Stack analysis tool that really work? Paul Rubin <no.email@nospam.invalid> - 2021-08-09 11:26 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-09 22:59 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-09 12:04 -0700
Re: Stack analysis tool that really work? Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-08-05 13:18 +0300
Re: Stack analysis tool that really work? Don Y <blockedofcourse@foo.invalid> - 2021-08-05 04:59 -0700
Page 1 of 3 [1] 2 3 Next page →
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2021-07-29 18:22 +0200 |
| Subject | Stack analysis tool that really work? |
| Message-ID | <sdukj9$8tu$1@dont-email.me> |
arm gcc and Cortex-Mx MCUs embedded systems. Is there a compilation-time (static) tool for stack analysis that really works? The best I could find is -fstack-usage and avstack.pl Perl script, but I guess there's another and better way.
[toc] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-07-29 19:36 +0300 |
| Message-ID | <img3p7Flnb9U1@mid.individual.net> |
| In reply to | #30744 |
On 2021-07-29 19:22, pozz wrote: > arm gcc and Cortex-Mx MCUs embedded systems. > > Is there a compilation-time (static) tool for stack analysis that really > works? > > The best I could find is -fstack-usage and avstack.pl Perl script, but I > guess there's another and better way. If you can pay, there is https://www.absint.com/stackanalyzer/index.htm. I haven't used it, but I have used other tools from AbsInt (WCET-analysis tools) which worked well, and (I believe) perform stack analysis internally, so I guess the simpler stack-analysis tool also works. There is also https://www.adacore.com/gnatpro/toolsuite/gnatstack, which I have used successfully. I used it for an Ada application, but it should also work for C and C++. Unfortunately I don't know of any free tools for your target.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-02 17:56 -0700 |
| Message-ID | <sea47k$j3s$1@dont-email.me> |
| In reply to | #30744 |
On 7/29/2021 9:22 AM, pozz wrote: > arm gcc and Cortex-Mx MCUs embedded systems. > > Is there a compilation-time (static) tool for stack analysis that really works? What do you mean by "really works"? It's a (potentially) unbounded problem as the compiler can't know what the inputs will drive the code to do, in practice. Your best practical option is to tease a callgraph (tree) out and use your own knowledge of what the code WANTS to do to identify the worst-case stack penetration path. This is also a great way to get a feel for if your code might benefit from a good refactoring! > The best I could find is -fstack-usage and avstack.pl Perl script, but I guess > there's another and better way. There are general tools that you can probably instrument to coax a number out of the source (if you don't have access to the source, you're typically SoL) but they will be expensive in time or money.
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-03 11:43 +0300 |
| Message-ID | <imsdtvF7jafU1@mid.individual.net> |
| In reply to | #30746 |
On 2021-08-03 3:56, Don Y wrote: > On 7/29/2021 9:22 AM, pozz wrote: >> arm gcc and Cortex-Mx MCUs embedded systems. >> >> Is there a compilation-time (static) tool for stack analysis that >> really works? > > What do you mean by "really works"? It's a (potentially) unbounded problem > as the compiler can't know what the inputs will drive the code to do, in > practice. There are practical static-analysis methods to compute an upper bound on the stack usage that work well for many embedded programs. An upper bound is usually all one needs. The exact worst case is less interesting. Some problems arise for programs that branch to dynamically computed addresses, for example by calling functions via function pointers. Static analyses may not be able to find the set of possible target addresses. When that happens you have to guide the analysis by specifying where such control transfers can end up. For typical embedded code that is not hard to do, but a program that relies extensively on virtual function calls may be hard to analyze. > There are general tools that you can probably instrument to coax a > number out of the source (if you don't have access to the source, you're > typically SoL) but they will be expensive in time or money. The exact stack usage of a subprogram can't be derived from source code without knowing what machine code the compiler and linker will produce. The static stack-analysis tools typically work on the final executable code (which also means that they can be independent of the programming language). But (as I said in an earlier post) the tools I am aware of, for the OP's target, are not free.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-03 02:28 -0700 |
| Message-ID | <seb289$ol0$1@dont-email.me> |
| In reply to | #30747 |
On 8/3/2021 1:43 AM, Niklas Holsti wrote: > On 2021-08-03 3:56, Don Y wrote: >> On 7/29/2021 9:22 AM, pozz wrote: >>> arm gcc and Cortex-Mx MCUs embedded systems. >>> >>> Is there a compilation-time (static) tool for stack analysis that really works? >> >> What do you mean by "really works"? It's a (potentially) unbounded problem >> as the compiler can't know what the inputs will drive the code to do, in >> practice. > > There are practical static-analysis methods to compute an upper bound on the > stack usage that work well for many embedded programs. An upper bound is > usually all one needs. The exact worst case is less interesting. That depends on the actual algorithm being implemented, the style of the developer and, often, the inputs provided. For example, I often use recursive algorithms for pattern matching (because they are easier to "get right"). Looking at the algorithm, you can't know how deep the recursion will be -- without seeing the input it will be fed. I, OTOH, have intimate knowledge of that input (or, at least *one* half of the comparison) and can ensure the recursion 1) stops and 2) stops at a predictable depth (based on that one half of the comparison). The same for "layered" UI's -- the structure of the user interface is encoded elsewhere; the code that implements it is driven by those structures (which can change -- or be changed -- at runtime). Any analysis (even by human beings) won't provide those figures -- without having a peek at the inputs. > Some problems arise for programs that branch to dynamically computed addresses, > for example by calling functions via function pointers. Static analyses may not > be able to find the set of possible target addresses. When that happens you > have to guide the analysis by specifying where such control transfers can end > up. For typical embedded code that is not hard to do, but a program that relies > extensively on virtual function calls may be hard to analyze. The same is true of a program that is driven by external events. The code doesn't (typically) "know" the constraints placed on those events. (one can argue as to whether or not this is "good practice") So, it can't "find the end". >> There are general tools that you can probably instrument to coax a >> number out of the source (if you don't have access to the source, you're >> typically SoL) but they will be expensive in time or money. > > The exact stack usage of a subprogram can't be derived from source code without > knowing what machine code the compiler and linker will produce. The static > stack-analysis tools typically work on the final executable code (which also > means that they can be independent of the programming language). If you don't have the sources, you can't *do* anything with the results of the analysis -- other than define a minimum stack size (which may be a surprise to you *and* your hardware!) If you don't have the sources, you likely haven't a clue as to how the code behaves, under the complete set of I/O conditions. > But (as I said in an earlier post) the tools I am aware of, for the OP's > target, are not free. You can possibly instrument some DSE-like tools. But, I would imagine the execution time of the tool would be prohibitively long -- for all but trivial codebases. [I should try that when I have some time!] How efficient are those you've used? Do they operate in "near compile time"? Or, something considerably longer (slower)? I.e., are they practical to use iteratively? On an entire application?
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-04 22:14 +0300 |
| Message-ID | <in078sF1a5uU1@mid.individual.net> |
| In reply to | #30748 |
On 2021-08-03 12:28, Don Y wrote: > On 8/3/2021 1:43 AM, Niklas Holsti wrote: >> On 2021-08-03 3:56, Don Y wrote: >>> On 7/29/2021 9:22 AM, pozz wrote: >>>> arm gcc and Cortex-Mx MCUs embedded systems. >>>> >>>> Is there a compilation-time (static) tool for stack analysis that >>>> really works? >>> >>> What do you mean by "really works"? It's a (potentially) unbounded >>> problem >>> as the compiler can't know what the inputs will drive the code to do, in >>> practice. >> >> There are practical static-analysis methods to compute an upper bound >> on the stack usage that work well for many embedded programs. An upper >> bound is usually all one needs. The exact worst case is less interesting. > > That depends on the actual algorithm being implemented, the style of the > developer and, often, the inputs provided. > > For example, I often use recursive algorithms for pattern matching (because > they are easier to "get right"). Looking at the algorithm, you can't know > how deep the recursion will be -- without seeing the input it will be fed. Well, most embedded programmers avoid recursion. And if you implement recursion in a memory-constrained system, your design and code should set a hard limit on the recursion depth and reject input that would require deeper recursion. Some (admittedly complex) static analyses can discover such limits from the machine code, in the same way as they discover loop iteration limits for WCET analysis. (In fact, I believe that the AbsInt tools translate loops into recursions before the analysis.) >> Some problems arise for programs that branch to dynamically computed >> addresses, for example by calling functions via function pointers. >> Static analyses may not be able to find the set of possible target >> addresses. When that happens you have to guide the analysis by >> specifying where such control transfers can end up. For typical >> embedded code that is not hard to do, but a program that relies >> extensively on virtual function calls may be hard to analyze. > > The same is true of a program that is driven by external events. > The code doesn't (typically) "know" the constraints placed on those > events. (one can argue as to whether or not this is "good practice") > So, it can't "find the end". Again, if some sequences of external events might use an unbounded amount of stack, the design and code should set a hard limit. I have not encountered such programs. The typical design is to allow some fixed maximum nesting of event processing (eg. a finite set of interrupt priority levels) and otherwise enqueue the events for sequential processing, which does not require an unbounded stack. >>> There are general tools that you can probably instrument to coax a >>> number out of the source (if you don't have access to the source, you're >>> typically SoL) but they will be expensive in time or money. >> >> The exact stack usage of a subprogram can't be derived from source >> code without knowing what machine code the compiler and linker will >> produce. The static stack-analysis tools typically work on the final >> executable code (which also means that they can be independent of the >> programming language). > > If you don't have the sources, you can't *do* anything with the results > of the analysis -- other than define a minimum stack size (which may > be a surprise to you *and* your hardware!) If the program is single-threaded, the allocated stack size is usually set in the linker command file. Sure, you need the source for that file if you want to change the stack size. Of course you are screwed if your machine does not have enough memory for the size of stack you want. > If you don't have the sources, you likely haven't a clue as to how > the code behaves, under the complete set of I/O conditions. I've analyzed the stack usage (upper bounds) of many libraries without access to source code. Typically embedded libraries have call-graphs that can be extracted from the machine code without assumptions about the I/O or other run-time values. But that may no longer be the case for libraries written in C++ or other languages with run-time binding of calls. I agree that for complete programs one sometimes needs more insight, in particular if there are calls through function pointers or local variables with dynamic (data-dependent) size. >> But (as I said in an earlier post) the tools I am aware of, for the >> OP's target, are not free. > > You can possibly instrument some DSE-like tools. Sorry, what is a "DSE-like" tool? DSE = ? > How efficient are those you've used? Do they operate in "near compile > time"? For stack-usage analysis the tools are quite fast, typically, because embedded programs tend not to allocate dynamically-sized local variables. The main time is spent in reading the executable and decoding the instructions. For programs that allocate local variables of dynamic size the analysis becomes much more complex, can need lots of time and memory, and can often fail. > I.e., are they practical to use iteratively? On an entire > application? Yes, for many applications. And if you are implementing a safety-critical system, you design your application to be analysable.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-04 15:43 -0700 |
| Message-ID | <sef565$4u7$1@dont-email.me> |
| In reply to | #30756 |
On 8/4/2021 12:14 PM, Niklas Holsti wrote: > On 2021-08-03 12:28, Don Y wrote: >> On 8/3/2021 1:43 AM, Niklas Holsti wrote: >>> On 2021-08-03 3:56, Don Y wrote: >>>> On 7/29/2021 9:22 AM, pozz wrote: >>>>> arm gcc and Cortex-Mx MCUs embedded systems. >>>>> >>>>> Is there a compilation-time (static) tool for stack analysis that really >>>>> works? >>>> >>>> What do you mean by "really works"? It's a (potentially) unbounded problem >>>> as the compiler can't know what the inputs will drive the code to do, in >>>> practice. >>> >>> There are practical static-analysis methods to compute an upper bound on the >>> stack usage that work well for many embedded programs. An upper bound is >>> usually all one needs. The exact worst case is less interesting. >> >> That depends on the actual algorithm being implemented, the style of the >> developer and, often, the inputs provided. >> >> For example, I often use recursive algorithms for pattern matching (because >> they are easier to "get right"). Looking at the algorithm, you can't know >> how deep the recursion will be -- without seeing the input it will be fed. > > Well, most embedded programmers avoid recursion. And if you implement recursion > in a memory-constrained system, your design and code should set a hard limit on > the recursion depth and reject input that would require deeper recursion. Yes, but you don't need that limit to be enforced by a "depth counter". Instead, it can be encoded in the data that *drives* the recursion. A *human* understands that there is a limit (and exactly what that limit is, for any dataset). But, an algorithm may be taxed with trying to determine this. I shouldn't have to adopt a coding style just for the sake of a tool. > Some (admittedly complex) static analyses can discover such limits from the > machine code, in the same way as they discover loop iteration limits for WCET > analysis. (In fact, I believe that the AbsInt tools translate loops into > recursions before the analysis.) > >>> Some problems arise for programs that branch to dynamically computed >>> addresses, for example by calling functions via function pointers. Static >>> analyses may not be able to find the set of possible target addresses. When >>> that happens you have to guide the analysis by specifying where such control >>> transfers can end up. For typical embedded code that is not hard to do, but >>> a program that relies extensively on virtual function calls may be hard to >>> analyze. >> >> The same is true of a program that is driven by external events. >> The code doesn't (typically) "know" the constraints placed on those >> events. (one can argue as to whether or not this is "good practice") >> So, it can't "find the end". > > Again, if some sequences of external events might use an unbounded amount of > stack, the design and code should set a hard limit. I have not encountered such > programs. > > The typical design is to allow some fixed maximum nesting of event processing > (eg. a finite set of interrupt priority levels) and otherwise enqueue the > events for sequential processing, which does not require an unbounded stack. Events need not be interrupts. They may be user actions/keystrokes. But, the "grammar" (odd choice of words) that defines the range of permissible actions can limit how deeply the "generic" algorithm recurses. Again, something that a human can see and verify but that could evade anything sort of a sophisticated analysis of code+data. >>>> There are general tools that you can probably instrument to coax a >>>> number out of the source (if you don't have access to the source, you're >>>> typically SoL) but they will be expensive in time or money. >>> >>> The exact stack usage of a subprogram can't be derived from source code >>> without knowing what machine code the compiler and linker will produce. The >>> static stack-analysis tools typically work on the final executable code >>> (which also means that they can be independent of the programming language). >> >> If you don't have the sources, you can't *do* anything with the results >> of the analysis -- other than define a minimum stack size (which may >> be a surprise to you *and* your hardware!) > > If the program is single-threaded, the allocated stack size is usually set in > the linker command file. Sure, you need the source for that file if you want to > change the stack size. Of course you are screwed if your machine does not have > enough memory for the size of stack you want. But you can't *change* your algorithm, having discovered that it uses more stack than you had anticipated (or, that other consumers have left available for its use). Without the sources, your only option is to change the hardware to make more stack available. [And, even that may not be possible; e.g., multithreaded in a single address space] >> If you don't have the sources, you likely haven't a clue as to how >> the code behaves, under the complete set of I/O conditions. > > I've analyzed the stack usage (upper bounds) of many libraries without access > to source code. Typically embedded libraries have call-graphs that can be > extracted from the machine code without assumptions about the I/O or other > run-time values. But that may no longer be the case for libraries written in > C++ or other languages with run-time binding of calls. > > I agree that for complete programs one sometimes needs more insight, in > particular if there are calls through function pointers or local variables with > dynamic (data-dependent) size. > >>> But (as I said in an earlier post) the tools I am aware of, for the OP's >>> target, are not free. >> >> You can possibly instrument some DSE-like tools. > > Sorry, what is a "DSE-like" tool? DSE = ? Dynamic Symbolic Execution. >> How efficient are those you've used? Do they operate in "near compile time"? > > For stack-usage analysis the tools are quite fast, typically, because embedded > programs tend not to allocate dynamically-sized local variables. The main time > is spent in reading the executable and decoding the instructions. > > For programs that allocate local variables of dynamic size the analysis becomes > much more complex, can need lots of time and memory, and can often fail. Ah. The symbolic tools (alluded to above) are *really* resource intensive. You can spend HOURS analyzing a piece of code -- with a fast workstation. (my point being this is a tool that you'd use to VERIFY your assumptions; relying on it to tell you what you don't yet know -- esp if your code is evolving -- is way too costly!) >> I.e., are they practical to use iteratively? On an entire >> application? > > Yes, for many applications. And if you are implementing a safety-critical > system, you design your application to be analysable. But, wouldn't you inherently *know* where your design is headed? And, just need the tool to confirm that? (and put real numbers on it)
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2021-08-03 11:49 +0200 |
| Message-ID | <seb3fa$82q$1@dont-email.me> |
| In reply to | #30746 |
Il 03/08/2021 02:56, Don Y ha scritto: > On 7/29/2021 9:22 AM, pozz wrote: >> arm gcc and Cortex-Mx MCUs embedded systems. >> >> Is there a compilation-time (static) tool for stack analysis that >> really works? > > What do you mean by "really works"? It's a (potentially) unbounded problem > as the compiler can't know what the inputs will drive the code to do, in > practice. I mean a simple tool that can be instructed, even manually, to produce a good result. -fstack-usage is not usable "by hands". You need at least a call-graph (generated by a tool), fill each branch (function) with a stack usage (generated by the compiler), fill every branch that is not known at compilation time by the tools (call functions by pointers, recursive, and so on). It's surprisingly to me there isn't a single non-expensive tool that helps in this, considering there are a multitude of good free tools for developers. > Your best practical option is to tease a callgraph (tree) out and use your > own knowledge of what the code WANTS to do to identify the worst-case > stack penetration path. This is also a great way to get a feel for if your > code might benefit from a good refactoring! > >> The best I could find is -fstack-usage and avstack.pl Perl script, but >> I guess there's another and better way. > > There are general tools that you can probably instrument to coax a > number out of the source (if you don't have access to the source, you're > typically SoL) but they will be expensive in time or money.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-03 20:17 -0700 |
| Message-ID | <sed0s0$ehl$1@dont-email.me> |
| In reply to | #30749 |
On 8/3/2021 2:49 AM, pozz wrote:
> Il 03/08/2021 02:56, Don Y ha scritto:
>> On 7/29/2021 9:22 AM, pozz wrote:
>>> arm gcc and Cortex-Mx MCUs embedded systems.
>>>
>>> Is there a compilation-time (static) tool for stack analysis that really works?
>>
>> What do you mean by "really works"? It's a (potentially) unbounded problem
>> as the compiler can't know what the inputs will drive the code to do, in
>> practice.
>
> I mean a simple tool that can be instructed, even manually, to produce a good
> result.
What's "good"? Does it have to solve *most* peoples' needs? Or, just yours?
As I said, the first step is understanding what the dynamics of execution
in your task happen to be. You may be surprised to see functions being
dragged in that you'd not have thought were part of the mix! ("why is
printf() being called, here?? and, couldn't I use something like itoa()
instead?")
The compiler won't know anything about your run-time environment. It won't
know if you have a separate stack for ISRs, if the function you are analyzing
runs as the "root" of a particular process tree, etc. Do you know how much
work is done BEFORE the first line of your function executed?
It also won't know which execution paths *will* be exercised in practice.
You may have paths that can't be executed (given a particular set of
inputs). How will you know to recognize their impact on any figures
reported?
> -fstack-usage is not usable "by hands".
No, but you can use that data *with* the call tree to get an idea of
where your maximum lies -- assuming no recursion and worst-case path
coverage.
You can also fill the stack space with 0x2B00B1E5, run your COMPREHENSIVE
test case suite that exercises ALL paths through the code and check to see
what the high-water mark was. (you *are* testing the code, right?)
Hint: you *really* want tasks to be of the lowest practical complexity
that can meet your requirements -- even if that means splitting tasks
into more subunits.
> You need at least a call-graph (generated by a tool), fill each branch
> (function) with a stack usage (generated by the compiler),
These can be done with a script (as I suggested below)
> fill every branch
> that is not known at compilation time by the tools (call functions by pointers,
> recursive, and so on).
Ah, well... there's the rub! How smart should this "free" tool be?
And, how should it handle cases that can't be known at compile time
("Sorry, your codebase appears to need AT LEAST X bytes of stack; but,
I can't tell you how much more!" -- what use, that?)
> It's surprisingly to me there isn't a single non-expensive tool that helps in
> this, considering there are a multitude of good free tools for developers.
It costs money to engage in any business (non-hobbyist) endeavor.
Expecting all of your tools to be "free" is a bit naive.
There are some absolutely *amazing* tools available that can save
man-years of development effort and greatly improve the quality/correctness
of code. You can buy them -- or, spend man-hours trying to do what they
do. Hopefully, without error.
And, having *done* that, do it all over again on your NEXT project!
<frown>
>> Your best practical option is to tease a callgraph (tree) out and use your
>> own knowledge of what the code WANTS to do to identify the worst-case
>> stack penetration path. This is also a great way to get a feel for if your
>> code might benefit from a good refactoring!
>>
>>> The best I could find is -fstack-usage and avstack.pl Perl script, but I
>>> guess there's another and better way.
>>
>> There are general tools that you can probably instrument to coax a
>> number out of the source (if you don't have access to the source, you're
>> typically SoL) but they will be expensive in time or money.
*Try* building the call tree (there are some graphic tools) and
have a look at it. Is it what you expected? Do you understand
*why* each function is being invoked in each edge?
Then, try to *guess* where the "stack pigs" are located.
Finally, see what the compiler tells you for each of them and
how well that fits with your "understanding" of the code.
[The reason you want to do this is so you have a better feel
for the costs of particular approaches -- instead of just
reacting to the "final assessment". For example, most newbies
are stunned to discover how expensive an off-the-shelf
printf() can be!]
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2021-08-04 16:43 +0200 |
| Message-ID | <see91v$uiq$1@dont-email.me> |
| In reply to | #30750 |
Il 04/08/2021 05:17, Don Y ha scritto:
> On 8/3/2021 2:49 AM, pozz wrote:
>> Il 03/08/2021 02:56, Don Y ha scritto:
>>> On 7/29/2021 9:22 AM, pozz wrote:
>>>> arm gcc and Cortex-Mx MCUs embedded systems.
>>>>
>>>> Is there a compilation-time (static) tool for stack analysis that
>>>> really works?
>>>
>>> What do you mean by "really works"? It's a (potentially) unbounded
>>> problem
>>> as the compiler can't know what the inputs will drive the code to do, in
>>> practice.
>>
>> I mean a simple tool that can be instructed, even manually, to produce
>> a good result.
>
> What's "good"? Does it have to solve *most* peoples' needs? Or, just
> yours?
Most peoples' needs that are similar: have a good estimate of stack
usage worst case.
> As I said, the first step is understanding what the dynamics of execution
> in your task happen to be. You may be surprised to see functions being
> dragged in that you'd not have thought were part of the mix! ("why is
> printf() being called, here?? and, couldn't I use something like itoa()
> instead?")
Oh yes, but a simple tool that generates automatically a call graph
could be very useful for this.
> The compiler won't know anything about your run-time environment. It won't
> know if you have a separate stack for ISRs, if the function you are
> analyzing
> runs as the "root" of a particular process tree, etc. Do you know how much
> work is done BEFORE the first line of your function executed?
>
> It also won't know which execution paths *will* be exercised in practice.
> You may have paths that can't be executed (given a particular set of
> inputs). How will you know to recognize their impact on any figures
> reported?
I know that compiler can't know everything, but *I* can instruct the
tool with that kind of info.
>> -fstack-usage is not usable "by hands".
>
> No, but you can use that data *with* the call tree to get an idea of
> where your maximum lies -- assuming no recursion and worst-case path
> coverage.
I think this job could be done by a single tool that creates a call
graph and fill in the values from stack usage.
> You can also fill the stack space with 0x2B00B1E5, run your COMPREHENSIVE
> test case suite that exercises ALL paths through the code and check to see
> what the high-water mark was. (you *are* testing the code, right?)
This is the dynamic approach, I was exploring the static approach.
> Hint: you *really* want tasks to be of the lowest practical complexity
> that can meet your requirements -- even if that means splitting tasks
> into more subunits.
>
>> You need at least a call-graph (generated by a tool), fill each branch
>> (function) with a stack usage (generated by the compiler),
>
> These can be done with a script (as I suggested below)
>
>> fill every branch that is not known at compilation time by the tools
>> (call functions by pointers, recursive, and so on).
>
> Ah, well... there's the rub! How smart should this "free" tool be?
> And, how should it handle cases that can't be known at compile time
> ("Sorry, your codebase appears to need AT LEAST X bytes of stack; but,
> I can't tell you how much more!" -- what use, that?)
>
>> It's surprisingly to me there isn't a single non-expensive tool that
>> helps in this, considering there are a multitude of good free tools
>> for developers.
>
> It costs money to engage in any business (non-hobbyist) endeavor.
> Expecting all of your tools to be "free" is a bit naive.
Anyway there are plenty of complex and good free and open-source
software (gcc is one of them).
So it's strange there isn't a similar tool for stack analysis. That's
all, it's strange for me, but I don't pretend all my preferred tools
must be free.
> There are some absolutely *amazing* tools available that can save
> man-years of development effort and greatly improve the quality/correctness
> of code. You can buy them -- or, spend man-hours trying to do what they
> do. Hopefully, without error.
>
> And, having *done* that, do it all over again on your NEXT project!
>
> <frown>
Yes, I know these are the only solutions. I was asking if a free tool
really existed but I didn't knew it.
>>> Your best practical option is to tease a callgraph (tree) out and use
>>> your
>>> own knowledge of what the code WANTS to do to identify the worst-case
>>> stack penetration path. This is also a great way to get a feel for
>>> if your
>>> code might benefit from a good refactoring!
>>>
>>>> The best I could find is -fstack-usage and avstack.pl Perl script,
>>>> but I guess there's another and better way.
>>>
>>> There are general tools that you can probably instrument to coax a
>>> number out of the source (if you don't have access to the source, you're
>>> typically SoL) but they will be expensive in time or money.
>
> *Try* building the call tree (there are some graphic tools) and
> have a look at it. Is it what you expected? Do you understand
> *why* each function is being invoked in each edge?
>
> Then, try to *guess* where the "stack pigs" are located.
>
> Finally, see what the compiler tells you for each of them and
> how well that fits with your "understanding" of the code.
>
> [The reason you want to do this is so you have a better feel
> for the costs of particular approaches -- instead of just
> reacting to the "final assessment". For example, most newbies
> are stunned to discover how expensive an off-the-shelf
> printf() can be!]
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-04 11:06 -0700 |
| Message-ID | <seekur$l16$1@dont-email.me> |
| In reply to | #30751 |
On 8/4/2021 7:43 AM, pozz wrote:
>> As I said, the first step is understanding what the dynamics of execution
>> in your task happen to be. You may be surprised to see functions being
>> dragged in that you'd not have thought were part of the mix! ("why is
>> printf() being called, here?? and, couldn't I use something like itoa()
>> instead?")
>
> Oh yes, but a simple tool that generates automatically a call graph could be
> very useful for this.
How "simple" does it have to be? There are already tools that will
do this for you. Even GUI out. How "pretty" is a matter of debate
given that it's hard to make an algorithm that can find the "prettiest"
way of drawing such a graph.
>> The compiler won't know anything about your run-time environment. It won't
>> know if you have a separate stack for ISRs, if the function you are analyzing
>> runs as the "root" of a particular process tree, etc. Do you know how much
>> work is done BEFORE the first line of your function executed?
>>
>> It also won't know which execution paths *will* be exercised in practice.
>> You may have paths that can't be executed (given a particular set of
>> inputs). How will you know to recognize their impact on any figures
>> reported?
>
> I know that compiler can't know everything, but *I* can instruct the tool with
> that kind of info.
When does your effort fall to the level of being "by hand"?
Note that you really would like a tool to do everything
(at least, everything IMPORTANT) for you so you don't
screw up or misapply it.
>>> -fstack-usage is not usable "by hands".
>>
>> No, but you can use that data *with* the call tree to get an idea of
>> where your maximum lies -- assuming no recursion and worst-case path
>> coverage.
>
> I think this job could be done by a single tool that creates a call graph and
> fill in the values from stack usage.
Have you looked at egypt? There are other similar tools (that may
require more than one command to build the output)
>> You can also fill the stack space with 0x2B00B1E5, run your COMPREHENSIVE
>> test case suite that exercises ALL paths through the code and check to see
>> what the high-water mark was. (you *are* testing the code, right?)
>
> This is the dynamic approach, I was exploring the static approach.
My point is that you still have to perform tests that exercise every path
through your code. So, the test suite can be instrumented to harvest
this data KNOWING that every option has been examined.
>> It costs money to engage in any business (non-hobbyist) endeavor.
>> Expecting all of your tools to be "free" is a bit naive.
>
> Anyway there are plenty of complex and good free and open-source software (gcc
> is one of them).
> So it's strange there isn't a similar tool for stack analysis. That's all, it's
> strange for me, but I don't pretend all my preferred tools must be free.
What's available is what SOMEONE decided they wanted to develop *and*
offer up to others. You typically have fewer choices for "free" than
"for pay". Developing any tool (and maintaining it -- or, providing enough
information that OTHERS can maintain it without you) isn't a trivial job.
And, *a* free tool will likely soak up much of the effort that others
may have spent on some OTHER approach to that free tool. So, the first
drives/hinders future development; it's hard to completely redesign an
existing tool -- esp if others have bought into it on the maintenance side!
I build lots of tools to address *my* needs. But, rarely publish them
(beyond close colleagues) because I don't want to "pay the tax" of
supporting others -- even if they just have simple questions and aren't
looking for some change to the tool. I have my own interests; maintaining
a tool FOR OTHERS isn't one of them! <frown>
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-05 12:00 +0300 |
| Message-ID | <in1nknFamrvU1@mid.individual.net> |
| In reply to | #30754 |
On 2021-08-04 21:06, Don Y wrote:
> On 8/4/2021 7:43 AM, pozz wrote:
>>> As I said, the first step is understanding what the dynamics of
>>> execution in your task happen to be. You may be surprised to see
>>> functions being dragged in that you'd not have thought were part
>>> of the mix! ("why is printf() being called, here?? and,
>>> couldn't I use something like itoa() instead?")
>>
>> Oh yes, but a simple tool that generates automatically a call graph
>> could be very useful for this.
>
> How "simple" does it have to be? There are already tools that will
> do this for you. Even GUI out. How "pretty" is a matter of debate
> given that it's hard to make an algorithm that can find the "prettiest"
> way of drawing such a graph.
The "dot" tool in the GraphViz package does a good job of graph lay-out.
See https://en.wikipedia.org/wiki/Graphviz. Bound-T generates its graphs
in "dot" format. The AbsInt tools have their own graph-layout package;
it may even be sold separately.
However, as a said earlier, a source-level call-graph is often not
complete with respect to the calls that happen at run time.
>> This is the dynamic approach, I was exploring the static approach.
>
> My point is that you still have to perform tests that exercise every path
> through your code.
That (full path coverage) is almost never done, because it is
exponential in the number of branches.
In case the sizes of local variables depend on input data, it may be
very hard to find the input values that lead to the actual worst-case
stack-usage path. Safe upper bounds are easier to find by analysis.
> What's available is what SOMEONE decided they wanted to develop *and*
> offer up to others. You typically have fewer choices for "free" than
> "for pay". Developing any tool (and maintaining it -- or, providing enough
> information that OTHERS can maintain it without you) isn't a trivial job.
My experience is that rather few developers favour the static-analysis
approach to resource analysis -- most just instrument and test. There
are a few application domains that require better guarantees --
aerospace, automotive, nuclear -- and they are also prepared to pay (a
bit) for the tools. However, tools for such domains usually need some
kind of formal qualification or certification, which can be expensive.
Also, while static analysis is still possible for stack usage, it is
becoming impossible for WCET, because of the complex, dynamic
architecture of current high-end embedded processors (out-of-order
execution, complex caches, multi-core with shared-resource conflicts,
and so on and on). The field seems to be moving towards hybrid analysis
methods that combine measured execution times with static flow analys,
for example the tools from Rapita (https://www.rapitasystems.com/).
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-05 04:54 -0700 |
| Message-ID | <segjih$e76$1@dont-email.me> |
| In reply to | #30759 |
On 8/5/2021 2:00 AM, Niklas Holsti wrote: > On 2021-08-04 21:06, Don Y wrote: >>> This is the dynamic approach, I was exploring the static approach. >> >> My point is that you still have to perform tests that exercise every path >> through your code. > > That (full path coverage) is almost never done, because it is exponential in > the number of branches. It's impractical for a "whole program" but is relatively easy to accomplish for tasks designed to be small and single-focus. A solution that is implemented in this sort of "decomposed" manner is easier to analyze whereas something "monolithic" is hard to (later) "chop up" to yield testable SMALLER/simpler pieces. > In case the sizes of local variables depend on input data, it may be very hard > to find the input values that lead to the actual worst-case stack-usage path. > Safe upper bounds are easier to find by analysis. > >> What's available is what SOMEONE decided they wanted to develop *and* >> offer up to others. You typically have fewer choices for "free" than >> "for pay". Developing any tool (and maintaining it -- or, providing enough >> information that OTHERS can maintain it without you) isn't a trivial job. > > My experience is that rather few developers favour the static-analysis approach > to resource analysis -- most just instrument and test. There are a few > application domains that require better guarantees -- aerospace, automotive, > nuclear -- and they are also prepared to pay (a bit) for the tools. However, > tools for such domains usually need some kind of formal qualification or > certification, which can be expensive. Ditto medical/pharma/gamiing. In addition to tool qualification, there are also *process* qualification issues. This tends to reduce the number of variants/releases of a "product" as each release requires running through the validation effort, again. [And, a release begs the question: "Do you mean there were things that DID NOT WORK in the prior release? If so, then how comprehensive was the previous validation effort??? Assure me that your process isn't inherently flawed..."] The fact that this effort exists (is required) means you will spend money to lessen it's cost AND increase the apparent integrity of your process to customers/agencies. Esp as you will be doing this repeatedly (for this product or others). Imagine having to *manually* repeat the entire effort from the previous release PLUS the changes brought about by the new release... for EVERY successive release! [No, you can't just *claim* that all of the stuff you validated before STILL WORKS!] > Also, while static analysis is still possible for stack usage, it is becoming > impossible for WCET, because of the complex, dynamic architecture of current > high-end embedded processors (out-of-order execution, complex caches, > multi-core with shared-resource conflicts, and so on and on). The field seems > to be moving towards hybrid analysis methods that combine measured execution > times with static flow analys, for example the tools from Rapita > (https://www.rapitasystems.com/). I've taken a different approach on my current (real-time) project: assume any task can fail to meet it's deadlines and provide mechanisms to handle those overruns. (a "hard" real-time task has a very simple deadline handler: kill the task! :> ) But, that's because the resource load (and resource complement) is not known a priori so you can't make *any* guarantees.
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-04 20:00 +0300 |
| Message-ID | <imvvdmFu7i4U1@mid.individual.net> |
| In reply to | #30749 |
On 2021-08-03 12:49, pozz wrote: > Il 03/08/2021 02:56, Don Y ha scritto: >> On 7/29/2021 9:22 AM, pozz wrote: >>> arm gcc and Cortex-Mx MCUs embedded systems. >>> >>> Is there a compilation-time (static) tool for stack analysis that >>> really works? >> >> What do you mean by "really works"? It's a (potentially) unbounded >> problem as the compiler can't know what the inputs will drive the >> code to do, in practice. > > I mean a simple tool that can be instructed, even manually, to > produce a good result. > > -fstack-usage is not usable "by hands". > > You need at least a call-graph (generated by a tool), fill each > branch (function) with a stack usage (generated by the compiler), > fill every branch that is not known at compilation time by the tools > (call functions by pointers, recursive, and so on). > > It's surprisingly to me there isn't a single non-expensive tool that > helps in this, considering there are a multitude of good free tools > for developers. One reason is that for good results, such a tool has to analyze the executable code, and therefore must be target-specific, or at least have ports to the various targets, increasing the effort to implement and maintain the tool. The gnatstack tool gets around that, to some extent, by relying on stack-usage and call information from the compiler (gcc). Note that a source-level call graph will not show calls to the various support routines (run-time routines) inserted by the compiler, but those calls do use stack. I am the main author of a WCET-analysis tool, Bound-T, that also does stack analysis and is now free. However, there is (as yet) no port for ARM Cortex-M. See http://www.bound-t.com/.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-04 10:50 -0700 |
| Message-ID | <seek0l$e3r$1@dont-email.me> |
| In reply to | #30752 |
On 8/4/2021 10:00 AM, Niklas Holsti wrote: > On 2021-08-03 12:49, pozz wrote: >> Il 03/08/2021 02:56, Don Y ha scritto: >>> On 7/29/2021 9:22 AM, pozz wrote: >>>> arm gcc and Cortex-Mx MCUs embedded systems. >>>> >>>> Is there a compilation-time (static) tool for stack analysis that >>>> really works? >>> >>> What do you mean by "really works"? It's a (potentially) unbounded >>> problem as the compiler can't know what the inputs will drive the >>> code to do, in practice. >> >> I mean a simple tool that can be instructed, even manually, to >> produce a good result. >> >> -fstack-usage is not usable "by hands". >> >> You need at least a call-graph (generated by a tool), fill each >> branch (function) with a stack usage (generated by the compiler), >> fill every branch that is not known at compilation time by the tools >> (call functions by pointers, recursive, and so on). >> >> It's surprisingly to me there isn't a single non-expensive tool that >> helps in this, considering there are a multitude of good free tools >> for developers. > > > One reason is that for good results, such a tool has to analyze the executable > code, and therefore must be target-specific, or at least have ports to the > various targets, increasing the effort to implement and maintain the tool. The > gnatstack tool gets around that, to some extent, by relying on stack-usage and > call information from the compiler (gcc). I am seeing an increasing number of tools relying on intermediate encodings (e.g., via LLVM) to give more portability to their application. But, then you're stuck *needing* access to the sources. > Note that a source-level call graph > will not show calls to the various support routines (run-time routines) > inserted by the compiler, but those calls do use stack. > > I am the main author of a WCET-analysis tool, Bound-T, that also does stack > analysis and is now free. However, there is (as yet) no port for ARM Cortex-M. > See http://www.bound-t.com/. But not free as in open (?)
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-04 21:50 +0300 |
| Message-ID | <in05quF11e0U1@mid.individual.net> |
| In reply to | #30753 |
On 2021-08-04 20:50, Don Y wrote:
> On 8/4/2021 10:00 AM, Niklas Holsti wrote:
...
>> I am the main author of a WCET-analysis tool, Bound-T, that also does
>> stack analysis and is now free. However, there is (as yet) no port for
>> ARM Cortex-M. See http://www.bound-t.com/.
>
> But not free as in open (?)
The source code is downloadable; see http://bound-t.com/download/src.
The copyright text is of my own writing, but I'm open to switching to
some better-known copyright such as GPL or even some non-viral version.
However, you may want to read about the state of the tool at
http://bound-t.com/status.html.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-04 15:46 -0700 |
| Message-ID | <sef5c3$5so$1@dont-email.me> |
| In reply to | #30755 |
On 8/4/2021 11:50 AM, Niklas Holsti wrote: > On 2021-08-04 20:50, Don Y wrote: >> On 8/4/2021 10:00 AM, Niklas Holsti wrote: > > ... > >>> I am the main author of a WCET-analysis tool, Bound-T, that also does stack >>> analysis and is now free. However, there is (as yet) no port for ARM >>> Cortex-M. See http://www.bound-t.com/. >> >> But not free as in open (?) > > The source code is downloadable; see http://bound-t.com/download/src. The > copyright text is of my own writing, but I'm open to switching to some > better-known copyright such as GPL or even some non-viral version. Ah, OK. I may have a look at it to see how well it works and how much work to port to ARM objects. Given that you've not done so, already (despite your familiarity with the codebase), I suspect that's not a trivial task? > However, you may want to read about the state of the tool at > http://bound-t.com/status.html. Hmmm... that sounds ominous! :> (or, am I just too much of a Cynic?)
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-05 13:43 +0300 |
| Message-ID | <in1tnaFbu8rU1@mid.individual.net> |
| In reply to | #30758 |
On 2021-08-05 1:46, Don Y wrote: > On 8/4/2021 11:50 AM, Niklas Holsti wrote: >> On 2021-08-04 20:50, Don Y wrote: >>> On 8/4/2021 10:00 AM, Niklas Holsti wrote: >> >> ... >> >>>> I am the main author of a WCET-analysis tool, Bound-T, that also >>>> does stack analysis and is now free. However, there is (as yet) no >>>> port for ARM Cortex-M. See http://www.bound-t.com/. >>> >>> But not free as in open (?) >> >> The source code is downloadable; see http://bound-t.com/download/src. >> The copyright text is of my own writing, but I'm open to switching to >> some better-known copyright such as GPL or even some non-viral version. > > Ah, OK. I may have a look at it to see how well it works and > how much work to port to ARM objects. Given that you've not > done so, already (despite your familiarity with the codebase), > I suspect that's not a trivial task? There is an ARM TDMI port (32-bit ARM code and THUMB, pre Cortex), but of course that architecture is out of date. I started a port to ARM Cortex-M, but did not (yet) finish it for the reasons described on the status page. Note that the tool is implemented in Ada. Porting to a new target processor means writing procedures to decode the machine instructions and translate them to the internal representation used by the analysis. Sometimes it is also necessary to modify or extend the tool parts that read the executable files and especially the debugging information -- some of that may be compiler-specific, unfortunately. It is a fair amount of work and requires a good understanding both of the target processor and of the Bound-T internal representation. And Ada, of course, but every programmer should know Ada, IMO :-) >> However, you may want to read about the state of the tool at >> http://bound-t.com/status.html. > > Hmmm... that sounds ominous! :> (or, am I just too much of a Cynic?) The problems described on the status page are more relevant to WCET analysis than to stack analysis, but can affect stack analysis too, in some cases.
[toc] | [prev] | [next] | [standalone]
| From | Don Y <blockedofcourse@foo.invalid> |
|---|---|
| Date | 2021-08-05 06:16 -0700 |
| Message-ID | <segoc2$6dj$1@dont-email.me> |
| In reply to | #30761 |
On 8/5/2021 3:43 AM, Niklas Holsti wrote: > On 2021-08-05 1:46, Don Y wrote: >>> The source code is downloadable; see http://bound-t.com/download/src. The >>> copyright text is of my own writing, but I'm open to switching to some >>> better-known copyright such as GPL or even some non-viral version. >> >> Ah, OK. I may have a look at it to see how well it works and >> how much work to port to ARM objects. Given that you've not >> done so, already (despite your familiarity with the codebase), >> I suspect that's not a trivial task? > > There is an ARM TDMI port (32-bit ARM code and THUMB, pre Cortex), but of > course that architecture is out of date. I started a port to ARM Cortex-M, but > did not (yet) finish it for the reasons described on the status page. > > Note that the tool is implemented in Ada. OK. It's been ~20 years since I wrote a line of Ada code but I doubt it will take much to "refresh" those memory cells. Esp as this likely doesn't have synchronization issues, RT constraints, etc. > Porting to a new target processor means writing procedures to decode the > machine instructions and translate them to the internal representation used by > the analysis. That shouldn't be hard -- except for the "timing uncertainties" in the processor. (Did you rely on some blanket generalization -- like all caches cold -- as you are looking for WORST case timing? OTOH, a loop known to fit in a cache line *should* expect that speedup... :< ) > Sometimes it is also necessary to modify or extend the tool parts > that read the executable files and especially the debugging information -- some > of that may be compiler-specific, unfortunately. It is a fair amount of work > and requires a good understanding both of the target processor and of the > Bound-T internal representation. The latter will likely be the bigger effort. It requires trying to infer your mindset when you began the design. [I now include "rationales" in my documentation for exactly this purpose; to let those "following" understand why particular choices were made instead of choices that may (in hindsight) appear better] > And Ada, of course, but every programmer > should know Ada, IMO :-) > >>> However, you may want to read about the state of the tool at >>> http://bound-t.com/status.html. >> >> Hmmm... that sounds ominous! :> (or, am I just too much of a Cynic?) > > The problems described on the status page are more relevant to WCET analysis > than to stack analysis, but can affect stack analysis too, in some cases. OK. I'll try to make some time to look through it. Sadly, a neighbor was admitted to hospital with congestive heart failure, last night. So, I've some added responsibilities cutting into my time (meal prep, chores around his house, etc.) until he's got a firmer prognosis... [I don't *need* to sleep, do I? :< ]
[toc] | [prev] | [next] | [standalone]
| From | Niklas Holsti <niklas.holsti@tidorum.invalid> |
|---|---|
| Date | 2021-08-05 18:39 +0300 |
| Message-ID | <in2f27FfeehU1@mid.individual.net> |
| In reply to | #30764 |
On 2021-08-05 16:16, Don Y wrote: > On 8/5/2021 3:43 AM, Niklas Holsti wrote: >> On 2021-08-05 1:46, Don Y wrote: > >>>> The source code is downloadable; see >>>> http://bound-t.com/download/src. The copyright text is of my own >>>> writing, but I'm open to switching to some better-known copyright >>>> such as GPL or even some non-viral version. >>> >>> Ah, OK. I may have a look at it to see how well it works and >>> how much work to port to ARM objects. Given that you've not >>> done so, already (despite your familiarity with the codebase), >>> I suspect that's not a trivial task? >> >> There is an ARM TDMI port (32-bit ARM code and THUMB, pre Cortex), but >> of course that architecture is out of date. I started a port to ARM >> Cortex-M, but did not (yet) finish it for the reasons described on the >> status page. >> >> Note that the tool is implemented in Ada. > > OK. It's been ~20 years since I wrote a line of Ada code but I doubt it > will take much to "refresh" those memory cells. Esp as this likely doesn't > have synchronization issues, RT constraints, etc. Right. The only use of tasking features is to set an upper limit on the execution time of the analysis, and that feature is easy to remove if needed. The code mostly relies on the 1995 Ada standard, with some use of Ada 2005 additions. >> Porting to a new target processor means writing procedures to decode >> the machine instructions and translate them to the internal >> representation used by the analysis. > > That shouldn't be hard -- except for the "timing uncertainties" in the > processor. (Did you rely on some blanket generalization -- like all > caches cold -- as you are looking for WORST case timing? OTOH, a > loop known to fit in a cache line *should* expect that speedup... :< ) At present the tool assumes that every instruction and control transfer can be assigned its own WCET, in machine cycles, independent of other context or data values. The only dynamic aspects of instruction execution time that are modelled are the possible pipeline stalls due to read-after-write interlocks. As a special case, in the version for SPARC, the concurrent execution of the Integer Unit and the Floating Point Unit is modelled to estimate where and for how long the IU has to wait for the FPU to complete an operation. Good algorithms for computing WCET bounds for most kinds of instruction caches are known, but I did not get around to implementing any of those, so only cache-less processors are supported now. If you need WCET analysis of caches, the AbsInt tool is best. Data caches are still a hard problem, where the WCET analyses tend to be quite pessimistic. Moreover, the increasing use of eviction algorithms other than LRU (for example, pseudo-random eviction) lessens the precision of the cache analyses, even for instruction caches. >> Sometimes it is also necessary to modify or extend the tool parts that >> read the executable files and especially the debugging information -- >> some of that may be compiler-specific, unfortunately. It is a fair >> amount of work and requires a good understanding both of the target >> processor and of the Bound-T internal representation. > > The latter will likely be the bigger effort. It requires trying to infer > your mindset when you began the design. You could start by reading http://bound-t.com/whats-inside.html. > [I now include "rationales" in my documentation for exactly this purpose; > to let those "following" understand why particular choices were made > instead of choices that may (in hindsight) appear better] Me too. Ceterum censeo that calling the in-code documentation "comments" was a very poor choice of term and very misleading for what such documentation should contain and its importance.
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.arch.embedded
csiph-web