From patchwork Fri Oct 7 10:35:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 77322 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp246220qge; Fri, 7 Oct 2016 02:36:44 -0700 (PDT) X-Received: by 10.200.53.165 with SMTP id k34mr19037991qtb.119.1475833003941; Fri, 07 Oct 2016 02:36:43 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z49si3153747qta.11.2016.10.07.02.36.43; Fri, 07 Oct 2016 02:36:43 -0700 (PDT) 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8FC2D617BF; Fri, 7 Oct 2016 09:36:43 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 4192D617AF; Fri, 7 Oct 2016 09:36:35 +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 7EA1C617BC; Fri, 7 Oct 2016 09:36:28 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 5E8C3617AD for ; Fri, 7 Oct 2016 09:36:14 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id b75so36552872lfg.3 for ; Fri, 07 Oct 2016 02:36:14 -0700 (PDT) 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:in-reply-to :references; bh=MFJeSrM6rZbfH0S6RI3uncrkQg16S8KdPoOiP9bPn9Q=; b=k+1AGPkKtM4YSFWMkwtSGXzA1HVt4OrA6y3Kx4Vg+CHEfUqeSa5AQ5gRyP5KmyTUCY i1/0oD2Zja3qcd1hpt2ytGwn9RjPixJXRzuBiUpBw3oc2dV/7yKCh5q7d+UzGhEqpslV L32QpEM/KrfWWysNBERe0c1mgeBdpTPJhD3mV56ewlpWpEI/+QpXM3JL3W5y6XDNN9UF diCcZFv3QVNSzcLy4R2UgvWXflKb1ZD6cNDsqNlmOFA2jDQzFQCjwir9bo25qfHzf+vi PTvLW+scXf6R5tCMb+licDun5vAImzrLVGF43l8OqghG7YXp+WCPrfhuMK/ceD2uIHn/ zejg== X-Gm-Message-State: AA6/9Rn73mFt+GrnqaSW1EyajG2oQi7JNXItHIZQX6sl/xW/kivJpKXEvkB+Ch1f1wu0IpLbqs0= X-Received: by 10.25.27.139 with SMTP id b133mr7131155lfb.157.1475832973111; Fri, 07 Oct 2016 02:36:13 -0700 (PDT) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id 5sm3465255ljb.22.2016.10.07.02.36.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Oct 2016 02:36:12 -0700 (PDT) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Fri, 7 Oct 2016 12:35:04 +0200 Message-Id: <1475836517-60484-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475836517-60484-1-git-send-email-christophe.milard@linaro.org> References: <1475836517-60484-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 01/14] linux-gen: _ishm: create link for external memory sharing 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" A new flag called _ODP_ISHM_LINK is added to _ishm. When this flag is specified at reserve() time, a link ("/tmp/odp--shm-" where is the process ID of the main ODP instatiation process and is the block name given at reserve time) is created, linking to the underlying block file (either in /tmp or in hugetlbfs). This link is meant to be used by processes external to ODP willing to share this memory. Signed-off-by: Christophe Milard --- platform/linux-generic/_ishm.c | 35 +++++++++++++++++++++++-- platform/linux-generic/include/_ishm_internal.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index f4aa6d3..e6ceb24 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -99,6 +99,14 @@ #define ISHM_FILENAME_NORMAL_PAGE_DIR "/tmp" /* + * when the memory is to be shared with an external entity (such as another + * ODP instance or an OS process not part of this ODP instance) then a + * link is created to the underlying filename: this defines the location + * and the format of this link name + */ +#define ISHM_LINKNAME_FORMAT "/tmp/odp-%d-shm-%s" + +/* * At worse case the virtual space gets so fragmented that there is * a unallocated fragment between each allocated fragment: * In that case, the number of fragments to take care of is twice the @@ -136,6 +144,7 @@ typedef struct ishm_fragment { typedef struct ishm_block { char name[ISHM_NAME_MAXLEN]; /* name for the ishm block (if any) */ char filename[ISHM_FILENAME_MAXLEN]; /* name of the .../odp-* file */ + char linkname[ISHM_FILENAME_MAXLEN]; /* name of the /tmp/odp-* link */ int main_odpthread; /* The thread which did the initial reserve*/ uint32_t user_flags; /* any flags the user want to remember. */ uint32_t flags; /* block creation flags. */ @@ -380,7 +389,7 @@ static void free_fragment(ishm_fragment_t *fragmnt) * or /mnt/huge/odp-- (for huge pages) * Return the new file descriptor, or -1 on error. */ -static int create_file(int block_index, int huge, uint64_t len) +static int create_file(int block_index, int huge, uint64_t len, uint32_t flags) { char *name; int fd; @@ -429,6 +438,21 @@ static int create_file(int block_index, int huge, uint64_t len) strncpy(new_block->filename, filename, ISHM_FILENAME_MAXLEN - 1); + /* if _ODP_ISHM_LINK is set, create a symbolic link for external ref: */ + if (flags & _ODP_ISHM_LINK) { + snprintf(new_block->linkname, ISHM_FILENAME_MAXLEN, + ISHM_LINKNAME_FORMAT, + odp_global_data.main_pid, + (name && name[0]) ? name : seq_string); + if (symlink(filename, new_block->linkname) < 0) { + ODP_ERR("symlink failed: err=%s.\n", + strerror(errno)); + new_block->linkname[0] = 0; + } + } else { + new_block->linkname[0] = 0; + } + return fd; } @@ -456,7 +480,7 @@ static void *do_map(int block_index, uint64_t len, uint32_t align, * unless a fd was already given */ if (*fd < 0) { - *fd = create_file(block_index, huge, len); + *fd = create_file(block_index, huge, len, flags); if (*fd < 0) return NULL; } else { @@ -472,6 +496,8 @@ static void *do_map(int block_index, uint64_t len, uint32_t align, close(*fd); *fd = -1; unlink(new_block->filename); + if (new_block->linkname[0]) + unlink(new_block->linkname); } return NULL; } @@ -487,6 +513,8 @@ static void *do_map(int block_index, uint64_t len, uint32_t align, close(*fd); *fd = -1; unlink(new_block->filename); + if (new_block->linkname[0]) + unlink(new_block->linkname); } return NULL; } @@ -870,6 +898,9 @@ static int block_free(int block_index) /* remove the .../odp-* file, unless fd was external: */ if (block->filename[0] != 0) unlink(block->filename); + /* also remove possible link: */ + if (block->linkname[0] != 0) + unlink(block->linkname); /* deregister the file descriptor from the file descriptor server. */ _odp_fdserver_deregister_fd(FD_SRV_CTX_ISHM, block_index); diff --git a/platform/linux-generic/include/_ishm_internal.h b/platform/linux-generic/include/_ishm_internal.h index 3231b60..4fa6d9c 100644 --- a/platform/linux-generic/include/_ishm_internal.h +++ b/platform/linux-generic/include/_ishm_internal.h @@ -14,6 +14,7 @@ extern "C" { /* flags available at ishm_reserve: */ #define _ODP_ISHM_SINGLE_VA 1 #define _ODP_ISHM_LOCK 2 +#define _ODP_ISHM_LINK 4 /*create soft link in /tmp */ /** * Shared memory block info