From cae8ca8f5cdd380973824ecfbd0b5ceb4d62b588 Mon Sep 17 00:00:00 2001 From: Klim Tsoutsman Date: Wed, 20 Sep 2023 05:17:57 +1000 Subject: [PATCH] Set `TaskInner.pinned_cpu` when spawning pinned tasks (#1044) * When spawning a pinned task, `spawn` didn't previously set `inner.pinned_cpu` for the newly-created `Task`. * This is not currently a problem because the scheduler doesn't perform task migration across CPUs, but when that gets enabled (in #1042), it would cause the pinning choice to be ignore by the scheduler. Signed-off-by: Klimenty Tsoutsman --- Cargo.lock | 1 + kernel/spawn/Cargo.toml | 1 + kernel/spawn/src/lib.rs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 65cc0e49c7..3260daba2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3518,6 +3518,7 @@ dependencies = [ "spin 0.9.4", "stack", "task", + "task_struct", "thread_local_macro", ] diff --git a/kernel/spawn/Cargo.toml b/kernel/spawn/Cargo.toml index ff1cb93dd4..c3ce259cfa 100644 --- a/kernel/spawn/Cargo.toml +++ b/kernel/spawn/Cargo.toml @@ -18,6 +18,7 @@ stack = { path = "../stack" } cpu = { path = "../cpu" } preemption = { path = "../preemption" } task = { path = "../task" } +task_struct = { path = "../task_struct" } runqueue = { path = "../runqueue" } scheduler = { path = "../scheduler" } mod_mgmt = { path = "../mod_mgmt" } diff --git a/kernel/spawn/src/lib.rs b/kernel/spawn/src/lib.rs index dbfc138bc1..043e6855e9 100755 --- a/kernel/spawn/src/lib.rs +++ b/kernel/spawn/src/lib.rs @@ -31,6 +31,7 @@ use spin::Mutex; use memory::{get_kernel_mmi_ref, MmiRef}; use stack::Stack; use task::{Task, TaskRef, RestartInfo, RunState, JoinableTaskRef, ExitableTaskRef, FailureCleanupFunction}; +use task_struct::ExposedTask; use mod_mgmt::{CrateNamespace, SectionType, SECTION_HASH_DELIMITER}; use path::Path; use fs_node::FileOrDir; @@ -381,7 +382,11 @@ impl TaskBuilder )?; // If a Task name wasn't provided, then just use the function's name. new_task.name = self.name.unwrap_or_else(|| String::from(core::any::type_name::())); - + + let exposed = ExposedTask { task: new_task }; + exposed.inner().lock().pinned_cpu = self.pin_on_cpu; + let ExposedTask { task: mut new_task } = exposed; + #[cfg(simd_personality)] { new_task.simd = self.simd; }