From 81a36e1c1a1e03966f103a5ba1aefa7b23c7df31 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 19 Jan 2016 17:16:48 +0800 Subject: [PATCH] spdk: show error message when no DMA channel found We will check the DMA channel count which associated with kernel ioatdma driver, and print the error message when no DMA channel found. Change-Id: I1d24108acb8fc6ee0c8f6041072e2dd528f55b24 Signed-off-by: Changpeng Liu --- examples/ioat/kperf/ioat_kperf.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/examples/ioat/kperf/ioat_kperf.c b/examples/ioat/kperf/ioat_kperf.c index 335adf41f5..fd2196626c 100644 --- a/examples/ioat/kperf/ioat_kperf.c +++ b/examples/ioat/kperf/ioat_kperf.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -148,6 +149,29 @@ get_u64_from_file(const char *sysfs_file, uint64_t *value) return 0; } +static int +get_dma_channel_count(void) +{ + int count = 0; + struct dirent *e; + DIR *dir; + char *str; + + dir = opendir("/sys/bus/pci/drivers/ioatdma"); + if (dir == NULL) { + return 0; + } + + while ((e = readdir(dir)) != NULL) { + str = strstr(e->d_name, ":"); + if (str != NULL) + count++; + } + closedir(dir); + + return count; +} + static void usage(char *program_name) { @@ -164,6 +188,7 @@ int main(int argc, char *argv[]) int op; int rc; char buf[BUFSIZ]; + uint32_t count = 0; uint32_t i, threads = 0; uint32_t ring_size, queue_depth = 0; uint32_t transfer_size, order = 0; @@ -181,6 +206,11 @@ int main(int argc, char *argv[]) " run `insmod dmaperf.ko` in the kmod directory\n"); return -1; } + count = get_dma_channel_count(); + if (!count) { + fprintf(stderr, "No DMA channel found\n"); + return -1; + } rc = get_u32_from_file("/sys/module/ioatdma/parameters/ioat_ring_alloc_order", &order); @@ -194,6 +224,10 @@ int main(int argc, char *argv[]) switch (op) { case 'n': threads = atoi(optarg); + if (threads > count) { + fprintf(stderr, "Error: Total channel count %u\n", count); + return -1; + } rc = put_u32_to_file("/sys/kernel/debug/dmaperf/dmaperf/threads", threads); if (rc < 0) { fprintf(stderr, "Cannot set dma channels\n");