All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: NZG <ngustavson@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Fwd: can't use message pipe - Cannot allocate	memory
Date: Thu, 07 Jun 2007 19:03:06 +0200	[thread overview]
Message-ID: <1181235786.4998.108.camel@domain.hid> (raw)
In-Reply-To: <200706071049.32906.ngustavson@domain.hid>

On Thu, 2007-06-07 at 10:49 -0500, NZG wrote:
> I'm trying to pass a message from user space to Xenomai and it doesn't seem
>  to be working. I keep getting an error when attempting to write to the pipe
>  in user space.
> 
> rt_pipe_write error
> 
> : Cannot allocate memory
> 

Issue confirmed here when passing a non-zero poolsize. Passing 0 does
not seem to exhibit the problem. Could you re-check that both cases
actually fail on your side?

I have crafted a quick and dirty demo showing the problem. Until a
non-zero value is passed to rt_pipe_create() to specify a local pool,
everything is ok. (note: we could have used rt_pipe_write/rt_pipe_read
indifferently, they both end up calling rt_pipe_send/receive).

I'll have a look at this asap.

--- /dev/null	2006-05-31 03:15:07.000000000 +0200
+++ pipe/module/module.c	2007-06-07 18:48:00.000000000 +0200
@@ -0,0 +1,90 @@
+#include <native/task.h>
+#include <native/pipe.h>
+
+static RT_TASK task;
+
+static RT_PIPE pipe;
+
+#define ACK_STR "OK"
+
+static void test_task(void *cookie)
+{
+	RT_PIPE_MSG *msg, *ack;
+	ssize_t sz;
+	int s;
+
+	printk("Pipe open: waiting...\n");
+
+	for (;;) {
+		sz = rt_pipe_receive(&pipe, &msg, TM_INFINITE);
+
+		if (sz < 0)
+			break;
+
+		printk("Read %d bytes => %.*s\n", sz, sz, P_MSGPTR(msg));
+
+		s = rt_pipe_free(&pipe, msg);
+
+		if (s) {
+			printk("pipe free: failed %d\n", s);
+			goto fail;
+		}
+
+		ack = rt_pipe_alloc(&pipe, 3);
+
+		if (!ack) {
+			printk("pipe alloc: failed\n");
+			goto fail;
+		}
+
+		strcpy(P_MSGPTR(ack), ACK_STR);
+
+		sz = rt_pipe_send(&pipe, ack, 3, 0);	/* with \0 */
+
+		if (sz != sizeof(ACK_STR)) {
+			printk("pipe write: failed %d\n", sz);
+			goto fail;
+		}
+	}
+
+      fail:
+
+	return;
+}
+
+int test_init_module(void)
+{
+	int s;
+
+	s = rt_pipe_create(&pipe, "test", P_MINOR_AUTO, 0);
+
+	if (s) {
+		printk("pipe open: failed %d\n", s);
+		goto fail;
+	}
+
+	s = rt_task_create(&task, "pipe_task", 0, 1, 0);
+
+	if (s)
+		printk("task create: failed %d\n", s);
+	else {
+		s = rt_task_start(&task, &test_task, NULL);
+
+		if (s)
+			printk("task start: failed %d\n", s);
+	}
+
+ fail:
+	return s;
+}
+
+void test_cleanup_module(void)
+{
+	rt_pipe_delete(&pipe);
+	rt_task_delete(&task);
+}
+
+module_init(test_init_module);
+module_exit(test_cleanup_module);
+
+MODULE_LICENSE("GPL");
--- /dev/null	2006-05-31 03:15:07.000000000 +0200
+++ pipe/module/Makefile	2007-06-07 18:08:57.000000000 +0200
@@ -0,0 +1,5 @@
+EXTRA_CFLAGS += -Iinclude/xenomai
+
+obj-m += module_rt.o
+
+module_rt-objs := module.o
--- /dev/null	2006-05-31 03:15:07.000000000 +0200
+++ pipe/pipe.c	2007-06-07 18:49:25.000000000 +0200
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+main()
+{
+	char buf[16];
+	int fd, n;
+    
+	fd = open("/proc/xenomai/registry/native/pipes/test", O_RDWR);
+
+	if (fd < 0) {
+		fprintf(stderr, "open(): %m\n");
+		exit(1);
+	}
+    
+	printf("open(): %m, fd: %d\n", fd);
+
+	n = write(fd, "Hello World", 11);
+
+	if (n != 11) {
+		perror("write");
+		exit(1);
+	}
+
+	n = read(fd, buf, sizeof(buf));
+
+	if (n < 0) {
+		perror("write");
+		exit(1);
+	}
+
+	printf("Received %.*s, n=%d\n", n, buf, n);
+
+	exit(0);
+}


-- 
Philippe.




  reply	other threads:[~2007-06-07 17:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07 15:49 [Xenomai-help] Fwd: can't use message pipe - Cannot allocate memory NZG
2007-06-07 17:03 ` Philippe Gerum [this message]
2007-06-07 17:19   ` Philippe Gerum
2007-06-07 18:11     ` NZG
2007-06-07 18:22       ` Jan Kiszka
2007-06-07 18:37         ` NZG
2007-06-07 19:27           ` Jan Kiszka
2007-06-07 19:39             ` NZG
2007-06-07 20:15             ` Philippe Gerum
2007-06-07 22:29             ` Philippe Gerum
2007-06-07 22:47               ` Jan Kiszka
2007-06-08  6:55                 ` [Xenomai-core] " Philippe Gerum

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=1181235786.4998.108.camel@domain.hid \
    --to=rpm@xenomai.org \
    --cc=ngustavson@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.