reduce wakeups from smart scheduler
The smart scheduler itimer currently always fires after each request (which in turn causes the CPU to wake out of idle, burning precious power). Rather than doing this, just stop the timer before going into the select() portion of the WaitFor loop. It's a cheap system call, and it will only get called if there's no more commands batched up from the active fd. This change also allows some of the functions to be simplified; setitimer() will only fail if it's passed invalid data, and we don't do that... so make it void and remove all the conditional code that deals with failure. The change also allows us to remove a few variables that were used for housekeeping between the signal handler and the main loop. Signed-off-by: Keith Packard <keithp@koto.keithp.com>
This commit is contained in:
parent
692654b430
commit
2338d5c991
|
@ -150,11 +150,9 @@ extern long SmartScheduleTime;
|
||||||
extern long SmartScheduleInterval;
|
extern long SmartScheduleInterval;
|
||||||
extern long SmartScheduleSlice;
|
extern long SmartScheduleSlice;
|
||||||
extern long SmartScheduleMaxSlice;
|
extern long SmartScheduleMaxSlice;
|
||||||
extern unsigned long SmartScheduleIdleCount;
|
|
||||||
extern Bool SmartScheduleDisable;
|
extern Bool SmartScheduleDisable;
|
||||||
extern Bool SmartScheduleIdle;
|
extern void SmartScheduleStartTimer(void);
|
||||||
extern Bool SmartScheduleTimerStopped;
|
extern void SmartScheduleStopTimer(void);
|
||||||
extern Bool SmartScheduleStartTimer(void);
|
|
||||||
#define SMART_MAX_PRIORITY (20)
|
#define SMART_MAX_PRIORITY (20)
|
||||||
#define SMART_MIN_PRIORITY (-20)
|
#define SMART_MIN_PRIORITY (-20)
|
||||||
|
|
||||||
|
|
11
os/WaitFor.c
11
os/WaitFor.c
|
@ -217,7 +217,8 @@ WaitForSomething(int *pClientsReady)
|
||||||
XFD_COPYSET(&AllSockets, &LastSelectMask);
|
XFD_COPYSET(&AllSockets, &LastSelectMask);
|
||||||
#ifdef SMART_SCHEDULE
|
#ifdef SMART_SCHEDULE
|
||||||
}
|
}
|
||||||
SmartScheduleIdle = TRUE;
|
SmartScheduleStopTimer ();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
BlockHandler((pointer)&wt, (pointer)&LastSelectMask);
|
BlockHandler((pointer)&wt, (pointer)&LastSelectMask);
|
||||||
if (NewOutputPending)
|
if (NewOutputPending)
|
||||||
|
@ -237,13 +238,7 @@ WaitForSomething(int *pClientsReady)
|
||||||
selecterr = GetErrno();
|
selecterr = GetErrno();
|
||||||
WakeupHandler(i, (pointer)&LastSelectMask);
|
WakeupHandler(i, (pointer)&LastSelectMask);
|
||||||
#ifdef SMART_SCHEDULE
|
#ifdef SMART_SCHEDULE
|
||||||
if (i >= 0)
|
SmartScheduleStartTimer ();
|
||||||
{
|
|
||||||
SmartScheduleIdle = FALSE;
|
|
||||||
SmartScheduleIdleCount = 0;
|
|
||||||
if (SmartScheduleTimerStopped)
|
|
||||||
(void) SmartScheduleStartTimer ();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (i <= 0) /* An error or timeout occurred */
|
if (i <= 0) /* An error or timeout occurred */
|
||||||
{
|
{
|
||||||
|
|
28
os/utils.c
28
os/utils.c
|
@ -1513,10 +1513,6 @@ XNFstrdup(const char *s)
|
||||||
|
|
||||||
#ifdef SMART_SCHEDULE
|
#ifdef SMART_SCHEDULE
|
||||||
|
|
||||||
unsigned long SmartScheduleIdleCount;
|
|
||||||
Bool SmartScheduleIdle;
|
|
||||||
Bool SmartScheduleTimerStopped;
|
|
||||||
|
|
||||||
#ifdef SIGVTALRM
|
#ifdef SIGVTALRM
|
||||||
#define SMART_SCHEDULE_POSSIBLE
|
#define SMART_SCHEDULE_POSSIBLE
|
||||||
#endif
|
#endif
|
||||||
|
@ -1526,7 +1522,7 @@ Bool SmartScheduleTimerStopped;
|
||||||
#define SMART_SCHEDULE_TIMER ITIMER_REAL
|
#define SMART_SCHEDULE_TIMER ITIMER_REAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
void
|
||||||
SmartScheduleStopTimer (void)
|
SmartScheduleStopTimer (void)
|
||||||
{
|
{
|
||||||
#ifdef SMART_SCHEDULE_POSSIBLE
|
#ifdef SMART_SCHEDULE_POSSIBLE
|
||||||
|
@ -1537,38 +1533,28 @@ SmartScheduleStopTimer (void)
|
||||||
timer.it_value.tv_sec = 0;
|
timer.it_value.tv_sec = 0;
|
||||||
timer.it_value.tv_usec = 0;
|
timer.it_value.tv_usec = 0;
|
||||||
(void) setitimer (ITIMER_REAL, &timer, 0);
|
(void) setitimer (ITIMER_REAL, &timer, 0);
|
||||||
SmartScheduleTimerStopped = TRUE;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool
|
void
|
||||||
SmartScheduleStartTimer (void)
|
SmartScheduleStartTimer (void)
|
||||||
{
|
{
|
||||||
#ifdef SMART_SCHEDULE_POSSIBLE
|
#ifdef SMART_SCHEDULE_POSSIBLE
|
||||||
struct itimerval timer;
|
struct itimerval timer;
|
||||||
|
|
||||||
SmartScheduleTimerStopped = FALSE;
|
|
||||||
timer.it_interval.tv_sec = 0;
|
timer.it_interval.tv_sec = 0;
|
||||||
timer.it_interval.tv_usec = SmartScheduleInterval * 1000;
|
timer.it_interval.tv_usec = SmartScheduleInterval * 1000;
|
||||||
timer.it_value.tv_sec = 0;
|
timer.it_value.tv_sec = 0;
|
||||||
timer.it_value.tv_usec = SmartScheduleInterval * 1000;
|
timer.it_value.tv_usec = SmartScheduleInterval * 1000;
|
||||||
return setitimer (ITIMER_REAL, &timer, 0) >= 0;
|
setitimer (ITIMER_REAL, &timer, 0);
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SMART_SCHEDULE_POSSIBLE
|
#ifdef SMART_SCHEDULE_POSSIBLE
|
||||||
static void
|
static void
|
||||||
SmartScheduleTimer (int sig)
|
SmartScheduleTimer (int sig)
|
||||||
{
|
{
|
||||||
int olderrno = errno;
|
|
||||||
|
|
||||||
SmartScheduleTime += SmartScheduleInterval;
|
SmartScheduleTime += SmartScheduleInterval;
|
||||||
if (SmartScheduleIdle)
|
|
||||||
{
|
|
||||||
SmartScheduleStopTimer ();
|
|
||||||
}
|
|
||||||
errno = olderrno;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1592,14 +1578,6 @@ SmartScheduleInit (void)
|
||||||
perror ("sigaction for smart scheduler");
|
perror ("sigaction for smart scheduler");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
/* Set up the virtual timer */
|
|
||||||
if (!SmartScheduleStartTimer ())
|
|
||||||
{
|
|
||||||
perror ("scheduling timer");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
/* stop the timer and wait for WaitForSomething to start it */
|
|
||||||
SmartScheduleStopTimer ();
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in New Issue