Skip to contentSkip to conversation

rt_pipe_write() returns -ENOMEM

Xenomai-help Markus Franke 3 participants 9 messages Mar 5, 2007 – Mar 8, 2007

lore
Share & tools
lore
#0 lore raw

Dear Xenomai Developers/Users,

I want to exchange data between User Space and Kernel Space via a Message Pipe. Therefore I set up a pipe via rt_pipe_create() and write to the pipe using rt_pipe_write(). After a few writes rt_pipe_write() returns -ENOMEM what means that memory is exhausted. What happens if I just ignore this error code? Does it simply mean that values are dropped until the first value is read from the pipe by the User-Space Task? If so, how can I increase the size of the message pipe? rt_pipe_alloc() doesn't seem to solve the problem, isn't it?

Thanks in advance,

Markus Franke

#1 lore raw
Quoted 10 lines · Markus Franke

Dear Xenomai Developers/Users,

I want to exchange data between User Space and Kernel Space via a Message Pipe. Therefore I set up a pipe via rt_pipe_create() and write to the pipe using rt_pipe_write(). After a few writes rt_pipe_write() returns -ENOMEM what means that memory is exhausted. What happens if I just ignore this error code? Does it simply mean that values are dropped until the first value is read from the pipe by the User-Space Task? If so, how can I increase the size of the message pipe? rt_pipe_alloc() doesn't seem to solve the problem, isn't it?

The fourth argument of rt_pipe_create is the size of the reserved pool used by the pipe. If you pass 0, the system heap is used. The size of the system heap is configured via the kernel configuration.

rt_pipe_alloc allocates a message from the used pool (the rt_pipe pool if you passed a non 0 pool size to rt_pipe_create, or the system heap if you passed a null pool size to rt_pipe_create).

Signature · 1 line
                                                 Gilles Chanteperdrix
#2 lore raw
Quoted 7 lines · Gilles Chanteperdrix

The fourth argument of rt_pipe_create is the size of the reserved pool used by the pipe. If you pass 0, the system heap is used. The size of the system heap is configured via the kernel configuration.

rt_pipe_alloc allocates a message from the used pool (the rt_pipe pool if you passed a non 0 pool size to rt_pipe_create, or the system heap if you passed a null pool size to rt_pipe_create).

Yes, this I know already. But what happens if rt_pipe_write() returns -ENOMEM? Does the data to be written simply get lost or is it simply enqeued at the end and the first element in the pipe get's lost?

#3 lore raw
Quoted 4 lines · Markus Franke

what happens if rt_pipe_write() returns
-ENOMEM? Does the data to be written simply get lost or is it simply enqeued at the end and the first element in the pipe get's lost?

No, the rt_pipe_write which returns an error fails.

Signature · 1 line
                                                 Gilles Chanteperdrix
#4 lore raw

OK. And if there is an overflow is there anything I can do during runtime, e.g. just to overwrite the data in the queue?

Regards,
Markus Franke

Quoted 10 lines · Gilles Chanteperdrix
Quoted 4 lines · Markus Franke

what happens if rt_pipe_write() returns
-ENOMEM? Does the data to be written simply get lost or is it simply enqeued at the end and the first element in the pipe get's lost?

No, the rt_pipe_write which returns an error fails.

Signature · 1 line
Nichts ist so praktisch wie eine gute Theorie!

begin:vcard
fn:Markus Franke
n:Franke;Markus
adr;quoted-printable:;;Vettersstra=C3=9Fe 64/722;Chemnitz;Saxony;09126;Germany email;internet:[email protected]
x-mozilla-html:FALSE
url:http://www.tu-chemnitz.de/~franm
version:2.1
end:vcard

#5 lore raw
Quoted 2 lines · Markus Franke

OK. And if there is an overflow is there anything I can do during runtime, e.g. just to overwrite the data in the queue?

Why not something like:

while (-ENOMEM == rt_pipe_write(pipe, buf, size, mode)) {
	RT_PIPE_MSG *msg;
	rt_pipe_receive(pipe, &msg, TM_INFINITE);
	rt_pipe_free(pipe, msgp);
}
Signature · 1 line
                                                 Gilles Chanteperdrix
