From owner-freebsd-hackers@FreeBSD.ORG Mon May 13 17:53:59 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 167156A5; Mon, 13 May 2013 17:53:59 +0000 (UTC) (envelope-from leonerd@leonerd.org.uk) Received: from cel.leonerd.org.uk (cel.leonerd.org.uk [IPv6:2001:8b0:3f7::2]) by mx1.freebsd.org (Postfix) with ESMTP id D3032D7B; Mon, 13 May 2013 17:53:58 +0000 (UTC) Received: from shy.leonerd.org.uk (8.9.7.8.3.c.e.f.f.f.2.8.9.a.e.8.3.4.0.0.7.f.3.0.0.b.8.0.1.0.0.2.ip6.arpa [IPv6:2001:8b0:3f7:43:8ea9:82ff:fec3:8798]) by cel.leonerd.org.uk (Postfix) with ESMTPSA id 350671BDF9; Mon, 13 May 2013 18:53:58 +0100 (BST) Date: Mon, 13 May 2013 18:53:57 +0100 From: Paul "LeoNerd" Evans To: freebsd-hackers@freebsd.org, adrian@freebsd.org Subject: Re: Managing userland data pointers in kqueue/kevent Message-ID: <20130513185357.1c552be5@shy.leonerd.org.uk> In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/6Q8zy2xciqc2jDxe2EbUEQn"; protocol="application/pgp-signature" X-Mailman-Approved-At: Mon, 13 May 2013 18:02:49 +0000 Cc: Eugen-Andrei Gavriloaie X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 May 2013 17:53:59 -0000 --Sig_/6Q8zy2xciqc2jDxe2EbUEQn Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable [I'm not currently on the list so please forgive the manually-crafted reply] > I'm confused as to why this is still an issue. Sure, fix the kqueue > semantics and do it in a way that doesn't break backwards > compatibility. I suggested that. Add a user->kernel flag EV_DROPWATCH which, if present, causes kernel to send back to userland events with the kernel->user flag EV_DROPPING any time it drops the pointer. Then trivially userland just has to set that flag on all its events to the kernel, and remember to send those events back to userland when it does in fact drop them. These events can be trivially created from the knote_drop() function: http://fxr.watson.org/fxr/source/kern/kern_event.c#L2127 because that's called everywhere in the kernel that actually drops the watch. Which brings me onto the main reason why: It becomes a lot simpler to write userland code. When I wrote the original idea 3 years ago, it was after some research into what reasons would drop these watches in the kernel. By having the kernel tell userland, that future-proofs it a lot better. To further answer the threading questions: Having the locking point decided by the kernel and the event reflected back up to userland still with the pointer that kernel had simplifies all this locking. Now, userland doesn't have to contend on a Big Structure Lock around whatever data structure it uses to store all this information. It allows less userland contention. It's fully back-compatible, because all it does is adds a new user->kernel flag, that if the userland didn't know about, wouldn't set, and no behaviour is changed. If the flag -is- set then userland simply starts receiving a few extra events, or has another bit flag set on the events it was already receiving. Finally: I feel quite sure this feature is implementable in ballpark-50 lines of kernel-side code. I'd half-bet the documentation would be longer than that. It is truely a tiny addition of behaviour to export information the kernel already knows (namely: that it is calling knote_drop()). I can't see any objection to it. I'm quite sure more words and objection have been spent arguing it back and forth than it would have taken just to implement it initially. --=20 Paul "LeoNerd" Evans leonerd@leonerd.org.uk ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/ --Sig_/6Q8zy2xciqc2jDxe2EbUEQn Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlGRKLUACgkQvLS2TC8cBo1S7QCgpMos/w4W9caVZ9ThV4g+ZLAE BIUAoNjeTpokLjZu2v9wuSVxSEUreljc =TYPs -----END PGP SIGNATURE----- --Sig_/6Q8zy2xciqc2jDxe2EbUEQn--