DEV: ncpu: also emulate sysconf() for _SC_NPROCESSORS_*
This is also needed in order to make the requested number of CPUs appear. For now we don't reroute to the original sysconf() call so we return -1,EINVAL for all other info.
This commit is contained in:
parent
ed75148ca0
commit
0ceb1f2c51
@ -1,4 +1,5 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -11,6 +12,22 @@
|
|||||||
|
|
||||||
static char prog_full_path[PATH_MAX];
|
static char prog_full_path[PATH_MAX];
|
||||||
|
|
||||||
|
long sysconf(int name)
|
||||||
|
{
|
||||||
|
if (name == _SC_NPROCESSORS_ONLN ||
|
||||||
|
name == _SC_NPROCESSORS_CONF) {
|
||||||
|
const char *ncpu = getenv("NCPU");
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = ncpu ? atoi(ncpu) : CPU_SETSIZE;
|
||||||
|
if (n < 0 || n > CPU_SETSIZE)
|
||||||
|
n = CPU_SETSIZE;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* return a cpu_set having the first $NCPU set */
|
/* return a cpu_set having the first $NCPU set */
|
||||||
int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask)
|
int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user