From patchwork Thu Aug 7 06:43:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 35017 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 49B3B20523 for ; Thu, 7 Aug 2014 06:43:33 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf14924791oag.8 for ; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=8+TIhxoqY9cPZSnnbBHFVvVLyT37AEPhePXTqgXUIUc=; b=PO+BGagKh086Vue4cksuaRZuYUorKj6G0oSqt5EBt8vqzAcMG4B+duclg3l+AtF1kt +B8LIAyvn/rNJ+1YJrpPseYC+O9swCcuqc9/6AhuHJ2zZqceCcqQXn5BZ8Vj1ZKS2knk ARHfsIBLsozOgwzsN/UgUvMmY6xoyEz03+REkKXlpby0eGQc0VL3cuOgQkXdo2i2bGQw bJ2iosTVFiY6CYoq5tAXUmlbauxFJ+rWzG7QONJXEgbJsJGT0DJwY3Cn6aBQdOP8WO0W 7RXAn9ToRAw7/TYKeamp7GPt/z/BVHLb7r4HcdAQLhCu9UBzAQVEl9O8+GZj/RD4F1Ps sBYA== X-Gm-Message-State: ALoCoQlodRypZQoqrI8vaFFGwRMcBDJtPQP8SeOlAbs9RfEokBSin0AwC3yF2+tTHl2G4ft0zF8T X-Received: by 10.50.88.105 with SMTP id bf9mr1391068igb.1.1407393812879; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.34 with SMTP id c31ls61591qge.92.gmail; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) X-Received: by 10.220.181.196 with SMTP id bz4mr14802002vcb.36.1407393812782; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id sb10si1430564vdc.89.2014.08.06.23.43.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 23:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so5678216vcb.9 for ; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) X-Received: by 10.52.127.5 with SMTP id nc5mr108636vdb.59.1407393812681; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp5212vcb; Wed, 6 Aug 2014 23:43:32 -0700 (PDT) X-Received: by 10.140.92.20 with SMTP id a20mr10130823qge.0.1407393812036; Wed, 06 Aug 2014 23:43:32 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u9si4890158qag.56.2014.08.06.23.43.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 06 Aug 2014 23:43:32 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XFHQB-0008Li-7a; Thu, 07 Aug 2014 06:43:31 +0000 Received: from mail-la0-f54.google.com ([209.85.215.54]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XFHPx-0008H6-0j for lng-odp@lists.linaro.org; Thu, 07 Aug 2014 06:43:17 +0000 Received: by mail-la0-f54.google.com with SMTP id hz20so3201532lab.27 for ; Wed, 06 Aug 2014 23:43:11 -0700 (PDT) X-Received: by 10.112.136.40 with SMTP id px8mr14177862lbb.36.1407393791162; Wed, 06 Aug 2014 23:43:11 -0700 (PDT) Received: from localhost.localdomain (ppp91-76-29-79.pppoe.mtu-net.ru. [91.76.29.79]) by mx.google.com with ESMTPSA id oy1sm4763464lbb.4.2014.08.06.23.43.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 23:43:10 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 7 Aug 2014 10:43:01 +0400 Message-Id: <1407393782-6189-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1407393782-6189-1-git-send-email-maxim.uvarov@linaro.org> References: <1407393782-6189-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/3] linux-keystone2: pass shm arg to odp_shm_reserve() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Maxim Uvarov --- .../include/odp_shared_memory_internal.h | 2 +- platform/linux-keystone2/odp_buffer_pool.c | 3 +- platform/linux-keystone2/odp_packet_io.c | 3 +- platform/linux-keystone2/odp_queue.c | 3 +- platform/linux-keystone2/odp_shared_memory.c | 45 +++++++++++++++++++--- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/platform/linux-keystone2/include/odp_shared_memory_internal.h b/platform/linux-keystone2/include/odp_shared_memory_internal.h index 833091e..fedec78 100644 --- a/platform/linux-keystone2/include/odp_shared_memory_internal.h +++ b/platform/linux-keystone2/include/odp_shared_memory_internal.h @@ -19,7 +19,7 @@ extern "C" { #endif void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, - int type); + int type, odp_shm_e flag); uintptr_t _odp_shm_get_paddr(void *vaddr); #ifdef __cplusplus diff --git a/platform/linux-keystone2/odp_buffer_pool.c b/platform/linux-keystone2/odp_buffer_pool.c index 6ce02d4..f3e6f01 100644 --- a/platform/linux-keystone2/odp_buffer_pool.c +++ b/platform/linux-keystone2/odp_buffer_pool.c @@ -96,7 +96,8 @@ int odp_buffer_pool_init_global(void) pool_tbl = odp_shm_reserve("odp_buffer_pools", sizeof(pool_table_t), - sizeof(pool_entry_t)); + sizeof(pool_entry_t), + ODP_SHM_THREAD); if (pool_tbl == NULL) return -1; diff --git a/platform/linux-keystone2/odp_packet_io.c b/platform/linux-keystone2/odp_packet_io.c index 1ded021..18efecd 100644 --- a/platform/linux-keystone2/odp_packet_io.c +++ b/platform/linux-keystone2/odp_packet_io.c @@ -71,7 +71,8 @@ int odp_pktio_init_global(void) pktio_tbl = odp_shm_reserve("odp_pktio_entries", sizeof(pktio_table_t), - sizeof(pktio_entry_t)); + sizeof(pktio_entry_t), + ODP_SHM_THREAD); if (pktio_tbl == NULL) return -1; diff --git a/platform/linux-keystone2/odp_queue.c b/platform/linux-keystone2/odp_queue.c index 031eeff..8963d6a 100644 --- a/platform/linux-keystone2/odp_queue.c +++ b/platform/linux-keystone2/odp_queue.c @@ -99,7 +99,8 @@ int odp_queue_init_global(void) queue_tbl = odp_shm_reserve("odp_queues", sizeof(queue_table_t), - sizeof(queue_entry_t)); + sizeof(queue_entry_t), + ODP_SHM_THREAD); if (queue_tbl == NULL) return -1; diff --git a/platform/linux-keystone2/odp_shared_memory.c b/platform/linux-keystone2/odp_shared_memory.c index e595111..bef7d40 100644 --- a/platform/linux-keystone2/odp_shared_memory.c +++ b/platform/linux-keystone2/odp_shared_memory.c @@ -99,9 +99,11 @@ enum { }; void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, - int type) + int type, odp_shm_e flag) { - int i; + int i, ret, shm_open_flags; + int shm = -1; + int mmap_flags = MAP_SHARED; odp_shm_block_t *block; #ifdef MAP_HUGETLB uint64_t huge_sz, page_sz; @@ -144,6 +146,12 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, mem_config.mapping_id = -1; if (type == ODP_SHM_CMA) { + if (flag != ODP_SHM_THREAD) { + ODP_ERR("shm_open with ODP_SHM_CMA is not implemented\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return NULL; + } + ti_em_rh_alloc_map_cma(&mem_config); if (!mem_config.vaddr) { @@ -161,18 +169,42 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, void *addr = MAP_FAILED; block->huge = 0; + if (flag != ODP_SHM_THREAD) { + shm_open_flags = O_RDWR; + if (flag == ODP_SHM_PROC) + shm_open_flags |= O_CREAT; + + shm = shm_open(name, shm_open_flags, S_IRUSR | S_IWUSR); + if (shm == -1) { + odp_spinlock_unlock(&odp_shm_tbl->lock); + ODP_ERR("shm_open failed"); + return NULL; + } + + ret = ftruncate(shm, size + align); + if (ret == -1) { + odp_spinlock_unlock(&odp_shm_tbl->lock); + if (flag != ODP_SHM_PROC_NOCREAT) + shm_unlink(name); + ODP_ERR("ftruncate failed"); + return NULL; + } + } else { + mmap_flags |= MAP_ANONYMOUS; + } + #ifdef MAP_HUGETLB /* Try first huge pages */ if (huge_sz && (size + align) > page_sz) { addr = mmap(NULL, size + align, PROT_READ | PROT_WRITE, - SHM_FLAGS | MAP_HUGETLB, -1, 0); + mmap_flags | MAP_HUGETLB, shm, 0); } #endif /* Use normal pages for small or failed huge page allocations */ if (addr == MAP_FAILED) { addr = mmap(NULL, size + align, PROT_READ | PROT_WRITE, - SHM_FLAGS, -1, 0); + mmap_flags, shm, 0); } else { block->huge = 1; } @@ -208,9 +240,10 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, return block->addr; } -void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align) +void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align, + odp_shm_e flag) { - return _odp_shm_reserve(name, size, align, ODP_SHM_CMA); + return _odp_shm_reserve(name, size, align, ODP_SHM_CMA, flag); } uintptr_t _odp_shm_get_paddr(void *vaddr)