Files
RedBear-OS/local/patches/kernel/P17-3-sched-affinity.patch
T
vasilito cee25393d8 fix: boot process improvements — dependency cycle, INIT_NOTIFY, probing loop, and log spam fixes
- Fix P15-8-init-cycle-detection.patch: replace visiting+error with seen+silent-skip
  to eliminate 11 false-positive 'dependency cycle detected' errors on shared deps
- Fix P0-daemon-fix-init-notify-unwrap.patch: remove eprintln! for missing
  INIT_NOTIFY (expected for oneshot_async services, ~7 daemons affected)
- Fix driver-manager hotplug loop: add PERMANENTLY_SKIPPED static set shared
  between hotplug handler and DriverConfig::probe() to stop infinite re-probing
  of Fatal/NotSupported/deferred-exhausted device+driver pairs (e.g. ided)
- Fix driver-manager log_timeline: suppress repeated EPIPE/ENOENT errors with
  AtomicI32 dedup and AtomicBool one-shot guards for boot timeline JSON
- Add driver-manager SIGTERM handler, ACPI bus registration, --status mode,
  driver reap loop, graceful shutdown, and reduced deferred retries (30→3)
2026-05-17 12:34:02 +03:00

83 lines
2.6 KiB
Diff

--- a/src/syscall/process.rs
+++ b/src/syscall/process.rs
@@ -11,6 +11,7 @@
memory::{AddrSpace, Grant, PageSpan},
ContextRef,
},
+ cpu_set::RawMask,
event,
sync::{CleanLockToken, RwLock},
syscall::flag::{EventFlags, O_CREAT, O_RDWR},
@@ -295,3 +296,71 @@
.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>())
+}