diff options
author | Matias Elo <matias.elo@nokia.com> | 2020-10-26 13:54:01 +0200 |
---|---|---|
committer | Matias Elo <matias.elo@nokia.com> | 2020-11-02 17:32:42 +0200 |
commit | c13a23704632c0801d2b79f8e5eb62065d2fa8f6 (patch) | |
tree | 49070a5e681715e5d780814e185de78f51432828 /platform | |
parent | bc416c6557acadd1760c492c5922b534382a809d (diff) |
linux-gen: pktio: implement odp_pktout_ts_read() function
Add common pktio level implementation for odp_pktout_ts_read(). Internal
helper functions _odp_pktio_tx_ts_enabled() and _odp_pktio_tx_ts_set() were
added for the pktio devices to use.
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/include/odp_packet_io_internal.h | 18 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_io.c | 28 |
2 files changed, 45 insertions, 1 deletions
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 8475042e9..4700bdb07 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -1,5 +1,5 @@ /* Copyright (c) 2013-2018, Linaro Limited - * Copyright (c) 2019, Nokia + * Copyright (c) 2019-2020, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -74,6 +74,8 @@ struct pktio_entry { uint8_t chksum_insert : 1; /* Classifier */ uint8_t cls : 1; + /* Tx timestamp */ + uint8_t tx_ts : 1; } enabled; odp_pktio_t handle; /**< pktio handle */ unsigned char ODP_ALIGNED_CACHE pkt_priv[PKTIO_PRIVATE_SIZE]; @@ -103,6 +105,8 @@ struct pktio_entry { struct { odp_atomic_u64_t in_discards; } stats_extra; + /* Latest Tx timestamp */ + odp_atomic_u64_t tx_ts; odp_proto_chksums_t in_chksums; /**< Checksums validation settings */ pktio_stats_type_t stats_type; char name[PKTIO_NAME_LEN]; /**< name of pktio provided to @@ -231,6 +235,18 @@ static inline void pktio_cls_enabled_set(pktio_entry_t *entry, int ena) entry->s.enabled.cls = !!ena; } +static inline int _odp_pktio_tx_ts_enabled(pktio_entry_t *entry) +{ + return entry->s.enabled.tx_ts; +} + +static inline void _odp_pktio_tx_ts_set(pktio_entry_t *entry) +{ + odp_time_t ts_val = odp_time_global(); + + odp_atomic_store_u64(&entry->s.tx_ts, ts_val.u64); +} + extern const pktio_if_ops_t netmap_pktio_ops; extern const pktio_if_ops_t dpdk_pktio_ops; extern const pktio_if_ops_t sock_mmsg_pktio_ops; diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 7ff567ddb..1f23bce32 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -315,6 +315,10 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, pktio_entry->s.pktin_frame_offset = pktin_frame_offset; odp_atomic_init_u64(&pktio_entry->s.stats_extra.in_discards, 0); + /* Tx timestamping is disabled by default */ + pktio_entry->s.enabled.tx_ts = 0; + odp_atomic_init_u64(&pktio_entry->s.tx_ts, 0); + odp_pktio_config_init(&pktio_entry->s.config); for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { @@ -567,6 +571,8 @@ int odp_pktio_config(odp_pktio_t hdl, const odp_pktio_config_t *config) entry->s.in_chksums.chksum.udp = config->pktin.bit.udp_chksum; entry->s.in_chksums.chksum.sctp = config->pktin.bit.sctp_chksum; + entry->s.enabled.tx_ts = config->pktout.bit.ts_ena; + if (entry->s.ops->config) res = entry->s.ops->config(entry, config); @@ -2150,3 +2156,25 @@ uint64_t odp_pktio_to_u64(odp_pktio_t hdl) { return _odp_pri(hdl); } + +int odp_pktout_ts_read(odp_pktio_t hdl, odp_time_t *ts) +{ + pktio_entry_t *entry; + uint64_t ts_val; + + entry = get_pktio_entry(hdl); + if (odp_unlikely(entry == NULL)) { + ODP_ERR("pktio entry %d does not exist\n", hdl); + return -1; + } + + if (odp_atomic_load_u64(&entry->s.tx_ts) == 0) + return 1; + + ts_val = odp_atomic_xchg_u64(&entry->s.tx_ts, 0); + if (odp_unlikely(ts_val == 0)) + return 1; + + ts->u64 = ts_val; + return 0; +} |