DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harpal Singh <harpal.sd@samsung.com>
To: dev@dpdk.org
Cc: Harpal Singh <harpal.sd@samsung.com>
Subject: [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program
Date: Tue, 04 Aug 2015 17:08:52 +0530	[thread overview]
Message-ID: <1438688332-3392-4-git-send-email-harpal.sd@samsung.com> (raw)
In-Reply-To: <1438688332-3392-1-git-send-email-harpal.sd@samsung.com>

From: Harpal Singh <harpal.sd@samsung.com>

Added a new hotplug test program: it has been added to test hot removal of a
vfio device.
1) This test will first deregister all the pci drivers and register its own driver.
2) Then it scan the bus and call probe for all the scanned devices whose vendor
id and device id is registered.
3) Inside driver init it enables req interrupt and then registers a callback for it.
4) After that it trigger the req interrupt by writting on fd.
5) Then req interrupt callback will be called which will create a posix
thread (since interrupt callback cant be deregistered within interrupt callback).
6) Inside posix thread it calls close one driver for the device.
7) After that driver deinit will be called by pci framework. Here we set the flag
to signal success in device removal.

If any of the above steps fails test will not pass.

Signed-off-by: Harpal Singh <harpal.sd@samsung.com>
---
 app/test/Makefile       |   2 +-
 app/test/test_hotplug.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_hotplug.c

diff --git a/app/test/Makefile b/app/test/Makefile
index e7f148f..e0e4425 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -57,7 +57,7 @@ SRCS-y += test_memzone.c
 SRCS-y += test_ring.c
 SRCS-y += test_ring_perf.c
 SRCS-y += test_pmd_perf.c
-
+SRCS-y += test_hotplug.c
 ifeq ($(CONFIG_RTE_LIBRTE_TABLE),y)
 SRCS-y += test_table.c
 SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += test_table_pipeline.c
