From: Ammar Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: Ammar Faizi <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH ncns v1 3/4] chnet: ring: Make sure we are holding the lock when calling `cqe_size()`
Date: Tue, 16 Aug 2022 23:53:13 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
In `CNRingCtx::WaitCQE`, the first call to `cqe_size()` is not protected
by the cqe_lock. Protect it.
Fixes: a04f582cdbdbcefa3c08ce123696d0fd08a20702 ("chnet: Full refactor CNRing and change the interface")
Signed-off-by: Ammar Faizi <[email protected]>
---
chnet/chnet_ring.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/chnet/chnet_ring.cc b/chnet/chnet_ring.cc
index c9a3da5..e9d0d57 100644
--- a/chnet/chnet_ring.cc
+++ b/chnet/chnet_ring.cc
@@ -366,6 +366,7 @@ uint32_t CNRingCtx::SubmitSQE(uint32_t to_submit)
void CNRingCtx::WaitCQE(uint32_t to_wait)
{
uint32_t max_to_wait;
+ uint32_t cq_size;
if (unlikely(!to_wait))
return;
@@ -375,10 +376,11 @@ void CNRingCtx::WaitCQE(uint32_t to_wait)
to_wait = max_to_wait;
NotifyWaitCQEFreeSlot();
- if (to_wait <= cqe_size())
- return;
std::unique_lock<std::mutex> cqe_lock(state_->cqe_lock_);
+ cq_size = cqe_size();
+ if (to_wait <= cq_size)
+ return;
state_->cqe_to_wait_.store(to_wait);
state_->cqe_cond_.wait(cqe_lock, [this, to_wait]{
--
Ammar Faizi
next prev parent reply other threads:[~2022-08-16 16:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 16:53 [PATCH ncns v1 0/4] chnet ring cleanups Ammar Faizi
2022-08-16 16:53 ` [PATCH ncns v1 1/4] chnet: ring: Refactor SQE handling Ammar Faizi
2022-08-16 16:53 ` [PATCH ncns v1 2/4] chnet: ring: Improve `PostCQE()` waiting mechanism Ammar Faizi
2022-08-16 16:53 ` Ammar Faizi [this message]
2022-08-16 16:53 ` [PATCH ncns v1 4/4] chnet: ring: Only notify CQE free slot when it's available Ammar Faizi
2022-08-16 17:12 ` Alviro Iskandar Setiawan
2022-08-16 17:17 ` Ammar Nofan Faizi
2022-08-16 17:23 ` Alviro Iskandar Setiawan
2022-08-16 17:24 ` [PATCH ncns v1 0/4] chnet ring cleanups Alviro Iskandar Setiawan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox