Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b88e16ce authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "proc: Add files for specifying scheduling related per-task attributes"

parents 3ee4b6f5 7e56ff05
Loading
Loading
Loading
Loading
+205 −0
Original line number Diff line number Diff line
@@ -1457,6 +1457,204 @@ static const struct file_operations proc_pid_sched_operations = {

#endif

/*
 * Print out various scheduling related per-task fields:
 */

#ifdef CONFIG_SMP

static int sched_wake_up_idle_show(struct seq_file *m, void *v)
{
	struct inode *inode = m->private;
	struct task_struct *p;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	seq_printf(m, "%d\n", sched_get_wake_up_idle(p));

	put_task_struct(p);

	return 0;
}

static ssize_t
sched_wake_up_idle_write(struct file *file, const char __user *buf,
	    size_t count, loff_t *offset)
{
	struct inode *inode = file_inode(file);
	struct task_struct *p;
	char buffer[PROC_NUMBUF];
	int wake_up_idle, err;

	memset(buffer, 0, sizeof(buffer));
	if (count > sizeof(buffer) - 1)
		count = sizeof(buffer) - 1;
	if (copy_from_user(buffer, buf, count)) {
		err = -EFAULT;
		goto out;
	}

	err = kstrtoint(strstrip(buffer), 0, &wake_up_idle);
	if (err)
		goto out;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	err = sched_set_wake_up_idle(p, wake_up_idle);

	put_task_struct(p);

out:
	return err < 0 ? err : count;
}

static int sched_wake_up_idle_open(struct inode *inode, struct file *filp)
{
	return single_open(filp, sched_wake_up_idle_show, inode);
}

static const struct file_operations proc_pid_sched_wake_up_idle_operations = {
	.open		= sched_wake_up_idle_open,
	.read		= seq_read,
	.write		= sched_wake_up_idle_write,
	.llseek		= seq_lseek,
	.release	= single_release,
};

#endif	/* CONFIG_SMP */

#ifdef CONFIG_SCHED_WALT

static int sched_init_task_load_show(struct seq_file *m, void *v)
{
	struct inode *inode = m->private;
	struct task_struct *p;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	seq_printf(m, "%d\n", sched_get_init_task_load(p));

	put_task_struct(p);

	return 0;
}

static ssize_t
sched_init_task_load_write(struct file *file, const char __user *buf,
	    size_t count, loff_t *offset)
{
	struct inode *inode = file_inode(file);
	struct task_struct *p;
	char buffer[PROC_NUMBUF];
	int init_task_load, err;

	memset(buffer, 0, sizeof(buffer));
	if (count > sizeof(buffer) - 1)
		count = sizeof(buffer) - 1;
	if (copy_from_user(buffer, buf, count)) {
		err = -EFAULT;
		goto out;
	}

	err = kstrtoint(strstrip(buffer), 0, &init_task_load);
	if (err)
		goto out;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	err = sched_set_init_task_load(p, init_task_load);

	put_task_struct(p);

out:
	return err < 0 ? err : count;
}

static int sched_init_task_load_open(struct inode *inode, struct file *filp)
{
	return single_open(filp, sched_init_task_load_show, inode);
}

static const struct file_operations proc_pid_sched_init_task_load_operations = {
	.open		= sched_init_task_load_open,
	.read		= seq_read,
	.write		= sched_init_task_load_write,
	.llseek		= seq_lseek,
	.release	= single_release,
};

static int sched_group_id_show(struct seq_file *m, void *v)
{
	struct inode *inode = m->private;
	struct task_struct *p;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	seq_printf(m, "%d\n", sched_get_group_id(p));

	put_task_struct(p);

	return 0;
}

static ssize_t
sched_group_id_write(struct file *file, const char __user *buf,
	    size_t count, loff_t *offset)
{
	struct inode *inode = file_inode(file);
	struct task_struct *p;
	char buffer[PROC_NUMBUF];
	int group_id, err;

	memset(buffer, 0, sizeof(buffer));
	if (count > sizeof(buffer) - 1)
		count = sizeof(buffer) - 1;
	if (copy_from_user(buffer, buf, count)) {
		err = -EFAULT;
		goto out;
	}

	err = kstrtoint(strstrip(buffer), 0, &group_id);
	if (err)
		goto out;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	err = sched_set_group_id(p, group_id);

	put_task_struct(p);

out:
	return err < 0 ? err : count;
}

static int sched_group_id_open(struct inode *inode, struct file *filp)
{
	return single_open(filp, sched_group_id_show, inode);
}

static const struct file_operations proc_pid_sched_group_id_operations = {
	.open		= sched_group_id_open,
	.read		= seq_read,
	.write		= sched_group_id_write,
	.llseek		= seq_lseek,
	.release	= single_release,
};

#endif	/* CONFIG_SCHED_WALT */

#ifdef CONFIG_SCHED_AUTOGROUP
/*
 * Print out autogroup related information:
@@ -2933,6 +3131,13 @@ static const struct pid_entry tgid_base_stuff[] = {
	ONE("status",     S_IRUGO, proc_pid_status),
	ONE("personality", S_IRUSR, proc_pid_personality),
	ONE("limits",	  S_IRUGO, proc_pid_limits),
#ifdef CONFIG_SMP
	REG("sched_wake_up_idle", 00644, proc_pid_sched_wake_up_idle_operations),
#endif
#ifdef CONFIG_SCHED_WALT
	REG("sched_init_task_load", 00644, proc_pid_sched_init_task_load_operations),
	REG("sched_group_id", 00666, proc_pid_sched_group_id_operations),
#endif
#ifdef CONFIG_SCHED_DEBUG
	REG("sched",      S_IRUGO|S_IWUSR, proc_pid_sched_operations),
#endif