Download fulltext - DiVA Portal

Transcript
4.1. IMU alternatives
41
The ag O_NDELAY is specied as a parameter in the open() call, making the message
passing operations (read() and devctl() )to this device non-blocking. Hence the reading
thread in the IMU driver, would check if there was any available data at the serial port,
and if not; check again immediately.
Practically this thread was performing a busy-
loop, doing less useful operations most of the time.
This also explains why the code
optimization didn't give any results; the busy loop would eat up all the freed CPU time.
Code sample 4.2
Opening of the serial device in
devc-imu.
O_NDELAY is specied.
printf("%s:\tOpening serial port ...\n",NAME);
if ( (serialFD=open(SERIAL_DEVICE,O_RDWR | O_NOCTTY | O_NDELAY)) == −1 ){
printf("%s:\tUnable to open port \n",NAME);
exit(1);
}
else{
printf("%s:\tPort opened. File desc: %d\n",NAME,serialFD);
tcsetattr(serialFD,TCSAFLUSH,0);
}
Changing the second code line in Code sample 4.2 as shown in Code sample 4.3,
solved the problem.
Code sample 4.3
Opening of the serial device in
devc-imu
correctly.
if ( (serialFD=open(SERIAL_DEVICE,O_RDWR | O_NOCTTY )) == −1 ){
...
The CPU consumption for the serial driver and the IMU driver in common, was
now reduced from 100% to approximately 14% as shown in the old version column
in Table 4.1. The new version percentages is when running the imu-driver whith the
improvements, mentioned above.
CPU consumption
devc-imu
devc-ser8250
Table 4.1:
old version
new version
2.5%
0.05%
11%
1%
CPU consumption for the old and new version of
devc-imu
(approximate
values).
These improvements were based on the use of the function readcond() instead of
read().
The IMU driver is made by two threads running in loops; the rst one is handling
the requests required by a QNX resource manager, and the second one is reading from
the serial device, and stores the values in a measurement array. The rst loop is shown
in Code sample 4.4.