From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 4CD761CD25 for ; Thu, 5 Apr 2018 18:11:34 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2018 09:11:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,411,1517904000"; d="scan'208";a="31835790" Received: from jeffguo-z170x-ud5.sh.intel.com (HELO localhost.localdomain) ([10.67.104.10]) by orsmga006.jf.intel.com with ESMTP; 05 Apr 2018 09:11:31 -0700 From: Jeff Guo To: stephen@networkplumber.org, bruce.richardson@intel.com, ferruh.yigit@intel.com, konstantin.ananyev@intel.com, gaetan.rivet@6wind.com, jingjing.wu@intel.com, thomas@monjalon.net, motih@mellanox.com, harry.van.haaren@intel.com, jianfeng.tan@intel.com Cc: jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org, jia.guo@intel.com, helin.zhang@intel.com Date: Fri, 6 Apr 2018 00:10:17 +0800 Message-Id: <1522944617-16601-5-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522944617-16601-1-git-send-email-jia.guo@intel.com> References: <1522918968-15290-5-git-send-email-jia.guo@intel.com> <1522944617-16601-1-git-send-email-jia.guo@intel.com> Subject: [dpdk-dev] [PATCH V20 4/4] app/testpmd: enable device hotplug monitoring X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2018 16:11:34 -0000 Use testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event. The process is that, testpmd first enable hotplug by below commands, E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug then testpmd starts the device event monitor by calling the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly. This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set. Signed-off-by: Jeff Guo Reviewed-by: Jianfeng Tan --- v20->v19: no change --- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 2192bdc..1a05284 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -186,6 +186,7 @@ usage(char* progname) printf(" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n"); printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n"); + printf(" --hot-plug: enable hot plug for device.\n"); } #ifdef RTE_LIBRTE_CMDLINE @@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, }; @@ -1101,7 +1103,8 @@ launch_args_parse(int argc, char** argv) rte_exit(EXIT_FAILURE, "invalid mask-event argument\n"); } - + if (!strcmp(lgopts[opt_idx].name, "hot-plug")) + hot_plug = 1; break; case 'h': usage(argv[0]); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 4c0e258..d2c122a 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -284,6 +285,8 @@ uint8_t lsc_interrupt = 1; /* enabled by default */ */ uint8_t rmv_interrupt = 1; /* enabled by default */ +uint8_t hot_plug = 0; /**< hotplug disabled by default. */ + /* * Display or mask ether events * Default to all events except VF_MBOX @@ -391,6 +394,12 @@ static void check_all_ports_link_status(uint32_t port_mask); static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, void *ret_param); +static void eth_dev_event_callback(char *device_name, + enum rte_dev_event_type type, + void *param); +static int eth_dev_event_callback_register(void); +static int eth_dev_event_callback_unregister(void); + /* * Check if all the ports are started. @@ -1853,6 +1862,39 @@ reset_port(portid_t pid) printf("Done\n"); } +static int +eth_dev_event_callback_register(void) +{ + int ret; + + /* register the device event callback */ + ret = rte_dev_event_callback_register(NULL, + eth_dev_event_callback, NULL); + if (ret) { + printf("Failed to register device event callback\n"); + return -1; + } + + return 0; +} + + +static int +eth_dev_event_callback_unregister(void) +{ + int ret; + + /* unregister the device event callback */ + ret = rte_dev_event_callback_unregister(NULL, + eth_dev_event_callback, NULL); + if (ret < 0) { + printf("Failed to unregister device event callback\n"); + return -1; + } + + return 0; +} + void attach_port(char *identifier) { @@ -1916,6 +1958,7 @@ void pmd_test_exit(void) { portid_t pt_id; + int ret; if (test_done == 0) stop_packet_forwarding(); @@ -1929,6 +1972,18 @@ pmd_test_exit(void) close_port(pt_id); } } + + if (hot_plug) { + ret = rte_dev_event_monitor_stop(); + if (ret) + RTE_LOG(ERR, EAL, + "fail to stop device event monitor."); + + ret = eth_dev_event_callback_unregister(); + if (ret) + RTE_LOG(ERR, EAL, + "fail to unregister all event callbacks."); + } printf("\nBye...\n"); } @@ -2059,6 +2114,37 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, return 0; } +/* This function is used by the interrupt thread */ +static void +eth_dev_event_callback(char *device_name, enum rte_dev_event_type type, + __rte_unused void *arg) +{ + if (type >= RTE_DEV_EVENT_MAX) { + fprintf(stderr, "%s called upon invalid event %d\n", + __func__, type); + fflush(stderr); + } + + switch (type) { + case RTE_DEV_EVENT_REMOVE: + RTE_LOG(ERR, EAL, "The device: %s has been removed!\n", + device_name); + /* TODO: After finish failure handle, begin to stop + * packet forward, stop port, close port, detach port. + */ + break; + case RTE_DEV_EVENT_ADD: + RTE_LOG(ERR, EAL, "The device: %s has been added!\n", + device_name); + /* TODO: After finish kernel driver binding, + * begin to attach port. + */ + break; + default: + break; + } +} + static int set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port) { @@ -2474,8 +2560,9 @@ signal_handler(int signum) int main(int argc, char** argv) { - int diag; + int diag; portid_t port_id; + int ret; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); @@ -2543,6 +2630,18 @@ main(int argc, char** argv) nb_rxq, nb_txq); init_config(); + + if (hot_plug) { + /* enable hot plug monitoring */ + ret = rte_dev_event_monitor_start(); + if (ret) { + rte_errno = EINVAL; + return -1; + } + eth_dev_event_callback_register(); + + } + if (start_port(RTE_PORT_ALL) != 0) rte_exit(EXIT_FAILURE, "Start ports failed\n"); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 153abea..8fde68d 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */ extern uint8_t lsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */ + /**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst index 1fd5395..d0ced36 100644 --- a/doc/guides/testpmd_app_ug/run_app.rst +++ b/doc/guides/testpmd_app_ug/run_app.rst @@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug. -- 2.7.4