Skip to contentSkip to conversation

nested enable/disable irq calls

PATCH In review Dmitry Adamushko 3 participants 5 messages Apr 7, 2006 – Apr 12, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nested enable/disable irq calls

Hi,

yep, this is yet another draft patch which aims at supporting the nested irq disable/enable calls for the primary domain.

o no changes on the adeos-ipipe layer, hence it's much cleaner and smaller that the one I have posted last time;

o eliminates the need for XN_ISR_NOENABLE flag;

o but is based on the presupposition (otherwise it's wrong) that for all acrhitectures that support Xenomai the following is true :

pic_handler->ack :
* mask
* eoi

pic_handler->end :
* unmask

Philippe told me some time ago that this is a _must_ now for any arch to be compatible with adeos-ipipe.

If so, with some minor cleanups (XN_ISR_NOENABLE should be removed all over the map,
docs fixes, ...) and testing the patch may hopefully find its way into the codebase.

Any feedback?

TIA,

--
Best regards,
Dmitry Adamushko

include/nucleus/intr.h +2 -0
diff -urp xenomai/include/nucleus/intr.h xenomai-depth/include/nucleus/intr.h
@@ -43,6 +43,8 @@ typedef struct xnintr {
 
 #if defined(CONFIG_XENO_OPT_SHIRQ_LEVEL) || defined(CONFIG_XENO_OPT_SHIRQ_EDGE)
     struct xnintr *next; /* !< Next object in the IRQ-sharing chain. */
+#else /* !CONFIG_XENO_OPT_SHIRQ_LEVEL && !CONFIG_XENO_OPT_SHIRQ_EDGE */
+    int depth;
 #endif /* CONFIG_XENO_OPT_SHIRQ_LEVEL || CONFIG_XENO_OPT_SHIRQ_EDGE */
 
     xnisr_t isr;	/* !< Interrupt service routine. */
ksrc/nucleus/intr.c +71 -11

170 lines not on this page · raw message

#1 lore raw
Quoted 17 lines · Dmitry Adamushko

Hi,

yep, this is yet another draft patch which aims at supporting the nested irq disable/enable calls for the primary domain.

o no changes on the adeos-ipipe layer, hence it's much cleaner and smaller that the one I have posted last time;

o eliminates the need for XN_ISR_NOENABLE flag;

o but is based on the presupposition (otherwise it's wrong) that for all acrhitectures that support Xenomai the following is true :

pic_handler->ack :
* mask
* eoi

Quoted 6 lines

pic_handler->end :
* unmask

Philippe told me some time ago that this is a _must_ now for any arch to be compatible with adeos-ipipe.

Ack, but with the special exception of the timer IRQ on x86 which is not masked but only acked, since we can skip this while keeping the PIT happy, and acknowledging the PIC through the ISA bus is so sloooow...

Quoted 20 lines

If so, with some minor cleanups (XN_ISR_NOENABLE should be removed all over the map,
docs fixes, ...) and testing the patch may hopefully find its way into the codebase.

Any feedback?

TIA,

--
Best regards,
Dmitry Adamushko

------------------------------------------------------------------------

_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.
#2 lore raw
In reply to Dmitry Adamushko

Hi Dmitry,

Quoted 23 lines · Dmitry Adamushko

Hi,

yep, this is yet another draft patch which aims at supporting the nested irq disable/enable calls for the primary domain.

o no changes on the adeos-ipipe layer, hence it's much cleaner and smaller that the one I have posted last time;

o eliminates the need for XN_ISR_NOENABLE flag;

o but is based on the presupposition (otherwise it's wrong) that for all acrhitectures that support Xenomai the following is true :

pic_handler->ack :
* mask
* eoi

pic_handler->end :
* unmask

Philippe told me some time ago that this is a _must_ now for any arch to be compatible with adeos-ipipe.

Quoted 7 lines

If so, with some minor cleanups (XN_ISR_NOENABLE should be removed all over the map,
docs fixes, ...) and testing the patch may hopefully find its way into the codebase.

Any feedback?

Yes, I do have some remarks: due to legacy issues (I think to remember), we have a lot of unbalanced irq-enable/disable code out there. IRQs are currently enabled after registering a handler, but are not disabled on detach. That's because of problems with Linux when letting it take over a disabled IRQ, and for the sake of shared-irqs. Thus, if we introduce such a nestable enable/disable, we _must_ think about managing the side effects in legacy code (I haven't thought about this in details yet).

Another thing I have on my mind ATM is providing an additional IRQ
model: threaded IRQs. This is certainly not the best default model, but it could help in certain scenarios to reduce prio-inversions due to overloaded IRQ handler jobs (like we face from time to time with devices on the slow ISA-bus...).

I think this should be rather simple to implement with the existing infrastructure. I'm just wondering if it should become a RTDM or a nucleus feature. Any opinions? [I'm currently in favour of RTDM.]

A nice add-on to this model would be to capture timestamps in the hard stub and to distribute it to the threaded handlers. That's quite egoistic, as it would perfectly fit our needs again: low timestamp jitter but schedulable IRQ jobs. :)

Jan

#3 lore raw

Hi Jan,

I'll read up more carefully you proposalsa bit later, just want to note now that the code I have posted (and actually the current shirq code) have a few nasty (hidden maybe for a first glance) synch. related bugs. brrr... although one will not encounter them when RTDM is used for driver development but may happilly find himslef in trouble using the native or posix skin.

I'm finding a way to solve them more gracefully now.

--
Best regards,
Dmitry Adamushko

#4 lore raw
In reply to Jan Kiszka
Quoted 5 lines

Yes, I do have some remarks: due to legacy issues (I think to remember), we have a lot of unbalanced irq-enable/disable code out there. IRQs are currently enabled after registering a handler, but are not disabled on detach. That's because of problems with Linux when letting it take over a disabled IRQ,

let's consider possible use cases one by one :

1) single interrupt object for a given IRQ in the primary mode

I guess, this is the most wide-spread use case for the legacy code.

possible problems:

o unbalanced enable/disable calls - e.g. a few consecutive disable calls but a single enable call is supposed to re-enable the IRQ line afterwards.

the only workaround - review and fix such code :)

