public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] question about Synchronization Levels in eCOS? Thanks a lot.
@ 2003-05-06 12:52 QiangHuang
  2003-05-06 13:12 ` Gary D. Thomas
  0 siblings, 1 reply; 5+ messages in thread
From: QiangHuang @ 2003-05-06 12:52 UTC (permalink / raw)
  To: Ecos-Discuss

Hi all:
   I have some question about the Synchronization Levels in ecos.  Can I set
the flag bit or post semaphore in a ISR()? if not why? As mentioned in the
ecos doc as:
" Since it would be dangerous for an ISR or DSR to make a call that might
reschedule the current thread (by trying to lock a mutex for example) all
functions in this API have an associated synchronization level. "

I can't completely understand why calling a function :
yg_drv_cond_signal( )  in isr() or dsr() should be forbidden. Is this just
to signal a condiction probably awaken a waiting thread. Then the awaken
thread might be able to run after exiting isr( ) and dsr( ), if this is
thread that the application want to run when such IRQ occured. so why ? how
does this compare to "cyg_flag_setbits( )" and "cyg_semaphore_post( )"


Thanks a lot.


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

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

* Re: [ECOS] question about Synchronization Levels in eCOS? Thanks a lot.
  2003-05-06 12:52 [ECOS] question about Synchronization Levels in eCOS? Thanks a lot QiangHuang
@ 2003-05-06 13:12 ` Gary D. Thomas
  2003-05-06 13:26   ` [ECOS] question about Synchronization Levels in eCOS? Thanks alot QiangHuang
  0 siblings, 1 reply; 5+ messages in thread
From: Gary D. Thomas @ 2003-05-06 13:12 UTC (permalink / raw)
  To: QiangHuang; +Cc: eCos Discussion

On Tue, 2003-05-06 at 06:51, QiangHuang wrote:
> Hi all:
>    I have some question about the Synchronization Levels in ecos.  Can I set
> the flag bit or post semaphore in a ISR()? if not why? As mentioned in the
> ecos doc as:
> " Since it would be dangerous for an ISR or DSR to make a call that might
> reschedule the current thread (by trying to lock a mutex for example) all
> functions in this API have an associated synchronization level. "
> 
> I can't completely understand why calling a function :
> yg_drv_cond_signal( )  in isr() or dsr() should be forbidden. Is this just
> to signal a condiction probably awaken a waiting thread. Then the awaken
> thread might be able to run after exiting isr( ) and dsr( ), if this is
> thread that the application want to run when such IRQ occured. so why ? how
> does this compare to "cyg_flag_setbits( )" and "cyg_semaphore_post( )"

This is illegal because ISR routines can be called at any point
that interrupts are enabled.  This includes during what some
systems call "critical sections", e.g. places where the kernel
is manipulating it's own internal data structures etc.

We allow ISR routines to be called like this in order to keep
interrupt response time to a minimum.  The ISR is then expected
to dispatch a DSR if more extensive (or dangerous) operations 
are required.  In this way, pure interrupt response time is
minimized and the kernel is kept fast and simple.

-- 
Gary D. Thomas <gary.thomas@mind.be>


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

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

* RE: [ECOS] question about Synchronization Levels in eCOS? Thanks alot.
  2003-05-06 13:12 ` Gary D. Thomas
@ 2003-05-06 13:26   ` QiangHuang
  2003-05-06 13:32     ` Gary D. Thomas
  2003-05-06 13:33     ` Andrew Lunn
  0 siblings, 2 replies; 5+ messages in thread
From: QiangHuang @ 2003-05-06 13:26 UTC (permalink / raw)
  To: Gary D. Thomas; +Cc: Ecos-Discuss

Thanks Gary.


Suppose the following:

thread1( )
{ 

cyg_flag_wait( &flag );

}

isr( )
{
// if cyg_flag_setbits(&flag) called here what problem would be?
}

dsr( )
{
// if cyg_flag_setbits(&flag) called here would this be OK?
}


Q1: But can I awaken a thread in DSR( ) by calling cyg_flag_setbits( ) ?

Q2: If I use the cyg_flag_setbits( ) in ISR( ) to awaken a thread what problem would happen?  (affect the IRQ responsing time?)

Thanks a lot.

-----Original Message-----
From: Gary D. Thomas [mailto:gary.thomas@mind.be]
Sent: 06 May 2003 14:13
To: QiangHuang
Cc: eCos Discussion
Subject: Re: [ECOS] question about Synchronization Levels in eCOS?
Thanks alot.


On Tue, 2003-05-06 at 06:51, QiangHuang wrote:
> Hi all:
>    I have some question about the Synchronization Levels in ecos.  Can I set
> the flag bit or post semaphore in a ISR()? if not why? As mentioned in the
> ecos doc as:
> " Since it would be dangerous for an ISR or DSR to make a call that might
> reschedule the current thread (by trying to lock a mutex for example) all
> functions in this API have an associated synchronization level. "
> 
> I can't completely understand why calling a function :
> yg_drv_cond_signal( )  in isr() or dsr() should be forbidden. Is this just
> to signal a condiction probably awaken a waiting thread. Then the awaken
> thread might be able to run after exiting isr( ) and dsr( ), if this is
> thread that the application want to run when such IRQ occured. so why ? how
> does this compare to "cyg_flag_setbits( )" and "cyg_semaphore_post( )"

This is illegal because ISR routines can be called at any point
that interrupts are enabled.  This includes during what some
systems call "critical sections", e.g. places where the kernel
is manipulating it's own internal data structures etc.

We allow ISR routines to be called like this in order to keep
interrupt response time to a minimum.  The ISR is then expected
to dispatch a DSR if more extensive (or dangerous) operations 
are required.  In this way, pure interrupt response time is
minimized and the kernel is kept fast and simple.

-- 
Gary D. Thomas <gary.thomas@mind.be>



-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

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

* RE: [ECOS] question about Synchronization Levels in eCOS? Thanks alot.
  2003-05-06 13:26   ` [ECOS] question about Synchronization Levels in eCOS? Thanks alot QiangHuang
