
Gurus...Unix serial-port, time-slice and timing help
Hi to all - apologies if I am cross-posting to the wrong group. Linux
people tend to be very aware of Operating Systems, and C/C++ programmers
might have some clues to my problem below.
First, I am just a mechanical engineer in robotics - I never took OS and
have only a high-level understanding of the kernel. I am using GNU C++
under SunOs 5.1 on a Sparc 20.
The problem:
The Sun is serially connected to a device (pan-tilt motor unit) that works
at 9600 baud. My C program can write to and read from it, in ASCII chars
just fine. The program writes chars to the device, then reads back a
3-char return prompt.
Physcially connecting a 2-channel oscilloscope on the serial port's RX/TX
and GND revealed the following: writing 4 chars and reading the 3
char return prompt took apx. 10 millseconds (ms). The scope showed a 1.51
ms delay between the RX and TX signals. 10 ms makes sense since a char
with start/stop bits yields:
7 chars * 10 bits/char / 9600 bit/s = 7.3 ms
add the delay of 1.51 ms gives a grand total of 8.81 ms
This is close to the actual scope reading...
Enveloping the read/write statements in a gettimeofday() says
read/write takes 40 ms !!
My Comp Sci friends tell me it's because of context switching.
Sparc 20 benchmarks say that a context switch takes 0.2 msec
and my friends speculate about 2 ms/time-slice.
Our Sparc20 is a multi-user networked machine. But I still can't
believe that the read/write cycle takes 40 ms... more than 4 times
longer than the scope reading. I don't have many processes running
(less than 10 I'd say). Typically I am the only one running the machine
too.
Any clues? Are my friends right? Seems like an awfully long time to me!
Very grateful,
-paul
----------------------------------------------------------------------------
Paul Oh
PhD Candidate
Columbia University
Dept of Mechanical Engineering
Center for Research in Intelligent Systems
http://www.*-*-*.com/ ~paul
----------------------------------------------------------------------------