diff options
author | imarom <imarom@cisco.com> | 2016-08-04 14:13:10 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-08-07 11:47:35 +0300 |
commit | e946a09e5237da5d87048c0f07e0685a99ba193c (patch) | |
tree | 5c58465e78c98a761b3a7d1ad0faae62659d24c7 /src/stateless/dp | |
parent | fef2d27782b661913f52a0016447bfdcc3ce49af (diff) |
fix for #trex-240
https://trex-tgn.cisco.com/youtrack/issue/trex-240
Diffstat (limited to 'src/stateless/dp')
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 39 | ||||
-rw-r--r-- | src/stateless/dp/trex_stream_node.h | 22 |
2 files changed, 37 insertions, 24 deletions
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index 5ad15033..4d9137f1 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -149,23 +149,39 @@ void CGenNodeStateless::Dump(FILE *fd){ } +void CGenNodeStateless::generate_random_seed() { + /* seed can be provided by the user */ + uint32_t unique_seed; + if (m_ref_stream_info->m_random_seed) { + unique_seed = m_ref_stream_info->m_random_seed; + } else { + unsigned int tmp = (unsigned int)time(NULL); + unique_seed = rand_r(&tmp); + } + + /* per thread divergence */ + unique_seed = (unique_seed * ( (m_thread_id + 1) * 514229 ) ) & 0xFFFFFFFF; + + /* set random */ + set_random_seed(unique_seed); +} -void CGenNodeStateless::refresh_vm_bss(){ + +void CGenNodeStateless::refresh_vm_bss() { if ( m_vm_flow_var ) { StreamVmDp * vm_s=m_ref_stream_info->m_vm_dp; assert(vm_s); memcpy(m_vm_flow_var,vm_s->get_bss(),vm_s->get_bss_size()); - if ( vm_s->is_random_seed() ){ - /* if we have random seed for this program */ - if (m_ref_stream_info->m_random_seed) { - set_random_seed(m_ref_stream_info->m_random_seed); - } + if ( vm_s->is_random_seed() ) { + generate_random_seed(); } + } } + /** * this function called when stream restart after it was inactive */ @@ -872,6 +888,7 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, CGenNodeStateless *node = m_core->create_node_sl(); + node->m_thread_id = m_thread_id; node->cache_mbuf_array_init(); node->m_batch_size=0; @@ -992,13 +1009,9 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, node->m_vm_program = lpDpVm->get_program(); /* same ref to the program */ node->m_vm_program_size = lpDpVm->get_program_size(); - - /* set the random seed if was set */ - if ( lpDpVm->is_random_seed() ){ - /* if we have random seed for this program */ - if (stream->m_random_seed) { - node->set_random_seed(stream->m_random_seed); - } + /* generate random seed if needed*/ + if (lpDpVm->is_random_seed()) { + node->generate_random_seed(); } /* we need to copy the object */ diff --git a/src/stateless/dp/trex_stream_node.h b/src/stateless/dp/trex_stream_node.h index 605ef6a0..8a68625c 100644 --- a/src/stateless/dp/trex_stream_node.h +++ b/src/stateless/dp/trex_stream_node.h @@ -138,17 +138,6 @@ private: public: - - - void set_random_seed(uint32_t seed){ - uint32_t *p=get_random_bss_seed_memory(); - *p=seed; - } - - uint32_t* get_random_bss_seed_memory(){ - return (uint32_t*)m_vm_flow_var;/* always the first 4 bytes */ - } - uint8_t get_port_id(){ return (m_port_id); } @@ -444,9 +433,20 @@ public: private: + void generate_random_seed(); void refresh_vm_bss(); + void set_random_seed(uint32_t seed){ + uint32_t *p=get_random_bss_seed_memory(); + *p=seed; + } + + uint32_t* get_random_bss_seed_memory(){ + return (uint32_t*)m_vm_flow_var;/* always the first 4 bytes */ + } + + } __rte_cache_aligned; static_assert(sizeof(CGenNodeStateless) == sizeof(CGenNode), "sizeof(CGenNodeStateless) != sizeof(CGenNode)" ); |