Knowing how much stack to allocate
CassLan
Posts: 586
Hello, I guess up until now I've been running everything in one cog, but its time to use the propeller the way it was meant to be used.
I've been reading the manual, and it seems pretty straight forward, in this example from the manual 6 longs are allocated for stackspace for the cog, how does one know how much to allocate?
Also, how do people know how many cogs they have left? I have seen this in screenshots, but havent found it in the manual.
Thanks,
Rick
I've been reading the manual, and it seems pretty straight forward, in this example from the manual 6 longs are allocated for stackspace for the cog, how does one know how much to allocate?
VAR long SqStack[noparse][[/noparse]6] 'Stack space for Square cog PUB Main | X X := 2 'Initialize X cognew(Square(@X), @SqStack) 'Launch square cog <check X here> 'Loop here and check X PUB Square(XAddr) 'Square the value at XAddr repeat 'Repeat the following endlessly long[noparse][[/noparse]XAddr] *= long[noparse][[/noparse]XAddr] ' Square value, store back waitcnt(2_000_000 + cnt) ' Wait 2 million cycles
Also, how do people know how many cogs they have left? I have seen this in screenshots, but havent found it in the manual.
Thanks,
Rick
Comments
1b) You can add a piece to your program that initializes the stack space to some unique pattern, then you exercise your program and look to see how much of this pattern gets overwritten. For this, you have to estimate the largest possible stack area needed and add a "fudge factor".
1c) You can just estimate the largest possible stack area needed and add a "fudge factor".
2) You attempt to start a cog (with an assembly program that just consists of a jump instruction to itself). If successful, you save the cog number and do it again. If it fails, you know how many cogs can be started and you go back through the saved list of cog numbers and stop each one so they're available again.
That makes allot of sense...if I write all "FF"s and then give the program access to all the space, I can observe how many address "FF"s get overwritten..Is there a way to see this in action? Or would that require ViewPort?
Rick
There's also an object in the Exchange to count the number of available cogs.
(It's about half-way into the Webinar.)
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Check out: Protoboard Introduction , Propeller Cookbook 1.4 & Software Index
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Check out the StackLength demo program (in Propeller Library Demos from the pull-down above the folder view in the Propeller Tool's Integrated Explorer).
As OBC mentioned, we talked about this today in my webinar.· A number of video clips (including that one) will be available as soon as possible on the archive page for our webinars... unfortunately, we couldn't get those clips up there today (sorry), but we will make them available soon.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Jeff Martin
· Sr. Software Engineer
· Parallax, Inc.