qchbai / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

sched_setaffinity call failed, error is EINVAL(22) #351

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set process cpu affinity by sched_setaffinity call.
   My sample source code (a.c file) is:

   #define _GNU_SOURCE
       #include <sched.h>
       #include <stdlib.h>
       #include <unistd.h>
       #include <stdio.h>
       #include <assert.h>

       int
       main(int argc, char *argv[])
       {

    cpu_set_t *cpusetp;
        size_t size = CPU_ALLOC_SIZE(32);
    int cpu;

    cpusetp = CPU_ALLOC(32);
    if (cpusetp == NULL) {
        perror("CPU_ALLOC");
        exit(EXIT_FAILURE);
    }

    CPU_ZERO_S(size, cpusetp);
    for (cpu = 0; cpu < 4; cpu += 2)
        CPU_SET_S(cpu, size, cpusetp);

 if (sched_setaffinity(0, sizeof(cpu_set_t), cpusetp) != 0)
         printf("failed to call sched_setaffinity\n");
 else
 printf("success to set process affinity\n");

           CPU_FREE(cpusetp);
           exit(EXIT_SUCCESS);
       }

2. Build it by:
   gcc  a.c -o a -ltcmalloc
   or
   gcc  a.c -o a -ltcmalloc_minimal

3. Execute program (./a) by root or non privileged user. The output is:
   "failed to call sched_setaffinity"

What is the expected output? What do you see instead?

If I use "gcc  a.c -o a" command line build source code that without "tcmalloc" 
standard or minimal library. The sched_setaffinity call will be successed 
(return zero). And the program output "success to set process affinity".

What version of the product are you using? On what operating system?

perftools version: 1.7
host os: Ubuntu 11.04 (Linux ubuntu 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 
03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux)

Original issue reported on code.google.com by lzy....@gmail.com on 22 Jun 2011 at 7:23

GoogleCodeExporter commented 9 years ago
Any idea why?  You may need to look at the sched_setaffinity source code (in 
glibc) for your OS, or run the program with a debug version of libc, and put a 
breakpoint in sched_setaffinity to see what it's doing, that is not interacting 
well with perftools.

Original comment by csilv...@gmail.com on 22 Jun 2011 at 3:57

GoogleCodeExporter commented 9 years ago
Haven't heard anything in a while, so closing.  Feel free to reopen if (when) 
you have more info!

(I note the manpage for schd_setaffinity says:
       EINVAL The affinity bitmask mask contains no processors that are physi-
              cally on the system, or cpusetsize is smaller than the  size  of
              the affinity mask used by the kernel.
These seem unrelated to perftools.  Though who knows how complete this listing 
is.)

Original comment by csilv...@gmail.com on 18 Oct 2011 at 6:43