* [Xenomai-help] writing from NRT to a rt_pipe
@ 2007-06-07 18:57 NZG
2007-06-07 19:13 ` NZG
2007-06-07 19:33 ` [Xenomai-help] writing from NRT to a rt_pipe Philippe Gerum
0 siblings, 2 replies; 11+ messages in thread
From: NZG @ 2007-06-07 18:57 UTC (permalink / raw)
To: xenomai
When writing from NRT to a real time pile (open, write, close).
Are message boundaries preserved based upon the length of the write call?
It's not working for me. The code below returns success, but calling
err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
or
err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
from RT space on the same pipe never returns any data
err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
always returns err
0x0b, Resource temporarily unavailable
err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
always returns err:
0x6e, Connection timed out
NZG
code specifics follow...............
int err;
kommand_t k = {
.type = KILLCYCLE,
};
int cfd = open(COMMANDPIPE, O_WRONLY|O_SYNC);
if(cfd<0){
printf("can't open %s (%s)\n",COMMANDPIPE, strerror(-cfd));
fflush(stdout);
return;
}
printf("sizeof kommand_t = %u\n",sizeof(kommand_t));
err=write(cfd,&k,sizeof(kommand_t));
if(err>=0)printf("wrote %u bytes to %s\n",err,COMMANDPIPE);
if(err<0)printf("err writing to %s (%s)\n",COMMANDPIPE,
strerror(errno));
if(close(cfd)<0)printf("couldn't close %s\n",COMMANDPIPE);
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 18:57 [Xenomai-help] writing from NRT to a rt_pipe NZG
@ 2007-06-07 19:13 ` NZG
2007-06-07 19:34 ` Philippe Gerum
2007-06-07 19:33 ` [Xenomai-help] writing from NRT to a rt_pipe Philippe Gerum
1 sibling, 1 reply; 11+ messages in thread
From: NZG @ 2007-06-07 19:13 UTC (permalink / raw)
To: xenomai
Further experimentations appear to show that the problem is that I'm closing
the NRT pipe before data is received in the RT thread, this appears to cause
the loss of data in the pipe.
Is this the desired behavior?
NZG
On Thursday 07 June 2007 1:57 pm, NZG wrote:
> When writing from NRT to a real time pile (open, write, close).
> Are message boundaries preserved based upon the length of the write call?
>
> It's not working for me. The code below returns success, but calling
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> or
> err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
>
> from RT space on the same pipe never returns any data
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> always returns err
> 0x0b, Resource temporarily unavailable
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
> always returns err:
> 0x6e, Connection timed out
>
> NZG
>
> code specifics follow...............
>
> int err;
> kommand_t k = {
> .type = KILLCYCLE,
> };
>
> int cfd = open(COMMANDPIPE, O_WRONLY|O_SYNC);
>
> if(cfd<0){
> printf("can't open %s (%s)\n",COMMANDPIPE, strerror(-cfd));
> fflush(stdout);
> return;
> }
>
> printf("sizeof kommand_t = %u\n",sizeof(kommand_t));
>
> err=write(cfd,&k,sizeof(kommand_t));
>
> if(err>=0)printf("wrote %u bytes to %s\n",err,COMMANDPIPE);
>
> if(err<0)printf("err writing to %s (%s)\n",COMMANDPIPE,
> strerror(errno));
>
>
> if(close(cfd)<0)printf("couldn't close %s\n",COMMANDPIPE);
>
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 19:13 ` NZG
@ 2007-06-07 19:34 ` Philippe Gerum
2007-06-07 19:46 ` NZG
0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2007-06-07 19:34 UTC (permalink / raw)
To: NZG; +Cc: xenomai
On Thu, 2007-06-07 at 14:13 -0500, NZG wrote:
> Further experimentations appear to show that the problem is that I'm closing
> the NRT pipe before data is received in the RT thread, this appears to cause
> the loss of data in the pipe.
>
> Is this the desired behavior?
Yes, clearly.
>
> NZG
>
>
> On Thursday 07 June 2007 1:57 pm, NZG wrote:
> > When writing from NRT to a real time pile (open, write, close).
> > Are message boundaries preserved based upon the length of the write call?
> >
> > It's not working for me. The code below returns success, but calling
> >
> > err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> > or
> > err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
> >
> > from RT space on the same pipe never returns any data
> >
> > err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> > always returns err
> > 0x0b, Resource temporarily unavailable
> >
> > err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
> > always returns err:
> > 0x6e, Connection timed out
> >
> > NZG
> >
> > code specifics follow...............
> >
> > int err;
> > kommand_t k = {
> > .type = KILLCYCLE,
> > };
> >
> > int cfd = open(COMMANDPIPE, O_WRONLY|O_SYNC);
> >
> > if(cfd<0){
> > printf("can't open %s (%s)\n",COMMANDPIPE, strerror(-cfd));
> > fflush(stdout);
> > return;
> > }
> >
> > printf("sizeof kommand_t = %u\n",sizeof(kommand_t));
> >
> > err=write(cfd,&k,sizeof(kommand_t));
> >
> > if(err>=0)printf("wrote %u bytes to %s\n",err,COMMANDPIPE);
> >
> > if(err<0)printf("err writing to %s (%s)\n",COMMANDPIPE,
> > strerror(errno));
> >
> >
> > if(close(cfd)<0)printf("couldn't close %s\n",COMMANDPIPE);
> >
> >
> >
> >
> > _______________________________________________
> > Xenomai-help mailing list
> > Xenomai-help@domain.hid
> > https://mail.gna.org/listinfo/xenomai-help
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Philippe.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 19:34 ` Philippe Gerum
@ 2007-06-07 19:46 ` NZG
2007-06-07 19:51 ` NZG
2007-06-07 20:14 ` Philippe Gerum
0 siblings, 2 replies; 11+ messages in thread
From: NZG @ 2007-06-07 19:46 UTC (permalink / raw)
To: rpm; +Cc: xenomai
> Yes, clearly.
Ah, that in conjunction with the
"can't use message pipe - Cannot allocate memory"
thread resolves my issues then.
My assumption was that data would exist in the pipe after the write until the
pipe was destroyed, irrespective of the "openness" of the NRT side.
It's possible that this assumption is due to a lack of experience with pipes
in general, I don't know.
thank you for all you help,
NZG
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 19:46 ` NZG
@ 2007-06-07 19:51 ` NZG
2007-06-07 20:14 ` Philippe Gerum
1 sibling, 0 replies; 11+ messages in thread
From: NZG @ 2007-06-07 19:51 UTC (permalink / raw)
To: rpm; +Cc: xenomai
from: man:pipe(7)
If all file descriptors referring to the write end of a pipe have been closed,
then an attempt to read(2) from the pipe will see end-of-file
well there ya go, when all else fails read the manual
thx again,
NZG
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 19:46 ` NZG
2007-06-07 19:51 ` NZG
@ 2007-06-07 20:14 ` Philippe Gerum
2007-06-07 20:41 ` NZG
2007-06-07 22:09 ` [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion NZG
1 sibling, 2 replies; 11+ messages in thread
From: Philippe Gerum @ 2007-06-07 20:14 UTC (permalink / raw)
To: NZG; +Cc: xenomai
On Thu, 2007-06-07 at 14:46 -0500, NZG wrote:
> > Yes, clearly.
> Ah, that in conjunction with the
> "can't use message pipe - Cannot allocate memory"
> thread resolves my issues then.
>
> My assumption was that data would exist in the pipe after the write until the
> pipe was destroyed, irrespective of the "openness" of the NRT side.
>
Nope, as a general rule, the read-side of an endpoint is flushed when
the other end closes. Then, you have also to take into account the
priority of the thread waiting on the endpoint wrt the priority of the
one which closes the other side.
For instance, if a RT thread is waiting for data (e.g. currently
sleeping on rt_pipe_read()) while the NRT side closes, then the RT
thread will be awaken, and a rescheduling will occur in the pipe release
routine before the input queue is eventually flushed, leaving the
opportunity for the RT side to consume the pending messages (since the
read-side has priority over the closing side in this situation).
What happened in your code is likely that the RT side was not actually
waiting for data, but maybe handling other duties while the NRT side
closed its endpoint. Yeah, that's a bit tricky, I agree, but in a
strictly prioritized system, this makes some sense.
> It's possible that this assumption is due to a lack of experience with pipes
> in general, I don't know.
>
Not really, fact is that we do have to deal with an asymmetric view of
the communication, i.e. RT / NRT, so there is room for specific
implementations. OTOH, regular Linux pipes won't give you more guarantee
on the read-side, you could just get a 0-bytes return from a read() to
notify the broken pipe condition.
Btw, do you happen to have CONFIG_XENO_OPT_NATIVE_PIPE_BUFSZ set to some
value in your .config?
> thank you for all you help,
> NZG
>
--
Philippe.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 20:14 ` Philippe Gerum
@ 2007-06-07 20:41 ` NZG
2007-06-07 22:09 ` [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion NZG
1 sibling, 0 replies; 11+ messages in thread
From: NZG @ 2007-06-07 20:41 UTC (permalink / raw)
To: rpm; +Cc: xenomai
On Thursday 07 June 2007 3:14 pm, Philippe Gerum wrote:
> Btw, do you happen to have CONFIG_XENO_OPT_NATIVE_PIPE_BUFSZ set to some
> value in your .config?
CONFIG_XENO_OPT_NATIVE_PIPE_BUFSZ=4096
NZG
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion
2007-06-07 20:14 ` Philippe Gerum
2007-06-07 20:41 ` NZG
@ 2007-06-07 22:09 ` NZG
2007-06-07 22:44 ` Philippe Gerum
1 sibling, 1 reply; 11+ messages in thread
From: NZG @ 2007-06-07 22:09 UTC (permalink / raw)
To: xenomai
On Thursday 07 June 2007 3:14 pm, Philippe Gerum wrote:
> On Thu, 2007-06-07 at 14:46 -0500, NZG wrote:
> > > Yes, clearly.
> >
> > Ah, that in conjunction with the
> > "can't use message pipe - Cannot allocate memory"
> > thread resolves my issues then.
> >
> > My assumption was that data would exist in the pipe after the write until
> > the pipe was destroyed, irrespective of the "openness" of the NRT side.
>
> Nope, as a general rule, the read-side of an endpoint is flushed when
> the other end closes. Then, you have also to take into account the
> priority of the thread waiting on the endpoint wrt the priority of the
> one which closes the other side.
So, if I wanted to use standard NRT calls in user space to wait for data to
actually be delivered through the rt pipe before closing the fd, what would
be the best method? Select? Or is there a simple call for this I'm missing?
thx,
NZG
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion
2007-06-07 22:09 ` [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion NZG
@ 2007-06-07 22:44 ` Philippe Gerum
2007-06-07 22:57 ` NZG
0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2007-06-07 22:44 UTC (permalink / raw)
To: NZG; +Cc: xenomai
On Thu, 2007-06-07 at 17:09 -0500, NZG wrote:
> On Thursday 07 June 2007 3:14 pm, Philippe Gerum wrote:
> > On Thu, 2007-06-07 at 14:46 -0500, NZG wrote:
> > > > Yes, clearly.
> > >
> > > Ah, that in conjunction with the
> > > "can't use message pipe - Cannot allocate memory"
> > > thread resolves my issues then.
> > >
> > > My assumption was that data would exist in the pipe after the write until
> > > the pipe was destroyed, irrespective of the "openness" of the NRT side.
> >
> > Nope, as a general rule, the read-side of an endpoint is flushed when
> > the other end closes. Then, you have also to take into account the
> > priority of the thread waiting on the endpoint wrt the priority of the
> > one which closes the other side.
> So, if I wanted to use standard NRT calls in user space to wait for data to
> actually be delivered through the rt pipe before closing the fd, what would
> be the best method? Select? Or is there a simple call for this I'm missing?
select() is supported, but it won't allow you to wait for the output
queue from the NRT-side to drain, it will only allow you to wait for
messages sent from the RT endpoint.
There is no simple call, I'm afraid. One way would be to make your RT
side always wait on the read-side (and process the messages as they
arrive); since the RT receiver would always have precedence over the NRT
sender, you would have the guarantee that all the messages sent have
been consumed before the NRT side closes its endpoint.
Another simple way would be to extend the pipe driver in order to
provide a new ioctl() function, returning the status of the RT input
queue, in which case, you would just have to loop issuing this ioctl()
until it reports that the RT side has consumed all the pending messages.
Not pretty, but would work.
The best way would be to extend our support for select(), in the poll
method the message pipe driver provides.
>
> thx,
> NZG
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Philippe.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion
2007-06-07 22:44 ` Philippe Gerum
@ 2007-06-07 22:57 ` NZG
0 siblings, 0 replies; 11+ messages in thread
From: NZG @ 2007-06-07 22:57 UTC (permalink / raw)
To: rpm; +Cc: xenomai
On Thursday 07 June 2007 5:44 pm, Philippe Gerum wrote:
> There is no simple call, I'm afraid. One way would be to make your RT
> side always wait on the read-side (and process the messages as they
> arrive); since the RT receiver would always have precedence over the NRT
> sender, you would have the guarantee that all the messages sent have
> been consumed before the NRT side closes its endpoint
I'm thinking this is the cleanest way, just spawn a separate RT thread of
lesser priority to my main rt loop, set it up to do nothing but read and
process messages, and put some locks on it.
thx,
NZG
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] writing from NRT to a rt_pipe
2007-06-07 18:57 [Xenomai-help] writing from NRT to a rt_pipe NZG
2007-06-07 19:13 ` NZG
@ 2007-06-07 19:33 ` Philippe Gerum
1 sibling, 0 replies; 11+ messages in thread
From: Philippe Gerum @ 2007-06-07 19:33 UTC (permalink / raw)
To: NZG; +Cc: xenomai
On Thu, 2007-06-07 at 13:57 -0500, NZG wrote:
> When writing from NRT to a real time pile (open, write, close).
> Are message boundaries preserved based upon the length of the write call?
>
It should yes, that's the main difference between this interface and
other RT fifo implementations. rt_pipe_stream() works the other way,
though (i.e. bytestream mode).
> It's not working for me. The code below returns success, but calling
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> or
> err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
>
> from RT space on the same pipe never returns any data
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),TM_NONBLOCK);
> always returns err
> 0x0b, Resource temporarily unavailable
>
> err = rt_pipe_read(comp,k,sizeof(kommand_t),100);
> always returns err:
> 0x6e, Connection timed out
>
Please send a compilable standalone test, so that we get a clear view of
what fails, and of the current runtime conditions when that fails.
> NZG
>
> code specifics follow...............
>
> int err;
> kommand_t k = {
> .type = KILLCYCLE,
> };
>
> int cfd = open(COMMANDPIPE, O_WRONLY|O_SYNC);
>
> if(cfd<0){
> printf("can't open %s (%s)\n",COMMANDPIPE, strerror(-cfd));
> fflush(stdout);
> return;
> }
>
> printf("sizeof kommand_t = %u\n",sizeof(kommand_t));
>
> err=write(cfd,&k,sizeof(kommand_t));
>
> if(err>=0)printf("wrote %u bytes to %s\n",err,COMMANDPIPE);
>
> if(err<0)printf("err writing to %s (%s)\n",COMMANDPIPE,
> strerror(errno));
>
>
> if(close(cfd)<0)printf("couldn't close %s\n",COMMANDPIPE);
>
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Philippe.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-06-07 22:57 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-07 18:57 [Xenomai-help] writing from NRT to a rt_pipe NZG
2007-06-07 19:13 ` NZG
2007-06-07 19:34 ` Philippe Gerum
2007-06-07 19:46 ` NZG
2007-06-07 19:51 ` NZG
2007-06-07 20:14 ` Philippe Gerum
2007-06-07 20:41 ` NZG
2007-06-07 22:09 ` [Xenomai-help] writing from NRT to a rt_pipe-> easy wait for completion NZG
2007-06-07 22:44 ` Philippe Gerum
2007-06-07 22:57 ` NZG
2007-06-07 19:33 ` [Xenomai-help] writing from NRT to a rt_pipe Philippe Gerum
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.