Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/dragonflybsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: DragonflyBSD

on:
pull_request:
push:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-DragonflyBSD
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Tests
id: test
uses: vmactions/dragonflybsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y socat git gmake bash
run: |
cd $GITHUB_WORKSPACE
./configure
gmake -j4
gmake run

33 changes: 33 additions & 0 deletions .github/workflows/freebsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: FreeBSD

on:
pull_request:
push:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-FreeBSD
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Tests
uses: vmactions/freebsd-vm@v1
with:
usesh: true
mem: 4096
copyback: false
prepare: pkg install -y git curl unzip gmake llvm gsed bash perl5
run: |
./configure
gmake -j4
gmake run
34 changes: 34 additions & 0 deletions .github/workflows/netbsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: NetBSD

on:
pull_request:
push:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-NetBSD
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Tests
id: test
uses: vmactions/netbsd-vm@v1
with:
usesh: true
prepare: |
/usr/sbin/pkg_add curl bash git gmake
run: |
cd $GITHUB_WORKSPACE
./configure
gmake -j4
gmake run

35 changes: 35 additions & 0 deletions .github/workflows/openbsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: OpenBSD

on:
pull_request:
push:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-OpenBSD
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Tests
id: test
uses: vmactions/openbsd-vm@v1
with:
usesh: true
prepare: |
pkg_add curl git gmake bash gcc
ln -sf /usr/local/bin/gmake /usr/local/bin/make || true
run: |
cd $GITHUB_WORKSPACE
./configure
gmake -j4
gmake run

34 changes: 34 additions & 0 deletions .github/workflows/solaris.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Solaris

on:
pull_request:
push:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Solaris
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Tests
id: test
uses: vmactions/solaris-vm@v1
with:
usesh: true
prepare: |
pkgutil -y -i socat git gmake bash gcc4g++ || pkgutil -y -i socat git gmake bash gcc5g++ || pkg install -y developer/gcc || true
run: |
cd $GITHUB_WORKSPACE
bash ./configure
gmake -j4
gmake run

12 changes: 9 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,11 @@ case "${os_host}" in
*darwin*) os_host="macosx" ;;
*linux*) os_host="linux" ;;
*freebsd*) os_host="freebsd" ;;
*netbsd*) os_host="netbsd" ;;
*openbsd*) os_host="openbsd" ;;
*dragonfly*) os_host="dragonflybsd" ;;
*bsd*) os_host="bsd" ;;
*sunos*) os_host="solaris" ;;
*haiku*) os_host="haiku" ;;
esac

Expand All @@ -708,8 +712,10 @@ is_host() {

# detect host architecture
os_arch=`uname -m | tr '[A-Z]' '[a-z]'`
if test_eq "${os_arch}" "i686"; then
if test_eq "${os_arch}" "i686" "i86pc"; then
os_arch="i386"
elif test_eq "${os_arch}" "amd64"; then
os_arch="x86_64"
elif test_eq "${os_arch}" "aarch64" || test_eq "${os_arch}" "arm64"; then
os_arch="arm64"
elif string_contains "${os_arch}" "armv7"; then
Expand All @@ -724,7 +730,7 @@ fi
_target_plat_default=${os_host}
if is_host "msys"; then
_target_plat_default="mingw"
elif is_host "freebsd"; then
elif is_host "freebsd" "openbsd" "dragonflybsd" "netbsd"; then
_target_plat_default="bsd"
elif test_nz "${EMSDK}"; then
_target_plat_default="wasm"
Expand Down Expand Up @@ -756,7 +762,7 @@ _target_mode_default="release"
_target_kind_default="static"

# set the default project generator and build program
if is_host "freebsd" "bsd"; then
if is_host "freebsd" "netbsd" "openbsd" "dragonflybsd" "bsd" "solaris"; then
project_generator="gmake"
_make_program_default="gmake"
_ninja_program_default="ninja"
Expand Down
48 changes: 46 additions & 2 deletions src/tbox/platform/posix/sched_affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <string.h>
#include <sched.h>
#include <sys/types.h>
#ifdef __NetBSD__
#include <sched.h>
#endif

/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
Expand All @@ -36,7 +39,23 @@ tb_bool_t tb_sched_setaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
// check
tb_assert_and_check_return_val(cpuset, tb_false);

// set cpu affinity
#ifdef __NetBSD__
// NetBSD uses cpuset_t API for process affinity
cpuset_t *cpu_set = cpuset_create();
if (!cpu_set)
return tb_false;

tb_int_t i;
for (i = 0; i < TB_CPUSET_SIZE; i++)
{
if (TB_CPUSET_ISSET(i, cpuset))
cpuset_set(i, cpu_set);
}
tb_bool_t ok = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, cpuset_size(cpu_set), cpu_set) == 0;
cpuset_destroy(cpu_set);
return ok;
#else
// Linux uses cpu_set_t API
tb_int_t i;
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
Expand All @@ -46,13 +65,37 @@ tb_bool_t tb_sched_setaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
CPU_SET(i, &cpu_set);
}
return sched_setaffinity((pid_t)pid, sizeof(cpu_set_t), &cpu_set) == 0;
#endif
}
tb_bool_t tb_sched_getaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
{
// check
tb_assert_and_check_return_val(cpuset, tb_false);

// get cpu affinity
#ifdef __NetBSD__
// NetBSD uses cpuset_t API for process affinity
cpuset_t *cpu_set = cpuset_create();
if (!cpu_set)
return tb_false;

if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, cpuset_size(cpu_set), cpu_set) != 0)
{
cpuset_destroy(cpu_set);
return tb_false;
}

