From patchwork Tue Feb 23 16:57:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 62727 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1906088lbl; Tue, 23 Feb 2016 07:58:20 -0800 (PST) X-Received: by 10.55.75.77 with SMTP id y74mr41899693qka.19.1456243100020; Tue, 23 Feb 2016 07:58:20 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g205si33004778qkb.89.2016.02.23.07.58.19; Tue, 23 Feb 2016 07:58:19 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 50679617D5; Tue, 23 Feb 2016 15:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id DC2CE6177D; Tue, 23 Feb 2016 15:58:14 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B7E196177D; Tue, 23 Feb 2016 15:58:09 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id A480661756 for ; Tue, 23 Feb 2016 15:58:08 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id bc4so103442950lbc.2 for ; Tue, 23 Feb 2016 07:58:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VmLW1kcHaxEee2HkUfnYUYYi4ux35zBqyU0RLiHu4DE=; b=ekobHr871x4IOyAdDObQJqAniRsxYlmYRj/8EN6LS8LimeKlNL14ES9QIg0yxrrM6n FZC79OHIiz3Tw/HWgnSUVOaAIMY4J4jUC6pI+wEFF/7++plEgs7IET8opM5/FOtwloMw i+Y4+KC4vtH8mDsNbo4iOrqVJ3M0C4S9B6MGSAVbtOgNT3Oe2/VP3FSWCvxSOcT9vrj3 2WHqHkj6aEs93SEHpe+Rz6EcniYxX0nj7d8Nsqz65jR/dwDNrqLk3INNXyo15cBYB5bN YO4vHicI1j5cncAYFfyIURwgBB6e+DAhEdkQfl5GL6WrOoMa36ipSWpdQEqxefibfx++ fm2g== X-Gm-Message-State: AG10YOTklkOhmK+bXGseGfrPT67CVr3klUqARzOwHeM1jOz+uEEPoVboSK+5Q5tHi05y9veJIic= X-Received: by 10.112.156.100 with SMTP id wd4mr3999996lbb.9.1456243087648; Tue, 23 Feb 2016 07:58:07 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id o97sm4204899lfi.25.2016.02.23.07.58.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Feb 2016 07:58:06 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org Date: Tue, 23 Feb 2016 17:57:11 +0100 Message-Id: <1456246631-64934-1-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCH] linux-generic: shmem: odp scope in /dev/shmem X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The name of the shared memory (created with linux shm_open() when the ODP_SHM_PROC flag is given) is now prefixed with "/opd--" so as to name scope ODP shared mem in /dev/shmem. Signed-off-by: Christophe Milard --- 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 #include #include +#include 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 #include #include +#include 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 #include +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-- */ + _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 {