Most Common Mistakes w ith Real-Time Softw are Development Embedded - - PowerPoint PPT Presentation

most common mistakes w ith real time softw are development
SMART_READER_LITE
LIVE PREVIEW

Most Common Mistakes w ith Real-Time Softw are Development Embedded - - PowerPoint PPT Presentation

Most Common Mistakes w ith Real-Time Softw are Development Embedded Systems Conference Boston, September 2006 Class ESC 401/421 Dave Stewart Director of Software Engineering I nHand Electronics Rockville, Maryland dstewart@inhand.com


slide-1
SLIDE 1

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Dave Stewart

Director of Software Engineering I nHand Electronics Rockville, Maryland dstewart@inhand.com http:/ / www.inhand.com

Most Common Mistakes w ith Real-Time Softw are Development

Embedded Systems Conference Boston, September 2006 Class ESC 401/421

slide-2
SLIDE 2

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Why this presentation? Novices and Experts in both industry and university, make the same mistakes over and over again.

slide-3
SLIDE 3

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

The Order The order is subjective, based on personal observations when using the following criteria:

What is the effect

  • f the mistake on

reliability? How often is the mistake made?

is highest on list

What is the bottom line regarding Time and Money? Does the mistake increase complexity

  • f the code?
slide-4
SLIDE 4

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

The Order is Not Really Important What is important is that the mistake is on the list! Correcting just ONE mistake can save thousands of dollars

  • r significantly improve

quality and robustness of software. Correcting SEVERAL mistakes can lead to savings and improvements that are incalculable!

slide-5
SLIDE 5

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

“My Problem is Different” Learn from experience of others Focus on similarities, not differences Rarely, if ever, is entire problem different

slide-6
SLIDE 6

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Delays implemented as empty loops Use RTOS timing mechanisms Build your own mechanism that automatically profiles CPU Poll the count-down value of a timer

slide-7
SLIDE 7

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Tools choice driven by marketing hype, not by evaluation of technical needs Select tools based on your own technical needs, not just because everybody else is using them. Spending $2,000 for the right tool can save $100,000 in labor.

slide-8
SLIDE 8

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Large if-then-else and case statements Usually a sign of implementation without design. Instead, Design First! Use Finite State Machines to reduce complexity.

slide-9
SLIDE 9

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Documentation w ritten after implementation Start implementation with documentation (the design document) Revise documentation interactively; this serves as a sanity check to ensure that the code implements everything defined in it. Document is written when functionality is fresh in programmer’s mind.

slide-10
SLIDE 10

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Interactive and incomplete test programs Simulate input devices with known patterns Always test the entire application all the time Nightly extensive self-tests Create non-interactive test programs Instead:

slide-11
SLIDE 11

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Softw are Engineers Don’t Participate in Hardw are Design

Leads to over-designing the system Instead, promote Hardware/Software Co-Design

slide-12
SLIDE 12

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No Simulators of Target Application Faster development Better debugging tools Multiple programmers Customer feedback Deeper understanding Safer and cheaper! Using a simulator:

slide-13
SLIDE 13

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Error detection and handling is an after-thought, and implemented through trial and error Treat errors as inputs, and error handling as a state Error detection and handling must be specified and designed prior to implementation.

slide-14
SLIDE 14

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Generalizations based on a single architecture Develop code on multiple architectures simultaneously Don’t generalize everything! Create configurable modules for whatever is different between architectures

slide-15
SLIDE 15

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

3*x or x+x+x Do not perform fine-grain optimizations unless needed, and only during final stages of implementation Measure performance after each optimization to ensure it is in fact an optimization Do coarse-grain optimization during design phase Optimizing at the Wrong Time

slide-16
SLIDE 16

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

To perform good coarse-grain

  • ptimization, must analyze hardware

peculiarities before starting Profile CPU before writing programs for it, to identify and understand anomalies. float+byte: 308 usec Byte+byte: 7 usec 16-bit+16-bit: 12 usec 32-bit+32-bit: 28 usec float+float: 137 usec On a 9 MHz Z180: Better understanding of hardware peculiarities will lead to better designs. Optimizing at the Wrong Time

