1 #include <klibc/compiler.h>
7 void (*sched_hook_func
)(void);
10 * __schedule() should only be called with interrupts locked out!
14 static bool in_sched_hook
;
15 struct thread
*curr
= current();
16 struct thread
*st
, *nt
, *best
;
19 if (__unlikely(irq_state() & 0x200)) {
20 dprintf("In __schedule with interrupts on!\n");
26 * Are we called from inside sched_hook_func()? If so we'll
27 * schedule anyway on the way out.
34 /* Possibly update the information on which we make
35 * scheduling decisions.
37 if (sched_hook_func
) {
40 in_sched_hook
= false;
44 * The unusual form of this walk is because we have to start with
45 * the thread *following* curr, and curr may not actually be part
46 * of the list anymore (in the case of __exit_thread).
49 nt
= st
= container_of(curr
->list
.next
, struct thread
, list
);
51 if (__unlikely(nt
->thread_magic
!= THREAD_MAGIC
)) {
52 dprintf("Invalid thread on thread list %p magic = 0x%08x\n",
53 nt
, nt
->thread_magic
);
57 dprintf("Thread %p (%s) ", nt
, nt
->name
);
59 dprintf("runnable priority %d\n", nt
->prio
);
60 if (!best
|| nt
->prio
< best
->prio
)
65 nt
= container_of(nt
->list
.next
, struct thread
, list
);
69 kaboom(); /* No runnable thread */
74 asm volatile("rdtsc" : "=A" (tsc
));
76 dprintf("@ %llu -> %p (%s)\n", tsc
, best
, best
->name
);
79 dprintf("no change\n");
84 * This can be called from "normal" code...
86 void thread_yield(void)
88 irq_state_t irq
= irq_save();