#6 lore raw
Quoted 11 lines · Gilles Chanteperdrix
Quoted 2 lines · Markus Franke

OK. And if there is an overflow is there anything I can do during runtime, e.g. just to overwrite the data in the queue?

Why not something like:

while (-ENOMEM == rt_pipe_write(pipe, buf, size, mode)) {
	RT_PIPE_MSG *msg;
	rt_pipe_receive(pipe, &msg, TM_INFINITE);
	rt_pipe_free(pipe, msgp);
}

This will not work: pipe are a two-ways communication channel, so that calling rt_pipe_receive returns messages that were sent from user-space, and not the messages previously sent with rt_pipe_write. I am afraid what you want to do is not what rt pipes were designed for.

Signature · 1 line
					    Gilles Chanteperdrix.
#7 lore raw

Well, I just want to use the RT Pipes as if they are a normal fifo. That is, the fifo has a bounded amount of memory and if the number of written bytes exceeds this threshold the data which was firstly written into the fifo should be dropped. By the way, I am using rt_pipe_write() and rt_pipe_read() because I just want to exchange simple integer values.

Thanks for help,

Markus Franke

Quoted 18 lines · Gilles Chanteperdrix
Quoted 11 lines · Gilles Chanteperdrix
Quoted 2 lines · Markus Franke

OK. And if there is an overflow is there anything I can do during runtime, e.g. just to overwrite the data in the queue?

Why not something like:

while (-ENOMEM == rt_pipe_write(pipe, buf, size, mode)) {
	RT_PIPE_MSG *msg;
	rt_pipe_receive(pipe, &msg, TM_INFINITE);
	rt_pipe_free(pipe, msgp);
}

This will not work: pipe are a two-ways communication channel, so that calling rt_pipe_receive returns messages that were sent from user-space, and not the messages previously sent with rt_pipe_write. I am afraid what you want to do is not what rt pipes were designed for.

Signature · 1 line
Nichts ist so praktisch wie eine gute Theorie!

begin:vcard
fn:Markus Franke
n:Franke;Markus
adr;quoted-printable:;;Vettersstra=C3=9Fe 64/722;Chemnitz;Saxony;09126;Germany email;internet:[email protected]
x-mozilla-html:FALSE
url:http://www.tu-chemnitz.de/~franm
version:2.1
end:vcard

#8 lore raw
Quoted 5 lines · Markus Franke

Well, I just want to use the RT Pipes as if they are a normal fifo.
That
is, the fifo has a bounded amount of memory and if the number of written bytes exceeds this threshold the data which was firstly written into the fifo should be dropped.

Actually, writing to a normal fifo (as UNIX pipes) rather blocks the caller, unless non-blocking i/o is in effect. This said, real-time message pipes have to be different, since the kernel endpoint is not expected to block for the non real-time user-space side to consume the data, otherwise, we would somehow synchronize the high-piority work with some low-priority task. Which in turn means that some support for flushing the i/o queues managed by the kernel endpoint space is indeed missing. The patch below attempts to address this - will be part of 2.4:

native/pipe.h +2 -1
Index: include/native/pipe.h
===================================================================
@@ -128,7 +128,8 @@
 int rt_pipe_free(RT_PIPE *pipe,
                  RT_PIPE_MSG *msg);
 
-ssize_t __deprecated_call__ rt_pipe_flush(RT_PIPE *pipe);
+int rt_pipe_flush(RT_PIPE *pipe,
+		  int mode);
 
 int __native_pipe_pkg_init(void);
 
nucleus/pipe.h +6 -0
Index: include/nucleus/pipe.h
===================================================================
@@ -31,6 +31,9 @@
 #define XNPIPE_NORMAL  0x0
 #define XNPIPE_URGENT  0x1
 
+#define XNPIPE_IFLUSH  0x1
+#define XNPIPE_OFLUSH  0x2
+
 #define XNPIPE_MINOR_AUTO  -1
 
 #ifdef __KERNEL__
@@ -141,6 +144,9 @@
 
 int xnpipe_inquire(int minor);
 
+int xnpipe_flush(int minor,
+		 int mode);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
skins/native/pipe.c +66 -0

75 lines not on this page · raw message

nucleus/pipe.c +52 -0

61 lines not on this page · raw message

Signature · 1 line
Philippe.