slide-17
SLIDE 17

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Reusing code not designed for reuse Don’t waste time trying to use old code that was not designed for reuse. Instead, re-design it using proven techniques for software reuse.

slide-18
SLIDE 18

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Using blocking forms of message passing

Schedulable bound: The maximum utilization of the processor for which a task set is guaranteed to still meet all its timing

  • constraints. Ideally, schedulable bound is 100%. In practice, it is

lower than that.

Problems:

  • Reduced real-time schedulable bound
  • Significant overhead
  • Results in lots of aperiodic servers
  • Forces tight synchronization
  • Potential for deadlock in closed-loop systems
  • Additional complexity for 1:many communication
slide-19
SLIDE 19

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Minimize inter-module communication and synchronization Solution: Use a shared-memory based protocol, such as state variable communication, publish/subscribe, or non-blocking message passing. If blocking is unavoidable, use proper synchronization techniques to prevent priority inversion and deadlock, such as priority ceiling protocol. Using blocking forms of message passing

slide-20
SLIDE 20

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No memory analysis during design Compute memory usage during design phase. Don’t forget about memory used by string constants. For code, estimate a budget for each module.

slide-21
SLIDE 21

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Improper use of Global Variables! Problem -- reduces maintainability of software:

  • Global variables (even static ones) are shared.
  • Limits expandability by preventing replication of modules.
  • Causes many inter-module dependencies.

Solution -- eliminate (most) global variables:

  • Use proper data abstraction and encapsulation
  • Use shared memory mechanisms to control access,

such as State Variable Table, Publish/Subscribe, etc.

slide-22
SLIDE 22

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Interrupts are an enemy to real-time predictability:

  • Always have high priority
  • Force a need for global variables
  • Cannot be scheduled
  • Difficult to analyze
  • Execute within wrong context
  • Operate in kernel space
  • Priority inversion
  • Difficult to debug

Indiscriminate use of interrupts

slide-23
SLIDE 23

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Instead, minimize use of interrupts whenever possible Periodic polling threads are more desirable than interrupts because they are schedulable Complex code should be replaced by a signal to an aperiodic server Only use real-time analysis methods that take interrupt handling into account Indiscriminate use of interrupts

slide-24
SLIDE 24

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Interrupts: 20 to 50 µsec per interrupt Threads: 50 to 100 µsec per context switch Non-preemptive processes: 10 to 30 µsec per switch A real-time executive with non-preemptive periodic processes can sometimes provide more predictable results and better utilization than using interrupts. Indiscriminate use of interrupts Myth: Interrupts save CPU time over processes Reality: Not usually in real-time systems

slide-25
SLIDE 25

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Interrupts save a bit of overhead, but at the huge cost of reducing the schedulable bound and increasing the possibility of race conditions Saving 10% overhead by using interrupts might reduce schedulable bound by 30% and increase

  • verhead of using shared variables by 20%!

Indiscriminate use of interrupts Myth: Interrupts save CPU time over processes Reality: Not usually in real-time systems

slide-26
SLIDE 26

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Poor Softw are Design Diagrams

slide-27
SLIDE 27

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No Softw are Design Diagrams

typedef struct _def_t { struct _def_t *next; struct _def_t *prev; char name[8]; short loval; short hival; } def_t; typedef struct _xyz_t { int i; float f; short s[2]; unsigned char b[8]; } xyz_t; typedef struct _abc_t { def_t *def; xyz_t *xyz; short ndef; } abc_t;

*def *xyz ndef abc_t

next prev name loval hival def_t structure abc_t field within structure zoomed-in view abc_t field head name1 namendef xyz[0] xyz[1] xyz[2] xyz[nxyz–1] i f s[1]

b[0] b[1] b[2] b[3] b[4] b[5] b[6] b[7]

  • f a structure

pointer Legend s[0]

slide-28
SLIDE 28

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Architectural decomposition: at least one diagram per level of decomposition Detailed design: at least one diagram per function or module Poor Softw are Design Diagrams Process-flow Data-flow Finite-state machines Data relationships Dependency graphs Sequence

