bdev: Use env mempool wrappers
Change-Id: I22f4f7894462c576c447346684a780bbc34f7ba3 Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
510e0861da
commit
70f8a8e2f4
@ -2,6 +2,7 @@
|
|||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation.
|
* Copyright (c) Intel Corporation.
|
||||||
|
* Copyright (c) NetApp, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -165,6 +166,11 @@ void spdk_mempool_put(struct spdk_mempool *mp, void *ele);
|
|||||||
*/
|
*/
|
||||||
void spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t count);
|
void spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of entries in the mempool.
|
||||||
|
*/
|
||||||
|
size_t spdk_mempool_count(const struct spdk_mempool *pool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return the number of dedicated CPU cores utilized by
|
* \brief Return the number of dedicated CPU cores utilized by
|
||||||
* this env abstraction
|
* this env abstraction
|
||||||
|
@ -37,9 +37,7 @@
|
|||||||
#include "spdk/bdev.h"
|
#include "spdk/bdev.h"
|
||||||
|
|
||||||
#include <rte_config.h>
|
#include <rte_config.h>
|
||||||
#include <rte_mempool.h>
|
#include <rte_lcore.h>
|
||||||
#include <rte_version.h>
|
|
||||||
|
|
||||||
#include "spdk/env.h"
|
#include "spdk/env.h"
|
||||||
#include "spdk/io_channel.h"
|
#include "spdk/io_channel.h"
|
||||||
#include "spdk/queue.h"
|
#include "spdk/queue.h"
|
||||||
@ -54,9 +52,9 @@
|
|||||||
#define BUF_SMALL_POOL_SIZE 8192
|
#define BUF_SMALL_POOL_SIZE 8192
|
||||||
#define BUF_LARGE_POOL_SIZE 1024
|
#define BUF_LARGE_POOL_SIZE 1024
|
||||||
|
|
||||||
static struct rte_mempool *spdk_bdev_g_io_pool = NULL;
|
static struct spdk_mempool *spdk_bdev_g_io_pool = NULL;
|
||||||
static struct rte_mempool *g_buf_small_pool = NULL;
|
static struct spdk_mempool *g_buf_small_pool = NULL;
|
||||||
static struct rte_mempool *g_buf_large_pool = NULL;
|
static struct spdk_mempool *g_buf_large_pool = NULL;
|
||||||
|
|
||||||
typedef TAILQ_HEAD(, spdk_bdev_io) need_buf_tailq_t;
|
typedef TAILQ_HEAD(, spdk_bdev_io) need_buf_tailq_t;
|
||||||
static need_buf_tailq_t g_need_buf_small[RTE_MAX_LCORE];
|
static need_buf_tailq_t g_need_buf_small[RTE_MAX_LCORE];
|
||||||
@ -132,7 +130,7 @@ spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf)
|
|||||||
static void
|
static void
|
||||||
spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
||||||
{
|
{
|
||||||
struct rte_mempool *pool;
|
struct spdk_mempool *pool;
|
||||||
struct spdk_bdev_io *tmp;
|
struct spdk_bdev_io *tmp;
|
||||||
void *buf;
|
void *buf;
|
||||||
need_buf_tailq_t *tailq;
|
need_buf_tailq_t *tailq;
|
||||||
@ -152,7 +150,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TAILQ_EMPTY(tailq)) {
|
if (TAILQ_EMPTY(tailq)) {
|
||||||
rte_mempool_put(pool, buf);
|
spdk_mempool_put(pool, buf);
|
||||||
} else {
|
} else {
|
||||||
tmp = TAILQ_FIRST(tailq);
|
tmp = TAILQ_FIRST(tailq);
|
||||||
TAILQ_REMOVE(tailq, tmp, buf_link);
|
TAILQ_REMOVE(tailq, tmp, buf_link);
|
||||||
@ -170,28 +168,24 @@ static int spdk_initialize_buf_pool(void)
|
|||||||
* to account for.
|
* to account for.
|
||||||
*/
|
*/
|
||||||
cache_size = BUF_SMALL_POOL_SIZE / (2 * spdk_env_get_core_count());
|
cache_size = BUF_SMALL_POOL_SIZE / (2 * spdk_env_get_core_count());
|
||||||
if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE)
|
g_buf_small_pool = spdk_mempool_create("buf_small_pool",
|
||||||
cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE;
|
BUF_SMALL_POOL_SIZE,
|
||||||
g_buf_small_pool = rte_mempool_create("buf_small_pool",
|
SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512,
|
||||||
BUF_SMALL_POOL_SIZE,
|
cache_size,
|
||||||
SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512,
|
SPDK_ENV_SOCKET_ID_ANY);
|
||||||
cache_size, 0, NULL, NULL, NULL, NULL,
|
|
||||||
SOCKET_ID_ANY, 0);
|
|
||||||
if (!g_buf_small_pool) {
|
if (!g_buf_small_pool) {
|
||||||
SPDK_ERRLOG("create buf small pool failed\n");
|
SPDK_ERRLOG("create rbuf small pool failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_size = BUF_LARGE_POOL_SIZE / (2 * spdk_env_get_core_count());
|
cache_size = BUF_LARGE_POOL_SIZE / (2 * spdk_env_get_core_count());
|
||||||
if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE)
|
g_buf_large_pool = spdk_mempool_create("buf_large_pool",
|
||||||
cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE;
|
BUF_LARGE_POOL_SIZE,
|
||||||
g_buf_large_pool = rte_mempool_create("buf_large_pool",
|
SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512,
|
||||||
BUF_LARGE_POOL_SIZE,
|
cache_size,
|
||||||
SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512,
|
SPDK_ENV_SOCKET_ID_ANY);
|
||||||
cache_size, 0, NULL, NULL, NULL, NULL,
|
|
||||||
SOCKET_ID_ANY, 0);
|
|
||||||
if (!g_buf_large_pool) {
|
if (!g_buf_large_pool) {
|
||||||
SPDK_ERRLOG("create buf large pool failed\n");
|
SPDK_ERRLOG("create rbuf large pool failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,13 +277,12 @@ spdk_bdev_initialize(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_bdev_g_io_pool = rte_mempool_create("blockdev_io",
|
spdk_bdev_g_io_pool = spdk_mempool_create("blockdev_io",
|
||||||
SPDK_BDEV_IO_POOL_SIZE,
|
SPDK_BDEV_IO_POOL_SIZE,
|
||||||
sizeof(struct spdk_bdev_io) +
|
sizeof(struct spdk_bdev_io) +
|
||||||
spdk_bdev_module_get_max_ctx_size(),
|
spdk_bdev_module_get_max_ctx_size(),
|
||||||
64, 0,
|
64,
|
||||||
NULL, NULL, NULL, NULL,
|
SPDK_ENV_SOCKET_ID_ANY);
|
||||||
SOCKET_ID_ANY, 0);
|
|
||||||
|
|
||||||
if (spdk_bdev_g_io_pool == NULL) {
|
if (spdk_bdev_g_io_pool == NULL) {
|
||||||
SPDK_ERRLOG("could not allocate spdk_bdev_io pool");
|
SPDK_ERRLOG("could not allocate spdk_bdev_io pool");
|
||||||
@ -304,23 +297,12 @@ spdk_bdev_initialize(void)
|
|||||||
return spdk_initialize_buf_pool();
|
return spdk_initialize_buf_pool();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Wrapper to provide rte_mempool_avail_count() on older DPDK versions.
|
|
||||||
* Drop this if the minimum DPDK version is raised to at least 16.07.
|
|
||||||
*/
|
|
||||||
#if RTE_VERSION < RTE_VERSION_NUM(16, 7, 0, 1)
|
|
||||||
static unsigned rte_mempool_avail_count(const struct rte_mempool *pool)
|
|
||||||
{
|
|
||||||
return rte_mempool_count(pool);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
spdk_bdev_check_pool(struct rte_mempool *pool, uint32_t count)
|
spdk_bdev_check_pool(struct spdk_mempool *pool, uint32_t count)
|
||||||
{
|
{
|
||||||
if (rte_mempool_avail_count(pool) != count) {
|
if (spdk_mempool_count(pool) != count) {
|
||||||
SPDK_ERRLOG("rte_mempool_avail_count(%s) == %d, should be %d\n",
|
SPDK_ERRLOG("spdk_mempool_count(%p) == %zu, should be %u\n",
|
||||||
pool->name, rte_mempool_avail_count(pool), count);
|
pool, spdk_mempool_count(pool), count);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -343,10 +325,9 @@ spdk_bdev_finish(void)
|
|||||||
struct spdk_bdev_io *spdk_bdev_get_io(void)
|
struct spdk_bdev_io *spdk_bdev_get_io(void)
|
||||||
{
|
{
|
||||||
struct spdk_bdev_io *bdev_io;
|
struct spdk_bdev_io *bdev_io;
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = rte_mempool_get(spdk_bdev_g_io_pool, (void **)&bdev_io);
|
bdev_io = spdk_mempool_get(spdk_bdev_g_io_pool);
|
||||||
if (rc < 0 || !bdev_io) {
|
if (!bdev_io) {
|
||||||
SPDK_ERRLOG("Unable to get spdk_bdev_io\n");
|
SPDK_ERRLOG("Unable to get spdk_bdev_io\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -367,16 +348,15 @@ spdk_bdev_put_io(struct spdk_bdev_io *bdev_io)
|
|||||||
spdk_bdev_io_put_buf(bdev_io);
|
spdk_bdev_io_put_buf(bdev_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
rte_mempool_put(spdk_bdev_g_io_pool, bdev_io);
|
spdk_mempool_put(spdk_bdev_g_io_pool, (void *)bdev_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io)
|
_spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io)
|
||||||
{
|
{
|
||||||
uint64_t len = bdev_io->u.read.len;
|
uint64_t len = bdev_io->u.read.len;
|
||||||
struct rte_mempool *pool;
|
struct spdk_mempool *pool;
|
||||||
need_buf_tailq_t *tailq;
|
need_buf_tailq_t *tailq;
|
||||||
int rc;
|
|
||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
|
|
||||||
if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) {
|
if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) {
|
||||||
@ -387,8 +367,9 @@ _spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io)
|
|||||||
tailq = &g_need_buf_large[rte_lcore_id()];
|
tailq = &g_need_buf_large[rte_lcore_id()];
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = rte_mempool_get(pool, (void **)&buf);
|
buf = spdk_mempool_get(pool);
|
||||||
if (rc < 0 || !buf) {
|
|
||||||
|
if (!buf) {
|
||||||
TAILQ_INSERT_TAIL(tailq, bdev_io, buf_link);
|
TAILQ_INSERT_TAIL(tailq, bdev_io, buf_link);
|
||||||
} else {
|
} else {
|
||||||
spdk_bdev_io_set_buf(bdev_io, buf);
|
spdk_bdev_io_set_buf(bdev_io, buf);
|
||||||
|
@ -197,6 +197,16 @@ spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t coun
|
|||||||
rte_mempool_put_bulk((struct rte_mempool *)mp, ele_arr, count);
|
rte_mempool_put_bulk((struct rte_mempool *)mp, ele_arr, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
spdk_mempool_count(const struct spdk_mempool *pool)
|
||||||
|
{
|
||||||
|
#if RTE_VERSION < RTE_VERSION_NUM(16, 7, 0, 1)
|
||||||
|
return rte_mempool_count((struct rte_mempool *)pool);
|
||||||
|
#else
|
||||||
|
return rte_mempool_avail_count((struct rte_mempool *)pool);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
spdk_process_is_primary(void)
|
spdk_process_is_primary(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user