LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-31-2004, 02:40 AM   #1
frostmagic
LQ Newbie
 
Registered: Sep 2003
Posts: 28

Rep: Reputation: 15
Timing problems


I am developing a server program that send 3 types of data
I data - 13888 usecs
P data - 2777 usecs
B data - 555 usecs

1. This data are to send within the time frame given.

2. There is a counter to add up the ideal time the data should be send known as streamtime.

3. At the beginning of the program, i used gettimeofday to get the time known as start.

4.Before i send the data, i gettime again known as beforesend

5. i get the difference between beforesend and start and then compare with streamtime. If is more than streamtime it wont send.

6. After sending i gettime again , i used the time got and minus it from streamtime, this will be the amount of time i will sleep.

7. This will continue in a loop until the program terminates.

My problem is that , sometimes at 5. the difference which is the timing is more than streamtime. I send 1700 pieces of data , about 400 pieces of data have that time more than the stream time.

Is is because of the background process tat cause some of this time to increase a lot?
 
Old 01-31-2004, 05:59 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Sort of. You are running in a system that gives out cpu time in slices (quanta). If some process that has nothing to do with what you are doing needs time, it will get it.

You need to develop some kind of inter-thread communication scheme using sempahores or whatever is appropriate. Just guessing that streamtime will be 13000 ms and then sleeping that long will get you in trouble. You need to have each transmission thread signal <I am Done>
and then have one controlling thread wait until it gets all three of these signals or semaphores or whatever, before it tries to send the next batch of data.
 
Old 01-31-2004, 10:34 AM   #3
frostmagic
LQ Newbie
 
Registered: Sep 2003
Posts: 28

Original Poster
Rep: Reputation: 15
dont really understand , i quite new to linux programming
read up it should work by using sched_setscheduler, mlockall and gettimeofday

but i dont know how to implement it
 
Old 01-31-2004, 12:04 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Well, because of the nature of linux, or windows, or any non-realtime OS you can't guarentee timing.
 
Old 01-31-2004, 08:24 PM   #5
frostmagic
LQ Newbie
 
Registered: Sep 2003
Posts: 28

Original Poster
Rep: Reputation: 15
but i read up , they say non real time OS still could implement it?
 
Old 01-31-2004, 10:26 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
You can get relatively close, but most of the time you'll find people implement protocols for what data should look like (start sequence, stop sequence, check sum) rather then timing schemes for how data should come because they are safer. Technically speaking, if the kernel decides it needs to do something more important it could cut you off in the middle of your routine. You could check out the RTLinux extensions and implement a kernel module for the timing that would easily get you the resolution you want.

One of the timing issues I imagine you'll run into is the fact that it is very hard to syncronize the clock on two different machines across the network, especially for us resolutions. And if you get off sync you'll end up with a huge mess.

Last edited by jtshaw; 01-31-2004 at 10:27 PM.
 
Old 02-01-2004, 10:26 AM   #7
frostmagic
LQ Newbie
 
Registered: Sep 2003
Posts: 28

Original Poster
Rep: Reputation: 15
hmm if i use rtlinux , my problem will be automatically slow or do i have to do something to make it work real time?
 
  


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
dhdpcd timing out jplev22 Linux - Wireless Networking 9 09-12-2005 02:30 PM
kudzu Keeps Timing Out timswim78 Linux - Software 1 02-19-2005 01:11 PM
timing a function saajii Programming 1 10-25-2004 02:37 AM
timing in c++ deveraux83 Programming 2 04-20-2004 05:34 PM
timing a process jonfa Linux - General 3 10-11-2001 04:33 PM

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

All times are GMT -5. The time now is 10:45 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