From: Hannes Mayer <h.mayer@domain.hid>
To: xenomai@xenomai.org
Subject: [Xenomai-help] Xeno 2.0 - rt_pipe issue
Date: Fri, 02 Dec 2005 21:31:55 +0100 [thread overview]
Message-ID: <4390AF3B.1030402@domain.hid> (raw)
[-- 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);
}
reply other threads:[~2005-12-02 20:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4390AF3B.1030402@domain.hid \
--to=h.mayer@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.