All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Some problems with shared memory
@ 2009-03-30  9:31 roderik.wildenburg
  2009-03-30 12:14 ` Gilles Chanteperdrix
  2009-05-03 20:21 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 27+ messages in thread
From: roderik.wildenburg @ 2009-03-30  9:31 UTC (permalink / raw)
  To: xenomai

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

I have two problems with shared memory and Xenomai 2.4.6 (2.4.25 PPC-kernel):

1.) If I don´t page align the size of shared memory (multiple of 4096) I get the following error message :
"createshm mmap: No such device or address"

Detailed programm output of attached testprogram :
{
prompt # ./killtest -c &
[1] 104
prompt # createshm mmap: No such device or address
shmsize = 100000; errno : 6 == Failed to create shm : -3
killtest user exit !
}

You can reproduce this effect by commenting out line 60 in the attached source file and calling the program as follows:

prompt # killtest -c


2.) If I create 2 processes which use the same shared memory and I kill the process which created the SHM before (!) the other process, which only uses the SHM, the whole system stalls.
You can reproduce this with the attached testprogramm by calling it in the following way :

prompt # ./killtest -c &
[1] 105
prompt # ./killtest &
[2] 106
prompt # kill 105
prompt # killtest user exit !
[1]-  Done                    ./killtest -c
prompt # kill 106

System stalls    


Is this a problem of Xenomai (Cleanup od SHM) or am I creating/deleting the SHM in a wrong way ?
Could you please try to reproduce this problem ?

Many thanks in advance
Roderik

--------------------------------------------------------
manroland 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: killtest.c --]
[-- Type: application/octet-stream, Size: 2967 bytes --]

/*
 * killtest.c
 *
 *  Created on: 24.03.2009
 *      Author: arowil
 */

#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/timex.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/mman.h>
#include <string.h>
#include <fcntl.h>
#include <pthread.h>


#define SHMNAME "/testshm"

char *testshm=NULL;
int shmfd=-1;
int shmsize=0;
int create=0;
int finished=0;
pthread_t testtaskid;

int createshm(char **shmbuf, int *shmfd, int create)
{
   int ret, shmsize=0;
   int oflags;
   char *tshm;

   tshm=MAP_FAILED;
   ret=0;
   *shmbuf=NULL;
   *shmfd=-1;

   if(create)
      oflags=O_CREAT | O_RDWR;
   else
      oflags=O_RDWR;

   *shmfd = shm_open(SHMNAME, oflags, 0);
   if (*shmfd == -1)
   {
       printf("shm_open fails. errno=%d SHM:%s\n",errno,SHMNAME);
       perror("shm_open");
       ret=-1;
       goto createshmexit;
   }

   /*SHM-Size*/
   shmsize=100000;
   shmsize=((shmsize>>12)+1)<<12; /*page (4096) align*/
   ret=shmsize;
   if (ftruncate(*shmfd,shmsize) == -1)
   {
      printf("ftruncate fails. errno=%d\n",errno);
      ret=-2;
      goto createshmexit;
   }

   /* Map shared memory object */
   tshm = mmap(NULL, shmsize, PROT_READ | PROT_WRITE, MAP_SHARED, *shmfd, 0);
   if(tshm==MAP_FAILED)
   {
      printf("shmsize = %d; errno : %d == ", shmsize, errno);
      perror("createshm mmap");
      ret=-3;
      goto createshmexit;
   }
   else
   {
      if(create)
      {
         memset(tshm,0,shmsize);
      }
   }

   *shmbuf=tshm;

createshmexit :
   if(ret<0)
   {
      if(tshm!=MAP_FAILED)
      {
         munmap(tshm,shmsize);
      }
      if(*shmfd>=0)
      {
         shm_unlink(SHMNAME);
         close(*shmfd);
      }
      *shmbuf=NULL;
      *shmfd=-1;
   }

   return(ret);
}

void deleteshm(char *testshm, int shmsize, int shmfd, int create)
{
   if( (testshm!=NULL) && (shmfd!=-1) )
   {
      munmap(testshm,shmsize);
      if(create)
         shm_unlink(SHMNAME);
      close(shmfd);
      shmfd=-1;
   }
}

void user_exit(void)
{
   if(create)
      deleteshm(testshm,shmsize,shmfd,create);
   printf("killtest user exit !\n");
}



void sighand(int sig __attribute__ ((unused)))
{
   finished = 1;
}

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

   while( (c = getopt(argc, argv, "c")) != EOF)
   {
      switch (c)
      {
         case 'c': // create SHM
            create=1;
            break;
         default:
            printf("killtest [-c]\n");
            return(0);
            break;
      }
   }

   signal(SIGINT, sighand);
   signal(SIGTERM, sighand);
   signal(SIGHUP, sighand);
   signal(SIGALRM, sighand);


   mlockall(MCL_CURRENT|MCL_FUTURE);

   if( (shmsize=createshm(&testshm, &shmfd, create))<0)
   {
      printf("Failed to create shm : %d\n",shmsize);
      user_exit();
      return(-1);
   }

   while (!finished)
      pause();

   user_exit();

   return 0;
}

[-- Attachment #3: Makefile --]
[-- Type: application/octet-stream, Size: 650 bytes --]

CROSSCOMPILE := ppc_6xx
TARGETS := killtest

XENO_PATH=/opt/eldk/xenomai-2.4.6
XENO_CONFIG=$(XENO_PATH)/bin/xeno-config
prefix := $(shell $(XENO_CONFIG) --prefix)

ifeq ($(prefix),)
$(error Please add <xenomai-install-path>/bin to your PATH variable or type: \
make XENO_CONFIG=<xenomai-install-path>/bin/xeno-config)
endif

CFLAGS_RT:= $(shell  $(XENO_CONFIG) --posix-cflags) -g -O -Wall 
LDFLAGS_RT:= $(shell  $(XENO_CONFIG) --posix-ldflags)

CC := $(CROSSCOMPILE)-gcc

all: $(TARGETS) 

killtest.o: killtest.c 
	$(CC) $(CFLAGS_RT) $< -c -o $@

killtest: killtest.o 
	$(CC)  $(LDFLAGS_RT) -Wall -o $@  killtest.o

	
clean:
	rm *.o $(TARGETS) *.asm 

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

end of thread, other threads:[~2009-06-18  8:51 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-30  9:31 [Xenomai-help] Some problems with shared memory roderik.wildenburg
2009-03-30 12:14 ` Gilles Chanteperdrix
2009-03-31 11:52   ` roderik.wildenburg
2009-04-06  8:47     ` roderik.wildenburg
2009-05-03 20:21 ` Gilles Chanteperdrix
2009-05-04  7:23   ` Wolfgang Denk
2009-05-04  8:49     ` Gilles Chanteperdrix
2009-05-04 15:24     ` Thomas Lockhart
2009-05-04 18:01       ` Wolfgang Denk
2009-05-04 18:33         ` Gilles Chanteperdrix
2009-05-05 12:16           ` roderik.wildenburg
2009-05-29 18:42             ` Gilles Chanteperdrix
2009-06-08  8:25               ` roderik.wildenburg
2009-06-08 20:36                 ` Gilles Chanteperdrix
2009-06-09  6:30                   ` roderik.wildenburg
2009-06-09 13:28                 ` Philippe Gerum
2009-06-09 13:38                   ` Philippe Gerum
2009-06-10 11:47                   ` roderik.wildenburg
2009-06-12 14:06                     ` Philippe Gerum
2009-06-16 13:20                       ` roderik.wildenburg
2009-06-16 13:45                         ` Philippe Gerum
2009-06-17 11:40                           ` roderik.wildenburg
2009-06-17 14:19                             ` Philippe Gerum
2009-06-18  8:37                               ` roderik.wildenburg
2009-06-18  8:51                                 ` Philippe Gerum
2009-05-05 16:36         ` Thomas Lockhart
2009-05-05 19:03           ` Wolfgang Denk

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.