All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] rt_queue_write error: "Cannot allocate memory "; bug or feature ?
@ 2007-11-19 13:43 Roderik.Wildenburg
  2007-11-19 14:35 ` Philippe Gerum
  0 siblings, 1 reply; 13+ messages in thread
From: Roderik.Wildenburg @ 2007-11-19 13:43 UTC (permalink / raw)
  To: xenomai

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

When running the attached programm for a while I get an "Cannot allocate memory" error with the function rt_queue_write.
I can´t see any obvious mistake in my code, so I don´t have an simple explanation for this behavior but just a suspicion (see below). Could somebody be so kind to try to reproduce this problem, so I can determine whether this is a problem of my context or of xenomai. 
I use Xenomai 2.3.2 with an 2.4.25 kernel on PPC.

Or, even better, could somebody explain to me the functionality of heap allocation of native queues. I have the impression the problem of my program results from some kind of heap fragmentation, as I write very differnt buffersizes to a quite small queue (see code line 59-62).

Thank you in advance and best regards
Roderik 

MAN Roland Druckmaschinen AG
Vorsitzender des Aufsichtsrates: Hanno C. Fiedler
Vorstand: Gerd Finkbeiner (Vorsitzender), Dr. Ingo Koch, Dr. Markus Rall, Paul Steidle    
Sitz der Gesellschaft: Offenbach am Main, Registergericht: Amtsgericht Offenbach HRB-Nr. 42592    
USt-Ident-Nr. DE 250200933

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

#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>

#include <native/task.h>
#include <native/queue.h>

#define  MAXLEN   1024  /* größer maximale Nachrichtenlänge */
#define CONTROLLER_WAIT 1500000000

RT_QUEUE qtest1q;
RT_TASK qtest1, qtest2;


void qtest1t(void)
{
   ssize_t len;
   static char buf[MAXLEN];

   for (;;)
   {
      if ((len = rt_queue_read(&qtest1q, &buf, sizeof (buf), TM_INFINITE)) < 0)
      {
         printf("qtest1t: rt_queue_read failed with %d\n",len);
         perror("perror qtest1t: rt_queue_read");
         errno = -len, perror("perror2 qtest1t: rt_queue_read");
      }
   }
    
}

void qtest2t(void)
{
   int ret, len;
   RT_QUEUE_INFO qinfo;
   static char buf[MAXLEN];
   int zuf;

   for (;;)
   {
      zuf=rand();
      len= (int) ((float)((float)zuf/(float)RAND_MAX) * (float)(MAXLEN-10) + 2.0 );
      printf("WriteQueue %d %d\n",len,zuf);
      if ((ret = rt_queue_write(&qtest1q, &buf, len , Q_NORMAL)) < 0)
      {
         errno = -ret, perror("qtest2t: rt_queue_write error");
         printf("Message size :%d return : %d\n",len, ret);
         if( (ret=rt_queue_inquire(&qtest1q,&qinfo))<0)
         {
            printf("queue_inquire : %d\n",ret);
         }
         else
         {
            printf("---- %s NMsg:%d Size:%d used:%d\n",qinfo.name, qinfo.nmessages,qinfo.poolsize,qinfo.usedmem);
         }
      }
      rt_task_sleep(CONTROLLER_WAIT);
   }
}
    

int startqtest(void)
{
   int err;

   srand (time (0));
   
   if(!rt_queue_bind(&qtest1q,"qtest1q",TM_NONBLOCK))
      rt_queue_delete(&qtest1q);
   if( (err = rt_queue_create(&qtest1q, "qtest1q", MAXLEN*10, 10, Q_FIFO)) != 0 )
      printf("q_create qtest1q failed with %d\n",err);

   err = rt_task_create(&qtest1, "qtest1t", 0, 50, 0);   /* TCP/UDP-Sendeprozess */
   if (!err)
      rt_task_start(&qtest1, (void(*)(void *))qtest1t, NULL);

   err = rt_task_create(&qtest2, "qtest2t", 0, 30, 0);   /* TCP-Empfangsprozess */
   if (!err)
      rt_task_start(&qtest2, (void(*)(void *))qtest2t, NULL);
   
   return(0);
}


int main (int ac, char *av[])

{
    sigset_t mask;
    int sig;

    printf("qtest start !\n");
    sleep(2);

    sigemptyset(&mask);
    sigaddset(&mask,SIGINT);
    sigaddset(&mask,SIGTERM);
    sigaddset(&mask,SIGHUP);
    sigaddset(&mask,SIGALRM);

    pthread_sigmask(SIG_BLOCK, &mask, NULL);

    mlockall(MCL_CURRENT|MCL_FUTURE);

    startqtest();


    sigwait(&mask, &sig);

    return 0;
}

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [Xenomai-help] rt_queue_write error: "Cannot allocate memory "; bug or feature ?
@ 2007-11-28 13:03 Roderik.Wildenburg
  0 siblings, 0 replies; 13+ messages in thread
From: Roderik.Wildenburg @ 2007-11-28 13:03 UTC (permalink / raw)
  To: rpm; +Cc: xenomai

> 
> You will need this attached patch on top of the previous one 
> to get the complete fix.


I applied  your second patch. Works fine. Thank you.
As allready your first patch did not produce 
the problem any more I unfortunatelly can´t report 
an obvious improvement from the 2. patch.
Nevertheless we will use both of your patches as 
long as 2.3.x ultimate isn´t out. 

(Did your 2. patch solve some rare situations, 
or why else did allready your 1. patch solve my
problem ?)

Roderik 

MAN Roland Druckmaschinen AG
Vorsitzender des Aufsichtsrates: Hanno C. Fiedler
Vorstand: Gerd Finkbeiner (Vorsitzender), Dr. Ingo Koch, Dr. Markus Rall, Paul Steidle    
Sitz der Gesellschaft: Offenbach am Main, Registergericht: Amtsgericht Offenbach HRB-Nr. 42592    
USt-Ident-Nr. DE 250200933


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

end of thread, other threads:[~2007-11-28 13:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-19 13:43 [Xenomai-help] rt_queue_write error: "Cannot allocate memory "; bug or feature ? Roderik.Wildenburg
2007-11-19 14:35 ` Philippe Gerum
2007-11-19 15:11   ` Roderik.Wildenburg
2007-11-19 18:06     ` Philippe Gerum
2007-11-20  8:51       ` Roderik.Wildenburg
2007-11-20 13:59         ` Philippe Gerum
2007-11-21 14:07           ` Roderik.Wildenburg
2007-11-23 17:08           ` Philippe Gerum
2007-11-28  9:21             ` Roderik.Wildenburg
2007-11-28  9:43               ` Philippe Gerum
2007-11-28 10:05                 ` Roderik.Wildenburg
2007-11-28 10:22                   ` Philippe Gerum
  -- strict thread matches above, loose matches on Subject: below --
2007-11-28 13:03 Roderik.Wildenburg

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.