DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Eimear Morrissey <eimear.morrissey@huawei.com>
To: <dev@dpdk.org>
Cc: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Subject: [PATCH 1/2] eal/pflock: add API to downgrade from wr to rd lock
Date: Wed, 10 Jun 2026 10:11:46 +0100	[thread overview]
Message-ID: <20260610091147.88412-2-eimear.morrissey@huawei.com> (raw)
In-Reply-To: <20260610091147.88412-1-eimear.morrissey@huawei.com>

From: Konstantin Ananyev <konstantin.ananyev@huawei.com>

Add a new API that allows for the caller to downgrade from wrlock
to rdlock. Note that caller is expected to obtain wrlock before calling
that function.

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
 lib/eal/include/rte_pflock.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/eal/include/rte_pflock.h b/lib/eal/include/rte_pflock.h
index 6797ce5920..ed5255b3b5 100644
--- a/lib/eal/include/rte_pflock.h
+++ b/lib/eal/include/rte_pflock.h
@@ -179,6 +179,27 @@ rte_pflock_write_unlock(rte_pflock_t *pf)
 	rte_atomic_fetch_add_explicit(&pf->wr.out, 1, rte_memory_order_release);
 }
 
+/**
+ * Release a pflock held for writing, while keeping lock for reading.
+ *
+ * @param pf
+ *   A pointer to a pflock structure.
+ */
+static inline void
+rte_pflock_write_downgrade(rte_pflock_t *pf)
+{
+	/* Migrate from write phase to read phase. */
+	rte_atomic_fetch_add_explicit(&pf->rd.in, RTE_PFLOCK_RINC,
+		rte_memory_order_acq_rel);
+	rte_atomic_fetch_and_explicit(&pf->rd.in, RTE_PFLOCK_LSB,
+			rte_memory_order_release);
+
+	/* Allow other writers to continue. */
+	rte_atomic_fetch_add_explicit(&pf->wr.out, 1,
+			rte_memory_order_release);
+}
+
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.51.0


  reply	other threads:[~2026-06-10  9:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10  9:11 [PATCH 0/2] Pflock downgrade & stress tests for pflock/rwlock libraries Eimear Morrissey
2026-06-10  9:11 ` Eimear Morrissey [this message]
2026-06-10  9:11 ` [PATCH 2/2] app/test: add stress tests for rwlock and pflock Eimear Morrissey
2026-06-10 15:59 ` [PATCH 0/2] Pflock downgrade & stress tests for pflock/rwlock libraries Stephen Hemminger

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 \
    --in-reply-to=20260610091147.88412-2-eimear.morrissey@huawei.com \
    --to=eimear.morrissey@huawei.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@huawei.com \
    /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