[PATCH xserver 1/4] dix: Push UpdateCurrentTimeIf down out of the main loop

Adam Jackson ajax at redhat.com
Fri Apr 29 18:22:51 UTC 2016


This was added in:

    commit 312910b4e34215aaa50fc0c6092684d5878dc32f
    Author: Chase Douglas <chase.douglas at canonical.com>
    Date:   Wed Apr 18 11:15:40 2012 -0700

        Update currentTime in dispatch loop

Unfortunately this is equivalent to calling GetTimeInMillis() once per
request. In the absolute best case (as on Linux) you're only hitting the
vDSO; on other platforms that's a syscall. Either way it puts a pretty
hard ceiling on request throughput.

Instead, push the call down to the requests that need it; basically,
grab processing and event generation.

Cc: Chase Douglas <chase.douglas at canonical.com>
Cc: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 Xext/shape.c     |  1 +
 Xi/extinit.c     |  2 ++
 Xi/xiproperty.c  |  6 +++++-
 dix/devices.c    | 16 ++++++++++------
 dix/dispatch.c   |  5 +----
 dix/enterleave.c |  1 +
 dix/events.c     |  6 ++++++
 dix/property.c   | 12 ++++++------
 dix/selection.c  |  3 +++
 randr/randr.c    |  2 ++
 xfixes/cursor.c  |  1 +
 xfixes/select.c  |  1 +
 12 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/Xext/shape.c b/Xext/shape.c
index 2fc789e..142f9c1 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -881,6 +881,7 @@ SendShapeNotify(WindowPtr pWin, int which)
     default:
         return;
     }
+    UpdateCurrentTimeIf();
     for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) {
         xShapeNotifyEvent se = {
             .type = ShapeNotify + ShapeEventBase,
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 26c628c..75f3832 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -406,6 +406,7 @@ ProcIDispatch(ClientPtr client)
     if (stuff->data >= ARRAY_SIZE(ProcIVector) || !ProcIVector[stuff->data])
         return BadRequest;
 
+    UpdateCurrentTimeIf();
     return (*ProcIVector[stuff->data]) (client);
 }
 
@@ -425,6 +426,7 @@ SProcIDispatch(ClientPtr client)
     if (stuff->data >= ARRAY_SIZE(SProcIVector) || !SProcIVector[stuff->data])
         return BadRequest;
 
+    UpdateCurrentTimeIf();
     return (*SProcIVector[stuff->data]) (client);
 }
 
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index e3b8f5a..26d1206 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -622,6 +622,7 @@ XIDeleteAllDeviceProperties(DeviceIntPtr device)
     XIPropertyPtr prop, next;
     XIPropertyHandlerPtr curr_handler, next_handler;
 
+    UpdateCurrentTimeIf();
     for (prop = device->properties.properties; prop; prop = next) {
         next = prop->next;
         send_property_event(device, prop->propertyName, XIPropertyDeleted);
@@ -672,6 +673,7 @@ XIDeleteDeviceProperty(DeviceIntPtr device, Atom property, Bool fromClient)
     }
 
     if (prop) {
+        UpdateCurrentTimeIf();
         *prev = prop->next;
         send_property_event(device, prop->propertyName, XIPropertyDeleted);
         XIDestroyDeviceProperty(prop);
@@ -793,9 +795,11 @@ XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
         dev->properties.properties = prop;
     }
 
-    if (sendevent)
+    if (sendevent) {
+        UpdateCurrentTimeIf();
         send_property_event(dev, prop->propertyName,
                             (add) ? XIPropertyCreated : XIPropertyModified);
+    }
 
     return Success;
 }
diff --git a/dix/devices.c b/dix/devices.c
index a532dcf..fcd0c08 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -281,6 +281,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     dev->startup = autoStart;
 
     /* device grab defaults */
+    UpdateCurrentTimeIf();
     dev->deviceGrab.grabTime = currentTime;
     dev->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
     dev->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
@@ -336,12 +337,13 @@ void
 SendDevicePresenceEvent(int deviceid, int type)
 {
     DeviceIntRec dummyDev = { .id =  XIAllDevices };
-    devicePresenceNotify ev = {
-        .type = DevicePresenceNotify,
-        .time = currentTime.milliseconds,
-        .devchange = type,
-        .deviceid = deviceid
-    };
+    devicePresenceNotify ev;
+
+    UpdateCurrentTimeIf();
+    ev.type = DevicePresenceNotify;
+    ev.time = currentTime.milliseconds;
+    ev.devchange = type;
+    ev.deviceid = deviceid;
 
     SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
                           (xEvent *) &ev, 1);
@@ -1403,6 +1405,7 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev)
     focc = malloc(sizeof(FocusClassRec));
     if (!focc)
         return FALSE;
+    UpdateCurrentTimeIf();
     focc->win = PointerRootWin;
     focc->revert = None;
     focc->time = currentTime;
@@ -2354,6 +2357,7 @@ ProcGetMotionEvents(ClientPtr client)
     if (rc != Success)
         return rc;
 
+    UpdateCurrentTimeIf();
     if (mouse->valuator->motionHintWindow)
         MaybeStopHint(mouse, client);
     rep = (xGetMotionEventsReply) {
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 53032dc..26122c1 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -393,11 +393,8 @@ Dispatch(void)
                         client->smart_priority--;
                     break;
                 }
+
                 /* now, finally, deal with client requests */
