From patchwork Fri Jan 13 07:55:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 91267 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp55963qgi; Thu, 12 Jan 2017 22:57:41 -0800 (PST) X-Received: by 10.55.183.3 with SMTP id h3mr18641009qkf.33.1484290661254; Thu, 12 Jan 2017 22:57:41 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p6si7800186qkp.210.2017.01.12.22.57.41; Thu, 12 Jan 2017 22:57:41 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E895760C5D; Fri, 13 Jan 2017 06:57:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E68A7608BF; Fri, 13 Jan 2017 06:57:05 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 806C16083A; Fri, 13 Jan 2017 06:57:00 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id F4237608D4 for ; Fri, 13 Jan 2017 06:56:30 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id z134so26037592lff.3 for ; Thu, 12 Jan 2017 22:56:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TSwZ7mA/nJM6wX7bItrAncARzWxklcgsILF4//5dB0U=; b=pS7OIYkZI3rmhOP37SdXNna2RqsWTxZ3rZPXFgAELWHWeOC5l/xcWkgMJC4XgT8RuL CKh5Q1mZfcSj8+myb9HufZ7Tm3eWhvEXV2W9JQZEBRxORO8wLrCNvfe7u9cUUgoAsbOV tnGZsY90c5SoU257mhmY8M7XBMOMPKOSaYFxcdjelHNEAEoXgo9jShly5OElZdbXZ9AG L+yXRgn3oDJsllyXfyRolU5p4IogkQ05JguOxphrLYZiKp/r0GGTJJQ+Ntt9zuHEoCI+ Nx2uZXGtL5M3jz1Gr2lQvkAYKMGEkt9EgyqvzmZTlgUtFJdJLeXJP6/bM6DcuuZ122P0 2SlQ== X-Gm-Message-State: AIkVDXLfYp6sGNZyn9ArC68GzgXZR5BgW+/vYY2zwHFYBLbfeMWFcWwSSETn6NqvZX53rC4Yoig= X-Received: by 10.25.4.9 with SMTP id 9mr6100439lfe.45.1484290589670; Thu, 12 Jan 2017 22:56:29 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id e7sm3327034lfb.10.2017.01.12.22.56.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Jan 2017 22:56:28 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, francois.ozog@linaro.org, lng-odp@lists.linaro.org Date: Fri, 13 Jan 2017 08:55:39 +0100 Message-Id: <1484294143-29882-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484294143-29882-1-git-send-email-christophe.milard@linaro.org> References: <1484294143-29882-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv7 2/6] drv: adding odpdrv_shm_pool functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Adding functions to create and destroy memory pools (from which memory can be allocated and freed) are added. These functions enable the usage of small memory amount (compared to drvshm_reserve() whose granularity is the page size). The usage of this pool guatantees that allocated memory is sharable between ODP threads. (using malloc would not work when ODP threads are linux processes). Signed-off-by: Christophe Milard Reviewed-by: Petri Savolainen --- include/odp/drv/spec/shm.h | 94 ++++++++++++++++++++++ .../linux-generic/include/odp/drv/plat/shm_types.h | 3 + 2 files changed, 97 insertions(+) -- 2.7.4 diff --git a/include/odp/drv/spec/shm.h b/include/odp/drv/spec/shm.h index ef64f5d..64124c0 100644 --- a/include/odp/drv/spec/shm.h +++ b/include/odp/drv/spec/shm.h @@ -220,6 +220,100 @@ int odpdrv_shm_print_all(const char *title); uint64_t odpdrv_shm_to_u64(odpdrv_shm_t hdl); /** + * drv shm pool parameters + * Used to communicate pool creation options. + */ +typedef struct { + /** Sum of all (simultaneous) allocs (bytes)*/ + uint64_t pool_size; + + /** Minimum alloc size user will request from pool (bytes)*/ + uint64_t min_alloc; + + /** Maximum alloc size user will request from pool (bytes)*/ + uint64_t max_alloc; +} odpdrv_shm_pool_param_t; + +/** + * @typedef odpdrv_shm_pool_t + * odpdrv shared memory pool + */ + +/** + * Create a memory pool + * + * This routine is used to create a memory pool. The use of pool name is + * optional. + * Unique names are not required. However, odpdrv_shm_pool_lookup() + * returns only a single matching pool. + * + * @param name Name of the pool or NULL. + * @param param Pool parameters. + * + * @return Handle of the created drv shm memory pool + * @retval ODPDRV_SHM_POOL_INVALID Pool could not be created + */ +odpdrv_shm_pool_t odpdrv_shm_pool_create(const char *pool_name, + odpdrv_shm_pool_param_t *param); + +/** + * Destroy a pool previously created by odpdrv_shm_pool_create() + * + * @param pool Handle of the pool to be destroyed + * + * @retval 0 Success + * @retval <0 Failure + * + * @note This routine destroys a previously created pool, and will destroy any + * internal shared memory objects associated with the pool. Results are + * undefined if an attempt is made to destroy a pool that contains allocated + * or otherwise active allocations. + */ +int odpdrv_shm_pool_destroy(odpdrv_shm_pool_t pool); + +/** + * Find a memory pool by name + * + * @param name Name of the pool + * + * @return Handle of the first matching pool + * @retval ODPDRV_SHM_POOL_INVALID Pool could not be found + */ +odpdrv_shm_pool_t odpdrv_shm_pool_lookup(const char *name); + +/** + * Allocate memory from a memory pool + * + * @param pool Memory pool handle + * @param size Number of bytes to allocate (bytes) + * + * @return A pointer to the allocated memory + * @retval NULL on error. + */ +void *odpdrv_shm_pool_alloc(odpdrv_shm_pool_t pool, uint64_t size); + +/** + * Free memory back to a memory pool + * + * @param pool Memory pool handle + * @param addr pointer to a previously allocated memory + * (as returned by a previous call to odpdrv_shm_pool_alloc) + */ +void odpdrv_shm_pool_free(odpdrv_shm_pool_t pool, void *addr); + +/** + * Print memory pool info + * + * @param title A string to be printed as a title (e.g. location) + * @param pool Memory pool handle + * + * @return 0 on success, negative value if pool inconsistency is detected. + * + * @note This routine writes implementation-defined information about the + * specified pool to the ODP log. The intended use is for debugging. + */ +int odpdrv_shm_pool_print(const char *title, odpdrv_shm_pool_t pool); +/** * @} */ diff --git a/platform/linux-generic/include/odp/drv/plat/shm_types.h b/platform/linux-generic/include/odp/drv/plat/shm_types.h index c48eeca..50a0837 100644 --- a/platform/linux-generic/include/odp/drv/plat/shm_types.h +++ b/platform/linux-generic/include/odp/drv/plat/shm_types.h @@ -35,6 +35,9 @@ static inline uint64_t odpdrv_shm_to_u64(odpdrv_shm_t hdl) return _odpdrv_pri(hdl); } +typedef ODPDRV_HANDLE_T(odpdrv_shm_pool_t); + +#define ODPDRV_SHM_POOL_INVALID _odpdrv_cast_scalar(odpdrv_shm_pool_t, NULL) /** * @} */