Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/sched/sched.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "arch/i386.h"
0019 #include "arch/i386-percpu.h"
0020 #include "kernel.h"
0021 #include "smp/smp.h"
0022 #include "smp/apic.h"
0023 #include "util/debug.h"
0024 #include "sched/sched.h"
0025 
0026 #define QUEST_SCHED vcpu        /* Use the VCPU scheduler */
0027 
0028 //#define DEBUG_SCHED
0029 #ifdef DEBUG_SCHED
0030 #define DLOG(fmt,...) DLOG_PREFIX("sched",fmt,##__VA_ARGS__)
0031 #else
0032 #define DLOG(fmt,...) ;
0033 #endif
0034 
0035 /* ************************************************** */
0036 uint8 sched_enabled = 0;
0037 
0038 /* These functions assume exclusive access to the queue. */
0039 extern void
0040 queue_append (uint16 * queue, uint16 selector)
0041 {
0042 
0043   quest_tss *tssp;
0044 
0045   if (*queue) {
0046     if (*queue == selector)
0047       return;                   /* already on queue */
0048 
0049     for (tssp = lookup_TSS (*queue); tssp->next; tssp = lookup_TSS (tssp->next))
0050       if (tssp->next == selector)
0051         /* already on queue */
0052         return;
0053 
0054     /* add to end of queue */
0055     tssp->next = selector;
0056 
0057   } else
0058     *queue = selector;
0059 
0060   tssp = lookup_TSS (selector);
0061   tssp->next = 0;
0062 
0063 }
0064 
0065 extern uint16
0066 queue_remove_head (uint16 * queue)
0067 {
0068 
0069   quest_tss *tssp;
0070   uint16 head;
0071 
0072   if (!(head = *queue))
0073     return 0;
0074 
0075   tssp = lookup_TSS (head);
0076 
0077   *queue = tssp->next;
0078 
0079   return head;
0080 }
0081 
0082 extern void
0083 wakeup_queue (uint16 * q)
0084 {
0085   uint16 head;
0086 
0087   while ((head = queue_remove_head (q)))
0088     wakeup (head);
0089 }
0090 
0091 /* ************************************************** */
0092 
0093 DEF_PER_CPU (u16, current_task);
0094 INIT_PER_CPU (current_task) {
0095   percpu_write (current_task, 0);
0096 }
0097 
0098 /* Hooks for scheduler */
0099 
0100 #define ___glue(a,b) a##b
0101 #define __glue(a,b) ___glue(a,b)
0102 #define S __glue(QUEST_SCHED,_schedule)
0103 #define W __glue(QUEST_SCHED,_wakeup)
0104 extern void S (void);
0105 void (*schedule) (void) = S;
0106 extern void W (uint16);
0107 void (*wakeup) (uint16) = W;
0108 
0109 /*
0110  * Local Variables:
0111  * indent-tabs-mode: nil
0112  * mode: C
0113  * c-file-style: "gnu"
0114  * c-basic-offset: 2
0115  * End:
0116  */
0117 
0118 /* vi: set et sw=2 sts=2: */