- uint8_t percentage;
-
- case PROC_POLICY_ACTION_GET:
- error = proc_get_task_ruse_cpu(proc->task, &cpuattr.ppattr_cpu_attr,
- &percentage,
- &cpuattr.ppattr_cpu_attr_interval,
- &cpuattr.ppattr_cpu_attr_deadline);
- if (error == 0) {
- cpuattr.ppattr_cpu_percentage = percentage;
- cpuattr.ppattr_cpu_attr_interval /= NSEC_PER_SEC;
- error = copyout((proc_policy_cpuusage_attr_t *)&cpuattr, (user_addr_t)attrp, sizeof(proc_policy_cpuusage_attr_t));
- }
- break;
+ case PROC_POLICY_ACTION_GET:
+ error = proc_get_task_ruse_cpu(proc->task, &cpuattr.ppattr_cpu_attr,
+ &percentage,
+ &cpuattr.ppattr_cpu_attr_interval,
+ &cpuattr.ppattr_cpu_attr_deadline);
+ if (error == 0) {
+ cpuattr.ppattr_cpu_percentage = percentage;
+ cpuattr.ppattr_cpu_attr_interval /= NSEC_PER_SEC;
+ error = copyout((proc_policy_cpuusage_attr_t *)&cpuattr, (user_addr_t)attrp, sizeof(proc_policy_cpuusage_attr_t));
+ }
+ break;
+
+ case PROC_POLICY_ACTION_APPLY:
+ case PROC_POLICY_ACTION_SET:
+ error = copyin((user_addr_t)attrp, (proc_policy_cpuusage_attr_t *)&cpuattr, sizeof(proc_policy_cpuusage_attr_t));
+ if (error != 0) {
+ return error;
+ }
+
+ /*
+ * The process_policy API uses seconds as the units for the interval,
+ * but the mach task policy SPI uses nanoseconds. Do the conversion,
+ * but preserve -1 as it has special meaning.
+ */
+ if (cpuattr.ppattr_cpu_attr_interval != -1ULL) {
+ interval = cpuattr.ppattr_cpu_attr_interval * NSEC_PER_SEC;
+ } else {
+ interval = -1ULL;
+ }
+
+ error = proc_set_task_ruse_cpu(proc->task, cpuattr.ppattr_cpu_attr,
+ cpuattr.ppattr_cpu_percentage,
+ interval,
+ cpuattr.ppattr_cpu_attr_deadline,
+ privileged);
+ break;
+
+ /* restore process to prior state */
+ case PROC_POLICY_ACTION_RESTORE:
+ error = proc_clear_task_ruse_cpu(proc->task, privileged);
+ break;
+
+ /* re-enable suspended monitor */
+ case PROC_POLICY_ACTION_ENABLE:
+ error = task_resume_cpumon(proc->task);
+ break;
+
+ case PROC_POLICY_ACTION_REMOVE:
+
+ default:
+ error = EINVAL;
+ break;
+ }