Skip to contentSkip to conversation

Problem with rt_queue

Xenomai-help Applied mani bhatti 3 participants 14 messages Oct 16, 2006 – Dec 6, 2006

lore
Share & tools
lore
#0 lore raw

Hi all
I am trying to broadcast a message to a queue from a producer by using function

rt_queue_send(&queue_input, msg,sizeof(TInputData), Q_BROADCAST);

I have two consumers waiting for the data from producer but the problem is producer is not broadcasting actually to all consumers and at one time if i run both consumers than only one of the consumer receives the data from producer the other consumer receives nothing and remains blank (the consumer which receives data from queue is not fixed it is arbitrary).If some one has encountered the problem before please advice me in this regard-Thanks all.The producer code is given below

 while(!end){
               rt_task_wait_period();
               void *msg = rt_queue_alloc(&queue_input, sizeof(TInputData));
                if(msg == NULL) {
                        printf("rt_queue_alloc(queue_inout, %d) failed\n",sizeof(TInputData));
                     }
                memcpy(msg, &sendData, sizeof(TInputData));
                int bytesSent = rt_queue_send(&queue_input,msg,sizeof(TInputData), Q_BROADCAST);
                if (bytesSent <= 0) {
                        printf("rt_queue_send(queue_input) failed: %d\n", bytesSent);
                        rt_queue_free(&queue_input, msg);
                }
                sendData.counter++;
        }

---------------------------------
Do you Yahoo!?
Get on board. You're invited to try the new Yahoo! Mail.

#1 lore raw
Quoted 7 lines · mani bhatti

Hi all
I am trying to broadcast a message to a queue from a producer by using function

rt_queue_send(&queue_input, msg,sizeof(TInputData), Q_BROADCAST);

I have two consumers waiting for the data from producer but the problem is producer is not broadcasting actually to all consumers and at one time if i run both consumers than only one of the consumer receives the data from producer the other consumer receives nothing and remains blank (the consumer which receives data from queue is not fixed it is arbitrary).If some one has encountered the problem before please advice me in this regard-Thanks all.The producer code is given below

Quoted 15 lines
 while(!end){
               rt_task_wait_period();
               void *msg = rt_queue_alloc(&queue_input, sizeof(TInputData));
                if(msg == NULL) {
                        printf("rt_queue_alloc(queue_inout, %d) failed\n",sizeof(TInputData));
                     }
                memcpy(msg, &sendData, sizeof(TInputData));
                int bytesSent = rt_queue_send(&queue_input,msg,sizeof(TInputData), Q_BROADCAST);
                if (bytesSent <= 0) {
                        printf("rt_queue_send(queue_input) failed: %d\n", bytesSent);
                        rt_queue_free(&queue_input, msg);
                }
                sendData.counter++;
        }

May I cite myself?

https://mail.gna.org/public/xenomai-help/2006-10/msg00032.html

Don't get me wrong, your observation might very well have revealed a Xenomai bug, but it is *far* easier for us poor hackers to analyse and discuss the issue based on *common* test code.

Thanks,
Jan

#2 lore raw
In reply to mani bhatti
Quoted 6 lines · mani bhatti

Hi all
I am trying to broadcast a message to a queue from a producer by using function

rt_queue_send(&queue_input, msg,sizeof(TInputData), Q_BROADCAST);

Quoted 8 lines

I have two consumers waiting for the data from producer but the problem is producer is not broadcasting actually to all consumers and at one time if i run both consumers than only one of the consumer receives the data from producer the other consumer receives nothing and remains blank (the consumer which receives data from queue is not fixed it is arbitrary).If some one has encountered the problem before please advice me in this regard-Thanks all.The producer code is given below

Excerpt from the documentation:

* - Q_BROADCAST causes the message to be sent to all tasks currently
* waiting for messages. [...]

Are both consumers actually aslept on the queue, waiting for a message? If so, then please send a compilable testcase that reproduces the issue, with the consumer part, too.

Quoted 31 lines

