From patchwork Wed Dec 20 15:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122473 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5690969qgn; Wed, 20 Dec 2017 07:04:27 -0800 (PST) X-Google-Smtp-Source: ACJfBosFZCctTQBxGpg9QJH1GjXQX9mcpFHpqcFKS2La/bjU/IL5AVZGMZEESdmnzr931CDzYY62 X-Received: by 10.237.35.207 with SMTP id k15mr10803361qtc.95.1513782267332; Wed, 20 Dec 2017 07:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513782267; cv=none; d=google.com; s=arc-20160816; b=R+tBSv446Z2YRyzET4mbf6A1c14DaZHdXkDkno6SteQZy+ENIdLSuxTQE6/aB7eCGu 8oJppLLljr9ur+GRVN0y58UM7ZW/jBrqcD13DmFtN46QXmEBnIGee/w0oPLfv8+TM/R2 IXvBDhDwQD5fUIoVHa2m+eidd0lJFK3xuDIx/IHAqkWULaHGnP9hOEG/TT3uHM/9UYi2 UqLg8QBmcWQQiOT6PLi9F8X+NgnAMoNBhUWCy/Jbwe6bhEnL8yRXpRYwWxAFFtgUGOAN Lglqkk8ATRCQVnuTfZ4YquJm/tSvcga+DwS98sPEsYkUElhv1BLIPITMX8d7QOi7r11I TrMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=OmJ67CxKHQZTiTf7WggZJs2YWB7UR1zT5Jqp/QalLcc=; b=y3lW+tcqZwDgz6+LiMgHfYhXs5wpTv9pq/GB9X3E/HxZx51tTKORIFpYM+xZJYKsj/ bkKdlx+3D2OYwOUny7HEfkTSPLWg1ZTdbk+QRu4kBuudZkM7AFKvrXQ6cuGLAxH+lNXS 1j2p+cb+LwQrFZN/7mcz0N156JuNJIo1mawy9x2OKARu3H7PqNdl9OguEiMrYwgKy8RR HrcMr5D7QnuhYKymsHlR7yvWwH6A/ZI07UruW2Z4oQPte0OhYdxezKSt3tMpy+4LMoUd 8sKC0qEopQrv5BrGrBcqgXGjYtRs+G+VBM003SPtOu2KAsk41RRUf1nvy7sUUAAOaDm5 rY0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id p5si3285190qkb.113.2017.12.20.07.04.16; Wed, 20 Dec 2017 07:04:27 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id CDDFF60940; Wed, 20 Dec 2017 15:04:16 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 E2C2D60922; Wed, 20 Dec 2017 15:01:00 +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 8FDEB60960; Wed, 20 Dec 2017 15:00:57 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id 89E2F608ED for ; Wed, 20 Dec 2017 15:00:22 +0000 (UTC) Received: from mxback5o.mail.yandex.net (mxback5o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1f]) by forward103j.mail.yandex.net (Yandex) with ESMTP id 415C234C2BE6 for ; Wed, 20 Dec 2017 18:00:20 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback5o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id aQ7SghtP3t-0E8SPIQn; Wed, 20 Dec 2017 18:00:14 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9OmWOYMNlY-0D5mmBBh; Wed, 20 Dec 2017 18:00:13 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Dec 2017 18:00:10 +0300 Message-Id: <1513782010-27654-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513782010-27654-1-git-send-email-odpbot@yandex.ru> References: <1513782010-27654-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 353 Subject: [lng-odp] [PATCH API-NEXT v1 3/3] validation: queue: test lock-free queue 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" From: Petri Savolainen Added simple, single threaded enqueue/dequeue test for lock-free queues. Signed-off-by: Petri Savolainen --- /** Email created from pull request 353 (psavol:next-lockfree-queue-impl2) ** https://github.com/Linaro/odp/pull/353 ** Patch: https://github.com/Linaro/odp/pull/353.patch ** Base sha: 12fd3a9224a856271934986a1bad981843915d68 ** Merge commit sha: 291f28b061ad4fa89a0346d6da4c6324c6335eca **/ test/validation/api/queue/queue.c | 121 +++++++++++++++++++++++++++++++++----- test/validation/api/queue/queue.h | 1 + 2 files changed, 106 insertions(+), 16 deletions(-) diff --git a/test/validation/api/queue/queue.c b/test/validation/api/queue/queue.c index f674b0813..1ff029176 100644 --- a/test/validation/api/queue/queue.c +++ b/test/validation/api/queue/queue.c @@ -10,9 +10,9 @@ #include #include "queue.h" -#define MAX_BUFFER_QUEUE (8) -#define MSG_POOL_SIZE (4 * 1024 * 1024) -#define CONFIG_MAX_ITERATION (100) +#define BURST_SIZE (8) +#define MAX_NUM_EVENT (1 * 1024) +#define MAX_ITERATION (100) #define MAX_QUEUES (64 * 1024) static int queue_context = 0xff; @@ -33,9 +33,11 @@ int queue_suite_init(void) { odp_pool_param_t params; - params.buf.size = 0; + odp_pool_param_init(¶ms); + + params.buf.size = 4; params.buf.align = ODP_CACHE_LINE_SIZE; - params.buf.num = 1024 * 10; + params.buf.num = MAX_NUM_EVENT; params.type = ODP_POOL_BUFFER; pool = odp_pool_create("msg_pool", ¶ms); @@ -153,18 +155,105 @@ void queue_test_mode(void) } } +static odp_event_t dequeue_event(odp_queue_t queue) +{ + odp_event_t ev; + int i; + + for (i = 0; i < MAX_ITERATION; i++) { + ev = odp_queue_deq(queue); + if (ev != ODP_EVENT_INVALID) + break; + } + + return ev; +} + +void queue_test_lockfree(void) +{ + odp_queue_param_t param; + odp_queue_t queue; + odp_queue_capability_t capa; + uint32_t max_burst, burst, i, j; + odp_pool_t pool; + odp_buffer_t buf; + odp_event_t ev; + uint32_t *data; + + CU_ASSERT_FATAL(odp_queue_capability(&capa) == 0); + + if (capa.plain.lockfree.max_num == 0) + return; + + max_burst = capa.plain.lockfree.max_size; + + if (max_burst == 0 || max_burst > MAX_NUM_EVENT) + max_burst = MAX_NUM_EVENT; + + pool = odp_pool_lookup("msg_pool"); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + + odp_queue_param_init(¶m); + param.type = ODP_QUEUE_TYPE_PLAIN; + param.nonblocking = ODP_NONBLOCKING_LF; + param.size = max_burst; + + queue = odp_queue_create("lockfree_queue", ¶m); + CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID); + + CU_ASSERT(odp_queue_deq(queue) == ODP_EVENT_INVALID); + + buf = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); + ev = odp_buffer_to_event(buf); + CU_ASSERT(odp_queue_enq(queue, ev) == 0); + ev = dequeue_event(queue); + CU_ASSERT_FATAL(ev != ODP_EVENT_INVALID); + if (ev != ODP_EVENT_INVALID) + odp_event_free(ev); + + for (j = 0; j < 2; j++) { + if (j == 0) + burst = max_burst / 4; + else + burst = max_burst; + + for (i = 0; i < burst; i++) { + buf = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); + data = odp_buffer_addr(buf); + *data = i; + ev = odp_buffer_to_event(buf); + CU_ASSERT(odp_queue_enq(queue, ev) == 0); + } + + for (i = 0; i < burst; i++) { + ev = dequeue_event(queue); + CU_ASSERT(ev != ODP_EVENT_INVALID); + if (ev != ODP_EVENT_INVALID) { + buf = odp_buffer_from_event(ev); + data = odp_buffer_addr(buf); + CU_ASSERT(*data == i); + odp_event_free(ev); + } + } + } + + CU_ASSERT(odp_queue_destroy(queue) == 0); +} + void queue_test_param(void) { odp_queue_t queue, null_queue; - odp_event_t enev[MAX_BUFFER_QUEUE]; - odp_event_t deev[MAX_BUFFER_QUEUE]; + odp_event_t enev[BURST_SIZE]; + odp_event_t deev[BURST_SIZE]; odp_buffer_t buf; odp_event_t ev; odp_pool_t msg_pool; odp_event_t *pev_tmp; int i, deq_ret, ret; int nr_deq_entries = 0; - int max_iteration = CONFIG_MAX_ITERATION; + int max_iteration = MAX_ITERATION; odp_queue_param_t qparams; odp_buffer_t enbuf; @@ -223,7 +312,7 @@ void queue_test_param(void) odp_buffer_free(buf); } - for (i = 0; i < MAX_BUFFER_QUEUE; i++) { + for (i = 0; i < BURST_SIZE; i++) { buf = odp_buffer_alloc(msg_pool); enev[i] = odp_buffer_to_event(buf); } @@ -233,23 +322,22 @@ void queue_test_param(void) * constraints in the implementation at that given point of time. * But here we assume that we succeed in enqueuing all buffers. */ - ret = odp_queue_enq_multi(queue, enev, MAX_BUFFER_QUEUE); - CU_ASSERT(MAX_BUFFER_QUEUE == ret); + ret = odp_queue_enq_multi(queue, enev, BURST_SIZE); + CU_ASSERT(BURST_SIZE == ret); i = ret < 0 ? 0 : ret; - for ( ; i < MAX_BUFFER_QUEUE; i++) + for ( ; i < BURST_SIZE; i++) odp_event_free(enev[i]); pev_tmp = deev; do { - deq_ret = odp_queue_deq_multi(queue, pev_tmp, - MAX_BUFFER_QUEUE); + deq_ret = odp_queue_deq_multi(queue, pev_tmp, BURST_SIZE); nr_deq_entries += deq_ret; max_iteration--; pev_tmp += deq_ret; CU_ASSERT(max_iteration >= 0); - } while (nr_deq_entries < MAX_BUFFER_QUEUE); + } while (nr_deq_entries < BURST_SIZE); - for (i = 0; i < MAX_BUFFER_QUEUE; i++) { + for (i = 0; i < BURST_SIZE; i++) { enbuf = odp_buffer_from_event(enev[i]); CU_ASSERT(enev[i] == deev[i]); odp_buffer_free(enbuf); @@ -326,6 +414,7 @@ void queue_test_info(void) odp_testinfo_t queue_suite[] = { ODP_TEST_INFO(queue_test_capa), ODP_TEST_INFO(queue_test_mode), + ODP_TEST_INFO(queue_test_lockfree), ODP_TEST_INFO(queue_test_param), ODP_TEST_INFO(queue_test_info), ODP_TEST_INFO_NULL, diff --git a/test/validation/api/queue/queue.h b/test/validation/api/queue/queue.h index 6b787b1d6..b85090707 100644 --- a/test/validation/api/queue/queue.h +++ b/test/validation/api/queue/queue.h @@ -12,6 +12,7 @@ /* test functions: */ void queue_test_capa(void); void queue_test_mode(void); +void queue_test_lockfree(void); void queue_test_param(void); void queue_test_info(void);