0

first,my english is very bad... this is my code:

ev_timer_init(&m_netmsgpoptimer, netMsgTimer_cb, 10, 10.);
ev_timer_start(m_loop, &m_netmsgpoptimer);

m_mainlooptimer.data = (void*)this;
// 
ev_timer_init(&m_mainlooptimer, mainloopTimer_cb, 20, 20.);
ev_timer_start(m_loop, &m_mainlooptimer);

ev_loop(m_loop, 0);

and this is perf said:

5504.368980 task-clock                #    0.999 CPUs utilized

the perf cpu-clock record like this:

+  30.08%  huhuGame  [kernel.kallsyms]  [k] mutex_lock                             ◆
+  29.40%  huhuGame  [kernel.kallsyms]  [k] memcpy                                 ▒
+   4.75%  huhuGame  [kernel.kallsyms]  [k] system_call_after_swapgs               ▒

if i changed my code line "ev_loop(m_loop, 0)" to this:

    timespec  _tstart, _tend;
while(!m_bExit)
{
    clock_gettime(CLOCK_REALTIME, &_tstart);
    ev_loop(m_loop, EVLOOP_ONESHOT);
    clock_gettime(CLOCK_REALTIME, &_tend);
    long long  t1, t2;
    t1 =   _tstart.tv_sec*10000+_tstart.tv_nsec/100000;
    t2 =  _tend.tv_sec*10000 + _tend.tv_nsec/100000;
    t1 =  (t2 - t1)*10;
    if(t1 < 100)
        usleep(100-t1);
}

cpu utiluze is low.. and why ev_loop(m_loop,0) with ev_time will cost 100% cpu performance?

any answer is helpful,thanks!

huhu
  • 1
  • 1
  • 1
    The english language knowledge is an important key to communicate in technical community. – QMaster Dec 25 '14 at 08:39
  • I guess that the problem might be elsewhere. What are the other events you are looping on? Compile with all warnings and debug info (`gcc -Wall -Wextra -g`). **Use the debugger** (`gdb`) and also `strace` – Basile Starynkevitch Dec 25 '14 at 08:49
  • i am trying to improve...it's a little hard for me. – huhu Dec 25 '14 at 08:53
  • @Basile Starynkevitch i used perf record again for a long elapse,reprot is different – huhu Dec 25 '14 at 08:56
  • + 30.08% huhuGame [kernel.kallsyms] [k] mutex_lock 29.40% huhuGame [kernel.kallsyms] [k] memcpy + 4.75% huhuGame [kernel.kallsyms] [k] system_call_after_swapgs ▒ – huhu Dec 25 '14 at 08:57
  • @Basile Starynkevitch you are right,there is a module hiredis async,it used libev too,it's ok when i commented it. – huhu Dec 25 '14 at 09:31
  • Try using ev_run(m_loop, 0), ev_loop is deprecated in libev 4.x. –  Mar 01 '16 at 20:07

0 Answers0