[swift-corelibs-dev] libdispatch epoll port

Pierre Habouzit phabouzit at apple.com
Thu Dec 17 15:57:20 CST 2015


libev model isn’t compatible with dispatch model, and retrofiting one on top of the other will put you in a world of hurt, and would diverge from the OS X port greatly, which we’d like to avoid.

I originally thought you were replying to the thread about having the Runloop queues code in dispatch ported (for some reason your reply wasn’t attached to a mail thread for me and I got confused), and that one needs a raw interface with epoll to interact with CFRunlopp and that’s what I “replied” to.

I don’t think that moving away from likqueue is a good idea yet. Technically, dispatch is really interleaved with kqueue code, and libkqueue overhead is smaller than I originally thought, so I’ve kind of revisited that argument.

The one thing that will be painful for the port to an extent, is that kevents are now uniquified in kernel based on the ident + udata, said another way, if you watch the same file descriptor twice with two different udata’s, then it’s two different kevents in kernel. That is *NOT* the case with epoll, where uniquing is only based on the file-descriptor: if you EPOLL_CTL_ADD two different “udata” for the same fd, you get EEXIST, which means that you need to do multiplexing in userland (which dispatch used to do before kevent started taking udata into account).

That has impacts on the userland parallelism as all source registering and deregistering have to be serialized wrt each other. This is the hard part, not abstracting epoll.

-Pierre

> On Dec 17, 2015, at 1:44 PM, Thomas Greany via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> What about libev? http://software.schmorp.de/pkg/libev.html <http://software.schmorp.de/pkg/libev.html>
> 
> On Thu, Dec 17, 2015 at 12:36 PM, Dzianis Fedarenka via swift-corelibs-dev <swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>> wrote:
> >> On Dec 10, 2015, at 12:42 AM, Joakim Hassila via swift-corelibs-dev <swift-corelibs-dev at swift.org <http://swift.org/>> wrote:
> >>
> >> Hi,
> >>
> >>> On 8 dec. 2015, at 16:56, Pierre Habouzit <pierre at habouzit.net <http://habouzit.net/>> wrote:
> >>>
> >>> FWIW, this is my personal, let’s call it enlightened, opinion, based on my knowledge of dispatch and my past extensive system programming experience with Linux before I joined Apple.
> >>>
> >>> I think that long term, the best way to maintain a Linux libdispatch port is to go away from the libkqueue that tries to emulate kqueue fully, where dispatch only needs a small subset of the surface of kqueue. Given how source.c is written today, this is not a very small undertaking, but eventually dispatch source map to epoll_ctl(EPOLLONESHOT) very very well.
> >>
> >> That makes sense, could simplify the implementation (and keep thing cleaner). Then the follow up question is of course how to split/manage source.c (as Daniel pointed out there is the merging issue).
> > we can decide when/if someone tries to tackle it. I humbly recognize that I have no great idea of how to do so.
> 
> I have some experience in event multiplexing programming for linux. So it looks like interesting project for me. There is some conceptual questions which I think should be discussed:
> 
> 1) Obviously, kqueue and epoll have a little different semantics. For example: in linux timers, signals and socket can be presented as file descriptor and processed uniformly. Is there any chance that community will agree to develop separate API for linux?
> 2) Does anyone have long term vision about how to inject platform specific code into current implementation of dispatch_source? As far as I’ve read the source it’s heavily bound with kqueue semantics and «#ifdef»-way seems to be completely messy..(
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev <https://lists.swift.org/mailman/listinfo/swift-corelibs-dev>
> 
>  _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151217/86476633/attachment.html>


More information about the swift-corelibs-dev mailing list