[Xcb] Hangs with xcb_take_socket

Jamey Sharp jamey at minilop.net
Wed Nov 17 10:47:31 PST 2010


Hello!

On Wed, Nov 17, 2010 at 8:00 AM, Uli Schlachter <psychon at znc.in> wrote:
> This is problem that I've been hitting with cairo git/master's perf
> measurements. They trigger the hang described above (No, I don't know why cairo
> jumps through hoops to simulate an XLockDisplay()-like behavior).

Um. Chris? What did you *do*?

Why would you want to hand-write all the code that XCB normally
generates for you, inlined in cairo's source? The cairo XCB backend
looks completely insane now. I expect you had a good reason, but I
can't imagine what it is.

> let's consider the following events:
>
> I use xcb_take_socket(), current sequence number is 0xffff.
> I send 2*2^16 XRENDER requests, all of which don't cause any reply. This causes
> two sequence number wraps and the current sequence number is now 0x2fffff, but
> the X server will only report 0xffff in replies/events, so if xcb sees the next
> reply, it will expand it's sequence number to e.g. 0x1ffff when it really should
> have been 0x2ffff.
> I hope this makes the problem clear.

Yes, it does. XCB is normally careful to insert GetInputFocus requests
exactly when they're needed, but it can't insert requests when callers
use xcb_take_socket.

Here's the rule: Keep track of the sequence number of the last
response you received. If
request >= last_response + (1 << 16) - 2
then you need to issue a sync first.

Note that this means that when you haven't received any responses yet,
you need to sync immediately after calling xcb_take_socket.

As an optimization, if you know the request you're about to issue has
a reply, then you don't need to sync. Also, in that case you can set
last_response to the sequence number of the current request, even
though you haven't received that response yet; that will delay your
next sync.

You can always choose to issue syncs sooner than the above rules
imply, of course.

By the way, you don't have to *wait* for the sync reply. You just have
to remember that you issued it so you can ignore the response when it
arrives.

And of course you don't have to do any of this if you don't use
xcb_take_socket, which I would recommend. :-)

Jamey


More information about the Xcb mailing list