// save cpuset
tb_int_t i;
TB_CPUSET_ZERO(cpuset);
for (i = 0; i < TB_CPUSET_SIZE; i++)
{
if (cpuset_isset(i, cpu_set))
TB_CPUSET_SET(i, cpuset);
}
cpuset_destroy(cpu_set);
return tb_true;
#else
// Linux uses cpu_set_t API
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
if (sched_getaffinity((pid_t)pid, sizeof(cpu_set_t), &cpu_set) != 0)
Expand All @@ -67,4 +110,5 @@ tb_bool_t tb_sched_getaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
TB_CPUSET_SET(i, cpuset);
}
return tb_true;
#endif
}
48 changes: 46 additions & 2 deletions src/tbox/platform/posix/thread_affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "../thread.h"
#include <pthread.h>
#include <string.h>
#ifdef __NetBSD__
#include <sched.h>
#endif

/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
Expand All @@ -39,7 +42,23 @@ tb_bool_t tb_thread_setaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
// get thread
pthread_t pthread = thread? *((pthread_t*)thread) : pthread_self();

// set cpu affinity
#ifdef __NetBSD__
// NetBSD uses cpuset_t API
cpuset_t *cpu_set = cpuset_create();
if (!cpu_set)
return tb_false;

tb_int_t i;
for (i = 0; i < TB_CPUSET_SIZE; i++)
{
if (TB_CPUSET_ISSET(i, cpuset))
cpuset_set(i, cpu_set);
}
tb_bool_t ok = pthread_setaffinity_np(pthread, cpuset_size(cpu_set), cpu_set) == 0;
cpuset_destroy(cpu_set);
return ok;
#else
// Linux uses cpu_set_t API
tb_int_t i;
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
Expand All @@ -49,6 +68,7 @@ tb_bool_t tb_thread_setaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
CPU_SET(i, &cpu_set);
}
return pthread_setaffinity_np(pthread, sizeof(cpu_set_t), &cpu_set) == 0;
#endif
}
tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
{
Expand All @@ -58,7 +78,30 @@ tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
// get thread
pthread_t pthread = thread? *((pthread_t*)thread) : pthread_self();

// get cpu affinity
#ifdef __NetBSD__
// NetBSD uses cpuset_t API
cpuset_t *cpu_set = cpuset_create();
if (!cpu_set)
return tb_false;

if (pthread_getaffinity_np(pthread, cpuset_size(cpu_set), cpu_set) != 0)
{
cpuset_destroy(cpu_set);
return tb_false;
}

// save cpuset
tb_int_t i;
TB_CPUSET_ZERO(cpuset);
for (i = 0; i < TB_CPUSET_SIZE; i++)
{
if (cpuset_isset(i, cpu_set))
TB_CPUSET_SET(i, cpuset);
}
cpuset_destroy(cpu_set);
return tb_true;
#else
// Linux uses cpu_set_t API
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
if (pthread_getaffinity_np(pthread, sizeof(cpu_set_t), &cpu_set) != 0)
Expand All @@ -73,4 +116,5 @@ tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
TB_CPUSET_SET(i, cpuset);
}
return tb_true;
#endif
}
2 changes: 2 additions & 0 deletions src/xmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ if is_plat "mingw" "msys" "cygwin"; then
add_syslinks "ws2_32" "pthread" "m"
elif is_plat "haiku"; then
add_syslinks "pthread" "network" "m" "c"
elif is_plat "bsd" "solaris"; then
add_syslinks "pthread" "m"
else
add_syslinks "pthread" "dl" "m" "c"
fi
Expand Down
Loading