title: how to shield a cpu from the linux scheduler (prevent it scheduling threads onto that cpu)?
body: <p>It is possible to use <code>sched_setaffinity</code> to pin a thread to a cpu, increasing performance (in some situations)</p>
  
  <p>From the linux man page:</p>
  
  <blockquote>
    <p>Restricting a process to run on a single CPU also avoids the
    performance cost caused by the cache invalidation that occurs when a
    process ceases to execute on one CPU and then recommences execution on
    a different CPU</p>
  </blockquote>
  
  <p>Further, if I desire a more real-time response, I can change the scheduler policy for that thread to <code>SCHED_FIFO</code>, and up the priority to some high value (up to <code>sched_get_priority_max</code>), meaning the thread in question should always pre-empt any other thread running on its cpu when it becomes ready.</p>
  
  <p>However, at this point, the thread running on the cpu which the real-time thread just pre-empted will possibly have evicted much of the real-time thread's level-1 cache entries.</p>
  
  <p>My questions are as follows:</p>
  
  <ol>
  <li>Is it possible to prevent the scheduler from scheduling any threads onto a given cpu? (eg: either hide the cpu completely from the scheduler, or some other way)</li>
  <li>Are there some threads which absolutely have to be able to run on that cpu? (eg: kernel threads / interrupt threads)</li>
  <li>If I need to have kernel threads running on that cpu, what is a reasonable maximum priority value to use such that I don't starve out the kernel threads?</li>
  </ol>