Lines Matching refs:processor
91 #include <kern/processor.h>
159 processor_t processor);
163 processor_t processor);
169 processor_t processor);
497 * Signal if idling on another processor.
500 processor_t processor = thread->last_processor;
502 if (processor != current_processor())
503 machine_signal_idle(processor);
906 processor_t processor = thread->last_processor;
908 if (processor != PROCESSOR_NULL && processor->active_thread == thread)
909 cause_ast_check(processor);
999 processor_t processor = thread->last_processor;
1001 if (processor != PROCESSOR_NULL && processor->active_thread == thread)
1002 cause_ast_check(processor);
1133 * Force the current thread to execute on the specified processor.
1142 processor_t processor)
1152 self->bound_processor = processor;
1163 * Select a new thread for the current processor to execute.
1170 processor_t processor)
1172 processor_set_t pset = processor->processor_set;
1183 processor->current_pri = thread->sched_pri;
1187 inactive_state = processor->state != PROCESSOR_SHUTDOWN && machine_cpu_is_inactive(processor->cpu_num);
1194 other_runnable = processor->runq.count > 0 || rt_runq.count > 0;
1198 * to run on this processor. Must be runnable, and not
1199 * bound to a different processor, nor be in the wrong
1200 * processor set.
1204 thread->bound_processor == processor) &&
1208 first_timeslice(processor) ) {
1215 processor->deadline) {
1232 processor->deadline = thread->realtime.deadline;
1241 (processor->runq.highq < thread->sched_pri &&
1248 pset_pri_hint(pset, processor, processor->current_pri);
1250 pset_count_hint(pset, processor, processor->runq.count);
1252 processor->deadline = UINT64_MAX;
1261 if (processor->runq.count > 0 && processor->runq.highq >= rt_runq.highq) {
1264 thread = run_queue_dequeue(&processor->runq, SCHED_HEADQ);
1267 pset_pri_hint(pset, processor, thread->sched_pri);
1269 pset_count_hint(pset, processor, processor->runq.count);
1272 processor->deadline = UINT64_MAX;
1281 processor->deadline = thread->realtime.deadline;
1289 processor->deadline = UINT64_MAX;
1292 if (processor->state == PROCESSOR_RUNNING)
1293 remqueue(&pset->active_queue, (queue_entry_t)processor);
1295 if (processor->state == PROCESSOR_IDLE)
1296 remqueue(&pset->idle_queue, (queue_entry_t)processor);
1298 processor->state = PROCESSOR_INACTIVE;
1302 return (processor->idle_thread);
1317 if (processor->runq.count > 0 || rt_runq.count > 0)
1323 * Nothing is runnable, so set this processor idle if it
1326 if (processor->state == PROCESSOR_RUNNING) {
1327 remqueue(&pset->active_queue, (queue_entry_t)processor);
1328 processor->state = PROCESSOR_IDLE;
1330 enqueue_head(&pset->idle_queue, (queue_entry_t)processor);
1331 pset->low_pri = pset->low_count = processor;
1340 return (processor->idle_thread);
1347 new_thread = thread_select_idle(thread, processor);
1357 * Idle the processor using the current thread context.
1364 processor_t processor)
1373 processor->current_pri = IDLEPRI;
1378 * Switch execution timing to processor idle thread.
1380 processor->last_dispatch = mach_absolute_time();
1381 thread_timer_event(processor->last_dispatch, &processor->idle_thread->system_timer);
1382 PROCESSOR_DATA(processor, kernel_timer) = &processor->idle_thread->system_timer;
1387 timer_call_cancel(&processor->quantum_timer);
1388 processor->timeslice = 0;
1396 spllo(); new_thread = processor_idle(thread, processor);
1410 processor->last_dispatch = mach_absolute_time();
1411 thread_timer_event(processor->last_dispatch, &thread->system_timer);
1412 PROCESSOR_DATA(processor, kernel_timer) = &thread->system_timer;
1416 processor->quantum_end = processor->last_dispatch + thread->current_quantum;
1417 timer_call_enter1(&processor->quantum_timer, thread, processor->quantum_end);
1418 processor->timeslice = 1;
1420 thread->computation_epoch = processor->last_dispatch;
1474 processor_t processor;
1515 processor = current_processor();
1516 processor->active_thread = thread;
1517 processor->current_pri = thread->sched_pri;
1518 if (thread->last_processor != processor && thread->last_processor != NULL) {
1519 if (thread->last_processor->processor_set != processor->processor_set)
1523 thread->last_processor = processor;
1530 processor->last_dispatch = mach_absolute_time();
1531 thread_timer_event(processor->last_dispatch, &thread->system_timer);
1532 PROCESSOR_DATA(processor, kernel_timer) = &thread->system_timer;
1592 processor = current_processor();
1593 processor->active_thread = thread;
1594 processor->current_pri = thread->sched_pri;
1595 if (thread->last_processor != processor && thread->last_processor != NULL) {
1596 if (thread->last_processor->processor_set != processor->processor_set)
1600 thread->last_processor = processor;
1610 processor->last_dispatch = mach_absolute_time();
1611 thread_timer_event(processor->last_dispatch, &thread->system_timer);
1612 PROCESSOR_DATA(processor, kernel_timer) = &thread->system_timer;
1658 processor_t processor = self->last_processor;
1675 if ( first_timeslice(processor) &&
1676 processor->quantum_end > processor->last_dispatch )
1677 thread->current_quantum = (processor->quantum_end - processor->last_dispatch);
1713 thread->last_switch = processor->last_dispatch;
1773 processor->quantum_end = (processor->last_dispatch + self->current_quantum);
1774 timer_call_enter1(&processor->quantum_timer, self, processor->quantum_end);
1776 processor->timeslice = 1;
1778 self->last_switch = processor->last_dispatch;
1783 timer_call_cancel(&processor->quantum_timer);
1784 processor->timeslice = 0;
1808 register processor_t processor;
1819 processor = current_processor();
1823 processor->timeslice = 0;
1833 new_thread = thread_select(self, processor);
1888 processor_t processor = current_processor();
1891 new_thread = thread_select(self, processor);
2055 processor_t processor,
2058 processor_set_t pset = processor->processor_set;
2061 * Dispatch directly onto idle processor.
2063 if (processor->state == PROCESSOR_IDLE) {
2064 remqueue(&pset->idle_queue, (queue_entry_t)processor);
2065 enqueue_tail(&pset->active_queue, (queue_entry_t)processor);
2067 processor->next_thread = thread;
2068 processor->deadline = thread->realtime.deadline;
2069 processor->state = PROCESSOR_DISPATCHING;
2072 if (processor != current_processor())
2073 machine_signal_idle(processor);
2078 if (processor == current_processor())
2081 cause_ast_check(processor);
2090 * Enqueue thread on a processor run queue. Thread must be locked,
2101 processor_t processor,
2105 run_queue_t rq = &processor->runq;
2124 thread->runq = processor;
2136 * processor.
2143 processor_t processor,
2147 processor_set_t pset = processor->processor_set;
2151 * Dispatch directly onto idle processor.
2153 if (processor->state == PROCESSOR_IDLE) {
2154 remqueue(&pset->idle_queue, (queue_entry_t)processor);
2155 enqueue_tail(&pset->active_queue, (queue_entry_t)processor);
2157 processor->next_thread = thread;
2158 processor->deadline = UINT64_MAX;
2159 processor->state = PROCESSOR_DISPATCHING;
2162 if (processor != current_processor())
2163 machine_signal_idle(processor);
2178 if (!processor_enqueue(processor, thread, options))
2182 if (processor == current_processor()) {
2183 if (csw_check(processor) != AST_NONE)
2187 if ( (processor->state == PROCESSOR_RUNNING ||
2188 processor->state == PROCESSOR_SHUTDOWN) &&
2189 thread->sched_pri >= processor->current_pri ) {
2190 cause_ast_check(processor);
2194 if ( processor->state == PROCESSOR_SHUTDOWN &&
2195 thread->sched_pri >= processor->current_pri ) {
2196 cause_ast_check(processor);
2229 * Choose a processor for the thread, beginning at
2232 * Returns a processor, possibly from a different pset.
2243 processor_t processor = thread->last_processor;
2246 * Prefer the last processor, when appropriate.
2248 if (processor != PROCESSOR_NULL) {
2249 if (processor->processor_set != pset || processor->state == PROCESSOR_INACTIVE ||
2250 processor->state == PROCESSOR_SHUTDOWN || processor->state == PROCESSOR_OFF_LINE)
2251 processor = PROCESSOR_NULL;
2253 if (processor->state == PROCESSOR_IDLE || ( thread->sched_pri > BASEPRI_DEFAULT && processor->current_pri < thread->sched_pri))
2254 return (processor);
2258 * Iterate through the processor sets to locate
2259 * an appropriate processor.
2263 * Choose an idle processor.
2272 processor = (processor_t)queue_first(&cset->active_queue);
2273 while (!queue_end(&cset->active_queue, (queue_entry_t)processor)) {
2274 if (thread->sched_pri > processor->current_pri ||
2275 thread->realtime.deadline < processor->deadline)
2276 return (processor);
2278 processor = (processor_t)queue_next((queue_entry_t)processor);
2281 processor = PROCESSOR_NULL;
2285 * Check any hinted processors in the processor set if available.
2289 (processor == PROCESSOR_NULL ||
2291 processor = cset->low_pri;
2296 (processor == PROCESSOR_NULL ||
2297 ( thread->sched_pri <= BASEPRI_DEFAULT && cset->low_count->runq.count < processor->runq.count))) {
2298 processor = cset->low_count;
2302 * Otherwise, choose an available processor in the set.
2304 if (processor == PROCESSOR_NULL) {
2305 processor = (processor_t)dequeue_head(&cset->active_queue);
2306 if (processor != PROCESSOR_NULL)
2307 enqueue_tail(&cset->active_queue, (queue_entry_t)processor);
2312 * Move onto the next processor set.
2325 * Make sure that we pick a running processor,
2326 * and that the correct processor set is locked.
2330 * If we haven't been able to choose a processor,
2331 * pick the boot processor and return it.
2333 if (processor == PROCESSOR_NULL) {
2334 processor = master_processor;
2337 * Check that the correct processor set is
2340 if (cset != processor->processor_set) {
2343 cset = processor->processor_set;
2347 return (processor);
2351 * Check that the processor set for the chosen
2352 * processor is locked.
2354 if (cset != processor->processor_set) {
2357 cset = processor->processor_set;
2362 * We must verify that the chosen processor is still available.
2364 if (processor->state == PROCESSOR_INACTIVE ||
2365 processor->state == PROCESSOR_SHUTDOWN || processor->state == PROCESSOR_OFF_LINE)
2366 processor = PROCESSOR_NULL;
2367 } while (processor == PROCESSOR_NULL);
2369 return (processor);
2376 * processor or run queue, and signal a preemption
2386 processor_t processor;
2412 processor = choose_processor(pset, thread);
2417 * Simple (last processor) affinity case.
2419 processor = thread->last_processor;
2420 pset = processor->processor_set;
2424 * Choose a different processor in certain cases.
2428 * If the processor is executing an RT thread with
2431 if (thread->sched_pri <= processor->current_pri ||
2432 thread->realtime.deadline >= processor->deadline)
2433 processor = choose_processor(pset, thread);
2436 processor = choose_processor(pset, thread);
2443 * among the available processor sets.
2454 processor = choose_processor(pset, thread);
2455 task->pset_hint = processor->processor_set;
2462 * Unconditionally dispatch on the processor.
2464 processor = thread->bound_processor;
2465 pset = processor->processor_set;
2470 * Dispatch the thread on the choosen processor.
2473 realtime_setrun(processor, thread);
2475 processor_setrun(processor, thread, options);
2481 * Shutdown a processor run queue by
2489 processor_t processor)
2491 processor_set_t pset = processor->processor_set;
2492 run_queue_t rq = &processor->runq;
2505 if (thread->bound_processor != processor) {
2548 processor_t processor)
2553 if (first_timeslice(processor)) {
2558 if (runq->highq > processor->current_pri) {
2565 runq = &processor->runq;
2566 if (runq->highq > processor->current_pri) {
2575 if (runq->highq >= processor->current_pri) {
2582 runq = &processor->runq;
2583 if (runq->highq >= processor->current_pri) {
2594 if (machine_cpu_is_inactive(processor->cpu_num))
2597 if (processor->active_thread->state & TH_SUSP)
2624 processor_t processor = thread->last_processor;
2629 processor->current_pri = priority;
2630 if ((preempt = csw_check(processor)) != AST_NONE)
2634 if ( processor != PROCESSOR_NULL &&
2635 processor->active_thread == thread )
2636 cause_ast_check(processor);
2682 processor_t processor = thread->runq;
2685 * If processor is PROCESSOR_NULL, the thread will stay out of the
2690 if (processor != PROCESSOR_NULL) {
2695 * The processor run queues are locked by the
2696 * processor set. Real-time priorities use a
2700 rqlock = &processor->processor_set->sched_lock;
2701 rq = &processor->runq;
2709 if (processor == thread->runq) {
2735 processor = PROCESSOR_NULL;
2741 return (processor != PROCESSOR_NULL);
2747 * Locate a thread to steal from the processor and
2755 processor_t processor)
2757 run_queue_t rq = &processor->runq;
2765 if (thread->bound_processor != processor) {
2807 processor_t processor;
2811 processor = (processor_t)queue_first(&cset->active_queue);
2812 while (!queue_end(&cset->active_queue, (queue_entry_t)processor)) {
2813 if (processor->runq.count > 0) {
2814 thread = steal_processor_thread(processor);
2816 remqueue(&cset->active_queue, (queue_entry_t)processor);
2817 enqueue_tail(&cset->active_queue, (queue_entry_t)processor);
2825 processor = (processor_t)queue_next((queue_entry_t)processor);
2844 * This is the processor idle loop, which just looks for other threads
2853 processor_t processor)
2855 processor_set_t pset = processor->processor_set;
2868 timer_switch(&PROCESSOR_DATA(processor, system_state),
2869 mach_absolute_time(), &PROCESSOR_DATA(processor, idle_state));
2870 PROCESSOR_DATA(processor, current_state) = &PROCESSOR_DATA(processor, idle_state);
2872 while (processor->next_thread == THREAD_NULL && processor->runq.count == 0 && rt_runq.count == 0 &&
2878 if (processor->state == PROCESSOR_INACTIVE && !machine_cpu_is_inactive(processor->cpu_num))
2882 timer_switch(&PROCESSOR_DATA(processor, idle_state),
2883 mach_absolute_time(), &PROCESSOR_DATA(processor, system_state));
2884 PROCESSOR_DATA(processor, current_state) = &PROCESSOR_DATA(processor, system_state);
2892 state = processor->state;
2897 new_thread = processor->next_thread;
2898 processor->next_thread = THREAD_NULL;
2899 processor->state = PROCESSOR_RUNNING;
2901 if ( processor->runq.highq > new_thread->sched_pri ||
2903 processor->deadline = UINT64_MAX;
2926 remqueue(&pset->idle_queue, (queue_entry_t)processor);
2928 processor->state = PROCESSOR_RUNNING;
2929 enqueue_tail(&pset->active_queue, (queue_entry_t)processor);
2933 processor->state = PROCESSOR_RUNNING;
2934 enqueue_tail(&pset->active_queue, (queue_entry_t)processor);
2942 if ((new_thread = processor->next_thread) != THREAD_NULL) {
2943 processor->next_thread = THREAD_NULL;
2944 processor->deadline = UINT64_MAX;
2968 * Each processor has a dedicated thread which
2975 processor_t processor = current_processor();
2978 new_thread = processor_idle(THREAD_NULL, processor);
2980 thread_run(processor->idle_thread, (thread_continue_t)idle_thread, NULL, new_thread);
2990 processor_t processor)
3002 thread->bound_processor = processor;
3003 processor->idle_thread = thread;
3189 processor_t processor = processor_list;
3196 pset = processor->processor_set;
3201 restart_needed = runq_scan(&processor->runq);
3209 thread = processor->idle_thread;
3219 } while ((processor = processor->processor_list) != NULL);