int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice) { static unsigned long next = INITIAL_JIFFIES; struct autogroup *ag; int err; if (*nice < -20 || *nice > 19) return -EINVAL; err = security_task_setnice(current, *nice); if (err) return err; if (*nice < 0 && !can_nice(current, *nice)) return -EPERM; /* this is a heavy operation taking global locks.. */ if (!capable(CAP_SYS_ADMIN) && time_before(jiffies, next)) return -EAGAIN; next = HZ / 10 + jiffies; ag = autogroup_task_get(p); down_write(&ag->lock); err = sched_group_set_shares(ag->tg, prio_to_weight[*nice + 20]); if (!err) ag->nice = *nice; up_write(&ag->lock); autogroup_kref_put(ag); return err; }
int linsched_test_main(int argc, char **argv) { struct task_struct *p; struct cgroup *cgrp; /* Initialize linsched. */ linsched_init(NULL); cgrp = linsched_create_cgroup(root_cgroup, "test"); sched_group_set_shares(cgroup_tg(cgrp), 2048); /* Create some tasks with "callbacks" that should be called * every scheduling decision. */ linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); linsched_create_RTrr_task(linsched_create_sleep_run(8, 2), 90); linsched_create_RTfifo_task(linsched_create_sleep_run(8, 2), 55); /* create more tasks here... */ p = linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); linsched_add_task_to_group(p, cgrp); linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); linsched_create_normal_task(linsched_create_sleep_run(8, 2), 0); /* Run simulation for 500 ticks. */ linsched_run_sim(500); #if 0 /* Force migrations between two CPUs, and allow migrations * afterwards (so load balancing will kick in eventually). */ linsched_force_migration(linsched_get_task(2), 0, 1); #endif /* Run simulation to completion. */ linsched_run_sim(LINSCHED_TICKS-500); return 0; }