diff --git a/app/test/test_hotplug.c b/app/test/test_hotplug.c
new file mode 100644
index 0000000..698069c
--- /dev/null
+++ b/app/test/test_hotplug.c
@@ -0,0 +1,259 @@
+/*-
+ *  BSD LICENSE
+ *
+ *  Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *  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.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <rte_common.h>
+#include <rte_cycles.h>
+#include <rte_interrupts.h>
+#include <string.h>
+#include <sys/queue.h>
+#include <rte_pci.h>
+#include <rte_ethdev.h>
+#include <rte_devargs.h>
+#include "test.h"
+
+
+#define TEST_INTERRUPT_CHECK_INTERVAL 1000 /* ms */
+#define NUM_MAX_DRIVERS 256
+
+/* flag of if removal is called */
+static volatile int flag;
+static struct rte_intr_handle req_handle;
+
+union intr_pipefds{
+	struct {
+		int pipefd[2];
+	};
+	struct {
+		int readfd;
+		int writefd;
+	};
+};
+
+static union intr_pipefds pfds;
+
+static unsigned pci_dev_count;
+
+#ifdef RTE_EXEC_ENV_LINUXAPP
+/**
+ * Initialization for req interrupt test.
+ */
+static int
+test_req_interrupt_init(void)
+{
+	if (pipe(pfds.pipefd) < 0)
+		return -1;
+
+	req_handle.fd = pfds.readfd;
+	req_handle.type = RTE_INTR_HANDLE_VFIO_REQ;
+
+	return 0;
+}
+
+/**
+ * Deinitialization for req interrupt test.
+ */
+static int
+test_req_interrupt_deinit(void)
+{
+	close(pfds.pipefd[0]);
+	close(pfds.pipefd[1]);
+	return 0;
+}
+
+/**
+ * Write the pipe to simulate an req interrupt.
+ */
+
+static int
+test_req_trigger_interrupt(void)
+{
+	if (write(pfds.writefd, "1", 1) < 0)
+		return -1;
+	return 0;
+}
+#else
+
+static int
+test_req_interrupt_init(void)
+{
+	return 0;
+}
+
+static int
+test_req_interrupt_deinit(void)
+{
+	return 0;
+}
+
+static int
+test_req_interrupt_trigger_interrupt(void)
+{
+	return 0;
+}
+#endif /* RTE_EXEC_ENV_LINUXAPP */
+
+
+/**
+ * Callback for the test req interrupt.
+ */
+static void *bh_test_req_interrupt_callback(void *arg)
+{
+	printf("Removal Callback is called\n");
+	struct rte_pci_device *dev = (struct rte_pci_device *)arg;
+	rte_eal_pci_close_one(&dev->addr);
+	return 0;
+}
+
+static void
+test_req_interrupt_callback(__attribute__((unused))struct rte_intr_handle *intr_handle, void *arg)
+{
+	pthread_t p_thread;
+	pthread_create(&p_thread,NULL, bh_test_req_interrupt_callback, arg);
+}
+
+
+
+struct rte_pci_id pci_driver_id[] = {
+#include <rte_pci_dev_ids.h>
+{ .vendor_id = 0, /* sentinel */ },
+};
+
+static int pci_driver_init(__attribute__((unused)) struct rte_pci_driver *dr
+					,struct rte_pci_device *dev);
+static int pci_driver_uninit(struct rte_pci_device *dev);
+
+struct rte_pci_driver pci_driver = {
+	.name = "test_driver",
+	.devinit = pci_driver_init,
+	.devuninit= pci_driver_uninit,
+	.id_table = pci_driver_id,
+	.drv_flags = 0,
+};
+
+static int
+pci_driver_init(__attribute__((unused)) struct rte_pci_driver *dr, struct rte_pci_device *dev)
+{
+	printf("My driver init called in %s\n", dr->name);
+	printf("%x:%x:%x.%d", dev->addr.domain, dev->addr.bus,
+	       dev->addr.devid, dev->addr.function);
+	printf(" - vendor:%x device:%x\n", dev->id.vendor_id, dev->id.device_id);
+
+	if (test_req_interrupt_init() < 0) {
+		printf("fail to initialize for testing req interrupt\n");
+		return -1;
+	}
+
+	printf("start req interrupt enable/disable test\n");
+	rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+	/* register req interrupt callback function */
+	if (rte_intr_callback_register(&req_handle,
+			test_req_interrupt_callback, (void *)dev) < 0) {
+		printf("fail to register callback\n");
+		return -1;
+	}
+	printf("Device is initialized and REQ interrupt is registered\n");
+	rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+	/* trigger req interruprt */
+	if (test_req_trigger_interrupt() < 0)
+		return -1;
+	printf("REQ interrupt is triggered, now device removal request will be called\n");
+	pci_dev_count ++;
+	return 0;
+}
+
+
+static int
+pci_driver_uninit(struct rte_pci_device *dev)
+{
+	printf("My driver Removal is called \n");
+	printf("%x:%x:%x.%d", dev->addr.domain, dev->addr.bus,
+	       dev->addr.devid, dev->addr.function);
+	printf(" - vendor:%x device:%x\n", dev->id.vendor_id, dev->id.device_id);
+	if (rte_intr_callback_unregister(&req_handle,
+			test_req_interrupt_callback, (void *)dev) < 0)
+		return -1;
+	test_req_interrupt_deinit();
+	flag = 1;
+	pci_dev_count --;
+	return 0;
+}
+
+static int
+test_hotplug(void)
+{
+	struct rte_pci_driver *dr = NULL;
+	struct rte_pci_driver *save_pci_driver_list[NUM_MAX_DRIVERS];
+	unsigned i,num_drivers = 0;
+	int count;
+
+	/* Unregister all previous drivers */
+	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+		rte_eal_pci_unregister(dr);
+		save_pci_driver_list[num_drivers++] = dr;
+	}
+	rte_eal_pci_register(&pci_driver);
+	flag = 0;
+	pci_dev_count = 0;
+	printf("Scan bus\n");
+	rte_eal_pci_scan();
+	rte_eal_pci_probe();
+
+	if (pci_dev_count == 0) {
+		printf("no device detected\n");
+		return -1;
+	}
+	/* check flag in 3 seconds */
+	for (count = 0; flag == 0 && count < 3; count++)
+		rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+
+	if (flag == 0) {
+		printf("callback has not been called\n");
+		return -1;
+	}
+	rte_eal_pci_unregister(&pci_driver);
+	/* Restore original driver list */
+	for (i = 0; i < num_drivers; i++)
+		rte_eal_pci_register(save_pci_driver_list[i]);
+
+	return 0;
+}
+
+static struct test_command hotplug_cmd = {
+	.command = "hotplug_autotest",
+	.callback = test_hotplug,
+};
+REGISTER_TEST_COMMAND(hotplug_cmd);
+
-- 
1.9.1

      parent reply	other threads:[~2015-08-04 11:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
2015-08-04 14:24   ` Burakov, Anatoly
2015-08-04 11:38 ` [dpdk-dev] [PATCH 2/3] vfio: Added vfio req interrupt support Harpal Singh
2015-08-04 11:38 ` Harpal Singh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438688332-3392-4-git-send-email-harpal.sd@samsung.com \
    --to=harpal.sd@samsung.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).