• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/xnu-2782.1.97/osfmk/kern/

Lines Matching refs:thread

34 #include <kern/thread.h>
49 * This table defines the starting base priority of the thread,
50 * which will be modified by the thread importance and the task max priority
62 * This table defines the highest IO priority that a thread marked with this
75 * a thread marked with this QoS class can have.
96 thread_recompute_qos(thread_t thread);
100 thread_t thread);
103 thread_set_user_sched_mode(thread_t thread, sched_mode_t mode);
109 extern void proc_get_thread_policy(thread_t thread, thread_policy_state_t info);
112 thread_has_qos_policy(thread_t thread) {
113 return (proc_get_task_policy(thread->task, thread, TASK_POLICY_ATTRIBUTE, TASK_POLICY_QOS) != THREAD_QOS_UNSPECIFIED) ? TRUE : FALSE;
117 thread_remove_qos_policy(thread_t thread)
123 __unused int prev_qos = thread->requested_policy.thrp_qos;
125 DTRACE_PROC2(qos__remove, thread_t, thread, int, prev_qos);
127 return thread_policy_set_internal(thread, THREAD_QOS_POLICY, (thread_policy_t)&unspec_qos, THREAD_QOS_POLICY_COUNT);
131 thread_is_static_param(thread_t thread)
133 if (thread->static_param) {
134 DTRACE_PROC1(qos__legacy__denied, thread_t, thread);
192 * testing thread qos policy from userspace
198 thread_t thread,
208 if (thread == THREAD_NULL)
212 if (thread_is_static_param(thread))
220 if (thread->requested_policy.thrp_qos != THREAD_QOS_UNSPECIFIED) {
222 req_qos.qos_tier = thread->requested_policy.thrp_qos;
223 req_qos.tier_importance = thread->requested_policy.thrp_qos_relprio;
225 kr = thread_remove_qos_policy(thread);
231 kr = thread_policy_set_internal(thread, flavor, policy_info, count);
237 (void)thread_policy_set_internal(thread, THREAD_QOS_POLICY, (thread_policy_t)&req_qos, THREAD_QOS_POLICY_COUNT);
246 thread_t thread,
254 thread_mtx_lock(thread);
255 if (!thread->active) {
256 thread_mtx_unlock(thread);
277 thread_lock(thread);
279 boolean_t removed = thread_run_queue_remove(thread);
281 thread_set_user_sched_mode(thread, mode);
282 thread_recompute_priority(thread);
285 thread_setrun(thread, SCHED_TAILQ);
287 thread_unlock(thread);
290 sfi_reevaluate(thread);
313 thread_lock(thread);
315 boolean_t removed = thread_run_queue_remove(thread);
317 thread->realtime.period = info->period;
318 thread->realtime.computation = info->computation;
319 thread->realtime.constraint = info->constraint;
320 thread->realtime.preemptible = info->preemptible;
322 thread_set_user_sched_mode(thread, TH_MODE_REALTIME);
323 thread_recompute_priority(thread);
326 thread_setrun(thread, SCHED_TAILQ);
328 thread_unlock(thread);
331 sfi_reevaluate(thread);
347 thread_lock(thread);
349 thread->importance = info->importance;
351 thread_recompute_priority(thread);
353 thread_unlock(thread);
374 * Unlock the thread mutex here and
379 thread_mtx_unlock(thread);
380 return thread_affinity_set(thread, info->affinity_tag);
399 thread->effective_policy.t_through_qos = tqos;
419 /* The expected use cases (opt-in) of per-thread latency QoS would seem to
420 * preclude any requirement at present to re-evaluate timers on a thread level
423 thread->effective_policy.t_latency_qos = lqos;
458 * We need to move thread policy to the thread mutex instead.
459 * <rdar://problem/15831652> separate thread policy from task policy
466 thread->requested_policy.thrp_qos_override != THREAD_QOS_UNSPECIFIED)
467 strongest_override = MAX(thread->requested_policy.thrp_qos_override, info->qos_tier);
469 thread_mtx_unlock(thread);
471 /* There is a race here. To be closed in <rdar://problem/15831652> separate thread policy from task policy */
473 proc_set_task_policy(thread->task, thread, TASK_POLICY_ATTRIBUTE, TASK_POLICY_QOS_OVERRIDE, strongest_override);
478 thread_mtx_unlock(thread);
480 proc_set_task_policy2(thread->task, thread, TASK_POLICY_ATTRIBUTE, TASK_POLICY_QOS_AND_RELPRIO, info->qos_tier, -info->tier_importance);
482 thread_mtx_lock(thread);
483 if (!thread->active) {
484 thread_mtx_unlock(thread);
496 thread_mtx_unlock(thread);
503 * Set scheduling policy & absolute priority for thread, for deprecated
509 * Called with thread mutex locked.
513 thread_t thread,
521 if (thread_is_static_param(thread))
524 if (thread->policy_reset)
528 if (thread->requested_policy.thrp_qos != THREAD_QOS_UNSPECIFIED) {
529 thread_mtx_unlock(thread);
531 kr = thread_remove_qos_policy(thread);
533 thread_mtx_lock(thread);
534 if (!thread->active) {
553 thread_lock(thread);
555 /* This path isn't allowed to change a thread out of realtime. */
556 if ((thread->sched_mode != TH_MODE_REALTIME) &&
557 (thread->saved_mode != TH_MODE_REALTIME)) {
564 if (priority >= thread->max_priority)
565 priority = thread->max_priority - thread->task_priority;
573 priority += thread->task_priority;
575 if (priority > thread->max_priority)
576 priority = thread->max_priority;
580 thread->importance = priority - thread->task_priority;
582 boolean_t removed = thread_run_queue_remove(thread);
584 thread_set_user_sched_mode(thread, mode);
586 thread_recompute_priority(thread);
589 thread_setrun(thread, SCHED_TAILQ);
592 thread_unlock(thread);
595 sfi_reevaluate(thread);
601 * Set the thread's requested mode
602 * Called with thread mutex and thread locked
605 thread_set_user_sched_mode(thread_t thread, sched_mode_t mode)
607 if (thread->policy_reset)
615 if (thread->sched_flags & TH_SFLAG_DEMOTED_MASK)
616 thread->saved_mode = mode;
618 sched_set_thread_mode(thread, mode);
623 thread_recompute_qos(thread_t thread) {
626 thread_mtx_lock(thread);
628 if (!thread->active) {
629 thread_mtx_unlock(thread);
634 thread_lock(thread);
636 thread_recompute_priority(thread);
638 thread_unlock(thread);
641 thread_mtx_unlock(thread);
646 thread_update_qos_cpu_time(thread_t thread, boolean_t lock_needed)
660 thread_lock(thread);
664 * Calculation of time elapsed by the thread in the current qos.
667 * thread ledger thread ledger
678 * Calculate time elapsed since last qos change on this thread.
679 * For cpu time on thread ledger, do not use ledger_get_balance,
681 * debit is used by per thread cpu limits and is not zero.
683 kr = ledger_get_entries(thread->t_threadledger, thread_ledgers.cpu_time, &thread_balance_credit, &thread_balance_debit);
686 last_qos_change_balance = thread->cpu_time_last_qos;
689 * If thread running on CPU, calculate time elapsed since this thread was last dispatched on cpu.
690 * The thread ledger is only updated at context switch, the time since last context swicth is not
691 * updated in the thread ledger cpu time.
693 processor = thread->last_processor;
695 (processor->active_thread == thread)) {
701 consumed = thread->quantum_remaining - remainder;
709 * thread ledger
714 * thread_dispatch thread ledger ctime quantum end
723 thread_unlock(thread);
730 thread->cpu_time_last_qos += (uint64_t)effective_qos_time;
736 switch (thread->effective_policy.thep_qos) {
739 thread->task->cpu_time_qos_stats.cpu_time_qos_default += effective_qos_time;
743 thread->task->cpu_time_qos_stats.cpu_time_qos_maintenance += effective_qos_time;
747 thread->task->cpu_time_qos_stats.cpu_time_qos_background += effective_qos_time;
751 thread->task->cpu_time_qos_stats.cpu_time_qos_utility += effective_qos_time;
755 thread->task->cpu_time_qos_stats.cpu_time_qos_legacy += effective_qos_time;
759 thread->task->cpu_time_qos_stats.cpu_time_qos_user_initiated += effective_qos_time;
763 thread->task->cpu_time_qos_stats.cpu_time_qos_user_interactive += effective_qos_time;
771 thread_unlock(thread);
777 * Calculate base priority from thread attributes, and set it on the thread
779 * Called with thread_lock and thread mutex held.
783 thread_t thread)
787 if (thread->policy_reset)
790 if (thread->sched_mode == TH_MODE_REALTIME) {
791 sched_set_thread_base_priority(thread, BASEPRI_RTQUEUES);
793 } else if (thread->effective_policy.thep_qos != THREAD_QOS_UNSPECIFIED) {
794 int qos = thread->effective_policy.thep_qos;
795 int qos_ui_is_urgent = thread->effective_policy.qos_ui_is_urgent;
796 int qos_relprio = -(thread->effective_policy.thep_qos_relprio); /* stored in task policy inverted */
812 if (thread->importance > MAXPRI)
814 else if (thread->importance < -MAXPRI)
817 priority = thread->importance;
819 priority += thread->task_priority;
822 if (priority > thread->max_priority)
823 priority = thread->max_priority;
828 sched_set_thread_base_priority(thread, priority);
831 /* Called with the thread mutex held */
834 thread_t thread,
840 assert(thread != THREAD_NULL);
842 if (!thread->active || thread->policy_reset)
846 thread_lock(thread);
848 integer_t old_max_priority = thread->max_priority;
850 thread->task_priority = priority;
851 thread->max_priority = max_priority;
853 /* A thread is 'throttled' when its max priority is below MAXPRI_THROTTLE */
855 sched_set_thread_throttled(thread, FALSE);
857 sched_set_thread_throttled(thread, TRUE);
860 thread_recompute_priority(thread);
862 thread_unlock(thread);
867 * Reset thread to default state in preparation for termination
868 * Called with thread mutex locked
870 * Always called on current thread, so we don't need a run queue remove
874 thread_t thread)
878 assert(thread == current_thread());
881 thread_lock(thread);
883 assert_thread_sched_count(thread);
885 if (thread->sched_flags & TH_SFLAG_FAILSAFE)
886 sched_thread_mode_undemote(thread, TH_SFLAG_FAILSAFE);
888 assert_thread_sched_count(thread);
890 if (thread->sched_flags & TH_SFLAG_THROTTLED)
891 sched_set_thread_throttled(thread, FALSE);
893 assert_thread_sched_count(thread);
895 assert(thread->BG_COUNT == 0);
898 assert(!(thread->sched_flags & TH_SFLAG_DEMOTED_MASK));
899 assert(!(thread->sched_flags & TH_SFLAG_THROTTLED));
900 assert(!(thread->sched_flags & TH_SFLAG_DEPRESSED_MASK));
902 /* Reset thread back to task-default basepri and mode */
903 sched_mode_t newmode = SCHED(initial_thread_sched_mode)(thread->task);
905 sched_set_thread_mode(thread, newmode);
907 thread->importance = 0;
909 sched_set_thread_base_priority(thread, thread->task_priority);
911 /* Prevent further changes to thread base priority or mode */
912 thread->policy_reset = 1;
914 assert(thread->BG_COUNT == 0);
915 assert_thread_sched_count(thread);
917 thread_unlock(thread);
923 thread_t thread,
932 if (thread == THREAD_NULL)
935 thread_mtx_lock(thread);
936 if (!thread->active) {
937 thread_mtx_unlock(thread);
950 thread_lock(thread);
952 if ( (thread->sched_mode != TH_MODE_REALTIME) &&
953 (thread->saved_mode != TH_MODE_REALTIME) ) {
954 if (!(thread->sched_flags & TH_SFLAG_DEMOTED_MASK))
955 timeshare = (thread->sched_mode == TH_MODE_TIMESHARE) != 0;
957 timeshare = (thread->saved_mode == TH_MODE_TIMESHARE) != 0;
962 thread_unlock(thread);
989 thread_lock(thread);
991 if ( (thread->sched_mode == TH_MODE_REALTIME) ||
992 (thread->saved_mode == TH_MODE_REALTIME) ) {
993 info->period = thread->realtime.period;
994 info->computation = thread->realtime.computation;
995 info->constraint = thread->realtime.constraint;
996 info->preemptible = thread->realtime.preemptible;
1001 thread_unlock(thread);
1028 thread_lock(thread);
1030 info->importance = thread->importance;
1032 thread_unlock(thread);
1057 info->affinity_tag = thread_affinity_get(thread);
1084 info->flags |= (thread->static_param ? THREAD_POLICY_STATE_FLAG_STATIC_PARAM : 0);
1087 * Unlock the thread mutex and directly return.
1091 thread_mtx_unlock(thread);
1092 proc_get_thread_policy(thread, info);
1116 plqos = thread->effective_policy.t_latency_qos;
1136 ptqos = thread->effective_policy.t_through_qos;
1155 info->qos_tier = thread->requested_policy.thrp_qos_override;
1159 info->qos_tier = thread->requested_policy.thrp_qos;
1160 info->tier_importance = thread->importance;
1175 thread_mtx_unlock(thread);