Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Jun 2014 18:52:10 +0400
From:      "Alexander V. Chernikov" <melifaro@FreeBSD.org>
To:        hackers@freebsd.org
Subject:   Permit init(8) use its own cpuset group.
Message-ID:  <538C8F9A.4020301@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
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 <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <sys/param.h>
+#include <sys/cpuset.h>
 #include <sys/sysctl.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?538C8F9A.4020301>