From owner-freebsd-toolchain@FreeBSD.ORG Fri Jan 11 20:49:53 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 872CF55A; Fri, 11 Jan 2013 20:49:53 +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 D7A23CD; Fri, 11 Jan 2013 20:49:52 +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 r0BKndIO014116; Fri, 11 Jan 2013 22:49:39 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r0BKndIO014116 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r0BKnc8c014115; Fri, 11 Jan 2013 22:49:38 +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 22:49:38 +0200 From: Konstantin Belousov To: David Xu Subject: Re: Fast sigblock (AKA rtld speedup) Message-ID: <20130111204938.GD2561@kib.kiev.ua> References: <20130107182235.GA65279@kib.kiev.ua> <20130111095459.GZ2561@kib.kiev.ua> <50EFE830.3030500@freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jYUWvSWTDpDT74zJ" Content-Disposition: inline In-Reply-To: <50EFE830.3030500@freebsd.org> 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 Cc: arch@freebsd.org, toolchain@freebsd.org 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 20:49:53 -0000 --jYUWvSWTDpDT74zJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 11, 2013 at 06:23:44PM +0800, David Xu wrote: > On 2013/01/11 17:54, Konstantin Belousov wrote: > > 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 priva= te > >> review. Might be, the list generates more responses. > >> > >> 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). > >> > >> 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. > >> > >> The proposed approach allows to shave off those two syscalls, doubling > >> the FreeBSD performance for the (silly) throw/catch C++ microbenchmark. > >> > >> Date: Mon, 13 Aug 2012 15:26:00 +0300 > >> From: Konstantin Belousov > >> > >> ... > >> > >> The basic idea is to implement sigprocmask() as single write into user= mode > >> address. If kernel needs to calculate the signal mask for current thre= ad, > >> it takes into the consideration non-zero value of the word at the agre= ed > >> address. Also, usermode is informed about signals which were put on ho= ld > >> due to fast sigblock active. > >> > >> 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, a= nd > >> same user time with zero system time on patched system. > >> > >> 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 pr= event > >> flag day. Also, the mask enforced by fast sigblock can be made configu= rable. > >> > >> Note that libthr already blocks signals by catching them, and not usin= g rtld > >> service in the first line handler. I tried to make the change in the s= pirit > >> of libthr interceptors, but handoff to libthr appears too complicated = to > >> work. In fact, libthr can be changed to start using fast sigblock inst= ead > >> of wrapping sigaction, but this is out of scope of the proposal right = now. > >> > >> Please comment. > > > > So there were no overly negative comments, and thanks to Alfred and Dav= id > > 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. > > >=20 > The patch looks fine to me. Sorry, I still have a question: > if I found a process does not responsing to a signal, now should we > check both its signal mask and fast block value ? but is there such > a tool available ? for example, in gdb. Fair enough. I added the facility to export the address of the fast sigblock word to the tools, and implemented the procstat extension to print the address with -j. You can indeed use gdb to look up the content of the word when debugging, after getting it address from procstat. http://people.freebsd.org/~kib/misc/rtld-sigblock.3.patch --jYUWvSWTDpDT74zJ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJQ8HriAAoJEJDCuSvBvK1BI/wP/i56RdjaKBiS48mkS24o2YHr yQ+NCpZE6Wj1PI37MnL/gPOPZyqoGEdsqdhDRfG0+dhEf2X1NCnOhWWHIaq4V2BJ CDhvpqLLU/Fd3N9N/JmaZvrHpZF7Bsvs36PLCAD7EChoX4KTnC9lEUqsfa9YUNuR 9eT7DmfSqGAcfUTlIs2EbudDI/EWkhXdx6PVAKGd6lBW74UQH6yeLrFJoB5ly6b9 dVEbufpcqy1OxbniM0BX9UgZUmbb3d3bE/tgrS/wrxo1gh4iMu5a2Ll/8zS6+PZm kcJ6pvp+4rTdmUxrgfmSlwgN+NIQpXGFOWtTR4zgyjOgK2uUkbUd9qujBHwmLoFS fJ7UIQCCyra3+GFPoEuRaHdrCMvEoR10J6zEHWN6TceIfei7FY0Qb2fbfRtW1If5 4p1tWoL0D+3lmO8aitdWQNIGEir4qXHQMFYW6zIBJC2qV8eMvxLW8uyCnq809vd7 5dmmwkybRR8n5vJQ2dXZwiWPF/K6o0WF+wI8bGMTAa4TO/TdKsy6AW1AtHOv33nO 8NChYxPM3s3YmjjKwp0qfrhHw7zacrooBPR3sHGpoDEMHSHsQESk5yOy0o63vSqG jJWAus44Lij0aQOCy4KJmkE7K41g0bUuUumSW4+D0+noDegykndojE5ulvj7RmPN z2GrZFFWTZd3O9NIbo7m =1Olc -----END PGP SIGNATURE----- --jYUWvSWTDpDT74zJ--