From owner-freebsd-sparc64@FreeBSD.ORG Tue Jul 20 18:16:13 2010 Return-Path: Delivered-To: freebsd-sparc64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 476DA1065676; Tue, 20 Jul 2010 18:16:13 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 17DA98FC0C; Tue, 20 Jul 2010 18:16:13 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id BC08746B2A; Tue, 20 Jul 2010 14:16:12 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D83B78A04F; Tue, 20 Jul 2010 14:16:11 -0400 (EDT) From: John Baldwin To: freebsd-sparc64@freebsd.org Date: Tue, 20 Jul 2010 13:54:02 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100217; KDE/4.4.5; amd64; ; ) References: <4C404018.6040405@FreeBSD.org> <4C41D99B.10202@FreeBSD.org> <20100718140508.GX4706@alchemy.franken.de> In-Reply-To: <20100718140508.GX4706@alchemy.franken.de> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201007201354.02827.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 20 Jul 2010 14:16:11 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Alexander Motin , Marius Strobl Subject: Re: [RFC] Event timers on sparc64/sun4v X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jul 2010 18:16:13 -0000 On Sunday, July 18, 2010 10:05:08 am Marius Strobl wrote: > On Sat, Jul 17, 2010 at 07:26:03PM +0300, Alexander Motin wrote: > > By the way I have some doubts about tick_get_timecount_mp() correctness. > > It tries to bind thread to BSP, but what if it is called inside > > interrupt handler, or under lock, or some else. I have doubt binding > > will work in that case. > > I've no idea whether sched_bind() works under locks etc as > there's no man page describing it, however as it requires > curthread to be locked and thread_lock() itself uses a > spin lock and locking(9) basically says that acquiring a > spinlock with any other lock held is okay I assume that > the whole thing is fine with any lock held. Also if there > were such restrictions I'd expect there some KASSERTs etc > to be in place in the functions invovled preventing > incorrect use but tick_get_timecount_mp() doesn't trigger > such. It isn't safe mostly because sched_bind() might need to context switch if you aren't currently running on the desired CPU. If you do that with another spin lock held you should hit this KASSERT(): KASSERT(td->td_critnest == 1 || (td->td_critnest == 2 && (td->td_owepreempt) && (flags & SW_INVOL) != 0 && newtd == NULL) || panicstr, ("mi_switch: switch in a critical section")); Since td_critnest will be > 1 and flags will have SW_VOL set instead of SW_INVOL. Really critical_exit() is the only place that is allowed to call mi_switch() with td_critnest != 1, but ULE doesn't even do that now. > Apart from that I'm not really happy about that construct > myself but I don't see an alternative to always bind to > the same CPU when reading the tick counter in order to > get reliable results and in US-IIIi-based machines there > just isn't another piece of hardware besides the per-CPU > stick and tick counters that could be used as a timecounter > available. You could check td_critnest perhaps in your routine and if it is non-zero just return the cached value of the timecounter from the last time it was polled from tc_ticktock() (effectively turning those instances of getfootime() into just footime()). Things like gettimeofday() would still be correct as they can safely bind to the BSP, and I doubt many interrupt handlers are actually using getfootime(). -- John Baldwin