mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 16:13:27 +00:00
Remove cpu_affinity field from OSTD Task struct
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
8927031426
commit
9cc63149f1
@ -55,19 +55,17 @@ pub fn create_new_kernel_task(mut thread_options: ThreadOptions) -> Arc<Task> {
|
||||
let kernel_thread = KernelThread;
|
||||
let status = ThreadStatus::Init;
|
||||
let priority = thread_options.priority;
|
||||
let cpu_affinity = thread_options.cpu_affinity;
|
||||
Arc::new(Thread::new(
|
||||
weak_task.clone(),
|
||||
kernel_thread,
|
||||
status,
|
||||
priority,
|
||||
cpu_affinity,
|
||||
))
|
||||
};
|
||||
|
||||
TaskOptions::new(thread_fn)
|
||||
.data(thread)
|
||||
.cpu_affinity(thread_options.cpu_affinity)
|
||||
.build()
|
||||
.unwrap()
|
||||
TaskOptions::new(thread_fn).data(thread).build().unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
use ostd::task::Task;
|
||||
use ostd::{cpu::CpuSet, sync::PreemptDisabled, task::Task};
|
||||
|
||||
use self::status::{AtomicThreadStatus, ThreadStatus};
|
||||
use crate::{
|
||||
@ -33,6 +33,8 @@ pub struct Thread {
|
||||
status: AtomicThreadStatus,
|
||||
/// Thread priority
|
||||
priority: AtomicPriority,
|
||||
/// Thread cpu affinity
|
||||
cpu_affinity: SpinLock<CpuSet>,
|
||||
}
|
||||
|
||||
impl Thread {
|
||||
@ -42,12 +44,14 @@ impl Thread {
|
||||
data: impl Send + Sync + Any,
|
||||
status: ThreadStatus,
|
||||
priority: Priority,
|
||||
cpu_affinity: CpuSet,
|
||||
) -> Self {
|
||||
Thread {
|
||||
task,
|
||||
data: Box::new(data),
|
||||
status: AtomicThreadStatus::new(status),
|
||||
priority: AtomicPriority::new(priority),
|
||||
cpu_affinity: SpinLock::new(cpu_affinity),
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +115,16 @@ impl Thread {
|
||||
self.priority.store(new_priority, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Acquires the lock of cpu affinity.
|
||||
pub fn lock_cpu_affinity(&self) -> SpinLockGuard<CpuSet, PreemptDisabled> {
|
||||
self.cpu_affinity.lock()
|
||||
}
|
||||
|
||||
/// Updates the cpu affinity with the new value.
|
||||
pub fn set_cpu_affinity(&self, new_cpu_affinity: CpuSet) {
|
||||
*self.cpu_affinity.lock() = new_cpu_affinity;
|
||||
}
|
||||
|
||||
pub fn yield_now() {
|
||||
Task::yield_now()
|
||||
}
|
||||
|
Reference in New Issue
Block a user