From owner-freebsd-toolchain@FreeBSD.ORG Fri Jan 11 09:55:11 2013 Return-Path: Delivered-To: toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id F3650AED; Fri, 11 Jan 2013 09:55:10 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 515A6FFF; Fri, 11 Jan 2013 09:55:10 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r0B9sxiX045840; Fri, 11 Jan 2013 11:54:59 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r0B9sxiX045840 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r0B9sxTZ045839; Fri, 11 Jan 2013 11:54:59 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 11 Jan 2013 11:54:59 +0200 From: Konstantin Belousov To: arch@freebsd.org, toolchain@freebsd.org Subject: Re: Fast sigblock (AKA rtld speedup) Message-ID: <20130111095459.GZ2561@kib.kiev.ua> References: <20130107182235.GA65279@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NSDslKtQVY7LeFYu" Content-Disposition: inline In-Reply-To: <20130107182235.GA65279@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jan 2013 09:55:11 -0000 --NSDslKtQVY7LeFYu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 07, 2013 at 08:22:35PM +0200, Konstantin Belousov wrote: > Below is the forward of the patch for which I failed to obtain a private > review. Might be, the list generates more responses. >=20 > Our rtld has a performance bootleneck, typically exposed by the images > with the lot of the run-time relocation processing, and by the C++ > exception handling. We block the signals delivery during the rtld > performing the relocations, as well as for the dl_iterate_phdr(3) (the > later is used for finding the dwarf unwinding tables). >=20 > The signal blocking is needed to allow the rtld to resolve the symbols > for the signal handlers in the safe way, but also causes 2 syscalls > overhead per each rtld entry. >=20 > The proposed approach allows to shave off those two syscalls, doubling > the FreeBSD performance for the (silly) throw/catch C++ microbenchmark. >=20 > Date: Mon, 13 Aug 2012 15:26:00 +0300 > From: Konstantin Belousov >=20 > ... >=20 > The basic idea is to implement sigprocmask() as single write into usermode > address. If kernel needs to calculate the signal mask for current thread, > it takes into the consideration non-zero value of the word at the agreed > address. Also, usermode is informed about signals which were put on hold > due to fast sigblock active. >=20 > As I said, on my measurements in microbenchmark that did throw/catch in > a loop, I see equal user and system time spent for unpatched system, and > same user time with zero system time on patched system. >=20 > Patch can be improved further, e.g. it would be nice to allow rtld to fall > back to sigprocmask(2) if kernel does not support fast sigblock, to preve= nt > flag day. Also, the mask enforced by fast sigblock can be made configurab= le. >=20 > Note that libthr already blocks signals by catching them, and not using r= tld > service in the first line handler. I tried to make the change in the spir= it > of libthr interceptors, but handoff to libthr appears too complicated to > work. In fact, libthr can be changed to start using fast sigblock instead > of wrapping sigaction, but this is out of scope of the proposal right now. >=20 > Please comment. So there were no overly negative comments, and thanks to Alfred and David for useful notes. The patch at http://people.freebsd.org/~kib/misc/rtld-sigblock.2.patch is the commit candidate. Now kernel informs rtld about supprt for fast_sigblock with new auxv flag. Rtld can operate on old (and possibly future) kernels without fast_sigblock, rtld checks the auxv for presence of the ELF_BSDF_FASTSIGBLK flag before use. --NSDslKtQVY7LeFYu Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJQ7+FyAAoJEJDCuSvBvK1BsJYP/iWcrdR8vkZY7F0vNFXpBxjR ut2gpD7pkI4biwsZECz8HzyR6nOceyxENv7ufyVu9M2bkIvwb7mIIfgnjAkBzvik yRh/LOl7eY0GBJpYtykF3m9dp3s+hPvF+SBg1NjQD5x8snC8uIWlToNRxms24P9i 0sUn4KosmntfedrVlLgf2cuXR3QJzOs7h9A1O/RBjelcMVMB1E1SmatrrCqAVWhz EwwKBdOhtyOWtKXEY3tkcsjsjI5nlsUnBOs17mwO1vqID956xZmCQGXM1/sM8yWH 2TAzKa89l06E9ql11lM+z6gzQ6oJb587S8VRPXgwaZU4pIKbgq3jbz2uFcsQKUiz IONGZyZBhO2VrvJWccE/5uASnc24yMck4eHztkibm6SqyrG0qnUZLxNmL2bUQXiN yg+U/DRxXjBBCFWiDnD6U3x+JlVbv91vIsOtrOGbmsIpXeZJ8ggybDD1ejR7n8fN 7V9UXneHrqM2/j7xFwZElqL7DfALVYv5pSqe/n0kf0/RkOZk3GMo3qZLf48im1A+ 8+2Iwez9MZDeWlIAJJPyrIPitZppjLCOb2NJZKFznc/tTQVg8Ug3GM8EnlzvRbw/ XltAhJilvGXGrZrrqxLekFeV9UUc0rQldZ/Wel9xFmrS5DrYNd94PME/lbRdzrEY ilQiq6EeRxZ893rISj3Q =66cr -----END PGP SIGNATURE----- --NSDslKtQVY7LeFYu--