This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to understand ARMv8 'SEVL' instruction in spin-lock?

hi experts,    

    ARMv7 spin-lock use 'WFE' instruction to wait for lock release and use 'SEV' in spin-unlock to notify all cores.   

    but ARMv8 use 'SEVL; WFE' instructions in spin-lock, and no 'SEV' in lock release.


    Why v8 use 'SEVL' in spin-lock instead of 'SEV' in lock release? what's the advantage using 'SEVL' in spin-lock?   

    Thanks for your attention!

  • The SEVL is usually in the lock function, and it's often used to get around the lack of conditional execution.  In ARMv7-A (or ARMv8-A AArch32) you writing something like this:

      LDREX  r1, [r0]
      CMP    r1, #UNLOCKED
      BNE    lock

    It's using the WFE instruction with the NE (Not Equal) condition to go to sleep if it's not unlocked.  In A64 the WFE instruction is not conditional.  Which makes this a little trickier.  SEVL is one way to get round this, it sets the Event register only of the core you are running on.  So we can writing something like this:

      LDXR  w1, [x0]
      CBNZ  w1, loop

    The SEVL means that the first time we hit the WFE it will "wake" immediately.  Getting round the need for a conditional WFE.

    (NOTE: The code snippets are cut down versions of what is in the DS-5 startup_v8_ARMCompiler6 and smp_primes_A9x4-FVP examples.  In case you want to see the full code and play with it).

    Which leaves the question of why in ARMv8-A you don't always need the SEV in unlock/release function.  This is down to a change introduced in ARMv8-A where clearing the Global Monitor automatically generates an event (see D1.17.1 "Wait for Event mechanism and Send event" in the ARMv8-A Architecture Reference Manual).  There is nothing to stop you putting a SEV instruction in your unlock function anyway.