28.08.2015 Views

The Design and Implementation of the Anykernel and Rump Kernels

1F3KDce

1F3KDce

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

86<br />

<strong>The</strong> fastpath is taken in cases where <strong>the</strong> same thread schedules <strong>the</strong> rump kernel<br />

consecutively without any o<strong>the</strong>r thread running on <strong>the</strong> virtual CPU in between.<br />

<strong>The</strong> fastpath not only applies to <strong>the</strong> entry point, but also to relinquishing <strong>and</strong><br />

rescheduling a CPU during a blocking hypercall. <strong>The</strong> implementation uses atomic<br />

operations to minimize <strong>the</strong> need for memory barriers which are required by full<br />

locks.<br />

Next, we <strong>of</strong>fer a verbose explanation <strong>of</strong> <strong>the</strong> scheduling algorithm.<br />

1. Use atomic compare-<strong>and</strong>-swap (CAS) to check if we were <strong>the</strong> previous thread<br />

to be associated with <strong>the</strong> CPU. If that is <strong>the</strong> case, we have locked <strong>the</strong> CPU<br />

<strong>and</strong> <strong>the</strong> scheduling fastpath was successful.<br />

2. <strong>The</strong> slow path does a full mutex lock to synchronize against ano<strong>the</strong>r thread<br />

releasing <strong>the</strong> CPU. In addition to enabling a race-free sleeping wait, using a<br />

lock makes sure <strong>the</strong> cache <strong>of</strong> <strong>the</strong> physical CPU <strong>the</strong> thread is running on is<br />

up-to-date.<br />

3. Mark <strong>the</strong> CPU as wanted with an atomic swap. We examine <strong>the</strong> return value<br />

<strong>and</strong> if we notice <strong>the</strong> CPU was no longer busy at that point, try to mark it<br />

busy with atomic CAS. If <strong>the</strong> CAS succeeds, we have successfully scheduled<br />

<strong>the</strong> CPU. We proceed to release <strong>the</strong> lock we took in step 2. If <strong>the</strong> CAS did<br />

not succeed, check if we want to migrate <strong>the</strong> lwp to ano<strong>the</strong>r CPU.<br />

4. In case <strong>the</strong> target CPU was busy <strong>and</strong> we did not choose to migrate to ano<strong>the</strong>r<br />

CPU, wait for <strong>the</strong> CPU to be released. After we have woken up, loop <strong>and</strong><br />

recheck if <strong>the</strong> CPU is available now. We must do a full check to prevent races<br />

against a third thread which also wanted to use <strong>the</strong> CPU.

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

Saved successfully!

Ooh no, something went wrong!