2015-12-03 21:30:38 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
2015-12-03 21:30:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-10-03 21:40:06 +00:00
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
#include "spdk/ioat.h"
|
2016-08-10 17:41:12 +00:00
|
|
|
#include "spdk/env.h"
|
2016-09-30 21:14:18 +00:00
|
|
|
#include "spdk/queue.h"
|
2015-12-03 21:30:38 +00:00
|
|
|
#include "spdk/string.h"
|
2018-06-24 20:10:51 +00:00
|
|
|
#include "spdk/util.h"
|
2015-12-03 21:30:38 +00:00
|
|
|
|
|
|
|
#define SRC_BUFFER_SIZE (512*1024)
|
|
|
|
|
2016-01-29 08:01:43 +00:00
|
|
|
enum ioat_task_type {
|
|
|
|
IOAT_COPY_TYPE,
|
|
|
|
IOAT_FILL_TYPE,
|
|
|
|
};
|
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
struct user_config {
|
|
|
|
int queue_depth;
|
|
|
|
int time_in_sec;
|
|
|
|
char *core_mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ioat_device {
|
2016-02-11 19:31:35 +00:00
|
|
|
struct spdk_ioat_chan *ioat;
|
2015-12-03 21:30:38 +00:00
|
|
|
TAILQ_ENTRY(ioat_device) tailq;
|
|
|
|
};
|
|
|
|
|
2020-10-12 15:21:48 +00:00
|
|
|
static TAILQ_HEAD(, ioat_device) g_devices = TAILQ_HEAD_INITIALIZER(g_devices);
|
2016-03-10 18:07:32 +00:00
|
|
|
static struct ioat_device *g_next_device;
|
2015-12-03 21:30:38 +00:00
|
|
|
|
|
|
|
static struct user_config g_user_config;
|
|
|
|
|
|
|
|
struct thread_entry {
|
2016-03-10 18:07:32 +00:00
|
|
|
struct spdk_ioat_chan *chan;
|
2015-12-03 21:30:38 +00:00
|
|
|
uint64_t xfer_completed;
|
|
|
|
uint64_t xfer_failed;
|
2016-01-29 08:01:43 +00:00
|
|
|
uint64_t fill_completed;
|
|
|
|
uint64_t fill_failed;
|
2015-12-03 21:30:38 +00:00
|
|
|
uint64_t current_queue_depth;
|
|
|
|
unsigned lcore_id;
|
|
|
|
bool is_draining;
|
2017-11-28 20:17:14 +00:00
|
|
|
bool init_failed;
|
2016-09-30 21:14:18 +00:00
|
|
|
struct spdk_mempool *data_pool;
|
|
|
|
struct spdk_mempool *task_pool;
|
2015-12-03 21:30:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ioat_task {
|
2016-01-29 08:01:43 +00:00
|
|
|
enum ioat_task_type type;
|
2015-12-03 21:30:38 +00:00
|
|
|
struct thread_entry *thread_entry;
|
|
|
|
void *buffer;
|
|
|
|
int len;
|
2016-01-29 08:01:43 +00:00
|
|
|
uint64_t fill_pattern;
|
2015-12-03 21:30:38 +00:00
|
|
|
void *src;
|
|
|
|
void *dst;
|
|
|
|
};
|
|
|
|
|
|
|
|
static __thread unsigned int seed = 0;
|
|
|
|
|
|
|
|
static unsigned char *g_src;
|
|
|
|
|
|
|
|
static void submit_single_xfer(struct ioat_task *ioat_task);
|
|
|
|
|
|
|
|
static void
|
|
|
|
construct_user_config(struct user_config *self)
|
|
|
|
{
|
|
|
|
self->queue_depth = 32;
|
|
|
|
self->time_in_sec = 10;
|
|
|
|
self->core_mask = "0x1";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_user_config(struct user_config *self)
|
|
|
|
{
|
|
|
|
printf("User configuration:\n");
|
|
|
|
printf("Run time: %u seconds\n", self->time_in_sec);
|
|
|
|
printf("Core mask: %s\n", self->core_mask);
|
|
|
|
printf("Queue depth: %u\n", self->queue_depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ioat_exit(void)
|
|
|
|
{
|
|
|
|
struct ioat_device *dev;
|
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(&g_devices)) {
|
|
|
|
dev = TAILQ_FIRST(&g_devices);
|
|
|
|
TAILQ_REMOVE(&g_devices, dev, tailq);
|
2015-12-07 23:48:25 +00:00
|
|
|
if (dev->ioat) {
|
2016-02-11 19:31:35 +00:00
|
|
|
spdk_ioat_detach(dev->ioat);
|
2015-12-07 23:48:25 +00:00
|
|
|
}
|
|
|
|
free(dev);
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void prepare_ioat_task(struct thread_entry *thread_entry, struct ioat_task *ioat_task)
|
|
|
|
{
|
|
|
|
int len;
|
2018-06-24 20:04:03 +00:00
|
|
|
uintptr_t src_offset;
|
|
|
|
uintptr_t dst_offset;
|
2016-01-29 08:01:43 +00:00
|
|
|
uint64_t fill_pattern;
|
|
|
|
|
|
|
|
if (ioat_task->type == IOAT_FILL_TYPE) {
|
|
|
|
fill_pattern = rand_r(&seed);
|
|
|
|
fill_pattern = fill_pattern << 32 | rand_r(&seed);
|
|
|
|
|
2018-06-24 19:50:10 +00:00
|
|
|
/* Ensure that the length of memset block is 8 Bytes aligned.
|
|
|
|
* In case the buffer crosses hugepage boundary and must be split,
|
|
|
|
* we also need to ensure 8 byte address alignment. We do it
|
|
|
|
* unconditionally to keep things simple.
|
|
|
|
*/
|
|
|
|
len = 8 + ((rand_r(&seed) % (SRC_BUFFER_SIZE - 16)) & ~0x7);
|
|
|
|
dst_offset = 8 + rand_r(&seed) % (SRC_BUFFER_SIZE - 8 - len);
|
2016-01-29 08:01:43 +00:00
|
|
|
ioat_task->fill_pattern = fill_pattern;
|
2018-06-24 19:50:10 +00:00
|
|
|
ioat_task->dst = (void *)(((uintptr_t)ioat_task->buffer + dst_offset) & ~0x7);
|
2016-01-29 08:01:43 +00:00
|
|
|
} else {
|
|
|
|
src_offset = rand_r(&seed) % SRC_BUFFER_SIZE;
|
|
|
|
len = rand_r(&seed) % (SRC_BUFFER_SIZE - src_offset);
|
|
|
|
dst_offset = rand_r(&seed) % (SRC_BUFFER_SIZE - len);
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-01-29 08:01:43 +00:00
|
|
|
memset(ioat_task->buffer, 0, SRC_BUFFER_SIZE);
|
2018-06-24 20:04:03 +00:00
|
|
|
ioat_task->src = (void *)((uintptr_t)g_src + src_offset);
|
2018-06-24 19:50:10 +00:00
|
|
|
ioat_task->dst = (void *)((uintptr_t)ioat_task->buffer + dst_offset);
|
2016-01-29 08:01:43 +00:00
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
ioat_task->len = len;
|
|
|
|
ioat_task->thread_entry = thread_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ioat_done(void *cb_arg)
|
|
|
|
{
|
2016-12-06 20:33:35 +00:00
|
|
|
char *value;
|
2016-01-29 08:01:43 +00:00
|
|
|
int i, failed = 0;
|
2015-12-03 21:30:38 +00:00
|
|
|
struct ioat_task *ioat_task = (struct ioat_task *)cb_arg;
|
|
|
|
struct thread_entry *thread_entry = ioat_task->thread_entry;
|
|
|
|
|
2016-01-29 08:01:43 +00:00
|
|
|
if (ioat_task->type == IOAT_FILL_TYPE) {
|
2016-12-06 20:33:35 +00:00
|
|
|
value = ioat_task->dst;
|
2016-01-29 08:01:43 +00:00
|
|
|
for (i = 0; i < ioat_task->len / 8; i++) {
|
2016-12-06 20:33:35 +00:00
|
|
|
if (memcmp(value, &ioat_task->fill_pattern, 8) != 0) {
|
2016-01-29 08:01:43 +00:00
|
|
|
thread_entry->fill_failed++;
|
|
|
|
failed = 1;
|
|
|
|
break;
|
|
|
|
}
|
2016-12-06 20:33:35 +00:00
|
|
|
value += 8;
|
2016-01-29 08:01:43 +00:00
|
|
|
}
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!failed) {
|
2016-01-29 08:01:43 +00:00
|
|
|
thread_entry->fill_completed++;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
} else {
|
2016-01-29 08:01:43 +00:00
|
|
|
if (memcmp(ioat_task->src, ioat_task->dst, ioat_task->len)) {
|
|
|
|
thread_entry->xfer_failed++;
|
|
|
|
} else {
|
|
|
|
thread_entry->xfer_completed++;
|
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
2016-01-29 08:01:43 +00:00
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
thread_entry->current_queue_depth--;
|
|
|
|
if (thread_entry->is_draining) {
|
2016-09-30 21:14:18 +00:00
|
|
|
spdk_mempool_put(thread_entry->data_pool, ioat_task->buffer);
|
|
|
|
spdk_mempool_put(thread_entry->task_pool, ioat_task);
|
2015-12-03 21:30:38 +00:00
|
|
|
} else {
|
|
|
|
prepare_ioat_task(thread_entry, ioat_task);
|
|
|
|
submit_single_xfer(ioat_task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
static bool
|
2016-02-03 21:36:26 +00:00
|
|
|
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev)
|
2015-12-03 21:30:38 +00:00
|
|
|
{
|
2017-02-10 23:55:14 +00:00
|
|
|
printf(" Found matching device at %04x:%02x:%02x.%x "
|
2016-11-02 17:50:28 +00:00
|
|
|
"vendor:0x%04x device:0x%04x\n",
|
2017-02-10 23:55:14 +00:00
|
|
|
spdk_pci_device_get_domain(pci_dev),
|
2016-02-03 21:36:26 +00:00
|
|
|
spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
|
|
|
|
spdk_pci_device_get_func(pci_dev),
|
2016-11-02 17:50:28 +00:00
|
|
|
spdk_pci_device_get_vendor_id(pci_dev), spdk_pci_device_get_device_id(pci_dev));
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
static void
|
2016-02-11 19:31:35 +00:00
|
|
|
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_ioat_chan *ioat)
|
2016-02-03 19:57:51 +00:00
|
|
|
{
|
|
|
|
struct ioat_device *dev;
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
dev = malloc(sizeof(*dev));
|
|
|
|
if (dev == NULL) {
|
|
|
|
printf("Failed to allocate device struct\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
dev->ioat = ioat;
|
|
|
|
TAILQ_INSERT_TAIL(&g_devices, dev, tailq);
|
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
static int
|
|
|
|
ioat_init(void)
|
|
|
|
{
|
2016-02-11 19:31:35 +00:00
|
|
|
if (spdk_ioat_probe(NULL, probe_cb, attach_cb) != 0) {
|
2016-02-03 19:57:51 +00:00
|
|
|
fprintf(stderr, "ioat_probe() failed\n");
|
|
|
|
return 1;
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 19:57:51 +00:00
|
|
|
return 0;
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(char *program_name)
|
|
|
|
{
|
|
|
|
printf("%s options\n", program_name);
|
|
|
|
printf("\t[-h help message]\n");
|
|
|
|
printf("\t[-c core mask for distributing I/O submission/completion work]\n");
|
|
|
|
printf("\t[-t time in seconds]\n");
|
|
|
|
printf("\t[-q queue depth]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_args(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int op;
|
|
|
|
|
|
|
|
construct_user_config(&g_user_config);
|
|
|
|
while ((op = getopt(argc, argv, "c:ht:q:")) != -1) {
|
|
|
|
switch (op) {
|
|
|
|
case 't':
|
2019-01-23 00:02:56 +00:00
|
|
|
g_user_config.time_in_sec = spdk_strtol(optarg, 10);
|
2015-12-03 21:30:38 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
g_user_config.core_mask = optarg;
|
|
|
|
break;
|
|
|
|
case 'q':
|
2019-01-23 00:02:56 +00:00
|
|
|
g_user_config.queue_depth = spdk_strtol(optarg, 10);
|
2015-12-03 21:30:38 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 00:02:56 +00:00
|
|
|
if (g_user_config.time_in_sec <= 0 || !g_user_config.core_mask ||
|
|
|
|
g_user_config.queue_depth <= 0) {
|
2015-12-03 21:30:38 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-06-12 19:55:37 +00:00
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drain_xfers(struct thread_entry *thread_entry)
|
|
|
|
{
|
|
|
|
while (thread_entry->current_queue_depth > 0) {
|
2016-03-10 18:07:32 +00:00
|
|
|
spdk_ioat_process_events(thread_entry->chan);
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_single_xfer(struct ioat_task *ioat_task)
|
|
|
|
{
|
2016-01-29 08:01:43 +00:00
|
|
|
if (ioat_task->type == IOAT_FILL_TYPE)
|
2016-03-10 18:07:32 +00:00
|
|
|
spdk_ioat_submit_fill(ioat_task->thread_entry->chan, ioat_task, ioat_done,
|
|
|
|
ioat_task->dst, ioat_task->fill_pattern, ioat_task->len);
|
2016-01-29 08:01:43 +00:00
|
|
|
else
|
2016-03-10 18:07:32 +00:00
|
|
|
spdk_ioat_submit_copy(ioat_task->thread_entry->chan, ioat_task, ioat_done,
|
|
|
|
ioat_task->dst, ioat_task->src, ioat_task->len);
|
2015-12-03 21:30:38 +00:00
|
|
|
ioat_task->thread_entry->current_queue_depth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_xfers(struct thread_entry *thread_entry, uint64_t queue_depth)
|
|
|
|
{
|
|
|
|
while (queue_depth-- > 0) {
|
|
|
|
struct ioat_task *ioat_task = NULL;
|
2016-09-30 21:14:18 +00:00
|
|
|
ioat_task = spdk_mempool_get(thread_entry->task_pool);
|
2020-09-09 21:06:20 +00:00
|
|
|
assert(ioat_task != NULL);
|
2016-09-30 21:14:18 +00:00
|
|
|
ioat_task->buffer = spdk_mempool_get(thread_entry->data_pool);
|
2020-09-09 21:06:20 +00:00
|
|
|
assert(ioat_task->buffer != NULL);
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2016-01-29 08:01:43 +00:00
|
|
|
ioat_task->type = IOAT_COPY_TYPE;
|
2016-03-10 18:07:32 +00:00
|
|
|
if (spdk_ioat_get_dma_capabilities(thread_entry->chan) & SPDK_IOAT_ENGINE_FILL_SUPPORTED) {
|
2017-12-07 23:23:48 +00:00
|
|
|
if (queue_depth % 2) {
|
2016-01-29 08:01:43 +00:00
|
|
|
ioat_task->type = IOAT_FILL_TYPE;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-01-29 08:01:43 +00:00
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
prepare_ioat_task(thread_entry, ioat_task);
|
|
|
|
submit_single_xfer(ioat_task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
work_fn(void *arg)
|
|
|
|
{
|
|
|
|
uint64_t tsc_end;
|
|
|
|
char buf_pool_name[20], task_pool_name[20];
|
|
|
|
struct thread_entry *t = (struct thread_entry *)arg;
|
|
|
|
|
2016-03-10 18:07:32 +00:00
|
|
|
if (!t->chan) {
|
2020-04-03 08:10:26 +00:00
|
|
|
return 1;
|
2016-03-10 18:07:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
t->lcore_id = spdk_env_get_current_core();
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
snprintf(buf_pool_name, sizeof(buf_pool_name), "buf_pool_%u", t->lcore_id);
|
|
|
|
snprintf(task_pool_name, sizeof(task_pool_name), "task_pool_%u", t->lcore_id);
|
2017-08-16 17:05:24 +00:00
|
|
|
t->data_pool = spdk_mempool_create(buf_pool_name, g_user_config.queue_depth, SRC_BUFFER_SIZE,
|
|
|
|
SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
|
2017-01-25 20:35:40 +00:00
|
|
|
SPDK_ENV_SOCKET_ID_ANY);
|
2016-09-30 21:14:18 +00:00
|
|
|
t->task_pool = spdk_mempool_create(task_pool_name, g_user_config.queue_depth,
|
2017-08-16 17:05:24 +00:00
|
|
|
sizeof(struct ioat_task),
|
|
|
|
SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
|
|
|
|
SPDK_ENV_SOCKET_ID_ANY);
|
2015-12-03 21:30:38 +00:00
|
|
|
if (!t->data_pool || !t->task_pool) {
|
|
|
|
fprintf(stderr, "Could not allocate buffer pool.\n");
|
2017-11-28 20:17:14 +00:00
|
|
|
t->init_failed = true;
|
2015-12-03 21:30:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-18 19:52:48 +00:00
|
|
|
tsc_end = spdk_get_ticks() + g_user_config.time_in_sec * spdk_get_ticks_hz();
|
2015-12-03 21:30:38 +00:00
|
|
|
|
|
|
|
submit_xfers(t, g_user_config.queue_depth);
|
2016-08-18 19:52:48 +00:00
|
|
|
while (spdk_get_ticks() < tsc_end) {
|
2016-03-10 18:07:32 +00:00
|
|
|
spdk_ioat_process_events(t->chan);
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t->is_draining = true;
|
|
|
|
drain_xfers(t);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
init_src_buffer(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-05-25 18:21:30 +00:00
|
|
|
g_src = spdk_dma_zmalloc(SRC_BUFFER_SIZE, 512, NULL);
|
2015-12-03 21:30:38 +00:00
|
|
|
if (g_src == NULL) {
|
|
|
|
fprintf(stderr, "Allocate src buffer failed\n");
|
2020-04-03 08:10:26 +00:00
|
|
|
return 1;
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < SRC_BUFFER_SIZE / 4; i++) {
|
|
|
|
memset((g_src + (4 * i)), i, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
init(void)
|
|
|
|
{
|
2017-01-12 18:25:17 +00:00
|
|
|
struct spdk_env_opts opts;
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
spdk_env_opts_init(&opts);
|
|
|
|
opts.name = "verify";
|
|
|
|
opts.core_mask = g_user_config.core_mask;
|
2017-12-18 19:57:01 +00:00
|
|
|
if (spdk_env_init(&opts) < 0) {
|
|
|
|
fprintf(stderr, "Unable to initialize SPDK env\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2015-12-03 21:30:38 +00:00
|
|
|
|
|
|
|
if (init_src_buffer() != 0) {
|
|
|
|
fprintf(stderr, "Could not init src buffer\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ioat_init() != 0) {
|
|
|
|
fprintf(stderr, "Could not init ioat\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-11-28 20:17:14 +00:00
|
|
|
dump_result(struct thread_entry *threads, uint32_t num_threads)
|
2015-12-03 21:30:38 +00:00
|
|
|
{
|
2017-11-28 20:17:14 +00:00
|
|
|
uint32_t i;
|
2015-12-03 21:30:38 +00:00
|
|
|
uint64_t total_completed = 0;
|
|
|
|
uint64_t total_failed = 0;
|
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
for (i = 0; i < num_threads; i++) {
|
2015-12-03 21:30:38 +00:00
|
|
|
struct thread_entry *t = &threads[i];
|
2017-11-28 20:17:14 +00:00
|
|
|
|
|
|
|
if (!t->chan) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t->init_failed) {
|
|
|
|
total_failed++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
total_completed += t->xfer_completed;
|
2016-01-29 08:01:43 +00:00
|
|
|
total_completed += t->fill_completed;
|
2015-12-03 21:30:38 +00:00
|
|
|
total_failed += t->xfer_failed;
|
2016-01-29 08:01:43 +00:00
|
|
|
total_failed += t->fill_failed;
|
2018-06-24 20:56:19 +00:00
|
|
|
if (total_completed || total_failed)
|
2020-11-17 14:40:28 +00:00
|
|
|
printf("lcore = %d, copy success = %" PRIu64 ", copy failed = %" PRIu64 ", fill success = %" PRIu64
|
|
|
|
", fill failed = %" PRIu64 "\n",
|
2016-01-29 08:01:43 +00:00
|
|
|
t->lcore_id, t->xfer_completed, t->xfer_failed, t->fill_completed, t->fill_failed);
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
return total_failed ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:07:32 +00:00
|
|
|
static struct spdk_ioat_chan *
|
|
|
|
get_next_chan(void)
|
|
|
|
{
|
|
|
|
struct spdk_ioat_chan *chan;
|
|
|
|
|
|
|
|
if (g_next_device == NULL) {
|
2018-09-05 20:32:10 +00:00
|
|
|
fprintf(stderr, "Not enough ioat channels found. Check that ioat channels are bound\n");
|
|
|
|
fprintf(stderr, "to uio_pci_generic or vfio-pci. scripts/setup.sh can help with this.\n");
|
2016-03-10 18:07:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chan = g_next_device->ioat;
|
|
|
|
|
|
|
|
g_next_device = TAILQ_NEXT(g_next_device, tailq);
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
static uint32_t
|
|
|
|
get_max_core(void)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
uint32_t max_core = 0;
|
|
|
|
|
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
if (i > max_core) {
|
|
|
|
max_core = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return max_core;
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:30:38 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2017-04-03 22:02:49 +00:00
|
|
|
uint32_t i, current_core;
|
2017-11-28 20:17:14 +00:00
|
|
|
struct thread_entry *threads;
|
|
|
|
uint32_t num_threads;
|
2015-12-07 23:48:25 +00:00
|
|
|
int rc;
|
2015-12-03 21:30:38 +00:00
|
|
|
|
|
|
|
if (parse_args(argc, argv) != 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init() != 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_user_config(&g_user_config);
|
|
|
|
|
2016-03-10 18:07:32 +00:00
|
|
|
g_next_device = TAILQ_FIRST(&g_devices);
|
2017-04-03 22:02:49 +00:00
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
num_threads = get_max_core() + 1;
|
|
|
|
threads = calloc(num_threads, sizeof(*threads));
|
|
|
|
if (!threads) {
|
|
|
|
fprintf(stderr, "Thread memory allocation failed\n");
|
2015-12-07 23:48:25 +00:00
|
|
|
rc = 1;
|
|
|
|
goto cleanup;
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
current_core = spdk_env_get_current_core();
|
2017-04-03 22:02:49 +00:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
if (i != current_core) {
|
2017-11-28 20:17:14 +00:00
|
|
|
threads[i].chan = get_next_chan();
|
|
|
|
spdk_env_thread_launch_pinned(i, work_fn, &threads[i]);
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 20:17:14 +00:00
|
|
|
threads[current_core].chan = get_next_chan();
|
2020-04-03 08:10:26 +00:00
|
|
|
if (work_fn(&threads[current_core]) != 0) {
|
|
|
|
rc = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-11-28 20:17:14 +00:00
|
|
|
|
|
|
|
spdk_env_thread_wait_all();
|
|
|
|
rc = dump_result(threads, num_threads);
|
2015-12-07 23:48:25 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-05-25 18:21:30 +00:00
|
|
|
spdk_dma_free(g_src);
|
2015-12-07 23:48:25 +00:00
|
|
|
ioat_exit();
|
2017-11-28 20:17:14 +00:00
|
|
|
free(threads);
|
2015-12-03 21:30:38 +00:00
|
|
|
|
2015-12-07 23:48:25 +00:00
|
|
|
return rc;
|
2015-12-03 21:30:38 +00:00
|
|
|
}
|