Shop OBEX P1 Docs P2 Docs Learn Events
OR — Parallax Forums

OR

I'm not arguing for any further expansion of the instruction set... I'm just trying to figure out how to do this with the current instruction set.

let's say that I have two different cogs interested in testing and then writing to two different bits of the same byte in hub memory...
at nearly the same time... they are contending cogs. If each cog operates on its bit of interest and then writes the result back... one of the cog's bits is going to be overwritten.

It would be handy if a Cog could issue a directive to OR a hub byte rather than simply writing to it... but we can't and we don't want Chip to add the logic for reasons that we all know and Ken can easily explain:)

So... can the first cog that has access to a hub byte... lock it for reading and writing until it is done... after which the other Cog can access it? How?

Comments

  • Heater.Heater. Posts: 21,230
    As far as I know the Prop II has locks just like the P1.

    It may be quicker and easier to keep your bits in separate bytes so they are individually updated atomically and OR them to together when you want to use them.
  • You have the same set of LOCK instructions as the Propeller except with 16 locks now.

    The lock/semaphore bit statuses and transitions are also monitored by each COG as events, so you can POLL AND WAIT on them like the other events and also register an ISR to handle an interrupt caused by a lock transition.
    POLLHLK/WAITHLK event flag

    Cleared on ‘SETHLK D/#’, which selects edge and hub LOCK bit:

    where D/# is %xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxEE_LLLL

    %EE: 00 = off
    01 = rising edge
    10 = falling edge
    11 = any edge

    %LLLL: LOCK number 0..15

    Set whenever the selected LOCK edge occurs.
    Also cleared on POLLHLK/WAITHLK.
  • rjo__rjo__ Posts: 2,114
    so... let's say I set a lock in cog xx set for a specific byte and cog yy tries to access that byte... but knows nothing about the lock... what happens?
  • Cog yy can read the byte without using the lock, but it must use the lock if both cogs want to write to the byte.
  • rjo__rjo__ Posts: 2,114
    Thanks guys
  • A lock's use enforces a contract between two or more COGS anyone deciding not to be a party to the contract can access the data any way they want.
  • to make this clear here, locks do not lock anything.

    BOTH cogs have to agree on lock number, checking/setting and releasing the lock for each access.

    the point is that a normal read or write is atomic. But if you read, modify and write back you need 3 instructions and are not atomic anymore.

    Therefore the locks. They basically provide you with one bit changed and the old value in one instruction to assure no other cog can do it at the same time.

    But using locks is cooperative, so nothing hinders any cog to write over that memory location(s) you want to share.

    Enjoy!

    Mike



  • rjo__rjo__ Posts: 2,114
    uh-huh

    Well... there is more than one way to do it. I'll just do it another way:)

  • potatoheadpotatohead Posts: 10,261
    edited 2015-11-15 15:29
    Can you make the accesses follow some sort of pattern? If so, they can be coordinated mathmatically. Have that math output addresses, and all the worker bees call it to request their bytes or longs, whatever.



  • rjo__rjo__ Posts: 2,114
    I haven't gotten there yet... just looking ahead to see what I need. In this case, I am talking about parallelizing pixel searches, which are used in several different ways. The way around this jog in the road will probably be to isolate pixel domains, so that two cogs would never search the same pixel at the same time.

    In the past, I know that at one step in the process, limiting the domain caused noise in intermediate results... which translated to less density in the final result. Previously, I experimented with isolated domains simply to speed up the process... to give the processor exponentially less to think about. Trading time for fidelity.

    This is all about differential analysis. So, when you blindly isolate domains, you have no concept what you are doing to the differentials at the borders of your domain.

    I am going to be testing some new general approaches to dealing with both the differentials and the noise. So, I really can't anticipate the final impact. That is the really fun and exciting stuff to me... we are all a little different. This kind of stuff I really like.
  • I am quite interested myself.

    Will be looking forward to your adventures.

  • rjo__rjo__ Posts: 2,114
    lots-o-fun
Sign In or Register to comment.