@ 2003-05-06 13:32     ` Gary D. Thomas
  2003-05-06 13:33     ` Andrew Lunn
  1 sibling, 0 replies; 5+ messages in thread
From: Gary D. Thomas @ 2003-05-06 13:32 UTC (permalink / raw)
  To: QiangHuang; +Cc: eCos Discussion

On Tue, 2003-05-06 at 07:25, QiangHuang wrote:
> Thanks Gary.
> 
> 
> Suppose the following:
> 
> thread1( )
> { 
> 
> cyg_flag_wait( &flag );
> 
> }
> 
> isr( )
> {
> // if cyg_flag_setbits(&flag) called here what problem would be?
> }
> 
> dsr( )
> {
> // if cyg_flag_setbits(&flag) called here would this be OK?
> }
> 
> 
> Q1: But can I awaken a thread in DSR( ) by calling cyg_flag_setbits( ) ?
> 

Yes.

> Q2: If I use the cyg_flag_setbits( ) in ISR( ) to awaken a thread what problem would happen?  (affect the IRQ responsing time?)
> 

As I said, since ISR routines can be called - *EVEN WHEN THE
KERNEL DATA STRUCTURES ARE IN FLUX* - calling any kernel
function which might manipulate data structures, e.g. awaken
a thread, would be disastrous.  Of course, you might get
away with it 99.999% of the time, but it would still be
potentially fatal.

Bottom line: don't do it.

Hint: there is a whole section in the eCos documentation
which discusses what functions can be called when [safely].
Perhaps reading that would answer your questions.

> Thanks a lot.
> 
> -----Original Message-----
> From: Gary D. Thomas [mailto:gary.thomas@mind.be]
> Sent: 06 May 2003 14:13
> To: QiangHuang
> Cc: eCos Discussion
> Subject: Re: [ECOS] question about Synchronization Levels in eCOS?
> Thanks alot.
> 
> 
> On Tue, 2003-05-06 at 06:51, QiangHuang wrote:
> > Hi all:
> >    I have some question about the Synchronization Levels in ecos.  Can I set
> > the flag bit or post semaphore in a ISR()? if not why? As mentioned in the
> > ecos doc as:
> > " Since it would be dangerous for an ISR or DSR to make a call that might
> > reschedule the current thread (by trying to lock a mutex for example) all
> > functions in this API have an associated synchronization level. "
> > 
> > I can't completely understand why calling a function :
> > yg_drv_cond_signal( )  in isr() or dsr() should be forbidden. Is this just
> > to signal a condiction probably awaken a waiting thread. Then the awaken
> > thread might be able to run after exiting isr( ) and dsr( ), if this is
> > thread that the application want to run when such IRQ occured. so why ? how
> > does this compare to "cyg_flag_setbits( )" and "cyg_semaphore_post( )"
> 
> This is illegal because ISR routines can be called at any point
> that interrupts are enabled.  This includes during what some
> systems call "critical sections", e.g. places where the kernel
> is manipulating it's own internal data structures etc.
> 
> We allow ISR routines to be called like this in order to keep
> interrupt response time to a minimum.  The ISR is then expected
> to dispatch a DSR if more extensive (or dangerous) operations 
> are required.  In this way, pure interrupt response time is
> minimized and the kernel is kept fast and simple.
> 
> -- 
> Gary D. Thomas <gary.thomas@mind.be>
-- 
Gary D. Thomas <gary.thomas@mind.be>


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

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

* Re: [ECOS] question about Synchronization Levels in eCOS? Thanks alot.
  2003-05-06 13:26   ` [ECOS] question about Synchronization Levels in eCOS? Thanks alot QiangHuang
  2003-05-06 13:32     ` Gary D. Thomas
@ 2003-05-06 13:33     ` Andrew Lunn
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2003-05-06 13:33 UTC (permalink / raw)
  To: QiangHuang; +Cc: Ecos-Discuss

On Tue, May 06, 2003 at 02:25:29PM +0100, QiangHuang wrote:
> Thanks Gary.
> 
> 
> Suppose the following:
> 
> thread1( )
> { 
> 
> cyg_flag_wait( &flag );
> 
> }
> 
> isr( )
> {
> // if cyg_flag_setbits(&flag) called here what problem would be?
> }

The kernel could be in the process of awakening thread1 from the
previous ISR when the current ISR goes off. ie its part way through
cyg_flag_wait(&flag), when the ISR goes off and changes the value of
flag without it realizing. Things can then go wrong. 

However, DSR are called at safe times when changing such variables
will not cause a problem since it 100% sure its not half way though a
cyg_flag_wait operation.

          Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

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

end of thread, other threads:[~2003-05-06 13:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-06 12:52 [ECOS] question about Synchronization Levels in eCOS? Thanks a lot QiangHuang
2003-05-06 13:12 ` Gary D. Thomas
2003-05-06 13:26   ` [ECOS] question about Synchronization Levels in eCOS? Thanks alot QiangHuang
2003-05-06 13:32     ` Gary D. Thomas
2003-05-06 13:33     ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).