while(!end){
rt_task_wait_period();
void *msg = rt_queue_alloc(&queue_input,
sizeof(TInputData));
if(msg == NULL) {
printf("rt_queue_alloc(queue_inout, %d) failed

\n",sizeof(TInputData));
                     }
                memcpy(msg, &sendData, sizeof(TInputData));
                int bytesSent =
rt_queue_send(&queue_input,msg,sizeof(TInputData), Q_BROADCAST);
                if (bytesSent <= 0) {
                        printf("rt_queue_send(queue_input) failed: %d
\n", bytesSent);
                        rt_queue_free(&queue_input, msg);
                }
                sendData.counter++;
        }

______________________________________________________________________
Do you Yahoo!?
Get on board. You're invited to try the new Yahoo! Mail.
_______________________________________________
Xenomai-help mailing list [email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#3 lore raw

Hi Phillipe and Jan
Thanks a lot for your help.I am sending the compilable source code so that you have an idea what wrong am i doing.I am sending the listeners which are listening to the same queue at the same time.But i dont know why at one time only one listener receives data from sender queue inspite of that i am using broadcast mode.Thanks a lot.I have attached files for sender and listener.

Quoted 53 lines · --- Philippe Gerum
Quoted 2 lines · mani bhatti

Hi all
I am trying to broadcast a message to a queue

from a producer by

Quoted 3 lines

using function

rt_queue_send(&queue_input,

msg,sizeof(TInputData), Q_BROADCAST);

Quoted 2 lines

I have two consumers waiting for the data from

producer but the

Quoted 1 line

problem is producer is not broadcasting actually

to all consumers and

Quoted 1 line

at one time if i run both consumers than only one

of the consumer

Quoted 1 line

receives the data from producer the other consumer

receives nothing

Quoted 1 line

and remains blank (the consumer which receives

data from queue is not

Quoted 1 line

fixed it is arbitrary).If some one has encountered

the problem before

Quoted 1 line

please advice me in this regard-Thanks all.The

producer code is given

Quoted 1 line

below

Excerpt from the documentation:

* - Q_BROADCAST causes the message to be sent to
all tasks currently
* waiting for messages. [...]

Are both consumers actually aslept on the queue, waiting for a message?
If so, then please send a compilable testcase that reproduces the issue,
with the consumer part, too.

Quoted 4 lines

while(!end){
rt_task_wait_period();
void *msg =

rt_queue_alloc(&queue_input,

Quoted 3 lines
sizeof(TInputData));
                if(msg == NULL) {

printf("rt_queue_alloc(queue_inout, %d) failed

Quoted 3 lines
\n",sizeof(TInputData));
                     }
                memcpy(msg, &sendData,

sizeof(TInputData));

Quoted 2 lines

int bytesSent =
rt_queue_send(&queue_input,msg,sizeof(TInputData),

Quoted 17 lines

Q_BROADCAST);

Quoted 2 lines
                if (bytesSent <= 0) {

printf("rt_queue_send(queue_input) failed: %d

Quoted 2 lines

\n", bytesSent);

rt_queue_free(&queue_input, msg);

Quoted 9 lines
                }
                sendData.counter++;
        }

______________________________________________________________________

Quoted 12 lines
Quoted 2 lines

Do you Yahoo!?
Get on board. You're invited to try the new Yahoo!

Mail.

Quoted 4 lines

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#include <math.h>
#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_PRIO1 2
#define STD_PRIO2 1
#define QUEUE_INPUT_LEN 1024
#define USE_READ_WRITE
RT_TASK zaehler1_task_ptr;
RT_TASK zaehler2_task_ptr;
int count1 = 0;
int count2 = 0;
int i;
int end = 0;

typedef struct  {
	int counter;
	int data;
}TInputData;

RT_QUEUE queue_input;

// --s-ms-us-ns
RTIME task_period_ns1 = 10000000llu;
RTIME task_period_ns2 = 10000000llu;

void zaehler1_task(void *cookie){

  int ret;
  TInputData sendData;
   memset(&sendData, 0, sizeof(TInputData));

// ************************* Xenomai-Krempel ********************************************************************

        ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns1));
        if (ret) {
                printf("error while set periodic, code %d\n",ret);
                return;
        }

// ************************* Ende Xenomai-Krempel ****************************************************************

// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************

        while(!end){
            
               rt_task_wait_period();


		void *msg = rt_queue_alloc(&queue_input, sizeof(TInputData));
		if(msg == NULL) {
			printf("rt_queue_alloc(queue_inout, %d) failed\n", sizeof(TInputData));
			
                     }
		memcpy(msg, &sendData, sizeof(TInputData));
		int bytesSent = rt_queue_send(&queue_input, msg,sizeof(TInputData), Q_BROADCAST);
		if (bytesSent <= 0) {
			printf("rt_queue_send(queue_input) failed: %d\n", bytesSent);
			rt_queue_free(&queue_input, msg);
			
		}

		sendData.counter++;  







        }

// ********************** Ende des wiederholt ausgefuehrten Codes *********************************************** }

// signal-handler, to ensure clean exit on Ctrl-C

void clean_exit(int dummy) {
	printf("cleanup\n");
	end = 1;
	rt_task_delete(&zaehler1_task_ptr);
	rt_task_delete(&zaehler2_task_ptr);
	printf("end\n");
}
int main(int argc, char *argv[]) {
	int err, ret;
	
       int res;
	res = mlockall(MCL_CURRENT | MCL_FUTURE);
	if (res < 0) {
		printf("mlockall failed: %d\n", res);
		
	}
        // INPUT_QUEUE
	res = rt_queue_create(&queue_input, "queue_input", sizeof(TInputData) * QUEUE_INPUT_LEN,
		QUEUE_INPUT_LEN, Q_FIFO | Q_SHARED);
	if (res == -EEXIST)  {
		res = rt_queue_bind(&queue_input, "queue_input", 1000);
		//rt_queue_clear(&queue_input);
	}
	if (res < 0) {
		printf("rt_queue_create(queue_input) failed: %d\n", res);
		
	}

	

 
       printf("start\n");
	// install signal handler
	signal(SIGTERM, clean_exit);	
	signal(SIGINT, clean_exit);	
	// start timer
	ret = rt_timer_start(TM_ONESHOT);
	switch (ret) {
		case 0:       printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
		              break;
		case -EBUSY:  printf("timer is running\n");
		              break;
		case -ENOSYS: printf("can't start timer\n");
		              return ret;
	}

	/* create zaehler1_task */
	err = rt_task_create(&zaehler1_task_ptr,"alpha",STACK_SIZE,STD_PRIO1,0);
	
	/* start zaehler1_task */
	err = rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL);

	

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

#include <math.h>
#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_PRIO1 2
#define STD_PRIO2 1
#define QUEUE_INPUT_LEN 1024
#define USE_READ_WRITE
RT_TASK zaehler1_task_ptr;
RT_TASK zaehler2_task_ptr;
int count1 = 0;
int count2 = 0;
int i;
int end = 0;

typedef struct  {
	int counter;
	int data;
}TInputData;

RT_QUEUE queue_input;

// --s-ms-us-ns
RTIME task_period_ns1 = 1000000000llu;
RTIME task_period_ns2 = 1000000000llu;

void zaehler2_task(void *cookie){
	int ret;	
	long ii;
	long jj;
	double a;


        TInputData receiveData;
	receiveData.counter = -1;

// ************************* Xenomai-Krempel ********************************************************************

	ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns2));
	if (ret) {
		printf("error while set periodic, code %d\n",ret);
		return;
	}

// ************************* Ende Xenomai-Krempel ****************************************************************

// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************

	while(!end){
		
              int counter = receiveData.counter;
               
               void *msg;
		int bytesRead = rt_queue_recv(&queue_input, &msg, TM_INFINITE);
		if (bytesRead > 0) {
			memcpy(&receiveData, msg, sizeof(TInputData));
			rt_queue_free(&queue_input, msg);
		}
		if (bytesRead <=0) {
			printf("rt_queue_receive(queue_input) failed: %d\n", bytesRead);
			
		}

		else if (receiveData.counter != counter + 1) {
			printf("counter error: %d\t->\t%d\n", counter + 1, receiveData.counter);
		} else {
			printf("Data received from main is %d\n", receiveData.counter);
		}
      



        }

// ********************** Ende des wiederholt ausgefuehrten Codes *********************************************** }

// signal-handler, to ensure clean exit on Ctrl-C

void clean_exit(int dummy) {
	printf("cleanup\n");
	end = 1;
	rt_task_delete(&zaehler1_task_ptr);
	rt_task_delete(&zaehler2_task_ptr);
	printf("end\n");
}
int main(int argc, char *argv[]) {
	int err, ret;
	
       int res;
	res = mlockall(MCL_CURRENT | MCL_FUTURE);
	if (res < 0) {
		printf("mlockall failed: %d\n", res);
		
	}
     
      
		res = rt_queue_bind(&queue_input, "queue_input", 1000);
		//rt_queue_clear(&queue_input);
	
	if (res < 0) {
		printf("rt_queue_create(queue_input) failed: %d\n", res);
		
	}

	

 
       printf("start\n");
	// install signal handler
	signal(SIGTERM, clean_exit);	
	signal(SIGINT, clean_exit);	
	// start timer
	ret = rt_timer_start(TM_ONESHOT);
	switch (ret) {
		case 0:       printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
		              break;
		case -EBUSY:  printf("timer is running\n");
		              break;
		case -ENOSYS: printf("can't start timer\n");
		              return ret;
	}

	/* create zaehler2_task */
	err = rt_task_create(&zaehler2_task_ptr,"beta",STACK_SIZE,STD_PRIO2,0);
	/* start zaehler2_task */
	err = rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL);

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

#include <math.h>
#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_PRIO1 2
#define STD_PRIO2 1
#define QUEUE_INPUT_LEN 1024
#define USE_READ_WRITE
RT_TASK zaehler1_task_ptr;
RT_TASK zaehler2_task_ptr;
int count1 = 0;
int count2 = 0;
int i;
int end = 0;

typedef struct  {
	int counter;
	int data;
}TInputData;

RT_QUEUE queue_input;

// --s-ms-us-ns
RTIME task_period_ns1 = 1000000000llu;
RTIME task_period_ns2 = 1000000000llu;

void zaehler2_task(void *cookie){
	int ret;	
	long ii;
	long jj;
	double a;


        TInputData receiveData;
	receiveData.counter = -1;

// ************************* Xenomai-Krempel ********************************************************************

	ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns2));
	if (ret) {
		printf("error while set periodic, code %d\n",ret);
		return;
	}

// ************************* Ende Xenomai-Krempel ****************************************************************

// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************

	while(!end){
		
              int counter = receiveData.counter;
               
               void *msg;
		int bytesRead = rt_queue_recv(&queue_input, &msg, TM_INFINITE);
		if (bytesRead > 0) {
			memcpy(&receiveData, msg, sizeof(TInputData));
			rt_queue_free(&queue_input, msg);
		}
		if (bytesRead <=0) {
			printf("rt_queue_receive(queue_input) failed: %d\n", bytesRead);
			
		}

		else if (receiveData.counter != counter + 1) {
			printf("counter error: %d\t->\t%d\n", counter + 1, receiveData.counter);
		} else {
			printf("Data received from main is %d\n", receiveData.counter);
		}
      



        }

// ********************** Ende des wiederholt ausgefuehrten Codes *********************************************** }

// signal-handler, to ensure clean exit on Ctrl-C

void clean_exit(int dummy) {
	printf("cleanup\n");
	end = 1;
	rt_task_delete(&zaehler1_task_ptr);
	rt_task_delete(&zaehler2_task_ptr);
	printf("end\n");
}
int main(int argc, char *argv[]) {
	int err, ret;
	
       int res;
	res = mlockall(MCL_CURRENT | MCL_FUTURE);
	if (res < 0) {
		printf("mlockall failed: %d\n", res);
		
	}
        // INPUT_QUEUE
//	res = rt_queue_create(&queue_input, "queue_input", sizeof(TInputData) * QUEUE_INPUT_LEN,
//		QUEUE_INPUT_LEN, Q_FIFO | Q_SHARED);
//	if (res == -EEXIST)  
      {
		res = rt_queue_bind(&queue_input, "queue_input", 1000);
		//rt_queue_clear(&queue_input);
	}
	if (res < 0) {
		printf("rt_queue_create(queue_input) failed: %d\n", res);
		
	}

	

 
       printf("start\n");
	// install signal handler
	signal(SIGTERM, clean_exit);	
	signal(SIGINT, clean_exit);	
	// start timer
	ret = rt_timer_start(TM_ONESHOT);
	switch (ret) {
		case 0:       printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
		              break;
		case -EBUSY:  printf("timer is running\n");
		              break;
		case -ENOSYS: printf("can't start timer\n");
		              return ret;
	}


	/* create zaehler2_task */
	err = rt_task_create(&zaehler2_task_ptr,"beta",STACK_SIZE,STD_PRIO2,0);

	/* start zaehler2_task */
	err = rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL);

	// wait for signal & return of signal handler
	pause();
	fflush(NULL);
	return 0;
}
#4 lore raw
Quoted 9 lines · mani bhatti

Hi Phillipe and Jan
Thanks a lot for your help.I am sending the compilable source code so that you have an idea what wrong am i doing.I am sending the listeners which are listening to the same queue at the same time.But i dont know why at one time only one listener receives data from sender queue inspite of that i am using broadcast mode.Thanks a lot.I have attached files for sender and listener.

Well, interesting test case. It actually revealed bugs, but not where expected.

Your problem is a simple bug in the listener tests. They both register a task of the name "beta", only the first one succeeds (your code is a bit hackish in this regard - when hunting problems, make sure to check ALL return codes for potential problems!). Once fixed, your code runs fine here.

Nevertheless, queue_sender by itself uncovered a problem of rt_queue_send in broadcast mode when no one is listening. The message reference count got messed up and the queue ran out of memory. The attached patch fixes it:

Jan

skins/native/queue.c +3 -1
Index: ksrc/skins/native/queue.c
===================================================================
@@ -631,7 +631,9 @@ int rt_queue_send(RT_QUEUE *q, void *mbu
 			prependq(&q->pendq, &msg->link);
 		else
 			appendq(&q->pendq, &msg->link);
-	}
+	} else
+		/* Ownership did not change, so update reference count. */
+		msg->refcount++;
 
 	err = nrecv;
 