-
-                /* Update currentTime so request time checks, such as for input
-                 * device grabs, are calculated correctly */
-                UpdateCurrentTimeIf();
                 result = ReadRequestFromClient(client);
                 if (result <= 0) {
                     if (result < 0)
diff --git a/dix/enterleave.c b/dix/enterleave.c
index f0b1572..0fba8bd 100644
--- a/dix/enterleave.c
+++ b/dix/enterleave.c
@@ -782,6 +782,7 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
     DeviceIntPtr mouse;
     int btlen, len, i;
 
+    UpdateCurrentTimeIf();
     mouse = IsFloating(dev) ? dev : GetMaster(dev, MASTER_POINTER);
 
     /* XI 2 event */
diff --git a/dix/events.c b/dix/events.c
index efaf91d..0404eba 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1822,6 +1822,7 @@ ProcAllowEvents(ClientPtr client)
     REQUEST(xAllowEventsReq);
 
     REQUEST_SIZE_MATCH(xAllowEventsReq);
+    UpdateCurrentTime();
     time = ClientTimeToServerTime(stuff->time);
 
     mouse = PickPointer(client);
@@ -2241,6 +2242,7 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
                                    this mask is the mask of the grab. */
     int type = pEvents->u.u.type;
 
+    UpdateCurrentTimeIf();
     /* Deliver to window owner */
     if ((filter == CantBeFiltered) || core_get_type(pEvents) != 0) {
         enum EventDeliveryState rc;
@@ -4952,6 +4954,7 @@ ProcChangeActivePointerGrab(ClientPtr client)
         return Success;
     if (!SameClient(grab, client))
         return Success;
+    UpdateCurrentTime();
     time = ClientTimeToServerTime(stuff->time);
     if ((CompareTimeStamps(time, currentTime) == LATER) ||
         (CompareTimeStamps(time, device->deviceGrab.grabTime) == EARLIER))
@@ -5132,6 +5135,7 @@ ProcGrabKeyboard(ClientPtr client)
     GrabMask mask;
 
     REQUEST_SIZE_MATCH(xGrabKeyboardReq);
+    UpdateCurrentTime();
 
     mask.core = KeyPressMask | KeyReleaseMask;
 
@@ -5544,6 +5548,7 @@ ProcGrabButton(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xGrabButtonReq);
+    UpdateCurrentTime();
     if ((stuff->pointerMode != GrabModeSync) &&
         (stuff->pointerMode != GrabModeAsync)) {
         client->errorValue = stuff->pointerMode;
@@ -5632,6 +5637,7 @@ ProcUngrabButton(ClientPtr client)
     DeviceIntPtr ptr;
 
     REQUEST_SIZE_MATCH(xUngrabButtonReq);
+    UpdateCurrentTime();
     if ((stuff->modifiers != AnyModifier) &&
         (stuff->modifiers & ~AllModifiersMask)) {
         client->errorValue = stuff->modifiers;
diff --git a/dix/property.c b/dix/property.c
index 92c2558..bde2af8 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -108,12 +108,12 @@ dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName,
 static void
 deliverPropertyNotifyEvent(WindowPtr pWin, int state, Atom atom)
 {
-    xEvent event = {
-        .u.property.window = pWin->drawable.id,
-        .u.property.state = state,
-        .u.property.atom = atom,
-        .u.property.time = currentTime.milliseconds
-    };
+    xEvent event;
+    UpdateCurrentTimeIf();
+    event.u.property.window = pWin->drawable.id;
+    event.u.property.state = state;
+    event.u.property.atom = atom;
+    event.u.property.time = currentTime.milliseconds;
     event.u.u.type = PropertyNotify;
     DeliverEvents(pWin, &event, 1, (WindowPtr) NULL);
 }
diff --git a/dix/selection.c b/dix/selection.c
index 4e994b1..d46103f 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -279,6 +279,9 @@ ProcConvertSelection(ClientPtr client)
         return BadAtom;
     }
 
+    if (stuff->time == CurrentTime)
+        UpdateCurrentTime();
+
     rc = dixLookupSelection(&pSel, stuff->selection, client, DixReadAccess);
 
     memset(&event, 0, sizeof(xEvent));
diff --git a/randr/randr.c b/randr/randr.c
index ad1dda2..3aabb19 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -676,6 +676,7 @@ ProcRRDispatch(ClientPtr client)
     REQUEST(xReq);
     if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data])
         return BadRequest;
+    UpdateCurrentTimeIf();
     return (*ProcRandrVector[stuff->data]) (client);
 }
 
@@ -685,5 +686,6 @@ SProcRRDispatch(ClientPtr client)
     REQUEST(xReq);
     if (stuff->data >= RRNumberRequests || !SProcRandrVector[stuff->data])
         return BadRequest;
+    UpdateCurrentTimeIf();
     return (*SProcRandrVector[stuff->data]) (client);
 }
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 10f9b23..f009a78 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -153,6 +153,7 @@ CursorDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
     if (pCursor != CursorCurrent[pDev->id]) {
         CursorEventPtr e;
 
+        UpdateCurrentTimeIf();
         CursorCurrent[pDev->id] = pCursor;
         for (e = cursorEvents; e; e = e->next) {
             if ((e->eventMask & XFixesDisplayCursorNotifyMask)) {
diff --git a/xfixes/select.c b/xfixes/select.c
index e964d58..87a3ad7 100644
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -75,6 +75,7 @@ XFixesSelectionCallback(CallbackListPtr *callbacks, void *data, void *args)
     default:
         return;
     }
+    UpdateCurrentTimeIf();
     for (e = selectionEvents; e; e = e->next) {
         if (e->selection == selection->selection && (e->eventMask & eventMask)) {
             xXFixesSelectionNotifyEvent ev = {
-- 
2.7.4



More information about the xorg-devel mailing list