Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Kay Sievers
On 10/14/07, Peter Zijlstra <[EMAIL PROTECTED]> wrote:
> The below patch is an idea proposed by tglx and depends on sched-devel +
> the hrtick patch previously posted.
>
> The current watchdog action is to demote the task to SCHED_NORMAL,
> however it might be wanted to deliver a signal instead (or have more per
> task configuration state). Which is why I added Lennart to the CC list
> as I gathered he would like something like this for PulseAudio.

Great, this looks very promising. Thanks for doing this.

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


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Lennart Poettering
On Sun, 14.10.07 00:51, Peter Zijlstra ([EMAIL PROTECTED]) wrote:

> The below patch is an idea proposed by tglx and depends on sched-devel +
> the hrtick patch previously posted.
> 
> The current watchdog action is to demote the task to SCHED_NORMAL,
> however it might be wanted to deliver a signal instead (or have more per
> task configuration state). Which is why I added Lennart to the CC list
> as I gathered he would like something like this for PulseAudio.

Indeed! Having this in the kernel would allow us to enable RT
scheduling for PulseAudio by default without bad effects. I was thinking about
adding some kind of babysitting process to userspace -- but doing this as
an RLIMIT in the kernel strikes me a much better idea!

I think it would make a lot of sense to make the API very similar to
RLIMIT_CPU, i.e. also send out SIGXCPU and SIGKILL, with the single
difference that RLIMIT_CPU sends out a signal depending on the total
CPU time used for the process and the new RLIMIT based on the time the
process spent without sleeping. That would be a very reasonable
extension to the current RLIMIT_CPU model.

Thank you very much for doing this patch!

Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/   GnuPG 0x1A015CC4
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Peter Zijlstra
On Mon, 2007-10-15 at 15:26 +0200, Dmitry Adamushko wrote:
> On 14/10/2007, Peter Zijlstra <[EMAIL PROTECTED]> wrote:
> > The below patch is an idea proposed by tglx and depends on sched-devel +
> > the hrtick patch previously posted.
> >
> > The current watchdog action is to demote the task to SCHED_NORMAL,
> > however it might be wanted to deliver a signal instead (or have more per
> > task configuration state). Which is why I added Lennart to the CC list
> > as I gathered he would like something like this for PulseAudio.
> >
> > ---
> > Subject: sched: SCHED_FIFO watchdog timer
> 
> Why only SHCED_FIFO and not SCHED_RR?
> Their (mis)behavior is similar wrt SCHED_NORMAL tasks.

Because SCHED_FIFO is easier, _RR is for later. It was mostly an RFC to
request behavioural wishes from the users.

