From owner-freebsd-current@FreeBSD.ORG Mon Feb 25 03:37:10 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 167D516A401 for ; Mon, 25 Feb 2008 03:37:10 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from webaccess-cl.virtdom.com (webaccess-cl.virtdom.com [216.240.101.25]) by mx1.freebsd.org (Postfix) with ESMTP id CC4C313C46E for ; Mon, 25 Feb 2008 03:37:09 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from [192.168.1.107] (cpe-24-94-75-93.hawaii.res.rr.com [24.94.75.93]) (authenticated bits=0) by webaccess-cl.virtdom.com (8.13.6/8.13.6) with ESMTP id m1P3b56a046523 for ; Sun, 24 Feb 2008 22:37:08 -0500 (EST) (envelope-from jroberson@chesapeake.net) Date: Sun, 24 Feb 2008 17:38:37 -1000 (HST) From: Jeff Roberson X-X-Sender: jroberson@desktop To: current@freebsd.org Message-ID: <20080224173229.I920@desktop> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Subject: cpuset and affinity implementation X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Feb 2008 03:37:10 -0000 Hello, I have implemented a new api similar to processors sets on solaris. This allows you to assign processes to sets of cpus and dynamically change those sets. This is useful for provisioning purposes to add and remove cpu resources for a particular process or group of processes. This new facility also supports binding secific threads to specific cpus which some applications may want to do. At some point in the future this will be integrated with jail so you can restrict the cpus any jail is allowed to use. This api should not be considered final and the 'cpuset' tool is quite rough. This also only works with ULE and is unfortunately intertwined with a big ULE patch I've been working on. The set management code is generic but 4BSD doesn't contain the hooks to actually constrain threads. Please see: http://people.freebsd.org/~jeff/cpuset.diff here's a couple of neat things to do with cpuset: cpuset -l 0-4 /bin/sh This creates a new group with a list (-l) of cpus 0-4 inclusive and runs sh in it. cpuset -g -p This will get (-g) the mask of cpus pid (-p) is allowed to run on. cpuset -l 0,2 -p This will restrict sh to running on cpus 0, 2 while its group is still allowed 0-4. cpuset -l 0,2 -c -p This will modify the cpuset (-c) that the sh belongs to. cpuset -l 0-3 -s 1 This will modify the set (-s) that all threads are in by default to contain the first 4 cpus leaving the rest idled. cpuset -g -i -p This will print the id of the set sh is in. cpuset -s -p This will move pid into the specified set so it may be managed with other pids in that set. Feedback is appreciated. Thanks, Jeff