From patchwork Wed Feb 21 11:59:59 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: 129041 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp541971ljc; Wed, 21 Feb 2018 04:03:43 -0800 (PST) X-Google-Smtp-Source: AG47ELtYT18Yk9dkFxFJQfdl7g/4CFnWBTAGbhYn3pVHeC7rYfSl6WvEU2JVhcCfI4ohOlGKEQIX X-Received: by 10.55.125.65 with SMTP id y62mr145608qkc.241.1519214623023; Wed, 21 Feb 2018 04:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519214623; cv=none; d=google.com; s=arc-20160816; b=yNrgJKKFSTdbc35jQpHHEJvRmBqRJlJd8TbQAyxB8x9GE3aKlYNbKQS90DZ6liTrQv I+LEUk1BGT7PZli7A7GGzX+O1+Oqq8yquHp+x4PGmcE7B77/EXTqR7zM5YLvzm5f/7hV OGYU8mUW7szM80aR7XxDllC/20Ur0YLGvoCZHIO3FqGIJbna2WEbRdWmiU1lGtqbB2vP yBVizEyfPyYFtqeYlL0VKYiLQ381rUqkQq/+t24lUs0IbEBMo6UtrGVMLsGMiHAkTzC8 1VHPyR2WrV7H+3G8sGp10D2Mj/xDThXe1QcjEyqVcs00cJj5P/22yTrwp+OThfBTS+kH NkFw== 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=Vnrp8hQIQ2srp39qhZBDL5h7Fft4Ntl0HV/trxHgo5I=; b=Wd3OVMy6yofm86kpFKaPBfOoZAJm+jY3dZXGPQNJv5B+/sSU4sd0GcMfUH24oX3Twg M8FkPZlseQNZsmf21rhQEgpIAJHCHhun/Qac5XajdRsD/OV/LYmbYB+YyciD5sDZi4OD mxAast8EH9EpvcvyfQyDwJLIeUTyxeveq//Td+vYM5b342eS2X21qS5XcBxccGzq1b5m G2/ymRL7IxJ4U4xIBwYDksEqOfbaLigolBXki0ZkUfSpAnh0K4gU4srCCZShykOvlk0T vl+eYGdWUrjjmqKMJxZuBg0abGF++pYChmPsSR/WkGCTRBYoLQgeLCrTYMhJs8sUmThi uRdg== 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 200si3213825qkn.115.2018.02.21.04.03.42; Wed, 21 Feb 2018 04:03:42 -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 AE9FF61789; Wed, 21 Feb 2018 12:03:42 +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 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 2B8FD60C40; Wed, 21 Feb 2018 12:01:59 +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 2A62A61522; Wed, 21 Feb 2018 12:01:43 +0000 (UTC) Received: from forward101j.mail.yandex.net (forward101j.mail.yandex.net [5.45.198.241]) by lists.linaro.org (Postfix) with ESMTPS id CD2286171C for ; Wed, 21 Feb 2018 12:00:11 +0000 (UTC) Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward101j.mail.yandex.net (Yandex) with ESMTP id 71314124451A for ; Wed, 21 Feb 2018 15:00:10 +0300 (MSK) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [2a02:6b8:0:801::ac]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id qbzXLSlvy0-0AJaKbbX; Wed, 21 Feb 2018 15:00:10 +0300 Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a6UlmCoovI-09v8826m; Wed, 21 Feb 2018 15:00:09 +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, 21 Feb 2018 14:59:59 +0300 Message-Id: <1519214407-28047-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519214407-28047-1-git-send-email-odpbot@yandex.ru> References: <1519214407-28047-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 492 Subject: [lng-odp] [PATCH v1 2/10] linux-gen: ring_st: ring for single thread usage 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 This ring can be used as simple FIFO when enqueue / dequeue operation synchronization is not needed, or synchronization is provided by an upper layer already. Signed-off-by: Petri Savolainen --- /** Email created from pull request 492 (psavol:master-sched-optim) ** https://github.com/Linaro/odp/pull/492 ** Patch: https://github.com/Linaro/odp/pull/492.patch ** Base sha: 5a58bbf2bb331fd7dde2ebbc0430634ace6900fb ** Merge commit sha: 82a6bfe942419330a430b63149220e6b472f419c **/ platform/linux-generic/Makefile.am | 3 +- .../linux-generic/include/odp_ring_st_internal.h | 118 +++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 platform/linux-generic/include/odp_ring_st_internal.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 7f212fe5e..5250709bf 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -111,8 +111,9 @@ noinst_HEADERS = \ include/odp_posix_extensions.h \ include/odp_queue_internal.h \ include/odp_queue_scalable_internal.h \ - include/odp_ring_internal.h \ include/odp_queue_if.h \ + include/odp_ring_internal.h \ + include/odp_ring_st_internal.h \ include/odp_schedule_if.h \ include/odp_schedule_scalable.h \ include/odp_schedule_scalable_config.h \ diff --git a/platform/linux-generic/include/odp_ring_st_internal.h b/platform/linux-generic/include/odp_ring_st_internal.h new file mode 100644 index 000000000..8b6e102b3 --- /dev/null +++ b/platform/linux-generic/include/odp_ring_st_internal.h @@ -0,0 +1,118 @@ +/* Copyright (c) 2018, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_RING_ST_INTERNAL_H_ +#define ODP_RING_ST_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* Basic ring for single thread usage. Operations must be synchronized by using + * locks (or other means), when multiple threads use the same ring. */ +typedef struct { + uint32_t head; + uint32_t tail; + uint32_t mask; + uint32_t *data; + +} ring_st_t; + +/* Initialize ring. Ring size must be a power of two. */ +static inline void ring_st_init(ring_st_t *ring, uint32_t *data, uint32_t size) +{ + ring->head = 0; + ring->tail = 0; + ring->mask = size - 1; + ring->data = data; +} + +/* Dequeue data from the ring head. Max_num is smaller than ring size.*/ +static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[], + uint32_t max_num) +{ + uint32_t head, tail, mask, idx; + uint32_t num, i; + + head = ring->head; + tail = ring->tail; + mask = ring->mask; + num = tail - head; + + /* Empty */ + if (num == 0) + return 0; + + if (num > max_num) + num = max_num; + + idx = head & mask; + + for (i = 0; i < num; i++) { + data[i] = ring->data[idx]; + idx = (idx + 1) & mask; + } + + ring->head = head + num; + + return num; +} + +/* Enqueue data into the ring tail. Num_data is smaller than ring size. */ +static inline uint32_t ring_st_enq_multi(ring_st_t *ring, const uint32_t data[], + uint32_t num_data) +{ + uint32_t head, tail, mask, size, idx; + uint32_t num, i; + + head = ring->head; + tail = ring->tail; + mask = ring->mask; + size = mask + 1; + num = size - (tail - head); + + /* Full */ + if (num == 0) + return 0; + + if (num > num_data) + num = num_data; + + idx = tail & mask; + + for (i = 0; i < num; i++) { + ring->data[idx] = data[i]; + idx = (idx + 1) & mask; + } + + ring->tail = tail + num; + + return num; +} + +/* Check if ring is empty */ +static inline int ring_st_is_empty(ring_st_t *ring) +{ + uint32_t head, tail, num; + + head = ring->head; + tail = ring->tail; + num = tail - head; + + if (num == 0) + return 1; + + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif