From patchwork Fri Aug 24 14: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: 145070 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1304832ljw; Fri, 24 Aug 2018 07:02:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaZobVQI5Zs1cNLbhpZ+SGrSgORS+hd6ukLX2raDfxZArLBwEEO8JuzzA+aumKBQTMWEHmA X-Received: by 2002:a0c:f312:: with SMTP id j18-v6mr1883607qvl.124.1535119343360; Fri, 24 Aug 2018 07:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535119343; cv=none; d=google.com; s=arc-20160816; b=KpMs5qBKNKDCrMVcUZM1qpovRPl0733Mhde3h82ZYDBQbypNvEQCu6hZ+fRBKtDl69 zDf8CZqjzeaeBJemaRyJH/pQH5fGq5bLQXJI0txJCgqoYxdDAjHgGSKX920QSNJZFN2I /MVg5LdrpoWCCX0TsaX1HfSuFZDAWpPoCKAQNe7JmrM9Q/BmS1pbzW6wE9YaKn9ErLzb I+MXq7evaIGrqa0ovmTDHtuFbINzlkETC6P3uMgw/5brCgCNFVkWfte1k9TMiI5YObBg /uHfLfqn+4gLmus5WtzbmMs3mf7oVXYLgzHiF2d7fgeXstVB0Mh+1B/3gM9h8sqFM92l Idqg== 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=4+S0msG0aBI4pHZHYCX8JfAWaIxRatl8i9scj49rpn4=; b=RwslfzB7RQKYMW5kCsGQ2OVMYY/4jS6n11uYjRe4m27wFzxTE8AmzVCloAKmA3WjBI 4Cs59LK8oByHg5xuxKEj2vh5xjMnl5ZUQyn2qVR1ROx2/suvqXVIG9/5V94rLOWbmrMP jXHlLKRRUiHVGrp8RhoYllxi0pTZACz8fW65zkRJLeuUV5xDIY6maKsKD1yGJ9I9zzQS H3zlHNQDrvSzt1/JLf6X7PWm14KLwvM2oiW7tv3Beb2SY5on8tmyrPbgjBUaJaCr/cU9 LBzvp0W4rtWQ+bdtHNSznctZwzmp/JxGkG8Vdn5NXN+MVB0EtD4DTAs3RN/oZRSbfVQh MaLg== 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 h14-v6si178985qkj.259.2018.08.24.07.02.23; Fri, 24 Aug 2018 07:02:23 -0700 (PDT) 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 1414A685E3; Fri, 24 Aug 2018 14:02:23 +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=-3.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI, 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 6A681685FE; Fri, 24 Aug 2018 14:00:35 +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 4363B685FE; Fri, 24 Aug 2018 14:00:21 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 1F0AE60833 for ; Fri, 24 Aug 2018 14:00:13 +0000 (UTC) Received: from mxback3o.mail.yandex.net (mxback3o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1d]) by forward106p.mail.yandex.net (Yandex) with ESMTP id ACC6C2D85F0E for ; Fri, 24 Aug 2018 17:00:11 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback3o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Md1nAvcXtE-0BxSXWNp; Fri, 24 Aug 2018 17:00:11 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 2CVvDjLgK3-0AjGUcfh; Fri, 24 Aug 2018 17: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: Fri, 24 Aug 2018 14:00:06 +0000 Message-Id: <1535119206-23556-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535119206-23556-1-git-send-email-odpbot@yandex.ru> References: <1535119206-23556-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 683 Subject: [lng-odp] [PATCH v1 4/4] linux-gen: ring_spsc: move ring mask and data pointer 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 Store mask and data pointer in queue entry instead of ring structure. Data is constant and can be stored among other frequently used read only data. Also other ring type use the same variables. Signed-off-by: Petri Savolainen --- /** Email created from pull request 683 (psavol:master-queue-lockless-enqdeq-3) ** https://github.com/Linaro/odp/pull/683 ** Patch: https://github.com/Linaro/odp/pull/683.patch ** Base sha: 989df5d2f97ab4711328b11282dcc743f5740e00 ** Merge commit sha: 28073c54671148efdd01c9cf38c1a235d5a133f0 **/ .../include/odp_ring_spsc_internal.h | 33 +++++++++---------- platform/linux-generic/odp_queue_spsc.c | 11 ++++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/platform/linux-generic/include/odp_ring_spsc_internal.h b/platform/linux-generic/include/odp_ring_spsc_internal.h index e38bda1da..de122bf57 100644 --- a/platform/linux-generic/include/odp_ring_spsc_internal.h +++ b/platform/linux-generic/include/odp_ring_spsc_internal.h @@ -29,31 +29,27 @@ extern "C" { typedef struct { odp_atomic_u32_t head; odp_atomic_u32_t tail; - uint32_t mask; - uint32_t *data; } ring_spsc_t; /* Initialize ring. Ring size must be a power of two. */ -static inline void ring_spsc_init(ring_spsc_t *ring, uint32_t *data, - uint32_t size) +static inline void ring_spsc_init(ring_spsc_t *ring) { odp_atomic_init_u32(&ring->head, 0); odp_atomic_init_u32(&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_spsc_deq_multi(ring_spsc_t *ring, uint32_t data[], +static inline uint32_t ring_spsc_deq_multi(ring_spsc_t *ring, + uint32_t *ring_data, + uint32_t ring_mask, uint32_t data[], uint32_t max_num) { - uint32_t head, tail, mask, idx; + uint32_t head, tail, idx; uint32_t num, i; tail = odp_atomic_load_acq_u32(&ring->tail); head = odp_atomic_load_u32(&ring->head); - mask = ring->mask; num = tail - head; /* Empty */ @@ -63,11 +59,11 @@ static inline uint32_t ring_spsc_deq_multi(ring_spsc_t *ring, uint32_t data[], if (num > max_num) num = max_num; - idx = head & mask; + idx = head & ring_mask; for (i = 0; i < num; i++) { - data[i] = ring->data[idx]; - idx = (idx + 1) & mask; + data[i] = ring_data[idx]; + idx = (idx + 1) & ring_mask; } odp_atomic_store_rel_u32(&ring->head, head + num); @@ -77,16 +73,17 @@ static inline uint32_t ring_spsc_deq_multi(ring_spsc_t *ring, uint32_t data[], /* Enqueue data into the ring tail. Num_data is smaller than ring size. */ static inline uint32_t ring_spsc_enq_multi(ring_spsc_t *ring, + uint32_t *ring_data, + uint32_t ring_mask, const uint32_t data[], uint32_t num_data) { - uint32_t head, tail, mask, size, idx; + uint32_t head, tail, size, idx; uint32_t num, i; head = odp_atomic_load_acq_u32(&ring->head); tail = odp_atomic_load_u32(&ring->tail); - mask = ring->mask; - size = mask + 1; + size = ring_mask + 1; num = size - (tail - head); /* Full */ @@ -96,11 +93,11 @@ static inline uint32_t ring_spsc_enq_multi(ring_spsc_t *ring, if (num > num_data) num = num_data; - idx = tail & mask; + idx = tail & ring_mask; for (i = 0; i < num; i++) { - ring->data[idx] = data[i]; - idx = (idx + 1) & mask; + ring_data[idx] = data[i]; + idx = (idx + 1) & ring_mask; } odp_atomic_store_rel_u32(&ring->tail, tail + num); diff --git a/platform/linux-generic/odp_queue_spsc.c b/platform/linux-generic/odp_queue_spsc.c index 0fd8d85a7..002561a49 100644 --- a/platform/linux-generic/odp_queue_spsc.c +++ b/platform/linux-generic/odp_queue_spsc.c @@ -49,7 +49,8 @@ static inline int spsc_enq_multi(odp_queue_t handle, return -1; } - return ring_spsc_enq_multi(ring_spsc, buf_idx, num); + return ring_spsc_enq_multi(ring_spsc, queue->s.ring_data, + queue->s.ring_mask, buf_idx, num); } static inline int spsc_deq_multi(odp_queue_t handle, @@ -68,7 +69,8 @@ static inline int spsc_deq_multi(odp_queue_t handle, return -1; } - num_deq = ring_spsc_deq_multi(ring_spsc, buf_idx, num); + num_deq = ring_spsc_deq_multi(ring_spsc, queue->s.ring_data, + queue->s.ring_mask, buf_idx, num); if (num_deq == 0) return 0; @@ -127,6 +129,7 @@ void queue_spsc_init(queue_entry_t *queue, uint32_t queue_size) offset = queue->s.index * (uint64_t)queue_glb->config.max_queue_size; - ring_spsc_init(&queue->s.ring_spsc, &queue_glb->ring_data[offset], - queue_size); + queue->s.ring_data = &queue_glb->ring_data[offset]; + queue->s.ring_mask = queue_size - 1; + ring_spsc_init(&queue->s.ring_spsc); }