ChangeLog +5 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,8 @@
+2006-10-26  Jan Kiszka  <[email protected]>
+
+	* ksrc/skins/native/queue.c (rt_queue_send): Track message count
+	correctly when broadcasting to a queue without listeners.
+
 2006-10-25  Jan Kiszka  <[email protected]>
 
 	* ksrc/drivers/testing/irqbench.c, doc/txt/irqbench.txt,
#5 lore raw

Thanks a lot Jan for the reply.Now after changing the task name queue is working but
following message is displayed by the sender if there is no queue which you had pointed in the last email. rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

Actually i dont understand about the patch which you had sent in your last email (because patch seems to be incomple to me ) because that seems to be part of xenomai source code and if that is how can i use that source code in my program for solving my problem i mean at which place in my program should i put that patch .Sorry for your inconvenience.thanks.

Jan Kiszka <[email protected]> wrote:

Quoted 9 lines · mani bhatti

Hi Phillipe and Jan
Thanks a lot for your help.I am sending the compilable source code so that you have an idea what wrong am i doing.I am sending the listeners which are listening to the same queue at the same time.But i dont know why at one time only one listener receives data from sender queue inspite of that i am using broadcast mode.Thanks a lot.I have attached files for sender and listener.

Well, interesting test case. It actually revealed bugs, but not where expected.

