From patchwork Tue Feb 23 18:14:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 62747 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1946540lbl; Tue, 23 Feb 2016 09:16:11 -0800 (PST) X-Received: by 10.141.4.139 with SMTP id g133mr45031109qhd.34.1456247771161; Tue, 23 Feb 2016 09:16:11 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z107si23843874qge.1.2016.02.23.09.16.10; Tue, 23 Feb 2016 09:16:11 -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 8617962F1E; Tue, 23 Feb 2016 17:16:10 +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 CFCD362F15; Tue, 23 Feb 2016 17:16:06 +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 DA4CC62F15; Tue, 23 Feb 2016 17:15:45 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id C2B29622D0 for ; Tue, 23 Feb 2016 17:15:44 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id l143so119908041lfe.2 for ; Tue, 23 Feb 2016 09:15:44 -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=yk0gHmVlx2hl+SJEw9rfN2Ykyq/WIZ9mw+NkSVpNl04=; b=OS1VMR8NX6iREepgeukCwhhFwb1oihuW9TNBuTL81sdgwttVUkmUbYfurUOi09NlPN pnUXbBzcB7pqdLIoCO0Eqh+P2PzPYO/3WAcvmcUIanlV0g2XbH5MbCMirXn+bw8RD+Dq 98t4bb7f0QYDAmlU2DcbAYGdeWGte6A+2NuzUdh2pGnj+JwwpEWAu7R8R3b1sf4nX3rn cpOZCLwSWyxESoDgAExUJaMZ4xhF+RUW90pXNtoeJ1hMk7yc+Q9Rx2SZg+m59fMB0TDy OHcr8o6gWTUgsB8M2MrcHe35u2sdZEB2miDQ/qxP7T0ueep6qT63C81PKuJzyTkMYMGP TWmw== X-Gm-Message-State: AG10YOQx0230sPccUS5Lx1+WSqs+z67VI0ojbWOnFw+1FWV2i3nfQTSfzttYgpl9utjRfE4etEA= X-Received: by 10.25.65.5 with SMTP id o5mr13307252lfa.38.1456247743725; Tue, 23 Feb 2016 09:15:43 -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 z194sm4155995lfd.20.2016.02.23.09.15.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Feb 2016 09:15:42 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org Date: Tue, 23 Feb 2016 19:14:47 +0100 Message-Id: <1456251287-65413-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] [PATCHv2] 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 "/odp--" so as to name scope ODP shared mem in /dev/shmem. Signed-off-by: Christophe Milard Reviewed-and-tested-by: Bill Fischofer --- since v1: fixed typo in commit message (Nikolay Nikolaev) 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 {