Term "area" highlights better that the per packet user area is fixed in size and position. E.g. odp_packet_data(), odp_packet_seg_data() return pointers which are (likely) modified during packet processing.
Signed-off-by: Petri Savolainen <[email protected]> --- include/odp/api/packet.h | 24 ++++++---- include/odp/api/pool.h | 7 ++- .../linux-generic/include/odp_buffer_internal.h | 4 +- platform/linux-generic/odp_packet.c | 56 +++++++++++----------- platform/linux-generic/odp_pool.c | 6 +-- test/validation/odp_packet.c | 22 ++++----- 6 files changed, 61 insertions(+), 58 deletions(-) diff --git a/include/odp/api/packet.h b/include/odp/api/packet.h index 840e152..cbd06d5 100644 --- a/include/odp/api/packet.h +++ b/include/odp/api/packet.h @@ -467,24 +467,28 @@ uint64_t odp_packet_user_u64(odp_packet_t pkt); void odp_packet_user_u64_set(odp_packet_t pkt, uint64_t ctx); /** - * Get address of user metadata associated with a packet + * User area address * - * @param pkt Packet handle + * Each packet has an area for user data. Size of the area is fixed and defined + * in packet pool parameters. * - * @retval addr Address of the user metadata associated with pkt - * @retval NULL The packet has no user metadata. + * @param pkt Packet handle + * + * @return User area address associated with the packet + * @retval NULL The packet does not have user area */ -void *odp_packet_user_data(odp_packet_t pkt); +void *odp_packet_user_area(odp_packet_t pkt); /** - * Get size of user metadata associated with a packet + * User area size * - * @param pkt Packet handle + * The size is fixed and defined in packet pool parameters. * - * @return Number of bytes of user metadata associated - * with pkt. + * @param pkt Packet handle + * + * @return User area size in bytes */ -uint32_t odp_packet_user_data_size(odp_packet_t pkt); +uint32_t odp_packet_user_area_size(odp_packet_t pkt); /** * Layer 2 start pointer diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h index 0092132..6df75e6 100644 --- a/include/odp/api/pool.h +++ b/include/odp/api/pool.h @@ -76,10 +76,9 @@ typedef struct odp_pool_param_t { The maximum value is defined by ODP_CONFIG_PACKET_SEG_LEN_MAX. Use 0 for default. */ - uint32_t udata_size; /**< User metadata size in - bytes. Specify as 0 if no - user metadata is to be - associated with the pkt */ + uint32_t uarea_size; /**< User area size in bytes. + Specify as 0 if no user area + is needed. */ } pkt; struct { uint32_t num; /**< Number of timeouts in the pool */ diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index ee965bb..e7b7568 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -125,8 +125,8 @@ typedef struct odp_buffer_hdr_t { void *buf_ctx; /* user context */ const void *buf_cctx; /* const alias for ctx */ }; - void *udata_addr; /* user metadata addr */ - uint32_t udata_size; /* size of user metadata */ + void *uarea_addr; /* user area address */ + uint32_t uarea_size; /* size of user area */ uint32_t segcount; /* segment count */ uint32_t segsize; /* segment size */ void *addr[ODP_BUFFER_MAX_SEG]; /* block addrs */ diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 2abb465..04a24f3 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -239,14 +239,14 @@ void odp_packet_user_u64_set(odp_packet_t pkt, uint64_t ctx) odp_packet_hdr(pkt)->buf_hdr.buf_u64 = ctx; } -void *odp_packet_user_data(odp_packet_t pkt) +void *odp_packet_user_area(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.udata_addr; + return odp_packet_hdr(pkt)->buf_hdr.uarea_addr; } -uint32_t odp_packet_user_data_size(odp_packet_t pkt) +uint32_t odp_packet_user_area_size(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.udata_size; + return odp_packet_hdr(pkt)->buf_hdr.uarea_size; } void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) @@ -419,14 +419,14 @@ odp_packet_t odp_packet_add_data(odp_packet_t pkt, uint32_t offset, odp_packet_hdr_t *new_hdr = odp_packet_hdr(newpkt); new_hdr->input = pkt_hdr->input; new_hdr->buf_hdr.buf_u64 = pkt_hdr->buf_hdr.buf_u64; - if (new_hdr->buf_hdr.udata_addr != NULL && - pkt_hdr->buf_hdr.udata_addr != NULL) - memcpy(new_hdr->buf_hdr.udata_addr, - pkt_hdr->buf_hdr.udata_addr, - new_hdr->buf_hdr.udata_size <= - pkt_hdr->buf_hdr.udata_size ? - new_hdr->buf_hdr.udata_size : - pkt_hdr->buf_hdr.udata_size); + if (new_hdr->buf_hdr.uarea_addr != NULL && + pkt_hdr->buf_hdr.uarea_addr != NULL) + memcpy(new_hdr->buf_hdr.uarea_addr, + pkt_hdr->buf_hdr.uarea_addr, + new_hdr->buf_hdr.uarea_size <= + pkt_hdr->buf_hdr.uarea_size ? + new_hdr->buf_hdr.uarea_size : + pkt_hdr->buf_hdr.uarea_size); odp_atomic_store_u32( &new_hdr->buf_hdr.ref_count, odp_atomic_load_u32( @@ -463,14 +463,14 @@ odp_packet_t odp_packet_rem_data(odp_packet_t pkt, uint32_t offset, odp_packet_hdr_t *new_hdr = odp_packet_hdr(newpkt); new_hdr->input = pkt_hdr->input; new_hdr->buf_hdr.buf_u64 = pkt_hdr->buf_hdr.buf_u64; - if (new_hdr->buf_hdr.udata_addr != NULL && - pkt_hdr->buf_hdr.udata_addr != NULL) - memcpy(new_hdr->buf_hdr.udata_addr, - pkt_hdr->buf_hdr.udata_addr, - new_hdr->buf_hdr.udata_size <= - pkt_hdr->buf_hdr.udata_size ? - new_hdr->buf_hdr.udata_size : - pkt_hdr->buf_hdr.udata_size); + if (new_hdr->buf_hdr.uarea_addr != NULL && + pkt_hdr->buf_hdr.uarea_addr != NULL) + memcpy(new_hdr->buf_hdr.uarea_addr, + pkt_hdr->buf_hdr.uarea_addr, + new_hdr->buf_hdr.uarea_size <= + pkt_hdr->buf_hdr.uarea_size ? + new_hdr->buf_hdr.uarea_size : + pkt_hdr->buf_hdr.uarea_size); odp_atomic_store_u32( &new_hdr->buf_hdr.ref_count, odp_atomic_load_u32( @@ -626,14 +626,14 @@ void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) dsthdr->input = srchdr->input; dsthdr->buf_hdr.buf_u64 = srchdr->buf_hdr.buf_u64; - if (dsthdr->buf_hdr.udata_addr != NULL && - srchdr->buf_hdr.udata_addr != NULL) - memcpy(dsthdr->buf_hdr.udata_addr, - srchdr->buf_hdr.udata_addr, - dsthdr->buf_hdr.udata_size <= - srchdr->buf_hdr.udata_size ? - dsthdr->buf_hdr.udata_size : - srchdr->buf_hdr.udata_size); + if (dsthdr->buf_hdr.uarea_addr != NULL && + srchdr->buf_hdr.uarea_addr != NULL) + memcpy(dsthdr->buf_hdr.uarea_addr, + srchdr->buf_hdr.uarea_addr, + dsthdr->buf_hdr.uarea_size <= + srchdr->buf_hdr.uarea_size ? + dsthdr->buf_hdr.uarea_size : + srchdr->buf_hdr.uarea_size); odp_atomic_store_u32( &dsthdr->buf_hdr.ref_count, odp_atomic_load_u32( diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index de502b2..f887665 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -224,7 +224,7 @@ odp_pool_t odp_pool_create(const char *name, if (blk_size / seg_len > ODP_BUFFER_MAX_SEG) return ODP_POOL_INVALID; - p_udata_size = params->pkt.udata_size; + p_udata_size = params->pkt.uarea_size; udata_stride = ODP_ALIGN_ROUNDUP(p_udata_size, sizeof(uint64_t)); @@ -368,8 +368,8 @@ odp_pool_t odp_pool_create(const char *name, odp_atomic_init_u32(&tmp->ref_count, 0); tmp->type = params->type; tmp->pool_hdl = pool->s.pool_hdl; - tmp->udata_addr = (void *)udat; - tmp->udata_size = p_udata_size; + tmp->uarea_addr = (void *)udat; + tmp->uarea_size = p_udata_size; tmp->segcount = 0; tmp->segsize = pool->s.seg_size; tmp->handle.handle = odp_buffer_encode_handle(tmp); diff --git a/test/validation/odp_packet.c b/test/validation/odp_packet.c index e9395b6..77e0409 100644 --- a/test/validation/odp_packet.c +++ b/test/validation/odp_packet.c @@ -41,7 +41,7 @@ static int packet_testsuite_init(void) .seg_len = PACKET_BUF_LEN, .len = PACKET_BUF_LEN, .num = 100, - .udata_size = sizeof(struct udata_struct), + .uarea_size = sizeof(struct udata_struct), }, .type = ODP_POOL_PACKET, }; @@ -57,8 +57,8 @@ static int packet_testsuite_init(void) if (odp_packet_is_valid(test_packet) == 0) return -1; - udat = odp_packet_user_data(test_packet); - udat_size = odp_packet_user_data_size(test_packet); + udat = odp_packet_user_area(test_packet); + udat_size = odp_packet_user_area_size(test_packet); if (udat == NULL || udat_size != sizeof(struct udata_struct)) return -1; odp_pool_print(packet_pool); @@ -200,9 +200,9 @@ static void packet_context(void) CU_ASSERT(odp_packet_user_u64(pkt) == u64_test_value); odp_packet_user_u64_set(pkt, prev_u64); - udat = odp_packet_user_data(pkt); + udat = odp_packet_user_area(pkt); CU_ASSERT(udat != NULL); - CU_ASSERT(odp_packet_user_data_size(pkt) == + CU_ASSERT(odp_packet_user_area_size(pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(udat, &test_packet_udata, sizeof(struct udata_struct)) == 0); @@ -518,8 +518,8 @@ static void packet_add_rem_data(void) pkt_len = odp_packet_len(pkt); usr_ptr = odp_packet_user_ptr(pkt); usr_u64 = odp_packet_user_u64(pkt); - udat = odp_packet_user_data(pkt); - CU_ASSERT(odp_packet_user_data_size(pkt) == + udat = odp_packet_user_area(pkt); + CU_ASSERT(odp_packet_user_area_size(pkt) == sizeof(struct udata_struct)); memcpy(udat, &test_packet_udata, sizeof(struct udata_struct)); @@ -537,9 +537,9 @@ static void packet_add_rem_data(void) CU_ASSERT(odp_packet_user_u64(new_pkt) == usr_u64); /* Verify that user metadata has been preserved */ - new_udat = odp_packet_user_data(new_pkt); + new_udat = odp_packet_user_area(new_pkt); CU_ASSERT(new_udat != NULL); - CU_ASSERT(odp_packet_user_data_size(new_pkt) == + CU_ASSERT(odp_packet_user_area_size(new_pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(new_udat, &test_packet_udata, sizeof(struct udata_struct)) == 0); @@ -558,9 +558,9 @@ static void packet_add_rem_data(void) CU_ASSERT(odp_packet_user_u64(new_pkt) == usr_u64); /* Verify that user metadata has been preserved */ - new_udat = odp_packet_user_data(new_pkt); + new_udat = odp_packet_user_area(new_pkt); CU_ASSERT(new_udat != NULL); - CU_ASSERT(odp_packet_user_data_size(new_pkt) == + CU_ASSERT(odp_packet_user_area_size(new_pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(new_udat, &test_packet_udata, sizeof(struct udata_struct)) == 0); -- 2.4.0 _______________________________________________ lng-odp mailing list [email protected] https://lists.linaro.org/mailman/listinfo/lng-odp
