Resource manager problem

Using QNX 6.1.0.A

I have a couple of resource manager questions:

  1. The standard resource manager examples use io_open() for setup
    instructions. Is there a similar function in which to put instructions to
    free allocated memory etc. I cannot find io_close but something must get
    called when the client calls “close(fd);”

  2. I am trying to share memory (for a dma buffer) between a resource manager
    and a client process. I am using:

resmgr.c

int sh_mem;
sh_mem = shm_open("/image", O_RDWR | O_CREAT, 0777);

client.c

int sh_mem;
sh_mem = shm_open("/image", O_RDWR, 0777);

However the resource manager shm_open() call causes it to exit inexplicably.
Any ideas?

Paul.

Paul Jones a écrit :

Using QNX 6.1.0.A

I have a couple of resource manager questions:

  1. The standard resource manager examples use io_open() for setup
    instructions. Is there a similar function in which to put instructions to
    free allocated memory etc. I cannot find io_close but something must get
    called when the client calls “close(fd);”

You can do that in ocb_calloc()/ocb_free() functions associated with
io_open()/io_close().
You don’t need any io_open()!
write something like that:

// optional, use iofunc_ocb_t if you need to overload the default structure.
// you can also overload the attribute structure to keep infos per device
typedef struct my_ocb_s {
iofunc_ocb_t ocb;
char *buffer; // for example if you have to keep a buffer per open
}my_ocb_t;

static iofunc_funcs_t my_ocb_funcs = {
_IOFUNC_NFUNCS,
my_ocb_calloc,
my_ocb_free
};

/**

  • The mount structure to attach the ocb overloaded functions
    */
    iofunc_mount_t my_mount = {0, 0, 0, 0, &my_ocb_funcs};

my_ocb_t *
my_ocb_calloc (resmgr_context_t *ctp, iofunc_attr_t *attr)
{
my_ocb_t *tocb;


if ((tocb = calloc (1, sizeof (my_ocb_t))) == NULL) {
return(NULL);
}
if ((tocb->buffer = calloc (1, 1024)) == NULL) {
return(NULL);
}

// do anything else to the ocb
return(tocb);
}


void
my_ocb_free (my_t *tocb)
{
//free anything you have to
free (tocb->buffer);
free (tocb);
}



-cutc
I don’t know about shared memory


Alain.

“Paul Jones” <paul.jones@bnc.ox.ac.uk> wrote in message
news:a1n27i$5ph$1@inn.qnx.com

  1. The standard resource manager examples use io_open() for setup
    instructions. Is there a similar function in which to put instructions to
    free allocated memory etc. I cannot find io_close but something must get
    called when the client calls “close(fd);”

io_close_dup() and io_close_ocb() as well as the ocb_free() handlers get
called upon client disconnect.

  1. I am trying to share memory (for a dma buffer) between a resource
    manager
    and a client process. I am using:

resmgr.c

int sh_mem;
sh_mem = shm_open("/image", O_RDWR | O_CREAT, 0777);

client.c

int sh_mem;
sh_mem = shm_open("/image", O_RDWR, 0777);

However the resource manager shm_open() call causes it to exit
inexplicably.
Any ideas?

Do you have any more info on the failure? Do you check the errno value
after the failure - that might lead to some clues.

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

QNX 6.1.0.A

What I would like to do is allocate an area of physically contiguous shared
memory that:

  1. the resource manager can use for dma transfer of image data from the pci
    card and
  2. the client can subsequently access for processing/display.

The code I have used to try and do this is shown below.

client_process.c

int sh_mem;

sh_mem = shm_open("/imagemem", O_RDWR | O_CREAT , 0777);
if (sh_mem == -1)
printf(“Problem with shared memory\n”);
else
printf(“Shared memory created OK\n”);
// Allocate physically contiguous shared memory
image_buf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );


resmgr.c

int sh_mem;

sh_mem = shm_open("/imagemem", O_RDWR , 0777);
if (sh_mem == -1)
printf(“problem with sh mem\n”);
dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );
if (dmabuf == MAP_FAILED)
{
printf(“mmap for dmabuf failed: %s\n”, strerror(errno));
exit(EXIT_FAILURE);
}
// Get physical address of dmabuf to use for dma transfer
if (mem_offset(dmabuf, NOFD, 1, &phys_addr, NULL) != 0)
exit(EXIT_FAILURE);

The problem is that mmap is returning MAP_FAILED with the error “invalid
argument”. However there is no problem if I change the line to:

dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, NOFD, 0 );

but then the mapped memory is not shared. What arguments should I pass to
mmap() to create a shared, physically contiguous area?

Paul.

Check out the knowledge base
http://qdn.qnx.com/support/bok/solution.qnx?10450 which illustrates how to
do exactly that.


Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>
“Paul Jones” <paul.jones@bnc.ox.ac.uk> wrote in message
news:a1uslf$ihv$1@inn.qnx.com

QNX 6.1.0.A

What I would like to do is allocate an area of physically contiguous
shared
memory that:

  1. the resource manager can use for dma transfer of image data from the
    pci
    card and
  2. the client can subsequently access for processing/display.

The code I have used to try and do this is shown below.

client_process.c

int sh_mem;

sh_mem = shm_open("/imagemem", O_RDWR | O_CREAT , 0777);
if (sh_mem == -1)
printf(“Problem with shared memory\n”);
else
printf(“Shared memory created OK\n”);
// Allocate physically contiguous shared memory
image_buf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );


resmgr.c

int sh_mem;

sh_mem = shm_open("/imagemem", O_RDWR , 0777);
if (sh_mem == -1)
printf(“problem with sh mem\n”);
dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );
if (dmabuf == MAP_FAILED)
{
printf(“mmap for dmabuf failed: %s\n”, strerror(errno));
exit(EXIT_FAILURE);
}
// Get physical address of dmabuf to use for dma transfer
if (mem_offset(dmabuf, NOFD, 1, &phys_addr, NULL) != 0)
exit(EXIT_FAILURE);

The problem is that mmap is returning MAP_FAILED with the error “invalid
argument”. However there is no problem if I change the line to:

dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, NOFD,
0 );

but then the mapped memory is not shared. What arguments should I pass to
mmap() to create a shared, physically contiguous area?

Paul.