All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Problem with rt_queue
@ 2006-10-16 15:39 mani bhatti
  2006-10-16 15:50 ` Jan Kiszka
  2006-10-16 15:58 ` Philippe Gerum
  0 siblings, 2 replies; 14+ messages in thread
From: mani bhatti @ 2006-10-16 15:39 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 2705 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-16 15:39 [Xenomai-help] Problem with rt_queue mani bhatti
@ 2006-10-16 15:50 ` Jan Kiszka
  2006-10-16 15:58 ` Philippe Gerum
  1 sibling, 0 replies; 14+ messages in thread
From: Jan Kiszka @ 2006-10-16 15:50 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1713 bytes --]

mani bhatti wrote:
> 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++;
>         }
> 

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-16 15:39 [Xenomai-help] Problem with rt_queue mani bhatti
  2006-10-16 15:50 ` Jan Kiszka
@ 2006-10-16 15:58 ` Philippe Gerum
  2006-10-25 14:34   ` mani bhatti
  1 sibling, 1 reply; 14+ messages in thread
From: Philippe Gerum @ 2006-10-16 15:58 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

On Mon, 2006-10-16 at 08:39 -0700, mani bhatti wrote:
> 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

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.
 
> 
>  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
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
-- 
Philippe.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-16 15:58 ` Philippe Gerum
@ 2006-10-25 14:34   ` mani bhatti
  2006-10-25 22:50     ` Jan Kiszka
  0 siblings, 1 reply; 14+ messages in thread
From: mani bhatti @ 2006-10-25 14:34 UTC (permalink / raw)
  To: rpm; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 2856 bytes --]

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.

--- Philippe Gerum <rpm@xenomai.org> wrote:

> On Mon, 2006-10-16 at 08:39 -0700, mani bhatti
> wrote:
> > 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
> 
> 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.
>  
> > 
> >  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
> > Xenomai-help@domain.hid
> > https://mail.gna.org/listinfo/xenomai-help
> -- 
> Philippe.
> 
> 
> 

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 3236561751-queue_sender.c --]
[-- Type: text/x-csrc; name="queue_sender.c", Size: 3500 bytes --]

#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;
}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 2025157140-queuelistener1_task.c --]
[-- Type: text/x-csrc; name="queuelistener1_task.c", Size: 3339 bytes --]

#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;
}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 3467232582-queuelistener2_task.c --]
[-- Type: text/x-csrc; name="queuelistener2_task.c", Size: 3517 bytes --]

#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;
}

[-- Attachment #5: 402397780-Makefile --]
[-- Type: application/octet-stream, Size: 496 bytes --]

prefix := $(shell xeno-config --prefix)

ifeq ($(prefix),)
$(error Please add <xeno-install>/bin to your PATH variable)
endif

CC = $(shell xeno-config --cc)
LXRT_CFLAGS = $(shell xeno-config --xeno-cflags)
LXRT_LDFLAGS = $(shell xeno-config --xeno-ldflags)


queue_sender :  queue_sender.o
	$(CC) $(LXRT_CFLAGS) $(LXRT_LDFLAGS) -lm -lnative -g -o $@ $+   

queue_sender.o :  queue_sender.c 
	$(CC) $(LXRT_CFLAGS) $(LXRT_LDFLAGS) -g  -c queue_sender.c 

clean:
	rm queue_sender.o

.PHONY: clean


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-25 14:34   ` mani bhatti
@ 2006-10-25 22:50     ` Jan Kiszka
  2006-10-27 15:13       ` mani bhatti
  2006-10-27 21:23       ` [Xenomai-help] Problem " Philippe Gerum
  0 siblings, 2 replies; 14+ messages in thread
From: Jan Kiszka @ 2006-10-25 22:50 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 1067 bytes --]

mani bhatti wrote:
> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: native-queue-bcast-fix.patch --]
[-- Type: text/x-patch; name="native-queue-bcast-fix.patch", Size: 926 bytes --]

Index: ksrc/skins/native/queue.c
===================================================================
--- ksrc/skins/native/queue.c	(Revision 1747)
+++ ksrc/skins/native/queue.c	(Arbeitskopie)
@@ -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;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(Revision 1748)
+++ ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2006-10-26  Jan Kiszka  <jan.kiszka@domain.hid>
+
+	* ksrc/skins/native/queue.c (rt_queue_send): Track message count
+	correctly when broadcasting to a queue without listeners.
+
 2006-10-25  Jan Kiszka  <jan.kiszka@domain.hid>
 
 	* ksrc/drivers/testing/irqbench.c, doc/txt/irqbench.txt,

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-25 22:50     ` Jan Kiszka
@ 2006-10-27 15:13       ` mani bhatti
  2006-10-27 16:52         ` Jan Kiszka
  2006-10-27 21:23       ` [Xenomai-help] Problem " Philippe Gerum
  1 sibling, 1 reply; 14+ messages in thread
From: mani bhatti @ 2006-10-27 15:13 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 2659 bytes --]

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 <jan.kiszka@domain.hid> wrote:
  mani bhatti wrote:
