From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 2 02:31:25 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 49A281065678 for ; Thu, 2 Aug 2012 02:31:25 +0000 (UTC) (envelope-from dr2867@pacbell.net) Received: from nm2-vm0.bullet.mail.ne1.yahoo.com (nm2-vm0.bullet.mail.ne1.yahoo.com [98.138.91.39]) by mx1.freebsd.org (Postfix) with SMTP id F01238FC18 for ; Thu, 2 Aug 2012 02:31:24 +0000 (UTC) Received: from [98.138.90.52] by nm2.bullet.mail.ne1.yahoo.com with NNFMP; 02 Aug 2012 02:31:18 -0000 Received: from [68.142.200.226] by tm5.bullet.mail.ne1.yahoo.com with NNFMP; 02 Aug 2012 02:31:18 -0000 Received: from [66.94.237.111] by t7.bullet.mud.yahoo.com with NNFMP; 02 Aug 2012 02:31:18 -0000 Received: from [127.0.0.1] by omp1016.access.mail.mud.yahoo.com with NNFMP; 02 Aug 2012 02:31:18 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 173278.23313.bm@omp1016.access.mail.mud.yahoo.com Received: (qmail 41312 invoked by uid 60001); 2 Aug 2012 02:31:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pacbell.net; s=s1024; t=1343874677; bh=d/f1sYZzLocarLWpoWV1PngT+hYNrpb8lOrG8xLwois=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=P7cIPQOv0kJjU/JvYnoW4QsEZaiv2Y7m6/6+1iyEWlXNbEWaJhmYWYQvSyxIG3NTWAGiZfMn3xkLmT/FlloAtilJVKF6T9OuHdxLe17W0oxAjrtVo+LfjjNW5iKPOSSoYXxMwGsrsEhTFuXKzNi6333DzcDTGATiqDCPdegY10U= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=pacbell.net; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=J4cVfGAC/8hkz6cUNjdrSbyBVdtEGOOFhVnXuQJ7PokNFys5TQDbTf1rwnm1k4+9tVTlp5jViO0bhnPUH6NJ7dhtmDzMSpg6KuosYekJpwUveBCPfD8HVNOINGhr5fc8XXTk+wMeSD6K3nGfFJkOUhIpngaOWKB/Kqyaej4jTq0=; X-YMail-OSG: zqsxanwVM1lDCyqyz9a5JnOFL7mrhebsPwM0zMGGy9z9B7y 3i0djUf7fZugTNhOeydm3bK2Fw_5pucfjy9KH.RfKCMhgIDEisu3kYoG460r 5qNlL._sTscRjHfg24zVp2AMtR9kuu3XM3SbUfRg.ijzpE7dMCs9DSs_UaPo UgYqNcGvN2x74xtiRx29Ke0A4d7qFWhFySknC85UgIubersyT0z_B0HsDVmJ 1L9WKUzvE6yaSqjdVLa78CQaojjkFYI7OJRMAMKBZGXHybR8Yi9yM6_nHUTh 9zax6EblNAUtnYHrLsuf02Q83yd_YZB7zP8cZp.uj751bcVmprxOvOlJbYEl 2RjO_DeuAJG.Pewat1IJPmiKLjLp_BfiYxRuPEL8kGmHtAdlTga7onK0xzFy ylweZONH21ha9pPR_YphKWYJxS_6O6Pe0jJQUcBqGsR4udXgPpJ9prF56qBM w7Z72VNCOdzxQORIl7p7CsX7UEiXUkzxrE8OtIFLpw6It7ftPq3zYMT.EsPo DozqHSe1dxNjsC0fUBw-- Received: from [99.20.134.213] by web182206.mail.bf1.yahoo.com via HTTP; Wed, 01 Aug 2012 19:31:17 PDT X-Mailer: YahooMailClassic/15.0.8 YahooMailWebService/0.8.120.356233 Message-ID: <1343874677.32627.YahooMailClassic@web182206.mail.bf1.yahoo.com> Date: Wed, 1 Aug 2012 19:31:17 -0700 (PDT) From: Daniel Rudy To: davidxu@freebsd.org In-Reply-To: <5019E500.8060105@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org Subject: Re: Enumerating sleeping threads X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 02:31:25 -0000 --- On Wed, 8/1/12, David Xu wrote: From: David Xu Subject: Re: Enumerating sleeping threads To: "Daniel Rudy" Cc: freebsd-hackers@freebsd.org Date: Wednesday, August 1, 2012, 7:25 PM On 2012/8/2 10:12, Daniel Rudy wrote: > Hello, >=20 > What is the best way to enumerate the sleeping threads via > sleepqueue(9)?=A0 Furthermore, when enumerating the threads that are on > the run queue, what locks are needed, if any? sleepqueue hash bucket is private data structure in subr_sleepqueue.c, I th= ink you can not access it outside of the file. One way to enumerate the sleeping threads is iterating all threads in the s= ystem, and check their states.=A0 proc.h contains two macros: FOREACH_PROC_IN_SYSTEM FOREACH_THREAD_IN_PROC To access thread state, you should use thread lock,=A0 call thread_lock() and thread_unlock(). thread lock is not fixed, it might be sleep-queue's sp= inlock or per-cpu runqueue lock, there even is a blocked spin-lock for intermediat= e state change. > Thank you. >=20 The problem is that I want to avoid using proc.h in this.=A0 I'm considerin= g adding a function to subr_sleepqueue.c to export the data structures, or = at least export a PID list.=A0 The reason why I am doing it this way is sec= urity related.=A0=20