mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] proc: Get/set timer slack through /proc
@ 2009-12-31 21:01 Smith, GeoffX
  2010-01-01 23:14 ` Arjan van de Ven
  0 siblings, 1 reply; 3+ messages in thread
From: Smith, GeoffX @ 2009-12-31 21:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arjan van de Ven

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, arjan@linux.intel.com 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 <geoffx.smith@intel.com>


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-04 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-31 21:01 [PATCH] proc: Get/set timer slack through /proc Smith, GeoffX
2010-01-01 23:14 ` Arjan van de Ven
2010-01-04 17:29   ` Smith, GeoffX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®