brintos

brintos / linux-shallow public Read only

0
0
Text · 12.4 KiB · b6aeae3 Raw
331 lines · plain
1==========================================2Reducing OS jitter due to per-cpu kthreads3==========================================4 5This document lists per-CPU kthreads in the Linux kernel and presents6options to control their OS jitter.  Note that non-per-CPU kthreads are7not listed here.  To reduce OS jitter from non-per-CPU kthreads, bind8them to a "housekeeping" CPU dedicated to such work.9 10References11==========12 13-	Documentation/core-api/irq/irq-affinity.rst:  Binding interrupts to sets of CPUs.14 15-	Documentation/admin-guide/cgroup-v1:  Using cgroups to bind tasks to sets of CPUs.16 17-	man taskset:  Using the taskset command to bind tasks to sets18	of CPUs.19 20-	man sched_setaffinity:  Using the sched_setaffinity() system21	call to bind tasks to sets of CPUs.22 23-	/sys/devices/system/cpu/cpuN/online:  Control CPU N's hotplug state,24	writing "0" to offline and "1" to online.25 26-	In order to locate kernel-generated OS jitter on CPU N:27 28		cd /sys/kernel/tracing29		echo 1 > max_graph_depth # Increase the "1" for more detail30		echo function_graph > current_tracer31		# run workload32		cat per_cpu/cpuN/trace33 34kthreads35========36 37Name:38  ehca_comp/%u39 40Purpose:41  Periodically process Infiniband-related work.42 43To reduce its OS jitter, do any of the following:44 451.	Don't use eHCA Infiniband hardware, instead choosing hardware46	that does not require per-CPU kthreads.  This will prevent these47	kthreads from being created in the first place.  (This will48	work for most people, as this hardware, though important, is49	relatively old and is produced in relatively low unit volumes.)502.	Do all eHCA-Infiniband-related work on other CPUs, including51	interrupts.523.	Rework the eHCA driver so that its per-CPU kthreads are53	provisioned only on selected CPUs.54 55 56Name:57  irq/%d-%s58 59Purpose:60  Handle threaded interrupts.61 62To reduce its OS jitter, do the following:63 641.	Use irq affinity to force the irq threads to execute on65	some other CPU.66 67Name:68  kcmtpd_ctr_%d69 70Purpose:71  Handle Bluetooth work.72 73To reduce its OS jitter, do one of the following:74 751.	Don't use Bluetooth, in which case these kthreads won't be76	created in the first place.772.	Use irq affinity to force Bluetooth-related interrupts to78	occur on some other CPU and furthermore initiate all79	Bluetooth activity on some other CPU.80 81Name:82  ksoftirqd/%u83 84Purpose:85  Execute softirq handlers when threaded or when under heavy load.86 87To reduce its OS jitter, each softirq vector must be handled88separately as follows:89 90TIMER_SOFTIRQ91-------------92 93Do all of the following:94 951.	To the extent possible, keep the CPU out of the kernel when it96	is non-idle, for example, by avoiding system calls and by forcing97	both kernel threads and interrupts to execute elsewhere.982.	Build with CONFIG_HOTPLUG_CPU=y.  After boot completes, force99	the CPU offline, then bring it back online.  This forces100	recurring timers to migrate elsewhere.	If you are concerned101	with multiple CPUs, force them all offline before bringing the102	first one back online.  Once you have onlined the CPUs in question,103	do not offline any other CPUs, because doing so could force the104	timer back onto one of the CPUs in question.105 106NET_TX_SOFTIRQ and NET_RX_SOFTIRQ107---------------------------------108 109Do all of the following:110 1111.	Force networking interrupts onto other CPUs.1122.	Initiate any network I/O on other CPUs.1133.	Once your application has started, prevent CPU-hotplug operations114	from being initiated from tasks that might run on the CPU to115	be de-jittered.  (It is OK to force this CPU offline and then116	bring it back online before you start your application.)117 118BLOCK_SOFTIRQ119-------------120 121Do all of the following:122 1231.	Force block-device interrupts onto some other CPU.1242.	Initiate any block I/O on other CPUs.1253.	Once your application has started, prevent CPU-hotplug operations126	from being initiated from tasks that might run on the CPU to127	be de-jittered.  (It is OK to force this CPU offline and then128	bring it back online before you start your application.)129 130IRQ_POLL_SOFTIRQ131----------------132 133Do all of the following:134 1351.	Force block-device interrupts onto some other CPU.1362.	Initiate any block I/O and block-I/O polling on other CPUs.1373.	Once your application has started, prevent CPU-hotplug operations138	from being initiated from tasks that might run on the CPU to139	be de-jittered.  (It is OK to force this CPU offline and then140	bring it back online before you start your application.)141 142TASKLET_SOFTIRQ143---------------144 145Do one or more of the following:146 1471.	Avoid use of drivers that use tasklets.  (Such drivers will contain148	calls to things like tasklet_schedule().)1492.	Convert all drivers that you must use from tasklets to workqueues.1503.	Force interrupts for drivers using tasklets onto other CPUs,151	and also do I/O involving these drivers on other CPUs.152 153SCHED_SOFTIRQ154-------------155 156Do all of the following:157 1581.	Avoid sending scheduler IPIs to the CPU to be de-jittered,159	for example, ensure that at most one runnable kthread is present160	on that CPU.  If a thread that expects to run on the de-jittered161	CPU awakens, the scheduler will send an IPI that can result in162	a subsequent SCHED_SOFTIRQ.1632.	CONFIG_NO_HZ_FULL=y and ensure that the CPU to be de-jittered164	is marked as an adaptive-ticks CPU using the "nohz_full="165	boot parameter.  This reduces the number of scheduler-clock166	interrupts that the de-jittered CPU receives, minimizing its167	chances of being selected to do the load balancing work that168	runs in SCHED_SOFTIRQ context.1693.	To the extent possible, keep the CPU out of the kernel when it170	is non-idle, for example, by avoiding system calls and by171	forcing both kernel threads and interrupts to execute elsewhere.172	This further reduces the number of scheduler-clock interrupts173	received by the de-jittered CPU.174 175HRTIMER_SOFTIRQ176---------------177 178Do all of the following:179 1801.	To the extent possible, keep the CPU out of the kernel when it181	is non-idle.  For example, avoid system calls and force both182	kernel threads and interrupts to execute elsewhere.1832.	Build with CONFIG_HOTPLUG_CPU=y.  Once boot completes, force the184	CPU offline, then bring it back online.  This forces recurring185	timers to migrate elsewhere.  If you are concerned with multiple186	CPUs, force them all offline before bringing the first one187	back online.  Once you have onlined the CPUs in question, do not188	offline any other CPUs, because doing so could force the timer189	back onto one of the CPUs in question.190 191RCU_SOFTIRQ192-----------193 194Do at least one of the following:195 1961.	Offload callbacks and keep the CPU in either dyntick-idle or197	adaptive-ticks state by doing all of the following:198 199	a.	CONFIG_NO_HZ_FULL=y and ensure that the CPU to be200		de-jittered is marked as an adaptive-ticks CPU using the201		"nohz_full=" boot parameter.  Bind the rcuo kthreads to202		housekeeping CPUs, which can tolerate OS jitter.203	b.	To the extent possible, keep the CPU out of the kernel204		when it is non-idle, for example, by avoiding system205		calls and by forcing both kernel threads and interrupts206		to execute elsewhere.207 2082.	Enable RCU to do its processing remotely via dyntick-idle by209	doing all of the following:210 211	a.	Build with CONFIG_NO_HZ=y.212	b.	Ensure that the CPU goes idle frequently, allowing other213		CPUs to detect that it has passed through an RCU quiescent214		state.	If the kernel is built with CONFIG_NO_HZ_FULL=y,215		userspace execution also allows other CPUs to detect that216		the CPU in question has passed through a quiescent state.217	c.	To the extent possible, keep the CPU out of the kernel218		when it is non-idle, for example, by avoiding system219		calls and by forcing both kernel threads and interrupts220		to execute elsewhere.221 222Name:223  kworker/%u:%d%s (cpu, id, priority)224 225Purpose:226  Execute workqueue requests227 228To reduce its OS jitter, do any of the following:229 2301.	Run your workload at a real-time priority, which will allow231	preempting the kworker daemons.2322.	A given workqueue can be made visible in the sysfs filesystem233	by passing the WQ_SYSFS to that workqueue's alloc_workqueue().234	Such a workqueue can be confined to a given subset of the235	CPUs using the ``/sys/devices/virtual/workqueue/*/cpumask`` sysfs236	files.	The set of WQ_SYSFS workqueues can be displayed using237	"ls /sys/devices/virtual/workqueue".  That said, the workqueues238	maintainer would like to caution people against indiscriminately239	sprinkling WQ_SYSFS across all the workqueues.	The reason for240	caution is that it is easy to add WQ_SYSFS, but because sysfs is241	part of the formal user/kernel API, it can be nearly impossible242	to remove it, even if its addition was a mistake.2433.	Do any of the following needed to avoid jitter that your244	application cannot tolerate:245 246	a.	Avoid using oprofile, thus avoiding OS jitter from247		wq_sync_buffer().248	b.	Limit your CPU frequency so that a CPU-frequency249		governor is not required, possibly enlisting the aid of250		special heatsinks or other cooling technologies.  If done251		correctly, and if you CPU architecture permits, you should252		be able to build your kernel with CONFIG_CPU_FREQ=n to253		avoid the CPU-frequency governor periodically running254		on each CPU, including cs_dbs_timer() and od_dbs_timer().255 256		WARNING:  Please check your CPU specifications to257		make sure that this is safe on your particular system.258	c.	As of v3.18, Christoph Lameter's on-demand vmstat workers259		commit prevents OS jitter due to vmstat_update() on260		CONFIG_SMP=y systems.  Before v3.18, is not possible261		to entirely get rid of the OS jitter, but you can262		decrease its frequency by writing a large value to263		/proc/sys/vm/stat_interval.  The default value is HZ,264		for an interval of one second.	Of course, larger values265		will make your virtual-memory statistics update more266		slowly.  Of course, you can also run your workload at267		a real-time priority, thus preempting vmstat_update(),268		but if your workload is CPU-bound, this is a bad idea.269		However, there is an RFC patch from Christoph Lameter270		(based on an earlier one from Gilad Ben-Yossef) that271		reduces or even eliminates vmstat overhead for some272		workloads at https://lore.kernel.org/r/00000140e9dfd6bd-40db3d4f-c1be-434f-8132-7820f81bb586-000000@email.amazonses.com.273	d.	If running on high-end powerpc servers, build with274		CONFIG_PPC_RTAS_DAEMON=n.  This prevents the RTAS275		daemon from running on each CPU every second or so.276		(This will require editing Kconfig files and will defeat277		this platform's RAS functionality.)  This avoids jitter278		due to the rtas_event_scan() function.279		WARNING:  Please check your CPU specifications to280		make sure that this is safe on your particular system.281	e.	If running on Cell Processor, build your kernel with282		CBE_CPUFREQ_SPU_GOVERNOR=n to avoid OS jitter from283		spu_gov_work().284		WARNING:  Please check your CPU specifications to285		make sure that this is safe on your particular system.286	f.	If running on PowerMAC, build your kernel with287		CONFIG_PMAC_RACKMETER=n to disable the CPU-meter,288		avoiding OS jitter from rackmeter_do_timer().289 290Name:291  rcuc/%u292 293Purpose:294  Execute RCU callbacks in CONFIG_RCU_BOOST=y kernels.295 296To reduce its OS jitter, do at least one of the following:297 2981.	Build the kernel with CONFIG_PREEMPT=n.  This prevents these299	kthreads from being created in the first place, and also obviates300	the need for RCU priority boosting.  This approach is feasible301	for workloads that do not require high degrees of responsiveness.3022.	Build the kernel with CONFIG_RCU_BOOST=n.  This prevents these303	kthreads from being created in the first place.  This approach304	is feasible only if your workload never requires RCU priority305	boosting, for example, if you ensure frequent idle time on all306	CPUs that might execute within the kernel.3073.	Build with CONFIG_RCU_NOCB_CPU=y and boot with the rcu_nocbs=308	boot parameter offloading RCU callbacks from all CPUs susceptible309	to OS jitter.  This approach prevents the rcuc/%u kthreads from310	having any work to do, so that they are never awakened.3114.	Ensure that the CPU never enters the kernel, and, in particular,312	avoid initiating any CPU hotplug operations on this CPU.  This is313	another way of preventing any callbacks from being queued on the314	CPU, again preventing the rcuc/%u kthreads from having any work315	to do.316 317Name:318  rcuop/%d and rcuos/%d319 320Purpose:321  Offload RCU callbacks from the corresponding CPU.322 323To reduce its OS jitter, do at least one of the following:324 3251.	Use affinity, cgroups, or other mechanism to force these kthreads326	to execute on some other CPU.3272.	Build with CONFIG_RCU_NOCB_CPU=n, which will prevent these328	kthreads from being created in the first place.  However, please329	note that this will not eliminate OS jitter, but will instead330	shift it to RCU_SOFTIRQ.331