Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: How to wait for events, and not lose any, while processing them ?

by talexb (Canon)
on Jan 27, 2009 at 04:48 UTC ( #739099=note: print w/replies, xml ) Need Help??


in reply to Re: How to wait for events, and not lose any, while processing them ?
in thread How to wait for events, and not lose any, while processing them ?

This is bang-on, and takes me back to writing word processing code in assembler back in the late 70s.

When an interrupt happens, the processor suspends whatever it's doing; it stuffs all of the register values, including the program counter, onto a stack, then calls the appropriate interrupt service routine. When that (very slim) routine is finished, it executes not a normal RET (subroutine return), but an RTI (return from interrupt) which pulls not only the program counter from the stack, but the values of all the registers. Thus, as far as the original code knows, nothing happened (OK, this depends on the processor architecture, but you get the idea).

Even cooler -- while an interrupt is being processed, that level of interrupt and everything below it is disabled, which means any interrupt that happens during the routine is ignored until the RTI is executed. If a higher level interrupt occurs, the obvious happens -- registers are pushed, and the processor again jumps to another interrupt service routine.

So, when an event occurs, you want to have the shortest (fastest) possible interrupt service routine handle the event, so that the processor can get back to whatever it was doing, such as drawing text on the screen, processing keyboard input, or waiting in an idle loop, without dropping any data. The idle loop runs around and waits for things to magically appear in the queues, via the interrupt service routines. It can then do the laborious process of figuring out what complicated processing needs to be done with the keystroke, without the worry that another event is going to come along and perhaps be dropped.

Problems occur when the interrupts come too thick and fast for even the slender interrupt service requests to deal with -- either that of the code that handles the incoming data can't empty the queues fast enough.

Fun stuff, and good to remember in this context.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

  • Comment on Re^2: How to wait for events, and not lose any, while processing them ?

Replies are listed 'Best First'.
Re^3: How to wait for events, and not lose any, while processing them ?
by Eyck (Priest) on Jan 27, 2009 at 08:27 UTC
    That is not exactly the problem here, imagine if you will, that your interrupt-handling routine calls interrupts herself.

    Now you have the same problem as I have - the 'disable interrupts' portion is similiar to the first version of the code - I stop listening for 'interrupts' while processing. The problem is that in this case, if interrupts come, then I ignore them.

      OK -- so your first approach is to make the interrupt service routine as lightweight as possible. If that means you're still dropping interrupts, you need to move to C or assembler to get a lighter weight ISR.

      If that still isn't working, you'll need to move more of your application away from Perl and down to C or assembler until the desired performance is realized.

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://739099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-10-22 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (225 votes). Check out past polls.

    Notices?