Shop OBEX P1 Docs P2 Docs Learn Events
How to count Cog usage with nearly all Spin files — Parallax Forums

How to count Cog usage with nearly all Spin files

HarleyHarley Posts: 997
edited 2010-07-09 17:14 in Propeller 1
I have rayman's 3.5" LCD and PTP board. Looking at all the demo files, I'm wondering how to count cog usage. This I'd not yet run into; mostly all Spin files. Do they all fit into one Spin 'space' and with the 'Stop's and the PASM only adding on to the one Spin cog, or what?

Below is this info included with the PTP Paint with my comments added on at the right. Would the cog count be 6 or 4 or 3 cogs? I'd guess THREE. I'm hoping, because I need to modify Paint mostly to code my main applications. And still have cogs left for PASD (1 cog more) or ViewPort (2 cogs more for 20 MHz sampling). I hope I've worded it clear enough.


───────────────────────────────────────
Parallax Propeller Chip Project Archive
───────────────────────────────────────

 Project :  "PTP_Paint"

Archived :  Monday, June 28, 2010 at 8:25:08 PM

    Tool :  Propeller Tool version 1.2.6


            PTP_Paint.spin
              │
              ├──PTP_LcdDriver.spin                              Spin w/stop + PASM
              │    │
              │    └──PTP_SPI_Spin.spin                         Spin only
              │
              ├──Graphics.spin                                      Spin w/stop + PASM
              │
              ├──Mouse.spin                                            - don't need
              │
              ├──PTP_i2cDriver.spin                               Spin only
              │
              ├──CalibrateCursor.dat                                - don't need
              │
              ├──Button1.dat                                           - don't need
              │
              ├──Button2.dat                                           - don't need
              │
              └──Button3.dat                                           - don't need


────────────────────
Parallax, Inc.
www.parallax.com
support@parallax.com
USA 916.624.8333

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko

Comments

  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 00:59
    Basically, if the code is launching any PASM, it's going to do it in another cog. So, you can check your spin files and see if they have any cognew or coginit commands in them.

    All of the spin code (generally) runs in one cog from HUB RAM (it's interpretered). PASM runs only in COG RAM, with the exception of LMM (and now TLMM!!!), which technically still runs in the COG, but can be loaded from HUB or elsewhere. (Note, you can load Spin in another cog, but you're still using cognew to do it.)

    There is a object in the OBEX that will tell you how many cogs your app is using/free.

    Bill

    Post Edited (wjsteele) : 7/9/2010 1:14:17 AM GMT
  • HarleyHarley Posts: 997
    edited 2010-07-09 02:03
    Bill, I think I found the 'cog counter' in OBEX. By Alex, under Tools? I'll give that a try.

    But was hoping to look at listing and say for sure the real count. If Spin it is all in Hub RAM, if one or more PASM then add all cogs used by them. I'd think then it is 1 for all Spin, plus 1 for each PASM cognew? Or might some Spin use an extra cog?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 09:13
    You're right, but Spin can start up another spin intreperter in another cog, but it's still using the cognew code. I don't see that in Ray's code.

    Bill
  • heaterheater Posts: 3,370
    edited 2010-07-09 09:32
    Harley: "But was hoping to look at listing and say for sure the real count."

    Of course you can get a listing of you compiled program if you compile it with BST (or Homespun I believe). In there you can search for all occurrences of coginit, cognew, cogstop. You can just as well search all the Spin source files for them as well.

    Sadly it's not really possible to tell how many cogs your program uses from doing just that.

    Cogs are started and stopped dynamically at run time. So in general the number of cogs used can vary with time as the program runs. It would be nice if the compiler could just report how many cogs are required at the end of compilation but it cannot as it has no idea about the dynamic behavior of the program as it runs. How would it know that FullDuplexSerial actually starts a cog. It would have to analyze the FDX code to see if a coginit/cogstart is called. Then it would have to analyze your app to see if you call the FDX start method. But that may depend on some external input. Basically can't be done. It's much the same problem as the compiler not knowing how much stack your code will use.

    What about code that uses coginit to start another spin or PASM code running in the same cog that is calling coginit, replacing the calling code?

    No, what you need is to:
    a) Understand all the code in your app and know how many cogs it will end up using.
    b) Hope that the author of any objects you use has documented it's cog usage.
    c) Run the thing and find out when it fails.
    d) Use a tool like Alex's 'cog counter'. But beware that foe complex programs the cog usage can changes as it runs.

    So far I have relied on a) for my code, b) for other objects and never ended up a c) yet[noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • HarleyHarley Posts: 997
    edited 2010-07-09 17:14
    Oh dear, I didn't imagine it would be so indeterminate from just looking through (even using Find) the source listings that one couldn't get a maximum cog count. Well, at least the code I've written/used I can determine the count fairly easily. Guess my applications are quite simple.

    Thanks guys, for the comments on this subject.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
Sign In or Register to comment.