2) a few interrupt objects in the primary domain.

new mode so there should not be too much code that use it out there.

Actually, here goes a problem.

rtdm_irq_request(); // doesn't enable the IRQ line
...
rtdm_irq_enable(); // explicitly enables the IRQ line

the same code is called for every ISR that share this IRQ line.

so how the internal counter is supposed to be used then?

i.e. we should avoid printing a warning when the counter becomes 0.

int xnintr_enable (xnintr_t *intr)

 {
    int ret = 0;
    spl_t s;

    xnlock_get_irqsave(&nklock,s);

    switch (__xnintr_depth(intr,0))
	{
	case 0:
-	    xnlogerr("xnintr_enable() : depth == 0. "
-		     "Unbalanced enable/disable calls for IRQ%d!\n",intr->irq);
	    break;
	case 1:
	    ret = xnarch_irq_enable(intr->irq);
	default:
	    __xnintr_depth(intr,-1);
	}

    xnlock_put_irqrestore(&nklock,s);
    return ret;

}

and, in fact, in the shared mode a driver can't rely on the fact that the IRQ line is still disabled
after attaching to the IRQ line.

driver 2:

rtdm_irq_request(..., SHARED, ...); // we have attached to the shared
IRQ line which is already enabled

... // this code can't expect that it's executed with the IRQ line off.

rtdm_irq_enable(); // explicitly enables the IRQ line

does it make sense to enable the IRQ line when attaching to the line?

rtdm_irq_request();
// the line is already enabled

3) the IRQ line is shared across domains (both primary and linux).

yep, new interface doesn't fit this case well.

Maybe, it would be possible to use the same "counter" accounting scheme for xnintr_enable/disable() in the primary domain and enable_irq/disable_irq() in the linux one.

Quoted 5 lines

Another thing I have on my mind ATM is providing an additional IRQ
model: threaded IRQs. This is certainly not the best default model, but it could help in certain scenarios to reduce prio-inversions due to overloaded IRQ handler jobs (like we face from time to time with devices on the slow ISA-bus...).

In the simplest case, I guess, one may just defer part of the work to the bottom half -
a thread of a given priority. And bottom halves (threads) for different ISRs may have different
priorities (== thread's priority).

Concerning the general support, RTDM layer would be likely preferable but I'm not sure that all necessary
bits are available on this layer.

e.g.

it would be better to run the following code from xnintr_shirq_handler()
...

    while (intr)
        {
	s |= intr->isr(intr) & XN_ISR_BITMASK;
        ++intr->hits;
        intr = intr->next;
        }

...

already from the thread context.

--
Best regards,
Dmitry Adamushko