From patchwork Thu Aug 7 12:48:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 35042 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f198.google.com (mail-yk0-f198.google.com [209.85.160.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C270F21137 for ; Thu, 7 Aug 2014 12:48:56 +0000 (UTC) Received: by mail-yk0-f198.google.com with SMTP id q200sf11908049ykb.5 for ; Thu, 07 Aug 2014 05:48:56 -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=ZjigUvmVvU+NKbN+GnpYjh7LrRyx3NeDJ/4suFOpqy0=; b=JCpW/8Fb2URztmTorj26X1A3O/KfWLtOMGTgY5BwruEy2TUqp0dudwz3YyX+LXO59k lD7dOVC6O1CtWcaKlzq8PVyl0sH9bcP1OycEI+VJbip0kA76C86mKe8wLYgNUkSh7+O+ H43qeQXy/37MLS+23vQnq3/zRYL7dSlwkCaS2QjAxjl+sCOjEQxPHYbs85gwqZ3ZlNPE M9RzI3cfTsYGKxPBWgqDzf9rrKRop/cJg161TcQGLzrVvn0E+4V2qgUQSYVIw6SCsbZn VfwPVZUtOjbwGh+MKwqTwWsdeHt4BDEV+slS9jjk6svnAfaG/yh604T5s0DvK6r2wz9G pqEQ== X-Gm-Message-State: ALoCoQnOYrCTZ3KM0GmCjQADbIH7hCL1PXWXtgwUeMJLIrC5iWlysfK/cTdBgvu+lf6ybEJ+Uzrh X-Received: by 10.236.26.105 with SMTP id b69mr88705yha.55.1407415736630; Thu, 07 Aug 2014 05:48:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.18 with SMTP id z18ls130718qge.0.gmail; Thu, 07 Aug 2014 05:48:56 -0700 (PDT) X-Received: by 10.220.202.9 with SMTP id fc9mr9442349vcb.40.1407415736478; Thu, 07 Aug 2014 05:48:56 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id j3si1717979vcn.48.2014.08.07.05.48.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 05:48:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id hy10so6113942vcb.32 for ; Thu, 07 Aug 2014 05:48:56 -0700 (PDT) X-Received: by 10.52.248.42 with SMTP id yj10mr1830775vdc.50.1407415736394; Thu, 07 Aug 2014 05:48:56 -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 tc5csp26999vcb; Thu, 7 Aug 2014 05:48:54 -0700 (PDT) X-Received: by 10.224.92.83 with SMTP id q19mr26073814qam.29.1407415734092; Thu, 07 Aug 2014 05:48:54 -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 q93si6015592qgd.109.2014.08.07.05.48.53 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 07 Aug 2014 05:48:53 -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 1XFN7l-0002HA-3M; Thu, 07 Aug 2014 12:48:53 +0000 Received: from mail-lb0-f180.google.com ([209.85.217.180]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XFN7K-0002Ex-CM for lng-odp@lists.linaro.org; Thu, 07 Aug 2014 12:48:26 +0000 Received: by mail-lb0-f180.google.com with SMTP id v6so2616274lbi.25 for ; Thu, 07 Aug 2014 05:48:20 -0700 (PDT) X-Received: by 10.112.14.199 with SMTP id r7mr15854930lbc.58.1407415700289; Thu, 07 Aug 2014 05:48:20 -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 q8sm2032933laj.33.2014.08.07.05.48.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 05:48:19 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 7 Aug 2014 16:48:06 +0400 Message-Id: <1407415686-352-7-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1407415686-352-1-git-send-email-maxim.uvarov@linaro.org> References: <1407415686-352-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [IPC PATCH DISCUSSION 6/6] 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.173 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 | 60 ++++++++++++++++++---- 5 files changed, 58 insertions(+), 13 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..3f1cdce 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; @@ -110,6 +112,7 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, huge_sz = odp_sys_huge_page_size(); page_sz = odp_sys_page_size(); #endif + void *addr = MAP_FAILED; odp_spinlock_lock(&odp_shm_tbl->lock); @@ -134,6 +137,31 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, block = &odp_shm_tbl->block[i]; + 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; + } + + /* Allocate memory */ mem_config.size = size + align; mem_config.flags = TI_EM_OSAL_MEM_CACHED; @@ -156,23 +184,31 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, align); return NULL; } + /* remap cma memory to shm mem */ + if (flag == ODP_SHM_PROC || flag == ODP_SHM_PROC_NOCREAT) { + addr = mmap((void *)mem_config.vaddr, size + align, + PROT_READ | PROT_WRITE, + mmap_flags, shm, 0); + } else { + addr = (void *)mem_config.vaddr; + } + } else if (type == ODP_SHM_MMAP) { - void *addr = MAP_FAILED; block->huge = 0; #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; } @@ -180,17 +216,22 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align, if (addr == MAP_FAILED) { /* Alloc failed */ odp_spinlock_unlock(&odp_shm_tbl->lock); + if (flag != ODP_SHM_PROC_NOCREAT) + shm_unlink(name); return NULL; } - mem_config.vaddr = (uintptr_t)addr; } else { + odp_spinlock_unlock(&odp_shm_tbl->lock); ODP_ERR("Unknown shared memory type: %d\n", type); + if (flag != ODP_SHM_PROC_NOCREAT) + shm_unlink(name); + return NULL; } block->mem_config = mem_config; /* move to correct alignment */ - block->addr = ODP_ALIGN_ROUNDUP_PTR(mem_config.vaddr, align); + block->addr = ODP_ALIGN_ROUNDUP_PTR(addr, align); strncpy(block->name, name, ODP_SHM_NAME_LEN - 1); block->name[ODP_SHM_NAME_LEN - 1] = 0; @@ -208,9 +249,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)