[PATCH xserver 13/25] dix/os: Merge priority computation into SmartScheduleClient
Keith Packard
keithp at keithp.com
Wed May 25 05:38:50 UTC 2016
Instead of having scheduling done in two places (one in
WaitForSomething, and the other in SmartScheduleClient), just stick
all of the scheduling in SmartScheduleClient.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
dix/dispatch.c | 17 ++++++++++-------
os/WaitFor.c | 33 ++-------------------------------
2 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index f7ac931..cd1e335 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -274,13 +274,11 @@ static ClientPtr
SmartScheduleClient(void)
{
ClientPtr pClient, best = NULL;
- int bestPrio;
int bestRobin, robin;
long now = SmartScheduleTime;
long idle;
int nready = 0;
- bestPrio = -0x7fffffff;
bestRobin = 0;
idle = 2 * SmartScheduleSlice;
@@ -298,11 +296,16 @@ SmartScheduleClient(void)
(pClient->index -
SmartLastIndex[pClient->smart_priority -
SMART_MIN_PRIORITY]) & 0xff;
- if (pClient->smart_priority > bestPrio ||
- (pClient->smart_priority == bestPrio && robin > bestRobin)) {
- bestPrio = pClient->smart_priority;
- bestRobin = robin;
+
+ /* pick the best client */
+ if (!best ||
+ pClient->priority > best->priority ||
+ (pClient->priority == best->priority &&
+ (pClient->smart_priority > best->smart_priority ||
+ (pClient->smart_priority == best->smart_priority && robin > bestRobin))))
+ {
best = pClient;
+ bestRobin = robin;
}
#ifdef SMART_DEBUG
if ((now - SmartLastPrint) >= 5000)
@@ -315,7 +318,7 @@ SmartScheduleClient(void)
SmartLastPrint = now;
}
#endif
- SmartLastIndex[bestPrio - SMART_MIN_PRIORITY] = best->index;
+ SmartLastIndex[best->smart_priority - SMART_MIN_PRIORITY] = best->index;
/*
* Set current client pointer
*/
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 994edf0..26673e4 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -326,17 +326,14 @@ WaitForSomething(int *pClientsReady)
if (XFD_ANYSET(&clientsReadable)) {
#ifndef WIN32
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
- int highest_priority = 0;
-
while (clientsReadable.fds_bits[i]) {
- int client_priority, client_index;
+ int client_index;
curclient = mffs(clientsReadable.fds_bits[i]) - 1;
client_index = /* raphael: modified */
ConnectionTranslation[curclient +
(i * (sizeof(fd_mask) * 8))];
#else
- int highest_priority = 0;
fd_set savedClientsReadable;
XFD_COPYSET(&clientsReadable, &savedClientsReadable);
@@ -346,33 +343,7 @@ WaitForSomething(int *pClientsReady)
curclient = XFD_FD(&savedClientsReadable, i);
client_index = GetConnectionTranslation(curclient);
#endif
- /* We implement "strict" priorities.
- * Only the highest priority client is returned to
- * dix. If multiple clients at the same priority are
- * ready, they are all returned. This means that an
- * aggressive client could take over the server.
- * This was not considered a big problem because
- * aggressive clients can hose the server in so many
- * other ways :)
- */
- client_priority = clients[client_index]->priority;
- if (nready == 0 || client_priority > highest_priority) {
- /* Either we found the first client, or we found
- * a client whose priority is greater than all others
- * that have been found so far. Either way, we want
- * to initialize the list of clients to contain just
- * this client.
- */
- pClientsReady[0] = client_index;
- highest_priority = client_priority;
- nready = 1;
- }
- /* the following if makes sure that multiple same-priority
- * clients get batched together
- */
- else if (client_priority == highest_priority) {
- pClientsReady[nready++] = client_index;
- }
+ pClientsReady[nready++] = client_index;
#ifndef WIN32
clientsReadable.fds_bits[i] &= ~(((fd_mask) 1L) << curclient);
}
--
2.8.0.rc3
More information about the xorg-devel
mailing list