Your problem is a simple bug in the listener tests. They both register a task of the name "beta", only the first one succeeds (your code is a bit hackish in this regard - when hunting problems, make sure to check ALL return codes for potential problems!). Once fixed, your code runs fine here.

Nevertheless, queue_sender by itself uncovered a problem of rt_queue_send in broadcast mode when no one is listening. The message reference count got messed up and the queue ran out of memory. The attached patch fixes it:

Jan

skins/native/queue.c (Arbeitskopie) renamed from skins/native/queue.c (Revision 1747) +0 -0
Index: ksrc/skins/native/queue.c
===================================================================
@@ -631,7 +631,9 @@ int rt_queue_send(RT_QUEUE *q, void *mbu

prependq(&q->pendq, &msg->link);
else
appendq(&q->pendq, &msg->link);
- }
+ } else
+ /* Ownership did not change, so update reference count. */
+ msg->refcount++;

err = nrecv;

ChangeLog (Arbeitskopie) renamed from ChangeLog (Revision 1748) +5 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,8 @@
+2006-10-26 Jan Kiszka 
+
+ * ksrc/skins/native/queue.c (rt_queue_send): Track message count
+ correctly when broadcasting to a queue without listeners.
+

2006-10-25 Jan Kiszka

* ksrc/drivers/testing/irqbench.c, doc/txt/irqbench.txt,

