All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michel He <michel.he@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] RT_QUEUE problem in Sender/Receiver order
Date: Tue, 20 Apr 2010 17:21:51 +0200	[thread overview]
Message-ID: <20100420172151.825755sbp92ssdc0@domain.hid> (raw)
In-Reply-To: <4BCC8D2C.3070905@domain.hid>

Re,

    In order to describe it (by thousand words as the proverbe said),  
I attach the following example.
You notice that in the line 85 :
rv = rt_task_send(&test_task3_ptr,&mcb_send,&mcb_reply,task_period_ns);

whenever you change &test_task3_ptr to &test_task2_ptr, the message is  
NOT delivered at all. Only task3 can receive good msg. (not task2)

thank you


/*
  * tasksend.c
  *
  *  Created on: 7 avr. 2010
  *      Author: hemichel
  */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>

#define STACK_SIZE 8192
#define STD_PRIO 1


#define MAXRECVTASK 0
#define ANYSRC 0
#define MAX_MESSAGE_LENGTH 4
#define QUEUE_LIM 512
#define PROBECODE 0xa

RT_TASK test_task_ptr,test_task2_ptr,test_task3_ptr;

//tache maintenant la liste recvhostlist
RT_TASK *recvTask[MAXRECVTASK];
unsigned int nrecvhost=0;

int int_count = 0;
int end = 0;

//delay reception 0.1 s
#define PEER_RATE_NS 100000000

//cycle de la tache d'emission
//                     --s-ms-us-ns
RTIME task_period_ns =   1000000000llu;



void testtask(void *cookie) {
	RT_TASK_MCB mcb_send, mcb_reply;
	int flowid, i, rv;
	unsigned char datasend[16];
	unsigned char datareply[16];

	int count = 0;
	int ret;
	unsigned long overrun;
	ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns));
	if (ret) {
		rt_printf("error while set periodic, code %d\n",ret);
		return;
	}

	mcb_send.opcode = 0x03;
	datasend[0]='a';
	mcb_send.data = datasend;
	mcb_send.size = sizeof(datasend);

	mcb_reply.size = sizeof(datareply);
	mcb_reply.data = datareply;

	while(!end){

		if (ret) {
			rt_printf("error while rt_task_set_mode, code %d\n",ret);
			return;
		}
		ret = rt_task_wait_period(&overrun);
		if (ret) {
			rt_printf("error while rt_task_wait_period, code %d\n",ret);
			return;
		}
		count++;
		rt_printf("message from testtask: count=%d\n", count);

		rv = rt_task_send(&test_task3_ptr,&mcb_send,&mcb_reply,task_period_ns);
		if (rv < 0) rt_printf("rt_task_send error\n");
		else rt_printf("get mcb_reply=%d\n",mcb_reply.data[0]);
		fflush(NULL);
	}
}


void testtask2(void *cookie) {
	RT_TASK_MCB mcb_rcv, mcb_reply;
	int flowid, i, rv;
	unsigned char datareply[16];
	unsigned int taskmsg;
	int count = 0;
	int ret;
	unsigned long overrun;
	ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns));
	if (ret) {
		rt_printf("error while set periodic, code %d\n",ret);
		return;
	}

	while(!end){

		ret = rt_task_wait_period(&overrun);
		if (ret) {
			rt_printf("error while rt_task_wait_period, code %d\n",ret);
			return;
		}

		mcb_rcv.data = (caddr_t)&datareply;
		mcb_rcv.size = sizeof(datareply);

		flowid = rt_task_receive(&mcb_rcv,PEER_RATE_NS);
		rt_printf("%s flowid=%d opcode=%d\n",\
				__FUNCTION__, flowid, mcb_rcv.opcode);
		if(flowid >= 0)
		{
				//this is my answer
				mcb_reply.opcode = 1;
				mcb_reply.size = 1;
				mcb_reply.data = datareply;
				datareply[0]=100;
				rt_task_reply(flowid, &mcb_reply);
				rt_printf("task2 replied to Sender\n");
		}
		else
		{
			rt_printf("err task2 : flowid neg\n");
		}

		fflush(NULL);
	}
}


