* @brief Get the CPU affinity mask of a process. * * This function retrieves the CPU affinity mask for a specified process. The affinity mask indicates which CPUs the * process is allowed to execute on. The process can run on any of the CPUs represented by the bits set in the mask. * * @param[in] pid The process ID of the process whose CPU affinity is to be retrieved. If `pid` is `0`, the
| 8621 | * @see sys_sched_setaffinity(), sys_getcpu() |
| 8622 | */ |
| 8623 | sysret_t sys_sched_getaffinity(const pid_t pid, size_t size, void *set) |
| 8624 | { |
| 8625 | #ifdef ARCH_MM_MMU |
| 8626 | LWP_DEF_RETURN_CODE(rc); |
| 8627 | void *mask; |
| 8628 | struct rt_lwp *lwp; |
| 8629 | |
| 8630 | if (size <= 0 || size > sizeof(cpu_set_t)) |
| 8631 | { |
| 8632 | return -EINVAL; |
| 8633 | } |
| 8634 | if (!lwp_user_accessable(set, size)) |
| 8635 | { |
| 8636 | return -EFAULT; |
| 8637 | } |
| 8638 | mask = kmem_get(size); |
| 8639 | if (!mask) |
| 8640 | { |
| 8641 | return -ENOMEM; |
| 8642 | } |
| 8643 | |
| 8644 | CPU_ZERO_S(size, mask); |
| 8645 | |
| 8646 | lwp_pid_lock_take(); |
| 8647 | lwp = lwp_from_pid_locked(pid); |
| 8648 | |
| 8649 | if (!lwp) |
| 8650 | { |
| 8651 | rc = -ESRCH; |
| 8652 | } |
| 8653 | else |
| 8654 | { |
| 8655 | #ifdef RT_USING_SMP |
| 8656 | if (lwp->bind_cpu == RT_CPUS_NR) /* not bind */ |
| 8657 | { |
| 8658 | for(int i = 0; i < RT_CPUS_NR; i++) |
| 8659 | { |
| 8660 | CPU_SET_S(i, size, mask); |
| 8661 | } |
| 8662 | } |
| 8663 | else /* set bind cpu */ |
| 8664 | { |
| 8665 | /* TODO: only single-core bindings are now supported of rt-smart */ |
| 8666 | CPU_SET_S(lwp->bind_cpu, size, mask); |
| 8667 | } |
| 8668 | #else |
| 8669 | CPU_SET_S(0, size, mask); |
| 8670 | #endif |
| 8671 | |
| 8672 | if (lwp_put_to_user(set, mask, size) != size) |
| 8673 | rc = -EFAULT; |
| 8674 | else |
| 8675 | rc = size; |
| 8676 | } |
| 8677 | |
| 8678 | lwp_pid_lock_release(); |
| 8679 | |
| 8680 | kmem_put(mask); |
nothing calls this directly
no test coverage detected