diff options
author | Ido Barnea <ibarnea@cisco.com> | 2016-03-17 16:10:11 +0200 |
---|---|---|
committer | Ido Barnea <ibarnea@cisco.com> | 2016-03-22 17:40:03 +0200 |
commit | 1e93f5b1fc20d7e8fd4b01b4e3c0715095b42e14 (patch) | |
tree | 46e5048b48b012ca66c6557b72a37a38e8393e6c /src/stateless/rx | |
parent | dd0507516960de491a3c697680d970f31661714b (diff) |
Added CP to RX messages
Diffstat (limited to 'src/stateless/rx')
-rw-r--r-- | src/stateless/rx/trex_stateless_rx_core.cpp | 112 | ||||
-rw-r--r-- | src/stateless/rx/trex_stateless_rx_core.h | 18 |
2 files changed, 103 insertions, 27 deletions
diff --git a/src/stateless/rx/trex_stateless_rx_core.cpp b/src/stateless/rx/trex_stateless_rx_core.cpp index a108bef3..86711189 100644 --- a/src/stateless/rx/trex_stateless_rx_core.cpp +++ b/src/stateless/rx/trex_stateless_rx_core.cpp @@ -1,48 +1,110 @@ #include <stdio.h> -#include "latency.h" +#include "bp_sim.h" #include "flow_stat_parser.h" -#include "stateless/rx/trex_stateless_rx_core.h" - +#include "latency.h" +#include "trex_stateless_messaging.h" +#include "trex_stateless_rx_core.h" void CRxCoreStateless::create(const CRxSlCfg &cfg) { m_max_ports = cfg.m_max_ports; + CMessagingManager * cp_rx = CMsgIns::Ins()->getCpRx(); + + m_ring_from_cp = cp_rx->getRingCpToDp(0); + m_ring_to_cp = cp_rx->getRingDpToCp(0); + m_state = STATE_IDLE; + for (int i = 0; i < m_max_ports; i++) { CLatencyManagerPerPort * lp = &m_ports[i]; - // CCPortLatency * lpo = &m_ports[swap_port(i)].m_port; - lp->m_io = cfg.m_ports[i]; - /* lp->m_port.Create(this, - i, - m_pkt_gen.get_payload_offset(), - m_pkt_gen.get_l4_offset(), - m_pkt_gen.get_pkt_size(),lpo );???*/ } +} +void CRxCoreStateless::handle_cp_msg(TrexStatelessCpToRxMsgBase *msg) { + msg->handle(this); + delete msg; } -void CRxCoreStateless::start() { - static int count = 0; - static int i = 0; - while (1) { - count += try_rx(); - i++; - if (i == 100000000) { - i = 0; - //??? remove - printf("counter:%d port0:[%u], port1:[%u]\n", count, m_ports[0].m_port.m_rx_pg_pkts[0], m_ports[1].m_port.m_rx_pg_pkts[1]); +bool CRxCoreStateless::periodic_check_for_cp_messages() { + /* fast path */ + if ( likely ( m_ring_from_cp->isEmpty() ) ) { + return false; + } + + while ( true ) { + CGenNode * node = NULL; + + if (m_ring_from_cp->Dequeue(node) != 0) { + break; + } + assert(node); + TrexStatelessCpToRxMsgBase * msg = (TrexStatelessCpToRxMsgBase *)node; + handle_cp_msg(msg); + } + + return true; + +} + +void CRxCoreStateless::idle_state_loop() { + const int SHORT_DELAY_MS = 2; + const int LONG_DELAY_MS = 50; + const int DEEP_SLEEP_LIMIT = 2000; + + int counter = 0; + + while (m_state == STATE_IDLE) { + bool had_msg = periodic_check_for_cp_messages(); + if (had_msg) { + counter = 0; + continue; + } + + /* enter deep sleep only if enough time had passed */ + if (counter < DEEP_SLEEP_LIMIT) { + delay(SHORT_DELAY_MS); + counter++; + } else { + delay(LONG_DELAY_MS); } } } -// ??? temp try +void CRxCoreStateless::start() { + static int count = 0; + static int i = 0; + + while (true) { + if (m_state == STATE_WORKING) { + count += try_rx(); + i++; + if (i == 100) { + i = 0; + // if no packets in 100 cycles, sleep for a while to spare the cpu + if (count == 0) { + delay(1); + } + count = 0; + periodic_check_for_cp_messages(); + } + } else { + idle_state_loop(); + } +#if 0 + ??? do we need this? + if ( m_core->is_terminated_by_master() ) { + break; + } +#endif + } +} + int CRxCoreStateless::try_rx() { rte_mbuf_t * rx_pkts[64]; int i, total_pkts = 0; for (i = 0; i < m_max_ports; i++) { CLatencyManagerPerPort * lp = &m_ports[i]; rte_mbuf_t * m; - //m_cpu_dp_u.start_work(); /* try to read 64 packets clean up the queue */ uint16_t cnt_p = lp->m_io->rx_burst(rx_pkts, 64); total_pkts += cnt_p; @@ -63,10 +125,8 @@ int CRxCoreStateless::try_rx() { } rte_pktmbuf_free(m); } - /* commit only if there was work to do ! */ - //m_cpu_dp_u.commit(); //??? what's this? - }/* if work */ - }// all ports + }/* if work */ + }// all ports return total_pkts; } diff --git a/src/stateless/rx/trex_stateless_rx_core.h b/src/stateless/rx/trex_stateless_rx_core.h index 942ddbd6..eecc8033 100644 --- a/src/stateless/rx/trex_stateless_rx_core.h +++ b/src/stateless/rx/trex_stateless_rx_core.h @@ -23,6 +23,8 @@ limitations under the License. #include <stdint.h> #include "latency.h" +class TrexStatelessCpToRxMsgBase; + class CRxSlCfg { public: CRxSlCfg (){ @@ -37,19 +39,33 @@ class CRxSlCfg { }; class CRxCoreStateless { + enum state_e { + STATE_IDLE, + STATE_WORKING, + }; + public: void start(); void create(const CRxSlCfg &cfg); void reset_rx_stats(uint8_t port_id); int get_rx_stats(uint8_t port_id, uint32_t *pkts, uint32_t *prev_pkts , uint32_t *bytes, uint32_t *prev_bytes, int min, int max); + void work() {m_state = STATE_WORKING;} + void idle() {m_state = STATE_IDLE;} private: + void handle_cp_msg(TrexStatelessCpToRxMsgBase *msg); + bool periodic_check_for_cp_messages(); + void idle_state_loop(); int try_rx(); bool is_flow_stat_id(uint16_t id); uint16_t get_hw_id(uint16_t id); - + private: uint32_t m_max_ports; + bool m_has_streams; CLatencyManagerPerPort m_ports[TREX_MAX_PORTS]; + state_e m_state; /* state of all ports */ + CNodeRing *m_ring_from_cp; + CNodeRing *m_ring_to_cp; }; #endif |