LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2008, 03:44 AM   #1
pmil
Member
 
Registered: Jul 2008
Posts: 43

Rep: Reputation: 15
Exclamation About ISR execution/priority


Hi all,

I have an interrupt which is caused every 10 ms and it is served by an ISR. I am also executing a user-space process inside a while(1) loop.

The problem is that the user-space process is affecting the ISR execution. Is this reasonable? How can I assure that when my ISR is executed no other processes are running?

The thing that I want looks like the following graph:

-------------------------------------------------------
ISR | Processes | ISR | Processes |
--------------------------------------------------------(ms)
0____________10_____________20

and not something like:
-------------------------------------------------------
ISR |_________| ISR |_________|
--------------------------------------------------------
__________Processes_________|
--------------------------------------------------------(ms)
0___________10____________20


Any help would be more than welcomed!

Thank you all!
 
Old 07-29-2008, 04:20 AM   #2
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
The interrupts are as their name say interrupts - they will interrupt any processing running and call the handler. I do not know what do you want, maybe the interrupts are not the solution.

Also, besides stating the problem, you should give more info (operating system, how do you set interrupts).
 
Old 07-29-2008, 04:48 AM   #3
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Perhaps you are doing too much in the ISR? Regardless of what other processes are doing, any enabled interrupt will cause the kernel's interrupt dispatch routine to be invoked. If you need greater "determinism" in the scheduling of the ISR you should look at the "Real Time" patches. However, no tweaking of the kernel will save you if you're simply trying to do too much work on a single processor.
 
Old 07-29-2008, 04:49 AM   #4
pmil
Member
 
Registered: Jul 2008
Posts: 43

Original Poster
Rep: Reputation: 15
Hi, and thanks for the very quick reply!

I am using kernel 2.6.20.4 in an ARM EP9302 based embedded board.

My ISR is being served when I have an overflow of an on-board timer.

What I want is when my handler runs (every 10 ms) no other processes to run until the handler ends its work.

I want all the processes to run after the end of the ISR and until its next call as in the following graph:


-------------------------------------------------------
ISR | Processes | ISR | Processes |
--------------------------------------------------------(ms)
0____________10_____________20


I know that this is not the case because I have interference from a user-space process to the proper execution of my handler.

In my case, I want on top of all proper execution of the handler.

Any ideas?

P.S: I want to have the above scenario but without the use of a RT patch such as RTAI and RT-Linux.

Thank you all!
 
Old 07-29-2008, 05:00 AM   #5
pmil
Member
 
Registered: Jul 2008
Posts: 43

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pinniped View Post
Perhaps you are doing too much in the ISR?
I don't think that this is the case because when I am not running a particular user-space process (which uses a while(1) loop), the execution of the ISR is proper.

But when I am running this user-space process with the while(1) loop, it affects the proper execution of my ISR.

In particular, I am blinking an LED every second inside my ISR and when I am runnning the user-space process the LED starts blinking randomly.

I am really having hard time with this!

Thank you again!
 
Old 07-29-2008, 06:04 AM   #6
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
Did you disabled interrupts in you ISR (put a disable interrupt at start and an enable interrupt at the end) ? If you didn't other things might happen while you process your interrupt.

I do not understand how do you do blink the LED every second ? You mean, each 100 runs of the ISR you blink the LED ?

I do not know what kind of interrupt controller do you have. Does it has something like priorities ? (maybe another interrupt gets served first)
 
Old 07-29-2008, 07:36 AM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
What I want is when my handler runs (every 10 ms) no other processes to run until the handler ends its work.
Consider very strongly that you are doing unnecessary things in your Interrupt Handler if you are executing more than two instructions (plus enable and disable instructions). That's two machine code instructions, not two high level language statements.

You get into a handler, it has to increment a count and then go away. That shouldn't need much complication. A separate issue is to toggle the state of a port pin on every 50th run of the ISR. That's incrementing a count up to fifty setting the count to zero and flipping a bit; you might be able to regard that part of the process as interruptible (but your 'user space' code wouldn't get in).

What other interrupts are active at the same time? Can they be masked, at least for the duration of this interrupt? (Have you any idea of the duration of your ISR? You could measure that.)

Without interrupts, the thing that you are calling a user-space process shouldn't be getting in, once the ISR has started, but your OS probably does stuff with interrupts too, that you may or may not know about.

I'm not sure about the EP9302, but some ARMs (Cortex M3s for example), have quite configurable interrupt controllers and there may well stuff you can do there to help. The danger is that you stop the OS doing stuff it has to do, particularly if you don't know what your OS is doing...
 
Old 07-30-2008, 12:55 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Do it like this:
  1. The only purpose of the interrupt is to say, "tick!" All that the interrupt handler does is to, say, increment a counter and wake-up a user-mode process that is waiting on the timer. (Let's say you have a /dev defined for the device, and the user-mode process is waiting on a fcntl() or even a read.) Or some kind of event. It doesn't do anything else.
  2. The user-mode process does the work that you now delegate to the interrupt-handler.
  3. The user-mode process now signals an event or semaphore that the other, lower-priority user-mode processes are waiting for. Each of those processes (running in no particular order on an unknown number of CPUs) now does their work.
  4. If the first process wants to wait for the others to be done, an event or semaphore is used for that.
  5. If the interrupt handler increments a counter, or sets an event-flag, this gives the first process a way to know when it is "running behind." (The counter value changed within the loop.) It waits, or not, as necessary.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Canceling ISR Thread cause extra Interrupts EmbeddedSteve Linux - Embedded & Single-board computer 0 09-18-2007 04:38 PM
process priority,nice -- small question regarding high/low priority values beeblequix Linux - Newbie 1 10-11-2006 10:22 AM
Restarting an ISR in a transaction-like style rnkayab Programming 8 08-25-2006 02:00 PM
Debugging ISR eshwar_ind Programming 1 06-18-2005 04:31 PM
Pentium Timer ISR obashir Programming 0 04-27-2003 04:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration