mirror of
https://github.com/redox-os/kernel.git
synced 2026-09-09 00:07:34 +08:00
Allow disabling opportunistic context locking.
This commit is contained in:
@@ -80,6 +80,7 @@ default = [
|
||||
"acpi",
|
||||
#"debugger",
|
||||
"multi_core",
|
||||
"opportunistic_context_locking",
|
||||
"serial_debug",
|
||||
"self_modifying",
|
||||
"x86_kvm_pv",
|
||||
@@ -91,6 +92,10 @@ default = [
|
||||
# Activates some limited code-overwriting optimizations, based on CPU features.
|
||||
self_modifying = []
|
||||
|
||||
# Allows the scheduler to skip contexts that were locked at the time of check.
|
||||
# This is preferred for performance, but makes it harder to spot deadlocks, and can therefore be disabled.
|
||||
opportunistic_context_locking = []
|
||||
|
||||
acpi = []
|
||||
lpss_debug = []
|
||||
multi_core = ["acpi"]
|
||||
|
||||
+17
-3
@@ -49,6 +49,14 @@ pub const STEAL_THRESHOLD: usize = 2;
|
||||
pub const STEAL_INTERVAL: usize = 2;
|
||||
pub const MAX_STEAL: usize = 2;
|
||||
|
||||
unsafe fn opportunistic_write_arc(lock: &Arc<ContextLock>) -> Option<ArcContextLockWriteGuard> {
|
||||
if cfg!(opportunistic_context_locking) {
|
||||
unsafe { lock.try_write_arc() }
|
||||
} else {
|
||||
Some(unsafe { lock.write_arc() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Determines if a given context is eligible to be scheduled on a given CPU (in
|
||||
/// principle, the current CPU).
|
||||
///
|
||||
@@ -256,8 +264,14 @@ pub fn switch(token: &mut CleanLockToken) -> SwitchResult {
|
||||
let Some(context_lock) = context_ref.upgrade() else {
|
||||
continue;
|
||||
};
|
||||
// TODO: can this happen?
|
||||
if !cfg!(opportunistic_context_locking)
|
||||
&& Weak::as_ptr(&context_ref.0) == Arc::as_ptr(&prev_context_lock)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(mut guard) = (unsafe { context_lock.try_write_arc() }) else {
|
||||
let Some(mut guard) = (unsafe { opportunistic_write_arc(&context_lock) }) else {
|
||||
if let Some(wake) = wake_opt {
|
||||
run_queue.timers.insert((wake, context_ref));
|
||||
} else {
|
||||
@@ -562,7 +576,7 @@ fn select_next_context(
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(mut guard) = (unsafe { context_lock.try_write_arc() }) else {
|
||||
let Some(mut guard) = (unsafe { opportunistic_write_arc(&context_lock) }) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -760,7 +774,7 @@ fn select_next_context(
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(guard) = (unsafe { context_lock.try_write_arc() }) else {
|
||||
let Some(guard) = (unsafe { opportunistic_write_arc(&context_lock) }) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user