Skip to contentSkip to conversation

How to control IRQ thread priority from inside the driver

DISCUSSION Juergen Beisert 5 participants 13 messages Aug 8, 2007 – Aug 10, 2007 IRQ

lore
Share & tools
lore
#0 lore raw

Hi,

with the rt-preempt patch the IRQs are all kernelthreads started with priority
50. Is there a way to change this priority from inside the driver, after I did the request_irq() call? I need a higher priority for one interrupt source but I do not want to change it with chrt from userspace. It should be done inside the driver.

Juergen

#1 lore raw
Quoted 7 lines · On Wednesday 08 August 2007 06:14:31 you wrote:

Hi,

with the rt-preempt patch the IRQs are all kernelthreads started with priority 50. Is there a way to change this priority from inside the driver, after I did the request_irq() call? I need a higher priority for one interrupt source but I do not want to change it with chrt from userspace. It should be done inside the driver.

I disagree. The point of real-time is to provide user-space with more control of what get's run, when, instead of something else - including system interrupts, etc. For instance, if networking should take a higher priority than their application, but disk i/o should take a lower one, the user needs to be able to control that. chrt is the correct approach for -rt in my opinion.

Signature · 3 lines
Darren Hart
IBM Linux Technology Center
Realtime Linux Team
#2 lore raw

Hello Darren,

Quoted 6 lines

I disagree. The point of real-time is to provide user-space with more control of what get's run, when, instead of something else - including system interrupts, etc. For instance, if networking should take a higher priority than their application, but disk i/o should take a lower one, the user needs to be able to control that. chrt is the correct approach for -rt in my opinion.

I believe this depends on the environment where the RT-kernel is used. Therefor this might be true for Realtime Desktop/Server applications, but, for RT-Embedded systems it is possible (likely) that the entire kernel is pre-configured for 1 single purpose, and that some developer wants to set the priorities for that purpose only. In that case there is usually no user that cares anything about what is running on the system, as long as his device works, so that user will never come to the idea to use 'chrt'.

In these case the default priorities at 50 are useless and the developer has to have a way to configure the priorities. So I understand the question of Juergen.
To suit my needs, I did this by just patching the kernel thread priorities at the places where they are started. (And I am still happy with my solution. Note that because it is very application specific, I never expect a patch like this to get to the mainline)

Kind Regards,

Remy

#3 lore raw
In reply to Darren Hart

Darren,

Quoted 9 lines · Darren Hart
Quoted 7 lines · On Wednesday 08 August 2007 06:14:31 you wrote:

Hi,

with the rt-preempt patch the IRQs are all kernelthreads started with priority 50. Is there a way to change this priority from inside the driver, after I did the request_irq() call? I need a higher priority for one interrupt source but I do not want to change it with chrt from userspace. It should be done inside the driver.

Quoted 6 lines

I disagree. The point of real-time is to provide user-space with more control of what get's run, when, instead of something else - including system interrupts, etc. For instance, if networking should take a higher priority than their application, but disk i/o should take a lower one, the user needs to be able to control that. chrt is the correct approach for -rt in my opinion.

All I need is one IRQ at priority 51, all other can still run at 50. And I don't want to search at system's runtime for the right PID of driver's thread to set its priority via "chrt". There is no user at this system, its an embedded one.

Juergen

#4 lore raw
Quoted 19 lines · On Thursday 09 August 2007 07:10:57 Juergen Beisert wrote:

Darren,

Quoted 9 lines · Darren Hart
Quoted 7 lines · On Wednesday 08 August 2007 06:14:31 you wrote:

Hi,

with the rt-preempt patch the IRQs are all kernelthreads started with priority 50. Is there a way to change this priority from inside the driver, after I did the request_irq() call? I need a higher priority for one interrupt source but I do not want to change it with chrt from userspace. It should be done inside the driver.

Quoted 6 lines

I disagree. The point of real-time is to provide user-space with more control of what get's run, when, instead of something else - including system interrupts, etc. For instance, if networking should take a higher priority than their application, but disk i/o should take a lower one, the user needs to be able to control that. chrt is the correct approach for -rt in my opinion.

Quoted 4 lines

All I need is one IRQ at priority 51, all other can still run at 50. And I don't want to search at system's runtime for the right PID of driver's thread to set its priority via "chrt". There is no user at this system, its an embedded one.

It seems reasonable then, for such a specialized case, to consider Remy's reply to my previous mail:

"To suit my needs, I did this by just patching the kernel thread priorities at the places where they are started. (And I am still happy with my solution. Note that because it is very application specific, I never expect a patch like this to get to the mainline)"

