env: Move memzone wrappers to env

Change-Id: Iaa4f4a1a1eefb8bed262e1167f13cb7eacd5edaf
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-09-08 14:30:58 -07:00
parent 7c3a6d8c43
commit 898c10147c
3 changed files with 78 additions and 39 deletions

View File

@ -42,6 +42,7 @@
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -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.
*/

44
lib/env/env.c vendored
View File

@ -38,6 +38,8 @@
#include <rte_config.h>
#include <rte_cycles.h>
#include <rte_malloc.h>
#include <rte_mempool.h>
#include <rte_memzone.h>
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();

View File

@ -56,7 +56,6 @@
#include <rte_config.h>
#include <rte_mempool.h>
#include <rte_version.h>
#include <rte_memzone.h>
#include <rte_eal.h>
#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.