Hi
We are observing that ltp test case getcpu01.c is failing in some of
the machines. In the test case: system call to sched_getaffinity() is
failing. Linux kernel is giving EINVAL on call to sched_getaffinity.
------------------------------------------------------------------------------------
Explanation:
When I execute the test case:
#include<stdio.h>
#include<errno.h>
#define _GNU_SOURCE
#include<sched.h>
int main()
{
cpu_set_t set;
if (sched_getaffinity(0, sizeof(cpu_set_t), &set) < 0)
printf("\n Call is failing with:%d", errno);
}
I get this error message
"Call is failing with:22"
------------------------------------------------------------------------------------
Analysis:
on further analysis I saw that this EINVAL error message is coming from
kernel code
SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
unsigned long __user *, user_mask_ptr)
{
int ret;
cpumask_var_t mask;
if (len < cpumask_size())
return -EINVAL; <== This is where the error
messages is coming from
cpumask_size() returns 512 as compared to len which is 128
(sizeof(cpu_set_t)). cpumask_size is returning 512 as NR_CPUS is 4096.
When you enable 'configure maximum number of SMP processors and NUMA
node' option in kernel config CONFIG_NR_CPUS will be initialized to 4096
leading to this issue
So at the user end glibc allows only 1024 CPU bits when kernel can
support 4096 cpus. Can this be changed ?
------------------------------------------------------------------------------------
Possible Fixes:
1. In bits/sched.c initialize __CPU_SETSIZE to 4096 instead of 1024
as it is currently.
2. Continue with same value for __CPU_SETSIZE and ignore the error
3. Explore if there is a way to dynamically determine __CPU_SETSIZE
Please let us know your thoughts, on best way to handle this issue
Thanks
Sharyathi