Signed-off-by: Kevin Wang <[email protected]>
Reviewed-by: Brian Brooks <[email protected]>
Reviewed-by: Honnappa Nagarahalli <[email protected]>
---
.../linux-generic/include/odp_queue_internal.h | 65 ++++++++++++++++
platform/linux-generic/odp_classification.c | 4 +-
platform/linux-generic/odp_packet_io.c | 89 +++++++++++++---------
platform/linux-generic/odp_queue.c | 2 +-
platform/linux-generic/odp_traffic_mngr.c | 7 +-
5 files changed, 123 insertions(+), 44 deletions(-)
diff --git a/platform/linux-generic/include/odp_queue_internal.h
b/platform/linux-generic/include/odp_queue_internal.h
index 560f826e..977546eb 100644
--- a/platform/linux-generic/include/odp_queue_internal.h
+++ b/platform/linux-generic/include/odp_queue_internal.h
@@ -37,6 +37,7 @@ extern "C" {
#define QUEUE_STATUS_NOTSCHED 3
#define QUEUE_STATUS_SCHED 4
+#define BUFFER_HDR_INVALID NULL
/* forward declaration */
union queue_entry_u;
@@ -94,6 +95,12 @@ int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t
*buf_hdr[], int num);
void queue_lock(queue_entry_t *queue);
void queue_unlock(queue_entry_t *queue);
+int queue_pktout_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr);
+int queue_pktout_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[],
+ int num);
+
+int queue_tm_reorder(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr);
+
static inline uint32_t queue_to_id(odp_queue_t handle)
{
return _odp_typeval(handle) - 1;
@@ -107,6 +114,64 @@ static inline queue_entry_t *queue_to_qentry(odp_queue_t
handle)
return get_qentry(queue_id);
}
+static inline odp_queue_t queue_get_handle(queue_entry_t *queue)
+{
+ return queue->s.handle;
+}
+
+static inline odp_pktout_queue_t queue_get_pktout(queue_entry_t *queue)
+{
+ return queue->s.pktout;
+}
+
+static inline void queue_set_pktout(queue_entry_t *queue,
+ odp_pktio_t pktio,
+ int index)
+{
+ queue->s.pktout.pktio = pktio;
+ queue->s.pktout.index = index;
+}
+
+static inline odp_pktin_queue_t queue_get_pktin(queue_entry_t *queue)
+{
+ return queue->s.pktin;
+}
+
+static inline void queue_set_pktin(queue_entry_t *queue,
+ odp_pktio_t pktio,
+ int index)
+{
+ queue->s.pktin.pktio = pktio;
+ queue->s.pktin.index = index;
+}
+
+static inline void queue_set_enq_func(queue_entry_t *queue, enq_func_t func)
+{
+ queue->s.enqueue = func;
+}
+
+static inline void queue_set_enq_multi_func(queue_entry_t *queue,
+ enq_multi_func_t func)
+{
+ queue->s.enqueue_multi = func;
+}
+
+static inline void queue_set_deq_func(queue_entry_t *queue, deq_func_t func)
+{
+ queue->s.dequeue = func;
+}
+
+static inline void queue_set_deq_multi_func(queue_entry_t *queue,
+ deq_multi_func_t func)
+{
+ queue->s.dequeue_multi = func;
+}
+
+static inline void queue_set_type(queue_entry_t *queue, odp_queue_type_t type)
+{
+ queue->s.type = type;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/platform/linux-generic/odp_classification.c
b/platform/linux-generic/odp_classification.c
index 7ebc47d7..1ba5c41c 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -282,7 +282,7 @@ odp_queue_t odp_cos_queue(odp_cos_t cos_id)
if (!cos->s.queue)
return ODP_QUEUE_INVALID;
- return cos->s.queue->s.handle;
+ return queue_get_handle(cos->s.queue);
}
int odp_cos_drop_set(odp_cos_t cos_id, odp_cls_drop_t drop_policy)
@@ -846,7 +846,7 @@ int cls_classify_packet(pktio_entry_t *entry, const uint8_t
*base,
*pool = cos->s.pool;
pkt_hdr->p.input_flags.dst_queue = 1;
- pkt_hdr->dst_queue = cos->s.queue->s.handle;
+ pkt_hdr->dst_queue = queue_get_handle(cos->s.queue);
return 0;
}
diff --git a/platform/linux-generic/odp_packet_io.c
b/platform/linux-generic/odp_packet_io.c
index d8cae15c..3e0d6ebf 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -5,23 +5,25 @@
*/
#include <odp_posix_extensions.h>
-#include <odp/api/packet_io.h>
-#include <odp_packet_io_internal.h>
-#include <odp_packet_io_queue.h>
#include <odp/api/packet.h>
-#include <odp_packet_internal.h>
-#include <odp_internal.h>
+#include <odp/api/packet_io.h>
#include <odp/api/spinlock.h>
#include <odp/api/ticketlock.h>
#include <odp/api/shared_memory.h>
-#include <odp_packet_socket.h>
+#include <odp/api/time.h>
+
+#include <odp_internal.h>
#include <odp_config_internal.h>
-#include <odp_queue_internal.h>
-#include <odp_schedule_if.h>
-#include <odp_classification_internal.h>
#include <odp_debug_internal.h>
+
+#include <odp_classification_internal.h>
+#include <odp_queue_internal.h>
#include <odp_packet_io_ipc_internal.h>
-#include <odp/api/time.h>
+#include <odp_packet_io_internal.h>
+#include <odp_packet_io_queue.h>
+#include <odp_packet_internal.h>
+#include <odp_packet_socket.h>
+#include <odp_schedule_if.h>
#include <string.h>
#include <inttypes.h>
@@ -472,7 +474,6 @@ int odp_pktio_start(odp_pktio_t hdl)
return -1;
}
}
-
sched_fn->pktio_start(pktio_to_id(hdl), num, index);
}
@@ -554,7 +555,6 @@ static inline int pktin_recv_buf(odp_pktin_queue_t queue,
odp_packet_t packets[num];
odp_packet_hdr_t *pkt_hdr;
odp_buffer_hdr_t *buf_hdr;
- odp_buffer_t buf;
int i;
int pkts;
int num_rx = 0;
@@ -564,9 +564,12 @@ 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);
- buf = _odp_packet_to_buffer(pkt);
- buf_hdr = buf_hdl_to_hdr(buf);
-
+#ifdef ODP_SCHEDULE_SCALABLE
+ buf_hdr = (odp_buffer_hdr_t *)(uintptr_t)
+ _odp_packet_to_buffer(pkt);
+#else
+ buf_hdr = buf_hdl_to_hdr(_odp_packet_to_buffer(pkt));
+#endif
if (pkt_hdr->p.input_flags.dst_queue) {
queue_entry_t *dst_queue;
int ret;
@@ -584,11 +587,17 @@ static inline int pktin_recv_buf(odp_pktin_queue_t queue,
int pktout_enqueue(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr)
{
- odp_packet_t pkt = _odp_packet_from_buffer(buf_hdr->handle.handle);
+ odp_packet_t pkt;
+
+#ifdef ODP_SCHEDULE_SCALABLE
+ pkt = _odp_packet_from_buffer((odp_buffer_t)buf_hdr);
+#else
+ pkt = _odp_packet_from_buffer(buf_hdr->handle.handle);
+#endif
int len = 1;
int nbr;
- nbr = odp_pktout_send(qentry->s.pktout, &pkt, len);
+ nbr = odp_pktout_send(queue_get_pktout(qentry), &pkt, len);
return (nbr == len ? 0 : -1);
}
@@ -606,9 +615,13 @@ int pktout_enq_multi(queue_entry_t *qentry,
odp_buffer_hdr_t *buf_hdr[],
int i;
for (i = 0; i < num; ++i)
+#ifdef ODP_SCHEDULE_SCALABLE
+ pkt_tbl[i] = _odp_packet_from_buffer((odp_buffer_t)buf_hdr[i]);
+#else
pkt_tbl[i] = _odp_packet_from_buffer(buf_hdr[i]->handle.handle);
+#endif
- nbr = odp_pktout_send(qentry->s.pktout, pkt_tbl, num);
+ nbr = odp_pktout_send(queue_get_pktout(qentry), pkt_tbl, num);
return nbr;
}
@@ -634,13 +647,14 @@ odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry)
int pkts;
buf_hdr = queue_deq(qentry);
- if (buf_hdr != NULL)
+ if (buf_hdr != BUFFER_HDR_INVALID)
return buf_hdr;
- pkts = pktin_recv_buf(qentry->s.pktin, hdr_tbl, QUEUE_MULTI_MAX);
+ pkts = pktin_recv_buf(queue_get_pktin(qentry),
+ hdr_tbl, QUEUE_MULTI_MAX);
if (pkts <= 0)
- return NULL;
+ return BUFFER_HDR_INVALID;
if (pkts > 1)
queue_enq_multi(qentry, &hdr_tbl[1], pkts - 1);
@@ -671,7 +685,8 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t
*buf_hdr[], int num)
if (nbr == num)
return nbr;
- pkts = pktin_recv_buf(qentry->s.pktin, hdr_tbl, QUEUE_MULTI_MAX);
+ pkts = pktin_recv_buf(queue_get_pktin(qentry),
+ hdr_tbl, QUEUE_MULTI_MAX);
if (pkts <= 0)
return nbr;
@@ -686,7 +701,6 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t
*buf_hdr[], int num)
queue_enq_multi(qentry, hdr_tbl, j);
return nbr;
}
-
int sched_cb_pktin_poll(int pktio_index, int num_queue, int index[])
{
odp_buffer_hdr_t *hdr_tbl[QUEUE_MULTI_MAX];
@@ -1268,13 +1282,14 @@ int odp_pktin_queue_config(odp_pktio_t pktio,
queue_entry_t *qentry;
qentry = queue_to_qentry(queue);
- qentry->s.pktin.index = i;
- qentry->s.pktin.pktio = pktio;
-
- qentry->s.enqueue = pktin_enqueue;
- qentry->s.dequeue = pktin_dequeue;
- qentry->s.enqueue_multi = pktin_enq_multi;
- qentry->s.dequeue_multi = pktin_deq_multi;
+ queue_set_pktin(qentry, pktio, i);
+
+ queue_set_enq_func(qentry, pktin_enqueue);
+ queue_set_deq_func(qentry, pktin_dequeue);
+ queue_set_enq_multi_func(qentry,
+ pktin_enq_multi);
+ queue_set_deq_multi_func(qentry,
+ pktin_deq_multi);
}
entry->s.in_queue[i].queue = queue;
@@ -1392,14 +1407,12 @@ int odp_pktout_queue_config(odp_pktio_t pktio,
}
qentry = queue_to_qentry(queue);
- qentry->s.pktout.index = i;
- qentry->s.pktout.pktio = pktio;
-
- /* Override default enqueue / dequeue functions */
- qentry->s.enqueue = pktout_enqueue;
- qentry->s.dequeue = pktout_dequeue;
- qentry->s.enqueue_multi = pktout_enq_multi;
- qentry->s.dequeue_multi = pktout_deq_multi;
+ queue_set_pktout(qentry, pktio, i);
+
+ queue_set_enq_func(qentry, pktout_enqueue);
+ queue_set_deq_func(qentry, pktout_dequeue);
+ queue_set_enq_multi_func(qentry, pktout_enq_multi);
+ queue_set_deq_multi_func(qentry, pktout_deq_multi);
entry->s.out_queue[i].queue = queue;
}
diff --git a/platform/linux-generic/odp_queue.c
b/platform/linux-generic/odp_queue.c
index 1114c95c..75847aca 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -293,11 +293,11 @@ void sched_cb_queue_destroy_finalize(uint32_t queue_index)
int odp_queue_destroy(odp_queue_t handle)
{
queue_entry_t *queue;
- queue = queue_to_qentry(handle);
if (handle == ODP_QUEUE_INVALID)
return -1;
+ queue = queue_to_qentry(handle);
LOCK(&queue->s.lock);
if (queue->s.status == QUEUE_STATUS_FREE) {
UNLOCK(&queue->s.lock);
diff --git a/platform/linux-generic/odp_traffic_mngr.c
b/platform/linux-generic/odp_traffic_mngr.c
index 4e9358b9..3244dfe3 100644
--- a/platform/linux-generic/odp_traffic_mngr.c
+++ b/platform/linux-generic/odp_traffic_mngr.c
@@ -3918,9 +3918,10 @@ odp_tm_queue_t odp_tm_queue_create(odp_tm_t odp_tm,
tm_queue_obj->pkt = ODP_PACKET_INVALID;
odp_ticketlock_init(&tm_wred_node->tm_wred_node_lock);
- tm_queue_obj->tm_qentry.s.type = QUEUE_TYPE_TM;
- tm_queue_obj->tm_qentry.s.enqueue = queue_tm_reenq;
- tm_queue_obj->tm_qentry.s.enqueue_multi = queue_tm_reenq_multi;
+ queue_set_type(&tm_queue_obj->tm_qentry, QUEUE_TYPE_TM);
+ queue_set_enq_func(&tm_queue_obj->tm_qentry, queue_tm_reenq);
+ queue_set_enq_multi_func(&tm_queue_obj->tm_qentry,
+ queue_tm_reenq_multi);
tm_system->queue_num_tbl[tm_queue_obj->queue_num - 1] = tm_queue_obj;
odp_ticketlock_lock(&tm_system->tm_system_lock);
--
2.12.2