Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Comp.Arch.Embedded | Disabling interrupts to protect data

There are 43 messages in this thread.

You are currently looking at messages 0 to 10.

Disabling interrupts to protect data - KIRAN - 2009-10-26 13:11:00

Hi Guys,

I am working on some RTOS, in which I see lot of interrupts "enabling"
and "disabling" code in most of the RTOS API's to protect kernel data.
For example, Semaphore API's, Message Queue APIs, Runtime memory
management API's. Is enabling / disabling interrupts only to protect
the kernel data? Why  I am asking this is whenever interrupts are
disabled, I am scared of losing timer interrupts. Any input is
appreciated?


Regards,
Kiran



Re: Disabling interrupts to protect data - D Yuniskis - 2009-10-26 13:32:00

KIRAN wrote:

> I am working on some RTOS, in which I see lot of interrupts "enabling"
> and "disabling" code in most of the RTOS API's to protect kernel data.
> For example, Semaphore API's, Message Queue APIs, Runtime memory
> management API's. Is enabling / disabling interrupts only to protect
> the kernel data? Why  I am asking this is whenever interrupts are
> disabled, I am scared of losing timer interrupts. Any input is
> appreciated?

A common approach to providing an atomic operation.
Some CPUs don't need this.

If it is done correctly, the critical region will be very
small (temporally).  You shouldn't *lose* a timer interrupt
(nor any other) as the hardware should latch the interrupt
and you will respond to it as soon as the critical region
passes.  (a few instructions?)

If the critical region is much longer than this, the OS
implementation is sloppy.

Re: Disabling interrupts to protect data - Tim Wescott - 2009-10-26 14:02:00

On Mon, 26 Oct 2009 10:34:33 -0700, D Yuniskis wrote:

> KIRAN wrote:
> 
>> I am working on some RTOS, in which I see lot of interrupts "enabling"
>> and "disabling" code in most of the RTOS API's to protect kernel data.
>> For example, Semaphore API's, Message Queue APIs, Runtime memory
>> management API's. Is enabling / disabling interrupts only to protect
>> the kernel data? Why  I am asking this is whenever interrupts are
>> disabled, I am scared of losing timer interrupts. Any input is
>> appreciated?
> 
> A common approach to providing an atomic operation. Some CPUs don't need
> this.
> 
> If it is done correctly, the critical region will be very small
> (temporally).  You shouldn't *lose* a timer interrupt (nor any other) as
> the hardware should latch the interrupt and you will respond to it as
> soon as the critical region passes.  (a few instructions?)
> 
> If the critical region is much longer than this, the OS implementation
> is sloppy.

... or your timer period is too short for that RTOS/processor combination.

One man's meat...

-- 
www.wescottdesign.com

Re: Disabling interrupts to protect data - Tim Wescott - 2009-10-26 14:05:00

On Mon, 26 Oct 2009 10:11:45 -0700, KIRAN wrote:

> Hi Guys,
> 
> I am working on some RTOS, in which I see lot of interrupts "enabling"
> and "disabling" code in most of the RTOS API's to protect kernel data.
> For example, Semaphore API's, Message Queue APIs, Runtime memory
> management API's. Is enabling / disabling interrupts only to protect the
> kernel data? Why  I am asking this is whenever interrupts are disabled,
> I am scared of losing timer interrupts. Any input is appreciated?

It's par for the course, and pretty much necessary on most processors.

Interrupt controllers don't forget that they've been interrupted -- so if 
the timer pops off in the middle of a critical block the interrupt will 
get latched, and vectored to as soon as the OS exits the critical code.  

You'll only have a problem if you get _two_ timer interrupts in the space 
of one critical block.  If this happens then you're pushing that 
particular RTOS/processor combination too hard, and you need to re-think 
some architectural decisions.

-- 
www.wescottdesign.com

Re: Disabling interrupts to protect data - Vladimir Vassilevsky - 2009-10-26 14:30:00


D Yuniskis wrote:
> KIRAN wrote:
> 
>> I am working on some RTOS, in which I see lot of interrupts "enabling"
>> and "disabling" code in most of the RTOS API's to protect kernel data.

> A common approach to providing an atomic operation.
> Some CPUs don't need this.

Some OSes claim that they never disable interrupts, however from what I 
have seen it was all very impractical. Once you have more or less 
sophisticated structure of threads and interrupts, you've got to have 
critical parts with the interrupts disabled.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com

Re: Disabling interrupts to protect data - FreeRTOS info - 2009-10-26 14:41:00