void testtask3(void *cookie) {
	RT_TASK_MCB mcb_rcv, mcb_reply;
	int flowid, i, rv;
	unsigned char datareply[16];
	unsigned int taskmsg;

	int count = 0;
	int ret;
	unsigned long overrun;
	ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns));
	if (ret) {
		rt_printf("error while set periodic, code %d\n",ret);
		return;
	}

	while(!end){

		ret = rt_task_wait_period(&overrun);
		if (ret) {
			rt_printf("error while rt_task_wait_period, code %d\n",ret);
			return;
		}

		mcb_rcv.data = (caddr_t)&datareply;
		mcb_rcv.size = sizeof(datareply);

		flowid = rt_task_receive(&mcb_rcv,PEER_RATE_NS);
		rt_printf("%s flowid=%d opcode=%d\n",\
				__FUNCTION__, flowid, mcb_rcv.opcode);
		if(flowid >= 0)
		{
				//this is my answer
				mcb_reply.opcode = 1;
				mcb_reply.size = 1;
				mcb_reply.data = datareply;
				datareply[0]=100;
				rt_task_reply(flowid, &mcb_reply);
				rt_printf("task3 replied to Sender\n");
		}
		else
		{
			rt_printf("err task3 : flowid neg\n");
		}

		fflush(NULL);
	}
}


// signal-handler, to ensure clean exit on Ctrl-C
void clean_exit(int dummy) {
	rt_printf("cleanup\n");
	end = 1;
	rt_task_delete(&test_task_ptr);
	rt_printf("end\n");
}

int main(int argc, char *argv[]) {
	int err, ret;
	int itask;


	// install signal handler
	signal(SIGTERM, clean_exit);
	signal(SIGINT, clean_exit);

	mlockall(MCL_CURRENT | MCL_FUTURE);

	/* Perform auto-init of rt_print buffers if the task doesn't do so */
	rt_print_auto_init(1);

	//Initialisation de Dispatch Sender
	for (itask=0; itask < nrecvhost; itask++)
	{
		recvTask[itask]=NULL;
	}

	err = rt_task_spawn(&test_task_ptr, "Timer", STACK_SIZE, STD_PRIO, 0,  
&testtask, NULL);
	recvTask[nrecvhost]=&test_task_ptr;
	nrecvhost++;
	if (err) {
		rt_printf("error rt_task_spawn\n");
		return 0;
	}

	nrecvhost=0;
	rt_printf("Fin Initialisation de la tache Emetteur\n");

	err = rt_task_spawn(&test_task2_ptr, "Timer2", STACK_SIZE, STD_PRIO,  
0, &testtask2, NULL);
	recvTask[nrecvhost]=&test_task2_ptr;
	nrecvhost++;
	if (err) {
		rt_printf("error rt_task_spawn\n");
		return 0;
	}


	err = rt_task_spawn(&test_task3_ptr, "Timer3", STACK_SIZE, STD_PRIO,  
0, &testtask3, NULL);
	recvTask[nrecvhost]=&test_task3_ptr;
	nrecvhost++;
	if (err) {
		rt_printf("error rt_task_spawn\n");
		return 0;
	}



	// wait for signal & return of signal handler
	pause();
	fflush(NULL);
	return 0;
}


Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org> a écrit :

> Michel He wrote:
>> hello everyone,
>>
>>     I find out a problem (it seems already mentionned before but I
>> can't find the link to the forum and the post). It deals with the
>> message passing, eg. when we change the order of task execution,
>> something can get wrong. Notice that codes below, if we launch the
>> exection of Recep2,Recep3,Sender, Recep2 won't get the right message.
>> But if we change the order to : Sender,Recep2,Recep3, everything is
>> back to OK. So any explanation ?
>
> A piece of self-contained code, compiling and demonstrating a bug when
> running is worth a thousand words.
>
>
> --
> 					    Gilles.
>




  reply	other threads:[~2010-04-20 15:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-19 17:01 [Xenomai-help] RT_QUEUE problem in Sender/Receiver order Michel He
2010-04-19 17:04 ` Gilles Chanteperdrix
2010-04-20 15:21   ` Michel He [this message]
2010-04-19 17:16 ` Philippe Gerum
2010-04-20  4:46   ` Josh Bowman
2010-04-20  8:22     ` Philippe Gerum
2010-04-20 10:20       ` Michel He

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=20100420172151.825755sbp92ssdc0@domain.hid \
    --to=michel.he@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.