diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 07:50:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 07:50:14 +0000 |
commit | 7020f6bf1e08bb16ab742cfd17b109e196096ee2 (patch) | |
tree | 7ef0713cfca533a50589c9c64577c7986b485042 /regressions/common.h | |
parent | Adding upstream version 0.7.1. (diff) | |
download | ck-upstream/0.7.2.tar.xz ck-upstream/0.7.2.zip |
Adding upstream version 0.7.2.upstream/0.7.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'regressions/common.h')
-rw-r--r-- | regressions/common.h | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/regressions/common.h b/regressions/common.h index 9cdc690..4d3d782 100644 --- a/regressions/common.h +++ b/regressions/common.h @@ -34,16 +34,24 @@ #include <stdlib.h> #include <sys/time.h> -#ifdef __linux__ +#if defined(__linux__) || defined(__DragonFly__) #include <sched.h> #include <sys/types.h> #include <sys/syscall.h> +#if defined(__DragonFly__) +#include <sys/sched.h> +#include <pthread_np.h> +#endif #elif defined(__MACH__) +#include <errno.h> #include <mach/mach.h> #include <mach/thread_policy.h> #elif defined(__FreeBSD__) #include <sys/param.h> #include <sys/cpuset.h> +#elif defined(__NetBSD__) +#include <pthread.h> +#include <sched.h> #endif #if defined(_WIN32) @@ -266,11 +274,15 @@ struct affinity { #define AFFINITY_INITIALIZER {0, 0} -#ifdef __linux__ +#if defined(__linux__) || defined(__DragonFly__) static pid_t common_gettid(void) { +#if defined(__linux__) return syscall(__NR_gettid); +#else + return pthread_getthreadid_np(); +#endif } CK_CC_UNUSED static int @@ -309,13 +321,19 @@ aff_iterate(struct affinity *acb) { thread_affinity_policy_data_t policy; unsigned int c; + int err; c = ck_pr_faa_uint(&acb->request, acb->delta) % CORES; policy.affinity_tag = c; - return thread_policy_set(mach_thread_self(), + err = thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, THREAD_AFFINITY_POLICY_COUNT); + if (err == KERN_NOT_SUPPORTED) + return 0; + if (err != 0) + errno = EINVAL; + return err; } CK_CC_UNUSED static int @@ -355,6 +373,39 @@ aff_iterate_core(struct affinity *acb CK_CC_UNUSED, unsigned int *core) return (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask), &mask)); } +#elif defined(__NetBSD__) +CK_CC_UNUSED static int +aff_iterate(struct affinity *acb CK_CC_UNUSED) +{ + unsigned int c; + cpuset_t *mask; + + c = ck_pr_faa_uint(&acb->request, acb->delta) % CORES; + mask = cpuset_create(); + if (!mask) + return -1; + cpuset_zero(mask); + cpuset_set(c, mask); + int ret = pthread_setaffinity_np(pthread_self(), cpuset_size(mask), mask); + cpuset_destroy(mask); + return ret; +} + +CK_CC_UNUSED static int +aff_iterate_core(struct affinity *acb CK_CC_UNUSED, unsigned int *core) +{ + cpuset_t *mask; + + *core = ck_pr_faa_uint(&acb->request, acb->delta) % CORES; + mask = cpuset_create(); + if (!mask) + return -1; + cpuset_zero(mask); + cpuset_set(*core, mask); + int ret = pthread_setaffinity_np(pthread_self(), cpuset_size(mask), mask); + cpuset_destroy(mask); + return ret; +} #else CK_CC_UNUSED static int aff_iterate(struct affinity *acb CK_CC_UNUSED) @@ -451,6 +502,11 @@ rdtsc(void) __asm __volatile__ ("mrs %0, cntvct_el0" : "=r" (r) : : "memory"); return r; +#elif defined(__riscv) && __riscv_xlen == 64 + uint64_t r; + + __asm __volatile__("rdtime %0" : "=r" (r) :: "memory"); + return r; #else return 0; #endif |