diff options
author | Tom Jones <thj@freebsd.org> | 2024-08-14 09:23:11 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@0xa5.net> | 2024-08-29 08:36:25 +0000 |
commit | 828353fa5f461319ef05d23984418a7652dd6315 (patch) | |
tree | d8d8577952c4ba4ad75ed3468e79fff1503d8042 | |
parent | d726f6a99968b0e198b20b7d6cd21a6b64ce7909 (diff) |
vppinfra: Use affinity for online cpus on FreeBSD
On FreeBSD the affinity returned by cpuset gives us a bitmask
documenting the available cpus. This can be modified if we are jailed or
are launched via the cpuset(1) command.
Initialise the clib bitmask otherwise it is always 0 and we cannot
configure any workers.
Type: improvement
Change-Id: I067e373ea440c6fbd03839d1cf103c8b97d8a0c6
Signed-off-by: Tom Jones <thj@freebsd.org>
-rw-r--r-- | src/vppinfra/unix-misc.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c index 88a56d88afc..05ca2f901c6 100644 --- a/src/vppinfra/unix-misc.c +++ b/src/vppinfra/unix-misc.c @@ -67,6 +67,8 @@ __clib_export __thread uword __os_thread_index = 0; __clib_export __thread uword __os_numa_index = 0; +__clib_export clib_bitmap_t *os_get_cpu_affinity_bitmap (int pid); + clib_error_t * clib_file_n_bytes (char *file, uword * result) { @@ -275,6 +277,8 @@ os_get_online_cpu_core_bitmap () { #if __linux__ return clib_sysfs_read_bitmap ("/sys/devices/system/cpu/online"); +#elif defined(__FreeBSD__) + return os_get_cpu_affinity_bitmap (0); #else return 0; #endif @@ -309,6 +313,9 @@ os_get_cpu_affinity_bitmap (int pid) cpuset_t mask; uword *r = NULL; + clib_bitmap_alloc (r, sizeof (CPU_SETSIZE)); + clib_bitmap_zero (r); + if (cpuset_getaffinity (CPU_LEVEL_CPUSET, CPU_WHICH_CPUSET, -1, sizeof (mask), &mask) != 0) { @@ -330,21 +337,6 @@ os_get_online_cpu_node_bitmap () { #if __linux__ return clib_sysfs_read_bitmap ("/sys/devices/system/node/online"); -#elif defined(__FreeBSD__) - domainset_t domain; - uword *r = NULL; - int policy; - - if (cpuset_getdomain (CPU_LEVEL_CPUSET, CPU_WHICH_CPUSET, -1, - sizeof (domain), &domain, &policy) != 0) - { - clib_bitmap_free (r); - return NULL; - } - - for (int bit = 0; bit < CPU_SETSIZE; bit++) - clib_bitmap_set (r, bit, CPU_ISSET (bit, &domain)); - return r; #else return 0; #endif |