2009-12-31 21:01:53

by Smith, GeoffX

[permalink] [raw]
Subject: [PATCH] proc: Get/set timer slack through /proc

Subject: Get/set timer_slack_ns through /proc

This patch makes the timer_slack_ns parameter accessible through the /proc system.

On 9/1/2008, [email protected] submitted a patch to allow a process to set the timer slack value as part of the range timers feature. Further, he noted that "Applications and admins can override this [the timer slack value] via the prctl()."

We have found this feature useful in attempting to reduce system wakeups caused by timer interrupts. But we have also found that while applications can set their own timer slack value, there is no provision for setting the timer slack for another process -- prctl() only operates on the current process.

This patch solves the problem by adding a /proc entry point to show and set the timer_slack_ns value. The new entry point is /proc/<procid>/task/<task_id>/timer_slack_ns and follows the same semantics as other single-valued /proc entry points.

Signed-off-by: Geoff Smith <[email protected]>


diff --git a/fs/proc/base.c b/fs/proc/base.c
index 18d5cc6..e8183c1 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1331,6 +1331,82 @@ static const struct file_operations proc_pid_set_comm_operations = {
.release = single_release,
};

+
+/*
+ * Show timer slack value
+ */
+static int timer_slack_ns_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;
+ task_lock(p);
+ seq_printf(m, "%lu", p->timer_slack_ns);
+ task_unlock(p);
+
+ put_task_struct(p);
+
+ return 0;
+}
+
+static ssize_t
+timer_slack_ns_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *offset)
+{
+ struct inode *inode = file->f_path.dentry->d_inode;
+ struct task_struct *p;
+ char buff[30];
+ unsigned long timer_slack_ns;
+ int err;
+
+ p = get_proc_task(inode);
+ if (!p)
+ return -ESRCH;
+
+ if (count > sizeof(buff))
+ return -EFAULT;
+
+ buff[sizeof(buff)-1] = 0;
+ if (strncpy_from_user(buff, buf, sizeof(buff)-1) < 0)
+ return -EFAULT;
+
+ err = strict_strtoul(strstrip(buff), 0, &timer_slack_ns);
+ if (err)
+ return -EINVAL;
+
+ task_lock(p);
+ p->timer_slack_ns = timer_slack_ns;
+ task_unlock(p);
+
+ put_task_struct(p);
+
+ return count;
+}
+
+static int timer_slack_ns_open(struct inode *inode, struct file *filp)
+{
+ int ret;
+
+ ret = single_open(filp, timer_slack_ns_show, NULL);
+ if (!ret) {
+ struct seq_file *m = filp->private_data;
+
+ m->private = inode;
+ }
+ return ret;
+}
+
+static const struct file_operations proc_pid_timer_slack_ns_operations = {
+ .open = timer_slack_ns_open,
+ .read = seq_read,
+ .write = timer_slack_ns_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/*
* We added or removed a vma mapping the executable. The vmas are only mapped
* during exec and are not mapped with the mmap system call.
@@ -2906,6 +2982,7 @@ static const struct pid_entry tid_base_stuff[] = {
REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
#endif
REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
+ REG("timer_slack_ns", S_IRUGO|S_IWUSR, proc_pid_timer_slack_ns_operations),
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
INF("syscall", S_IRUSR, proc_pid_syscall),
#endif


2010-01-01 23:12:13

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] proc: Get/set timer slack through /proc

On Thu, 31 Dec 2009 13:01:49 -0800
"Smith, GeoffX" <[email protected]> wrote:

> Subject: Get/set timer_slack_ns through /proc
>
> This patch makes the timer_slack_ns parameter accessible through
> the /proc system.
>
> On 9/1/2008, [email protected] submitted a patch to allow a
> process to set the timer slack value as part of the range timers
> feature. Further, he noted that "Applications and admins can
> override this [the timer slack value] via the prctl()."
>
> We have found this feature useful in attempting to reduce system
> wakeups caused by timer interrupts. But we have also found that
> while applications can set their own timer slack value, there is no
> provision for setting the timer slack for another process -- prctl()
> only operates on the current process.
>

this statement is incorrect btw;
timerslack is explicitly inherited over exec, so you can have (and we
do have) a utility similar to the nice program, that launches an
application with a specific timer slack.


--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2010-01-04 17:30:38

by Smith, GeoffX

[permalink] [raw]
Subject: RE: [PATCH] proc: Get/set timer slack through /proc


On Friday, January 01, 2010, [email protected] wrote:

>On Thu, 31 Dec 2009 13:01:49 -0800
>"Smith, GeoffX" <[email protected]> wrote:
>
>> Subject: Get/set timer_slack_ns through /proc
>>
>> This patch makes the timer_slack_ns parameter accessible through
>> the /proc system.
>>
>> On 9/1/2008, [email protected] submitted a patch to allow a
>> process to set the timer slack value as part of the range timers
>> feature. Further, he noted that "Applications and admins can
>> override this [the timer slack value] via the prctl()."
>>
>> We have found this feature useful in attempting to reduce system
>> wakeups caused by timer interrupts. But we have also found that
>> while applications can set their own timer slack value, there is no
>> provision for setting the timer slack for another process -- prctl()
>> only operates on the current process.
>
>this statement is incorrect btw;
>timerslack is explicitly inherited over exec, so you can have (and we
>do have) a utility similar to the nice program, that launches an
>application with a specific timer slack.

Hmmm, that seems a lot less flexible, but I see how that would work.

Nonetheless, using "nice" as a model is that you would have to modify anything that launches applications, right? This would mean modifying /etc/init.d and application scripts, which seems beyond the scope of "admin". Or am I missing something?