LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC PATCH] RTTIME watchdog timer proc interface
@ 2008-02-11 21:44 Hiroshi Shimamoto
  2008-02-11 21:52 ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Hiroshi Shimamoto @ 2008-02-11 21:44 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, a.p.zijlstra

Hi Ingo,

I think an interface to access RLIMIT_RTTIME from outside is useful.
It makes administrator able to set RLIMIT_RTTIME watchdog to existing
real-time applications without impact.

I implemented that interface with /proc filesystem.

---
From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>

Introduce new proc interface for RTTIME watchdog.
It makes administrator able to set RTTIME watchdog to existing applications.

$ echo 10000000 > /proc/<pid>/rttime
set RTTIME current value to 10000000, it means 10sec.

$ echo "10000000 20000000" > /proc/<pid>/rttime
set RTTIME current value to 10000000 and max value to 20000000.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
---
 fs/proc/base.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7c6b4ec..5689c0e 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -381,6 +381,93 @@ static const struct file_operations proc_lstats_operations = {
 
 #endif
 
+static int rttime_show_proc(struct seq_file *m, void *v)
+{
+	struct task_struct *task = m->private;
+	struct signal_struct *signal = task->signal;
+	struct rlimit *rt = &signal->rlim[RLIMIT_RTTIME];
+
+	if (rt->rlim_cur == RLIM_INFINITY)
+		seq_printf(m, "unlimited ");
+	else
+		seq_printf(m, "%lu ", rt->rlim_cur);
+
+	if (rt->rlim_max == RLIM_INFINITY)
+		seq_printf(m, "unlimited\n");
+	else
+		seq_printf(m, "%lu\n", rt->rlim_max);
+
+	return 0;
+}
+
+static int rttime_open(struct inode *inode, struct file *file)
+{
+	int ret;
+	struct seq_file *m;
+	struct task_struct *task = get_proc_task(inode);
+
+	ret = single_open(file, rttime_show_proc, NULL);
+	if (!ret) {
+		m = file->private_data;
+		m->private = task;
+	}
+	return ret;
+}
+
+static ssize_t rttime_write(struct file *file,
+			    const char __user *buf,
+			    size_t count,
+			    loff_t *ppos)
+{
+	struct seq_file *m = file->private_data;
+	struct task_struct *task = m->private;
+	char buffer[PROC_NUMBUF], *end;
+	struct rlimit new_rlim, *old_rlim;
+	int n, ret;
+
+	old_rlim = task->signal->rlim + RLIMIT_RTTIME;
+	new_rlim = *old_rlim;
+	memset(buffer, 0, sizeof(buffer));
+	n = count;
+	if (n > sizeof(buffer) - 1)
+		n = sizeof(buffer) - 1;
+	if (copy_from_user(buffer, buf, n))
+		return -EFAULT;
+	new_rlim.rlim_cur = simple_strtoul(buffer, &end, 0);
+	if (*end == ' ') {
+		++end;
+		buf += end - buffer;
+		memset(buffer, 0, sizeof(buffer));
+		n = count - (end - buffer);
+		if (n > sizeof(buffer) - 1)
+			n = sizeof(buffer) - 1;
+		if (copy_from_user(buffer, buf, n))
+			return -EFAULT;
+		new_rlim.rlim_max = simple_strtoul(buffer, &end, 0);
+	}
+	if (new_rlim.rlim_cur > new_rlim.rlim_max)
+		return -EINVAL;
+	if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
+	    !capable(CAP_SYS_RESOURCE))
+		return -EPERM;
+	ret = security_task_setrlimit(RLIMIT_RTTIME, &new_rlim);
+	if (ret)
+		return ret;
+	task_lock(task->group_leader);
+	*old_rlim = new_rlim;
+	task_unlock(task->group_leader);
+
+	return count;
+}
+
+static const struct file_operations proc_rttime_operations = {
+	.open		= rttime_open,
+	.read		= seq_read,
+	.write		= rttime_write,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 /* The badness from the OOM killer */
 unsigned long badness(struct task_struct *p, unsigned long uptime);
 static int proc_oom_score(struct task_struct *task, char *buffer)
@@ -2300,6 +2387,7 @@ static const struct pid_entry tgid_base_stuff[] = {
 	LNK("exe",        exe),
 	REG("mounts",     S_IRUGO, mounts),
 	REG("mountstats", S_IRUSR, mountstats),
+	REG("rttime",     S_IRUSR|S_IWUSR, rttime),
 #ifdef CONFIG_PROC_PAGE_MONITOR
 	REG("clear_refs", S_IWUSR, clear_refs),
 	REG("smaps",      S_IRUGO, smaps),
-- 
1.5.3.8


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

* Re: [RFC PATCH] RTTIME watchdog timer proc interface
  2008-02-11 21:44 [RFC PATCH] RTTIME watchdog timer proc interface Hiroshi Shimamoto
@ 2008-02-11 21:52 ` Peter Zijlstra
  2008-02-11 23:03   ` Alexey Dobriyan
  2008-02-12 22:21   ` Hiroshi Shimamoto
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2008-02-11 21:52 UTC (permalink / raw)
  To: Hiroshi Shimamoto; +Cc: mingo, linux-kernel


On Mon, 2008-02-11 at 13:44 -0800, Hiroshi Shimamoto wrote:
> Hi Ingo,
> 
> I think an interface to access RLIMIT_RTTIME from outside is useful.
> It makes administrator able to set RLIMIT_RTTIME watchdog to existing
> real-time applications without impact.
> 
> I implemented that interface with /proc filesystem.

/proc/<pid>/tasks/<tid>/rttime might also make sense.



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

* Re: [RFC PATCH] RTTIME watchdog timer proc interface
  2008-02-11 21:52 ` Peter Zijlstra
@ 2008-02-11 23:03   ` Alexey Dobriyan
  2008-02-12 22:21   ` Hiroshi Shimamoto
  1 sibling, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2008-02-11 23:03 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Hiroshi Shimamoto, mingo, linux-kernel

On Mon, Feb 11, 2008 at 10:52:47PM +0100, Peter Zijlstra wrote:
> 
> On Mon, 2008-02-11 at 13:44 -0800, Hiroshi Shimamoto wrote:
> > Hi Ingo,
> > 
> > I think an interface to access RLIMIT_RTTIME from outside is useful.
> > It makes administrator able to set RLIMIT_RTTIME watchdog to existing
> > real-time applications without impact.
> > 
> > I implemented that interface with /proc filesystem.
> 
> /proc/<pid>/tasks/<tid>/rttime might also make sense.

As well as /proc/*/limits for all kinds of rlimit stuff.

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

* Re: [RFC PATCH] RTTIME watchdog timer proc interface
  2008-02-11 21:52 ` Peter Zijlstra
  2008-02-11 23:03   ` Alexey Dobriyan
@ 2008-02-12 22:21   ` Hiroshi Shimamoto
  2008-02-13  9:27     ` Peter Zijlstra
  1 sibling, 1 reply; 6+ messages in thread
From: Hiroshi Shimamoto @ 2008-02-12 22:21 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, linux-kernel

Peter Zijlstra wrote:
> On Mon, 2008-02-11 at 13:44 -0800, Hiroshi Shimamoto wrote:
>> Hi Ingo,
>>
>> I think an interface to access RLIMIT_RTTIME from outside is useful.
>> It makes administrator able to set RLIMIT_RTTIME watchdog to existing
>> real-time applications without impact.
>>
>> I implemented that interface with /proc filesystem.
> 
> /proc/<pid>/tasks/<tid>/rttime might also make sense.
> 
thanks, I'll add.


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

* Re: [RFC PATCH] RTTIME watchdog timer proc interface
  2008-02-12 22:21   ` Hiroshi Shimamoto
@ 2008-02-13  9:27     ` Peter Zijlstra
  2008-02-13 17:57       ` Hiroshi Shimamoto
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2008-02-13  9:27 UTC (permalink / raw)
  To: Hiroshi Shimamoto; +Cc: mingo, linux-kernel


On Tue, 2008-02-12 at 14:21 -0800, Hiroshi Shimamoto wrote:
> Peter Zijlstra wrote:
> > On Mon, 2008-02-11 at 13:44 -0800, Hiroshi Shimamoto wrote:
> >> Hi Ingo,
> >>
> >> I think an interface to access RLIMIT_RTTIME from outside is useful.
> >> It makes administrator able to set RLIMIT_RTTIME watchdog to existing
> >> real-time applications without impact.
> >>
> >> I implemented that interface with /proc filesystem.
> > 
> > /proc/<pid>/tasks/<tid>/rttime might also make sense.
> > 
> thanks, I'll add.

I just realized that because its an rlimit, we store these values
process-wide. The per task thing was a feature request from someone, and
I just jumped on your interface without proper consideration.

I'll need to think a bit more on this


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

* Re: [RFC PATCH] RTTIME watchdog timer proc interface
  2008-02-13  9:27     ` Peter Zijlstra
@ 2008-02-13 17:57       ` Hiroshi Shimamoto
  0 siblings, 0 replies; 6+ messages in thread
From: Hiroshi Shimamoto @ 2008-02-13 17:57 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, linux-kernel

Peter Zijlstra wrote:
> On Tue, 2008-02-12 at 14:21 -0800, Hiroshi Shimamoto wrote:
>> Peter Zijlstra wrote:
>>> On Mon, 2008-02-11 at 13:44 -0800, Hiroshi Shimamoto wrote:
>>>> Hi Ingo,
>>>>
>>>> I think an interface to access RLIMIT_RTTIME from outside is useful.
>>>> It makes administrator able to set RLIMIT_RTTIME watchdog to existing
>>>> real-time applications without impact.
>>>>
>>>> I implemented that interface with /proc filesystem.
>>> /proc/<pid>/tasks/<tid>/rttime might also make sense.
>>>
>> thanks, I'll add.
> 
> I just realized that because its an rlimit, we store these values
> process-wide. The per task thing was a feature request from someone, and
> I just jumped on your interface without proper consideration.

I know RLIMIT_RTTIME is process-wide.
I'm not sure that someone requests for the per task.

> 
> I'll need to think a bit more on this

OK.

Thanks,
Hiroshi Shimamoto

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

end of thread, other threads:[~2008-02-13 17:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-11 21:44 [RFC PATCH] RTTIME watchdog timer proc interface Hiroshi Shimamoto
2008-02-11 21:52 ` Peter Zijlstra
2008-02-11 23:03   ` Alexey Dobriyan
2008-02-12 22:21   ` Hiroshi Shimamoto
2008-02-13  9:27     ` Peter Zijlstra
2008-02-13 17:57       ` Hiroshi Shimamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).