All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] rtpipe consistency problems
@ 2007-12-10 10:18 Ulf Karlsson
  2007-12-10 14:16 ` Philippe Gerum
  0 siblings, 1 reply; 7+ messages in thread
From: Ulf Karlsson @ 2007-12-10 10:18 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

Hi,

I encounter a problem with rtpipes where the packets are being being
"locked up" inside the pipe, that is the read(2) call waiting for the
data does not return, Furthermore, it appears like I lose packets in
the pipe.

I have attached a two simple C-programs that demonstrate this behavior.

The program linux-pipe.c writes increasing integer values to the pipe
and expects to be able to read the same value back from the pipe,
while the program xeno-pipe.c reads an integer from the pipe and
instantly writes the very same value back.

I am using a 2.6.20.21 kernel together with xenomai 2.4.0.

Here is an example run after having started xeno-pipe in another shell:

$ ./linux-pipe 0
0
1
2
...
3499
3500
<process hangs in read(2)>

$ ./linux-pipe 10
mismatch: in: 10 out: 3501 <now when read(2) is restarted, the old
value is delivered>

$ ./linux-pipe 20
mismatch: in: 20 out: 10 <the pipe is still out of sync however>

$ ./linux-pipe 30
30
31
32
<the value 20 that was previously written has somehow been lost in the
pipe and it is back in sync!>

The behavior is somewhat different between individual runs, but
roughly the same.

I'd be grateful for any help or suggestions.

Regards,
Ulf

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xeno-pipe.c --]
[-- Type: text/x-csrc; name=xeno-pipe.c, Size: 796 bytes --]

/* gcc $(xeno-config --xeno-cflags --xeno-ldflags) -Wall -lnative \
 *     xeno-pipe.c -o xeno-pipe
 */
#include <native/task.h>
#include <native/pipe.h>
#include <stdio.h>
#include <error.h>
#include <sys/mman.h>

#define PIPE_NAME "extcmd1"

RT_TASK main_task;
RT_PIPE extcmd_pipe;

int main()
{
	int ret;
	unsigned long val;
	mlockall(MCL_CURRENT|MCL_FUTURE);
	rt_task_shadow(&main_task, "main task", 5, T_CPU(0));

	ret = rt_pipe_create(&extcmd_pipe, PIPE_NAME, P_MINOR_AUTO,0);
	if (ret < 0) {
		error(0,-ret,"rt_pipe_create");
		return;
	}
	for (;;) {
		ret = rt_pipe_read(&extcmd_pipe, &val, sizeof (val), TM_INFINITE);
		if (ret < 0)
			error(1,-ret,"rt_pipe_read");
		ret = rt_pipe_write(&extcmd_pipe, &val, sizeof (val), P_NORMAL);
		if (ret < 0)
			error(1,-ret,"rt_pipe_write");
	}
}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: linux-pipe.c --]
[-- Type: text/x-csrc; name=linux-pipe.c, Size: 678 bytes --]

/* gcc -Wall linux-pipe.c -o linux-pipe
 */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
	unsigned long in = 0, out;
	int fd;
	int ret;

	if (argc > 1)
		in = atoi(argv[1]);
	
	fd = open("/proc/xenomai/registry/native/pipes/extcmd1", O_RDWR);
	if (fd < 0)
		error(0, -fd, "open");

	for (;;) {
		ret = write(fd, &in, sizeof (in));
		if (ret < 0)
			error(1, -ret, "write");
		ret = read(fd, &out, sizeof (out));
		if (ret < 0)
			error(1, -ret, "read");
		if (in != out) {
			printf("mismatch: in: %lu out: %lu\n", in, out);
			return 1;
		}
		printf("%lu\n", out);
		in++;
	}

	return 0;
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-12-24 13:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-10 10:18 [Xenomai-help] rtpipe consistency problems Ulf Karlsson
2007-12-10 14:16 ` Philippe Gerum
2007-12-10 14:55   ` Ulf Karlsson
2007-12-10 17:57     ` Philippe Gerum
2007-12-12  9:42     ` Philippe Gerum
2007-12-22 18:55       ` Philippe Gerum
2007-12-24 13:43         ` Ulf Karlsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.