[En-Nut-Discussion] What stops a Nut...

Brett Abbott Brett.Abbott at digital-telemetry.com
Mon Jul 24 04:58:07 CEST 2006


Hi

A regular scan of the "DEADDEEF" border that each thread maintains in 
memory (see the thread list demo below to check memory corruption is 
useful). 

Another thing that is useful is checking how much of memory within each 
thread has been used/unused over time - to allow you to optimise how 
much memory you allocate to a thread.  I do this by modifying the Create 
Thread function so it memsets all of the allocated memory to 0's when 
starting a thread, this allows you to scan the memory from the boundary, 
looking for the 1st occurence of non 0 - You have to do the memset to 
ensure clean RAM.


 Library Change.  os/arch/avr_thread.c, Alloc changed to use AllocClear 
to support mem monitoring

int CountZeroes(u_char *td_memory)  // See example code below for usage
{
    int myInt=0;
    u_char *myPtr=td_memory;
    while(*(myPtr++)==0)
        myInt++;
   
    return myInt;
}


                for (tdp = nutThreadList; tdp; tdp = tdp->td_next) {
                    sprintf(TextToPrint, "%s", tdp->td_name);
                    switch (tdp->td_state) {
                    case TDS_TERM:
                        sprintf(TextToPrint+strlen(TextToPrint),"\tTerm\t");
                        break;
                    case TDS_RUNNING:
                        sprintf(TextToPrint+strlen(TextToPrint),"\tRun\t");
                        break;
                    case TDS_READY:
                        
sprintf(TextToPrint+strlen(TextToPrint),"\tReady\t");
                        break;
                    case TDS_SLEEP:
                        
sprintf(TextToPrint+strlen(TextToPrint),"\tSleep\t");
                        break;
                    }
                    sprintf(TextToPrint+strlen(TextToPrint), "%u\t%u", 
(u_int)tdp->td_priority, (u_int) tdp->td_sp - (u_int) tdp->td_memory);
                    if (*((u_long *) tdp->td_memory) != DEADBEEF)
                        
sprintf(TextToPrint+strlen(TextToPrint),"\tCorrupted\t");
                    else
                        sprintf(TextToPrint+strlen(TextToPrint),"\tOK\t");

                    // Count the amount of untouched memory left in the 
stack for this thread
                    // This requires the patch to NutThreadCreate to 
clear allocated heap to be effective   
                    sprintf(TextToPrint+strlen(TextToPrint),"%d\t", 
CountZeroes(tdp->td_memory+16));

                    if ((tnp = (NUTTIMERINFO *) tdp->td_timer) != 0)
                        sprintf(TextToPrint+strlen(TextToPrint),"%lu\r", 
(u_long)tnp->tn_ticks_left);
                    else
                        sprintf(TextToPrint+strlen(TextToPrint),"None\r");

fprintf(yourtargetstream,                    TextToPrint);
  

Don Ingram wrote:
> Hi all,
>
> I am in the ongoing process of investigating an intermittent failure 
> of a protocol conversion application running on an AVR based unit & am 
> looking for suggestions on areas to instrument.
>
> Currently I am generating a set of tools for looking a trends in 
> memory usage ( heap & thread stack ),async interrupt rates, task cycle 
> times & states.  Henrik has suggested an interesting issue which may 
> result from incorrectly set priority levels locking out certain tasks 
> under high load from the network.
>
> The idea is to generate a histogram for each of these areas & hourly 
> write the data set to EEPROM.  As the current issue presents about 
> every 10 hours or so about 24 hrs of data storage should be fine.
>
> Any ideas on other areas that I should be monitoring?
>
>

-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------





More information about the En-Nut-Discussion mailing list