This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

task stack overflow

Other Parts Discussed in Thread: SYSBIOS

i'm trying to learn my self how to use the heapmultibuff and the task status monitored and i found something strange and i don't know i miss something or not.

i had a task with 2k stack and i allocated inside a task arrays with size larger than the 2K, so i would expect that i will have an error with stack overflow or another indication, but unfortunately, it didn't and when i check the ROV for the task details i got that the peak stack size very small, Any idea?

  • Hi Mohamed,

    A few questions. How are you declaring the local arrays ? And are these local arrays being initialized and used in the app ? If they are not used, the compiler will most likely optimize them out.

    Best,

    Ashish

  • Also, if you're allocating memory dynamically, it will be allocated from heap, not stack.

  • Hello Guys,

    Sorry for replying late but it seems that the picture that i capture during my first post is removed my somehow, anyway.

    i'm taking about the array that is allocated inside the task function, so they should be allocated inside the task stack, and the following are the pic that i capture, the first one is when i'm allocating arrays and some local variable that will fully consume the stack and the second when when i added 100 byte to some of the array while the ROV is displaying 0 in the used stack amount. i hope this time the pic reach you.

    BTW, i was in the middle of debugging when i got the screen shoots, and the optimization is disabled.

    thanks,

    Mohamed Fawzy

  • Hi Mohamed,

    Your first picture shows that the task stack overflowed. The stack peak is 2048 (same as stack size) and marked in red. If you hover the mouse over the highlighted stack peak, it will show a stack overrun message.

    It looks to me that the app is behaving as expected. With large local arrays, the stack is overflowing.

    Best,

    Ashish

  • Hi Ashish,

    actually i don't have any concern in the first picture, i just put it to persuade you that the arrays are located in the stack and  if the arrays size are increased, it won't be noticed by the ROV and this was obvious in the second picture.

    so my post is for the second image.

    Best Regards,

    Mohamed Fawzy

  • Mohamed,
    BIOS did notice the stack overflow and that is evident from the detailed view that shows the stack peak.

    Did you get the basic view screenshot at the same time you got the detailed view screenshot ?

    Best,

    Ashish

  • Hi,

    Actually, what I understood is that the two screenshots are from different codes. The second one shows that when clearly there's a stack overflow (because we had it with a smaller array) the basic view shows a stack size of zero and altough we can see that there's an overflow using ROV, BIOS didn't throw an error message in console. Maybe there wasn't a context switch?

    Regards

    J.

  • Hi Ashish,

    i thought that to give you the chance to help me more to send you the code that i used for testing and two screen shoots for the basic view and the detailed view.

    Best Regards,

    Mohamed Fawzy4774.memory_TivaTM4C129XNCZAD.rar

  • Hi Mohamed,

    I imported your project and tried it out on my machine. I believe you are not seeing the stack overflow because the buffers are declared but never used. The compiler optimizes them out. In order to see the stack overflow problem you would have to use the buffers so the compiler allocates them on the stack. Try adding the following to your task2 func:

    Void task2Fxn(UArg arg0, UArg arg1)
    {
    	UInt idx;
    	Char buf0[1024];
    
    	// Add bug init code
    	for (idx = 0; idx < 1024; idx++) {
    		buf0[idx] = idx;
    	}
    ....
    }

    With the above code, you will notice ROV show the stack has overflowed.

    Best,

    Ashish

  • Hi Ashish,

    I believe that it isn't  an optimization issue, such that the stack overflow will be detected if the stack usage is below certain limit and upper this limit the stack over flow won't be detected, and you can check it on your setup and here is the update to the function

    Void task2Fxn(UArg arg0, UArg arg1)

    {

    HeapMultiBuf_Params prms;

    HeapMultiBuf_Handle heap;

    /* Create the buffers to manage */

    Char buf0[900];

    Char buf1[256];

    Char buf2[1640];

    int idx;

    Ptr bufs[1];

    System_printf("\n************************************************");

    System_printf("Initial task2 heap status\n");

    /* print initial task1Heap status */

    // printHeapStats(heap);

    for (idx = 0; idx < 900; idx++) {

    buf0[idx] = idx;

    }

    for (idx = 0; idx < 256; idx++) {

    buf1[idx] = idx;

    }

    for (idx = 0; idx < 1640; idx++) {

    buf2[idx] = idx;

    }

    anyway, all my questions regarding this topic because I want to know how can I discover the over flow in the runtime so I can get the reasonable reaction inside the application.

    so please advice.

    thanks,

    Mohamed Fawzy

  • Hi,

    Check section 3.5.4 (Testing for Stack Overflow, page 88) of SYS/BIOS user guide (www.ti.com/lit/pdf/spruex3) and see if it's what you want.

    Regards

    J

  • Hi,

    the "Task_stat" will return the same result like the ROV and both of them can't detect the overflow for the example that I demo previously.

    Thanks,

    Mohamed Fawzy

  • Hi,

    I tested your last code and modifyied it to include the stack test of sys/bios user guide:


        Task_Stat statbuf; /* declare buffer */    

        System_printf("\n************************************************");

        System_printf("Initial task2 heap status\n");

        /* print initial task1Heap status */

        // printHeapStats(heap);
        
        Task_stat(Task_self(), &statbuf); /* call func to get status */
        System_printf("%d\n", statbuf.used);
        if (statbuf.used > (statbuf.stackSize * 9 / 10)) {
            System_printf("Over 90% of task's stack is in use.\n");
        }

        for (idx = 0; idx < 900; idx++) {
            buf0[idx] = idx;
        }

        Task_stat(Task_self(), &statbuf);
        System_printf("%d\n", statbuf.used);
        if (statbuf.used > (statbuf.stackSize * 9 / 10)) {
            System_printf("Over 90% of task's stack is in use.\n");
        }

        for (idx = 0; idx < 256; idx++) {
            buf1[idx] = idx;
        }

        Task_stat(Task_self(), &statbuf);
        System_printf("%d\n", statbuf.used);
        if (statbuf.used > (statbuf.stackSize * 9 / 10)) {
            System_printf("Over 90% of task's stack is in use.\n");
        }

        for (idx = 0; idx < 1640; idx++) {

            buf2[idx] = idx;
        }

        Task_stat(Task_self(), &statbuf);
        System_printf("%d\n", statbuf.used);
        if (statbuf.used > (statbuf.stackSize * 9 / 10)) {
            System_printf("Over 90% of task's stack is in use.\n");
        }

    The results I get are: (I'm using BIOS 6.33.6.50 and XDC 3.24.5.48, also C6000 compiler 7.4.0)

    [TMS320C66x_0]
    [TMS320C66x_0] ************************************************Initial task2 heap status
    [TMS320C66x_0] 68
    [TMS320C66x_0] -134810124
    [TMS320C66x_0] Over 90 of task's stack is in use.
    [TMS320C66x_0] -134810124
    [TMS320C66x_0] Over 90 of task's stack is in use.
    [TMS320C66x_0] -134810124
    [TMS320C66x_0] Over 90 of task's stack is in use.
    [TMS320C66x_0] ti.sysbios.knl.Task: line 330: E_stackOverflow: Task 0x90000020 stack overflow.
    [TMS320C66x_0] xdc.runtime.Error.raise: terminating execution


    You can see by the results (-134810124), that there was an overflow, altough bios error message is printed only only when the task exits.

    Regards

    J