On 06/21/16 16:20, Petri Savolainen wrote:
TM code used zero as the invalid packet handle value. Use
ODP_PACKET_INVALID instead, which currently has a non-zero
value. This mismatch caused bugs when packet handle value was
zero (first packet from pool 0).
Signed-off-by: Petri Savolainen <[email protected]>
---
.../include/odp_traffic_mngr_internal.h | 2 +-
platform/linux-generic/odp_pkt_queue.c | 31 ++++++++++++++++------
test/validation/traffic_mngr/traffic_mngr.c | 6 ++---
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/platform/linux-generic/include/odp_traffic_mngr_internal.h
b/platform/linux-generic/include/odp_traffic_mngr_internal.h
index 3586889..8585b0a 100644
--- a/platform/linux-generic/include/odp_traffic_mngr_internal.h
+++ b/platform/linux-generic/include/odp_traffic_mngr_internal.h
@@ -38,7 +38,7 @@ typedef struct stat file_stat_t;
#define INPUT_WORK_RING_SIZE (16 * 1024)
-#define INVALID_PKT 0
+#define INVALID_PKT ODP_PACKET_INVALID
Usually it's bad practice to add new define for already existence. In
that case
it looks like you definitely can use ODP_PACKET_INVALID directly.
Other changes looks good.
Maxim.
#define TM_QUEUE_MAGIC_NUM 0xBABEBABE
#define TM_NODE_MAGIC_NUM 0xBEEFBEEF
diff --git a/platform/linux-generic/odp_pkt_queue.c
b/platform/linux-generic/odp_pkt_queue.c
index 949cf74..cbaea64 100644
--- a/platform/linux-generic/odp_pkt_queue.c
+++ b/platform/linux-generic/odp_pkt_queue.c
@@ -17,12 +17,13 @@
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#define INVALID_PKT 0
+#define INVALID_PKT ODP_PACKET_INVALID
+#define NUM_PKTS 7
typedef struct /* Must be exactly 64 bytes long AND cacheline aligned! */ {
uint32_t next_queue_blk_idx;
uint32_t tail_queue_blk_idx;
- odp_packet_t pkts[7];
+ odp_packet_t pkts[NUM_PKTS];
} ODP_ALIGNED_CACHE queue_blk_t;
typedef struct {
@@ -62,6 +63,16 @@ typedef struct {
uint8_t all_regions_used;
} queue_pool_t;
+static inline void init_queue_blk(queue_blk_t *queue_blk)
+{
+ int i;
+
+ memset(queue_blk, 0, sizeof(queue_blk_t));
+
+ for (i = 0; i < NUM_PKTS; i++)
+ queue_blk->pkts[i] = INVALID_PKT;
+}
+
static queue_blk_t *blk_idx_to_queue_blk(queue_pool_t *queue_pool,
uint32_t queue_blk_idx)
{
@@ -91,9 +102,13 @@ static int pkt_queue_free_list_add(queue_pool_t *pool,
num_blks = region_desc->num_blks;
queue_blks = region_desc->queue_blks;
if (!queue_blks) {
+ uint32_t i;
malloc_len = num_blks * sizeof(queue_blk_t);
queue_blks = malloc(malloc_len);
- memset(queue_blks, 0, malloc_len);
+
+ for (i = 0; i < num_blks; i++)
+ init_queue_blk(&queue_blks->blks[i]);
+
region_desc->queue_blks = queue_blks;
}
@@ -146,7 +161,7 @@ static queue_blk_t *queue_blk_alloc(queue_pool_t *pool,
if (pool->free_list_size < pool->min_free_list_size)
pool->min_free_list_size = pool->free_list_size;
- memset(head_queue_blk, 0, sizeof(queue_blk_t));
+ init_queue_blk(head_queue_blk);
return head_queue_blk;
}
@@ -255,7 +270,7 @@ int _odp_pkt_queue_append(_odp_int_queue_pool_t queue_pool,
return -1;
pool->queue_num_tbl[queue_num] = first_blk_idx;
- memset(first_blk, 0, sizeof(queue_blk_t));
+ init_queue_blk(first_blk);
first_blk->pkts[0] = pkt;
return 0;
}
@@ -268,7 +283,7 @@ int _odp_pkt_queue_append(_odp_int_queue_pool_t queue_pool,
tail_blk = blk_idx_to_queue_blk(pool, tail_blk_idx);
/* Find first empty slot and insert pkt there. */
- for (idx = 0; idx < 7; idx++) {
+ for (idx = 0; idx < NUM_PKTS; idx++) {
if (tail_blk->pkts[idx] == INVALID_PKT) {
tail_blk->pkts[idx] = pkt;
return 0;
@@ -282,7 +297,7 @@ int _odp_pkt_queue_append(_odp_int_queue_pool_t queue_pool,
if (!new_tail_blk)
return -1;
- memset(new_tail_blk, 0, sizeof(queue_blk_t));
+ init_queue_blk(new_tail_blk);
new_tail_blk->pkts[0] = pkt;
tail_blk->next_queue_blk_idx = new_tail_blk_idx;
first_blk->tail_queue_blk_idx = new_tail_blk_idx;
@@ -307,7 +322,7 @@ int _odp_pkt_queue_remove(_odp_int_queue_pool_t queue_pool,
/* Now remove the first valid odp_packet_t handle value we find. */
first_blk = blk_idx_to_queue_blk(pool, first_blk_idx);
- for (idx = 0; idx < 7; idx++) {
+ for (idx = 0; idx < NUM_PKTS; idx++) {
if (first_blk->pkts[idx] != INVALID_PKT) {
*pkt = first_blk->pkts[idx];
first_blk->pkts[idx] = INVALID_PKT;
diff --git a/test/validation/traffic_mngr/traffic_mngr.c
b/test/validation/traffic_mngr/traffic_mngr.c
index 0645370..1c4e90b 100644
--- a/test/validation/traffic_mngr/traffic_mngr.c
+++ b/test/validation/traffic_mngr/traffic_mngr.c
@@ -2086,14 +2086,14 @@ int traffic_mngr_suite_term(void)
/* Close the pktios and associated packet pools. */
free_rcvd_pkts();
for (iface = 0; iface < num_ifaces; iface++) {
- if (odp_pool_destroy(pools[iface]) != 0)
- return -1;
-
if (odp_pktio_stop(pktios[iface]) != 0)
return -1;
if (odp_pktio_close(pktios[iface]) != 0)
return -1;
+
+ if (odp_pool_destroy(pools[iface]) != 0)
+ return -1;
}
return 0;
_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp