From 312ac3a23a2c9dc06bf182c99ddf16d273519afd Mon Sep 17 00:00:00 2001 From: Ryan Stone Date: Sat, 4 Feb 2012 16:49:29 +0000 Subject: [PATCH] Whenever a new kernel thread is spawned, explicitly clear any CPU affinity set on the new thread. This prevents the thread from inadvertently inheriting affinity from a random sibling. Submitted by: attilio Tested by: pho MFC after: 1 week --- sys/kern/kern_kthread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index bb1246980d5b..dc3fdab8b4f9 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -117,6 +118,9 @@ kproc_create(void (*func)(void *), void *arg, /* call the processes' main()... */ cpu_set_fork_handler(td, func, arg); + + /* Avoid inheriting affinity from a random parent. */ + cpuset_setthread(td->td_tid, cpuset_root); thread_lock(td); TD_SET_CAN_RUN(td); sched_prio(td, PVM); @@ -299,6 +303,9 @@ kthread_add(void (*func)(void *), void *arg, struct proc *p, tidhash_add(newtd); + /* Avoid inheriting affinity from a random parent. */ + cpuset_setthread(newtd->td_tid, cpuset_root); + /* Delay putting it on the run queue until now. */ if (!(flags & RFSTOPPED)) { thread_lock(newtd);