| Previous | Next |
| KERN_POLICY_LIMIT | KERN_INVALID_OBJECT |
KERN_INVALID_POLICY
The policy is not available in this context
KERN_INVALID_POLICY is a Mach scheduler result, not a statement that the policy-data pointer is malformed. The declaration in kern_return.h describes a scheduling policy that is not currently enabled for the processor-set context. In current XNU code, the same result is also used when a thread is not allowed to enter a requested real-time mode or when affinity sets are disabled.
That makes the policy flavor essential diagnostic data. A request that is valid on one system, thread class, or workload context can be unavailable on another without any change to the structure layout.
Two concrete policy contexts
THREAD_TIME_CONSTRAINT_POLICYrequests real-time scheduling parameters. Current XNU rejects that request withKERN_INVALID_POLICYwhen the thread belongs to a work interval with a workload ID that does not permit real-time operation.THREAD_AFFINITY_POLICYis marked experimental in the XNU header. It expresses an affinity relationship between threads; matching tags are only a scheduler hint to share an L2 cache when possible. It is not a request to pin a thread to a particular processor, and XNU returnsKERN_INVALID_POLICYwhen affinity sets are disabled.
Separate availability from bad input
| Result | What it points to |
|---|---|
KERN_INVALID_POLICY | The policy cannot be applied in the target’s current scheduling context. |
KERN_POLICY_LIMIT | The requested attributes exceed a limit even though the policy is applicable. |
KERN_INVALID_ARGUMENT | The call contract is wrong: for example, an invalid target, flavor, count, or field value. |
KERN_NOT_SUPPORTED | The selected facility is not supported by the current platform or implementation. |
Useful investigation data
- Log the policy flavor and its complete structure, rather than only the numeric return value.
- Identify whether the target is the calling thread or another thread, and whether it has joined a work interval or has an existing QoS policy.
- For affinity, verify the intended outcome. Cache-affinity tags are advisory relationships, not a portable CPU-binding mechanism.
- For real-time requests, review the timing model before retrying. The policy data specifies period, computation, and constraint in absolute-time units, and the constraint must not be smaller than computation.