linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RT] rt priority losing
@ 2006-07-24 15:41 Steven Rostedt
  2006-07-24 17:00 ` Esben Nielsen
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2006-07-24 15:41 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Thomas Gleixner, LKML, Duetsch, Thomas LDE1

Ingo or Tglx,

It has come to my attention that the dynamic hrtimer softirq can lose a
boosted priority.  That is, if a softirq is running while a timeout
happens, and the call back is of lower priority than the currently
running hrtimer softirq, the timer interrupt will still lower the
hrtimer softirq.

Here's the problem code:

static void wakeup_softirqd_prio(int softirq, int prio)
{
	/* Interrupts are disabled: no need to stop preemption */
	struct task_struct *tsk = __get_cpu_var(ksoftirqd[softirq].tsk);

	if (tsk) {
		if (tsk->normal_prio != prio) {
			struct sched_param param;

			param.sched_priority = MAX_RT_PRIO-1 - prio;
			setscheduler(tsk, -1, SCHED_FIFO, &param);
		}
		if(tsk->state != TASK_RUNNING)
			wake_up_process(tsk);
	}
}


So, tsk could be softirqd-hrmono and we lower the priority. (only
normal_prio is checked versus prio).

So this can be a problem, if the softirq function holds a lock of a high
priority task, and is running boosted.  If another timer goes off with a
lower priority, we can lower the priority of the softirqd and lose the
inherited priority that it was running at.

-- Steve


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

* Re: [RT] rt priority losing
  2006-07-24 17:00 ` Esben Nielsen
@ 2006-07-24 16:37   ` Steven Rostedt
  2006-07-24 16:44     ` Thomas Gleixner
  2006-07-24 17:54     ` Esben Nielsen
  0 siblings, 2 replies; 7+ messages in thread
From: Steven Rostedt @ 2006-07-24 16:37 UTC (permalink / raw)
  To: Esben Nielsen; +Cc: Ingo Molnar, Thomas Gleixner, LKML, Duetsch, Thomas LDE1

On Mon, 2006-07-24 at 18:00 +0100, Esben Nielsen wrote:
> On Mon, 24 Jul 2006, Steven Rostedt wrote:
> 
> > Ingo or Tglx,
> >
> > It has come to my attention that the dynamic hrtimer softirq can lose a
> > boosted priority.  That is, if a softirq is running while a timeout
> > happens, and the call back is of lower priority than the currently
> > running hrtimer softirq, the timer interrupt will still lower the
> > hrtimer softirq.
> >
> > Here's the problem code:
> >
> > static void wakeup_softirqd_prio(int softirq, int prio)
> > {
> > 	/* Interrupts are disabled: no need to stop preemption */
> > 	struct task_struct *tsk = __get_cpu_var(ksoftirqd[softirq].tsk);
> >
> > 	if (tsk) {
> > 		if (tsk->normal_prio != prio) {
> > 			struct sched_param param;
> >
> > 			param.sched_priority = MAX_RT_PRIO-1 - prio;
> > 			setscheduler(tsk, -1, SCHED_FIFO, &param);
> > 		}
> > 		if(tsk->state != TASK_RUNNING)
> > 			wake_up_process(tsk);
> > 	}
> > }
> >
> >
> > So, tsk could be softirqd-hrmono and we lower the priority. (only
> > normal_prio is checked versus prio).
> >
> > So this can be a problem, if the softirq function holds a lock of a high
> > priority task, and is running boosted.  If another timer goes off with a
> > lower priority, we can lower the priority of the softirqd and lose the
> > inherited priority that it was running at.
> 
> There is a check for that inside setscheduler():
>  	p->prio = rt_mutex_getprio(p);

OK, you are right about this.  The PI chain should not be affected.  But
this could still be a problem if the softirq was running at a high prio
for a task when a lower prio callback needs to be made.  It looks like
timer is removed from the base before the function runs.  So when the
interrupt looks at the base to determine the priority to set it at, it
might actually lower the priority of a running hrtimer thread.

-- Steve



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

* Re: [RT] rt priority losing
  2006-07-24 16:37   ` Steven Rostedt
@ 2006-07-24 16:44     ` Thomas Gleixner
  2006-07-24 17:54     ` Esben Nielsen
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2006-07-24 16:44 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Esben Nielsen, Ingo Molnar, Thomas Gleixner, LKML, Duetsch, Thomas LDE1

