NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/58679: sched_getaffinity_np() always returns an empty set



>Number:         58679
>Category:       lib
>Synopsis:       sched_getaffinity_np() always returns an empty set
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 19 12:30:00 +0000 2024
>Originator:     Ondřej Surý
>Release:        9.4 and 10.0
>Organization:
ISC
>Environment:
NetBSD netbsd-10.home.sury.org 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
The sched_getaffinity_np() (and pthread_getaffinity_np()) always return an empty set.  It was suggested on IRC this is a bug and just not my misunderstanding how the API should work.
>How-To-Repeat:
Compile and run following code:

```
#include <sched.h>
#include <unistd.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) {
  long rc = -1;
  cpuset_t* set = cpuset_create();
  if (set != NULL) {
    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;
}
```

the output is:

```
cpuset_isset(0, 0x7c712ce02008) -> 0
cpuset_isset(1, 0x7c712ce02008) -> 0
cpuset_isset(2, 0x7c712ce02008) -> 0
cpuset_isset(3, 0x7c712ce02008) -> 0
cpuset_isset(4, 0x7c712ce02008) -> 0
cpuset_isset(5, 0x7c712ce02008) -> 0
cpuset_isset(6, 0x7c712ce02008) -> 0
cpuset_isset(7, 0x7c712ce02008) -> 0
cpuset_isset(8, 0x7c712ce02008) -> 0
cpuset_isset(9, 0x7c712ce02008) -> 0
cpuset_isset(10, 0x7c712ce02008) -> 0
cpuset_isset(11, 0x7c712ce02008) -> 0
cpuset_isset(12, 0x7c712ce02008) -> 0
cpuset_isset(13, 0x7c712ce02008) -> 0
cpuset_isset(14, 0x7c712ce02008) -> 0
cpuset_isset(15, 0x7c712ce02008) -> 0
cpuset_isset(16, 0x7c712ce02008) -> 0
cpuset_isset(17, 0x7c712ce02008) -> 0
cpuset_isset(18, 0x7c712ce02008) -> 0
cpuset_isset(19, 0x7c712ce02008) -> 0
cpuset_isset(20, 0x7c712ce02008) -> 0
cpuset_isset(21, 0x7c712ce02008) -> 0
cpuset_isset(22, 0x7c712ce02008) -> 0
cpuset_isset(23, 0x7c712ce02008) -> 0
cpuset_isset(24, 0x7c712ce02008) -> 0
cpuset_isset(25, 0x7c712ce02008) -> 0
cpuset_isset(26, 0x7c712ce02008) -> 0
cpuset_isset(27, 0x7c712ce02008) -> 0
cpuset_isset(28, 0x7c712ce02008) -> 0
cpuset_isset(29, 0x7c712ce02008) -> 0
cpuset_isset(30, 0x7c712ce02008) -> 0
cpuset_isset(31, 0x7c712ce02008) -> 0
cpuset_isset(32, 0x7c712ce02008) -> -1
Number of processors reported by sched_getaffinity_np: 0
Number of processors reported by sysconf(_SC_NPROCESSORS_ONLN): 6
```
>Fix:
:shrug:



Home | Main Index | Thread Index | Old Index