From patchwork Thu Nov 20 07:12:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41218 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F2F0823588 for ; Thu, 20 Nov 2014 07:13:18 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id q1sf1388838lam.1 for ; Wed, 19 Nov 2014 23:13:18 -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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=JuZ2vMBLWce+H/GH8yDwWhNj1yeyr4W7jQzHBdp1Sr8=; b=IeajSRRhpEbzDOn70K3nyOdp8bKxbT/i3LCCQt9DwPGg8nFwRbFP55cPC9XI7iBpJL hAtVWY67ZoMpW107hedS9uZrNXLgcVV/BZY8EVXSvl4b4tabzV1izW3Cjzw87Gsffw/p aK5RU5TbbQIhGmW7viDCye3XgVINg583WxXh/5pUI2T+VLL4V61z2tgRl+NyhZ/MMcGh 4z2ONPOGEXDg/3pALYI/UUHRhFjSB+abDB8KW9eWZSCxlYD8mX9R+ZgbuvxPyWsC1WG0 QxaHTdgdVq3kYdLYGK5hoBCRnLHqrrn3V4PrnLwyAFRi+jo07QitCo2mWE9ZlRYju6Ny 6CPg== X-Gm-Message-State: ALoCoQmRktMAT6v+mJQQ9nipDF+jCz8DlpRLwTpfCXtLEMsXTa3k77U93gU6RQSGsYLbSfbDsb5I X-Received: by 10.112.151.38 with SMTP id un6mr1798287lbb.0.1416467597991; Wed, 19 Nov 2014 23:13:17 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.169 with SMTP id c9ls23127laa.104.gmail; Wed, 19 Nov 2014 23:13:17 -0800 (PST) X-Received: by 10.112.133.138 with SMTP id pc10mr9701200lbb.48.1416467597756; Wed, 19 Nov 2014 23:13:17 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id ap1si1345867lac.54.2014.11.19.23.13.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 23:13:17 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so1926563lab.34 for ; Wed, 19 Nov 2014 23:13:17 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr9530215laz.27.1416467597642; Wed, 19 Nov 2014 23:13:17 -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 ew9csp218002lbc; Wed, 19 Nov 2014 23:13:16 -0800 (PST) X-Received: by 10.224.127.133 with SMTP id g5mr58753748qas.24.1416467596278; Wed, 19 Nov 2014 23:13:16 -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 g1si1869426qaq.47.2014.11.19.23.13.15 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 23:13:16 -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 1XrLvU-00042I-Pw; Thu, 20 Nov 2014 07:13:12 +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 1XrLvN-00042A-W2 for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 07:13:06 +0000 Received: by mail-pd0-f176.google.com with SMTP id y10so2516400pdj.21 for ; Wed, 19 Nov 2014 23:13:00 -0800 (PST) X-Received: by 10.68.68.237 with SMTP id z13mr27389609pbt.151.1416467580413; Wed, 19 Nov 2014 23:13:00 -0800 (PST) Received: from localhost.localdomain ([210.51.195.9]) by mx.google.com with ESMTPSA id el1sm1104401pbc.80.2014.11.19.23.12.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Nov 2014 23:12:59 -0800 (PST) From: Yan Sonming To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 02:12:48 -0500 Message-Id: <1416467568-20380-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v4] platform: odp_shared_memory.c: implement func 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.47 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. fix retval for odp_shm_free. Signed-off-by: Yan Songming Reviewed-by: Mike Holmes --- v4 add more information about the retval and change the subject of this patch. v3 change the return value of odp_shm_free. v2 fix the problem which Maxim found. --- .../linux-generic/include/api/odp_shared_memory.h | 5 +-- platform/linux-generic/odp_shared_memory.c | 42 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 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..26e208b 100644 --- a/platform/linux-generic/include/api/odp_shared_memory.h +++ b/platform/linux-generic/include/api/odp_shared_memory.h @@ -80,8 +80,9 @@ 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 0 if the handle is already free + * @retval 0 if the handle free succeeds + * @retval -1 on failure to free the handle */ 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..0721292 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -114,6 +114,42 @@ 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 (NULL == odp_shm_tbl->block[i].addr) { + 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 +257,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;