--- Gnu-Mach/kern/sched_prim.c 2020/09/02 04:42:39 1.1.1.2 +++ Gnu-Mach/kern/sched_prim.c 2020/09/02 04:45:10 1.1.1.3 @@ -32,19 +32,18 @@ * */ -#include -#include -#include -#include -#include -#include -#include - +#include #include +#include +#include /* For def'n of splsched() */ +#include #include #include #include +#include #include +#include +#include #include #include #include @@ -53,19 +52,14 @@ #include #include #include -#include #include #include #include -#include /* For def'n of splsched() */ #if MACH_FIXPRI #include #endif /* MACH_FIXPRI */ - -extern int hz; - int min_quantum; /* defines max context switch rate */ unsigned sched_tick; @@ -76,8 +70,6 @@ int sched_usec; thread_t sched_thread_id; -void recompute_priorities(void); /* forward */ -void update_priority(thread_t); void set_pri(thread_t, int, boolean_t); void do_thread_scan(void); @@ -147,14 +139,14 @@ void thread_check(thread_t, run_queue_t) * The wait event hash table declarations are as follows: */ -#define NUMQUEUES 59 +#define NUMQUEUES 1031 queue_head_t wait_queue[NUMQUEUES]; decl_simple_lock_data(, wait_lock[NUMQUEUES]) /* NOTE: we want a small positive integer out of this */ #define wait_hash(event) \ - ((((int)(event) < 0) ? ~(int)(event) : (int)(event)) % NUMQUEUES) + ((((long)(event) < 0) ? ~(long)(event) : (long)(event)) % NUMQUEUES) void wait_queue_init(void) { @@ -168,8 +160,8 @@ void wait_queue_init(void) void sched_init(void) { - recompute_priorities_timer.fcn = (int (*)())recompute_priorities; - recompute_priorities_timer.param = (char *)0; + recompute_priorities_timer.fcn = recompute_priorities; + recompute_priorities_timer.param = NULL; min_quantum = hz / 10; /* context switch 10 times/second */ wait_queue_init(); @@ -188,8 +180,9 @@ void sched_init(void) * Called at splsoftclock. */ void thread_timeout( - thread_t thread) + void *_thread) { + thread_t thread = _thread; assert(thread->timer.set == TELT_UNSET); clear_wait(thread, THREAD_TIMED_OUT, FALSE); @@ -224,10 +217,10 @@ void thread_set_timeout( void thread_timeout_setup( register thread_t thread) { - thread->timer.fcn = (int (*)())thread_timeout; - thread->timer.param = (char *)thread; - thread->depress_timer.fcn = (int (*)())thread_depress_timeout; - thread->depress_timer.param = (char *)thread; + thread->timer.fcn = thread_timeout; + thread->timer.param = thread; + thread->depress_timer.fcn = (void (*)(void*))thread_depress_timeout; + thread->depress_timer.param = thread; } /* @@ -644,6 +637,7 @@ boolean_t thread_invoke( thread_lock(new_thread); new_thread->state &= ~TH_UNINT; thread_unlock(new_thread); + thread_wakeup(&new_thread->state); if (continuation != (void (*)()) 0) { (void) spl0(); @@ -665,6 +659,7 @@ boolean_t thread_invoke( new_thread->state &= ~(TH_SWAPPED | TH_UNINT); thread_unlock(new_thread); + thread_wakeup(&new_thread->state); #if NCPUS > 1 new_thread->last_processor = current_processor(); @@ -794,6 +789,7 @@ boolean_t thread_invoke( new_thread->state &= ~(TH_SWAPPED | TH_UNINT); thread_unlock(new_thread); + thread_wakeup(&new_thread->state); /* * Thread is now interruptible. @@ -1024,7 +1020,7 @@ shift_data_t wait_shift[32] = { (pri) = (th)->priority /* start with base priority */ \ + ((th)->sched_usage >> (PRI_SHIFT + SCHED_SHIFT)) \ + ((th)->sched_usage >> (PRI_SHIFT_2 + SCHED_SHIFT)); \ - if ((pri) > 31) (pri) = 31; \ + if ((pri) > NRQS - 1) (pri) = NRQS - 1; \ MACRO_END #else /* PRI_SHIFT_2 */ #define do_priority_computation(th, pri) \ @@ -1032,7 +1028,7 @@ shift_data_t wait_shift[32] = { (pri) = (th)->priority /* start with base priority */ \ + ((th)->sched_usage >> (PRI_SHIFT + SCHED_SHIFT)) \ - ((th)->sched_usage >> (SCHED_SHIFT - PRI_SHIFT_2)); \ - if ((pri) > 31) (pri) = 31; \ + if ((pri) > NRQS - 1) (pri) = NRQS - 1; \ MACRO_END #endif /* PRI_SHIFT_2 */ #else /* defined(PRI_SHIFT_2) */ @@ -1040,7 +1036,7 @@ shift_data_t wait_shift[32] = { MACRO_BEGIN \ (pri) = (th)->priority /* start with base priority */ \ + ((th)->sched_usage >> (PRI_SHIFT + SCHED_SHIFT)); \ - if ((pri) > 31) (pri) = 31; \ + if ((pri) > NRQS - 1) (pri) = NRQS - 1; \ MACRO_END #endif /* defined(PRI_SHIFT_2) */ @@ -1102,7 +1098,7 @@ void compute_my_priority( * * Update the priorities of all threads periodically. */ -void recompute_priorities(void) +void recompute_priorities(void *param) { #if SIMPLE_CLOCK int new_usec; @@ -1807,8 +1803,8 @@ void idle_thread(void) stack_privilege(self); s = splsched(); - self->priority = 31; - self->sched_pri = 31; + self->priority = NRQS-1; + self->sched_pri = NRQS-1; /* * Set the idle flag to indicate that this is an idle thread, @@ -1952,7 +1948,7 @@ do_runq_scan( stuck_threads[stuck_count++] = thread; if (do_thread_scan_debug) - printf("do_runq_scan: adding thread %#x\n", thread); + printf("do_runq_scan: adding thread %p\n", thread); } count--; thread = next;