Lines Matching refs:thread

46 #include <kern/thread.h>
64 * When we choose a new thread, we will decide whether to look at the bound runqueue, the global runqueue
65 * or the current group's runqueue, then dequeue the next thread in that runqueue.
77 * NOTE ABOUT thread->sched_pri:
79 * It can change after enqueue - it's changed without pset lock but with thread lock if thread->runq is 0.
111 * was from a thread in the same group or different group,
127 * Perhaps choose_thread could pass in the current thread?
134 * A) Hand off only when switching thread to thread in the same group
145 * but will not help when a thread from a different task is involved.
151 * Existing algorithm - preemption doesn't re-set quantum, puts thread on head of runq.
152 * Blocking or quantum expiration does re-set quantum, puts thread on tail of runq.
156 * Even if thread was blocked it uses last thread remaining quanta when it starts.
162 * non-handoff wakeups i.e. wake other thread then wait then block - doesn't mean that
163 * woken thread will be what I switch to - other processor may have stolen it.
169 * on the preempted thread if it's preempted by something outside the task.
202 * Only cycle it to the end of the runqueue when a thread in the task
208 * Don't favor the task when an urgent thread is present.
252 sched_multiq_processor_enqueue(processor_t processor, thread_t thread, integer_t options);
255 sched_multiq_processor_queue_remove(processor_t processor, thread_t thread);
258 sched_multiq_quantum_expire(thread_t thread);
517 thread_t thread = (thread_t)(void*)queue_first(queue);
519 assert(thread != THREAD_NULL);
521 assert(thread->sched_group == group);
524 assert(thread->sched_pri == rq->highq);
526 return thread;
549 /* Asserts if thread is not in group at its priority */
551 sched_group_check_thread(sched_group_t group, thread_t thread)
555 int pri = thread->sched_pri;
557 assert(thread->runq != PROCESSOR_NULL);
562 if (elem == thread)
566 panic("group %p doesn't contain thread %p at pri %d", group, thread, pri);
581 thread_t thread = group_first_thread(group);
583 __assert_only sched_entry_t thread_entry = group_entry_for_pri(thread->sched_group, thread->sched_pri);
588 assert(thread->runq != PROCESSOR_NULL);
597 thread_t thread = group_first_thread(group);
599 assert(thread->runq != PROCESSOR_NULL);
601 sched_entry_t sched_entry = group_entry_for_pri(thread->sched_group, thread->sched_pri);
603 entry_queue_check_entry(main_entryq, sched_entry, thread->sched_pri);
605 assert(sched_entry->sched_pri == thread->sched_pri);
725 thread_t thread;
733 thread = (thread_t)(void*)dequeue_head(queue);
749 return (thread);
759 thread_t thread,
766 assert(thread->runq == PROCESSOR_NULL);
769 enqueue_tail(queue, (queue_entry_t)thread);
778 enqueue_tail(queue, (queue_entry_t)thread);
780 enqueue_head(queue, (queue_entry_t)thread);
791 * The thread must be in this runqueue.
797 thread_t thread,
802 assert(thread->runq != PROCESSOR_NULL);
804 remqueue((queue_entry_t)thread);
820 thread->runq = PROCESSOR_NULL;
826 * A thread's sched pri may change out from under us because
827 * we're clearing thread->runq here without the thread locked.
836 thread_t thread;
847 thread = group_run_queue_dequeue_thread(group_runq, &thread_pri, &pri_level_empty);
849 thread->runq = PROCESSOR_NULL;
855 return thread;
858 /* Dequeue a thread from the global runq without moving the entry */
865 thread_t thread;
876 thread = group_run_queue_dequeue_thread(group_runq, &thread_pri, &pri_level_empty);
878 thread->runq = PROCESSOR_NULL;
884 return thread;
895 thread_t thread;
898 thread = group_run_queue_dequeue_thread(group_runq, &thread_pri, &pri_level_empty);
900 thread->runq = PROCESSOR_NULL;
906 return thread;
913 thread_t thread)
915 integer_t thread_pri = thread->sched_pri;
923 sched_group_check_thread(group, thread);
928 boolean_t pri_level_empty = group_run_queue_remove_thread(&group->runq, thread, thread_pri);
946 thread_t thread,
956 int sched_pri = thread->sched_pri;
958 boolean_t pri_level_was_empty = group_run_queue_enqueue_thread(&group->runq, thread, sched_pri, options);
970 * Locate a thread to execute from the run queue and return it.
971 * Only choose a thread with greater or equal priority.
973 * pset is locked, thread is not locked.
975 * Returns THREAD_NULL if it cannot find a valid thread.
977 * Note: we cannot rely on the value of thread->sched_pri in this path because
978 * we don't have the thread locked.
1041 * don't pick a thread below the limit.
1053 /* Don't favor the task when an urgent thread is present. */
1088 thread_t thread,
1093 assert(processor == thread->chosen_processor);
1095 if (thread->bound_processor != PROCESSOR_NULL) {
1096 assert(thread->bound_processor == processor);
1098 result = run_queue_enqueue(multiq_bound_runq(processor), thread, options);
1099 thread->runq = processor;
1105 thread->sched_group,
1106 thread, options);
1108 thread->runq = processor;
1114 * Called in the context of thread with thread and pset unlocked,
1115 * after updating thread priority but before propagating that priority
1119 sched_multiq_quantum_expire(thread_t thread)
1127 processor_t processor = thread->last_processor;
1133 sched_entry_t entry = group_entry_for_pri(thread->sched_group, processor->current_pri);
1248 thread_t thread;
1262 thread = sched_global_dequeue_thread(main_entryq);
1263 enqueue_tail(&tqueue, (queue_entry_t)thread);
1268 while ((thread = (thread_t)(void*)dequeue_head(&tqueue)) != THREAD_NULL) {
1269 thread_lock(thread);
1271 thread_setrun(thread, SCHED_TAILQ);
1273 thread_unlock(thread);
1280 * This is why we can never read sched_pri unless we have the thread locked.
1286 thread_t thread)
1294 if (thread->runq != PROCESSOR_NULL) {
1300 assert(thread->runq == processor);
1302 if (thread->bound_processor != PROCESSOR_NULL) {
1303 assert(processor == thread->bound_processor);
1304 run_queue_remove(multiq_bound_runq(processor), thread);
1305 thread->runq = PROCESSOR_NULL;
1308 thread->sched_group,
1309 thread);
1365 thread_t thread;
1388 thread = processor->idle_thread;
1389 if (thread != THREAD_NULL && thread->sched_stamp != sched_tick) {
1390 if (thread_update_add_thread(thread) == FALSE) {