[Xcb] [Bug 51648] xcb calls read(2) to test data availability on xorg sockets instead of polling on FreeBSD

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Jul 2 16:08:37 PDT 2012


https://bugs.freedesktop.org/show_bug.cgi?id=51648

Yuri <yuri at tsoft.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |

--- Comment #2 from Yuri <yuri at tsoft.com> 2012-07-02 16:08:37 PDT ---
> (I won't comment on your patch adding a poll()-call :-) )

Where did I say this was a suggested patch? This was an experiment, I am not an
xorg developer so I experiment with the code to see what is going on.

When I put a breakpoint into _xcb_in_read with the condition that read(2)
failed, I got several stack traces, see below.

> So if you see lots of EAGAINs from _xcb_in_read(), something (Xlib?) is doing
> lots of xcb_poll_for_event() calls.

This is exactly what is happening: Xlib is making a lot of unnecessary read(2)
calls. It should only call read(2) when response is actually expected. From
those stack traces it looks like _XReply calls read(2) one extra time, after
the original response to the caller inquiry was already received. Such calls
always necessarily return EAGAIN (unless server error or disconnect happens at
this time). Therefore, such calls shouldn't even be made. Unnecessary system
calls like these (as any unnecessary code) waste system resources.

This is an essence of this PR.

--- example stack traces ---
#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804512fee in poll_for_response (dpy=0x807dfb000) at xcb_io.c:288
#4  0x00000008045131fe in _XEventsQueued (dpy=0x807dfb000, mode=1) at
xcb_io.c:362
#5  0x00000008045137a6 in _XFlush (dpy=0x807dfb000) at xcb_io.c:513
#6  0x00000008044dd205 in XCreateGC (dpy=0x807dfb000, d=346, valuemask=12,
values=0x7fffffffbb30) at CrGC.c:89
#7  0x00000008044fa690 in XOpenDisplay (display=0x0) at OpenDis.c:533

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffbb30,
extra=0, discard=0) at xcb_io.c:625
#4  0x00000008044fa837 in XOpenDisplay (display=0x0) at OpenDis.c:563

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffb9c0,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450351d in XQueryExtension (dpy=0x807dfb000, name=0x80461e631
"XKEYBOARD", major_opcode=0x7fffffffba14, first_event=0x7fffffffba18,
first_error=0x7fffffffba1c) at QuExt.c:48
#5  0x00000008044f04eb in XInitExtension (dpy=0x807dfb000, name=0x80461e631
"XKEYBOARD") at InitExt.c:47
#6  0x00000008045945cb in XkbUseExtension (dpy=0x807dfb000, major_rtrn=0x0,
minor_rtrn=0x0) at XKBUse.c:727
#7  0x00000008044fa98e in XOpenDisplay (display=0x0) at OpenDis.c:584

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffb9c0,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450351d in XQueryExtension (dpy=0x807dfb000, name=0x80461e631
"XKEYBOARD", major_opcode=0x7fffffffba14, first_event=0x7fffffffba18,
first_error=0x7fffffffba1c) at QuExt.c:48
#5  0x00000008044f04eb in XInitExtension (dpy=0x807dfb000, name=0x80461e631
"XKEYBOARD") at InitExt.c:47
#6  0x00000008045945cb in XkbUseExtension (dpy=0x807dfb000, major_rtrn=0x0,
minor_rtrn=0x0) at XKBUse.c:727
#7  0x00000008044fa98e in XOpenDisplay (display=0x0) at OpenDis.c:584

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffba60,
extra=0, discard=0) at xcb_io.c:625
#4  0x000000080459477c in XkbUseExtension (dpy=0x807dfb000, major_rtrn=0x0,
minor_rtrn=0x0) at XKBUse.c:743
#5  0x00000008044fa98e in XOpenDisplay (display=0x0) at OpenDis.c:584

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffbc50,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450351d in XQueryExtension (dpy=0x807dfb000, name=0x801553c47
"RENDER", major_opcode=0x807cca23c, first_event=0x7fffffffc6d0,
first_error=0x7fffffffc6cc) at QuExt.c:48


#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffbb70,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450351d in XQueryExtension (dpy=0x807dfb000, name=0x804075a60
"RENDER", major_opcode=0x7fffffffbbc4, first_event=0x7fffffffbbc8,
first_error=0x7fffffffbbcc) at QuExt.c:48
#5  0x00000008044f04eb in XInitExtension (dpy=0x807dfb000, name=0x804075a60
"RENDER") at InitExt.c:47
#6  0x0000000803e73c02 in XRenderFindDisplay () from
/usr/local/lib/libXrender.so.1
#7  0x0000000803e74aa9 in XRenderQueryExtension () from
/usr/local/lib/libXrender.so.1

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffbbb0,
extra=0, discard=0) at xcb_io.c:625
#4  0x0000000803e741cf in XRenderQueryFormats () from
/usr/local/lib/libXrender.so.1
#5  0x0000000803e74a4d in XRenderQueryVersion () from
/usr/local/lib/libXrender.so.1

<after a while>
#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffc490,
extra=0, discard=0) at xcb_io.c:625
#4  0x00000008044ead2f in XGetWindowProperty (dpy=0x807dfb000, w=138412037,
property=256, offset=0, length=5, delete=0, req_type=256,
actual_type=0x7fffffffc528, actual_format=0x7fffffffc534,
nitems=0x7fffffffc520, bytesafter=0x7fffffffc518, prop=0x7fffffffc510) at
GetProp.c:61
#5  0x0000000800ed5aa0 in GetMWMHints(_XDisplay*, unsigned long) () from
/usr/local/lib/qt4/libQtGui.so.4
#6  0x0000000800ed98da in QWidgetPrivate::show_sys() () from
/usr/local/lib/qt4/libQtGui.so.4



#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffbed0,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450cc90 in XSync (dpy=0x807dfb000, discard=0) at Sync.c:44
#5  0x0000000800eb2198 in QETWidget::translateConfigEvent(_XEvent const*) ()
from /usr/local/lib/qt4/libQtGui.so.4

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffabc0,
extra=0, discard=1) at xcb_io.c:625
#4  0x000000080450f70f in XTranslateCoordinates (dpy=0x807dfb000, src_win=346,
dest_win=138412037, src_x=456, src_y=244, dst_x=0x7fffffffac0c,
dst_y=0x7fffffffac08, child=0x7fffffffac00) at TrCoords.c:51
#5  0x0000000800edacde in QWidgetPrivate::mapFromGlobal(QPoint const&) const ()
from /usr/local/lib/qt4/libQtGui.so.4

#0  _xcb_in_read (c=0x807e42000) at xcb_in.c:680
#1  0x00000008052af1c8 in xcb_poll_for_event (c=0x807e42000) at xcb_in.c:551
#2  0x0000000804512d3b in poll_for_event (dpy=0x807dfb000) at xcb_io.c:256
#3  0x0000000804513ca9 in _XReply (dpy=0x807dfb000, rep=0x7fffffffb210,
extra=0, discard=1) at xcb_io.c:625
#4  0x00000008045037ea in XQueryPointer (dpy=0x807dfb000, w=346,
root=0x7fffffffb298, child=0x7fffffffb290, root_x=0x7fffffffb2b4,
root_y=0x7fffffffb2b0, win_x=0x7fffffffb2ac, win_y=0x7fffffffb2a8,
mask=0x7fffffffb2a4) at QuPntr.c:48
#5  0x0000000800ec9d1d in QCursor::pos() () from
/usr/local/lib/qt4/libQtGui.so.4

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA Contact for the bug.
You are the assignee for the bug.


More information about the Xcb mailing list