Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
#define DISPATCH_WORKQ_MAX_PTHREAD_COUNT 255
#endif

#include "shims/hw_config.h"
#include "shims/priority.h"

#if HAVE_PTHREAD_NP_H
#include <pthread_np.h>
#endif
Expand All @@ -69,6 +66,9 @@
#include <pthread/private.h>
#endif

#include "shims/hw_config.h"
#include "shims/priority.h"

#if !HAVE_DECL_FD_COPY
#define FD_COPY(f, t) (void)(*(t) = *(f))
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/shims/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ static inline uint32_t
_dispatch_hw_get_config(_dispatch_hw_config_t c)
{
uint32_t val = 1;
#if defined(__linux__) && HAVE_SYSCONF
#if defined(__FreeBSD__) || (defined(__linux__) && HAVE_SYSCONF)
switch (c) {
case _dispatch_hw_config_logical_cpus:
case _dispatch_hw_config_physical_cpus:
return (uint32_t)sysconf(_SC_NPROCESSORS_CONF);
case _dispatch_hw_config_active_cpus:
{
#ifdef __USE_GNU
#if defined(__FreeBSD__) || __USE_GNU
// Prefer pthread_getaffinity_np because it considers
// scheduler cpu affinity. This matters if the program
// is restricted to a subset of the online cpus (eg via numactl).
Expand Down
10 changes: 7 additions & 3 deletions tests/dispatch_workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#if defined(__linux__)
// For pthread_getaffinity_np()
#include <pthread.h>
#elif defined(__FreeBSD__)
// for pthread_getaffinity_np / cpu_set_t
#include <pthread.h>
#include <pthread_np.h>
#endif

struct test_context {
Expand Down Expand Up @@ -37,11 +41,11 @@ spin(void *context)
static uint32_t
activecpu(void)
{
uint32_t activecpu;
#if defined(__linux__) || defined(__OpenBSD__)
uint32_t activecpu = 0xa1a1a1;
#if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__)
activecpu = (uint32_t)sysconf(_SC_NPROCESSORS_ONLN);

#if defined(__linux__) && __USE_GNU
#if defined(__FreeBSD__) || (defined(__linux__) && __USE_GNU)
cpu_set_t cpuset;
if (pthread_getaffinity_np(pthread_self(),
sizeof(cpu_set_t),
Expand Down