Allow specifying orderings when loading/storing AtomicCpuSets

This commit is contained in:
Zhang Junyang
2025-05-07 20:47:33 +08:00
committed by Ruihan Li
parent 90e3afd47c
commit 773b965767
5 changed files with 42 additions and 23 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use core::{cmp, mem};
use core::{cmp, mem, sync::atomic::Ordering};
use ostd::cpu::{num_cpus, CpuId, CpuSet};
@ -14,9 +14,9 @@ pub fn sys_sched_getaffinity(
ctx: &Context,
) -> Result<SyscallReturn> {
let cpu_set = match tid {
0 => ctx.thread.atomic_cpu_affinity().load(),
0 => ctx.thread.atomic_cpu_affinity().load(Ordering::Relaxed),
_ => match thread_table::get_thread(tid) {
Some(thread) => thread.atomic_cpu_affinity().load(),
Some(thread) => thread.atomic_cpu_affinity().load(Ordering::Relaxed),
None => return Err(Error::with_message(Errno::ESRCH, "thread does not exist")),
},
};
@ -39,10 +39,15 @@ pub fn sys_sched_setaffinity(
let user_cpu_set = read_cpu_set_from(ctx.user_space(), cpuset_size, cpu_set_ptr)?;
match tid {
0 => ctx.thread.atomic_cpu_affinity().store(&user_cpu_set),
0 => ctx
.thread
.atomic_cpu_affinity()
.store(&user_cpu_set, Ordering::Relaxed),
_ => match thread_table::get_thread(tid) {
Some(thread) => {
thread.atomic_cpu_affinity().store(&user_cpu_set);
thread
.atomic_cpu_affinity()
.store(&user_cpu_set, Ordering::Relaxed);
}
None => return Err(Error::with_message(Errno::ESRCH, "thread does not exist")),
},