Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Nov 2001 18:36:41 -0800
From:      Peter Wemm <peter@wemm.org>
To:        Luigi Rizzo <rizzo@aciri.org>
Cc:        John Baldwin <jhb@FreeBSD.ORG>, current@FreeBSD.ORG
Subject:   Re: where is the idle_loop in current ? 
Message-ID:  <20011124023641.56C0F380D@overcee.netplex.com.au>
In-Reply-To: <20011123151522.B58238@iguana.aciri.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
Luigi Rizzo wrote:
> In order to port my network polling stuff to current, I was looking
> at ways to do things within the "idle loop", and was pointed to
> the idle_proc() or vm_pagezero() .  I am listing below the code
> for these kernel threads (I hope the name is the correct one).

idle_proc isn't a real process.  It has to be guaranteed to be runnable
at any time. pgzero is a real idle priority thread.

> I do not follow, however, the reason why these two threads periodically
> give up the CPU, given that their priority is (i guess) lower than
> any other thread in the system, so any event that should wake up
> a thread would immediately cause their preemption.
> Where am i wrong ?

processes while in kernel mode cannot be preempted by another higher
priority process.  Once they have the cpu, they either have to return
to userland (which kernel threads dont do), or block on something, or give
up the cpu.

> 	cheers
> 	luigi
> 
> 
> 
> 	static void
> 	vm_pagezero(void)
> 	{
> 	    struct thread *td = curthread;
> 	    struct rtprio rtp;
> 	    int pages = 0;
> 
> 	    rtp.prio = RTP_PRIO_MAX;
> 	    rtp.type = RTP_PRIO_IDLE;
> 	    mtx_lock_spin(&sched_lock); 
> 	    rtp_to_pri(&rtp, &td->td_ksegrp->kg_pri);
> 	    mtx_unlock_spin(&sched_lock);
> 
> 	    for (;;) {
> 		if (vm_page_zero_check()) {
> 		    pages += vm_page_zero_idle();
> 		    if (pages > idlezero_maxrun) {
> 			mtx_lock_spin(&sched_lock);
> 			setrunqueue(td);
> 			td->td_proc->p_stats->p_ru.ru_nvcsw++;
> 			mi_switch();
> 			mtx_unlock_spin(&sched_lock);
> 			pages = 0;
> 		    }
> 		} else {
> 		    tsleep(&zero_state, PPAUSE, "pgzero", hz * 300);
> 		    pages = 0;
> 		}
> 	    }
> 	}
> 
> 	/*
> 	 * idle process context
> 	 */
> 	static void
> 	idle_proc(void *dummy)
> 	{
> 	    for (;;) {
> 		mtx_assert(&Giant, MA_NOTOWNED);
> 
> 		while (procrunnable() == 0) {
> 		    /*
> 		     * This is a good place to put things to be done in
> 		     * the background, including sanity checks.
> 		     */
> 	#ifdef __i386__
> 		    cpu_idle();
> 	#endif
> 		}
> 
> 		mtx_lock_spin(&sched_lock);
> 		curproc->p_stats->p_ru.ru_nvcsw++;
> 		mi_switch();
> 		mtx_unlock_spin(&sched_lock);
> 	    }
> 	}
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-current" in the body of the message
> 
> 

Cheers,
-Peter
--
Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au
"All of this is for nothing if we don't go to the stars" - JMS/B5


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?20011124023641.56C0F380D>