From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by dpdk.org (Postfix) with ESMTP id 29CDE1B1B9 for ; Tue, 10 Oct 2017 11:56:48 +0200 (CEST) Received: by mail-pf0-f195.google.com with SMTP id b85so14045039pfj.1 for ; Tue, 10 Oct 2017 02:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+R6AmqdDNBGeni8gUsxCCwZHJwAqOMCYRmSzHlx8Smw=; b=KoFEAHvdeBFi1jci+OQ+LKFrILevG9+kOJh18zvempD7MuhLxle2l2h8fpw+BRfobO Gc+j3o9u6F8rIjWGzckPbvkrfrVMxRdGKMQZmsj/54PR1VqiY2oKxjY1DajboSrZci9H LQ7yb3e34MWZozOiEC1A0E8gPr/eVR6iDgie5duWNjK1kJod6FSNNM3Fu+e2TKEKC46I mdMUy/m0JLPXaAsEi7CYnO7zSlIB1gS/+xKG2w7q69btUAC3gqaylpRUbvu+RZatMhmy ch11e+pUXcM0Xb2awry+2FkoOI5r+bi+qUKv3Ou7dx7hXpRKpX3GBOKkMl7kVVsvyATg VHpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+R6AmqdDNBGeni8gUsxCCwZHJwAqOMCYRmSzHlx8Smw=; b=YqBhZBkEE/wtDKtg1TPUK9bFl+MZQz45jZJpA0pfNDyXR4e+SRaThXbnrYMTZhH9qG TkbksSKR2e/0ZslBeBY2QW+ZVxkUlYzz9xhNFDvTL8oz8hlQRS2+DDBKciP99JOLQrzO SA5aOz66bEubB5Y5zLV/7acmwjMTOmPAwy2eh5RnkecTAyI2rgC+ms1MdWSloYl6cJfE RsMFLi6+bZw8i+I+dZx9YNLgbZwz8Wd0xi6PZgWRvgVAZOfJWur+5lPthEmCKyRMLpGX Ub8JumuKvXNyP4g1iw6TU/TS3Qn2qqN4OYr+FZ6C1YJIZ4qmfWQ2Jec1O35U5DSLT7JS RKzQ== X-Gm-Message-State: AMCzsaWbgNeBcBgTeSCCCsFSZEAoKo+IYjQV7z0rSP2bzPD6BOZNC211 NTgo1KlNgYF4ZPIFHOrbgbE= X-Google-Smtp-Source: AOwi7QBlbZ6x1KFdFqPx8zV8bzxQh2zdLm0GIwimXBG6poOsuhmugDd5Orcs3DyQCh8d7xXN3y7Nxg== X-Received: by 10.98.149.88 with SMTP id p85mr11251097pfd.12.1507629407449; Tue, 10 Oct 2017 02:56:47 -0700 (PDT) Received: from localhost.localdomain ([180.173.249.63]) by smtp.gmail.com with ESMTPSA id w12sm21208843pfk.83.2017.10.10.02.56.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Oct 2017 02:56:46 -0700 (PDT) From: Jia He To: olivier.matz@6wind.com Cc: dev@dpdk.org, Jia He , jia.he@hxt-semitech.com, jie2.liu@hxt-semitech.com, bing.zhao@hxt-semitech.com Date: Tue, 10 Oct 2017 17:56:36 +0800 Message-Id: <20171010095636.4507-1-hejianet@gmail.com> X-Mailer: git-send-email 2.13.6 Subject: [dpdk-dev] [PATCH] ring: guarantee ordering of cons/prod loading when doing enqueue/dequeue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Oct 2017 09:56:48 -0000 Before this patch: In __rte_ring_move_cons_head() ... do { /* Restore n as it may change every loop */ n = max; *old_head = r->cons.head; //1st load const uint32_t prod_tail = r->prod.tail; //2nd load In weak memory order architectures(powerpc,arm), the 2nd load might be reodered before the 1st load, that makes *entries is bigger than we wanted. This nasty reording messed enque/deque up. cpu1(producer) cpu2(consumer) cpu3(consumer) load r->prod.tail in enqueue: load r->cons.tail load r->prod.head store r->prod.tail load r->cons.head load r->prod.tail ... store r->cons.{head,tail} load r->cons.head THEN,r->cons.head will be bigger than prod_tail, then make *entries very big After this patch, the old cons.head will be recaculated after failure of rte_atomic32_cmpset There is no such issue in X86 cpu, because X86 is strong memory order model Signed-off-by: Jia He Signed-off-by: jia.he@hxt-semitech.com Signed-off-by: jie2.liu@hxt-semitech.com Signed-off-by: bing.zhao@hxt-semitech.com --- lib/librte_ring/rte_ring.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 5e9b3b7..15c72e2 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -409,6 +409,10 @@ __rte_ring_move_prod_head(struct rte_ring *r, int is_sp, n = max; *old_head = r->prod.head; + + /* load of prod.tail can't be reordered before cons.head */ + rte_smp_rmb(); + const uint32_t cons_tail = r->cons.tail; /* * The subtraction is done between two unsigned 32bits value @@ -517,6 +521,10 @@ __rte_ring_move_cons_head(struct rte_ring *r, int is_sc, n = max; *old_head = r->cons.head; + + /* load of prod.tail can't be reordered before cons.head */ + rte_smp_rmb(); + const uint32_t prod_tail = r->prod.tail; /* The subtraction is done between two unsigned 32bits value * (the result is always modulo 32 bits even if we have -- 2.7.4