From owner-freebsd-questions@FreeBSD.ORG Wed Jan 19 00:36:05 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C215106566B for ; Wed, 19 Jan 2011 00:36:05 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from asmtpout030.mac.com (asmtpout030.mac.com [17.148.16.105]) by mx1.freebsd.org (Postfix) with ESMTP id E823A8FC12 for ; Wed, 19 Jan 2011 00:36:04 +0000 (UTC) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from cswiger1.apple.com ([17.209.4.71]) by asmtp030.mac.com (Oracle Communications Messaging Exchange Server 7u4-20.01 64bit (built Nov 21 2010)) with ESMTPSA id <0LF8008KOUZEFYD0@asmtp030.mac.com> for freebsd-questions@freebsd.org; Tue, 18 Jan 2011 16:35:39 -0800 (PST) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15,1.0.148,0.0.0000 definitions=2011-01-18_09:2011-01-19, 2011-01-18, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=6.0.2-1010190000 definitions=main-1101180204 From: Chuck Swiger In-reply-to: <57927.35211.qm@web110302.mail.gq1.yahoo.com> Date: Tue, 18 Jan 2011 16:35:38 -0800 Message-id: <9319A30D-9AC6-46BB-B7EE-A476C88A05ED@mac.com> References: <57927.35211.qm@web110302.mail.gq1.yahoo.com> To: Mark Terribile X-Mailer: Apple Mail (2.1082) Cc: freebsd-questions@freebsd.org Subject: Re: rusage and pthreads X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jan 2011 00:36:05 -0000 On Jan 18, 2011, at 4:07 PM, Mark Terribile wrote: > I'm trying to figure out the interactions between rusage and pthreads. There largely isn't any-- struct rusage is per-process, not per thread. > Peeking around in the kernel (7.2) I see updates occurring in various places. kern_clock.c, for instance, appears to increment the memory occupancy (*rss) counters. This would make it appear that every thread gets part of the count, but also that only the process that happens to have the CPU at that moment gets its count updated, even if it holds the memory. Am I misreading this? Nope. statclock() is fired off periodically (with some fuzz, to avoid clever games by processes trying to avoid being sampled) to update the stats for the currently running process. > And the context switch counters also appear to be updated per-thread, but in mi_switch(), in kern_synch.c. Is this true? Probably. > If the answer is "yes, it's per-thread", then how does a process report its usages without putting the requisite code in each thread, along with the machinery to divert from whatever the thread is doing (even waiting on I/O) to get the report at (nearly) the same time in all threads? The process doesn't have userland threads updating this information. The kernel keeps track of it, and it updates the information periodically when the scheduler does context switches, when statclock() fires off, when disk I/O completes, etc. Regards, -- -Chuck