[LLVMdev] Finding safe thread suspension points while JIT-ing (was: Add pass run listeners to the pass manager.)

Juergen Ributzka juergen at apple.com
Tue May 13 11:49:10 PDT 2014


Sounds good. Lets get started by nailing down the C API and semantics for this first.

I mirrored the C API for the LLVM context diagnostic handler and used Andy’s suggested name for the callback.
The opaque handle was suggested by Duncan and can provide optional user specified information that is
provided back during the callback (i.e. barrier, etc).

Cheers,
Juergen 

Core.h:
typedef void (*LLVMMaySuspendCallback)(LLVMContextRef, void *);

/**
 * Set the may-suspend callback function for this context.
 *
 * @see LLVMContext::setMaySuspendCallback()
 */
void LLVMContextSetMaySuspendCallback(LLVMContextRef C,
                                      LLVMMaySuspendCallback Callback,
                                      void *OpaqueHandle);

LLVMContext.h:
/// \brief Registers a may-suspend callback with the context.
///
/// The may-suspend callback function may be called by LLVM to transfer
/// control back to the client that invoked the LLVM compilation. The client
/// is not garantueed to ever receive this callback. It is at the sole
/// discretion of LLVM to do so and only if it can guarantee that suspending
/// the thread won't block any forward progress in other LLVM contexts.
void setMaySuspendCallback(MaySuspendCallbackTy Callback, void *OpaqueHandle);

/// \brief Calls the may-suspend callback (if applicable).
///
/// This transfers control back to the client, which may suspend the current
/// thread. Only call this method when LLVM doesn't hold any global mutex or
/// cannot block the execution in another LLVM context.
void callMaySuspendCallback();

On May 12, 2014, at 5:26 PM, Nick Lewycky <nlewycky at google.com> wrote:

> Would you (or anyone) oppose a simple maySuspendContext() callback API? It would mean nothing more than the thread(s) for a given LLVM context can be suspended independent from other contexts.
> 
> I think this is the right approach. So a given thread hits a safe point, it optionally calls a "suspend check" or "i an safe to suspend right now" callback if set. It doesn't stop other threads, it doesn't continue until the function returns.
> 
> If you want to stop all threads then the user callback may contain a barrier and count down how many threads have stopped until it sees all of them.
> 
> Nick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140513/2ea7888c/attachment.html>


More information about the llvm-dev mailing list