On epoll_pwait, POSIX timers and X11 events. Most of X11 events is either delayed or dropped

十年热恋 提交于 2021-02-11 12:39:20

问题


The setup is below.

have a X11 connection file descriptor x11_fd set in non-blocking mode.
have a signal file descriptor sig_fd         set in non-blocking mode.
create a POSIX timer with timer_create

add all above in epoll set

main_loop:
 n = epoll_pwait(ep_fd, ep_evs, MAXEVENTS, -1, &mask_sigs)
  if(fd == sig_fd)
   do set some signal flags
  if(fd == x11_fd)
   do X11 events
  if(fd == timer_fd or timeout)
   do some small computations
end_main_loop

X11 events are processed with while((event = xcb_poll_for_event(...)))

The timer was set to expire at 4 second rate. And all X11 events were deliwered in order and non were dropped. Now, if the timer is set to have a sub-second rate, the X11 events got delayed or completely dropped.

The problem is, the application may need a high-rate timers.

My naive thought was that epoll will queue the X11 events while callbacks generated by POSIX timers are processing. The epoll seems lacking of a CPU time or something. Honestly I do not know why is X11 events got dropped. I just want to overcome it. Preferably with some multiplexing and without threading.

Update

I removed the timer and had set epoll_pwait timeout to minimum. The problem still persists. I had to note that events are not dropped, but got queued and recieved in batch. Also, the delayed events are not all events that I do listen to. Mouse movement, focus, leave/enter displayed without delay. Also the application behaves very strangely in a way, that, when i move mouse, or move window, or do some other interaction(I do not get what kind of interaction is it), the keyboard gets pulled at higher rate.

Need some help here. Can post a code with some scripts to github.

Update

Well, after some thoughts, I think that interaction with X11 and a computational task that must be run at constant rate do not integrate well in multiplexing paradigm. The one epoll_wait for all computing seem to change time frequency of multiplexed tasks of a different kind.

Update

Changed the pseudocode to reflect that I do some small computations in a event loop.

N.B.

Timer event frequency is higher then the X11 event frequency. X server events get in-between the timer events and screw the processing.

来源:https://stackoverflow.com/questions/65906541/on-epoll-pwait-posix-timers-and-x11-events-most-of-x11-events-is-either-delaye

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!