From 898c10147ca5e71a4cdfc3a2d8ce86108f0359fb Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 8 Sep 2016 14:30:58 -0700 Subject: [PATCH] env: Move memzone wrappers to env Change-Id: Iaa4f4a1a1eefb8bed262e1167f13cb7eacd5edaf Signed-off-by: Ben Walker --- include/spdk/env.h | 30 ++++++++++++++++++++++++++++++ lib/env/env.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/nvme/nvme_impl.h | 43 ++++--------------------------------------- 3 files changed, 78 insertions(+), 39 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index 729dbed77a..4ce5dc1382 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -42,6 +42,7 @@ extern "C" { #endif +#include #include #include @@ -61,6 +62,35 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr); void spdk_free(void *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. + */ +void * +spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags); + +/** + * 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. + */ +void * +spdk_memzone_lookup(const char *name); + +/** + * Free the memory zone identified by the given name. + */ +int +spdk_memzone_free(const char *name); + +/** + * Return true if the calling process is primary process + */ +bool +spdk_process_is_primary(void); + /** * Get a monotonic timestamp counter. */ diff --git a/lib/env/env.c b/lib/env/env.c index aaef1ca754..21bfd7f8dc 100644 --- a/lib/env/env.c +++ b/lib/env/env.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) @@ -56,6 +58,48 @@ spdk_free(void *buf) return rte_free(buf); } +void * +spdk_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; + } +} + +void * +spdk_memzone_lookup(const char *name) +{ + const struct rte_memzone *mz = rte_memzone_lookup(name); + + if (mz != NULL) { + return mz->addr; + } else { + return NULL; + } +} + +int +spdk_memzone_free(const char *name) +{ + const struct rte_memzone *mz = rte_memzone_lookup(name); + + if (mz != NULL) { + return rte_memzone_free(mz); + } + + return -1; +} + +bool +spdk_process_is_primary(void) +{ + return (rte_eal_process_type() == RTE_PROC_PRIMARY); +} + uint64_t spdk_get_ticks(void) { return rte_get_timer_cycles(); diff --git a/lib/nvme/nvme_impl.h b/lib/nvme/nvme_impl.h index cba62c6e29..2135bd7e02 100644 --- a/lib/nvme/nvme_impl.h +++ b/lib/nvme/nvme_impl.h @@ -56,7 +56,6 @@ #include #include #include -#include #include #include "spdk/pci_ids.h" @@ -91,58 +90,24 @@ * 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; - } -} +#define nvme_memzone_reserve spdk_memzone_reserve /** * 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; - } -} +#define nvme_memzone_lookup spdk_memzone_lookup /** * 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; -} +#define nvme_memzone_free spdk_memzone_free /** * 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); -} +#define nvme_process_is_primary spdk_process_is_primary /** * Return the physical address for the specified virtual address.