From 7babda5d4573d432441a416f880cb8cc8c15b55b Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 31 Jul 2018 23:48:38 +1000 Subject: Modified the scheduler so that a HLT instruction is executed if no runnable task is found. This is a very basic method of putting the CPU into an idle state to reduce power consumption and heat production. This method is far from perfect however since when the CPU is woken by a timer interrupt, the scheduler runs through the entire process table again regardless of whether any task has become runnable, before putting the CPU back to sleep. In practice, this basic sleep mechanism reduced idle CPU usage of the VM from 100% to ~6%, a very effective amount. Updated the sleep() library function to use the new sys_alarm and sys_pause system calls. This method works by first registering a dummy signal handler, setting an alarm and finally calling pause() to put the process to sleep. When the alarm expires, the dummy signal handler is called (which returns immediately) and finally, the sleep() call returns. Note however, that this is a temporary function implemented poorly since it overwrites any pending alarms as well as the SIGALRM handler. --- lib/time.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/time.c b/lib/time.c index 0f4a251..ab28f71 100644 --- a/lib/time.c +++ b/lib/time.c @@ -1,3 +1,4 @@ +#include #include #include @@ -5,8 +6,10 @@ _syscall0(time_t, time); _syscall1(int, alarm, unsigned int, seconds); -void sleep(time_t t) { - time_t start = time(); +static void sleepsig(int sig) {} - while(time() < start + t); +void sleep(time_t t) { + signal(SIGALRM, &sleepsig); + alarm(t); + pause(); } -- cgit v1.3