lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 31 Dec 2009 13:01:49 -0800
From:	"Smith, GeoffX" <geoffx.smith@...el.com>
To:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:	Arjan van de Ven <arjan@...radead.org>
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, arjan@...ux.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@...el.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