embedded xinu kernel programming

7
[email protected] UNIVERSITY AT BUFFALO Embedded Xinu Kernel Programming 5/24/2013 Amrita-UB-MSES-2013-13 1

Upload: lars-mendoza

Post on 30-Dec-2015

30 views

Category:

Documents


0 download

DESCRIPTION

Embedded Xinu Kernel Programming. [email protected] University at Buffalo. Topics. Creating a task/thread Ready/adding to the queue Resched /no rescheduling Semaphores of synchronization and mutual exclusion Memory operation errors including memory leak. Memory leaks etc. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

1

[email protected] AT BUFFALO

Embedded Xinu Kernel Programming

5/24/2013

Page 2: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

2

Topics

Creating a task/threadReady/adding to the queueResched/no reschedulingSemaphores of synchronization and mutual

exclusionMemory operation errors including memory

leak

5/24/2013

Page 3: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

3

Memory leaks etc.

See http://www.ibm.com/developerworks/aix/library/au-toughgame/

IBM developer works is good source of valuable information

Good practices while working with small footprint systems

Though there are tools available to detect most of these, it is always good to know the best practices in any technology and field

5/24/2013

Page 4: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

4

Known Pitfalls

These are some of the prominent pitfalls while working with memory at low level

Uninitialized memorychar *p = malloc (10); memset(p,’\0’,10);

Memory overwritechar *name = (char *) malloc(11); // Assign some value to name memcpy ( p,name,11);

Memory overeadchar *ptr = (char *)malloc(10); char name[20] ; memcpy ( name,ptr,20);

5/24/2013

Page 5: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

5

Known Pitfalls (contd.)

Memory leak: reassignmentchar *memoryArea = malloc(10); char *newArea = malloc(10);memoryArea = newArea;

Memory leak: freeing the parent area firstfree(memoryArea); //wrong//correct method is given belowfree( memoryArea->newArea); free(memoryArea);

5/24/2013

Page 6: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

6

Known Pitfalls (contd.)

Improper handling of return functionschar *func ( ) { return malloc(20); // make sure to memset this location to ‘\0’… }

void callingFunc ( ) { func ( ); // Problem lies here }

5/24/2013

Page 7: Embedded  Xinu  Kernel Programming

Amrita-UB-MSES-2013-13

7

Summary

5/24/2013

We discussed some things to pay attention to when designing systems at low level and deal with dynamic memory management.

This is especially critical for small embedded systems with limited memory.

Memory leaks are serious problem resulting in dramatic system slow down at runtime.