Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2001 16:09:49 -0800
From:      Luigi Rizzo <rizzo@aciri.org>
To:        current@freebsd.org
Cc:        peter@freebsd.org
Subject:   vm_zeropage priority problems.
Message-ID:  <20011218160949.B89864@iguana.aciri.org>

next in thread | raw e-mail | index | archive | help
[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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011218160949.B89864>