---------------------------------
All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.

#6 lore raw
Quoted 7 lines · mani bhatti

Thanks a lot Jan for the reply.Now after changing the task name queue is working but
following message is displayed by the sender if there is no queue which you had pointed in the last email. rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

Actually i dont understand about the patch which you had sent in your last email (because patch seems to be incomple to me ) because that seems to be part of xenomai source code and if that is how can i use that source code in my program for solving my problem i mean at which place in my program should i put that patch .Sorry for your inconvenience.thanks.

Goto xenomai source directory and execute

# patch -p0 < native-queue-bcast-fix.patch

But I guess the patch will soon be SVN as well fixing your problem.

Jan

#7 lore raw

Thanks Jan .
I have executed # patch -p0 < native-queue-bcast-fix.patch in directory where xenomai is installed and in my case it is /usr/xenomai directory but sender still goes out of memory if no listener is waiting on the queue and displays the message

rt_queue_alloc(queue_inout, 8) failed

After this message is displayed and i try to execute sender again then sender doesnot execute at all and simply displays above message so i need to restart my computer if i want to eecute sender again .Should i execute patch in some other directory or is it some other problem? Thanks for the help.

Quoted 7 lines · Jan Kiszka <[email protected]> wrote: mani bhatti wrote:

Thanks a lot Jan for the reply.Now after changing the task name queue is working but
following message is displayed by the sender if there is no queue which you had pointed in the last email. rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

