From patchwork Wed Nov 19 15:36:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41180 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9432C241C9 for ; Wed, 19 Nov 2014 15:36:59 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e53sf887800eek.3 for ; Wed, 19 Nov 2014 07:36:58 -0800 (PST) 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=RRuhiCYq7Yswy5y4q5HYANxObCsYqfvYCWAPgDgOm8E=; b=AuAoEAaZ4awh6TwgjgTNpY7T+y8mS9+3FUuv7qwVbfU+5EORO9HTOjjTl50y9QkVmc 3/Y88WaK0Cx/Uo/NgCpiDeVI6V499Oc1KATXKHnBN31F4tQ5JraI6240E75+pyW9M7C4 AtoWNuvzSdIHE3kKFDHE9wCdHagmnKhifYFB2YgVrGtCIhoKs4u7Nazm/UysP9yZZNq4 aK4a31MGoOEJLwWVhkJEVFiWYnjyiwdZqh17yJIvQCvSclhttGSXUMJm+l/MCZ+9geRy k9519pvHWrOZvuXjTV0YDcKesfanIS6ZeQRjKVs0zH3OKW/vCy7k3HDZ5zEInP0v+avI 3A4Q== X-Gm-Message-State: ALoCoQk6rGPSwU6W/pKGOnoxfE65ZtRvVXp8N+4lxaVyXRrrKdLK6WKoiQX/WlxG1ad2qUpUhPNz X-Received: by 10.180.94.3 with SMTP id cy3mr902587wib.7.1416411418186; Wed, 19 Nov 2014 07:36:58 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.227 with SMTP id i3ls1130969lae.28.gmail; Wed, 19 Nov 2014 07:36:57 -0800 (PST) X-Received: by 10.112.142.197 with SMTP id ry5mr6089068lbb.26.1416411417929; Wed, 19 Nov 2014 07:36:57 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id n9si2151630lbc.57.2014.11.19.07.36.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 07:36:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id mc6so722676lab.10 for ; Wed, 19 Nov 2014 07:36:57 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr6079909lal.29.1416411417791; Wed, 19 Nov 2014 07:36:57 -0800 (PST) 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.112.184.201 with SMTP id ew9csp103931lbc; Wed, 19 Nov 2014 07:36:57 -0800 (PST) X-Received: by 10.236.3.69 with SMTP id 45mr39112417yhg.24.1416411416436; Wed, 19 Nov 2014 07:36:56 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id h92si2514386qgh.22.2014.11.19.07.36.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 07:36:56 -0800 (PST) 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-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xr7JO-000249-Cb; Wed, 19 Nov 2014 15:36:54 +0000 Received: from mail-pd0-f176.google.com ([209.85.192.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xr7JH-00023x-Rc for lng-odp@lists.linaro.org; Wed, 19 Nov 2014 15:36:47 +0000 Received: by mail-pd0-f176.google.com with SMTP id y10so1079961pdj.7 for ; Wed, 19 Nov 2014 07:36:42 -0800 (PST) X-Received: by 10.66.119.105 with SMTP id kt9mr15005076pab.113.1416411402349; Wed, 19 Nov 2014 07:36:42 -0800 (PST) Received: from ysm-linux.localdomain ([223.65.50.73]) by mx.google.com with ESMTPSA id tv4sm2234356pab.28.2014.11.19.07.36.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Nov 2014 07:36:41 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Wed, 19 Nov 2014 23:36:31 +0800 Message-Id: <1416411391-19060-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v3] add implement for odp_shm_free 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: yan.songming@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.215.51 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 New API implementing odp_shm_free to match the odp_shm_reserve. Signed-off-by: Yan Songming --- v3 change the return value of odp_shm_free. v2 fix the problem which Maxim found. --- .../linux-generic/include/api/odp_shared_memory.h | 2 +- platform/linux-generic/odp_shared_memory.c | 43 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/platform/linux-generic/include/api/odp_shared_memory.h b/platform/linux-generic/include/api/odp_shared_memory.h index ff6f9a9..d42e272 100644 --- a/platform/linux-generic/include/api/odp_shared_memory.h +++ b/platform/linux-generic/include/api/odp_shared_memory.h @@ -81,7 +81,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, * @param[in] shm Block handle * * @retval 0 for success - * @retval 1 on failure + * @retval -1 on failure */ int odp_shm_free(odp_shm_t shm); diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 24a5d60..bc0ab55 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -114,6 +114,43 @@ static int find_block(const char *name, uint32_t *index) return 0; } +int odp_shm_free(odp_shm_t shm) +{ + uint32_t i; + int ret; + odp_shm_block_t *shm_block; + uint64_t alloc_size; + + i = from_handle(shm); + if (odp_shm_tbl->block[i].addr == NULL) { + /* free block */ + ODP_DBG("odp_shm_free: Free block\n"); + return 0; + } + + odp_spinlock_lock(&odp_shm_tbl->lock); + shm_block = &odp_shm_tbl->block[i]; + + alloc_size = shm_block->size + shm_block->align; + ret = munmap(shm_block->addr, alloc_size); + if (0 != ret) { + ODP_DBG("odp_shm_free: munmap failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + + if (shm_block->flags & ODP_SHM_PROC) { + ret = shm_unlink(shm_block->name); + if (0 != ret) { + ODP_DBG("odp_shm_free: shm_unlink failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + } + memset(&odp_shm_tbl->block[i], 0, sizeof(odp_shm_block_t)); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return 0; +} odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags) @@ -221,12 +258,6 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, return block->hdl; } -int odp_shm_free(odp_shm_t shm ODP_UNUSED) -{ - ODP_UNIMPLEMENTED(); - return 0; -} - odp_shm_t odp_shm_lookup(const char *name) { uint32_t i;