Skip to content

Commit

Permalink
Save/restore interrupt state during context switch (#1036)
Browse files Browse the repository at this point in the history
Previously, there were no guarantees about the value of the
interrupt flag when context switching.
If the context switch was voluntary, i.e. a task called `schedule()`
to yield the CPU, interrupts would most likely be enabled.
If a task was preempted, interrupts would be disabled.

This could result in a preempted task A switching to a
task B that voluntarily yielded, causing task B to return from
the call to `schedule()` with interrupts disabled, which
usually isn't desirable.

Now, this can no longer happen due to saving and restoring
the state of interrupts for a task when context switching
away from or to it, respectively.

* On aarch64, this corresponds to the DAIF+NZCV bitflags of `PSTATE`.
* On x86_64, this corresponds to the IF bit flag of the `RFLAGS` register.

Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
Co-authored-by: Nathan Royer <nathan.royer.pro@gmail.com> 349adf8
  • Loading branch information
kevinaboos committed Sep 7, 2023
1 parent a1710e6 commit 5de443a
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 60 deletions.
8 changes: 4 additions & 4 deletions doc/compositor/trait.CompositableRegion.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
The <code>dest_coord</code> is the coordinate in the destination buffer (relative to its top-left corner)
where the <code>src_fb</code> will be composited (starting at the <code>src_fb</code>’s top-left corner).
<code>src_fb_row_range</code> is the index range of rows in the source framebuffer to blend.</p>
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-CompositableRegion-for-Coord" class="impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#94-118">source</a><a href="#impl-CompositableRegion-for-Coord" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CompositableRegion.html" title="trait compositor::CompositableRegion">CompositableRegion</a> for Coord</h3></section></summary><div class="impl-items"><section id="method.row_range" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#96-98">source</a><a href="#method.row_range" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.row_range" class="fn">row_range</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.isize.html">isize</a>&gt;</h4></section><section id="method.size" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#101-103">source</a><a href="#method.size" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.size" class="fn">size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section><section id="method.blend_buffers" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#105-117">source</a><a href="#method.blend_buffers" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.blend_buffers" class="fn">blend_buffers</a>&lt;P: Pixel&gt;(
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-CompositableRegion-for-Rectangle" class="impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#120-199">source</a><a href="#impl-CompositableRegion-for-Rectangle" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CompositableRegion.html" title="trait compositor::CompositableRegion">CompositableRegion</a> for Rectangle</h3></section></summary><div class="impl-items"><section id="method.row_range" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#122-124">source</a><a href="#method.row_range" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.row_range" class="fn">row_range</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.isize.html">isize</a>&gt;</h4></section><section id="method.size" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#127-129">source</a><a href="#method.size" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.size" class="fn">size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section><section id="method.blend_buffers" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#131-198">source</a><a href="#method.blend_buffers" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.blend_buffers" class="fn">blend_buffers</a>&lt;P: Pixel&gt;(
&amp;self,
src_fb: &amp;Framebuffer&lt;P&gt;,
dest_fb: &amp;mut Framebuffer&lt;P&gt;,
dest_coord: Coord,
_src_fb_row_range: <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>&gt;
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.unit.html">()</a>, &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>&gt;</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CompositableRegion-for-Rectangle" class="impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#120-199">source</a><a href="#impl-CompositableRegion-for-Rectangle" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CompositableRegion.html" title="trait compositor::CompositableRegion">CompositableRegion</a> for Rectangle</h3></section></summary><div class="impl-items"><section id="method.row_range-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#122-124">source</a><a href="#method.row_range-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.row_range" class="fn">row_range</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.isize.html">isize</a>&gt;</h4></section><section id="method.size-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#127-129">source</a><a href="#method.size-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.size" class="fn">size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section><section id="method.blend_buffers-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#131-198">source</a><a href="#method.blend_buffers-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.blend_buffers" class="fn">blend_buffers</a>&lt;P: Pixel&gt;(
src_fb_row_range: <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>&gt;
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.unit.html">()</a>, &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>&gt;</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CompositableRegion-for-Coord" class="impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#94-118">source</a><a href="#impl-CompositableRegion-for-Coord" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CompositableRegion.html" title="trait compositor::CompositableRegion">CompositableRegion</a> for Coord</h3></section></summary><div class="impl-items"><section id="method.row_range-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#96-98">source</a><a href="#method.row_range-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.row_range" class="fn">row_range</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.isize.html">isize</a>&gt;</h4></section><section id="method.size-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#101-103">source</a><a href="#method.size-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.size" class="fn">size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section><section id="method.blend_buffers-1" class="method trait-impl"><a class="srclink rightside" href="../src/compositor/lib.rs.html#105-117">source</a><a href="#method.blend_buffers-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.blend_buffers" class="fn">blend_buffers</a>&lt;P: Pixel&gt;(
&amp;self,
src_fb: &amp;Framebuffer&lt;P&gt;,
dest_fb: &amp;mut Framebuffer&lt;P&gt;,
dest_coord: Coord,
src_fb_row_range: <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>&gt;
_src_fb_row_range: <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>&gt;
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.unit.html">()</a>, &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>&gt;</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../implementors/compositor/trait.CompositableRegion.js" data-ignore-extern-crates="shapes" async></script></section></div></main></body></html>
2 changes: 1 addition & 1 deletion doc/context_switch_regular/fn.context_switch_regular.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Switches context from a regular Task to another regular Task."><title>context_switch_regular in context_switch_regular - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-f40c346f39d9abc1.css" id="mainThemeStyle"><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="context_switch_regular" data-themes="" data-resource-suffix="" data-rustdoc-version="1.72.0-nightly (065a1f5df 2023-06-21)" data-search-js="search-95c92dd01058facf.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ></div><script src="../static.files/storage-62ce34ea385b278a.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-190c35055d2a8300.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><div class="sidebar-elems"><h2><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Function <a href="index.html">context_switch_regular</a>::<wbr><a class="fn" href="#">context_switch_regular</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/x86_64.rs.html#146-156">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub unsafe extern &quot;C&quot; fn context_switch_regular(
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Switches context from a regular Task to another regular Task."><title>context_switch_regular in context_switch_regular - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-f40c346f39d9abc1.css" id="mainThemeStyle"><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="context_switch_regular" data-themes="" data-resource-suffix="" data-rustdoc-version="1.72.0-nightly (065a1f5df 2023-06-21)" data-search-js="search-95c92dd01058facf.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ></div><script src="../static.files/storage-62ce34ea385b278a.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-190c35055d2a8300.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><div class="sidebar-elems"><h2><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Function <a href="index.html">context_switch_regular</a>::<wbr><a class="fn" href="#">context_switch_regular</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/x86_64.rs.html#152-162">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub unsafe extern &quot;C&quot; fn context_switch_regular(
_prev_stack_pointer: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>,
_next_stack_pointer_value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>
)</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Switches context from a regular Task to another regular Task.</p>
Expand Down
Loading

0 comments on commit 5de443a

Please sign in to comment.