Shared interrupts (ready to merge)
PATCH 1/1 Shared interrupts (ready to merge)
Hello everybody,
being inspired by successful results of tests conducted recently by Jan & team,
I'm presenting the final (yep, yet another final :) combo-patch.
The shirq support now is optional, so that
CONFIG_XENO_OPT_SHIRQ_LEVEL - enables shirq for level-triggered
interrupts;
CONFIG_XENO_OPT_SHIRQ_EDGE - -//- for edge-triggered ones.
I addressed all the remarks and now, IMHO, it's (hopefully) ready for merge.
--
Best regards,
Dmitry Adamushko
include/asm-generic/hal.h +5 -0
@@ -64,6 +64,11 @@#define RTHAL_NR_CPUS IPIPE_NR_CPUS#define RTHAL_ROOT_PRIO IPIPE_ROOT_PRIO#define RTHAL_NR_FAULTS IPIPE_NR_FAULTS +#define RTHAL_NR_IRQS IPIPE_NR_IRQS +#define RTHAL_VIRQ_BASE IPIPE_VIRQ_BASE + +#define rthal_virtual_irq_p (irq) ((irq) >= RTHAL_VIRQ_BASE && \ + (irq) < RTHAL_NR_IRQS)#define RTHAL_SERVICE_IPI0 IPIPE_SERVICE_IPI0#define RTHAL_SERVICE_VECTOR0 IPIPE_SERVICE_VECTOR0
include/asm-generic/system.h +2 -0
@@ -101,6 +101,8 @@ typedef struct { volatile unsigned long#define XNARCH_NR_CPUS RTHAL_NR_CPUS +#define XNARCH_TIMER_IRQ RTHAL_TIMER_IRQ +#define XNARCH_ROOT_STACKSZ 0/* Only a placeholder -- no stack */ #define XNARCH_PROMPT "Xenomai: "
include/asm-i386/hal.h +3 -0
@@ -139,6 +139,9 @@ static inline __attribute_const__ unsign#define RTHAL_APIC_TIMER_VECTOR RTHAL_SERVICE_VECTOR3#define RTHAL_APIC_TIMER_IPI RTHAL_SERVICE_IPI3#define RTHAL_APIC_ICOUNT ((RTHAL_TIMER_FREQ + HZ/2)/HZ) +#define RTHAL_TIMER_IRQ RTHAL_APIC_TIMER_IPI +#else /* !CONFIG_X86_LOCAL_APIC */ +#define RTHAL_TIMER_IRQ RTHAL_8254_IRQ#endif /* CONFIG_X86_LOCAL_APIC */ #define RTHAL_NMICLK_FREQ RTHAL_CPU_FREQ
include/asm-sim/system.h +3 -0
@@ -75,6 +75,9 @@ typedef unsigned long xnlock_t;#define XNARCH_NR_CPUS 1 +/* Should be equal to the value used for creating the mvmtimer object (mvm_start_timer). */ +#define XNARCH_TIMER_IRQ 1 +#define XNARCH_DEFAULT_TICK 10000000/* ns, i.e. 10ms */ #define XNARCH_HOST_TICK 0/* No host ticking service. */
include/asm-uvm/system.h +2 -0
@@ -74,6 +74,8 @@ typedef unsigned long xnlock_t;#define XNARCH_NR_CPUS 1 +#define XNARCH_TIMER_IRQ 0 +#define XNARCH_DEFAULT_TICK 1000000/* ns, i.e. 1ms */ #define XNARCH_SIG_RESTART SIGUSR1#define XNARCH_HOST_TICK 0/* No host ticking service */
include/native/intr.h +10 -4
@@ -50,9 +50,14 @@ typedef struct rt_intr_placeholder {#define XENO_INTR_MAGIC 0x55550a0a +/* Creation flags. */ +#define I_SHARED XN_ISR_SHARED +#define I_EDGE XN_ISR_EDGE +#define RT_INTR_HANDLED XN_ISR_HANDLED#define RT_INTR_CHAINED XN_ISR_CHAINED#define RT_INTR_ENABLE XN_ISR_ENABLE +#define RT_INTR_NOINT XN_ISR_NOINT#define I_DESC (xintr) ((RT_INTR *)(xintr)->cookie)
@@ -71,8 +76,6 @@ typedef struct rt_intr {rt_handle_t handle;/* !< Handle in registry -- zero if unregistered. */ -char name[XNOBJECT_NAME_LEN ];/* !< Symbolic name. */ -#if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE )int mode;/* !< Interrupt control mode. */
@@ -101,9 +104,11 @@ int __native_intr_pkg_init(void);void __native_intr_pkg_cleanup (void );int rt_intr_create (RT_INTR *intr, +const char *name,unsigned irq,rt_isr_t isr, -rt_iack_t iack); +rt_iack_t iack, +int mode);#ifdef CONFIG_XENO_OPT_PERVASIVE int rt_intr_handler (xnintr_t *cookie);
@@ -122,7 +127,7 @@ extern "C" {#endif int rt_intr_bind (RT_INTR *intr, -unsigned irq, +const char *name,RTIME timeout);static inline int rt_intr_unbind (RT_INTR *intr)
@@ -133,6 +138,7 @@ static inline int rt_intr_unbind (RT_INT }int rt_intr_create (RT_INTR *intr, +const char *name,unsigned irq,int mode);
include/nucleus/intr.h +24 -5
@@ -25,22 +25,36 @@#define XN_ISR_HANDLED 0x0#define XN_ISR_CHAINED 0x1#define XN_ISR_ENABLE 0x2 +#define XN_ISR_NOINT 0x4 -#if defined(__KERNEL__) || defined(__XENO_UVM__) || defined(__XENO_SIM__) +/* Creation flags. */ +#define XN_ISR_SHARED 0x1 +#define XN_ISR_EDGE 0x2 + +/* Operational flags. */ +#define XN_ISR_ATTACHED 0x100 -struct xnintr ; +#if defined(__KERNEL__) || defined(__XENO_UVM__) || defined(__XENO_SIM__)typedef struct xnintr { -unsigned irq;/* !< IRQ number. */ +#if defined(CONFIG_XENO_OPT_SHIRQ_LEVEL ) || defined(CONFIG_XENO_OPT_SHIRQ_EDGE ) +struct xnintr *next;/* !< Next object in the IRQ-sharing chain. */ +#endif /* CONFIG_XENO_OPT_SHIRQ_LEVEL || CONFIG_XENO_OPT_SHIRQ_EDGE */ xnisr_t isr;/* !< Interrupt service routine. */ -xniack_t iack;/* !< Interrupt acknowledge routine. */ +void *cookie;/* !< User-defined cookie value. */ unsigned long hits;/* !< Number of receipts (since attachment). */ -void *cookie;/* !< User-defined cookie value. */ +xnflags_t flags;/* !< Creation flags. */ + +unsigned irq;/* !< IRQ number. */ + +xniack_t iack;/* !< Interrupt acknowledge routine. */ + +char name[XNOBJECT_NAME_LEN ];/* !< Symbolic name. */ }xnintr_t ;
@@ -50,11 +64,16 @@ extern xnintr_t nkclock;extern "C" {#endif +int xnintr_mount (void ); +void xnintr_clock_handler (void ); +int xnintr_irq_proc (unsigned int irq,char *str); +/* Public interface. */ int xnintr_init(xnintr_t *intr, + const char *name, unsigned irq, xnisr_t isr, xniack_t iack,
include/rtdm/rtdm_driver.h +14 -2
@@ -693,6 +693,17 @@ typedef unsigned long rtdmtypedef xnintr_t rtdm_irq_t ; +/*! +* @anchor RTDM_IRQTYPE_xxx @name RTDM_IRQTYPE_xxx +* Interrupt registrations flags +* @{ +*/ +/** Enable IRQ-sharing with other real-time drivers */ +#define RTDM_IRQTYPE_SHARED XN_ISR_SHARED +/** Additional flag to enable IRQ-sharing of edge-triggered interrupts */ +#define RTDM_IRQTYPE_EDGE XN_ISR_EDGE +/** @} */ +/** * Interrupt handler *
@@ -702,7 +713,6 @@ typedef xnintr_t rtdm*/ typedef int (*rtdm_irq_handler_t )(rtdm_irq_t *irq_handle); -/*! * @anchor RTDM_IRQ_xxx @name RTDM_IRQ_xxx * Return flags of interrupt handlers
@@ -712,6 +722,8 @@ typedef int (*rtdm_irq_handler_t)(rtdm_i#define RTDM_IRQ_PROPAGATE XN_ISR_CHAINED/** Re-enable interrupt line on return */ #define RTDM_IRQ_ENABLE XN_ISR_ENABLE +/** Denote unhandled interrupt */ +#define RTDM_IRQ_NOINT XN_ISR_NOINT/** @} */ /**
@@ -741,7 +753,7 @@ static inline int rtdm_irq_request(rtdm_const char *device_name, void *arg) { -xnintr_init (irq_handle ,irq_no ,handler ,NULL ,flags ); +xnintr_init (irq_handle ,device_name ,irq_no ,handler ,NULL ,flags );return xnintr_attach (irq_handle, arg); }
ksrc/arch/generic/hal.c +0 -46
64 lines not on this page · raw message
ksrc/drivers/16550A/16550A.c +3 -2
@@ -238,7 +238,7 @@ static int rt_16550_interrupt(rtdm_irq_tint rbytes =0 ;int events =0 ;int modem; -int ret =RTDM_IRQ_PROPAGATE ; +int ret =RTDM_IRQ_PROPAGATE |RTDM_IRQ_NOINT ; ctx = rtdm_irq_get_arg(irq_context, struct rt_16550_context);
@@ -446,7 +446,8 @@ int rt_16550_open(struct rtdm_dev_contex ctx = (struct rt_16550_context *)context->dev_private; ret =rtdm_irq_request (&ctx->irq_handle, irq[dev_id], rt_16550_interrupt, -0 , context->device->proc_name, ctx); +RTDM_IRQTYPE_SHARED |RTDM_IRQTYPE_EDGE , + context->device->proc_name, ctx);if (ret <0 )return ret;
ksrc/nucleus/intr.c +377 -10
456 lines not on this page · raw message
ksrc/nucleus/module.c +51 -0
75 lines not on this page · raw message
ksrc/nucleus/pod.c +2 -3
@@ -3040,11 +3040,10 @@ unlock_and_exit:/* The clock interrupt does not need to be attached since the timer service will handle the arch-dependent setup. The IRQ -number (arg #2) is not used since the IRQ source will be -attached directly by the arch-dependent layer +source will be attached directly by the arch-dependent layer (xnarch_start_timer). */ -xnintr_init (&nkclock,0 ,tickhandler,NULL ,0 ); +xnintr_init (&nkclock,"[timer]" ,XNARCH_TIMER_IRQ ,tickhandler,NULL ,0 );__setbits (nkpod->status,XNTIMED );
ksrc/skins/native/intr.c +20 -6
@@ -119,7 +119,7 @@ static RT_OBJECT_PROCNODE __intr_pnode =#endif /* CONFIG_XENO_NATIVE_EXPORT_REGISTRY */ /*! -* \fn int rt_intr_create (RT_INTR *intr,unsigned irq,rt_isr_t isr,rt_iack_t iack) +* \fn int rt_intr_create (RT_INTR *intr,const char *name,unsigned irq,rt_isr_t isr,rt_iack_t iack,int mode) * \brief Create an interrupt object from kernel space. * * Initializes and associates an interrupt object with an IRQ line. In
@@ -155,6 +155,11 @@ static RT_OBJECT_PROCNODE __intr_pnode =* be valid while the object is active therefore it must be allocated * in permanent memory. * +* @param name An ASCII string standing for the symbolic name of the +* interrupt object. When non-NULL and non-empty, this string is copied +* to a safe place into the descriptor, and passed to the registry package +* if enabled for indexing the created interrupt objects. +* * @param irq The hardware interrupt channel associated with the * interrupt object. This value is architecture-dependent. *
@@ -173,6 +178,14 @@ static RT_OBJECT_PROCNODE __intr_pnode =* the interrupt has been properly acknowledged. If @a iack is NULL, * the default routine will be used instead. * +* @param mode The interrupt object creation mode. The following flags can be +* OR'ed into this bitmask, each of them affecting the new interrupt object: +* +* - I_SHARED enables IRQ-sharing with other interrupt objects. +* +* - I_EDGE is an additional flag need to be set together with I_SHARED +* to enable IRQ-sharing of edge-triggered interrupts. +* * @return 0 is returned upon success. Otherwise: * * - -ENOMEM is returned if the system fails to get enough dynamic
@@ -205,9 +218,11 @@ static RT_OBJECT_PROCNODE __intr_pnode =*/ int rt_intr_create (RT_INTR *intr, +const char *name,unsigned irq,rt_isr_t isr, -rt_iack_t iack) +rt_iack_t iack, +int mode) {int err;spl_t s;
@@ -215,7 +230,7 @@ int rt_intr_create (RT_INTR *intr,if (xnpod_asynch_p ())return -EPERM ; -xnintr_init (&intr->intr_base,irq,isr,iack,0 ); +xnintr_init (&intr->intr_base,name,irq,isr,iack,mode);#if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE )xnsynch_init (&intr->synch_base,XNSYNCH_PRIO ); intr->pending =0 ;
@@ -228,7 +243,6 @@ int rt_intr_create (RT_INTR *intr,xnlock_get_irqsave (&nklock,s);appendq (&__xeno_intr_q,&intr->link);xnlock_put_irqrestore (&nklock,s); -snprintf (intr->name,sizeof (intr->name),"irq%u" ,irq); err =xnintr_attach (&intr->intr_base,intr);
@@ -238,7 +252,7 @@ int rt_intr_create (RT_INTR *intr,half-baked objects... */ if (!err) - err =rt_registry_enter (intr->name,intr,&intr->handle,&__intr_pnode); + err =rt_registry_enter (intr->intr_base.name,intr,&intr->handle,&__intr_pnode);#endif /* CONFIG_XENO_OPT_NATIVE_REGISTRY */ if (err)
@@ -492,7 +506,7 @@ int rt_intr_inquire (RT_INTR *intr, goto unlock_and_exit; } -strcpy (info->name,intr->name); +strcpy (info->name,intr->intr_base.name); info->hits = intr->intr_base.hits; info->irq = intr->intr_base.irq;
ksrc/skins/native/snippets/user_irq.c +1 -1
@@ -33,7 +33,7 @@ int main (int argc, char *argv[])/* ... */ - err =rt_intr_create (&intr_desc,IRQ_NUMBER ,I_AUTOENA ); + err =rt_intr_create (&intr_desc,"MyIrq" ,IRQ_NUMBER ,I_AUTOENA );/* ... */
ksrc/skins/native/syscall.c +16 -3
@@ -2894,6 +2894,7 @@ EXPORT_SYMBOL(rt_intr_handler);/* * int __rt_intr_create(RT_INTR_PLACEHOLDER *ph, +* const char *name, * unsigned irq, * int mode) */
@@ -2901,6 +2902,7 @@ EXPORT_SYMBOL(rt_intr_handler);static int __rt_intr_create (struct task_struct *curr,struct pt_regs *regs) { +char name[XNOBJECT_NAME_LEN ];RT_INTR_PLACEHOLDER ph;int err, mode;RT_INTR *intr;
@@ -2909,11 +2911,22 @@ static int __rt_intr_create (struct taskif (!__xn_access_ok (curr,VERIFY_WRITE ,__xn_reg_arg1 (regs),sizeof (ph)))return -EFAULT ; +if (__xn_reg_arg2 (regs)) + { +if (!__xn_access_ok (curr,VERIFY_READ ,__xn_reg_arg2 (regs),sizeof (name))) +return -EFAULT ; + +__xn_strncpy_from_user (curr,name,(const char __user *)__xn_reg_arg2 (regs),sizeof (name) -1 ); + name[sizeof (name) -1 ] ='\0' ; + } +else + *name ='\0' ; +/* Interrupt line number. */ - irq = (unsigned )__xn_reg_arg2 (regs); + irq = (unsigned )__xn_reg_arg3 (regs);/* Interrupt control mode. */ - mode = (int )__xn_reg_arg3 (regs); + mode = (int )__xn_reg_arg4 (regs);if (mode & ~(I_AUTOENA |I_PROPAGATE ))return -EINVAL ;
@@ -2923,7 +2936,7 @@ static int __rt_intr_create (struct taskif (!intr)return -ENOMEM ; - err =rt_intr_create (intr,irq,&rt_intr_handler,NULL ); + err =rt_intr_create (intr,name,irq,&rt_intr_handler,NULL ,0 );if (err ==0 ) {
ksrc/skins/posix/intr.c +1 -1
@@ -27,7 +27,7 @@ int pse51_intr_attach (struct pse51_inteint err;spl_t s; -xnintr_init (&intr->intr_base,irq,isr,iack,0 ); +xnintr_init (&intr->intr_base,NULL ,irq,isr,iack,0 );#if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE )xnsynch_init (&intr->synch_base,XNSYNCH_PRIO );
ksrc/skins/rtdm/drvlib.c +1 -1
@@ -1200,7 +1200,7 @@ EXPORT_SYMBOL(rtdm_mutex_unlock);* @param[in,out] irq_handle IRQ handle * @param[in] irq_no Line number of the addressed IRQ * @param[in] handler Interrupt handler -* @param[in] flags Currently unused, pass 0 +* @param[in] flags Registration flags, see @ref RTDM_IRQTYPE_xxx for details * @param[in] device_name Optional device name to show up in real-time IRQ * lists (not yet implemented) * @param[in] arg Pointer to be passed to the interrupt handler on invocation
src/skins/native/intr.c +4 -6
@@ -24,24 +24,22 @@extern int __native_muxid;int rt_intr_create (RT_INTR *intr, +const char *name,unsigned irq,int mode) { -return XENOMAI_SKINCALL3 (__native_muxid, +return XENOMAI_SKINCALL4 (__native_muxid, __native_intr_create, intr, + name, irq, mode); }int rt_intr_bind (RT_INTR *intr, -unsigned irq, +const char *name,RTIME timeout) { -char name[XNOBJECT_NAME_LEN ]; - -snprintf (name,sizeof (name),"irq%u" ,irq); - return XENOMAI_SKINCALL3(__native_muxid, __native_intr_bind, intr,
Config.in +7 -0
@@ -27,6 +27,13 @@ if [ "$CONFIG_XENO_OPT_NUCLEUS" != "n" ] int 'Number of priority levels' CONFIG_XENO_OPT_SCALABLE_PRIOS 256 fi endmenu + + mainmenu_option next_comment + comment 'Shared interrupts' + bool 'Level-triggered interrupts' CONFIG_XENO_OPT_SHIRQ_LEVEL + bool 'Edge-triggered interrupts' CONFIG_XENO_OPT_SHIRQ_EDGE + endmenu + if [ "$CONFIG_LTT" != "n" ]; then mainmenu_option next_comment comment 'LTT tracepoints filtering'
Kconfig +24 -0
@@ -131,6 +131,30 @@ config XENO_OPT_SCALABLE_PRIOS endmenu +menu "Shared interrupts" + +config XENO_OPT_SHIRQ_LEVEL + bool "Level-triggered interrupts" + default n + help + + Enables support for shared _level-triggered_ interrupts, so that + multiple real-time interrupt handlers are allowed to control + dedicated hardware devices which are configured to share + the same interrupt channel. + +config XENO_OPT_SHIRQ_EDGE + bool "Edge-triggered interrupts" + default n + help + + Enables support for shared _edge-triggered_ interrupts, so that + multiple real-time interrupt handlers are allowed to control + dedicated hardware devices which are configured to share + the same interrupt channel. + +endmenu + menu "LTT tracepoints filtering" depends on LTT
ChangeLog renamed from ChangeLog-old +8 -0
@@ -1,3 +1,11 @@ +2006-02-15 Dmitry Adamushko <[email protected]> + + * include/nucleus/intr.h, nucleus/intr.c: Add optional support + for shared interrupts (level- and edge-triggered), so that + multiple real-time interrupt handlers are allowed to control + dedicated hardware devices which are configured to share + the same interrupt channel. + 2006-02-02 Wolfgang Grandegger <[email protected]> * include/asm-generic/hal.h, include/asm-generic/system.h
Quoted 6 lines · Dmitry Adamushko
Hello everybody,
being inspired by successful results of tests conducted recently by Jan & team,
I'm presenting the final (yep, yet another final :) combo-patch.
Quoted 9 lines
The shirq support now is optional, so that
CONFIG_XENO_OPT_SHIRQ_LEVEL- enables shirq for level-triggered
interrupts;
CONFIG_XENO_OPT_SHIRQ_EDGE- -//- for edge-triggered ones.I addressed all the remarks and now, IMHO, it's (hopefully) ready for merge.
Hmm, I still find XN_ISR_NOINT in the patch. Shouldn't we solve this before merging (i.e. make XN_ISR_HANDLED non-zero)?
Moreover, I attached an add-on patch to overcome the name buffer in xnintr_t. Note that this patch is only compile-tested, I have no native interrupt test-case at hand.
Jan
nucleus/intr.h +1 -1
@@ -54,7 +54,7 @@xniack_t iack;/* !< Interrupt acknowledge routine. */ -char name[XNOBJECT_NAME_LEN ];/* !< Symbolic name. */ +const char *name;/* !< Symbolic name. */ } xnintr_t;
skins/native/syscall.c +29 -19
75 lines not on this page · raw message
nucleus/intr.c +1 -1
@@ -148,7 +148,7 @@ intr->cookie =NULL ; intr->hits =0 ; intr->flags = flags; -xnobject_copy_name (intr->name,name); + intr->name = name;#if defined(CONFIG_XENO_OPT_SHIRQ_LEVEL ) || defined(CONFIG_XENO_OPT_SHIRQ_EDGE ) intr->next =NULL ;#endif /* CONFIG_XENO_OPT_SHIRQ_LEVEL || CONFIG_XENO_OPT_SHIRQ_EDGE */
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find XN_ISR_NOINT in the patch. Shouldn't we solve this
Quoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?
Ok, XN_ISR_NOINT is removed in favor of XN_ISR_HANDLED which is now non-zero.
Actually, at first I wanted to make it just the other way about.
Moreover, I attached an add-on patch to overcome the name buffer in
Quoted 2 lines
xnintr_t. Note that this patch is only compile-tested, I have no native interrupt test-case at hand.
Heh.. someone once suggested the -p key with "diff" to me? :o)
I bet your patch would even work but it's, well, slightly broken indeed ;-)
Look at the native/syscall.c : __rt_intr_delete() :
RT_INTR *intr = (RT_INTR *)rt_registry_fetch(ph.opaque);
...
xnfree(intr);
"intr" actually points to intr_buf->intr and it works as expected only because "RT_INTR intr" is the first member of the struct, so that it's address == the address of the whole object of this struct.
To do it properly you would need to make your "unnamed" struct visible for both __rt_intr_create() and __rt_intr_delete(). Something like :
struct RT_INTR_ENV {
#define link2intr_env(laddr) \
((RT_INTR_ENV *)(((char* )laddr) - (int)(&((RT_INTR_ENV *)0)->intr)))
RT_INTR intr;
char name[XNOBJECT_NAME_LEN];
};and then make use of link2intr_env() in __rt_intr_delet().
Ok, with you approach we would avoid allocating memory for name[XNOBJECT_NAME_LEN] when an object is created in kernel-mode and do it via RT_INTR_ENV only when it's created in user-mode.
We could even use that approach for all objects in native skin, but we can't because of "anonymous" objects supported in kernel-mode too and, well, I personally would not like those RT_OBJECT_ENV structures all over the map in syscall.c :)
So I don't want to break the whole picture only for the RT_INTR object (it doesn't support "anonymous" objects now).
Nevertheless, if you still want to save a hundred bytes of data or so (how many interrupt objects would a normal system have? and I guess the lenght of name is about 10 symbols on average :)
for the users that don't use native skin, then I would suggest the following way :
xnintr_t contains just the link "char *name" as you suggested but RT_INTR contains the name[XNOBJECT_NAME_LEN] member (as it was before actually).
If it's ok, then I'll send um... yet another final patch that addresses both issues :)
Jan
Quoted 3 lines
--
Best regards,
Dmitry Adamushko
Quoted 10 lines · Dmitry Adamushko
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find
XN_ISR_NOINTin the patch. Shouldn't we solve thisQuoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?Ok,
XN_ISR_NOINTis removed in favor ofXN_ISR_HANDLEDwhich is now non-zero.
Actually, at first I wanted to make it just the other way about.
Hmm, thinking about this again, I would like to revert my suggestion in favour of a third approach (trying to keep you busy ;) ).
Recommended default values:
<new>XN_ISR_HANDLED => <old non-zero>XN_ISR_HANDLED | <old>XN_ISR_ENABLE
<new>XN_ISR_NOINT => <new>XN_ISR_NO_ENABLE
Additional bits:
<new>XN_ISR_NO_ENABLE
=> indicate that <old>XN_ISR_ENABLE is not set
(use case: handle but delay re-enable)
<new>XN_ISR_PROPAGATE
=> <old>XN_ISR_CHAINED (the new name is closer to the related function
calls - at least for me).
Not expressible combination:
<old>XN_ISR_ENABLE | <new>XN_ISR_NOINT
=> Doesn't make sense, does it?
Still expressible invalid combination:
<new>XN_ISR_HANDLED | <new>XN_ISR_PROPAGATE
=> The implicit enable request should be easy to ignore at nucleus
level.
Rational:
Most users will either indicate that an IRQ was handled and should be re-enabled as soon as possible or that it was unhandled and should better remain masked if no one else cares.
XN_ISR_PROPAGATE (or related skin defines) are only useful for very very special corner-case drivers and applications. Normal generic drivers should not touch this (including my own xeno_16550A... bah!). BTW, if there is some unintentional IRQ sharing so that spurious RT interrupts occur, I think we should detect this at nucleus level and bail out. Otherwise, systems quickly lock up (I just faced this once again two days ago on an old RTAI box).
This will break some stuff (RTDM e.g., but we have some version flags for such cases), but it takes us closer to the standard Linux API without loosing control over the details when required.
Comments?
Quoted 8 lines
Moreover, I attached an add-on patch to overcome the name buffer in
Quoted 2 lines
xnintr_t. Note that this patch is only compile-tested, I have no native interrupt test-case at hand.Heh.. someone once suggested the -p key with "diff" to me? :o)
Mmpf. Must have been too late, and I was too impressed how interdiff worked out this patch. :)
Quoted 5 lines
I bet your patch would even work but it's, well, slightly broken indeed ;-)
Look at the
native/syscall.c:__rt_intr_delete():
Quoted 7 lines
RT_INTR*intr = (RT_INTR*)rt_registry_fetch(ph.opaque);
...
xnfree(intr);"intr" actually points to
intr_buf->intrand it works as expected only because "RT_INTRintr" is the first member of the struct, so that it's address == the address of the whole object of this struct.
But this is not an unusual trick, and I see no practical problems.
Quoted 16 lines
To do it properly you would need to make your "unnamed" struct visible for both
__rt_intr_create()and__rt_intr_delete(). Something like :struct
RT_INTR_ENV{#define
link2intr_env(laddr)\
((RT_INTR_ENV*)(((char* )laddr) - (int)(&((RT_INTR_ENV *)0)->intr)))RT_INTR intr; char name[XNOBJECT_NAME_LEN]; };and then make use of
link2intr_env()in__rt_intr_delet().
Quoted 8 lines
Ok, with you approach we would avoid allocating memory for name[XNOBJECT_NAME_LEN] when an object is created in kernel-mode and do it via
RT_INTR_ENVonly when it's created in user-mode.We could even use that approach for all objects in native skin, but we can't because of "anonymous" objects supported in kernel-mode too and, well, I personally would not like those
RT_OBJECT_ENVstructures all over the map insyscall.c:)
Me too.
Quoted 7 lines
So I don't want to break the whole picture only for the
RT_INTRobject (it doesn't support "anonymous" objects now).Nevertheless, if you still want to save a hundred bytes of data or so (how many interrupt objects would a normal system have? and I guess the lenght of name is about 10 symbols on average :)
RT_INTR is now disabled by default in the kernel config. Thus most users should not see its code in their kernels, only the additional data and code related to xnintr_t.name.
Quoted 9 lines
for the users that don't use native skin, then I would suggest the following way :
xnintr_tcontains just the link "char *name" as you suggested butRT_INTRcontains the name[XNOBJECT_NAME_LEN] member (as it was before actually).If it's ok, then I'll send um... yet another final patch that addresses both issues :)
I'm fine with this as well if you prefer it, no problem.
Jan
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Dmitry Adamushko
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find
XN_ISR_NOINTin the patch. Shouldn't we solve thisQuoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?
Quoted 7 lines
Quoted 4 lines
Ok,
XN_ISR_NOINTis removed in favor ofXN_ISR_HANDLEDwhich is now non-zero.
Actually, at first I wanted to make it just the other way about.Hmm, thinking about this again, I would like to revert my suggestion in favour of a third approach (trying to keep you busy ;) ).
Ok, you are wellcome :)
I didn't get it, at least while looking briefly. To make it a bit easier, at least for me, let's go another way.
At the left is the list of allowed values as Philippe pointed out. At the right is another list which corresponds to the left one but when NOINT is used instead of HANDLED. Moreover, I have added another case - pure NOINT. The ISR says it's not mine and, well, it doesn't know whether it should be propagated or no
(ok, so far CHAINED standed for NOINT).
HANDLED -> 0
HANDLED | ENABLE -> ENABLE
HANDLED | CHAINED -> CHAINED
CHAINED -> CHAINED | NOINT
-> NOINTCould you provide the 3-d corresponding table using your new flags?
Quoted 7 lines
xnintr_tcontains just the link "char *name" as you suggested butRT_INTRQuoted 4 lines
contains the name[XNOBJECT_NAME_LEN] member (as it was before actually).
If it's ok, then I'll send um... yet another final patch that addresses both issues :)
I'm fine with this as well if you prefer it, no problem.
Yep, let's go this way.
Jan
Quoted 3 lines
--
Best regards,
Dmitry Adamushko
Quoted 27 lines · Dmitry Adamushko
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Dmitry Adamushko
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find
XN_ISR_NOINTin the patch. Shouldn't we solve thisQuoted 8 lines
Quoted 6 lines
Quoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?Ok,
XN_ISR_NOINTis removed in favor ofXN_ISR_HANDLEDwhich is now non-zero.
Actually, at first I wanted to make it just the other way about.Hmm, thinking about this again, I would like to revert my suggestion in favour of a third approach (trying to keep you busy ;) ).
Ok, you are wellcome :)
I didn't get it, at least while looking briefly. To make it a bit easier, at least for me, let's go another way.
At the left is the list of allowed values as Philippe pointed out. At the right is another list which corresponds to the left one but when NOINT is used instead of HANDLED. Moreover, I have added another case - pure NOINT. The ISR says it's not mine and, well, it doesn't know whether it should be propagated or no
(ok, so far CHAINED standed for NOINT).
Quoted 8 lines
1.) HANDLED -> 0
2.) HANDLED | ENABLE -> ENABLE 3.) HANDLED | CHAINED -> CHAINED4.) CHAINED -> CHAINED | NOINT
5.) -> NOINTCould you provide the 3-d corresponding table using your new flags?
Still not 3D, but hopefully clarifying: :)
1.) XN_ISR_HANDLED |XN_ISR_NO_ENABLE
2.) XN_ISR_HANDLED
3.) XN_ISR_HANDLED | XN_ISR_PROPAGATE
(nucleus ignores implicit IRQ enable)
4.) XN_ISR_NOINT | XN_ISR_PROPAGATE
5.) XN_ISR_NOINT
2.) and 5.) are most common, the others for special scenarios. Especially, as long as we have no API for ending IRQs outside the handler, 1.) is of limited usage I think.
Jan
Quoted 37 lines · Jan Kiszka
Quoted 11 lines · Dmitry Adamushko
Quoted 10 lines · Jan Kiszka
Quoted 9 lines · Dmitry Adamushko
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find
XN_ISR_NOINTin the patch. Shouldn't we solve thisQuoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?Ok,
XN_ISR_NOINTis removed in favor ofXN_ISR_HANDLEDwhich is now non-zero.
Actually, at first I wanted to make it just the other way about.Quoted 7 lines
Quoted 2 lines
Hmm, thinking about this again, I would like to revert my suggestion in favour of a third approach (trying to keep you busy ;) ).
Ok, you are wellcome :)
I didn't get it, at least while looking briefly. To make it a bit
easier, at
Quoted 5 lines
least for me, let's go another way.
At the left is the list of allowed values as Philippe pointed out. At the right is another list which corresponds to the left one but when NOINT is used instead of HANDLED. Moreover, I have added another case -
pure
Quoted 10 lines
NOINT. The ISR says it's not mine and, well, it doesn't know whether it should be propagated or no
(ok, so far CHAINED standed for NOINT).1.) HANDLED -> 0
2.) HANDLED | ENABLE -> ENABLE 3.) HANDLED | CHAINED -> CHAINED4.) CHAINED -> CHAINED | NOINT
5.) -> NOINT
Quoted 4 lines
Quoted 2 lines
Could you provide the 3-d corresponding table using your new flags?
Still not 3D, but hopefully clarifying: :)
1.) XN_ISR_HANDLED |XN_ISR_NO_ENABLE
Quoted 5 lines
2.)
XN_ISR_HANDLED
3.)XN_ISR_HANDLED|XN_ISR_PROPAGATE
(nucleus ignores implicit IRQ enable)
4.)XN_ISR_NOINT|XN_ISR_PROPAGATE
5.)XN_ISR_NOINT
Then why do we need XN_ISR_NOINT? is it not just the same as ~HANDLED?
Moreover, I tend to think now that PROPAGATE (CHAINED) should not be normally used by ISRs at all. The only exception would be irq sharing between RT and non-RT domains, but that's of no concern for most part of rt drivers and, as last events revealed, it's very partially supported at the moment and possible implementations are quite arguable.
So HANDLED means the irq line is .end-ed by xnintr_irq_handler() (xnarch_end_irq(irq) is called).
If one wants to do it on his own later, NOENABLE can be returned additionally.
But then, one must use xnintr_end_irq() and not just xnintr_irq_enable().
If xnintr_end_irq() would be always the same as xnintr_irq_enable() or we would decouple ending and enabling operations on the line (don't have sources at hand); we could go Linux way and make use of a "nested" counter in xnintr_t, so that xnintr_irq_disable() could be called in a nested way. This said, calling xnintr_irq_disable() in ISR leads to the interrupt line being still disabled upon return from xnintr_irq_handler() and re-enabled again by the user later.
~HANDLED means the ISR was not concerned about this interrupt. i.e. :
- there is ISR in another domain (down the pipeline) which is interested in this irq ;
well, the designer of the system should be aware of such cases and
probably avoid that on hw layer or, at least, to know what she is doing.
- this is a spurious irq.
So upon getting ~HANDLED, xnintr_irq_handler() does :
success = xnintr_irq_chained(irq);
if (success)
{
/* i.e. another domain is really interested and got this irq as pending*/
return without .end-ing
}
else
{
/* this is a spurious irq */
make use of some accounting of spurious interrupts (if we need it)), i.e. keep the irq line disabled if the % of unhandled requests > some limit.
otherwise
xnintr_end_irq() and return
}
too long :) ok, it's quite similar indeed to what you have suggested, with the exception that
- no need for NOINT (if it's really == ~HANDLED);
- nucleus provides some additional logic while handling ~HANDLED case.
- user don't need to return ENABLE explicitly - in most cases, that's what he actually needs but sometimes just forgets (I recall a few questions on the mailing list about "only one interrupt".
Jan
Quoted 2 lines
--
Best regards,
Dmitry Adamushko
Quoted 42 lines · Dmitry Adamushko
Quoted 34 lines · Jan Kiszka
Quoted 10 lines · Dmitry Adamushko
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Dmitry Adamushko
On 16/02/06, Jan Kiszka <[email protected]> wrote:
Hmm, I still find
XN_ISR_NOINTin the patch. Shouldn't we solve thisQuoted 1 line
before merging (i.e. make
XN_ISR_HANDLEDnon-zero)?Ok,
XN_ISR_NOINTis removed in favor ofXN_ISR_HANDLEDwhich is now non-zero.
Actually, at first I wanted to make it just the other way about.Quoted 6 lines
Quoted 2 lines
Hmm, thinking about this again, I would like to revert my suggestion in favour of a third approach (trying to keep you busy ;) ).
Ok, you are wellcome :)
I didn't get it, at least while looking briefly. To make it a bit
easier, at
Quoted 5 lines
least for me, let's go another way.
At the left is the list of allowed values as Philippe pointed out. At the right is another list which corresponds to the left one but when NOINT is used instead of HANDLED. Moreover, I have added another case -
pure
Quoted 10 lines
NOINT. The ISR says it's not mine and, well, it doesn't know whether it should be propagated or no
(ok, so far CHAINED standed for NOINT).1.) HANDLED -> 0
2.) HANDLED | ENABLE -> ENABLE 3.) HANDLED | CHAINED -> CHAINED4.) CHAINED -> CHAINED | NOINT
5.) -> NOINTQuoted 3 lines
Quoted 2 lines
Could you provide the 3-d corresponding table using your new flags?
Still not 3D, but hopefully clarifying: :)
1.)
XN_ISR_HANDLED|XN_ISR_NO_ENABLE
Quoted 8 lines
Quoted 5 lines
2.)
XN_ISR_HANDLED
3.)XN_ISR_HANDLED|XN_ISR_PROPAGATE
(nucleus ignores implicit IRQ enable)
4.)XN_ISR_NOINT|XN_ISR_PROPAGATE
5.)XN_ISR_NOINTThen why do we need
XN_ISR_NOINT? is it not just the same as ~HANDLED?
The idea is to have at least a define so that
a) users explicitly have to state what they mean
b) we can map the define to some other value whenever we may need this in the future
The first property could even be used to apply some debug checks in the user's return value.
Quoted 6 lines
Moreover, I tend to think now that PROPAGATE (CHAINED) should not be normally used by ISRs at all. The only exception would be irq sharing between RT and non-RT domains, but that's of no concern for most part of rt drivers and, as last events revealed, it's very partially supported at the moment and possible implementations are quite arguable.
Ack. But you should still export this feature for those who think they know what they are doing. ;)
Quoted 6 lines
So HANDLED means the irq line is .end-ed by
xnintr_irq_handler()(xnarch_end_irq(irq)is called).If one wants to do it on his own later, NOENABLE can be returned additionally.
Yep. So let's call it XN_ISR_NOENABLE.
Quoted 2 lines
But then, one must use
xnintr_end_irq()and not justxnintr_irq_enable().
Yep, but a different (add-on) topic.
Quoted 13 lines
If
xnintr_end_irq()would be always the same asxnintr_irq_enable()or we would decouple ending and enabling operations on the line (don't have sources at hand); we could go Linux way and make use of a "nested" counter inxnintr_t, so thatxnintr_irq_disable()could be called in a nested way. This said, callingxnintr_irq_disable()in ISR leads to the interrupt line being still disabled upon return fromxnintr_irq_handler()and re-enabled again by the user later.~HANDLED means the ISR was not concerned about this interrupt. i.e. :
- there is ISR in another domain (down the pipeline) which is interested in this irq ;
Quoted 8 lines
well, the designer of the system should be aware of such cases and
probably avoid that on hw layer or, at least, to know what she is doing.- this is a spurious irq.
So upon getting ~HANDLED,
xnintr_irq_handler()does :success =
xnintr_irq_chained(irq);
Only if requested via XN_ISR_PROPAGATE (or _CHAINED)! There is still a real-time ISR registered on that IRQ you are about to forward now, and you don't know if someone is handling it down the pipeline. Actually, this is a fatal situation. The system is broken, bail out, and switch this line off.
Quoted 29 lines
if (success)
{
/* i.e. another domain is really interested and got this irq as pending*/return without .end-ing
}
else
{
/* this is a spurious irq */make use of some accounting of spurious interrupts (if we need it)), i.e. keep the irq line disabled if the % of unhandled requests > some limit.
otherwise
xnintr_end_irq()and return
}too long :) ok, it's quite similar indeed to what you have suggested, with the exception that
- no need for NOINT (if it's really == ~HANDLED);
- nucleus provides some additional logic while handling ~HANDLED case.
- user don't need to return ENABLE explicitly - in most cases, that's what he actually needs but sometimes just forgets (I recall a few questions on the mailing list about "only one interrupt".
Quoted 6 lines
Jan
Quoted 1 line
--
Best regards,
Dmitry Adamushko
Jan
Hi Jan,
let's make yet another revision of the bits :
new XN_ISR_HANDLED == old XN_ISR_HANDLED + old XN_ISR_NO_ENABLE
ok.
new XN_ISR_NOENABLE == ~ old XN_ISR_ENABLE
ok.
new XN_ISR_PROPAGATE == XN_ISR_CHAINED
ok.
new XN_ISR_NOINT == ?
does it suppose the interrupt line to be .end-ed (enabled) and irq not to be propagated? Should be so, I guess, if it's different from 5). Then nucleus ignores implicit IRQ enable for 5) as well as for 3).
Do we really need that NOINT then, as it seems to be the same as ~HANDLED?
or NOINT == 0 and then it's a scalar value, not a bit.
So one may consider HANDLED == 1 and NOINT == 0 as really scalar values
and
NOENABLE and PROPAGATE as additional bits (used only if needed).
--
Best regards,
Dmitry Adamushko
Hi Dmitry,
Quoted 8 lines · Dmitry Adamushko
Hi Jan,
let's make yet another revision of the bits :
new
XN_ISR_HANDLED== oldXN_ISR_HANDLED+ oldXN_ISR_NO_ENABLEok.
Quoted 8 lines
new
XN_ISR_NOENABLE== ~ oldXN_ISR_ENABLEok.
new
XN_ISR_PROPAGATE==XN_ISR_CHAINEDok.
Just to make sure that you understand my weird ideas: each of the three new XN_ISR_xxx above should be encoded with an individual bit
Quoted 8 lines
new
XN_ISR_NOINT== ?does it suppose the interrupt line to be .end-ed (enabled) and irq not to be propagated? Should be so, I guess, if it's different from 5). Then nucleus ignores implicit IRQ enable for 5) as well as for 3).
Do we really need that NOINT then, as it seems to be the same as ~HANDLED?
Quoted 8 lines
or NOINT == 0 and then it's a scalar value, not a bit.
So one may consider HANDLED == 1 and NOINT == 0 as really scalar values
and
NOENABLE and PROPAGATE as additional bits (used only if needed).
My idea is to urge the user specifying one of the base return types (HANDLED or NOINT) + any of the two additional bits (NOENABLE and PROPAGATE).
For correct drivers NOINT could be 0 indeed, but to check that the user picked a new constant we may want to set NOINT != 0. With the old API "return 0" expressed HANDLED + ~ENABLE for the old API. With the new one the user signals no interest and the nucleus may raise a warning that a spurious IRQ occurred. So I would add a debug bit for NOINT here to optionally (on OPT_XENO_DEBUG) detect old-style usage (return 0). Moreover, we gain freedom to move bits in the future when every state is encoded via constants. Or am I too paranoid here?
Jan
Quoted 48 lines · Jan Kiszka
Hi Dmitry,
Quoted 8 lines · Dmitry Adamushko
Hi Jan,
let's make yet another revision of the bits :
new
XN_ISR_HANDLED== oldXN_ISR_HANDLED+ oldXN_ISR_NO_ENABLEok.
Quoted 8 lines
new
XN_ISR_NOENABLE== ~ oldXN_ISR_ENABLEok.
new
XN_ISR_PROPAGATE==XN_ISR_CHAINEDok.
Just to make sure that you understand my weird ideas: each of the three new
XN_ISR_xxxabove should be encoded with an individual bitQuoted 8 lines
new
XN_ISR_NOINT== ?does it suppose the interrupt line to be .end-ed (enabled) and irq not to be propagated? Should be so, I guess, if it's different from 5). Then nucleus ignores implicit IRQ enable for 5) as well as for 3).
Do we really need that NOINT then, as it seems to be the same as ~HANDLED?
Quoted 8 lines
or NOINT == 0 and then it's a scalar value, not a bit.
So one may consider HANDLED == 1 and NOINT == 0 as really scalar values
and
NOENABLE and PROPAGATE as additional bits (used only if needed).
My idea is to urge the user specifying one of the base return types (HANDLED or NOINT) + any of the two additional bits (NOENABLE and PROPAGATE).
Quoted 8 lines
For correct drivers NOINT could be 0 indeed, but to check that the user picked a new constant we may want to set NOINT != 0. With the old API "return 0" expressed HANDLED + ~ENABLE for the old API. With the new one the user signals no interest and the nucleus may raise a warning that a spurious IRQ occurred. So I would add a debug bit for NOINT here to optionally (on
OPT_XENO_DEBUG) detect old-style usage (return 0). Moreover, we gain freedom to move bits in the future when every state is encoded via constants. Or am I too paranoid here?
After reading the above discussion (of which I understand very little), and looking at (what I believe to be) the relevant code:
+ intr = shirq->handlers;
+
+ while (intr)
+ {
+ s |= intr->isr(intr);
+ ++intr->hits;
+ intr = intr->next;
+ }+ xnintr_shirq_unlock(shirq);
+
+ --sched->inesting;
+
+ if (s & XN_ISR_ENABLE)
+ xnarch_end_irq(irq);
+ else if (s & XN_ISR_CHAINED)
+ xnarch_chain_irq(irq);
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted, returns NOENABLE|HANDLED and another return only HANDLED?
2. What happens if one returns PROPAGATE and another returns HANDLED?
As far as I can tell, after all RT handlers havve run, the following scenarios are possible:
1. The interrupt is deasserted (i.e. it was a RT interrupt)
2. The interrupt is still asserted, it will be deasserted later by some RT task (i.e. it was a RT interrupt)
3. The interrupt is still asserted and will be deasserted by the Linux IRQ handler.
IMHO that leads to the conclusion that the IRQ handlers should return a scalar
#define UNHANDLED 0
#define HANDLED_ENABLE 1
#define HANDLED_NOENABLE 2
#define PROPAGATE 3
and the loop should be
s = UNHANDLED
while (intr) {
tmp = intr->isr(intr);
if (tmp > s) { s = tmp; }
intr = intr->next;
}
if (s == PROPAGATE) {
xnarch_chain_irq(irq);
} else if (s == HANDLED_ENABLE) {
xnarch_end_irq(irq);
}To be really honest, I think that PROPAGATE should be excluded from the RT IRQ-handlers, since with the current scheme all RT-handlers has to test if the IRQ was a Linux interrupt (otherwise the system will only work when the handler that returns PROPAGATE is installed)
Signature · 1 line
Anders
N.B. Amongst other things, some thoughts about CHAINED with shared interrupts.
Quoted 7 lines · Anders Blomdell
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted,
returns NOENABLE|HANDLED and another return only HANDLED?2. What happens if one returns PROPAGATE and another returns HANDLED?
Yep, each ISR may return a different value and all of them are accumulated in the "s" variable ( s |= intr->isr(intr); ).
So the loop may end up with "s" which contains all of the possible bits:
(e.g.
isr1 - HANDLED | ENABLE
isr2 - HANDLED (don't want the irq to be enabled)
isr3 - CHAINED
)
s = HANDLED | ENABLE | CHAINED;
Then CHAINED will be ignored because of the following code :
+ if (s & XN_ISR_ENABLE)
+ xnarch_end_irq(irq);
+ else if (s & XN_ISR_CHAINED) (*)
+ xnarch_chain_irq(irq);
the current code in the CVS doen not contain "else" in (*), so that ENABLE | CHAINED is possible, though it's a wrong combination.
This said, we suppose that one knows what he is doing.
In the case of a single ISR per line, it's not that difficult to achieve. But if there are a few ISRs, then one should analize and take into account all possible return values of all the ISRs, as each of them may affect others (e.g. if one returns CHAINED when another - HANDLED | ENABLE).
So my feeling is that CHAINED should not be used by drivers which registered their ISRs as SHARED.
Moreover, I actually see the only scenario of CHAINED (I provided it before) :
all ISRs in the primary domain have reported UNHANDLED => nucleus propagates the interrupt down the pipeline with xnacrh_chain_irq(). This call actually returns 1 upon successful propagation (some domain down the pipeline was interested in this irq) and 0 otherwise.
Upon 0, this is a spurious irq (none of domains was interested in its handling).
ok, let's suppose now :
we have 2 ISRs on the same shared line :
isr1 : HANDLED (will be enabled by rt task. Note, rt task must call xnarch_end_irq() and not just xnarch_enable_irq()! )
isr2 : CHAINED
So HANDLED | CHAINED is ok for the single ISR on the line, but it may lead to HANDLED | CHAINED | ENABLE in a case of the shared line.
rt task that works jointly with isr1 just calls xnarch_end_irq() at some moment of time and some ISR in the linux domain does the same later => the line is .end-ed 2 times.
ISR should never return CHAINED as to indicate _only_ that it is not interested in this irq, but ~HANDLED or NOINT (if we'll support it) instead.
If the ISR nevertheless wants to propagate the IRQ to the Linux domain _explicitly_, it _must not_ register itself as SHARED, i.e. it _must_ be the only ISR on this line, otherwise that may lead to the IRQ line being .end-ed twice (lost interrupts in some cases).
#define UNHANDLED 0
Quoted 3 lines
#define
HANDLED_ENABLE1
#defineHANDLED_NOENABLE2
#define PROPAGATE 3
Yep, I'd agree with you. Moreover, PROPAGATE should not be used for shared interrupts.
--
Best regards,
Dmitry Adamushko
Quoted 34 lines · Dmitry Adamushko
N.B. Amongst other things, some thoughts about CHAINED with shared interrupts.
Quoted 7 lines · Anders Blomdell
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted,
returns NOENABLE|HANDLED and another return only HANDLED?2. What happens if one returns PROPAGATE and another returns HANDLED?
Yep, each ISR may return a different value and all of them are accumulated in the "s" variable ( s |=
intr->isr(intr); ).So the loop may end up with "s" which contains all of the possible bits:
(e.g.
isr1 - HANDLED | ENABLE
isr2 - HANDLED (don't want the irq to be enabled)
isr3 - CHAINED)
s = HANDLED | ENABLE | CHAINED;
Then CHAINED will be ignored because of the following code :
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (s & XN_ISR_ENABLE) + xnarch_end_irq(irq); + else if (s & XN_ISR_CHAINED) (*) + xnarch_chain_irq(irq);
Which may actually be fatal: consider one ISR intentionally not handling an IRQ but propagating it while another ISR thinks it has to re-enable it - bang! Anders' as well as my original suggestion were to ignore the ENABLE in this case.
Quoted 6 lines
the current code in the CVS doen not contain "else" in (*), so that ENABLE | CHAINED is possible, though it's a wrong combination.
This said, we suppose that one knows what he is doing.
Quoted 7 lines
In the case of a single ISR per line, it's not that difficult to achieve. But if there are a few ISRs, then one should analize and take into account all possible return values of all the ISRs, as each of them may affect others (e.g. if one returns CHAINED when another - HANDLED | ENABLE).
So my feeling is that CHAINED should not be used by drivers which registered their ISRs as SHARED.
That's true for standard drivers, but we should not prevent special corner-case designs which can be tuned to make even shared RT-IRQs + propagation possible. Sharing does not necessarily mean that different RT drivers are involved...
Quoted 8 lines
Moreover, I actually see the only scenario of CHAINED (I provided it before) :
all ISRs in the primary domain have reported UNHANDLED => nucleus propagates the interrupt down the pipeline with
xnacrh_chain_irq(). This call actually returns 1 upon successful propagation (some domain down the pipeline was interested in this irq) and 0 otherwise.
But this only means that some handler is registered down there, it cannot predict if that handler will actually care about the event.
Quoted 35 lines
Upon 0, this is a spurious irq (none of domains was interested in its handling).
ok, let's suppose now :
we have 2 ISRs on the same shared line :
isr1 : HANDLED (will be enabled by rt task. Note, rt task must call
xnarch_end_irq()and not justxnarch_enable_irq()! )isr2 : CHAINED
So HANDLED | CHAINED is ok for the single ISR on the line, but it may lead to HANDLED | CHAINED | ENABLE in a case of the shared line.
rt task that works jointly with isr1 just calls
xnarch_end_irq()at some moment of time and some ISR in the linux domain does the same later => the line is .end-ed 2 times.ISR should never return CHAINED as to indicate _only_ that it is not interested in this irq, but ~HANDLED or NOINT (if we'll support it) instead.
If the ISR nevertheless wants to propagate the IRQ to the Linux domain _explicitly_, it
_mustnot_register itself as SHARED, i.e. it _must_ be the only ISR on this line, otherwise that may lead to the IRQ line being .end-ed twice (lost interrupts in some cases).#define UNHANDLED 0
Quoted 3 lines
#define
HANDLED_ENABLE1
#defineHANDLED_NOENABLE2
#define PROPAGATE 3
Quoted 8 lines
Yep, I'd agree with you. Moreover, PROPAGATE should not be used for shared interrupts.
--
Best regards,
Dmitry Adamushko
Jan
Quoted 60 lines · Jan Kiszka
Quoted 34 lines · Dmitry Adamushko
N.B. Amongst other things, some thoughts about CHAINED with shared interrupts.
Quoted 7 lines · Anders Blomdell
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted,
returns NOENABLE|HANDLED and another return only HANDLED?2. What happens if one returns PROPAGATE and another returns HANDLED?
Yep, each ISR may return a different value and all of them are accumulated in the "s" variable ( s |=
intr->isr(intr); ).So the loop may end up with "s" which contains all of the possible bits:
(e.g.
isr1 - HANDLED | ENABLE
isr2 - HANDLED (don't want the irq to be enabled)
isr3 - CHAINED)
s = HANDLED | ENABLE | CHAINED;
Then CHAINED will be ignored because of the following code :
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (s & XN_ISR_ENABLE) + xnarch_end_irq(irq); + else if (s & XN_ISR_CHAINED) (*) + xnarch_chain_irq(irq);Which may actually be fatal: consider one ISR intentionally not handling an IRQ but propagating it while another ISR thinks it has to re-enable it - bang! Anders' as well as my original suggestion were to ignore the ENABLE in this case.
Quoted 2 lines
the current code in the CVS doen not contain "else" in (*), so that
ENABLE |
Quoted 5 lines
CHAINED is possible, though it's a wrong combination.
This said, we suppose that one knows what he is doing.
In the case of a single ISR per line, it's not that difficult to
achieve.
Quoted 1 line
But if there are a few ISRs, then one should analize and take into
account
Quoted 3 lines
all possible return values of all the ISRs, as each of them may affect others (e.g. if one returns CHAINED when another - HANDLED | ENABLE).
Quoted 8 lines
Quoted 1 line
So my feeling is that CHAINED should not be used by drivers which
registered
Quoted 1 line
their ISRs as SHARED.
That's true for standard drivers, but we should not prevent special corner-case designs which can be tuned to make even shared RT-IRQs + propagation possible. Sharing does not necessarily mean that different RT drivers are involved...
Yep. But in this case the designer of the system should _care_ about all corners of the system, i.e. to make sure that all ISRs return values which are not contradictory to each other.
e.g.
1)
isr1 : HANDLED (keep disabled)
isr2 : CHAINED
or
2)
isr1 : HANDLED | NOENABLE (will be enabled by rt_task1) isr2 : HANDLED | NOENABLE (-//- by rt_task2)
1) and 2) are wrong! Both lead to the IRQ line being .end-ed (xnarch_end_irq()) twice! And on some archs, as we have seen before, that may lead to lost interrupts.
Of course, when designing the real-time system, one should take charge of all corners of the system, so that analyzing the possible return values of all other ISRs that may share the same IRQ line is not anything extravagant, but a requirement.
This said, I see no reason then why we should prevent users from some cases (like CHAINED | ENABLE) and let him do the ones like 2).
2) is much more common scenario for irq sharing and looks sane from the point of view of a separate ISR, when the global picture (and nucleus innards) is not taken into account.
p.s.
my 2) is equal to 2 ISRs returning HANDLED_NOENABLE in terms of Anders. This case is one of the most common with shared interrupts which I would imagine. And it nevertheless leads to problems when the whole picture is not taken into account by the designer of a given ISR.
Quoted 2 lines
Moreover, I actually see the only scenario of CHAINED (I provided it
before)
Quoted 10 lines
:
all ISRs in the primary domain have reported UNHANDLED => nucleus propagates the interrupt down the pipeline with
xnacrh_chain_irq(). This call actually returns 1 upon successful propagation (some domain down the pipeline was interested in this irq) and 0 otherwise.But this only means that some handler is registered down there, it
cannot predict if that handler will actually care about the event.
Linux (not only vanilla, but ipipe-aware too) always .end-s (calls desc->handler->end(irq)) on return from __do_IRQ(), no matter this interrupt was handled by some ISR or not. It also re-enables the IRQ line if it was not disabled by some ISR explicitly.
We don't care about anything else.
Quoted 4 lines
Jan
--
Best regards,
Dmitry Adamushko
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 62 lines · Anders Blomdell
Quoted 10 lines · Dmitry Adamushko
N.B. Amongst other things, some thoughts about CHAINED with shared interrupts.
On 20/02/06, *Anders Blomdell* <[email protected] <mailto:[email protected]>> wrote:
Quoted 7 lines
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted,
returns NOENABLE|HANDLED and another return only HANDLED?2. What happens if one returns PROPAGATE and another returns
HANDLED?
Quoted 19 lines
Yep, each ISR may return a different value and all of them are accumulated in the "s" variable ( s |=
intr->isr(intr); ).So the loop may end up with "s" which contains all of the possible bits:
(e.g.
isr1 - HANDLED | ENABLE
isr2 - HANDLED (don't want the irq to be enabled)
isr3 - CHAINED)
s = HANDLED | ENABLE | CHAINED;
Then CHAINED will be ignored because of the following code :
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (s & XN_ISR_ENABLE) + xnarch_end_irq(irq); + else if (s & XN_ISR_CHAINED) (*) + xnarch_chain_irq(irq);Which is the worst way possible of prioritizing them, if a Linux interrupt is
active when we get there with ENABLE|CHAINED, interrupts will be enabled with
the Linux interrupt still asserted -> the IRQ-handlers will be called once more,
probably returning ENABLE|CHAINED again -> infinite loop...Quoted 11 lines
the current code in the CVS doen not contain "else" in (*), so that ENABLE | CHAINED is possible, though it's a wrong combination.
This said, we suppose that one knows what he is doing.
In the case of a single ISR per line, it's not that difficult to achieve. But if there are a few ISRs, then one should analize and take into account all possible return values of all the ISRs, as each of them may affect others (e.g. if one returns CHAINED when another - HANDLED | ENABLE).
Quoted 6 lines
Which is somewhat contrary to the concept of shared interrupts, if we have to
take care of the global picture, why make them shared in the first place? (I like the concept of shared interrupts, but it is important that the framework
gives a separation of concerns)
Unfortunately, it looks to me that the current picture (even with your scalar values) requires from the user who develops a given IRQ to take into account the possible return values of other ISRs.
As I pointed out, the situation when 2 ISRs return HANDLED_NOENABLE may lead to problems on some archs.
---
Quoted 1 line
...
I'll take a look at the rest of the message a bit later.
--
Best regards,
Dmitry Adamushko
Quoted 80 lines · Dmitry Adamushko
On 21/02/06, *Anders Blomdell* <[email protected] <mailto:[email protected]>> wrote:
Dmitry Adamushko wrote: > > N.B. Amongst other things, some thoughts about CHAINED with shared > interrupts. > > > On 20/02/06, *Anders Blomdell* < [email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>> wrote: > > > > A number of questions arise: > > 1. What happens if one of the shared handlers leaves the interrupt > asserted, > returns NOENABLE|HANDLED and another return only HANDLED? > > 2. What happens if one returns PROPAGATE and another returns HANDLED? > > > Yep, each ISR may return a different value and all of them are > accumulated in the "s" variable ( s |= intr->isr(intr); ). > > So the loop may end up with "s" which contains all of the possible bits: > > (e.g. > > isr1 - HANDLED | ENABLE > isr2 - HANDLED (don't want the irq to be enabled) > isr3 - CHAINED > > ) > > s = HANDLED | ENABLE | CHAINED; > > Then CHAINED will be ignored because of the following code : > > + if (s & XN_ISR_ENABLE) > + xnarch_end_irq(irq); > + else if (s & XN_ISR_CHAINED) (*) > + xnarch_chain_irq(irq); Which is the worst way possible of prioritizing them, if a Linux interrupt is active when we get there with ENABLE|CHAINED, interrupts will be enabled with the Linux interrupt still asserted -> the IRQ-handlers will be called once more, probably returning ENABLE|CHAINED again -> infinite loop... > > the current code in the CVS doen not contain "else" in (*), so that > ENABLE | CHAINED is possible, though it's a wrong combination. > > This said, we suppose that one knows what he is doing. > > In the case of a single ISR per line, it's not that difficult to > achieve. But if there are a few ISRs, then one should analize and take > into account all possible return values of all the ISRs, as each of them > may affect others (e.g. if one returns CHAINED when another - HANDLED | > ENABLE). Which is somewhat contrary to the concept of shared interrupts, if we have to take care of the global picture, why make them shared in the first place? (I like the concept of shared interrupts, but it is important that the framework gives a separation of concerns)
Quoted 3 lines
Unfortunately, it looks to me that the current picture (even with your scalar values) requires from the user who develops a given IRQ to take into account the possible return values of other ISRs.
As I pointed out, the situation when 2 ISRs return
HANDLED_NOENABLEmay lead to problems on some archs.
Good point, leaves us with 2 possible return values for shared handlers:
HANDLED
NOT_HANDLED
i.e. shared handlers should never defer the end'ing of the interrupt (which makes sense, since this would affect the other [shared] handlers).
Signature · 1 line
Anders
Quoted 89 lines · Anders Blomdell
Quoted 82 lines · Dmitry Adamushko
On 21/02/06, *Anders Blomdell* <[email protected] <mailto:[email protected]>> wrote:
Dmitry Adamushko wrote: > > N.B. Amongst other things, some thoughts about CHAINED with shared > interrupts. > > > On 20/02/06, *Anders Blomdell* < [email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>> wrote: > > > > A number of questions arise: > > 1. What happens if one of the shared handlers leaves the interrupt > asserted, > returns NOENABLE|HANDLED and another return only HANDLED? > > 2. What happens if one returns PROPAGATE and another returns HANDLED? > > > Yep, each ISR may return a different value and all of them are > accumulated in the "s" variable ( s |= intr->isr(intr); ). > > So the loop may end up with "s" which contains all of the possible bits: > > (e.g. > > isr1 - HANDLED | ENABLE > isr2 - HANDLED (don't want the irq to be enabled) > isr3 - CHAINED > > ) > > s = HANDLED | ENABLE | CHAINED; > > Then CHAINED will be ignored because of the following code : > > + if (s & XN_ISR_ENABLE) > + xnarch_end_irq(irq); > + else if (s & XN_ISR_CHAINED) (*) > + xnarch_chain_irq(irq); Which is the worst way possible of prioritizing them, if a Linux interrupt is active when we get there with ENABLE|CHAINED, interrupts will be enabled with the Linux interrupt still asserted -> the IRQ-handlers will be called once more, probably returning ENABLE|CHAINED again -> infinite loop... > > the current code in the CVS doen not contain "else" in (*), sothat
> ENABLE | CHAINED is possible, though it's a wrong combination. >
> This said, we suppose that one knows what he is doing. >
> In the case of a single ISR per line, it's not that difficult to > achieve. But if there are a few ISRs, then one should analize and
take
> into account all possible return values of all the ISRs, as each
of them
> may affect others (e.g. if one returns CHAINED when another -
HANDLED |
> ENABLE).
Which is somewhat contrary to the concept of shared interrupts, if we have to
take care of the global picture, why make them shared in the first place?
(I like the concept of shared interrupts, but it is important that the framework
gives a separation of concerns)Quoted 6 lines
Unfortunately, it looks to me that the current picture (even with your scalar values) requires from the user who develops a given IRQ to take into account the possible return values of other ISRs.
As I pointed out, the situation when 2 ISRs return
HANDLED_NOENABLEmay lead to problems on some archs.
Quoted 8 lines
Good point, leaves us with 2 possible return values for shared handlers:
HANDLED
NOT_HANDLEDi.e. shared handlers should never defer the end'ing of the interrupt (which makes sense, since this would affect the other [shared] handlers).
Yes, "should". And this "should" is best be handled by
a) Documenting the potential conflict in the same place when describing the return values
b) Placing some debug warning in the nucleus' IRQ trampoline function to bail out (once per line) when running into such situation
But I'm against any further runtime restrictions, especially as most drivers will never return anything else than NOT_HANDLED or HANDLED. Actually, this was the reason why I tried to separate the NO_ENABLE and PROPAGATE features as *additional* bits from HANDLED and NOT_HANDLED/UNHANDLED/NOINT. But I acknowledge that having all valid bit combination present as constants can be more helpful for the user. We just have to draw some line between the standard values and the additional gurus return codes (documentation: "don't use NO_ENABLE or PROPAGATE unless you understand their side-effects and pitfalls precisely").
Jan
Quoted 6 lines
Good point, leaves us with 2 possible return values for shared handlers:
HANDLED
NOT_HANDLEDi.e. shared handlers should never defer the end'ing of the interrupt
(which
Quoted 1 line
makes sense, since this would affect the other [shared] handlers).
HANDLED_NOEBNABLE could be supported too. There would be no need in reenventing
a wheel, just do it the way Linux does it.
But it's about some additional re-designing of the current codebase (e.g. nested calling for irq_enable/disable())
I'm not sure we do need it for something else rather than irq sharing code but it affects the rest of the code.
And we have a kind of wrong concept :
XN_ISR_ENABLE (or NOENABLE) corresponds to xnarch_end_irq().
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support HANDLED_NOENABLE properly, those 2 have to be decoupled, i.e. EOI should always be sent from xnintr_shirq_handler().
Quoted 8 lines
Yes, "should". And this "should" is best be handled by
a) Documenting the potential conflict in the same place when describing the return values
b) Placing some debug warning in the nucleus' IRQ trampoline function to bail out (once per line) when running into such situation
Quoted 9 lines
But I'm against any further runtime restrictions, especially as most drivers will never return anything else than
NOT_HANDLEDor HANDLED. Actually, this was the reason why I tried to separate theNO_ENABLEand PROPAGATE features as *additional* bits from HANDLED and NOT_HANDLED/UNHANDLED/NOINT. But I acknowledge that having all valid bit combination present as constants can be more helpful for the user. We just have to draw some line between the standard values and the additional gurus return codes
(documentation: "don't use NO_ENABLE or
Quoted 1 line
PROPAGATE unless you understand their side-effects and pitfalls
precisely").
I agree with you on PROPAGATE case, but NO_ENABLE that, as pointed out above,
should (IMHO and at least, in theory) only mean "keep the IRQ line disabled" (and have nothing to do with .end-ing the IRQ line) would be better supported.
But this is, again as was pointed out above, about some redesigning of the current code => some overhead that likely affects non-shared aware code too.
So on one hand,
I'm ready to re-work code with :
HANDLED and UNHANDLED (or NOINT)
+ 2 additional bits : NOENABLE and PROPAGATE.
and document it like you suggested "don't use NO_ENABLE or PROPAGATE with shared interrupts
unless you understand their side-effects and pitfalls precisely";
on the other hand,
I'd say that I'm almost ready to vote against merging the irq sharing code at all as it looks to be a rather partial solution.
--
Best regards,
Dmitry Adamushko
Quoted 11 lines · Dmitry Adamushko
Quoted 7 lines
Good point, leaves us with 2 possible return values for shared handlers:
HANDLED
NOT_HANDLEDi.e. shared handlers should never defer the end'ing of the interrupt
(which
Quoted 1 line
makes sense, since this would affect the other [shared] handlers).
HANDLED_NOEBNABLEcould be supported too.
Yes, but it breaks decoupling between shared handlers; interrupts will be deferred for all [shared] handlers until it is properly ended.
Quoted 9 lines
There would be no need in reenventing
a wheel, just do it the way Linux does it.
But it's about some additional re-designing of the current codebase
(e.g. nested calling for irq_enable/disable())
I'm not sure we do need it for something else rather than irq sharing code but it affects the rest of the code.And we have a kind of wrong concept :
XN_ISR_ENABLE(or NOENABLE) corresponds toxnarch_end_irq().
Agree
Quoted 6 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e. EOI should always be sent fromxnintr_shirq_handler().
But the one returning HANDLED_NOENABLE is likely to leave the interrupt asserted, hence we can't EOI at this point (unless NO_ENABLE means DISABLE).
Quoted 37 lines
Quoted 9 lines
Yes, "should". And this "should" is best be handled by
a) Documenting the potential conflict in the same place when describing the return values
b) Placing some debug warning in the nucleus' IRQ trampoline function to bail out (once per line) when running into such situation
Quoted 9 lines
But I'm against any further runtime restrictions, especially as most drivers will never return anything else than
NOT_HANDLEDor HANDLED. Actually, this was the reason why I tried to separate theNO_ENABLEand PROPAGATE features as *additional* bits from HANDLED and NOT_HANDLED/UNHANDLED/NOINT. But I acknowledge that having all valid bit combination present as constants can be more helpful for the user. We just have to draw some line between the standard values and the additional gurus return codes(documentation: "don't use
NO_ENABLEorQuoted 1 line
PROPAGATE unless you understand their side-effects and pitfalls
precisely").
I agree with you on PROPAGATE case, but
NO_ENABLEthat, as pointed out above, should (IMHO and at least, in theory) only mean "keep the IRQ line disabled" (and have nothing to do with .end-ing the IRQ line) would be better supported. But this is, again as was pointed out above, about some redesigning of the current code => some overhead that likely affects non-shared aware code too.So on one hand,
I'm ready to re-work code with :
HANDLED and UNHANDLED (or NOINT)
+ 2 additional bits : NOENABLE and PROPAGATE.
Quoted 7 lines
and document it like you suggested "don't use
NO_ENABLEor PROPAGATE with shared interrupts
unless you understand their side-effects and pitfalls precisely";on the other hand,
I'd say that I'm almost ready to vote against merging the irq sharing code at all as it looks to be a rather partial solution.
I vote for (even though I'm the one who complains the most), BUT I think it is important to keep the rules for using it simple (that's why I worry about the plethora of return-flags).
Signature · 3 lines
Regards Anders
Quoted 32 lines · Anders Blomdell
Quoted 4 lines · Dmitry Adamushko
Quoted 2 lines
Good point, leaves us with 2 possible return values for shared
handlers:
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
HANDLED
NOT_HANDLEDi.e. shared handlers should never defer the end'ing of the
interrupt (which
Quoted 1 line
makes sense, since this would affect the other [shared] handlers).
HANDLED_NOEBNABLEcould be supported too.Yes, but it breaks decoupling between shared handlers; interrupts will be deferred for all [shared] handlers until it is properly ended.
Quoted 10 lines
There would be no need in reenventing
a wheel, just do it the way Linux does it.
But it's about some additional re-designing of the current codebase (e.g. nested calling for irq_enable/disable())
I'm not sure we do need it for something else rather than irq sharing code but it affects the rest of the code.And we have a kind of wrong concept :
XN_ISR_ENABLE(or NOENABLE) corresponds toxnarch_end_irq().Agree
Quoted 4 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
Quoted 6 lines
Quoted 3 lines
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).
I guess this is what Dmitry meant: explicitly call disable() if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks. But what about NOENABLE+PROPAGATE? Will this special case still mean NOT to end the ISR (as Linux will do)?
Bah, we are running in circles, I'm afraid. I think it's better to call NOENABLE NOEOI, which will indeed mean to not end this line (as it is the current situation anyway, isn't it?), and leave the user with what (s)he can do with such a feature. We found out that there are trillions of ways to shoot oneself into the foot with NOENABLE and PROPAGATE, and we cannot prevent most of them. So let's stop trying, at least for this patch!
Quoted 51 lines
Quoted 51 lines
Quoted 5 lines
Yes, "should". And this "should" is best be handled by
a) Documenting the potential conflict in the same place when
describing
Quoted 3 lines
the return values
b) Placing some debug warning in the nucleus' IRQ trampoline
function to
Quoted 5 lines
bail out (once per line) when running into such situation
But I'm against any further runtime restrictions, especially as most drivers will never return anything else than
NOT_HANDLEDor HANDLED. Actually, this was the reason why I tried to separate theNO_ENABLEand
Quoted 2 lines
PROPAGATE features as *additional* bits from HANDLED and NOT_HANDLED/UNHANDLED/NOINT. But I acknowledge that having all
valid bit
Quoted 4 lines
combination present as constants can be more helpful for the user. We just have to draw some line between the standard values and the additional gurus return codes
(documentation: "don't use
NO_ENABLEorQuoted 1 line
PROPAGATE unless you understand their side-effects and pitfalls
precisely").
I agree with you on PROPAGATE case, but
NO_ENABLEthat, as pointed out above,
should (IMHO and at least, in theory) only mean "keep the IRQ line disabled"
(and have nothing to do with .end-ing the IRQ line) would be better supported.
But this is, again as was pointed out above, about some redesigning of the
current code => some overhead that likely affects non-shared aware code too.So on one hand,
I'm ready to re-work code with :
HANDLED and UNHANDLED (or NOINT)
+ 2 additional bits : NOENABLE and PROPAGATE.
and document it like you suggested "don't use
NO_ENABLEor PROPAGATE with shared interrupts
unless you understand their side-effects and pitfalls precisely";
Quoted 8 lines
Quoted 4 lines
on the other hand,
I'd say that I'm almost ready to vote against merging the irq sharing code at all as it looks to be a rather partial solution.
I vote for (even though I'm the one who complains the most), BUT I think it is important to keep the rules for using it simple (that's why I worry about the plethora of return-flags).
And I'm with you here: My original proposal (2 base-states + 2 bits) created 8 expressible states while your version only knows 4 states - those which make sense most (and 2 of them are still the ones recommand for the masses).
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
Jan
Quoted 126 lines · Jan Kiszka
Quoted 35 lines · Anders Blomdell
Quoted 11 lines · Dmitry Adamushko
Quoted 1 line
Good point, leaves us with 2 possible return values for shared
handlers:
Quoted 5 lines
HANDLED
NOT_HANDLEDi.e. shared handlers should never defer the end'ing of the
interrupt (which
Quoted 1 line
makes sense, since this would affect the other [shared] handlers).
HANDLED_NOEBNABLEcould be supported too.Yes, but it breaks decoupling between shared handlers; interrupts will be deferred for all [shared] handlers until it is properly ended.
Quoted 10 lines
There would be no need in reenventing
a wheel, just do it the way Linux does it.
But it's about some additional re-designing of the current codebase (e.g. nested calling for irq_enable/disable())
I'm not sure we do need it for something else rather than irq sharing code but it affects the rest of the code.And we have a kind of wrong concept :
XN_ISR_ENABLE(or NOENABLE) corresponds toxnarch_end_irq().Agree
Quoted 3 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
Quoted 7 lines
Quoted 3 lines
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).I guess this is what Dmitry meant: explicitly call
disable()if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks. But what about NOENABLE+PROPAGATE? Will this special case still mean NOT to end the ISR (as Linux will do)?Bah, we are running in circles, I'm afraid. I think it's better to call NOENABLE NOEOI, which will indeed mean to not end this line (as it is the current situation anyway, isn't it?), and leave the user with what (s)he can do with such a feature. We found out that there are trillions of ways to shoot oneself into the foot with NOENABLE and PROPAGATE, and we cannot prevent most of them. So let's stop trying, at least for this patch!
Quoted 49 lines
Quoted 49 lines
Quoted 3 lines
Yes, "should". And this "should" is best be handled by
a) Documenting the potential conflict in the same place when
describing
Quoted 3 lines
the return values
b) Placing some debug warning in the nucleus' IRQ trampoline
function to
Quoted 5 lines
bail out (once per line) when running into such situation
But I'm against any further runtime restrictions, especially as most drivers will never return anything else than
NOT_HANDLEDor HANDLED. Actually, this was the reason why I tried to separate theNO_ENABLEand
Quoted 2 lines
PROPAGATE features as *additional* bits from HANDLED and NOT_HANDLED/UNHANDLED/NOINT. But I acknowledge that having all
valid bit
Quoted 4 lines
combination present as constants can be more helpful for the user. We just have to draw some line between the standard values and the additional gurus return codes
(documentation: "don't use
NO_ENABLEorQuoted 1 line
PROPAGATE unless you understand their side-effects and pitfalls
precisely").
I agree with you on PROPAGATE case, but
NO_ENABLEthat, as pointed out above,
should (IMHO and at least, in theory) only mean "keep the IRQ line disabled"
(and have nothing to do with .end-ing the IRQ line) would be better supported.
But this is, again as was pointed out above, about some redesigning of the
current code => some overhead that likely affects non-shared aware code too.So on one hand,
I'm ready to re-work code with :
HANDLED and UNHANDLED (or NOINT)
+ 2 additional bits : NOENABLE and PROPAGATE.
and document it like you suggested "don't use
NO_ENABLEor PROPAGATE with shared interrupts
unless you understand their side-effects and pitfalls precisely";Quoted 9 lines
Quoted 4 lines
on the other hand,
I'd say that I'm almost ready to vote against merging the irq sharing code at all as it looks to be a rather partial solution.
I vote for (even though I'm the one who complains the most), BUT I think it is important to keep the rules for using it simple (that's why I worry about the plethora of return-flags).
And I'm with you here: My original proposal (2 base-states + 2 bits) created 8 expressible states while your version only knows 4 states - those which make sense most (and 2 of them are still the ones recommand for the masses).
Quoted 4 lines
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
You have my vote for this.
Signature · 1 line
Anders
Quoted 4 lines
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
Good. Then let's go for
HANDLED, UNHANDLED - we may consider them even as 2 scalar values
+
NOENABLE, CHAINED - additional bits.
They are not encouraged to be used with shared interrupts (explained in docs + debug messages when XENO_OPT_DEBUG is on).
Any ISR on the shared irq line should "understand" that it's just one among the equals. That said, it should not do anything that may affect other ISRs and not require any special treatment (like CHAINED or NOENABLE).
If it wants it indeed, then don't declare itself as SHARED.
We may come back to the topic about possible return values of ISRs a bit later maybe having got more feedback (hm.. hopefully) on shared irq support.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().
Quoted 8 lines
Quoted 3 lines
But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).I guess this is what Dmitry meant: explicitly call
disable()if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks.
Almost.
Let's consider the following only as anorther way of doing some things; I don't propose to implement it, it's just to illustrate my thoughts. So one may simply ski-skip-skip it :o)
Let's keep in mind that what is behind .end-ing the IRQ line depends on archs.
Sometimes end == enable (EOI was sent on .ack step), while in other cases end == send_EOI [+ re-enabling].
But anyway, all ISRs are running with a given IRQ line disabled.
Supported values : HANDLED, UNHANDLED, PROPAGATE.
nucleus :: xnintr_irq_handler()
{
ret = 0;
...
for each isr in isr_list[ IRQ ]
{
temp = isr->handler();
if (temp > ret)
ret = temp;
}
if (ret == PROPAGATE)
{
// quite dengerous with shared interrupts, be sure you understand
// what you are doing!
xnarch_chain_irq(irq); // will be .end-ed in Linux domain
}
else
{
// HANDLED or UNHANDLED
xnarch_end_irq();
}
...}
ENABLE or NOENABLE is missing? Nop.
let's say we have 2 rt-ISRs :
isr1 : HANDLED
isr2 : HANDLED + WISH
WISH == I want the IRQ line remain disabled until later
(e.g. bottom half in rt_task will enable it)
How may isr2 express this WISH? Simply, xnarch_irq_disable/enable() should support an internal counter that allows them to be called in a nested way.
So e.g. if there are 2 consecutive calls to disable_irq(), then 2 calls to enable_irq() are needed to really enable the IRQ line.
This way, the WISH is only about directly calling xnarch_irq_disable() in isr2
and there is no need in ENABLE or NOENABLE flags.
This way, PROPAGATE really means NOEND - the IRQ will be .end-ed in Linux domain;
while WISH==NOENABLE - has nothing to do with sending EOI, but only with enabling/disabling the given IRQ line.
Yes, if one isr (or a few) defers the IRQ line enabling until later, it will affect
all others ISR => all interrupts are temporary not accepted on this line. This scenario is possible under Linux, but should be used with even more care in real-time system. At least, this way HANDLED_NOENABLE case works and doesn't lead to lost interrupts on some archs.
Moreover, it avoids the need for ENABLE flag even in non-shared interrupt case.
--
Best regards,
Dmitry Adamushko
Quoted 113 lines · Dmitry Adamushko
Quoted 5 lines
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
Good. Then let's go for
HANDLED, UNHANDLED - we may consider them even as 2 scalar values
+
NOENABLE, CHAINED - additional bits.
They are not encouraged to be used with shared interrupts (explained in docs + debug messages when
XENO_OPT_DEBUGis on).Any ISR on the shared irq line should "understand" that it's just one among the equals. That said, it should not do anything that may affect other ISRs and not require any special treatment (like CHAINED or NOENABLE).
If it wants it indeed, then don't declare itself as SHARED.We may come back to the topic about possible return values of ISRs a bit later maybe having got more feedback (hm.. hopefully) on shared irq support.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().Quoted 8 lines
Quoted 3 lines
But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).I guess this is what Dmitry meant: explicitly call
disable()if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks.Almost.
Let's consider the following only as anorther way of doing some things; I don't propose to implement it, it's just to illustrate my thoughts. So one may simply ski-skip-skip it :o)
Let's keep in mind that what is behind .end-ing the IRQ line depends on archs. Sometimes end == enable (EOI was sent on .ack step), while in other cases end ==
send_EOI[+ re-enabling].But anyway, all ISRs are running with a given IRQ line disabled.
Supported values : HANDLED, UNHANDLED, PROPAGATE.
nucleus ::
xnintr_irq_handler(){ ret = 0; ... for each isr in isr_list[ IRQ ] { temp = isr->handler(); if (temp > ret) ret = temp; } if (ret == PROPAGATE) { // quite dengerous with shared interrupts, be sure you understand // what you are doing! xnarch_chain_irq(irq); // will be .end-ed in Linux domain } else { // HANDLED or UNHANDLED xnarch_end_irq(); } ...}
ENABLE or NOENABLE is missing? Nop.
let's say we have 2 rt-ISRs :
isr1 : HANDLED
isr2 : HANDLED + WISHWISH == I want the IRQ line remain disabled until later
(e.g. bottom half inrt_taskwill enable it)How may isr2 express this WISH? Simply, xnarch_irq_disable/enable() should support an internal counter that allows them to be called in a nested way.
So e.g. if there are 2 consecutive calls to
disable_irq(), then 2 calls toenable_irq()are needed to really enable the IRQ line.This way, the WISH is only about directly calling
xnarch_irq_disable()in isr2 and there is no need in ENABLE or NOENABLE flags.This way, PROPAGATE really means NOEND - the IRQ will be .end-ed in Linux domain; while WISH==NOENABLE - has nothing to do with sending EOI, but only with enabling/disabling the given IRQ line.
Quoted 7 lines
Yes, if one isr (or a few) defers the IRQ line enabling until later, it will affect all others ISR => all interrupts are temporary not accepted on this line. This scenario is possible under Linux, but should be used with even more care in real-time system. At least, this way
HANDLED_NOENABLEcase works and doesn't lead to lost interrupts on some archs.Moreover, it avoids the need for ENABLE flag even in non-shared interrupt case.
Lokks clean enough to me, i.e. no objections...
Signature · 1 line
Anders
Quoted 8 lines · Dmitry Adamushko
Quoted 4 lines
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
Good. Then let's go for
HANDLED, UNHANDLED - we may consider them even as 2 scalar values
Ok, just avoid the 0.
Quoted 112 lines
+
NOENABLE, CHAINED - additional bits.
They are not encouraged to be used with shared interrupts (explained in docs + debug messages when
XENO_OPT_DEBUGis on).Any ISR on the shared irq line should "understand" that it's just one among the equals. That said, it should not do anything that may affect other ISRs and not require any special treatment (like CHAINED or NOENABLE).
If it wants it indeed, then don't declare itself as SHARED.We may come back to the topic about possible return values of ISRs a bit later maybe having got more feedback (hm.. hopefully) on shared irq support.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().Quoted 7 lines
Quoted 3 lines
But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).I guess this is what Dmitry meant: explicitly call
disable()if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks.Almost.
Let's consider the following only as anorther way of doing some things; I don't propose to implement it, it's just to illustrate my thoughts. So one may simply ski-skip-skip it :o)
Let's keep in mind that what is behind .end-ing the IRQ line depends on archs.
Sometimes end == enable (EOI was sent on .ack step), while in other cases end ==send_EOI[+ re-enabling].But anyway, all ISRs are running with a given IRQ line disabled.
Supported values : HANDLED, UNHANDLED, PROPAGATE.
nucleus ::
xnintr_irq_handler(){ ret = 0; ... for each isr in isr_list[ IRQ ] { temp = isr->handler(); if (temp > ret) ret = temp; } if (ret == PROPAGATE) { // quite dengerous with shared interrupts, be sure you understand // what you are doing! xnarch_chain_irq(irq); // will be .end-ed in Linux domain } else { // HANDLED or UNHANDLED xnarch_end_irq(); } ...}
ENABLE or NOENABLE is missing? Nop.
let's say we have 2 rt-ISRs :
isr1 : HANDLED
isr2 : HANDLED + WISHWISH == I want the IRQ line remain disabled until later
(e.g. bottom half inrt_taskwill enable it)How may isr2 express this WISH? Simply, xnarch_irq_disable/enable() should support an internal counter that allows them to be called in a nested way.
So e.g. if there are 2 consecutive calls to
disable_irq(), then 2 calls toenable_irq()are needed to really enable the IRQ line.This way, the WISH is only about directly calling
xnarch_irq_disable()in isr2
and there is no need in ENABLE or NOENABLE flags.This way, PROPAGATE really means NOEND - the IRQ will be .end-ed in Linux domain;
while WISH==NOENABLE - has nothing to do with sending EOI, but only with enabling/disabling the given IRQ line.Yes, if one isr (or a few) defers the IRQ line enabling until later, it will affect
all others ISR => all interrupts are temporary not accepted on this line. This scenario is possible under Linux, but should be used with even more care in real-time system. At least, this wayHANDLED_NOENABLEcase works and doesn't lead to lost interrupts on some archs.
Quoted 3 lines
Moreover, it avoids the need for ENABLE flag even in non-shared interrupt case.
Yep, really looks like this is the best way to go.
Jan
Quoted 113 lines · Dmitry Adamushko
Quoted 5 lines
For RTDM I'm now almost determined to rework the API in way that only HANDLED/UNHANDLED (or what ever their names will be) get exported, any additional guru features will remain excluded as long as we have no clean usage policy for them.
Good. Then let's go for
HANDLED, UNHANDLED - we may consider them even as 2 scalar values
+
NOENABLE, CHAINED - additional bits.
They are not encouraged to be used with shared interrupts (explained in docs + debug messages when
XENO_OPT_DEBUGis on).Any ISR on the shared irq line should "understand" that it's just one among the equals. That said, it should not do anything that may affect other ISRs and not require any special treatment (like CHAINED or NOENABLE).
If it wants it indeed, then don't declare itself as SHARED.We may come back to the topic about possible return values of ISRs a bit later maybe having got more feedback (hm.. hopefully) on shared irq support.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
But the later one is not only about enabling the line, but on some archs - about .end-ing it too (sending EOI).
And to support
HANDLED_NOENABLEproperly, those 2 have to be decoupled, i.e.
EOI should always be sent fromxnintr_shirq_handler().Quoted 8 lines
Quoted 3 lines
But the one returning
HANDLED_NOENABLEis likely to leave the interrupt asserted, hence we can't EOI at this point (unlessNO_ENABLEmeans DISABLE).I guess this is what Dmitry meant: explicitly call
disable()if one or more ISRs returned NOENABLE - at least on archs where end != enable. Will this work? We could then keep on using the existing IRQ-enable API from bottom-half IRQ tasks.Almost.
Let's consider the following only as anorther way of doing some things; I don't propose to implement it, it's just to illustrate my thoughts. So one may simply ski-skip-skip it :o)
Let's keep in mind that what is behind .end-ing the IRQ line depends on archs. Sometimes end == enable (EOI was sent on .ack step), while in other cases end ==
send_EOI[+ re-enabling].But anyway, all ISRs are running with a given IRQ line disabled.
Supported values : HANDLED, UNHANDLED, PROPAGATE.
nucleus ::
xnintr_irq_handler(){ ret = 0; ... for each isr in isr_list[ IRQ ] { temp = isr->handler(); if (temp > ret) ret = temp; } if (ret == PROPAGATE) { // quite dengerous with shared interrupts, be sure you understand // what you are doing! xnarch_chain_irq(irq); // will be .end-ed in Linux domain } else { // HANDLED or UNHANDLED xnarch_end_irq(); } ...}
ENABLE or NOENABLE is missing? Nop.
let's say we have 2 rt-ISRs :
isr1 : HANDLED
isr2 : HANDLED + WISHWISH == I want the IRQ line remain disabled until later
(e.g. bottom half inrt_taskwill enable it)How may isr2 express this WISH? Simply, xnarch_irq_disable/enable() should support an internal counter that allows them to be called in a nested way.
So e.g. if there are 2 consecutive calls to
disable_irq(), then 2 calls toenable_irq()are needed to really enable the IRQ line.This way, the WISH is only about directly calling
xnarch_irq_disable()in isr2 and there is no need in ENABLE or NOENABLE flags.This way, PROPAGATE really means NOEND - the IRQ will be .end-ed in Linux domain; while WISH==NOENABLE - has nothing to do with sending EOI, but only with enabling/disabling the given IRQ line.
Quoted 9 lines
Yes, if one isr (or a few) defers the IRQ line enabling until later, it will affect all others ISR => all interrupts are temporary not accepted on this line. This scenario is possible under Linux, but should be used with even more care in real-time system. At least, this way
HANDLED_NOENABLEcase works and doesn't lead to lost interrupts on some archs.Moreover, it avoids the need for ENABLE flag even in non-shared interrupt case.
Ok, general bottom line regarding IRQ support (and the rest):
1- we want the rules applicable to the common case to be simple, well-defined and straightforward. This applies to the ISR return value as exposed.
2- some requirements might fall outside of the common case; to support them, we need to refrain from imposing a strong policy, but only provide sound mechanisms to implement that. Specifically, let's keep the basic ability to control the Adeos pipelining from Xenomai intact.
3- however, let's be true to the good old UNIX way-of-life: there is no point in penalizing 99% of the common user base to please only 1% of them who happen to have very specific needs. E.g., don't slow down the fast path everyone takes, don't impose hard rules most of the users won't benefit from. [I'm not referring to the enable/disable nesting count here: this _is_ correct, and is currently missing -- this should be done at Xeno's arch-level, not from the HAL which should be kept the way it is to have a direct, unmoderated access to the PIC handling].
IOW, the patch, the way you discussed it recently, is ok for me too.
Signature · 1 line
Philippe.
Quoted 3 lines
Ok, general bottom line regarding IRQ support (and the rest):
1- we want the rules applicable to the common case to be simple,
well-defined and
Quoted 2 lines
straightforward. This applies to the ISR return value as exposed. 2- some requirements might fall outside of the common case; to support
them, we
Quoted 1 line
need to refrain from imposing a strong policy, but only provide sound
mechanisms
Quoted 1 line
to implement that. Specifically, let's keep the basic ability to control
the Adeos
Quoted 2 lines
pipelining from Xenomai intact.
3- however, let's be true to the good old UNIX way-of-life: there is no
point in
Quoted 1 line
penalizing 99% of the common user base to please only 1% of them who
happen to
Quoted 1 line
have very specific needs. E.g., don't slow down the fast path everyone
takes,
Quoted 1 line
don't impose hard rules most of the users won't benefit from.
Ack.
Quoted 2 lines
[I'm not referring
to the enable/disable nesting count here: this _is_ correct, and is
currently
Quoted 1 line
missing -- this should be done at Xeno's arch-level, not from the HAL
which should
Quoted 1 line
be kept the way it is to have a direct, unmoderated access to the PIC
handling].
Let's consider it a bit. The counter as well as XENO_IRQ_DISABLED bit (or something similar)
should be kept somewhere. So it's either xnintr_t or irq description in low-level
ipipe code; we just don't want to introduce new structures and probably it's better to implement this feature on Xeno layer, rather than on ipipe one.
Actually, xnintr_t is not visible from arch-level code.
In order to support nested calls of irq_enable/disable, we should take additional control
in all places where irq_desc[irq]->handler->enable/disable() are used (ok, hal interface
is out of the scope, but e.g. xnintr_enable() and xnintr_disable() must be modified
appropriately not to use this hal interface).
Another thing is xnarch_irq_end() which re-enables the IRQ line upon exitting from
interrupt handling code.
It must make check for DISABLED bit (ISR might have called xnintr_disable() to defer
the IRQ line enabling).
For most part of the archs supported by Xeno, .ending (xnarch_irq_end()) is only about
calling irq_desc[irq]->handler->enable()
(handler->end() is never used) so it's not a problem to make a small wrapper that re-enables the IRQ line only when XENO_IRQ_DISABLED bit is not set.
On ppc, irq_desc[irq]->handler->end() can be called indeed and we don't know what's all about - at least, on the Xeno layer.
So either
handler->end() must check for XENO_IRQ_DISABLED - but this is an arch-level code
in Linux (i.e. not the Xeno layer);
or Xeno/arch/ppc must represent an .end substitution for each sub-arch supported.
Quoted 1 line
IOW, the patch, the way you discussed it recently, is ok for me too.
This said, I'm going to publish the shirq patch (after finalizing ISR return bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.
--
Quoted 3 lines
Philippe.
--
Best regards,
Dmitry Adamushko
Quoted 6 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.
Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device> rtdm_irq_enable(...);
But I do not disable the IRQ before rtdm_irq_free() again. Is this unbalanced enabling still needed today? Is it even wrong these days? Is it arch-dependent? I think the pattern dates back in RTAI times and was needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Jan
Quoted 14 lines · Jan Kiszka
Quoted 6 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?
Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
I think the pattern dates back in RTAI times and was
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
Quoted 6 lines
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Jan
Signature · 1 line
Philippe.
Quoted 33 lines · Philippe Gerum
Quoted 15 lines · Jan Kiszka
Quoted 7 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return
bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
Quoted 9 lines
I think the pattern dates back in RTAI times and was
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
So the enable is definitely needed and a disable on release should not cause harm anymore? If that's the case, we could start re-introducing rtdm_irq_disable before rtdm_irq_free again.
Quoted 9 lines
Quoted 7 lines
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Jan
Jan
Quoted 50 lines · Jan Kiszka
Quoted 38 lines · Philippe Gerum
Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return
bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
I think the pattern dates back in RTAI times and was
Quoted 8 lines
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
Quoted 4 lines
So the enable is definitely needed and a disable on release should not cause harm anymore? If that's the case, we could start re-introducing
rtdm_irq_disablebeforertdm_irq_freeagain.
It should work that way.
Quoted 13 lines
Quoted 10 lines
Quoted 8 lines
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Jan
Jan
Signature · 1 line
Philippe.
Quoted 50 lines · Jan Kiszka
Quoted 38 lines · Philippe Gerum
Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return
bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
I think the pattern dates back in RTAI times and was
Quoted 8 lines
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
Quoted 3 lines
So the enable is definitely needed and a disable on release should not cause harm anymore? If that's the case, we could start re-introducing
rtdm_irq_disablebeforertdm_irq_freeagain.
Except for interrupts shared between RT/non-RT, the don't need enable (since they are enabled by Linux already), and probably doesn't fare well with a final disable.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Signature · 1 line
Anders
Quoted 53 lines · Anders Blomdell
Quoted 52 lines · Jan Kiszka
Quoted 48 lines · Philippe Gerum
Quoted 18 lines · Jan Kiszka
Quoted 9 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return
bits,
where I still have some doubts) without enable/disable nesting support.
It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
I think the pattern dates back in RTAI times and was
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
Quoted 7 lines
Quoted 3 lines
So the enable is definitely needed and a disable on release should not cause harm anymore? If that's the case, we could start re-introducing
rtdm_irq_disablebeforertdm_irq_freeagain.Except for interrupts shared between RT/non-RT, the don't need enable (since they are enabled by Linux already), and probably doesn't fare well with a final disable.
This does not apply to the drivers I have in mind (e.g. RTnet NIC drivers). None of them is prepared to share the IRQ line with Linux. There is only the scenario that a Linux driver for the same hardware gets loaded later after removing the RT driver (e.g. switching from RTnet to standard Linux networking).
Anyway, before changing anything here we need some tests - and counting enable/disable. Otherwise, we will already run into troubles with shared RT-IRQs.
Jan
Quoted 54 lines · Anders Blomdell
Quoted 52 lines · Jan Kiszka
Quoted 48 lines · Philippe Gerum
Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Dmitry Adamushko
...
This said, I'm going to publish the shirq patch (after finalizing ISR return
bits,
where I still have some doubts) without enable/disable nesting support. It can be supported at some point of time later, if it's really needed.Regarding enable/disable nesting and existing driver patterns: I currently do the following on devices init via RTDM (and users may have copied this):
Quoted 6 lines
rtdm_irq_request(...);
<init_hardware, also clear pending IRQs of the device>rtdm_irq_enable(...);But I do not disable the IRQ before
rtdm_irq_free()again. Is this unbalanced enabling still needed today? Is it even wrong these days?Looks unsafe, since nothing says that freeing the descriptor associated with some IRQ should disable this IRQ line at hw level. However, we would be correct to assume that no IRQ could happen after we have been asked to free its associated descriptor.
Is
Quoted 1 line
it arch-dependent?
Nope. Both APIs are arch-agnostic anyway.
I think the pattern dates back in RTAI times and was
Quoted 3 lines
needed for so far unused IRQs. Disabling them on device closure blocked the line for later use under Linux.
We never had this problem with Xeno, since we always relied on the standard IRQ controllers defined by Linux for managing interrupt lines. IOW, Linux can undo what Xenomai did wrt IRQ line enabling/disabling.
Quoted 6 lines
Quoted 3 lines
So the enable is definitely needed and a disable on release should not cause harm anymore? If that's the case, we could start re-introducing
rtdm_irq_disablebeforertdm_irq_freeagain.Except for interrupts shared between RT/non-RT, the don't need enable (since they are enabled by Linux already), and probably doesn't fare well with a final disable.
That's the uncommon case by essence, for which a different set of rules already applies anyway.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I'm asking now in case we have to change the usage: we may better do it early (e.g. with the introduction of Xenomai 2.1), so that the number of surprises can be kept low when the underlying mechanisms get reworked later.
Signature · 1 line
Philippe.
Quoted 34 lines · Dmitry Adamushko
N.B. Amongst other things, some thoughts about CHAINED with shared interrupts.
On 20/02/06, *Anders Blomdell* <[email protected] <mailto:[email protected]>> wrote:
A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted,
returns NOENABLE|HANDLED and another return only HANDLED?2. What happens if one returns PROPAGATE and another returns HANDLED?
Yep, each ISR may return a different value and all of them are accumulated in the "s" variable ( s |=
intr->isr(intr); ).So the loop may end up with "s" which contains all of the possible bits:
(e.g.
isr1 - HANDLED | ENABLE
isr2 - HANDLED (don't want the irq to be enabled)
isr3 - CHAINED)
s = HANDLED | ENABLE | CHAINED;
Then CHAINED will be ignored because of the following code :
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (s & XN_ISR_ENABLE) + xnarch_end_irq(irq); + else if (s & XN_ISR_CHAINED) (*) + xnarch_chain_irq(irq);
Which is the worst way possible of prioritizing them, if a Linux interrupt is active when we get there with ENABLE|CHAINED, interrupts will be enabled with the Linux interrupt still asserted -> the IRQ-handlers will be called once more, probably returning ENABLE|CHAINED again -> infinite loop...
Quoted 6 lines
the current code in the CVS doen not contain "else" in (*), so that ENABLE | CHAINED is possible, though it's a wrong combination.
This said, we suppose that one knows what he is doing.
In the case of a single ISR per line, it's not that difficult to achieve. But if there are a few ISRs, then one should analize and take into account all possible return values of all the ISRs, as each of them may affect others (e.g. if one returns CHAINED when another - HANDLED | ENABLE).
Which is somewhat contrary to the concept of shared interrupts, if we have to take care of the global picture, why make them shared in the first place? (I like the concept of shared interrupts, but it is important that the framework gives a separation of concerns)
Quoted 1 line
So my feeling is that CHAINED should not be used by drivers which registered their ISRs as SHARED.
Well, CHAINED should not be used by drivers which return ENABLE (and are of course hence incompatible with true realtime IRQ's)
Quoted 25 lines
Moreover, I actually see the only scenario of CHAINED (I provided it before) :
all ISRs in the primary domain have reported UNHANDLED => nucleus propagates the interrupt down the pipeline with
xnacrh_chain_irq(). This call actually returns 1 upon successful propagation (some domain down the pipeline was interested in this irq) and 0 otherwise.Upon 0, this is a spurious irq (none of domains was interested in its handling).
ok, let's suppose now :
we have 2 ISRs on the same shared line :
isr1 : HANDLED (will be enabled by rt task. Note, rt task must call
xnarch_end_irq()and not justxnarch_enable_irq()! )isr2 : CHAINED
So HANDLED | CHAINED is ok for the single ISR on the line, but it may lead to HANDLED | CHAINED | ENABLE in a case of the shared line.
rt task that works jointly with isr1 just calls
xnarch_end_irq()at some moment of time and some ISR in the linux domain does the same later => the line is .end-ed 2 times.ISR should never return CHAINED as to indicate _only_ that it is not interested in this irq, but ~HANDLED or NOINT (if we'll support it) instead.
If the ISR nevertheless wants to propagate the IRQ to the Linux domain _explicitly_, it
_mustnot_register itself as SHARED, i.e. it _must_ be the only ISR on this line, otherwise that may lead to the IRQ line being .end-ed twice (lost interrupts in some cases).
Quoted 7 lines
#define UNHANDLED 0 #define HANDLED_ENABLE 1 #define HANDLED_NOENABLE 2 #define PROPAGATE 3Yep, I'd agree with you. Moreover, PROPAGATE should not be used for shared interrupts.
My feeling is that it should be considered an error to attach a RT IRQ handler to a line that has a Linux IRQ handler (this should be possible to check, since /proc/interrupts contains the relevant information), unless a "Linux IRQ-mask" function is installed. This IRQ-mask function should the be called:
1. each time domains are switched
2. each time an interrupt is generated
The IRQ-mask function should look something like:
unsigned int rt_irq_mask(struct ipipe_domain *ipd, unsigned int irq) {
int result = 0;
static int enabled = true;
int enable = enabled;
if (irq >= 0) {
// Interrupt has occured, we are about to run IRQ handlers
if (disable_early) {
enable = false;
}
if (for_linux(irq)) {
result = XN_ISR_CHAINED;
}
} else if (ipd == ipipe_root_domain) {
// Entering Linux
enable = true;
} else {
// Other doamin, block linux interrupts
enable = false;
}
if (enable != enabled) {
enabled = enable
if (enable) {
// Enable Linux interrupts by unmasking appropriate
// device registers (and possibly entire IRQ's)
} else {
// Disable Linux interrupts by masking appropriate
// device registers (and possibly entire IRQ's)
} }
return result;
}
The advantages with this scheme is:
1. Linux interrupts are handled in one (platform specific) routine, and does not clobber the RT IRQ-handlers, thus making it simpler to port a RT application to a new platform: only the irq_mask funtion needs to be changed, i.e. separation of concerns.
2. By setting disable_early and masking out all Linux IRQ's, the RT part only needs to take the hit from one Linux interrupt even if they all occur.
Signature · 3 lines
Regards Anders
Quoted 106 lines · Anders Blomdell
Quoted 51 lines · Jan Kiszka
Hi Dmitry,
Quoted 8 lines · Dmitry Adamushko
Hi Jan,
let's make yet another revision of the bits :
new
XN_ISR_HANDLED== oldXN_ISR_HANDLED+ oldXN_ISR_NO_ENABLEok.
Quoted 8 lines
new
XN_ISR_NOENABLE== ~ oldXN_ISR_ENABLEok.
new
XN_ISR_PROPAGATE==XN_ISR_CHAINEDok.
Just to make sure that you understand my weird ideas: each of the three new
XN_ISR_xxxabove should be encoded with an individual bitQuoted 11 lines
new
XN_ISR_NOINT== ?does it suppose the interrupt line to be .end-ed (enabled) and irq not to be
propagated? Should be so, I guess, if it's different from 5). Then nucleus
ignores implicit IRQ enable for 5) as well as for 3).Do we really need that NOINT then, as it seems to be the same as ~HANDLED?
Quoted 8 lines
or NOINT == 0 and then it's a scalar value, not a bit.
So one may consider HANDLED == 1 and NOINT == 0 as really scalar values
and
NOENABLE and PROPAGATE as additional bits (used only if needed).
My idea is to urge the user specifying one of the base return types (HANDLED or NOINT) + any of the two additional bits (NOENABLE and PROPAGATE).
Quoted 8 lines
For correct drivers NOINT could be 0 indeed, but to check that the user picked a new constant we may want to set NOINT != 0. With the old API "return 0" expressed HANDLED + ~ENABLE for the old API. With the new one the user signals no interest and the nucleus may raise a warning that a spurious IRQ occurred. So I would add a debug bit for NOINT here to optionally (on
OPT_XENO_DEBUG) detect old-style usage (return 0). Moreover, we gain freedom to move bits in the future when every state is encoded via constants. Or am I too paranoid here?After reading the above discussion (of which I understand very little), and looking at (what I believe to be) the relevant code:
(quoted diff) +16
-0+ intr = shirq->handlers; + + while (intr) + { + s |= intr->isr(intr); + ++intr->hits; + intr = intr->next; + } + xnintr_shirq_unlock(shirq); + + --sched->inesting; + + if (s & XN_ISR_ENABLE) + xnarch_end_irq(irq); + else if (s & XN_ISR_CHAINED) + xnarch_chain_irq(irq);A number of questions arise:
1. What happens if one of the shared handlers leaves the interrupt asserted, returns NOENABLE|HANDLED and another return only HANDLED?
2. What happens if one returns PROPAGATE and another returns HANDLED?
As far as I can tell, after all RT handlers havve run, the following scenarios are possible:
1. The interrupt is deasserted (i.e. it was a RT interrupt)
2. The interrupt is still asserted, it will be deasserted later by some RT task (i.e. it was a RT interrupt)
3. The interrupt is still asserted and will be deasserted by the Linux IRQ handler.IMHO that leads to the conclusion that the IRQ handlers should return a scalar
#define UNHANDLED 0
#defineHANDLED_ENABLE1
#defineHANDLED_NOENABLE2
#define PROPAGATE 3and the loop should be
Quoted 11 lines
s = UNHANDLED
while (intr) {
tmp = intr->isr(intr);
if (tmp > s) { s = tmp; }
intr = intr->next;
}
if (s == PROPAGATE) {
xnarch_chain_irq(irq);
} else if (s == HANDLED_ENABLE) {
xnarch_end_irq(irq);
}This is a very useful suggestion, specifically this escalation of the return value in the shared case. I would just let UNHANLDED start with 1 for the reasons I explained here:
https://mail.gna.org/public/xenomai-core/2006-02/msg00186.html
Ok, I would say let's got for this and finalise the patch!
Quoted 6 lines
To be really honest, I think that PROPAGATE should be excluded from the RT IRQ-handlers, since with the current scheme all RT-handlers has to test if the IRQ was a Linux interrupt (otherwise the system will only work when the handler that returns PROPAGATE is installed)
Indeed, but I'm with Philippe here: do not exclude the strange corner case scenarios users may craft with the appropriate care. I could, e.g., imagine a scenario where an RT handler takes the arrival time stamp of a non-RT IRQ and then propagates it.
Jsn