All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Xeno 2.0 - rt_pipe issue
@ 2005-12-02 20:31 Hannes Mayer
  0 siblings, 0 replies; only message in thread
From: Hannes Mayer @ 2005-12-02 20:31 UTC (permalink / raw)
  To: xenomai

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

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\x7fµ¿¨q᷐Kô·”ñó·
read from pipe: T\x7fµ¿¨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.

[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 238 bytes --]

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



[-- Attachment #3: pipe.c --]
[-- Type: text/x-csrc, Size: 1559 bytes --]

#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");



[-- Attachment #4: user.c --]
[-- Type: text/x-csrc, Size: 639 bytes --]

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-02 20:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-02 20:31 [Xenomai-help] Xeno 2.0 - rt_pipe issue Hannes Mayer

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.