libev与两个ev_timer 100%CPU utiluzed

时间:2014-12-25 08:30:35

标签: cpu libev

首先,我的英语非常糟糕...... 这是我的代码:

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);

这是perf说的:

5504.368980 task-clock                #    0.999 CPUs utilized

这样的perf cpu-clock记录:

+  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               ▒

如果我将我的代码行“ev_loop(m_loop,0)”更改为:

    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很低.. 为什么带有ev_time的ev_loop(m_loop,0)将花费100%的CPU性能?

任何答案都有帮助,谢谢!

0 个答案:

没有答案