Loading include/spdk/env.h +30 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,36 @@ spdk_memzone_lookup(const char *name); int spdk_memzone_free(const char *name); struct spdk_mempool; /** * Create a thread-safe memory pool. Cache size is the number of * elements in a thread-local cache. Can be 0 for no caching, or -1 * for unspecified. */ struct spdk_mempool * spdk_mempool_create(const char *name, size_t count, size_t ele_size, size_t cache_size); /** * Free a memory pool. */ void spdk_mempool_free(struct spdk_mempool *mp); /** * Get an element from a memory pool. If no elements remain, return NULL. */ void * spdk_mempool_get(struct spdk_mempool *mp); /** * Put an element back into the memory pool. */ void spdk_mempool_put(struct spdk_mempool *mp, void *ele); /** * Return true if the calling process is primary process */ Loading lib/env/env.c +49 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <rte_malloc.h> #include <rte_mempool.h> #include <rte_memzone.h> #include <rte_version.h> void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) Loading Loading @@ -94,6 +95,54 @@ spdk_memzone_free(const char *name) return -1; } struct spdk_mempool * spdk_mempool_create(const char *name, size_t count, size_t ele_size, size_t cache_size) { struct rte_mempool *mp; size_t tmp; /* No more than half of all elements can be in cache */ tmp = (count / 2) / rte_lcore_count(); if (cache_size > tmp) { cache_size = tmp; } if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) { cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE; } mp = rte_mempool_create(name, count, ele_size, cache_size, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); return (struct spdk_mempool *)mp; } void spdk_mempool_free(struct spdk_mempool *mp) { #if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 1) rte_mempool_free((struct rte_mempool *)mp); #endif } void * spdk_mempool_get(struct spdk_mempool *mp) { void *ele = NULL; rte_mempool_get((struct rte_mempool *)mp, &ele); return ele; } void spdk_mempool_put(struct spdk_mempool *mp, void *ele) { rte_mempool_put((struct rte_mempool *)mp, ele); } bool spdk_process_is_primary(void) { Loading lib/nvme/nvme.c +2 −2 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, { struct nvme_request *req = NULL; nvme_mempool_get(g_spdk_nvme_driver->request_mempool, (void **)&req); req = nvme_mempool_get(g_spdk_nvme_driver->request_mempool); if (req == NULL) { return req; } Loading Loading @@ -280,7 +280,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a if (g_spdk_nvme_driver->request_mempool == NULL) { g_spdk_nvme_driver->request_mempool = nvme_mempool_create("nvme_request", 8192, sizeof(struct nvme_request), 128); sizeof(struct nvme_request), -1); if (g_spdk_nvme_driver->request_mempool == NULL) { SPDK_ERRLOG("Unable to allocate pool of requests\n"); pthread_mutex_unlock(&g_spdk_nvme_driver->lock); Loading lib/nvme/nvme_impl.h +5 −29 Original line number Diff line number Diff line Loading @@ -115,41 +115,17 @@ #define nvme_vtophys(buf) spdk_vtophys(buf) #define NVME_VTOPHYS_ERROR SPDK_VTOPHYS_ERROR typedef struct rte_mempool nvme_mempool_t; typedef struct spdk_mempool nvme_mempool_t; /** * Create a mempool with the given configuration. * Return a pointer to the allocated memory address. If the allocation * cannot be done, return NULL. */ static inline nvme_mempool_t * nvme_mempool_create(const char *name, unsigned n, unsigned elt_size, unsigned cache_size) { struct rte_mempool *mp; mp = rte_mempool_create(name, n, elt_size, cache_size, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); if (mp == NULL) { return NULL; } return (nvme_mempool_t *)mp; } static inline void nvme_mempool_get(nvme_mempool_t *mp, void **buf) { rte_mempool_get(mp, buf); } static inline void nvme_mempool_put(nvme_mempool_t *mp, void *buf) { rte_mempool_put(mp, buf); } #define nvme_mempool_create spdk_mempool_create #define nvme_mempool_free spdk_mempool_free #define nvme_mempool_get spdk_mempool_get #define nvme_mempool_put spdk_mempool_put /** * Get a monotonic timestamp counter (used for measuring timeouts during initialization). Loading test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c +1 −1 Original line number Diff line number Diff line Loading @@ -321,7 +321,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, void *cb_arg) { struct nvme_request *req = NULL; nvme_mempool_get(_g_nvme_driver.request_mempool, (void **)&req); req = nvme_mempool_get(_g_nvme_driver.request_mempool); if (req != NULL) { memset(req, 0, offsetof(struct nvme_request, children)); Loading Loading
include/spdk/env.h +30 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,36 @@ spdk_memzone_lookup(const char *name); int spdk_memzone_free(const char *name); struct spdk_mempool; /** * Create a thread-safe memory pool. Cache size is the number of * elements in a thread-local cache. Can be 0 for no caching, or -1 * for unspecified. */ struct spdk_mempool * spdk_mempool_create(const char *name, size_t count, size_t ele_size, size_t cache_size); /** * Free a memory pool. */ void spdk_mempool_free(struct spdk_mempool *mp); /** * Get an element from a memory pool. If no elements remain, return NULL. */ void * spdk_mempool_get(struct spdk_mempool *mp); /** * Put an element back into the memory pool. */ void spdk_mempool_put(struct spdk_mempool *mp, void *ele); /** * Return true if the calling process is primary process */ Loading
lib/env/env.c +49 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <rte_malloc.h> #include <rte_mempool.h> #include <rte_memzone.h> #include <rte_version.h> void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) Loading Loading @@ -94,6 +95,54 @@ spdk_memzone_free(const char *name) return -1; } struct spdk_mempool * spdk_mempool_create(const char *name, size_t count, size_t ele_size, size_t cache_size) { struct rte_mempool *mp; size_t tmp; /* No more than half of all elements can be in cache */ tmp = (count / 2) / rte_lcore_count(); if (cache_size > tmp) { cache_size = tmp; } if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) { cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE; } mp = rte_mempool_create(name, count, ele_size, cache_size, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); return (struct spdk_mempool *)mp; } void spdk_mempool_free(struct spdk_mempool *mp) { #if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 1) rte_mempool_free((struct rte_mempool *)mp); #endif } void * spdk_mempool_get(struct spdk_mempool *mp) { void *ele = NULL; rte_mempool_get((struct rte_mempool *)mp, &ele); return ele; } void spdk_mempool_put(struct spdk_mempool *mp, void *ele) { rte_mempool_put((struct rte_mempool *)mp, ele); } bool spdk_process_is_primary(void) { Loading
lib/nvme/nvme.c +2 −2 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, { struct nvme_request *req = NULL; nvme_mempool_get(g_spdk_nvme_driver->request_mempool, (void **)&req); req = nvme_mempool_get(g_spdk_nvme_driver->request_mempool); if (req == NULL) { return req; } Loading Loading @@ -280,7 +280,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a if (g_spdk_nvme_driver->request_mempool == NULL) { g_spdk_nvme_driver->request_mempool = nvme_mempool_create("nvme_request", 8192, sizeof(struct nvme_request), 128); sizeof(struct nvme_request), -1); if (g_spdk_nvme_driver->request_mempool == NULL) { SPDK_ERRLOG("Unable to allocate pool of requests\n"); pthread_mutex_unlock(&g_spdk_nvme_driver->lock); Loading
lib/nvme/nvme_impl.h +5 −29 Original line number Diff line number Diff line Loading @@ -115,41 +115,17 @@ #define nvme_vtophys(buf) spdk_vtophys(buf) #define NVME_VTOPHYS_ERROR SPDK_VTOPHYS_ERROR typedef struct rte_mempool nvme_mempool_t; typedef struct spdk_mempool nvme_mempool_t; /** * Create a mempool with the given configuration. * Return a pointer to the allocated memory address. If the allocation * cannot be done, return NULL. */ static inline nvme_mempool_t * nvme_mempool_create(const char *name, unsigned n, unsigned elt_size, unsigned cache_size) { struct rte_mempool *mp; mp = rte_mempool_create(name, n, elt_size, cache_size, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); if (mp == NULL) { return NULL; } return (nvme_mempool_t *)mp; } static inline void nvme_mempool_get(nvme_mempool_t *mp, void **buf) { rte_mempool_get(mp, buf); } static inline void nvme_mempool_put(nvme_mempool_t *mp, void *buf) { rte_mempool_put(mp, buf); } #define nvme_mempool_create spdk_mempool_create #define nvme_mempool_free spdk_mempool_free #define nvme_mempool_get spdk_mempool_get #define nvme_mempool_put spdk_mempool_put /** * Get a monotonic timestamp counter (used for measuring timeouts during initialization). Loading
test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c +1 −1 Original line number Diff line number Diff line Loading @@ -321,7 +321,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, void *cb_arg) { struct nvme_request *req = NULL; nvme_mempool_get(_g_nvme_driver.request_mempool, (void **)&req); req = nvme_mempool_get(_g_nvme_driver.request_mempool); if (req != NULL) { memset(req, 0, offsetof(struct nvme_request, children)); Loading