Skip to content

Commit

Permalink
env: Move memzone wrappers to env
Browse files Browse the repository at this point in the history
Change-Id: Iaa4f4a1a1eefb8bed262e1167f13cb7eacd5edaf
Signed-off-by: Ben Walker <[email protected]>
  • Loading branch information
Ben Walker committed Oct 6, 2016
1 parent 7c3a6d8 commit 898c101
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 39 deletions.
30 changes: 30 additions & 0 deletions include/spdk/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
extern "C" {
#endif

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Expand All @@ -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.
*/
Expand Down
44 changes: 44 additions & 0 deletions lib/env/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
43 changes: 4 additions & 39 deletions lib/nvme/nvme_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 898c101

Please sign in to comment.