On Tue, Feb 23, 2016 at 10:57 AM, Christophe Milard <
[email protected]> wrote:

> The name of the shared memory (created with linux shm_open()
> when the ODP_SHM_PROC flag is given) is now prefixed with
> "/opd-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem.
>
> Signed-off-by: Christophe Milard <[email protected]>
>

Reviewed-and-tested-by: Bill Fischofer <[email protected]>


> ---
>  platform/linux-generic/include/odp_internal.h |  2 ++
>  platform/linux-generic/odp_init.c             |  3 +++
>  platform/linux-generic/odp_shared_memory.c    | 18 ++++++++++++++----
>  3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/platform/linux-generic/include/odp_internal.h
> b/platform/linux-generic/include/odp_internal.h
> index e75154a..98a5699 100644
> --- a/platform/linux-generic/include/odp_internal.h
> +++ b/platform/linux-generic/include/odp_internal.h
> @@ -21,6 +21,7 @@ extern "C" {
>  #include <odp/init.h>
>  #include <odp/thread.h>
>  #include <stdio.h>
> +#include <sys/types.h>
>
>  extern __thread int __odp_errno;
>
> @@ -37,6 +38,7 @@ typedef struct {
>  } odp_system_info_t;
>
>  struct odp_global_data_s {
> +       pid_t main_pid;
>         odp_log_func_t log_fn;
>         odp_abort_func_t abort_fn;
>         odp_system_info_t system_info;
> diff --git a/platform/linux-generic/odp_init.c
> b/platform/linux-generic/odp_init.c
> index 3a990d2..4a5e687 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -8,12 +8,15 @@
>  #include <odp_internal.h>
>  #include <odp/debug.h>
>  #include <odp_debug_internal.h>
> +#include <unistd.h>
>
>  struct odp_global_data_s odp_global_data;
>
>  int odp_init_global(const odp_init_t *params,
>                     const odp_platform_init_t *platform_params ODP_UNUSED)
>  {
> +       odp_global_data.main_pid = getpid();
> +
>         enum init_stage stage = NO_INIT;
>         odp_global_data.log_fn = odp_override_log;
>         odp_global_data.abort_fn = odp_override_abort;
> diff --git a/platform/linux-generic/odp_shared_memory.c
> b/platform/linux-generic/odp_shared_memory.c
> index 7847cc9..81000cb 100644
> --- a/platform/linux-generic/odp_shared_memory.c
> +++ b/platform/linux-generic/odp_shared_memory.c
> @@ -26,6 +26,9 @@
>  #include <string.h>
>  #include <errno.h>
>
> +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16)
> +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */
> +
>  _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS,
>                    "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS");
>
> @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm)
>         uint32_t i;
>         int ret;
>         odp_shm_block_t *block;
> +       char shm_devname[SHM_DEVNAME_MAXLEN];
>
>         if (shm == ODP_SHM_INVALID) {
>                 ODP_DBG("odp_shm_free: Invalid handle\n");
> @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm)
>         }
>
>         if (block->flags & ODP_SHM_PROC) {
> -               ret = shm_unlink(block->name);
> +               snprintf(shm_devname, SHM_DEVNAME_MAXLEN,
> +                        SHM_DEVNAME_FORMAT, odp_global_data.main_pid,
> +                        block->name);
> +               ret = shm_unlink(shm_devname);
>                 if (0 != ret) {
>                         ODP_DBG("odp_shm_free: shm_unlink failed\n");
>                         odp_spinlock_unlock(&odp_shm_tbl->lock);
> @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t
> size, uint64_t align,
>                           uint32_t flags)
>  {
>         uint32_t i;
> +       char shm_devname[SHM_DEVNAME_MAXLEN];
>         odp_shm_block_t *block;
>         void *addr;
>         int fd = -1;
> @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t
> size, uint64_t align,
>  #endif
>
>         if (flags & ODP_SHM_PROC) {
> -               /* Creates a file to /dev/shm */
> -               fd = shm_open(name, oflag,
> +               /* Creates a file to /dev/shm/odp */
> +               snprintf(shm_devname, SHM_DEVNAME_MAXLEN,
> +                        SHM_DEVNAME_FORMAT, odp_global_data.main_pid,
> name);
> +               fd = shm_open(shm_devname, oflag,
>                               S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
>                 if (fd == -1) {
> -                       ODP_DBG("%s: shm_open failed.\n", name);
> +                       ODP_DBG("%s: shm_open failed.\n", shm_devname);
>                         return ODP_SHM_INVALID;
>                 }
>         } else {
> --
> 2.1.4
>
>
_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to