nvme: add the APIs to use the shared memory zone

Change-Id: I7faca95a15d320f3e2940c112b91d05a69797c90
Signed-off-by: GangCao <gang.cao@intel.com>
This commit is contained in:
GangCao 2016-08-04 22:59:38 -04:00 committed by Ben Walker
parent 7bdba4437d
commit 20953e1ccd
2 changed files with 89 additions and 0 deletions

View File

@ -51,11 +51,14 @@
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <rte_config.h>
#include <rte_cycles.h>
#include <rte_malloc.h>
#include <rte_mempool.h>
#include <rte_version.h>
#include <rte_memzone.h>
#include <rte_eal.h>
#ifdef SPDK_CONFIG_PCIACCESS
#include <pciaccess.h>
@ -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.
*/

View File

@ -38,6 +38,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#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__ */