diff options
author | imarom <imarom@cisco.com> | 2016-08-18 13:49:59 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-08-18 13:52:49 +0300 |
commit | b8353aa9eb017f66166da9ee03ad7cd09abda175 (patch) | |
tree | 416cd03e701fdb2209034d04ea37bdc8a21bf3f4 /src | |
parent | 5f530a21aa669b4ddc0f8d0329794d0c439f6879 (diff) |
CPU util. measurements fix (more accurate and steady)
see #trex-246
Diffstat (limited to 'src')
-rwxr-xr-x | src/bp_sim.cpp | 3 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 18 | ||||
-rwxr-xr-x | src/os_time.h | 13 | ||||
-rwxr-xr-x | src/utl_cpuu.cpp | 7 | ||||
-rwxr-xr-x | src/utl_cpuu.h | 8 |
5 files changed, 33 insertions, 16 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 2d1d020b..773e82fc 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -4615,8 +4615,7 @@ double CFlowGenList::GetCpuUtilRaw(){ void CFlowGenList::UpdateFast(){ - int i; - for (i=0; i<(int)m_threads_info.size(); i++) { + for (int i=0; i<(int)m_threads_info.size(); i++) { CFlowGenListPerThread * lp=m_threads_info[i]; lp->Update(); } diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 6beb4e3e..0ef83c02 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -4126,15 +4126,21 @@ void CGlobalTRex::handle_fast_path() { /* check from messages from DP */ check_for_dp_messages(); - // update CPU% - m_fl.UpdateFast(); - if (get_is_stateless()) { - m_rx_sl.update_cpu_util(); - }else{ - m_mg.update_fast(); + /* measure CPU utilization by sampling (we sample 1000 to get an accurate sampling) */ + for (int i = 0; i < 1000; i++) { + m_fl.UpdateFast(); + + if (get_is_stateless()) { + m_rx_sl.update_cpu_util(); + }else{ + m_mg.update_fast(); + } + + rte_pause(); } + if ( is_all_cores_finished() ) { mark_for_shutdown(SHUTDOWN_TEST_ENDED); } diff --git a/src/os_time.h b/src/os_time.h index b1d44c03..4f10e2b5 100755 --- a/src/os_time.h +++ b/src/os_time.h @@ -165,6 +165,17 @@ void delay(int msec){ nanosleep(&time1,&remain); } - +/** + * more accurate sleep by doing spin + * + */ +static inline +void delay_spin(double sec) { + double target = now_sec() + sec; + + while (now_sec() < target) { + rte_pause(); + } +} #endif diff --git a/src/utl_cpuu.cpp b/src/utl_cpuu.cpp index 47c78c8e..c01326d6 100755 --- a/src/utl_cpuu.cpp +++ b/src/utl_cpuu.cpp @@ -42,10 +42,11 @@ void CCpuUtlCp::Update(){ if ( m_dpcpu->sample_data() ) { m_work++; } - if (m_ticks==100) { + if (m_ticks==100000) { /* LPF*/ - m_cpu_util_lpf = (m_cpu_util_lpf*0.75)+((double)m_work*0.25); - AppendHistory(m_work); + double work = (m_work / double(m_ticks)) * 100; + m_cpu_util_lpf = (m_cpu_util_lpf*0.75)+(work*0.25); + AppendHistory(work); m_ticks=0; m_work=0; } diff --git a/src/utl_cpuu.h b/src/utl_cpuu.h index b0a76fce..690eb200 100755 --- a/src/utl_cpuu.h +++ b/src/utl_cpuu.h @@ -47,7 +47,7 @@ public: private: - uint8_t m_data; + volatile uint8_t m_data; } __rte_cache_aligned; class CCpuUtlCp { @@ -62,9 +62,9 @@ public: void GetHistory(cpu_vct_st &cpu_vct); private: void AppendHistory(uint8_t); - CCpuUtlDp * m_dpcpu; - uint8_t m_ticks; - uint8_t m_work; + CCpuUtlDp * m_dpcpu; + uint32_t m_ticks; + uint32_t m_work; static const int m_history_size=20; uint8_t m_cpu_util[m_history_size]; // history as cyclic array |