Skip to contentSkip to conversation

Context Switch with rtnet

Xenomai Franz Engel 5 participants 8 messages Sep 14, 2012 – Sep 21, 2012

lore
Share & tools
lore
#0 lore raw

Hi,

I've a little problem. I'm using the rtnet.h-header and the following function:
ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

I compiled the program with the xenomai compiling flags and library.

When I look to the xenomai state I get something like this:
CPU  PID    MSW        CSW        PF    STAT       %CPU  NAME 22  0      0          834840     0     00000082    0.1  rtnet-stack 22  0      0          1          0     00000082    0.0  rtnet-rtpc 0  6262   2          2          0     00300380    0.0  qs_robotpositio 2  6265   2          6          0     00300380    0.0  qs_robotpositio 0  6266   1          1          0     00300380    0.0  robotrsiinterfa 1  6268   1147       2365       0     00300182    0.8  robotrsiinterfa

You can see, I get a lote of context and module switches just as the rtnet-stack itself. Is that normal?

Thanks in advanced,
    Franz

#1 lore raw
Quoted 17 lines · Franz Engel

Hi,

I've a little problem. I'm using the rtnet.h-header and the following function:
ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

I compiled the program with the xenomai compiling flags and library.

When I look to the xenomai state I get something like this:

CPU  PID    MSW        CSW        PF    STAT       %CPU  NAME
 22  0      0          834840     0     00000082    0.1  rtnet-stack
 22  0      0          1          0     00000082    0.0  rtnet-rtpc
  0  6262   2          2          0     00300380    0.0  qs_robotpositio
  2  6265   2          6          0     00300380    0.0  qs_robotpositio
  0  6266   1          1          0     00300380    0.0  robotrsiinterfa
  1  6268   1147       2365       0     00300182    0.8  robotrsiinterfa
Quoted 1 line

You can see, I get a lote of context and module switches just as the rtnet-stack itself. Is that normal?

Well, I have no clue what you configured, so I can only guess. If your task 6268 is a pure RT task that is not supposed to interact with Linux services, you first of all have a bug in your software stack. You should look for the reason of those mode switches to Linux, e.g. by asking Xenomai to raise SIGXCPU when this happens.

Regarding the rtnet-stack context switches: basically, every switch is one packet arriving at your NIC. Either you are receiving a lot of small but valid packets or you are on an open network, and that is basically heavy unrelated broadcast traffic of other sources than the RT device(s).

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120916/21fcac64/attachment.pgp>

#2 lore raw

Hi Jan,

Quoted 24 lines
Quoted 3 lines

Hi,

I've a little problem. I'm using the rtnet.h-header and the following

function:

Quoted 5 lines

ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Quoted 7 lines

I compiled the program with the xenomai compiling flags and library.

When I look to the xenomai state I get something like this:

CPU  PID    MSW        CSW        PF    STAT       %CPU  NAME
 22  0      0          834840     0     00000082    0.1  rtnet-stack
 22  0      0          1          0     00000082    0.0  rtnet-rtpc
  0  6262   2          2          0     00300380    0.0

qs_robotpositio

Quoted 1 line

2 6265 2 6 0 00300380 0.0

qs_robotpositio

Quoted 1 line

0 6266 1 1 0 00300380 0.0

robotrsiinterfa

Quoted 1 line

1 6268 1147 2365 0 00300182 0.8

robotrsiinterfa

Quoted 1 line
Quoted 8 lines
Quoted 1 line

You can see, I get a lote of context and module switches just as the

rtnet-stack itself. Is that normal?

Well, I have no clue what you configured, so I can only guess. If your task 6268 is a pure RT task that is not supposed to interact with Linux services, you first of all have a bug in your software stack. You should look for the reason of those mode switches to Linux, e.g. by asking Xenomai to raise SIGXCPU when this happens.

I use the SIGXCPU signal to look where I get a context switch. It is exactly in the line of the recvfrom. I get the same result when I step through my code. I debug from line to line and check the /proc/xenomai/state, so I can see that the CSW and MSW increases when I step over the recvfrom. I tried my code also with the native commands, like rt_recvfrom. But the result is the same.

Quoted 8 lines

Regarding the rtnet-stack context switches: basically, every switch is one packet arriving at your NIC. Either you are receiving a lot of small but valid packets or you are on an open network, and that is basically heavy unrelated broadcast traffic of other sources than the RT device(s).

Jan

I'm connected to a robot that sends me his position every 4ms.

I send you a minimal example of my code. But I'm not sure if I understand your question for the configuration correct. Depends the realtime capability of rtnet only by my kdevelop project (cmake, *.c and *.h) or is it possible that I miss some settings in the kernel? I start rtnet before I run my program and I load the modules for my NIC and for UDP etc. Is there something more what I have to do?

Thanks and regards,
Franz

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DemoCSW.tar.gz
Type: application/octet-stream
Size: 3601 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120920/c87f6809/attachment.obj>

#3 lore raw
Quoted 35 lines · Franz Engel

Hi Jan,

Quoted 24 lines
Quoted 3 lines

Hi,

I've a little problem. I'm using the rtnet.h-header and the following

function:

Quoted 5 lines

ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Quoted 7 lines

I compiled the program with the xenomai compiling flags and library.

When I look to the xenomai state I get something like this:

