diff options
Diffstat (limited to 'regressions')
-rw-r--r-- | regressions/Makefile | 1 | ||||
-rw-r--r-- | regressions/ck_sequence/validate/ck_sequence.c | 2 | ||||
-rw-r--r-- | regressions/common.h | 62 |
3 files changed, 60 insertions, 5 deletions
diff --git a/regressions/Makefile b/regressions/Makefile index c74b4fa..1dbf988 100644 --- a/regressions/Makefile +++ b/regressions/Makefile @@ -18,7 +18,6 @@ DIR=array \ queue \ ring \ rwlock \ - swlock \ sequence \ spinlock \ stack \ diff --git a/regressions/ck_sequence/validate/ck_sequence.c b/regressions/ck_sequence/validate/ck_sequence.c index 47de852..5c85d44 100644 --- a/regressions/ck_sequence/validate/ck_sequence.c +++ b/regressions/ck_sequence/validate/ck_sequence.c @@ -124,7 +124,7 @@ main(int argc, char *argv[]) n_threads = atoi(argv[1]) - 1; if (n_threads <= 0) { - ck_error("ERROR: Number of threads must be greater than 0\n"); + return 0; /* nothing to do */ } threads = malloc(sizeof(pthread_t) * n_threads); 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 |