From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 22 22:18:06 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 96E7C16A4CE for ; Tue, 22 Feb 2005 22:18:06 +0000 (GMT) Received: from mail23.sea5.speakeasy.net (mail23.sea5.speakeasy.net [69.17.117.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id 53F6543D54 for ; Tue, 22 Feb 2005 22:18:06 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 19920 invoked from network); 22 Feb 2005 22:18:06 -0000 Received: from server.baldwin.cx ([216.27.160.63]) (envelope-sender )AES256-SHA encrypted SMTP for ; 22 Feb 2005 22:18:05 -0000 Received: from [10.50.40.202] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id j1MMHvg7017494; Tue, 22 Feb 2005 17:17:58 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-hackers@FreeBSD.org Date: Tue, 22 Feb 2005 15:34:41 -0500 User-Agent: KMail/1.6.2 References: <000801c51327$0e2bf020$58e243a4@ash> <20050215132020.GA376@pm514-9.comsys.ntu-kpi.kiev.ua> In-Reply-To: <20050215132020.GA376@pm514-9.comsys.ntu-kpi.kiev.ua> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200502221534.41979.jhb@FreeBSD.org> X-Spam-Status: No, score=-102.8 required=4.2 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx cc: Andrey Simonenko cc: Ashwin Chandra Subject: Re: Kernel monitor, the return X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Feb 2005 22:18:06 -0000 On Tuesday 15 February 2005 08:20 am, Andrey Simonenko wrote: > On Mon, Feb 14, 2005 at 10:24:50PM -0800, Ashwin Chandra wrote: > > In trying to create a simple kernel thread that prints out all > > the processes data and stack size, i still get a panic fault > > (vm_fault on no entry) at the printf statement...ive narrowed > > it down to the ru_idrss variable that is causing the problem, > > Definitely ru_idrss cannot cause any error, may be you made > such desition, because arguments are pushed to the stack > in the reverse order. p->p_stats pointer causes the error. > > > im not sure why > > (I think that) If some process is not running, then you cannot > use p->p_stats without additional checks for memory p->p_stats > points to, since p->p_stats points to u_stats in struct user{}, > which can be swapped out if a process is not running. > > Actually you can read this in the comment before struct user{} > in /sys/sys/user.h. > > >. I thought maybe I was not locking properly or > > obseriving correct mutexes, but I have tried everything. > > You'll get an error at some time, because of incorrect usage > (really not usage) of locks. > > > If anyone > > knows why the fault is occurring at the printf, please let me know. =) > > Following code works on my system: > > ---- > > sx_slock(&allproc_lock); > > FOREACH_PROC_IN_SYSTEM(p) { > mtx_lock_spin(&sched_lock); > PROC_LOCK(p); > printf("proc %ld:", (long)p->p_pid); > if ((p->p_sflag & PS_INMEM) && p->p_stats != NULL) > printf(" ru_isrss %ld, rui_idrss %ld\n", p->p_stats->p_ru.ru_isrss, > p->p_stats->p_ru.ru_idrss); else { > if (!(p->p_sflag & PS_INMEM)) > printf(" !PS_INMEM"); > if (p->p_stats == NULL) > printf(" p_stats == NULL"); > } > printf("\n"); > PROC_UNLOCK(p); > mtx_unlock(&sched_lock); > } > > sx_sunlock(&allproc_lock); You don't need sched_lock to check PS_INMEM, proc lock is sufficient (PS_INMEM is magic this way). If you did though, you would lock proc first, then sched_lock. You can _not_ lock a regular mutex (proc lock) after a spin mutex (sched_lock) or you can deadlock. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org