CPU  PID    MSW        CSW        PF    STAT       %CPU  NAME
 22  0      0          834840     0     00000082    0.1  rtnet-stack
 22  0      0          1          0     00000082    0.0  rtnet-rtpc
  0  6262   2          2          0     00300380    0.0

qs_robotpositio

Quoted 1 line

2 6265 2 6 0 00300380 0.0

qs_robotpositio

Quoted 1 line

0 6266 1 1 0 00300380 0.0

robotrsiinterfa

Quoted 1 line

1 6268 1147 2365 0 00300182 0.8

robotrsiinterfa

Quoted 1 line
Quoted 8 lines
Quoted 1 line

You can see, I get a lote of context and module switches just as the

rtnet-stack itself. Is that normal?

Well, I have no clue what you configured, so I can only guess. If your task 6268 is a pure RT task that is not supposed to interact with Linux services, you first of all have a bug in your software stack. You should look for the reason of those mode switches to Linux, e.g. by asking Xenomai to raise SIGXCPU when this happens.

Quoted 6 lines

I use the SIGXCPU signal to look where I get a context switch. It is exactly in the line of the recvfrom. I get the same result when I step through my code. I debug from line to line and check the /proc/xenomai/state, so I can see that the CSW and MSW increases when I step over the recvfrom. I tried my code also with the native commands, like rt_recvfrom. But the result is the same.

What is the reason for the mode switch? How to get it see:

http://www.rts.uni-hannover.de/xenomai/lxr/source/examples/native/sigdebug.c

Wolfgang.

#4 lore raw
In reply to Franz Engel
Quoted 35 lines · Franz Engel

Hi Jan,

Quoted 24 lines
Quoted 3 lines

Hi,

I've a little problem. I'm using the rtnet.h-header and the following

function:

Quoted 5 lines

ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Quoted 7 lines

I compiled the program with the xenomai compiling flags and library.

When I look to the xenomai state I get something like this:

CPU  PID    MSW        CSW        PF    STAT       %CPU  NAME
 22  0      0          834840     0     00000082    0.1  rtnet-stack
 22  0      0          1          0     00000082    0.0  rtnet-rtpc
  0  6262   2          2          0     00300380    0.0

qs_robotpositio

Quoted 1 line

2 6265 2 6 0 00300380 0.0

qs_robotpositio

Quoted 1 line

0 6266 1 1 0 00300380 0.0

robotrsiinterfa

Quoted 1 line

1 6268 1147 2365 0 00300182 0.8

robotrsiinterfa

Quoted 1 line
Quoted 8 lines
Quoted 1 line

You can see, I get a lote of context and module switches just as the

rtnet-stack itself. Is that normal?

Well, I have no clue what you configured, so I can only guess. If your task 6268 is a pure RT task that is not supposed to interact with Linux services, you first of all have a bug in your software stack. You should look for the reason of those mode switches to Linux, e.g. by asking Xenomai to raise SIGXCPU when this happens.

Quoted 6 lines

I use the SIGXCPU signal to look where I get a context switch. It is exactly in the line of the recvfrom. I get the same result when I step through my code. I debug from line to line and check the /proc/xenomai/state, so I can see that the CSW and MSW increases when I step over the recvfrom. I tried my code also with the native commands, like rt_recvfrom. But the result is the same.

Stepping in gdb causes switches to secondary mode (each step is a switch to secondary mode).

Anyway, you did not tell us:
- what version of xenomai
- what version of the Linux kernel
- what version of the I-pipe patch
- what architecture
- what NIC

you are using.

Signature · 1 line
					    Gilles.
#5 lore raw
In reply to Franz Engel
Quoted 4 lines · Franz Engel

Hi,

I've a little problem. I'm using the rtnet.h-header and the following function:
ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Hi,

stupid question: But you do use an rtnet socket, not a normal one, do you? In this case, shouldn't it be rt_dev_recvfrom(...)?

Kai

#6 lore raw
Quoted 10 lines · Kai Bollue
Quoted 4 lines · Franz Engel

Hi,

I've a little problem. I'm using the rtnet.h-header and the following function:
ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Hi,

stupid question: But you do use an rtnet socket, not a normal one, do you? In this case, shouldn't it be rt_dev_recvfrom(...)?

When using the posix skin, recvfrom is substituted at compilation (or more exactly link-edit) time with __wrap_recvfrom, implemented in libpthread_rt.so, allowing to work with real-time sockets.

(But that works only if you used socket too instead of rt_dev_socket).

Signature · 1 line
					    Gilles.
#7 lore raw
Quoted 6 lines · Gilles Chanteperdrix
Quoted 5 lines · Kai Bollue
Quoted 4 lines · Franz Engel

Hi,

I've a little problem. I'm using the rtnet.h-header and the following function:
ret = recvfrom ( ethernetConnection.sock, &recBuffer, sizeof ( recBuffer ),0, ( struct sockaddr * ) &ethernetConnection.dest_addr,&destlen );

Quoted 8 lines
Quoted 4 lines

Hi,

stupid question: But you do use an rtnet socket, not a normal one, do you? In this case, shouldn't it be rt_dev_recvfrom(...)?

When using the posix skin, recvfrom is substituted at compilation (or more exactly link-edit) time with __wrap_recvfrom, implemented in libpthread_rt.so, allowing to work with real-time sockets.

Ah, sorry, I missed that.

Kai