Actually i dont understand about the patch which you had sent in your last email (because patch seems to be incomple to me ) because that seems to be part of xenomai source code and if that is how can i use that source code in my program for solving my problem i mean at which place in my program should i put that patch .Sorry for your inconvenience.thanks.

Goto xenomai source directory and execute

# patch -p0 < native-queue-bcast-fix.patch

But I guess the patch will soon be SVN as well fixing your problem.

Jan

---------------------------------
Get your email and see which of your friends are online - Right on the new Yahoo.com

#8 lore raw
Quoted 6 lines · mani bhatti

Thanks Jan .
I have executed # patch -p0 < native-queue-bcast-fix.patch in directory where xenomai is installed and in my case it is /usr/xenomai directory but sender still goes out of memory if no listener is waiting on the queue and displays the message

rt_queue_alloc(queue_inout, 8) failed

After this message is displayed and i try to execute sender again then sender doesnot execute at all and simply displays above message so i need to restart my computer if i want to eecute sender again .Should i execute patch in some other directory or is it some other problem?

Nope. Executing your original test case after applying my patch (AND rebuilding Xenomai - did you check if the kernel you run got updated?) clearly demonstrated on my box that the problem was fixed.

I would suggest to do a clean rebuild from latest SVN.

Jan

#9 lore raw

