|
|
1.1 ! root 1: /* ! 2: * Linux scheduling support. ! 3: * ! 4: * Copyright (C) 1996 The University of Utah and the Computer Systems ! 5: * Laboratory at the University of Utah (CSL) ! 6: * ! 7: * This program is free software; you can redistribute it and/or modify ! 8: * it under the terms of the GNU General Public License as published by ! 9: * the Free Software Foundation; either version 2, or (at your option) ! 10: * any later version. ! 11: * ! 12: * This program is distributed in the hope that it will be useful, ! 13: * but WITHOUT ANY WARRANTY; without even the implied warranty of ! 14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 15: * GNU General Public License for more details. ! 16: * ! 17: * You should have received a copy of the GNU General Public License ! 18: * along with this program; if not, write to the Free Software ! 19: * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ! 20: * ! 21: * Author: Shantanu Goel, University of Utah CSL ! 22: */ ! 23: ! 24: /* ! 25: * linux/kernel/sched.c ! 26: * ! 27: * Copyright (C) 1991, 1992 Linus Torvalds ! 28: */ ! 29: ! 30: #include <sys/types.h> ! 31: ! 32: #include <mach/boolean.h> ! 33: ! 34: #include <kern/thread.h> ! 35: #include <kern/sched_prim.h> ! 36: ! 37: #include <i386at/gpl/linux/linux_emul.h> ! 38: ! 39: #define MACH_INCLUDE ! 40: #include <linux/sched.h> ! 41: #include <linux/fs.h> ! 42: #include <linux/blkdev.h> ! 43: ! 44: #include <asm/system.h> ! 45: ! 46: struct tq_struct tq_last = ! 47: { ! 48: &tq_last, 0, 0, 0 ! 49: }; ! 50: ! 51: DECLARE_TASK_QUEUE(tq_timer); ! 52: ! 53: static struct wait_queue **auto_config_queue; ! 54: ! 55: void ! 56: tqueue_bh (void *unused) ! 57: { ! 58: run_task_queue(&tq_timer); ! 59: } ! 60: ! 61: void ! 62: add_wait_queue (struct wait_queue **q, struct wait_queue *wait) ! 63: { ! 64: unsigned long flags; ! 65: ! 66: if (! linux_auto_config) ! 67: { ! 68: save_flags (flags); ! 69: cli (); ! 70: assert_wait ((event_t) q, FALSE); ! 71: restore_flags (flags); ! 72: return; ! 73: } ! 74: ! 75: if (auto_config_queue) ! 76: printf ("add_wait_queue: queue not empty\n"); ! 77: auto_config_queue = q; ! 78: } ! 79: ! 80: void ! 81: remove_wait_queue (struct wait_queue **q, struct wait_queue *wait) ! 82: { ! 83: unsigned long flags; ! 84: ! 85: if (! linux_auto_config) ! 86: { ! 87: save_flags (flags); ! 88: thread_wakeup ((event_t) q); ! 89: restore_flags (flags); ! 90: return; ! 91: } ! 92: ! 93: auto_config_queue = NULL; ! 94: } ! 95: ! 96: void ! 97: __down (struct semaphore *sem) ! 98: { ! 99: int s; ! 100: unsigned long flags; ! 101: ! 102: if (! linux_auto_config) ! 103: { ! 104: save_flags (flags); ! 105: s = splhigh (); ! 106: while (sem->count <= 0) ! 107: { ! 108: assert_wait ((event_t) &sem->wait, FALSE); ! 109: splx (s); ! 110: thread_block (0); ! 111: s = splhigh (); ! 112: } ! 113: splx (s); ! 114: restore_flags (flags); ! 115: return; ! 116: } ! 117: ! 118: while (sem->count <= 0) ! 119: barrier (); ! 120: } ! 121: ! 122: void ! 123: __sleep_on (struct wait_queue **q, int interruptible) ! 124: { ! 125: unsigned long flags; ! 126: ! 127: if (! q) ! 128: return; ! 129: save_flags (flags); ! 130: if (! linux_auto_config) ! 131: { ! 132: assert_wait ((event_t) q, interruptible); ! 133: sti (); ! 134: thread_block (0); ! 135: restore_flags (flags); ! 136: return; ! 137: } ! 138: ! 139: add_wait_queue (q, NULL); ! 140: sti (); ! 141: while (auto_config_queue) ! 142: barrier (); ! 143: restore_flags (flags); ! 144: } ! 145: ! 146: void ! 147: sleep_on (struct wait_queue **q) ! 148: { ! 149: __sleep_on (q, FALSE); ! 150: } ! 151: ! 152: void ! 153: interruptible_sleep_on (struct wait_queue **q) ! 154: { ! 155: __sleep_on (q, TRUE); ! 156: } ! 157: ! 158: void ! 159: wake_up (struct wait_queue **q) ! 160: { ! 161: unsigned long flags; ! 162: ! 163: if (! linux_auto_config) ! 164: { ! 165: if (q != &wait_for_request) ! 166: { ! 167: save_flags (flags); ! 168: thread_wakeup ((event_t) q); ! 169: restore_flags (flags); ! 170: } ! 171: return; ! 172: } ! 173: ! 174: if (auto_config_queue == q) ! 175: auto_config_queue = NULL; ! 176: } ! 177: ! 178: void ! 179: __wait_on_buffer (struct buffer_head *bh) ! 180: { ! 181: unsigned long flags; ! 182: ! 183: save_flags (flags); ! 184: if (! linux_auto_config) ! 185: { ! 186: while (1) ! 187: { ! 188: cli (); ! 189: if (! buffer_locked (bh)) ! 190: break; ! 191: bh->b_wait = (struct wait_queue *) 1; ! 192: assert_wait ((event_t) bh, FALSE); ! 193: sti (); ! 194: thread_block (0); ! 195: } ! 196: restore_flags (flags); ! 197: return; ! 198: } ! 199: ! 200: sti (); ! 201: while (buffer_locked (bh)) ! 202: barrier (); ! 203: restore_flags (flags); ! 204: } ! 205: ! 206: void ! 207: unlock_buffer (struct buffer_head *bh) ! 208: { ! 209: unsigned long flags; ! 210: ! 211: save_flags (flags); ! 212: cli (); ! 213: clear_bit (BH_Lock, &bh->b_state); ! 214: if (bh->b_wait && ! linux_auto_config) ! 215: { ! 216: bh->b_wait = NULL; ! 217: thread_wakeup ((event_t) bh); ! 218: } ! 219: restore_flags (flags); ! 220: } ! 221: ! 222: void ! 223: schedule () ! 224: { ! 225: if (! linux_auto_config) ! 226: thread_block (0); ! 227: } ! 228: ! 229: void ! 230: cdrom_sleep (int t) ! 231: { ! 232: int xxx; ! 233: ! 234: assert_wait ((event_t) &xxx, TRUE); ! 235: thread_set_timeout (t); ! 236: thread_block (0); ! 237: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.