From patchwork Thu Sep 25 15:49:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rosenboim, Leonid" X-Patchwork-Id: 37924 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 22345202DB for ; Thu, 25 Sep 2014 15:50:06 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id ho1sf4796979wib.0 for ; Thu, 25 Sep 2014 08:50:05 -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:thread-topic:thread-index :date:message-id:references:in-reply-to:accept-language:mime-version :subject:precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-language :content-type; bh=cwub8xsUZaZncOHn/5TeoN+waqb2j3HJximyUadlNFE=; b=bqjzHXatJ6JDysb/b35YT0w1wKYq8e11Y0OQnGONMFkE0QfFBat+9UhGcdRhSX1JPr 8grI1HHefgNksiG6dD7g1zp1llVDI0EiT4WNxTl8r8aEARdq0tIdS9MMUv3Pu22tuQKW B9IDvUQ8OEnzVUgJduYrEG1SOkRShdvsMCZXiMY49SE2PlTW/pTtDK7lOcD5ifDwSNmT lem67ReJx23mJOF5W/jQpODKzzFKumm1gMqBa3BQ3IRRbDxqptASApZzqta0fPVXrwpO 6X5+lRov7e2o+EuxZUOoiQiBgGRCXioM2ZpRm+B4NLqCqN6E835VRRQEMoteJMPcTjjX BbBg== X-Gm-Message-State: ALoCoQkkkyBoaQFLs62nXFY6Zf8CFGyQUSrhTKLOphQlPuENQVUSbvLdFCZmzGP45NJaIm1z8RXd X-Received: by 10.112.89.8 with SMTP id bk8mr2268678lbb.6.1411660205027; Thu, 25 Sep 2014 08:50:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.201 with SMTP id u9ls296608lau.107.gmail; Thu, 25 Sep 2014 08:50:04 -0700 (PDT) X-Received: by 10.112.171.229 with SMTP id ax5mr6869409lbc.25.1411660204755; Thu, 25 Sep 2014 08:50:04 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) by mx.google.com with ESMTPS id am9si3623326lbc.32.2014.09.25.08.50.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Sep 2014 08:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id q1so1182518lam.21 for ; Thu, 25 Sep 2014 08:50:03 -0700 (PDT) X-Received: by 10.152.7.8 with SMTP id f8mr14100886laa.27.1411660203824; Thu, 25 Sep 2014 08:50:03 -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.112.130.169 with SMTP id of9csp774679lbb; Thu, 25 Sep 2014 08:50:02 -0700 (PDT) X-Received: by 10.140.104.68 with SMTP id z62mr21883880qge.81.1411660202345; Thu, 25 Sep 2014 08:50:02 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id x4si2755213qat.104.2014.09.25.08.50.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 25 Sep 2014 08:50:02 -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-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XXBIu-0000bg-F1; Thu, 25 Sep 2014 15:50:00 +0000 Received: from mail-by2on0075.outbound.protection.outlook.com ([207.46.100.75] helo=na01-by2-obe.outbound.protection.outlook.com) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XXBIo-0000ba-QO for lng-odp@lists.linaro.org; Thu, 25 Sep 2014 15:49:55 +0000 Received: from SN2PR07MB031.namprd07.prod.outlook.com (10.255.174.41) by SN2PR07MB032.namprd07.prod.outlook.com (10.255.174.42) with Microsoft SMTP Server (TLS) id 15.0.1034.13; Thu, 25 Sep 2014 15:49:47 +0000 Received: from SN2PR07MB031.namprd07.prod.outlook.com ([169.254.1.203]) by SN2PR07MB031.namprd07.prod.outlook.com ([169.254.1.203]) with mapi id 15.00.1034.003; Thu, 25 Sep 2014 15:49:47 +0000 From: "Rosenboim, Leonid" To: Anders Roxell , lng-odp-forward Thread-Topic: [lng-odp] [PATCH] Add API odp_buffer_pool_delete Thread-Index: AQHP2DQdJMrlnjLP0USweauXKEI6TJwRzZ+AgAAvw1o= Date: Thu, 25 Sep 2014 15:49:46 +0000 Message-ID: <1411660186731.24886@caviumnetworks.com> References: <1411589561-20050-1-git-send-email-anders.roxell@linaro.org> <1411589561-20050-2-git-send-email-anders.roxell@linaro.org>, In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [64.2.3.195] x-microsoft-antispam: BCL:0;PCL:0;RULEID:;SRVR:SN2PR07MB032; x-forefront-prvs: 0345CFD558 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(199003)(377454003)(189002)(35774003)(24454002)(53754006)(19627405001)(2656002)(87936001)(64706001)(85306004)(15975445006)(20776003)(76482002)(31966008)(15202345003)(19580395003)(19617315012)(107886001)(83322001)(19580405001)(85806002)(107046002)(66066001)(16601075003)(21056001)(86362001)(106356001)(117636001)(92726001)(76176999)(92566001)(50986999)(90102001)(99286002)(105586002)(77096002)(95666004)(106116001)(97736003)(10300001)(85852003)(83072002)(99396003)(4396001)(36756003)(16236675004)(54356999)(81542003)(46102003)(77982003)(120916001)(81342003)(101416001)(74502003)(80022003)(79102003)(74662003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR07MB032; H:SN2PR07MB031.namprd07.prod.outlook.com; FPR:; MLV:sfv; PTR:InfoNoRecords; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-Topics: patch Subject: Re: [lng-odp] [PATCH] Add API odp_buffer_pool_delete 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: , 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: Leonid.Rosenboim@caviumnetworks.com 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.48 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 Content-Language: en-US How about checking that all buffers have been freed to the pool prior to destroying the pool itself ? Also, since odp_buffer_pool_create() gets memory from the caller, the destroy description should spell out that the caller is also responsable for freeing this memory for complete reverse of the action. Then, if some buffers have not been returned, what to do ? One option is to warn and proceed, another option is to bail and return an error, a third option is to mark the pool as destined for deletion, which prevents new buffers from being doled out, but allows buffer frees, and trigger an automatic pool destruction when the last buffer is returned. The risk of proceeding with destruction while some buffers are outstanding is potential memory corruption that is very hard to debug. diff --git a/platform/linux-generic/include/api/odp_buffer_pool.h b/platform/linux-generic/include/api/odp_buffer_pool.h index fe88898..fca2c62 100644 --- a/platform/linux-generic/include/api/odp_buffer_pool.h +++ b/platform/linux-generic/include/api/odp_buffer_pool.h @@ -34,6 +34,15 @@ typedef uint32_t odp_buffer_pool_t; /** + * Delete a buffer pool + * + * @param pool_hdl Buffer pool handle + * + * @return 0 if successful else -1 + */ +int odp_buffer_pool_delete(odp_buffer_pool_t pool_hdl); + +/** * Create a buffer pool * * @param name Name of the pool (max ODP_BUFFER_POOL_NAME_LEN - 1 chars) diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index 4d9ff45..7ba793d 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -375,6 +375,31 @@ static void link_bufs(pool_entry_t *pool) } } +int odp_buffer_pool_delete(odp_buffer_pool_t pool_hdl) +{ + pool_entry_t *pool; + if (odp_unlikely(ODP_CONFIG_BUFFER_POOLS <= pool_hdl)) + ODP_ERR("set_handle: Bad pool handle %u\n", pool_hdl); + + pool = get_pool_entry(pool_hdl); + pool->s.free_bufs = 0; + strcpy(pool->s.name, ""); + /* Need to restore this because this is setup in + * odp_buffer_pool_init_global + * */ + pool->s.pool_hdl = pool_hdl; + pool->s.buf_base = 0; + pool->s.buf_size = 0; + pool->s.buf_offset = 0; + pool->s.num_bufs = 0; + pool->s.pool_base_addr = NULL; + pool->s.pool_size = 0; + pool->s.user_size = 0; + pool->s.user_align = 0; + pool->s.buf_type = ODP_BUFFER_POOL_INVALID; + pool->s.hdr_size = 0; + return 0; +} odp_buffer_pool_t odp_buffer_pool_create(const char *name, void *base_addr, uint64_t size,