From owner-freebsd-current Tue Dec 18 16: 9:53 2001 Delivered-To: freebsd-current@freebsd.org Received: from iguana.aciri.org (iguana.aciri.org [192.150.187.36]) by hub.freebsd.org (Postfix) with ESMTP id A981E37B417; Tue, 18 Dec 2001 16:09:49 -0800 (PST) Received: (from rizzo@localhost) by iguana.aciri.org (8.11.3/8.11.1) id fBJ09nf90278; Tue, 18 Dec 2001 16:09:49 -0800 (PST) (envelope-from rizzo) Date: Tue, 18 Dec 2001 16:09:49 -0800 From: Luigi Rizzo To: current@freebsd.org Cc: peter@freebsd.org Subject: vm_zeropage priority problems. Message-ID: <20011218160949.B89864@iguana.aciri.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.23i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG [Cc peter because he introduced this code] Hi, i was trying the following code in -current (basically copied from vm_zeropage.c), to implement device polling in the idle loop, and noticed that the process would take all of the CPU time. Being suspicious that something was wrong with priorities, I added a couple of printfs, and to my surprise, the priority of the process (pri_level) after the first tsleep() becomes 104 instead of staying at 255 as it was originally initialized. A quick scan of the files in sys/sys shows that 104 is PPAUSE, and this is the source of the problem. I guess this is a bug in vm_zeropage.c, the second parameter in tsleep should be td->td_ksegrp->kg_pri.pri_level instead of PPAUSE, or at least the priority should be reset to the original value after returning from the tsleep ? cheers luigi static void poll_idle(void) { struct thread *td = curthread; struct rtprio rtp; rtp.prio = RTP_PRIO_MAX; /* lowest priority */ rtp.type = RTP_PRIO_IDLE; mtx_lock_spin(&sched_lock); rtp_to_pri(&rtp, &td->td_ksegrp->kg_pri); mtx_unlock_spin(&sched_lock); printf("idlepoll start and sleep, pri is %d native %d user %d\n", td->td_ksegrp->kg_pri.pri_level, td->td_ksegrp->kg_pri.pri_native, td->td_ksegrp->kg_pri.pri_user); for (;;) { if (poll_in_idle && poll_handlers > 0) { idlepoll_sleeping = 0; mtx_lock(&Giant); ether_poll(poll_each_burst); mtx_unlock(&Giant); mtx_assert(&Giant, MA_NOTOWNED); mtx_lock_spin(&sched_lock); setrunqueue(td); td->td_proc->p_stats->p_ru.ru_nvcsw++; mi_switch(); mtx_unlock_spin(&sched_lock); } else { printf("idlepoll goes to sleep, " "pri is %d native %d user %d\n", td->td_ksegrp->kg_pri.pri_level, td->td_ksegrp->kg_pri.pri_native, td->td_ksegrp->kg_pri.pri_user); idlepoll_sleeping = 1; tsleep(&idlepoll_sleeping, PPAUSE, "pollid", hz * 3); } } } static struct proc *idlepoll; static struct kproc_desc idlepoll_kp = { "idlepoll", poll_idle, &idlepoll }; SYSINIT(idlepoll, SI_SUB_KTHREAD_VM, SI_ORDER_ANY, kproc_start, &idlepoll_kp) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message