Page 76 - The Art of Designing Embedded Systems
P. 76

Real Time Means Right Now!  63



                           250-275  nsec        for(i=O; i<count; ++i)
                           508-580  nsec        {if (start-count  !=
                                                 end-c oun t )
                           250  nsec       end_point=head;
                                                  I

                      where  a range  of  values  cover possible  differences  in  execution
                      paths depending on how the statement operates (for example, if the
                      FOR statement iterates or terminates).
                           To get actual times, of course, the compiler needs to know a lot
                      about our system, including clock rates and wait states. Another op-
                      tion is to display T states, or even just number of instructions exe-
                      cuted  (since that would give us at least some  sort of  view  of  the
                      code’s performance in the time domain).
                           Vendors tell me that cache, pipelines,  and prefetchers make
                      modeling code performance too difficult. I disagree. Most small em-
                      bedded CPUs don’t have these features, and of them, only cache is
                      truly tough to model.
                           Please, Mr. Compiler Vendor, give us some sort of indication
                      about the sort of performance we can expect! Give us a clue about
                      how long a runtime routine or floating-point operation takes.
                           A friend told me  how his DOD project uses an antique lan-
                      guage called CMSP. The compiler is so buggy they have to look for
                      bugs in the assembly listing after each and every compile-and  then
                      make a more or less random change and recompile, hoping to lure
                      the tool into creating correct code. I laughed until I realized that’s
                      exactly the situation we’re in when using a high-quality C compiler
                      in performance-bound applications.


                         Be especially wary of using complex data structures in ISRs. Watch
                    what the compiler generates. You may gain an enormous amount of per-
                    formance by sizing an array at an even power of 2, perhaps wasting some
                    memory, but avoiding the need for the compiler to generate complicated
                    and slow indexing code.
                         An  old software adage recommends coding  for  functionality first,
                    and speed second. Since 80% of the speed problems are usually in 20% of
                    the code, it makes sense to get the system working and then determine
                    where the bottlenecks are. Unfortunately, real-time systems by their nature
                    usually don’t work at all if things are slow. You’ve often got to code for
                    speed up front.
   71   72   73   74   75   76   77   78   79   80   81