[Xenomai-help] problem persists with rt_queue

Hi
I had a problem of rt_queue overflow in xenomai 2.1.Then installed xenomai 2.2.5 but previous poblem with rt_queue is still there.I repeat the problem that when there is no listener on the queue the sender the sender displays the error message

rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_alloc(queue_inout, 8) failed

and then stops and if i try to start my program again following message

start
rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

is displayed and program doesnot work at all.I would be very thankful for the correcting me what wrong am i doing.the code for the sender is attached.

Quoted 6 lines · Jan Kiszka <[email protected]> wrote: mani bhatti wrote:

Thanks Jan .
I have executed # patch -p0 < native-queue-bcast-fix.patch in directory where xenomai is installed and in my case it is /usr/xenomai directory but sender still goes out of memory if no listener is waiting on the queue and displays the message

rt_queue_alloc(queue_inout, 8) failed

After this message is displayed and i try to execute sender again then sender doesnot execute at all and simply displays above message so i need to restart my computer if i want to eecute sender again .Should i execute patch in some other directory or is it some other problem?

Nope. Executing your original test case after applying my patch (AND rebuilding Xenomai - did you check if the kernel you run got updated?) clearly demonstrated on my box that the problem was fixed.

I would suggest to do a clean rebuild from latest SVN.

Jan

---------------------------------
Any questions? Get answers on any topic at Yahoo! Answers. Try it now.

#include <math.h>
#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_PRIO1 2
#define STD_PRIO2 1
#define QUEUE_INPUT_LEN 1024
#define USE_READ_WRITE
RT_TASK zaehler1_task_ptr;
RT_TASK zaehler2_task_ptr;
int count1 = 0;
int count2 = 0;
int i;
int end = 0;

typedef struct  {
	int counter;
	int data;
}TInputData;

int missedpackets=0;

RT_QUEUE queue_input;

// --s-ms-us-ns
RTIME task_period_ns1 = 10000000llu;
RTIME task_period_ns2 = 10000000000llu;

void zaehler1_task(void *cookie){

  int ret;
  TInputData sendData;
   memset(&sendData, 0, sizeof(TInputData));

// ************************* Xenomai-Krempel ********************************************************************

        ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns1));
        if (ret) {
                printf("error while set periodic, code %d\n",ret);
                return;
        }

// ************************* Ende Xenomai-Krempel ****************************************************************

// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************

        while(!end){
            
               rt_task_wait_period(NULL);


		void *msg = rt_queue_alloc(&queue_input, sizeof(TInputData));
		if(msg == NULL) {
			printf("rt_queue_alloc(queue_inout, %d) failed\n", sizeof(TInputData));
			
                     }
		memcpy(msg, &sendData, sizeof(TInputData));
		int bytesSent = rt_queue_send(&queue_input, msg,sizeof(TInputData), Q_BROADCAST);
		
                  if (bytesSent <= 0) {
		  	
                    printf("rt_queue_send(queue_input) failed sent bytes: %d\n", bytesSent);
			rt_queue_free(&queue_input, msg);
		 	
		}

		
                sendData.counter++;  
      }

// ********************** Ende des wiederholt ausgefuehrten Codes *********************************************** }

// signal-handler, to ensure clean exit on Ctrl-C

