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
The following reply was made to PR lib/58679; it has been noted by GNATS.
From: Christos Zoulas <christos%zoulas.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: lib-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost,
netbsd-bugs%netbsd.org@localhost, ondrej%sury.org@localhost
Subject: Re: lib/58679: sched_getaffinity_np() always returns an empty set
Date: Thu, 19 Sep 2024 10:14:26 -0400
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