From: Petri Savolainen <petri.savolai...@linaro.org> Use only one function (packet_hdr) in handle to header pointer conversion. odp_packet_hdr is bad name for an implementation internal function as API function prefix is odp_packet_.
Signed-off-by: Petri Savolainen <petri.savolai...@linaro.org> --- /** Email created from pull request 437 (psavol:master-packet-optim) ** https://github.com/Linaro/odp/pull/437 ** Patch: https://github.com/Linaro/odp/pull/437.patch ** Base sha: b95ccd3db6eeb7358a877541747e06354429acdd ** Merge commit sha: 3c2134ecc18e4fd52cd526b5c067815ca73864cc **/ .../include/odp/api/plat/packet_inlines.h | 5 ----- .../linux-generic/include/odp_packet_internal.h | 8 ++++---- platform/linux-generic/odp_crypto.c | 4 ++-- platform/linux-generic/odp_ipsec.c | 8 ++++---- platform/linux-generic/odp_packet.c | 10 +++++----- platform/linux-generic/odp_packet_flags.c | 22 +++++++++++----------- platform/linux-generic/odp_packet_io.c | 4 ++-- platform/linux-generic/pktio/dpdk.c | 12 ++++++------ platform/linux-generic/pktio/ipc.c | 14 +++++++------- platform/linux-generic/pktio/loop.c | 2 +- platform/linux-generic/pktio/netmap.c | 2 +- platform/linux-generic/pktio/pcap.c | 2 +- platform/linux-generic/pktio/socket.c | 2 +- platform/linux-generic/pktio/socket_mmap.c | 2 +- platform/linux-generic/pktio/tap.c | 2 +- 15 files changed, 47 insertions(+), 52 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index 90e205fd4..dee8f71ce 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -228,11 +228,6 @@ static inline void _odp_packet_prefetch(odp_packet_t pkt, uint32_t offset, (void)pkt; (void)offset; (void)len; } -static inline odp_buffer_t packet_to_buffer(odp_packet_t pkt) -{ - return (odp_buffer_t)pkt; -} - static inline int _odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, uint32_t len, const void *src) { diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 32e41d7f5..89009a021 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -169,7 +169,7 @@ typedef struct { /** * Return the packet header */ -static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt) +static inline odp_packet_hdr_t *packet_hdr(odp_packet_t pkt) { return (odp_packet_hdr_t *)(uintptr_t)pkt; } @@ -181,7 +181,7 @@ static inline odp_packet_t packet_handle(odp_packet_hdr_t *pkt_hdr) static inline odp_buffer_hdr_t *packet_to_buf_hdr(odp_packet_t pkt) { - return &odp_packet_hdr(pkt)->buf_hdr; + return &packet_hdr(pkt)->buf_hdr; } static inline odp_packet_t packet_from_buf_hdr(odp_buffer_hdr_t *buf_hdr) @@ -201,12 +201,12 @@ static inline seg_entry_t *seg_entry_last(odp_packet_hdr_t *hdr) static inline odp_event_subtype_t packet_subtype(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->subtype; + return packet_hdr(pkt)->subtype; } static inline void packet_subtype_set(odp_packet_t pkt, int ev) { - odp_packet_hdr(pkt)->subtype = ev; + packet_hdr(pkt)->subtype = ev; } /** diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 8ae484fd8..325a9d066 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -1434,7 +1434,7 @@ odp_event_t odp_crypto_packet_to_event(odp_packet_t pkt) static odp_crypto_packet_result_t *get_op_result_from_packet(odp_packet_t pkt) { - odp_packet_hdr_t *hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *hdr = packet_hdr(pkt); return &hdr->crypto_op_result; } @@ -1520,7 +1520,7 @@ int odp_crypto_int(odp_packet_t pkt_in, (rc_cipher == ODP_CRYPTO_ALG_ERR_NONE) && (rc_auth == ODP_CRYPTO_ALG_ERR_NONE); - pkt_hdr = odp_packet_hdr(out_pkt); + pkt_hdr = packet_hdr(out_pkt); pkt_hdr->p.error_flags.crypto_err = !op_result->ok; /* Synchronous, simply return results */ diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c index 521627f1d..586653d4e 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -158,7 +158,7 @@ static odp_ipsec_packet_result_t *ipsec_pkt_result(odp_packet_t packet) ODP_ASSERT(ODP_EVENT_PACKET_IPSEC == odp_event_subtype(odp_packet_to_event(packet))); - return &odp_packet_hdr(packet)->ipsec_ctx; + return &packet_hdr(packet)->ipsec_ctx; } static inline int _odp_ipv4_csum(odp_packet_t pkt, @@ -829,7 +829,7 @@ static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt, return ipsec_sa; err: - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pkt_hdr->p.error_flags.ipsec_err = 1; *pkt_out = pkt; @@ -1404,7 +1404,7 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, return ipsec_sa; err: - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pkt_hdr->p.error_flags.ipsec_err = 1; @@ -1652,7 +1652,7 @@ int _odp_ipsec_try_inline(odp_packet_t pkt) result->sa = ipsec_sa->ipsec_sa_hdl; result->flag.inline_mode = 1; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pkt_hdr->p.input_flags.dst_queue = 1; pkt_hdr->dst_queue = queue_fn->from_ext(ipsec_sa->queue); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 2867e67e9..043e4cb5c 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -49,11 +49,6 @@ const _odp_packet_inline_offset_t ODP_ALIGNED_CACHE _odp_packet_inline = { #include <odp/visibility_end.h> -static inline odp_packet_hdr_t *packet_hdr(odp_packet_t pkt) -{ - return (odp_packet_hdr_t *)(uintptr_t)pkt; -} - static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) { return (odp_buffer_t)pkt_hdr; @@ -69,6 +64,11 @@ odp_packet_t _odp_packet_from_buf_hdr(odp_buffer_hdr_t *buf_hdr) return (odp_packet_t)buf_hdr; } +static inline odp_buffer_t packet_to_buffer(odp_packet_t pkt) +{ + return (odp_buffer_t)pkt; +} + static inline seg_entry_t *seg_entry(odp_packet_hdr_t *hdr, uint32_t seg_idx) { diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c index 96507c664..2909703f3 100644 --- a/platform/linux-generic/odp_packet_flags.c +++ b/platform/linux-generic/odp_packet_flags.c @@ -11,18 +11,18 @@ #include <odp_packet_internal.h> #define retflag(pkt, x) do { \ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); \ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); \ return pkt_hdr->p.x; \ } while (0) #define setflag(pkt, x, v) do { \ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); \ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); \ pkt_hdr->p.x = (v) & 1; \ } while (0) int odp_packet_has_error(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->p.error_flags.all != 0; } @@ -31,7 +31,7 @@ int odp_packet_has_error(odp_packet_t pkt) int odp_packet_has_l2_error(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); /* L2 parsing is always done by default and hence no additional check is required */ return pkt_hdr->p.error_flags.frame_len @@ -46,7 +46,7 @@ int odp_packet_has_l3(odp_packet_t pkt) int odp_packet_has_l3_error(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->p.error_flags.ip_err; } @@ -58,7 +58,7 @@ int odp_packet_has_l4(odp_packet_t pkt) int odp_packet_has_l4_error(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->p.error_flags.tcp_err | pkt_hdr->p.error_flags.udp_err; } @@ -150,14 +150,14 @@ odp_packet_color_t odp_packet_color(odp_packet_t pkt) void odp_packet_color_set(odp_packet_t pkt, odp_packet_color_t color) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->p.input_flags.color = color; } odp_bool_t odp_packet_drop_eligible(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return !pkt_hdr->p.input_flags.nodrop; } @@ -174,7 +174,7 @@ int8_t odp_packet_shaper_len_adjust(odp_packet_t pkt) void odp_packet_shaper_len_adjust_set(odp_packet_t pkt, int8_t adj) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->p.output_flags.shaper_len_adj = adj; } @@ -288,14 +288,14 @@ void odp_packet_has_icmp_set(odp_packet_t pkt, int val) void odp_packet_has_flow_hash_clr(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->p.input_flags.flow_hash = 0; } void odp_packet_has_ts_clr(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->p.input_flags.timestamp = 0; } diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index b8dd7c90d..460891d06 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -570,7 +570,7 @@ static inline int pktin_recv_buf(odp_pktin_queue_t queue, for (i = 0; i < pkts; i++) { pkt = packets[i]; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); buf_hdr = packet_to_buf_hdr(pkt); if (pkt_hdr->p.input_flags.dst_queue) { @@ -698,7 +698,7 @@ int sched_cb_pktin_poll_one(int pktio_index, num_rx = 0; for (i = 0; i < num_pkts; i++) { pkt = packets[i]; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (odp_unlikely(pkt_hdr->p.input_flags.dst_queue)) { queue = pkt_hdr->dst_queue; buf_hdr = packet_to_buf_hdr(pkt); diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 86d7a4513..bd6920e6a 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -262,7 +262,7 @@ static int pool_dequeue_bulk(struct rte_mempool *mp, void **obj_table, for (i = 0; i < pkts; i++) { odp_packet_t pkt = packet_tbl[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); struct rte_mbuf *mbuf = (struct rte_mbuf *) (uintptr_t)pkt_hdr->extra; if (pkt_hdr->extra_type != PKT_EXTRA_TYPE_DPDK) @@ -468,7 +468,7 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, } pkt = pkt_table[i]; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pull_tail(pkt_hdr, alloc_len - pkt_len); if (_odp_packet_copy_from_mem(pkt, 0, pkt_len, data) != 0) @@ -636,7 +636,7 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, return 0; } for (i = 0; i < num; i++) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt_table[i]); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt_table[i]); pkt_len = packet_len(pkt_hdr); @@ -697,7 +697,7 @@ static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry, pkt_len = rte_pktmbuf_pkt_len(mbuf); pkt = (odp_packet_t)mbuf->userdata; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, @@ -754,7 +754,7 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, for (i = 0; i < num; i++) { odp_packet_t pkt = pkt_table[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); struct rte_mbuf *mbuf = (struct rte_mbuf *) (uintptr_t)pkt_hdr->extra; uint16_t pkt_len = odp_packet_len(pkt); @@ -1606,7 +1606,7 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int index, for (i = 0; i < mbufs && freed != copy_count; i++) { odp_packet_t pkt = pkt_table[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (pkt_hdr->buf_hdr.segcount > 1) { if (odp_likely(i < tx_pkts)) diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index b6c493ea0..95b526646 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -507,14 +507,14 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, memcpy(pkt_data, rmt_data_ptr, phdr->frame_len); /* Copy packets L2, L3 parsed offsets and size */ - copy_packet_cls_metadata(phdr, odp_packet_hdr(pkt)); + copy_packet_cls_metadata(phdr, packet_hdr(pkt)); - odp_packet_hdr(pkt)->frame_len = phdr->frame_len; - odp_packet_hdr(pkt)->headroom = phdr->headroom; - odp_packet_hdr(pkt)->tailroom = phdr->tailroom; + packet_hdr(pkt)->frame_len = phdr->frame_len; + packet_hdr(pkt)->headroom = phdr->headroom; + packet_hdr(pkt)->tailroom = phdr->tailroom; /* Take classification fields */ - odp_packet_hdr(pkt)->p = phdr->p; + packet_hdr(pkt)->p = phdr->p; pkt_table[i] = pkt; } @@ -604,7 +604,7 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, odp_packet_hdr_t *pkt_hdr; pool_t *pool; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pool = pkt_hdr->buf_hdr.pool_ptr; if (pool->pool_idx != ipc_pool->pool_idx || @@ -626,7 +626,7 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, for (i = 0; i < num; i++) { uint64_t data_pool_off; odp_packet_t pkt = pkt_table_mapped[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); odp_pool_t pool_hdl = odp_packet_pool(pkt); pool_t *pool = pool_entry_from_hdl(pool_hdl); diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index aecb0263a..0cf45acbd 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -101,7 +101,7 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, pkt = packet_from_buf_hdr(hdr_tbl[i]); pkt_len = odp_packet_len(pkt); - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); packet_parse_reset(pkt_hdr); if (pktio_cls_enabled(pktio_entry)) { diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index c03564f4e..66fe247d3 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -647,7 +647,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, } pkt = pkt_tbl[i]; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); pull_tail(pkt_hdr, alloc_len - len); /* For now copy the data in the mbuf, diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 76cbf9eef..889903ddd 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -248,7 +248,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, if (ts != NULL) ts_val = odp_time_global(); - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (_odp_packet_copy_from_mem(pkt, 0, hdr->caplen, data) != 0) { ODP_ERR("failed to copy packet data\n"); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 71980b540..749377c09 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -639,7 +639,7 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, void *base = msgvec[i].msg_hdr.msg_iov->iov_base; struct ethhdr *eth_hdr = base; odp_packet_t pkt = pkt_table[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint16_t pkt_len = msgvec[i].msg_len; int ret; diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 2ace1a597..852bc7669 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -243,7 +243,7 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, frame_num = next_frame_num; continue; } - hdr = odp_packet_hdr(pkt_table[nb_rx]); + hdr = packet_hdr(pkt_table[nb_rx]); ret = _odp_packet_copy_from_mem(pkt_table[nb_rx], 0, pkt_len, pkt_buf); if (ret != 0) { diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index ccfa19b25..56f90b31b 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -280,7 +280,7 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, return ODP_PACKET_INVALID; } - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr);