ports/sysutils/roct/files/patch-src_fmm.c
Johannes M Dieterich 0b9475cf6c new ports: sysutils/rocr and sysutils/roct
roct is the ROC thunk interface  and rocr is the ROCm platform runtime.
Together these form the userspace partners to the amdkfd compute driver.
Hence, in the current absence of a working amdkfd on FreeBSD, these ports do
not function yet. They are integrated to facilitate integration of amdkfd and
test it as part of the LinuxKPI-based DRM.

Note that these ports are for the time being based off my forks with FreeBSD
bringup bits, I'll work with the corresponding upstream teams to get patches
reviewed and integrated.

Limit these ports to amd64, as even our upstream does not support anything but
that for the time being.

Version numbers correspond to the overall ROCm release, currently 1.9.1.
2018-11-19 04:05:31 +00:00

45 lines
1.6 KiB
C

--- src/fmm.c.orig 2018-11-19 01:35:23 UTC
+++ src/fmm.c
@@ -37,7 +37,9 @@
#include <sys/time.h>
#include <errno.h>
#include <pci/pci.h>
+#ifdef __linux__
#include <numaif.h>
+#endif
#ifndef MPOL_F_STATIC_NODES
/* Bug in numaif.h, this should be defined in there. Definition copied
* from linux/mempolicy.h.
@@ -1207,7 +1209,9 @@ static void *fmm_allocate_host_gpu(uint32_t node_id, u
if (!flags.ui32.NonPaged && svm.userptr_for_paged_mem) {
const unsigned int bits_per_long = sizeof(unsigned long) * 8;
unsigned long node_mask[node_id / bits_per_long + 1];
+#ifdef __linux__
int mode = MPOL_F_STATIC_NODES;
+#endif
/* Allocate address space */
pthread_mutex_lock(&aperture->fmm_mutex);
@@ -1219,10 +1223,12 @@ static void *fmm_allocate_host_gpu(uint32_t node_id, u
/* Bind to NUMA node */
memset(node_mask, 0, sizeof(node_mask));
node_mask[node_id / bits_per_long] = 1UL << (node_id % bits_per_long);
+#ifdef __linux__
mode |= flags.ui32.NoSubstitute ? MPOL_BIND : MPOL_PREFERRED;
if (mbind(mem, MemorySizeInBytes, mode, node_mask, node_id+1, 0))
pr_warn("Failed to set NUMA policy for %lu pages at %p\n",
MemorySizeInBytes >> 12, mem);
+#endif
/* Map anonymous pages */
if (mmap(mem, MemorySizeInBytes, PROT_READ | PROT_WRITE,
@@ -1334,7 +1340,9 @@ static void __fmm_release(void *address, manageable_ap
if (address >= dgpu_shared_aperture_base &&
address <= dgpu_shared_aperture_limit) {
/* Reset NUMA policy */
+#ifdef __linux__
mbind(address, object->size, MPOL_DEFAULT, NULL, 0, 0);
+#endif
munmap_and_reserve_address(address, object->size);
}