gnu: add pthread_setaffinity_np()/pthread_getaffinity_np()

* also sched_setaffinity/sched_getaffinity() added.
* add a test

Change-Id: Id8c308788f6364f5340b4991def2fbb9a05da728
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7675
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Jérôme Duval
2024-06-10 16:34:25 +00:00
committed by waddlesplash
parent f7a85eea15
commit c5a740cdb2
7 changed files with 151 additions and 1 deletions
+6
View File
@@ -12,6 +12,9 @@
#ifdef _GNU_SOURCE
#include <sched.h>
#ifdef __cplusplus
extern "C" {
#endif
@@ -22,6 +25,9 @@ extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
extern int pthread_setname_np(pthread_t thread, const char* name);
extern int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpuset_t* mask);
extern int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpuset_t* mask);
#ifdef __cplusplus
}
+36
View File
@@ -8,15 +8,51 @@
#include_next <sched.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef _GNU_SOURCE
#ifndef CPU_SETSIZE
#define CPU_SETSIZE 1024
#endif
typedef __haiku_uint32 cpuset_mask;
#ifndef _howmany
#define _howmany(x, y) (((x) + ((y) - 1)) / (y))
#endif
#define NCPUSETBITS (sizeof(cpuset_mask) * 8) /* bits per mask */
typedef struct _cpuset {
cpuset_mask bits[_howmany(CPU_SETSIZE, NCPUSETBITS)];
} cpuset_t;
#define _CPUSET_BITSINDEX(cpu) ((cpu) / NCPUSETBITS)
#define _CPUSET_BIT(cpu) (1L << ((cpu) % NCPUSETBITS))
/* FD_ZERO uses memset */
#include <string.h>
#define CPUSET_ZERO(set) memset((set), 0, sizeof(cpuset_t))
#define CPUSET_SET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] |= _CPUSET_BIT(cpu))
#define CPUSET_CLR(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] &= ~_CPUSET_BIT(cpu))
#define CPUSET_ISSET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] & _CPUSET_BIT(cpu))
#define CPUSET_COPY(source, target) (*(target) = *(source))
#ifdef __cplusplus
extern "C" {
#endif
extern int sched_getcpu(void);
extern int sched_setaffinity(pid_t id, size_t cpusetsize, const cpuset_t* mask);
extern int sched_getaffinity(pid_t id, size_t cpusetsize, cpuset_t* mask);
#ifdef __cplusplus
}