summaryrefslogtreecommitdiffstats
path: root/src/stateless/dp
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-05-08 13:50:57 +0300
committerHanoh Haim <hhaim@cisco.com>2016-05-08 13:50:57 +0300
commitc2912dfc5ad81e2edcf77b7ee992f92216ed0bad (patch)
tree4676234974ed4de8c804047b2e4463b893518932 /src/stateless/dp
parentf27bfbab72f9221b221a7f36f4063e9ff8e9d307 (diff)
add cache capability to stateless node object
Diffstat (limited to 'src/stateless/dp')
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp97
-rw-r--r--src/stateless/dp/trex_stream_node.h72
2 files changed, 147 insertions, 22 deletions
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index d3d49a34..23f1f4c2 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -26,6 +26,75 @@ limitations under the License.
#include "trex_stream_node.h"
#include "trex_streams_compiler.h"
+
+
+
+void CGenNodeStateless::cache_mbuf_array_init(){
+ m_cache_size=0;
+ m_cache_array_cnt=0;
+}
+
+
+
+rte_mbuf_t ** CGenNodeStateless::cache_mbuf_array_alloc(uint16_t size){
+
+ uint32_t buf_size = CGenNodeCacheMbuf::get_object_size(size);
+ /* TBD replace with align, zero API */
+ m_cache_mbuf = (void *)malloc(buf_size);
+ assert(m_cache_mbuf);
+ memset(m_cache_mbuf,0,buf_size);
+
+ m_flags |= SL_NODE_CONST_MBUF_CACHE_ARRAY;
+ m_cache_size=size;
+ m_cache_array_cnt=0;
+ return ((rte_mbuf_t **)m_cache_mbuf);
+}
+
+void CGenNodeStateless::cache_mbuf_array_free(){
+
+ assert(m_cache_mbuf);
+ int i;
+ for (i=0; i<(int)m_cache_size; i++) {
+ rte_mbuf_t * m=cache_mbuf_array_get((uint16_t)i);
+ assert(m);
+ rte_pktmbuf_free(m);
+ }
+
+ /* free the const */
+ rte_mbuf_t * m=cache_mbuf_array_get_const_mbuf() ;
+ if (m) {
+ rte_pktmbuf_free(m);
+ }
+
+ free(m_cache_mbuf);
+ m_cache_mbuf=0;
+}
+
+
+rte_mbuf_t * CGenNodeStateless::cache_mbuf_array_get(uint16_t index){
+
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ return (p->m_array[index]);
+}
+
+void CGenNodeStateless::cache_mbuf_array_set_const_mbuf(rte_mbuf_t * m){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ p->m_mbuf_const=m;
+}
+
+rte_mbuf_t * CGenNodeStateless::cache_mbuf_array_get_const_mbuf(){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ return (p->m_mbuf_const);
+}
+
+
+void CGenNodeStateless::cache_mbuf_array_set(uint16_t index,
+ rte_mbuf_t * m){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ p->m_array[index]=m;
+}
+
+
void CDpOneStream::Delete(CFlowGenListPerThread * core){
assert(m_node->get_state() == CGenNodeStateless::ss_INACTIVE);
core->free_node((CGenNode *)m_node);
@@ -188,18 +257,24 @@ rte_mbuf_t * CGenNodeStateless::alloc_node_with_vm(){
void CGenNodeStateless::free_stl_node(){
- /* if we have cache mbuf free it */
- rte_mbuf_t * m=get_cache_mbuf();
- if (m) {
- rte_pktmbuf_free(m);
- m_cache_mbuf=0;
+
+ if ( is_cache_mbuf_array() ){
+ /* do we have cache of mbuf pre allocated */
+ cache_mbuf_array_free();
}else{
- /* non cache - must have an header */
- m=get_const_mbuf();
- if (m) {
- rte_pktmbuf_free(m); /* reduce the ref counter */
- }
- free_prefix_header();
+ /* if we have cache mbuf free it */
+ rte_mbuf_t * m=get_cache_mbuf();
+ if (m) {
+ rte_pktmbuf_free(m);
+ m_cache_mbuf=0;
+ }else{
+ /* non cache - must have an header */
+ m=get_const_mbuf();
+ if (m) {
+ rte_pktmbuf_free(m); /* reduce the ref counter */
+ }
+ free_prefix_header();
+ }
}
if (m_vm_flow_var) {
/* free flow var */
diff --git a/src/stateless/dp/trex_stream_node.h b/src/stateless/dp/trex_stream_node.h
index c85bf8b5..4d3c2ae1 100644
--- a/src/stateless/dp/trex_stream_node.h
+++ b/src/stateless/dp/trex_stream_node.h
@@ -49,6 +49,15 @@ public:
static_assert(sizeof(CGenNodeCommand) == sizeof(CGenNode), "sizeof(CGenNodeCommand) != sizeof(CGenNode)" );
+struct CGenNodeCacheMbuf {
+ rte_mbuf_t * m_mbuf_const;
+ rte_mbuf_t * m_array[0];
+public:
+ static uint32_t get_object_size(uint32_t size){
+ return ( sizeof(CGenNodeCacheMbuf) + sizeof(rte_mbuf_t *) * size );
+ }
+};
+
/* this is a event for stateless */
struct CGenNodeStateless : public CGenNodeBase {
friend class TrexStatelessDpCore;
@@ -61,10 +70,10 @@ public:
SL_NODE_FLAGS_MBUF_CACHE =2, //USED by master
SL_NODE_CONST_MBUF =4,
-
- SL_NODE_VAR_PKT_SIZE =8,
- SL_NODE_STATS_NEEDED = 0x10
-
+
+ SL_NODE_VAR_PKT_SIZE = 8,
+ SL_NODE_STATS_NEEDED = 0x10,
+ SL_NODE_CONST_MBUF_CACHE_ARRAY = 0x20 /* array of mbuf - cache */
};
enum {
@@ -77,15 +86,18 @@ public:
static std::string get_stream_state_str(stream_state_t stream_state);
private:
- /* cache line 0 */
- /* important stuff here */
- void * m_cache_mbuf;
+ /******************************/
+ /* cache line 0 */
+ /* important stuff here R/W */
+ /******************************/
+ void * m_cache_mbuf; /* could be an array or a one mbuf */
double m_next_time_offset; /* in sec */
uint16_t m_action_counter;
uint8_t m_stat_hw_id; // hw id used to count rx and tx stats
uint8_t m_null_stream;
- uint32_t m_pad12;
+ uint16_t m_cache_array_cnt;
+ uint16_t m_pad12;
stream_state_t m_state;
uint8_t m_port_id;
@@ -97,7 +109,10 @@ private:
uint32_t m_multi_bursts; /* in case of multi_burst how many bursts */
- /* cache line 1 */
+ /******************************/
+ /* cache line 1
+ this cache line should be READONLY ! you can write only at init time */
+ /******************************/
TrexStream * m_ref_stream_info; /* the stream info */
CGenNodeStateless * m_next_stream;
@@ -107,8 +122,11 @@ private:
uint8_t * m_vm_flow_var; /* pointer to the vm flow var */
uint8_t * m_vm_program; /* pointer to the program */
uint16_t m_vm_program_size; /* up to 64K op codes */
- uint16_t m_pad2;
- uint32_t m_pad3;
+ uint16_t m_cache_size; /*RO*/ /* the size of the mbuf array */
+ uint8_t m_batch_size; /*RO*/ /* the batch size */
+
+ uint8_t m_pad4;
+ uint16_t m_pad5;
/* End Fast Field VM Section */
@@ -118,6 +136,8 @@ private:
public:
+
+
void set_random_seed(uint32_t seed){
uint32_t *p=get_random_bss_seed_memory();
*p=seed;
@@ -369,6 +389,36 @@ public:
void free_stl_node();
public:
+ void cache_mbuf_array_init();
+
+ inline bool is_cache_mbuf_array(){
+ return ( m_flags & SL_NODE_CONST_MBUF_CACHE_ARRAY ? true:false );
+ }
+
+ rte_mbuf_t ** cache_mbuf_array_alloc(uint16_t size);
+
+ void cache_mbuf_array_free();
+
+ void cache_mbuf_array_set(uint16_t index,rte_mbuf_t * m);
+
+ void cache_mbuf_array_set_const_mbuf(rte_mbuf_t * m);
+
+ rte_mbuf_t * cache_mbuf_array_get_const_mbuf();
+
+ rte_mbuf_t * cache_mbuf_array_get(uint16_t index);
+
+ rte_mbuf_t * cache_mbuf_array_get_cur(void){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ rte_mbuf_t * m=p->m_array[m_cache_array_cnt];
+ assert(m);
+ m_cache_array_cnt++;
+ if (m_cache_array_cnt == m_cache_size) {
+ m_cache_array_cnt=0;
+ }
+ return m;
+ }
+
+public:
/* debug functions */
int get_stream_id();