From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2F06A034E; Fri, 21 Jan 2022 11:32:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C804C42786; Fri, 21 Jan 2022 11:31:46 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 005E440042 for ; Fri, 21 Jan 2022 11:31:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642761104; x=1674297104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8LhZfzmp2EezJLVPdCKhcaxDJb9I56S7MDmCLyZtqZc=; b=JXshPH6vKC2Pe7GIO5Pf18el9MBUPTk6Q4eQ9dpmzbV9qIV15VfwoBid jFCXMRRu1Qh6yjz1AecGQF43AKO6a4MihkuOZ6dR363PpcCbDLffYXzMF VrpWFiRDjOFqdsJScFvr8uwI9pCL3jb+UJa2erxFT+8ybU4vv+RbIESGR ctShyVQfs9zauFPVyLlsTiOhFgkAxqnYAoNpt/Dop9Fn1NrTOZpPB1gky K69/bJQD96R3sYUJHSBvKkpq334XevSlbT1HVwZX7xkemvKy71VFGTDtZ mefpkwzIQRv32NkHU+zwhzvQZJ/bFjjjXxFPwDpqNuKaqtGnoEYDHUOHT Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10233"; a="270045136" X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="270045136" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 02:31:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="533222780" Received: from silpixa00401120.ir.intel.com ([10.55.128.255]) by orsmga008.jf.intel.com with ESMTP; 21 Jan 2022 02:31:42 -0800 From: Ronan Randles To: dev@dpdk.org Cc: Ronan Randles Subject: [PATCH v2 11/15] examples/generator: link status check added Date: Fri, 21 Jan 2022 10:31:18 +0000 Message-Id: <20220121103122.2926856-12-ronan.randles@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220121103122.2926856-1-ronan.randles@intel.com> References: <20211214141242.3383831-1-ronan.randles@intel.com> <20220121103122.2926856-1-ronan.randles@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commit brings in a link status check so that the generator will only start sending packets once there is something on the other end of the link. Signed-off-by: Ronan Randles --- examples/generator/main.c | 68 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/examples/generator/main.c b/examples/generator/main.c index 1ac3caafcc..0834a094a4 100644 --- a/examples/generator/main.c +++ b/examples/generator/main.c @@ -27,9 +27,13 @@ static const struct rte_eth_conf port_conf_default = { .rxmode = { .max_lro_pkt_size = RTE_ETHER_MAX_LEN, }, + .intr_conf = { + .lsc = 1, /**< lsc interrupt */ + }, }; static volatile int done; +static volatile int link_status[RTE_MAX_ETHPORTS]; static struct rte_mempool *mbuf_pool; struct rte_gen *gen; @@ -56,6 +60,30 @@ static struct telemetry_userdata telemetry_userdata; static void handle_sigint(int sig); +static int +link_status_change_cb(uint16_t port_id, enum rte_eth_event_type type, + void *param, void *ret_param) +{ + if (unlikely(port_id >= RTE_DIM(link_status))) + rte_panic("got LSC interrupt for unknown port id\n"); + + RTE_SET_USED(type); + RTE_SET_USED(param); + RTE_SET_USED(ret_param); + + struct rte_eth_link link; + int ret = rte_eth_link_get_nowait(port_id, &link); + if (ret < 0) { + printf("Failed link get on port %d: %s\n", + port_id, rte_strerror(-ret)); + return ret; + } + + printf("Link status change port %i\n", port_id); + link_status[port_id] = link.link_status; + return 0; +} + /* Initializes a given port using global settings and with the RX buffers * coming from the mbuf_pool passed as a parameter. */ @@ -99,6 +127,9 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) printf("Not enough threads available\n"); return -1; } + /* Register the LinkStatusChange callback */ + rte_eth_dev_callback_register(port, RTE_ETH_EVENT_INTR_LSC, + link_status_change_cb, NULL); /* Allocate and set up 1 RX queue per Ethernet port. */ for (q = 0; q < rx_rings; q++) { @@ -138,9 +169,33 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) if (retval != 0) return retval; + struct rte_eth_link link; + int ret = rte_eth_link_get_nowait(port, &link); + if (ret < 0) { + printf("Failed link get on port %d: %s\n", port, + rte_strerror(-ret)); + return ret; + } + + link_status[port] = link.link_status; + return 0; } +static void +gen_wait_for_links_up(void) +{ + /* Ensure all available ports are up before generating packets */ + uint16_t nb_eth_ports = rte_eth_dev_count_avail(); + uint16_t nb_links_up = 0; + while (!done && nb_links_up < nb_eth_ports) { + if (link_status[nb_links_up]) + nb_links_up++; + + rte_delay_us_block(100); + } +} + /* The lcore main. This is the main thread that does the work, reading from * an input port and writing to an output port. */ @@ -164,12 +219,19 @@ lcore_producer(void *arg) uint64_t tsc_hz = rte_get_tsc_hz(); uint64_t last_tsc_reading = 0; uint64_t last_tx_total = 0; + uint16_t nb_tx = 0; + + /* Wait for links to come up before generating packets */ + gen_wait_for_links_up(); + if (!done) + printf("Generating packets...\n"); /* Run until the application is quit or killed. */ while (!done) { + struct rte_mbuf *bufs[BURST_SIZE]; - uint16_t nb_tx = 0; /* Receive packets from gen and then tx them over port */ + RTE_ETH_FOREACH_DEV(port) { int nb_generated = rte_gen_rx_burst(gen, bufs, BURST_SIZE); @@ -217,8 +279,12 @@ lcore_consumer(void *arg) "polling thread.\n\tPerformance will " "not be optimal.\n", port); + /* Wait for links to come up before generating packets */ + gen_wait_for_links_up(); + /* Run until the application is quit or killed. */ while (!done) { + struct rte_mbuf *bufs[BURST_SIZE]; /* Receive packets over port and then tx them to gen library -- 2.25.1