[En-Nut-Discussion] GCC optimizations

Ole Reinhardt ole.reinhardt at embedded-it.de
Tue Mar 17 21:23:00 CET 2009


Hi, 

> I will try the 4.8 version as soon as I get a chance.  If I understand the
> abort handling in 4.8, it has a stack trace, also.  That would be beneficial
> in trying to further track this down.  Am I mistaken about this?

Yes, this might help. But in case of a stack underflow / overwritten
buffers, the failure (abort) will occur on a totaly different place
where the reason has to be searched.

> > if you gave your threads enough stack space. The resulting data aborts
> > might occur quite randomly as the stack usage is not always
> > deterministic and in case of an underrun there might be any (non
> > deterministic) data from other threads overwritten. This might (also
> > non
> > determinstic) lead to a data abort condition in some situtions.
> 
> In the cases where the data aborts occur, it's always in NutThreadSwitch or
> NutThreadKill.  

If I remember correctly there was in issue about data aborts during
NutThreadSwitch some time ago on this liste.... Perhaps it might be a
good idea to search the archive.

> Which demo code were you referring to?  This would be useful in a diagnostic
> page on our product.  

Sorry, I missed to paste the code :)

Here it is:

INFO and ERROR are just macros, that resolve to printf. So you can
easily substitute them by fprintf(stderr, ...).


void show_threads(void)
{
    NUTTHREADINFO *tdp;
    NUTTIMERINFO *tnp;
    char *buffer;
    buffer = malloc(4096);
    
    strcpy(buffer, ("List of threads with
name,state,prio,stack,mem,timeout follows\r\n"));

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

        if ((tnp = (NUTTIMERINFO *) tdp->td_timer) != 0)
            sprintf(&buffer[strlen(buffer)],"%lu\r\n",
tnp->tn_ticks_left);
        else
            sprintf(&buffer[strlen(buffer)],"None\r\n");
    }
    
    INFO("Threads: %s\r\n", buffer);
    free(buffer);
}

void test_threads(void)
{
    NUTTHREADINFO *tdp;
    u_int stack;
    
    for (tdp = nutThreadList; tdp; tdp = tdp->td_next) {
        stack = (u_int) tdp->td_sp - (u_int) tdp->td_memory;
        if ((tdp->td_name[0] == 'r') && (tdp->td_name[1] == 'x'))
continue;
        if ((tdp->td_name[0] == 'i') && (tdp->td_name[1] == 'd') &&
(tdp->td_name[2] == 'l')) continue;
        
        if (*((u_long *) tdp->td_memory) != DEADBEEF) {
            ERROR("!!! Corruptet: %s, %d\r\n", tdp->td_name, stack);
            show_threads();
        }
    
        if (stack < 700) {    
            ERROR("!!! StackLow: %s, %d\r\n", tdp->td_name, stack);
        }   
        if (stack < 300) {
            show_threads();
        }
    }
}

Bye,

Ole Reinhardt

-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT          Hard- und Softwarelösungen             |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|                      UstID / VAT:       DE198944716         |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list