From patchwork Wed Dec 21 11:11:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 88709 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2186960qgi; Wed, 21 Dec 2016 02:12:07 -0800 (PST) X-Received: by 10.55.36.204 with SMTP id k73mr4235498qkk.125.1482315127448; Wed, 21 Dec 2016 02:12:07 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 31si14634484qty.166.2016.12.21.02.12.06; Wed, 21 Dec 2016 02:12:07 -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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 962C6635DC; Wed, 21 Dec 2016 10:12:06 +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 027C36358A; Wed, 21 Dec 2016 10:12:01 +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 ECD3A635BE; Wed, 21 Dec 2016 10:11:56 +0000 (UTC) Received: from mail-lf0-f46.google.com (mail-lf0-f46.google.com [209.85.215.46]) by lists.linaro.org (Postfix) with ESMTPS id 98C9A62C47 for ; Wed, 21 Dec 2016 10:11:55 +0000 (UTC) Received: by mail-lf0-f46.google.com with SMTP id c13so94555766lfg.0 for ; Wed, 21 Dec 2016 02:11:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VQqx/n1g47DwBmJ2IlbKMT8YljeC3SWGVjSP15eKyHM=; b=cGWOG3Do9QzQHhimFl7LpiFlV5QCRBOZ90/6kSJ+uotxkQgUvZa4C7UqgP7OrxiM+b ZSPyTnJ2duWV+UeAmpQ/duQvaDN7CTg1XcWtO6nPrtyGSjHuPHk2pW6MxYX7gAmXQ28a b9weygQvAVESoW17l13SdGz9Je6YH60PCN4vIoJkTmbjCpLgoDZ3Bs7zpM/O7oNy12zv HybWpF22ZRHZe/CY2N8yHin/P4+1JBlJm+v6HhbSAmesVzBGLuYnuvmllRJlTJK0j0iz cBi2MP7yh8L4Y+rYPpyle16sayvyBkiVHMEejlG54+XxB2fpYfPrxLdRGFGspsGy/DGw j7OQ== X-Gm-Message-State: AIkVDXJ3MVFZ5mSpJLPXHVEAaCOoXeEQECA8V2Rm919/BhEjPOoYseZ5j100ZnO9rVj4T154nu4= X-Received: by 10.25.41.203 with SMTP id p194mr1487789lfp.108.1482315114216; Wed, 21 Dec 2016 02:11:54 -0800 (PST) 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 c25sm5636712ljb.32.2016.12.21.02.11.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Dec 2016 02:11:53 -0800 (PST) From: Christophe Milard To: maxim.uvarov@linaro.com, mike.holmes@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 21 Dec 2016 12:11:32 +0100 Message-Id: <1482318693-5086-1-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [API-NEXT PATCH 1/2] linux-gen: _ishm: exporting/importing user len and flags 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" The size of the shared memory and its user flag set, as given at reserve time, are exported and imported so that odp_shm_info() return proper values on imported blocks Signed-off-by: Christophe Milard --- platform/linux-generic/_ishm.c | 38 +++++++++++++++++----- .../validation/api/shmem/shmem_linux.c | 14 ++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index 449e357..8b32709 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -124,7 +124,9 @@ #define EXPORT_FILE_LINE3_FMT "file: %s" #define EXPORT_FILE_LINE4_FMT "length: %" PRIu64 #define EXPORT_FILE_LINE5_FMT "flags: %" PRIu32 -#define EXPORT_FILE_LINE6_FMT "align: %" PRIu32 +#define EXPORT_FILE_LINE6_FMT "user_length: %" PRIu64 +#define EXPORT_FILE_LINE7_FMT "user_flags: %" PRIu32 +#define EXPORT_FILE_LINE8_FMT "align: %" PRIu32 /* * A fragment describes a piece of the shared virtual address space, * and is allocated only when allocation is done with the _ODP_ISHM_SINGLE_VA @@ -477,7 +479,11 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, new_block->filename); fprintf(export_file, EXPORT_FILE_LINE4_FMT "\n", len); fprintf(export_file, EXPORT_FILE_LINE5_FMT "\n", flags); - fprintf(export_file, EXPORT_FILE_LINE6_FMT "\n", align); + fprintf(export_file, EXPORT_FILE_LINE6_FMT "\n", + new_block->user_len); + fprintf(export_file, EXPORT_FILE_LINE7_FMT "\n", + new_block->user_flags); + fprintf(export_file, EXPORT_FILE_LINE8_FMT "\n", align); fclose(export_file); } @@ -800,6 +806,10 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, else new_block->name[0] = 0; + /* save user data: */ + new_block->user_flags = user_flags; + new_block->user_len = size; + /* If a file descriptor is provided, get the real size and map: */ if (fd >= 0) { fstat(fd, &statbuf); @@ -911,9 +921,11 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, FILE *export_file; uint64_t len; uint32_t flags; + uint64_t user_len; + uint32_t user_flags; uint32_t align; int fd; - int ret; + int block_index; /* try to read the block description file: */ snprintf(export_filename, ISHM_FILENAME_MAXLEN, @@ -943,7 +955,13 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, if (fscanf(export_file, EXPORT_FILE_LINE5_FMT " ", &flags) != 1) goto error_exp_file; - if (fscanf(export_file, EXPORT_FILE_LINE6_FMT " ", &align) != 1) + if (fscanf(export_file, EXPORT_FILE_LINE6_FMT " ", &user_len) != 1) + goto error_exp_file; + + if (fscanf(export_file, EXPORT_FILE_LINE7_FMT " ", &user_flags) != 1) + goto error_exp_file; + + if (fscanf(export_file, EXPORT_FILE_LINE8_FMT " ", &align) != 1) goto error_exp_file; fclose(export_file); @@ -960,13 +978,17 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, flags &= ~(uint32_t)_ODP_ISHM_EXPORT; /* reserve the memory, providing the opened file descriptor: */ - ret = _odp_ishm_reserve(local_name, 0, fd, align, flags, 0); - if (ret < 0) { + block_index = _odp_ishm_reserve(local_name, 0, fd, align, flags, 0); + if (block_index < 0) { close(fd); - return ret; + return block_index; } - return ret; + /* set inherited info: */ + ishm_tbl->block[block_index].user_flags = user_flags; + ishm_tbl->block[block_index].user_len = user_len; + + return block_index; error_exp_file: fclose(export_file); diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c index 39473f3..2f4c762 100644 --- a/test/linux-generic/validation/api/shmem/shmem_linux.c +++ b/test/linux-generic/validation/api/shmem/shmem_linux.c @@ -102,7 +102,8 @@ */ static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname, char *filename, uint64_t *len, - uint32_t *flags, uint32_t *align) + uint32_t *flags, uint64_t *user_len, + uint32_t *user_flags, uint32_t *align) { char shm_attr_filename[PATH_MAX]; FILE *export_file; @@ -130,6 +131,12 @@ static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname, if (fscanf(export_file, "flags: %" PRIu32 " ", flags) != 1) goto export_file_read_err; + if (fscanf(export_file, "user_length: %" PRIu64 " ", user_len) != 1) + goto export_file_read_err; + + if (fscanf(export_file, "user_flags: %" PRIu32 " ", user_flags) != 1) + goto export_file_read_err; + if (fscanf(export_file, "align: %" PRIu32 " ", align) != 1) goto export_file_read_err; @@ -192,6 +199,8 @@ int main(int argc __attribute__((unused)), char *argv[]) char shm_filename[PATH_MAX];/* shared mem device name, under /dev/shm */ uint64_t len; uint32_t flags; + uint64_t user_len; + uint32_t user_flags; uint32_t align; int shm_fd; test_shared_linux_data_t *addr; @@ -231,7 +240,8 @@ int main(int argc __attribute__((unused)), char *argv[]) /* read the shared memory attributes (includes the shm filename): */ if (read_shmem_attribues(odp_app1, ODP_SHM_NAME, - shm_filename, &len, &flags, &align) != 0) + shm_filename, &len, &flags, + &user_len, &user_flags, &align) != 0) test_failure(fifo_name, fifo_fd, odp_app1); /* open the shm filename (which is either on /tmp or on hugetlbfs)