From 20953e1ccd1d50b1a7e8a0bd9d71f95c9613ef1c Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 4 Aug 2016 22:59:38 -0400 Subject: [PATCH] nvme: add the APIs to use the shared memory zone Change-Id: I7faca95a15d320f3e2940c112b91d05a69797c90 Signed-off-by: GangCao --- lib/nvme/nvme_impl.h | 62 ++++++++++++++++++++++++++++++++++ test/lib/nvme/unit/nvme_impl.h | 27 +++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/lib/nvme/nvme_impl.h b/lib/nvme/nvme_impl.h index f35ae68f0f..8c96d289ac 100644 --- a/lib/nvme/nvme_impl.h +++ b/lib/nvme/nvme_impl.h @@ -51,11 +51,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #ifdef SPDK_CONFIG_PCIACCESS #include @@ -100,6 +103,65 @@ nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr) */ #define nvme_free(buf) rte_free(buf) +/** + * Reserve a named, process shared memory zone with the given size, + * socket_id and flags. + * Return a pointer to the allocated memory address. If the allocation + * cannot be done, return NULL. + */ +static inline void * +nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) +{ + const struct rte_memzone *mz = rte_memzone_reserve(name, len, socket_id, flags); + + if (mz != NULL) { + return mz->addr; + } else { + return NULL; + } +} + +/** + * Lookup the memory zone identified by the given name. + * Return a pointer to the reserved memory address. If the reservation + * cannot be found, return NULL. + */ +static inline void * +nvme_memzone_lookup(const char *name) +{ + const struct rte_memzone *mz = rte_memzone_lookup(name); + + if (mz != NULL) { + return mz->addr; + } else { + return NULL; + } +} + +/** + * Free the memory zone identified by the given name. + */ +static inline int +nvme_memzone_free(const char *name) +{ + const struct rte_memzone *mz = rte_memzone_lookup(name); + + if (mz != NULL) { + return rte_memzone_free(mz); + } + + return -1; +} + +/** + * Return true if the calling process is primary process + */ +static inline bool +nvme_process_is_primary(void) +{ + return (rte_eal_process_type() == RTE_PROC_PRIMARY); +} + /** * Log or print a message from the NVMe driver. */ diff --git a/test/lib/nvme/unit/nvme_impl.h b/test/lib/nvme/unit/nvme_impl.h index dce65d024f..83dafa47f3 100644 --- a/test/lib/nvme/unit/nvme_impl.h +++ b/test/lib/nvme/unit/nvme_impl.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "spdk/nvme_spec.h" @@ -119,4 +120,30 @@ nvme_pcicfg_get_bar_addr_len(void *devhandle, uint32_t bar, uint64_t *addr, uint *size = 0; } +static inline void * +nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) +{ + return malloc(len); +} + +static inline void * +nvme_memzone_lookup(const char *name) +{ + assert(0); + return NULL; +} + +static inline int +nvme_memzone_free(const char *name) +{ + assert(0); + return 0; +} + +static inline bool +nvme_process_is_primary(void) +{ + return true; +} + #endif /* __NVME_IMPL_H__ */