LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-13-2006, 11:49 PM   #1
zielchri
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Rep: Reputation: 0
RTAI Timing Problem


I have an interesting problem about a program I'm writing for research at Michigan State University. Our goal is to create an RTAI linux computer which uses comedi drivers to take samples off a board from an experiment in the lab. The basic problem is that, once we exceed 4 or more inputs it essentually takes twice as long to take each sample than if I used 3 or less inputs into the board. I don't understand how this can be at all. Looking through data we collect, we can see that in nanoseconds the time it takes for each sample really is about twice as long as it should be, even though the program itself is counting how many samples we want and storing them correctly.

Does anybody know what could be the problem? The program itself is set up as follows: Using a user space QT based program we start the program and input on the graphical screen all of the information needed to run the program. Then, using a structure, this information is sent into the kernel space program to run the sampling for our experiment and relayed back into the user space program for storage using FIFO's. Please let me know what I can do - basically I think I'm asking for help in developing the most stable algorithm as possible for making sure each sample happens when I want it to during each run.

Ideally I'd like to be able to use all inputs / outputs on the computer so please let me know what I can do. Let me know if you want to see any code, although I can tell you right now the problem is only in the kernel space program (or maybe RTAI?), not in user space (and the kernel space program is very short, the bulk is the for loop that controls how many samples to take, what sub-device and channel to take the sample at, and then the fifo lines to send the data to the user space).

-Chris
 
Old 04-16-2006, 01:22 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Strong suggestion:

a) Invest a couple of hours learning a code profiler (for example, gprof)
b) Recompile your application with profiling enabled
Rebuild the Comedi source (at least the user-space libraries, not the kernel portion) and make sure your Comedi calls are included in your profile
c) Try profiling your application
d) Determine if you're compute bound (e.g. excessive polling activity) or I/O bound (e.g. excessive latency waiting for I/O)
e) Determine if the problem is in your code, in Comedi, or "someplace else"

In general, you *definitely* want to acquire your data in such a way that you *BLOCK* on I/O (whenever, wherever possible), and that you poll for data ONLY as a last resort, if there's no other way around it.

You'll probably also want to post some queries to the Comedi mail group - they're both knowledgeable and responsive.

Good luck .. PSM
 
Old 04-16-2006, 11:21 PM   #3
zielchri
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
paul,

Thank you for the reply, however, I'm afraid I don't really understand anything you said. I'm actually an electrical engineer so I've learned everything I know pretty much by myself. Is there a source you would recommend to look at that I can read about your suggestion? Let me know if you get the chance.

-Chris
 
Old 04-17-2006, 01:13 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Sorry about that. Here's what I was trying to suggest:

1. It sounds like the problem has to do with "performance".

Since you're an EE (hence comfortable with math), this book might be of interest to you:
The Practical Performance Analyst, Neil Gunther
http://www.amazon.com/gp/product/059...lance&n=283155

2. But before you do any analysis, you need to get some numbers.

That's where "gprof" comes in.

You can add special flags when you compile your program that that, as it runs, certain statistics will be accumulated. Then you can dump these statistics to try to figure out why your program isn't executing as quickly as you expected it to.

Here is a nice, short tutorial on gprof. You can easily google for many others:
http://badgertronics.com/writings/gprof.html

3. If things are "taking a long time", then you'll generally find it's for one of two reasons:

a) Either the application is "compute bound" (in which case you'll see high CPU usage,
and quite probably one particular subroutine called an excessive #/times)
... or ...
b) The application is "I/O bound" (in which case you'll see *LOW* CPU usage, and
quite probably one particular subroutine will show excessive wait times).

4. From there, you need to figure out *what* is wrong.

It's probably less a problem with comedi (although that's certainly possible), than a
problem with the way you're using comedi (for example, excessive polling: constantly
looping to check if some data is available).

5. Finally, I suggested you might want to join the comedi mailing list. You can do so from the comedi web page:
http://www.comedi.org

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
RTAI kernel problem pgpython Linux From Scratch 11 08-02-2007 02:09 PM
RTAI on kernel 2.6.15 cyb0rg777 Linux - Software 2 02-19-2006 02:35 AM
Squid Access Timing Restriction problem gurusmaran Linux - Security 1 10-19-2005 01:03 AM
Problem with nfs server timing out DarkSun4241 Linux - Networking 1 08-10-2005 09:14 AM
RTAI Proramming mrgoodtrips Programming 0 04-14-2005 01:59 PM

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

All times are GMT -5. The time now is 08:59 AM.

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