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 A5D93A052A; Tue, 26 Jan 2021 17:37:06 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2F066140DB4; Tue, 26 Jan 2021 17:37:06 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 535AF140CD9 for ; Tue, 26 Jan 2021 17:37:05 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 2F1B44005E for ; Tue, 26 Jan 2021 17:37:04 +0100 (CET) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 1D43E40080; Tue, 26 Jan 2021 17:37:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on bernadotte.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=disabled version=3.4.2 X-Spam-Score: -1.0 Received: from isengard.friendlyfire.se (h-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id D31EB4005E; Tue, 26 Jan 2021 17:36:52 +0100 (CET) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: jerinj@marvell.com Cc: dev@dpdk.org, =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Date: Tue, 26 Jan 2021 17:36:50 +0100 Message-Id: <20210126163650.63528-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH] event/dsw: use GCC built-ins for atomics 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" Use C11-style GCC built-in functions for atomic operations. Signed-off-by: Mattias Rönnblom --- drivers/event/dsw/dsw_evdev.c | 5 +---- drivers/event/dsw/dsw_evdev.h | 6 +++--- drivers/event/dsw/dsw_event.c | 37 ++++++++++++++++++++-------------- drivers/event/dsw/dsw_xstats.c | 4 ++-- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/event/dsw/dsw_evdev.c b/drivers/event/dsw/dsw_evdev.c index 933a5a559b..455e8b9027 100644 --- a/drivers/event/dsw/dsw_evdev.c +++ b/drivers/event/dsw/dsw_evdev.c @@ -61,9 +61,6 @@ dsw_port_setup(struct rte_eventdev *dev, uint8_t port_id, port->in_ring = in_ring; port->ctl_in_ring = ctl_in_ring; - rte_atomic16_init(&port->load); - rte_atomic32_init(&port->immigration_load); - port->load_update_interval = (DSW_LOAD_UPDATE_INTERVAL * rte_get_timer_hz()) / US_PER_S; @@ -275,7 +272,7 @@ dsw_start(struct rte_eventdev *dev) uint16_t i; uint64_t now; - rte_atomic32_init(&dsw->credits_on_loan); + dsw->credits_on_loan = 0; initial_flow_to_port_assignment(dsw); diff --git a/drivers/event/dsw/dsw_evdev.h b/drivers/event/dsw/dsw_evdev.h index 6cb77cfc44..08889a0990 100644 --- a/drivers/event/dsw/dsw_evdev.h +++ b/drivers/event/dsw/dsw_evdev.h @@ -219,9 +219,9 @@ struct dsw_port { struct rte_ring *ctl_in_ring __rte_cache_aligned; /* Estimate of current port load. */ - rte_atomic16_t load __rte_cache_aligned; + int16_t load __rte_cache_aligned; /* Estimate of flows currently migrating to this port. */ - rte_atomic32_t immigration_load __rte_cache_aligned; + int32_t immigration_load __rte_cache_aligned; } __rte_cache_aligned; struct dsw_queue { @@ -241,7 +241,7 @@ struct dsw_evdev { uint8_t num_queues; int32_t max_inflight; - rte_atomic32_t credits_on_loan __rte_cache_aligned; + int32_t credits_on_loan __rte_cache_aligned; }; #define DSW_CTL_PAUS_REQ (0) diff --git a/drivers/event/dsw/dsw_event.c b/drivers/event/dsw/dsw_event.c index 611b36781f..1f09816945 100644 --- a/drivers/event/dsw/dsw_event.c +++ b/drivers/event/dsw/dsw_event.c @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -32,7 +31,8 @@ dsw_port_acquire_credits(struct dsw_evdev *dsw, struct dsw_port *port, return true; } - total_on_loan = rte_atomic32_read(&dsw->credits_on_loan); + total_on_loan = + __atomic_load_n(&dsw->credits_on_loan, __ATOMIC_RELAXED); available = dsw->max_inflight - total_on_loan; acquired_credits = RTE_MAX(missing_credits, DSW_PORT_MIN_CREDITS); @@ -43,12 +43,14 @@ dsw_port_acquire_credits(struct dsw_evdev *dsw, struct dsw_port *port, * thread can allocate tokens in between the check and the * allocation. */ - new_total_on_loan = rte_atomic32_add_return(&dsw->credits_on_loan, - acquired_credits); + new_total_on_loan = + __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits, + __ATOMIC_RELAXED); if (unlikely(new_total_on_loan > dsw->max_inflight)) { /* Some other port took the last credits */ - rte_atomic32_sub(&dsw->credits_on_loan, acquired_credits); + __atomic_sub_fetch(&dsw->credits_on_loan, acquired_credits, + __ATOMIC_RELAXED); return false; } @@ -74,7 +76,8 @@ dsw_port_return_credits(struct dsw_evdev *dsw, struct dsw_port *port, port->inflight_credits = leave_credits; - rte_atomic32_sub(&dsw->credits_on_loan, return_credits); + __atomic_sub_fetch(&dsw->credits_on_loan, return_credits, + __ATOMIC_RELAXED); DSW_LOG_DP_PORT(DEBUG, port->id, "Returned %d tokens to pool.\n", @@ -152,19 +155,19 @@ dsw_port_load_update(struct dsw_port *port, uint64_t now) int16_t period_load; int16_t new_load; - old_load = rte_atomic16_read(&port->load); + old_load = __atomic_load_n(&port->load, __ATOMIC_RELAXED); period_load = dsw_port_load_close_period(port, now); new_load = (period_load + old_load*DSW_OLD_LOAD_WEIGHT) / (DSW_OLD_LOAD_WEIGHT+1); - rte_atomic16_set(&port->load, new_load); + __atomic_store_n(&port->load, new_load, __ATOMIC_RELAXED); /* The load of the recently immigrated flows should hopefully * be reflected the load estimate by now. */ - rte_atomic32_set(&port->immigration_load, 0); + __atomic_store_n(&port->immigration_load, 0, __ATOMIC_RELAXED); } static void @@ -367,9 +370,11 @@ dsw_retrieve_port_loads(struct dsw_evdev *dsw, int16_t *port_loads, uint16_t i; for (i = 0; i < dsw->num_ports; i++) { - int16_t measured_load = rte_atomic16_read(&dsw->ports[i].load); + int16_t measured_load = + __atomic_load_n(&dsw->ports[i].load, __ATOMIC_RELAXED); int32_t immigration_load = - rte_atomic32_read(&dsw->ports[i].immigration_load); + __atomic_load_n(&dsw->ports[i].immigration_load, + __ATOMIC_RELAXED); int32_t load = measured_load + immigration_load; load = RTE_MIN(load, DSW_MAX_LOAD); @@ -502,8 +507,8 @@ dsw_select_emigration_target(struct dsw_evdev *dsw, target_qfs[*targets_len] = *candidate_qf; (*targets_len)++; - rte_atomic32_add(&dsw->ports[candidate_port_id].immigration_load, - candidate_flow_load); + __atomic_add_fetch(&dsw->ports[candidate_port_id].immigration_load, + candidate_flow_load, __ATOMIC_RELAXED); return true; } @@ -850,7 +855,8 @@ dsw_port_consider_emigration(struct dsw_evdev *dsw, return; } - source_port_load = rte_atomic16_read(&source_port->load); + source_port_load = + __atomic_load_n(&source_port->load, __ATOMIC_RELAXED); if (source_port_load < DSW_MIN_SOURCE_LOAD_FOR_MIGRATION) { DSW_LOG_DP_PORT(DEBUG, source_port->id, "Load %d is below threshold level %d.\n", @@ -1205,7 +1211,8 @@ dsw_event_enqueue_burst_generic(struct dsw_port *source_port, * simplicity reasons, we deny the whole burst if the port is * above the water mark. */ - if (unlikely(num_new > 0 && rte_atomic32_read(&dsw->credits_on_loan) > + if (unlikely(num_new > 0 && + __atomic_load_n(&dsw->credits_on_loan, __ATOMIC_RELAXED) > source_port->new_event_threshold)) return 0; diff --git a/drivers/event/dsw/dsw_xstats.c b/drivers/event/dsw/dsw_xstats.c index e8e92183e2..4f7d4e3ff9 100644 --- a/drivers/event/dsw/dsw_xstats.c +++ b/drivers/event/dsw/dsw_xstats.c @@ -48,7 +48,7 @@ struct dsw_xstats_port { static uint64_t dsw_xstats_dev_credits_on_loan(struct dsw_evdev *dsw) { - return rte_atomic32_read(&dsw->credits_on_loan); + return __atomic_load_n(&dsw->credits_on_loan, __ATOMIC_RELAXED); } static struct dsw_xstat_dev dsw_dev_xstats[] = { @@ -126,7 +126,7 @@ dsw_xstats_port_get_load(struct dsw_evdev *dsw, uint8_t port_id, { int16_t load; - load = rte_atomic16_read(&dsw->ports[port_id].load); + load = __atomic_load_n(&dsw->ports[port_id].load, __ATOMIC_RELAXED); return DSW_LOAD_TO_PERCENT(load); } -- 2.25.1