> 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
Index: ksrc/skins/native/queue.c
===================================================================
--- ksrc/skins/native/queue.c (Revision 1747)
+++ ksrc/skins/native/queue.c (Arbeitskopie)
@@ -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;

Index: ChangeLog
===================================================================
--- ChangeLog (Revision 1748)
+++ ChangeLog (Arbeitskopie)
@@ -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.

[-- Attachment #2: Type: text/html, Size: 3225 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-27 15:13       ` mani bhatti
@ 2006-10-27 16:52         ` Jan Kiszka
  2006-10-30 16:08           ` mani bhatti
  0 siblings, 1 reply; 14+ messages in thread
From: Jan Kiszka @ 2006-10-27 16:52 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-25 22:50     ` Jan Kiszka
  2006-10-27 15:13       ` mani bhatti
@ 2006-10-27 21:23       ` Philippe Gerum
  1 sibling, 0 replies; 14+ messages in thread
From: Philippe Gerum @ 2006-10-27 21:23 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

On Thu, 2006-10-26 at 00:50 +0200, Jan Kiszka wrote:

> 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.

> Jan
-- 
Philippe.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-27 16:52         ` Jan Kiszka
@ 2006-10-30 16:08           ` mani bhatti
  2006-10-30 17:37             ` Jan Kiszka
  0 siblings, 1 reply; 14+ messages in thread
From: mani bhatti @ 2006-10-30 16:08 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1582 bytes --]

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.

Jan Kiszka <jan.kiszka@domain.hid> 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

[-- Attachment #2: Type: text/html, Size: 1926 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Xenomai-help] Problem with rt_queue
  2006-10-30 16:08           ` mani bhatti
@ 2006-10-30 17:37             ` Jan Kiszka
  2006-12-06 15:04               ` [Xenomai-help] problem persists " mani bhatti
  0 siblings, 1 reply; 14+ messages in thread
From: Jan Kiszka @ 2006-10-30 17:37 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Xenomai-help] problem persists with rt_queue
  2006-10-30 17:37             ` Jan Kiszka
@ 2006-12-06 15:04               ` mani bhatti
  2006-12-06 15:30                 ` [Xenomai-help] " Jan Kiszka
  0 siblings, 1 reply; 14+ messages in thread
From: mani bhatti @ 2006-12-06 15:04 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 1751 bytes --]


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.


Jan Kiszka <jan.kiszka@domain.hid> 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.

[-- Attachment #1.2: Type: text/html, Size: 2154 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 3236561751-queue_sender.c --]
[-- Type: text/x-csrc; name="queue_sender.c", Size: 3264 bytes --]

#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;
}

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Xenomai-help] Re: problem persists with rt_queue
  2006-12-06 15:04               ` [Xenomai-help] problem persists " mani bhatti
@ 2006-12-06 15:30                 ` Jan Kiszka
  2006-12-06 16:11                   ` mani bhatti
  0 siblings, 1 reply; 14+ messages in thread
From: Jan Kiszka @ 2006-12-06 15:30 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

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
> 
> 
>  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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Xenomai-help] Re: problem persists with rt_queue
  2006-12-06 15:30                 ` [Xenomai-help] " Jan Kiszka
@ 2006-12-06 16:11                   ` mani bhatti
  2006-12-06 16:44                     ` Jan Kiszka
  0 siblings, 1 reply; 14+ messages in thread
From: mani bhatti @ 2006-12-06 16:11 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]

Hi
Please tell me how can i do the following 

run the test over SVN trunk 

Thanks a lot for the gr8 help Jan.




Jan Kiszka <jan.kiszka@domain.hid> 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
> 
> 
>  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.

[-- Attachment #2: Type: text/html, Size: 2046 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Xenomai-help] Re: problem persists with rt_queue
  2006-12-06 16:11                   ` mani bhatti
@ 2006-12-06 16:44                     ` Jan Kiszka
  0 siblings, 0 replies; 14+ messages in thread
From: Jan Kiszka @ 2006-12-06 16:44 UTC (permalink / raw)
  To: mani bhatti; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 211 bytes --]

mani bhatti wrote:
> 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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-12-06 16:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-16 15:39 [Xenomai-help] Problem with rt_queue mani bhatti
2006-10-16 15:50 ` Jan Kiszka
2006-10-16 15:58 ` Philippe Gerum
2006-10-25 14:34   ` mani bhatti
2006-10-25 22:50     ` Jan Kiszka
2006-10-27 15:13       ` mani bhatti
2006-10-27 16:52         ` Jan Kiszka
2006-10-30 16:08           ` mani bhatti
2006-10-30 17:37             ` Jan Kiszka
2006-12-06 15:04               ` [Xenomai-help] problem persists " mani bhatti
2006-12-06 15:30                 ` [Xenomai-help] " Jan Kiszka
2006-12-06 16:11                   ` mani bhatti
2006-12-06 16:44                     ` Jan Kiszka
2006-10-27 21:23       ` [Xenomai-help] Problem " 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.