From patchwork Thu Aug 7 11:44:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 35035 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3A78421457 for ; Thu, 7 Aug 2014 11:44:44 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id nu7sf15843957obb.3 for ; Thu, 07 Aug 2014 04:44:43 -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: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=5WyS+VGxVem9oJLN8uUd4OXBoyxVjhpSFpmW0jcJx2A=; b=FoqS4lLQ/PIEtpqs8Lf5Tn/eGSutcHz8q7Koh3ew7zRb+nZQ/j6dhxBYOHN5yhMWrM qGMDezUJrDRtXq8/AudXMHqFa1OmL2Xp2obj1MlkDDxpe8HZE72MmmcQfyMvBnfocc9w FtpvgiKxp7tEWhTgr2v8k1ucyMmKsSKU8hmNELxvz9UBo5fDQE7AlbZKqgl4pov7hF4f K0gm4yGkTc7nL6y1X0Lt1NA/B4AGr3AgueTK23PTHFGF4cn1JUF5KMKl29Mj3y6//RVu cbhZvZGMOSYF/GkhnA3h4ZWqYy3HBGECj6CfkShXSN3fN5RvyrBmCoY55sAD40APW7ml qnzw== X-Gm-Message-State: ALoCoQkZg0diYzelwVhjiqxaOG6L1u+jSKG8WXGPq2FqAXirjc6rUps1LPYZ4c8P2AeUXR53NNet X-Received: by 10.42.207.146 with SMTP id fy18mr1235904icb.12.1407411883771; Thu, 07 Aug 2014 04:44:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.106 with SMTP id 97ls117683qgq.26.gmail; Thu, 07 Aug 2014 04:44:43 -0700 (PDT) X-Received: by 10.220.1.5 with SMTP id 5mr46534vcd.74.1407411883631; Thu, 07 Aug 2014 04:44:43 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id dc1si1669569vdc.4.2014.08.07.04.44.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 04:44:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so5968859vcb.26 for ; Thu, 07 Aug 2014 04:44:43 -0700 (PDT) X-Received: by 10.221.47.9 with SMTP id uq9mr305350vcb.48.1407411883534; Thu, 07 Aug 2014 04:44:43 -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 tc5csp22784vcb; Thu, 7 Aug 2014 04:44:43 -0700 (PDT) X-Received: by 10.224.28.66 with SMTP id l2mr26452151qac.46.1407411882807; Thu, 07 Aug 2014 04:44:42 -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 r9si5800134qaj.102.2014.08.07.04.44.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 07 Aug 2014 04:44:42 -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 1XFM7d-0000Qm-Bg; Thu, 07 Aug 2014 11:44:41 +0000 Received: from mail-lb0-f173.google.com ([209.85.217.173]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XFM7W-0000Qh-GR for lng-odp@lists.linaro.org; Thu, 07 Aug 2014 11:44:34 +0000 Received: by mail-lb0-f173.google.com with SMTP id u10so695938lbd.4 for ; Thu, 07 Aug 2014 04:44:28 -0700 (PDT) X-Received: by 10.152.20.168 with SMTP id o8mr15975463lae.4.1407411868466; Thu, 07 Aug 2014 04:44:28 -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 ok1sm5745248lbc.18.2014.08.07.04.44.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 04:44:27 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 7 Aug 2014 15:44:21 +0400 Message-Id: <1407411861-16228-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Topics: patch Subject: [lng-odp] [PATCHv2] 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.181 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 --- v2: shm add CMA support ****Patch not tested******. .../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)