From patchwork Tue Jan 16 12:00:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 124659 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp987767lje; Tue, 16 Jan 2018 04:01:04 -0800 (PST) X-Google-Smtp-Source: ACJfBosSAknInl5VXUaBN8v1I3QFwWMi8KVohJ3vp+bjR6Hgnp/v74VarCxdbQrg2/dmSd4tgqgH X-Received: by 10.55.82.197 with SMTP id g188mr55929203qkb.335.1516104064584; Tue, 16 Jan 2018 04:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516104064; cv=none; d=google.com; s=arc-20160816; b=VBkaMON/SCuZs1T7BXho3z19xi82eXs6iaqlncuaTrLl64qkm11NIuUBtZPSPET96W 6dIZX87qZwMFqsMEYWgl44UDGm1PTiDfORoA24nCz1IWn16gGZwlAyBYhur7xpjOLPR8 9rV7VCWvIOZ3Fzii78bC+olu9QN9ug5blBV6h76nOsJqql+qoyut3581BxhCh226ekvq MYeqZCWvqoBKg/aoCYsfLVfNnHZaoSsWbRvpxJiDJ9pkMF+ri8q+7cJfYC3ZDcuSXKzL 0tMzc/h5bAmvN9fezLj+gcZtkLO1j6WEx7TU7fJkkA0rP8t2JzIosP4HpivNGZeX9LZB dCHg== 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=z958e/LHmgQ0ifbOnpJh7LpRII2+xdCDLujA+7eG1B0=; b=ZjvSMqUFHa7KghAhNN8/FbV9ZpIn9ghMylFgviiQOnIcPSzotXuAeJ2h9IJVdCFAp0 XF4es6iA0cI1nO1Xkkpv1ls2bsZGXC/1CZEhFDcDUideBzMyKrRjPEjvtt4KXkoqtf+X 2BtezB4BWBK1v/kMHUWcX60DYosDzbTl/pOi56BsSedayox8JDVwyNuRKxD+JWSpCTxv f9hL7oX28EqZ6HdMdDpTwVlFis8H0bkFv9eKcxNaH3H3LpMh1JwO80hXaoUzmIBSJpVL x2tdKAItF6GqWsZAQzrBSrggAaTAoRPJ2MifFmiaeUCbjUSprw3CHp43HenwLVBUFy2+ v7ow== 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 3si1259075qtt.39.2018.01.16.04.01.03; Tue, 16 Jan 2018 04:01:04 -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 E1108617A8; Tue, 16 Jan 2018 12:01:03 +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 D707361798; Tue, 16 Jan 2018 12:00:53 +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 55BB361798; Tue, 16 Jan 2018 12:00:48 +0000 (UTC) Received: from forward105j.mail.yandex.net (forward105j.mail.yandex.net [5.45.198.248]) by lists.linaro.org (Postfix) with ESMTPS id BC2F661785 for ; Tue, 16 Jan 2018 12:00:12 +0000 (UTC) Received: from mxback4j.mail.yandex.net (mxback4j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10d]) by forward105j.mail.yandex.net (Yandex) with ESMTP id 25448183AE4 for ; Tue, 16 Jan 2018 15:00:11 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback4j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 5iyQktTk8a-0BNG8dR9; Tue, 16 Jan 2018 15:00:11 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id b7CVxjO9hV-0AgaNdk0; Tue, 16 Jan 2018 15:00:10 +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: Tue, 16 Jan 2018 15:00:06 +0300 Message-Id: <1516104008-9628-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516104008-9628-1-git-send-email-odpbot@yandex.ru> References: <1516104008-9628-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 393 Subject: [lng-odp] [PATCH API-NEXT v1 2/4] 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 393 (psavol:next-lockfree-queue-impl-rebased) ** https://github.com/Linaro/odp/pull/393 ** Patch: https://github.com/Linaro/odp/pull/393.patch ** Base sha: f6dab2bfa90ef5d3146cb76f86bc8782666f0f3e ** Merge commit sha: 3da13358015ca674abf51f61f539fcbf6607cb2d **/ 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);