From owner-freebsd-current@FreeBSD.ORG Mon Oct 4 07:18:24 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 427DE1065673 for ; Mon, 4 Oct 2010 07:18:24 +0000 (UTC) (envelope-from giovanni.trematerra@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id CF2C68FC0A for ; Mon, 4 Oct 2010 07:18:23 +0000 (UTC) Received: by wwb17 with SMTP id 17so6301620wwb.31 for ; Mon, 04 Oct 2010 00:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=3A9DZKncomfiK4Fb54Gsa0QeZJwKeS9XMdkM4n/13u4=; b=JUDzgMovEuCH346RpBaIxPLQu4FcF5AH9AehQDre22u8ko7pjffSqzZWDT28v+ZDpA fkbLXYGYxNGOkcZ8plGjY79O1ya8wdxdAxGFWg+Yiybutpj66PIMO/uapkpCXyWGq89u rr7XGcA8FVvAQFUu3ZxrZPVOb/7XtzyDL+1Xk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=GWvqTY4b/7cKEMWMvZiad+rxG/7hI04kgNlBXwnH9NsleHx316oQkfJRL51oVL8ZB8 JxJBXDSElmqR5kUVs+N35h5UU3ZaZw0KpsIl24jlcsc4lKvWrAxpEWbz1nMxYC01P/RD 3CAXHmK5HShiIQEQdM9r/OerD/v2X+wqDdBBc= MIME-Version: 1.0 Received: by 10.227.24.141 with SMTP id v13mr7119175wbb.210.1286176702762; Mon, 04 Oct 2010 00:18:22 -0700 (PDT) Sender: giovanni.trematerra@gmail.com Received: by 10.227.144.203 with HTTP; Mon, 4 Oct 2010 00:18:22 -0700 (PDT) Date: Mon, 4 Oct 2010 09:18:22 +0200 X-Google-Sender-Auth: UOoevgjXC8HgTLibvpmyCIvFIVQ Message-ID: From: Giovanni Trematerra To: FreeBSD Current Content-Type: text/plain; charset=ISO-8859-1 Subject: [PATCH] panic on boot with QEMU a multiple cpu emulated X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2010 07:18:24 -0000 Qemu 0.11.1 installed from port with -CURRENT as host, emulating 8 CPU on a 8-way box makes my FreeBSD -CURRENT guest kernel, panic with this bt at boot: panic: sched_priority: invalid priority 230: nice 0, ticks 2289712 ftick 353 ltick 1363 tick pri 50 cpuid = 7 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2a kdb_backtrace() at kdb_backtrace+0x37 panic() at panic+0x182 sched_priority() at sched_priority+0x1f8 sched_clock() at sched_clock+0x136 statclock() at statclock+0xc6 handleevents() at handleevents+0xda timercb() at timercb+0x1cb lapic_handle_timer() at lapic_handle_timer+0xb2 Xtimerint() at Xtimerint+0x8d The panic is due a KASSERT in sched_priority (sched_ule.c) KASSERT(pri >= PRI_MIN_TIMESHARE && pri <= PRI_MAX_TIMESHARE, ("sched_priority: invalid priority %d: nice %d, " "ticks %d ftick %d ltick %d tick pri %d", pri, td->td_proc->p_nice, td->td_sched->ts_ticks, td->td_sched->ts_ftick, td->td_sched->ts_ltick, SCHED_PRI_TICKS(td->td_sched))); ts->ts_ticks is higher than what you could expect. I figured out that sched_tick is being passed a huge number of ticks elapsed for the cpu at startup by hardclock_anycpu (kern_clock.c). I assume that QEMU is not doing a proper job of distributing run-time amongst cores. My hack, below, will assure that we won't be running for more than 5s solid, if we have a huge number of ticks in input to sched_tick, which is something that ULE can still handle. I don't think it's worth to have the hack into the tree for now. I'm just posting it FYI. -- Gianni diff -r d16464301129 sys/kern/kern_clock.c --- a/sys/kern/kern_clock.c Thu Sep 23 11:56:35 2010 -0400 +++ b/sys/kern/kern_clock.c Sun Oct 03 17:53:39 2010 -0400 @@ -525,7 +525,7 @@ hardclock_anycpu(int cnt, int usermode) PROC_SUNLOCK(p); } thread_lock(td); - sched_tick(cnt); + sched_tick((cnt < (hz*10)/2) ? cnt : (hz*10)/2); td->td_flags |= flags; thread_unlock(td);