NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/58679: sched_getaffinity_np() always returns an empty set
Not really a bug.
christos
[10:10am] 26>cat getaffinity.c
#include <sched.h>
#include <unistd.h>
#include <err.h>
#include <stdio.h>
static int
cpu_count(cpuset_t *cpuset)
{
int rc;
cpuid_t i;
rc = 0;
for (i = 0;; i++) {
int r = cpuset_isset(i, cpuset);
fprintf(stderr, "cpuset_isset(%d, %p) -> %d\n", (int)i,
cpuset, r);
if (r < 0)
break;
if (r)
rc++;
}
return rc;
}
int
main(void)
{
int rc = -1;
cpuset_t *set = cpuset_create();
if (set != NULL) {
cpuset_set(0, set);
if (-1 == sched_setaffinity_np(getpid(),
cpuset_size(set), set))
err(1, "setaffinity");
if (0 == sched_getaffinity_np(getpid(),
cpuset_size(set), set))
rc = cpu_count(set);
cpuset_destroy(set);
}
printf("Number of processors reported by sched_getaffinity_np:
%d\n", rc);
if (rc < 1)
rc = sysconf(_SC_NPROCESSORS_ONLN);
printf("Number of processors reported by
sysconf(_SC_NPROCESSORS_ONLN): %d\n", rc);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index