All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] task suspending while starting the task
@ 2007-10-29 15:23 poornima r
  2007-10-29 15:35 ` Philippe Gerum
  0 siblings, 1 reply; 2+ messages in thread
From: poornima r @ 2007-10-29 15:23 UTC (permalink / raw)
  To: xenomai


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

  
Hello,

I am working on powerPC board latest Xenomai stable version.
I am communicating between two kernel(queue1.c and queue2.c)modules using Message queues.The queue descriptor is shared between the two 
kernel modules by using EXPORT_SYMBOL(queue_desc).
The data is sent to the user space(read.c) through message pipes.
This program runs fine somtimes but sometimes the task gets suspended while starting the task. 

My questions are:
Is it a valid thing to pass messages through queues between two kernel modules using EXPORT_SYMBOL(queue_desc)?
What are the possibilities that a task gets suspending while starting a task?

Thanks & Regards,
Poornima


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

[-- Attachment #2: queue1.c --]
[-- Type: application/octet-stream, Size: 2487 bytes --]

/**********************************************************
* Celestial Systems                                      **
* This program illustrate the service of Message queue   **
* by which real-time tasks can exchange or pass data     **  
* through a Xenomai-managed queue of messages.            ** 
**********************************************************/

/* Include Files */

#include <linux/kernel.h>
#include <native/task.h>
#include <native/queue.h>
/* Global Defines */

#define TASK_PRIO  99       /* Highest RT priority */
#define TASK_MODE  0        /* No flags */
#define TASK_STKSZ 4096     /* Stack size (in bytes) */

/* Global variables */

RT_TASK  task_desc;        /*Task   Descriptor*/
RT_QUEUE queue_desc;       /*Queue  Descriptor */

/*Register a Module*/

static int __init my_module(void)
{
       int err,len;
       char messages[10] = "celestial";
       void *msg;
       len= sizeof(messages);

        /*Create an Message Queue*/

         err= rt_queue_create(&queue_desc,"KERN_QUEUE",100,Q_UNLIMITED,Q_SHARED | Q_FIFO);
         if(err)
         printk("Error in creating Queue,ERROR = %d\n",err);
         else
         printk("Queue Created\n");

       /* Allocate a Message queue buffer. */

         msg = rt_queue_alloc(&queue_desc,sizeof(messages));
         if (msg==NULL)
         printk("Allocation fail\n");
         else
          {
           printk("Message queue buffer is allocated\n");
           //strcpy(msg,messages[10]);
           memcpy(msg,&messages, sizeof(messages));

           /*Send a Message to a queue*/
	   
           err= rt_queue_send(&queue_desc,msg,sizeof(messages),Q_FIFO);
           if(err < 0)
           	printk("Error while sending,ERROR  =%d\n",err);
           else
           	printk("Number of receivers which got awaken  %d\n", err);
           
	  }
          printk("INIT DONE\n");
	   return 0;

}

static void __exit exit_module(void)
{
printk("deleting task and queue and unbinding them\n");
int ret;

/*ret= rt_queue_unbind(&q_desc);
if(ret!=0)
{
printk("can't unbind\n");
}*/
ret= rt_queue_delete(&queue_desc);
if(ret!=0)
{
printk("error in deleting queue %d\n",ret);
}
ret= rt_task_delete(&task_desc);
if(ret!=0)
{
printk("error in deleting task %d\n",ret);
}
printk("all items are deleted\n");
}

EXPORT_SYMBOL (queue_desc);
module_init(my_module);
module_exit(exit_module);
MODULE_LICENSE("GPL");

[-- Attachment #3: queue2.c --]
[-- Type: application/octet-stream, Size: 3466 bytes --]

/**********************************************************
* Celestial Systems                                      **
* This program illustrate the service of Message queue   **
* by which real-time tasks can exchange or pass data     **  
* through a Xenomai-managed queue of messages.            ** 
**********************************************************/

/* Include Files */

#include <linux/kernel.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/pipe.h>

/* Global Defines */
#define TASK_PRIO  99       /* Highest RT priority */
#define TASK_MODE  0        /* No flags */
#define TASK_STKSZ 4096     /* Stack size (in bytes) */

#define BUFSIZ 10

/* Global variables */

RT_PIPE rt_pipe;  /* Pipe Descriptor */


RT_TASK  task_desc;
extern RT_QUEUE queue_desc;

/* Global variables */



void task_body (void *cookie)
{
     int err;
     ssize_t len;
     void *msg;
     printk ("task started\n");
     //len = rt_queue_receive(&queue_desc,&msg,TM_NONBLOCK);
     len = rt_queue_receive(&queue_desc,&msg,TM_INFINITE);
     //len = rt_queue_receive(&queue_desc,&msg,1000);
     if(len==0)
     {
          printk("error in receiving %d\n",len);
     }
     else
     {
        printk("the message size is :%d, the message is :%s\n",len,(const char *)msg);
        
	err = rt_pipe_write(&rt_pipe, msg, BUFSIZ, P_NORMAL);
        if (err > 0)
        {
              printk("Data is writen on pipe\n");
        }
        else
        {
             printk("Error in writing = %d\n",err);
        }
	err= rt_queue_free(&queue_desc,msg);
        if(err!=0)
        {
       		printk("error while freeing %d\n",err);
        }
        else
      	{
        	printk("freed\n");
        }
     }

}


/*Register a Module*/

static int __init my_module1(void)
{
     int err;
     ssize_t len;
     void *msg;
	/*Create an FIRST RT task by the name COND_TASK_ONE */
   	 err = rt_pipe_create(&rt_pipe, "pipe",4,0);  /* Creating a pipe with name as pipe, minor number as 4*/
        if (err !=0)
                printk("Error in creating pipe\n");
        else
        {
		printk("creating pipe\n");
	}
	
        err = rt_task_create(&task_desc, "QUEUE_TASK", TASK_STKSZ, TASK_PRIO, TASK_MODE);
        if(!err)
        {
           /* Starting the execution of first task */
	
           err = rt_task_start(&task_desc, &task_body, NULL);
           if (err != 0)
           printk("Error in starting the First task ERROR = %d\n",err);
           else
           printk("Successful in starting the First task\n");
         }
    
   /*
    
    len = rt_queue_receive(&queue_desc,&msg,TM_INFINITE);
    
    if (len == -EPERM)
    {
	printk ("EPERM error\n");
	return;
    }
    if(len==0)
    {
       printk("error in receiving %d\n",len);
    }
    else
    {
                printk("the message size is :%d, the message is :%s\n",len,(const char *)msg);
            	err= rt_queue_free(&queue_desc,msg);
        	if(err!=0)
    		{
      			 printk("error while freeing %d\n",err);
         	}
        	else
      		{
        		printk("freed\n");
        	}
    }

    printk("INIT DONE\n");
    */
     return 0;

}

static void __exit exit_module1(void)
{
	printk("deleting task and queue and unbinding them\n");
}
module_init(my_module1);
module_exit(exit_module1);
MODULE_LICENSE("GPL");

[-- Attachment #4: read.c --]
[-- Type: application/octet-stream, Size: 938 bytes --]

/************************************************************
* This program illustrate the linux process communication  **
* with Xenomai through  reading on pipe			   **
************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define BUFSIZ 10
int main()
{
  char buff[BUFSIZ];
  int ret;
  int fd; 
  printf("Opening the pipe\n"); 
  fd = open("/dev/rtp4",O_RDWR); /* openning the pipe device file rtp4 as xenomai task creates pipe 
				    with minor 4 */
  if (fd < 0)
    {
      printf("Error in opening file descriptor = %d\n",fd);
      exit(0);
    }
  {
    
    ret = read(fd, (void *)buff, (sizeof(buff)+1));
    if (ret > 0)
    printf("the data bytes read are =%d & the data is = %s\n",ret,buff);
    
    if (strcmp(buff,"celestial") == 0)
      {
        ret = 0;
      }
    else
       ret = 1;
  }
}    
  

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

* Re: [Xenomai-help] task suspending while starting the task
  2007-10-29 15:23 [Xenomai-help] task suspending while starting the task poornima r
@ 2007-10-29 15:35 ` Philippe Gerum
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Gerum @ 2007-10-29 15:35 UTC (permalink / raw)
  To: poornima r; +Cc: xenomai

poornima r wrote:
>  
> Hello,
> 
> I am working on powerPC board latest Xenomai stable version.
> I am communicating between two kernel(queue1.c and queue2.c)modules
> using Message queues.The queue descriptor is shared between the two
> kernel modules by using EXPORT_SYMBOL(queue_desc).
> The data is sent to the user space(read.c) through message pipes.
> This program runs fine somtimes but sometimes the task gets suspended
> while starting the task.

dmesg output?

-- 
Philippe.


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

end of thread, other threads:[~2007-10-29 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-29 15:23 [Xenomai-help] task suspending while starting the task poornima r
2007-10-29 15:35 ` 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.