From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
David Marchand <david.marchand@redhat.com>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Haiyue Wang <haiyue.wang@intel.com>,
Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>,
Jerin Jacob <jerinj@marvell.com>,
Ferruh Yigit <ferruh.yigit@intel.com>,
Elena Agostini <eagostini@nvidia.com>,
Ray Kinsella <mdr@ashroe.eu>
Subject: [dpdk-dev] [RFC PATCH v2 5/7] hcdev: add memory API
Date: Fri, 30 Jul 2021 15:55:31 +0200 [thread overview]
Message-ID: <20210730135533.417611-6-thomas@monjalon.net> (raw)
In-Reply-To: <20210730135533.417611-1-thomas@monjalon.net>
From: Elena Agostini <eagostini@nvidia.com>
In heterogeneous computing system, processing is not only in the CPU.
Some tasks can be delegated to devices working in parallel.
Such workload distribution can be achieved by sharing some memory.
As a first step, the features are focused on memory management.
A function allows to allocate memory inside the device,
or in the main (CPU) memory while making it visible for the device.
This memory may be used to save packets or for synchronization data.
The next step should focus on GPU processing task control.
Signed-off-by: Elena Agostini <eagostini@nvidia.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
doc/guides/hcdevs/features/default.ini | 3 +
doc/guides/rel_notes/release_21_08.rst | 1 +
lib/hcdev/hcdev.c | 88 ++++++++++++++++++++++++++
lib/hcdev/hcdev_driver.h | 9 +++
lib/hcdev/rte_hcdev.h | 53 ++++++++++++++++
lib/hcdev/version.map | 2 +
6 files changed, 156 insertions(+)
diff --git a/doc/guides/hcdevs/features/default.ini b/doc/guides/hcdevs/features/default.ini
index f988ee73d4..ee32753d94 100644
--- a/doc/guides/hcdevs/features/default.ini
+++ b/doc/guides/hcdevs/features/default.ini
@@ -8,3 +8,6 @@
;
[Features]
Get device info =
+Share CPU memory with device =
+Allocate device memory =
+Free memory =
diff --git a/doc/guides/rel_notes/release_21_08.rst b/doc/guides/rel_notes/release_21_08.rst
index fb350b4706..e955a331a6 100644
--- a/doc/guides/rel_notes/release_21_08.rst
+++ b/doc/guides/rel_notes/release_21_08.rst
@@ -58,6 +58,7 @@ New Features
* **Introduced Heterogeneous Computing Device library with first features:**
* Device information
+ * Memory management
* **Added auxiliary bus support.**
diff --git a/lib/hcdev/hcdev.c b/lib/hcdev/hcdev.c
index a7badd122b..621e0b99bd 100644
--- a/lib/hcdev/hcdev.c
+++ b/lib/hcdev/hcdev.c
@@ -6,6 +6,7 @@
#include <rte_tailq.h>
#include <rte_string_fns.h>
#include <rte_memzone.h>
+#include <rte_malloc.h>
#include <rte_errno.h>
#include <rte_log.h>
@@ -501,3 +502,90 @@ rte_hcdev_info_get(int16_t dev_id, struct rte_hcdev_info *info)
}
return HCDEV_DRV_RET(dev->ops.dev_info_get(dev, info));
}
+
+#define RTE_HCDEV_MALLOC_FLAGS_ALL \
+ RTE_HCDEV_MALLOC_REGISTER_FROM_CPU
+#define RTE_HCDEV_MALLOC_FLAGS_RESERVED ~RTE_HCDEV_MALLOC_FLAGS_ALL
+
+void *
+rte_hcdev_malloc(int16_t dev_id, size_t size, uint32_t flags)
+{
+ struct rte_hcdev *dev;
+ void *ptr;
+ int ret;
+
+ dev = hcdev_get_by_id(dev_id);
+ if (dev == NULL) {
+ HCDEV_LOG(ERR, "alloc mem for invalid device ID %d", dev_id);
+ rte_errno = ENODEV;
+ return NULL;
+ }
+ if (flags & RTE_HCDEV_MALLOC_FLAGS_RESERVED) {
+ HCDEV_LOG(ERR, "alloc mem with reserved flag 0x%x",
+ flags & RTE_HCDEV_MALLOC_FLAGS_RESERVED);
+ rte_errno = EINVAL;
+ return NULL;
+ }
+
+ if (flags & RTE_HCDEV_MALLOC_REGISTER_FROM_CPU) {
+ if (dev->ops.mem_register == NULL) {
+ HCDEV_LOG(ERR, "mem registration not supported");
+ rte_errno = ENOTSUP;
+ return NULL;
+ }
+ } else {
+ if (dev->ops.mem_alloc == NULL) {
+ HCDEV_LOG(ERR, "mem allocation not supported");
+ rte_errno = ENOTSUP;
+ return NULL;
+ }
+ }
+
+ if (size == 0) /* dry-run */
+ return NULL;
+
+ if (flags & RTE_HCDEV_MALLOC_REGISTER_FROM_CPU) {
+ ptr = rte_zmalloc(NULL, size, 0);
+ if (ptr == NULL) {
+ HCDEV_LOG(ERR, "cannot allocate CPU memory");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+ ret = dev->ops.mem_register(dev, size, ptr);
+ } else {
+ ret = dev->ops.mem_alloc(dev, size, &ptr);
+ }
+ /* TODO maintain a table of chunks registered/allocated */
+ switch (ret) {
+ case 0:
+ return ptr;
+ case -ENOMEM:
+ case -E2BIG:
+ rte_errno = -ret;
+ return NULL;
+ default:
+ rte_errno = EPERM;
+ return NULL;
+ }
+}
+
+int
+rte_hcdev_free(int16_t dev_id, void *ptr)
+{
+ struct rte_hcdev *dev;
+
+ dev = hcdev_get_by_id(dev_id);
+ if (dev == NULL) {
+ HCDEV_LOG(ERR, "free mem for invalid device ID %d", dev_id);
+ rte_errno = ENODEV;
+ return -rte_errno;
+ }
+
+ if (dev->ops.mem_free == NULL) {
+ rte_errno = ENOTSUP;
+ return -rte_errno;
+ }
+ return HCDEV_DRV_RET(dev->ops.mem_free(dev, ptr));
+ /* TODO unregister callback */
+ /* TODO rte_free CPU memory */
+}
diff --git a/lib/hcdev/hcdev_driver.h b/lib/hcdev/hcdev_driver.h
index f33b56947b..f42f08508f 100644
--- a/lib/hcdev/hcdev_driver.h
+++ b/lib/hcdev/hcdev_driver.h
@@ -27,12 +27,21 @@ enum rte_hcdev_state {
struct rte_hcdev;
typedef int (rte_hcdev_close_t)(struct rte_hcdev *dev);
typedef int (rte_hcdev_info_get_t)(struct rte_hcdev *dev, struct rte_hcdev_info *info);
+typedef int (rte_hcdev_mem_alloc_t)(struct rte_hcdev *dev, size_t size, void **ptr);
+typedef int (rte_hcdev_mem_register_t)(struct rte_hcdev *dev, size_t size, void *ptr);
+typedef int (rte_hcdev_free_t)(struct rte_hcdev *dev, void *ptr);
struct rte_hcdev_ops {
/* Get device info. If NULL, info is just copied. */
rte_hcdev_info_get_t *dev_info_get;
/* Close device or child context. */
rte_hcdev_close_t *dev_close;
+ /* Allocate memory in device. */
+ rte_hcdev_mem_alloc_t *mem_alloc;
+ /* Register CPU memory in device. */
+ rte_hcdev_mem_register_t *mem_register;
+ /* Free memory allocated or registered in device. */
+ rte_hcdev_free_t *mem_free;
};
struct rte_hcdev_mpshared {
diff --git a/lib/hcdev/rte_hcdev.h b/lib/hcdev/rte_hcdev.h
index c95f37063d..11895d9486 100644
--- a/lib/hcdev/rte_hcdev.h
+++ b/lib/hcdev/rte_hcdev.h
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include <rte_bitops.h>
#include <rte_compat.h>
/**
@@ -293,6 +294,58 @@ int rte_hcdev_callback_unregister(int16_t dev_id, enum rte_hcdev_event event,
__rte_experimental
int rte_hcdev_info_get(int16_t dev_id, struct rte_hcdev_info *info);
+/** Memory allocated on a CPU node and visible by the device. */
+#define RTE_HCDEV_MALLOC_REGISTER_FROM_CPU RTE_BIT32(0)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Allocate a chunk of memory usable by the device.
+ *
+ * @param dev_id
+ * Device ID requiring allocated memory.
+ * @param size
+ * Number of bytes to allocate.
+ * Requesting 0 will do nothing.
+ * @param flags
+ * If 0, the default is to allocate in the device memory.
+ * See flags RTE_HCDEV_MALLOC_*
+ *
+ * @return
+ * A pointer to the allocated memory, otherwise NULL and rte_errno is set:
+ * - ENODEV if invalid dev_id
+ * - EINVAL if reserved flags
+ * - ENOTSUP if operation not supported by the driver
+ * - E2BIG if size is higher than limit
+ * - ENOMEM if out of space
+ * - EPERM if driver error
+ */
+__rte_experimental
+void *rte_hcdev_malloc(int16_t dev_id, size_t size, uint32_t flags)
+__rte_alloc_size(2);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Deallocate a chunk of memory allocated with rte_hcdev_malloc().
+ *
+ * @param dev_id
+ * Reference device ID.
+ * @param ptr
+ * Pointer to the memory area to be deallocated.
+ * NULL is a no-op accepted value.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - ENODEV if invalid dev_id
+ * - ENOTSUP if operation not supported by the driver
+ * - EPERM if driver error
+ */
+__rte_experimental
+int rte_hcdev_free(int16_t dev_id, void *ptr);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/hcdev/version.map b/lib/hcdev/version.map
index 450c256527..9195f4f747 100644
--- a/lib/hcdev/version.map
+++ b/lib/hcdev/version.map
@@ -8,9 +8,11 @@ EXPERIMENTAL {
rte_hcdev_close;
rte_hcdev_count_avail;
rte_hcdev_find_next;
+ rte_hcdev_free;
rte_hcdev_info_get;
rte_hcdev_init;
rte_hcdev_is_valid;
+ rte_hcdev_malloc;
};
INTERNAL {
--
2.31.1
next prev parent reply other threads:[~2021-07-30 13:56 UTC|newest]
Thread overview: 128+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 20:35 [dpdk-dev] [PATCH] gpudev: introduce " Thomas Monjalon
2021-06-02 20:46 ` Stephen Hemminger
2021-06-02 20:48 ` Thomas Monjalon
2021-06-03 7:06 ` Andrew Rybchenko
2021-06-03 7:26 ` Thomas Monjalon
2021-06-03 7:49 ` Andrew Rybchenko
2021-06-03 8:26 ` Thomas Monjalon
2021-06-03 8:57 ` Andrew Rybchenko
2021-06-03 7:18 ` David Marchand
2021-06-03 7:30 ` Thomas Monjalon
2021-06-03 7:47 ` Jerin Jacob
2021-06-03 8:28 ` Thomas Monjalon
2021-06-03 8:41 ` Jerin Jacob
2021-06-03 8:43 ` Thomas Monjalon
2021-06-03 8:47 ` Jerin Jacob
2021-06-03 8:53 ` Thomas Monjalon
2021-06-03 9:20 ` Jerin Jacob
2021-06-03 9:36 ` Thomas Monjalon
2021-06-03 10:04 ` Jerin Jacob
2021-06-03 10:30 ` Thomas Monjalon
2021-06-03 11:38 ` Jerin Jacob
2021-06-04 12:55 ` Thomas Monjalon
2021-06-04 15:05 ` Jerin Jacob
2021-06-03 9:33 ` Ferruh Yigit
2021-06-04 10:28 ` Thomas Monjalon
2021-06-04 11:09 ` Jerin Jacob
2021-06-04 12:46 ` Thomas Monjalon
2021-06-04 13:05 ` Andrew Rybchenko
2021-06-04 13:18 ` Thomas Monjalon
2021-06-04 13:59 ` Andrew Rybchenko
2021-06-04 14:09 ` Thomas Monjalon
2021-06-04 15:20 ` Jerin Jacob
2021-06-04 15:51 ` Thomas Monjalon
2021-06-04 18:20 ` Wang, Haiyue
2021-06-05 5:09 ` Jerin Jacob
2021-06-06 1:13 ` Honnappa Nagarahalli
2021-06-06 5:28 ` Jerin Jacob
2021-06-07 10:29 ` Thomas Monjalon
2021-06-07 7:20 ` Wang, Haiyue
2021-06-07 10:43 ` Thomas Monjalon
2021-06-07 13:54 ` Jerin Jacob
2021-06-07 16:47 ` Thomas Monjalon
2021-06-08 4:10 ` Jerin Jacob
2021-06-08 6:34 ` Thomas Monjalon
2021-06-08 7:09 ` Jerin Jacob
2021-06-08 7:32 ` Thomas Monjalon
2021-06-15 18:24 ` Ferruh Yigit
2021-06-15 18:54 ` Thomas Monjalon
2021-06-07 23:31 ` Honnappa Nagarahalli
2021-06-04 5:51 ` Wang, Haiyue
2021-06-04 8:15 ` Thomas Monjalon
2021-06-04 11:07 ` Wang, Haiyue
2021-06-04 12:43 ` Thomas Monjalon
2021-06-04 13:25 ` Wang, Haiyue
2021-06-04 14:06 ` Thomas Monjalon
2021-06-04 18:04 ` Wang, Haiyue
2021-06-05 7:49 ` Thomas Monjalon
2021-06-05 11:09 ` Wang, Haiyue
2021-06-06 1:10 ` Honnappa Nagarahalli
2021-06-07 10:50 ` Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 0/7] heterogeneous computing library Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 1/7] hcdev: introduce heterogeneous computing device library Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 2/7] hcdev: add event notification Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 3/7] hcdev: add child device representing a device context Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 4/7] hcdev: support multi-process Thomas Monjalon
2021-07-30 13:55 ` Thomas Monjalon [this message]
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 6/7] hcdev: add communication flag Thomas Monjalon
2021-07-30 13:55 ` [dpdk-dev] [RFC PATCH v2 7/7] hcdev: add communication list Thomas Monjalon
2021-07-31 7:06 ` [dpdk-dev] [RFC PATCH v2 0/7] heterogeneous computing library Jerin Jacob
2021-07-31 8:21 ` Thomas Monjalon
2021-07-31 13:42 ` Jerin Jacob
2021-08-27 9:44 ` Thomas Monjalon
2021-08-27 12:19 ` Jerin Jacob
2021-08-29 5:32 ` Wang, Haiyue
2021-09-01 15:35 ` Elena Agostini
2021-09-02 13:12 ` Jerin Jacob
2021-09-06 16:11 ` Elena Agostini
2021-09-06 17:15 ` Wang, Haiyue
2021-09-06 17:22 ` Elena Agostini
2021-09-07 0:55 ` Wang, Haiyue
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 0/9] GPU library eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 1/9] gpudev: introduce GPU device class library eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 2/9] gpudev: add event notification eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 3/9] gpudev: add child device representing a device context eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 4/9] gpudev: support multi-process eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 5/9] gpudev: add memory API eagostini
2021-10-08 20:18 ` Thomas Monjalon
2021-10-29 19:38 ` Mattias Rönnblom
2021-11-08 15:16 ` Elena Agostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 6/9] gpudev: add memory barrier eagostini
2021-10-08 20:16 ` Thomas Monjalon
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 7/9] gpudev: add communication flag eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 8/9] gpudev: add communication list eagostini
2021-10-09 1:53 ` [dpdk-dev] [PATCH v3 9/9] doc: add CUDA example in GPU guide eagostini
2021-10-10 10:16 ` [dpdk-dev] [PATCH v3 0/9] GPU library Jerin Jacob
2021-10-11 8:18 ` Thomas Monjalon
2021-10-11 8:43 ` Jerin Jacob
2021-10-11 9:12 ` Thomas Monjalon
2021-10-11 9:29 ` Jerin Jacob
2021-10-11 10:27 ` Thomas Monjalon
2021-10-11 11:41 ` Jerin Jacob
2021-10-11 12:44 ` Thomas Monjalon
2021-10-11 13:30 ` Jerin Jacob
2021-10-19 10:00 ` Elena Agostini
2021-10-19 18:47 ` Jerin Jacob
2021-10-19 19:11 ` Thomas Monjalon
2021-10-19 19:56 ` [dpdk-dev] [EXT] " Jerin Jacob Kollanukkaran
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 " eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 1/9] gpudev: introduce GPU device class library eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 2/9] gpudev: add event notification eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 3/9] gpudev: add child device representing a device context eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 4/9] gpudev: support multi-process eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 5/9] gpudev: add memory API eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 6/9] gpudev: add memory barrier eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 7/9] gpudev: add communication flag eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 8/9] gpudev: add communication list eagostini
2021-11-03 19:15 ` [dpdk-dev] [PATCH v4 9/9] doc: add CUDA example in GPU guide eagostini
2021-11-08 18:57 ` [dpdk-dev] [PATCH v5 0/9] GPU library eagostini
2021-11-08 16:25 ` Thomas Monjalon
2021-11-08 18:57 ` [dpdk-dev] [PATCH v5 1/9] gpudev: introduce GPU device class library eagostini
2021-11-08 18:57 ` [dpdk-dev] [PATCH v5 2/9] gpudev: add event notification eagostini
2021-11-08 18:57 ` [dpdk-dev] [PATCH v5 3/9] gpudev: add child device representing a device context eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 4/9] gpudev: support multi-process eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 5/9] gpudev: add memory API eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 6/9] gpudev: add memory barrier eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 7/9] gpudev: add communication flag eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 8/9] gpudev: add communication list eagostini
2021-11-08 18:58 ` [dpdk-dev] [PATCH v5 9/9] doc: add CUDA example in GPU guide eagostini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210730135533.417611-6-thomas@monjalon.net \
--to=thomas@monjalon.net \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=eagostini@nvidia.com \
--cc=ferruh.yigit@intel.com \
--cc=haiyue.wang@intel.com \
--cc=honnappa.nagarahalli@arm.com \
--cc=jerinj@marvell.com \
--cc=mdr@ashroe.eu \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).