#include <stdbool.h>
#include <string.h>
-#include <rte_atomic.h>
#include <rte_cycles.h>
#include <rte_memcpy.h>
#include <rte_random.h>
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);
* 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;
}
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",
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
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);
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;
}
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",
* 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;