Signature · 3 lines
Darren Hart
IBM Linux Technology Center
Realtime Linux Team
#5 lore raw

Hello Darren, Juergen and Ingo,

Quoted 10 lines
Quoted 4 lines

All I need is one IRQ at priority 51, all other can still run at 50. And I don't want to search at system's runtime for the right PID of driver's thread to set its priority via "chrt". There is no user at this system, its an embedded one.

It seems reasonable then, for such a specialized case, to consider Remy's reply to my previous mail:

"To suit my needs, I did this by just patching the kernel thread priorities at the places where they are started.

Attached I have put my patch to change the priorities of the soft-irq's and the IRQ threads.
Maybe Juergen can use it so suit his needs. (Sorry for attaching instead of inlining, but I have not find a way to inline a patch without corrupting it while using Gmail from within Firefox)

But, I think that the mechanism to change the soft-irq priorities can be integrated in the mainline RT-patch, I have modified the softirq_info struct with the soft-irq thread names such that it also contains the thread priority per soft-irq. For customisation it is easier to adapt this struct, than to apply the entire patch over and over. Until now the code seems to change that frequently that I have to reimplement this patch over and over...

Maybe Ingo can look at it, and find a way to implement it more generic? (In the softirq_info struct we could default set all prios back to 50, and than from functional point of view there will be no change for other RT-patch users, but makes Embedded-users life easier.

While looking at the IRQ-threads: Notice that setting all IRQ-threads priorities to 50 with SCHED_FIFO is a bit strange to begin with, because on a non-RT kernel all IRQ's have different priorities and a higher prio irq can preempt a lower prio one. (on X86) The current implementation will not preempt another irq-thread due to the same prios and fifo scheduling.
The implementation I have in this patch follows the original behaviour more closely, but changing that also could lead to some discussion...

Kind Regards,

Remy

This patch changes the soft-irq priority for all kernel daemon threads like Interrupt threads and soft-irqs to match them with our applications.

---
 kernel/irq/manage.c |   12 +++++++++--
 kernel/softirq.c    |   53 +++++++++++++++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 21 deletions(-)
kernel/irq/manage.c +10 -2
Index: linux-2.6.22/kernel/irq/manage.c
===================================================================
@@ -757,10 +757,13 @@ static void do_hardirq(struct irq_desc *
 		wake_up(&desc->wait_for_handler);
 }
 
+#define base_irq_prio  45
+
 static int do_irqd(void * __desc)
 {
 	struct sched_param param = { 0, };
 	struct irq_desc *desc = __desc;
+	int irq = desc - irq_desc;
 
 #ifdef CONFIG_SMP
 	cpumask_t cpus_allowed, mask;
@@ -776,12 +779,17 @@ static int do_irqd(void * __desc)
 	current->flags |= PF_NOFREEZE | PF_HARDIRQ;
 
 	/*
-	 * Set irq thread priority to SCHED_FIFO/50:
+	 * Use a custom irq thread priority mechanism:
 	 */
-	param.sched_priority = MAX_USER_RT_PRIO/2;
+	param.sched_priority = base_irq_prio - irq;
+	if (param.sched_priority < 1)
+		param.sched_priority = 1;
 
 	sys_sched_setscheduler(current->pid, SCHED_FIFO, &param);
 
+	printk(KERN_INFO "[IRQ-%d] started with prio:%i\n",
+		irq, param.sched_priority);
+
 	while (!kthread_should_stop()) {
 		local_irq_disable_nort();
 		do {
kernel/softirq.c +34 -19

80 lines not on this page · raw message

#6 lore raw

--
When I'm asked what language is my mother tongue,
I simply answer "C".

Quoted 6 lines · Remy Bohmer

Hello Darren, Juergen and Ingo,

Maybe Ingo can look at it, and find a way to implement it more generic? (In the softirq_info struct we could default set all prios back to 50, and than from functional point of view there will be no change for other RT-patch users, but makes Embedded-users life easier.

Hi Remy,

I'm taking your concern seriously, and we are seeing other areas that it would be nice to set up a different irq priority than the default at boot. Perhaps adding in a new command line interface (We may need to extend the command line size limit). Where one could do irq_priority_map=10-51,21-40,... Where the first number is the irq number followed by the irq priority. We can also do something similar to softirqs.

Would something like that satisfy your needs?

Quoted 5 lines

While looking at the IRQ-threads: Notice that setting all IRQ-threads priorities to 50 with SCHED_FIFO is a bit strange to begin with, because on a non-RT kernel all IRQ's have different priorities and a higher prio irq can preempt a lower prio one. (on X86) The current

Only if the lower one enabled interrupts ;-)

Also that's hardware defined, not user defined. Note that the sofitrqs are not prioritized either. Well, they are by their position in the pending bitmask. But one softirq will not preempt another.

Quoted 5 lines

implementation will not preempt another irq-thread due to the same prios and fifo scheduling.
The implementation I have in this patch follows the original behaviour more closely, but changing that also could lead to some discussion...

We originally had a special "priority" for each new irq, but found that it really didn't make sense, and we had pressure to make them all the same, and let the user change them. What we need is a way to pass information to the kernel to set a userdefined default.

When I get time, I can write up a patch to do something like this.

-- Steve

#7 lore raw

Hello Steven,

Quoted 7 lines

Perhaps adding in a new command line interface (We may need to extend the command line size limit). Where one could do irq_priority_map=10-51,21-40,... Where the first number is the irq number followed by the irq priority. We can also do something similar to softirqs.

Would something like that satisfy your needs?

Yeah, it would at least suit my needs :-)
But, the irq-numbers to be defined is hardware specific, and even board specific on X86. Maybe someone wants to give a certain interrupt handler a different priority, but not a certain IRQ-number to keep it possible to use 1 target image usable on multiple boards with 1 single kernel and 1 single config.
How to define that on a kernel commandline is still a question to me...

Quoted 1 line

When I get time, I can write up a patch to do something like this.

I could write a proposal on a solution for this, and if we all agree for one solution, I could make the patch for this. (Maybe I have more time free than you ;-) )

Remy

#8 lore raw

--

Quoted 8 lines · Remy Bohmer

Hello Steven,

Quoted 6 lines

Perhaps adding in a new command line interface (We may need to extend the command line size limit). Where one could do irq_priority_map=10-51,21-40,... Where the first number is the irq number followed by the irq priority. We can also do something similar to softirqs.

Quoted 4 lines
Quoted 1 line

Would something like that satisfy your needs?

Yeah, it would at least suit my needs :-)
But, the irq-numbers to be defined is hardware specific, and even

Yeah, but they should be the same on boot up. A command line is something one would add in the boot loader (grub for example). It's not hard coded.

Quoted 2 lines

board specific on X86. Maybe someone wants to give a certain interrupt handler a different priority, but not a certain IRQ-number to keep it

Actually, the handler thread runs _all_ register interrupt handlers. So there's no way to make one a higher priority than the other. This is a tough problem. If you have two shared handlers on the same irq line, and think you can make one a higher priority than the other, you can't. If the lower one is running (at the lower priority), and it gets preempted by an RT task with a priority that is between the lower priority handler and the higher priority handler, the higher priority handler may never run. The interrupt line for the IRQ is masked while the handlers are running. So by preempting the lower priority handler you are also preempting the higher priority IRQ from coming in.

Quoted 2 lines

possible to use 1 target image usable on multiple boards with 1 single kernel and 1 single config.

You can still have one kernel and one config. A command line is separate.

Quoted 1 line

How to define that on a kernel commandline is still a question to me...

Don't worry about labeling handlers. We will only need to know the IRQ #.

If we can redesign the IRQ handlers of all drivers, where they can pass in a function to disable the device so we don't need to mask the IRQ line if another device exists with a higher IRQ, then we may have a solution there. But don't expect that to happen anytime soon.

Quoted 2 lines
Quoted 2 lines

When I get time, I can write up a patch to do something like this.

Sure go ahead :-)