At Mon, 24 Jul 2006 12:37:22 -0400,
Steven Rostedt wrote:
> > > So this can be a problem, if the softirq function holds a lock of a high
> > > priority task, and is running boosted.  If another timer goes off with a
> > > lower priority, we can lower the priority of the softirqd and lose the
> > > inherited priority that it was running at.
> > 
> > There is a check for that inside setscheduler():
> >  	p->prio = rt_mutex_getprio(p);
> 
> OK, you are right about this.  The PI chain should not be affected.  But
> this could still be a problem if the softirq was running at a high prio
> for a task when a lower prio callback needs to be made.  It looks like
> timer is removed from the base before the function runs.  So when the
> interrupt looks at the base to determine the priority to set it at, it
> might actually lower the priority of a running hrtimer thread.

The correct solution is to run the callback in the context of
the thread which will receive it and get rid of the softirq.

I experimented with this already, but its more than a saturday
afternoon project.

	tglx

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

* Re: [RT] rt priority losing
  2006-07-24 15:41 [RT] rt priority losing Steven Rostedt
@ 2006-07-24 17:00 ` Esben Nielsen
  2006-07-24 16:37   ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Esben Nielsen @ 2006-07-24 17:00 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Ingo Molnar, Thomas Gleixner, LKML, Duetsch, Thomas LDE1

On Mon, 24 Jul 2006, Steven Rostedt wrote:

> Ingo or Tglx,
>
> It has come to my attention that the dynamic hrtimer softirq can lose a
> boosted priority.  That is, if a softirq is running while a timeout
> happens, and the call back is of lower priority than the currently
> running hrtimer softirq, the timer interrupt will still lower the
> hrtimer softirq.
>
> Here's the problem code:
>
> static void wakeup_softirqd_prio(int softirq, int prio)
> {
> 	/* Interrupts are disabled: no need to stop preemption */
> 	struct task_struct *tsk = __get_cpu_var(ksoftirqd[softirq].tsk);
>
> 	if (tsk) {
> 		if (tsk->normal_prio != prio) {
> 			struct sched_param param;
>
> 			param.sched_priority = MAX_RT_PRIO-1 - prio;
> 			setscheduler(tsk, -1, SCHED_FIFO, &param);
> 		}
> 		if(tsk->state != TASK_RUNNING)
> 			wake_up_process(tsk);
> 	}
> }
>
>
> So, tsk could be softirqd-hrmono and we lower the priority. (only
> normal_prio is checked versus prio).
>
> So this can be a problem, if the softirq function holds a lock of a high
> priority task, and is running boosted.  If another timer goes off with a
> lower priority, we can lower the priority of the softirqd and lose the
> inherited priority that it was running at.

There is a check for that inside setscheduler():
 	p->prio = rt_mutex_getprio(p);

Esben

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

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

* [PATCH -rt] Don't let raise_softirq_prio lower the prio (was: [RT] rt priority losing)
  2006-07-24 17:54     ` Esben Nielsen
