Thread: High priority task

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    20

    High priority task

    Hi,

    i need to write a programm which checks every milisecond for new data through an ioport.

    In the meantime it has to do some calculations, but getting the data MUST have priority.

    I tried it with setitimer() and ITIMER_VIRTUAL calling every milisecond a sighandler function, but this fails.
    /edit : the function gets called but sometimes after more than a miliseconda

    So i wanted to ask whether there could be a better way to do this. The programm runs using root rights

    Thanks
    Last edited by BeBu; 02-15-2005 at 10:08 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What kind of ioport? If you have a descriptor associated with it then you can use select() or poll().
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Doing anything with repeatable 1-ms accuracy in a desktop operating system is pretty near impossible. There's simply too many things going on which can interfere with your timings.

    > So i wanted to ask whether there could be a better way to do this
    The better (but very involved) way is to write a kernel level driver for your port, which can react rapidly to servicing the port, and store the data until your program is ready to read it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    20
    The programm will not run under a desktop system.

    It will run on an embedded Linux, which basically, beside system tasks, runs this programm alone.
    I directly access the ports at the moment via inw() and outw(), the PCI Card has no Interrupt capabilty.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The programm will not run under a desktop system.
    See - this is critical information in my book.

    Are there other things you're not saying?
    Like what PCI card you have for example.

    This is one hell of a jump from your previous question.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    20
    Sorry not to mention that before.

    Well the PCI Card is a self developed one with a Lattice Chip for PCI Communications.

    The embedded linux is from IES and based on SuSE 9.2 Kernel, the hardware is basically a i386 in µATX format.

    Thanks anyway.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > the PCI Card has no Interrupt capabilty.
    An important omission on your part then.

    I still think a driver is the best approach, but instead of using card interrupts it uses a fast clock on the motherboard instead to trigger polling of the card.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Yeah, Salem is right, if you want the most accurate timing, you need to write a kernel driver, that deals with the times instead, then it can call tasklet. But to change a user process's priority, look into nice.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    20
    Thank you very much.
    I decided to code a kernelmodul.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. priority inversion due to pthread_mutex_lock(): how to avoid?
    By mynickmynick in forum C Programming
    Replies: 11
    Last Post: 04-07-2009, 10:34 AM
  2. crazy pipe/fork
    By fortune2k in forum C Programming
    Replies: 8
    Last Post: 03-13-2009, 11:28 AM
  3. Where do a task get "wakeuped", blocked, preempted?
    By micke_b in forum Linux Programming
    Replies: 4
    Last Post: 12-28-2007, 04:49 PM
  4. Priority Queue Help
    By cjwenigma in forum C++ Programming
    Replies: 6
    Last Post: 11-15-2007, 12:48 AM
  5. priority list won't work, i give up
    By teamster in forum C Programming
    Replies: 8
    Last Post: 10-19-2006, 12:26 PM