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 8C05DA00C3; Tue, 14 Dec 2021 15:13:57 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 667E541155; Tue, 14 Dec 2021 15:13:14 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 8F5BD4113E for ; Tue, 14 Dec 2021 15:13:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1639491192; x=1671027192; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pJwgtgPDAa76cI6LGrsSGCMlAYxRRljoTl6XxGmmILo=; b=dtHy81VU5CxAodSatC11eu7BeLgYsfoHLfhA14vw5Zn0zws7fBI4CT5q kmhtdpPkUJsZNRa9rEuxAYuHxd9fkB0KG0j14zyngfDigTArvzcK5+42x MrS7/+aUzdNv0gmK0fXJVORPeHXZZTd+tz+0RLZhi11HIXj7z73pCNF0T js7f0auqjhdw++P7PTB5Q327pp7NgTGc+A2UFcFN+3P/NTUobTzfwRb7B ZS5b23LmCKhZiF69Qx9W27kD2ERpCZVvufWkhei9U8cryWneKs3VQrt2v wbjqTmoQH5MTA+jWXpVx7D5QfVKZzlfNyx4Zc08d1RItvAOw7B9IV8dml Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10197"; a="263123885" X-IronPort-AV: E=Sophos;i="5.88,205,1635231600"; d="scan'208";a="263123885" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2021 06:13:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,205,1635231600"; d="scan'208";a="465104187" Received: from silpixa00401120.ir.intel.com ([10.55.129.95]) by orsmga006.jf.intel.com with ESMTP; 14 Dec 2021 06:13:01 -0800 From: Ronan Randles To: dev@dpdk.org Cc: harry.van.haaren@intel.com, Ronan Randles Subject: [PATCH 11/12] examples/generator: link status check added Date: Tue, 14 Dec 2021 14:12:41 +0000 Message-Id: <20211214141242.3383831-12-ronan.randles@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214141242.3383831-1-ronan.randles@intel.com> References: <20211214141242.3383831-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 | 70 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/examples/generator/main.c b/examples/generator/main.c index 2525d34b6e..f11110e528 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; @@ -58,6 +62,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. */ @@ -101,6 +129,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++) { @@ -140,6 +171,16 @@ 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; } @@ -166,12 +207,26 @@ 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; + + /* 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); + } + 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); @@ -219,8 +274,19 @@ lcore_consumer(void *arg) "polling thread.\n\tPerformance will " "not be optimal.\n", port); + /* 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); + } + /* 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 @@ -257,8 +323,6 @@ tele_gen_packet(const char *cmd, const char *params, struct rte_tel_data *d) { RTE_SET_USED(cmd); RTE_SET_USED(params); - RTE_SET_USED(d); - rte_tel_data_string(d, "Ether()/IP()"); return 0; } -- 2.25.1