Quoted 4 lines

I could write a proposal on a solution for this, and if we all agree for one solution, I could make the patch for this. (Maybe I have more time free than you ;-) )

You probably do ;-) I'm struggling with four projects at the moment, five if you count my writing of the chapter in the O'Reilly book "Building Embedded Linux Systems" about RT. But these are some of the things that I'm talking about in that.

Thanks,

-- Steve

#12 lore raw
In reply to Remy Bohmer

Em Fri, Aug 10, 2007 at 06:00:28PM +0200, Remy Bohmer escreveu:

Quoted 10 lines

Hello Steven,

Quoted 7 lines

Perhaps adding in a new command line interface (We may need to extend the command line size limit). Where one could do irq_priority_map=10-51,21-40,... Where the first number is the irq number followed by the irq priority. We can also do something similar to softirqs.

Would something like that satisfy your needs?

Quoted 7 lines

Yeah, it would at least suit my needs :-)
But, the irq-numbers to be defined is hardware specific, and even board specific on X86. Maybe someone wants to give a certain interrupt handler a different priority, but not a certain IRQ-number to keep it possible to use 1 target image usable on multiple boards with 1 single kernel and 1 single config.
How to define that on a kernel commandline is still a question to me...

Well, we could use the IRQ name, as given in:

        if (request_irq(pdev->irq, megasas_isr, IRQF_SHARED, "megasas", instance)) {

So it would be something like:

irq_pmap=megasas:90,eth0:40,50

With the last one being the default, if different than the kernel default, not having the ':' would mean default.

- Arnaldo

#9 lore raw
In reply to Steven Rostedt

Hello Steven,

Quoted 11 lines

Actually, the handler thread runs _all_ register interrupt handlers. So there's no way to make one a higher priority than the other. This is a tough problem. If you have two shared handlers on the same irq line, and think you can make one a higher priority than the other, you can't. If the lower one is running (at the lower priority), and it gets preempted by an RT task with a priority that is between the lower priority handler and the higher priority handler, the higher priority handler may never run. The interrupt line for the IRQ is masked while the handlers are running. So by preempting the lower priority handler you are also preempting the higher priority IRQ from coming in.

Hmm, I think you did not get my point... What you mention is basic knowledge... ;-))

