Merge bootprocess branch overlay into 0.2.0
Restore all bootprocess branch files that were overwritten by later 0.2.0 commits. This overlay brings back the complete boot infrastructure: - Configs: redbear-full, redbear-mini, redbear-device-services, driver .d files - Kernel: IRQ affinity, x2APIC, C-states, NUMA (SLIT/SRAT), MCS locks, cpuidle - Base patches: P0-P55 + new P6 (lived block_size=512) + P57 (fbbootlogd graceful init) - Driver infra: driver-manager, udev-shim, thermald, cpufreqd, iommu, redox-driver-sys/core - GPU: redox-drm with improved connector handling - System: redbear-info, redbear-hwutils phase-timer-check - Build system: fetch.rs improvements, build-iso.sh, run_full.sh - Kernel source: new ACPI (SLIT, SRAT), cpuidle, cstate, MCS lock modules 83 files changed, +3966/-1248 lines
This commit is contained in:
@@ -28,6 +28,11 @@ use crate::{
|
||||
sync::CleanLockToken,
|
||||
};
|
||||
|
||||
/// Local syscall numbers not yet in the redox_syscall crate.
|
||||
/// These are allocated from the 987+ range to avoid collisions with crate numbers.
|
||||
pub const SYS_SCHED_SETAFFINITY: usize = 987;
|
||||
pub const SYS_SCHED_GETAFFINITY: usize = 988;
|
||||
|
||||
/// Debug
|
||||
pub mod debug;
|
||||
|
||||
@@ -220,6 +225,10 @@ pub fn syscall(
|
||||
unlinkat(fd, UserSlice::ro(c, d)?, e, f as _, g as _, token).map(|()| 0)
|
||||
}
|
||||
SYS_YIELD => sched_yield(token).map(|()| 0),
|
||||
|
||||
// P17-3: CPU affinity syscalls. Numbers allocated locally (not yet in redox_syscall crate).
|
||||
SYS_SCHED_SETAFFINITY => sched_setaffinity(b, UserSlice::ro(c, d)?, token),
|
||||
SYS_SCHED_GETAFFINITY => sched_getaffinity(b, UserSlice::wo(c, d)?, token),
|
||||
SYS_NANOSLEEP => nanosleep(
|
||||
UserSlice::ro(b, size_of::<TimeSpec>())?,
|
||||
UserSlice::wo(c, size_of::<TimeSpec>())?.none_if_null(),
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
memory::{AddrSpace, Grant, PageSpan},
|
||||
ContextRef,
|
||||
},
|
||||
cpu_set::RawMask,
|
||||
event,
|
||||
sync::{CleanLockToken, RwLock},
|
||||
syscall::flag::{EventFlags, O_CREAT, O_RDWR},
|
||||
@@ -295,3 +296,71 @@ fn insert_fd(scheme: SchemeId, number: usize, cloexec: bool, token: &mut CleanLo
|
||||
.expect("failed to insert fd to current context")
|
||||
.get()
|
||||
}
|
||||
|
||||
/// Set CPU affinity mask for a process.
|
||||
///
|
||||
/// # Arguments (syscall ABI)
|
||||
/// - `pid`: Process ID (0 = current process; other PIDs not yet supported)
|
||||
/// - `mask_ptr`: Pointer to a `RawMask` (32 bytes on 64-bit, 256-bit bitmap)
|
||||
/// - `mask_len`: Length of mask in bytes (must equal `size_of::<RawMask>()`)
|
||||
pub fn sched_setaffinity(
|
||||
pid: usize,
|
||||
mask_ptr: super::usercopy::UserSliceRo,
|
||||
token: &mut CleanLockToken,
|
||||
) -> Result<usize> {
|
||||
// Validate mask size
|
||||
if mask_ptr.len() != core::mem::size_of::<RawMask>() {
|
||||
return Err(Error::new(super::error::EINVAL));
|
||||
}
|
||||
|
||||
// pid == 0 means current process
|
||||
let target = if pid == 0 {
|
||||
context::current()
|
||||
} else {
|
||||
// TODO: Support PID-based lookup (requires context list iteration
|
||||
// with lock token downgrades). For now, only pid=0 is supported.
|
||||
return Err(Error::new(super::error::ESRCH));
|
||||
};
|
||||
|
||||
// Read mask from userspace
|
||||
let raw_mask: RawMask = unsafe { mask_ptr.read_exact() }?;
|
||||
|
||||
// Apply to context's affinity mask
|
||||
let mut ctx = target.write(token.token());
|
||||
ctx.sched_affinity.override_from(&raw_mask);
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
/// Get CPU affinity mask for a process.
|
||||
///
|
||||
/// # Arguments (syscall ABI)
|
||||
/// - `pid`: Process ID (0 = current process; other PIDs not yet supported)
|
||||
/// - `mask_ptr`: Pointer to a `RawMask` buffer (32 bytes on 64-bit)
|
||||
/// - `mask_len`: Length of buffer in bytes (must equal `size_of::<RawMask>()`)
|
||||
///
|
||||
/// # Returns
|
||||
/// Number of bytes written to mask_ptr on success.
|
||||
pub fn sched_getaffinity(
|
||||
pid: usize,
|
||||
mask_ptr: super::usercopy::UserSliceWo,
|
||||
token: &mut CleanLockToken,
|
||||
) -> Result<usize> {
|
||||
// Validate mask size
|
||||
if mask_ptr.len() != core::mem::size_of::<RawMask>() {
|
||||
return Err(Error::new(super::error::EINVAL));
|
||||
}
|
||||
|
||||
// pid == 0 means current process
|
||||
let target = if pid == 0 {
|
||||
context::current()
|
||||
} else {
|
||||
return Err(Error::new(super::error::ESRCH));
|
||||
};
|
||||
|
||||
let ctx = target.read(token.token());
|
||||
let raw_mask = ctx.sched_affinity.to_raw();
|
||||
mask_ptr.copy_common_bytes_from_slice(crate::cpu_set::mask_as_bytes(&raw_mask))?;
|
||||
|
||||
Ok(core::mem::size_of::<RawMask>())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user