* Register memory within DPDK
- If IOVA table is not specified, IOVA addresses will be assumed to be
unavailable
+ - Other processes must attach to the memory area before they can use it
* Perform DMA mapping with ``rte_vfio_dma_map`` if needed
* Use the memory area in your application
* If memory area is no longer needed, it can be unregistered
- If the area was mapped for DMA, unmapping must be performed before
unregistering memory
+ - Other processes must detach from the memory area before it can be
+ unregistered
Since these externally allocated memory areas will not be managed by DPDK, it is
therefore up to the user application to decide how to use them and what to do
return ret;
}
+static int
+sync_memory(void *va_addr, size_t len, bool attach)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ struct rte_memseg_list *msl;
+ int ret = 0;
+
+ if (va_addr == NULL || len == 0) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+ rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+
+ /* find our segment */
+ msl = malloc_heap_find_external_seg(va_addr, len);
+ if (msl == NULL) {
+ rte_errno = ENOENT;
+ ret = -1;
+ goto unlock;
+ }
+ if (attach)
+ ret = rte_fbarray_attach(&msl->memseg_arr);
+ else
+ ret = rte_fbarray_detach(&msl->memseg_arr);
+
+unlock:
+ rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+ return ret;
+}
+
+int __rte_experimental
+rte_extmem_attach(void *va_addr, size_t len)
+{
+ return sync_memory(va_addr, len, true);
+}
+
+int __rte_experimental
+rte_extmem_detach(void *va_addr, size_t len)
+{
+ return sync_memory(va_addr, len, false);
+}
+
/* init memory subsystem */
int
rte_eal_memory_init(void)
* @note This API will not perform any DMA mapping. It is expected that user
* will do that themselves.
*
+ * @note Before accessing this memory in other processes, it needs to be
+ * attached in each of those processes by calling ``rte_extmem_attach`` in
+ * each other process.
+ *
* @param va_addr
* Start of virtual area to register. Must be aligned by ``page_sz``.
* @param len
* @note This API will not perform any DMA unmapping. It is expected that user
* will do that themselves.
*
+ * @note Before calling this function, all other processes must call
+ * ``rte_extmem_detach`` to detach from the memory area.
+ *
* @param va_addr
* Start of virtual area to unregister
* @param len
int __rte_experimental
rte_extmem_unregister(void *va_addr, size_t len);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Attach to external memory chunk registered in another process.
+ *
+ * @note Using this API is mutually exclusive with ``rte_malloc`` family of
+ * API's.
+ *
+ * @note This API will not perform any DMA mapping. It is expected that user
+ * will do that themselves.
+ *
+ * @param va_addr
+ * Start of virtual area to register
+ * @param len
+ * Length of virtual area to register
+ *
+ * @return
+ * - 0 on success
+ * - -1 in case of error, with rte_errno set to one of the following:
+ * EINVAL - one of the parameters was invalid
+ * ENOENT - memory chunk was not found
+ */
+int __rte_experimental
+rte_extmem_attach(void *va_addr, size_t len);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Detach from external memory chunk registered in another process.
+ *
+ * @note Using this API is mutually exclusive with ``rte_malloc`` family of
+ * API's.
+ *
+ * @note This API will not perform any DMA unmapping. It is expected that user
+ * will do that themselves.
+ *
+ * @param va_addr
+ * Start of virtual area to unregister
+ * @param len
+ * Length of virtual area to unregister
+ *
+ * @return
+ * - 0 on success
+ * - -1 in case of error, with rte_errno set to one of the following:
+ * EINVAL - one of the parameters was invalid
+ * ENOENT - memory chunk was not found
+ */
+int __rte_experimental
+rte_extmem_detach(void *va_addr, size_t len);
+
/**
* Dump the physical memory layout to a file.
*