What I meant was that from Embedded point of view, some developer probably don't care about what the irq-line-number is of some device. But, such a developer probably wants to prioritize the interrupt handler of his device. Dependant on how the hardware layout looks like it can be interrupt # X, Y or Z. If the kernel can match the device name to a certain IRQ #, the implementation is probably much more flexible than by just specifying the IRQ # at the kernel commandline. In the case where the IRQ handler is shared with some other device, than there are 2 options: the developer does not care, or should choose different hardware.

Arnaldo mentioned to use the irq-name for this, and to me this sounds good.

Quoted 4 lines
Quoted 2 lines

possible to use 1 target image usable on multiple boards with 1 single kernel and 1 single config.

You can still have one kernel and one config. A command line is separate.

My mistake: I meant with config the grub, u-boot or ... config, not the kernel config

Quoted 3 lines

five if you count my writing of the chapter in the O'Reilly book "Building Embedded Linux Systems" about RT. But these are some of the

Interesting... When will this book be finished? I am always curious about the point of view of others on RT... (I am working with Ingo's RT-patch for several years now, started with the early preemption patches on 2.4 kernels)

Kind Regards,

Remy

#10 lore raw

--

Quoted 2 lines · Remy Bohmer

Arnaldo mentioned to use the irq-name for this, and to me this sounds good.

Yeah, that wouldn't be too hard to implement.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

possible to use 1 target image usable on multiple boards with 1 single kernel and 1 single config.

You can still have one kernel and one config. A command line is separate.

My mistake: I meant with config the grub, u-boot or ... config, not the kernel config

OK, understood.

Quoted 6 lines
Quoted 4 lines

five if you count my writing of the chapter in the O'Reilly book "Building Embedded Linux Systems" about RT. But these are some of the

Interesting... When will this book be finished? I am always curious

hehe, it was due last year! I'm only doing the RT chapter about Ingo's patch. I wont give a time frame, since I'm working my butt on getting it out. But it is due soon.

Quoted 3 lines

about the point of view of others on RT... (I am working with Ingo's RT-patch for several years now, started with the early preemption patches on 2.4 kernels)

I've been developing Ingo's patches for a few years now too. I'm one of the authors of the rt-mutex.c code. Actually, I started out on RT Linux programing as a kernel developer at TimeSys working on their Linux 2.2 port. Now I'm at Red Hat with Ingo, but I'm on other projects that keep me from doing RT full time :-(

-- Steve

#11 lore raw

Hello Steven,

Quoted 2 lines
Quoted 1 line

Arnaldo mentioned to use the irq-name for this, and to me this sounds good.

Yeah, that wouldn't be too hard to implement.

I am going to take a look at it... I can propose a patch in a few days to a week...

I hope Juergen also thinks this is a good idea?

Quoted 3 lines

I've been developing Ingo's patches for a few years now too. I'm one of the authors of the rt-mutex.c code. Actually, I started out on RT Linux programing as a kernel developer at TimeSys working on their Linux 2.2

I already thought I saw your name listed somewhere ;-))))

Quoted 1 line

port. Now I'm at Red Hat with Ingo, but I'm on other projects that keep

This is **really** a small world ;-)

Remy