void clean_exit(int dummy) {
	printf("cleanup\n");
	end = 1;
	rt_task_delete(&zaehler1_task_ptr);
	rt_task_delete(&zaehler2_task_ptr);
	printf("end\n");
}
int main(int argc, char *argv[]) {
	int err, ret;
	
       int res;
	res = mlockall(MCL_CURRENT | MCL_FUTURE);
	if (res < 0) {
		printf("mlockall failed: %d\n", res);
		
	}
        // INPUT_QUEUE
	res = rt_queue_create(&queue_input, "queue_input", sizeof(TInputData) * QUEUE_INPUT_LEN,
		QUEUE_INPUT_LEN, Q_FIFO | Q_SHARED);
	if (res == -EEXIST)  {
		res = rt_queue_bind(&queue_input, "queue_input", 1000);
		//rt_queue_clear(&queue_input);
	}
	if (res < 0) {
		printf("rt_queue_create(queue_input) failed: %d\n", res);
		
	}

	

 
       printf("start\n");
	// install signal handler
	signal(SIGTERM, clean_exit);	
	signal(SIGINT, clean_exit);	

	/* create zaehler1_task */
	err = rt_task_create(&zaehler1_task_ptr,"alpha",STACK_SIZE,STD_PRIO1,0);

	/* start zaehler1_task */
	err = rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL);

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

[Xenomai-help] Re: problem persists with rt_queue

Quoted 9 lines · mani bhatti

Hi
I had a problem of rt_queue overflow in xenomai 2.1.Then installed xenomai 2.2.5 but previous poblem with rt_queue is still there.I repeat the problem that when there is no listener on the queue the sender the sender displays the error message

rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_alloc(queue_inout, 8) failed

Quoted 7 lines

and then stops and if i try to start my program again following message

start
rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

is displayed and program doesnot work at all.I would be very thankful for the correcting me what wrong am i doing.the code for the sender is attached.

...and your code still runs fine (SVN trunk, but the required patch is in 2.2.5 as well). Moreover, stopping and restarting also causes no problem.

So, please check:

- content of /proc/xenomai/version

If this actually gives "2.2.5":

- run the test over SVN trunk (make sure you actually run trunk via /proc/xenomai/version, should give "2.3-rc2")

- report your findings

Again, *precisely* your problem was understood, fixed, and applied to both branches. It should really not show up the same way as before.

Jan

#11 lore raw

[Xenomai-help] Re: problem persists with rt_queue

Hi
Please tell me how can i do the following

run the test over SVN trunk

Thanks a lot for the gr8 help Jan.

Quoted 9 lines · Jan Kiszka <[email protected]> wrote: mani bhatti wrote:

Hi
I had a problem of rt_queue overflow in xenomai 2.1.Then installed xenomai 2.2.5 but previous poblem with rt_queue is still there.I repeat the problem that when there is no listener on the queue the sender the sender displays the error message

rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_send(queue_input) failed sent bytes: 0
rt_queue_alloc(queue_inout, 8) failed

Quoted 7 lines

and then stops and if i try to start my program again following message

start
rt_queue_alloc(queue_inout, 8) failed
Segmentation fault

is displayed and program doesnot work at all.I would be very thankful for the correcting me what wrong am i doing.the code for the sender is attached.

...and your code still runs fine (SVN trunk, but the required patch is in 2.2.5 as well). Moreover, stopping and restarting also causes no problem.

So, please check:

- content of /proc/xenomai/version

If this actually gives "2.2.5":

- run the test over SVN trunk (make sure you actually run trunk via /proc/xenomai/version, should give "2.3-rc2")

- report your findings

Again, *precisely* your problem was understood, fixed, and applied to both branches. It should really not show up the same way as before.

Jan

---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.

#12 lore raw

[Xenomai-help] Re: problem persists with rt_queue

Quoted 4 lines · mani bhatti

Hi
Please tell me how can i do the following

run the test over SVN trunk

Check https://gna.org/svn/?group=xenomai on how to obtain the code. The rest is as usual.

Jan

#13 lore raw
In reply to Jan Kiszka
Quoted 5 lines · Jan Kiszka

Nevertheless, queue_sender by itself uncovered a problem of rt_queue_send in broadcast mode when no one is listening. The message reference count got messed up and the queue ran out of memory. The attached patch fixes it:

Applied, thanks.

Quoted 1 line

Jan

Signature · 1 line
Philippe.