Improve Embedded System Stability and Performance through Memory Analysis Tools Bill Graham, Product Line Manager Development Tools November 14, 2006.

Slides:



Advertisements
Similar presentations
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Advertisements

Chorus and other Microkernels Presented by: Jonathan Tanner and Brian Doyle Articles By: Jon Udell Peter D. Varhol Dick Pountain.
Last update: August 9, 2002 CodeTest Embedded Software Verification Tools By Advanced Microsystems Corporation.
1 C Review and Dissection V: Dynamic Memory Allocation and Linked Lists These lecture notes created by Dr. Alex Dean, NCSU.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
Designing High-Performance Network Elements Using Multiprocessing Technology and Adaptive Partitioning Peter van der Veen QNX Software Systems.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
CPSC 388 – Compiler Design and Construction
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Operating System Support Focus on Architecture
INTRODUCTION OS/2 was initially designed to extend the capabilities of DOS by IBM and Microsoft Corporations. To create a single industry-standard operating.
2: OS Structures 1 Jerry Breecher OPERATING SYSTEMS STRUCTURES.
Mid#1 Revision. CH1 Mind map Ch2 Mind map Types of Questions Short Answers (essay) True/False MCQ Problems Code to trace.
Introduction Operating Systems’ Concepts and Structure Lecture 1 ~ Spring, 2008 ~ Spring, 2008TUCN. Operating Systems. Lecture 1.
Operating System Organization
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
Programming mobile devices Part II Programming Symbian devices with Symbian C++
Chapter 2 Operating System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: System Structures.
Chapter 3: Operating-System Structures System Components Operating System Services System Calls System Programs System Structure Virtual Machines System.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Matt Wolfe LC Development Environment Group Lawrence Livermore National Laboratory Lawrence Livermore National Laboratory, P. O. Box 808, Livermore, CA.
Computer Systems Week 14: Memory Management Amanda Oddie.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Department of Computer Science and Software Engineering
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Test Plan: Introduction o Primary focus: developer testing –Implementation phase –Release testing –Maintenance and enhancement o Secondary focus: formal.
6-1 Embedded Systems C Programming Language Review and Dissection IV Lecture 6.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Announcements Partial Credit Due Date for Assignment 2 now due on Sat, Feb 27 I always seem to be behind and get tons of daily. If you me and.
Computer Operating Systems And Software applications.
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
QNX® Momentics® Development Suite Tools for Building, Debugging and Optimizing Embedded Systems.
Beyond Application Profiling to System Aware Analysis Elena Laskavaia, QNX Bill Graham, QNX.
System Components Operating System Services System Calls.
Operating System Structure Lecture: - Operating System Concepts Lecturer: - Pooja Sharma Computer Science Department, Punjabi University, Patiala.
Overview of today’s lecture Major components of an operating system Structure and internal architecture of an operating system Monolithic Vs Micro-kernels.
Embedded Real-Time Systems
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems Concepts
Computer System Structures
Kernel Design & Implementation
Presented by: Daniel Taylor
Process concept.
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
YAHMD - Yet Another Heap Memory Debugger
Debugging Memory Issues
Software Architecture in Practice
C Programming Language Review and Dissection IV
Operating System Structure
KERNEL ARCHITECTURE.
Threads, SMP, and Microkernels
QNX Technology Overview
PerfView Measure and Improve Your App’s Performance for Free
Optimize Your Java Code By Tools
Dynamic Memory Allocation
Memory Management Overview
Lecture 4- Threads, SMP, and Microkernels
Chapter 2: Operating-System Structures
Operating Systems Lecture 3.
Introduction to Operating Systems
Prof. Leonardo Mostarda University of Camerino
Operating System Introduction.
Chapter 2: Operating-System Structures
COMP755 Advanced Operating Systems
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Improve Embedded System Stability and Performance through Memory Analysis Tools Bill Graham, Product Line Manager Development Tools November 14, 2006

2 out of 48 All content copyright of QNX Software Systems Co. Agenda 1. Introduction 2. Memory Analysis Primer 3. Memory-related Error Detection 4. Memory Leak Detection 5. Memory Profiling 6. Memory Optimization 7. QNX Momentics Development Suite 8. Q&A

Introduction – The role of an OS

4 out of 48 All content copyright of QNX Software Systems Co. Memory-related Challenges  Memory leaks, errors and other crash-causing problems can have catastrophic effects on other processes and threads ► Undetected memory leaks can lead to system crashes ► Sub-optimal memory allocation can degrade performance ► Excessive memory usage can inflate costs ► Memory errors can cause failures in the field

