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

Lines Matching refs:thread

57  *  This subsystem manages task and thread IO priority and backgrounding,
77 * Here are the steps to change a policy on a task or thread:
108 * Changing task policy on a task or thread takes the task lock, and not the thread lock.
109 * TODO: Should changing policy on a thread take the thread lock instead?
123 extern void thread_recompute_qos(thread_t thread);
126 static void proc_set_task_policy_locked(task_t task, thread_t thread, int category, int flavor, int value);
127 static void proc_set_task_policy2_locked(task_t task, thread_t thread, int category, int flavor, int value1, int value2);
129 static void task_policy_update_locked(task_t task, thread_t thread, task_pend_token_t pend_token);
130 static void task_policy_update_internal_locked(task_t task, thread_t thread, boolean_t in_create, task_pend_token_t pend_token);
132 static void task_policy_update_thread_locked(thread_t thread, int update_cpu, boolean_t update_throttle, boolean_t update_sfi, boolean_t update_qos);
134 static int proc_get_effective_policy(task_t task, thread_t thread, int policy);
139 static uintptr_t trequested_0(task_t task, thread_t thread);
140 static uintptr_t trequested_1(task_t task, thread_t thread);
141 static uintptr_t teffective_0(task_t task, thread_t thread);
142 static uintptr_t teffective_1(task_t task, thread_t thread);
144 static uint64_t task_requested_bitfield(task_t task, thread_t thread);
145 static uint64_t task_effective_bitfield(task_t task, thread_t thread);
147 void proc_get_thread_policy(thread_t thread, thread_policy_state_t info);
163 extern void proc_apply_task_networkbg(void * bsd_info, thread_t thread);
196 #define tpriority(task, thread) ((uintptr_t)(thread == THREAD_NULL ? (task->priority) : (thread->priority)))
197 #define tisthread(thread) (thread == THREAD_NULL ? TASK_POLICY_TASK : TASK_POLICY_THREAD)
198 #define targetid(task, thread) ((uintptr_t)(thread == THREAD_NULL ? (audit_token_pid_from_task(task)) : (thread->thread_id)))
670 thread_policy_create(thread_t thread)
672 task_t task = thread->task;
676 targetid(task, thread), teffective_0(task, thread),
677 teffective_1(task, thread), tpriority(task, thread), 0);
679 task_policy_update_internal_locked(task, thread, TRUE, NULL);
683 targetid(task, thread), teffective_0(task, thread),
684 teffective_1(task, thread), tpriority(task, thread), 0);
688 task_policy_update_locked(task_t task, thread_t thread, task_pend_token_t pend_token)
691 (IMPORTANCE_CODE(IMP_UPDATE, tisthread(thread)) | DBG_FUNC_START),
692 targetid(task, thread), teffective_0(task, thread),
693 teffective_1(task, thread), tpriority(task, thread), 0);
695 task_policy_update_internal_locked(task, thread, FALSE, pend_token);
698 (IMPORTANCE_CODE(IMP_UPDATE, tisthread(thread))) | DBG_FUNC_END,
699 targetid(task, thread), teffective_0(task, thread),
700 teffective_1(task, thread), tpriority(task, thread), 0);
706 * This function updates the task or thread effective policy fields
712 * Called with task locked, not thread
716 task_policy_update_internal_locked(task_t task, thread_t thread, boolean_t in_create, task_pend_token_t pend_token)
718 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
726 (on_task) ? task->requested_policy : thread->requested_policy;
735 * If operating on a thread, don't touch anything starting with t_
790 * Set thread qos tier
792 * A thread must already be participating in QoS for override to take effect
825 * are boosting the thread.
897 /* darwinbg on either task or thread implies background QOS (or lower) */
1069 /* Acquire thread mutex to synchronize against
1072 * A more efficient model would be to make the thread bits
1075 thread_mtx_lock(thread);
1079 (on_task) ? task->effective_policy : thread->effective_policy;
1092 /* Preserve thread specific latency/throughput QoS modified via
1095 * If thread QoS class is set, we don't need to preserve the previously set values.
1096 * We should ensure to not accidentally preserve previous thread QoS values if you set a thread
1099 uint32_t lqos = thread->effective_policy.t_latency_qos, tqos = thread->effective_policy.t_through_qos;
1112 thread_update_qos_cpu_time(thread, TRUE);
1113 thread->effective_policy = next;
1114 thread_mtx_unlock(thread);
1117 /* Don't do anything further to a half-formed task or thread */
1196 task_policy_update_thread_locked(thread, update_cpu, update_throttle, update_sfi, update_qos);
1200 /* Despite the name, the thread's task is locked, the thread is not */
1202 task_policy_update_thread_locked(thread_t thread,
1211 rethrottle_thread(thread->uthread);
1215 sfi_reevaluate(thread);
1222 * TODO: A BG thread's priority is 0 on desktop and 4 on embedded. Need to reconcile this.
1225 thread->saved_importance = thread->importance;
1228 policy.importance = thread->saved_importance;
1229 thread->saved_importance = 0;
1232 /* Takes thread lock and thread mtx lock */
1234 thread_policy_set_internal(thread, THREAD_PRECEDENCE_POLICY,
1239 thread_recompute_qos(thread);
1307 thread_t thread;
1309 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1311 thread_mtx_lock(thread);
1313 thread_task_priority(thread, priority, max_priority);
1315 thread_mtx_unlock(thread);
1319 rethrottle_thread(thread->uthread);
1323 sfi_reevaluate(thread);
1327 thread->requested_policy.bg_iotier = task->effective_policy.bg_iotier;
1328 thread->requested_policy.terminated = task->effective_policy.terminated;
1330 task_policy_update_internal_locked(task, thread, FALSE, NULL);
1331 /* The thread policy must not emit any completion actions due to this change. */
1341 task_policy_update_complete_unlocked(task_t task, thread_t thread, task_pend_token_t pend_token)
1343 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1347 proc_apply_task_networkbg(task->bsd_info, thread);
1369 * TODO: Do we need to check task->active or thread->active?
1373 thread_t thread,
1383 (IMPORTANCE_CODE(flavor, (category | tisthread(thread)))) | DBG_FUNC_START,
1384 targetid(task, thread), trequested_0(task, thread), trequested_1(task, thread), value, 0);
1386 proc_set_task_policy_locked(task, thread, category, flavor, value);
1388 task_policy_update_locked(task, thread, &pend_token);
1393 (IMPORTANCE_CODE(flavor, (category | tisthread(thread)))) | DBG_FUNC_END,
1394 targetid(task, thread), trequested_0(task, thread), trequested_1(task, thread), tpending(&pend_token), 0);
1396 task_policy_update_complete_unlocked(task, thread, &pend_token);
1400 * Initiate a task policy state transition on a thread with its TID
1401 * Useful if you cannot guarantee the thread won't get terminated
1410 thread_t thread;
1417 thread = self;
1419 thread = task_findtid(task, tid);
1421 if (thread == THREAD_NULL) {
1428 targetid(task, thread), trequested_0(task, thread), trequested_1(task, thread), value, 0);
1430 proc_set_task_policy_locked(task, thread, category, flavor, value);
1432 task_policy_update_locked(task, thread, &pend_token);
1438 targetid(task, thread), trequested_0(task, thread), trequested_1(task, thread), tpending(&pend_token), 0);
1440 task_policy_update_complete_unlocked(task, thread, &pend_token);
1448 proc_set_task_policy2(task_t task, thread_t thread, int category, int flavor, int value1, int value2)
1455 (IMPORTANCE_CODE(flavor, (category | tisthread(thread)))) | DBG_FUNC_START,
1456 targetid(task, thread), trequested_0(task, thread), trequested_1(task, thread), value1, 0);
1458 proc_set_task_policy2_locked(task, thread, category, flavor, value1, value2);
1460 task_policy_update_locked(task, thread, &pend_token);
1465 (IMPORTANCE_CODE(flavor, (category | tisthread(thread)))) | DBG_FUNC_END,
1466 targetid(task, thread), trequested_0(task, thread), trequested_0(task, thread), tpending(&pend_token), 0);
1468 task_policy_update_complete_unlocked(task, thread, &pend_token);
1479 thread_t thread,
1484 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1489 (on_task) ? task->requested_policy : thread->requested_policy;
1493 /* Category: EXTERNAL and INTERNAL, thread and task */
1569 /* Category: ATTRIBUTE, thread only */
1599 thread->requested_policy = requested;
1607 thread_t thread,
1613 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1616 (on_task) ? task->requested_policy : thread->requested_policy;
1634 /* Category: ATTRIBUTE, thread only */
1641 DTRACE_BOOST3(qos_set, uint64_t, thread->thread_id, int, requested.thrp_qos, int, requested.thrp_qos_relprio);
1652 thread->requested_policy = requested;
1661 thread_t thread,
1665 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1672 (on_task) ? task->requested_policy : thread->requested_policy;
1735 proc_get_task_policy2(task_t task, thread_t thread, int category __unused, int flavor, int *value1, int *value2)
1737 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1742 (on_task) ? task->requested_policy : thread->requested_policy;
1787 proc_get_effective_thread_policy(thread_t thread, int flavor)
1789 return proc_get_effective_policy(thread->task, thread, flavor);
1802 thread_t thread,
1805 boolean_t on_task = (thread == THREAD_NULL) ? TRUE : FALSE;
1822 thread->effective_policy.darwinbg) ? 1 : 0;
1835 thread->effective_policy.io_tier);
1836 if (thread->iotier_override != THROTTLE_LEVEL_NONE)
1837 value = MIN(value, thread->iotier_override);
1852 int io_tier = MAX(task->effective_policy.io_tier, thread->effective_policy.io_tier);
1853 boolean_t override_in_effect = (thread->iotier_override != THROTTLE_LEVEL_NONE) && (thread->iotier_override < io_tier);
1856 thread->effective_policy.io_passive || override_in_effect) ? 1 : 0;
1864 * This consults both thread and task so un-DBGing a thread while the task is BG
1871 thread->effective_policy.all_sockets_bg) ? 1 : 0;
1882 thread->effective_policy.new_sockets_bg) ? 1 : 0;
1892 thread->effective_policy.lowpri_cpu) ? 1 : 0;
1909 value = MAX(task->effective_policy.t_latency_qos, thread->effective_policy.t_latency_qos);
1933 value = thread->effective_policy.thep_qos;
2016 proc_apply_workq_bgthreadpolicy(thread_t thread)
2018 if (thread == THREAD_NULL)
2021 proc_set_task_policy(thread->task, thread, TASK_POLICY_ATTRIBUTE,
2032 proc_restore_workq_bgthreadpolicy(thread_t thread)
2034 if (thread == THREAD_NULL)
2037 proc_set_task_policy(thread->task, thread, TASK_POLICY_ATTRIBUTE,
2045 proc_setthread_saved_importance(__unused thread_t thread, __unused int importance)
2051 * Set an override on the thread which is consulted with a
2052 * higher priority than the task/thread policy. This should
2053 * only be set for temporary grants until the thread
2057 * the assumption that the thread itself can
2062 * However a thread reference must be held on the thread.
2065 void set_thread_iotier_override(thread_t thread, int policy)
2071 current_override = thread->iotier_override;
2080 } while (!OSCompareAndSwap(current_override, policy, &thread->iotier_override));
2083 * Since the thread may be currently throttled,
2087 rethrottle_thread(thread->uthread);
2094 * priority thread. In these cases, we attempt to propagate the priority token, as long
2104 boolean_t proc_thread_qos_add_override(task_t task, thread_t thread, uint64_t tid, int override_qos, boolean_t first_override_for_resource)
2110 /* XXX move to thread mutex when thread policy does */
2114 * If thread is passed, it is assumed to be most accurate, since the caller must have an explicit (or implicit) reference
2115 * to the thread
2118 if (thread != THREAD_NULL) {
2119 assert(task == thread->task);
2122 thread = self;
2124 thread = task_findtid(task, tid);
2126 if (thread == THREAD_NULL) {
2136 thread_tid(thread), override_qos, first_override_for_resource ? 1 : 0, 0, 0);
2138 DTRACE_BOOST5(qos_add_override_pre, uint64_t, tid, uint64_t, thread->requested_policy.thrp_qos,
2139 uint64_t, thread->effective_policy.thep_qos, int, override_qos, boolean_t, first_override_for_resource);
2142 resource_count = ++thread->usynch_override_contended_resource_count;
2144 resource_count = thread->usynch_override_contended_resource_count;
2147 struct task_requested_policy requested = thread->requested_policy;
2154 thread->requested_policy = requested;
2156 task_policy_update_locked(task, thread, &pend_token);
2158 thread_reference(thread);
2162 task_policy_update_complete_unlocked(task, thread, &pend_token);
2165 uint64_t, thread->effective_policy.thep_qos, int, resource_count);
2167 thread_deallocate(thread);
2175 boolean_t proc_thread_qos_remove_override(task_t task, thread_t thread, uint64_t tid)
2181 /* XXX move to thread mutex when thread policy does */
2185 * If thread is passed, it is assumed to be most accurate, since the caller must have an explicit (or implicit) reference
2186 * to the thread
2188 if (thread != THREAD_NULL) {
2189 assert(task == thread->task);
2192 thread = self;
2194 thread = task_findtid(task, tid);
2196 if (thread == THREAD_NULL) {
2205 resource_count = --thread->usynch_override_contended_resource_count;
2208 thread_tid(thread), resource_count, 0, 0, 0);
2211 thread->requested_policy.thrp_qos_override = THREAD_QOS_UNSPECIFIED;
2213 task_policy_update_locked(task, thread, &pend_token);
2215 thread_reference(thread);
2219 task_policy_update_complete_unlocked(task, thread, &pend_token);
2221 thread_deallocate(thread);
2223 // panic("usynch_override_contended_resource_count underflow for thread %p", thread);
2354 /* Set up the primordial thread's QoS */
2455 /* All per-thread state is in the first 32-bits of the bitfield */
2457 proc_get_thread_policy(thread_t thread, thread_policy_state_t info)
2459 task_t task = thread->task;
2461 info->requested = (integer_t)task_requested_bitfield(task, thread);
2462 info->effective = (integer_t)task_effective_bitfield(task, thread);
2471 * Each task/thread requested/effective structure is 64 bits in size. Any
2474 * A tracepoint may emit any of task, thread, or task & thread data.
2477 * task and thread data are emitted. In LP32 systems, the first and second
2478 * halves of either the task or thread data is emitted.
2486 * 1) task and thread are uintptr_t*
2493 * trequested_0(task, thread) thread[0] task[0]
2494 * trequested_1(task, thread) thread[1] thread[0]
2496 * Basically, you get a full task or thread on LP32, and both on LP64.
2510 trequested_0(task_t task, thread_t thread)
2514 _Static_assert(sizeof(task->requested_policy) == sizeof(thread->requested_policy), "size invariant violated");
2516 uintptr_t* raw = (uintptr_t*)((thread == THREAD_NULL) ? &task->requested_policy : &thread->requested_policy);
2521 trequested_1(task_t task, thread_t thread)
2525 _Static_assert(sizeof(task->requested_policy) == sizeof(thread->requested_policy), "size invariant violated");
2528 return (thread == NULL) ? 0 : *(uintptr_t*)&thread->requested_policy;
2530 uintptr_t* raw = (uintptr_t*)((thread == THREAD_NULL) ? &task->requested_policy : &thread->requested_policy);
2536 teffective_0(task_t task, thread_t thread)
2540 _Static_assert(sizeof(task->effective_policy) == sizeof(thread->effective_policy), "size invariant violated");
2542 uintptr_t* raw = (uintptr_t*)((thread == THREAD_NULL) ? &task->effective_policy : &thread->effective_policy);
2547 teffective_1(task_t task, thread_t thread)
2551 _Static_assert(sizeof(task->effective_policy) == sizeof(thread->effective_policy), "size invariant violated");
2554 return (thread == NULL) ? 0 : *(uintptr_t*)&thread->effective_policy;
2556 uintptr_t* raw = (uintptr_t*)((thread == THREAD_NULL) ? &task->effective_policy : &thread->effective_policy);
2565 task_requested_bitfield(task_t task, thread_t thread)
2569 (thread == THREAD_NULL) ? task->requested_policy : thread->requested_policy;
2583 if (thread != THREAD_NULL) {
2613 task_effective_bitfield(task_t task, thread_t thread)
2617 (thread == THREAD_NULL) ? task->effective_policy : thread->effective_policy;
2629 if (thread != THREAD_NULL)
2681 * For tasks which have this mechanism activated: if any thread in the
2719 * PROC_POLICY_RSRCACT_NOTIFY_EXC | ENOTSUP | Per-thread scope only
2727 * in the task are added together), or by any one thread in the task (so-called "per-thread" scope).
2734 * Currently, requesting notification via an exception is the only way to get per-thread scope for a
2866 * only allows for one at a time. This means that if there is a per-thread limit active, the other
2901 thread_t thread;
2918 * Disable the monitor for the task, and propagate that change to each thread.
2921 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2922 set_astledger(thread);
2933 thread_t thread;
2948 * A per-thread CPU limit on a task generates an exception
2949 * (LEDGER_ACTION_EXCEPTION) if any one thread in the task
2982 * - Leave the interval as-is, if there's already a per-thread
3026 queue_iterate(&task->threads, thread, thread_t, task_threads) {
3027 set_astledger(thread);