From owner-cvs-src@FreeBSD.ORG Sat May 7 00:50:22 2005 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 16C4F16A4D4; Sat, 7 May 2005 00:50:22 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E58C943D88; Sat, 7 May 2005 00:50:21 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from [127.0.0.1] (davidxu@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j470oH5b070070; Sat, 7 May 2005 00:50:20 GMT (envelope-from davidxu@freebsd.org) Message-ID: <427C10D8.9060600@freebsd.org> Date: Sat, 07 May 2005 08:50:32 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.7.5) Gecko/20050402 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruce Evans References: <200505060737.j467b2R4041476@repoman.freebsd.org> <20050507043824.P12302@delplex.bde.org> In-Reply-To: <20050507043824.P12302@delplex.bde.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: cvs-src@freebsd.org cc: src-committers@freebsd.org cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/lib/libc/gmon mcount.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2005 00:50:22 -0000 Bruce Evans wrote: > On Fri, 6 May 2005, David Xu wrote: > >> davidxu 2005-05-06 07:37:01 UTC >> >> FreeBSD src repository >> >> Modified files: >> lib/libc/gmon mcount.c >> Log: >> Fix race by using atomic operation, with this change, both libpthread >> and libthr now can run profiling on SMP. >> >> Revision Changes Path >> 1.21 +5 -3 src/lib/libc/gmon/mcount.c > > > Doesn't userland need to wait for mcount() to become unbusy, like the > kernel > does? Just returning gives broken profiling. mcount() takes a long > time, > so there is a good chance of a thread being preempted while in mcount(). > Then I think profiling is effectively turned off until the thread in > mcount() is rescheduled and leaves mcount(). > > I don't know exactly how to avoid deadlock in userland. The kernel > just disables interrupts. Userland would have to stop rescheduling, > and do this without calling mcount() or dding much overhead. Note > that the kernel must disable interrupts and not just use > critical_enter(), > since if it used the latter then low level interrupt handling would > be complicated and broken by not being able to call mcount(). > > Bruce > > First, this is a bandaid to avoid deadlock, the deadlock is easy to be reproduced. Also, userland is different with kernel on profiling. if I understand it correctly, I can not call other functions in mcount(), otherwise, the cputime of those functions will be at top of gprof result, for system scope thread, we can not disable rescheduling, only kernel can do this. Also, signal handler will cause mcount to be reentered with same thread, so we have to disable signal, but you know I can not call other functions to disable signal(I don't know how to handle this for M:N threads). so I don't know how to fix all these problems. David Xu