This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, api-next has been updated via 44ae9773bc94f8cd349034901f08a2eed46dc822 (commit) via 82e5497c801ee3be6f49371c065b4eb43628048c (commit) via 3f5d8c5b1f50efe8bf017b8a0014af668c664c43 (commit) via f72f999552de02c602864baa82bb374322415b24 (commit) via 56ee80a8482f1161a84b3e5145fab2e0f7653ccb (commit) via 431a0783ebea4fc09e781f431599cacd3a3e4e0e (commit) via 483cc787d1bec821a2008e32ef4dd611e365ffe4 (commit) via de21a1cc01d03c39fd0772dff96fb69b06613f58 (commit) via 3d6cbd2e2881c1e18922b26c7fd4a2ec9464becd (commit) via 52f32ce1fa6b5416c59ead45ff27d731d98b8f87 (commit) from abc36ae6747eb7729ea10ab4fa806939abca8c3e (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 44ae9773bc94f8cd349034901f08a2eed46dc822 Author: Petri Savolainen petri.savolainen@linaro.org Date: Mon Feb 13 14:53:30 2017 +0200
linux-gen: packet: implement references as copy
Implement packet references API as packet copy. This is the simplest way to support the API, as other packet functions are not affected at all.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 024f694..1d2b506 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2221,3 +2221,81 @@ uint64_t odp_packet_seg_to_u64(odp_packet_seg_t hdl) { return _odp_pri(hdl); } + +odp_packet_t odp_packet_ref_static(odp_packet_t pkt) +{ + odp_packet_t new; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + return new; +} + +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) +{ + odp_packet_t new; + int ret; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + if (new == ODP_PACKET_INVALID) { + ODP_ERR("copy failed\n"); + return ODP_PACKET_INVALID; + } + + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); + + if (ret < 0) { + ODP_ERR("trunk_head failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + + return new; +} + +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, + odp_packet_t hdr) +{ + odp_packet_t new; + int ret; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + if (new == ODP_PACKET_INVALID) { + ODP_ERR("copy failed\n"); + return ODP_PACKET_INVALID; + } + + if (offset) { + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); + + if (ret < 0) { + ODP_ERR("trunk_head failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + } + + ret = odp_packet_concat(&hdr, new); + + if (ret < 0) { + ODP_ERR("concat failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + + return hdr; +} + +int odp_packet_has_ref(odp_packet_t pkt) +{ + (void)pkt; + + return 0; +} + +uint32_t odp_packet_unshared_len(odp_packet_t pkt) +{ + return odp_packet_len(pkt); +}
commit 82e5497c801ee3be6f49371c065b4eb43628048c Author: Petri Savolainen petri.savolainen@linaro.org Date: Mon Feb 13 14:53:29 2017 +0200
Revert "linux-generic: packet: implement reference apis"
This reverts commit 22b3986fea090986625f3255d57b64de35bbc475. Plan to merge first version with packet copy. Than this patch will be applied again.
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 42df5ac..e3ada5c 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -19,7 +19,6 @@ extern "C" {
#include <odp/api/align.h> #include <odp/api/debug.h> -#include <odp_debug_internal.h> #include <odp_buffer_internal.h> #include <odp_pool_internal.h> #include <odp_buffer_inlines.h> @@ -169,7 +168,7 @@ typedef struct { * packet_init(). Because of this any new fields added must be reviewed for * initialization requirements. */ -typedef struct odp_packet_hdr_t { +typedef struct { /* common buffer header */ odp_buffer_hdr_t buf_hdr;
@@ -185,13 +184,6 @@ typedef struct odp_packet_hdr_t { uint32_t headroom; uint32_t tailroom;
- /* Fields used to support packet references */ - uint32_t unshared_len; - struct odp_packet_hdr_t *ref_hdr; - uint32_t ref_offset; - uint32_t ref_len; - odp_atomic_u32_t ref_count; - /* * Members below are not initialized by packet_init() */ @@ -220,55 +212,6 @@ static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt) return (odp_packet_hdr_t *)buf_hdl_to_hdr((odp_buffer_t)pkt); }
-static inline odp_packet_hdr_t *odp_packet_last_hdr(odp_packet_t pkt, - uint32_t *offset) -{ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - odp_packet_hdr_t *prev_hdr = pkt_hdr; - uint32_t ref_offset = 0; - - while (pkt_hdr->ref_hdr) { - ref_offset = pkt_hdr->ref_offset; - prev_hdr = pkt_hdr; - pkt_hdr = pkt_hdr->ref_hdr; - } - - if (offset) { - if (prev_hdr != pkt_hdr) - ref_offset += pkt_hdr->frame_len - prev_hdr->ref_len; - *offset = ref_offset; - } - - return pkt_hdr; -} - -static inline odp_packet_hdr_t *odp_packet_prev_hdr(odp_packet_hdr_t *pkt_hdr, - odp_packet_hdr_t *cur_hdr, - uint32_t *offset) -{ - uint32_t ref_offset = 0; - odp_packet_hdr_t *prev_hdr = pkt_hdr; - - while (pkt_hdr->ref_hdr != cur_hdr) { - ref_offset = pkt_hdr->ref_offset; - prev_hdr = pkt_hdr; - pkt_hdr = pkt_hdr->ref_hdr; - } - - if (offset) { - if (prev_hdr != pkt_hdr) - ref_offset += pkt_hdr->frame_len - prev_hdr->ref_len; - *offset = ref_offset; - } - - return pkt_hdr; -} - -static inline odp_packet_t _odp_packet_hdl(odp_packet_hdr_t *pkt_hdr) -{ - return (odp_packet_t)odp_hdr_to_buf(&pkt_hdr->buf_hdr); -} - static inline void copy_packet_parser_metadata(odp_packet_hdr_t *src_hdr, odp_packet_hdr_t *dst_hdr) { @@ -291,41 +234,17 @@ static inline void pull_tail(odp_packet_hdr_t *pkt_hdr, uint32_t len)
pkt_hdr->tailroom += len; pkt_hdr->frame_len -= len; - pkt_hdr->unshared_len -= len; pkt_hdr->buf_hdr.seg[last].len -= len; }
static inline uint32_t packet_len(odp_packet_hdr_t *pkt_hdr) { - uint32_t pkt_len = 0; - uint32_t offset = 0; - - do { - pkt_len += pkt_hdr->frame_len - offset; - offset = pkt_hdr->ref_offset; - if (pkt_hdr->ref_hdr) - offset += (pkt_hdr->ref_hdr->frame_len - - pkt_hdr->ref_len); - pkt_hdr = pkt_hdr->ref_hdr; - } while (pkt_hdr); - - return pkt_len; -} - -static inline uint32_t packet_ref_count(odp_packet_hdr_t *pkt_hdr) -{ - return odp_atomic_load_u32(&pkt_hdr->ref_count); -} - -static inline void packet_ref_count_set(odp_packet_hdr_t *pkt_hdr, uint32_t n) -{ - odp_atomic_init_u32(&pkt_hdr->ref_count, n); + return pkt_hdr->frame_len; }
static inline void packet_set_len(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->frame_len = len; - pkt_hdr->unshared_len = len; }
static inline int packet_parse_l2_not_done(packet_parser_t *prs) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 3aadc4d..024f694 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -33,24 +33,13 @@ static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->buf_hdr.handle.handle; }
-static inline uint32_t packet_ref_inc(odp_packet_hdr_t *pkt_hdr) -{ - return odp_atomic_fetch_inc_u32(&pkt_hdr->ref_count); -} - -static inline uint32_t packet_ref_dec(odp_packet_hdr_t *pkt_hdr) -{ - return odp_atomic_fetch_dec_u32(&pkt_hdr->ref_count); -} - static inline uint32_t packet_seg_len(odp_packet_hdr_t *pkt_hdr, uint32_t seg_idx) { return pkt_hdr->buf_hdr.seg[seg_idx].len; }
-static inline uint8_t *packet_seg_data(odp_packet_hdr_t *pkt_hdr, - uint32_t seg_idx) +static inline void *packet_seg_data(odp_packet_hdr_t *pkt_hdr, uint32_t seg_idx) { return pkt_hdr->buf_hdr.seg[seg_idx].data; } @@ -63,11 +52,6 @@ static inline int packet_last_seg(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->buf_hdr.segcount - 1; }
-static inline void *packet_data(odp_packet_hdr_t *pkt_hdr) -{ - return pkt_hdr->buf_hdr.seg[0].data; -} - static inline uint32_t packet_first_seg_len(odp_packet_hdr_t *pkt_hdr) { return packet_seg_len(pkt_hdr, 0); @@ -80,6 +64,11 @@ static inline uint32_t packet_last_seg_len(odp_packet_hdr_t *pkt_hdr) return packet_seg_len(pkt_hdr, last); }
+static inline void *packet_data(odp_packet_hdr_t *pkt_hdr) +{ + return pkt_hdr->buf_hdr.seg[0].data; +} + static inline void *packet_tail(odp_packet_hdr_t *pkt_hdr) { int last = packet_last_seg(pkt_hdr); @@ -110,7 +99,6 @@ static inline void push_head(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->headroom -= len; pkt_hdr->frame_len += len; - pkt_hdr->unshared_len += len; pkt_hdr->buf_hdr.seg[0].data -= len; pkt_hdr->buf_hdr.seg[0].len += len; } @@ -119,7 +107,6 @@ static inline void pull_head(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->headroom += len; pkt_hdr->frame_len -= len; - pkt_hdr->unshared_len -= len; pkt_hdr->buf_hdr.seg[0].data += len; pkt_hdr->buf_hdr.seg[0].len -= len; } @@ -130,7 +117,6 @@ static inline void push_tail(odp_packet_hdr_t *pkt_hdr, uint32_t len)
pkt_hdr->tailroom -= len; pkt_hdr->frame_len += len; - pkt_hdr->unshared_len += len; pkt_hdr->buf_hdr.seg[last].len += len; }
@@ -158,10 +144,6 @@ static inline void packet_seg_copy_md(odp_packet_hdr_t *dst, dst->buf_hdr.uarea_addr = src->buf_hdr.uarea_addr; dst->buf_hdr.uarea_size = src->buf_hdr.uarea_size;
- /* reference related metadata */ - dst->ref_len = src->ref_len; - dst->unshared_len = src->unshared_len; - /* segmentation data is not copied: * buf_hdr.seg[] * buf_hdr.segcount @@ -176,15 +158,7 @@ static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, int seg = 0; int seg_count = pkt_hdr->buf_hdr.segcount;
- /* Special processing for references */ - while (offset >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { - offset -= (pkt_hdr->frame_len - pkt_hdr->ref_offset); - offset += (pkt_hdr->ref_hdr->frame_len - pkt_hdr->ref_len); - pkt_hdr = pkt_hdr->ref_hdr; - seg_count = pkt_hdr->buf_hdr.segcount; - } - - if (odp_unlikely(offset > pkt_hdr->frame_len)) + if (odp_unlikely(offset >= pkt_hdr->frame_len)) return NULL;
if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || seg_count == 1)) { @@ -233,9 +207,6 @@ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) pkt_hdr->p.l2_offset = 0; pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID; pkt_hdr->p.l4_offset = ODP_PACKET_OFFSET_INVALID; - - /* Ensure dummy pkt_hdrs used in I/O recv classification are valid */ - pkt_hdr->ref_hdr = NULL; }
/** @@ -281,10 +252,6 @@ static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len, CONFIG_PACKET_TAILROOM;
pkt_hdr->input = ODP_PKTIO_INVALID; - - /* By default packet has no references */ - pkt_hdr->unshared_len = len; - pkt_hdr->ref_hdr = NULL; }
static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) @@ -297,7 +264,6 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num)
hdr->buf_hdr.seg[0].data = hdr->buf_hdr.base_data; hdr->buf_hdr.seg[0].len = BASE_LEN; - packet_ref_count_set(hdr, 1);
/* Link segments */ if (CONFIG_PACKET_MAX_SEGS != 1) { @@ -307,7 +273,6 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) for (i = 1; i < num; i++) { odp_buffer_hdr_t *buf_hdr;
- packet_ref_count_set(pkt_hdr[i], 1); buf_hdr = &pkt_hdr[i]->buf_hdr; hdr->buf_hdr.seg[i].hdr = buf_hdr; hdr->buf_hdr.seg[i].data = buf_hdr->base_data; @@ -411,10 +376,9 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr, new_hdr->buf_hdr.seg[0].len = seg_len;
packet_seg_copy_md(new_hdr, pkt_hdr); - new_hdr->frame_len = pkt_hdr->frame_len + len; - new_hdr->unshared_len = pkt_hdr->unshared_len + len; - new_hdr->headroom = pool->headroom + offset; - new_hdr->tailroom = pkt_hdr->tailroom; + new_hdr->frame_len = pkt_hdr->frame_len + len; + new_hdr->headroom = pool->headroom + offset; + new_hdr->tailroom = pkt_hdr->tailroom;
pkt_hdr = new_hdr; } else { @@ -427,9 +391,8 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr, last = packet_last_seg(pkt_hdr); pkt_hdr->buf_hdr.seg[last].len = seg_len;
- pkt_hdr->frame_len += len; - pkt_hdr->unshared_len += len; - pkt_hdr->tailroom = pool->tailroom + offset; + pkt_hdr->frame_len += len; + pkt_hdr->tailroom = pool->tailroom + offset; }
return pkt_hdr; @@ -437,18 +400,13 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr,
static inline void free_bufs(odp_packet_hdr_t *pkt_hdr, int first, int num) { - int i, nfree; + int i; odp_buffer_t buf[num];
- for (i = 0, nfree = 0; i < num; i++) { - odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[first + i].hdr; - - if (packet_ref_dec(hdr) == 1) - buf[nfree++] = buffer_handle(hdr); - } + for (i = 0; i < num; i++) + buf[i] = buffer_handle(pkt_hdr->buf_hdr.seg[first + i].hdr);
- if (nfree > 0) - buffer_free_multi(buf, nfree); + buffer_free_multi(buf, num); }
static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, @@ -459,15 +417,11 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
if (head) { odp_packet_hdr_t *new_hdr; - int i, nfree; + int i; odp_buffer_t buf[num];
- for (i = 0, nfree = 0; i < num; i++) { - new_hdr = pkt_hdr->buf_hdr.seg[i].hdr; - - if (packet_ref_dec(new_hdr) == 1) - buf[nfree++] = buffer_handle(new_hdr); - } + for (i = 0; i < num; i++) + buf[i] = buffer_handle(pkt_hdr->buf_hdr.seg[i].hdr);
/* First remaining segment is the new packet descriptor */ new_hdr = pkt_hdr->buf_hdr.seg[num].hdr; @@ -476,17 +430,15 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, packet_seg_copy_md(new_hdr, pkt_hdr);
/* Tailroom not changed */ - new_hdr->tailroom = pkt_hdr->tailroom; - new_hdr->headroom = seg_headroom(new_hdr, 0); - new_hdr->frame_len = pkt_hdr->frame_len - free_len; - new_hdr->unshared_len = pkt_hdr->unshared_len - free_len; + new_hdr->tailroom = pkt_hdr->tailroom; + new_hdr->headroom = seg_headroom(new_hdr, 0); + new_hdr->frame_len = pkt_hdr->frame_len - free_len;
pull_head(new_hdr, pull_len);
pkt_hdr = new_hdr;
- if (nfree > 0) - buffer_free_multi(buf, nfree); + buffer_free_multi(buf, num); } else { /* Free last 'num' bufs */ free_bufs(pkt_hdr, num_remain, num); @@ -495,7 +447,6 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, * of the metadata. */ pkt_hdr->buf_hdr.segcount = num_remain; pkt_hdr->frame_len -= free_len; - pkt_hdr->unshared_len -= free_len; pkt_hdr->tailroom = seg_tailroom(pkt_hdr, num_remain - 1);
pull_tail(pkt_hdr, pull_len); @@ -599,34 +550,45 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, return num; }
-static inline void packet_free(odp_packet_hdr_t *pkt_hdr) -{ - odp_packet_hdr_t *ref_hdr; - uint32_t ref_count; - - do { - ref_hdr = pkt_hdr->ref_hdr; - ref_count = packet_ref_count(pkt_hdr) - 1; - free_bufs(pkt_hdr, 0, pkt_hdr->buf_hdr.segcount); - - if (ref_count == 1) - pkt_hdr->unshared_len = pkt_hdr->frame_len; - - pkt_hdr = ref_hdr; - } while (pkt_hdr); -} - void odp_packet_free(odp_packet_t pkt) { - packet_free(odp_packet_hdr(pkt)); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + int num_seg = pkt_hdr->buf_hdr.segcount; + + if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1)) + buffer_free_multi((odp_buffer_t *)&pkt, 1); + else + free_bufs(pkt_hdr, 0, num_seg); }
void odp_packet_free_multi(const odp_packet_t pkt[], int num) { - int i; + if (CONFIG_PACKET_MAX_SEGS == 1) { + buffer_free_multi((const odp_buffer_t * const)pkt, num); + } else { + odp_buffer_t buf[num * CONFIG_PACKET_MAX_SEGS]; + int i, j; + int bufs = 0;
- for (i = 0; i < num; i++) - packet_free(odp_packet_hdr(pkt[i])); + for (i = 0; i < num; i++) { + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt[i]); + int num_seg = pkt_hdr->buf_hdr.segcount; + odp_buffer_hdr_t *buf_hdr = &pkt_hdr->buf_hdr; + + buf[bufs] = (odp_buffer_t)pkt[i]; + bufs++; + + if (odp_likely(num_seg == 1)) + continue; + + for (j = 1; j < num_seg; j++) { + buf[bufs] = buffer_handle(buf_hdr->seg[j].hdr); + bufs++; + } + } + + buffer_free_multi(buf, bufs); + } }
int odp_packet_reset(odp_packet_t pkt, uint32_t len) @@ -637,9 +599,6 @@ int odp_packet_reset(odp_packet_t pkt, uint32_t len) if (len > pool->headroom + pool->data_size + pool->tailroom) return -1;
- if (pkt_hdr->ref_hdr) - packet_free(pkt_hdr->ref_hdr); - packet_init(pkt_hdr, len, 0);
return 0; @@ -682,21 +641,15 @@ void *odp_packet_head(odp_packet_t pkt) uint32_t odp_packet_buf_len(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t buf_len = 0;
- do { - buf_len += pkt_hdr->buf_hdr.size * pkt_hdr->buf_hdr.segcount; - pkt_hdr = pkt_hdr->ref_hdr; - } while (pkt_hdr); - - return buf_len; + return pkt_hdr->buf_hdr.size * pkt_hdr->buf_hdr.segcount; }
void *odp_packet_data(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- return packet_map(pkt_hdr, 0, NULL, NULL); + return packet_data(pkt_hdr); }
uint32_t odp_packet_seg_len(odp_packet_t pkt) @@ -708,32 +661,7 @@ uint32_t odp_packet_seg_len(odp_packet_t pkt)
uint32_t odp_packet_len(odp_packet_t pkt) { - return packet_len(odp_packet_hdr(pkt)); -} - -uint32_t odp_packet_unshared_len(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t pkt_len = 0, offset = 0; - - do { - if (packet_ref_count(pkt_hdr) > 1) { - if (offset == 0) - pkt_len += pkt_hdr->unshared_len; - break; - } - - pkt_len += pkt_hdr->frame_len - offset; - offset = pkt_hdr->ref_offset; - - if (pkt_hdr->ref_hdr) - offset += (pkt_hdr->ref_hdr->frame_len - - pkt_hdr->ref_len); - - pkt_hdr = pkt_hdr->ref_hdr; - } while (pkt_hdr); - - return pkt_len; + return odp_packet_hdr(pkt)->frame_len; }
uint32_t odp_packet_headroom(odp_packet_t pkt) @@ -743,12 +671,12 @@ uint32_t odp_packet_headroom(odp_packet_t pkt)
uint32_t odp_packet_tailroom(odp_packet_t pkt) { - return odp_packet_last_hdr(pkt, NULL)->tailroom; + return odp_packet_hdr(pkt)->tailroom; }
void *odp_packet_tail(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(pkt, NULL); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
return packet_tail(pkt_hdr); } @@ -942,7 +870,7 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt); uint32_t frame_len = pkt_hdr->frame_len; - uint32_t headroom = pkt_hdr->headroom; + uint32_t headroom = pkt_hdr->headroom; int ret = 0;
if (len > headroom) { @@ -957,46 +885,6 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, segs = pkt_hdr->buf_hdr.segcount;
if (odp_unlikely((segs + num) > CONFIG_PACKET_MAX_SEGS)) { - /* Handle recursively via references when - * working with referenced packets since another - * thread may be accessing it concurrently via - * its reference to it. */ - if (packet_ref_count(pkt_hdr) > 1) { - odp_packet_t ref; - uint32_t unshared_len; - - push_head(pkt_hdr, headroom); - unshared_len = pkt_hdr->unshared_len; - ref = odp_packet_ref(*pkt, 0); - - if (ref == ODP_PACKET_INVALID) { - pull_head(pkt_hdr, headroom); - return -1; - } - - ret = odp_packet_extend_head(&ref, - len - headroom, - data_ptr, - seg_len); - - if (ret < 0) { - odp_packet_free(ref); - pull_head(pkt_hdr, headroom); - return -1; - } - - /* Since this is a special ref, the - * base pkt's unshared len is unchanged */ - pkt_hdr->unshared_len = unshared_len; - - /* Remove extra ref to the base pkt */ - odp_packet_free(*pkt); - - /* Return the ref as the extension result */ - *pkt = ref; - return 1; - } - /* Cannot directly add new segments */ odp_packet_hdr_t *new_hdr; int new_segs = 0; @@ -1048,7 +936,6 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len,
pkt_hdr->buf_hdr.segcount = segs; pkt_hdr->frame_len = frame_len; - pkt_hdr->unshared_len = frame_len; pkt_hdr->headroom = offset + pool->headroom; pkt_hdr->tailroom = pool->tailroom;
@@ -1074,16 +961,11 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, push_head(pkt_hdr, len); }
- if (data_ptr || seg_len) { - uint32_t seg_ln = 0; - void *data = packet_map(pkt_hdr, 0, &seg_ln, NULL); - - if (data_ptr) - *data_ptr = data; + if (data_ptr) + *data_ptr = packet_data(pkt_hdr);
- if (seg_len) - *seg_len = seg_ln; - } + if (seg_len) + *seg_len = packet_first_seg_len(pkt_hdr);
return ret; } @@ -1095,8 +977,6 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) if (len > pkt_hdr->frame_len) return NULL;
- ODP_ASSERT(len <= pkt_hdr->unshared_len); - pull_head(pkt_hdr, len); return packet_data(pkt_hdr); } @@ -1104,35 +984,15 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt), *nxt_hdr; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt); uint32_t seg_len = packet_first_seg_len(pkt_hdr); - int ret = 0;
- if (len > packet_len(pkt_hdr)) + if (len > pkt_hdr->frame_len) return -1;
- ODP_ASSERT(len <= odp_packet_unshared_len(*pkt)); - - /* Special processing for references */ - while (len >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { - ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); - nxt_hdr = pkt_hdr->ref_hdr; - len -= pkt_hdr->frame_len; - len += pkt_hdr->ref_offset + - (nxt_hdr->frame_len - pkt_hdr->ref_len); - pkt_hdr->ref_hdr = NULL; - packet_free(pkt_hdr); - pkt_hdr = nxt_hdr; - seg_len = packet_first_seg_len(pkt_hdr); - *pkt = packet_handle(pkt_hdr); - ret = 1; - } - - if (CONFIG_PACKET_MAX_SEGS == 1 || - len < seg_len || - pkt_hdr->buf_hdr.segcount == 1) { + if (len < seg_len) { pull_head(pkt_hdr, len); - } else { + } else if (CONFIG_PACKET_MAX_SEGS != 1) { int num = 0; uint32_t pull_len = 0;
@@ -1147,29 +1007,23 @@ int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, *pkt = packet_handle(pkt_hdr); }
- if (data_ptr || seg_len_out) { - void *data_head = packet_map(pkt_hdr, 0, &seg_len, NULL); - - if (data_ptr) - *data_ptr = data_head; + if (data_ptr) + *data_ptr = packet_data(pkt_hdr);
- if (seg_len_out) - *seg_len_out = seg_len; - } + if (seg_len_out) + *seg_len_out = packet_first_seg_len(pkt_hdr);
- return ret; + return 0; }
void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(pkt, NULL); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); void *old_tail;
if (len > pkt_hdr->tailroom) return NULL;
- ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); - old_tail = packet_tail(pkt_hdr); push_tail(pkt_hdr, len);
@@ -1179,14 +1033,12 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(*pkt, NULL); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt); uint32_t frame_len = pkt_hdr->frame_len; uint32_t tailroom = pkt_hdr->tailroom; uint32_t tail_off = frame_len; int ret = 0;
- ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); - if (len > tailroom) { pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl); int num; @@ -1277,7 +1129,6 @@ void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len) if (len > packet_last_seg_len(pkt_hdr)) return NULL;
- ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); pull_tail(pkt_hdr, len);
return packet_tail(pkt_hdr); @@ -1288,34 +1139,17 @@ int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len, { int last; uint32_t seg_len; - uint32_t offset; - odp_packet_hdr_t *first_hdr = odp_packet_hdr(*pkt); - odp_packet_hdr_t *pkt_hdr, *prev_hdr; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt);
- if (len > packet_len(first_hdr)) + if (len > pkt_hdr->frame_len) return -1;
- pkt_hdr = odp_packet_last_hdr(*pkt, &offset); - - /* Special processing for references */ - while (len >= pkt_hdr->frame_len - offset && first_hdr->ref_hdr) { - len -= (pkt_hdr->frame_len - offset); - prev_hdr = odp_packet_prev_hdr(first_hdr, pkt_hdr, &offset); - ODP_ASSERT(packet_ref_count(prev_hdr) == 1); - prev_hdr->ref_hdr = NULL; - packet_free(pkt_hdr); - pkt_hdr = prev_hdr; - } - - ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); last = packet_last_seg(pkt_hdr); seg_len = packet_seg_len(pkt_hdr, last);
- if (CONFIG_PACKET_MAX_SEGS == 1 || - len < seg_len || - pkt_hdr->buf_hdr.segcount == 1) { + if (len < seg_len) { pull_tail(pkt_hdr, len); - } else { + } else if (CONFIG_PACKET_MAX_SEGS != 1) { int num = 0; uint32_t pull_len = 0;
@@ -1522,50 +1356,35 @@ void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp)
int odp_packet_is_segmented(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - - return pkt_hdr->buf_hdr.segcount > 1 || pkt_hdr->ref_hdr != NULL; + return odp_packet_hdr(pkt)->buf_hdr.segcount > 1; }
int odp_packet_num_segs(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t segcount = 0, i; - uint32_t seg_offset = 0, offset; - - do { - segcount += pkt_hdr->buf_hdr.segcount - seg_offset; - offset = pkt_hdr->ref_offset; - pkt_hdr = pkt_hdr->ref_hdr; - if (pkt_hdr) { - for (i = 0, seg_offset = 0; - i < pkt_hdr->buf_hdr.segcount; - i++, seg_offset++) { - if (offset < pkt_hdr->buf_hdr.seg[i].len) - break; - offset -= pkt_hdr->buf_hdr.seg[i].len; - } - } - } while (pkt_hdr);
- return segcount; + return pkt_hdr->buf_hdr.segcount; }
-odp_packet_seg_t odp_packet_first_seg(odp_packet_t pkt ODP_UNUSED) +odp_packet_seg_t odp_packet_first_seg(odp_packet_t pkt) { + (void)pkt; + return 0; }
odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt) { - return (odp_packet_seg_t)(odp_packet_num_segs(pkt) - 1); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + return packet_last_seg(pkt_hdr); }
odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (odp_unlikely(seg >= packet_last_seg(pkt_hdr))) + if (odp_unlikely(seg >= (odp_packet_seg_t)packet_last_seg(pkt_hdr))) return ODP_PACKET_SEG_INVALID;
return seg + 1; @@ -1581,51 +1400,21 @@ odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg) void *odp_packet_seg_data(odp_packet_t pkt, odp_packet_seg_t seg) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t seg_offset = 0, offset = 0, i; - - while (seg >= pkt_hdr->buf_hdr.segcount - seg_offset && - pkt_hdr->ref_hdr) { - seg -= (pkt_hdr->buf_hdr.segcount - seg_offset); - offset = pkt_hdr->ref_offset; - pkt_hdr = pkt_hdr->ref_hdr; - for (i = 0, seg_offset = 0; - i < pkt_hdr->buf_hdr.segcount; - i++, seg_offset++) { - if (offset < pkt_hdr->buf_hdr.seg[i].len) - break; - offset -= pkt_hdr->buf_hdr.seg[i].len; - } - }
- if (odp_unlikely(seg + seg_offset >= pkt_hdr->buf_hdr.segcount)) + if (odp_unlikely(seg >= pkt_hdr->buf_hdr.segcount)) return NULL;
- return packet_seg_data(pkt_hdr, seg + seg_offset) + offset; + return packet_seg_data(pkt_hdr, seg); }
uint32_t odp_packet_seg_data_len(odp_packet_t pkt, odp_packet_seg_t seg) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t seg_offset = 0, offset = 0, i; - - while (seg >= pkt_hdr->buf_hdr.segcount - seg_offset && - pkt_hdr->ref_hdr) { - seg -= (pkt_hdr->buf_hdr.segcount - seg_offset); - offset = pkt_hdr->ref_offset; - pkt_hdr = pkt_hdr->ref_hdr; - for (i = 0, seg_offset = 0; - i < pkt_hdr->buf_hdr.segcount; - i++, seg_offset++) { - if (offset < pkt_hdr->buf_hdr.seg[i].len) - break; - offset -= pkt_hdr->buf_hdr.seg[i].len; - } - }
- if (odp_unlikely(seg + seg_offset >= pkt_hdr->buf_hdr.segcount)) + if (odp_unlikely(seg >= pkt_hdr->buf_hdr.segcount)) return 0;
- return packet_seg_len(pkt_hdr, seg + seg_offset) - offset; + return packet_seg_len(pkt_hdr, seg); }
/* @@ -1639,14 +1428,12 @@ int odp_packet_add_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) { odp_packet_t pkt = *pkt_ptr; odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - uint32_t pktlen = packet_len(pkt_hdr); + uint32_t pktlen = pkt_hdr->frame_len; odp_packet_t newpkt;
if (offset > pktlen) return -1;
- ODP_ASSERT(odp_packet_unshared_len(*pkt_ptr) >= offset); - newpkt = odp_packet_alloc(pkt_hdr->buf_hdr.pool_hdl, pktlen + len);
if (newpkt == ODP_PACKET_INVALID) @@ -1709,8 +1496,6 @@ int odp_packet_align(odp_packet_t *pkt, uint32_t offset, uint32_t len, if (align > ODP_CACHE_LINE_SIZE) return -1;
- ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); - if (seglen >= len) { misalign = align <= 1 ? 0 : ROUNDUP_ALIGN(uaddr, align) - uaddr; @@ -1750,13 +1535,10 @@ int odp_packet_concat(odp_packet_t *dst, odp_packet_t src) uint32_t dst_len = dst_hdr->frame_len; uint32_t src_len = src_hdr->frame_len;
- ODP_ASSERT(packet_ref_count(dst_hdr) == 1); - /* Do a copy if resulting packet would be out of segments or packets - * are from different pools or src is a reference. */ + * are from different pools. */ if (odp_unlikely((dst_segs + src_segs) > CONFIG_PACKET_MAX_SEGS) || - odp_unlikely(dst_pool != src_pool) || - odp_unlikely(packet_ref_count(src_hdr)) > 1) { + odp_unlikely(dst_pool != src_pool)) { if (odp_packet_extend_tail(dst, src_len, NULL, NULL) >= 0) { (void)odp_packet_copy_from_pkt(*dst, dst_len, src, 0, src_len); @@ -1771,9 +1553,8 @@ int odp_packet_concat(odp_packet_t *dst, odp_packet_t src)
add_all_segs(dst_hdr, src_hdr);
- dst_hdr->frame_len = dst_len + src_len; - dst_hdr->unshared_len = dst_len + src_len; - dst_hdr->tailroom = src_hdr->tailroom; + dst_hdr->frame_len = dst_len + src_len; + dst_hdr->tailroom = src_hdr->tailroom;
/* Data was not moved in memory */ return 0; @@ -1786,7 +1567,6 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) if (len >= pktlen || tail == NULL) return -1;
- ODP_ASSERT(odp_packet_unshared_len(*pkt) >= len); *tail = odp_packet_copy_part(*pkt, len, pktlen - len, odp_packet_pool(*pkt));
@@ -1797,109 +1577,6 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) }
/* - * References - */ - -static inline void packet_ref(odp_packet_hdr_t *pkt_hdr) -{ - uint32_t i; - odp_packet_hdr_t *hdr; - - do { - for (i = 0; i < pkt_hdr->buf_hdr.segcount; i++) { - hdr = pkt_hdr->buf_hdr.seg[i].hdr; - packet_ref_inc(hdr); - } - - pkt_hdr = pkt_hdr->ref_hdr; - } while (pkt_hdr); -} - -static inline odp_packet_t packet_splice(odp_packet_hdr_t *pkt_hdr, - uint32_t offset, - odp_packet_hdr_t *ref_hdr) -{ - /* Catch attempted references to stale handles in debug builds */ - ODP_ASSERT(packet_ref_count(pkt_hdr) > 0); - - /* Splicing is from the last section of src pkt */ - while (ref_hdr->ref_hdr) - ref_hdr = ref_hdr->ref_hdr; - - /* Find section where splice begins */ - while (offset >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { - offset -= (pkt_hdr->frame_len - pkt_hdr->ref_offset); - offset += (pkt_hdr->ref_hdr->frame_len - pkt_hdr->ref_len); - pkt_hdr = pkt_hdr->ref_hdr; - } - - ref_hdr->ref_hdr = pkt_hdr; - ref_hdr->ref_offset = offset; - ref_hdr->ref_len = pkt_hdr->frame_len; - - if (offset < pkt_hdr->unshared_len) - pkt_hdr->unshared_len = offset; - - packet_ref(pkt_hdr); - return _odp_packet_hdl(ref_hdr); -} - -odp_packet_t odp_packet_ref_static(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - - pkt_hdr->unshared_len = 0; - packet_ref(pkt_hdr); - return pkt; -} - -odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) -{ - odp_packet_t hdr; - odp_packet_hdr_t *pkt_hdr; - - if (pkt == ODP_PACKET_INVALID) - return ODP_PACKET_INVALID; - - pkt_hdr = odp_packet_hdr(pkt); - if (offset >= packet_len(pkt_hdr)) - return ODP_PACKET_INVALID; - - hdr = odp_packet_alloc(odp_packet_pool(pkt), 0); - - if (hdr == ODP_PACKET_INVALID) - return ODP_PACKET_INVALID; - - return packet_splice(pkt_hdr, offset, odp_packet_hdr(hdr)); -} - -odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, - odp_packet_t hdr) -{ - odp_packet_hdr_t *pkt_hdr; - - if (pkt == ODP_PACKET_INVALID || - hdr == ODP_PACKET_INVALID || - pkt == hdr) - return ODP_PACKET_INVALID; - - ODP_ASSERT(odp_packet_has_ref(hdr) == 0); - - pkt_hdr = odp_packet_hdr(pkt); - if (offset >= packet_len(pkt_hdr)) - return ODP_PACKET_INVALID; - - return packet_splice(pkt_hdr, offset, odp_packet_hdr(hdr)); -} - -int odp_packet_has_ref(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - - return pkt_hdr->ref_hdr != NULL || packet_ref_count(pkt_hdr) > 1; -} - -/* * * Copy * ******************************************************** @@ -1908,7 +1585,8 @@ int odp_packet_has_ref(odp_packet_t pkt)
odp_packet_t odp_packet_copy(odp_packet_t pkt, odp_pool_t pool) { - uint32_t pktlen = odp_packet_len(pkt); + odp_packet_hdr_t *srchdr = odp_packet_hdr(pkt); + uint32_t pktlen = srchdr->frame_len; odp_packet_t newpkt = odp_packet_alloc(pool, pktlen);
if (newpkt != ODP_PACKET_INVALID) { @@ -1947,7 +1625,7 @@ int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, uint8_t *dstaddr = (uint8_t *)dst; odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (offset + len > packet_len(pkt_hdr)) + if (offset + len > pkt_hdr->frame_len) return -1;
while (len > 0) { @@ -1971,11 +1649,9 @@ int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, const uint8_t *srcaddr = (const uint8_t *)src; odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (offset + len > packet_len(pkt_hdr)) + if (offset + len > pkt_hdr->frame_len) return -1;
- ODP_ASSERT(odp_packet_unshared_len(pkt) >= offset + len); - while (len > 0) { mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); cpylen = len > seglen ? seglen : len; @@ -2001,12 +1677,10 @@ int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, uint32_t src_seglen = 0; /* GCC */ int overlap;
- if (dst_offset + len > packet_len(dst_hdr) || - src_offset + len > packet_len(src_hdr)) + if (dst_offset + len > dst_hdr->frame_len || + src_offset + len > src_hdr->frame_len) return -1;
- ODP_ASSERT(odp_packet_unshared_len(dst) >= dst_offset + len); - overlap = (dst_hdr == src_hdr && ((dst_offset <= src_offset && dst_offset + len >= src_offset) || @@ -2090,7 +1764,7 @@ void odp_packet_print(odp_packet_t pkt) len += snprintf(&str[len], n - len, " l4_offset %" PRIu32 "\n", hdr->p.l4_offset); len += snprintf(&str[len], n - len, - " frame_len %" PRIu32 "\n", packet_len(hdr)); + " frame_len %" PRIu32 "\n", hdr->frame_len); len += snprintf(&str[len], n - len, " input %" PRIu64 "\n", odp_pktio_to_u64(hdr->input));
commit 3f5d8c5b1f50efe8bf017b8a0014af668c664c43 Author: Petri Savolainen petri.savolainen@linaro.org Date: Mon Feb 13 14:53:28 2017 +0200
validation: packet: remove non compatible tests
Tests for bad inputs are not compatible to the spec. Out-of-range values cause undefined results and must not be tested in validation suite.
Remove reference checks that do not comply anymore to the new odp_packet_has_ref() specification.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c index f64c599..900c426 100644 --- a/test/common_plat/validation/api/packet/packet.c +++ b/test/common_plat/validation/api/packet/packet.c @@ -1877,46 +1877,70 @@ void packet_test_extend_ref(void) /* Verify ref lengths */ CU_ASSERT(ref != ODP_PACKET_INVALID); CU_ASSERT(odp_packet_len(ref) == max_len - 200); - CU_ASSERT(odp_packet_unshared_len(ref) == 0); + if (odp_packet_has_ref(ref) == 1) { + CU_ASSERT(odp_packet_unshared_len(ref) == 0);
- /* And ref's affect on max_pkt */ - CU_ASSERT(odp_packet_has_ref(max_pkt) == 1); - CU_ASSERT(odp_packet_unshared_len(max_pkt) == 100); + /* And ref's affect on max_pkt */ + CU_ASSERT(odp_packet_has_ref(max_pkt) == 1); + CU_ASSERT(odp_packet_unshared_len(max_pkt) == 100); + } else { + CU_ASSERT(odp_packet_unshared_len(ref) == odp_packet_len(ref)); + CU_ASSERT(odp_packet_unshared_len(max_pkt) == + odp_packet_len(max_pkt)); + }
/* Now extend max_pkt and verify effect */ CU_ASSERT(odp_packet_extend_head(&max_pkt, 10, NULL, NULL) >= 0); CU_ASSERT(odp_packet_len(max_pkt) == max_len - 90); - CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110); - CU_ASSERT(odp_packet_has_ref(max_pkt) == 1); + + if (odp_packet_has_ref(max_pkt) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110); + }
/* Extend on max_pkt should not affect ref */ - CU_ASSERT(odp_packet_has_ref(ref) == 1); CU_ASSERT(odp_packet_len(ref) == max_len - 200); - CU_ASSERT(odp_packet_unshared_len(ref) == 0); + + if (odp_packet_has_ref(ref) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref) == 0); + }
/* Now extend ref and verify effect*/ CU_ASSERT(odp_packet_extend_head(&ref, 20, NULL, NULL) >= 0); CU_ASSERT(odp_packet_len(ref) == max_len - 180); - CU_ASSERT(odp_packet_unshared_len(ref) == 20); + + if (odp_packet_has_ref(ref) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref) == 20); + }
/* Extend on ref should not affect max_pkt */ CU_ASSERT(odp_packet_len(max_pkt) == max_len - 90); - CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110); - CU_ASSERT(odp_packet_has_ref(max_pkt) == 1); + + if (odp_packet_has_ref(max_pkt) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110); + }
/* Trunc max_pkt of all unshared len */ - CU_ASSERT(odp_packet_trunc_head(&max_pkt, - odp_packet_unshared_len(max_pkt), - NULL, NULL) >= 0); + CU_ASSERT(odp_packet_trunc_head(&max_pkt, 110, NULL, NULL) >= 0);
/* Verify effect on max_pkt */ CU_ASSERT(odp_packet_len(max_pkt) == max_len - 200); - CU_ASSERT(odp_packet_unshared_len(max_pkt) == 0); - CU_ASSERT(odp_packet_has_ref(max_pkt) == 1); + + if (odp_packet_has_ref(max_pkt) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(max_pkt) == 0); + }
/* Verify that ref is unchanged */ CU_ASSERT(odp_packet_len(ref) == max_len - 180); - CU_ASSERT(odp_packet_unshared_len(ref) == 20); + + if (odp_packet_has_ref(ref) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref) == 20); + }
/* Free ref and verify that max_pkt is back to being unreferenced */ odp_packet_free(ref); @@ -2089,37 +2113,42 @@ void packet_test_ref(void) odp_packet_unshared_len(hdr_pkt[i])); }
- /* Attempt an invalid ref */ - refhdr_pkt[0] = odp_packet_ref_pkt(base_pkt, pkt_len, hdr_pkt[0]); - CU_ASSERT(refhdr_pkt[0] == ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_ref(hdr_pkt[0]) == 0); - CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); - - /* We can't ref to ourselves */ - refhdr_pkt[0] = odp_packet_ref_pkt(hdr_pkt[0], 0, hdr_pkt[0]); - CU_ASSERT(refhdr_pkt[0] == ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_ref(hdr_pkt[0]) == 0); - - /* Now create a couple of valid refs */ + /* Create a couple of refs */ refhdr_pkt[0] = odp_packet_ref_pkt(base_pkt, offset[0], hdr_pkt[0]); refhdr_pkt[1] = odp_packet_ref_pkt(base_pkt, offset[1], hdr_pkt[1]);
CU_ASSERT(refhdr_pkt[0] != ODP_PACKET_INVALID); CU_ASSERT(refhdr_pkt[1] != ODP_PACKET_INVALID);
- CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1); - CU_ASSERT(odp_packet_has_ref(refhdr_pkt[1]) == 1); - CU_ASSERT(odp_packet_has_ref(base_pkt) == 1); + /* If base packet has now references, ref packet should be also + * references. */ + if (odp_packet_has_ref(base_pkt) == 1) { + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[1]) == 1);
- /* Verify ref lengths and contents */ - CU_ASSERT(odp_packet_unshared_len(base_pkt) == 0); + CU_ASSERT(odp_packet_unshared_len(base_pkt) == 0); + } else { + CU_ASSERT(odp_packet_unshared_len(base_pkt) == pkt_len); + }
CU_ASSERT(odp_packet_len(refhdr_pkt[0]) == hdr_len[0] + pkt_len - offset[0]); - CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]); CU_ASSERT(odp_packet_len(refhdr_pkt[1]) == hdr_len[1] + pkt_len - offset[1]); - CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) == hdr_len[1]); + + if (odp_packet_has_ref(refhdr_pkt[0]) == 1) { + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]); + } else { + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == + odp_packet_len(refhdr_pkt[0])); + } + + if (odp_packet_has_ref(refhdr_pkt[1]) == 1) { + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) == hdr_len[1]); + } else { + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) == + odp_packet_len(refhdr_pkt[1])); + }
packet_compare_offset(refhdr_pkt[0], hdr_len[0], base_pkt, offset[0], @@ -2137,23 +2166,16 @@ void packet_test_ref(void) refhdr_pkt[2] = odp_packet_ref_pkt(refhdr_pkt[0], 2, hdr_cpy); CU_ASSERT(refhdr_pkt[2] != ODP_PACKET_INVALID);
- if (refhdr_pkt[2] != ODP_PACKET_INVALID) { - CU_ASSERT(odp_packet_has_ref(base_pkt) == 1); - CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1); + if (odp_packet_has_ref(refhdr_pkt[2]) == 1) { CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1); CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[2]) == hdr_len[2]); CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == 2); - - /* Free the compound ref and verify we're back to simple ref */ - odp_packet_free(refhdr_pkt[2]); - CU_ASSERT(odp_packet_has_ref(base_pkt) == 1); - CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1); - CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]); }
/* Delete the refs */ odp_packet_free(refhdr_pkt[0]); odp_packet_free(refhdr_pkt[1]); + odp_packet_free(refhdr_pkt[2]);
/* Verify that base_pkt no longer has a ref */ CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); @@ -2164,9 +2186,11 @@ void packet_test_ref(void)
CU_ASSERT(hdr_pkt[2] != ODP_PACKET_INVALID); CU_ASSERT(hdr_pkt[3] != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1); - CU_ASSERT(odp_packet_has_ref(refhdr_pkt[3]) == 1); - CU_ASSERT(odp_packet_has_ref(base_pkt) == 1); + + if (odp_packet_has_ref(base_pkt) == 1) { + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[3]) == 1); + }
CU_ASSERT(odp_packet_len(refhdr_pkt[2]) == odp_packet_len(refhdr_pkt[3])); @@ -2185,7 +2209,12 @@ void packet_test_ref(void) /* Create a static reference */ ref_pkt[0] = odp_packet_ref_static(base_pkt); CU_ASSERT(ref_pkt[0] != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_ref(base_pkt) == 1); + + if (odp_packet_has_ref(base_pkt) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_has_ref(ref_pkt[0]) == 1); + } + CU_ASSERT(odp_packet_len(ref_pkt[0]) == odp_packet_len(base_pkt)); packet_compare_offset(ref_pkt[0], 0, base_pkt, 0, odp_packet_len(base_pkt)); @@ -2194,33 +2223,38 @@ void packet_test_ref(void) odp_packet_free(ref_pkt[0]); CU_ASSERT(odp_packet_has_ref(base_pkt) == 0);
- /* Create an invalid basic reference */ - ref_pkt[0] = odp_packet_ref(segmented_base_pkt, segmented_pkt_len); - CU_ASSERT(ref_pkt[0] == ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 0); - - /* Now create valid references */ + /* Create references */ ref_pkt[0] = odp_packet_ref(segmented_base_pkt, offset[0]); - CU_ASSERT(odp_packet_has_ref(ref_pkt[0]) == 1); - CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1); + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1); + }
ref_pkt[1] = odp_packet_ref(segmented_base_pkt, offset[1]); - CU_ASSERT(odp_packet_has_ref(ref_pkt[1]) == 1); - CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1); + + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1); + }
/* Verify reference lengths */ CU_ASSERT(odp_packet_len(ref_pkt[0]) == segmented_pkt_len - offset[0]); CU_ASSERT(odp_packet_len(ref_pkt[1]) == segmented_pkt_len - offset[1]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + } + + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + }
/* Free the base pkts -- references should still be valid */ odp_packet_free(base_pkt); odp_packet_free(segmented_base_pkt);
- CU_ASSERT(odp_packet_has_ref(ref_pkt[0]) == 1); - CU_ASSERT(odp_packet_has_ref(ref_pkt[1]) == 1); - packet_compare_offset(ref_pkt[0], 0, segmented_test_packet, offset[0], segmented_pkt_len - offset[0]); @@ -2233,20 +2267,35 @@ void packet_test_ref(void) hr[1] = odp_packet_headroom(ref_pkt[1]);
CU_ASSERT(odp_packet_push_head(ref_pkt[0], hr[0]) != NULL); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); + + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); + } + CU_ASSERT(odp_packet_len(ref_pkt[0]) == hr[0] + segmented_pkt_len - offset[0]);
CU_ASSERT(odp_packet_pull_head(ref_pkt[0], hr[0] / 2) != NULL); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0] - (hr[0] / 2)); + + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == + hr[0] - (hr[0] / 2)); + }
if (hr[1] > 0) { CU_ASSERT(odp_packet_push_head(ref_pkt[1], 1) != NULL); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 1); + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 1); + } CU_ASSERT(odp_packet_len(ref_pkt[1]) == 1 + segmented_pkt_len - offset[1]); CU_ASSERT(odp_packet_pull_head(ref_pkt[1], 1) != NULL); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + } CU_ASSERT(odp_packet_len(ref_pkt[1]) == segmented_pkt_len - offset[1]); } @@ -2261,36 +2310,68 @@ void packet_test_ref(void) CU_ASSERT_FATAL(ref_pkt[1] != ODP_PACKET_INVALID); ref_len[1] = odp_packet_len(ref_pkt[1]); CU_ASSERT(ref_len[1] == odp_packet_len(base_pkt) - offset[1]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + }
CU_ASSERT(odp_packet_push_head(base_pkt, base_hr / 2) != NULL); - CU_ASSERT(odp_packet_unshared_len(base_pkt) == base_hr / 2 + offset[1]); + + if (odp_packet_has_ref(base_pkt) == 1) { + CU_ASSERT(odp_packet_unshared_len(base_pkt) == + base_hr / 2 + offset[1]); + } CU_ASSERT(odp_packet_len(ref_pkt[1]) == ref_len[1]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + }
ref_pkt[0] = odp_packet_ref(base_pkt, offset[0]); CU_ASSERT_FATAL(ref_pkt[0] != ODP_PACKET_INVALID); ref_len[0] = odp_packet_len(ref_pkt[0]); CU_ASSERT(ref_len[0] = odp_packet_len(base_pkt) - offset[0]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + }
CU_ASSERT(odp_packet_push_head(base_pkt, base_hr - base_hr / 2) != NULL); - CU_ASSERT(odp_packet_unshared_len(base_pkt) == - base_hr - base_hr / 2 + offset[0]); + if (odp_packet_has_ref(base_pkt) == 1) { + CU_ASSERT(odp_packet_unshared_len(base_pkt) == + base_hr - base_hr / 2 + offset[0]); + } CU_ASSERT(odp_packet_len(ref_pkt[1]) == ref_len[1]); CU_ASSERT(odp_packet_len(ref_pkt[0]) == ref_len[0]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + } + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + }
hr[0] = odp_packet_headroom(ref_pkt[0]); hr[1] = odp_packet_headroom(ref_pkt[1]); CU_ASSERT(odp_packet_push_head(ref_pkt[0], hr[0]) != NULL); CU_ASSERT(odp_packet_push_head(ref_pkt[1], hr[1]) != NULL); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); - CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == hr[1]); - CU_ASSERT(odp_packet_unshared_len(base_pkt) == - base_hr - base_hr / 2 + offset[0]); + if (odp_packet_has_ref(ref_pkt[0]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); + } + if (odp_packet_has_ref(ref_pkt[1]) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == hr[1]); + } + if (odp_packet_has_ref(base_pkt) == 1) { + /* CU_ASSERT needs braces */ + CU_ASSERT(odp_packet_unshared_len(base_pkt) == + base_hr - base_hr / 2 + offset[0]); + }
odp_packet_free(base_pkt); odp_packet_free(ref_pkt[0]);
commit f72f999552de02c602864baa82bb374322415b24 Author: Petri Savolainen petri.savolainen@linaro.org Date: Mon Feb 13 14:53:27 2017 +0200
api: packet: references may be implemented as copy
Some implementations may implement new references as packet copy. odp_packet_has_ref() will return 0 for copies, since those are unique packets.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h index b6450c1..05ffd68 100644 --- a/include/odp/api/spec/packet.h +++ b/include/odp/api/spec/packet.h @@ -892,9 +892,6 @@ odp_packet_t odp_packet_ref_static(odp_packet_t pkt); * dynamic references must not be mixed. Results are undefined if these * restrictions are not observed. * - * odp_packet_unshared_len() may be used to determine the number of bytes - * starting at offset zero that are unique to a packet handle. - * * The packet handle 'pkt' may itself by a (dynamic) reference to a packet. * * If the caller does not intend to modify either the packet or the new @@ -952,8 +949,9 @@ odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, * When a packet has multiple references, packet data is divided into two * parts: unshared and shared. The unshared part always precedes the shared * part. This call returns number of bytes in the unshared part. When a - * packet has only a single reference, all packet data is unshared and - * unshared length equals the packet length (odp_packet_len()). + * packet has only a single reference (see odp_packet_has_ref()), all packet + * data is unshared and unshared length equals the packet length + * (odp_packet_len()). * * Application may modify only the unshared part, the rest of the packet data * must be treated as read only. @@ -967,8 +965,16 @@ uint32_t odp_packet_unshared_len(odp_packet_t pkt); /** * Test if packet has multiple references * - * A packet that has multiple references shares data and possibly metadata - * with other packets. Shared part must be treated as read only. + * A packet that has multiple references share data with other packets. In case + * of a static reference it also shares metadata. Shared parts must be treated + * as read only. + * + * New references are created with odp_packet_ref_static(), odp_packet_ref() and + * odp_packet_ref_pkt() calls. However, some of those calls may implement the + * new reference as a packet copy. If a copy is done, the new reference is + * actually a new, unique packet and this function returns '0' for it. + * When a real reference is created (instead of a copy), this function + * returns '1' for both packets (the original packet and the new reference). * * @param pkt Packet handle *
commit 56ee80a8482f1161a84b3e5145fab2e0f7653ccb Merge: abc36ae 431a078 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Feb 21 15:57:58 2017 +0300
Merge branch 'master' into api-next
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --cc configure.ac index 0ff6c5a,d344e6a..e4bd3a7 --- a/configure.ac +++ b/configure.ac @@@ -53,9 -53,11 +53,11 @@@ AC_PROG_CX AC_PROG_INSTALL AC_PROG_MAKE_SET
+ AC_PROG_LN_S + AM_PROG_AR #Use libtool -LT_INIT([]) +LT_INIT([dlopen]) AC_SUBST([LIBTOOL_DEPS]) AM_PROG_LIBTOOL
-----------------------------------------------------------------------
Summary of changes: configure.ac | 2 + include/odp/api/spec/packet.h | 20 +- platform/linux-generic/Makefile.am | 10 + .../include/odp_classification_inlines.h | 40 +- .../linux-generic/include/odp_packet_internal.h | 85 +-- platform/linux-generic/odp_packet.c | 614 ++++++--------------- .../validation/api/classification/classification.h | 2 + .../classification/odp_classification_test_pmr.c | 224 ++++++++ test/common_plat/validation/api/packet/packet.c | 241 +++++--- 9 files changed, 629 insertions(+), 609 deletions(-)
hooks/post-receive