From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 651E1A0093 for ; Mon, 7 Mar 2022 15:36:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 553614014E; Mon, 7 Mar 2022 15:36:32 +0100 (CET) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by mails.dpdk.org (Postfix) with ESMTP id CC3C94014E for ; Mon, 7 Mar 2022 15:36:30 +0100 (CET) Received: by mail-lj1-f182.google.com with SMTP id q5so6029265ljb.11 for ; Mon, 07 Mar 2022 06:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E01rmvnZY591noc3C+ZTiOJGEpLIH2oEeHAVwo9oJr4=; b=vwxOwrr36iq88vXFKwGIW6pAJP1csDt4BU5te8W9qmqR4PFZh0AX462FCIoBqXZbrq dHKfTdUyYB5MhTf8KrBl+hS6ylVqZ8c+WC/c+IEWHajvUQr2HlTLROkGOaTajxp7OjBU T1897UwwRQtDPMRIxo166DXi4ZWjVR+GWLmWGuriQenclbqiWwjSUiapXnQdfjM4y0AF q0R6Onmf8AQ6ubDN17LxZlYIyDmHuLGcUqNmDGUgiWv0Wg6qx6LNsOASbm17Db8y/VAx Mb1FTzhgFvrS78n/h/92sYj6wytVqQVwrzZdQKcXXVgcibuMo6FNK/eQnClKhI8ZZ752 c+KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E01rmvnZY591noc3C+ZTiOJGEpLIH2oEeHAVwo9oJr4=; b=ouPDqOEuPJwVtZVBHIgmRJbVxtBzghgKUXWaxbessCtMdXqW2ly0UQ2RHH+owrTB9Y nstmEDIpGIXYcP45dD8pVIEq5XbrrGLsykMWG+L/YUJDjcPl77t/DLy1jndz1Z55EaOg 5+3/VXMpk3JvRDm91StXJ1ITA5CSr+hcCyCjWmbVNDfFmYRdyELSCbNfu/HRUjkPWtkg zQa6IKqqNPD0mIX8EUJu077e98DFbNbyMmmf850aBdewvX7GO+veuIg1Psh1PdTpqYFi I7IaUb1U+5EcnZuY+UE84EXxQ4Esv3pAzXmEdWYwvbK+ujUki/DKn+xX7MsJQ+Jbyts+ wNhA== X-Gm-Message-State: AOAM531C31nb+rym8cLmOAr2qrXRY+8f7wPyc3KbKToIPMB1UWcQU8c+ oMxRMLluBDct0ncz2JtyNU6jat48rxOHFQ== X-Google-Smtp-Source: ABdhPJyMRl1ietuUImNCkVS4+QiCYRNZsSRmhrCpG++ueW6R0v3ZQ1vR2t3akAQjO7lyvw0eq8WNWA== X-Received: by 2002:a05:651c:1192:b0:246:1d6b:d323 with SMTP id w18-20020a05651c119200b002461d6bd323mr7792725ljo.360.1646663790348; Mon, 07 Mar 2022 06:36:30 -0800 (PST) Received: from andrzejo-l.semihalf.net ([83.142.187.84]) by smtp.googlemail.com with ESMTPSA id s3-20020ac25fe3000000b004481d8f1bfcsm1991513lfg.1.2022.03.07.06.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 06:36:29 -0800 (PST) From: Andrzej Ostruszka To: stable@dpdk.org Cc: Andrzej Ostruszka , Olivier Matz , Konstantin Ananyev , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH 19.11] ring: optimize corner case for enqueue/dequeue Date: Mon, 7 Mar 2022 15:14:52 +0100 Message-Id: <20220307141452.872210-1-amo@semihalf.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 97ed4cb6fb324f4277ee754d4b6f3c7a0d96400b ] When enqueueing/dequeueing to/from the ring we try to optimize by manual loop unrolling. The check for this optimization looks like: if (likely(idx + n < size)) { where 'idx' points to the first usable element (empty slot for enqueue, data for dequeue). The correct comparison here should be '<=' instead of '<'. This is not a functional error since we fall back to the loop with correct checks on indexes. Just a minor suboptimal behaviour for the case when we want to enqueue/dequeue exactly the number of elements that we have in the ring before wrapping to its beginning. Fixes: cc4b218790f6 ("ring: support configurable element size") Fixes: 286bd05bf70d ("ring: optimisations") Signed-off-by: Andrzej Ostruszka Reviewed-by: Olivier Matz Acked-by: Konstantin Ananyev Reviewed-by: Morten Brørup --- lib/librte_ring/rte_ring.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 2a9f768a1c..e020781336 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -242,7 +242,7 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r); const uint32_t size = (r)->size; \ uint32_t idx = prod_head & (r)->mask; \ obj_type *ring = (obj_type *)ring_start; \ - if (likely(idx + n < size)) { \ + if (likely(idx + n <= size)) { \ for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \ ring[idx] = obj_table[i]; \ ring[idx+1] = obj_table[i+1]; \ @@ -273,7 +273,7 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r); uint32_t idx = cons_head & (r)->mask; \ const uint32_t size = (r)->size; \ obj_type *ring = (obj_type *)ring_start; \ - if (likely(idx + n < size)) { \ + if (likely(idx + n <= size)) { \ for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\ obj_table[i] = ring[idx]; \ obj_table[i+1] = ring[idx+1]; \ -- 2.35.1.616.g0bdcbb4464-goog