Skip to content

Commit

Permalink
task/schedule: Rename create_kernel_task()
Browse files Browse the repository at this point in the history
Rename the function to start_kernel_task() to reflect that it puts the
new task on the TASKLIST and run-queue and calls schedule().

Also add rust-doc comments for the function.

Signed-off-by: Joerg Roedel <[email protected]>
  • Loading branch information
joergroedel committed Nov 27, 2024
1 parent 7367154 commit 5cdac82
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions kernel/src/cpu/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::error::SvsmError;
use crate::platform::SvsmPlatform;
use crate::platform::SVSM_PLATFORM;
use crate::requests::{request_loop, request_processing_main};
use crate::task::{create_kernel_task, schedule_init};
use crate::task::{schedule_init, start_kernel_task};
use crate::utils::immut_after_init::immut_after_init_set_multithreaded;

fn start_cpu(platform: &dyn SvsmPlatform, apic_id: u32) -> Result<(), SvsmError> {
Expand Down Expand Up @@ -68,7 +68,7 @@ fn start_ap() {

#[no_mangle]
pub extern "C" fn ap_request_loop() {
create_kernel_task(request_processing_main).expect("Failed to launch request processing task");
start_kernel_task(request_processing_main).expect("Failed to launch request processing task");
request_loop();
panic!("Returned from request_loop!");
}
4 changes: 2 additions & 2 deletions kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use svsm::sev::utils::{rmp_adjust, RMPFlags};
use svsm::sev::{secrets_page, secrets_page_mut};
use svsm::svsm_paging::{init_page_table, invalidate_early_boot_memory};
use svsm::task::exec_user;
use svsm::task::{create_kernel_task, schedule_init};
use svsm::task::{schedule_init, start_kernel_task};
use svsm::types::{PageSize, GUEST_VMPL, PAGE_SIZE};
use svsm::utils::{immut_after_init::ImmutAfterInitCell, zero_mem_region};
#[cfg(all(feature = "vtpm", not(test)))]
Expand Down Expand Up @@ -462,7 +462,7 @@ pub extern "C" fn svsm_main() {
}
}

create_kernel_task(request_processing_main).expect("Failed to launch request processing task");
start_kernel_task(request_processing_main).expect("Failed to launch request processing task");

#[cfg(test)]
crate::test_main();
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod tasks;
mod waiting;

pub use schedule::{
create_kernel_task, create_user_task, current_task, current_task_terminated, is_current_task,
schedule, schedule_init, schedule_task, terminate, RunQueue, TASKLIST,
create_user_task, current_task, current_task_terminated, is_current_task, schedule,
schedule_init, schedule_task, start_kernel_task, terminate, RunQueue, TASKLIST,
};

pub use tasks::{
Expand Down
12 changes: 11 additions & 1 deletion kernel/src/task/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,17 @@ impl TaskList {

pub static TASKLIST: SpinLock<TaskList> = SpinLock::new(TaskList::new());

pub fn create_kernel_task(entry: extern "C" fn()) -> Result<TaskPointer, SvsmError> {
/// Creates, initializes and starts a new kernel task. Note that the task has
/// already started to run before this function returns.
///
/// # Arguments
///
/// * entry: The function to run as the new tasks main function
///
/// # Returns
///
/// A new instance of [`TaskPointer`] on success, [`SvsmError`] on failure.
pub fn start_kernel_task(entry: extern "C" fn()) -> Result<TaskPointer, SvsmError> {
let cpu = this_cpu();
let task = Task::create(cpu, entry)?;
TASKLIST.lock().list().push_back(task.clone());
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/task/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ extern "C" fn task_exit() {

#[cfg(test)]
mod tests {
use crate::task::create_kernel_task;
use crate::task::start_kernel_task;
use core::arch::asm;
use core::arch::global_asm;

Expand Down Expand Up @@ -792,7 +792,7 @@ mod tests {
#[test]
#[cfg_attr(not(test_in_svsm), ignore = "Can only be run inside guest")]
fn test_fpu_context_switch() {
create_kernel_task(task1).expect("Failed to launch request processing task");
start_kernel_task(task1).expect("Failed to launch request processing task");
}

extern "C" fn task1() {
Expand All @@ -801,7 +801,7 @@ mod tests {
asm!("call test_fpu", options(att_syntax));
}

create_kernel_task(task2).expect("Failed to launch request processing task");
start_kernel_task(task2).expect("Failed to launch request processing task");

unsafe {
asm!("call check_fpu", out("rax") ret, options(att_syntax));
Expand Down

0 comments on commit 5cdac82

Please sign in to comment.