From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by dpdk.org (Postfix) with ESMTP id 8DE3F37AA for ; Tue, 4 Aug 2015 13:32:58 +0200 (CEST) Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NSK00WLZ2QW9JC0@mailout2.samsung.com> for dev@dpdk.org; Tue, 04 Aug 2015 20:32:56 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.125]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 57.0B.28411.8E2A0C55; Tue, 4 Aug 2015 20:32:56 +0900 (KST) X-AuditID: cbfee68e-f79c56d000006efb-06-55c0a2e8268a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 3B.CC.07062.8E2A0C55; Tue, 4 Aug 2015 20:32:56 +0900 (KST) Received: from ubuntu.sisodomain.com ([107.108.207.86]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NSK00HV52NGTF00@mmp2.samsung.com>; Tue, 04 Aug 2015 20:32:56 +0900 (KST) From: Harpal Singh To: dev@dpdk.org Date: Tue, 04 Aug 2015 17:08:52 +0530 Message-id: <1438688332-3392-4-git-send-email-harpal.sd@samsung.com> X-Mailer: git-send-email 1.8.3.2 In-reply-to: <1438688332-3392-1-git-send-email-harpal.sd@samsung.com> References: <1438688332-3392-1-git-send-email-harpal.sd@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsWyRsSkVvfFogOhBtuXmFm8+7SdyWLrQSkH Jo9fC5ayevRtWcUYwBTFZZOSmpNZllqkb5fAldH9+C1LwRbXip7dF9gaGK9bdDFyckgImEgs f7eKCcIWk7hwbz0biC0ksIJR4t9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BBrYllxZe4hRgkOZiURXoOq A6FCvCmJlVWpRfnxRaU5qcWHGE2BDpvILCWanA+My7ySeENjE3NTY1NLEwsTM0slcV59k02h QgLpiSWp2ampBalFMH1MHJxSDYy+V1NDnl36EOnLdDrJu5Xj8JmKn49PXZqR+Wk2p8zXE8Jl Jre6/2vrhR1ZNlGlQ8x3vmplj6hHyYGN+i+TXYO9ZyUcvKKoY7f3tnPhhtkfDr/I6I+ssX3/ 9mbd9be865knZrdEn7DPyBHk8pl3LbXdbV/n47PC0k7CpT8m7055/0me8afJIQElluKMREMt 5qLiRACoY4PvkwIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Mailman-Approved-At: Tue, 04 Aug 2015 14:10:06 +0200 Cc: Harpal Singh Subject: [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2015 11:32:59 -0000 From: Harpal Singh 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 --- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 +{ .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