5 out of 48 All content copyright of QNX Software Systems Co. The Role of OS Architecture  First and last line of defense is a robust operating system architecture  Memory protection and microkernel architecture can protect the OS and applications from each other

6 out of 48 All content copyright of QNX Software Systems Co. Microkernel Architecture Realtime Executive (VxWorks, proprietary) >No MMU and no protection >Applications, drivers, etc. are all in kernel space Monolithic Kernel (XP, Unix, Linux, etc.) >MMU with partial protection >Applications are protected True Microkernel (QNX ® Neutrino ® RTOS ) >MMU with full protection >Applications, drivers, and protocols are all protected Device DriversTCP/IP StackFile System Application Kernel space Device DriversTCP/IP Stack File System Application Kernel Device DriversTCP/IP StackFile System Application Kernel space User Space  System-wide corruption

7 out of 48 All content copyright of QNX Software Systems Co. Microkernel Architecture Realtime Executive (VxWorks, proprietary) >No MMU and no protection >Applications, drivers, etc. are all in kernel space Monolithic Kernel (XP, Unix, Linux, etc.) >MMU with partial protection >Applications are protected True Microkernel (QNX ® Neutrino ® RTOS ) >MMU with full protection >Applications, drivers, and protocols are all protected Device DriversTCP/IP StackFile System Application Kernel space Device DriversTCP/IP Stack File System Application Kernel Device DriversTCP/IP StackFile System Application Kernel space User Space System-wide corruption    Contained (re-startable) System-wide corruption

8 out of 48 All content copyright of QNX Software Systems Co. Microkernel Architecture Realtime Executive (VxWorks, proprietary) >No MMU and no protection >Applications, drivers, etc. are all in kernel space Monolithic Kernel (XP, Unix, Linux, etc.) >MMU with partial protection >Applications are protected True Microkernel (QNX ® Neutrino ® RTOS ) >MMU with full protection >Applications, drivers, and protocols are all protected Device DriversTCP/IP StackFile System Application Kernel space Device DriversTCP/IP Stack File System Application Kernel Device DriversTCP/IP StackFile System Application Kernel space User Space System-wide corruption    Contained (re-startable)   System-wide corruption Contained (re-startable)

9 out of 48 All content copyright of QNX Software Systems Co. Microkernel Architecture File System Protocol Stack Microkernel Application Microkernel the only trusted component Audio Driver Graphics Driver Applications and drivers:  Processes that plug into a message bus  Reside in memory-protected address space  Cannot corrupt other software components  Can be started, stopped, and upgraded dynamically  Critical for survivability Message Bus …

Memory Analysis Primer

11 out of 48 All content copyright of QNX Software Systems Co. Target Management  Embedded systems need to be monitored, debugged and controlled remotely ► Much of the complexity and difficulty with embedded development is limited insight into the operation of the target system

12 out of 48 All content copyright of QNX Software Systems Co. Run-time Memory Analysis malloc() free() strcpy() … Debug Library Application  Memory analysis works through trapping memory-related API calls

13 out of 48 All content copyright of QNX Software Systems Co. Memory Analysis  Observe ► See time history of all allocations and deallocations ► Catch run-time errors ► Monitor memory leaks  Correct ► Back trace to source line of code – gives you direct place to fix the problem ► Remove leaks to increase stability  Profile ► See history of allocations and deallocations, peak usage, average usage, overhead  Optimize ► Match allocation distribution to memory allocation algorithm ► Reduce peak usage to save RAM cost

Memory-related Error Detection

15 out of 48 All content copyright of QNX Software Systems Co. Runtime Memory Error Detection  Certain C library calls (which cause system crashes) are intercepted ► Perform sanity check on parameters  e.g. strcpy(), memcpy()  Memory allocation functions are intercepted and recorded ► Perform a sanity check on pointer values  e.g. malloc(), calloc(), free(), etc  If these methods don’t trap the error and the application crashes, a core file is created ► Use for postmortem debugging

16 out of 48 All content copyright of QNX Software Systems Co. Run-time Memory Analysis malloc() strcpy() free() Debug Library str = (char *) malloc(10); strcpy(str,"AbCdEfGhIjK"); strcpy(mystring,str); free(str); Intercepted CallsApplication

17 out of 48 All content copyright of QNX Software Systems Co. Report Errors Error Back trace Source view

