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

Don Ingram don at led.com.au
Tue Jul 25 01:27:20 CEST 2006


Brett,

Thanks for that, it's getting built in ;-)

Cheers

Don

  Abbott wrote:
> 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);
>  
> 



More information about the En-Nut-Discussion mailing list