> Some OSes claim that they never disable interrupts, however from what I 
> have seen it was all very impractical. 

I have seen this claim too - but when you look closely you find it is 
achieved by having the kernel itself execute with the absolute highest 
interrupt priority - so the effect on lower priority interrupts is 
exactly as if interrupts had been disabled.  So while the claim is not 
incorrect, it is somewhat deliberately misleading.  People who are that 
good at marketing should not be engineers.

[disclaimer - I don't know this to be the case for all systems that make 
this claim, just the ones I know about]

-- 

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.



Re: Disabling interrupts to protect data - D Yuniskis - 2009-10-26 15:06:00

Vladimir Vassilevsky wrote:
> 
> 
> D Yuniskis wrote:
>> KIRAN wrote:
>>
>>> I am working on some RTOS, in which I see lot of interrupts "enabling"
>>> and "disabling" code in most of the RTOS API's to protect kernel data.
> 
>> A common approach to providing an atomic operation.
>> Some CPUs don't need this.
> 
> Some OSes claim that they never disable interrupts, however from what I 
> have seen it was all very impractical. Once you have more or less 
> sophisticated structure of threads and interrupts, you've got to have 
> critical parts with the interrupts disabled.

You only need to disable interrupts if an interrupt context
can access those "shared objects" *without* observing whatever
other "mutex" mechanism you are using.

It *can* be done.  But, it is a lot trickier than just
a tiny little critical region.

E.g., if the jiffy comes along (perhaps the most notable
active element that *would* be interrupt spawned and asynchronously
compete for access to those strctures), it has to notice that a
critical region has been entered (by whatever it has interrupted!)
and then "schedule" a defered activation.  So, the jiffy
terminates as expected.  The interrupted routine (probably
an OS action) finishes up what it was working on, then,
examines a flag to see if it can "simply return" or if it has
to process some deferred "activity" (i.e. those things that the
jiffy *would* have done had it been fortunate enough to come
along "outside" that critical region.

Re: Disabling interrupts to protect data - D Yuniskis - 2009-10-26 15:07:00

Tim Wescott wrote:
> On Mon, 26 Oct 2009 10:34:33 -0700, D Yuniskis wrote:
> 
>> KIRAN wrote:
>>
>>> I am working on some RTOS, in which I see lot of interrupts "enabling"
>>> and "disabling" code in most of the RTOS API's to protect kernel data.
>>> For example, Semaphore API's, Message Queue APIs, Runtime memory
>>> management API's. Is enabling / disabling interrupts only to protect
>>> the kernel data? Why  I am asking this is whenever interrupts are
>>> disabled, I am scared of losing timer interrupts. Any input is
>>> appreciated?
>> A common approach to providing an atomic operation. Some CPUs don't need
>> this.
>>
>> If it is done correctly, the critical region will be very small
>> (temporally).  You shouldn't *lose* a timer interrupt (nor any other) as
>> the hardware should latch the interrupt and you will respond to it as
>> soon as the critical region passes.  (a few instructions?)
>>
>> If the critical region is much longer than this, the OS implementation
>> is sloppy.
> 
> .... or your timer period is too short for that RTOS/processor combination.

I look at it as the RTOS not having been designed "lean enough"
(to keep with the meat analogy  :> )

> One man's meat...

Re: Disabling interrupts to protect data - FreeRTOS info - 2009-10-26 15:08:00

D Yuniskis wrote:
> and then "schedule" a defered activation.  So, the jiffy
> terminates as expected.  The interrupted routine (probably
> an OS action) finishes up what it was working on, then,
> examines a flag to see if it can "simply return" or if it has
> to process some deferred "activity" 

...and how are you protecting access to the flag - or are you assuming 
the hardware supports atomic read-modify-writes on variables - or that 
the hardware supports atomic semaphore type operations?

-- 

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.



Re: Disabling interrupts to protect data - D Yuniskis - 2009-10-26 15:16:00

FreeRTOS info wrote:
> D Yuniskis wrote:
>> and then "schedule" a defered activation.  So, the jiffy
>> terminates as expected.  The interrupted routine (probably
>> an OS action) finishes up what it was working on, then,
>> examines a flag to see if it can "simply return" or if it has
>> to process some deferred "activity" 
> 
> ....and how are you protecting access to the flag - or are you assuming 
> the hardware supports atomic read-modify-writes on variables - or that 
> the hardware supports atomic semaphore type operations?

Assuming you don't have a second processor...

ever hear of a "Test and Set" instruction?

| 1 | 2 | 3 | 4 | 5 | next