18 out of 48 All content copyright of QNX Software Systems Co. Postmortem Debugging Core file session Source view Memory/Variables Outline

Memory Leak Detection

20 out of 48 All content copyright of QNX Software Systems Co. Memory Leaks  Memory leaks are cases of missing deallocations for allocations  Memory allocations that are never freed are tagged as memory leaks  Rapid leaks are usually found early enough but slow leaks can lead to system instability and failure in the field  Examples: ► 128 byte leak every 500ms for 1 year = 7.7 MB ► 128 byte leak every 20s for 1 year = 197 KB ► Devices expected to run for very long periods in the field will eventually fail inexplicably

21 out of 48 All content copyright of QNX Software Systems Co. Memory Leaks Allocation/ deallocation details Distribution: time-order relationship Time selection

22 out of 48 All content copyright of QNX Software Systems Co. Memory Leaks – Details  Allocations/deallocations can be readily traced to code  Leaks are detected when there is no pointer reference to allocated memory  Potential memory leaks can still exist as outstanding traces Details with back trace

23 out of 48 All content copyright of QNX Software Systems Co. Memory Leaks – Details Details with back trace Source view

Memory Profiling

25 out of 48 All content copyright of QNX Software Systems Co. Memory Profiling  Memory usage can be observed over time ► Peak memory usage ► Distribution of allocation size ► Time / memory usage relationship ► Allocation algorithm overhead  Visual reference for memory usage can give more meaningful data ► Optimization based on observation

26 out of 48 All content copyright of QNX Software Systems Co. Memory Profiling Usage: allocated, free, overhead Usage: time- order relationships Time selection Time playback

27 out of 48 All content copyright of QNX Software Systems Co. Statistics Types of calls and number of requests Allocation size distribution

28 out of 48 All content copyright of QNX Software Systems Co. Allocation Size Distribution Histogram Distribution: time relationship Time selection Time playback

Memory Optimization

30 out of 48 All content copyright of QNX Software Systems Co. Memory Optimization  Two benefits of optimization work ► Reduce memory usage or address peak demands ► Ensure allocation algorithm matches usage pattern  Optimization is fed by observations from memory analysis  Results can be evaluated through same tools

31 out of 48 All content copyright of QNX Software Systems Co. Application Scenario  Program that creates a linked list of large data items ► List is used for a period of time then all elements are deleted  Program that used copy and forward for data packets ► There is new or malloc() for each copy  Program that has many class constructions ► Classes with large payload maybe used wastefully throughout program ► Developers may not understand or know about memory payload

32 out of 48 All content copyright of QNX Software Systems Co. Peak Usage & Memory Load Observe total usage and overhead over time Observe spikes in allocation/deallocation Observe trend in overhead

33 out of 48 All content copyright of QNX Software Systems Co. Peak Usage & Memory Load  Here is an example of a program does large free() of data structure ► Investigation would reveal: was this necessary? Was this a copy and forward scenario?

34 out of 48 All content copyright of QNX Software Systems Co. Memory Allocation Schemes  Most schemes break up available heap space into fixed block sizes  Allocation requests are distributed among the blocks  114 bytes = 24 bytes + 48 bytes + 48 bytes ( 120 bytes) ► Overhead for this allocation – 6 bytes (roughly 5%) bytes Overhead – extra memory used per allocation

35 out of 48 All content copyright of QNX Software Systems Co. Memory Allocation Distribution Observe pattern of allocations Observe time trends in usage

36 out of 48 All content copyright of QNX Software Systems Co. Memory Allocation Bands Observe pattern of allocations versus malloc() band implementation Observe time trends in band usage

37 out of 48 All content copyright of QNX Software Systems Co. Allocation Band Mismatch  Distribution of allocation size versus memory allocation block size (band) can be compared  Mismatch between band and allocation distribution can increase overhead  Memory allocation scheme can be tuned on a per- application basis

QNX ® Momentics ® Development Suite

39 out of 48 All content copyright of QNX Software Systems Co. QNX ® Momentics ® at a Glance

40 out of 48 All content copyright of QNX Software Systems Co. Built on the Eclipse Platform

41 out of 48 All content copyright of QNX Software Systems Co. Summary  Memory analysis is a key function in ensuring the quality of embedded systems  Developer productivity is enhanced when easy-to-use visual tools are provided  QNX Momentics Development Suite provides the tools needed to observe, correct, profile and optimize memory usage

Thank you! Bill Graham, Product Line Manager Development Tools Questions and Answers