Skip to content

Commit 9cc5b86

Browse files
matosattiPeter Zijlstra
authored andcommitted
isolcpus: Affine unbound kernel threads to housekeeping cpus
This is a kernel enhancement that configures the cpu affinity of kernel threads via kernel boot option nohz_full=. When this option is specified, the cpumask is immediately applied upon kthread launch. This does not affect kernel threads that specify cpu and node. This allows CPU isolation (that is not allowing certain threads to execute on certain CPUs) without using the isolcpus=domain parameter, making it possible to enable load balancing on such CPUs during runtime (see kernel-parameters.txt). Note-1: this is based off on Wind River's patch at https://github.com/starlingx-staging/stx-integ/blob/master/kernel/kernel-std/centos/patches/affine-compute-kernel-threads.patch Difference being that this patch is limited to modifying kernel thread cpumask. Behaviour of other threads can be controlled via cgroups or sched_setaffinity. Note-2: Wind River's patch was based off Christoph Lameter's patch at https://lwn.net/Articles/565932/ with the only difference being the kernel parameter changed from kthread to kthread_cpus. Signed-off-by: Frederic Weisbecker <[email protected]> Signed-off-by: Marcelo Tosatti <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 043eb8e commit 9cc5b86

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

include/linux/sched/isolation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum hk_flags {
1414
HK_FLAG_DOMAIN = (1 << 5),
1515
HK_FLAG_WQ = (1 << 6),
1616
HK_FLAG_MANAGED_IRQ = (1 << 7),
17+
HK_FLAG_KTHREAD = (1 << 8),
1718
};
1819

1920
#ifdef CONFIG_CPU_ISOLATION

kernel/kthread.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/ptrace.h>
2828
#include <linux/uaccess.h>
2929
#include <linux/numa.h>
30+
#include <linux/sched/isolation.h>
3031
#include <trace/events/sched.h>
3132

3233

@@ -383,7 +384,8 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
383384
* The kernel thread should not inherit these properties.
384385
*/
385386
sched_setscheduler_nocheck(task, SCHED_NORMAL, &param);
386-
set_cpus_allowed_ptr(task, cpu_possible_mask);
387+
set_cpus_allowed_ptr(task,
388+
housekeeping_cpumask(HK_FLAG_KTHREAD));
387389
}
388390
kfree(create);
389391
return task;
@@ -608,7 +610,7 @@ int kthreadd(void *unused)
608610
/* Setup a clean context for our children to inherit. */
609611
set_task_comm(tsk, "kthreadd");
610612
ignore_signals(tsk);
611-
set_cpus_allowed_ptr(tsk, cpu_possible_mask);
613+
set_cpus_allowed_ptr(tsk, housekeeping_cpumask(HK_FLAG_KTHREAD));
612614
set_mems_allowed(node_states[N_MEMORY]);
613615

614616
current->flags |= PF_NOFREEZE;

kernel/sched/isolation.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static int __init housekeeping_nohz_full_setup(char *str)
140140
{
141141
unsigned int flags;
142142

143-
flags = HK_FLAG_TICK | HK_FLAG_WQ | HK_FLAG_TIMER | HK_FLAG_RCU | HK_FLAG_MISC;
143+
flags = HK_FLAG_TICK | HK_FLAG_WQ | HK_FLAG_TIMER | HK_FLAG_RCU |
144+
HK_FLAG_MISC | HK_FLAG_KTHREAD;
144145

145146
return housekeeping_setup(str, flags);
146147
}

0 commit comments

Comments
 (0)