28.08.2015 Views

The Design and Implementation of the Anykernel and Rump Kernels

1F3KDce

1F3KDce

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

88<br />

Releasing a CPU requires <strong>the</strong> following steps. <strong>The</strong> pseudocode is presented in Figure<br />

3.7. <strong>The</strong> fastpath is taken if no o<strong>the</strong>r thread wanted to take <strong>the</strong> CPU while <strong>the</strong><br />

current thread was using it.<br />

1. Issue a memory barrier: even if <strong>the</strong> CPU is currently not wanted, we must<br />

perform this step.<br />

In more detail, <strong>the</strong> problematic case is as follows. Immediately after we<br />

release <strong>the</strong> rump CPU, <strong>the</strong> same rump CPU may be acquired by ano<strong>the</strong>r<br />

hardware thread running on ano<strong>the</strong>r physical CPU. Although <strong>the</strong> scheduling<br />

operation must go through <strong>the</strong> slowpath, unless we issue <strong>the</strong> memory barrier<br />

before releasing <strong>the</strong> CPU, <strong>the</strong> releasing CPU may have cached data which<br />

has not reached global visibility.<br />

2. Release <strong>the</strong> CPU with an atomic swap. <strong>The</strong> return value <strong>of</strong> <strong>the</strong> swap is<br />

used to determine if any o<strong>the</strong>r thread is waiting for <strong>the</strong> CPU. If <strong>the</strong>re are no<br />

waiters for <strong>the</strong> CPU, <strong>the</strong> fastpath is complete.<br />

3. If <strong>the</strong>re are waiters, take <strong>the</strong> CPU lock <strong>and</strong> perform a wakeup. <strong>The</strong> lock<br />

necessary to avoid race conditions with <strong>the</strong> slow path <strong>of</strong> schedule_cpu().

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!