From patchwork Wed Dec 21 11:28:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 88718 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2194104qgi; Wed, 21 Dec 2016 02:31:13 -0800 (PST) X-Received: by 10.55.104.141 with SMTP id d135mr3802379qkc.243.1482316273170; Wed, 21 Dec 2016 02:31:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 12si4705270qkv.211.2016.12.21.02.31.12; Wed, 21 Dec 2016 02:31:13 -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 dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D69FF635D2; Wed, 21 Dec 2016 10:31:12 +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 7B75D635E2; Wed, 21 Dec 2016 10:29: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 27A90635D6; Wed, 21 Dec 2016 10:28:48 +0000 (UTC) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com [209.85.215.45]) by lists.linaro.org (Postfix) with ESMTPS id 59035635D2 for ; Wed, 21 Dec 2016 10:28:46 +0000 (UTC) Received: by mail-lf0-f45.google.com with SMTP id t196so94836619lff.3 for ; Wed, 21 Dec 2016 02:28:46 -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=HFOf8jybz9duuukL/nJOt8ttX9bpCPhpcvjRr5+qDBc=; b=iGeZS0lqMcAGEuxz8tInJuPPYJOC7qD3IBoJ2QDI3hzj6OY0rcpYzWLFFmrJR8XA+p bcv3+5Zis51Y0n05uP0arn/yyzurLJTcTNNKYmG/T0ySfzJdnKRcs/NftH66qkOLpDuM R6SjdY/1iPkZ1oKYIWK/edIDs3jM5srTVarIlNXtAt70Oxz09w8A23Ho1eyyPjDAGCqN ltEG8AR1WxQupnI1vNEBzldAXQl/YoicXjsf0969geWt4mByPu+nhroXL48iVMD00BDZ 95OSJgvv5A0M/E/5quxU/xADE8uwgH84jUZdvJn8AyKjiEJYzL+xwXRbeFc9e8O603HT qGvg== X-Gm-Message-State: AIkVDXI2SnTm5MGjII6vdKJEXtxPBKkt67k08SmYAK17QY55hq14AIxYjKdYo1wvPan7XuB2LDQ= X-Received: by 10.25.15.40 with SMTP id e40mr1232983lfi.10.1482316125127; Wed, 21 Dec 2016 02:28:45 -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 u204sm5532775lja.5.2016.12.21.02.28.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Dec 2016 02:28:44 -0800 (PST) From: Christophe Milard To: francois.ozog@linaro.org, forrest.shi@linaro.org, mike.holmes@linaro.org, yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 21 Dec 2016 12:28:20 +0100 Message-Id: <1482319702-5766-4-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482319702-5766-1-git-send-email-christophe.milard@linaro.org> References: <1482319702-5766-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 3/5] linux-gen: drv: shm: adding buddy allocator 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" A pool for buddy allocation of small memory sizes is created at boot time and functions to reserve/free memory from this pool added (using the _ishm equivalent, of course). Memory allocated from this pool is sharable between ODP threads, (which malloc() would not guarantee in the odptreads as process case) Signed-off-by: Christophe Milard --- platform/linux-generic/drv_shm.c | 44 +++++++++++++++++++++- .../linux-generic/include/odp_config_internal.h | 10 +++++ platform/linux-generic/include/odp_internal.h | 4 ++ platform/linux-generic/odp_init.c | 13 +++++++ 4 files changed, 70 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_shm.c b/platform/linux-generic/drv_shm.c index 9b2560d..dec3e6c 100644 --- a/platform/linux-generic/drv_shm.c +++ b/platform/linux-generic/drv_shm.c @@ -7,7 +7,14 @@ #include #include #include +#include +#include +#include #include <_ishm_internal.h> +#include <_ishmbuddy_internal.h> + +#define BUDDYPOOL_NAME "drvshm_buddy_pool" +static _odpdrv_shm_bpool_t *buddy_pool; static inline uint32_t from_handle(odpdrv_shm_t shm) { @@ -98,5 +105,40 @@ int odpdrv_shm_info(odpdrv_shm_t shm, odpdrv_shm_info_t *info) int odpdrv_shm_print_all(const char *title) { - return _odp_ishm_status(title); + int res; + + /* print shm status */ + res = _odp_ishm_status(title); + /* print buddy allocator status: */ + (void)_odp_ishmbud_status(buddy_pool); + + return res; +} + +void *odpdrv_shm_sreserve(uint64_t size) +{ + return _odp_ishmbud_alloc(buddy_pool, size); +} + +int odpdrv_shm_sfree(void *addr) +{ + return _odp_ishmbud_free(buddy_pool, addr); +} + +int _odpdrv_shm_init_global(void) +{ + /* create a buddy pool of granularity = cache_line_size: */ + buddy_pool = _odp_ishmbud_pool_create(BUDDYPOOL_NAME, + ODP_CONFIG_DRVSHM_BUDDY_POOL_SZ, + ODP_CACHE_LINE_SIZE, 0); + if (!buddy_pool) + return -1; + + return 0; +} + +int _odpdrv_shm_term_global(void) +{ + /* destroy the buddy pool: */ + return _odp_ishmbud_pool_destroy(buddy_pool); } diff --git a/platform/linux-generic/include/odp_config_internal.h b/platform/linux-generic/include/odp_config_internal.h index c494660..0b810c8 100644 --- a/platform/linux-generic/include/odp_config_internal.h +++ b/platform/linux-generic/include/odp_config_internal.h @@ -116,6 +116,16 @@ extern "C" { */ #define ODP_CONFIG_ISHM_VA_PREALLOC_SZ (536870912L) +/* + * Size of the DRVSHM buddy allocator pool, available on south interface. + * + * This pool is preallocated at init time. Memory from this pool can + * be allocated using odpdrv_shm_sreserve(). + * should be a power of 2 (or will be rounded as such) + * In bytes. + */ +#define ODP_CONFIG_DRVSHM_BUDDY_POOL_SZ (1048576UL) + /* Maximum number of shared memory blocks available on the driver interface. * * This the the number of separate SHM areas that can be reserved concurrently diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index b313b1f..908891f 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -59,6 +59,7 @@ enum init_stage { SYSINFO_INIT, FDSERVER_INIT, ISHM_INIT, + DRVSHM_INIT, THREAD_INIT, POOL_INIT, QUEUE_INIT, @@ -127,6 +128,9 @@ int _odp_ishm_init_local(void); int _odp_ishm_term_global(void); int _odp_ishm_term_local(void); +int _odpdrv_shm_init_global(void); +int _odpdrv_shm_term_global(void); + int cpuinfo_parser(FILE *file, system_info_t *sysinfo); uint64_t odp_cpu_hz_current(int id); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 1b0d8f8..dd396be 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -120,6 +120,12 @@ int odp_init_global(odp_instance_t *instance, } stage = ISHM_INIT; + if (_odpdrv_shm_init_global()) { + ODP_ERR("ODP drvshm init failed.\n"); + goto init_failed; + } + stage = DRVSHM_INIT; + if (odp_thread_init_global()) { ODP_ERR("ODP thread init failed.\n"); goto init_failed; @@ -273,6 +279,13 @@ int _odp_term_global(enum init_stage stage) } /* Fall through */ + case DRVSHM_INIT: + if (_odpdrv_shm_term_global()) { + ODP_ERR("ODP drvshm term failed.\n"); + rc = -1; + } + /* Fall through */ + case ISHM_INIT: if (_odp_ishm_term_global()) { ODP_ERR("ODP ishm term failed.\n");