From owner-freebsd-hackers@freebsd.org Mon Mar 13 13:39:22 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CE242D08B3D for ; Mon, 13 Mar 2017 13:39:22 +0000 (UTC) (envelope-from pho@holm.cc) Received: from relay01.pair.com (relay01.pair.com [209.68.5.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AD8861AAA; Mon, 13 Mar 2017 13:39:22 +0000 (UTC) (envelope-from pho@holm.cc) Received: from x2.osted.lan (87-58-223-204-dynamic.dk.customer.tdc.net [87.58.223.204]) by relay01.pair.com (Postfix) with ESMTP id 9834CD00B47; Mon, 13 Mar 2017 09:39:20 -0400 (EDT) Received: from x2.osted.lan (localhost [127.0.0.1]) by x2.osted.lan (8.14.9/8.14.9) with ESMTP id v2DDdI4g058077 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 14:39:18 +0100 (CET) (envelope-from pho@x2.osted.lan) Received: (from pho@localhost) by x2.osted.lan (8.14.9/8.14.9/Submit) id v2DDdIn2058076; Mon, 13 Mar 2017 14:39:18 +0100 (CET) (envelope-from pho) Date: Mon, 13 Mar 2017 14:39:18 +0100 From: Peter Holm To: Hans Petter Selasky Cc: Mark Johnston , freebsd-hackers@FreeBSD.org Subject: Re: draining high-frequency callouts Message-ID: <20170313133918.GA57972@x2.osted.lan> References: <20170110205711.GA86449@wkstn-mjohnston.west.isilon.com> <20170313082120.GA44651@x2.osted.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Mar 2017 13:39:22 -0000 On Mon, Mar 13, 2017 at 09:27:59AM +0100, Hans Petter Selasky wrote: > On 03/13/17 09:21, Peter Holm wrote: > > On Tue, Jan 10, 2017 at 12:57:12PM -0800, Mark Johnston wrote: > >> I'm occasionally seeing an assertion failure in softclock_call_cc() when > >> running DTrace tests on a system with hz=10000. The assertion > >> (c->c_flags & CALLOUT_ACTIVE) != 0 is failing while a thread is > >> concurrently draining the callout, which runs at a high frequency. At > >> the time of the panic, that thread is spinning on the per-CPU callout > >> lock after having been awoken from "codrain", and CALLOUT_PENDING is > >> set on the callout. The callout is direct, i.e., it is executed in hard > >> interrupt context. > >> > >> I think this is what's happening: > >> - callout_drain() is called while the callout is executing but after the > >> callout has rescheduled itself, and goes to sleep after having cleared > >> CALLOUT_ACTIVE. > >> - softclock_call_cc() wakes up the callout_drain() caller, but the > >> callout fires again before the caller is scheduled. > >> - the second softclock_call_cc() call sees that CALLOUT_ACTIVE is > >> cleared and panics. > >> > >> Is there anything that prevents this scenario? Is it really correct to > >> leave CALLOUT_ACTIVE cleared when the per-CPU callout lock must be > >> dropped in order to acquire a sleepqueue lock? > >> > > > > Is this the same problem? > > > > panic: softclock_call_cc: act 0xfffff8000de64800 0 > > cpuid = 10 > > time = 1489389893 > > KDB: stack backtrace: > > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0f984c9660 > > vpanic() at vpanic+0x19c/frame 0xfffffe0f984c96e0 > > kassert_panic() at kassert_panic+0x126/frame 0xfffffe0f984c9750 > > softclock_call_cc() at softclock_call_cc+0xae/frame 0xfffffe0f984c98f0 > > softclock() at softclock+0x12c/frame 0xfffffe0f984c9930 > > intr_event_execute_handlers() at intr_event_execute_handlers+0x248/frame 0xfffffe0f984c9980 > > ithread_execute_handlers() at ithread_execute_handlers+0x47/frame 0xfffffe0f984c99b0 > > ithread_loop() at ithread_loop+0xfc/frame 0xfffffe0f984c9a30 > > fork_exit() at fork_exit+0x13b/frame 0xfffffe0f984c9ab0 > > > > https://people.freebsd.org/~pho/stress/log/kevent7-2.txt > > > > I first spotted this @ 12.0-CURRENT #2 r305652M: Fri Sep 9 13:09:03 CEST 2016 > > It's quite easy to reproduce. > > > > Hi, > > It depends on the trigger. The panic above just means the callout > structure was referred after being freed. Either a drain call is missing > or the callout escaped drain. > > Can you run this test with a kernel built from projects/hps_head aswell? > No problem there. I ran the test for 3 hours without any problems. - Peter