1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
15 #include <rte_atomic.h>
17 #include "sfc_tweak.h"
24 * 64-bit packets and bytes counters covered by 128-bit integer
25 * in order to do atomic updates to guarantee consistency if
28 union sfc_pkts_bytes {
34 rte_int128_t pkts_bytes;
38 * Update packets and bytes counters atomically in assumption that
39 * the counter is written on one core only.
42 sfc_pkts_bytes_add(union sfc_pkts_bytes *st, uint64_t pkts, uint64_t bytes)
44 #if SFC_SW_STATS_ATOMIC
45 union sfc_pkts_bytes result;
47 /* Stats are written on single core only, so just load values */
48 result.pkts = st->pkts + pkts;
49 result.bytes = st->bytes + bytes;
52 * Store the result atomically to guarantee that the reader
53 * core sees both counter updates together.
55 __atomic_store_n(&st->pkts_bytes.int128, result.pkts_bytes.int128,
64 * Get an atomic copy of a packets and bytes counters.
67 sfc_pkts_bytes_get(const union sfc_pkts_bytes *st, union sfc_pkts_bytes *result)
69 #if SFC_SW_STATS_ATOMIC
70 result->pkts_bytes.int128 = __atomic_load_n(&st->pkts_bytes.int128,
80 #endif /* _SFC_STATS_H */