@ 2006-07-24 17:15       ` Steven Rostedt
  2006-07-26  8:10         ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2006-07-24 17:15 UTC (permalink / raw)
  To: Esben Nielsen; +Cc: Ingo Molnar, Thomas Gleixner, LKML, Duetsch, Thomas LDE1

On Mon, 2006-07-24 at 18:54 +0100, Esben Nielsen wrote:

> >
> > OK, you are right about this.  The PI chain should not be affected.  But
> > this could still be a problem if the softirq was running at a high prio
> > for a task when a lower prio callback needs to be made.  It looks like
> > timer is removed from the base before the function runs.  So when the
> > interrupt looks at the base to determine the priority to set it at, it
> > might actually lower the priority of a running hrtimer thread.
> >
> 
> That is a simple bug which ought to be simple fixable.

I guess the simple fix is not to allow the interrupt to lower the
priority. But simple fixes do not always handle all the cases.

Thomas G., see any side effects with this patch?

-- Steve

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Index: linux-2.6.17-rt7/kernel/softirq.c
===================================================================
--- linux-2.6.17-rt7.orig/kernel/softirq.c	2006-07-24 13:08:53.000000000 -0400
+++ linux-2.6.17-rt7/kernel/softirq.c	2006-07-24 13:10:13.000000000 -0400
@@ -108,7 +108,12 @@ static void wakeup_softirqd_prio(int sof
 	struct task_struct *tsk = __get_cpu_var(ksoftirqd[softirq].tsk);
 
 	if (tsk) {
-		if (tsk->normal_prio != prio) {
+		/*
+		 * The lower the prio, the higher the priority.
+		 * This can only raise the priority but it can
+		 * not lower it.
+		 */
+		if (tsk->normal_prio > prio) {
 			struct sched_param param;
 
 			param.sched_priority = MAX_RT_PRIO-1 - prio;



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

* Re: [RT] rt priority losing
  2006-07-24 16:37   ` Steven Rostedt
  2006-07-24 16:44     ` Thomas Gleixner
@ 2006-07-24 17:54     ` Esben Nielsen
  2006-07-24 17:15       ` [PATCH -rt] Don't let raise_softirq_prio lower the prio (was: [RT] rt priority losing) Steven Rostedt
  1 sibling, 1 reply; 7+ messages in thread
From: Esben Nielsen @ 2006-07-24 17:54 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Esben Nielsen, Ingo Molnar, Thomas Gleixner, LKML, Duetsch, Thomas LDE1

On Mon, 24 Jul 2006, Steven Rostedt wrote:

> On Mon, 2006-07-24 at 18:00 +0100, Esben Nielsen wrote:
>> On Mon, 24 Jul 2006, Steven Rostedt wrote:
>>
>>> Ingo or Tglx,
>>>
>>> It has come to my attention that the dynamic hrtimer softirq can lose a
>>> boosted priority.  That is, if a softirq is running while a timeout
>>> happens, and the call back is of lower priority than the currently
>>> running hrtimer softirq, the timer interrupt will still lower the
>>> hrtimer softirq.
>>>
>>> Here's the problem code:
>>>
>>> static void wakeup_softirqd_prio(int softirq, int prio)
>>> {
>>> 	/* Interrupts are disabled: no need to stop preemption */
>>> 	struct task_struct *tsk = __get_cpu_var(ksoftirqd[softirq].tsk);
>>>
>>> 	if (tsk) {
>>> 		if (tsk->normal_prio != prio) {
>>> 			struct sched_param param;
>>>
>>> 			param.sched_priority = MAX_RT_PRIO-1 - prio;
>>> 			setscheduler(tsk, -1, SCHED_FIFO, &param);
>>> 		}
>>> 		if(tsk->state != TASK_RUNNING)
>>> 			wake_up_process(tsk);
>>> 	}
>>> }
>>>
>>>
>>> So, tsk could be softirqd-hrmono and we lower the priority. (only
>>> normal_prio is checked versus prio).
>>>
>>> So this can be a problem, if the softirq function holds a lock of a high
>>> priority task, and is running boosted.  If another timer goes off with a
>>> lower priority, we can lower the priority of the softirqd and lose the
>>> inherited priority that it was running at.
>>
>> There is a check for that inside setscheduler():
>>  	p->prio = rt_mutex_getprio(p);
>
> OK, you are right about this.  The PI chain should not be affected.  But
> this could still be a problem if the softirq was running at a high prio
> for a task when a lower prio callback needs to be made.  It looks like
> timer is removed from the base before the function runs.  So when the
> interrupt looks at the base to determine the priority to set it at, it
> might actually lower the priority of a running hrtimer thread.
>

That is a simple bug which ought to be simple fixable.

Esben
> -- Steve
>
>

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

* Re: [PATCH -rt] Don't let raise_softirq_prio lower the prio (was: [RT] rt priority losing)
  2006-07-24 17:15       ` [PATCH -rt] Don't let raise_softirq_prio lower the prio (was: [RT] rt priority losing) Steven Rostedt
@ 2006-07-26  8:10         ` Ingo Molnar
  0 siblings, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2006-07-26  8:10 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Esben Nielsen, Thomas Gleixner, LKML, Duetsch, Thomas LDE1


* Steven Rostedt <rostedt@goodmis.org> wrote:

> I guess the simple fix is not to allow the interrupt to lower the 
> priority. But simple fixes do not always handle all the cases.
> 
> Thomas G., see any side effects with this patch?
> 
> -- Steve
> 
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

thanks, applied. Thomas, fine with you too?

	Ingo

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

end of thread, other threads:[~2006-07-26  8:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-24 15:41 [RT] rt priority losing Steven Rostedt
2006-07-24 17:00 ` Esben Nielsen
2006-07-24 16:37   ` Steven Rostedt
2006-07-24 16:44     ` Thomas Gleixner
2006-07-24 17:54     ` Esben Nielsen
2006-07-24 17:15       ` [PATCH -rt] Don't let raise_softirq_prio lower the prio (was: [RT] rt priority losing) Steven Rostedt
2006-07-26  8:10         ` Ingo Molnar

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).