> 
> > +#ifdef CONFIG_SCHED_HRT_TICK
> > +static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
> > +{
> > +   if (likely(!queued || p->policy != SCHED_FIFO))
> > +   return 0;
> > +
> > +   /*
> > +* task has been naughty, turn into SCHED_NORMAL
> > +*/
> > +   printk(KERN_INFO "SCHED_FIFO task %s/%d exceeded his runtime quota,"
> > +   " demoting to regular task\n", p->comm, 
> > task_pid_nr(p));
> > +   deactivate_task(rq, p, 0);
> > +   __setscheduler(rq, p, SCHED_NORMAL, 0);
> > +   activate_task(rq, p, 0);
> > +   resched_task(p);
> 
> I guess, put_prev_task() / set_curr_task() should be called (for the
> case of task_running(p)) to make it group-scheduler-friendly (as it's
> done e.g. in sched_setscheduler()).
> 
> (normilize_task() should probably do the same)

Right, that is where I copied from, I'll pull the functionality into a
single function and make this and the sysrq stuff use it.

Thanks!


signature.asc
Description: This is a digitally signed message part


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Dmitry Adamushko
On 14/10/2007, Peter Zijlstra <[EMAIL PROTECTED]> wrote:
> The below patch is an idea proposed by tglx and depends on sched-devel +
> the hrtick patch previously posted.
>
> The current watchdog action is to demote the task to SCHED_NORMAL,
> however it might be wanted to deliver a signal instead (or have more per
> task configuration state). Which is why I added Lennart to the CC list
> as I gathered he would like something like this for PulseAudio.
>
> ---
> Subject: sched: SCHED_FIFO watchdog timer

Why only SHCED_FIFO and not SCHED_RR?
Their (mis)behavior is similar wrt SCHED_NORMAL tasks.


> +#ifdef CONFIG_SCHED_HRT_TICK
> +static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
> +{
> +   if (likely(!queued || p->policy != SCHED_FIFO))
> +   return 0;
> +
> +   /*
> +* task has been naughty, turn into SCHED_NORMAL
> +*/
> +   printk(KERN_INFO "SCHED_FIFO task %s/%d exceeded his runtime quota,"
> +   " demoting to regular task\n", p->comm, 
> task_pid_nr(p));
> +   deactivate_task(rq, p, 0);
> +   __setscheduler(rq, p, SCHED_NORMAL, 0);
> +   activate_task(rq, p, 0);
> +   resched_task(p);

I guess, put_prev_task() / set_curr_task() should be called (for the
case of task_running(p)) to make it group-scheduler-friendly (as it's
done e.g. in sched_setscheduler()).

(normilize_task() should probably do the same)


-- 
Best regards,
Dmitry Adamushko
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Dmitry Adamushko
On 14/10/2007, Peter Zijlstra [EMAIL PROTECTED] wrote:
 The below patch is an idea proposed by tglx and depends on sched-devel +
 the hrtick patch previously posted.

 The current watchdog action is to demote the task to SCHED_NORMAL,
 however it might be wanted to deliver a signal instead (or have more per
 task configuration state). Which is why I added Lennart to the CC list
 as I gathered he would like something like this for PulseAudio.

 ---
 Subject: sched: SCHED_FIFO watchdog timer

Why only SHCED_FIFO and not SCHED_RR?
Their (mis)behavior is similar wrt SCHED_NORMAL tasks.


 +#ifdef CONFIG_SCHED_HRT_TICK
 +static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
 +{
 +   if (likely(!queued || p-policy != SCHED_FIFO))
 +   return 0;
 +
 +   /*
 +* task has been naughty, turn into SCHED_NORMAL
 +*/
 +   printk(KERN_INFO SCHED_FIFO task %s/%d exceeded his runtime quota,
 +demoting to regular task\n, p-comm, 
 task_pid_nr(p));
 +   deactivate_task(rq, p, 0);
 +   __setscheduler(rq, p, SCHED_NORMAL, 0);
 +   activate_task(rq, p, 0);
 +   resched_task(p);

I guess, put_prev_task() / set_curr_task() should be called (for the
case of task_running(p)) to make it group-scheduler-friendly (as it's
done e.g. in sched_setscheduler()).

(normilize_task() should probably do the same)


-- 
Best regards,
Dmitry Adamushko
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Peter Zijlstra
On Mon, 2007-10-15 at 15:26 +0200, Dmitry Adamushko wrote:
 On 14/10/2007, Peter Zijlstra [EMAIL PROTECTED] wrote:
  The below patch is an idea proposed by tglx and depends on sched-devel +
  the hrtick patch previously posted.
 
  The current watchdog action is to demote the task to SCHED_NORMAL,
  however it might be wanted to deliver a signal instead (or have more per
  task configuration state). Which is why I added Lennart to the CC list
  as I gathered he would like something like this for PulseAudio.
 
  ---
  Subject: sched: SCHED_FIFO watchdog timer
 
 Why only SHCED_FIFO and not SCHED_RR?
 Their (mis)behavior is similar wrt SCHED_NORMAL tasks.

Because SCHED_FIFO is easier, _RR is for later. It was mostly an RFC to
request behavioural wishes from the users.

 
  +#ifdef CONFIG_SCHED_HRT_TICK
  +static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
  +{
  +   if (likely(!queued || p-policy != SCHED_FIFO))
  +   return 0;
  +
  +   /*
  +* task has been naughty, turn into SCHED_NORMAL
  +*/
  +   printk(KERN_INFO SCHED_FIFO task %s/%d exceeded his runtime quota,
  +demoting to regular task\n, p-comm, 
  task_pid_nr(p));
  +   deactivate_task(rq, p, 0);
  +   __setscheduler(rq, p, SCHED_NORMAL, 0);
  +   activate_task(rq, p, 0);
  +   resched_task(p);
 
 I guess, put_prev_task() / set_curr_task() should be called (for the
 case of task_running(p)) to make it group-scheduler-friendly (as it's
 done e.g. in sched_setscheduler()).
 
 (normilize_task() should probably do the same)

Right, that is where I copied from, I'll pull the functionality into a
single function and make this and the sysrq stuff use it.

Thanks!


signature.asc
Description: This is a digitally signed message part


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Lennart Poettering
On Sun, 14.10.07 00:51, Peter Zijlstra ([EMAIL PROTECTED]) wrote:

 The below patch is an idea proposed by tglx and depends on sched-devel +
 the hrtick patch previously posted.
 
 The current watchdog action is to demote the task to SCHED_NORMAL,
 however it might be wanted to deliver a signal instead (or have more per
 task configuration state). Which is why I added Lennart to the CC list
 as I gathered he would like something like this for PulseAudio.

Indeed! Having this in the kernel would allow us to enable RT
scheduling for PulseAudio by default without bad effects. I was thinking about
adding some kind of babysitting process to userspace -- but doing this as
an RLIMIT in the kernel strikes me a much better idea!

I think it would make a lot of sense to make the API very similar to
RLIMIT_CPU, i.e. also send out SIGXCPU and SIGKILL, with the single
difference that RLIMIT_CPU sends out a signal depending on the total
CPU time used for the process and the new RLIMIT based on the time the
process spent without sleeping. That would be a very reasonable
extension to the current RLIMIT_CPU model.

Thank you very much for doing this patch!

Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/   GnuPG 0x1A015CC4
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-15 Thread Kay Sievers
On 10/14/07, Peter Zijlstra [EMAIL PROTECTED] wrote:
 The below patch is an idea proposed by tglx and depends on sched-devel +
 the hrtick patch previously posted.

 The current watchdog action is to demote the task to SCHED_NORMAL,
 however it might be wanted to deliver a signal instead (or have more per
 task configuration state). Which is why I added Lennart to the CC list
 as I gathered he would like something like this for PulseAudio.

Great, this looks very promising. Thanks for doing this.

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


[RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-13 Thread Peter Zijlstra
The below patch is an idea proposed by tglx and depends on sched-devel +
the hrtick patch previously posted.

The current watchdog action is to demote the task to SCHED_NORMAL,
however it might be wanted to deliver a signal instead (or have more per
task configuration state). Which is why I added Lennart to the CC list
as I gathered he would like something like this for PulseAudio.

---
Subject: sched: SCHED_FIFO watchdog timer

Set a per task (rlimit based) limit on SCHED_FIFO runtime. When the
limit is exceeded the task is demoted back to SCHED_NORMAL.

Signed-off-by: Peter Zijlstra <[EMAIL PROTECTED]>
---
 include/asm-generic/resource.h |5 +++--
 kernel/sched.c |5 +
 kernel/sched_rt.c  |   36 
 3 files changed, 44 insertions(+), 2 deletions(-)

Index: linux-2.6/include/asm-generic/resource.h
===
--- linux-2.6.orig/include/asm-generic/resource.h
+++ linux-2.6/include/asm-generic/resource.h
@@ -44,8 +44,8 @@
 #define RLIMIT_NICE13  /* max nice prio allowed to raise to
   0-39 for nice level 19 .. -20 */
 #define RLIMIT_RTPRIO  14  /* maximum realtime priority */
-
-#define RLIM_NLIMITS   15
+#define RLIMIT_FIFOTIME15  /* timeout for fifo slices in 
us */
+#define RLIM_NLIMITS   16
 
 /*
  * SuS says limits have to be unsigned.
@@ -86,6 +86,7 @@
[RLIMIT_MSGQUEUE]   = {   MQ_BYTES_MAX,   MQ_BYTES_MAX },   \
[RLIMIT_NICE]   = { 0, 0 }, \
[RLIMIT_RTPRIO] = { 0, 0 }, \
+   [RLIMIT_FIFOTIME]   = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 }
 
 #endif /* __KERNEL__ */
Index: linux-2.6/kernel/sched_rt.c
===
--- linux-2.6.orig/kernel/sched_rt.c
+++ linux-2.6/kernel/sched_rt.c
@@ -89,6 +89,14 @@ static struct task_struct *pick_next_tas
 
next->se.exec_start = rq->clock;
 
+   if (next->policy == SCHED_FIFO) {
+   unsigned long fifotime;
+
+   fifotime = rq->curr->signal->rlim[RLIMIT_FIFOTIME].rlim_cur;
+   if (fifotime != RLIM_INFINITY)
+   hrtick_start(rq, (u64)fifotime * 1000, 0);
+   }
+
return next;
 }
 
@@ -194,8 +202,36 @@ load_balance_rt(struct rq *this_rq, int 
return load_moved;
 }
 
+#ifdef CONFIG_SCHED_HRT_TICK
+static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
+{
+   if (likely(!queued || p->policy != SCHED_FIFO))
+   return 0;
+
+   /*
+* task has been naughty, turn into SCHED_NORMAL
+*/
+   printk(KERN_INFO "SCHED_FIFO task %s/%d exceeded his runtime quota,"
+   " demoting to regular task\n", p->comm, task_pid_nr(p));
+   deactivate_task(rq, p, 0);
+   __setscheduler(rq, p, SCHED_NORMAL, 0);
+   activate_task(rq, p, 0);
+   resched_task(p);
+
+   return 1;
+}
+#else
+static inline int fifo_watchdog(struct rq *rq, struct task_struct *p, int 
queued)
+{
+   return 0;
+}
+#endif
+
 static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
 {
+   if (fifo_watchdog(rq, p, queued))
+   return;
+
/*
 * RR tasks need a special form of timeslice management.
 * FIFO tasks have no timeslices.
Index: linux-2.6/kernel/sched.c
===
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -132,6 +132,11 @@ static inline void sg_inc_cpu_power(stru
 }
 #endif
 
+static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep);
+static void activate_task(struct rq *rq, struct task_struct *p, int wakeup);
+static void
+__setscheduler(struct rq *rq, struct task_struct *p, int policy, int prio);
+
 static inline int rt_policy(int policy)
 {
if (unlikely(policy == SCHED_FIFO) || unlikely(policy == SCHED_RR))


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


[RFC][PATCH] sched: SCHED_FIFO watchdog timer

2007-10-13 Thread Peter Zijlstra
The below patch is an idea proposed by tglx and depends on sched-devel +
the hrtick patch previously posted.

The current watchdog action is to demote the task to SCHED_NORMAL,
however it might be wanted to deliver a signal instead (or have more per
task configuration state). Which is why I added Lennart to the CC list
as I gathered he would like something like this for PulseAudio.

---
Subject: sched: SCHED_FIFO watchdog timer

Set a per task (rlimit based) limit on SCHED_FIFO runtime. When the
limit is exceeded the task is demoted back to SCHED_NORMAL.

Signed-off-by: Peter Zijlstra [EMAIL PROTECTED]
---
 include/asm-generic/resource.h |5 +++--
 kernel/sched.c |5 +
 kernel/sched_rt.c  |   36 
 3 files changed, 44 insertions(+), 2 deletions(-)

Index: linux-2.6/include/asm-generic/resource.h
===
--- linux-2.6.orig/include/asm-generic/resource.h
+++ linux-2.6/include/asm-generic/resource.h
@@ -44,8 +44,8 @@
 #define RLIMIT_NICE13  /* max nice prio allowed to raise to
   0-39 for nice level 19 .. -20 */
 #define RLIMIT_RTPRIO  14  /* maximum realtime priority */
-
-#define RLIM_NLIMITS   15
+#define RLIMIT_FIFOTIME15  /* timeout for fifo slices in 
us */
+#define RLIM_NLIMITS   16
 
 /*
  * SuS says limits have to be unsigned.
@@ -86,6 +86,7 @@
[RLIMIT_MSGQUEUE]   = {   MQ_BYTES_MAX,   MQ_BYTES_MAX },   \
[RLIMIT_NICE]   = { 0, 0 }, \
[RLIMIT_RTPRIO] = { 0, 0 }, \
+   [RLIMIT_FIFOTIME]   = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 }
 
 #endif /* __KERNEL__ */
Index: linux-2.6/kernel/sched_rt.c
===
--- linux-2.6.orig/kernel/sched_rt.c
+++ linux-2.6/kernel/sched_rt.c
@@ -89,6 +89,14 @@ static struct task_struct *pick_next_tas
 
next-se.exec_start = rq-clock;
 
+   if (next-policy == SCHED_FIFO) {
+   unsigned long fifotime;
+
+   fifotime = rq-curr-signal-rlim[RLIMIT_FIFOTIME].rlim_cur;
+   if (fifotime != RLIM_INFINITY)
+   hrtick_start(rq, (u64)fifotime * 1000, 0);
+   }
+
return next;
 }
 
@@ -194,8 +202,36 @@ load_balance_rt(struct rq *this_rq, int 
return load_moved;
 }
 
+#ifdef CONFIG_SCHED_HRT_TICK
+static int fifo_watchdog(struct rq *rq, struct task_struct *p, int queued)
+{
+   if (likely(!queued || p-policy != SCHED_FIFO))
+   return 0;
+
+   /*
+* task has been naughty, turn into SCHED_NORMAL
+*/
+   printk(KERN_INFO SCHED_FIFO task %s/%d exceeded his runtime quota,
+demoting to regular task\n, p-comm, task_pid_nr(p));
+   deactivate_task(rq, p, 0);
+   __setscheduler(rq, p, SCHED_NORMAL, 0);
+   activate_task(rq, p, 0);
+   resched_task(p);
+
+   return 1;
+}
+#else
+static inline int fifo_watchdog(struct rq *rq, struct task_struct *p, int 
queued)
+{
+   return 0;
+}
+#endif
+
 static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
 {
+   if (fifo_watchdog(rq, p, queued))
+   return;
+
/*
 * RR tasks need a special form of timeslice management.
 * FIFO tasks have no timeslices.
Index: linux-2.6/kernel/sched.c
===
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -132,6 +132,11 @@ static inline void sg_inc_cpu_power(stru
 }
 #endif
 
+static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep);
+static void activate_task(struct rq *rq, struct task_struct *p, int wakeup);
+static void
+__setscheduler(struct rq *rq, struct task_struct *p, int policy, int prio);
+
 static inline int rt_policy(int policy)
 {
if (unlikely(policy == SCHED_FIFO) || unlikely(policy == SCHED_RR))


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