aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/unix-misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/unix-misc.c')
-rw-r--r--src/vppinfra/unix-misc.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c
index 29cbe0a557d..31c0a489e8d 100644
--- a/src/vppinfra/unix-misc.c
+++ b/src/vppinfra/unix-misc.c
@@ -35,6 +35,10 @@
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <vppinfra/error.h>
#include <vppinfra/os.h>
#include <vppinfra/bitmap.h>
@@ -42,13 +46,19 @@
#include <vppinfra/format.h>
#ifdef __linux__
#include <vppinfra/linux/sysfs.h>
-#else
+#include <sched.h>
+#elif defined(__FreeBSD__)
+#define _WANT_FREEBSD_BITSET
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/cpuset.h>
+#include <sys/domainset.h>
#include <sys/sysctl.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/syscall.h>
#include <sys/uio.h> /* writev */
#include <fcntl.h>
#include <stdio.h> /* for sprintf */
@@ -290,7 +300,7 @@ os_get_cpu_affinity_bitmap (int pid)
__CPU_ZERO_S (sizeof (cpu_set_t), &cpuset);
- ret = syscall (SYS_sched_getaffinity, 0, sizeof (cpu_set_t), &cpuset);
+ ret = sched_getaffinity (0, sizeof (cpu_set_t), &cpuset);
if (ret < 0)
{
@@ -302,8 +312,23 @@ os_get_cpu_affinity_bitmap (int pid)
if (__CPU_ISSET_S (index, sizeof (cpu_set_t), &cpuset))
clib_bitmap_set (affinity_cpus, index, 1);
return affinity_cpus;
+#elif defined(__FreeBSD__)
+ cpuset_t mask;
+ uword *r = NULL;
+
+ if (cpuset_getaffinity (CPU_LEVEL_CPUSET, CPU_WHICH_CPUSET, -1,
+ sizeof (mask), &mask) != 0)
+ {
+ clib_bitmap_free (r);
+ return NULL;
+ }
+
+ for (int bit = 0; bit < CPU_SETSIZE; bit++)
+ clib_bitmap_set (r, bit, CPU_ISSET (bit, &mask));
+
+ return r;
#else
- return 0;
+ return NULL;
#endif
}
@@ -312,6 +337,21 @@ 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