From owner-freebsd-questions@FreeBSD.ORG Mon Dec 15 22:58:37 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DD3E0CEC for ; Mon, 15 Dec 2014 22:58:37 +0000 (UTC) Received: from host203.r-bonomi.com (host203.r-bonomi.com [204.87.227.203]) by mx1.freebsd.org (Postfix) with ESMTP id B41528ED for ; Mon, 15 Dec 2014 22:58:37 +0000 (UTC) Received: (from bonomi@localhost) by host203.r-bonomi.com (8.14.9/8.14.7) id sBFMoksQ017043 for freebsd-questions@freebsd.org; Mon, 15 Dec 2014 16:50:46 -0600 (CST) (envelope-from bonomi) Date: Mon, 15 Dec 2014 16:50:46 -0600 (CST) From: Robert Bonomi Message-Id: <201412152250.sBFMoksQ017043@host203.r-bonomi.com> To: freebsd-questions@freebsd.org Subject: getting 'load averages' (or something similar) from inside a _kernel_ X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Dec 2014 22:58:38 -0000 I'm trying to get the current 'runnable processes' count from inside a kernel loadable module for BSD 8.4, so I can tweak it's behavior depending on the current activity level. All I've found so far is what's in 'man 9 runqueue', and it is *badly* out-of-sync with the 8.4 kernel code. e.g., the external arrays at the beginning of the synopisis are shown as being of type 'struct rq' -- but there *ISN"T* any defined struct 'rq'; it seems to be named 'runq', at least in /usr/include/sys/runq.h Then the cr*p gets deeper -- trying to make heads or tails out of how to get a count of runnable processes from the _arrays_ (of unknown size) described on the 'man 9 runqueue' page info has me defeated. Looking at '/usr/include/sys/runq.h', it appears that 'struct runq' is a single item with an array of queues (by 'nice' level), and a bitmap of which array elements have non-zero length queues. I'm perfectly willing to brute-force the data out of the queue lists, *IF* there's some reasonable, _current_, descriptive info of the format/usage of those kernel structures. Alternatively, is there a way to directly access the 'sysctl' MIB data in kernel memory. sysctl(3) is out -- it's in 'libc', and not available to kernel modules. Pointers to descriptions of the kernel in-memory data for that MIB would be a big help. Or 'where to ask', if there's a better place.