From: Philippe Gerum <rpm@xenomai.org>
To: Vincent Levesque <vleves@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] problem with rt_task_send() timeout and timer overruns
Date: Thu, 14 Sep 2006 15:58:22 +0200 [thread overview]
Message-ID: <1158242302.5040.121.camel@domain.hid> (raw)
In-Reply-To: <45087D79.50506@domain.hid>
On Wed, 2006-09-13 at 17:51 -0400, Vincent Levesque wrote:
> Hello all,
>
> I ran into some problems after moving working code to a slower machine
> and traced the problem down to the example attached at the bottom of
> this email. I've been using rt_task_send() to implement the equivalent
> of a function call, with an error code returned in the reply MCB's
> opcode field. In the example below, I send a message and expect a "666"
> opcode to be returned but I receive garbage at least on a few calls. The
> problem seems to occur when 1) the update rate in the sender is too high
> and 2) rt_task_send() has a timeout value (1 sec in the example.) If I
> increase MAIN_RATE_NS or set the TIMEOUT to TM_INFINITE everything seems
> to be ok. I've been able to reproduce this problem with xenomai 2.2.2
> (two PCs) and 2.1.3. In more complex versions of this code the reply
> data buffers also seemed to be invalid or corrupted.
>
Confirmed and reproduced, including over the simulator. The reason for
the invalid opcode is that rt_task_reply() signals an EXIO error, so the
return value is not filled in. The question is: why do we get this
error. More later.
> Looking at the docs, I'm not sure what to expect when rt_task_send()
> times out. It is returning 0 here. If I understand correctly, there is
> also no way to distinguish between an empty reply (with an opcode but no
> data buffer) and a NULL reply (i.e. rt_task_reply(flowid, NULL)). Could
> I be missing a rt_task_send() failure? If so, why would it fail here?
>
rt_task_reply(flowid, NULL) would always force the opcode field to zero.
Therefore, you should use non-zero return codes for valid messages,
whether they are empty or not.
> Thanks,
>
> Vincent Levesque
> vleves@domain.hid
>
> gcc -o test main.c `/usr/xenomai-2.2/bin/xeno-config --xeno-cflags`
> `/usr/xenomai-2.2/bin/xeno-config --xeno-ldflags` -lnative
>
> #include <sys/mman.h>
> #include <native/task.h>
>
> #define TIMEOUT ((RTIME)1E9)
> #define PEER_RATE_NS 100000
> #define MAIN_RATE_NS 5000000
> #define PEER_NB_ITER 50
>
> void run_peer(void *arg)
> {
> unsigned char buf[1024];
> RT_TASK_MCB mcb_rcv, mcb_reply;
> int flowid, i, rv;
>
> while (1)
> {
> mcb_rcv.data = (caddr_t)buf;
> mcb_rcv.size = sizeof(buf);
> flowid = rt_task_receive(&mcb_rcv,TM_INFINITE);
> if(flowid >= 0)
> {
> rt_task_set_periodic(NULL,TM_NOW,PEER_RATE_NS);
> for (i=0; i<PEER_NB_ITER; ++i)
> rt_task_wait_period(NULL);
> rt_task_set_periodic(NULL,TM_NOW,TM_INFINITE);
>
> mcb_reply.opcode = 666;
> mcb_reply.size = 0;
> mcb_reply.data = NULL;
> rt_task_reply(flowid, &mcb_reply);
> }
> }
> }
>
> int main(int argc, char *argv[])
> {
> int i, rv;
> RT_TASK task, peer_task;
> RT_TASK_MCB mcb_send, mcb_reply;
>
> mlockall(MCL_CURRENT | MCL_FUTURE);
>
> rt_task_spawn(&peer_task, "peer", 4096, 99, T_FPU, &run_peer, NULL);
> rt_task_shadow(&task, "user", 50, 0);
>
> rt_task_set_periodic(NULL,TM_NOW,MAIN_RATE_NS);
>
> for (i=0; i<10; ++i)
> {
> rt_task_wait_period(NULL);
> mcb_send.opcode = 0x02;
> mcb_send.data = NULL;
> mcb_send.size = 0;
> mcb_reply.size = 0;
> mcb_reply.data = NULL;
> rv = rt_task_send(&peer_task,&mcb_send,&mcb_reply,TIMEOUT);
> if (rv < 0) printf("rt_task_send error\n");
> if (mcb_reply.opcode != 666)
> printf("rv=%d, opcode=%d\n", rv, mcb_reply.opcode);
> }
>
> rt_task_delete(&peer_task);
> rt_task_delete(NULL);
>
> return 0;
> }
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Philippe.
next prev parent reply other threads:[~2006-09-14 13:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-13 21:51 [Xenomai-help] problem with rt_task_send() timeout and timer overruns Vincent Levesque
2006-09-14 13:58 ` Philippe Gerum [this message]
2006-09-14 14:57 ` Philippe Gerum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1158242302.5040.121.camel@domain.hid \
--to=rpm@xenomai.org \
--cc=vleves@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.