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 25B81A0C41; Mon, 2 Aug 2021 12:21:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12E8641136; Mon, 2 Aug 2021 12:21:08 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 47BD641136 for ; Mon, 2 Aug 2021 12:21:06 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB46DD6E; Mon, 2 Aug 2021 03:21:05 -0700 (PDT) Received: from net-arm-n1sdp.shanghai.arm.com (net-arm-n1sdp.shanghai.arm.com [10.169.208.222]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1E6543F70D; Mon, 2 Aug 2021 03:20:58 -0700 (PDT) From: Joyce Kong To: thomas@monjalon.net, david.marchand@redhat.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com, konstantin.ananyev@intel.com, rsanford@akamai.com, erik.g.carrillo@intel.com, olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, vladimir.medvedkin@intel.com, anatoly.burakov@intel.com, andrew.rybchenko@oktetlabs.ru, jerinj@marvell.com, declan.doherty@intel.com, ciara.power@intel.com, xiaoyun.li@intel.com, nicolas.chautru@intel.com, maryam.tahhan@intel.com, reshma.pattan@intel.com, cristian.dumitrescu@intel.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 2 Aug 2021 05:18:45 -0500 Message-Id: <20210802101847.3462-11-joyce.kong@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210802101847.3462-1-joyce.kong@arm.com> References: <20210802101847.3462-1-joyce.kong@arm.com> Subject: [dpdk-dev] [PATCH v1 10/12] app/testpmd: use compiler atomic builtins for port sync 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 Sender: "dev" Replace rte_atomic16_cmpset operation with compiler atomic CAS operation for port status sync in testpmd case. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang --- app/test-pmd/testpmd.c | 75 +++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 6cbe9ba3c8..22579dd438 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -2302,6 +2301,7 @@ setup_hairpin_queues(portid_t pi, portid_t p_pi, uint16_t cnt_pi) uint16_t peer_tx_port = pi; uint32_t manual = 1; uint32_t tx_exp = hairpin_mode & 0x10; + uint16_t port_exp; if (!(hairpin_mode & 0xf)) { peer_rx_port = pi; @@ -2347,10 +2347,11 @@ setup_hairpin_queues(portid_t pi, portid_t p_pi, uint16_t cnt_pi) if (diag == 0) continue; + port_exp = RTE_PORT_HANDLING; /* Fail to setup rx queue, return */ - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, - RTE_PORT_STOPPED) == 0) + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); fprintf(stderr, "Fail to configure port %d hairpin queues\n", @@ -2370,10 +2371,11 @@ setup_hairpin_queues(portid_t pi, portid_t p_pi, uint16_t cnt_pi) if (diag == 0) continue; + port_exp = RTE_PORT_HANDLING; /* Fail to setup rx queue, return */ - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, - RTE_PORT_STOPPED) == 0) + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); fprintf(stderr, "Fail to configure port %d hairpin queues\n", @@ -2444,6 +2446,7 @@ start_port(portid_t pid) queueid_t qi; struct rte_port *port; struct rte_eth_hairpin_cap cap; + uint16_t port_exp; if (port_id_is_invalid(pid, ENABLED_WARN)) return 0; @@ -2454,8 +2457,10 @@ start_port(portid_t pid) need_check_link_status = 0; port = &ports[pi]; - if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED, - RTE_PORT_HANDLING) == 0) { + port_exp = RTE_PORT_STOPPED; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_HANDLING, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) { fprintf(stderr, "Port %d is now not stopped\n", pi); continue; } @@ -2487,8 +2492,10 @@ start_port(portid_t pid) nb_txq + nb_hairpinq, &(port->dev_conf)); if (diag != 0) { - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0) + port_exp = RTE_PORT_HANDLING; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); @@ -2518,10 +2525,11 @@ start_port(portid_t pid) if (diag == 0) continue; + port_exp = RTE_PORT_HANDLING; /* Fail to setup tx queue, return */ - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, - RTE_PORT_STOPPED) == 0) + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); @@ -2570,10 +2578,11 @@ start_port(portid_t pid) if (diag == 0) continue; + port_exp = RTE_PORT_HANDLING; /* Fail to setup rx queue, return */ - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, - RTE_PORT_STOPPED) == 0) + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); @@ -2607,17 +2616,21 @@ start_port(portid_t pid) fprintf(stderr, "Fail to start port %d: %s\n", pi, rte_strerror(-diag)); + port_exp = RTE_PORT_HANDLING; /* Fail to setup rx queue, return */ - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0) + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set back to stopped\n", pi); continue; } - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0) + port_exp = RTE_PORT_HANDLING; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STARTED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set into started\n", pi); @@ -2697,6 +2710,7 @@ stop_port(portid_t pid) int need_check_link_status = 0; portid_t peer_pl[RTE_MAX_ETHPORTS]; int peer_pi; + uint16_t port_exp; if (port_id_is_invalid(pid, ENABLED_WARN)) return; @@ -2722,8 +2736,10 @@ stop_port(portid_t pid) } port = &ports[pi]; - if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED, - RTE_PORT_HANDLING) == 0) + port_exp = RTE_PORT_STARTED; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_HANDLING, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) continue; if (hairpin_mode & 0xf) { @@ -2749,8 +2765,10 @@ stop_port(portid_t pid) RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n", pi); - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0) + port_exp = RTE_PORT_HANDLING; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_STOPPED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0) fprintf(stderr, "Port %d can not be set into stopped\n", pi); need_check_link_status = 1; @@ -2788,6 +2806,7 @@ close_port(portid_t pid) { portid_t pi; struct rte_port *port; + uint16_t port_exp; if (port_id_is_invalid(pid, ENABLED_WARN)) return; @@ -2813,8 +2832,10 @@ close_port(portid_t pid) } port = &ports[pi]; - if (rte_atomic16_cmpset(&(port->port_status), - RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) { + port_exp = RTE_PORT_CLOSED; + if (__atomic_compare_exchange_n(&(port->port_status), + &port_exp, RTE_PORT_CLOSED, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { fprintf(stderr, "Port %d is already closed\n", pi); continue; } -- 2.17.1