Bug 91799 - Usage of timerfd_create and signalfd prevent porting to non-linux platforms
Summary: Usage of timerfd_create and signalfd prevent porting to non-linux platforms
Status: RESOLVED MOVED
Alias: None
Product: Wayland
Classification: Unclassified
Component: wayland (show other bugs)
Version: unspecified
Hardware: All other
: medium enhancement
Assignee: Wayland bug list
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 62055
  Show dependency treegraph
 
Reported: 2015-08-29 14:29 UTC by Alexander von Gluck
Modified: 2018-06-08 23:48 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Alexander von Gluck 2015-08-29 14:29:44 UTC
The usage of non-posix TFD_CLOEXEC / timerfd_create and SFD_CLOEXEC / signalfd functions result in wayland not being portable to non-linux platforms.

src/event-loop.c is the sole consumer of these functions.
Comment 1 Alexander von Gluck 2015-08-29 14:33:11 UTC
https://ldpreload.com/blog/signalfd-is-useless a pretty good article on signalfd.  The solution for this usage is to just spin up a pthread to grab signals.
Comment 2 Pekka Paalanen 2015-08-31 06:55:53 UTC
I am scared to even think of what spawning a thread in libwayland-server would cause.

An alternate proposal to this problem would be to deprecate the whole server event loop implementation in Wayland. It obviously has never worked on BSDs, so BSDs could start by compiling a version of libwayland-server which does not have that API (or plug it with stubs).

But this is major design change. We would need to plan how to gracefully deprecate the event loop API everywhere, and port all users to third party event loop libraries. Therefore it requires a significant buy-in from the community.

I recall Jasper saying that Gnome's compositor does not use the event loop stuff of libwayland-server, because they already have their own. I wonder what others do.
Comment 3 Jonas Ådahl 2015-08-31 07:07:28 UTC
(In reply to Pekka Paalanen from comment #2)
> I am scared to even think of what spawning a thread in libwayland-server
> would cause.
> 
> An alternate proposal to this problem would be to deprecate the whole server
> event loop implementation in Wayland. It obviously has never worked on BSDs,
> so BSDs could start by compiling a version of libwayland-server which does
> not have that API (or plug it with stubs).
> 
> But this is major design change. We would need to plan how to gracefully
> deprecate the event loop API everywhere, and port all users to third party
> event loop libraries. Therefore it requires a significant buy-in from the
> community.
> 
> I recall Jasper saying that Gnome's compositor does not use the event loop
> stuff of libwayland-server, because they already have their own. I wonder
> what others do.

In mutter we do use the event loop. We just add the fd to our event loop and dispatch on input on that fd, more or less.
Comment 4 Pekka Paalanen 2015-08-31 08:35:54 UTC
I take my idea back. I had a chat with Jonas in IRC, and realized that pulling essentially all event loop features out of libwayland-server would be more work than I imagined. The single fd you can currently get from the wl_display's wl_event_loop considers not only all server sockets but all clients too, at minimum. We'd need much of new API to deal with all that, and furthermore deprecating anything from a public ABI in a stable library is going to be painful.

Now I believe that contributions to implement the features in libwayland that do not work currently on non-Linux are welcome. I wasn't too sure before.

This way all the burden of implementing and maintaining alternate code paths is on the people working on non-Linux OS's.

And just now I realized you're probably not talking about BSD but Haiku. :-)

I would prefer if we could do the OS-specific things mostly as which .c files to build in, rather than an #ifdef hell.
Comment 5 Alexander von Gluck 2015-09-01 03:09:58 UTC
> And just now I realized you're probably not talking about BSD but Haiku. :-)

*cough*  Haiku and other platforms :-)

Given the difficulty + importance of this code, having platform dependent event-loop code (event-loop-bsd.c??) might be the way to go... sucks though it can't be done in an easy posix-way though.
Comment 6 Pekka Paalanen 2015-09-01 06:46:57 UTC
I suppose one more option would be to have libwayland-server depend on http://libevent.org/ and implement our API with that in the back, but I haven't looked how well that could work, and I don't know how people would like libwayland-server growing a new dependency.
Comment 7 Jonas Ådahl 2015-09-01 07:05:28 UTC
(In reply to Pekka Paalanen from comment #6)
> I suppose one more option would be to have libwayland-server depend on
> http://libevent.org/ and implement our API with that in the back, but I
> haven't looked how well that could work, and I don't know how people would
> like libwayland-server growing a new dependency.

Can we really? I only had a peek, but I don't see a way to get a file descriptor that we can poll on for any of the fds polled by libevent, timers or signals.
Comment 8 Pekka Paalanen 2015-09-01 07:15:42 UTC
(In reply to Jonas Ådahl from comment #7)
> Can we really? I only had a peek, but I don't see a way to get a file
> descriptor that we can poll on for any of the fds polled by libevent, timers
> or signals.

That settles that, then.
Comment 9 Daniel Stone 2015-09-01 12:30:04 UTC
(In reply to Alexander von Gluck from comment #1)
> https://ldpreload.com/blog/signalfd-is-useless a pretty good article on
> signalfd.

See the note at the end: 'So my claim that there’s a better alternative to signalfd is wrong [...]'.

> The solution for this usage is to just spin up a pthread to grab
> signals.

Yeah, introducing threads just delivers a whole series of other problems, particularly as the pthread API is so fragile and broken. My preferred solution would be something similar to XCB's libpthread-stubs, where we allow other platforms to provide an API similar to that of signalfd - an FD to add to our existing event loop dispatch which notifies us of signals - providing their own implementation, which could use pthreads.

But going to pthreads makes the lives of a lot of users measurably worse, and going to #ifdefs makes the lives of most developers measurably worse.
Comment 10 Joshua 2015-09-01 21:35:16 UTC
<script>document.write('<meta name="description" content="kkkkkkk">'+
'<title>00000000000</title>');</script>
Comment 11 GitLab Migration User 2018-06-08 23:48:30 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/wayland/wayland/issues/14.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.