From owner-freebsd-arch@FreeBSD.ORG Mon Jan 7 20:18:51 2013 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 12DCA58C; Mon, 7 Jan 2013 20:18:51 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) by mx1.freebsd.org (Postfix) with ESMTP id AB44733C; Mon, 7 Jan 2013 20:18:50 +0000 (UTC) Received: from JRE-MBP-2.local (c-50-143-148-105.hsd1.ca.comcast.net [50.143.148.105]) (authenticated bits=0) by vps1.elischer.org (8.14.5/8.14.5) with ESMTP id r07KImEt070010 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 7 Jan 2013 12:18:49 -0800 (PST) (envelope-from julian@freebsd.org) Message-ID: <50EB2DA1.5090306@freebsd.org> Date: Mon, 07 Jan 2013 12:18:41 -0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Konstantin Belousov Subject: Re: Fast sigblock (AKA rtld speedup) References: <20130107182235.GA65279@kib.kiev.ua> In-Reply-To: <20130107182235.GA65279@kib.kiev.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: arch@freebsd.org, toolchain@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2013 20:18:51 -0000 On 1/7/13 10:22 AM, 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. > > 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 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. > > 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. > > 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 prevent > flag day. Also, the mask enforced by fast sigblock can be made configurable. > > Note that libthr already blocks signals by catching them, and not using rtld > service in the first line handler. I tried to make the change in the spirit > 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. Is there any danger that an upriveliged user program can trick the kernel into doing anything it shouldn't by manipulating either the agreed upon address or the contents of the mask at the address? (even reading something by seeing what sigs get masked) This was an issue with the M:N threading package and resulted in extra syscalls to get around the problem. (I forget the details).