slide-29
SLIDE 29

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

How do w e create good diagrams? Land Water Create a legend for every diagram. Every block, symbol, line, shading, color, and font type should be specified in legend. Any deviation from legend shows an error in the design. Poor Softw are Design Diagrams

slide-30
SLIDE 30

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

“It’s just a glitch” Never assume that a problem has been fixed magically Note problem in your log book immediately! Spend some time to try and fix the problem

slide-31
SLIDE 31

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

“It’s just a glitch” What are the most likely causes? Timing Error (race condition, priority inversion) Memory Corruption Deadlock

slide-32
SLIDE 32

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

(1) During design phase, take precautions: Formal code review Minimize shared resources and memory Minimize use of interrupts Use deadlock-free IPC solutions “It’s just a glitch” How do we pinpoint the problem? (2) During testing and maintenance phases: Put sleep() commands within critical sections Check for stack corruption Incrementally add debug statements Monitor progress on logic analyzer

slide-33
SLIDE 33

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

The first right answ er is the only answ er Every problem has at least 3 answers: The first answer The opposite answer A compromise between the first two answers Which is the best answer? Learn to be more creative to find the other answers.

slide-34
SLIDE 34

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No code review s Code reviews are a proven way to improve quality and robustness Reviews help eliminate messy code by forcing programmers to show their code to others Studies have shown that more problems can get fixed in

  • ne day of code review than in a month of debugging

Reviews double as training sessions to increase number of employees who understand the code

slide-35
SLIDE 35

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

“Nobody else here can help me” syndrome

Learn by teaching others!

slide-36
SLIDE 36

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

One Big Loop

slide-37
SLIDE 37

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

One Big Loop Use proper concurrent design techniques: Non-preemptive: cyclic or multi-rate executive Preemptive: real-time operating system Don’t use interrupts to emulate multitasking

slide-38
SLIDE 38

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Too many inter-module dependencies

slide-39
SLIDE 39

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

abc def ghi jkl stu mno uvw prq xyz abc def ghi jkl stu mno uvw pqr xyz abc def ghi jkl stu mno uvw prq xyz Example of Dependency Graph abc def ghi jkl stu mno uvw prq xyz jkl jkl uvw pqr xyz abc def ghi jkl stu mno uvw pqr xyz Minimize Circular Dependencies!

Too many inter-module dependencies

slide-40
SLIDE 40

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

#include “globals.h” problem

Follow fundamental Software Engineering concepts, especially:

· Data encapsulation and modularity · Use abstract data types or objects Put code for module abc in file abc.c.

abc.h abc.c pqr.h pqr.c

Only put definitions of anything exported from abc.c into file abc.h #include only the .h files you need.

Too many inter-module dependencies

Hints for maximizing modularity:

slide-41
SLIDE 41

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No naming and style conventions!

Establish a set of conventions, and stick to them! Use the conventions to help reader to quickly identify the origin and purpose of the symbol.

slide-42
SLIDE 42

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No measurements of execution time!

slide-43
SLIDE 43

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

No measurements of execution time!

First, design your system so that the code is measurable! Learn both coarse-grain and fine-grain techniques to measure execution time. Measure execution time as part of your standard testing. Do not only test the functionality of the code!

Use coarse-grain measurements for analyzing real-time properties Use fine-grain measurements for optimizing and fine-tuning

slide-44
SLIDE 44

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Most Common Mistakes w ith Real-Time Softw are Development Correcting just ONE mistake can save thousands of dollars

  • r significantly improve

quality and robustness of software. Correcting SEVERAL mistakes can lead to savings and improvements that are incalculable! Summary

slide-45
SLIDE 45

Top 25 Most Common Mistakes with Real-Time Software Development Dave Stewart; Director of Software Engineering, InHand Electronics, www.inhand.com Embedded Systems Conference Boston, 2006

Dave Stewart

Director of Software Engineering I nHand Electronics Rockville, Maryland dstewart@inhand.com http:/ / www.inhand.com

Most Common Mistakes w ith Real-Time Softw are Development