Skip to contentSkip to conversation

Xeno 2.0 - rt_pipe issue

Xenomai-help Hannes Mayer 1 participant 1 message Dec 2, 2005

lore
Share & tools
lore
#0 lore raw

Hi all!

Find attached a simple, quick hack of a kernel-user pipe. (Xeno 2.0 / 2.6.13.4 with the adeos patch) Sometimes it works, but sometimes just garbage comes out of the pipe:

muon:/home/xenomai/pipe# ./user
read from pipe: HELLO
read from pipe: JODEL
written string 'World' - see kernel log
muon:/home/xenomai/pipe# ./user
read from pipe: Tµ¿¨q᷐Kô·”ñó·
read from pipe: Tµ¿¨q᷐Kô·”ñó·
written string 'World' - see kernel log

I even had a hard lockup. Nothing in the kernel log.

It works perfectly with only one rt_pipe_send in the kernel module, so most likely I'm missing something with pipe-usage. We have a saying here in Austria, if someone doesn't see something obvious to others:
"One is standing on the pipe" ... oh how true ;-)

Thanks for any hints!

Best regards,
Hannes.

obj-m := pipe.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS := -I/usr/realtime/include -I/usr/include/

default:

	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
	gcc -o user user.c -I/usr/realtime/include

#include <linux/module.h>
#include <native/task.h>
#include <native/pipe.h>

#define PIPE_MINOR 0

#define TASK_PRIO  2               /* Highest RT priority */
#define TASK_MODE  T_FPU|T_CPU(0)  /* Uses FPU, bound to CPU #0 */
#define TASK_STKSZ 4096            /* Stack size (in bytes) */

RT_TASK task_desc;
RT_PIPE pipe_desc;

void task_body (void *cookie) {
    RT_PIPE_MSG *msgout, *msgin;
    int len = sizeof("HELLO");
    msgout = rt_pipe_alloc(len);
    if (msgout) {
		strcpy( P_MSGPTR(msgout), "HELLO");
		if (rt_pipe_send(&pipe_desc, msgout, len, 0) != len) {
			rt_pipe_free(msgout);
		}
      msgout = rt_pipe_alloc(len);
      strcpy( P_MSGPTR(msgout), "JODEL");
      if (rt_pipe_send(&pipe_desc, msgout, len, 0) != len) {
         rt_pipe_free(msgout);
      }
		rt_pipe_receive(&pipe_desc, &msgin, TM_INFINITE);
		printk("received msg> %s, size=%d\n",P_MSGPTR(msgin),P_MSGSIZE(msgin));
		rt_pipe_free(msgin);
	} else {
		printk("ERROR: rt_pipe_alloc\n");
	}
}
int __init init_module (void) {
	int err;
	err = rt_pipe_create(&pipe_desc, "pipetest", PIPE_MINOR);
	if (!err) {
		err = rt_task_create(&task_desc, "MyTaskName", TASK_STKSZ, TASK_PRIO, TASK_MODE);
		if (!err) {
			rt_task_start(&task_desc, &task_body, NULL);
		} else {
			printk("ERROR: cannot create task\n");
			return 0;
		}
	} else {
		printk("ERROR: cannot create pipe\n");
	}
	printk("INIT DONE\n");
	return 0;
}
void __exit cleanup_module (void) {
    rt_pipe_delete(&pipe_desc);
    rt_task_delete(&task_desc);
    printk("CLEANUP DONE\n");
}

MODULE_LICENSE("GPL");

#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <native/pipe.h>

#define PIPE_MINOR 0

int pipe_fd;

int main (int argc, char *argv[]) {

	char devname[32], buf[32];
	sprintf(devname, "/dev/rtp%d", PIPE_MINOR);
	pipe_fd = open(devname, O_RDWR);
    
	if (pipe_fd < 0) {
		printf("cannot open pipe %s\n", devname);
		exit(1);
	}

	read(pipe_fd, buf, sizeof(buf));
	printf("read from pipe: %s\n", buf);
   read(pipe_fd, buf, sizeof(buf));
   printf("read from pipe: %s\n", buf);
	
	write(pipe_fd, "World", sizeof("World"));
	printf("written string 'World' - see kernel log\n");
	
	close(pipe_fd);
}