ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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).
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.
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.
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)
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...
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.
The user-mode process does the work that you now delegate to the interrupt-handler.
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.
If the first process wants to wait for the others to be done, an event or semaphore is used for that.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.