Isolate Kernel Module to a Specific Core Using Cpuset
<p>From user-space we can use <a href="http://man7.org/linux/man-pages/man7/cpuset.7.html" rel="nofollow noreferrer">cpuset</a> to actually <strong>isolate</strong> a specific core in our system and execute just one specific process to that core.</p>

<p>I'm trying to do the same thing with a kernel module. So I want the module to get executed in an isolated core. In other words: <strong>How do I use <code>cpuset</code>'s from inside a kernel module?</strong> * </p>

<p>Using <a href="http://lxr.free-electrons.com/source/include/linux/cpuset.h" rel="nofollow noreferrer">linux/cpuset.h</a> in my kernel module doesn't work. So, I have a module like this:</p>

<pre><code>#include &lt;linux/module.h&gt;
#include &lt;linux/cpuset.h&gt;

...
#ifdef CONFIG_CPUSETS
    printk(KERN_INFO, "cpusets is enabled!");
#endif
cpuset_init(); // this function is declared in cpuset.h
...
</code></pre>

<p>When trying to load this module I get (in <code>dmesg</code>) the following message <code>cpusets is enabled!</code>. But I also receive the message <code>Unknown symbol cpu_init (err 0)</code>.</p>

<p>Similarly, I tried using <code>sched_setaffinity</code> from <code>linux/sched.h</code> in order to move all running procceses to a specific core and then run my module to an isolated core. I got the same error mesage: <code>Unknown symbol sched_setaffinity (err 0)</code>. I guess I got the "unknown symbols" because those functions have no <code>EXPORT_SYMBOL</code> in the kernel. So I went and tried to call the <code>sys_sched_setaffinity</code> <strong>system call</strong> (based on this <a href="https://stackoverflow.com/questions/26952036/how-do-i-use-a-linux-system-call-from-a-linux-kernel-module">question</a>) but again got this mesage: <code>Unknown symbol sys_sched_setaffinity (err 0)</code>!</p>

<p>Furthermore, I am not looking for a solution that uses <code>isolcpus</code>, which is set while booting. I would like to just load the module and afterwards the isolationo to occur.</p>

<ul>
<li>(More precise, I want its kernel threads to execute in <strong>isolated</strong> cores. I know that I can use affinity to bind threads to specific cores, but this does not guarantee me that the cores are going to be isolated by other processes running on them.)</li>
</ul>