From owner-freebsd-emulation@FreeBSD.ORG Mon Oct 4 08:07:41 2010 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A2ECC1065696 for ; Mon, 4 Oct 2010 08:07:41 +0000 (UTC) (envelope-from giovanni.trematerra@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 3B55B8FC20 for ; Mon, 4 Oct 2010 08:07:40 +0000 (UTC) Received: by wyb29 with SMTP id 29so3887641wyb.13 for ; Mon, 04 Oct 2010 01:07:40 -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=G6SKSyP5WGlVloD4Y9G83iOPr/nd3Y1ba4WquVQ0mRe4wpUh3/BsgeIFrNzzwmrvcp +mDTOG1+/Zr4vugOkuDlGqYTpa99q42j8qM+DmXVrTPNUuJc0/q91bXHwbskPK/ndH9j 6uw11Ckkrb9fwoq26TsDTweuiQ7yTV/BnTagE= 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=UoxN36C7LplkifaHPrZcUbIKpA+gBqpjhINo94s07ej3VvsgRWQcB60oOeHu0JatjD RVCEBAahOnwgzd9ljQSwnxPYCqd+RTiLeh7lcMvZxqiofT9btudX7szAn5k8VMKN1T3M USyH0TJQDZcUZzgFlPZflmxlRi2QjXpsOZlDw= MIME-Version: 1.0 Received: by 10.227.156.67 with SMTP id v3mr7174669wbw.147.1286177800246; Mon, 04 Oct 2010 00:36:40 -0700 (PDT) Sender: giovanni.trematerra@gmail.com Received: by 10.227.144.203 with HTTP; Mon, 4 Oct 2010 00:36:40 -0700 (PDT) Date: Mon, 4 Oct 2010 09:36:40 +0200 X-Google-Sender-Auth: CPrx2wXgriJQFXxsSKa3gFk8uL0 Message-ID: From: Giovanni Trematerra To: freebsd-emulation@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: [PATCH] panic on boot with QEMU and multiple cpu emulated X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2010 08:07:41 -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);