Shop OBEX P1 Docs P2 Docs Learn Events
Easiest Method to find stack size for cogs. — Parallax Forums

Easiest Method to find stack size for cogs.

FORDFORD Posts: 221
edited 2012-10-18 15:23 in Propeller 1
Howdy All,

While I try to get my head around stack sizing correctly for a few cogs in a program...

I was wondering if a rough initial method would be to use the parallax spin editor, and after compiling, just click on the PUB line at the top of the method...

...Then the number of bytes in the method show at the bottom of the screen.

Is it ok to just divide the bytes by 4, add another say 20 longs, and use this as a stack size ?

Sorry in advance if my question is completely off track, I'm not far off understanding the stack stuff, but have a little way to go.

Edit : I tried to use the stack finding method to do it, but failed miserably :(

regards to All,
Chris.

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-10-18 07:25
    Take a look at Application Note - AN019: Measuring Stack Space for Parallel Processes
  • FORDFORD Posts: 221
    edited 2012-10-18 07:27
    Thanks Mike,
    I've actually just printed that out an hour or so ago, and will have a read in the morning (head spinning and tired now)...

    Is my question about the byte data in the editor close to the mark or should I steer clear of it ?

    Cheers,
    'Chris
  • Mike GMike G Posts: 2,702
    edited 2012-10-18 07:36
    Is my question about the byte data in the editor close to the mark or should I steer clear of it ?
    I'm not sure or qualified to answer.

    I usually experiment. Rough estimate or pick a high number for stack allocation. Then do a brute force halving until I find the threshold.
  • FORDFORD Posts: 221
    edited 2012-10-18 07:39
    cheers Mike,

    yes I have done that (extra space allocated), and have plenty of spare memory.

    Would be keen to hear from somebody at Parallax to comment on the pro's / cons of using the bytes per PUB reported in the editor.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-10-18 08:25
    The bytes per PUB number tells you how many program bytecodes are used by the method. It doesn't tell you how many stack bytes are used. The number of stack longs used by a method is a sum of the bytes used by the stack frame, calling parameters and local variables plus the space used by any methods that are called. You also have to account for the space used by methods called by methods that you call, and there is a small amount of the stack used as scratch-pad memory when evaluating expressions. You can get a rough idea of the number of bytes needed by looking at methods that have a lot of local variables, or call methods that call other methods, and so one.

    The easiest approach is to use Mike G's approach where you use large stacks at first. There's at least one method in the OBEX that will pre-fill the stacks with a known pattern, and then you can measure how much of the stack was unused after running your program.
  • FORDFORD Posts: 221
    edited 2012-10-18 15:23
    Thanks Dave,
    Your reply has cleared that up for me, and thanks for the tip for the obex object, I'll start searching for it now.
Sign In or Register to comment.