Subject: Re: [PATCH] powerpc/64s: Add support for ASB_Notify on POWER9

From: Michael Neuling <[email-masked]>
Date: Mon, 14 Aug 2017 16:40:33 +1000

On Sat, 2017-08-05 at 14:28 +1000, Benjamin Herrenschmidt wrote:
> On Fri, 2017-08-04 at 16:56 +0200, Christophe Lombard wrote:
> > The POWER9 core supports a new feature: ASB_Notify which requires the
> > support of the Special Purpose Register: TIDR.
> > 
> > The ASB_Notify command, generated by the AFU, will attempt to
> > wake-up the host thread identified by the particular LPID:PID:TID.
> > 
> > The special register TIDR has to be updated to with the same value
> > present in the process element.
> > 
> > If the length of the register TIDR is 64bits, the CAPI Translation
> > Service Layer core (XSL9) for Power9 systems limits the size (16bits) of
> > the Thread ID when it generates the ASB_Notify message adding
> > PID:LPID:TID information from the context.
> > 
> > The content of the internal kernel Thread ID (32bits) can not therefore
> > be used to fulfill the register TIDR.
> > 
> > This patch allows to avoid this limitation by adding a new interface
> > for the user. The instructions mfspr/mtspr SPRN_TIDR are emulated,
> > save/restore SPRs (context switch) are updated and a new feature
> > (CPU_FTR_TIDR) is added to POWER9 system.
> 
> Those CPU_FTR_* are internal to the kernel. You probably also need a
> feature in AT_HWCAP2 to indicate to userspace that this is supported.
> 
> Also you put the onus of allocating the TIDs onto userspace which is a
> bit tricky. What happens if there are duplicate TIDs for example ? (ie,
> userspace doesn't allocate it or uses a library that spawns a thread)

I tend to agree.  I don't want userspace knowing anything about TIDR
allocations.  If we want userspace to receive one of these as_notifys, there
should be some abstract handle (like a file descriptor) that the kernel gives
out. That handle should be associated with an LPID/PID/TID tuple by the kernel.

This is similar to the PE number in CAPI. Most of the time userspace doesn't
need to know its PE number (there is some cases were a master needs to know a
slave PE, but that's the exception, not the rule).  Similarly, guests don't know
their LPID.  Processes don't know their PID. Threads shouldn't know the TID.

Also, Suka has posted a patch that does TID allocation in the kernel... 
http://patchwork.ozlabs.org/patch/799494/

Regards,
Mikey