[swift-corelibs-dev] libdispatch roadmap and api addition proposal

Daniel A. Steffen das at apple.com
Mon Dec 7 16:11:58 CST 2015


Hi Joakim,

> On Dec 7, 2015, at 4:55, Joakim Hassila via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> Hi,
> 
> I think (and hope) that this is the proper forum for a few questions wrt to libdispatch, otherwise any pointers are appreciated.
> 
> We are currently using libdispatch extensively on Linux (and Solaris for a while longer…) based on the previous version available from Mac OS forge (with later additions merged from opensource.apple.com) over time.

FWIW I’ve updated the macosforge svn repo trunk to match with github swift-corelibs-libdispatch trunk (sans the PRs, excecpt for my buildsystem one), but going forward we are likely going to retire the macosforge repository in favor of the github one.

> 
> I have a few questions on how (particularly Apple folks) view this going forward:
> 
> First, the previous port to Linux/Solaris of libdispatch was dependent on libkqueue and more importantly on libpthread_workqueue (to have some heuristics for managing the number of threads when lacking kernel support).
> 
> How do you view this, would you consider integrating support for libpthread_workqueue, or would you have another preference for how to manage this on other platforms (Linux for starters, but essentially any lacking the pthread_workqueue interface)?

yes, staying with libpthread_workqueue is the focus of the current Linux porting effort, but it may make sense to move to something more native over time, e.g. like on FreeBSD where a version of the kernel workqueue was implemented natively.

> 
> Secondly, we have extended the public libdispatch API internally with one more flavor of dispatching, let’s call it ‘dispatch_async_inline’ - the semantics being ‘perform the processing of the work synchronously if we wouldn’t block the calling thread, if we would block, instead perform the work as a normal dispatch_async’.
> 
> Would such a change be considered to be integrated, or should we keep our internal diffs indefinitely? Just to understand if it is worth the effort with a nicely packaged pull request or not...
> 
> The rationale for the API is that we are quite latency sensitive and want to use inline processing up until the point where we can’t keep up with the available work, at which point we would switch to asynchronous processing seamlessly (we have multiple producers). This means that the thread calling this API can be stolen for a significant amount of time (emptying the queue it was assigned to), but when the system is under ‘light' load, we don’t need to incur the wakeup penalty for a completely asynchronous dispatch.

sounds familiar, have we talked to about this in the past somewhere ?

we actually have something quite similar internal to the library already: _dispatch_barrier_trysync_f

	https://github.com/apple/swift-corelibs-libdispatch/blob/master/src/queue.c#L3089

but it currently (intentionally) ignores anything about the target queue hierarchy of the queue passed in (e.g. it will allow the sync even if the target queue is busy or suspended), so is not suitable as a general facility.

There are various technical reasons why we don’t believe this primitive in all generality is a good idea, Pierre is writing up an email about that so I won’t go into details here.

Daniel

> 
> Cheers,
> 
> Joakim
> 
> PS Big kudos to whoever at Apple is responsible for driving fundamentals like this out as OSS…



More information about the swift-corelibs-dev mailing list