dix/os: Merge priority computation into SmartScheduleClient
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@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
parent
4af00242ef
commit
7762a602c1
|
@ -244,15 +244,13 @@ void Dispatch(void);
|
||||||
static int
|
static int
|
||||||
SmartScheduleClient(int *clientReady, int nready)
|
SmartScheduleClient(int *clientReady, int nready)
|
||||||
{
|
{
|
||||||
ClientPtr pClient;
|
|
||||||
int i;
|
int i;
|
||||||
int client;
|
int client;
|
||||||
int bestPrio, best = 0;
|
ClientPtr pClient, best = NULL;
|
||||||
int bestRobin, robin;
|
int bestRobin, robin;
|
||||||
long now = SmartScheduleTime;
|
long now = SmartScheduleTime;
|
||||||
long idle;
|
long idle;
|
||||||
|
|
||||||
bestPrio = -0x7fffffff;
|
|
||||||
bestRobin = 0;
|
bestRobin = 0;
|
||||||
idle = 2 * SmartScheduleSlice;
|
idle = 2 * SmartScheduleSlice;
|
||||||
for (i = 0; i < nready; i++) {
|
for (i = 0; i < nready; i++) {
|
||||||
|
@ -269,11 +267,16 @@ SmartScheduleClient(int *clientReady, int nready)
|
||||||
(pClient->index -
|
(pClient->index -
|
||||||
SmartLastIndex[pClient->smart_priority -
|
SmartLastIndex[pClient->smart_priority -
|
||||||
SMART_MIN_PRIORITY]) & 0xff;
|
SMART_MIN_PRIORITY]) & 0xff;
|
||||||
if (pClient->smart_priority > bestPrio ||
|
|
||||||
(pClient->smart_priority == bestPrio && robin > bestRobin)) {
|
/* pick the best client */
|
||||||
bestPrio = pClient->smart_priority;
|
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;
|
bestRobin = robin;
|
||||||
best = client;
|
|
||||||
}
|
}
|
||||||
#ifdef SMART_DEBUG
|
#ifdef SMART_DEBUG
|
||||||
if ((now - SmartLastPrint) >= 5000)
|
if ((now - SmartLastPrint) >= 5000)
|
||||||
|
@ -286,8 +289,7 @@ SmartScheduleClient(int *clientReady, int nready)
|
||||||
SmartLastPrint = now;
|
SmartLastPrint = now;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
pClient = clients[best];
|
SmartLastIndex[best->smart_priority - SMART_MIN_PRIORITY] = best->index;
|
||||||
SmartLastIndex[bestPrio - SMART_MIN_PRIORITY] = pClient->index;
|
|
||||||
/*
|
/*
|
||||||
* Set current client pointer
|
* Set current client pointer
|
||||||
*/
|
*/
|
||||||
|
@ -312,7 +314,7 @@ SmartScheduleClient(int *clientReady, int nready)
|
||||||
else {
|
else {
|
||||||
SmartScheduleSlice = SmartScheduleInterval;
|
SmartScheduleSlice = SmartScheduleInterval;
|
||||||
}
|
}
|
||||||
return best;
|
return best->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
33
os/WaitFor.c
33
os/WaitFor.c
|
@ -326,17 +326,14 @@ WaitForSomething(int *pClientsReady)
|
||||||
if (XFD_ANYSET(&clientsReadable)) {
|
if (XFD_ANYSET(&clientsReadable)) {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
|
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
|
||||||
int highest_priority = 0;
|
|
||||||
|
|
||||||
while (clientsReadable.fds_bits[i]) {
|
while (clientsReadable.fds_bits[i]) {
|
||||||
int client_priority, client_index;
|
int client_index;
|
||||||
|
|
||||||
curclient = mffs(clientsReadable.fds_bits[i]) - 1;
|
curclient = mffs(clientsReadable.fds_bits[i]) - 1;
|
||||||
client_index = /* raphael: modified */
|
client_index = /* raphael: modified */
|
||||||
ConnectionTranslation[curclient +
|
ConnectionTranslation[curclient +
|
||||||
(i * (sizeof(fd_mask) * 8))];
|
(i * (sizeof(fd_mask) * 8))];
|
||||||
#else
|
#else
|
||||||
int highest_priority = 0;
|
|
||||||
fd_set savedClientsReadable;
|
fd_set savedClientsReadable;
|
||||||
|
|
||||||
XFD_COPYSET(&clientsReadable, &savedClientsReadable);
|
XFD_COPYSET(&clientsReadable, &savedClientsReadable);
|
||||||
|
@ -346,33 +343,7 @@ WaitForSomething(int *pClientsReady)
|
||||||
curclient = XFD_FD(&savedClientsReadable, i);
|
curclient = XFD_FD(&savedClientsReadable, i);
|
||||||
client_index = GetConnectionTranslation(curclient);
|
client_index = GetConnectionTranslation(curclient);
|
||||||
#endif
|
#endif
|
||||||
/* We implement "strict" priorities.
|
pClientsReady[nready++] = client_index;
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
clientsReadable.fds_bits[i] &= ~(((fd_mask) 1L) << curclient);
|
clientsReadable.fds_bits[i] &= ~(((fd_mask) 1L) << curclient);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue