Discussion Forum

Help adjusting task stack size

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Andre Moutinho
Posted
1-Sep-2010 23:28 GMT
Toolset
ARM
New! Help adjusting task stack size

Hello all,

I need to free more RAM memory in my application so the first thing will be reducing (optimizing) the task stack sizes.

I have created a check task that verify each stack area magic number and indicate the stack usage worst case. I run some test scenario and then adjust the stack sizes based on this worst case values.

I also tried to use the keil syntactic analyser (the htm file generated after compilation). This file gives me information concerning the stack usage of each task such as:

[Stack]
Max Depth = 624 + Unknown Stack Size

I have noticed that the real memory usage for each task is higher than the value indicated by the HTM file. If I set the stack memory as indicated by the HTM I get the stack overflow exception. So I adjusted the stack memory in a trial and error manner. But this is risky and demands much tests.

Does anyone can give me some advice on a better method to get the safer/optimized stack size value and how can I predict the "Unknown Stack Size" found in the HTM file?

Thanks
Andre Moutinho

Read-Only
Author
Hans-Bernhard Broeker
Posted
2-Sep-2010 19:53 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

I run some test scenario and then adjust the stack sizes based on this worst case values.

That plan is doomed to fail because those are not, actually, known to be the worst-case value values. They're just the worst case encountered during the particular tests you happened to run.

how can I predict the "Unknown Stack Size" found in the HTM file?

Most probably you can't. Nobody can, in the general case. What you can often do instead is avoid putting sources of unknown stack consumption into your program in the first place. The usual candidates are function pointers, recursion and any kind of assembly code.

Read-Only
Author
Andre Moutinho
Posted
2-Sep-2010 21:21 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

Hello,

I have a DEBUGPrintf() function in my project that uses the vsprintf() function.

int DEBUGPrintf(const char *szFmt, ...)
{

  char s[200];
  va_list vlArgList;
  va_start(vlArgList, szFmt);
  vsprintf(s, szFmt, vlArgList);
  va_end(vlArgList);
  DEBUGPuts(s);
  return (0);
}

The vsprintf() function is the source of the 'Unknown Stack Size' problem.
1) Does anyone know another way to implement such print function without using vsprintf()?
2) Does anyone know why the vsprintf() function causes this undefined stack usage?

Thanks
André Moutinho

Read-Only
Author
Hans-Bernhard Broeker
Posted
3-Sep-2010 19:25 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

1) Does anyone know another way to implement such print function without using vsprintf()?

No. There is none. Well, except the one using vsnprintf(), which would have the same problems as this one.

2) Does anyone know why the vsprintf() function causes this undefined stack usage?

That's because either nobody defined its stack usage for the analysis tool to know, or because its stack usage is actually unknown.

Your best bet may be to simply not use any of the *printf()/*scanf() family of functions.

Read-Only
Author
Andre Moutinho
Posted
3-Sep-2010 19:33 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

Your best bet may be to simply not use any of the *printf()/*scanf() family of functions.

Hello Hans, this is what I am doing now.

Thanks you
Andre

Read-Only
Author
Andre Moutinho
Posted
3-Sep-2010 19:41 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

Operations with unsigned int seems to cause the "Unknown Stack Size" problem. Does anyone know how to fix this?

Thanks
Andre

Read-Only
Author
Mike Kleshov
Posted
3-Sep-2010 21:51 GMT
Toolset
ARM
New! RE: Help adjusting task stack size

If reducing stack sizes doesn't free up enough memory, you might want to try reducing the number of tasks. Or even abandon multitasking altogether.

Next Thread | Thread List | Previous Thread Start a Thread | Settings