This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] sched_getaffinity() fails with -EINVAL


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

Index: glibc/bits/sched.h
===================================================================
--- glibc.orig/bits/sched.h	2009-10-29 11:09:30.000000000 +0530
+++ glibc/bits/sched.h	2009-10-29 12:14:20.000000000 +0530
@@ -38,7 +38,7 @@
 #if defined _SCHED_H && !defined __cpu_set_t_defined
 # define __cpu_set_t_defined
 /* Size definition for CPU sets.  */
-# define __CPU_SETSIZE	1024
+# define __CPU_SETSIZE	4096
 # define __NCPUBITS	(8 * sizeof (__cpu_mask))
 
 /* Type for array elements in 'cpu_set'.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]