Page MenuHomeFreeBSD

Powerpc64: Enable Hardware Transactional Memory
Needs ReviewPublic

Authored by jhibbits on Apr 30 2018, 6:39 PM.



This patch enable Hardware Transactional Memory (HTM) facility.

The facility is only enabled on a process that executes a HTM instruction. It
will raise and facility trap, which will enable flag the process with PCB_HTM,
from there after, the context switch will save and restore the 3 SPRs that are
associated with HTM.

Diff Detail

Lint OK
No Unit Test Coverage
Build Status
Buildable 19060
Build 18691: arc lint + arc unit

Event Timeline

jhibbits added inline comments.May 9 2018, 2:31 PM

Why not make these return bool? It looks like they're not used anywhere other than conditional checks.


I think SIGTRAP is the wrong signal here. Maybe SIGILL with ucode of ILL_ILLTRP (illegal trap)?


Maybe we want to abort the transaction and kill the process in here? SIGILL, or SIGTRAP, or such like that? I don't think it's right to just ignore a trap instruction.

Actually, reading above, the transaction is aborted already anyway at this point so why not follow through? I'm not sure what the right thing to do is. Maybe, like above, it should be SIGILL/ILL_ILLTRP.

Nathan, do you have an opinion? marked an inline comment as done.May 16 2018, 2:56 PM updated this revision to Diff 42625.

Changes according to the Justin's review:

  • Changed return type for htm_enabled, htm_transactional and htm_suspended
  • Returning SIGILL if calling systemcall (instead of SIGTRAP) inside a transaction.
  • Returning SIGILL instead of ignoring a trap instruction inside a transaction, thus, avoiding calling kdb_trap() also.

Hi Justin,

Right, the tabort just dommed the transaction, but it is still suspended, and it will be aborted when we return the userspace (rfid). In this case, the transaction will try to continue and it will fail, returning to the the next line after tbegin. (usually a bne XX).

I just created another revision with SIGILL/ILL_ILLTRP, but I needed to avoid adding a breakpoint inside the transaction, as showed in my new patch at db_trap_glue.

The code looks fine to me. Can you include a test for it? You showed me the torture test, so that'd be good to include in tools/tools. With a test, I'll approve it.

Add aditional tests. Mainly two things:

  • Instead of testing for transactional states, look for active (Transactional + Suspended)
  • Avoid signal handling inside a transaction, since the code will be rolled back.

Adding additional testsuite for the code.

  • Powerpc64: Enable Hardware Transactional Memory
  • Powerpc64: Add HTM example

This patchset has one caveat at this time that will be fixed soon. If we go into kernel space during the transaction, and the process is rescheduled to another cpu, the transaction state will be on the original CPU, and the new CPU will not have the same CPU state, caused an undefined behaviour.

The right way to solve it is calling 'treclaim' (reclaim the checkpointed values from registers and save them in memory) and, later, calling trechekpoint (put the register back to the checkpointed area, i.e, loading the checkpointed registers, calling trecheckpoint, and restoring the GPRs, once the CPU is rescheduled.

In order to do so, I will need to call 'treclaim' instead of 'tabort' at the beginning of the execption (in file sys/powerpc/powerpc/trap.c). and implement treclaim, which is not very trivial, since it will put all the registers back to userspace while we are in kernel space. Later, call trecheckpoint when a new process, which was aborted in the middle of a transaction, is rescheduled back to the CPU. Can you pull out the pcb.h and pcpu.h changes into a separate diff? That way we can get that in before the KBI freeze, and wait until 12.1 to get the actual code in. Once KBI is frozen it's frozen for the full 12.0 life, and any KBI breakage we want to perform will have to wait for 13.0.


One thing to note is you need to adjust the padding down below, else it should CTASSERT. I'm surprised it doesn't already. This may have changed recently, though. Can you check to confirm?


Hi Justin,

Sure. I also included the struct pcb change, since I am not sure if that will also be considered kABI.

The change is at

jhibbits commandeered this revision.

Will take this to completion.