From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 2 14:53:49 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4D5B86C6 for ; Mon, 2 Jun 2014 14:53:49 +0000 (UTC) Received: from mail.ipfw.ru (mail.ipfw.ru [IPv6:2a01:4f8:120:6141::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 10B7B2F0A for ; Mon, 2 Jun 2014 14:53:49 +0000 (UTC) Received: from [2a02:6b8:0:401:222:4dff:fe50:cd2f] (helo=ptichko.yndx.net) by mail.ipfw.ru with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.76 (FreeBSD)) (envelope-from ) id 1WrPhe-0006CZ-Cy for hackers@freebsd.org; Mon, 02 Jun 2014 14:42:54 +0400 Message-ID: <538C8F9A.4020301@FreeBSD.org> Date: Mon, 02 Jun 2014 18:52:10 +0400 From: "Alexander V. Chernikov" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: hackers@freebsd.org Subject: Permit init(8) use its own cpuset group. Content-Type: multipart/mixed; boundary="------------070505090402050105000502" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jun 2014 14:53:49 -0000 This is a multi-part message in MIME format. --------------070505090402050105000502 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello list! Currently init(8) uses group 1 which is root group. Modifications of this group affects both kernel and userland threads. Additionally, such modifications are impossible, for example, in presence of multi-queue NIC drivers (like igb or ixgbe) which binds their threads to particular cpus. Proposed change ("init_cpuset" loader tunable) permits changing cpu masks for userland more easily. Restricting user processes to migrate to/from CPU cores used for network traffic processing is one of the cases. Phabricator: https://phabric.freebsd.org/D141 (the same version attached inline) If there are no objections, I'll commit this next week. --------------070505090402050105000502 Content-Type: text/x-patch; name="init_cpuset.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="init_cpuset.diff" Index: sbin/init/init.c =================================================================== --- sbin/init/init.c (revision 266306) +++ sbin/init/init.c (working copy) @@ -47,6 +47,8 @@ static const char rcsid[] = #include #include #include +#include +#include #include #include #include @@ -320,6 +322,19 @@ invalid: warning("Can't chroot to %s: %m", kenv_value); } + if (kenv(KENV_GET, "init_cpuset", kenv_value, sizeof(kenv_value)) > 0) { + if (getpid() == 1) { + cpusetid_t setid; + + setid = -1; + if (cpuset(&setid) != 0) { + warning("cpu set alloc failed: %m"); + } else { + if (cpuset_setid(CPU_WHICH_PID, 1, setid) != 0) + warning("cpuset_setsid failed: %m"); + } + } + } /* * Additional check if devfs needs to be mounted: * If "/" and "/dev" have the same device number, --------------070505090402050105000502--