[PATCH] sched_getaffinity() fails with -EINVAL

Sharyathi Nagesh sharyath@in.ibm.com
Thu Feb 18 14:43:00 GMT 2010


Explanation:
  	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()
fails. Linux kernel is giving EINVAL on call to sched_getaffinity().
	
-----------------------------------------------------------------------
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"
-----------------------------------------------------------------------
Further analysis revealed that this EINVAL error message is coming from
this part of Linux 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 when 'configure maximum number of SMP
processors and NUMA node' option is enabled in kernel config. Since len
is only 128 (sizeof(cpu_set_t)) system call fails with EINVAL.
     In the sense user end glibc allows only 1024 CPU bits in cpu_set_t
when kernel can support 4096 cpus/bits. This patch is to increase the
size of this data
structure.

========================================================================
Testing:
     There was no regression observed when tested on x86-linux-gnu box
with older kernel. Kernel in this case was 2.6.16 and application was
built as 32 bit.
========================================================================
FSF copyright assignment
     My current FSF copy right assignment is in approved status.
========================================================================
GNU Changelog

2010-02-18  Sharyathi Nagesh  <sharyathi@in.ibm.com>

	* bits/sched.h (__CPU_SETSIZE): Size of the cpu_set_t data structure is
	changed to 4096 bits from earlier 1024 bits to reflect changes in the Linux
	kernel.		

========================================================================

Thanks
Yeehaw

-------------- next part --------------
A non-text attachment was scrubbed...
Name: increase_cpu_setsize.patch
Type: text/x-patch
Size: 511 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20100218/5b156ca4/attachment.bin>


More information about the Libc-alpha mailing list