From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9488 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: FreeBSD's Google Summer of Code 2016 Date: Sat, 5 Mar 2016 18:32:54 -0500 Message-ID: <20160305233254.GL9349@brightrain.aerifal.cx> References: <56DB3D70.8010601@FreeBSD.org> <20160305212517.GK9349@brightrain.aerifal.cx> <56DB6095.4060204@FreeBSD.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1457220796 6745 80.91.229.3 (5 Mar 2016 23:33:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Mar 2016 23:33:16 +0000 (UTC) Cc: musl@lists.openwall.com To: Pedro Giffuni Original-X-From: musl-return-9501-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 06 00:33:15 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1acLhD-0007Ku-79 for gllmg-musl@m.gmane.org; Sun, 06 Mar 2016 00:33:15 +0100 Original-Received: (qmail 21515 invoked by uid 550); 5 Mar 2016 23:33:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 20473 invoked from network); 5 Mar 2016 23:33:11 -0000 Content-Disposition: inline In-Reply-To: <56DB6095.4060204@FreeBSD.org> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:9488 Archived-At: On Sat, Mar 05, 2016 at 05:41:25PM -0500, Pedro Giffuni wrote: > First of all, great to hear there is interest on the musl side too. > > I think the biggest precedent of porting linux-oriented C libraries > came from Debian's kFreeBSD. We accomodated a little by for them > by defining __FreeBSD_kernel__ in sys/param.h. > > While using the optional linux-abi futex in FreeBSD could be an option, > it is not really the cleanest option. The Debian guys did a port of > NPTL using regular pthreads: > > http://thread.gmane.org/gmane.linux.debian.ports.bsd/11702 > > I am certain this will require more research but it would be useful > for other ports as well. Glibc/NPTL has a lot of what I'd call "gratuitous abstraction" (like the lll stuff) in their pthread primitives which makes this "possible". I call it gratuitous because it's really really hard to achieve correct implementations of the pthread sync primitives that don't have serious corner-case bugs, and it's unlikely that their abstractions actually suffice to make correct alternate implementations. musl does not have any such abstraction. We require a compare-and-swap operation or equivalent on which arbitrary atomic operations can be constructed, a futex or equivalent operation that's roughly while(*addr==expected) sleep(), and implement all the sync primitives just once on top of these. In a worst case, futex can be emulated trivially by having wait and wake both be nops; then everything just spins at 100% cpu load. Of course this does not give very nice results. It's possible futex could be emulated better; certainly it can be within a single process where the futex wait queue could just be implemented in userspace, but emulating process-shared futexes effectively this way sounds nontrivial. Since the functionality is already there in the kernel, though, just exposing it sounds like a much better solution to me. Rich