title: What is the purpose of Thread ID registers like TPIDR_EL0/TPIDR_EL1 in ARM?
body: <p>According to <a href="https://developer.arm.com/documentation/ddi0433/c/system-control/about-system-control/c13--software-thread-id-registers" rel="nofollow noreferrer">ARM documentation</a>, the thread ID registers like <code>TPIDR_EL0</code> or <code>TPIDR_EL1</code>,</p>
  <blockquote>
  <p>Provide locations to store the IDs of software threads and processes
  for OS management purposes. These registers have no effect on
  processor behavior.</p>
  </blockquote>
  <p>Why would someone want to store the thread ID in a special register? Do ARM processors require threads to have special structures in memory just like the MMU has? Is a Thread something special to ARM, something ARM expect to find somewhere? Or can I implement threads (efficiently) without using this register at all?</p>
  <p>I'm asking because I found this code on the Zircon Kernel from Fuchsia OS:</p>
  <pre><code>static inline void arch_set_current_thread(Thread* t) {
    __arm_wsr64(&quot;tpidr_el1&quot;, (uint64_t)&amp;t-&gt;arch_.thread_pointer_location);
    __isb(ARM_MB_SY);
  }
  </code></pre>
  <p>Right at boot it creates a thread and stores its pointer in <code>tpidr_el1</code></p>