1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: MPL-2.0
//! This module maintains preemption-related information for the current task
//! on a CPU with a single 32-bit, CPU-local integer value.
//!
//! * Bits from 0 to 30 represents an unsigned counter called `guard_count`,
//! which is the number of `DisabledPreemptGuard` instances held by the
//! current CPU;
//! * Bit 31 is set to `!need_preempt`, where `need_preempt` is a boolean value
//! that will be set by the scheduler when it decides that the current task
//! _needs_ to be preempted.
//!
//! Thus, the current task on a CPU _should_ be preempted if and only if this
//! integer is equal to zero.
//!
//! The initial value of this integer is equal to `1 << 31`.
//!
//! This module provides a set of functions to access and manipulate
//! `guard_count` and `need_preempt`.
use cratecpu_local_cell;
/// Returns whether the current task _should_ be preempted or not.
///
/// `should_preempt() == need_preempt() && get_guard_count() == 0`.
pub
pub
pub
pub
pub
pub
pub
cpu_local_cell!
/// Resets the preempt info to the initial state.
///
/// # Safety
///
/// This function is only useful for the initialization of application
/// processors' CPU-local storage. Because that the BSP should access the CPU-
/// local storage (`PREEMPT_INFO`) (when doing heap allocation) before we can
/// initialize the CPU-local storage for APs, the value of the AP's
/// `PREEMPT_INFO` would be that of the BSP's. Therefore, we need to reset the
/// `PREEMPT_INFO` to the initial state on APs' initialization.
pub unsafe
const NEED_PREEMPT_MASK: u32 = 1 << 31;
const GUARD_COUNT_MASK: u32 = - 1;